mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
Ref T163, using settings descriptions
* renamed to getUnsavedSettingsKeys * no private slots in close dialog * use descriptions instead of keys
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<int> rows = CGuiUtility::indexToUniqueRows(indexes);
|
||||
QStringList saveKeys;
|
||||
const QList<int> 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
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <QDialog>
|
||||
#include <QScopedPointer>
|
||||
#include <QAbstractButton>
|
||||
#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::CApplicationCloseDialog> 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();
|
||||
|
||||
Reference in New Issue
Block a user