From 983432effdae888a372d814ff9516abbcb7a3c29 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 3 Jan 2020 15:03:39 +0100 Subject: Introduce Q_MOC_INCLUDE A new macro that can be added in the header file parsed by moc to tell moc to include that file in the generated file Change-Id: I03ad702c3fcd8380371015f226ee4b7456daf132 Reviewed-by: Thiago Macieira --- tests/auto/tools/moc/allmocs_baseline_in.json | 59 +++++++++++++++++++++ tests/auto/tools/moc/fwdclass1.h | 38 ++++++++++++++ tests/auto/tools/moc/fwdclass2.h | 38 ++++++++++++++ tests/auto/tools/moc/fwdclass3.h | 38 ++++++++++++++ tests/auto/tools/moc/moc.pro | 3 +- tests/auto/tools/moc/moc_include.h | 74 +++++++++++++++++++++++++++ tests/auto/tools/moc/tst_moc.cpp | 33 ++++++++++-- 7 files changed, 279 insertions(+), 4 deletions(-) create mode 100644 tests/auto/tools/moc/fwdclass1.h create mode 100644 tests/auto/tools/moc/fwdclass2.h create mode 100644 tests/auto/tools/moc/fwdclass3.h create mode 100644 tests/auto/tools/moc/moc_include.h (limited to 'tests') diff --git a/tests/auto/tools/moc/allmocs_baseline_in.json b/tests/auto/tools/moc/allmocs_baseline_in.json index c8abba6a8f..2a70a52587 100644 --- a/tests/auto/tools/moc/allmocs_baseline_in.json +++ b/tests/auto/tools/moc/allmocs_baseline_in.json @@ -1012,6 +1012,65 @@ "inputFile": "grand-parent-gadget-class.h", "outputRevision": 67 }, + { + "classes": [ + { + "className": "TestFwdProperties", + "properties": [ + { + "constant": false, + "designable": true, + "final": false, + "name": "prop1", + "read": "getProp1", + "scriptable": true, + "stored": true, + "type": "FwdClass1", + "user": false, + "write": "setProp1" + }, + { + "constant": false, + "designable": true, + "final": false, + "name": "prop2", + "read": "getProp2", + "scriptable": true, + "stored": true, + "type": "FwdClass2", + "user": false, + "write": "setProp2" + }, + { + "constant": false, + "designable": true, + "final": false, + "name": "prop3", + "read": "getProp3", + "scriptable": true, + "stored": true, + "type": "FwdClass3", + "user": false, + "write": "setProp3" + } + ], + "qualifiedClassName": "TestFwdProperties", + "superClasses": [ + { + "access": "public", + "name": "QObject" + } + ] + }, + { + "className": "SomeRandomNamespace", + "gadget": true, + "qualifiedClassName": "SomeRandomNamespace" + } + ], + "inputFile": "moc_include.h", + "outputRevision": 67 + }, { "classes": [ { diff --git a/tests/auto/tools/moc/fwdclass1.h b/tests/auto/tools/moc/fwdclass1.h new file mode 100644 index 0000000000..a8457cca77 --- /dev/null +++ b/tests/auto/tools/moc/fwdclass1.h @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2020 Olivier Goffart +** 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$ +** +****************************************************************************/ + +#ifdef FWDCLASS1_H +#error "This file can only be included once" +#endif +#define FWDCLASS1_H + +class FwdClass1 +{ +public: + int x; +}; diff --git a/tests/auto/tools/moc/fwdclass2.h b/tests/auto/tools/moc/fwdclass2.h new file mode 100644 index 0000000000..650da18116 --- /dev/null +++ b/tests/auto/tools/moc/fwdclass2.h @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2020 Olivier Goffart +** 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$ +** +****************************************************************************/ + +#ifdef FWDCLASS2_H +#error "This file can only be included once" +#endif +#define FWDCLASS2_H + +class FwdClass2 +{ +public: + int x; +}; diff --git a/tests/auto/tools/moc/fwdclass3.h b/tests/auto/tools/moc/fwdclass3.h new file mode 100644 index 0000000000..080ac0340d --- /dev/null +++ b/tests/auto/tools/moc/fwdclass3.h @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2020 Olivier Goffart +** 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$ +** +****************************************************************************/ + +#ifdef FWDCLASS3_H +#error "This file can only be included once" +#endif +#define FWDCLASS3_H + +class FwdClass3 +{ +public: + int x; +}; diff --git a/tests/auto/tools/moc/moc.pro b/tests/auto/tools/moc/moc.pro index 93ca330126..094c76227b 100644 --- a/tests/auto/tools/moc/moc.pro +++ b/tests/auto/tools/moc/moc.pro @@ -30,7 +30,8 @@ HEADERS += using-namespaces.h no-keywords.h task87883.h c-comments.h backslash-n related-metaobjects-in-gadget.h \ related-metaobjects-name-conflict.h \ namespace.h cxx17-namespaces.h \ - cxx-attributes.h + cxx-attributes.h \ + moc_include.h # No platform specifics in the JSON files, so that we can compare them JSON_HEADERS = $$HEADERS diff --git a/tests/auto/tools/moc/moc_include.h b/tests/auto/tools/moc/moc_include.h new file mode 100644 index 0000000000..49b484a0c9 --- /dev/null +++ b/tests/auto/tools/moc/moc_include.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2020 Olivier Goffart +** 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 MOC_INCLUDE_H +#define MOC_INCLUDE_H + +#include + +class FwdClass1; +class FwdClass2; +class FwdClass3; + +Q_MOC_INCLUDE(fwdclass3.h) + +namespace SomeRandomNamespace { +Q_MOC_INCLUDE("fwdclass1.h") +Q_NAMESPACE +} + +class TestFwdProperties : public QObject +{ + Q_OBJECT + Q_PROPERTY(FwdClass1 prop1 WRITE setProp1 READ getProp1) + Q_PROPERTY(FwdClass2 prop2 WRITE setProp2 READ getProp2) + Q_PROPERTY(FwdClass3 prop3 WRITE setProp3 READ getProp3) +public: + ~TestFwdProperties(); + + void setProp1(const FwdClass1 &val); + void setProp2(const FwdClass2 &val); + void setProp3(const FwdClass3 &val); + const FwdClass1 &getProp1() { return *prop1; } + const FwdClass2 &getProp2() { return *prop2; } + const FwdClass3 &getProp3() { return *prop3; } + + QScopedPointer prop1; + QScopedPointer prop2; + QScopedPointer prop3; + + Q_MOC_INCLUDE( + \ + "fwdclass2.h" + ) + +}; + +Q_MOC_INCLUDE() + +#endif // MOC_INCLUDE_H diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index e5de647930..2bad8f2e63 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2013 Olivier Goffart +** Copyright (C) 2020 Olivier Goffart ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -27,8 +27,6 @@ ** ****************************************************************************/ - - #include #include #include @@ -74,6 +72,11 @@ #include "cxx17-namespaces.h" #include "cxx-attributes.h" +#include "moc_include.h" +#include "fwdclass1.h" +#include "fwdclass2.h" +#include "fwdclass3.h" + #ifdef Q_MOC_RUN // check that moc can parse these constructs, they are being used in Windows winsock2.h header #define STRING_HASH_HASH(x) ("foo" ## x ## "bar") @@ -717,6 +720,7 @@ private slots: void cxx17Namespaces(); void cxxAttributes(); void mocJsonOutput(); + void mocInclude(); signals: void sigWithUnsignedArg(unsigned foo); @@ -4002,6 +4006,29 @@ void tst_Moc::mocJsonOutput() QVERIFY2(actualOutput == expectedOutput, showPotentialDiff(actualOutput, expectedOutput).constData()); } +void TestFwdProperties::setProp1(const FwdClass1 &v) +{ + prop1.reset(new FwdClass1(v)); +} +void TestFwdProperties::setProp2(const FwdClass2 &v) +{ + prop2.reset(new FwdClass2(v)); +} +void TestFwdProperties::setProp3(const FwdClass3 &v) +{ + prop3.reset(new FwdClass3(v)); +} +TestFwdProperties::~TestFwdProperties() {} + +Q_DECLARE_METATYPE(FwdClass1); + +void tst_Moc::mocInclude() +{ + TestFwdProperties obj; + obj.setProperty("prop1", QVariant::fromValue(FwdClass1 { 45 })); + QCOMPARE(obj.prop1->x, 45); +} + QTEST_MAIN(tst_Moc) // the generated code must compile with QT_NO_KEYWORDS -- cgit v1.2.3