qt5base-lts/tests/auto/tools/moc
Simon Hausmann 54f0733e7d 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>
2013-12-12 22:57:19 +01:00
..
task71021 Moved autotests in category 'tools' into new directory structure 2011-09-12 10:08:29 +02:00
Test.framework/Headers Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
testproject Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
.gitattributes Moved autotests in category 'tools' into new directory structure 2011-09-12 10:08:29 +02:00
.gitignore Moved autotests in category 'tools' into new directory structure 2011-09-12 10:08:29 +02:00
assign-namespace.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
backslash-newlines.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
c-comments.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
cstyle-enums.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
cxx11-enums.h Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
cxx11-explicit-override-control.h Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
cxx11-final-classes.h Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
dir-in-include-path.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
dollars.h moc: Support the '$' character as an identifier 2013-03-02 12:58:18 +01:00
error-on-wrong-notify.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
escapes-in-string-literals.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
extraqualification.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
forgotten-qinterface.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
forward-declared-param.h Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
function-with-attributes.h moc: Don't stumble over MSVC __declspec. 2013-09-24 10:09:14 +02:00
gadgetwithnoenums.h Whitespace cleanup: remove trailing whitespace 2013-03-16 20:22:50 +01:00
Header Moved autotests in category 'tools' into new directory structure 2011-09-12 10:08:29 +02:00
interface-from-framework.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
interface-from-include.h moc: add unittest for --ignore-option-clashes 2013-07-30 09:36:25 +02:00
macro-on-cmdline.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
moc.pro Fix erroneous exclusion of classes from related meta objects in moc 2013-12-12 22:57:19 +01:00
namespaced-flags.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
no-keywords.h use qtconcurrent instead of qtgui in test code 2013-06-10 21:12:01 +02:00
oldstyle-casts.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
os9-newlines.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
parse-boost.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
parse-defines.h Fix tst_moc when variadic macros are enabled 2013-03-17 10:57:49 +01:00
plugin_metadata.h moc: add -M<key=value> to ease static qml plugin linking 2013-09-13 11:48:08 +02:00
pp-dollar-signs.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
pure-virtual-signals.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
qinvokable.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
qprivateslots.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
related-metaobjects-in-namespaces.h Fix erroneous exclusion of classes from related meta objects in moc 2013-12-12 22:57:19 +01:00
single_function_keyword.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
single-quote-digit-separator-n3781.h Test that Qt tools can handle ' as a digit separator. 2013-10-30 09:44:07 +01:00
slots-with-void-template.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
task87883.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
task189996.h Whitespace cleanup: remove trailing whitespace 2013-03-16 20:22:50 +01:00
task192552.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
task234909.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
task240368.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
template-gtgt.h Whitespace cleanup: remove trailing whitespace 2013-03-16 20:22:50 +01:00
trigraphs.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
tst_moc.cpp Fix erroneous exclusion of classes from related meta objects in moc 2013-12-12 22:57:19 +01:00
unterminated-function-macro.h moc: Error out when detecting unterminated macro usage 2013-02-19 20:51:44 +01:00
using-namespaces.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
warn-on-multiple-qobject-subclasses.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
warn-on-property-without-read.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
win-newlines.h Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00