Add min & max in selection to the status bar and always show rows & columns

Now number of rows and columns is always showed, independent of the number
of cells threshold. Plural forms are used in translations (Spanish and
British English updated for testing).

Min and Max have also been added to the status bar message.
This commit is contained in:
mgrojo
2019-03-28 00:17:35 +01:00
committed by Martin Kleusberg
parent 4d5e841813
commit 25715bb590
3 changed files with 622 additions and 550 deletions

View File

@@ -62,6 +62,8 @@
#include <QOpenGLWidget>
#endif
#include <limits>
const int MainWindow::MaxRecentFiles;
// These are needed for reading and writing object files
@@ -723,18 +725,28 @@ void MainWindow::populateTable()
updateInsertDeleteRecordButton();
const QModelIndexList& sel = ui->dataTable->selectionModel()->selectedIndexes();
if (sel.count() > 1 && sel.count() < Settings::getValue("databrowser", "complete_threshold").toInt()) {
QString statusMessage;
if (sel.count() > 1) {
int rows = sel.last().row() - sel.first().row() + 1;
statusMessage = tr("%n row(s)", "", rows);
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();
statusMessage += tr(", %n column(s)", "", columns);
if (sel.count() < Settings::getValue("databrowser", "complete_threshold").toInt()) {
double sum = 0;
double first = m_browseTableModel->data(sel.first(), Qt::EditRole).toDouble();
double min = first;
double max = first;
for (const QModelIndex& index : sel) {
double data = m_browseTableModel->data(index, Qt::EditRole).toDouble();
sum += data;
min = std::min(min, data);
max = std::max(max, data);
}
statusMessage += tr(". Sum: %1; Average: %2; Min: %3; Max: %4").arg(sum).arg(sum/sel.count()).arg(min).arg(max);
}
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());
};
ui->statusbar->showMessage(statusMessage);
});
}
// Search stored table settings for this table

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff