From e6a2892772c9ea18a941625b2b8dec38e6774f82 Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Fri, 28 May 2021 11:11:08 +0200 Subject: [PATCH] moc: Add relative property index to JSON output of PropertyDef Needed for QML compiler to know property index of C++ type at compile time without going through QMetaObject::indexOfProperty Change-Id: I404e71d6071d36812661df17d12b879a8dcbd146 Reviewed-by: Fabian Kosmale --- src/tools/moc/moc.cpp | 9 +++++---- src/tools/moc/moc.h | 3 ++- tests/auto/tools/moc/allmocs_baseline_in.json | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index c8fe0e9a837..bce75644f5c 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1242,9 +1242,10 @@ void Moc::parseSignals(ClassDef *def) } } -void Moc::createPropertyDef(PropertyDef &propDef) +void Moc::createPropertyDef(PropertyDef &propDef, int propertyIndex) { propDef.location = index; + propDef.relativeIndex = propertyIndex; QByteArray type = parseType().name; if (type.isEmpty()) @@ -1401,7 +1402,7 @@ void Moc::parseProperty(ClassDef *def) { next(LPAREN); PropertyDef propDef; - createPropertyDef(propDef); + createPropertyDef(propDef, int(def->propertyList.size())); next(RPAREN); def->propertyList += propDef; @@ -1495,7 +1496,7 @@ void Moc::parsePrivateProperty(ClassDef *def) next(COMMA); - createPropertyDef(propDef); + createPropertyDef(propDef, int(def->propertyList.size())); def->propertyList += propDef; } @@ -2068,7 +2069,7 @@ QJsonObject PropertyDef::toJson() const prop[QLatin1String("constant")] = constant; prop[QLatin1String("final")] = final; prop[QLatin1String("required")] = required; - + prop[QLatin1String("index")] = relativeIndex; if (revision > 0) prop[QLatin1String("revision")] = revision; diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index 889ee156521..1c2d6624fa8 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -140,6 +140,7 @@ struct PropertyDef bool constant = false; bool final = false; bool required = false; + int relativeIndex = -1; // property index in current metaobject int location = -1; // token index, used for error reporting @@ -263,7 +264,7 @@ public: void parseSignals(ClassDef *def); void parseProperty(ClassDef *def); void parsePluginData(ClassDef *def); - void createPropertyDef(PropertyDef &def); + void createPropertyDef(PropertyDef &def, int propertyIndex); void parsePropertyAttributes(PropertyDef &propDef); void parseEnumOrFlag(BaseDef *def, bool isFlag); void parseFlag(BaseDef *def); diff --git a/tests/auto/tools/moc/allmocs_baseline_in.json b/tests/auto/tools/moc/allmocs_baseline_in.json index 830a1371eaf..d362f94c7b0 100644 --- a/tests/auto/tools/moc/allmocs_baseline_in.json +++ b/tests/auto/tools/moc/allmocs_baseline_in.json @@ -1136,6 +1136,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "prop1", "read": "getProp1", "required": false, @@ -1149,6 +1150,7 @@ "constant": false, "designable": true, "final": false, + "index": 1, "name": "prop2", "read": "getProp2", "required": false, @@ -1162,6 +1164,7 @@ "constant": false, "designable": true, "final": false, + "index": 2, "name": "prop3", "read": "getProp3", "required": false, @@ -1274,6 +1277,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "flags", "read": "flags", "required": false, @@ -1300,6 +1304,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "flags", "read": "flags", "required": false, @@ -1313,6 +1318,7 @@ "constant": false, "designable": true, "final": false, + "index": 1, "name": "flagsList", "read": "flagsList", "required": false, @@ -1854,6 +1860,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "blah", "read": "blah", "required": false, @@ -1906,6 +1913,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "blah", "read": "blah", "required": false, @@ -2081,6 +2089,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "gadgetPoperty", "read": "gadgetPoperty", "required": false, @@ -2093,6 +2102,7 @@ "constant": false, "designable": true, "final": false, + "index": 1, "name": "objectPoperty", "read": "objectPoperty", "required": false, @@ -2118,6 +2128,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "nestedGadgetPoperty", "read": "nestedGadgetPoperty", "required": false, @@ -2143,6 +2154,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "nestedObjectPoperty", "read": "nestedObjectPoperty", "required": false, @@ -2276,6 +2288,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "gadgetPoperty", "read": "gadgetPoperty", "required": false, @@ -2288,6 +2301,7 @@ "constant": false, "designable": true, "final": false, + "index": 1, "name": "objectPoperty", "read": "objectPoperty", "required": false, @@ -2313,6 +2327,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "nestedGadgetPoperty", "read": "nestedGadgetPoperty", "required": false, @@ -2338,6 +2353,7 @@ "constant": false, "designable": true, "final": false, + "index": 0, "name": "nestedObjectPoperty", "read": "nestedObjectPoperty", "required": false,