Add QML_EXTRA_VERSION for adding extra QML versions

Currently internal, as the only user might be qtcharts.

Change-Id: I40fc5295de6375c082d82ebeeb73bf4cd6dc7e4a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Fabian Kosmale 2021-06-02 16:12:43 +02:00
parent ba2928c787
commit 4386de70cb
9 changed files with 211 additions and 6 deletions

View File

@ -355,6 +355,17 @@
\sa QML_ELEMENT, QML_NAMED_ELEMENT()
*/
/*!
\internal
\macro QML_EXTRA_VERSION(MAJOR, MINOR)
\relates QQmlEngine
Declare that the type should also be available in version \c MAJOR.MINOR.
This can be helpful if a type should be available in multiple major versions.
\sa QML_ELEMENT, QML_ADDED_IN_MINOR_VERSION
*/
/*!
\macro QML_ATTACHED(ATTACHED_TYPE)
\relates QQmlEngine

View File

@ -471,8 +471,10 @@ int QQmlPrivate::qmlregister(RegistrationType type, void *data)
QTypeRevision::fromMinorVersion(0));
const QTypeRevision removed = revisionClassInfo(
type.classInfoMetaObject, "QML.RemovedInVersion");
const QList<QTypeRevision> furtherRevisions = revisionClassInfos(type.classInfoMetaObject,
"QML.ExtraVersion");
auto revisions = prepareRevisions(type.metaObject, added);
auto revisions = prepareRevisions(type.metaObject, added) + furtherRevisions;
if (type.attachedPropertiesMetaObject)
revisions += availableRevisions(type.attachedPropertiesMetaObject);
uniqueRevisions(&revisions, type.version, added);
@ -524,8 +526,10 @@ int QQmlPrivate::qmlregister(RegistrationType type, void *data)
QTypeRevision::fromMinorVersion(0));
const QTypeRevision removed = revisionClassInfo(
type.classInfoMetaObject, "QML.RemovedInVersion");
const QList<QTypeRevision> furtherRevisions = revisionClassInfos(type.classInfoMetaObject,
"QML.ExtraVersion");
auto revisions = prepareRevisions(type.instanceMetaObject, added);
auto revisions = prepareRevisions(type.instanceMetaObject, added) + furtherRevisions;
uniqueRevisions(&revisions, type.version, added);
for (QTypeRevision revision : qAsConst(revisions)) {
@ -569,8 +573,9 @@ int QQmlPrivate::qmlregister(RegistrationType type, void *data)
QTypeRevision::fromMinorVersion(0));
const QTypeRevision removed = revisionClassInfo(
type.classInfoMetaObject, "QML.RemovedInVersion");
QVector<QTypeRevision> revisions = { added };
QList<QTypeRevision> revisions = revisionClassInfos(type.classInfoMetaObject,
"QML.ExtraVersion");
revisions.append(added);
uniqueRevisions(&revisions, type.version, added);
for (QTypeRevision revision : qAsConst(revisions)) {

View File

@ -724,13 +724,16 @@ namespace QQmlPrivate
bool alreadyCalled = false;
};
static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key)
static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset = -1)
{
if (!metaObject || !key)
return -1;
const int offset = metaObject->classInfoOffset();
for (int i = metaObject->classInfoCount() + offset - 1; i >= offset; --i)
const int start = (startOffset == -1)
? (metaObject->classInfoCount() + offset - 1)
: startOffset;
for (int i = start; i >= offset; --i)
if (qstrcmp(key, metaObject->classInfo(i).name()) == 0) {
return i;
}
@ -751,6 +754,17 @@ namespace QQmlPrivate
QByteArray(metaObject->classInfo(index).value()).toInt());
}
inline QList<QTypeRevision> revisionClassInfos(const QMetaObject *metaObject, const char *key)
{
QList<QTypeRevision> revisions;
for (int index = indexOfOwnClassInfo(metaObject, key); index != -1;
index = indexOfOwnClassInfo(metaObject, key, index - 1)) {
revisions.push_back(QTypeRevision::fromEncodedVersion(
QByteArray(metaObject->classInfo(index).value()).toInt()));
}
return revisions;
}
inline bool boolClassInfo(const QMetaObject *metaObject, const char *key,
bool defaultValue = false)
{

View File

@ -89,6 +89,9 @@ QT_BEGIN_NAMESPACE
#define QML_ADDED_IN_VERSION(MAJOR, MINOR) \
Q_CLASSINFO("QML.AddedInVersion", Q_REVISION(MAJOR, MINOR))
#define QML_EXTRA_VERSION(MAJOR, MINOR) \
Q_CLASSINFO("QML.ExtraVersion", Q_REVISION(MAJOR, MINOR))
#define QML_REMOVED_IN_MINOR_VERSION(VERSION) \
Q_CLASSINFO("QML.RemovedInVersion", Q_REVISION(VERSION))

View File

@ -5,6 +5,7 @@ qt_exclude_tool_directories_from_default_target(
qmlplugindump
)
add_subdirectory(registrationmacros)
add_subdirectory(parserstress)
add_subdirectory(qjsprimitivevalue)
add_subdirectory(qjsvalueiterator)

View File

@ -0,0 +1,17 @@
qt_internal_add_test(tst_registrationmacros
SOURCES
tst_registrationmacros.cpp
types.h
types.cpp
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::QmlPrivate
)
set_target_properties(tst_registrationmacros PROPERTIES
QT_QML_MODULE_VERSION 6.2
QT_QML_MODULE_URI test
)
qt6_qml_type_registration(tst_registrationmacros)

View File

@ -0,0 +1,74 @@
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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 General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** 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-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <qtest.h>
#include <QObject>
#include <QQmlComponent>
#include <QQmlEngine>
#include "types.h"
class tst_registrationmacros : public QObject
{
Q_OBJECT
private slots:
void checkExtraVersions_data();
void checkExtraVersions();
};
void tst_registrationmacros::checkExtraVersions_data()
{
QTest::addColumn<int>("major");
QTest::addColumn<int>("minor");
QTest::addColumn<bool>("shouldWork");
QTest::addRow("1.1") << 1 << 1 << true;
QTest::addRow("2.0") << 2 << 0 << true;
QTest::addRow("3.0") << 3 << 0 << true;
QTest::addRow("6.2") << 6 << 2 << true;
}
void tst_registrationmacros::checkExtraVersions()
{
QFETCH(int, minor);
QFETCH(int, major);
QQmlEngine engine;
QQmlComponent component(&engine);
QString data = QString::asprintf("import test %d.%d\n Test {}", major, minor);
component.setData(data.toUtf8(), QUrl());
QScopedPointer<QObject> root(component.create());
QVERIFY2(!component.isError(), qPrintable(component.errorString()));
QVERIFY(qobject_cast<Test *>(root.get()));
}
QTEST_GUILESS_MAIN(tst_registrationmacros)
#include "tst_registrationmacros.moc"

View File

@ -0,0 +1,33 @@
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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 General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** 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-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "types.h"
bool Test::check() const
{
return true;
}

View File

@ -0,0 +1,47 @@
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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 General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** 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-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef TYPES_H
#define TYPES_H
#include <qqmlregistration.h>
#include <QObject>
class Test : public QObject {
Q_OBJECT
QML_ELEMENT
QML_ADDED_IN_VERSION(1, 1)
QML_EXTRA_VERSION(2, 0)
QML_EXTRA_VERSION(3, 0)
public:
Q_INVOKABLE bool check() const;
};
#endif