diff --git a/src/kdefrontend/spreadsheet/FunctionValuesDialog.h b/src/kdefrontend/spreadsheet/FunctionValuesDialog.h --- a/src/kdefrontend/spreadsheet/FunctionValuesDialog.h +++ b/src/kdefrontend/spreadsheet/FunctionValuesDialog.h @@ -49,6 +49,7 @@ explicit FunctionValuesDialog(Spreadsheet* s, QWidget* parent = nullptr); ~FunctionValuesDialog() override; void setColumns(QVector); + bool validVariableName(QLineEdit *le); private: Ui::FunctionValuesWidget ui; diff --git a/src/kdefrontend/spreadsheet/FunctionValuesDialog.cpp b/src/kdefrontend/spreadsheet/FunctionValuesDialog.cpp --- a/src/kdefrontend/spreadsheet/FunctionValuesDialog.cpp +++ b/src/kdefrontend/spreadsheet/FunctionValuesDialog.cpp @@ -31,6 +31,7 @@ #include "backend/core/Project.h" #include "backend/lib/macros.h" #include "backend/spreadsheet/Spreadsheet.h" +#include "backend/gsl/ExpressionParser.h" #include "commonfrontend/widgets/TreeViewComboBox.h" #include "kdefrontend/widgets/ConstantsWidget.h" #include "kdefrontend/widgets/FunctionsWidget.h" @@ -158,6 +159,25 @@ checkValues(); } +bool FunctionValuesDialog::validVariableName(QLineEdit* le) { + + if (ExpressionParser::getInstance()->constants().indexOf(le->text()) != -1) { + le->setStyleSheet("QLineEdit{background: red;}"); + le->setToolTip(i18n("Provided variable name is already reserved for a name of a constant. Please use another name.")); + return false; + } + + if (ExpressionParser::getInstance()->functions().indexOf(le->text()) != -1) { + le->setStyleSheet("QLineEdit{background: red;}"); + le->setToolTip(i18n("Provided variable name is already reserved for a name of a function. Please use another name.")); + return false; + } + + le->setStyleSheet(QString()); + le->setToolTip(""); + return true; +} + /*! check the user input and enables/disables the Ok-button depending on the correctness of the input */ @@ -179,6 +199,11 @@ m_okButton->setEnabled(false); return; } + + if (!validVariableName(m_variableNames[i])) { + m_okButton->setEnabled(false); + return; + } /* Column* column = dynamic_cast(aspect); DEBUG("row count = " << (static_cast* >(column->data()))->size()); if (!column || column->rowCount() < 1) { @@ -320,6 +345,7 @@ ui.lFunction->setText(text); ui.teEquation->setVariables(vars); + checkValues(); } void FunctionValuesDialog::generate() {