From 467749ce994e7ee394faf2ab3a57b9cbb7103f48 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 2 Feb 2024 12:39:03 +0100 Subject: [PATCH] Long live QT_TECH_PREVIEW_API A macro to mark tech preview APIs, in order to make header reviews easier: * newly introduced TP APIs are clearly marked as such; * an API that leaves TP and becomes stable requires to change the header, and not just the documentation (and therefore will again appear in the header review). The idea is to use this macro as if it were a C++ attribute. It can't actually be an attribute, because we want to use it to tag e.g. macro expansions (like Q_PROPERTY). Change-Id: I05c5a91a4fa5bedfbd1c6146d4dc00e1d1d28628 Reviewed-by: Volker Hilsheimer (cherry picked from commit 32a1151245034e4d5d3162df21518e38b6f81fcd) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/global/qtversionchecks.h | 39 +++++++++++++++++++++++++ tests/auto/tools/moc/tech-preview.h | 43 ++++++++++++++++++++++++++++ tests/auto/tools/moc/tst_moc.cpp | 2 ++ 3 files changed, 84 insertions(+) create mode 100644 tests/auto/tools/moc/tech-preview.h diff --git a/src/corelib/global/qtversionchecks.h b/src/corelib/global/qtversionchecks.h index 7b5d99af869..14df2780d85 100644 --- a/src/corelib/global/qtversionchecks.h +++ b/src/corelib/global/qtversionchecks.h @@ -72,4 +72,43 @@ # define QT6_CALL_NEW_OVERLOAD_TAIL QT6_ONLY(, QT6_CALL_NEW_OVERLOAD) #endif +/* + Macro to tag Tech Preview APIs. + It expands to nothing, because we want to use it in places where + nothing is generally allowed (not even an attribute); for instance: + to tag other macros, Q_PROPERTY declarations, and so on. + + Still: use it as if it were an C++ attribute. + + To mark a class as TP: + class QT_TECH_PREVIEW_API Q_CORE_EXPORT QClass { ... }; + + To mark a function: + QT_TECH_PREVIEW_API void qFunction(); + + To mark an enumeration or enumerator: + enum class QT_TECH_PREVIEW_API QEnum { + Enum1, + Enum2 QT_TECH_PREVIEW_API, + }; + + To mark parts of a class: + class QClass : public QObject + { + Q_OBJECT + + QT_TECH_PREVIEW_API + Q_PROPERTY(int countNG ...) // this is TP + + Q_PROPERTY(int count ...) // this is stable API + + public: + QT_TECH_PREVIEW_API + void f(); // TP + + void g(); // stable + }; +*/ +#define QT_TECH_PREVIEW_API + #endif /* QTVERSIONCHECKS_H */ diff --git a/tests/auto/tools/moc/tech-preview.h b/tests/auto/tools/moc/tech-preview.h new file mode 100644 index 00000000000..8f285048e4e --- /dev/null +++ b/tests/auto/tools/moc/tech-preview.h @@ -0,0 +1,43 @@ +// Copyright (C) 2024 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef TECH_PREVIEW_H +#define TECH_PREVIEW_H + +#include + +class QT_TECH_PREVIEW_API MyTechPreviewObject : public QObject +{ + QT_TECH_PREVIEW_API + Q_OBJECT + + QT_TECH_PREVIEW_API + Q_PROPERTY(int status MEMBER m_status) + + int m_status = 0; + +public: + void myMethod() {} + QT_TECH_PREVIEW_API void myTPMethod() {} + + Q_INVOKABLE QT_TECH_PREVIEW_API void myTPInvokable1() {} + QT_TECH_PREVIEW_API Q_INVOKABLE void myTPInvokable2() {} + + enum class QT_TECH_PREVIEW_API MyTechPreviewEnum + { + A, B, C, + TP QT_TECH_PREVIEW_API, + X, Y, Z + }; + +signals: + void mySignal(); + QT_TECH_PREVIEW_API void myTPSignal(); + +public Q_SLOTS: + void mySlot() {} + QT_TECH_PREVIEW_API void myTPSlot() {} +}; + + +#endif // TECH_PREVIEW_H diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 3fe170a9a70..a671d92dade 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -62,6 +62,8 @@ #include "qmlmacro.h" +#include "tech-preview.h" + using namespace Qt::StringLiterals; #ifdef Q_MOC_RUN