diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-11-08 14:39:17 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-11-08 17:58:49 +0000 |
commit | 08b780205a91aef12141cc0650a6197794f09e00 (patch) | |
tree | 32b72ec5ccb9fd077c09f71b3a04ce36d48395be /src/plugins | |
parent | 062512a246279b632a93db544445a447d8cf2633 (diff) | |
download | qt-creator-08b780205a91aef12141cc0650a6197794f09e00.tar.gz |
Theme: Use QVariantMap for theme properties
QML can directly mirror this into a JavaScript object, so there is no
need to manually copy the values into a different container. Also,
QQmlPropertyMap is very expensive as it will listen to changes to any
value in the map. We never use this. It would be entirely enough to
update the whole map at once if we ever want to update the theme at
runtime.
Change-Id: Ie2b549e9af51d620801808c87d6f659cc7a06c04
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@theqtcompany.com>
Diffstat (limited to 'src/plugins')
9 files changed, 19 insertions, 33 deletions
diff --git a/src/plugins/qmldesigner/components/componentcore/theming.cpp b/src/plugins/qmldesigner/components/componentcore/theming.cpp index d1429ff45b..e74a0561e8 100644 --- a/src/plugins/qmldesigner/components/componentcore/theming.cpp +++ b/src/plugins/qmldesigner/components/componentcore/theming.cpp @@ -33,11 +33,13 @@ namespace QmlDesigner { -void Theming::insertTheme(QQmlPropertyMap *map) +const QVariantMap &Theming::theme() { - const QVariantHash creatorTheme = Utils::creatorTheme()->values(); - for (auto it = creatorTheme.constBegin(); it != creatorTheme.constEnd(); ++it) - map->insert(it.key(), it.value()); + static QVariantMap map; + if (!map.isEmpty()) + return map; + + map = Utils::creatorTheme()->values(); /* Define QmlDesigner colors and remove alpha channels */ const QColor backgroundColor = Utils::creatorTheme()->color(Utils::Theme::QmlDesigner_BackgroundColor); @@ -58,18 +60,18 @@ void Theming::insertTheme(QQmlPropertyMap *map) tabDark = tabDark.darker(260); } - map->insert("QmlDesignerBackgroundColorDarker", darkerBackground); - map->insert("QmlDesignerBackgroundColorDarkAlternate", backgroundColor); - map->insert("QmlDesignerTabLight", tabLight); - map->insert("QmlDesignerTabDark", tabDark); - map->insert("QmlDesignerButtonColor", buttonColor); - map->insert("QmlDesignerBorderColor", Utils::creatorTheme()->color(Utils::Theme::SplitterColor)); + map.insert("QmlDesignerBackgroundColorDarker", darkerBackground); + map.insert("QmlDesignerBackgroundColorDarkAlternate", backgroundColor); + map.insert("QmlDesignerTabLight", tabLight); + map.insert("QmlDesignerTabDark", tabDark); + map.insert("QmlDesignerButtonColor", buttonColor); + map.insert("QmlDesignerBorderColor", Utils::creatorTheme()->color(Utils::Theme::SplitterColor)); + return map; } QString Theming::replaceCssColors(const QString &input) { - QQmlPropertyMap map; - insertTheme(&map); + const QVariantMap &map = theme(); QRegExp rx("creatorTheme\\.(\\w+);"); int pos = 0; diff --git a/src/plugins/qmldesigner/components/componentcore/theming.h b/src/plugins/qmldesigner/components/componentcore/theming.h index cb582994bf..d9a11ce7b5 100644 --- a/src/plugins/qmldesigner/components/componentcore/theming.h +++ b/src/plugins/qmldesigner/components/componentcore/theming.h @@ -33,7 +33,7 @@ namespace QmlDesigner { class Theming { public: - static void insertTheme(QQmlPropertyMap *map); + static const QVariantMap &theme(); static QString replaceCssColors(const QString &input); static void registerIconProvider(QQmlEngine *engine); }; diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp index 6bd6a75be0..ad59291fe6 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp @@ -83,8 +83,7 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) : rootContext->setContextProperty(QStringLiteral("itemLibraryIconWidth"), m_itemIconSize.width()); rootContext->setContextProperty(QStringLiteral("itemLibraryIconHeight"), m_itemIconSize.height()); rootContext->setContextProperty(QStringLiteral("rootView"), this); - Theming::insertTheme(&m_themeProperties); - rootContext->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties); + rootContext->setContextProperty(QLatin1String("creatorTheme"), Theming::theme()); m_itemViewQuickWidget->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor()); diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h index ca8cd82c31..148b0b90dc 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h @@ -132,7 +132,6 @@ private: QPointer<Model> m_model; FilterChangeFlag m_filterFlag; ItemLibraryEntry m_currentitemLibraryEntry; - QQmlPropertyMap m_themeProperties; }; } diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index 3d4884d9bd..ff299af870 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -103,8 +103,7 @@ PropertyEditorQmlBackend::PropertyEditorQmlBackend(PropertyEditorView *propertyE m_contextObject->setModel(propertyEditor->model()); m_contextObject->insertInQmlContext(context()); - Theming::insertTheme(&m_themeProperties); - context()->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties); + context()->setContextProperty(QLatin1String("creatorTheme"), Theming::theme()); QObject::connect(&m_backendValuesPropertyMap, &DesignerPropertyMap::valueChanged, propertyEditor, &PropertyEditorView::changeValue); } diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h index 0e073b20be..a272b35aef 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.h @@ -103,7 +103,6 @@ private: QScopedPointer<PropertyEditorTransaction> m_propertyEditorTransaction; QScopedPointer<PropertyEditorValue> m_dummyPropertyEditorValue; QScopedPointer<PropertyEditorContextObject> m_contextObject; - QQmlPropertyMap m_themeProperties; }; } //QmlDesigner diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp index ae869763cd..a9a96cf05d 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp @@ -99,8 +99,7 @@ StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, State rootContext()->setContextProperty(QLatin1String("canAddNewStates"), true); - Theming::insertTheme(&m_themeProperties); - rootContext()->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties); + rootContext()->setContextProperty(QLatin1String("creatorTheme"), Theming::theme()); Theming::registerIconProvider(engine()); diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h index eb0c26ce04..fc78ecb450 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h @@ -67,7 +67,6 @@ private: QPointer<StatesEditorView> m_statesEditorView; Internal::StatesEditorImageProvider *m_imageProvider; QShortcut *m_qmlSourceUpdateShortcut; - QQmlPropertyMap m_themeProperties; }; } diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp index ac3d3a01fa..884eeb30db 100644 --- a/src/plugins/welcome/welcomeplugin.cpp +++ b/src/plugins/welcome/welcomeplugin.cpp @@ -158,7 +158,6 @@ private: void sceneGraphError(QQuickWindow::SceneGraphError, const QString &message); void facilitateQml(QQmlEngine *engine); void addPages(const QList<IWelcomePage *> &pages); - void applyTheme(); void addKeyboardShortcuts(); QWidget *m_modeWidget; @@ -166,7 +165,6 @@ private: QMap<Id, IWelcomePage *> m_idPageMap; QList<IWelcomePage *> m_pluginList; int m_activePlugin; - QQmlPropertyMap m_themeProperties; QStringList m_recentProjectsShortcuts; QStringList m_sessionsShortcuts; }; @@ -197,7 +195,6 @@ WelcomeMode::WelcomeMode() layout->setSpacing(0); m_welcomePage = new QQuickWidget; - applyTheme(); // initialize background color and theme properties m_welcomePage->setResizeMode(QQuickWidget::SizeRootObjectToView); m_welcomePage->setObjectName(QLatin1String("WelcomePage")); @@ -217,13 +214,6 @@ WelcomeMode::WelcomeMode() setWidget(m_modeWidget); } -void WelcomeMode::applyTheme() -{ - const QVariantHash creatorTheme = Utils::creatorTheme()->values(); - for (auto it = creatorTheme.constBegin(); it != creatorTheme.constEnd(); ++it) - m_themeProperties.insert(it.key(), it.value()); -} - void WelcomeMode::addKeyboardShortcuts() { const int actionsCount = 9; @@ -294,7 +284,7 @@ void WelcomeMode::facilitateQml(QQmlEngine *engine) QQmlContext *ctx = engine->rootContext(); ctx->setContextProperty(QLatin1String("welcomeMode"), this); - ctx->setContextProperty(QLatin1String("creatorTheme"), &m_themeProperties); + ctx->setContextProperty(QLatin1String("creatorTheme"), Utils::creatorTheme()->values()); ctx->setContextProperty(QLatin1String("useNativeText"), true); } |