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:
parent
be144d4611
commit
77badd37ff
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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_;
|
||||
|
|
|
@ -20,3 +20,15 @@
|
|||
|
||||
SettingsPage::SettingsPage(SettingsDialog* dialog)
|
||||
: QWidget(dialog), dialog_(dialog) {}
|
||||
|
||||
void SettingsPage::Apply() {
|
||||
Save();
|
||||
}
|
||||
|
||||
void SettingsPage::Accept() {
|
||||
Save();
|
||||
}
|
||||
|
||||
void SettingsPage::Reject() {
|
||||
Cancel();
|
||||
}
|
||||
|
|
|
@ -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_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue