Show info in status bar when a selection is made in Data Browser

When a selection is made in the Data Browser, the status bar shows:
number of rows, number of columns, sum and average of numeric values (other
data types count as 0) in the selection.

For avoiding expensive computations when the selection is very big
(selecting all cells or an entire column) the threshold setting for the
completion is reused.

This was inspired by #1791, but does not implement the proposed feature.
This commit is contained in:
mgrojo
2019-03-24 21:08:29 +01:00
committed by Martin Kleusberg
parent 5de6adeb42
commit 4d5e841813
2 changed files with 19 additions and 3 deletions
+14
View File
@@ -721,6 +721,20 @@ void MainWindow::populateTable()
connect(ui->dataTable->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(dataTableSelectionChanged(QModelIndex)));
connect(ui->dataTable->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection&, const QItemSelection&) {
updateInsertDeleteRecordButton();
const QModelIndexList& sel = ui->dataTable->selectionModel()->selectedIndexes();
if (sel.count() > 1 && sel.count() < Settings::getValue("databrowser", "complete_threshold").toInt()) {
int rows = sel.last().row() - sel.first().row() + 1;
int columns = sel.last().column() - sel.first().column() + 1;
double sum = 0;
for (const QModelIndex& index : sel) {
QVariant data = m_browseTableModel->data(index, Qt::EditRole);
sum += data.toDouble();
}
ui->statusbar->showMessage(QString("%1 rows, %2 columns. Sum: %3. Average: %4").arg(rows).arg(columns).arg(sum).
arg(sum/sel.count()));
} else
ui->statusbar->showMessage(QString());
});
}
// Search stored table settings for this table
+5 -3
View File
@@ -794,8 +794,10 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>This is the maximum number of rows in a table for enabling the value completion based on current values in the column.
Can be set to 0 for disabling completion.</string>
<string>This is the maximum number of items allowed for some computationally expensive functionalities to be enabled:
Maximum number of rows in a table for enabling the value completion based on current values in the column.
Maximum number of indexes in a selection for calculating sum and average.
Can be set to 0 for disabling the functionalities.</string>
</property>
<property name="whatsThis">
<string>This is the maximum number of rows in a table for enabling the value completion based on current values in the column.
@@ -812,7 +814,7 @@ Can be set to 0 for disabling completion.</string>
<item row="1" column="0">
<widget class="QLabel" name="labelCompleteThreshold">
<property name="text">
<string>Row count threshold for completion</string>
<string>Threshold for completion and calculation on selection</string>
</property>
<property name="buddy">
<cstring>spinCompleteThreshold</cstring>