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;
|
pages_[id] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::Save() {
|
|
||||||
for (const PageData& data : pages_.values()) {
|
|
||||||
data.page_->Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsDialog::accept() {
|
void SettingsDialog::accept() {
|
||||||
Save();
|
for (const PageData& data : pages_.values()) {
|
||||||
|
data.page_->Accept();
|
||||||
|
}
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::reject() {
|
void SettingsDialog::reject() {
|
||||||
// Notify each page that user clicks on Cancel
|
// Notify each page that user clicks on Cancel
|
||||||
for (const PageData& data : pages_.values()) {
|
for (const PageData& data : pages_.values()) {
|
||||||
data.page_->Cancel();
|
data.page_->Reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
QDialog::reject();
|
QDialog::reject();
|
||||||
|
@ -292,7 +288,9 @@ void SettingsDialog::reject() {
|
||||||
void SettingsDialog::DialogButtonClicked(QAbstractButton* button) {
|
void SettingsDialog::DialogButtonClicked(QAbstractButton* button) {
|
||||||
// While we only connect Apply at the moment, this might change in the future
|
// While we only connect Apply at the moment, this might change in the future
|
||||||
if (ui_->buttonBox->button(QDialogButtonBox::Apply) == button) {
|
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);
|
QTreeWidgetItem* AddCategory(const QString& name);
|
||||||
void AddPage(Page id, SettingsPage* page, QTreeWidgetItem* parent = nullptr);
|
void AddPage(Page id, SettingsPage* page, QTreeWidgetItem* parent = nullptr);
|
||||||
|
|
||||||
void Save();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Application* app_;
|
Application* app_;
|
||||||
LibraryDirectoryModel* model_;
|
LibraryDirectoryModel* model_;
|
||||||
|
|
|
@ -20,3 +20,15 @@
|
||||||
|
|
||||||
SettingsPage::SettingsPage(SettingsDialog* dialog)
|
SettingsPage::SettingsPage(SettingsDialog* dialog)
|
||||||
: QWidget(dialog), dialog_(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.
|
// Return false to grey out the page's item in the list.
|
||||||
virtual bool IsEnabled() const { return true; }
|
virtual bool IsEnabled() const { return true; }
|
||||||
|
|
||||||
// Load is called when the dialog is shown, Save when the user clicks OK, and
|
// Called when the dialog is shown.
|
||||||
// Cancel when the user clicks on Cancel
|
|
||||||
virtual void Load() = 0;
|
virtual void Load() = 0;
|
||||||
virtual void Save() = 0;
|
// Called when Apply is selected.
|
||||||
virtual void Cancel() {}
|
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.
|
// The dialog that this page belongs to.
|
||||||
SettingsDialog* dialog() const { return dialog_; }
|
SettingsDialog* dialog() const { return dialog_; }
|
||||||
|
@ -47,6 +50,9 @@ signals:
|
||||||
void SetWiimotedevInterfaceActived(bool);
|
void SetWiimotedevInterfaceActived(bool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void Save() = 0;
|
||||||
|
virtual void Cancel() {}
|
||||||
|
|
||||||
SettingsDialog* dialog_;
|
SettingsDialog* dialog_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue