summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2016-06-10 14:44:34 +0200
committerUlf Hermann <ulf.hermann@qt.io>2016-07-08 13:00:19 +0000
commit950f6bc78a4ed855abc7657d7dbc7f83e4df6b2a (patch)
tree5c23bddc138934ad3e59b117ce4d4a220770b7c0 /tools
parent032847aa29bcf0526f9790173715c6afef8c9481 (diff)
Restore Q_PROPERTY macros
This is still almost for free, and vastly easier to do than a solution with plugins.qmltypes. The plugins.qmltypes format is tailored for actual plugins, identifyable by a fixed URL. However, in the workflow we suggest right now, the URL is controlled by the user. Resolving it from the code would require the same guesswork as we have to do to resolve Q_PROPERTY macros from the headers. Change-Id: Iec916e7e91de096a38b61e6b76794b3dca3139d5 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qscxmlc/decl.t1
-rw-r--r--tools/qscxmlc/scxmlcppdumper.cpp31
-rw-r--r--tools/qscxmlc/scxmlcppdumper.h2
3 files changed, 34 insertions, 0 deletions
diff --git a/tools/qscxmlc/decl.t b/tools/qscxmlc/decl.t
index 2b35d67..b0963e4 100644
--- a/tools/qscxmlc/decl.t
+++ b/tools/qscxmlc/decl.t
@@ -3,6 +3,7 @@ class ${classname}: public QScxmlStateMachine
public:
/* qmake ignore Q_OBJECT */
Q_OBJECT
+${properties}
public:
${classname}(QObject *parent = 0);
diff --git a/tools/qscxmlc/scxmlcppdumper.cpp b/tools/qscxmlc/scxmlcppdumper.cpp
index f6cc42a..e425dee 100644
--- a/tools/qscxmlc/scxmlcppdumper.cpp
+++ b/tools/qscxmlc/scxmlcppdumper.cpp
@@ -528,6 +528,7 @@ void CppDumper::writeClass(const QString &className, const GeneratedTableData::M
const bool qtMode = m_translationUnit->mainDocument->qtMode;
Replacements r;
r[QStringLiteral("classname")] = className;
+ r[QStringLiteral("properties")] = generatePropertyDecls(info, qtMode);
r[QStringLiteral("signals")] = qtMode ? generateSignalDecls(info) : QString();
r[QStringLiteral("slots")] = qtMode ? generateSlotDecls(info) : QString();
r[QStringLiteral("getters")] = qtMode ? generateGetterDecls(info) : QString();
@@ -716,6 +717,36 @@ QString CppDumper::mangleIdentifier(const QString &str)
return mangled;
}
+QString CppDumper::generatePropertyDecls(const GeneratedTableData::MetaDataInfo &info, bool qtMode)
+{
+ QString decls;
+
+ foreach (const QString &stateName, info.stateNames) {
+ if (!stateName.isEmpty()) {
+ const QString decl = QString::fromLatin1(
+ qtMode ? " Q_PROPERTY(bool %1 READ %2 NOTIFY %2Changed)\n" :
+ " Q_PROPERTY(bool %1 NOTIFY %2Changed)\n");
+ decls += decl.arg(stateName, mangleIdentifier(stateName));
+ }
+ }
+
+ QString namespacePrefix;
+ if (!m_translationUnit->namespaceName.isEmpty()) {
+ namespacePrefix = QStringLiteral("::%1").arg(m_translationUnit->namespaceName);
+ }
+
+ foreach (const QString &machineName, info.subStateMachineNames) {
+ if (!machineName.isEmpty()) {
+ const QString decl = QString::fromLatin1(
+ qtMode ? " Q_PROPERTY(%1::%2 *%3 READ %2 NOTIFY %2Changed)\n" :
+ " Q_PROPERTY(%1::%2 *%3 NOTIFY %2Changed)\n");
+ decls += decl.arg(namespacePrefix, mangleIdentifier(machineName), machineName);
+ }
+ }
+
+ return decls;
+}
+
QString CppDumper::generateSignalDecls(const GeneratedTableData::MetaDataInfo &info)
{
QString decls;
diff --git a/tools/qscxmlc/scxmlcppdumper.h b/tools/qscxmlc/scxmlcppdumper.h
index 97011d0..5391fa7 100644
--- a/tools/qscxmlc/scxmlcppdumper.h
+++ b/tools/qscxmlc/scxmlcppdumper.h
@@ -86,6 +86,8 @@ private:
QString mangleIdentifier(const QString &str);
private:
+ QString generatePropertyDecls(const QScxmlInternal::GeneratedTableData::MetaDataInfo &info,
+ bool qtMode);
QString generateSignalDecls(const QScxmlInternal::GeneratedTableData::MetaDataInfo &info);
QString generateSlotDecls(const QScxmlInternal::GeneratedTableData::MetaDataInfo &info);
QString generateSlotDefs(const QString &className,