aboutsummaryrefslogtreecommitdiffstats
path: root/src/controls
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-01 18:05:05 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-02 16:16:45 +0000
commitcd4467753105e69b967d3aad8e6d890609dc830b (patch)
tree56633d70f422fde85741382ab4fde847de78c7e7 /src/controls
parent4d05ededdd5730af746b6c5dd5f7625ff80533d4 (diff)
QQuickStyleSelector: don't inherit QObject
Fixes the "QObject: Cannot create children for a parent that is in a different thread." -warnings. Change-Id: I94ed34c6c4c7a6b6507e91e74a354630b0ad6d04 Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Diffstat (limited to 'src/controls')
-rw-r--r--src/controls/qquickstyleselector.cpp24
-rw-r--r--src/controls/qquickstyleselector_p.h13
-rw-r--r--src/controls/qquickstyleselector_p_p.h5
3 files changed, 17 insertions, 25 deletions
diff --git a/src/controls/qquickstyleselector.cpp b/src/controls/qquickstyleselector.cpp
index d72de632..a84645d2 100644
--- a/src/controls/qquickstyleselector.cpp
+++ b/src/controls/qquickstyleselector.cpp
@@ -52,15 +52,12 @@ Q_GLOBAL_STATIC(QQuickStyleSelectorSharedData, sharedData);
static QBasicMutex sharedDataMutex;
QQuickStyleSelectorPrivate::QQuickStyleSelectorPrivate()
- : QObjectPrivate()
{
}
-QQuickStyleSelector::QQuickStyleSelector(QObject *parent)
- : QObject(*(new QQuickStyleSelectorPrivate()), parent)
+QQuickStyleSelector::QQuickStyleSelector() : d_ptr(new QQuickStyleSelectorPrivate)
{
Q_D(QQuickStyleSelector);
-
d->style = QGuiApplicationPrivate::styleOverride;
if (d->style.isEmpty())
d->style = QString::fromLatin1(qgetenv("QT_LABS_CONTROLS_STYLE"));
@@ -93,10 +90,10 @@ QUrl QQuickStyleSelector::select(const QUrl &filePath) const
QUrl ret(filePath);
if (isLocalScheme(filePath.scheme())) {
QString equivalentPath = QLatin1Char(':') + filePath.path();
- QString selectedPath = d->select(equivalentPath);
+ QString selectedPath = d->select(equivalentPath, allSelectors());
ret.setPath(selectedPath.remove(0, 1));
} else {
- ret = QUrl::fromLocalFile(d->select(ret.toLocalFile()));
+ ret = QUrl::fromLocalFile(d->select(ret.toLocalFile(), allSelectors()));
}
return ret;
}
@@ -127,16 +124,15 @@ static QString selectionHelper(const QString &path, const QString &fileName, con
return path + fileName;
}
-QString QQuickStyleSelectorPrivate::select(const QString &filePath) const
+QString QQuickStyleSelectorPrivate::select(const QString &filePath, const QStringList &allSelectors) const
{
- Q_Q(const QQuickStyleSelector);
QFileInfo fi(filePath);
// If file doesn't exist, don't select
if (!fi.exists())
return filePath;
QString ret = selectionHelper(fi.path().isEmpty() ? QString() : fi.path() + QLatin1Char('/'),
- fi.fileName(), q->allSelectors());
+ fi.fileName(), allSelectors);
if (!ret.isEmpty())
return ret;
@@ -176,12 +172,10 @@ QUrl QQuickStyleSelector::baseUrl() const
return d->baseUrl;
}
-QQuickStyleSelector *QQuickStyleSelector::instance(QObject *parent)
+QQuickStyleSelector *QQuickStyleSelector::instance()
{
- QPointer<QQuickStyleSelector> self;
- if (!self)
- self = new QQuickStyleSelector(parent);
- return self;
+ static QQuickStyleSelector self;
+ return &self;
}
void QQuickStyleSelectorPrivate::updateSelectors()
@@ -234,5 +228,3 @@ void QQuickStyleSelectorPrivate::addStatics(const QStringList &statics)
}
QT_END_NAMESPACE
-
-#include "moc_qquickstyleselector_p.cpp"
diff --git a/src/controls/qquickstyleselector_p.h b/src/controls/qquickstyleselector_p.h
index 567f592a..36ccf07c 100644
--- a/src/controls/qquickstyleselector_p.h
+++ b/src/controls/qquickstyleselector_p.h
@@ -46,17 +46,17 @@
// We mean it.
//
-#include <QtCore/QObject>
-#include <QtCore/QStringList>
+#include <QtCore/qurl.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qscopedpointer.h>
QT_BEGIN_NAMESPACE
class QQuickStyleSelectorPrivate;
-class QQuickStyleSelector : public QObject
+class QQuickStyleSelector
{
- Q_OBJECT
public:
- explicit QQuickStyleSelector(QObject *parent = Q_NULLPTR);
+ explicit QQuickStyleSelector();
~QQuickStyleSelector();
QString select(const QString &filePath) const;
@@ -69,12 +69,13 @@ public:
void setBaseUrl(const QUrl &base);
QUrl baseUrl() const;
- static QQuickStyleSelector *instance(QObject *parent = Q_NULLPTR);
+ static QQuickStyleSelector *instance();
private:
QUrl select(const QUrl &filePath) const;
Q_DECLARE_PRIVATE(QQuickStyleSelector)
+ QScopedPointer<QQuickStyleSelectorPrivate> d_ptr;
};
QT_END_NAMESPACE
diff --git a/src/controls/qquickstyleselector_p_p.h b/src/controls/qquickstyleselector_p_p.h
index bf11fd1c..b0de326b 100644
--- a/src/controls/qquickstyleselector_p_p.h
+++ b/src/controls/qquickstyleselector_p_p.h
@@ -60,15 +60,14 @@ struct QQuickStyleSelectorSharedData //Not QSharedData because currently is just
QStringList preloadedStatics;
};
-class QQuickStyleSelectorPrivate : QObjectPrivate
+class QQuickStyleSelectorPrivate
{
- Q_DECLARE_PUBLIC(QQuickStyleSelector)
public:
static void updateSelectors();
static QStringList platformSelectors();
static void addStatics(const QStringList &); //For loading GUI statics from other Qt modules
QQuickStyleSelectorPrivate();
- QString select(const QString &filePath) const;
+ QString select(const QString &filePath, const QStringList &allSelectors) const;
QString style;
QUrl baseUrl;