aboutsummaryrefslogtreecommitdiffstats
path: root/src/controls
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-17 15:27:40 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-18 22:14:31 +0000
commit94136244c58ed035be44183bd8eb00314bccf7df (patch)
tree193a92473f4ed478f62512f748b7bb3fc8de3c4b /src/controls
parente1963859d6ade7a3341a48229f1bb64ef3c9ea68 (diff)
Cleanup QQuickStyleSelector
Remove some unneeded cruft that originates from QFileSelector and what we don't need in this specialized selector. Also, fix the header guards and include directives to use the same convention than all other classes. Change-Id: I728beba1156c0934bd0dd171038fc7560a556708 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/controls')
-rw-r--r--src/controls/qquickstyleselector.cpp186
-rw-r--r--src/controls/qquickstyleselector_p.h10
-rw-r--r--src/controls/qquickstyleselector_p_p.h18
3 files changed, 86 insertions, 128 deletions
diff --git a/src/controls/qquickstyleselector.cpp b/src/controls/qquickstyleselector.cpp
index a9778b07..9a48a9a4 100644
--- a/src/controls/qquickstyleselector.cpp
+++ b/src/controls/qquickstyleselector.cpp
@@ -36,41 +36,68 @@
#include "qquickstyleselector_p_p.h"
#include "qquickstyle.h"
-#include <QtCore/QDir>
-#include <QtCore/QMutex>
-#include <QtCore/QMutexLocker>
-#include <QtCore/QUrl>
-#include <QtCore/QFileInfo>
-#include <QtCore/QLocale>
-#include <QtCore/QDebug>
-#include <QtCore/QSettings>
+#include <QtCore/qdir.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qfileinfo.h>
+#include <QtCore/qsysinfo.h>
+#include <QtCore/qlocale.h>
#include <QtGui/private/qguiapplication_p.h>
QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC(QQuickStyleSelectorSharedData, sharedData);
-static QBasicMutex sharedDataMutex;
-
-QQuickStyleSelectorPrivate::QQuickStyleSelectorPrivate()
+static bool isLocalScheme(const QString &scheme)
{
+ bool local = scheme == QLatin1String("qrc");
+#ifdef Q_OS_ANDROID
+ local |= scheme == QLatin1String("assets");
+#endif
+ return local;
}
-QQuickStyleSelector::QQuickStyleSelector() : d_ptr(new QQuickStyleSelectorPrivate)
+// similar, but not identical to QSysInfo::osType
+static QStringList platformSelectors()
{
-}
+ static QStringList selectors;
+ if (!selectors.isEmpty())
+ return selectors;
-QQuickStyleSelector::~QQuickStyleSelector()
-{
+#if defined(Q_OS_WIN)
+ // can't fall back to QSysInfo because we need both "winphone" and "winrt" for the Windows Phone case
+ selectors << QStringLiteral("windows");
+ selectors << QSysInfo::kernelType(); // "wince" and "winnt"
+# if defined(Q_OS_WINRT)
+ selectors << QStringLiteral("winrt");
+# if defined(Q_OS_WINPHONE)
+ selectors << QStringLiteral("winphone");
+# endif
+# endif
+#elif defined(Q_OS_UNIX)
+ selectors << QStringLiteral("unix");
+# if !defined(Q_OS_ANDROID) && !defined(Q_OS_BLACKBERRY)
+ // we don't want "linux" for Android or "qnx" for Blackberry here
+ selectors << QSysInfo::kernelType();
+# ifdef Q_OS_MAC
+ selectors << QStringLiteral("mac"); // compatibility, since kernelType() is "darwin"
+# endif
+# endif
+ QString productName = QSysInfo::productType();
+ if (productName != QLatin1String("unknown"))
+ selectors << productName; // "opensuse", "fedora", "osx", "ios", "blackberry", "android"
+#endif
+ return selectors;
}
-static bool isLocalScheme(const QString &file)
+static QStringList allSelectors(bool includeStyle)
{
- bool local = file == QLatin1String("qrc");
-#ifdef Q_OS_ANDROID
- local |= file == QLatin1String("assets");
-#endif
- return local;
+ QStringList selectors = platformSelectors();
+ selectors += QLocale().name();
+ if (includeStyle) {
+ QString style = QQuickStyle::name();
+ if (!style.isEmpty())
+ selectors.prepend(style.toLower());
+ }
+ return selectors;
}
static QString selectionHelper(const QString &path, const QString &fileName, const QStringList &selectors)
@@ -99,35 +126,6 @@ static QString selectionHelper(const QString &path, const QString &fileName, con
return path + fileName;
}
-QString QQuickStyleSelector::select(const QString &fileName) const
-{
- Q_D(const QQuickStyleSelector);
- const QString overridePath = QQuickStyle::path();
- if (!overridePath.isEmpty()) {
- const QString stylePath = overridePath + QQuickStyle::name() + QLatin1Char('/');
- if (QFile::exists(stylePath + fileName)) {
- // the style name is included to the path, so exclude it from the selectors.
- // the rest of the selectors (os, locale) are still valid, though.
- const QString selectedPath = selectionHelper(stylePath, fileName, d->allSelectors(false));
- if (selectedPath.startsWith(QLatin1Char(':')))
- return QLatin1String("qrc") + selectedPath;
- return QUrl::fromLocalFile(selectedPath).toString();
- }
- }
-
- QUrl url(d->baseUrl.toString() + QLatin1Char('/') + fileName);
- if (isLocalScheme(url.scheme()) || url.isLocalFile()) {
- if (isLocalScheme(url.scheme())) {
- QString equivalentPath = QLatin1Char(':') + url.path();
- QString selectedPath = d->select(equivalentPath);
- url.setPath(selectedPath.remove(0, 1));
- } else {
- url = QUrl::fromLocalFile(d->select(url.toLocalFile()));
- }
- }
- return url.toString();
-}
-
QString QQuickStyleSelectorPrivate::select(const QString &filePath) const
{
QFileInfo fi(filePath);
@@ -143,24 +141,12 @@ QString QQuickStyleSelectorPrivate::select(const QString &filePath) const
return filePath;
}
-QStringList QQuickStyleSelectorPrivate::allSelectors(bool includeStyle) const
+QQuickStyleSelector::QQuickStyleSelector() : d_ptr(new QQuickStyleSelectorPrivate)
{
- QMutexLocker locker(&sharedDataMutex);
- updateSelectors();
- QStringList selectors = sharedData->staticSelectors;
- if (includeStyle) {
- QString style = QQuickStyle::name();
- if (!style.isEmpty())
- selectors.prepend(style.toLower());
- }
- return selectors;
}
-void QQuickStyleSelector::setBaseUrl(const QUrl &base)
+QQuickStyleSelector::~QQuickStyleSelector()
{
- Q_D(QQuickStyleSelector);
- if (d->baseUrl != base)
- d->baseUrl = base;
}
QUrl QQuickStyleSelector::baseUrl() const
@@ -169,53 +155,39 @@ QUrl QQuickStyleSelector::baseUrl() const
return d->baseUrl;
}
-void QQuickStyleSelectorPrivate::updateSelectors()
+void QQuickStyleSelector::setBaseUrl(const QUrl &url)
{
- if (!sharedData->staticSelectors.isEmpty())
- return; //Already loaded
-
- sharedData->staticSelectors << sharedData->preloadedStatics; //Potential for static selectors from other modules
-
- // TODO: Update on locale changed?
- sharedData->staticSelectors << QLocale().name();
-
- sharedData->staticSelectors << platformSelectors();
+ Q_D(QQuickStyleSelector);
+ d->baseUrl = url;
}
-QStringList QQuickStyleSelectorPrivate::platformSelectors()
+QString QQuickStyleSelector::select(const QString &fileName) const
{
- // similar, but not identical to QSysInfo::osType
- QStringList ret;
-#if defined(Q_OS_WIN)
- // can't fall back to QSysInfo because we need both "winphone" and "winrt" for the Windows Phone case
- ret << QStringLiteral("windows");
- ret << QSysInfo::kernelType(); // "wince" and "winnt"
-# if defined(Q_OS_WINRT)
- ret << QStringLiteral("winrt");
-# if defined(Q_OS_WINPHONE)
- ret << QStringLiteral("winphone");
-# endif
-# endif
-#elif defined(Q_OS_UNIX)
- ret << QStringLiteral("unix");
-# if !defined(Q_OS_ANDROID) && !defined(Q_OS_BLACKBERRY)
- // we don't want "linux" for Android or "qnx" for Blackberry here
- ret << QSysInfo::kernelType();
-# ifdef Q_OS_MAC
- ret << QStringLiteral("mac"); // compatibility, since kernelType() is "darwin"
-# endif
-# endif
- QString productName = QSysInfo::productType();
- if (productName != QLatin1String("unknown"))
- ret << productName; // "opensuse", "fedora", "osx", "ios", "blackberry", "android"
-#endif
- return ret;
-}
+ Q_D(const QQuickStyleSelector);
+ const QString overridePath = QQuickStyle::path();
+ if (!overridePath.isEmpty()) {
+ const QString stylePath = overridePath + QQuickStyle::name() + QLatin1Char('/');
+ if (QFile::exists(stylePath + fileName)) {
+ // the style name is included to the path, so exclude it from the selectors.
+ // the rest of the selectors (os, locale) are still valid, though.
+ const QString selectedPath = selectionHelper(stylePath, fileName, allSelectors(false));
+ if (selectedPath.startsWith(QLatin1Char(':')))
+ return QLatin1String("qrc") + selectedPath;
+ return QUrl::fromLocalFile(selectedPath).toString();
+ }
+ }
-void QQuickStyleSelectorPrivate::addStatics(const QStringList &statics)
-{
- QMutexLocker locker(&sharedDataMutex);
- sharedData->preloadedStatics << statics;
+ QUrl url(d->baseUrl.toString() + QLatin1Char('/') + fileName);
+ if (isLocalScheme(url.scheme()) || url.isLocalFile()) {
+ if (isLocalScheme(url.scheme())) {
+ QString equivalentPath = QLatin1Char(':') + url.path();
+ QString selectedPath = d->select(equivalentPath);
+ url.setPath(selectedPath.remove(0, 1));
+ } else {
+ url = QUrl::fromLocalFile(d->select(url.toLocalFile()));
+ }
+ }
+ return url.toString();
}
QT_END_NAMESPACE
diff --git a/src/controls/qquickstyleselector_p.h b/src/controls/qquickstyleselector_p.h
index 86e550e7..5c6434cb 100644
--- a/src/controls/qquickstyleselector_p.h
+++ b/src/controls/qquickstyleselector_p.h
@@ -47,6 +47,7 @@
//
#include <QtCore/qurl.h>
+#include <QtCore/qstring.h>
#include <QtCore/qscopedpointer.h>
#include <QtQuickControls/private/qtquickcontrolsglobal_p.h>
@@ -57,15 +58,16 @@ class QQuickStyleSelectorPrivate;
class Q_QUICKCONTROLS_PRIVATE_EXPORT QQuickStyleSelector
{
public:
- explicit QQuickStyleSelector();
+ QQuickStyleSelector();
~QQuickStyleSelector();
- QString select(const QString &fileName) const;
-
- void setBaseUrl(const QUrl &base);
QUrl baseUrl() const;
+ void setBaseUrl(const QUrl &url);
+
+ QString select(const QString &fileName) const;
private:
+ Q_DISABLE_COPY(QQuickStyleSelector)
Q_DECLARE_PRIVATE(QQuickStyleSelector)
QScopedPointer<QQuickStyleSelectorPrivate> d_ptr;
};
diff --git a/src/controls/qquickstyleselector_p_p.h b/src/controls/qquickstyleselector_p_p.h
index dc91af5f..9f831428 100644
--- a/src/controls/qquickstyleselector_p_p.h
+++ b/src/controls/qquickstyleselector_p_p.h
@@ -46,30 +46,14 @@
// We mean it.
//
-#include <QtCore/QString>
-#include <QtCore/QUrl>
-#include <private/qobject_p.h>
-#include <QtCore/qstringlist.h>
-
-#include "qquickstyleselector_p.h"
+#include <QtQuickControls/private/qquickstyleselector_p.h>
QT_BEGIN_NAMESPACE
-struct QQuickStyleSelectorSharedData //Not QSharedData because currently is just a global store
-{
- QStringList staticSelectors;
- QStringList preloadedStatics;
-};
-
class QQuickStyleSelectorPrivate
{
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;
- QStringList allSelectors(bool includeStyle) const;
QUrl baseUrl;
};