aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-14 16:20:45 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-14 16:03:45 +0000
commit8c3316aeea5f061e5b1be5605d69b8777345dd98 (patch)
treec2dda31267eb1da0df71d2af91338694f79d132e
parentcd0c04c630b6924d444f0e84e1b63477e4346aeb (diff)
Remove QQuickStyleSelector::instance()
It was a bad idea to share the same instance, because non-thread-safe instance() ends up being called from multiple threads. Let the style plugins create their own instances instead, QQuickStyleSelector ctor is not that heavy and there's no such shared state as originally was anticipated. Change-Id: Ie23091c6dd50f5d7abbab3b996da4471054da89a Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
-rw-r--r--src/controls/qquickstyleselector.cpp6
-rw-r--r--src/controls/qquickstyleselector_p.h2
-rw-r--r--src/imports/controls/material/qtlabsmaterialstyleplugin.cpp4
-rw-r--r--src/imports/controls/qtlabscontrolsplugin.cpp69
-rw-r--r--src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp4
5 files changed, 38 insertions, 47 deletions
diff --git a/src/controls/qquickstyleselector.cpp b/src/controls/qquickstyleselector.cpp
index 8c67cdce..61d7136e 100644
--- a/src/controls/qquickstyleselector.cpp
+++ b/src/controls/qquickstyleselector.cpp
@@ -179,12 +179,6 @@ QUrl QQuickStyleSelector::baseUrl() const
return d->baseUrl;
}
-QQuickStyleSelector *QQuickStyleSelector::instance()
-{
- static QQuickStyleSelector self;
- return &self;
-}
-
void QQuickStyleSelectorPrivate::updateSelectors()
{
if (!sharedData->staticSelectors.isEmpty())
diff --git a/src/controls/qquickstyleselector_p.h b/src/controls/qquickstyleselector_p.h
index 36ccf07c..64319098 100644
--- a/src/controls/qquickstyleselector_p.h
+++ b/src/controls/qquickstyleselector_p.h
@@ -69,8 +69,6 @@ public:
void setBaseUrl(const QUrl &base);
QUrl baseUrl() const;
- static QQuickStyleSelector *instance();
-
private:
QUrl select(const QUrl &filePath) const;
diff --git a/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp b/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp
index ab98991a..db8b47ee 100644
--- a/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp
+++ b/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp
@@ -85,8 +85,8 @@ void QtLabsMaterialStylePlugin::initializeEngine(QQmlEngine *engine, const char
Q_UNUSED(engine);
Q_UNUSED(uri);
- QQuickStyleSelector *selector = QQuickStyleSelector::instance();
- if (selector && selector->style() == QStringLiteral("material")) {
+ QQuickStyleSelector selector;
+ if (selector.style() == QStringLiteral("material")) {
if (QFont(QStringLiteral("Roboto")).family() == QStringLiteral("Roboto")) {
QPlatformTheme *old = QGuiApplicationPrivate::platform_theme;
if (old) {
diff --git a/src/imports/controls/qtlabscontrolsplugin.cpp b/src/imports/controls/qtlabscontrolsplugin.cpp
index b55bd20f..05135213 100644
--- a/src/imports/controls/qtlabscontrolsplugin.cpp
+++ b/src/imports/controls/qtlabscontrolsplugin.cpp
@@ -71,42 +71,41 @@ void QtLabsControlsPlugin::registerTypes(const char *uri)
qmlRegisterType<QQuickControl>(uri, 1, 0, "Control");
qmlRegisterType<QQuickPopup>(uri, 1, 0, "Popup");
- // TODO: read the style from application manifest file
- QQuickStyleSelector *selector = QQuickStyleSelector::instance();
- selector->setBaseUrl(baseUrl());
+ QQuickStyleSelector selector;
+ selector.setBaseUrl(baseUrl());
- qmlRegisterType(selector->select(QStringLiteral("/ApplicationWindow.qml")), uri, 1, 0, "ApplicationWindow");
- qmlRegisterType(selector->select(QStringLiteral("/BusyIndicator.qml")), uri, 1, 0, "BusyIndicator");
- qmlRegisterType(selector->select(QStringLiteral("/Button.qml")), uri, 1, 0, "Button");
- qmlRegisterType(selector->select(QStringLiteral("/CheckBox.qml")), uri, 1, 0, "CheckBox");
- qmlRegisterType(selector->select(QStringLiteral("/ComboBox.qml")), uri, 1, 0, "ComboBox");
- qmlRegisterType(selector->select(QStringLiteral("/Dial.qml")), uri, 1, 0, "Dial");
- qmlRegisterType(selector->select(QStringLiteral("/Drawer.qml")), uri, 1, 0, "Drawer");
- qmlRegisterType(selector->select(QStringLiteral("/Frame.qml")), uri, 1, 0, "Frame");
- qmlRegisterType(selector->select(QStringLiteral("/GroupBox.qml")), uri, 1, 0, "GroupBox");
- qmlRegisterType(selector->select(QStringLiteral("/ItemDelegate.qml")), uri, 1, 0, "ItemDelegate");
- qmlRegisterType(selector->select(QStringLiteral("/Label.qml")), uri, 1, 0, "Label");
- qmlRegisterType(selector->select(QStringLiteral("/Menu.qml")), uri, 1, 0, "Menu");
- qmlRegisterType(selector->select(QStringLiteral("/MenuItem.qml")), uri, 1, 0, "MenuItem");
- qmlRegisterType(selector->select(QStringLiteral("/Pane.qml")), uri, 1, 0, "Pane");
- qmlRegisterType(selector->select(QStringLiteral("/PageIndicator.qml")), uri, 1, 0, "PageIndicator");
- qmlRegisterType(selector->select(QStringLiteral("/ProgressBar.qml")), uri, 1, 0, "ProgressBar");
- qmlRegisterType(selector->select(QStringLiteral("/RadioButton.qml")), uri, 1, 0, "RadioButton");
- qmlRegisterType(selector->select(QStringLiteral("/RangeSlider.qml")), uri, 1, 0, "RangeSlider");
- qmlRegisterType(selector->select(QStringLiteral("/ScrollBar.qml")), uri, 1, 0, "ScrollBar");
- qmlRegisterType(selector->select(QStringLiteral("/ScrollIndicator.qml")), uri, 1, 0, "ScrollIndicator");
- qmlRegisterType(selector->select(QStringLiteral("/Slider.qml")), uri, 1, 0, "Slider");
- qmlRegisterType(selector->select(QStringLiteral("/SpinBox.qml")), uri, 1, 0, "SpinBox");
- qmlRegisterType(selector->select(QStringLiteral("/StackView.qml")), uri, 1, 0, "StackView");
- qmlRegisterType(selector->select(QStringLiteral("/SwipeView.qml")), uri, 1, 0, "SwipeView");
- qmlRegisterType(selector->select(QStringLiteral("/Switch.qml")), uri, 1, 0, "Switch");
- qmlRegisterType(selector->select(QStringLiteral("/TabBar.qml")), uri, 1, 0, "TabBar");
- qmlRegisterType(selector->select(QStringLiteral("/TabButton.qml")), uri, 1, 0, "TabButton");
- qmlRegisterType(selector->select(QStringLiteral("/TextArea.qml")), uri, 1, 0, "TextArea");
- qmlRegisterType(selector->select(QStringLiteral("/TextField.qml")), uri, 1, 0, "TextField");
- qmlRegisterType(selector->select(QStringLiteral("/ToolBar.qml")), uri, 1, 0, "ToolBar");
- qmlRegisterType(selector->select(QStringLiteral("/ToolButton.qml")), uri, 1, 0, "ToolButton");
- qmlRegisterType(selector->select(QStringLiteral("/Tumbler.qml")), uri, 1, 0, "Tumbler");
+ qmlRegisterType(selector.select(QStringLiteral("/ApplicationWindow.qml")), uri, 1, 0, "ApplicationWindow");
+ qmlRegisterType(selector.select(QStringLiteral("/BusyIndicator.qml")), uri, 1, 0, "BusyIndicator");
+ qmlRegisterType(selector.select(QStringLiteral("/Button.qml")), uri, 1, 0, "Button");
+ qmlRegisterType(selector.select(QStringLiteral("/CheckBox.qml")), uri, 1, 0, "CheckBox");
+ qmlRegisterType(selector.select(QStringLiteral("/ComboBox.qml")), uri, 1, 0, "ComboBox");
+ qmlRegisterType(selector.select(QStringLiteral("/Dial.qml")), uri, 1, 0, "Dial");
+ qmlRegisterType(selector.select(QStringLiteral("/Drawer.qml")), uri, 1, 0, "Drawer");
+ qmlRegisterType(selector.select(QStringLiteral("/Frame.qml")), uri, 1, 0, "Frame");
+ qmlRegisterType(selector.select(QStringLiteral("/GroupBox.qml")), uri, 1, 0, "GroupBox");
+ qmlRegisterType(selector.select(QStringLiteral("/ItemDelegate.qml")), uri, 1, 0, "ItemDelegate");
+ qmlRegisterType(selector.select(QStringLiteral("/Label.qml")), uri, 1, 0, "Label");
+ qmlRegisterType(selector.select(QStringLiteral("/Menu.qml")), uri, 1, 0, "Menu");
+ qmlRegisterType(selector.select(QStringLiteral("/MenuItem.qml")), uri, 1, 0, "MenuItem");
+ qmlRegisterType(selector.select(QStringLiteral("/Pane.qml")), uri, 1, 0, "Pane");
+ qmlRegisterType(selector.select(QStringLiteral("/PageIndicator.qml")), uri, 1, 0, "PageIndicator");
+ qmlRegisterType(selector.select(QStringLiteral("/ProgressBar.qml")), uri, 1, 0, "ProgressBar");
+ qmlRegisterType(selector.select(QStringLiteral("/RadioButton.qml")), uri, 1, 0, "RadioButton");
+ qmlRegisterType(selector.select(QStringLiteral("/RangeSlider.qml")), uri, 1, 0, "RangeSlider");
+ qmlRegisterType(selector.select(QStringLiteral("/ScrollBar.qml")), uri, 1, 0, "ScrollBar");
+ qmlRegisterType(selector.select(QStringLiteral("/ScrollIndicator.qml")), uri, 1, 0, "ScrollIndicator");
+ qmlRegisterType(selector.select(QStringLiteral("/Slider.qml")), uri, 1, 0, "Slider");
+ qmlRegisterType(selector.select(QStringLiteral("/SpinBox.qml")), uri, 1, 0, "SpinBox");
+ qmlRegisterType(selector.select(QStringLiteral("/StackView.qml")), uri, 1, 0, "StackView");
+ qmlRegisterType(selector.select(QStringLiteral("/SwipeView.qml")), uri, 1, 0, "SwipeView");
+ qmlRegisterType(selector.select(QStringLiteral("/Switch.qml")), uri, 1, 0, "Switch");
+ qmlRegisterType(selector.select(QStringLiteral("/TabBar.qml")), uri, 1, 0, "TabBar");
+ qmlRegisterType(selector.select(QStringLiteral("/TabButton.qml")), uri, 1, 0, "TabButton");
+ qmlRegisterType(selector.select(QStringLiteral("/TextArea.qml")), uri, 1, 0, "TextArea");
+ qmlRegisterType(selector.select(QStringLiteral("/TextField.qml")), uri, 1, 0, "TextField");
+ qmlRegisterType(selector.select(QStringLiteral("/ToolBar.qml")), uri, 1, 0, "ToolBar");
+ qmlRegisterType(selector.select(QStringLiteral("/ToolButton.qml")), uri, 1, 0, "ToolButton");
+ qmlRegisterType(selector.select(QStringLiteral("/Tumbler.qml")), uri, 1, 0, "Tumbler");
}
void QtLabsControlsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
diff --git a/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp b/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp
index 72dca8e8..703da011 100644
--- a/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp
+++ b/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp
@@ -82,8 +82,8 @@ void QtLabsUniversalStylePlugin::registerTypes(const char *uri)
void QtLabsUniversalStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
- QQuickStyleSelector *selector = QQuickStyleSelector::instance();
- if (selector && selector->style() == QStringLiteral("universal")) {
+ QQuickStyleSelector selector;
+ if (selector.style() == QStringLiteral("universal")) {
if (QFont(QStringLiteral("Segoe UI")).family() == QStringLiteral("Segoe UI")) {
QPlatformTheme *old = QGuiApplicationPrivate::platform_theme;
if (old) {