diff options
34 files changed, 1487 insertions, 107 deletions
diff --git a/examples/quickcontrols2/gallery/gallery.qml b/examples/quickcontrols2/gallery/gallery.qml index 8418161f4f..35eaed9f11 100644 --- a/examples/quickcontrols2/gallery/gallery.qml +++ b/examples/quickcontrols2/gallery/gallery.qml @@ -1,10 +1,10 @@ -// Copyright (C) 2017 The Qt Company Ltd. +// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtCore import QtQuick import QtQuick.Layouts import QtQuick.Controls -import Qt.labs.settings import "." as App diff --git a/examples/quickcontrols2/ios/todolist/AppSettings.qml b/examples/quickcontrols2/ios/todolist/AppSettings.qml index c732b9fbc8..764ba8b8fc 100644 --- a/examples/quickcontrols2/ios/todolist/AppSettings.qml +++ b/examples/quickcontrols2/ios/todolist/AppSettings.qml @@ -3,7 +3,7 @@ pragma Singleton -import Qt.labs.settings +import QtCore Settings { // The properties here are given default values to account for the first run of the application. diff --git a/examples/quickcontrols2/wearable/wearable.qml b/examples/quickcontrols2/wearable/wearable.qml index f7c56bbf28..27887354dc 100644 --- a/examples/quickcontrols2/wearable/wearable.qml +++ b/examples/quickcontrols2/wearable/wearable.qml @@ -1,9 +1,9 @@ -// Copyright (C) 2017 The Qt Company Ltd. +// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtCore import QtQuick import QtQuick.Controls as QQC2 -import Qt.labs.settings import "qml" import "qml/Style" diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 6387cbde77..fb6f15ffec 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -15,6 +15,8 @@ qt_internal_add_qml_module(QmlCore qqmlstandardpaths_p.h qqmlstandardpaths.cpp qqmlcoreglobal_p.h + qqmlsettings_p.h + qqmlsettings.cpp DEFINES QT_BUILD_QML_CORE_LIB PUBLIC_LIBRARIES diff --git a/src/core/qqmlsettings.cpp b/src/core/qqmlsettings.cpp new file mode 100644 index 0000000000..38352c2141 --- /dev/null +++ b/src/core/qqmlsettings.cpp @@ -0,0 +1,489 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "qqmlsettings_p.h" +#include <qcoreevent.h> +#include <qcoreapplication.h> +#include <qloggingcategory.h> +#include <qsettings.h> +#include <qpointer.h> +#include <qjsvalue.h> +#include <qqmlinfo.h> +#include <qdebug.h> +#include <qhash.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Settings +//! \instantiates QQmlSettings + \inherits QtObject + \inqmlmodule QtCore + \since 6.5 + \brief Provides persistent platform-independent application settings. + + The Settings type provides persistent platform-independent application settings. + + Users normally expect an application to remember its settings (window sizes + and positions, options, etc.) across sessions. The Settings type enables you + to save and restore such application settings with the minimum of effort. + + Individual setting values are specified by declaring properties within a + Settings element. Only value types recognized by QSettings are supported. + The recommended approach is to use property aliases in order + to get automatic property updates both ways. The following example shows + how to use Settings to store and restore the geometry of a window. + + \qml + import QtCore + import QtQuick + + Window { + id: window + + width: 800 + height: 600 + + Settings { + property alias x: window.x + property alias y: window.y + property alias width: window.width + property alias height: window.height + } + } + \endqml + + At first application startup, the window gets default dimensions specified + as 800x600. Notice that no default position is specified - we let the window + manager handle that. Later when the window geometry changes, new values will + be automatically stored to the persistent settings. The second application + run will get initial values from the persistent settings, bringing the window + back to the previous position and size. + + A fully declarative syntax, achieved by using property aliases, comes at the + cost of storing persistent settings whenever the values of aliased properties + change. Normal properties can be used to gain more fine-grained control over + storing the persistent settings. The following example illustrates how to save + a setting on component destruction. + + \qml + import QtCore + import QtQuick + + Item { + id: page + + state: settings.state + + states: [ + State { + name: "active" + // ... + }, + State { + name: "inactive" + // ... + } + ] + + Settings { + id: settings + property string state: "active" + } + + Component.onDestruction: { + settings.state = page.state + } + } + \endqml + + Notice how the default value is now specified in the persistent setting property, + and the actual property is bound to the setting in order to get the initial value + from the persistent settings. + + \section1 Application Identifiers + + Application specific settings are identified by providing application + \l {QCoreApplication::applicationName}{name}, + \l {QCoreApplication::organizationName}{organization} and + \l {QCoreApplication::organizationDomain}{domain}, or by specifying + \l location. + + \code + #include <QGuiApplication> + #include <QQmlApplicationEngine> + + int main(int argc, char *argv[]) + { + QGuiApplication app(argc, argv); + app.setOrganizationName("Some Company"); + app.setOrganizationDomain("somecompany.com"); + app.setApplicationName("Amazing Application"); + + QQmlApplicationEngine engine("main.qml"); + return app.exec(); + } + \endcode + + These are typically specified in C++ in the beginning of \c main(), + but can also be controlled in QML via the following properties: + \list + \li \l {Qt::application}{Qt.application.name}, + \li \l {Qt::application}{Qt.application.organization} and + \li \l {Qt::application}{Qt.application.domain}. + \endlist + + \section1 Categories + + Application settings may be divided into logical categories by specifying + a category name via the \l category property. Using logical categories not + only provides a cleaner settings structure, but also prevents possible + conflicts between setting keys. + + If several categories are required, use several Settings objects, each with + their own category: + + \qml + Item { + id: panel + + visible: true + + Settings { + category: "OutputPanel" + property alias visible: panel.visible + // ... + } + + Settings { + category: "General" + property alias fontSize: fontSizeSpinBox.value + // ... + } + } + \endqml + + Instead of ensuring that all settings in the application have unique names, + the settings can be divided into unique categories that may then contain + settings using the same names that are used in other categories - without + a conflict. + + \section1 Notes + + The current implementation is based on \l QSettings. This imposes certain + limitations, such as missing change notifications. Writing a setting value + using one instance of Settings does not update the value in another Settings + instance, even if they are referring to the same setting in the same category. + + The information is stored in the system registry on Windows, and in XML + preferences files on \macos. On other Unix systems, in the absence of a + standard, INI text files are used. See \l QSettings documentation for + more details. + + \sa QSettings +*/ + +using namespace Qt::StringLiterals; + +Q_LOGGING_CATEGORY(lcQmlSettings, "qt.core.settings") + +static constexpr const int settingsWriteDelay = 500; + +class QQmlSettingsPrivate +{ + Q_DISABLE_COPY_MOVE(QQmlSettingsPrivate) + Q_DECLARE_PUBLIC(QQmlSettings) + +public: + QQmlSettingsPrivate() = default; + ~QQmlSettingsPrivate() = default; + + QSettings *instance() const; + + void init(); + void reset(); + + void load(); + void store(); + + void _q_propertyChanged(); + QVariant readProperty(const QMetaProperty &property) const; + + QQmlSettings *q_ptr = nullptr; + int timerId = 0; + bool initialized = false; + QString category = {}; + QUrl location = {}; + mutable QPointer<QSettings> settings = nullptr; + QHash<const char *, QVariant> changedProperties = {}; +}; + +QSettings *QQmlSettingsPrivate::instance() const +{ + if (settings) + return settings; + + QQmlSettings *q = const_cast<QQmlSettings *>(q_func()); + settings = location.isLocalFile() ? new QSettings(location.toLocalFile(), QSettings::IniFormat, q) : new QSettings(q); + + if (settings->status() != QSettings::NoError) { + // TODO: can't print out the enum due to the following error: + // error: C2666: 'QQmlInfo::operator <<': 15 overloads have similar conversions + qmlWarning(q) << "Failed to initialize QSettings instance. Status code is: " << int(settings->status()); + + if (settings->status() == QSettings::AccessError) { + QStringList missingIdentifiers = {}; + if (QCoreApplication::organizationName().isEmpty()) + missingIdentifiers.append(u"organizationName"_s); + if (QCoreApplication::organizationDomain().isEmpty()) + missingIdentifiers.append(u"organizationDomain"_s); + if (QCoreApplication::applicationName().isEmpty()) + missingIdentifiers.append(u"applicationName"_s); + + if (!missingIdentifiers.isEmpty()) + qmlWarning(q) << "The following application identifiers have not been set: " << missingIdentifiers; + } + + return settings; + } + + if (!category.isEmpty()) + settings->beginGroup(category); + + if (initialized) + q->d_func()->load(); + + return settings; +} + +void QQmlSettingsPrivate::init() +{ + if (initialized) + return; + load(); + initialized = true; + qCDebug(lcQmlSettings) << "QQmlSettings: stored at" << instance()->fileName(); +} + +void QQmlSettingsPrivate::reset() +{ + if (initialized && settings && !changedProperties.isEmpty()) + store(); + delete settings; +} + +void QQmlSettingsPrivate::load() +{ + Q_Q(QQmlSettings); + const QMetaObject *mo = q->metaObject(); + const int offset = mo->propertyOffset(); + const int count = mo->propertyCount(); + + // don't save built-in properties if there aren't any qml properties + if (offset == 1) + return; + + for (int i = offset; i < count; ++i) { + QMetaProperty property = mo->property(i); + const QString propertyName = QString::fromUtf8(property.name()); + + const QVariant previousValue = readProperty(property); + const QVariant currentValue = instance()->value(propertyName, + previousValue); + + if (!currentValue.isNull() && (!previousValue.isValid() + || (currentValue.canConvert(previousValue.metaType()) + && previousValue != currentValue))) { + property.write(q, currentValue); + qCDebug(lcQmlSettings) << "QQmlSettings: load" << property.name() << "setting:" << currentValue << "default:" << previousValue; + } + + // ensure that a non-existent setting gets written + // even if the property wouldn't change later + if (!instance()->contains(propertyName)) + _q_propertyChanged(); + + // setup change notifications on first load + if (!initialized && property.hasNotifySignal()) { + static const int propertyChangedIndex = mo->indexOfSlot("_q_propertyChanged()"); + QMetaObject::connect(q, property.notifySignalIndex(), q, propertyChangedIndex); + } + } +} + +void QQmlSettingsPrivate::store() +{ + QHash<const char *, QVariant>::const_iterator it = changedProperties.constBegin(); + while (it != changedProperties.constEnd()) { + instance()->setValue(QString::fromUtf8(it.key()), it.value()); + qCDebug(lcQmlSettings) << "QQmlSettings: store" << it.key() << ":" << it.value(); + ++it; + } + changedProperties.clear(); +} + +void QQmlSettingsPrivate::_q_propertyChanged() +{ + Q_Q(QQmlSettings); + const QMetaObject *mo = q->metaObject(); + const int offset = mo->propertyOffset(); + const int count = mo->propertyCount(); + for (int i = offset; i < count; ++i) { + const QMetaProperty &property = mo->property(i); + const QVariant value = readProperty(property); + changedProperties.insert(property.name(), value); + qCDebug(lcQmlSettings) << "QQmlSettings: cache" << property.name() << ":" << value; + } + if (timerId != 0) + q->killTimer(timerId); + timerId = q->startTimer(settingsWriteDelay); +} + +QVariant QQmlSettingsPrivate::readProperty(const QMetaProperty &property) const +{ + Q_Q(const QQmlSettings); + QVariant var = property.read(q); + if (var.metaType() == QMetaType::fromType<QJSValue>()) + var = var.value<QJSValue>().toVariant(); + return var; +} + +QQmlSettings::QQmlSettings(QObject *parent) + : QObject(parent), d_ptr(new QQmlSettingsPrivate) +{ + Q_D(QQmlSettings); + d->q_ptr = this; +} + +QQmlSettings::~QQmlSettings() +{ + Q_D(QQmlSettings); + d->reset(); // flush pending changes +} + +/*! + \qmlproperty string Settings::category + + This property holds the name of the settings category. + + Categories can be used to group related settings together. +*/ +QString QQmlSettings::category() const +{ + Q_D(const QQmlSettings); + return d->category; +} + +void QQmlSettings::setCategory(const QString &category) +{ + Q_D(QQmlSettings); + if (d->category == category) + return; + d->reset(); + d->category = category; + if (d->initialized) + d->load(); + Q_EMIT categoryChanged(category); +} + +/*! + \qmlproperty url Settings::location + + This property holds the path to the settings file. If the file doesn't + already exist, it will be created. + + If this property is empty (the default), then QSettings::defaultFormat() + will be used. Otherwise, QSettings::IniFormat will be used. + + \sa QSettings::fileName, QSettings::defaultFormat, QSettings::IniFormat +*/ +QUrl QQmlSettings::location() const +{ + Q_D(const QQmlSettings); + return d->location; +} + +void QQmlSettings::setLocation(const QUrl &location) +{ + Q_D(QQmlSettings); + if (d->location == location) + return; + d->reset(); + d->location = location; + if (d->initialized) + d->load(); + Q_EMIT locationChanged(location); +} + +/*! + \qmlmethod var Settings::value(string key, var defaultValue) + + Returns the value for setting \a key. If the setting doesn't exist, + returns \a defaultValue. + + \sa QSettings::value +*/ +QVariant QQmlSettings::value(const QString &key, const QVariant &defaultValue) const +{ + Q_D(const QQmlSettings); + return d->instance()->value(key, defaultValue); +} + +/*! + \qmlmethod Settings::setValue(string key, var value) + + Sets the value of setting \a key to \a value. If the key already exists, + the previous value is overwritten. + + \sa QSettings::setValue +*/ +void QQmlSettings::setValue(const QString &key, const QVariant &value) +{ + Q_D(const QQmlSettings); + d->instance()->setValue(key, value); + qCDebug(lcQmlSettings) << "QQmlSettings: setValue" << key << ":" << value; +} + +/*! + \qmlmethod Settings::sync() + + Writes any unsaved changes to permanent storage, and reloads any + settings that have been changed in the meantime by another + application. + + This function is called automatically from QSettings's destructor and + by the event loop at regular intervals, so you normally don't need to + call it yourself. + + \sa QSettings::sync +*/ +void QQmlSettings::sync() +{ + Q_D(QQmlSettings); + d->instance()->sync(); +} + +void QQmlSettings::classBegin() +{ +} + +void QQmlSettings::componentComplete() +{ + Q_D(QQmlSettings); + d->init(); +} + +void QQmlSettings::timerEvent(QTimerEvent *event) +{ + Q_D(QQmlSettings); + QObject::timerEvent(event); + if (event->timerId() != d->timerId) + return; + killTimer(d->timerId); + d->timerId = 0; + d->store(); +} + +QT_END_NAMESPACE + +#include "moc_qqmlsettings_p.cpp" diff --git a/src/core/qqmlsettings_p.h b/src/core/qqmlsettings_p.h new file mode 100644 index 0000000000..90d664efaf --- /dev/null +++ b/src/core/qqmlsettings_p.h @@ -0,0 +1,72 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QQMLSETTINGS_P_H +#define QQMLSETTINGS_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/qobject.h> +#include <QtCore/qvariant.h> +#include <QtCore/qurl.h> +#include <QtQml/qqml.h> +#include <QtQml/qqmlparserstatus.h> +#include <QtQmlCore/private/qqmlcoreglobal_p.h> + +QT_BEGIN_NAMESPACE + +class QQmlSettingsPrivate; + +class Q_QMLCORE_PRIVATE_EXPORT QQmlSettings : public QObject, public QQmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QQmlParserStatus) + Q_DECLARE_PRIVATE(QQmlSettings) + QML_NAMED_ELEMENT(Settings) + QML_ADDED_IN_VERSION(6, 5) + + Q_PROPERTY(QString category READ category WRITE setCategory NOTIFY categoryChanged FINAL) + Q_PROPERTY(QUrl location READ location WRITE setLocation NOTIFY locationChanged FINAL) + +public: + explicit QQmlSettings(QObject *parent = nullptr); + ~QQmlSettings() override; + + QString category() const; + void setCategory(const QString &category); + + QUrl location() const; + void setLocation(const QUrl &location); + + Q_INVOKABLE QVariant value(const QString &key, const QVariant &defaultValue = {}) const; + Q_INVOKABLE void setValue(const QString &key, const QVariant &value); + Q_INVOKABLE void sync(); + +Q_SIGNALS: + void categoryChanged(const QString &arg); + void locationChanged(const QUrl &arg); + +protected: + void timerEvent(QTimerEvent *event) override; + + void classBegin() override; + void componentComplete() override; + +private: + QScopedPointer<QQmlSettingsPrivate> d_ptr; + + Q_PRIVATE_SLOT(d_func(), void _q_propertyChanged()) +}; + +QT_END_NAMESPACE + +#endif // QQMLSETTINGS_P_H diff --git a/src/labs/settings/qqmlsettings.cpp b/src/labs/settings/qqmlsettings.cpp index a964f4dbdc..fe0fa831d2 100644 --- a/src/labs/settings/qqmlsettings.cpp +++ b/src/labs/settings/qqmlsettings.cpp @@ -18,6 +18,7 @@ QT_BEGIN_NAMESPACE \qmlmodule Qt.labs.settings 1.0 \title Qt Labs Settings QML Types \ingroup qmlmodules + \deprecated [6.5] Use \l {QtQmlCore::}{Settings} from Qt QML Core instead. \brief Provides persistent platform-independent application settings. To use this module, import the module with the following line: @@ -32,6 +33,7 @@ QT_BEGIN_NAMESPACE //! \instantiates QQmlSettings \inqmlmodule Qt.labs.settings \ingroup settings + \deprecated [6.5] Use \l {QtQmlCore::}{Settings} from Qt QML Core instead. \brief Provides persistent platform-independent application settings. The Settings type provides persistent platform-independent application settings. @@ -196,7 +198,7 @@ QT_BEGIN_NAMESPACE standard, INI text files are used. See \l QSettings documentation for more details. - \sa QSettings + \sa {QtQmlCore::}{Settings}, QSettings */ Q_LOGGING_CATEGORY(lcSettings, "qt.labs.settings") @@ -481,6 +483,9 @@ void QQmlSettings::componentComplete() { Q_D(QQmlSettings); d->init(); + qmlWarning(this) << "The Settings type from Qt.labs.settings is deprecated" + " and will be removed in a future release. Please use " + "the one from QtCore instead."; } void QQmlSettings::timerEvent(QTimerEvent *event) diff --git a/src/quicktemplates2/qquicksplitview.cpp b/src/quicktemplates2/qquicksplitview.cpp index 7f6a86f116..2ca9923860 100644 --- a/src/quicktemplates2/qquicksplitview.cpp +++ b/src/quicktemplates2/qquicksplitview.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2018 The Qt Company Ltd. +// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qquicksplitview_p.h" @@ -173,8 +173,8 @@ QT_BEGIN_NAMESPACE serialized using the \l saveState() and \l restoreState() functions: \qml + import QtCore import QtQuick.Controls - import Qt.labs.settings ApplicationWindow { // ... @@ -198,8 +198,8 @@ QT_BEGIN_NAMESPACE functions of \l Settings can be used: \qml + import QtCore import QtQuick.Controls - import Qt.labs.settings ApplicationWindow { // ... diff --git a/tests/auto/core/CMakeLists.txt b/tests/auto/core/CMakeLists.txt index 9749925832..fefa6ff1c1 100644 --- a/tests/auto/core/CMakeLists.txt +++ b/tests/auto/core/CMakeLists.txt @@ -1,34 +1,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Collect test data -file(GLOB_RECURSE test_data_glob - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/data/tst_*) -list(APPEND test_data ${test_data_glob}) - -qt_internal_add_test(tst_core - GUI - QMLTEST - SOURCES - tst_core.cpp - LIBRARIES - Qt::CorePrivate - Qt::QmlPrivate - Qt::QuickTestUtilsPrivate - TESTDATA ${test_data} -) - -if(QT_BUILD_STANDALONE_TESTS) - qt_import_qml_plugins(tst_core) -endif() - -qt_internal_extend_target(tst_core CONDITION ANDROID OR IOS - DEFINES - QT_QMLTEST_DATADIR=\\\":/data\\\" -) - -qt_internal_extend_target(tst_core CONDITION NOT ANDROID AND NOT IOS - DEFINES - QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" -) +add_subdirectory(qqmlstandardpaths) +add_subdirectory(qqmlsysteminformation) +add_subdirectory(qqmlsettings) diff --git a/tests/auto/core/data/tst_standardpaths.qml b/tests/auto/core/data/tst_standardpaths.qml deleted file mode 100644 index 06a96ca2e5..0000000000 --- a/tests/auto/core/data/tst_standardpaths.qml +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtCore -import QtTest - -TestCase { - id: testCase - name: "StandardPaths" - - function test_standardLocation() { - // Q_ENUMS(QStandardPaths::StandardLocation) - compare(StandardPaths.DesktopLocation, 0) - compare(StandardPaths.DocumentsLocation, 1) - compare(StandardPaths.FontsLocation, 2) - compare(StandardPaths.ApplicationsLocation, 3) - compare(StandardPaths.MusicLocation, 4) - compare(StandardPaths.MoviesLocation, 5) - compare(StandardPaths.PicturesLocation, 6) - compare(StandardPaths.TempLocation, 7) - compare(StandardPaths.HomeLocation, 8) - compare(StandardPaths.AppLocalDataLocation, 9) - compare(StandardPaths.CacheLocation, 10) - compare(StandardPaths.GenericDataLocation, 11) - compare(StandardPaths.RuntimeLocation, 12) - compare(StandardPaths.ConfigLocation, 13) - compare(StandardPaths.DownloadLocation, 14) - compare(StandardPaths.GenericCacheLocation, 15) - compare(StandardPaths.GenericConfigLocation, 16) - compare(StandardPaths.AppDataLocation, 17) - compare(StandardPaths.AppConfigLocation, 18) - } - - function test_locateOptions() { - // Q_ENUMS(QStandardPaths::LocateOptions) - compare(StandardPaths.LocateFile, 0) - compare(StandardPaths.LocateDirectory, 1) - } -} diff --git a/tests/auto/core/qqmlsettings/CMakeLists.txt b/tests/auto/core/qqmlsettings/CMakeLists.txt new file mode 100644 index 0000000000..357a7f4d9f --- /dev/null +++ b/tests/auto/core/qqmlsettings/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + data/*) +list(APPEND test_data ${test_data_glob}) + +qt_internal_add_test(tst_qqmlsettings + SOURCES + tst_qqmlsettings.cpp + LIBRARIES + Qt::Gui + Qt::Qml + Qt::QuickTestUtilsPrivate + TESTDATA ${test_data} +) + +qt_internal_extend_target(tst_qqmlsettings CONDITION ANDROID OR IOS + DEFINES + QT_QMLTEST_DATADIR=\\\":/data\\\" +) + +qt_internal_extend_target(tst_qqmlsettings CONDITION NOT ANDROID AND NOT IOS + DEFINES + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" +) diff --git a/tests/auto/core/qqmlsettings/data/aliases.qml b/tests/auto/core/qqmlsettings/data/aliases.qml new file mode 100644 index 0000000000..547b4d5c13 --- /dev/null +++ b/tests/auto/core/qqmlsettings/data/aliases.qml @@ -0,0 +1,51 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import QtQml +import QtCore +import QtQuick + +QtObject { + id: root + + property int intProperty: 123 + property bool boolProperty: true + property real realProperty: 1.23 + property double doubleProperty: 3.45 + property string stringProperty: "foo" + property url urlProperty: "http://www.qt-project.org" + property var objectProperty: {"foo":"bar"} + property var intListProperty: [1, 2, 3] + property var stringListProperty: ["a", "b", "c"] + property var objectListProperty: [{"a":"b"}, {"c":"d"}] + property date dateProperty: "2000-01-02" + // QTBUG-32295: Expected property type + //property time timeProperty: "12:34:56" + property size sizeProperty: Qt.size(12, 34) + property point pointProperty: Qt.point(12, 34) + property rect rectProperty: Qt.rect(1, 2, 3, 4) + property color colorProperty: "red" + property font fontProperty + + property Settings settings: Settings { + id: settings + + property alias intProperty: root.intProperty + property alias boolProperty: root.boolProperty + property alias realProperty: root.realProperty + property alias doubleProperty: root.doubleProperty + property alias stringProperty: root.stringProperty + property alias urlProperty: root.urlProperty + property alias objectProperty: root.objectProperty + property alias intListProperty: root.intListProperty + property alias stringListProperty: root.stringListProperty + property alias objectListProperty: root.objectListProperty + property alias dateProperty: root.dateProperty + // QTBUG-32295: Expected property type + //property alias timeProperty: root.timeProperty + property alias sizeProperty: root.sizeProperty + property alias pointProperty: root.pointProperty + property alias rectProperty: root.rectProperty + property alias colorProperty: root.colorProperty + property alias fontProperty: root.fontProperty + } +} diff --git a/tests/auto/core/qqmlsettings/data/basic.qml b/tests/auto/core/qqmlsettings/data/basic.qml new file mode 100644 index 0000000000..2c395b56e3 --- /dev/null +++ b/tests/auto/core/qqmlsettings/data/basic.qml @@ -0,0 +1,8 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import QtQml +import QtCore + +Settings { + property bool success: true +} diff --git a/tests/auto/core/qqmlsettings/data/categories.qml b/tests/auto/core/qqmlsettings/data/categories.qml new file mode 100644 index 0000000000..54cd22a8b1 --- /dev/null +++ b/tests/auto/core/qqmlsettings/data/categories.qml @@ -0,0 +1,9 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import QtQml +import QtCore + +Settings { + category: "initialCategory" + property string value: "initialValue" +} diff --git a/tests/auto/core/qqmlsettings/data/cpp-aliases.qml b/tests/auto/core/qqmlsettings/data/cpp-aliases.qml new file mode 100644 index 0000000000..22d7338986 --- /dev/null +++ b/tests/auto/core/qqmlsettings/data/cpp-aliases.qml @@ -0,0 +1,31 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import QtQml +import QtCore +import QtQuick +import Qt.test + +CppObject { + id: obj + + property Settings settings: Settings { + property alias intProperty: obj.intProperty + property alias boolProperty: obj.boolProperty + property alias realProperty: obj.realProperty + property alias doubleProperty: obj.doubleProperty + property alias stringProperty: obj.stringProperty + property alias urlProperty: obj.urlProperty + property alias objectProperty: obj.objectProperty + property alias intListProperty: obj.intListProperty + property alias stringListProperty: obj.stringListProperty + property alias objectListProperty: obj.objectListProperty + property alias dateProperty: obj.dateProperty + // QTBUG-32295: Expected property type + //property alias timeProperty: obj.timeProperty + property alias sizeProperty: obj.sizeProperty + property alias pointProperty: obj.pointProperty + property alias rectProperty: obj.rectProperty + property alias colorProperty: obj.colorProperty + property alias fontProperty: obj.fontProperty + } +} diff --git a/tests/auto/core/qqmlsettings/data/siblings.qml b/tests/auto/core/qqmlsettings/data/siblings.qml new file mode 100644 index 0000000000..e483623d82 --- /dev/null +++ b/tests/auto/core/qqmlsettings/data/siblings.qml @@ -0,0 +1,24 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import QtQml +import QtCore +import QtQuick + +Item { + id: root + + Item { + id: sibling1 + property string prop1: "value1" + } + + Settings { + property alias alias1: sibling1.prop1 + property alias alias2: sibling2.prop2 + } + + Item { + id: sibling2 + property string prop2: "value2" + } +} diff --git a/tests/auto/core/qqmlsettings/data/types.qml b/tests/auto/core/qqmlsettings/data/types.qml new file mode 100644 index 0000000000..3f38594323 --- /dev/null +++ b/tests/auto/core/qqmlsettings/data/types.qml @@ -0,0 +1,79 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import QtQml +import QtCore +import QtQuick + +QtObject { + id: root + + property int intProperty + property bool boolProperty + property real realProperty + property double doubleProperty + property string stringProperty + property url urlProperty + property var objectProperty + property var intListProperty + property var stringListProperty + property var objectListProperty + property date dateProperty + // QTBUG-32295: Expected property type + // property time timeProperty + property size sizeProperty + property point pointProperty + property rect rectProperty + property color colorProperty + property font fontProperty + + function readSettings() { + __setProperties(settings, root) + } + + function writeSettings() { + __setProperties(root, settings) + } + + function __setProperties(from, to) { + to.intProperty = from.intProperty + to.boolProperty = from.boolProperty + to.realProperty = from.realProperty + to.doubleProperty = from.doubleProperty + to.stringProperty = from.stringProperty + to.urlProperty = from.urlProperty + to.objectProperty = from.objectProperty + to.intListProperty = from.intListProperty + to.stringListProperty = from.stringListProperty + to.objectListProperty = from.objectListProperty + to.dateProperty = from.dateProperty + //to.timeProperty = from.timeProperty + to.sizeProperty = from.sizeProperty + to.pointProperty = from.pointProperty + to.rectProperty = from.rectProperty + to.colorProperty = from.colorProperty + to.fontProperty = from.fontProperty + } + + property Settings settings: Settings { + id: settings + + property int intProperty: 123 + property bool boolProperty: true + property real realProperty: 1.23 + property double doubleProperty: 3.45 + property string stringProperty: "foo" + property url urlProperty: "http://www.qt-project.org" + property var objectProperty: {"foo":"bar"} + property var intListProperty: [1, 2, 3] + property var stringListProperty: ["a", "b", "c"] + property var objectListProperty: [{"a":"b"}, {"c":"d"}] + property date dateProperty: "2000-01-02" + // QTBUG-32295: Expected property type + //property time timeProperty: "12:34:56" + property size sizeProperty: Qt.size(12, 34) + property point pointProperty: Qt.point(12, 34) + property rect rectProperty: Qt.rect(1, 2, 3, 4) + property color colorProperty: "red" + property font fontProperty + } +} diff --git a/tests/auto/core/qqmlsettings/tst_qqmlsettings.cpp b/tests/auto/core/qqmlsettings/tst_qqmlsettings.cpp new file mode 100644 index 0000000000..1b6ab3f68b --- /dev/null +++ b/tests/auto/core/qqmlsettings/tst_qqmlsettings.cpp @@ -0,0 +1,498 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include <QtTest/QtTest> +#include <QtCore/QCoreApplication> +#include <QtCore/QScopedPointer> +#include <QtCore/QSettings> +#include <QtCore/QVariant> +#include <QtGui/QColor> +#include <QtGui/QFont> +#include <QtQml/QQmlEngine> +#include <QtQml/QQmlComponent> +#include <QtQuickTestUtils/private/qmlutils_p.h> + +class tst_QQmlSettings : public QQmlDataTest +{ + Q_OBJECT + +public: + tst_QQmlSettings(); + +private slots: + void initTestCase() override; + + void init() override; + void cleanup(); + + void basic(); + void types(); + void aliases_data(); + void aliases(); + void categories(); + void siblings(); + void initial(); + void noApplicationIdentifiersSet(); +}; + +// ### Replace keyValueMap("foo", "bar") with QVariantMap({{"foo", "bar"}}) +// when C++11 uniform initialization can be used (not supported by MSVC 2013). +static QVariantMap keyValueMap(const QString &key, const QString &value) +{ + QVariantMap var; + var.insert(key, value); + return var; +} + +class CppObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int intProperty MEMBER m_intProperty NOTIFY intPropertyChanged) + Q_PROPERTY(bool boolProperty MEMBER m_boolProperty NOTIFY boolPropertyChanged) + Q_PROPERTY(qreal realProperty MEMBER m_realProperty NOTIFY realPropertyChanged) + Q_PROPERTY(double doubleProperty MEMBER m_doubleProperty NOTIFY doublePropertyChanged) + Q_PROPERTY(QString stringProperty MEMBER m_stringProperty NOTIFY stringPropertyChanged) + Q_PROPERTY(QUrl urlProperty MEMBER m_urlProperty NOTIFY urlPropertyChanged) + Q_PROPERTY(QVariant varProperty MEMBER m_varProperty NOTIFY varPropertyChanged) + Q_PROPERTY(QVariantMap objectProperty MEMBER m_objectProperty NOTIFY objectPropertyChanged) + Q_PROPERTY(QVariantList intListProperty MEMBER m_intListProperty NOTIFY intListPropertyChanged) + Q_PROPERTY(QVariantList stringListProperty MEMBER m_stringListProperty NOTIFY stringListPropertyChanged) + Q_PROPERTY(QVariantList objectListProperty MEMBER m_objectListProperty NOTIFY objectListPropertyChanged) + Q_PROPERTY(QDate dateProperty MEMBER m_dateProperty NOTIFY datePropertyChanged) + // QTBUG-32295: Q_PROPERTY(QTime timeProperty MEMBER m_timeProperty NOTIFY timePropertyChanged) + Q_PROPERTY(QSizeF sizeProperty MEMBER m_sizeProperty NOTIFY sizePropertyChanged) + Q_PROPERTY(QPointF pointProperty MEMBER m_pointProperty NOTIFY pointPropertyChanged) + Q_PROPERTY(QRectF rectProperty MEMBER m_rectProperty NOTIFY rectPropertyChanged) + Q_PROPERTY(QColor colorProperty MEMBER m_colorProperty NOTIFY colorPropertyChanged) + Q_PROPERTY(QFont fontProperty MEMBER m_fontProperty NOTIFY fontPropertyChanged) + +public: + CppObject(QObject *parent = nullptr) : QObject(parent), + + m_stringProperty("foo"), + m_urlProperty("http://www.qt-project.org"), + m_objectProperty(keyValueMap("foo", "bar")), + m_intListProperty(QVariantList() << 1 << 2 << 3), + m_stringListProperty(QVariantList() << "a" << "b" << "c"), + m_objectListProperty(QVariantList() << keyValueMap("a", "b") << keyValueMap("c", "d")), + m_dateProperty(2000, 1, 2), + // QTBUG-32295: m_timeProperty(12, 34, 56), + m_sizeProperty(12, 34), + m_pointProperty(12, 34), + m_rectProperty(1, 2, 3, 4), + m_colorProperty("red") + { + } + +signals: + void intPropertyChanged(int arg); + void boolPropertyChanged(bool arg); + void realPropertyChanged(qreal arg); + void doublePropertyChanged(double arg); + void stringPropertyChanged(const QString &arg); + void urlPropertyChanged(const QUrl &arg); + void varPropertyChanged(const QVariant &arg); + void objectPropertyChanged(const QVariantMap &arg); + void intListPropertyChanged(const QVariantList &arg); + void stringListPropertyChanged(const QVariantList &arg); + void objectListPropertyChanged(const QVariantList &arg); + void datePropertyChanged(QDate arg); + void sizePropertyChanged(const QSizeF &arg); + void pointPropertyChanged(const QPointF &arg); + void rectPropertyChanged(const QRectF &arg); + void colorPropertyChanged(const QColor &arg); + void fontPropertyChanged(const QFont &arg); + +private: + int m_intProperty = 123; + bool m_boolProperty = true; + qreal m_realProperty = 1.23; + double m_doubleProperty = 3.45; + QString m_stringProperty; + QUrl m_urlProperty; + QVariant m_varProperty; + QVariantMap m_objectProperty; + QVariantList m_intListProperty; + QVariantList m_stringListProperty; + QVariantList m_objectListProperty; + QDate m_dateProperty; + QSizeF m_sizeProperty; + QPointF m_pointProperty; + QRectF m_rectProperty; + QColor m_colorProperty; + QFont m_fontProperty; +}; + +tst_QQmlSettings::tst_QQmlSettings() + : QQmlDataTest(QT_QMLTEST_DATADIR) +{ +} + +void tst_QQmlSettings::initTestCase() +{ + QQmlDataTest::initTestCase(); + + qmlRegisterType<CppObject>("Qt.test", 1, 0, "CppObject"); +} + +void tst_QQmlSettings::init() +{ + QQmlDataTest::init(); + + QSettings settings; + settings.clear(); + + QCoreApplication::setApplicationName("tst_QQmlSettings"); + QCoreApplication::setOrganizationName("QtProject"); + QCoreApplication::setOrganizationDomain("qt-project.org"); +} + +void tst_QQmlSettings::cleanup() +{ + QSettings settings; + settings.clear(); +} + +void tst_QQmlSettings::basic() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("basic.qml")); + QScopedPointer<QObject> root(component.create()); + QVERIFY(root.data()); + QVERIFY(root->property("success").toBool()); + QSettings settings; + QTRY_VERIFY(settings.value("success").toBool()); +} + +void tst_QQmlSettings::types() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("types.qml")); + QScopedPointer<QObject> root(component.create()); + QVERIFY(root.data()); + QObject *settings = root->property("settings").value<QObject *>(); + QVERIFY(settings); + + // default property values + QCOMPARE(root->property("intProperty").toInt(), 0); + QCOMPARE(root->property("boolProperty").toBool(), false); + QCOMPARE(root->property("realProperty").toReal(), static_cast<qreal>(0.0)); + QCOMPARE(root->property("doubleProperty").toDouble(), static_cast<double>(0.0)); + QCOMPARE(root->property("stringProperty").toString(), QString()); + QCOMPARE(root->property("urlProperty").toUrl(), QUrl()); + QCOMPARE(root->property("objectProperty").toMap(), QVariantMap()); + QCOMPARE(root->property("intListProperty").toList(), QVariantList()); + QCOMPARE(root->property("stringListProperty").toList(), QVariantList()); + QCOMPARE(root->property("objectListProperty").toList(), QVariantList()); + QCOMPARE(root->property("dateProperty").toDate(), QDate()); + // QTBUG-32295: QCOMPARE(root->property("timeProperty").toDate(), QTime()); + QCOMPARE(root->property("sizeProperty").toSizeF(), QSizeF()); + QCOMPARE(root->property("pointProperty").toPointF(), QPointF()); + QCOMPARE(root->property("rectProperty").toRectF(), QRectF()); + QCOMPARE(root->property("colorProperty").value<QColor>(), QColor()); + QCOMPARE(root->property("fontProperty").value<QFont>(), QFont()); + + // default settings values + QCOMPARE(settings->property("intProperty").toInt(), 123); + QCOMPARE(settings->property("boolProperty").toBool(), true); + QCOMPARE(settings->property("realProperty").toReal(), static_cast<qreal>(1.23)); + QCOMPARE(settings->property("doubleProperty").toDouble(), static_cast<double>(3.45)); + QCOMPARE(settings->property("stringProperty").toString(), QStringLiteral("foo")); + QCOMPARE(settings->property("urlProperty").toUrl(), QUrl("http://www.qt-project.org")); + QCOMPARE(settings->property("objectProperty").toMap(), keyValueMap("foo","bar")); + QCOMPARE(settings->property("intListProperty").toList(), QVariantList() << 1 << 2 << 3); + QCOMPARE(settings->property("stringListProperty").toList(), QVariantList() << QStringLiteral("a") << QStringLiteral("b") << QStringLiteral("c")); + QCOMPARE(settings->property("objectListProperty").toList(), QVariantList() << keyValueMap("a", "b") << keyValueMap("c","d")); + QCOMPARE(settings->property("dateProperty").toDate(), QDate(2000, 01, 02)); + // QTBUG-32295: QCOMPARE(settings->property("timeProperty").toDate(), QTime(12, 34, 56)); + QCOMPARE(settings->property("sizeProperty").toSizeF(), QSizeF(12, 34)); + QCOMPARE(settings->property("pointProperty").toPointF(), QPointF(12, 34)); + QCOMPARE(settings->property("rectProperty").toRectF(), QRectF(1, 2, 3, 4)); + QCOMPARE(settings->property("colorProperty").value<QColor>(), QColor(Qt::red)); + QCOMPARE(settings->property("fontProperty").value<QFont>(), QFont()); + + // read settings + QVERIFY(QMetaObject::invokeMethod(root.data(), "readSettings")); + QCOMPARE(root->property("intProperty").toInt(), 123); + QCOMPARE(root->property("boolProperty").toBool(), true); + QCOMPARE(root->property("realProperty").toReal(), static_cast<qreal>(1.23)); + QCOMPARE(root->property("doubleProperty").toDouble(), static_cast<double>(3.45)); + QCOMPARE(root->property("stringProperty").toString(), QStringLiteral("foo")); + QCOMPARE(root->property("urlProperty").toUrl(), QUrl("http://www.qt-project.org")); + QCOMPARE(root->property("objectProperty").toMap(), keyValueMap("foo","bar")); + QCOMPARE(root->property("intListProperty").toList(), QVariantList() << 1 << 2 << 3); + QCOMPARE(root->property("stringListProperty").toList(), QVariantList() << QStringLiteral("a") << QStringLiteral("b") << QStringLiteral("c")); + QCOMPARE(root->property("dateProperty").toDate(), QDate(2000, 01, 02)); + QCOMPARE(root->property("objectListProperty").toList(), QVariantList() << keyValueMap("a", "b") << keyValueMap("c","d")); + // QTBUG-32295: QCOMPARE(root->property("timeProperty").toDate(), QTime(12, 34, 56)); + QCOMPARE(root->property("sizeProperty").toSizeF(), QSizeF(12, 34)); + QCOMPARE(root->property("pointProperty").toPointF(), QPointF(12, 34)); + QCOMPARE(root->property("rectProperty").toRectF(), QRectF(1, 2, 3, 4)); + QCOMPARE(root->property("colorProperty").value<QColor>(), QColor(Qt::red)); + QCOMPARE(root->property("fontProperty").value<QFont>(), QFont()); + + // change properties + QVERIFY(root->setProperty("intProperty", 456)); + QVERIFY(root->setProperty("boolProperty", false)); + QVERIFY(root->setProperty("realProperty", static_cast<qreal>(4.56))); + QVERIFY(root->setProperty("doubleProperty", static_cast<double>(6.78))); + QVERIFY(root->setProperty("stringProperty", QStringLiteral("bar"))); + QVERIFY(root->setProperty("urlProperty", QUrl("https://codereview.qt-project.org"))); + QVERIFY(root->setProperty("objectProperty", keyValueMap("bar", "baz"))); + QVERIFY(root->setProperty("intListProperty", QVariantList() << 4 << 5 << 6)); + QVERIFY(root->setProperty("stringListProperty", QVariantList() << QStringLiteral("d") << QStringLiteral("e") << QStringLiteral("f"))); + QVERIFY(root->setProperty("objectListProperty", QVariantList() << keyValueMap("e", "f") << keyValueMap("g", "h"))); + QVERIFY(root->setProperty("dateProperty", QDate(2010, 02, 01))); + // QTBUG-32295: QVERIFY(root->setProperty("timeProperty", QTime(6, 56, 34))); + QVERIFY(root->setProperty("sizeProperty", QSizeF(56, 78))); + QVERIFY(root->setProperty("pointProperty", QPointF(56, 78))); + QVERIFY(root->setProperty("rectProperty", QRectF(5, 6, 7, 8))); + QVERIFY(root->setProperty("colorProperty", QColor(Qt::blue))); + QFont boldFont; boldFont.setBold(true); + QVERIFY(root->setProperty("fontProperty", boldFont)); + + // write settings + QVERIFY(QMetaObject::invokeMethod(root.data(), "writeSettings")); + QTRY_COMPARE(settings->property("intProperty").toInt(), 456); + QTRY_COMPARE(settings->property("boolProperty").toBool(), false); + QTRY_COMPARE(settings->property("realProperty").toReal(), static_cast<qreal>(4.56)); + QTRY_COMPARE(settings->property("doubleProperty").toDouble(), static_cast<double>(6.78)); + QTRY_COMPARE(settings->property("stringProperty").toString(), QStringLiteral("bar")); + QTRY_COMPARE(settings->property("urlProperty").toUrl(), QUrl("https://codereview.qt-project.org")); + QTRY_COMPARE(settings->property("objectProperty").toMap(), keyValueMap("bar", "baz")); + QTRY_COMPARE(settings->property("intListProperty").toList(), QVariantList() << 4 << 5 << 6); + QTRY_COMPARE(settings->property("stringListProperty").toList(), QVariantList() << QStringLiteral("d") << QStringLiteral("e") << QStringLiteral("f")); + QTRY_COMPARE(settings->property("objectListProperty").toList(), QVariantList() << keyValueMap("e", "f") << keyValueMap("g", "h")); + QTRY_COMPARE(settings->property("dateProperty").toDate(), QDate(2010, 02, 01)); + // QTBUG-32295: QTRY_COMPARE(settings->property("timeProperty").toDate(), QTime(6, 56, 34)); + QTRY_COMPARE(settings->property("sizeProperty").toSizeF(), QSizeF(56, 78)); + QTRY_COMPARE(settings->property("pointProperty").toPointF(), QPointF(56, 78)); + QTRY_COMPARE(settings->property("rectProperty").toRectF(), QRectF(5, 6, 7, 8)); + QTRY_COMPARE(settings->property("colorProperty").value<QColor>(), QColor(Qt::blue)); + QTRY_COMPARE(settings->property("fontProperty").value<QFont>(), boldFont); + + QSettings qs; + QTRY_COMPARE(qs.value("intProperty").toInt(), 456); + QTRY_COMPARE(qs.value("boolProperty").toBool(), false); + QTRY_COMPARE(qs.value("realProperty").toReal(), static_cast<qreal>(4.56)); + QTRY_COMPARE(qs.value("doubleProperty").toDouble(), static_cast<double>(6.78)); + QTRY_COMPARE(qs.value("stringProperty").toString(), QStringLiteral("bar")); + QTRY_COMPARE(qs.value("urlProperty").toUrl(), QUrl("https://codereview.qt-project.org")); + QTRY_COMPARE(qs.value("objectProperty").toMap(), keyValueMap("bar", "baz")); + QTRY_COMPARE(qs.value("intListProperty").toList(), QVariantList() << 4 << 5 << 6); + QTRY_COMPARE(qs.value("stringListProperty").toList(), QVariantList() << QStringLiteral("d") << QStringLiteral("e") << QStringLiteral("f")); + QTRY_COMPARE(qs.value("objectListProperty").toList(), QVariantList() << keyValueMap("e", "f") << keyValueMap("g", "h")); + QTRY_COMPARE(qs.value("dateProperty").toDate(), QDate(2010, 02, 01)); + // QTBUG-32295: QTRY_COMPARE(qs.value("timeProperty").toDate(), QTime(6, 56, 34)); + QTRY_COMPARE(qs.value("sizeProperty").toSizeF(), QSizeF(56, 78)); + QTRY_COMPARE(qs.value("pointProperty").toPointF(), QPointF(56, 78)); + QTRY_COMPARE(qs.value("rectProperty").toRectF(), QRectF(5, 6, 7, 8)); + QTRY_COMPARE(qs.value("colorProperty").value<QColor>(), QColor(Qt::blue)); + QTRY_COMPARE(qs.value("fontProperty").value<QFont>(), boldFont); +} + +void tst_QQmlSettings::aliases_data() +{ + QTest::addColumn<QString>("testFile"); + QTest::newRow("qml") << "aliases.qml"; + QTest::newRow("cpp") << "cpp-aliases.qml"; +} + +void tst_QQmlSettings::aliases() +{ + QFETCH(QString, testFile); + + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl(testFile)); + QScopedPointer<QObject> root(component.create()); + QVERIFY(root.data()); + QObject *settings = root->property("settings").value<QObject *>(); + QVERIFY(settings); + + // default property values + QCOMPARE(root->property("intProperty").toInt(), 123); + QCOMPARE(root->property("boolProperty").toBool(), true); + QCOMPARE(root->property("realProperty").toReal(), static_cast<qreal>(1.23)); + QCOMPARE(root->property("doubleProperty").toDouble(), static_cast<double>(3.45)); + QCOMPARE(root->property("stringProperty").toString(), QStringLiteral("foo")); + QCOMPARE(root->property("urlProperty").toUrl(), QUrl("http://www.qt-project.org")); + QCOMPARE(root->property("objectProperty").toMap(), keyValueMap("foo","bar")); + QCOMPARE(root->property("intListProperty").toList(), QVariantList() << 1 << 2 << 3); + QCOMPARE(root->property("stringListProperty").toList(), QVariantList() << QStringLiteral("a") << QStringLiteral("b") << QStringLiteral("c")); + QCOMPARE(root->property("objectListProperty").toList(), QVariantList() << keyValueMap("a", "b") << keyValueMap("c","d")); + QCOMPARE(root->property("dateProperty").toDate(), QDate(2000, 01, 02)); + // QTBUG-32295: QCOMPARE(root->property("timeProperty").toDate(), QTime(12, 34, 56)); + QCOMPARE(root->property("sizeProperty").toSizeF(), QSizeF(12, 34)); + QCOMPARE(root->property("pointProperty").toPointF(), QPointF(12, 34)); + QCOMPARE(root->property("rectProperty").toRectF(), QRectF(1, 2, 3, 4)); + QCOMPARE(root->property("colorProperty").value<QColor>(), QColor(Qt::red)); + QCOMPARE(root->property("fontProperty").value<QFont>(), QFont()); + + // default settings values + QCOMPARE(settings->property("intProperty").toInt(), 123); + QCOMPARE(settings->property("boolProperty").toBool(), true); + QCOMPARE(settings->property("realProperty").toReal(), static_cast<qreal>(1.23)); + QCOMPARE(settings->property("doubleProperty").toDouble(), static_cast<double>(3.45)); + QCOMPARE(settings->property("stringProperty").toString(), QStringLiteral("foo")); + QCOMPARE(settings->property("urlProperty").toUrl(), QUrl("http://www.qt-project.org")); + QCOMPARE(settings->property("objectProperty").toMap(), keyValueMap("foo","bar")); + QCOMPARE(settings->property("intListProperty").toList(), QVariantList() << 1 << 2 << 3); + QCOMPARE(settings->property("stringListProperty").toList(), QVariantList() << QStringLiteral("a") << QStringLiteral("b") << QStringLiteral("c")); + QCOMPARE(settings->property("objectListProperty").toList(), QVariantList() << keyValueMap("a", "b") << keyValueMap("c","d")); + QCOMPARE(settings->property("dateProperty").toDate(), QDate(2000, 01, 02)); + // QTBUG-32295: QCOMPARE(settings->property("timeProperty").toDate(), QTime(12, 34, 56)); + QCOMPARE(settings->property("sizeProperty").toSizeF(), QSizeF(12, 34)); + QCOMPARE(settings->property("pointProperty").toPointF(), QPointF(12, 34)); + QCOMPARE(settings->property("rectProperty").toRectF(), QRectF(1, 2, 3, 4)); + QCOMPARE(settings->property("colorProperty").value<QColor>(), QColor(Qt::red)); + QCOMPARE(settings->property("fontProperty").value<QFont>(), QFont()); + + // change settings + QVERIFY(settings->setProperty("intProperty", 456)); + QVERIFY(settings->setProperty("boolProperty", false)); + QVERIFY(settings->setProperty("realProperty", static_cast<qreal>(4.56))); + QVERIFY(settings->setProperty("doubleProperty", static_cast<double>(6.78))); + QVERIFY(settings->setProperty("stringProperty", QStringLiteral("bar"))); + QVERIFY(settings->setProperty("urlProperty", QUrl("https://codereview.qt-project.org"))); + QVERIFY(settings->setProperty("objectProperty", keyValueMap("bar", "baz"))); + QVERIFY(settings->setProperty("intListProperty", QVariantList() << 4 << 5 << 6)); + QVERIFY(settings->setProperty("stringListProperty", QVariantList() << QStringLiteral("d") << QStringLiteral("e") << QStringLiteral("f"))); + QVERIFY(settings->setProperty("objectListProperty", QVariantList() << keyValueMap("e", "f") << keyValueMap("g", "h"))); + QVERIFY(settings->setProperty("dateProperty", QDate(2010, 02, 01))); + // QTBUG-32295: QVERIFY(settings->setProperty("timeProperty", QTime(6, 56, 34))); + QVERIFY(settings->setProperty("sizeProperty", QSizeF(56, 78))); + QVERIFY(settings->setProperty("pointProperty", QPointF(56, 78))); + QVERIFY(settings->setProperty("rectProperty", QRectF(5, 6, 7, 8))); + QVERIFY(settings->setProperty("colorProperty", QColor(Qt::blue))); + QFont boldFont; boldFont.setBold(true); + QVERIFY(settings->setProperty("fontProperty", boldFont)); + + QSettings qs; + QTRY_COMPARE(qs.value("intProperty").toInt(), 456); + QTRY_COMPARE(qs.value("boolProperty").toBool(), false); + QTRY_COMPARE(qs.value("realProperty").toReal(), static_cast<qreal>(4.56)); + QTRY_COMPARE(qs.value("doubleProperty").toDouble(), static_cast<double>(6.78)); + QTRY_COMPARE(qs.value("stringProperty").toString(), QStringLiteral("bar")); + QTRY_COMPARE(qs.value("urlProperty").toUrl(), QUrl("https://codereview.qt-project.org")); + QTRY_COMPARE(qs.value("objectProperty").toMap(), keyValueMap("bar", "baz")); + QTRY_COMPARE(qs.value("intListProperty").toList(), QVariantList() << 4 << 5 << 6); + QTRY_COMPARE(qs.value("stringListProperty").toList(), QVariantList() << QStringLiteral("d") << QStringLiteral("e") << QStringLiteral("f")); + QTRY_COMPARE(qs.value("objectListProperty").toList(), QVariantList() << keyValueMap("e", "f") << keyValueMap("g", "h")); + QTRY_COMPARE(qs.value("dateProperty").toDate(), QDate(2010, 02, 01)); + // QTBUG-32295: QTRY_COMPARE(qs.value("timeProperty").toDate(), QTime(6, 56, 34)); + QTRY_COMPARE(qs.value("sizeProperty").toSizeF(), QSizeF(56, 78)); + QTRY_COMPARE(qs.value("pointProperty").toPointF(), QPointF(56, 78)); + QTRY_COMPARE(qs.value("rectProperty").toRectF(), QRectF(5, 6, 7, 8)); + QTRY_COMPARE(qs.value("colorProperty").value<QColor>(), QColor(Qt::blue)); + QTRY_COMPARE(qs.value("fontProperty").value<QFont>(), boldFont); +} + +void tst_QQmlSettings::categories() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("categories.qml")); + + { + // initial state + QSettings qs; + QVERIFY(!qs.childGroups().contains("initialCategory")); + QVERIFY(!qs.childGroups().contains("changedCategory")); + QVERIFY(!qs.childKeys().contains("value")); + } + + { + // load & write default values + QScopedPointer<QObject> settings(component.create()); + QVERIFY(settings.data()); + QCOMPARE(settings->property("category").toString(), QStringLiteral("initialCategory")); + QCOMPARE(settings->property("value").toString(), QStringLiteral("initialValue")); + } + + { + // verify written settings & change the value + QSettings qs; + QVERIFY(qs.childGroups().contains("initialCategory")); + qs.beginGroup("initialCategory"); + QVERIFY(qs.childKeys().contains("value")); + QCOMPARE(qs.value("value").toString(), QStringLiteral("initialValue")); + qs.setValue("value", QStringLiteral("changedValue")); + } + + { + // load changed value & change the category + QScopedPointer<QObject> settings(component.create()); + QVERIFY(settings.data()); + QCOMPARE(settings->property("category").toString(), QStringLiteral("initialCategory")); + QCOMPARE(settings->property("value").toString(), QStringLiteral("changedValue")); + QVERIFY(settings->setProperty("category", QStringLiteral("changedCategory"))); + } + + { + // verify written settings + QSettings qs; + QVERIFY(qs.childGroups().contains("changedCategory")); + qs.beginGroup("changedCategory"); + QVERIFY(qs.childKeys().contains("value")); + QCOMPARE(qs.value("value").toString(), QStringLiteral("changedValue")); + qs.setValue("value", QStringLiteral("changedValue")); + qs.endGroup(); + } +} + +void tst_QQmlSettings::siblings() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("siblings.qml")); + delete component.create(); + + // verify setting aliases to destructed siblings + QSettings settings; + QCOMPARE(settings.value("alias1").toString(), QStringLiteral("value1")); + QCOMPARE(settings.value("alias2").toString(), QStringLiteral("value2")); +} + +void tst_QQmlSettings::initial() +{ + QSettings qs; + qs.setValue("value", QStringLiteral("initial")); + qs.sync(); + + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import QtQml; import QtCore; Settings { property var value }", QUrl()); + QScopedPointer<QObject> settings(component.create()); + QVERIFY(settings.data()); + + // verify that the initial value from QSettings gets properly loaded + // even if no initial value is set in QML + QCOMPARE(settings->property("value").toString(), QStringLiteral("initial")); +} + +void tst_QQmlSettings::noApplicationIdentifiersSet() +{ +#ifdef Q_OS_MACOS + QSKIP("macOS doesn't complain about empty application identifiers"); +#endif + + QCoreApplication::setApplicationName(QString()); + QCoreApplication::setOrganizationName(QString()); + QCoreApplication::setOrganizationDomain(QString()); + + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*QML Settings: Failed to initialize QSettings instance. Status code is: 1")); + // Can't set an empty applicationName because QCoreApplication won't allow it, which is why it's not listed here. + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*QML Settings: The following application identifiers have not been set: QList\\(\"organizationName\", \"organizationDomain\"\\)")); + + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("basic.qml")); + QScopedPointer<QObject> root(component.create()); + QVERIFY(root.data()); + // The value of the QML property will be true because it defaults to it... + QVERIFY(root->property("success").toBool()); + QSettings settings; + // ... but the settings' value should be false because it was never loaded. + QVERIFY(!settings.value("success").toBool()); +} + +QTEST_MAIN(tst_QQmlSettings) + +#include "tst_qqmlsettings.moc" diff --git a/tests/auto/core/qqmlstandardpaths/CMakeLists.txt b/tests/auto/core/qqmlstandardpaths/CMakeLists.txt new file mode 100644 index 0000000000..6b09bf718a --- /dev/null +++ b/tests/auto/core/qqmlstandardpaths/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/data/tst_*) +list(APPEND test_data ${test_data_glob}) + +qt_internal_add_test(tst_qqmlstandardpaths + GUI + QMLTEST + SOURCES + tst_qqmlstandardpaths.cpp + LIBRARIES + Qt::CorePrivate + Qt::QmlPrivate + Qt::QuickTestUtilsPrivate + TESTDATA ${test_data} +) + +if(QT_BUILD_STANDALONE_TESTS) + qt_import_qml_plugins(tst_qqmlstandardpaths) +endif() + +qt_internal_extend_target(tst_qqmlstandardpaths CONDITION ANDROID OR IOS + DEFINES + QT_QMLTEST_DATADIR=\\\":/data\\\" +) + +qt_internal_extend_target(tst_qqmlstandardpaths CONDITION NOT ANDROID AND NOT IOS + DEFINES + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" +) diff --git a/tests/auto/core/qqmlstandardpaths/data/tst_standardpaths.qml b/tests/auto/core/qqmlstandardpaths/data/tst_standardpaths.qml new file mode 100644 index 0000000000..afc196e92a --- /dev/null +++ b/tests/auto/core/qqmlstandardpaths/data/tst_standardpaths.qml @@ -0,0 +1,32 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQml +import QtCore + +QtObject { + // Q_ENUM(QStandardPaths::StandardLocation) + property int desktop: StandardPaths.DesktopLocation + property int documents: StandardPaths.DocumentsLocation + property int fonts: StandardPaths.FontsLocation + property int applications: StandardPaths.ApplicationsLocation + property int music: StandardPaths.MusicLocation + property int movies: StandardPaths.MoviesLocation + property int pictures: StandardPaths.PicturesLocation + property int temp: StandardPaths.TempLocation + property int home: StandardPaths.HomeLocation + property int appLocalData: StandardPaths.AppLocalDataLocation + property int cache: StandardPaths.CacheLocation + property int genericData: StandardPaths.GenericDataLocation + property int runtime: StandardPaths.RuntimeLocation + property int config: StandardPaths.ConfigLocation + property int download: StandardPaths.DownloadLocation + property int genericCache: StandardPaths.GenericCacheLocation + property int genericConfig: StandardPaths.GenericConfigLocation + property int appData: StandardPaths.AppDataLocation + property int appConfig: StandardPaths.AppConfigLocation + + // Q_ENUMS(QStandardPaths::LocateOptions) + property int locateFile: StandardPaths.LocateFile + property int locateDirectory: StandardPaths.LocateDirectory +} diff --git a/tests/auto/core/qqmlstandardpaths/tst_qqmlstandardpaths.cpp b/tests/auto/core/qqmlstandardpaths/tst_qqmlstandardpaths.cpp new file mode 100644 index 0000000000..9c66bb25cf --- /dev/null +++ b/tests/auto/core/qqmlstandardpaths/tst_qqmlstandardpaths.cpp @@ -0,0 +1,53 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include <QQmlEngine> +#include <QQmlComponent> +#include <QtQuickTestUtils/private/qmlutils_p.h> +#include <QtCore/qstandardpaths.h> + +class tst_qqmlstandardpaths : public QQmlDataTest +{ + Q_OBJECT + +public: + explicit tst_qqmlstandardpaths() : QQmlDataTest(QT_QMLTEST_DATADIR) {} + +private Q_SLOTS: + void standardPaths(); +}; + +void tst_qqmlstandardpaths::standardPaths() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("tst_standardpaths.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + QCOMPARE(object->property("desktop").toInt(), QStandardPaths::DesktopLocation); + QCOMPARE(object->property("documents").toInt(), QStandardPaths::DocumentsLocation); + QCOMPARE(object->property("fonts").toInt(), QStandardPaths::FontsLocation); + QCOMPARE(object->property("applications").toInt(), QStandardPaths::ApplicationsLocation); + QCOMPARE(object->property("music").toInt(), QStandardPaths::MusicLocation); + QCOMPARE(object->property("movies").toInt(), QStandardPaths::MoviesLocation); + QCOMPARE(object->property("pictures").toInt(), QStandardPaths::PicturesLocation); + QCOMPARE(object->property("temp").toInt(), QStandardPaths::TempLocation); + QCOMPARE(object->property("home").toInt(), QStandardPaths::HomeLocation); + QCOMPARE(object->property("appLocalData").toInt(), QStandardPaths::AppLocalDataLocation); + QCOMPARE(object->property("cache").toInt(), QStandardPaths::CacheLocation); + QCOMPARE(object->property("genericData").toInt(), QStandardPaths::GenericDataLocation); + QCOMPARE(object->property("runtime").toInt(), QStandardPaths::RuntimeLocation); + QCOMPARE(object->property("config").toInt(), QStandardPaths::ConfigLocation); + QCOMPARE(object->property("download").toInt(), QStandardPaths::DownloadLocation); + QCOMPARE(object->property("genericCache").toInt(), QStandardPaths::GenericCacheLocation); + QCOMPARE(object->property("genericConfig").toInt(), QStandardPaths::GenericConfigLocation); + QCOMPARE(object->property("appData").toInt(), QStandardPaths::AppDataLocation); + QCOMPARE(object->property("appConfig").toInt(), QStandardPaths::AppConfigLocation); + QCOMPARE(object->property("locateFile").toInt(), QStandardPaths::LocateFile); + QCOMPARE(object->property("locateDirectory").toInt(), QStandardPaths::LocateDirectory); +} + +QTEST_MAIN(tst_qqmlstandardpaths) + +#include "tst_qqmlstandardpaths.moc" diff --git a/tests/auto/core/qqmlsysteminformation/CMakeLists.txt b/tests/auto/core/qqmlsysteminformation/CMakeLists.txt new file mode 100644 index 0000000000..d8037a0b49 --- /dev/null +++ b/tests/auto/core/qqmlsysteminformation/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/data/tst_*) +list(APPEND test_data ${test_data_glob}) + +qt_internal_add_test(tst_qqmlsysteminformation + GUI + QMLTEST + SOURCES + tst_qqmlsysteminformation.cpp + LIBRARIES + Qt::CorePrivate + Qt::QmlPrivate + Qt::QuickTestUtilsPrivate + TESTDATA ${test_data} +) + +if(QT_BUILD_STANDALONE_TESTS) + qt_import_qml_plugins(tst_qqmlsysteminformation) +endif() + +qt_internal_extend_target(tst_qqmlsysteminformation CONDITION ANDROID OR IOS + DEFINES + QT_QMLTEST_DATADIR=\\\":/data\\\" +) + +qt_internal_extend_target(tst_qqmlsysteminformation CONDITION NOT ANDROID AND NOT IOS + DEFINES + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" +) diff --git a/tests/auto/core/data/tst_systeminformation.qml b/tests/auto/core/qqmlsysteminformation/data/tst_systeminformation.qml index afc53dde54..afc53dde54 100644 --- a/tests/auto/core/data/tst_systeminformation.qml +++ b/tests/auto/core/qqmlsysteminformation/data/tst_systeminformation.qml diff --git a/tests/auto/core/tst_core.cpp b/tests/auto/core/qqmlsysteminformation/tst_qqmlsysteminformation.cpp index 18e54448cc..5a743dee0c 100644 --- a/tests/auto/core/tst_core.cpp +++ b/tests/auto/core/qqmlsysteminformation/tst_qqmlsysteminformation.cpp @@ -6,18 +6,18 @@ #include <QtCore/qsysinfo.h> #include <QtQuickTestUtils/private/qmlutils_p.h> -class tst_core : public QQmlDataTest +class tst_qqmlsysteminformation : public QQmlDataTest { Q_OBJECT public: - explicit tst_core() : QQmlDataTest(QT_QMLTEST_DATADIR) {} + explicit tst_qqmlsysteminformation() : QQmlDataTest(QT_QMLTEST_DATADIR) {} private Q_SLOTS: void systemInformation(); }; -void tst_core::systemInformation() +void tst_qqmlsysteminformation::systemInformation() { QQmlEngine engine; QQmlComponent component(&engine, testFileUrl("tst_systeminformation.qml")); @@ -40,6 +40,6 @@ void tst_core::systemInformation() QCOMPARE(object->property("bootUniqueId").toByteArray(), QSysInfo::bootUniqueId()); } -QTEST_MAIN(tst_core) +QTEST_MAIN(tst_qqmlsysteminformation) -#include "tst_core.moc" +#include "tst_qqmlsysteminformation.moc" diff --git a/tests/auto/qml/qqmlsettings/CMakeLists.txt b/tests/auto/qml/qqmlsettings/CMakeLists.txt index d355285f04..0d4b45e55e 100644 --- a/tests/auto/qml/qqmlsettings/CMakeLists.txt +++ b/tests/auto/qml/qqmlsettings/CMakeLists.txt @@ -4,7 +4,7 @@ # Generated from qqmlsettings.pro. ##################################################################### -## tst_qqmlsettings Test: +## tst_qqmlsettings_labs Test: ##################################################################### # Collect test data @@ -13,7 +13,7 @@ file(GLOB_RECURSE test_data_glob data/*) list(APPEND test_data ${test_data_glob}) -qt_internal_add_test(tst_qqmlsettings +qt_internal_add_test(tst_qqmlsettings_labs SOURCES tst_qqmlsettings.cpp LIBRARIES @@ -26,12 +26,12 @@ qt_internal_add_test(tst_qqmlsettings ## Scopes: ##################################################################### -qt_internal_extend_target(tst_qqmlsettings CONDITION ANDROID OR IOS +qt_internal_extend_target(tst_qqmlsettings_labs CONDITION ANDROID OR IOS DEFINES QT_QMLTEST_DATADIR=\\\":/data\\\" ) -qt_internal_extend_target(tst_qqmlsettings CONDITION NOT ANDROID AND NOT IOS +qt_internal_extend_target(tst_qqmlsettings_labs CONDITION NOT ANDROID AND NOT IOS DEFINES QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" ) diff --git a/tests/auto/quickcontrols2/controls/basic/dummy_imports.qml b/tests/auto/quickcontrols2/controls/basic/dummy_imports.qml index 580db56d12..66e184f138 100644 --- a/tests/auto/quickcontrols2/controls/basic/dummy_imports.qml +++ b/tests/auto/quickcontrols2/controls/basic/dummy_imports.qml @@ -3,10 +3,10 @@ // Otherwise, it fails to find the imports that are expressed in C++. import QtQml +import QtCore import QtQuick import QtQuick.NativeStyle import QtQuick.Layouts -import Qt.labs.settings import Qt.labs.qmlmodels QtObject { } diff --git a/tests/auto/quickcontrols2/controls/data/tst_splitview.qml b/tests/auto/quickcontrols2/controls/data/tst_splitview.qml index ec4e94768e..8d9c1dcc81 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_splitview.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_splitview.qml @@ -1,11 +1,11 @@ -// Copyright (C) 2018 The Qt Company Ltd. +// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtCore import QtQuick import QtQuick.Controls import QtQuick.Window import QtTest -import Qt.labs.settings import Qt.test.controls TestCase { diff --git a/tests/auto/quickcontrols2/controls/fusion/dummy_imports.qml b/tests/auto/quickcontrols2/controls/fusion/dummy_imports.qml index 580db56d12..66e184f138 100644 --- a/tests/auto/quickcontrols2/controls/fusion/dummy_imports.qml +++ b/tests/auto/quickcontrols2/controls/fusion/dummy_imports.qml @@ -3,10 +3,10 @@ // Otherwise, it fails to find the imports that are expressed in C++. import QtQml +import QtCore import QtQuick import QtQuick.NativeStyle import QtQuick.Layouts -import Qt.labs.settings import Qt.labs.qmlmodels QtObject { } diff --git a/tests/auto/quickcontrols2/controls/imagine/dummy_imports.qml b/tests/auto/quickcontrols2/controls/imagine/dummy_imports.qml index 580db56d12..66e184f138 100644 --- a/tests/auto/quickcontrols2/controls/imagine/dummy_imports.qml +++ b/tests/auto/quickcontrols2/controls/imagine/dummy_imports.qml @@ -3,10 +3,10 @@ // Otherwise, it fails to find the imports that are expressed in C++. import QtQml +import QtCore import QtQuick import QtQuick.NativeStyle import QtQuick.Layouts -import Qt.labs.settings import Qt.labs.qmlmodels QtObject { } diff --git a/tests/auto/quickcontrols2/controls/material/dummy_imports.qml b/tests/auto/quickcontrols2/controls/material/dummy_imports.qml index 580db56d12..66e184f138 100644 --- a/tests/auto/quickcontrols2/controls/material/dummy_imports.qml +++ b/tests/auto/quickcontrols2/controls/material/dummy_imports.qml @@ -3,10 +3,10 @@ // Otherwise, it fails to find the imports that are expressed in C++. import QtQml +import QtCore import QtQuick import QtQuick.NativeStyle import QtQuick.Layouts -import Qt.labs.settings import Qt.labs.qmlmodels QtObject { } diff --git a/tests/auto/quickcontrols2/controls/universal/dummy_imports.qml b/tests/auto/quickcontrols2/controls/universal/dummy_imports.qml index 580db56d12..66e184f138 100644 --- a/tests/auto/quickcontrols2/controls/universal/dummy_imports.qml +++ b/tests/auto/quickcontrols2/controls/universal/dummy_imports.qml @@ -3,10 +3,10 @@ // Otherwise, it fails to find the imports that are expressed in C++. import QtQml +import QtCore import QtQuick import QtQuick.NativeStyle import QtQuick.Layouts -import Qt.labs.settings import Qt.labs.qmlmodels QtObject { } diff --git a/tests/manual/quickcontrols2/testbench/testbench.qml b/tests/manual/quickcontrols2/testbench/testbench.qml index 379992f56d..c9185e35d0 100644 --- a/tests/manual/quickcontrols2/testbench/testbench.qml +++ b/tests/manual/quickcontrols2/testbench/testbench.qml @@ -1,12 +1,12 @@ -// Copyright (C) 2017 The Qt Company Ltd. +// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtCore import QtQuick import QtQuick.Window import QtQuick.Layouts import QtQuick.Controls import Qt.labs.folderlistmodel -import Qt.labs.settings import Backend import "." as Ui diff --git a/tests/manual/quickdialogs/dialogs/dialogs.qml b/tests/manual/quickdialogs/dialogs/dialogs.qml index c044d068e8..cd0c2e7e7f 100644 --- a/tests/manual/quickdialogs/dialogs/dialogs.qml +++ b/tests/manual/quickdialogs/dialogs/dialogs.qml @@ -1,12 +1,11 @@ -// Copyright (C) 2021 The Qt Company Ltd. +// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +import QtCore import QtQuick import QtQuick.Controls import QtQuick.Layouts -import Qt.labs.settings - ApplicationWindow { id: window width: 800 diff --git a/tests/testapplications/listview/sticky.qml b/tests/testapplications/listview/sticky.qml index 81e4f0729f..e617b3cbfe 100644 --- a/tests/testapplications/listview/sticky.qml +++ b/tests/testapplications/listview/sticky.qml @@ -1,12 +1,11 @@ -// Copyright (C) 2017 The Qt Company Ltd. +// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick 2.4 -import QtQuick.Window 2.1 -import QtQuick.Layouts 1.1 -import QtQuick.Controls 1.1 -import QtQuick.Controls.Styles 1.1 -import Qt.labs.settings 1.0 +import QtCore +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls +import QtQuick.Controls.Styles ApplicationWindow { id: window |