! * updates the content of the statistics spreadsheet. * called when the data in the parent spreadsheet was modified. */
| 148 | * called when the data in the parent spreadsheet was modified. |
| 149 | */ |
| 150 | void StatisticsSpreadsheet::update() { |
| 151 | // determine the number of activated metrics and properly resize the spreadsheet |
| 152 | int colCount = 1; // first column for "column name" |
| 153 | for (const auto& metric : m_metricValues) { |
| 154 | if (m_metrics.testFlag(metric)) |
| 155 | ++colCount; |
| 156 | } |
| 157 | |
| 158 | setUndoAware(false); |
| 159 | setRowCount(m_spreadsheet->columnCount()); |
| 160 | setColumnCount(colCount); |
| 161 | setUndoAware(true); |
| 162 | |
| 163 | // make all columns in this statistics spreadsheet undo unaware |
| 164 | const auto& statisticsColumns = children<Column>(); |
| 165 | for (auto* col : statisticsColumns) { |
| 166 | col->setUndoAware(false); |
| 167 | col->setFixed(true); |
| 168 | } |
| 169 | |
| 170 | // show the column names in the first column of the statistics spreadsheet |
| 171 | auto* statisticsColumn = statisticsColumns.at(0); |
| 172 | statisticsColumn->setName(i18n("Column")); |
| 173 | statisticsColumn->setColumnMode(AbstractColumn::ColumnMode::Text); |
| 174 | const auto& columns = m_spreadsheet->children<Column>(); |
| 175 | for (int i = 0; i < columns.count(); ++i) |
| 176 | statisticsColumn->setTextAt(i, columns.at(i)->name()); |
| 177 | |
| 178 | // show other statistics metrics that were activated |
| 179 | int colIndex = 1; |
| 180 | int metricIndex = 0; |
| 181 | for (const auto& metric : m_metricValues) { |
| 182 | if (m_metrics.testFlag(metric)) { |
| 183 | // rename the statistics column |
| 184 | auto* statisticsColumn = statisticsColumns.at(colIndex); |
| 185 | statisticsColumn->setName(m_metricNames.at(metricIndex)); |
| 186 | |
| 187 | // set the column mode |
| 188 | if (m_metricValues.at(metricIndex) == StatisticsSpreadsheet::Metric::Count) |
| 189 | statisticsColumn->setColumnMode(AbstractColumn::ColumnMode::Integer); |
| 190 | else |
| 191 | statisticsColumn->setColumnMode(AbstractColumn::ColumnMode::Double); |
| 192 | |
| 193 | // set the cell values |
| 194 | for (int i = 0; i < columns.count(); ++i) { |
| 195 | const auto* column = columns.at(i); |
| 196 | const auto& statistics = column->statistics(); |
| 197 | |
| 198 | switch (metric) { |
| 199 | case Metric::Count: |
| 200 | statisticsColumn->setIntegerAt(i, statistics.size); |
| 201 | break; |
| 202 | case Metric::Minimum: |
| 203 | statisticsColumn->setValueAt(i, statistics.minimum); |
| 204 | break; |
| 205 | case Metric::Maximum: |
| 206 | statisticsColumn->setValueAt(i, statistics.maximum); |
| 207 | break; |
nothing calls this directly
no test coverage detected