MCPcopy Create free account
hub / github.com/KDE/labplot / update

Method update

src/backend/spreadsheet/StatisticsSpreadsheet.cpp:150–289  ·  view source on GitHub ↗

! * updates the content of the statistics spreadsheet. * called when the data in the parent spreadsheet was modified. */

Source from the content-addressed store, hash-verified

148 * called when the data in the parent spreadsheet was modified.
149 */
150void 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;

Callers

nothing calls this directly

Calls 11

setUndoAwareMethod · 0.80
setFixedMethod · 0.80
statisticsMethod · 0.80
columnCountMethod · 0.45
setNameMethod · 0.45
setColumnModeMethod · 0.45
countMethod · 0.45
setTextAtMethod · 0.45
nameMethod · 0.45
setIntegerAtMethod · 0.45
setValueAtMethod · 0.45

Tested by

no test coverage detected