settings: Add dialog methods to settings pages

Add Accept, Apply, Reject methods to settings pages to mirror dialog. This will
allow settings pages to handle these events at a more granular level and will
allow common behavor in the base class.
This commit is contained in:
Jim Broadus 2020-05-11 21:04:44 -07:00 committed by John Maguire
parent be144d4611
commit 77badd37ff
4 changed files with 29 additions and 15 deletions

View File

@ -269,21 +269,17 @@ void SettingsDialog::AddPage(Page id, SettingsPage* page,
pages_[id] = data;
}
void SettingsDialog::Save() {
for (const PageData& data : pages_.values()) {
data.page_->Save();
}
}
void SettingsDialog::accept() {
Save();
for (const PageData& data : pages_.values()) {
data.page_->Accept();
}
QDialog::accept();
}
void SettingsDialog::reject() {
// Notify each page that user clicks on Cancel
for (const PageData& data : pages_.values()) {
data.page_->Cancel();
data.page_->Reject();
}
QDialog::reject();
@ -292,7 +288,9 @@ void SettingsDialog::reject() {
void SettingsDialog::DialogButtonClicked(QAbstractButton* button) {
// While we only connect Apply at the moment, this might change in the future
if (ui_->buttonBox->button(QDialogButtonBox::Apply) == button) {
Save();
for (const PageData& data : pages_.values()) {
data.page_->Apply();
}
}
}

View File

@ -133,8 +133,6 @@ class SettingsDialog : public QDialog {
QTreeWidgetItem* AddCategory(const QString& name);
void AddPage(Page id, SettingsPage* page, QTreeWidgetItem* parent = nullptr);
void Save();
private:
Application* app_;
LibraryDirectoryModel* model_;

View File

@ -20,3 +20,15 @@
SettingsPage::SettingsPage(SettingsDialog* dialog)
: QWidget(dialog), dialog_(dialog) {}
void SettingsPage::Apply() {
Save();
}
void SettingsPage::Accept() {
Save();
}
void SettingsPage::Reject() {
Cancel();
}

View File

@ -33,11 +33,14 @@ class SettingsPage : public QWidget {
// Return false to grey out the page's item in the list.
virtual bool IsEnabled() const { return true; }
// Load is called when the dialog is shown, Save when the user clicks OK, and
// Cancel when the user clicks on Cancel
// Called when the dialog is shown.
virtual void Load() = 0;
virtual void Save() = 0;
virtual void Cancel() {}
// Called when Apply is selected.
virtual void Apply();
// Called when OK is selected.
virtual void Accept();
// Called when Cancel is selected.
virtual void Reject();
// The dialog that this page belongs to.
SettingsDialog* dialog() const { return dialog_; }
@ -47,6 +50,9 @@ signals:
void SetWiimotedevInterfaceActived(bool);
private:
virtual void Save() = 0;
virtual void Cancel() {}
SettingsDialog* dialog_;
};