diff --git a/src/kdefrontend/spreadsheet/SortDialog.cpp b/src/kdefrontend/spreadsheet/SortDialog.cpp index 5dd8deec2..8693662c1 100644 --- a/src/kdefrontend/spreadsheet/SortDialog.cpp +++ b/src/kdefrontend/spreadsheet/SortDialog.cpp @@ -1,91 +1,110 @@ /*************************************************************************** File : SortDialog.h Project : LabPlot Description : Sorting options dialog -------------------------------------------------------------------- - Copyright : (C) 2011 by Alexander Semke (alexander.semke@web.de) + Copyright : (C) 2011-2018 by Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #include "SortDialog.h" #include +#include +#include +#include /*! \class SortDialog \brief Dialog for sorting the columns in a spreadsheet. \ingroup kdefrontend */ - -SortDialog::SortDialog( QWidget* parent ) : QDialog( parent ) { - +SortDialog::SortDialog(QWidget* parent) : QDialog(parent) { setWindowIcon(QIcon::fromTheme("view-sort-ascending")); setWindowTitle(i18nc("@title:window", "Sort Columns")); setSizeGripEnabled(true); setAttribute(Qt::WA_DeleteOnClose); ui.setupUi(this); ui.buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("Sort")); connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &SortDialog::sortColumns); connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &SortDialog::reject); connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &SortDialog::accept); + connect(ui.cbSorting, SIGNAL(currentIndexChanged(int)), this, SLOT(changeType(int))); + connect(ui.cbSorting, static_cast(&QComboBox::currentIndexChanged), + this, &SortDialog::changeType); + + //restore saved settings if available + KConfigGroup conf(KSharedConfig::openConfig(), QLatin1String("SortDialog")); + if (conf.exists()) + KWindowConfig::restoreWindowSize(windowHandle(), conf); + else + resize(QSize(300, 0).expandedTo(minimumSize())); + + ui.cbOrdering->setCurrentIndex(conf.readEntry(QLatin1String("Ordering"), 0)); + ui.cbSorting->setCurrentIndex(conf.readEntry(QLatin1String("Sorting"), 0)); +} - connect(ui.cbType, SIGNAL(currentIndexChanged(int)), this, SLOT(changeType(int))); +SortDialog::~SortDialog() { + //save the current settings + KConfigGroup conf(KSharedConfig::openConfig(), QLatin1String("SortDialog")); - resize(minimumSize()); + // general settings + conf.writeEntry(QLatin1String("Ordering"), ui.cbOrdering->currentIndex()); + conf.writeEntry(QLatin1String("Sorting"), ui.cbSorting->currentIndex()); } void SortDialog::sortColumns() { Column* leading; - if (ui.cbType->currentIndex() == Together) + if (ui.cbSorting->currentIndex() == Together) leading = m_columns.at(ui.cbColumns->currentIndex()); else leading = nullptr; emit sort(leading, m_columns, ui.cbOrdering->currentIndex() == Ascending); } void SortDialog::setColumns(QVector columns) { m_columns = columns; for (auto* col : m_columns) ui.cbColumns->addItem(col->name()); ui.cbColumns->setCurrentIndex(0); if (m_columns.size() == 1) { - ui.lType->hide(); - ui.cbType->hide(); + ui.lSorting->hide(); + ui.cbSorting->hide(); ui.lColumns->hide(); ui.cbColumns->hide(); } } void SortDialog::changeType(int Type) { if (Type == Together) ui.cbColumns->setEnabled(true); else ui.cbColumns->setEnabled(false); } diff --git a/src/kdefrontend/spreadsheet/SortDialog.h b/src/kdefrontend/spreadsheet/SortDialog.h index 8f701d278..ada60ba08 100644 --- a/src/kdefrontend/spreadsheet/SortDialog.h +++ b/src/kdefrontend/spreadsheet/SortDialog.h @@ -1,57 +1,59 @@ /*************************************************************************** File : SortDialog.h Project : LabPlot Description : Sorting options dialog -------------------------------------------------------------------- Copyright : (C) 2011 by Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef SORTDIALOG_H #define SORTDIALOG_H #include "backend/core/column/Column.h" #include #include class SortDialog : public QDialog { Q_OBJECT public: - explicit SortDialog( QWidget* parent = nullptr ); + explicit SortDialog(QWidget* parent = nullptr); + ~SortDialog() override; + void setColumns(QVector); enum { Separately=0, Together=1 }; enum { Ascending=0, Descending=1 }; private slots: void sortColumns(); void changeType(int index); signals: void sort(Column*, QVector, bool ascending); private: Ui::SortDialogWidget ui; QVector m_columns; }; #endif diff --git a/src/kdefrontend/ui/spreadsheet/sortdialogwidget.ui b/src/kdefrontend/ui/spreadsheet/sortdialogwidget.ui index b4e503308..39fa40a24 100644 --- a/src/kdefrontend/ui/spreadsheet/sortdialogwidget.ui +++ b/src/kdefrontend/ui/spreadsheet/sortdialogwidget.ui @@ -1,102 +1,123 @@ SortDialogWidget 0 0 - 258 - 147 + 448 + 237 - - - - - - - Order: - - - - - - - - Ascending - - - - .. - - - - - Descending - - - - .. - - - - - - - - Sort columns: - - + + + + + + 0 + 0 + + + + Order: + + + + + + + + 0 + 0 + + + + + Ascending + + + + .. + - - - - - Separately - - - - - Together - - - + + + Descending + + + + .. + - - - - Leading column: - - + + + + + + Sort columns: + + + + + + + + Separately + - - + + + Together + - + - + + + + Leading column: + + + + + + + Qt::Vertical 20 1 - + + + + Qt::Horizontal + + + + 209 + 20 + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok