| 187 | } |
| 188 | |
| 189 | void FunctionValuesDialog::checkValues() { |
| 190 | if (ui.teEquation->toPlainText().simplified().isEmpty()) { |
| 191 | m_okButton->setToolTip(i18n("Empty formula expression")); |
| 192 | m_okButton->setEnabled(false); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | // check whether the formula syntax is correct |
| 197 | if (!ui.teEquation->isValid()) { |
| 198 | m_okButton->setToolTip(i18n("Incorrect formula syntax: ") + ui.teEquation->errorMessage()); |
| 199 | m_okButton->setEnabled(false); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | // check if expression uses variables |
| 204 | if (ui.teEquation->expressionUsesVariables()) { |
| 205 | // check the variables |
| 206 | for (int i = 0; i < m_variableDataColumns.size(); ++i) { |
| 207 | const auto& varName = m_variableLineEdits.at(i)->text(); |
| 208 | |
| 209 | // ignore empty |
| 210 | if (varName.isEmpty()) |
| 211 | continue; |
| 212 | |
| 213 | // check whether a valid column was provided for the variable |
| 214 | auto* cb = m_variableDataColumns.at(i); |
| 215 | auto* aspect = static_cast<AbstractAspect*>(cb->currentModelIndex().internalPointer()); |
| 216 | if (!aspect) { |
| 217 | m_okButton->setToolTip(i18n("Select a valid column")); |
| 218 | m_okButton->setEnabled(false); |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | // check whether the variable name is correct |
| 223 | if (!validVariableName(m_variableLineEdits.at(i))) { |
| 224 | m_okButton->setToolTip(i18n("Variable name can contain letters, digits and '_' only and should start with a letter")); |
| 225 | m_okButton->setEnabled(false); |
| 226 | return; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | m_okButton->setToolTip(i18n("Generate function values")); |
| 232 | m_okButton->setEnabled(true); |
| 233 | } |
| 234 | |
| 235 | void FunctionValuesDialog::showConstants() { |
| 236 | QMenu menu; |
nothing calls this directly
no test coverage detected