From 3cf97b3f376ab96a86636bf7444632f9654b97f0 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 26 Sep 2017 20:08:02 +0200 Subject: [PATCH] Ref T163, using settings descriptions * renamed to getUnsavedSettingsKeys * no private slots in close dialog * use descriptions instead of keys --- src/blackcore/application.cpp | 20 +++++------- src/blackcore/application.h | 3 +- .../components/applicationclosedialog.cpp | 31 +++++++++++-------- .../components/applicationclosedialog.h | 23 +++++++------- 4 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index 3d8e8e7f1..6b3b84209 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -538,7 +538,7 @@ namespace BlackCore bool CApplication::hasUnsavedSettings() const { - return !this->getAllUnsavedSettings().isEmpty(); + return !this->getUnsavedSettingsKeys().isEmpty(); } void CApplication::setSettingsAutoSave(bool autoSave) @@ -546,23 +546,19 @@ namespace BlackCore m_autoSaveSettings = autoSave; } - QStringList CApplication::getAllUnsavedSettings() const + QStringList CApplication::getUnsavedSettingsKeys() const { - if (this->supportsContexts()) - { - return this->getIContextApplication()->getUnsavedSettingsKeys(); - } - return {}; + return this->supportsContexts() ? + this->getIContextApplication()->getUnsavedSettingsKeys() : + CSettingsCache::instance()->getAllUnsavedKeys(); } CStatusMessage CApplication::saveSettingsByKey(const QStringList &keys) { if (keys.isEmpty()) { return CStatusMessage(); } - if (this->supportsContexts()) - { - return this->getIContextApplication()->saveSettingsByKey(keys); - } - return CSettingsCache::instance()->saveToStore(keys); + return this->supportsContexts() ? + this->getIContextApplication()->saveSettingsByKey(keys) : + CSettingsCache::instance()->saveToStore(keys); } QString CApplication::getTemporaryDirectory() const diff --git a/src/blackcore/application.h b/src/blackcore/application.h index b1c68c5f0..2131ffa96 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -197,6 +197,7 @@ namespace BlackCore BlackMisc::CStatusMessageList requestReloadOfSetupAndVersion(); //! Web data services available? + //! \threadsafe bool hasWebDataServices() const; //! Get the web data services @@ -234,7 +235,7 @@ namespace BlackCore void setSettingsAutoSave(bool autoSave); //! All unsaved settings - QStringList getAllUnsavedSettings() const; + QStringList getUnsavedSettingsKeys() const; //! Save all settings BlackMisc::CStatusMessage saveSettingsByKey(const QStringList &keys); diff --git a/src/blackgui/components/applicationclosedialog.cpp b/src/blackgui/components/applicationclosedialog.cpp index 42db044fb..7bacc06b6 100644 --- a/src/blackgui/components/applicationclosedialog.cpp +++ b/src/blackgui/components/applicationclosedialog.cpp @@ -21,6 +21,7 @@ using namespace BlackMisc; using namespace BlackGui; +using namespace BlackCore::Context; namespace BlackGui { @@ -35,35 +36,37 @@ namespace BlackGui this->initSettingsView(); ui->bb_ApplicationCloseDialog->button(QDialogButtonBox::Save)->setDefault(true); - connect(this, &CApplicationCloseDialog::accepted, this, &CApplicationCloseDialog::ps_onAccepted); - connect(this, &CApplicationCloseDialog::rejected, this, &CApplicationCloseDialog::ps_onRejected); - connect(ui->bb_ApplicationCloseDialog, &QDialogButtonBox::clicked, this, &CApplicationCloseDialog::ps_buttonClicked); + connect(this, &CApplicationCloseDialog::accepted, this, &CApplicationCloseDialog::onAccepted); + connect(this, &CApplicationCloseDialog::rejected, this, &CApplicationCloseDialog::onRejected); + connect(ui->bb_ApplicationCloseDialog, &QDialogButtonBox::clicked, this, &CApplicationCloseDialog::buttonClicked); } CApplicationCloseDialog::~CApplicationCloseDialog() { } - void CApplicationCloseDialog::ps_onAccepted() + void CApplicationCloseDialog::onAccepted() { const QModelIndexList indexes = ui->lv_UnsavedSettings->selectionModel()->selectedIndexes(); if (indexes.isEmpty()) { return; } - const QList rows = CGuiUtility::indexToUniqueRows(indexes); QStringList saveKeys; + const QList rows = CGuiUtility::indexToUniqueRows(indexes); for (int r : rows) { - const QString key = this->m_settingskeys.at(r); - saveKeys.append(key); + const QString description = m_settingsDescriptions[r]; + const QString key = m_settingsDictionary.key(description); + if (!key.isEmpty()) { saveKeys.append(description); } } + if (saveKeys.isEmpty()) { return; } CStatusMessage msg = sApp->saveSettingsByKey(saveKeys); if (msg.isFailure()) { CLogMessage::preformatted(msg); } } - void CApplicationCloseDialog::ps_onRejected() + void CApplicationCloseDialog::onRejected() { // void } - void CApplicationCloseDialog::ps_buttonClicked(QAbstractButton *button) + void CApplicationCloseDialog::buttonClicked(QAbstractButton *button) { if (button == ui->bb_ApplicationCloseDialog->button(QDialogButtonBox::Discard)) { @@ -74,13 +77,15 @@ namespace BlackGui void CApplicationCloseDialog::initSettingsView() { - QStringList settings(sApp->getIContextApplication()->getUnsavedSettingsKeys()); - settings.sort(); - QStringListModel *model = new QStringListModel(settings, this); + const CSettingsDictionary settingsDictionary(sApp->getIContextApplication()->getUnsavedSettingsKeysDescribed()); + QStringList descriptions = settingsDictionary.values(); + descriptions.sort(); + QStringListModel *model = new QStringListModel(descriptions, this); ui->lv_UnsavedSettings->setModel(model); ui->lv_UnsavedSettings->selectAll(); - this->m_settingskeys = settings; + m_settingsDictionary = settingsDictionary; + m_settingsDescriptions = descriptions; } } // ns } // ns diff --git a/src/blackgui/components/applicationclosedialog.h b/src/blackgui/components/applicationclosedialog.h index 1898c2838..e74f2c4da 100644 --- a/src/blackgui/components/applicationclosedialog.h +++ b/src/blackgui/components/applicationclosedialog.h @@ -15,6 +15,7 @@ #include #include #include +#include "blackcore/context/contextapplication.h" namespace Ui { class CApplicationCloseDialog; } namespace BlackGui @@ -35,19 +36,19 @@ namespace BlackGui //! Destructor virtual ~CApplicationCloseDialog(); - private slots: - //! Accepted - void ps_onAccepted(); - - //! Rejected - void ps_onRejected(); - - //! Button pressed - void ps_buttonClicked(QAbstractButton *button); - private: QScopedPointer ui; - QStringList m_settingskeys; + QStringList m_settingsDescriptions; //!< values as displayed + BlackCore::Context::CSettingsDictionary m_settingsDictionary; //!< values and descriptions, unsorted + + //! Accepted + void onAccepted(); + + //! Rejected + void onRejected(); + + //! Button pressed + void buttonClicked(QAbstractButton *button); //! Init the settings view void initSettingsView();