aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols2
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2020-04-02 11:51:21 +0200
committerMitch Curtis <mitch.curtis@qt.io>2020-08-26 11:45:48 +0200
commitef771a0fd70f05d7204fb8cbd8789aa1ed6eff4b (patch)
treea42ee55e8bf0c1af8d69f1578945229eb7790c25 /src/quickcontrols2
parent2ba4a895a48be6927818008580ab0a88cc8c4e12 (diff)
Stop using resolvedUrl() to resolve QML files
This is necessary to move away from imperative type registration of QML files (i.e. qmlRegisterType()). A later patch will use qmlRegisterModuleImport() to register the QtQuick.Controls import with the style set by the user, which will require each style to have a qmldir listing the files that it provides. Note that some plugins still register QML files, but these registrations will have to stay for now until we can split out "impl" plugins in later patches where those files can be registered. tst_qquickstyleselector will be added back in some other form in a follow-up patch. Task-number: QTBUG-82922 Change-Id: I8182533d9912ed493efda6eb91c69fc064af07ee Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/quickcontrols2')
-rw-r--r--src/quickcontrols2/qquickstyleplugin.cpp42
-rw-r--r--src/quickcontrols2/qquickstyleplugin_p.h6
-rw-r--r--src/quickcontrols2/qquickstyleselector.cpp163
-rw-r--r--src/quickcontrols2/qquickstyleselector_p.h86
-rw-r--r--src/quickcontrols2/qquickstyleselector_p_p.h70
-rw-r--r--src/quickcontrols2/quickcontrols2.pri7
6 files changed, 9 insertions, 365 deletions
diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp
index 9bbaad11..067d8dff 100644
--- a/src/quickcontrols2/qquickstyleplugin.cpp
+++ b/src/quickcontrols2/qquickstyleplugin.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
@@ -37,18 +37,14 @@
#include "qquickstyleplugin_p.h"
#include "qquickstyle.h"
#include "qquickstyle_p.h"
-#include "qquickstyleselector_p.h"
-QT_BEGIN_NAMESPACE
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlfile.h>
-class QQuickStylePluginPrivate
-{
-public:
- mutable QScopedPointer<QQuickStyleSelector> selector;
-};
+QT_BEGIN_NAMESPACE
QQuickStylePlugin::QQuickStylePlugin(QObject *parent)
- : QQmlExtensionPlugin(parent), d_ptr(new QQuickStylePluginPrivate)
+ : QQmlExtensionPlugin(parent)
{
}
@@ -66,34 +62,8 @@ void QQuickStylePlugin::initializeTheme(QQuickTheme *theme)
Q_UNUSED(theme);
}
-void QQuickStylePlugin::unregisterTypes()
+void QQuickStylePlugin::registerTypes(const char */*uri*/)
{
- Q_D(QQuickStylePlugin);
- // Destroy the selector so that it is recreated in resolvedUrl() and
- // any new style that has been set at runtime will be accounted for when selecting QML files.
- d->selector.reset();
-}
-
-QUrl QQuickStylePlugin::resolvedUrl(const QString &fileName) const
-{
- Q_D(const QQuickStylePlugin);
- if (!d->selector) {
- d->selector.reset(new QQuickStyleSelector);
- const QString style = QQuickStyle::name();
- if (!style.isEmpty())
- d->selector->addSelector(style);
-
- const QString fallback = QQuickStylePrivate::fallbackStyle();
- if (!fallback.isEmpty() && fallback != style)
- d->selector->addSelector(fallback);
-
- const QString theme = name();
- if (!theme.isEmpty() && theme != style)
- d->selector->addSelector(theme);
-
- d->selector->setPaths(QQuickStylePrivate::stylePaths(true));
- }
- return d->selector->select(fileName);
}
QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyleplugin_p.h b/src/quickcontrols2/qquickstyleplugin_p.h
index 67103e12..a9700c15 100644
--- a/src/quickcontrols2/qquickstyleplugin_p.h
+++ b/src/quickcontrols2/qquickstyleplugin_p.h
@@ -54,7 +54,6 @@
QT_BEGIN_NAMESPACE
class QQuickTheme;
-class QQuickStylePluginPrivate;
class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePlugin : public QQmlExtensionPlugin
{
@@ -66,14 +65,11 @@ public:
virtual QString name() const;
virtual void initializeTheme(QQuickTheme *theme);
- virtual void unregisterTypes() override;
- QUrl resolvedUrl(const QString &fileName) const;
+ void registerTypes(const char *uri) override;
private:
Q_DISABLE_COPY(QQuickStylePlugin)
- Q_DECLARE_PRIVATE(QQuickStylePlugin)
- QScopedPointer<QQuickStylePluginPrivate> d_ptr;
};
QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyleselector.cpp b/src/quickcontrols2/qquickstyleselector.cpp
deleted file mode 100644
index 72e7af66..00000000
--- a/src/quickcontrols2/qquickstyleselector.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qquickstyleselector_p.h"
-#include "qquickstyleselector_p_p.h"
-
-#include <QtCore/qfileinfo.h>
-#include <QtCore/qlocale.h>
-#include <QtCore/qloggingcategory.h>
-#include <QtCore/private/qfileselector_p.h>
-
-QT_BEGIN_NAMESPACE
-
-Q_LOGGING_CATEGORY(lcStyleSelectorSelect, "qt.quick.controls.styleSelector.select")
-Q_LOGGING_CATEGORY(lcStyleSelectorSetPaths, "qt.quick.controls.styleSelector.setPaths")
-Q_LOGGING_CATEGORY(lcStyleSelectorAddSelector, "qt.quick.controls.styleSelector.addSelector")
-
-static QString ensureSlash(const QString &path)
-{
- if (path.isEmpty() || path.endsWith(QLatin1Char('/')))
- return path;
- return path + QLatin1Char('/');
-}
-
-static QStringList prefixedPlatformSelectors(const QChar &prefix)
-{
- QStringList selectors = QFileSelectorPrivate::platformSelectors();
- for (int i = 0; i < selectors.count(); ++i)
- selectors[i].prepend(prefix);
- return selectors;
-}
-
-static QStringList allSelectors()
-{
- static const QStringList platformSelectors = prefixedPlatformSelectors(QLatin1Char('+'));
- QStringList selectors = platformSelectors;
- const QString locale = QLocale().name();
- if (!locale.isEmpty())
- selectors += QLatin1Char('+') + locale;
- return selectors;
-}
-
-QUrl QQuickStyleSelectorPrivate::select(const QString &filePath) const
-{
- QFileInfo fi(filePath);
- // If file doesn't exist, don't select
- if (!fi.exists())
- return QUrl();
-
- const QString selected = QFileSelectorPrivate::selectionHelper(ensureSlash(fi.canonicalPath()),
- fi.fileName(), allSelectors(), QChar());
-
- if (selected.startsWith(QLatin1Char(':')))
- return QUrl(QLatin1String("qrc") + selected);
-
- return QUrl::fromLocalFile(selected.isEmpty() ? filePath : selected);
-}
-
-QQuickStyleSelector::QQuickStyleSelector() : d_ptr(new QQuickStyleSelectorPrivate)
-{
-}
-
-QQuickStyleSelector::~QQuickStyleSelector()
-{
-}
-
-QStringList QQuickStyleSelector::selectors() const
-{
- Q_D(const QQuickStyleSelector);
- return d->selectors;
-}
-
-void QQuickStyleSelector::addSelector(const QString &selector)
-{
- Q_D(QQuickStyleSelector);
- if (d->selectors.contains(selector))
- return;
-
- d->selectors += selector;
-
- qCDebug(lcStyleSelectorSetPaths).nospace() << "added selector " << selector
- << "; full list is now: " << d->selectors;
-}
-
-QStringList QQuickStyleSelector::paths() const
-{
- Q_D(const QQuickStyleSelector);
- return d->paths;
-}
-
-void QQuickStyleSelector::setPaths(const QStringList &paths)
-{
- Q_D(QQuickStyleSelector);
- qCDebug(lcStyleSelectorSetPaths) << "setting paths to" << paths;
- d->paths = paths;
-}
-
-QUrl QQuickStyleSelector::select(const QString &fileName) const
-{
- Q_D(const QQuickStyleSelector);
- // The lookup order is
- // 1) requested style (e.g. "MyStyle", included in d->selectors)
- // 2) fallback style (e.g. "Material", included in d->selectors)
- // 3) default style (empty selector, not in d->selectors)
- qCDebug(lcStyleSelectorSelect) << "selecting" << fileName << "from" << d->paths << "with selectors" << d->selectors;
-
- int to = d->selectors.count() - 1;
- if (d->selectors.isEmpty() || !d->selectors.first().isEmpty())
- ++to; // lookup #3 unless #1 is also empty (redundant)
-
- // NOTE: last iteration intentionally out of bounds => empty selector
- for (int i = 0; i <= to; ++i) {
- const QString selector = d->selectors.value(i);
- for (const QString &path : d->paths) {
- const QUrl selectedUrl = d->select(ensureSlash(path) + selector + QLatin1Char('/') + fileName);
- if (selectedUrl.isValid()) {
- qCDebug(lcStyleSelectorSelect) << "==>" << selectedUrl << "from" << path << "with selector" << selector;
- return selectedUrl;
- }
- }
- }
-
- return fileName;
-}
-
-QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyleselector_p.h b/src/quickcontrols2/qquickstyleselector_p.h
deleted file mode 100644
index c4c0f540..00000000
--- a/src/quickcontrols2/qquickstyleselector_p.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQUICKSTYLESELECTOR_P_H
-#define QQUICKSTYLESELECTOR_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qurl.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qscopedpointer.h>
-#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QQuickStyleSelectorPrivate;
-
-class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStyleSelector
-{
-public:
- QQuickStyleSelector();
- ~QQuickStyleSelector();
-
- QStringList selectors() const;
- void addSelector(const QString &selector);
-
- QStringList paths() const;
- void setPaths(const QStringList &paths);
-
- QUrl select(const QString &fileName) const;
-
-private:
- Q_DISABLE_COPY(QQuickStyleSelector)
- Q_DECLARE_PRIVATE(QQuickStyleSelector)
- QScopedPointer<QQuickStyleSelectorPrivate> d_ptr;
-};
-
-QT_END_NAMESPACE
-
-#endif // QQUICKSTYLESELECTOR_P_H
diff --git a/src/quickcontrols2/qquickstyleselector_p_p.h b/src/quickcontrols2/qquickstyleselector_p_p.h
deleted file mode 100644
index e69e7db2..00000000
--- a/src/quickcontrols2/qquickstyleselector_p_p.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQUICKSTYLESELECTOR_P_P_H
-#define QQUICKSTYLESELECTOR_P_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtQuickControls2/private/qquickstyleselector_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QQuickStyleSelectorPrivate
-{
-public:
- QUrl select(const QString &filePath) const;
-
- QStringList paths;
- QStringList selectors;
-};
-
-QT_END_NAMESPACE
-
-#endif // QQUICKSTYLESELECTOR_P_P_H
diff --git a/src/quickcontrols2/quickcontrols2.pri b/src/quickcontrols2/quickcontrols2.pri
index 781658ef..2c28038f 100644
--- a/src/quickcontrols2/quickcontrols2.pri
+++ b/src/quickcontrols2/quickcontrols2.pri
@@ -15,9 +15,7 @@ HEADERS += \
$$PWD/qquickplaceholdertext_p.h \
$$PWD/qquickstyle.h \
$$PWD/qquickstyle_p.h \
- $$PWD/qquickstyleplugin_p.h \
- $$PWD/qquickstyleselector_p.h \
- $$PWD/qquickstyleselector_p_p.h
+ $$PWD/qquickstyleplugin_p.h
SOURCES += \
$$PWD/qquickanimatednode.cpp \
@@ -33,8 +31,7 @@ SOURCES += \
$$PWD/qquickpaddedrectangle.cpp \
$$PWD/qquickplaceholdertext.cpp \
$$PWD/qquickstyle.cpp \
- $$PWD/qquickstyleplugin.cpp \
- $$PWD/qquickstyleselector.cpp
+ $$PWD/qquickstyleplugin.cpp
qtConfig(quick-listview):qtConfig(quick-pathview) {
HEADERS += \