summaryrefslogtreecommitdiff
path: root/src/plugins/coreplugin/dialogs/ioptionspage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/coreplugin/dialogs/ioptionspage.cpp')
-rw-r--r--src/plugins/coreplugin/dialogs/ioptionspage.cpp86
1 files changed, 58 insertions, 28 deletions
diff --git a/src/plugins/coreplugin/dialogs/ioptionspage.cpp b/src/plugins/coreplugin/dialogs/ioptionspage.cpp
index a3a0f7eb38..6f03c23668 100644
--- a/src/plugins/coreplugin/dialogs/ioptionspage.cpp
+++ b/src/plugins/coreplugin/dialogs/ioptionspage.cpp
@@ -28,8 +28,11 @@
#include "ioptionspage.h"
-#include <utils/stringutils.h>
+#include <coreplugin/icore.h>
+
+#include <utils/aspects.h>
#include <utils/qtcassert.h>
+#include <utils/stringutils.h>
#include <QCheckBox>
#include <QGroupBox>
@@ -40,6 +43,8 @@
using namespace Utils;
+namespace Core {
+
/*!
\class Core::IOptionsPageProvider
\inmodule QtCreator
@@ -94,7 +99,7 @@ using namespace Utils;
Returns the category icon of the options page. This icon is displayed in the list on the left
side of the \uicontrol Options dialog.
*/
-QIcon Core::IOptionsPage::categoryIcon() const
+QIcon IOptionsPage::categoryIcon() const
{
return m_categoryIcon.icon();
}
@@ -103,7 +108,7 @@ QIcon Core::IOptionsPage::categoryIcon() const
Sets the \a widgetCreator callback to create page widgets on demand. The
widget will be destroyed on finish().
*/
-void Core::IOptionsPage::setWidgetCreator(const WidgetCreator &widgetCreator)
+void IOptionsPage::setWidgetCreator(const WidgetCreator &widgetCreator)
{
m_widgetCreator = widgetCreator;
}
@@ -119,11 +124,18 @@ void Core::IOptionsPage::setWidgetCreator(const WidgetCreator &widgetCreator)
Either override this function in a derived class, or set a widget creator.
*/
-QWidget *Core::IOptionsPage::widget()
+QWidget *IOptionsPage::widget()
{
- QTC_ASSERT(m_widgetCreator, return nullptr);
- if (!m_widget)
- m_widget = m_widgetCreator();
+ if (!m_widget) {
+ if (m_widgetCreator) {
+ m_widget = m_widgetCreator();
+ } else if (m_layouter) {
+ m_widget = new QWidget;
+ m_layouter(m_widget);
+ } else {
+ QTC_CHECK(false);
+ }
+ }
return m_widget;
}
@@ -136,11 +148,16 @@ QWidget *Core::IOptionsPage::widget()
\sa setWidgetCreator()
*/
-void Core::IOptionsPage::apply()
+void IOptionsPage::apply()
{
- QTC_ASSERT(m_widgetCreator, return);
- if (m_widget)
- m_widget->apply();
+ if (auto widget = qobject_cast<IOptionsPageWidget *>(m_widget)) {
+ widget->apply();
+ } else if (m_settings) {
+ if (m_settings->isDirty()) {
+ m_settings->apply();
+ m_settings->writeSettings(ICore::settings());
+ }
+ }
}
/*!
@@ -152,24 +169,35 @@ void Core::IOptionsPage::apply()
\sa setWidgetCreator()
*/
-void Core::IOptionsPage::finish()
+void IOptionsPage::finish()
{
- QTC_ASSERT(m_widgetCreator, return);
- if (m_widget) {
- m_widget->finish();
- delete m_widget;
- }
+ if (auto widget = qobject_cast<IOptionsPageWidget *>(m_widget))
+ widget->finish();
+ else if (m_settings)
+ m_settings->finish();
+
+ delete m_widget;
}
/*!
Sets \a categoryIconPath as the path to the category icon of the options
page.
*/
-void Core::IOptionsPage::setCategoryIconPath(const QString &categoryIconPath)
+void IOptionsPage::setCategoryIconPath(const QString &categoryIconPath)
{
m_categoryIcon = Icon({{categoryIconPath, Theme::PanelTextColorDark}}, Icon::Tint);
}
+void IOptionsPage::setSettings(AspectContainer *settings)
+{
+ m_settings = settings;
+}
+
+void IOptionsPage::setLayouter(const std::function<void(QWidget *w)> &layouter)
+{
+ m_layouter = layouter;
+}
+
/*!
\fn void Core::IOptionsPage::setId(Utils::Id id)
@@ -200,13 +228,13 @@ void Core::IOptionsPage::setCategoryIconPath(const QString &categoryIconPath)
Sets \a categoryIcon as the category icon of the options page.
*/
-static QList<Core::IOptionsPage *> g_optionsPages;
+static QList<IOptionsPage *> g_optionsPages;
/*!
Constructs an options page with the given \a parent and registers it
at the global options page pool if \a registerGlobally is \c true.
*/
-Core::IOptionsPage::IOptionsPage(QObject *parent, bool registerGlobally)
+IOptionsPage::IOptionsPage(QObject *parent, bool registerGlobally)
: QObject(parent)
{
if (registerGlobally)
@@ -216,7 +244,7 @@ Core::IOptionsPage::IOptionsPage(QObject *parent, bool registerGlobally)
/*!
\internal
*/
-Core::IOptionsPage::~IOptionsPage()
+IOptionsPage::~IOptionsPage()
{
g_optionsPages.removeOne(this);
}
@@ -224,7 +252,7 @@ Core::IOptionsPage::~IOptionsPage()
/*!
Returns a list of all options pages.
*/
-const QList<Core::IOptionsPage *> Core::IOptionsPage::allOptionsPages()
+const QList<IOptionsPage *> IOptionsPage::allOptionsPages()
{
return g_optionsPages;
}
@@ -234,7 +262,7 @@ const QList<Core::IOptionsPage *> Core::IOptionsPage::allOptionsPages()
page. This defaults to take the widget and then looks for all child labels, check boxes, push
buttons, and group boxes. Should return \c true when a match is found.
*/
-bool Core::IOptionsPage::matches(const QRegularExpression &regexp) const
+bool IOptionsPage::matches(const QRegularExpression &regexp) const
{
if (!m_keywordsInitialized) {
auto that = const_cast<IOptionsPage *>(this);
@@ -259,25 +287,27 @@ bool Core::IOptionsPage::matches(const QRegularExpression &regexp) const
return false;
}
-static QList<Core::IOptionsPageProvider *> g_optionsPagesProviders;
+static QList<IOptionsPageProvider *> g_optionsPagesProviders;
-Core::IOptionsPageProvider::IOptionsPageProvider(QObject *parent)
+IOptionsPageProvider::IOptionsPageProvider(QObject *parent)
: QObject(parent)
{
g_optionsPagesProviders.append(this);
}
-Core::IOptionsPageProvider::~IOptionsPageProvider()
+IOptionsPageProvider::~IOptionsPageProvider()
{
g_optionsPagesProviders.removeOne(this);
}
-const QList<Core::IOptionsPageProvider *> Core::IOptionsPageProvider::allOptionsPagesProviders()
+const QList<IOptionsPageProvider *> IOptionsPageProvider::allOptionsPagesProviders()
{
return g_optionsPagesProviders;
}
-QIcon Core::IOptionsPageProvider::categoryIcon() const
+QIcon IOptionsPageProvider::categoryIcon() const
{
return m_categoryIcon.icon();
}
+
+} // Core