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

Method showColumnStatistics

src/frontend/spreadsheet/SpreadsheetView.cpp:3233–3305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3231}
3232
3233void SpreadsheetView::showColumnStatistics(bool forAll) {
3234 QString dlgTitle(i18n("%1: column statistics", m_spreadsheet->name()));
3235 QVector<Column*> columns;
3236
3237 // Column statistics can be shown for:
3238 // * all columns in the spreadsheet - called via the action_statistics_all_columns or when one single cell is selected (=no selection)
3239 // * all selected columns in the speadsheet - called via the context menu of the header
3240 // * selected column cells - called via the context menu in the spreadsheet with multiple selected cells
3241 const auto& indexes = m_tableView->selectionModel()->selectedIndexes();
3242 if (forAll || indexes.size() <= 1) {
3243 for (int col = 0; col < m_spreadsheet->columnCount(); ++col) {
3244 auto* column = m_spreadsheet->column(col);
3245 if (column->hasValues())
3246 columns << column;
3247 }
3248 } else {
3249 columns = selectedColumns(true);
3250
3251 // if no columns are fully selected, copy the selected cells into new Columns which will be processes in the statistics dialog
3252 if (columns.isEmpty()) {
3253 const auto& children = m_spreadsheet->children<Column>();
3254 Column* targetColumn{nullptr};
3255 QMap<int, int> columnMappings; // key = child column index in the spreadsheet, value = column index in the vector of new colums
3256 QMap<int, int> rowMappings; // key = child column index in the spreadsheet, value = last row index
3257 for (const auto& index : indexes) {
3258 int col = index.column();
3259 int row = index.row();
3260 const auto* sourceColumn = children.at(col);
3261
3262 if (columnMappings.contains(col))
3263 targetColumn = columns.at(columnMappings[col]);
3264 else {
3265 targetColumn = new Column(i18n("Selection in %1", sourceColumn->name()), sourceColumn->columnMode());
3266 columns << targetColumn;
3267 columnMappings[col] = columns.count() - 1;
3268 rowMappings[col] = 0;
3269 }
3270
3271 int targetRow = rowMappings[col];
3272
3273 switch (targetColumn->columnMode()) {
3274 case AbstractColumn::ColumnMode::Double:
3275 targetColumn->setValueAt(targetRow, sourceColumn->valueAt(row));
3276 break;
3277 case AbstractColumn::ColumnMode::Integer:
3278 targetColumn->setIntegerAt(targetRow, sourceColumn->integerAt(row));
3279 break;
3280 case AbstractColumn::ColumnMode::BigInt:
3281 targetColumn->setBigIntAt(targetRow, sourceColumn->bigIntAt(row));
3282 break;
3283 case AbstractColumn::ColumnMode::Text:
3284 targetColumn->setTextAt(targetRow, sourceColumn->textAt(row));
3285 break;
3286 case AbstractColumn::ColumnMode::DateTime:
3287 case AbstractColumn::ColumnMode::Month:
3288 case AbstractColumn::ColumnMode::Day:
3289 targetColumn->setDateTimeAt(targetRow, sourceColumn->dateTimeAt(row));
3290 break;

Callers

nothing calls this directly

Calls 15

selectionModelMethod · 0.80
showMethod · 0.80
nameMethod · 0.45
sizeMethod · 0.45
columnCountMethod · 0.45
columnMethod · 0.45
hasValuesMethod · 0.45
isEmptyMethod · 0.45
rowMethod · 0.45
containsMethod · 0.45
columnModeMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected