summaryrefslogtreecommitdiffstats
path: root/tests/auto/tools/moc/related-metaobjects-in-namespaces.h
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-12-12 10:50:00 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-12 22:57:19 +0100
commit54f0733e7df4134afbcf0a81ba39751f31c9b84d (patch)
treeb9e1259dc0b3ae4f90488c2825ccae855d7cee99 /tests/auto/tools/moc/related-metaobjects-in-namespaces.h
parentd56f5df84fb84cdd85e06c1b8e6f075836179847 (diff)
Fix erroneous exclusion of classes from related meta objects in moc
Assume an unrelated class that declares an enum and uses Q_ENUMS. Consider then a class that uses UnrelatedClass::Enum as a Q_PROPERTY. We used to include UnrelatedClass in the primary class's related meta objects, in order to support use-cases like obj->setProperty("enumProperty", "ValueOfEnumAsString"); If however moc happens to see Q_DECLARE_METATYPE(UnrelatedClass::Enum), then it would exclude it from the related meta objects, which would silently break the string based enum value conversion. This was meant as an optimization, but it isn't apparent to the developer why sometimes the string conversion would work and sometimes not (depending on whether somebody declares that macro). This also becomes visible in QML, which relies on the same embedded type information for enum assignments. This patch removes that check in moc's code generator and cleans up the code a little. However always including the prefix of Q_PROPERTY(SomePrefix::Enum ...) is not correct either, because it may be that SomePrefix is a namespace, which would cause compilation issues. Therefore we limit the inclusion of related meta objects only to Q_OBJECT decorated classes the moc has seen, and for these we save the fully qualified name in the related meta objects array (for QTBUG-2151). While this patch makes the previous workaround for namespace issues by using a Q_DECLARE_METATYPE not workable anymore, by saving the fully qualified name we are making a hopefully sufficient effort to not require a workaround in the first place. There's always the new workaround of fully qualifying the type in Q_PROPERTY. One side-effect of this change is that in the autoPropertyMetaTypeRegistration test of tst_moc, the CustomQObject for Q_PROPERTY(CustomQObject::Number enumValue ...) is now a related meta object, and therefore when querying for the type of this property via QMetaProperty::userType(), we are now aware of this being an enum and try to resolve CustomQObject::Number via QMetaType::type(qualfiedName). As there is no guarantee for this to succeed, we must now also do what is done in the non-enum code path in ::userType(), which is to call the moc generated type registration function. Task-number: QTBUG-33577 Task-number: QTBUG-2151 Change-Id: Ibf20e7421cba464c558a25c76a7e1eef002c6cff Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/tools/moc/related-metaobjects-in-namespaces.h')
-rw-r--r--tests/auto/tools/moc/related-metaobjects-in-namespaces.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/tools/moc/related-metaobjects-in-namespaces.h b/tests/auto/tools/moc/related-metaobjects-in-namespaces.h
new file mode 100644
index 0000000000..0a3e9ed77d
--- /dev/null
+++ b/tests/auto/tools/moc/related-metaobjects-in-namespaces.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QObject>
+
+namespace QTBUG_2151 {
+ class A : public QObject {
+ Q_OBJECT
+ Q_ENUMS(SomeEnum)
+ public:
+ enum SomeEnum { SomeEnumValue = 0 };
+ };
+
+ class B : public QObject
+ {
+ Q_OBJECT
+ Q_PROPERTY(A::SomeEnum blah READ blah)
+ public:
+
+ A::SomeEnum blah() const { return A::SomeEnumValue; }
+ };
+}