| 95 | } |
| 96 | |
| 97 | void FunctionValuesDialog::setColumns(const QVector<Column*>& columns) { |
| 98 | m_columns = columns; |
| 99 | const Column* firstColumn{m_columns.first()}; |
| 100 | |
| 101 | // formula expression |
| 102 | ui.teEquation->setPlainText(firstColumn->formula()); |
| 103 | // variables |
| 104 | const auto& formulaData = firstColumn->formulaData(); |
| 105 | if (formulaData.isEmpty()) { |
| 106 | // A formula without any column variable is also possible, for example when just using the rownumber: "i / 1000" |
| 107 | // This is a workaround, because right now there is no way to determine which variable is used in the formula and which not |
| 108 | // it makes no sense to add variables if they are not used (preventing cyclic dependency) Gitlab #1037 |
| 109 | |
| 110 | // no formula was used for this column -> add the first variable "x" |
| 111 | // addVariable(); |
| 112 | // m_variableLineEdits[0]->setText(QStringLiteral("x")); |
| 113 | } else { // formula and variables are available |
| 114 | // add all available variables and select the corresponding columns |
| 115 | const auto& cols = m_spreadsheet->project()->children<Column>(AbstractAspect::ChildIndexFlag::Recursive); |
| 116 | for (int i = 0; i < formulaData.size(); ++i) { |
| 117 | addVariable(); |
| 118 | m_variableLineEdits[i]->setText(formulaData.at(i).variableName()); |
| 119 | |
| 120 | bool found = false; |
| 121 | for (const auto* col : cols) { |
| 122 | if (col != formulaData.at(i).column()) |
| 123 | continue; |
| 124 | |
| 125 | const auto* column = dynamic_cast<const AbstractColumn*>(col); |
| 126 | if (column) |
| 127 | m_variableDataColumns[i]->setCurrentModelIndex(m_aspectTreeModel->modelIndexOfAspect(column)); |
| 128 | else |
| 129 | m_variableDataColumns[i]->setCurrentModelIndex(QModelIndex()); |
| 130 | |
| 131 | m_variableDataColumns[i]->setInvalid(false); |
| 132 | |
| 133 | found = true; |
| 134 | break; |
| 135 | } |
| 136 | |
| 137 | // for the current variable name no column exists anymore (was deleted) |
| 138 | //->highlight the combobox red |
| 139 | if (!found) { |
| 140 | m_variableDataColumns[i]->setCurrentModelIndex(QModelIndex()); |
| 141 | m_variableDataColumns[i]->setInvalid( |
| 142 | true, |
| 143 | i18n("The column \"%1\"\nis not available anymore. It will be automatically used once it is created again.", |
| 144 | formulaData.at(i).columnName())); |
| 145 | m_variableDataColumns[i]->setText(formulaData.at(i).columnName().split(QLatin1Char('/')).last()); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // auto update |
| 151 | // Enable if linking is turned on, so the user has to explicit disable recalculation, so it cannot be forgotten |
| 152 | ui.chkAutoUpdate->setChecked(firstColumn->formulaAutoUpdate() || m_spreadsheet->linking()); |
| 153 | |
| 154 | // auto-resize |
nothing calls this directly
no test coverage detected