Commit 59c8b933 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Modified IOptionsPage interface for Apply button

The previous interface wasn't sufficient to properly support the Apply
button, since it didn't separate applying the changes from the cleanup
phase.

Designer settings pages still need some fixing.

Fixes Apply button causing problems for certain plugins, for example the
QuickOpen.
parent e6f7cb68
......@@ -54,7 +54,8 @@ public:
virtual QString trCategory() const = 0;
virtual QWidget *createPage(QWidget *parent) = 0;
virtual void finished(bool accepted) = 0;
virtual void apply() = 0;
virtual void finish() = 0;
};
} // namespace Core
......
......@@ -126,20 +126,22 @@ void SettingsDialog::pageSelected(QTreeWidgetItem *)
void SettingsDialog::accept()
{
foreach (IOptionsPage *page, m_pages)
page->finished(true);
foreach (IOptionsPage *page, m_pages) {
page->apply();
page->finish();
}
done(QDialog::Accepted);
}
void SettingsDialog::reject()
{
foreach (IOptionsPage *page, m_pages)
page->finished(false);
page->finish();
done(QDialog::Rejected);
}
void SettingsDialog::apply()
{
foreach (IOptionsPage *page, m_pages)
page->finished(true);
page->apply();
}
......@@ -120,14 +120,14 @@ QWidget *ShortcutSettings::createPage(QWidget *parent)
return w;
}
void ShortcutSettings::finished(bool accepted)
void ShortcutSettings::apply()
{
if (accepted) {
foreach (ShortcutItem *item, m_scitems) {
item->m_cmd->setKeySequence(item->m_key);
}
}
foreach (ShortcutItem *item, m_scitems)
item->m_cmd->setKeySequence(item->m_key);
}
void ShortcutSettings::finish()
{
qDeleteAll(m_scitems);
m_scitems.clear();
}
......
......@@ -77,7 +77,8 @@ public:
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void finished(bool accepted);
void apply();
void finish();
protected:
bool eventFilter(QObject *o, QEvent *e);
......
......@@ -81,11 +81,8 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
return w;
}
void GeneralSettings::finished(bool accepted)
void GeneralSettings::apply()
{
if (!accepted)
return;
// Apply the new base color if accepted
StyleHelper::setBaseColor(m_page->colorButton->color());
EditorManager::instance()->setExternalEditor(m_page->externalEditorEdit->text());
......
......@@ -55,7 +55,8 @@ public:
QString category() const;
QString trCategory() const;
QWidget* createPage(QWidget *parent);
void finished(bool accepted);
void apply();
void finish() { }
private slots:
void resetInterfaceColor();
......
......@@ -86,11 +86,8 @@ QWidget *SettingsPage::createPage(QWidget *parent)
return w;
}
void SettingsPage::finished(bool accepted)
void SettingsPage::apply()
{
if (!accepted)
return;
m_username = m_ui.userEdit->text();
m_server = QUrl(m_ui.serverEdit->text());
m_copy = m_ui.clipboardBox->isChecked();
......
......@@ -59,7 +59,8 @@ public:
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void finished(bool accepted);
void apply();
void finish() { }
QString username() const;
QUrl serverUrl() const;
......
......@@ -78,11 +78,8 @@ QWidget *CompletionSettingsPage::createPage(QWidget *parent)
return w;
}
void CompletionSettingsPage::finished(bool accepted)
void CompletionSettingsPage::apply()
{
if (!accepted)
return;
m_completion->setCaseSensitivity(
m_page->caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);
m_completion->setAutoInsertBraces(m_page->autoInsertBraces->isChecked());
......
......@@ -56,7 +56,8 @@ public:
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void finished(bool accepted);
void apply();
void finish() { }
private:
CppCodeCompletion *m_completion;
......
......@@ -122,11 +122,8 @@ void GdbOptionPage::onScriptFileChanged()
m_settings->m_scriptFile = m_ui.scriptFileChooser->path();
}
void GdbOptionPage::finished(bool accepted)
void GdbOptionPage::apply()
{
if (!accepted)
return;
m_settings->m_gdbCmd = m_ui.gdbLocationChooser->path();
m_settings->m_gdbEnv = m_ui.environmentEdit->text();
m_settings->m_autoRun = m_ui.autoStartBox->isChecked();
......
......@@ -59,7 +59,8 @@ public:
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void finished(bool accepted);
void apply();
void finish() { }
public slots:
void onGdbLocationChanged();
......
......@@ -39,7 +39,8 @@
using namespace Designer::Internal;
SettingsPage::SettingsPage(QDesignerOptionsPageInterface *designerPage) :
m_designerPage(designerPage)
m_designerPage(designerPage),
m_applyOnFinish(false)
{
}
......@@ -64,10 +65,17 @@ QString SettingsPage::trCategory() const
QWidget *SettingsPage::createPage(QWidget *parent)
{
m_applyOnFinish = false;
return m_designerPage->createPage(parent);
}
void SettingsPage::finished(bool accepted)
void SettingsPage::apply()
{
m_designerPage->finish(accepted);
// FIXME: Since no cleanup should be done here, we can't call finish(true)
m_applyOnFinish = true;
}
void SettingsPage::finish()
{
m_designerPage->finish(m_applyOnFinish);
}
......@@ -59,10 +59,12 @@ public:
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void finished(bool accepted);
void apply();
void finish();
private:
QDesignerOptionsPageInterface *m_designerPage;
bool m_applyOnFinish;
};
} // namespace Internal
......
......@@ -95,11 +95,10 @@ QWidget *SettingsPage::createPage(QWidget *parent)
return m_widget;
}
void SettingsPage::finished(bool accepted)
void SettingsPage::apply()
{
if (!accepted || !m_widget)
if (!m_widget)
return;
GitPlugin::instance()->setSettings(m_widget->settings());
}
......@@ -77,7 +77,8 @@ public:
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void finished(bool accepted);
void apply();
void finish() { }
private:
QPointer<SettingsPageWidget> m_widget;
......
......@@ -38,7 +38,7 @@
#include <QtHelp/QHelpEngine>
using namespace Help::Internal;
DocSettingsPage::DocSettingsPage(QHelpEngine *helpEngine)
: m_helpEngine(helpEngine),
m_registeredDocs(false)
......@@ -64,16 +64,16 @@ QWidget *DocSettingsPage::createPage(QWidget *parent)
{
QWidget *w = new QWidget(parent);
m_ui.setupUi(w);
connect(m_ui.addButton, SIGNAL(clicked()),
this, SLOT(addDocumentation()));
connect(m_ui.removeButton, SIGNAL(clicked()),
this, SLOT(removeDocumentation()));
m_ui.docsListWidget->addItems(m_helpEngine->registeredDocumentations());
m_registeredDocs = false;
m_removeDocs.clear();
return w;
}
......@@ -82,7 +82,7 @@ void DocSettingsPage::addDocumentation()
QStringList files = QFileDialog::getOpenFileNames(m_ui.addButton->parentWidget(),
tr("Add Documentation"),
QString(), tr("Qt Help Files (*.qch)"));
if (files.isEmpty())
return;
......@@ -107,23 +107,20 @@ void DocSettingsPage::removeDocumentation()
QListWidgetItem *item = m_ui.docsListWidget->currentItem();
if (!item)
return;
m_removeDocs.append(item->text());
int row = m_ui.docsListWidget->currentRow();
m_ui.docsListWidget->takeItem(row);
m_ui.docsListWidget->takeItem(row);
if (row > 0)
--row;
if (m_ui.docsListWidget->count())
m_ui.docsListWidget->setCurrentRow(row);
delete item;
delete item;
}
void DocSettingsPage::finished(bool accepted)
void DocSettingsPage::apply()
{
if (!accepted)
return;
emit dialogAccepted();
}
......
......@@ -57,7 +57,8 @@ public:
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void finished(bool accepted);
void apply();
void finish() { }
bool applyChanges();
......
......@@ -173,8 +173,10 @@ void FilterSettingsPage::removeFilter()
m_ui.filterWidget->setCurrentRow(0);
}
void FilterSettingsPage::finished(bool)
void FilterSettingsPage::apply()
{
// This is handled via HelpPlugin::checkForHelpChanges, which is connected
// to DocSettingsPage::apply.
}
bool FilterSettingsPage::applyChanges()
......
......@@ -56,7 +56,8 @@ public:
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void finished(bool accepted);
void apply();
void finish() { }
bool applyChanges();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment