Changeset View
Changeset View
Standalone View
Standalone View
src/kdefrontend/spreadsheet/FunctionValuesDialog.cpp
Show All 25 Lines | |||||
26 | * * | 26 | * * | ||
27 | ***************************************************************************/ | 27 | ***************************************************************************/ | ||
28 | #include "FunctionValuesDialog.h" | 28 | #include "FunctionValuesDialog.h" | ||
29 | #include "backend/core/AspectTreeModel.h" | 29 | #include "backend/core/AspectTreeModel.h" | ||
30 | #include "backend/core/column/Column.h" | 30 | #include "backend/core/column/Column.h" | ||
31 | #include "backend/core/Project.h" | 31 | #include "backend/core/Project.h" | ||
32 | #include "backend/lib/macros.h" | 32 | #include "backend/lib/macros.h" | ||
33 | #include "backend/spreadsheet/Spreadsheet.h" | 33 | #include "backend/spreadsheet/Spreadsheet.h" | ||
34 | #include "backend/gsl/ExpressionParser.h" | ||||
34 | #include "commonfrontend/widgets/TreeViewComboBox.h" | 35 | #include "commonfrontend/widgets/TreeViewComboBox.h" | ||
35 | #include "kdefrontend/widgets/ConstantsWidget.h" | 36 | #include "kdefrontend/widgets/ConstantsWidget.h" | ||
36 | #include "kdefrontend/widgets/FunctionsWidget.h" | 37 | #include "kdefrontend/widgets/FunctionsWidget.h" | ||
37 | 38 | | |||
38 | #include <QMenu> | 39 | #include <QMenu> | ||
39 | #include <QWidgetAction> | 40 | #include <QWidgetAction> | ||
40 | #include <QDialogButtonBox> | 41 | #include <QDialogButtonBox> | ||
41 | #include <QPushButton> | 42 | #include <QPushButton> | ||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | 120 | void FunctionValuesDialog::setColumns(QVector<Column*> columns) { | |||
153 | } | 154 | } | ||
154 | 155 | | |||
155 | //auto update | 156 | //auto update | ||
156 | ui.chkAutoUpdate->setChecked(m_columns.first()->formulaAutoUpdate()); | 157 | ui.chkAutoUpdate->setChecked(m_columns.first()->formulaAutoUpdate()); | ||
157 | 158 | | |||
158 | checkValues(); | 159 | checkValues(); | ||
159 | } | 160 | } | ||
160 | 161 | | |||
162 | bool FunctionValuesDialog::validVariableName(QLineEdit* le) { | ||||
163 | | ||||
asemke: why not to search with constants().indexOf(name) and comparing the found index with -1? | |||||
164 | if (ExpressionParser::getInstance()->constants().indexOf(le->text()) != -1) { | ||||
165 | le->setStyleSheet("QLineEdit{background: red;}"); | ||||
166 | le->setToolTip(i18n("Provided variable name is already reserved for a name of a constant. Please use another name.")); | ||||
167 | return false; | ||||
168 | } | ||||
169 | | ||||
170 | if (ExpressionParser::getInstance()->functions().indexOf(le->text()) != -1) { | ||||
171 | le->setStyleSheet("QLineEdit{background: red;}"); | ||||
172 | le->setToolTip(i18n("Provided variable name is already reserved for a name of a function. Please use another name.")); | ||||
173 | return false; | ||||
174 | } | ||||
175 | | ||||
176 | le->setStyleSheet(QString()); | ||||
177 | le->setToolTip(""); | ||||
178 | return true; | ||||
179 | } | ||||
180 | | ||||
161 | /*! | 181 | /*! | ||
162 | check the user input and enables/disables the Ok-button depending on the correctness of the input | 182 | check the user input and enables/disables the Ok-button depending on the correctness of the input | ||
163 | */ | 183 | */ | ||
164 | void FunctionValuesDialog::checkValues() { | 184 | void FunctionValuesDialog::checkValues() { | ||
165 | //check whether the formula syntax is correct | 185 | //check whether the formula syntax is correct | ||
166 | if (!ui.teEquation->isValid()) { | 186 | if (!ui.teEquation->isValid()) { | ||
167 | m_okButton->setEnabled(false); | 187 | m_okButton->setEnabled(false); | ||
168 | return; | 188 | return; | ||
169 | } | 189 | } | ||
170 | 190 | | |||
171 | //check whether for the variables where a name was provided also a column was selected. | 191 | //check whether for the variables where a name was provided also a column was selected. | ||
172 | for (int i = 0; i < m_variableDataColumns.size(); ++i) { | 192 | for (int i = 0; i < m_variableDataColumns.size(); ++i) { | ||
173 | if (m_variableNames.at(i)->text().simplified().isEmpty()) | 193 | if (m_variableNames.at(i)->text().simplified().isEmpty()) | ||
174 | continue; | 194 | continue; | ||
175 | 195 | | |||
176 | TreeViewComboBox* cb = m_variableDataColumns.at(i); | 196 | TreeViewComboBox* cb = m_variableDataColumns.at(i); | ||
177 | AbstractAspect* aspect = static_cast<AbstractAspect*>(cb->currentModelIndex().internalPointer()); | 197 | AbstractAspect* aspect = static_cast<AbstractAspect*>(cb->currentModelIndex().internalPointer()); | ||
178 | if (!aspect) { | 198 | if (!aspect) { | ||
179 | m_okButton->setEnabled(false); | 199 | m_okButton->setEnabled(false); | ||
180 | return; | 200 | return; | ||
181 | } | 201 | } | ||
202 | | ||||
203 | if (!validVariableName(m_variableNames[i])) { | ||||
204 | m_okButton->setEnabled(false); | ||||
205 | return; | ||||
206 | } | ||||
182 | /* Column* column = dynamic_cast<Column*>(aspect); | 207 | /* Column* column = dynamic_cast<Column*>(aspect); | ||
183 | DEBUG("row count = " << (static_cast<QVector<double>* >(column->data()))->size()); | 208 | DEBUG("row count = " << (static_cast<QVector<double>* >(column->data()))->size()); | ||
184 | if (!column || column->rowCount() < 1) { | 209 | if (!column || column->rowCount() < 1) { | ||
185 | m_okButton->setEnabled(false); | 210 | m_okButton->setEnabled(false); | ||
186 | //Warning: x column is empty | 211 | //Warning: x column is empty | ||
187 | return; | 212 | return; | ||
188 | } | 213 | } | ||
189 | */ | 214 | */ | ||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Line(s) | 325 | void FunctionValuesDialog::variableNameChanged() { | |||
315 | 340 | | |||
316 | if (!text.isEmpty()) | 341 | if (!text.isEmpty()) | ||
317 | text = "f(" + text + ") = "; | 342 | text = "f(" + text + ") = "; | ||
318 | else | 343 | else | ||
319 | text = "f = "; | 344 | text = "f = "; | ||
320 | 345 | | |||
321 | ui.lFunction->setText(text); | 346 | ui.lFunction->setText(text); | ||
322 | ui.teEquation->setVariables(vars); | 347 | ui.teEquation->setVariables(vars); | ||
348 | checkValues(); | ||||
323 | } | 349 | } | ||
324 | 350 | | |||
325 | void FunctionValuesDialog::generate() { | 351 | void FunctionValuesDialog::generate() { | ||
326 | Q_ASSERT(m_spreadsheet); | 352 | Q_ASSERT(m_spreadsheet); | ||
327 | 353 | | |||
328 | WAIT_CURSOR; | 354 | WAIT_CURSOR; | ||
329 | m_spreadsheet->beginMacro(i18np("%1: fill column with function values", | 355 | m_spreadsheet->beginMacro(i18np("%1: fill column with function values", | ||
330 | "%1: fill columns with function values", | 356 | "%1: fill columns with function values", | ||
Show All 30 Lines |
why not to search with constants().indexOf(name) and comparing the found index with -1?