Commit 40b12032 authored by Alexander Semke's avatar Alexander Semke

Don't block the UI when showing the statics for big columns in the

Statistics Dialog.
parent a38645da
......@@ -1481,7 +1481,6 @@ void MatrixView::exportToLaTeX(const QString& path, const bool verticalHeaders,
void MatrixView::showColumnStatistics() {
if (selectedColumnCount() > 0) {
QString dlgTitle (m_matrix->name() + " column statistics");
auto* dlg = new StatisticsDialog(dlgTitle);
QVector<Column*> columns;
for (int col = 0; col < m_matrix->columnCount(); ++col) {
if (isColumnSelected(col, false)) {
......@@ -1489,7 +1488,8 @@ void MatrixView::showColumnStatistics() {
columns << new Column(headerString, static_cast<QVector<QVector<double>>*>(m_matrix->data())->at(col));
}
}
dlg->setColumns(columns);
auto* dlg = new StatisticsDialog(dlgTitle, columns);
dlg->showStatistics();
if (dlg->exec() == QDialog::Accepted) {
qDeleteAll(columns);
columns.clear();
......@@ -1500,7 +1500,6 @@ void MatrixView::showColumnStatistics() {
void MatrixView::showRowStatistics() {
if (selectedRowCount() > 0) {
QString dlgTitle (m_matrix->name() + " row statistics");
auto* dlg = new StatisticsDialog(dlgTitle);
QVector<Column*> columns;
for (int row = 0; row < m_matrix->rowCount(); ++row) {
if (isRowSelected(row, false)) {
......@@ -1509,7 +1508,8 @@ void MatrixView::showRowStatistics() {
columns << new Column(headerString, m_matrix->rowCells<double>(row, 0, m_matrix->columnCount()-1));
}
}
dlg->setColumns(columns);
auto* dlg = new StatisticsDialog(dlgTitle, columns);
dlg->showStatistics();
if (dlg->exec() == QDialog::Accepted) {
qDeleteAll(columns);
columns.clear();
......
......@@ -83,6 +83,7 @@
#include <QSqlError>
#include <QSqlQuery>
#include <QTableView>
#include <QTimer>
#include <QToolBar>
#include <QTextStream>
#include <QProcess>
......@@ -2715,27 +2716,26 @@ void SpreadsheetView::showAllColumnsStatistics() {
void SpreadsheetView::showColumnStatistics(bool forAll) {
QString dlgTitle(m_spreadsheet->name() + " column statistics");
auto* dlg = new StatisticsDialog(dlgTitle);
QVector<Column*> columns;
if (!forAll)
dlg->setColumns(selectedColumns());
columns = selectedColumns();
else if (forAll) {
for (int col = 0; col < m_spreadsheet->columnCount(); ++col) {
if (m_spreadsheet->column(col)->columnMode() == AbstractColumn::ColumnMode::Numeric)
columns << m_spreadsheet->column(col);
}
dlg->setColumns(columns);
}
if (dlg->exec() == QDialog::Accepted) {
if (forAll)
columns.clear();
}
auto* dlg = new StatisticsDialog(dlgTitle, columns);
dlg->setModal(true);
dlg->show();
QApplication::processEvents(QEventLoop::AllEvents, 0);
QTimer::singleShot(0, this, [=] () {dlg->showStatistics();});
}
void SpreadsheetView::showRowStatistics() {
QString dlgTitle(m_spreadsheet->name() + " row statistics");
auto* dlg = new StatisticsDialog(dlgTitle);
QVector<Column*> columns;
for (int i = 0; i < m_spreadsheet->rowCount(); ++i) {
......@@ -2743,10 +2743,11 @@ void SpreadsheetView::showRowStatistics() {
QVector<double> rowValues;
for (int j = 0; j < m_spreadsheet->columnCount(); ++j)
rowValues << m_spreadsheet->column(j)->valueAt(i);
columns << new Column(QString::number(i+1), rowValues);
columns << new Column(i18n("Row %1").arg(i+1), rowValues);
}
}
dlg->setColumns(columns);
auto* dlg = new StatisticsDialog(dlgTitle, columns);
dlg->showStatistics();
if (dlg->exec() == QDialog::Accepted) {
qDeleteAll(columns);
......
......@@ -34,6 +34,7 @@
#include <QPushButton>
#include <QTabWidget>
#include <QTextEdit>
#include <QTimer>
#include <QVBoxLayout>
#include <QWindow>
......@@ -43,7 +44,7 @@
#include <cmath>
StatisticsDialog::StatisticsDialog(const QString& title, QWidget* parent) : QDialog(parent),
StatisticsDialog::StatisticsDialog(const QString& title, const QVector<Column*>& columns, QWidget* parent) : QDialog(parent),
m_twStatistics(new QTabWidget) {
QDialogButtonBox* btnBox = new QDialogButtonBox(QDialogButtonBox::Ok);
......@@ -215,6 +216,25 @@ StatisticsDialog::StatisticsDialog(const QString& title, QWidget* parent) : QDia
"</tr>"
"</table>");
m_columns = columns;
//create tab widgets for every column and show the initial text with the placeholders
if (!m_columns.isEmpty()) {
for (auto* col : m_columns) {
auto* textEdit = new QTextEdit(this);
textEdit->setReadOnly(true);
m_twStatistics->addTab(textEdit, col->name());
}
auto* const textEdit = static_cast<QTextEdit*>(m_twStatistics->currentWidget());
textEdit->setHtml(m_htmlText.arg(QLatin1String("-"), QLatin1String("-"), QLatin1String("-"), QLatin1String("-"),
QLatin1String("-"), QLatin1String("-"), QLatin1String("-"), QLatin1String("-"), QLatin1String("-")).
arg(QLatin1String("-"), QLatin1String("-"), QLatin1String("-"), QLatin1String("-"), QLatin1String("-"),
QLatin1String("-"), QLatin1String("-"), QLatin1String("-"), QLatin1String("-")).
arg(QLatin1String("-"), QLatin1String("-"), QLatin1String("-")));
}
connect(m_twStatistics, &QTabWidget::currentChanged, this, &StatisticsDialog::currentTabChanged);
//restore saved settings if available
......@@ -232,18 +252,9 @@ StatisticsDialog::~StatisticsDialog() {
KWindowConfig::saveWindowSize(windowHandle(), conf);
}
void StatisticsDialog::setColumns(const QVector<Column*>& columns) {
if (!columns.size())
return;
m_columns = columns;
for (auto* col : m_columns) {
auto* textEdit = new QTextEdit;
textEdit->setReadOnly(true);
m_twStatistics->addTab(textEdit, col->name());
}
currentTabChanged(0);
void StatisticsDialog::showStatistics() {
QApplication::processEvents(QEventLoop::AllEvents, 0);
QTimer::singleShot(0, this, [=] () {currentTabChanged(0);});
}
const QString StatisticsDialog::isNanValue(const double value) {
......@@ -275,11 +286,13 @@ QString modeValue(Column* column, double value) {
}
void StatisticsDialog::currentTabChanged(int index) {
auto* const textEdit = static_cast<QTextEdit*>(m_twStatistics->currentWidget());
if (!textEdit)
return;
WAIT_CURSOR;
const Column::ColumnStatistics& statistics = m_columns[index]->statistics();
RESET_CURSOR;
auto* const textEdit = static_cast<QTextEdit*>(m_twStatistics->currentWidget());
textEdit->setHtml(m_htmlText.arg(QString::number(statistics.size),
isNanValue(statistics.minimum == INFINITY ? NAN : statistics.minimum),
isNanValue(statistics.maximum == -INFINITY ? NAN : statistics.maximum),
......@@ -301,4 +314,5 @@ void StatisticsDialog::currentTabChanged(int index) {
arg(isNanValue(statistics.skewness),
isNanValue(statistics.kurtosis),
isNanValue(statistics.entropy)));
RESET_CURSOR;
}
......@@ -38,9 +38,9 @@ class StatisticsDialog : public QDialog {
Q_OBJECT
public:
explicit StatisticsDialog(const QString&, QWidget *parent = nullptr);
explicit StatisticsDialog(const QString&, const QVector<Column*>&, QWidget *parent = nullptr);
~StatisticsDialog() override;
void setColumns(const QVector<Column*>&);
void showStatistics();
private:
const QString isNanValue(const double);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment