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