From a9c496e0652b128714a3acca9b68156e2d31fe3a Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 2 Oct 2014 12:46:24 +0300 Subject: [PATCH] Fixed built-in functions. --HG-- branch : develop --- src/app/container/calculator.cpp | 5 +++++ src/app/container/vcontainer.cpp | 2 +- src/app/dialogs/app/dialogincrements.cpp | 2 +- src/app/options.cpp | 4 ++++ src/app/options.h | 3 +++ src/app/widgets/textdelegate.cpp | 4 ++-- src/app/widgets/textdelegate.h | 1 + 7 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/app/container/calculator.cpp b/src/app/container/calculator.cpp index 4bd488acb..dc0fafae4 100644 --- a/src/app/container/calculator.cpp +++ b/src/app/container/calculator.cpp @@ -164,6 +164,11 @@ void Calculator::InitVariables(const VContainer *data, const QMap } } + if (builInFunctions.contains(i.value())) + {// We found built-in function + found = true; + } + if (found == false) { throw qmu::QmuParserError (ecUNASSIGNABLE_TOKEN, i.value(), formula, i.key()); diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index 027cf3308..d4a12a768 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -414,7 +414,7 @@ const QMap > VContainer::DataAngleLines() co //--------------------------------------------------------------------------------------------------------------------- bool VContainer::IsUnique(const QString &name) { - return !uniqueNames.contains(name); + return (!uniqueNames.contains(name) && !builInFunctions.contains(name)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index 54c2d40ac..ef575dd10 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -544,7 +544,7 @@ void DialogIncrements::clickedToolButtonAdd() { name = QString(tr("Name_%1")).arg(num); num++; - } while (data->VariableExist(name)); + } while (data->IsUnique(name)==false); const quint32 id = data->getNextId(); const QString description(tr("Description")); diff --git a/src/app/options.cpp b/src/app/options.cpp index 95229d42e..02aeae0e1 100644 --- a/src/app/options.cpp +++ b/src/app/options.cpp @@ -28,6 +28,7 @@ #include "options.h" #include +#include //Same regexp in pattern.xsd shema file. Don't forget synchronize. const QString nameRegExp = QStringLiteral("^([^0-9-*/^+=\\s\\(\\)%:;!.,]){1,1}([^-*/^+=\\s\\(\\)%:;!.,]){0,}$"); @@ -212,6 +213,9 @@ const QString max_F = QStringLiteral("max"); const QString sum_F = QStringLiteral("sum"); const QString avg_F = QStringLiteral("avg"); +const QStringList builInFunctions{sin_F, cos_F, tan_F, asin_F, acos_F, atan_F, sinh_F, cosh_F, tanh_F, asinh_F, acosh_F, + atanh_F, log2_F, log10_F, log_F, ln_F, exp_F, sqrt_F, sign_F, rint_F, abs_F, min_F, max_F, sum_F, avg_F}; + // Postfix operators const QString cm_Oprt = QStringLiteral("cm"); const QString mm_Oprt = QStringLiteral("mm"); diff --git a/src/app/options.h b/src/app/options.h index baf82ef35..725c75d4c 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -38,6 +38,7 @@ #include class QString; +class QStringList; static const quint32 null_id = 0; @@ -304,6 +305,8 @@ extern const QString max_F; extern const QString sum_F; extern const QString avg_F; +extern const QStringList builInFunctions; + // Postfix operators extern const QString cm_Oprt; extern const QString mm_Oprt; diff --git a/src/app/widgets/textdelegate.cpp b/src/app/widgets/textdelegate.cpp index c037fbbfd..296dd1507 100644 --- a/src/app/widgets/textdelegate.cpp +++ b/src/app/widgets/textdelegate.cpp @@ -79,7 +79,7 @@ void TextDelegate::setEditorData(QWidget *editor, const QModelIndex &index) cons SCASSERT(lineEdit != nullptr); if ( lastText != text && text.isEmpty() == false) { - //Here need save text, but method is const, so, we use signal instead. + //Here need save text, but this method is const, so, we use signal instead. emit SaveText(text); } lineEdit->setText(text); @@ -129,7 +129,7 @@ void TextDelegate::commitAndCloseEditor() QLineEdit *lineEdit = qobject_cast(sender()); SCASSERT(lineEdit != nullptr); QString text = lineEdit->text(); - if ( lastText != text && text.isEmpty() == false && data->VariableExist(text) == false) + if ( lastText != text && text.isEmpty() == false && data->IsUnique(text)) { lastText = text; emit commitData(lineEdit); diff --git a/src/app/widgets/textdelegate.h b/src/app/widgets/textdelegate.h index 0b2138b40..974579ed7 100644 --- a/src/app/widgets/textdelegate.h +++ b/src/app/widgets/textdelegate.h @@ -53,6 +53,7 @@ signals: void SaveText(const QString &text) const; public slots: void commitAndCloseEditor(); +private slots: void InitText(const QString &text); private: Q_DISABLE_COPY(TextDelegate)