added generic method to save state of dialogs
This commit is contained in:
parent
0e8dfbc397
commit
88c75da532
@ -15,6 +15,9 @@
|
||||
|
||||
FormBackupDatabaseSettings::FormBackupDatabaseSettings(QWidget* parent) : QDialog(parent), m_ui(new Ui::FormBackupDatabaseSettings) {
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setObjectName(QSL("form_backup_db_set"));
|
||||
|
||||
m_ui->m_txtBackupName->lineEdit()->setPlaceholderText(tr("Common name for backup files"));
|
||||
|
||||
GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("document-export")));
|
||||
@ -33,6 +36,9 @@ FormBackupDatabaseSettings::FormBackupDatabaseSettings(QWidget* parent) : QDialo
|
||||
if (qApp->database()->activeDatabaseDriver() != DatabaseDriver::DriverType::SQLite) {
|
||||
m_ui->m_checkBackupDatabase->setDisabled(true);
|
||||
}
|
||||
|
||||
GuiUtilities::restoreState(this,
|
||||
qApp->settings()->value(GROUP(GUI), objectName(), QByteArray()).toByteArray());
|
||||
}
|
||||
|
||||
FormBackupDatabaseSettings::~FormBackupDatabaseSettings() {
|
||||
@ -82,3 +88,10 @@ void FormBackupDatabaseSettings::checkOkButton() {
|
||||
(!m_ui->m_checkBackupDatabase->isChecked() &&
|
||||
!m_ui->m_checkBackupSettings->isChecked()));
|
||||
}
|
||||
|
||||
void FormBackupDatabaseSettings::hideEvent(QHideEvent* event) {
|
||||
QByteArray state = GuiUtilities::saveState(this);
|
||||
|
||||
qApp->settings()->setValue(GROUP(GUI), objectName(), state);
|
||||
QDialog::hideEvent(event);
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ class FormBackupDatabaseSettings : public QDialog {
|
||||
explicit FormBackupDatabaseSettings(QWidget* parent = nullptr);
|
||||
virtual ~FormBackupDatabaseSettings();
|
||||
|
||||
protected:
|
||||
virtual void hideEvent(QHideEvent* event);
|
||||
|
||||
private slots:
|
||||
void performBackup();
|
||||
void selectFolderInitial();
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "gui/dialogs/formdatabasecleanup.h"
|
||||
|
||||
#include "database/databasefactory.h"
|
||||
#include "definitions/definitions.h"
|
||||
#include "gui/guiutilities.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
@ -14,6 +15,8 @@
|
||||
FormDatabaseCleanup::FormDatabaseCleanup(QWidget* parent) : QDialog(parent), m_ui(new Ui::FormDatabaseCleanup), m_cleaner(nullptr) {
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setObjectName(QSL("form_db_cleanup"));
|
||||
|
||||
GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("edit-clear")));
|
||||
|
||||
connect(m_ui->m_spinDays, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &FormDatabaseCleanup::updateDaysSuffix);
|
||||
@ -27,6 +30,9 @@ FormDatabaseCleanup::FormDatabaseCleanup(QWidget* parent) : QDialog(parent), m_u
|
||||
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Information, tr("I am ready."), tr("I am ready."));
|
||||
|
||||
loadDatabaseInfo();
|
||||
|
||||
GuiUtilities::restoreState(this,
|
||||
qApp->settings()->value(GROUP(GUI), objectName(), QByteArray()).toByteArray());
|
||||
}
|
||||
|
||||
void FormDatabaseCleanup::closeEvent(QCloseEvent* event) {
|
||||
@ -99,3 +105,10 @@ void FormDatabaseCleanup::loadDatabaseInfo() {
|
||||
m_ui->m_txtFileSize->setText(data_size_str);
|
||||
m_ui->m_txtDatabaseType->setText(qApp->database()->driver()->humanDriverType());
|
||||
}
|
||||
|
||||
void FormDatabaseCleanup::hideEvent(QHideEvent* event) {
|
||||
QByteArray state = GuiUtilities::saveState(this);
|
||||
|
||||
qApp->settings()->setValue(GROUP(GUI), objectName(), state);
|
||||
QDialog::hideEvent(event);
|
||||
}
|
||||
|
@ -17,8 +17,9 @@ class FormDatabaseCleanup : public QDialog {
|
||||
virtual ~FormDatabaseCleanup() = default;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
virtual void closeEvent(QCloseEvent* event);
|
||||
virtual void hideEvent(QHideEvent* event);
|
||||
virtual void keyPressEvent(QKeyEvent* event);
|
||||
|
||||
private slots:
|
||||
void updateDaysSuffix(int number);
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
@ -50,3 +52,63 @@ void GuiUtilities::applyResponsiveDialogResize(QWidget& widget, double factor) {
|
||||
Q_UNUSED(widget)
|
||||
#endif
|
||||
}
|
||||
|
||||
void GuiUtilities::restoreState(QWidget* wdg, QByteArray state) {
|
||||
QHash<QString, QStringList> props_to_serialize {
|
||||
{ QSL("QCheckBox"), { QSL("checked") } },
|
||||
{ QSL("QSpinBox"), { QSL("value") } }
|
||||
};
|
||||
QHash<QString, QHash<QString, QVariant>> props;
|
||||
QDataStream str(&state, QIODevice::OpenModeFlag::ReadOnly);
|
||||
|
||||
str >> props;
|
||||
|
||||
QList<QObject*> to_process = { wdg };
|
||||
|
||||
while (!to_process.isEmpty()) {
|
||||
QObject* act = to_process.takeFirst();
|
||||
|
||||
if (props.contains(act->objectName())) {
|
||||
auto saved_props = props.value(act->objectName());
|
||||
auto saved_props_names = saved_props.keys();
|
||||
|
||||
for (const QString& saved_key : saved_props_names) {
|
||||
act->setProperty(saved_key.toLocal8Bit().constData(), saved_props.value(saved_key));
|
||||
}
|
||||
}
|
||||
|
||||
to_process.append(act->children());
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray GuiUtilities::saveState(QWidget* wdg) {
|
||||
QHash<QString, QStringList> props_to_serialize {
|
||||
{ QSL("QCheckBox"), { QSL("checked") } },
|
||||
{ QSL("QSpinBox"), { QSL("value") } }
|
||||
};
|
||||
QHash<QString, QHash<QString, QVariant>> props;
|
||||
QList<QObject*> to_process = { wdg };
|
||||
|
||||
while (!to_process.isEmpty()) {
|
||||
QObject* act = to_process.takeFirst();
|
||||
const QMetaObject* meta = act->metaObject();
|
||||
auto act_props = props_to_serialize.value(meta->className());
|
||||
QHash<QString, QVariant> props_obj;
|
||||
|
||||
for (const QString& prop : act_props) {
|
||||
props_obj.insert(prop, act->property(prop.toLocal8Bit().constData()));
|
||||
}
|
||||
|
||||
if (!props_obj.isEmpty()) {
|
||||
props.insert(act->objectName(), props_obj);
|
||||
}
|
||||
|
||||
to_process.append(act->children());
|
||||
}
|
||||
|
||||
QByteArray arr;
|
||||
QDataStream str(&arr, QIODevice::OpenModeFlag::WriteOnly);
|
||||
|
||||
str << props;
|
||||
return arr;
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ class GuiUtilities {
|
||||
static void setLabelAsNotice(QLabel& label, bool is_warning, bool set_margins = true);
|
||||
static void applyDialogProperties(QWidget& widget, const QIcon& icon = QIcon(), const QString& title = QString());
|
||||
static void applyResponsiveDialogResize(QWidget& widget, double factor = 0.6);
|
||||
static void restoreState(QWidget* wdg, QByteArray state);
|
||||
static QByteArray saveState(QWidget* wdg);
|
||||
|
||||
private:
|
||||
explicit GuiUtilities();
|
||||
|
Loading…
x
Reference in New Issue
Block a user