diff options
author | Michael Brasser <mbrasser@ford.com> | 2017-10-04 15:59:39 -0500 |
---|---|---|
committer | Michael Brasser <michael.brasser@live.com> | 2017-10-06 13:17:44 +0000 |
commit | a3e68cda27ff01ab8fab73978f3f09db21222a98 (patch) | |
tree | 50d01c6c67df56e92979324bcbd8988462876c5b /tools | |
parent | 5e3c8093fe596f1911ae692a743a93c9e96f0aeb (diff) |
Generate a protected setter for SimpleSource READONLY propertiesv5.10.0-beta2
Follow the strategy used for READPUSH/READWRITE property types,
only make the setter protected rather than public.
Change-Id: Ide52b3c930371a20a4de94635607573bde480250
Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/repc/repcodegenerator.cpp | 36 | ||||
-rw-r--r-- | tools/repc/repcodegenerator.h | 2 |
2 files changed, 31 insertions, 7 deletions
diff --git a/tools/repc/repcodegenerator.cpp b/tools/repc/repcodegenerator.cpp index 4464bdf..5a75a35 100644 --- a/tools/repc/repcodegenerator.cpp +++ b/tools/repc/repcodegenerator.cpp @@ -344,6 +344,17 @@ QString RepCodeGenerator::formatMarshallingOperators(const POD &pod) ; } +void RepCodeGenerator::generateSimpleSetter(QTextStream &out, const ASTProperty &property) +{ + out << " virtual void set" << cap(property.name) << "(" << property.type << " " << property.name << ")" << endl; + out << " {" << endl; + out << " if (" << property.name << " != _" << property.name << ") {" << endl; + out << " _" << property.name << " = " << property.name << ";" << endl; + out << " Q_EMIT " << property.name << "Changed(_" << property.name << ");" << endl; + out << " }" << endl; + out << " }" << endl; +} + void RepCodeGenerator::generatePOD(QTextStream &out, const POD &pod) { QByteArray podData = pod.name.toLatin1(); @@ -730,13 +741,7 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass Q_FOREACH (const ASTProperty &property, astClass.properties) { if (property.modifier == ASTProperty::ReadWrite || property.modifier == ASTProperty::ReadPush) { - out << " virtual void set" << cap(property.name) << "(" << property.type << " " << property.name << ")" << endl; - out << " {" << endl; - out << " if (" << property.name << " != _" << property.name << ") { " << endl; - out << " _" << property.name << " = " << property.name << ";" << endl; - out << " Q_EMIT " << property.name << "Changed(_" << property.name << ");" << endl; - out << " }" << endl; - out << " }" << endl; + generateSimpleSetter(out, property); } } } @@ -824,6 +829,23 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass } } + if (mode == SIMPLE_SOURCE) + { + if (!astClass.properties.isEmpty()) { + bool addProtected = true; + Q_FOREACH (const ASTProperty &property, astClass.properties) { + if (property.modifier == ASTProperty::ReadOnly) { + if (addProtected) { + out << "" << endl; + out << "protected:" << endl; + addProtected = false; + } + generateSimpleSetter(out, property); + } + } + } + } + out << "" << endl; out << "private:" << endl; diff --git a/tools/repc/repcodegenerator.h b/tools/repc/repcodegenerator.h index 18421e8..f9e8654 100644 --- a/tools/repc/repcodegenerator.h +++ b/tools/repc/repcodegenerator.h @@ -38,6 +38,7 @@ struct AST; struct ASTClass; struct POD; struct ASTEnum; +struct ASTProperty; class QIODevice; class QStringList; @@ -65,6 +66,7 @@ private: QString generateMetaTypeRegistrationForEnums(const QVector<QString> &enums); void generateStreamOperatorsForEnums(QTextStream &out, const QVector<QString> &enums); + void generateSimpleSetter(QTextStream &out, const ASTProperty &property); void generatePOD(QTextStream &out, const POD &pod); void generateENUMs(QTextStream &out, const QVector<ASTEnum> &enums, const QString &className); void generateDeclarationsForEnums(QTextStream &out, const QVector<ASTEnum> &enums, bool generateQENUM=true); |