diff options
41 files changed, 560 insertions, 2173 deletions
diff --git a/.qmake.conf b/.qmake.conf index 09883cb..21f7866 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -4,6 +4,6 @@ CONFIG += qt_example_installs DEFINES += QT_NO_JAVA_STYLE_ITERATORS DEFINES += QT_NO_FOREACH -MODULE_VERSION = 5.14.2 +MODULE_VERSION = 5.15.0 QTRO_SOURCE_TREE = $$PWD diff --git a/examples/remoteobjects/clientapp/clientapp.qrc b/examples/remoteobjects/clientapp/clientapp.qrc index 7e6bf64..23bdb39 100644 --- a/examples/remoteobjects/clientapp/clientapp.qrc +++ b/examples/remoteobjects/clientapp/clientapp.qrc @@ -5,5 +5,4 @@ <file>qml/plugins1.qml</file> <file>qml/plugins2.qml</file> </qresource> - <qresource prefix="/images"/> </RCC> diff --git a/src/imports/remoteobjects/plugin.cpp b/src/imports/remoteobjects/plugin.cpp index 2cdf38c..7e79de1 100644 --- a/src/imports/remoteobjects/plugin.cpp +++ b/src/imports/remoteobjects/plugin.cpp @@ -140,6 +140,7 @@ public: qmlRegisterType<QRemoteObjectNode>(uri, 5, 12, "Node"); qmlRegisterType<QRemoteObjectSettingsStore>(uri, 5, 12, "SettingsStore"); qmlRegisterSingletonType<QtQmlRemoteObjects>(uri, 5, 14, "QtRemoteObjects", [](QQmlEngine *, QJSEngine*){return new QtQmlRemoteObjects();}); + qmlRegisterType<QRemoteObjectHost>(uri, 5, 15, "Host"); qmlProtectModule(uri, 5); } }; diff --git a/src/remoteobjects/Qt5RemoteObjectsConfigExtras.cmake.in b/src/remoteobjects/Qt5RemoteObjectsConfigExtras.cmake.in index 4907ded..f98c37a 100644 --- a/src/remoteobjects/Qt5RemoteObjectsConfigExtras.cmake.in +++ b/src/remoteobjects/Qt5RemoteObjectsConfigExtras.cmake.in @@ -49,3 +49,14 @@ if (NOT TARGET Qt5::repc) ) get_target_property(Qt5RemoteObjects_REPC_EXECUTABLE Qt5::repc LOCATION) endif() + +# Create versionless tool targets. +foreach(__qt_tool repc) + if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND NOT TARGET Qt::${__qt_tool} + AND TARGET Qt5::${__qt_tool}) + add_executable(Qt::${__qt_tool} IMPORTED) + get_target_property(__qt_imported_location Qt5::${__qt_tool} IMPORTED_LOCATION) + set_target_properties(Qt::${__qt_tool} + PROPERTIES IMPORTED_LOCATION \"${__qt_imported_location}\") + endif() +endforeach() diff --git a/src/remoteobjects/Qt5RemoteObjectsMacros.cmake b/src/remoteobjects/Qt5RemoteObjectsMacros.cmake index 0710616..02cb710 100644 --- a/src/remoteobjects/Qt5RemoteObjectsMacros.cmake +++ b/src/remoteobjects/Qt5RemoteObjectsMacros.cmake @@ -91,3 +91,14 @@ macro(qt5_generate_repc outfiles infile outputtype) qt5_create_moc_command(${_outfile_header} ${_moc_outfile} "${_moc_flags}" "" "" "") list(APPEND ${outfiles} "${_outfile_header}" ${_moc_outfile}) endmacro() + +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_generate_repc outfiles) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_generate_repc("${outfiles}" ${ARGN}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_generate_repc("${outfiles}" ${ARGN}) + endif() + set("${outfiles}" "${${outfiles}}" PARENT_SCOPE) + endfunction() +endif() diff --git a/src/remoteobjects/doc/src/remoteobjects-repc.qdoc b/src/remoteobjects/doc/src/remoteobjects-repc.qdoc index a51e10e..459b512 100644 --- a/src/remoteobjects/doc/src/remoteobjects-repc.qdoc +++ b/src/remoteobjects/doc/src/remoteobjects-repc.qdoc @@ -84,7 +84,7 @@ \code class MyType { - //PROP/SIGNAL/SLOT/ENUM declarations to define your API + //PROP/CLASS/MODEL/SIGNAL/SLOT/ENUM declarations to define your API }; \endcode @@ -224,6 +224,39 @@ \sa QRemoteObjectAbstractPersistedStore + \section3 CLASS + + The CLASS keyword generates special Q_PROPERTY elements for objects derived from QObject. + These properties have the same semantics as SOURCEONLYSETTER. The syntax is the \c CLASS + keyword followed by the property name and then the type of subobject enclosed in parentheses. + \code + // In .rep file + class OtherClass + { + PROP(int value) + } + + class MainClass + { + CLASS subObject(OtherClass) + } + \endcode + + \section3 MODEL + + The MODEL keyword generates special Q_PROPERTY elements for objects derived from QAbstractItemModel. + These properties have the same semantics as SOURCEONLYSETTER. The syntax is the \c MODEL + keyword followed by the property name and then parentheses enclosing the (comma-separated) roles + that should be exposed to the replica. + \code + // In .rep file + class CdClass + { + PROP(QString title READONLY) + MODEL tracks(title, artist, length) + } + \endcode + \section3 SIGNAL \l [DOC QtCore] {Signals} {Signal} methods are created by using the SIGNAL keyword in the rep file. diff --git a/src/remoteobjects/qremoteobjectnode.cpp b/src/remoteobjects/qremoteobjectnode.cpp index c2fba06..79d5b23 100644 --- a/src/remoteobjects/qremoteobjectnode.cpp +++ b/src/remoteobjects/qremoteobjectnode.cpp @@ -1640,6 +1640,19 @@ QRemoteObjectNode::QRemoteObjectNode(QRemoteObjectNodePrivate &dptr, QObject *pa } /*! + \qmltype Host + \instantiates QRemoteObjectHost + \inqmlmodule QtRemoteObjects + \brief A host node on a Qt Remote Objects network. + + The Host type provides an entry point to a Qt Remote Objects network. A network + can be as simple as two nodes, or an arbitrarily complex set of processes and devices. + + Hosts have the same capabilities as Nodes, but they can also be connected to and can + share source objects on the network. +*/ + +/*! \internal This is a base class for both QRemoteObjectHost and QRemoteObjectRegistryHost to provide the shared features/functions for sharing \l Source objects. @@ -1817,6 +1830,21 @@ bool QRemoteObjectHostBase::setHostUrl(const QUrl &hostAddress, AllowedSchemas a } /*! + \qmlproperty url Host::hostUrl + + The host address for the node. + + This is the address where source objects remoted by this node will reside. +*/ + +/*! + \property QRemoteObjectHost::hostUrl + \brief The host address for the node. + + This is the address where source objects remoted by this node will reside. +*/ + +/*! Returns the host address for the QRemoteObjectNode as a QUrl. If the Node is not a Host node, returns an empty QUrl. @@ -1839,7 +1867,10 @@ QUrl QRemoteObjectHost::hostUrl() const */ bool QRemoteObjectHost::setHostUrl(const QUrl &hostAddress, AllowedSchemas allowedSchemas) { - return QRemoteObjectHostBase::setHostUrl(hostAddress, allowedSchemas); + bool success = QRemoteObjectHostBase::setHostUrl(hostAddress, allowedSchemas); + if (success) + emit hostUrlChanged(); + return success; } /*! @@ -2163,6 +2194,24 @@ QRemoteObjectDynamicReplica *QRemoteObjectNode::acquireDynamic(const QString &na } /*! + \qmlmethod void Host::enableRemoting(object object, string name) + Enables a host node to dynamically provide remote access to the QObject \a + object. Client nodes connected to the node hosting this object may obtain + Replicas of this Source. + + The \a name defines the lookup-name under which the QObject can be acquired + using \l QRemoteObjectNode::acquire() . If not explicitly set then the name + given in the QCLASSINFO_REMOTEOBJECT_TYPE will be used. If no such macro + was defined for the QObject then the \l QObject::objectName() is used. + + Returns \c false if the current node is a client node, or if the QObject is already + registered to be remoted, and \c true if remoting is successfully enabled + for the dynamic QObject. + + \sa disableRemoting() +*/ + +/*! Enables a host node to dynamically provide remote access to the QObject \a object. Client nodes connected to the node hosting this object may obtain Replicas of this Source. @@ -2284,6 +2333,18 @@ bool QRemoteObjectHostBase::enableRemoting(QObject *object, const SourceApiMap * } /*! + \qmlmethod void Host::disableRemoting(object remoteObject) + Disables remote access for the QObject \a remoteObject. Returns \c false if + the current node is a client node or if the \a remoteObject is not + registered, and returns \c true if remoting is successfully disabled for + the Source object. + + \warning Replicas of this object will no longer be valid after calling this method. + + \sa enableRemoting() +*/ + +/*! Disables remote access for the QObject \a remoteObject. Returns \c false if the current node is a client node or if the \a remoteObject is not registered, and returns \c true if remoting is successfully disabled for diff --git a/src/remoteobjects/qremoteobjectnode.h b/src/remoteobjects/qremoteobjectnode.h index d69b369..5e677e8 100644 --- a/src/remoteobjects/qremoteobjectnode.h +++ b/src/remoteobjects/qremoteobjectnode.h @@ -181,9 +181,9 @@ public: ApiDefinition<ObjectType> *api = new ApiDefinition<ObjectType>(object); return enableRemoting(object, api); } - bool enableRemoting(QObject *object, const QString &name = QString()); + Q_INVOKABLE bool enableRemoting(QObject *object, const QString &name = QString()); bool enableRemoting(QAbstractItemModel *model, const QString &name, const QVector<int> roles, QItemSelectionModel *selectionModel = nullptr); - bool disableRemoting(QObject *remoteObject); + Q_INVOKABLE bool disableRemoting(QObject *remoteObject); void addHostSideConnection(QIODevice *ioDevice); typedef std::function<bool(const QString &, const QString &)> RemoteObjectNameFilter; @@ -204,6 +204,8 @@ private: class Q_REMOTEOBJECTS_EXPORT QRemoteObjectHost : public QRemoteObjectHostBase { Q_OBJECT + Q_PROPERTY(QUrl hostUrl READ hostUrl WRITE setHostUrl NOTIFY hostUrlChanged) + public: QRemoteObjectHost(QObject *parent = nullptr); QRemoteObjectHost(const QUrl &address, const QUrl ®istryAddress = QUrl(), @@ -213,6 +215,9 @@ public: QUrl hostUrl() const override; bool setHostUrl(const QUrl &hostAddress, AllowedSchemas allowedSchemas=BuiltInSchemasOnly) override; +Q_SIGNALS: + void hostUrlChanged(); + protected: QRemoteObjectHost(QRemoteObjectHostPrivate &, QObject *); diff --git a/src/remoteobjects/qremoteobjectreplica.cpp b/src/remoteobjects/qremoteobjectreplica.cpp index 3c2c84b..e619e83 100644 --- a/src/remoteobjects/qremoteobjectreplica.cpp +++ b/src/remoteobjects/qremoteobjectreplica.cpp @@ -177,6 +177,14 @@ void QRemoteObjectReplicaImplementation::setState(QRemoteObjectReplica::State st QMetaObject::activate(this, metaObject(), stateChangedIndex, args); } +void QRemoteObjectReplicaImplementation::emitNotified() +{ + const static int notifiedIndex = QRemoteObjectReplica::staticMetaObject.indexOfMethod("notified()"); + Q_ASSERT(notifiedIndex != -1); + void *args[] = {nullptr}; + QMetaObject::activate(this, metaObject(), notifiedIndex, args); +} + bool QConnectedReplicaImplementation::sendCommand() { if (connectionToSource.isNull() || !connectionToSource->isOpen()) { @@ -227,6 +235,7 @@ void QConnectedReplicaImplementation::initialize(QVariantList &values) args[1] = m_propertyStorage[i].data(); QMetaObject::activate(this, metaObject(), notifyIndex, args); } + emitNotified(); qCDebug(QT_REMOTEOBJECT) << "isSet = true for" << m_objectName; if (node()->heartbeatInterval()) @@ -307,6 +316,7 @@ void QConnectedReplicaImplementation::setDynamicProperties(const QVariantList &v QMetaObject::activate(this, metaObject(), mp.notifySignalIndex(), args); } } + emitNotified(); qCDebug(QT_REMOTEOBJECT) << "isSet = true for" << m_objectName; } @@ -596,12 +606,28 @@ void QConnectedReplicaImplementation::configurePrivate(QRemoteObjectReplica *rep /*! \fn void QRemoteObjectReplica::initialized() - This signal is emitted once the replica is initialized. + This signal is emitted once the replica is initialized. An intialized replica + has all property values set, but has not yet emitted any property change + notifications. \sa isInitialized(), stateChanged() */ /*! + \fn void QRemoteObjectReplica::notified() + + This signal is emitted once the replica is initialized and all property change + notifications have been emitted. + + It is sometimes useful to respond to property changes as events. + For example, you might want to display a user notification when a certain + property change occurs. However, this user notification would then also be + triggered when a replica first became \c QRemoteObjectReplica::Valid, as + all property change signals are emitted at that time. This isn't always desirable, + and \c notified allows the developer to distinguish between these two cases. +*/ + +/*! \internal \enum QRemoteObjectReplica::ConstructorType */ diff --git a/src/remoteobjects/qremoteobjectreplica.h b/src/remoteobjects/qremoteobjectreplica.h index cfd0de3..e70a5ab 100644 --- a/src/remoteobjects/qremoteobjectreplica.h +++ b/src/remoteobjects/qremoteobjectreplica.h @@ -79,6 +79,7 @@ public: Q_SIGNALS: void initialized(); + void notified(); void stateChanged(State state, State oldState); protected: diff --git a/src/remoteobjects/qremoteobjectreplica_p.h b/src/remoteobjects/qremoteobjectreplica_p.h index 8acefda..061d21e 100644 --- a/src/remoteobjects/qremoteobjectreplica_p.h +++ b/src/remoteobjects/qremoteobjectreplica_p.h @@ -124,6 +124,7 @@ public: virtual void notifyAboutReply(int, const QVariant &) {} virtual void configurePrivate(QRemoteObjectReplica *); void emitInitialized(); + void emitNotified(); QRemoteObjectNode *node() const override { return m_node; } void _q_send(QMetaObject::Call call, int index, const QVariantList &args) override = 0; diff --git a/tests/auto/integration_external/client/client.pro b/tests/auto/integration_external/client/client.pro index 4c42f5c..6bcc136 100644 --- a/tests/auto/integration_external/client/client.pro +++ b/tests/auto/integration_external/client/client.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += remoteobjects core testlib QT -= gui -TARGET = client +TARGET = integration_external_client DESTDIR = ./ CONFIG += c++11 CONFIG -= app_bundle diff --git a/tests/auto/integration_external/external/tst_integration_external.cpp b/tests/auto/integration_external/external/tst_integration_external.cpp index 8994db8..4c62e38 100644 --- a/tests/auto/integration_external/external/tst_integration_external.cpp +++ b/tests/auto/integration_external/external/tst_integration_external.cpp @@ -81,7 +81,7 @@ private slots: env.insert("TEMPLATED_REMOTING", "true"); serverProc.setProcessEnvironment(env); } - serverProc.start(findExecutable("server", { + serverProc.start(findExecutable("integration_external_server", { QCoreApplication::applicationDirPath() + "/../server/" })); QVERIFY(serverProc.waitForStarted()); @@ -92,7 +92,7 @@ private slots: qDebug() << "Starting client process"; QProcess clientProc; clientProc.setProcessChannelMode(QProcess::ForwardedChannels); - clientProc.start(findExecutable("client", { + clientProc.start(findExecutable("integration_external_client", { QCoreApplication::applicationDirPath() + "/../client/" })); QVERIFY(clientProc.waitForStarted()); diff --git a/tests/auto/integration_external/server/server.pro b/tests/auto/integration_external/server/server.pro index fea0c03..73b79b3 100644 --- a/tests/auto/integration_external/server/server.pro +++ b/tests/auto/integration_external/server/server.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += remoteobjects core testlib QT -= gui -TARGET = server +TARGET = integration_external_server DESTDIR = ./ CONFIG += c++11 CONFIG -= app_bundle @@ -14,6 +14,5 @@ SOURCES += main.cpp \ HEADERS += \ mytestserver.h - $$OUT_PWD/rep_MyInterface_source.h INCLUDEPATH += $$PWD diff --git a/tests/auto/integration_multiprocess/MyInterface.rep b/tests/auto/integration_multiprocess/MyInterface.rep index fc6a565..a10dbcf 100644 --- a/tests/auto/integration_multiprocess/MyInterface.rep +++ b/tests/auto/integration_multiprocess/MyInterface.rep @@ -6,6 +6,7 @@ class MyInterface PROP(Enum1 enum1 = First READWRITE) PROP(bool started = false) + PROP(int initialValue) SLOT(bool start()) SLOT(bool stop()) diff --git a/tests/auto/integration_multiprocess/client/client.pro b/tests/auto/integration_multiprocess/client/client.pro index 4c42f5c..084e665 100644 --- a/tests/auto/integration_multiprocess/client/client.pro +++ b/tests/auto/integration_multiprocess/client/client.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += remoteobjects core testlib QT -= gui -TARGET = client +TARGET = integration_multiprocess_client DESTDIR = ./ CONFIG += c++11 CONFIG -= app_bundle diff --git a/tests/auto/integration_multiprocess/client/main.cpp b/tests/auto/integration_multiprocess/client/main.cpp index 87f2ad8..923539e 100644 --- a/tests/auto/integration_multiprocess/client/main.cpp +++ b/tests/auto/integration_multiprocess/client/main.cpp @@ -42,6 +42,12 @@ private Q_SLOTS: m_repNode.reset(new QRemoteObjectNode); m_repNode->connectToNode(QUrl(QStringLiteral("tcp://127.0.0.1:65213"))); m_rep.reset(m_repNode->acquire<MyInterfaceReplica>()); + connect(m_rep.data(), &MyInterfaceReplica::notified, [&]() { m_notified = true; }); + connect(m_rep.data(), &MyInterfaceReplica::initialValueChanged, [&]() { + // this value is only set when the replica first connects to the source + QCOMPARE(m_notified, false); + QCOMPARE(m_rep->initialValue(), 18); + }); QVERIFY(m_rep->waitForSource()); } @@ -187,6 +193,7 @@ private Q_SLOTS: private: QScopedPointer<QRemoteObjectNode> m_repNode; QScopedPointer<MyInterfaceReplica> m_rep; + bool m_notified = false; }; QTEST_MAIN(tst_Client_Process) diff --git a/tests/auto/integration_multiprocess/server/mytestserver.cpp b/tests/auto/integration_multiprocess/server/mytestserver.cpp index 94983d1..c97a13a 100644 --- a/tests/auto/integration_multiprocess/server/mytestserver.cpp +++ b/tests/auto/integration_multiprocess/server/mytestserver.cpp @@ -35,6 +35,7 @@ MyTestServer::MyTestServer(QObject *parent) : MyInterfaceSimpleSource(parent) { qDebug() << "Server started"; + setInitialValue(18); } MyTestServer::~MyTestServer() diff --git a/tests/auto/integration_multiprocess/server/server.pro b/tests/auto/integration_multiprocess/server/server.pro index 5bb7120..71f9160 100644 --- a/tests/auto/integration_multiprocess/server/server.pro +++ b/tests/auto/integration_multiprocess/server/server.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += remoteobjects core testlib QT -= gui -TARGET = server +TARGET = integration_multiprocess_server DESTDIR = ./ CONFIG += c++11 CONFIG -= app_bundle @@ -15,6 +15,5 @@ SOURCES += main.cpp \ HEADERS += \ mytestserver.h - $$OUT_PWD/rep_MyInterface_source.h INCLUDEPATH += $$PWD diff --git a/tests/auto/integration_multiprocess/tst/tst_integration_multiprocess.cpp b/tests/auto/integration_multiprocess/tst/tst_integration_multiprocess.cpp index fe5d929..ccdc973 100644 --- a/tests/auto/integration_multiprocess/tst/tst_integration_multiprocess.cpp +++ b/tests/auto/integration_multiprocess/tst/tst_integration_multiprocess.cpp @@ -81,7 +81,7 @@ private slots: env.insert("TEMPLATED_REMOTING", "true"); serverProc.setProcessEnvironment(env); } - serverProc.start(findExecutable("server", { + serverProc.start(findExecutable("integration_multiprocess_server", { QCoreApplication::applicationDirPath() + "/../server/" })); QVERIFY(serverProc.waitForStarted()); @@ -92,7 +92,7 @@ private slots: qDebug() << "Starting client process"; QProcess clientProc; clientProc.setProcessChannelMode(QProcess::ForwardedChannels); - clientProc.start(findExecutable("client", { + clientProc.start(findExecutable("integration_multiprocess_client", { QCoreApplication::applicationDirPath() + "/../client/" })); QVERIFY(clientProc.waitForStarted()); diff --git a/tests/auto/proxy_multiprocess/client/client.pro b/tests/auto/proxy_multiprocess/client/client.pro index 7a181a2..aad86e2 100644 --- a/tests/auto/proxy_multiprocess/client/client.pro +++ b/tests/auto/proxy_multiprocess/client/client.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += remoteobjects core testlib QT -= gui -TARGET = client +TARGET = proxy_multiprocess_client DESTDIR = ./ CONFIG += c++11 CONFIG -= app_bundle diff --git a/tests/auto/proxy_multiprocess/client/main.cpp b/tests/auto/proxy_multiprocess/client/main.cpp index f28c65a..89fe043 100644 --- a/tests/auto/proxy_multiprocess/client/main.cpp +++ b/tests/auto/proxy_multiprocess/client/main.cpp @@ -61,7 +61,7 @@ private Q_SLOTS: QVERIFY(m_rep->tracks() != nullptr); QVERIFY(tracksSpy.count() || tracksSpy.wait()); QCOMPARE(m_rep->myEnum(), ParentClassReplica::bar); - QCOMPARE(m_rep->date(), Qt::SystemLocaleShortDate); + QCOMPARE(m_rep->date(), Qt::RFC2822Date); QCOMPARE(m_rep->nsEnum(), NS::Bravo); QCOMPARE(m_rep->ns2Enum(), NS2::NamespaceEnum::Bravo); QCOMPARE(m_rep->variant(), QVariant::fromValue(42.0f)); @@ -100,7 +100,7 @@ private Q_SLOTS: QCOMPARE(m_rep->subClass()->i(), updatedI); QVERIFY(m_rep->tracks() != nullptr); QCOMPARE(m_rep->myEnum(), ParentClassReplica::foobar); - QCOMPARE(m_rep->date(), Qt::SystemLocaleLongDate); + QCOMPARE(m_rep->date(), Qt::ISODateWithMs); QCOMPARE(m_rep->nsEnum(), NS::Charlie); QCOMPARE(m_rep->ns2Enum(), NS2::NamespaceEnum::Charlie); QCOMPARE(m_rep->variant(), QVariant::fromValue(podValue)); diff --git a/tests/auto/proxy_multiprocess/namespace.h b/tests/auto/proxy_multiprocess/namespace.h index 2d06e67..1b9b59e 100644 --- a/tests/auto/proxy_multiprocess/namespace.h +++ b/tests/auto/proxy_multiprocess/namespace.h @@ -1,3 +1,6 @@ +#ifndef __PROXY_MULTIPROCESS_NAMESPACE_H__ +#define __PROXY_MULTIPROCESS_NAMESPACE_H__ + #include <QMetaType> namespace NS @@ -13,3 +16,5 @@ namespace NS2 enum class NamespaceEnum : quint8 { Alpha=1, Bravo, Charlie }; Q_ENUM_NS(NamespaceEnum) } + +#endif // include guard diff --git a/tests/auto/proxy_multiprocess/server/main.cpp b/tests/auto/proxy_multiprocess/server/main.cpp index 1e8f107..04682bc 100644 --- a/tests/auto/proxy_multiprocess/server/main.cpp +++ b/tests/auto/proxy_multiprocess/server/main.cpp @@ -56,7 +56,7 @@ private Q_SLOTS: parent.setSubClass(&subclass); parent.setTracks(&model); parent.setMyEnum(ParentClassSource::bar); - parent.setDate(Qt::SystemLocaleShortDate); + parent.setDate(Qt::RFC2822Date); parent.setNsEnum(NS::Bravo); parent.setNs2Enum(NS2::NamespaceEnum::Bravo); parent.setVariant(QVariant::fromValue(42.0f)); @@ -85,7 +85,7 @@ private Q_SLOTS: if (objectMode == QLatin1String("NullPointer")) parent.setTracks(&model); parent.setMyEnum(ParentClassSource::foobar); - parent.setDate(Qt::SystemLocaleLongDate); + parent.setDate(Qt::ISODateWithMs); parent.setNsEnum(NS::Charlie); parent.setNs2Enum(NS2::NamespaceEnum::Charlie); parent.setVariant(QVariant::fromValue(podValue)); diff --git a/tests/auto/proxy_multiprocess/server/mytestserver.cpp b/tests/auto/proxy_multiprocess/server/mytestserver.cpp index e55739d..19302ce 100644 --- a/tests/auto/proxy_multiprocess/server/mytestserver.cpp +++ b/tests/auto/proxy_multiprocess/server/mytestserver.cpp @@ -63,5 +63,5 @@ ParentClassSource::MyEnum MyTestServer::enumSlot(QPoint p, MyEnum myEnum) Qt::DateFormat MyTestServer::dateSlot(Qt::DateFormat date) { Q_UNUSED(date) - return Qt::SystemLocaleDate; + return Qt::RFC2822Date; } diff --git a/tests/auto/proxy_multiprocess/server/server.pro b/tests/auto/proxy_multiprocess/server/server.pro index 02ca498..a56477b 100644 --- a/tests/auto/proxy_multiprocess/server/server.pro +++ b/tests/auto/proxy_multiprocess/server/server.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += remoteobjects core testlib QT -= gui -TARGET = server +TARGET = proxy_multiprocess_server DESTDIR = ./ CONFIG += c++11 CONFIG -= app_bundle diff --git a/tests/auto/proxy_multiprocess/tst/tst_proxy_multiprocess.cpp b/tests/auto/proxy_multiprocess/tst/tst_proxy_multiprocess.cpp index e7f382b..6973101 100644 --- a/tests/auto/proxy_multiprocess/tst/tst_proxy_multiprocess.cpp +++ b/tests/auto/proxy_multiprocess/tst/tst_proxy_multiprocess.cpp @@ -89,7 +89,7 @@ private slots: env.insert("TEMPLATED_REMOTING", "true"); } serverProc.setProcessEnvironment(env); - serverProc.start(findExecutable("server", { + serverProc.start(findExecutable("proxy_multiprocess_server", { QCoreApplication::applicationDirPath() + "/../server/" })); QVERIFY(serverProc.waitForStarted()); @@ -102,7 +102,7 @@ private slots: QProcess clientProc; clientProc.setProcessChannelMode(QProcess::ForwardedChannels); clientProc.setProcessEnvironment(env); - clientProc.start(findExecutable("client", { + clientProc.start(findExecutable("proxy_multiprocess_client", { QCoreApplication::applicationDirPath() + "/../client/" })); QVERIFY(clientProc.waitForStarted()); diff --git a/tests/auto/qml/integration/integration.pro b/tests/auto/qml/integration/integration.pro index 0ad77a0..74c1ec9 100644 --- a/tests/auto/qml/integration/integration.pro +++ b/tests/auto/qml/integration/integration.pro @@ -1,5 +1,5 @@ TEMPLATE = app -TARGET = tst_integration +TARGET = tst_qmlintegration CONFIG += qmltestcase SOURCES += \ diff --git a/tests/auto/qml/usertypes/data/hosted.qml b/tests/auto/qml/usertypes/data/hosted.qml new file mode 100644 index 0000000..743a5c7 --- /dev/null +++ b/tests/auto/qml/usertypes/data/hosted.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 +import QtRemoteObjects 5.15 +import usertypes 1.0 + +Item { + SimpleClockSimpleSource { + id: clock + } + + Host { + hostUrl: "local:testHost" + Component.onCompleted: enableRemoting(clock) + } +} diff --git a/tests/auto/qml/usertypes/tst_usertypes.cpp b/tests/auto/qml/usertypes/tst_usertypes.cpp index 07bed59..e5a8b6f 100644 --- a/tests/auto/qml/usertypes/tst_usertypes.cpp +++ b/tests/auto/qml/usertypes/tst_usertypes.cpp @@ -62,6 +62,7 @@ private Q_SLOTS: void complexInQml_data(); void complexInQml(); void watcherInQml(); + void hostInQml(); }; tst_usertypes::tst_usertypes() @@ -235,6 +236,21 @@ void tst_usertypes::watcherInQml() QCOMPARE(obj->property("hasError").value<bool>(), false); } +void tst_usertypes::hostInQml() +{ + qmlRegisterType<SimpleClockSimpleSource>("usertypes", 1, 0, "SimpleClockSimpleSource"); + + QQmlEngine e; + QQmlComponent c(&e, SRCDIR "data/hosted.qml"); + QObject *obj = c.create(); + QVERIFY(obj); + + QRemoteObjectNode node; + node.connectToNode(QUrl("local:testHost")); + SimpleClockReplica *replica = node.acquire<SimpleClockReplica>(); + QTRY_COMPARE_WITH_TIMEOUT(replica->state(), QRemoteObjectReplica::Valid, 300); +} + QTEST_MAIN(tst_usertypes) #include "tst_usertypes.moc" diff --git a/tests/auto/repc/pods/pods.pro b/tests/auto/repc/pods/pods.pro index c32fffa..dc7b717 100644 --- a/tests/auto/repc/pods/pods.pro +++ b/tests/auto/repc/pods/pods.pro @@ -1,5 +1,5 @@ CONFIG += testcase -TARGET = tst_pods +TARGET = tst_repc_pods QT += testlib remoteobjects QT -= gui diff --git a/tests/auto/restart/client/client.pro b/tests/auto/restart/client/client.pro index ce435c2..24a83b3 100644 --- a/tests/auto/restart/client/client.pro +++ b/tests/auto/restart/client/client.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += remoteobjects core testlib QT -= gui -TARGET = client +TARGET = restart_client DESTDIR = ./ CONFIG += c++11 CONFIG -= app_bundle diff --git a/tests/auto/restart/server/server.pro b/tests/auto/restart/server/server.pro index eefc7a5..4ad55ee 100644 --- a/tests/auto/restart/server/server.pro +++ b/tests/auto/restart/server/server.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += remoteobjects core testlib QT -= gui -TARGET = server +TARGET = restart_server DESTDIR = ./ CONFIG += c++11 CONFIG -= app_bundle @@ -14,6 +14,5 @@ SOURCES += main.cpp \ HEADERS += \ mytestserver.h - $$OUT_PWD/rep_subclass_source.h INCLUDEPATH += $$PWD diff --git a/tests/auto/restart/tst/tst_restart.cpp b/tests/auto/restart/tst/tst_restart.cpp index a3633fa..d76b3de 100644 --- a/tests/auto/restart/tst/tst_restart.cpp +++ b/tests/auto/restart/tst/tst_restart.cpp @@ -96,7 +96,7 @@ private slots: env.insert("RunMode", QVariant::fromValue(runMode).toString()); env.insert("ObjectMode", QVariant::fromValue(objectMode).toString()); serverProc.setProcessEnvironment(env); - serverProc.start(findExecutable("server", { + serverProc.start(findExecutable("restart_server", { QCoreApplication::applicationDirPath() + "/../server/" })); QVERIFY(serverProc.waitForStarted()); @@ -108,7 +108,7 @@ private slots: QProcess clientProc; clientProc.setProcessChannelMode(QProcess::ForwardedChannels); clientProc.setProcessEnvironment(env); - clientProc.start(findExecutable("client", { + clientProc.start(findExecutable("restart_client", { QCoreApplication::applicationDirPath() + "/../client/" })); QVERIFY(clientProc.waitForStarted()); @@ -123,7 +123,7 @@ private slots: QCOMPARE(serverProc.exitCode(), 0); qDebug() << "Restarting server"; serverProc.setProcessEnvironment(env); - serverProc.start(findExecutable("server", { + serverProc.start(findExecutable("restart_server", { QCoreApplication::applicationDirPath() + "/../server/" })); QVERIFY(serverProc.waitForStarted()); diff --git a/tests/auto/shared/model_utilities.h b/tests/auto/shared/model_utilities.h index 60bb7b2..ab71d15 100644 --- a/tests/auto/shared/model_utilities.h +++ b/tests/auto/shared/model_utilities.h @@ -68,7 +68,7 @@ struct WaitForDataChanged cancel = m_pending.isEmpty(); } if (!cancel) - m_spy->wait(50); + m_spy->wait(); ++runs; if (runs >= maxRuns) cancel = true; diff --git a/tools/repc/moc_copy/generator.cpp b/tools/repc/moc_copy/generator.cpp deleted file mode 100644 index c418492..0000000 --- a/tools/repc/moc_copy/generator.cpp +++ /dev/null @@ -1,1601 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "generator.h" -#include "outputrevision.h" -#include "utils.h" -#include <QtCore/qmetatype.h> -#include <QtCore/qjsondocument.h> -#include <QtCore/qjsonobject.h> -#include <QtCore/qjsonvalue.h> -#include <QtCore/qjsonarray.h> -#include <QtCore/qplugin.h> -#include <stdio.h> - -#include <private/qmetaobject_p.h> //for the flags. - -QT_BEGIN_NAMESPACE - -uint nameToBuiltinType(const QByteArray &name) -{ - if (name.isEmpty()) - return 0; - - uint tp = QMetaType::type(name.constData()); - return tp < uint(QMetaType::User) ? tp : uint(QMetaType::UnknownType); -} - -/* - Returns \c true if the type is a built-in type. -*/ -bool isBuiltinType(const QByteArray &type) - { - int id = QMetaType::type(type.constData()); - if (id == QMetaType::UnknownType) - return false; - return (id < QMetaType::User); -} - -static const char *metaTypeEnumValueString(int type) - { -#define RETURN_METATYPENAME_STRING(MetaTypeName, MetaTypeId, RealType) \ - case QMetaType::MetaTypeName: return #MetaTypeName; - - switch (type) { -QT_FOR_EACH_STATIC_TYPE(RETURN_METATYPENAME_STRING) - } -#undef RETURN_METATYPENAME_STRING - return 0; - } - -Generator::Generator(ClassDef *classDef, const QList<QByteArray> &metaTypes, const QHash<QByteArray, QByteArray> &knownQObjectClasses, const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile) - : out(outfile), cdef(classDef), metaTypes(metaTypes), knownQObjectClasses(knownQObjectClasses) - , knownGadgets(knownGadgets) -{ - if (cdef->superclassList.size()) - purestSuperClass = cdef->superclassList.constFirst().first; -} - -static inline int lengthOfEscapeSequence(const QByteArray &s, int i) -{ - if (s.at(i) != '\\' || i >= s.length() - 1) - return 1; - const int startPos = i; - ++i; - char ch = s.at(i); - if (ch == 'x') { - ++i; - while (i < s.length() && is_hex_char(s.at(i))) - ++i; - } else if (is_octal_char(ch)) { - while (i < startPos + 4 - && i < s.length() - && is_octal_char(s.at(i))) { - ++i; - } - } else { // single character escape sequence - i = qMin(i + 1, s.length()); - } - return i - startPos; -} - -void Generator::strreg(const QByteArray &s) -{ - if (!strings.contains(s)) - strings.append(s); -} - -int Generator::stridx(const QByteArray &s) -{ - int i = strings.indexOf(s); - Q_ASSERT_X(i != -1, Q_FUNC_INFO, "We forgot to register some strings"); - return i; -} - -// Returns the sum of all parameters (including return type) for the given -// \a list of methods. This is needed for calculating the size of the methods' -// parameter type/name meta-data. -static int aggregateParameterCount(const QVector<FunctionDef> &list) -{ - int sum = 0; - for (int i = 0; i < list.count(); ++i) - sum += list.at(i).arguments.count() + 1; // +1 for return type - return sum; -} - -bool Generator::registerableMetaType(const QByteArray &propertyType) -{ - if (metaTypes.contains(propertyType)) - return true; - - if (propertyType.endsWith('*')) { - QByteArray objectPointerType = propertyType; - // The objects container stores class names, such as 'QState', 'QLabel' etc, - // not 'QState*', 'QLabel*'. The propertyType does contain the '*', so we need - // to chop it to find the class type in the known QObjects list. - objectPointerType.chop(1); - if (knownQObjectClasses.contains(objectPointerType)) - return true; - } - - static const QVector<QByteArray> smartPointers = QVector<QByteArray>() -#define STREAM_SMART_POINTER(SMART_POINTER) << #SMART_POINTER - QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(STREAM_SMART_POINTER) -#undef STREAM_SMART_POINTER - ; - - for (const QByteArray &smartPointer : smartPointers) { - if (propertyType.startsWith(smartPointer + "<") && !propertyType.endsWith("&")) - return knownQObjectClasses.contains(propertyType.mid(smartPointer.size() + 1, propertyType.size() - smartPointer.size() - 1 - 1)); - } - - static const QVector<QByteArray> oneArgTemplates = QVector<QByteArray>() -#define STREAM_1ARG_TEMPLATE(TEMPLATENAME) << #TEMPLATENAME - QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(STREAM_1ARG_TEMPLATE) -#undef STREAM_1ARG_TEMPLATE - ; - for (const QByteArray &oneArgTemplateType : oneArgTemplates) { - if (propertyType.startsWith(oneArgTemplateType + "<") && propertyType.endsWith(">")) { - const int argumentSize = propertyType.size() - oneArgTemplateType.size() - 1 - // The closing '>' - - 1 - // templates inside templates have an extra whitespace char to strip. - - (propertyType.at(propertyType.size() - 2) == ' ' ? 1 : 0 ); - const QByteArray templateArg = propertyType.mid(oneArgTemplateType.size() + 1, argumentSize); - return isBuiltinType(templateArg) || registerableMetaType(templateArg); - } - } - return false; -} - -/* returns \c true if name and qualifiedName refers to the same name. - * If qualified name is "A::B::C", it returns \c true for "C", "B::C" or "A::B::C" */ -static bool qualifiedNameEquals(const QByteArray &qualifiedName, const QByteArray &name) -{ - if (qualifiedName == name) - return true; - int index = qualifiedName.indexOf("::"); - if (index == -1) - return false; - return qualifiedNameEquals(qualifiedName.mid(index+2), name); -} - -void Generator::generateCode() -{ - bool isQt = (cdef->classname == "Qt"); - bool isQObject = (cdef->classname == "QObject"); - bool isConstructible = !cdef->constructorList.isEmpty(); - - // filter out undeclared enumerators and sets - { - QVector<EnumDef> enumList; - for (int i = 0; i < cdef->enumList.count(); ++i) { - EnumDef def = cdef->enumList.at(i); - if (cdef->enumDeclarations.contains(def.name)) { - enumList += def; - } - QByteArray alias = cdef->flagAliases.value(def.name); - if (cdef->enumDeclarations.contains(alias)) { - def.name = alias; - enumList += def; - } - } - cdef->enumList = enumList; - } - -// -// Register all strings used in data section -// - strreg(cdef->qualified); - registerClassInfoStrings(); - registerFunctionStrings(cdef->signalList); - registerFunctionStrings(cdef->slotList); - registerFunctionStrings(cdef->methodList); - registerFunctionStrings(cdef->constructorList); - registerPropertyStrings(); - registerEnumStrings(); - - QByteArray qualifiedClassNameIdentifier = cdef->qualified; - qualifiedClassNameIdentifier.replace(':', '_'); - -// -// Build stringdata struct -// - const int constCharArraySizeLimit = 65535; - fprintf(out, "struct qt_meta_stringdata_%s_t {\n", qualifiedClassNameIdentifier.constData()); - fprintf(out, " QByteArrayData data[%d];\n", strings.size()); - { - int stringDataLength = 0; - int stringDataCounter = 0; - for (int i = 0; i < strings.size(); ++i) { - int thisLength = strings.at(i).length() + 1; - stringDataLength += thisLength; - if (stringDataLength / constCharArraySizeLimit) { - // save previous stringdata and start computing the next one. - fprintf(out, " char stringdata%d[%d];\n", stringDataCounter++, stringDataLength - thisLength); - stringDataLength = thisLength; - } - } - fprintf(out, " char stringdata%d[%d];\n", stringDataCounter, stringDataLength); - - } - fprintf(out, "};\n"); - - // Macro that expands into a QByteArrayData. The offset member is - // calculated from 1) the offset of the actual characters in the - // stringdata.stringdata member, and 2) the stringdata.data index of the - // QByteArrayData being defined. This calculation relies on the - // QByteArrayData::data() implementation returning simply "this + offset". - fprintf(out, "#define QT_MOC_LITERAL(idx, ofs, len) \\\n" - " Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \\\n" - " qptrdiff(offsetof(qt_meta_stringdata_%s_t, stringdata0) + ofs \\\n" - " - idx * sizeof(QByteArrayData)) \\\n" - " )\n", - qualifiedClassNameIdentifier.constData()); - - fprintf(out, "static const qt_meta_stringdata_%s_t qt_meta_stringdata_%s = {\n", - qualifiedClassNameIdentifier.constData(), qualifiedClassNameIdentifier.constData()); - fprintf(out, " {\n"); - { - int idx = 0; - for (int i = 0; i < strings.size(); ++i) { - const QByteArray &str = strings.at(i); - fprintf(out, "QT_MOC_LITERAL(%d, %d, %d)", i, idx, str.length()); - if (i != strings.size() - 1) - fputc(',', out); - const QByteArray comment = str.length() > 32 ? str.left(29) + "..." : str; - fprintf(out, " // \"%s\"\n", comment.constData()); - idx += str.length() + 1; - for (int j = 0; j < str.length(); ++j) { - if (str.at(j) == '\\') { - int cnt = lengthOfEscapeSequence(str, j) - 1; - idx -= cnt; - j += cnt; - } - } - } - fprintf(out, "\n },\n"); - } - -// -// Build stringdata array -// - fprintf(out, " \""); - int col = 0; - int len = 0; - int stringDataLength = 0; - for (int i = 0; i < strings.size(); ++i) { - QByteArray s = strings.at(i); - len = s.length(); - stringDataLength += len + 1; - if (stringDataLength >= constCharArraySizeLimit) { - fprintf(out, "\",\n \""); - stringDataLength = len + 1; - col = 0; - } else if (i) - fputs("\\0", out); // add \0 at the end of each string - - if (col && col + len >= 72) { - fprintf(out, "\"\n \""); - col = 0; - } else if (len && s.at(0) >= '0' && s.at(0) <= '9') { - fprintf(out, "\"\""); - len += 2; - } - int idx = 0; - while (idx < s.length()) { - if (idx > 0) { - col = 0; - fprintf(out, "\"\n \""); - } - int spanLen = qMin(70, s.length() - idx); - // don't cut escape sequences at the end of a line - int backSlashPos = s.lastIndexOf('\\', idx + spanLen - 1); - if (backSlashPos >= idx) { - int escapeLen = lengthOfEscapeSequence(s, backSlashPos); - spanLen = qBound(spanLen, backSlashPos + escapeLen - idx, s.length() - idx); - } - fprintf(out, "%.*s", spanLen, s.constData() + idx); - idx += spanLen; - col += spanLen; - } - col += len + 2; - } - -// Terminate stringdata struct - fprintf(out, "\"\n};\n"); - fprintf(out, "#undef QT_MOC_LITERAL\n\n"); - -// -// build the data array -// - - int index = MetaObjectPrivateFieldCount; - fprintf(out, "static const uint qt_meta_data_%s[] = {\n", qualifiedClassNameIdentifier.constData()); - fprintf(out, "\n // content:\n"); - fprintf(out, " %4d, // revision\n", int(QMetaObjectPrivate::OutputRevision)); - fprintf(out, " %4d, // classname\n", stridx(cdef->qualified)); - fprintf(out, " %4d, %4d, // classinfo\n", cdef->classInfoList.count(), cdef->classInfoList.count() ? index : 0); - index += cdef->classInfoList.count() * 2; - - int methodCount = cdef->signalList.count() + cdef->slotList.count() + cdef->methodList.count(); - fprintf(out, " %4d, %4d, // methods\n", methodCount, methodCount ? index : 0); - index += methodCount * 5; - if (cdef->revisionedMethods) - index += methodCount; - int paramsIndex = index; - int totalParameterCount = aggregateParameterCount(cdef->signalList) - + aggregateParameterCount(cdef->slotList) - + aggregateParameterCount(cdef->methodList) - + aggregateParameterCount(cdef->constructorList); - index += totalParameterCount * 2 // types and parameter names - - methodCount // return "parameters" don't have names - - cdef->constructorList.count(); // "this" parameters don't have names - - fprintf(out, " %4d, %4d, // properties\n", cdef->propertyList.count(), cdef->propertyList.count() ? index : 0); - index += cdef->propertyList.count() * 3; - if(cdef->notifyableProperties) - index += cdef->propertyList.count(); - if (cdef->revisionedProperties) - index += cdef->propertyList.count(); - fprintf(out, " %4d, %4d, // enums/sets\n", cdef->enumList.count(), cdef->enumList.count() ? index : 0); - - int enumsIndex = index; - for (int i = 0; i < cdef->enumList.count(); ++i) - index += 4 + (cdef->enumList.at(i).values.count() * 2); - fprintf(out, " %4d, %4d, // constructors\n", isConstructible ? cdef->constructorList.count() : 0, - isConstructible ? index : 0); - - int flags = 0; - if (cdef->hasQGadget) { - // Ideally, all the classes could have that flag. But this broke classes generated - // by qdbusxml2cpp which generate code that require that we call qt_metacall for properties - flags |= PropertyAccessInStaticMetaCall; - } - fprintf(out, " %4d, // flags\n", flags); - fprintf(out, " %4d, // signalCount\n", cdef->signalList.count()); - - -// -// Build classinfo array -// - generateClassInfos(); - -// -// Build signals array first, otherwise the signal indices would be wrong -// - generateFunctions(cdef->signalList, "signal", MethodSignal, paramsIndex); - -// -// Build slots array -// - generateFunctions(cdef->slotList, "slot", MethodSlot, paramsIndex); - -// -// Build method array -// - generateFunctions(cdef->methodList, "method", MethodMethod, paramsIndex); - -// -// Build method version arrays -// - if (cdef->revisionedMethods) { - generateFunctionRevisions(cdef->signalList, "signal"); - generateFunctionRevisions(cdef->slotList, "slot"); - generateFunctionRevisions(cdef->methodList, "method"); - } - -// -// Build method parameters array -// - generateFunctionParameters(cdef->signalList, "signal"); - generateFunctionParameters(cdef->slotList, "slot"); - generateFunctionParameters(cdef->methodList, "method"); - if (isConstructible) - generateFunctionParameters(cdef->constructorList, "constructor"); - -// -// Build property array -// - generateProperties(); - -// -// Build enums array -// - generateEnums(enumsIndex); - -// -// Build constructors array -// - if (isConstructible) - generateFunctions(cdef->constructorList, "constructor", MethodConstructor, paramsIndex); - -// -// Terminate data array -// - fprintf(out, "\n 0 // eod\n};\n\n"); - -// -// Generate internal qt_static_metacall() function -// - const bool hasStaticMetaCall = !isQt && - (cdef->hasQObject || !cdef->methodList.isEmpty() - || !cdef->propertyList.isEmpty() || !cdef->constructorList.isEmpty()); - if (hasStaticMetaCall) - generateStaticMetacall(); - -// -// Build extra array -// - QList<QByteArray> extraList; - QHash<QByteArray, QByteArray> knownExtraMetaObject = knownGadgets; - knownExtraMetaObject.unite(knownQObjectClasses); - - for (int i = 0; i < cdef->propertyList.count(); ++i) { - const PropertyDef &p = cdef->propertyList.at(i); - if (isBuiltinType(p.type)) - continue; - - if (p.type.contains('*') || p.type.contains('<') || p.type.contains('>')) - continue; - - int s = p.type.lastIndexOf("::"); - if (s <= 0) - continue; - - QByteArray unqualifiedScope = p.type.left(s); - - // The scope may be a namespace for example, so it's only safe to include scopes that are known QObjects (QTBUG-2151) - QHash<QByteArray, QByteArray>::ConstIterator scopeIt; - - QByteArray thisScope = cdef->qualified; - do { - int s = thisScope.lastIndexOf("::"); - thisScope = thisScope.left(s); - QByteArray currentScope = thisScope.isEmpty() ? unqualifiedScope : thisScope + "::" + unqualifiedScope; - scopeIt = knownExtraMetaObject.constFind(currentScope); - } while (!thisScope.isEmpty() && scopeIt == knownExtraMetaObject.constEnd()); - - if (scopeIt == knownExtraMetaObject.constEnd()) - continue; - - const QByteArray &scope = *scopeIt; - - if (scope == "Qt") - continue; - if (qualifiedNameEquals(cdef->qualified, scope)) - continue; - - if (!extraList.contains(scope)) - extraList += scope; - } - - // QTBUG-20639 - Accept non-local enums for QML signal/slot parameters. - // Look for any scoped enum declarations, and add those to the list - // of extra/related metaobjects for this object. - for (auto it = cdef->enumDeclarations.keyBegin(), - end = cdef->enumDeclarations.keyEnd(); it != end; ++it) { - const QByteArray &enumKey = *it; - int s = enumKey.lastIndexOf("::"); - if (s > 0) { - QByteArray scope = enumKey.left(s); - if (scope != "Qt" && !qualifiedNameEquals(cdef->qualified, scope) && !extraList.contains(scope)) - extraList += scope; - } - } - - if (!extraList.isEmpty()) { - fprintf(out, "static const QMetaObject * const qt_meta_extradata_%s[] = {\n ", qualifiedClassNameIdentifier.constData()); - for (int i = 0; i < extraList.count(); ++i) { - fprintf(out, " &%s::staticMetaObject,\n", extraList.at(i).constData()); - } - fprintf(out, " nullptr\n};\n\n"); - } - -// -// Finally create and initialize the static meta object -// - if (isQt) - fprintf(out, "const QMetaObject QObject::staticQtMetaObject = {\n"); - else - fprintf(out, "const QMetaObject %s::staticMetaObject = {\n", cdef->qualified.constData()); - - if (isQObject) - fprintf(out, " { nullptr, "); - else if (cdef->superclassList.size() && (!cdef->hasQGadget || knownGadgets.contains(purestSuperClass))) - fprintf(out, " { &%s::staticMetaObject, ", purestSuperClass.constData()); - else - fprintf(out, " { nullptr, "); - fprintf(out, "qt_meta_stringdata_%s.data,\n" - " qt_meta_data_%s, ", qualifiedClassNameIdentifier.constData(), - qualifiedClassNameIdentifier.constData()); - if (hasStaticMetaCall) - fprintf(out, " qt_static_metacall, "); - else - fprintf(out, " nullptr, "); - - if (extraList.isEmpty()) - fprintf(out, "nullptr, "); - else - fprintf(out, "qt_meta_extradata_%s, ", qualifiedClassNameIdentifier.constData()); - fprintf(out, "nullptr}\n};\n\n"); - - if(isQt) - return; - - if (!cdef->hasQObject) - return; - - fprintf(out, "\nconst QMetaObject *%s::metaObject() const\n{\n return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;\n}\n", - cdef->qualified.constData()); - -// -// Generate smart cast function -// - fprintf(out, "\nvoid *%s::qt_metacast(const char *_clname)\n{\n", cdef->qualified.constData()); - fprintf(out, " if (!_clname) return nullptr;\n"); - fprintf(out, " if (!strcmp(_clname, qt_meta_stringdata_%s.stringdata0))\n" - " return static_cast<void*>(const_cast< %s*>(this));\n", - qualifiedClassNameIdentifier.constData(), cdef->classname.constData()); - for (int i = 1; i < cdef->superclassList.size(); ++i) { // for all superclasses but the first one - if (cdef->superclassList.at(i).second == FunctionDef::Private) - continue; - const char *cname = cdef->superclassList.at(i).first.constData(); - fprintf(out, " if (!strcmp(_clname, \"%s\"))\n return static_cast< %s*>(const_cast< %s*>(this));\n", - cname, cname, cdef->classname.constData()); - } - for (int i = 0; i < cdef->interfaceList.size(); ++i) { - const QVector<ClassDef::Interface> &iface = cdef->interfaceList.at(i); - for (int j = 0; j < iface.size(); ++j) { - fprintf(out, " if (!strcmp(_clname, %s))\n return ", iface.at(j).interfaceId.constData()); - for (int k = j; k >= 0; --k) - fprintf(out, "static_cast< %s*>(", iface.at(k).className.constData()); - fprintf(out, "const_cast< %s*>(this)%s;\n", - cdef->classname.constData(), QByteArray(j+1, ')').constData()); - } - } - if (!purestSuperClass.isEmpty() && !isQObject) { - QByteArray superClass = purestSuperClass; - fprintf(out, " return %s::qt_metacast(_clname);\n", superClass.constData()); - } else { - fprintf(out, " return nullptr;\n"); - } - fprintf(out, "}\n"); - -// -// Generate internal qt_metacall() function -// - generateMetacall(); - -// -// Generate internal signal functions -// - for (int signalindex = 0; signalindex < cdef->signalList.size(); ++signalindex) - generateSignal(&cdef->signalList[signalindex], signalindex); - -// -// Generate plugin meta data -// - generatePluginMetaData(); -} - - -void Generator::registerClassInfoStrings() -{ - for (int i = 0; i < cdef->classInfoList.size(); ++i) { - const ClassInfoDef &c = cdef->classInfoList.at(i); - strreg(c.name); - strreg(c.value); - } -} - -void Generator::generateClassInfos() -{ - if (cdef->classInfoList.isEmpty()) - return; - - fprintf(out, "\n // classinfo: key, value\n"); - - for (int i = 0; i < cdef->classInfoList.size(); ++i) { - const ClassInfoDef &c = cdef->classInfoList.at(i); - fprintf(out, " %4d, %4d,\n", stridx(c.name), stridx(c.value)); - } -} - -void Generator::registerFunctionStrings(const QVector<FunctionDef>& list) -{ - for (int i = 0; i < list.count(); ++i) { - const FunctionDef &f = list.at(i); - - strreg(f.name); - if (!isBuiltinType(f.normalizedType)) - strreg(f.normalizedType); - strreg(f.tag); - - int argsCount = f.arguments.count(); - for (int j = 0; j < argsCount; ++j) { - const ArgumentDef &a = f.arguments.at(j); - if (!isBuiltinType(a.normalizedType)) - strreg(a.normalizedType); - strreg(a.name); - } - } -} - -void Generator::generateFunctions(const QVector<FunctionDef>& list, const char *functype, int type, int ¶msIndex) -{ - if (list.isEmpty()) - return; - fprintf(out, "\n // %ss: name, argc, parameters, tag, flags\n", functype); - - for (int i = 0; i < list.count(); ++i) { - const FunctionDef &f = list.at(i); - - QByteArray comment; - unsigned char flags = type; - if (f.access == FunctionDef::Private) { - flags |= AccessPrivate; - comment.append("Private"); - } else if (f.access == FunctionDef::Public) { - flags |= AccessPublic; - comment.append("Public"); - } else if (f.access == FunctionDef::Protected) { - flags |= AccessProtected; - comment.append("Protected"); - } - if (f.isCompat) { - flags |= MethodCompatibility; - comment.append(" | MethodCompatibility"); - } - if (f.wasCloned) { - flags |= MethodCloned; - comment.append(" | MethodCloned"); - } - if (f.isScriptable) { - flags |= MethodScriptable; - comment.append(" | isScriptable"); - } - if (f.revision > 0) { - flags |= MethodRevisioned; - comment.append(" | MethodRevisioned"); - } - - int argc = f.arguments.count(); - fprintf(out, " %4d, %4d, %4d, %4d, 0x%02x /* %s */,\n", - stridx(f.name), argc, paramsIndex, stridx(f.tag), flags, comment.constData()); - - paramsIndex += 1 + argc * 2; - } -} - -void Generator::generateFunctionRevisions(const QVector<FunctionDef>& list, const char *functype) -{ - if (list.count()) - fprintf(out, "\n // %ss: revision\n", functype); - for (int i = 0; i < list.count(); ++i) { - const FunctionDef &f = list.at(i); - fprintf(out, " %4d,\n", f.revision); - } -} - -void Generator::generateFunctionParameters(const QVector<FunctionDef>& list, const char *functype) -{ - if (list.isEmpty()) - return; - fprintf(out, "\n // %ss: parameters\n", functype); - for (int i = 0; i < list.count(); ++i) { - const FunctionDef &f = list.at(i); - fprintf(out, " "); - - // Types - int argsCount = f.arguments.count(); - for (int j = -1; j < argsCount; ++j) { - if (j > -1) - fputc(' ', out); - const QByteArray &typeName = (j < 0) ? f.normalizedType : f.arguments.at(j).normalizedType; - generateTypeInfo(typeName, /*allowEmptyName=*/f.isConstructor); - fputc(',', out); - } - - // Parameter names - for (int j = 0; j < argsCount; ++j) { - const ArgumentDef &arg = f.arguments.at(j); - fprintf(out, " %4d,", stridx(arg.name)); - } - - fprintf(out, "\n"); - } -} - -void Generator::generateTypeInfo(const QByteArray &typeName, bool allowEmptyName) -{ - Q_UNUSED(allowEmptyName); - if (isBuiltinType(typeName)) { - int type; - const char *valueString; - if (typeName == "qreal") { - type = QMetaType::UnknownType; - valueString = "QReal"; - } else { - type = nameToBuiltinType(typeName); - valueString = metaTypeEnumValueString(type); - } - if (valueString) { - fprintf(out, "QMetaType::%s", valueString); - } else { - Q_ASSERT(type != QMetaType::UnknownType); - fprintf(out, "%4d", type); - } - } else { - Q_ASSERT(!typeName.isEmpty() || allowEmptyName); - fprintf(out, "0x%.8x | %d", IsUnresolvedType, stridx(typeName)); - } -} - -void Generator::registerPropertyStrings() -{ - for (int i = 0; i < cdef->propertyList.count(); ++i) { - const PropertyDef &p = cdef->propertyList.at(i); - strreg(p.name); - if (!isBuiltinType(p.type)) - strreg(p.type); - } -} - -void Generator::generateProperties() -{ - // - // Create meta data - // - - if (cdef->propertyList.count()) - fprintf(out, "\n // properties: name, type, flags\n"); - for (int i = 0; i < cdef->propertyList.count(); ++i) { - const PropertyDef &p = cdef->propertyList.at(i); - uint flags = Invalid; - if (!isBuiltinType(p.type)) - flags |= EnumOrFlag; - if (!p.member.isEmpty() && !p.constant) - flags |= Writable; - if (!p.read.isEmpty() || !p.member.isEmpty()) - flags |= Readable; - if (!p.write.isEmpty()) { - flags |= Writable; - if (p.stdCppSet()) - flags |= StdCppSet; - } - if (!p.reset.isEmpty()) - flags |= Resettable; - -// if (p.override) -// flags |= Override; - - if (p.designable.isEmpty()) - flags |= ResolveDesignable; - else if (p.designable != "false") - flags |= Designable; - - if (p.scriptable.isEmpty()) - flags |= ResolveScriptable; - else if (p.scriptable != "false") - flags |= Scriptable; - - if (p.stored.isEmpty()) - flags |= ResolveStored; - else if (p.stored != "false") - flags |= Stored; - - if (p.editable.isEmpty()) - flags |= ResolveEditable; - else if (p.editable != "false") - flags |= Editable; - - if (p.user.isEmpty()) - flags |= ResolveUser; - else if (p.user != "false") - flags |= User; - - if (p.notifyId != -1) - flags |= Notify; - - if (p.revision > 0) - flags |= Revisioned; - - if (p.constant) - flags |= Constant; - if (p.final) - flags |= Final; - - fprintf(out, " %4d, ", stridx(p.name)); - generateTypeInfo(p.type); - fprintf(out, ", 0x%.8x,\n", flags); - } - - if(cdef->notifyableProperties) { - fprintf(out, "\n // properties: notify_signal_id\n"); - for (int i = 0; i < cdef->propertyList.count(); ++i) { - const PropertyDef &p = cdef->propertyList.at(i); - if(p.notifyId == -1) - fprintf(out, " %4d,\n", - 0); - else - fprintf(out, " %4d,\n", - p.notifyId); - } - } - if (cdef->revisionedProperties) { - fprintf(out, "\n // properties: revision\n"); - for (int i = 0; i < cdef->propertyList.count(); ++i) { - const PropertyDef &p = cdef->propertyList.at(i); - fprintf(out, " %4d,\n", p.revision); - } - } -} - -void Generator::registerEnumStrings() -{ - for (int i = 0; i < cdef->enumList.count(); ++i) { - const EnumDef &e = cdef->enumList.at(i); - strreg(e.name); - for (int j = 0; j < e.values.count(); ++j) - strreg(e.values.at(j)); - } -} - -void Generator::generateEnums(int index) -{ - if (cdef->enumDeclarations.isEmpty()) - return; - - fprintf(out, "\n // enums: name, flags, count, data\n"); - index += 4 * cdef->enumList.count(); - int i; - for (i = 0; i < cdef->enumList.count(); ++i) { - const EnumDef &e = cdef->enumList.at(i); - int flags = 0; - if (cdef->enumDeclarations.value(e.name)) - flags |= EnumIsFlag; - if (e.isEnumClass) - flags |= EnumIsScoped; - fprintf(out, " %4d, 0x%.1x, %4d, %4d,\n", - stridx(e.name), - flags, - e.values.count(), - index); - index += e.values.count() * 2; - } - - fprintf(out, "\n // enum data: key, value\n"); - for (i = 0; i < cdef->enumList.count(); ++i) { - const EnumDef &e = cdef->enumList.at(i); - for (int j = 0; j < e.values.count(); ++j) { - const QByteArray &val = e.values.at(j); - QByteArray code = cdef->qualified.constData(); - if (e.isEnumClass) - code += "::" + e.name; - code += "::" + val; - fprintf(out, " %4d, uint(%s),\n", - stridx(val), code.constData()); - } - } -} - -void Generator::generateMetacall() -{ - bool isQObject = (cdef->classname == "QObject"); - - fprintf(out, "\nint %s::qt_metacall(QMetaObject::Call _c, int _id, void **_a)\n{\n", - cdef->qualified.constData()); - - if (!purestSuperClass.isEmpty() && !isQObject) { - QByteArray superClass = purestSuperClass; - fprintf(out, " _id = %s::qt_metacall(_c, _id, _a);\n", superClass.constData()); - } - - - bool needElse = false; - QVector<FunctionDef> methodList; - methodList += cdef->signalList; - methodList += cdef->slotList; - methodList += cdef->methodList; - - // If there are no methods or properties, we will return _id anyway, so - // don't emit this comparison -- it is unnecessary, and it makes coverity - // unhappy. - if (methodList.size() || cdef->propertyList.size()) { - fprintf(out, " if (_id < 0)\n return _id;\n"); - } - - fprintf(out, " "); - - if (methodList.size()) { - needElse = true; - fprintf(out, "if (_c == QMetaObject::InvokeMetaMethod) {\n"); - fprintf(out, " if (_id < %d)\n", methodList.size()); - fprintf(out, " qt_static_metacall(this, _c, _id, _a);\n"); - fprintf(out, " _id -= %d;\n }", methodList.size()); - - fprintf(out, " else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {\n"); - fprintf(out, " if (_id < %d)\n", methodList.size()); - - if (methodsWithAutomaticTypesHelper(methodList).isEmpty()) - fprintf(out, " *reinterpret_cast<int*>(_a[0]) = -1;\n"); - else - fprintf(out, " qt_static_metacall(this, _c, _id, _a);\n"); - fprintf(out, " _id -= %d;\n }", methodList.size()); - - } - - if (cdef->propertyList.size()) { - bool needDesignable = false; - bool needScriptable = false; - bool needStored = false; - bool needEditable = false; - bool needUser = false; - for (int i = 0; i < cdef->propertyList.size(); ++i) { - const PropertyDef &p = cdef->propertyList.at(i); - needDesignable |= p.designable.endsWith(')'); - needScriptable |= p.scriptable.endsWith(')'); - needStored |= p.stored.endsWith(')'); - needEditable |= p.editable.endsWith(')'); - needUser |= p.user.endsWith(')'); - } - - fprintf(out, "\n#ifndef QT_NO_PROPERTIES\n "); - if (needElse) - fprintf(out, "else "); - fprintf(out, - "if (_c == QMetaObject::ReadProperty || _c == QMetaObject::WriteProperty\n" - " || _c == QMetaObject::ResetProperty || _c == QMetaObject::RegisterPropertyMetaType) {\n" - " qt_static_metacall(this, _c, _id, _a);\n" - " _id -= %d;\n }", cdef->propertyList.count()); - - fprintf(out, " else "); - fprintf(out, "if (_c == QMetaObject::QueryPropertyDesignable) {\n"); - if (needDesignable) { - fprintf(out, " bool *_b = reinterpret_cast<bool*>(_a[0]);\n"); - fprintf(out, " switch (_id) {\n"); - for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) { - const PropertyDef &p = cdef->propertyList.at(propindex); - if (!p.designable.endsWith(')')) - continue; - fprintf(out, " case %d: *_b = %s; break;\n", - propindex, p.designable.constData()); - } - fprintf(out, " default: break;\n"); - fprintf(out, " }\n"); - } - fprintf(out, - " _id -= %d;\n" - " }", cdef->propertyList.count()); - - fprintf(out, " else "); - fprintf(out, "if (_c == QMetaObject::QueryPropertyScriptable) {\n"); - if (needScriptable) { - fprintf(out, " bool *_b = reinterpret_cast<bool*>(_a[0]);\n"); - fprintf(out, " switch (_id) {\n"); - for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) { - const PropertyDef &p = cdef->propertyList.at(propindex); - if (!p.scriptable.endsWith(')')) - continue; - fprintf(out, " case %d: *_b = %s; break;\n", - propindex, p.scriptable.constData()); - } - fprintf(out, " default: break;\n"); - fprintf(out, " }\n"); - } - fprintf(out, - " _id -= %d;\n" - " }", cdef->propertyList.count()); - - fprintf(out, " else "); - fprintf(out, "if (_c == QMetaObject::QueryPropertyStored) {\n"); - if (needStored) { - fprintf(out, " bool *_b = reinterpret_cast<bool*>(_a[0]);\n"); - fprintf(out, " switch (_id) {\n"); - for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) { - const PropertyDef &p = cdef->propertyList.at(propindex); - if (!p.stored.endsWith(')')) - continue; - fprintf(out, " case %d: *_b = %s; break;\n", - propindex, p.stored.constData()); - } - fprintf(out, " default: break;\n"); - fprintf(out, " }\n"); - } - fprintf(out, - " _id -= %d;\n" - " }", cdef->propertyList.count()); - - fprintf(out, " else "); - fprintf(out, "if (_c == QMetaObject::QueryPropertyEditable) {\n"); - if (needEditable) { - fprintf(out, " bool *_b = reinterpret_cast<bool*>(_a[0]);\n"); - fprintf(out, " switch (_id) {\n"); - for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) { - const PropertyDef &p = cdef->propertyList.at(propindex); - if (!p.editable.endsWith(')')) - continue; - fprintf(out, " case %d: *_b = %s; break;\n", - propindex, p.editable.constData()); - } - fprintf(out, " default: break;\n"); - fprintf(out, " }\n"); - } - fprintf(out, - " _id -= %d;\n" - " }", cdef->propertyList.count()); - - - fprintf(out, " else "); - fprintf(out, "if (_c == QMetaObject::QueryPropertyUser) {\n"); - if (needUser) { - fprintf(out, " bool *_b = reinterpret_cast<bool*>(_a[0]);\n"); - fprintf(out, " switch (_id) {\n"); - for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) { - const PropertyDef &p = cdef->propertyList.at(propindex); - if (!p.user.endsWith(')')) - continue; - fprintf(out, " case %d: *_b = %s; break;\n", - propindex, p.user.constData()); - } - fprintf(out, " default: break;\n"); - fprintf(out, " }\n"); - } - fprintf(out, - " _id -= %d;\n" - " }", cdef->propertyList.count()); - - fprintf(out, "\n#endif // QT_NO_PROPERTIES"); - } - if (methodList.size() || cdef->propertyList.size()) - fprintf(out, "\n "); - fprintf(out,"return _id;\n}\n"); -} - - -QMultiMap<QByteArray, int> Generator::automaticPropertyMetaTypesHelper() -{ - QMultiMap<QByteArray, int> automaticPropertyMetaTypes; - for (int i = 0; i < cdef->propertyList.size(); ++i) { - const QByteArray propertyType = cdef->propertyList.at(i).type; - if (registerableMetaType(propertyType) && !isBuiltinType(propertyType)) - automaticPropertyMetaTypes.insert(propertyType, i); - } - return automaticPropertyMetaTypes; -} - -QMap<int, QMultiMap<QByteArray, int> > Generator::methodsWithAutomaticTypesHelper(const QVector<FunctionDef> &methodList) -{ - QMap<int, QMultiMap<QByteArray, int> > methodsWithAutomaticTypes; - for (int i = 0; i < methodList.size(); ++i) { - const FunctionDef &f = methodList.at(i); - for (int j = 0; j < f.arguments.count(); ++j) { - const QByteArray argType = f.arguments.at(j).normalizedType; - if (registerableMetaType(argType) && !isBuiltinType(argType)) - methodsWithAutomaticTypes[i].insert(argType, j); - } - } - return methodsWithAutomaticTypes; -} - -void Generator::generateStaticMetacall() -{ - fprintf(out, "void %s::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)\n{\n", - cdef->qualified.constData()); - - bool needElse = false; - bool isUsed_a = false; - - if (!cdef->constructorList.isEmpty()) { - fprintf(out, " if (_c == QMetaObject::CreateInstance) {\n"); - fprintf(out, " switch (_id) {\n"); - for (int ctorindex = 0; ctorindex < cdef->constructorList.count(); ++ctorindex) { - fprintf(out, " case %d: { %s *_r = new %s(", ctorindex, - cdef->classname.constData(), cdef->classname.constData()); - const FunctionDef &f = cdef->constructorList.at(ctorindex); - int offset = 1; - - int argsCount = f.arguments.count(); - for (int j = 0; j < argsCount; ++j) { - const ArgumentDef &a = f.arguments.at(j); - if (j) - fprintf(out, ","); - fprintf(out, "(*reinterpret_cast< %s>(_a[%d]))", a.typeNameForCast.constData(), offset++); - } - if (f.isPrivateSignal) { - if (argsCount > 0) - fprintf(out, ", "); - fprintf(out, "%s", QByteArray("QPrivateSignal()").constData()); - } - fprintf(out, ");\n"); - fprintf(out, " if (_a[0]) *reinterpret_cast<%s**>(_a[0]) = _r; } break;\n", - cdef->hasQGadget ? "void" : "QObject"); - } - fprintf(out, " default: break;\n"); - fprintf(out, " }\n"); - fprintf(out, " }"); - needElse = true; - isUsed_a = true; - } - - QVector<FunctionDef> methodList; - methodList += cdef->signalList; - methodList += cdef->slotList; - methodList += cdef->methodList; - - if (!methodList.isEmpty()) { - if (needElse) - fprintf(out, " else "); - else - fprintf(out, " "); - fprintf(out, "if (_c == QMetaObject::InvokeMetaMethod) {\n"); - if (cdef->hasQObject) { -#ifndef QT_NO_DEBUG - fprintf(out, " Q_ASSERT(staticMetaObject.cast(_o));\n"); -#endif - fprintf(out, " %s *_t = static_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); - } else { - fprintf(out, " %s *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); - } - fprintf(out, " Q_UNUSED(_t)\n"); - fprintf(out, " switch (_id) {\n"); - for (int methodindex = 0; methodindex < methodList.size(); ++methodindex) { - const FunctionDef &f = methodList.at(methodindex); - Q_ASSERT(!f.normalizedType.isEmpty()); - fprintf(out, " case %d: ", methodindex); - if (f.normalizedType != "void") - fprintf(out, "{ %s _r = ", noRef(f.normalizedType).constData()); - fprintf(out, "_t->"); - if (f.inPrivateClass.size()) - fprintf(out, "%s->", f.inPrivateClass.constData()); - fprintf(out, "%s(", f.name.constData()); - int offset = 1; - - int argsCount = f.arguments.count(); - for (int j = 0; j < argsCount; ++j) { - const ArgumentDef &a = f.arguments.at(j); - if (j) - fprintf(out, ","); - fprintf(out, "(*reinterpret_cast< %s>(_a[%d]))",a.typeNameForCast.constData(), offset++); - isUsed_a = true; - } - if (f.isPrivateSignal) { - if (argsCount > 0) - fprintf(out, ", "); - fprintf(out, "%s", "QPrivateSignal()"); - } - fprintf(out, ");"); - if (f.normalizedType != "void") { - fprintf(out, "\n if (_a[0]) *reinterpret_cast< %s*>(_a[0]) = std::move(_r); } ", - noRef(f.normalizedType).constData()); - isUsed_a = true; - } - fprintf(out, " break;\n"); - } - fprintf(out, " default: ;\n"); - fprintf(out, " }\n"); - fprintf(out, " }"); - needElse = true; - - QMap<int, QMultiMap<QByteArray, int> > methodsWithAutomaticTypes = methodsWithAutomaticTypesHelper(methodList); - - if (!methodsWithAutomaticTypes.isEmpty()) { - fprintf(out, " else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {\n"); - fprintf(out, " switch (_id) {\n"); - fprintf(out, " default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n"); - QMap<int, QMultiMap<QByteArray, int> >::const_iterator it = methodsWithAutomaticTypes.constBegin(); - const QMap<int, QMultiMap<QByteArray, int> >::const_iterator end = methodsWithAutomaticTypes.constEnd(); - for ( ; it != end; ++it) { - fprintf(out, " case %d:\n", it.key()); - fprintf(out, " switch (*reinterpret_cast<int*>(_a[1])) {\n"); - fprintf(out, " default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n"); - auto jt = it->begin(); - const auto jend = it->end(); - while (jt != jend) { - fprintf(out, " case %d:\n", jt.value()); - const QByteArray &lastKey = jt.key(); - ++jt; - if (jt == jend || jt.key() != lastKey) - fprintf(out, " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", lastKey.constData()); - } - fprintf(out, " }\n"); - fprintf(out, " break;\n"); - } - fprintf(out, " }\n"); - fprintf(out, " }"); - isUsed_a = true; - } - - } - if (!cdef->signalList.isEmpty()) { - Q_ASSERT(needElse); // if there is signal, there was method. - fprintf(out, " else if (_c == QMetaObject::IndexOfMethod) {\n"); - fprintf(out, " int *result = reinterpret_cast<int *>(_a[0]);\n"); - fprintf(out, " void **func = reinterpret_cast<void **>(_a[1]);\n"); - bool anythingUsed = false; - for (int methodindex = 0; methodindex < cdef->signalList.size(); ++methodindex) { - const FunctionDef &f = cdef->signalList.at(methodindex); - if (f.wasCloned || !f.inPrivateClass.isEmpty() || f.isStatic) - continue; - anythingUsed = true; - fprintf(out, " {\n"); - fprintf(out, " typedef %s (%s::*_t)(",f.type.rawName.constData() , cdef->classname.constData()); - - int argsCount = f.arguments.count(); - for (int j = 0; j < argsCount; ++j) { - const ArgumentDef &a = f.arguments.at(j); - if (j) - fprintf(out, ", "); - fprintf(out, "%s", QByteArray(a.type.name + ' ' + a.rightType).constData()); - } - if (f.isPrivateSignal) { - if (argsCount > 0) - fprintf(out, ", "); - fprintf(out, "%s", "QPrivateSignal"); - } - if (f.isConst) - fprintf(out, ") const;\n"); - else - fprintf(out, ");\n"); - fprintf(out, " if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&%s::%s)) {\n", - cdef->classname.constData(), f.name.constData()); - fprintf(out, " *result = %d;\n", methodindex); - fprintf(out, " return;\n"); - fprintf(out, " }\n }\n"); - } - if (!anythingUsed) - fprintf(out, " Q_UNUSED(result);\n Q_UNUSED(func);\n"); - fprintf(out, " }"); - needElse = true; - } - - const QMultiMap<QByteArray, int> automaticPropertyMetaTypes = automaticPropertyMetaTypesHelper(); - - if (!automaticPropertyMetaTypes.isEmpty()) { - if (needElse) - fprintf(out, " else "); - else - fprintf(out, " "); - fprintf(out, "if (_c == QMetaObject::RegisterPropertyMetaType) {\n"); - fprintf(out, " switch (_id) {\n"); - fprintf(out, " default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n"); - auto it = automaticPropertyMetaTypes.begin(); - const auto end = automaticPropertyMetaTypes.end(); - while (it != end) { - fprintf(out, " case %d:\n", it.value()); - const QByteArray &lastKey = it.key(); - ++it; - if (it == end || it.key() != lastKey) - fprintf(out, " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", lastKey.constData()); - } - fprintf(out, " }\n"); - fprintf(out, " }\n"); - isUsed_a = true; - needElse = true; - } - - if (!cdef->propertyList.empty()) { - bool needGet = false; - bool needTempVarForGet = false; - bool needSet = false; - bool needReset = false; - for (int i = 0; i < cdef->propertyList.size(); ++i) { - const PropertyDef &p = cdef->propertyList.at(i); - needGet |= !p.read.isEmpty() || !p.member.isEmpty(); - if (!p.read.isEmpty() || !p.member.isEmpty()) - needTempVarForGet |= (p.gspec != PropertyDef::PointerSpec - && p.gspec != PropertyDef::ReferenceSpec); - - needSet |= !p.write.isEmpty() || (!p.member.isEmpty() && !p.constant); - needReset |= !p.reset.isEmpty(); - } - fprintf(out, "\n#ifndef QT_NO_PROPERTIES\n "); - - if (needElse) - fprintf(out, "else "); - fprintf(out, "if (_c == QMetaObject::ReadProperty) {\n"); - if (needGet) { - if (cdef->hasQObject) { -#ifndef QT_NO_DEBUG - fprintf(out, " Q_ASSERT(staticMetaObject.cast(_o));\n"); -#endif - fprintf(out, " %s *_t = static_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); - } else { - fprintf(out, " %s *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); - } - fprintf(out, " Q_UNUSED(_t)\n"); - if (needTempVarForGet) - fprintf(out, " void *_v = _a[0];\n"); - fprintf(out, " switch (_id) {\n"); - for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) { - const PropertyDef &p = cdef->propertyList.at(propindex); - if (p.read.isEmpty() && p.member.isEmpty()) - continue; - QByteArray prefix = "_t->"; - if (p.inPrivateClass.size()) { - prefix += p.inPrivateClass + "->"; - } - if (p.gspec == PropertyDef::PointerSpec) - fprintf(out, " case %d: _a[0] = const_cast<void*>(reinterpret_cast<const void*>(%s%s())); break;\n", - propindex, prefix.constData(), p.read.constData()); - else if (p.gspec == PropertyDef::ReferenceSpec) - fprintf(out, " case %d: _a[0] = const_cast<void*>(reinterpret_cast<const void*>(&%s%s())); break;\n", - propindex, prefix.constData(), p.read.constData()); - else if (cdef->enumDeclarations.value(p.type, false)) - fprintf(out, " case %d: *reinterpret_cast<int*>(_v) = QFlag(%s%s()); break;\n", - propindex, prefix.constData(), p.read.constData()); - else if (!p.read.isEmpty()) - fprintf(out, " case %d: *reinterpret_cast< %s*>(_v) = %s%s(); break;\n", - propindex, p.type.constData(), prefix.constData(), p.read.constData()); - else - fprintf(out, " case %d: *reinterpret_cast< %s*>(_v) = %s%s; break;\n", - propindex, p.type.constData(), prefix.constData(), p.member.constData()); - } - fprintf(out, " default: break;\n"); - fprintf(out, " }\n"); - } - - fprintf(out, " }"); - - fprintf(out, " else "); - fprintf(out, "if (_c == QMetaObject::WriteProperty) {\n"); - - if (needSet) { - if (cdef->hasQObject) { -#ifndef QT_NO_DEBUG - fprintf(out, " Q_ASSERT(staticMetaObject.cast(_o));\n"); -#endif - fprintf(out, " %s *_t = static_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); - } else { - fprintf(out, " %s *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); - } - fprintf(out, " Q_UNUSED(_t)\n"); - fprintf(out, " void *_v = _a[0];\n"); - fprintf(out, " switch (_id) {\n"); - for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) { - const PropertyDef &p = cdef->propertyList.at(propindex); - if (p.constant) - continue; - if (p.write.isEmpty() && p.member.isEmpty()) - continue; - QByteArray prefix = "_t->"; - if (p.inPrivateClass.size()) { - prefix += p.inPrivateClass + "->"; - } - if (cdef->enumDeclarations.value(p.type, false)) { - fprintf(out, " case %d: %s%s(QFlag(*reinterpret_cast<int*>(_v))); break;\n", - propindex, prefix.constData(), p.write.constData()); - } else if (!p.write.isEmpty()) { - fprintf(out, " case %d: %s%s(*reinterpret_cast< %s*>(_v)); break;\n", - propindex, prefix.constData(), p.write.constData(), p.type.constData()); - } else { - fprintf(out, " case %d:\n", propindex); - fprintf(out, " if (%s%s != *reinterpret_cast< %s*>(_v)) {\n", - prefix.constData(), p.member.constData(), p.type.constData()); - fprintf(out, " %s%s = *reinterpret_cast< %s*>(_v);\n", - prefix.constData(), p.member.constData(), p.type.constData()); - if (!p.notify.isEmpty() && p.notifyId != -1) { - const FunctionDef &f = cdef->signalList.at(p.notifyId); - if (f.arguments.size() == 0) - fprintf(out, " Q_EMIT _t->%s();\n", p.notify.constData()); - else if (f.arguments.size() == 1 && f.arguments.at(0).normalizedType == p.type) - fprintf(out, " Q_EMIT _t->%s(%s%s);\n", - p.notify.constData(), prefix.constData(), p.member.constData()); - } - fprintf(out, " }\n"); - fprintf(out, " break;\n"); - } - } - fprintf(out, " default: break;\n"); - fprintf(out, " }\n"); - } - - fprintf(out, " }"); - - fprintf(out, " else "); - fprintf(out, "if (_c == QMetaObject::ResetProperty) {\n"); - if (needReset) { - if (cdef->hasQObject) { -#ifndef QT_NO_DEBUG - fprintf(out, " Q_ASSERT(staticMetaObject.cast(_o));\n"); -#endif - fprintf(out, " %s *_t = static_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); - } else { - fprintf(out, " %s *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); - } - fprintf(out, " Q_UNUSED(_t)\n"); - fprintf(out, " switch (_id) {\n"); - for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) { - const PropertyDef &p = cdef->propertyList.at(propindex); - if (!p.reset.endsWith(')')) - continue; - QByteArray prefix = "_t->"; - if (p.inPrivateClass.size()) { - prefix += p.inPrivateClass + "->"; - } - fprintf(out, " case %d: %s%s; break;\n", - propindex, prefix.constData(), p.reset.constData()); - } - fprintf(out, " default: break;\n"); - fprintf(out, " }\n"); - } - fprintf(out, " }"); - fprintf(out, "\n#endif // QT_NO_PROPERTIES"); - needElse = true; - } - - if (needElse) - fprintf(out, "\n"); - - if (methodList.isEmpty()) { - fprintf(out, " Q_UNUSED(_o);\n"); - if (cdef->constructorList.isEmpty() && automaticPropertyMetaTypes.isEmpty() && methodsWithAutomaticTypesHelper(methodList).isEmpty()) { - fprintf(out, " Q_UNUSED(_id);\n"); - fprintf(out, " Q_UNUSED(_c);\n"); - } - } - if (!isUsed_a) - fprintf(out, " Q_UNUSED(_a);\n"); - - fprintf(out, "}\n\n"); -} - -void Generator::generateSignal(FunctionDef *def,int index) -{ - if (def->wasCloned || def->isAbstract) - return; - fprintf(out, "\n// SIGNAL %d\n%s %s::%s(", - index, def->type.name.constData(), cdef->qualified.constData(), def->name.constData()); - - QByteArray thisPtr = "this"; - const char *constQualifier = ""; - - if (def->isConst) { - thisPtr = "const_cast< " + cdef->qualified + " *>(this)"; - constQualifier = "const"; - } - - Q_ASSERT(!def->normalizedType.isEmpty()); - if (def->arguments.isEmpty() && def->normalizedType == "void" && !def->isPrivateSignal) { - fprintf(out, ")%s\n{\n" - " QMetaObject::activate(%s, &staticMetaObject, %d, nullptr);\n" - "}\n", constQualifier, thisPtr.constData(), index); - return; - } - - int offset = 1; - for (int j = 0; j < def->arguments.count(); ++j) { - const ArgumentDef &a = def->arguments.at(j); - if (j) - fprintf(out, ", "); - fprintf(out, "%s _t%d%s", a.type.name.constData(), offset++, a.rightType.constData()); - } - if (def->isPrivateSignal) { - if (!def->arguments.isEmpty()) - fprintf(out, ", "); - fprintf(out, "QPrivateSignal _t%d", offset++); - } - - fprintf(out, ")%s\n{\n", constQualifier); - if (def->type.name.size() && def->normalizedType != "void") { - QByteArray returnType = noRef(def->normalizedType); - fprintf(out, " %s _t0{};\n", returnType.constData()); - } - - fprintf(out, " void *_a[] = { "); - if (def->normalizedType == "void") { - fprintf(out, "nullptr"); - } else { - if (def->returnTypeIsVolatile) - fprintf(out, "const_cast<void*>(reinterpret_cast<const volatile void*>(&_t0))"); - else - fprintf(out, "const_cast<void*>(reinterpret_cast<const void*>(&_t0))"); - } - int i; - for (i = 1; i < offset; ++i) - if (i <= def->arguments.count() && def->arguments.at(i - 1).type.isVolatile) - fprintf(out, ", const_cast<void*>(reinterpret_cast<const volatile void*>(&_t%d))", i); - else - fprintf(out, ", const_cast<void*>(reinterpret_cast<const void*>(&_t%d))", i); - fprintf(out, " };\n"); - fprintf(out, " QMetaObject::activate(%s, &staticMetaObject, %d, _a);\n", thisPtr.constData(), index); - if (def->normalizedType != "void") - fprintf(out, " return _t0;\n"); - fprintf(out, "}\n"); -} - -static void writePluginMetaData(FILE *out, const QJsonObject &data) -{ - const QJsonDocument doc(data); - - fputs("\nQT_PLUGIN_METADATA_SECTION\n" - "static const unsigned char qt_pluginMetaData[] = {\n" - " 'Q', 'T', 'M', 'E', 'T', 'A', 'D', 'A', 'T', 'A', ' ', ' ',\n ", out); -#if 0 - fprintf(out, "\"%s\";\n", doc.toJson().constData()); -#else - const QByteArray binary = doc.toBinaryData(); - const int last = binary.size() - 1; - for (int i = 0; i < last; ++i) { - uchar c = (uchar)binary.at(i); - if (c < 0x20 || c >= 0x7f) - fprintf(out, " 0x%02x,", c); - else if (c == '\'' || c == '\\') - fprintf(out, " '\\%c',", c); - else - fprintf(out, " '%c', ", c); - if (!((i + 1) % 8)) - fputs("\n ", out); - } - fprintf(out, " 0x%02x\n};\n", (uchar)binary.at(last)); -#endif -} - -void Generator::generatePluginMetaData() -{ - if (cdef->pluginData.iid.isEmpty()) - return; - - // Write plugin meta data #ifdefed QT_NO_DEBUG with debug=false, - // true, respectively. - - QJsonObject data; - const QString debugKey = QStringLiteral("debug"); - data.insert(QStringLiteral("IID"), QLatin1String(cdef->pluginData.iid.constData())); - data.insert(QStringLiteral("className"), QLatin1String(cdef->classname.constData())); - data.insert(QStringLiteral("version"), (int)QT_VERSION); - data.insert(debugKey, QJsonValue(false)); - data.insert(QStringLiteral("MetaData"), cdef->pluginData.metaData.object()); - - // Add -M args from the command line: - for (auto it = cdef->pluginData.metaArgs.cbegin(), end = cdef->pluginData.metaArgs.cend(); it != end; ++it) - data.insert(it.key(), it.value()); - - fputs("\nQT_PLUGIN_METADATA_SECTION const uint qt_section_alignment_dummy = 42;\n\n" - "#ifdef QT_NO_DEBUG\n", out); - writePluginMetaData(out, data); - - fputs("\n#else // QT_NO_DEBUG\n", out); - - data.remove(debugKey); - data.insert(debugKey, QJsonValue(true)); - writePluginMetaData(out, data); - - fputs("#endif // QT_NO_DEBUG\n\n", out); - - // 'Use' all namespaces. - int pos = cdef->qualified.indexOf("::"); - for ( ; pos != -1 ; pos = cdef->qualified.indexOf("::", pos + 2) ) - fprintf(out, "using namespace %s;\n", cdef->qualified.left(pos).constData()); - fprintf(out, "QT_MOC_EXPORT_PLUGIN(%s, %s)\n\n", - cdef->qualified.constData(), cdef->classname.constData()); -} - -QT_END_NAMESPACE diff --git a/tools/repc/moc_copy/generator.h b/tools/repc/moc_copy/generator.h deleted file mode 100644 index 3833148..0000000 --- a/tools/repc/moc_copy/generator.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef GENERATOR_H -#define GENERATOR_H - -#include "moc.h" - -QT_BEGIN_NAMESPACE - -class Generator -{ - FILE *out; - ClassDef *cdef; - QVector<uint> meta_data; -public: - Generator(ClassDef *classDef, const QList<QByteArray> &metaTypes, const QHash<QByteArray, QByteArray> &knownQObjectClasses, const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile = 0); - void generateCode(); -private: - bool registerableMetaType(const QByteArray &propertyType); - void registerClassInfoStrings(); - void generateClassInfos(); - void registerFunctionStrings(const QVector<FunctionDef> &list); - void generateFunctions(const QVector<FunctionDef> &list, const char *functype, int type, int ¶msIndex); - void generateFunctionRevisions(const QVector<FunctionDef> &list, const char *functype); - void generateFunctionParameters(const QVector<FunctionDef> &list, const char *functype); - void generateTypeInfo(const QByteArray &typeName, bool allowEmptyName = false); - void registerEnumStrings(); - void generateEnums(int index); - void registerPropertyStrings(); - void generateProperties(); - void generateMetacall(); - void generateStaticMetacall(); - void generateSignal(FunctionDef *def, int index); - void generatePluginMetaData(); - QMultiMap<QByteArray, int> automaticPropertyMetaTypesHelper(); - QMap<int, QMultiMap<QByteArray, int> > methodsWithAutomaticTypesHelper(const QVector<FunctionDef> &methodList); - - void strreg(const QByteArray &); // registers a string - int stridx(const QByteArray &); // returns a string's id - QList<QByteArray> strings; - QByteArray purestSuperClass; - QList<QByteArray> metaTypes; - QHash<QByteArray, QByteArray> knownQObjectClasses; - QHash<QByteArray, QByteArray> knownGadgets; -}; - -QT_END_NAMESPACE - -#endif // GENERATOR_H diff --git a/tools/repc/moc_copy/moc.cpp b/tools/repc/moc_copy/moc.cpp index 36d84a6..68c01f3 100644 --- a/tools/repc/moc_copy/moc.cpp +++ b/tools/repc/moc_copy/moc.cpp @@ -28,7 +28,6 @@ ****************************************************************************/ #include "moc.h" -#include "generator.h" #include "qdatetime.h" #include "utils.h" #include "outputrevision.h" @@ -903,9 +902,9 @@ void Moc::parse() if (it != classList.end()) { it->classInfoList += def.classInfoList; - it->enumDeclarations.unite(def.enumDeclarations); + it->enumDeclarations.insert(def.enumDeclarations); it->enumList += def.enumList; - it->flagAliases.unite(def.flagAliases); + it->flagAliases.insert(def.flagAliases); } else { knownGadgets.insert(def.classname, def.qualified); knownGadgets.insert(def.qualified, def.qualified); @@ -914,129 +913,6 @@ void Moc::parse() } } -static bool any_type_contains(const QVector<PropertyDef> &properties, const QByteArray &pattern) -{ - for (const auto &p : properties) { - if (p.type.contains(pattern)) - return true; - } - return false; -} - -static bool any_arg_contains(const QVector<FunctionDef> &functions, const QByteArray &pattern) -{ - for (const auto &f : functions) { - for (const auto &arg : f.arguments) { - if (arg.normalizedType.contains(pattern)) - return true; - } - } - return false; -} - -static QByteArrayList make_candidates() -{ - QByteArrayList result; - result -#define STREAM_SMART_POINTER(SMART_POINTER) << #SMART_POINTER - QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(STREAM_SMART_POINTER) -#undef STREAM_SMART_POINTER -#define STREAM_1ARG_TEMPLATE(TEMPLATENAME) << #TEMPLATENAME - QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(STREAM_1ARG_TEMPLATE) -#undef STREAM_1ARG_TEMPLATE - ; - return result; -} - -static QByteArrayList requiredQtContainers(const QVector<ClassDef> &classes) -{ - static const QByteArrayList candidates = make_candidates(); - - QByteArrayList required; - required.reserve(candidates.size()); - - for (const auto &candidate : candidates) { - const QByteArray pattern = candidate + '<'; - - for (const auto &c : classes) { - if (any_type_contains(c.propertyList, pattern) || - any_arg_contains(c.slotList, pattern) || - any_arg_contains(c.signalList, pattern) || - any_arg_contains(c.methodList, pattern)) { - required.push_back(candidate); - break; - } - } - } - - return required; -} - -void Moc::generate(FILE *out) -{ - QByteArray fn = filename; - int i = filename.length()-1; - while (i > 0 && filename.at(i - 1) != '/' && filename.at(i - 1) != '\\') - --i; // skip path - if (i >= 0) - fn = filename.mid(i); - fprintf(out, "/****************************************************************************\n" - "** Meta object code from reading C++ file '%s'\n**\n" , fn.constData()); - fprintf(out, "** Created by: The Qt Meta Object Compiler version %d (Qt %s)\n**\n" , mocOutputRevision, QT_VERSION_STR); - fprintf(out, "** WARNING! All changes made in this file will be lost!\n" - "*****************************************************************************/\n\n"); - - - if (!noInclude) { - if (includePath.size() && !includePath.endsWith('/')) - includePath += '/'; - for (int i = 0; i < includeFiles.size(); ++i) { - QByteArray inc = includeFiles.at(i); - if (inc.at(0) != '<' && inc.at(0) != '"') { - if (includePath.size() && includePath != "./") - inc.prepend(includePath); - inc = '\"' + inc + '\"'; - } - fprintf(out, "#include %s\n", inc.constData()); - } - } - if (classList.size() && classList.constFirst().classname == "Qt") - fprintf(out, "#include <QtCore/qobject.h>\n"); - - fprintf(out, "#include <QtCore/qbytearray.h>\n"); // For QByteArrayData - fprintf(out, "#include <QtCore/qmetatype.h>\n"); // For QMetaType::Type - if (mustIncludeQPluginH) - fprintf(out, "#include <QtCore/qplugin.h>\n"); - - const auto qtContainers = requiredQtContainers(classList); - for (const QByteArray &qtContainer : qtContainers) - fprintf(out, "#include <QtCore/%s>\n", qtContainer.constData()); - - - fprintf(out, "#if !defined(Q_MOC_OUTPUT_REVISION)\n" - "#error \"The header file '%s' doesn't include <QObject>.\"\n", fn.constData()); - fprintf(out, "#elif Q_MOC_OUTPUT_REVISION != %d\n", mocOutputRevision); - fprintf(out, "#error \"This file was generated using the moc from %s." - " It\"\n#error \"cannot be used with the include files from" - " this version of Qt.\"\n#error \"(The moc has changed too" - " much.)\"\n", QT_VERSION_STR); - fprintf(out, "#endif\n\n"); - - fprintf(out, "QT_BEGIN_MOC_NAMESPACE\n"); - fprintf(out, "QT_WARNING_PUSH\n"); - fprintf(out, "QT_WARNING_DISABLE_DEPRECATED\n"); - - fputs("", out); - for (i = 0; i < classList.size(); ++i) { - Generator generator(&classList[i], metaTypes, knownQObjectClasses, knownGadgets, out); - generator.generateCode(); - } - fputs("", out); - - fprintf(out, "QT_WARNING_POP\n"); - fprintf(out, "QT_END_MOC_NAMESPACE\n"); -} - void Moc::parseSlots(ClassDef *def, FunctionDef::Access access) { int defaultRevision = -1; diff --git a/tools/repc/moc_copy/moc.h b/tools/repc/moc_copy/moc.h index 6040f94..de10b90 100644 --- a/tools/repc/moc_copy/moc.h +++ b/tools/repc/moc_copy/moc.h @@ -215,7 +215,6 @@ public: QMap<QString, QJsonArray> metaArgs; void parse(); - void generate(FILE *out); bool parseClassHead(ClassDef *def); inline bool inClass(const ClassDef *def) const { diff --git a/tools/repc/moc_copy/moc.pri b/tools/repc/moc_copy/moc.pri index b689a35..a6546b8 100644 --- a/tools/repc/moc_copy/moc.pri +++ b/tools/repc/moc_copy/moc.pri @@ -1,16 +1,14 @@ INCLUDEPATH += $$PWD -HEADERS = $$PWD/moc.h \ +HEADERS += $$PWD/moc.h \ $$PWD/preprocessor.h \ $$PWD/parser.h \ $$PWD/symbols.h \ $$PWD/token.h \ $$PWD/utils.h \ - $$PWD/generator.h \ $$PWD/outputrevision.h -SOURCES = $$PWD/moc.cpp \ +SOURCES += $$PWD/moc.cpp \ $$PWD/preprocessor.cpp \ - $$PWD/generator.cpp \ $$PWD/parser.cpp \ $$PWD/token.cpp diff --git a/tools/repc/repcodegenerator.cpp b/tools/repc/repcodegenerator.cpp index 8673a0e..b6159d3 100644 --- a/tools/repc/repcodegenerator.cpp +++ b/tools/repc/repcodegenerator.cpp @@ -179,13 +179,13 @@ void RepCodeGenerator::generate(const AST &ast, Mode mode, QString fileName) { QTextStream stream(m_outputDevice); if (fileName.isEmpty()) - stream << "#pragma once" << endl << endl; + stream << "#pragma once" << Qt::endl << Qt::endl; else { fileName = QFileInfo(fileName).fileName(); fileName = fileName.toUpper(); fileName.replace(QLatin1Char('.'), QLatin1Char('_')); - stream << "#ifndef " << fileName << endl; - stream << "#define " << fileName << endl << endl; + stream << "#ifndef " << fileName << Qt::endl; + stream << "#define " << fileName << Qt::endl << Qt::endl; } generateHeader(mode, stream, ast); @@ -244,9 +244,9 @@ void RepCodeGenerator::generate(const AST &ast, Mode mode, QString fileName) generateStreamOperatorsForEnums(stream, ast.enumUses); - stream << endl; + stream << Qt::endl; if (!fileName.isEmpty()) - stream << "#endif // " << fileName << endl; + stream << "#endif // " << fileName << Qt::endl; } void RepCodeGenerator::generateHeader(Mode mode, QTextStream &out, const AST &ast) @@ -403,13 +403,13 @@ void RepCodeGenerator::generateSimpleSetter(QTextStream &out, const ASTProperty out << "void set" << cap(property.name) << "(" << typeForMode(property, SIMPLE_SOURCE) << " " << property.name << ")"; if (generateOverride) out << " override"; - out << endl; - out << " {" << endl; - out << " if (" << property.name << " != m_" << property.name << ") {" << endl; - out << " m_" << property.name << " = " << property.name << ";" << endl; - out << " Q_EMIT " << property.name << "Changed(m_" << property.name << ");" << endl; - out << " }" << endl; - out << " }" << endl; + out << Qt::endl; + out << " {" << Qt::endl; + out << " if (" << property.name << " != m_" << property.name << ") {" << Qt::endl; + out << " m_" << property.name << " = " << property.name << ";" << Qt::endl; + out << " Q_EMIT " << property.name << "Changed(m_" << property.name << ");" << Qt::endl; + out << " }" << Qt::endl; + out << " }" << Qt::endl; } void RepCodeGenerator::generatePOD(QTextStream &out, const POD &pod) @@ -466,20 +466,20 @@ QString getEnumType(const ASTEnum &en) void RepCodeGenerator::generateDeclarationsForEnums(QTextStream &out, const QVector<ASTEnum> &enums, bool generateQENUM) { if (!generateQENUM) { - out << " // You need to add this enum as well as Q_ENUM to your" << endl; - out << " // QObject class in order to use .rep enums over QtRO for" << endl; - out << " // non-repc generated QObjects." << endl; + out << " // You need to add this enum as well as Q_ENUM to your" << Qt::endl; + out << " // QObject class in order to use .rep enums over QtRO for" << Qt::endl; + out << " // non-repc generated QObjects." << Qt::endl; } for (const ASTEnum &en : enums) { m_globalEnumsPODs[en.name] = enumSignature(en); - out << " enum " << en.name << " {" << endl; + out << " enum " << en.name << " {" << Qt::endl; for (const ASTEnumParam &p : en.params) - out << " " << p.name << " = " << p.value << "," << endl; + out << " " << p.name << " = " << p.value << "," << Qt::endl; - out << " };" << endl; + out << " };" << Qt::endl; if (generateQENUM) - out << " Q_ENUM(" << en.name << ")" << endl; + out << " Q_ENUM(" << en.name << ")" << Qt::endl; } } @@ -600,41 +600,41 @@ QString RepCodeGenerator::generateMetaTypeRegistrationForEnums(const QVector<QSt void RepCodeGenerator::generateStreamOperatorsForEnums(QTextStream &out, const QVector<QString> &enumUses) { - out << "QT_BEGIN_NAMESPACE" << endl; + out << "QT_BEGIN_NAMESPACE" << Qt::endl; for (const QString &enumName : enumUses) { - out << "inline QDataStream &operator<<(QDataStream &out, " << enumName << " value)" << endl; - out << "{" << endl; - out << " out << static_cast<qint32>(value);" << endl; - out << " return out;" << endl; - out << "}" << endl; - out << endl; - out << "inline QDataStream &operator>>(QDataStream &in, " << enumName << " &value)" << endl; - out << "{" << endl; - out << " qint32 intValue = 0;" << endl; - out << " in >> intValue;" << endl; - out << " value = static_cast<" << enumName << ">(intValue);" << endl; - out << " return in;" << endl; - out << "}" << endl; - out << endl; + out << "inline QDataStream &operator<<(QDataStream &out, " << enumName << " value)" << Qt::endl; + out << "{" << Qt::endl; + out << " out << static_cast<qint32>(value);" << Qt::endl; + out << " return out;" << Qt::endl; + out << "}" << Qt::endl; + out << Qt::endl; + out << "inline QDataStream &operator>>(QDataStream &in, " << enumName << " &value)" << Qt::endl; + out << "{" << Qt::endl; + out << " qint32 intValue = 0;" << Qt::endl; + out << " in >> intValue;" << Qt::endl; + out << " value = static_cast<" << enumName << ">(intValue);" << Qt::endl; + out << " return in;" << Qt::endl; + out << "}" << Qt::endl; + out << Qt::endl; } - out << "QT_END_NAMESPACE" << endl << endl; + out << "QT_END_NAMESPACE" << Qt::endl << Qt::endl; } void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass &astClass, const QString &metaTypeRegistrationCode) { const QString className = (astClass.name + (mode == REPLICA ? QStringLiteral("Replica") : mode == SOURCE ? QStringLiteral("Source") : QStringLiteral("SimpleSource"))); if (mode == REPLICA) - out << "class " << className << " : public QRemoteObjectReplica" << endl; + out << "class " << className << " : public QRemoteObjectReplica" << Qt::endl; else if (mode == SIMPLE_SOURCE) - out << "class " << className << " : public " << astClass.name << "Source" << endl; + out << "class " << className << " : public " << astClass.name << "Source" << Qt::endl; else - out << "class " << className << " : public QObject" << endl; + out << "class " << className << " : public QObject" << Qt::endl; - out << "{" << endl; - out << " Q_OBJECT" << endl; + out << "{" << Qt::endl; + out << " Q_OBJECT" << Qt::endl; if (mode != SIMPLE_SOURCE) { - out << " Q_CLASSINFO(QCLASSINFO_REMOTEOBJECT_TYPE, \"" << astClass.name << "\")" << endl; - out << " Q_CLASSINFO(QCLASSINFO_REMOTEOBJECT_SIGNATURE, \"" << QLatin1String(classSignature(astClass)) << "\")" << endl; + out << " Q_CLASSINFO(QCLASSINFO_REMOTEOBJECT_TYPE, \"" << astClass.name << "\")" << Qt::endl; + out << " Q_CLASSINFO(QCLASSINFO_REMOTEOBJECT_SIGNATURE, \"" << QLatin1String(classSignature(astClass)) << "\")" << Qt::endl; for (int i = 0; i < astClass.modelMetadata.count(); i++) { const auto model = astClass.modelMetadata.at(i); const auto modelName = astClass.properties.at(model.propertyIndex).name; @@ -642,7 +642,7 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass QStringList list; for (auto role : model.roles) list << role.name; - out << QString::fromLatin1(" Q_CLASSINFO(\"%1_ROLES\", \"%2\")").arg(modelName.toUpper(), list.join(QChar::fromLatin1('|'))) << endl; + out << QString::fromLatin1(" Q_CLASSINFO(\"%1_ROLES\", \"%2\")").arg(modelName.toUpper(), list.join(QChar::fromLatin1('|'))) << Qt::endl; } } @@ -665,105 +665,105 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass else // The Source can use the setter, since non-asynchronous out << " WRITE set" << cap(property.name) << " NOTIFY " << property.name << "Changed"; } - out << ")" << endl; + out << ")" << Qt::endl; } if (!astClass.enums.isEmpty()) { - out << "" << endl; - out << "public:" << endl; + out << "" << Qt::endl; + out << "public:" << Qt::endl; generateDeclarationsForEnums(out, astClass.enums); } } - out << "" << endl; - out << "public:" << endl; + out << "" << Qt::endl; + out << "public:" << Qt::endl; if (mode == REPLICA) { - out << " " << className << "() : QRemoteObjectReplica() { initialize(); }" << endl; - out << " static void registerMetatypes()" << endl; - out << " {" << endl; - out << " static bool initialized = false;" << endl; - out << " if (initialized)" << endl; - out << " return;" << endl; - out << " initialized = true;" << endl; + out << " " << className << "() : QRemoteObjectReplica() { initialize(); }" << Qt::endl; + out << " static void registerMetatypes()" << Qt::endl; + out << " {" << Qt::endl; + out << " static bool initialized = false;" << Qt::endl; + out << " if (initialized)" << Qt::endl; + out << " return;" << Qt::endl; + out << " initialized = true;" << Qt::endl; if (!metaTypeRegistrationCode.isEmpty()) - out << metaTypeRegistrationCode << endl; + out << metaTypeRegistrationCode << Qt::endl; - out << " }" << endl; + out << " }" << Qt::endl; if (astClass.hasPointerObjects()) { - out << " void setNode(QRemoteObjectNode *node) override" << endl; - out << " {" << endl; - out << " QRemoteObjectReplica::setNode(node);" << endl; + out << " void setNode(QRemoteObjectNode *node) override" << Qt::endl; + out << " {" << Qt::endl; + out << " QRemoteObjectReplica::setNode(node);" << Qt::endl; for (int index = 0; index < astClass.properties.count(); ++index) { const ASTProperty &property = astClass.properties.at(index); if (!property.isPointer) continue; if (astClass.subClassPropertyIndices.contains(index)) out << QString::fromLatin1(" setChild(%1, QVariant::fromValue(node->acquire<%2Replica>(QRemoteObjectStringLiterals::CLASS().arg(\"%3\"))));") - .arg(QString::number(index), property.type, property.name) << endl; + .arg(QString::number(index), property.type, property.name) << Qt::endl; else out << QString::fromLatin1(" setChild(%1, QVariant::fromValue(node->acquireModel(QRemoteObjectStringLiterals::MODEL().arg(\"%2\"))));") - .arg(QString::number(index), property.name) << endl; - out << " Q_EMIT " << property.name << "Changed(" << property.name << "()" << ");" << endl; + .arg(QString::number(index), property.name) << Qt::endl; + out << " Q_EMIT " << property.name << "Changed(" << property.name << "()" << ");" << Qt::endl; } - out << " }" << endl; + out << " }" << Qt::endl; } - out << "" << endl; - out << "private:" << endl; - out << " " << className << "(QRemoteObjectNode *node, const QString &name = QString())" << endl; - out << " : QRemoteObjectReplica(ConstructWithNode)" << endl; - out << " {" << endl; - out << " initializeNode(node, name);" << endl; + out << "" << Qt::endl; + out << "private:" << Qt::endl; + out << " " << className << "(QRemoteObjectNode *node, const QString &name = QString())" << Qt::endl; + out << " : QRemoteObjectReplica(ConstructWithNode)" << Qt::endl; + out << " {" << Qt::endl; + out << " initializeNode(node, name);" << Qt::endl; for (int index = 0; index < astClass.properties.count(); ++index) { const ASTProperty &property = astClass.properties.at(index); if (!property.isPointer) continue; if (astClass.subClassPropertyIndices.contains(index)) out << QString::fromLatin1(" setChild(%1, QVariant::fromValue(node->acquire<%2Replica>(QRemoteObjectStringLiterals::CLASS().arg(\"%3\"))));") - .arg(QString::number(index), property.type, property.name) << endl; + .arg(QString::number(index), property.type, property.name) << Qt::endl; else out << QString::fromLatin1(" setChild(%1, QVariant::fromValue(node->acquireModel(QRemoteObjectStringLiterals::MODEL().arg(\"%2\"))));") - .arg(QString::number(index), property.name) << endl; + .arg(QString::number(index), property.name) << Qt::endl; } - out << " }" << endl; + out << " }" << Qt::endl; - out << "" << endl; + out << "" << Qt::endl; - out << " void initialize() override" << endl; - out << " {" << endl; - out << " " << className << "::registerMetatypes();" << endl; - out << " QVariantList properties;" << endl; - out << " properties.reserve(" << astClass.properties.size() << ");" << endl; + out << " void initialize() override" << Qt::endl; + out << " {" << Qt::endl; + out << " " << className << "::registerMetatypes();" << Qt::endl; + out << " QVariantList properties;" << Qt::endl; + out << " properties.reserve(" << astClass.properties.size() << ");" << Qt::endl; for (const ASTProperty &property : astClass.properties) { if (property.isPointer) - out << " properties << QVariant::fromValue((" << typeForMode(property, mode) << ")" << property.defaultValue << ");" << endl; + out << " properties << QVariant::fromValue((" << typeForMode(property, mode) << ")" << property.defaultValue << ");" << Qt::endl; else - out << " properties << QVariant::fromValue(" << typeForMode(property, mode) << "(" << property.defaultValue << "));" << endl; + out << " properties << QVariant::fromValue(" << typeForMode(property, mode) << "(" << property.defaultValue << "));" << Qt::endl; } int nPersisted = 0; if (astClass.hasPersisted) { - out << " QVariantList stored = retrieveProperties(\"" << astClass.name << "\", \"" << classSignature(astClass) << "\");" << endl; - out << " if (!stored.isEmpty()) {" << endl; + out << " QVariantList stored = retrieveProperties(\"" << astClass.name << "\", \"" << classSignature(astClass) << "\");" << Qt::endl; + out << " if (!stored.isEmpty()) {" << Qt::endl; for (int i = 0; i < astClass.properties.size(); i++) { if (astClass.properties.at(i).persisted) { - out << " properties[" << i << "] = stored.at(" << nPersisted << ");" << endl; + out << " properties[" << i << "] = stored.at(" << nPersisted << ");" << Qt::endl; nPersisted++; } } - out << " }" << endl; + out << " }" << Qt::endl; } - out << " setProperties(properties);" << endl; - out << " }" << endl; + out << " setProperties(properties);" << Qt::endl; + out << " }" << Qt::endl; } else if (mode == SOURCE) { - out << " explicit " << className << "(QObject *parent = nullptr) : QObject(parent)" << endl; - out << " {" << endl; + out << " explicit " << className << "(QObject *parent = nullptr) : QObject(parent)" << Qt::endl; + out << " {" << Qt::endl; if (!metaTypeRegistrationCode.isEmpty()) - out << metaTypeRegistrationCode << endl; - out << " }" << endl; + out << metaTypeRegistrationCode << Qt::endl; + out << " }" << Qt::endl; } else { QVector<int> constIndices; for (int index = 0; index < astClass.properties.count(); ++index) { @@ -772,7 +772,7 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass constIndices.append(index); } if (constIndices.isEmpty()) { - out << " explicit " << className << "(QObject *parent = nullptr) : " << astClass.name << "Source(parent)" << endl; + out << " explicit " << className << "(QObject *parent = nullptr) : " << astClass.name << "Source(parent)" << Qt::endl; } else { QStringList parameters; for (int index : constIndices) { @@ -780,35 +780,35 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass parameters.append(QString::fromLatin1("%1 %2 = %3").arg(typeForMode(property, SOURCE), property.name, property.defaultValue)); } parameters.append(QStringLiteral("QObject *parent = nullptr")); - out << " explicit " << className << "(" << parameters.join(QStringLiteral(", ")) << ") : " << astClass.name << "Source(parent)" << endl; + out << " explicit " << className << "(" << parameters.join(QStringLiteral(", ")) << ") : " << astClass.name << "Source(parent)" << Qt::endl; } for (const ASTProperty &property : astClass.properties) { if (property.modifier == ASTProperty::Constant) - out << " , m_" << property.name << "(" << property.name << ")" << endl; + out << " , m_" << property.name << "(" << property.name << ")" << Qt::endl; else - out << " , m_" << property.name << "(" << property.defaultValue << ")" << endl; + out << " , m_" << property.name << "(" << property.defaultValue << ")" << Qt::endl; } - out << " {" << endl; - out << " }" << endl; + out << " {" << Qt::endl; + out << " }" << Qt::endl; } - out << "" << endl; - out << "public:" << endl; + out << "" << Qt::endl; + out << "public:" << Qt::endl; if (mode == REPLICA && astClass.hasPersisted) { - out << " ~" << className << "() override {" << endl; - out << " QVariantList persisted;" << endl; + out << " ~" << className << "() override {" << Qt::endl; + out << " QVariantList persisted;" << Qt::endl; for (int i = 0; i < astClass.properties.size(); i++) { if (astClass.properties.at(i).persisted) { - out << " persisted << propAsVariant(" << i << ");" << endl; + out << " persisted << propAsVariant(" << i << ");" << Qt::endl; } } - out << " persistProperties(\"" << astClass.name << "\", \"" << classSignature(astClass) << "\", persisted);" << endl; - out << " }" << endl; + out << " persistProperties(\"" << astClass.name << "\", \"" << classSignature(astClass) << "\", persisted);" << Qt::endl; + out << " }" << Qt::endl; } else { - out << " ~" << className << "() override = default;" << endl; + out << " ~" << className << "() override = default;" << Qt::endl; } - out << "" << endl; + out << "" << Qt::endl; if (mode != SIMPLE_SOURCE) generateConversionFunctionsForEnums(out, astClass.enums); @@ -819,46 +819,46 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass for (const ASTProperty &property : astClass.properties) { auto type = typeForMode(property, mode); if (type == QLatin1String("QVariant")) { - out << " " << type << " " << property.name << "() const" << endl; - out << " {" << endl; - out << " return propAsVariant(" << i << ");" << endl; - out << " }" << endl; + out << " " << type << " " << property.name << "() const" << Qt::endl; + out << " {" << Qt::endl; + out << " return propAsVariant(" << i << ");" << Qt::endl; + out << " }" << Qt::endl; } else { - out << " " << type << " " << property.name << "() const" << endl; - out << " {" << endl; - out << " const QVariant variant = propAsVariant(" << i << ");" << endl; - out << " if (!variant.canConvert<" << type << ">()) {" << endl; - out << " qWarning() << \"QtRO cannot convert the property " << property.name << " to type " << type << "\";" << endl; - out << " }" << endl; - out << " return variant.value<" << type << " >();" << endl; - out << " }" << endl; + out << " " << type << " " << property.name << "() const" << Qt::endl; + out << " {" << Qt::endl; + out << " const QVariant variant = propAsVariant(" << i << ");" << Qt::endl; + out << " if (!variant.canConvert<" << type << ">()) {" << Qt::endl; + out << " qWarning() << \"QtRO cannot convert the property " << property.name << " to type " << type << "\";" << Qt::endl; + out << " }" << Qt::endl; + out << " return variant.value<" << type << " >();" << Qt::endl; + out << " }" << Qt::endl; } i++; if (property.modifier == ASTProperty::ReadWrite) { - out << "" << endl; - out << " void set" << cap(property.name) << "(" << property.type << " " << property.name << ")" << endl; - out << " {" << endl; - out << " static int __repc_index = " << className << "::staticMetaObject.indexOfProperty(\"" << property.name << "\");" << endl; - out << " QVariantList __repc_args;" << endl; - out << " __repc_args << QVariant::fromValue(" << property.name << ");" << endl; - out << " send(QMetaObject::WriteProperty, __repc_index, __repc_args);" << endl; - out << " }" << endl; + out << "" << Qt::endl; + out << " void set" << cap(property.name) << "(" << property.type << " " << property.name << ")" << Qt::endl; + out << " {" << Qt::endl; + out << " static int __repc_index = " << className << "::staticMetaObject.indexOfProperty(\"" << property.name << "\");" << Qt::endl; + out << " QVariantList __repc_args;" << Qt::endl; + out << " __repc_args << QVariant::fromValue(" << property.name << ");" << Qt::endl; + out << " send(QMetaObject::WriteProperty, __repc_index, __repc_args);" << Qt::endl; + out << " }" << Qt::endl; } - out << "" << endl; + out << "" << Qt::endl; } } else if (mode == SOURCE) { for (const ASTProperty &property : astClass.properties) - out << " virtual " << typeForMode(property, mode) << " " << property.name << "() const = 0;" << endl; + out << " virtual " << typeForMode(property, mode) << " " << property.name << "() const = 0;" << Qt::endl; for (const ASTProperty &property : astClass.properties) { if (property.modifier == ASTProperty::ReadWrite || property.modifier == ASTProperty::ReadPush || property.modifier == ASTProperty::SourceOnlySetter) - out << " virtual void set" << cap(property.name) << "(" << typeForMode(property, mode) << " " << property.name << ") = 0;" << endl; + out << " virtual void set" << cap(property.name) << "(" << typeForMode(property, mode) << " " << property.name << ") = 0;" << Qt::endl; } } else { for (const ASTProperty &property : astClass.properties) out << " " << typeForMode(property, mode) << " " << property.name << "() const override { return m_" - << property.name << "; }" << endl; + << property.name << "; }" << Qt::endl; for (const ASTProperty &property : astClass.properties) { if (property.modifier == ASTProperty::ReadWrite || property.modifier == ASTProperty::ReadPush || @@ -871,23 +871,23 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass if (mode != SIMPLE_SOURCE) { //Next output property signals if (!astClass.properties.isEmpty() || !astClass.signalsList.isEmpty()) { - out << "" << endl; - out << "Q_SIGNALS:" << endl; + out << "" << Qt::endl; + out << "Q_SIGNALS:" << Qt::endl; for (const ASTProperty &property : astClass.properties) { if (property.modifier != ASTProperty::Constant) - out << " void " << property.name << "Changed(" << fullyQualifiedTypeName(astClass, className, typeForMode(property, mode)) << " " << property.name << ");" << endl; + out << " void " << property.name << "Changed(" << fullyQualifiedTypeName(astClass, className, typeForMode(property, mode)) << " " << property.name << ");" << Qt::endl; } const QVector<ASTFunction> signalsList = transformEnumParams(astClass, astClass.signalsList, className); for (const ASTFunction &signal : signalsList) - out << " void " << signal.name << "(" << signal.paramsAsString() << ");" << endl; + out << " void " << signal.name << "(" << signal.paramsAsString() << ");" << Qt::endl; // CONSTANT source properties still need an onChanged signal on the Replica side to // update (once) when the value is initialized. Put these last, so they don't mess // up the signal index order for (const ASTProperty &property : astClass.properties) { if (mode == REPLICA && property.modifier == ASTProperty::Constant) - out << " void " << property.name << "Changed(" << fullyQualifiedTypeName(astClass, className, typeForMode(property, mode)) << " " << property.name << ");" << endl; + out << " void " << property.name << "Changed(" << fullyQualifiedTypeName(astClass, className, typeForMode(property, mode)) << " " << property.name << ");" << Qt::endl; } } bool hasWriteSlots = false; @@ -898,24 +898,24 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass } } if (hasWriteSlots || !astClass.slotsList.isEmpty()) { - out << "" << endl; - out << "public Q_SLOTS:" << endl; + out << "" << Qt::endl; + out << "public Q_SLOTS:" << Qt::endl; for (const ASTProperty &property : astClass.properties) { if (property.modifier == ASTProperty::ReadPush) { const auto type = fullyQualifiedTypeName(astClass, className, property.type); if (mode != REPLICA) { - out << " virtual void push" << cap(property.name) << "(" << type << " " << property.name << ")" << endl; - out << " {" << endl; - out << " set" << cap(property.name) << "(" << property.name << ");" << endl; - out << " }" << endl; + out << " virtual void push" << cap(property.name) << "(" << type << " " << property.name << ")" << Qt::endl; + out << " {" << Qt::endl; + out << " set" << cap(property.name) << "(" << property.name << ");" << Qt::endl; + out << " }" << Qt::endl; } else { - out << " void push" << cap(property.name) << "(" << type << " " << property.name << ")" << endl; - out << " {" << endl; - out << " static int __repc_index = " << className << "::staticMetaObject.indexOfSlot(\"push" << cap(property.name) << "(" << type << ")\");" << endl; - out << " QVariantList __repc_args;" << endl; - out << " __repc_args << QVariant::fromValue(" << property.name << ");" << endl; - out << " send(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args);" << endl; - out << " }" << endl; + out << " void push" << cap(property.name) << "(" << type << " " << property.name << ")" << Qt::endl; + out << " {" << Qt::endl; + out << " static int __repc_index = " << className << "::staticMetaObject.indexOfSlot(\"push" << cap(property.name) << "(" << type << ")\");" << Qt::endl; + out << " QVariantList __repc_args;" << Qt::endl; + out << " __repc_args << QVariant::fromValue(" << property.name << ");" << Qt::endl; + out << " send(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args);" << Qt::endl; + out << " }" << Qt::endl; } } } @@ -923,30 +923,30 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass for (const ASTFunction &slot : slotsList) { const auto returnType = fullyQualifiedTypeName(astClass, className, slot.returnType); if (mode != REPLICA) { - out << " virtual " << returnType << " " << slot.name << "(" << slot.paramsAsString() << ") = 0;" << endl; + out << " virtual " << returnType << " " << slot.name << "(" << slot.paramsAsString() << ") = 0;" << Qt::endl; } else { // TODO: Discuss whether it is a good idea to special-case for void here, const bool isVoid = slot.returnType == QStringLiteral("void"); if (isVoid) - out << " void " << slot.name << "(" << slot.paramsAsString() << ")" << endl; + out << " void " << slot.name << "(" << slot.paramsAsString() << ")" << Qt::endl; else - out << " QRemoteObjectPendingReply<" << returnType << "> " << slot.name << "(" << slot.paramsAsString()<< ")" << endl; - out << " {" << endl; - out << " static int __repc_index = " << className << "::staticMetaObject.indexOfSlot(\"" << slot.name << "(" << slot.paramsAsString(ASTFunction::Normalized) << ")\");" << endl; - out << " QVariantList __repc_args;" << endl; + out << " QRemoteObjectPendingReply<" << returnType << "> " << slot.name << "(" << slot.paramsAsString()<< ")" << Qt::endl; + out << " {" << Qt::endl; + out << " static int __repc_index = " << className << "::staticMetaObject.indexOfSlot(\"" << slot.name << "(" << slot.paramsAsString(ASTFunction::Normalized) << ")\");" << Qt::endl; + out << " QVariantList __repc_args;" << Qt::endl; const auto ¶mNames = slot.paramNames(); if (!paramNames.isEmpty()) { - out << " __repc_args" << endl; + out << " __repc_args" << Qt::endl; for (const QString &name : paramNames) - out << " << " << "QVariant::fromValue(" << name << ")" << endl; - out << " ;" << endl; + out << " << " << "QVariant::fromValue(" << name << ")" << Qt::endl; + out << " ;" << Qt::endl; } if (isVoid) - out << " send(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args);" << endl; + out << " send(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args);" << Qt::endl; else - out << " return QRemoteObjectPendingReply<" << returnType << ">(sendWithReply(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args));" << endl; - out << " }" << endl; + out << " return QRemoteObjectPendingReply<" << returnType << ">(sendWithReply(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args));" << Qt::endl; + out << " }" << Qt::endl; } } } @@ -956,8 +956,8 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass for (const ASTProperty &property : astClass.properties) { if (property.modifier == ASTProperty::ReadOnly) { if (addProtected) { - out << "" << endl; - out << "protected:" << endl; + out << "" << Qt::endl; + out << "protected:" << Qt::endl; addProtected = false; } generateSimpleSetter(out, property, false); @@ -966,57 +966,57 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass } } - out << "" << endl; - out << "private:" << endl; + out << "" << Qt::endl; + out << "private:" << Qt::endl; //Next output data members if (mode == SIMPLE_SOURCE) { for (const ASTProperty &property : astClass.properties) - out << " " << typeForMode(property, SOURCE) << " " << "m_" << property.name << ";" << endl; + out << " " << typeForMode(property, SOURCE) << " " << "m_" << property.name << ";" << Qt::endl; } if (mode != SIMPLE_SOURCE) - out << " friend class QT_PREPEND_NAMESPACE(QRemoteObjectNode);" << endl; + out << " friend class QT_PREPEND_NAMESPACE(QRemoteObjectNode);" << Qt::endl; - out << "};" << endl; - out << "" << endl; + out << "};" << Qt::endl; + out << "" << Qt::endl; if (mode != SIMPLE_SOURCE) generateStreamOperatorsForEnums(out, astClass.enums, className); - out << "" << endl; + out << "" << Qt::endl; } void RepCodeGenerator::generateSourceAPI(QTextStream &out, const ASTClass &astClass) { const QString className = astClass.name + QStringLiteral("SourceAPI"); - out << QStringLiteral("template <class ObjectType>") << endl; - out << QString::fromLatin1("struct %1 : public SourceApiMap").arg(className) << endl; - out << QStringLiteral("{") << endl; + out << QStringLiteral("template <class ObjectType>") << Qt::endl; + out << QString::fromLatin1("struct %1 : public SourceApiMap").arg(className) << Qt::endl; + out << QStringLiteral("{") << Qt::endl; if (!astClass.enums.isEmpty()) { // Include enum definition in SourceAPI generateDeclarationsForEnums(out, astClass.enums, false); } - out << QString::fromLatin1(" %1(ObjectType *object, const QString &name = QLatin1String(\"%2\"))").arg(className, astClass.name) << endl; - out << QStringLiteral(" : SourceApiMap(), m_name(name)") << endl; - out << QStringLiteral(" {") << endl; + out << QString::fromLatin1(" %1(ObjectType *object, const QString &name = QLatin1String(\"%2\"))").arg(className, astClass.name) << Qt::endl; + out << QStringLiteral(" : SourceApiMap(), m_name(name)") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; if (!astClass.hasPointerObjects()) - out << QStringLiteral(" Q_UNUSED(object);") << endl; + out << QStringLiteral(" Q_UNUSED(object);") << Qt::endl; const int enumCount = astClass.enums.count(); for (int i : astClass.subClassPropertyIndices) { const ASTProperty &child = astClass.properties.at(i); out << QString::fromLatin1(" using %1_type_t = typename std::remove_pointer<decltype(object->%1())>::type;") - .arg(child.name) << endl; + .arg(child.name) << Qt::endl; } - out << QString::fromLatin1(" m_enums[0] = %1;").arg(enumCount) << endl; + out << QString::fromLatin1(" m_enums[0] = %1;").arg(enumCount) << Qt::endl; for (int i = 0; i < enumCount; ++i) { const auto enumerator = astClass.enums.at(i); out << QString::fromLatin1(" m_enums[%1] = ObjectType::staticMetaObject.indexOfEnumerator(\"%2\");") - .arg(i+1).arg(enumerator.name) << endl; + .arg(i+1).arg(enumerator.name) << Qt::endl; } const int propCount = astClass.properties.count(); - out << QString::fromLatin1(" m_properties[0] = %1;").arg(propCount) << endl; + out << QString::fromLatin1(" m_properties[0] = %1;").arg(propCount) << Qt::endl; QList<ASTProperty> onChangeProperties; QList<int> propertyChangeIndex; for (int i = 0; i < propCount; ++i) { @@ -1024,33 +1024,33 @@ void RepCodeGenerator::generateSourceAPI(QTextStream &out, const ASTClass &astCl const QString propTypeName = fullyQualifiedTypeName(astClass, QStringLiteral("typename ObjectType"), typeForMode(prop, SOURCE)); out << QString::fromLatin1(" m_properties[%1] = QtPrivate::qtro_property_index<ObjectType>(&ObjectType::%2, " "static_cast<%3 (QObject::*)()>(0),\"%2\");") - .arg(QString::number(i+1), prop.name, propTypeName) << endl; + .arg(QString::number(i+1), prop.name, propTypeName) << Qt::endl; if (prop.modifier == prop.ReadWrite) //Make sure we have a setter function out << QStringLiteral(" QtPrivate::qtro_method_test<ObjectType>(&ObjectType::set%1, static_cast<void (QObject::*)(%2)>(0));") - .arg(cap(prop.name), propTypeName) << endl; + .arg(cap(prop.name), propTypeName) << Qt::endl; if (prop.modifier != prop.Constant) { //Make sure we have an onChange signal out << QStringLiteral(" QtPrivate::qtro_method_test<ObjectType>(&ObjectType::%1Changed, static_cast<void (QObject::*)()>(0));") - .arg(prop.name) << endl; + .arg(prop.name) << Qt::endl; onChangeProperties << prop; propertyChangeIndex << i + 1; //m_properties[0] is the count, so index is one higher } } const int signalCount = astClass.signalsList.count(); const int changedCount = onChangeProperties.size(); - out << QString::fromLatin1(" m_signals[0] = %1;").arg(signalCount+onChangeProperties.size()) << endl; + out << QString::fromLatin1(" m_signals[0] = %1;").arg(signalCount+onChangeProperties.size()) << Qt::endl; for (int i = 0; i < changedCount; ++i) out << QString::fromLatin1(" m_signals[%1] = QtPrivate::qtro_signal_index<ObjectType>(&ObjectType::%2Changed, " "static_cast<void (QObject::*)(%3)>(0),m_signalArgCount+%4,&m_signalArgTypes[%4]);") .arg(QString::number(i+1), onChangeProperties.at(i).name, fullyQualifiedTypeName(astClass, QStringLiteral("typename ObjectType"), typeForMode(onChangeProperties.at(i), SOURCE)), - QString::number(i)) << endl; + QString::number(i)) << Qt::endl; QVector<ASTFunction> signalsList = transformEnumParams(astClass, astClass.signalsList, QStringLiteral("typename ObjectType")); for (int i = 0; i < signalCount; ++i) { const ASTFunction &sig = signalsList.at(i); out << QString::fromLatin1(" m_signals[%1] = QtPrivate::qtro_signal_index<ObjectType>(&ObjectType::%2, " "static_cast<void (QObject::*)(%3)>(0),m_signalArgCount+%4,&m_signalArgTypes[%4]);") - .arg(QString::number(changedCount+i+1), sig.name, sig.paramsAsString(ASTFunction::Normalized), QString::number(changedCount+i)) << endl; + .arg(QString::number(changedCount+i+1), sig.name, sig.paramsAsString(ASTFunction::Normalized), QString::number(changedCount+i)) << Qt::endl; } const int slotCount = astClass.slotsList.count(); QVector<ASTProperty> pushProps; @@ -1060,7 +1060,7 @@ void RepCodeGenerator::generateSourceAPI(QTextStream &out, const ASTClass &astCl } const int pushCount = pushProps.count(); const int methodCount = slotCount + pushCount; - out << QString::fromLatin1(" m_methods[0] = %1;").arg(methodCount) << endl; + out << QString::fromLatin1(" m_methods[0] = %1;").arg(methodCount) << Qt::endl; for (int i = 0; i < pushCount; ++i) { const ASTProperty &prop = pushProps.at(i); const QString propTypeName = fullyQualifiedTypeName(astClass, QStringLiteral("typename ObjectType"), prop.type); @@ -1068,7 +1068,7 @@ void RepCodeGenerator::generateSourceAPI(QTextStream &out, const ASTClass &astCl "static_cast<void (QObject::*)(%3)>(0),\"push%2(%4)\",m_methodArgCount+%5,&m_methodArgTypes[%5]);") .arg(QString::number(i+1), cap(prop.name), propTypeName, QString(propTypeName).remove(QStringLiteral("typename ObjectType::")), // we don't want this in the string signature - QString::number(i)) << endl; + QString::number(i)) << Qt::endl; } QVector<ASTFunction> slotsList = transformEnumParams(astClass, astClass.slotsList, QStringLiteral("typename ObjectType")); @@ -1079,130 +1079,130 @@ void RepCodeGenerator::generateSourceAPI(QTextStream &out, const ASTClass &astCl "static_cast<void (QObject::*)(%3)>(0),\"%2(%4)\",m_methodArgCount+%5,&m_methodArgTypes[%5]);") .arg(QString::number(i+pushCount+1), slot.name, params, QString(params).remove(QStringLiteral("typename ObjectType::")), // we don't want this in the string signature - QString::number(i+pushCount)) << endl; + QString::number(i+pushCount)) << Qt::endl; } for (const auto &model : astClass.modelMetadata) { const ASTProperty &property = astClass.properties.at(model.propertyIndex); - out << QString::fromLatin1(" m_models << ModelInfo({object->%1(),").arg(property.name) << endl; - out << QString::fromLatin1(" QStringLiteral(\"%1\"),").arg(property.name) << endl; + out << QString::fromLatin1(" m_models << ModelInfo({object->%1(),").arg(property.name) << Qt::endl; + out << QString::fromLatin1(" QStringLiteral(\"%1\"),").arg(property.name) << Qt::endl; QStringList list; if (!model.roles.isEmpty()) { for (auto role : model.roles) list << role.name; } - out << QString::fromLatin1(" QByteArrayLiteral(\"%1\")});").arg(list.join(QChar::fromLatin1('|'))) << endl; + out << QString::fromLatin1(" QByteArrayLiteral(\"%1\")});").arg(list.join(QChar::fromLatin1('|'))) << Qt::endl; } for (int i : astClass.subClassPropertyIndices) { const ASTProperty &child = astClass.properties.at(i); out << QString::fromLatin1(" m_subclasses << new %2SourceAPI<%1_type_t>(object->%1(), QStringLiteral(\"%1\"));") - .arg(child.name, child.type) << endl; + .arg(child.name, child.type) << Qt::endl; } - out << QStringLiteral(" }") << endl; - out << QStringLiteral("") << endl; - out << QString::fromLatin1(" QString name() const override { return m_name; }") << endl; - out << QString::fromLatin1(" QString typeName() const override { return QStringLiteral(\"%1\"); }").arg(astClass.name) << endl; - out << QStringLiteral(" int enumCount() const override { return m_enums[0]; }") << endl; - out << QStringLiteral(" int propertyCount() const override { return m_properties[0]; }") << endl; - out << QStringLiteral(" int signalCount() const override { return m_signals[0]; }") << endl; - out << QStringLiteral(" int methodCount() const override { return m_methods[0]; }") << endl; - out << QStringLiteral(" int sourceEnumIndex(int index) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" if (index < 0 || index >= m_enums[0])") << endl; - out << QStringLiteral(" return -1;") << endl; - out << QStringLiteral(" return m_enums[index+1];") << endl; - out << QStringLiteral(" }") << endl; - out << QStringLiteral(" int sourcePropertyIndex(int index) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" if (index < 0 || index >= m_properties[0])") << endl; - out << QStringLiteral(" return -1;") << endl; - out << QStringLiteral(" return m_properties[index+1];") << endl; - out << QStringLiteral(" }") << endl; - out << QStringLiteral(" int sourceSignalIndex(int index) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" if (index < 0 || index >= m_signals[0])") << endl; - out << QStringLiteral(" return -1;") << endl; - out << QStringLiteral(" return m_signals[index+1];") << endl; - out << QStringLiteral(" }") << endl; - out << QStringLiteral(" int sourceMethodIndex(int index) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" if (index < 0 || index >= m_methods[0])") << endl; - out << QStringLiteral(" return -1;") << endl; - out << QStringLiteral(" return m_methods[index+1];") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" }") << Qt::endl; + out << QStringLiteral("") << Qt::endl; + out << QString::fromLatin1(" QString name() const override { return m_name; }") << Qt::endl; + out << QString::fromLatin1(" QString typeName() const override { return QStringLiteral(\"%1\"); }").arg(astClass.name) << Qt::endl; + out << QStringLiteral(" int enumCount() const override { return m_enums[0]; }") << Qt::endl; + out << QStringLiteral(" int propertyCount() const override { return m_properties[0]; }") << Qt::endl; + out << QStringLiteral(" int signalCount() const override { return m_signals[0]; }") << Qt::endl; + out << QStringLiteral(" int methodCount() const override { return m_methods[0]; }") << Qt::endl; + out << QStringLiteral(" int sourceEnumIndex(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" if (index < 0 || index >= m_enums[0])") << Qt::endl; + out << QStringLiteral(" return -1;") << Qt::endl; + out << QStringLiteral(" return m_enums[index+1];") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; + out << QStringLiteral(" int sourcePropertyIndex(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" if (index < 0 || index >= m_properties[0])") << Qt::endl; + out << QStringLiteral(" return -1;") << Qt::endl; + out << QStringLiteral(" return m_properties[index+1];") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; + out << QStringLiteral(" int sourceSignalIndex(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" if (index < 0 || index >= m_signals[0])") << Qt::endl; + out << QStringLiteral(" return -1;") << Qt::endl; + out << QStringLiteral(" return m_signals[index+1];") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; + out << QStringLiteral(" int sourceMethodIndex(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" if (index < 0 || index >= m_methods[0])") << Qt::endl; + out << QStringLiteral(" return -1;") << Qt::endl; + out << QStringLiteral(" return m_methods[index+1];") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; if (signalCount+changedCount > 0) { - out << QStringLiteral(" int signalParameterCount(int index) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" if (index < 0 || index >= m_signals[0])") << endl; - out << QStringLiteral(" return -1;") << endl; - out << QStringLiteral(" return m_signalArgCount[index];") << endl; - out << QStringLiteral(" }") << endl; - out << QStringLiteral(" int signalParameterType(int sigIndex, int paramIndex) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" if (sigIndex < 0 || sigIndex >= m_signals[0] || paramIndex < 0 || paramIndex >= m_signalArgCount[sigIndex])") << endl; - out << QStringLiteral(" return -1;") << endl; - out << QStringLiteral(" return m_signalArgTypes[sigIndex][paramIndex];") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" int signalParameterCount(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" if (index < 0 || index >= m_signals[0])") << Qt::endl; + out << QStringLiteral(" return -1;") << Qt::endl; + out << QStringLiteral(" return m_signalArgCount[index];") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; + out << QStringLiteral(" int signalParameterType(int sigIndex, int paramIndex) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" if (sigIndex < 0 || sigIndex >= m_signals[0] || paramIndex < 0 || paramIndex >= m_signalArgCount[sigIndex])") << Qt::endl; + out << QStringLiteral(" return -1;") << Qt::endl; + out << QStringLiteral(" return m_signalArgTypes[sigIndex][paramIndex];") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; } else { - out << QStringLiteral(" int signalParameterCount(int index) const override { Q_UNUSED(index); return -1; }") << endl; - out << QStringLiteral(" int signalParameterType(int sigIndex, int paramIndex) const override") << endl; - out << QStringLiteral(" { Q_UNUSED(sigIndex); Q_UNUSED(paramIndex); return -1; }") << endl; + out << QStringLiteral(" int signalParameterCount(int index) const override { Q_UNUSED(index); return -1; }") << Qt::endl; + out << QStringLiteral(" int signalParameterType(int sigIndex, int paramIndex) const override") << Qt::endl; + out << QStringLiteral(" { Q_UNUSED(sigIndex); Q_UNUSED(paramIndex); return -1; }") << Qt::endl; } if (methodCount > 0) { - out << QStringLiteral(" int methodParameterCount(int index) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" if (index < 0 || index >= m_methods[0])") << endl; - out << QStringLiteral(" return -1;") << endl; - out << QStringLiteral(" return m_methodArgCount[index];") << endl; - out << QStringLiteral(" }") << endl; - out << QStringLiteral(" int methodParameterType(int methodIndex, int paramIndex) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" if (methodIndex < 0 || methodIndex >= m_methods[0] || paramIndex < 0 || paramIndex >= m_methodArgCount[methodIndex])") << endl; - out << QStringLiteral(" return -1;") << endl; - out << QStringLiteral(" return m_methodArgTypes[methodIndex][paramIndex];") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" int methodParameterCount(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" if (index < 0 || index >= m_methods[0])") << Qt::endl; + out << QStringLiteral(" return -1;") << Qt::endl; + out << QStringLiteral(" return m_methodArgCount[index];") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; + out << QStringLiteral(" int methodParameterType(int methodIndex, int paramIndex) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" if (methodIndex < 0 || methodIndex >= m_methods[0] || paramIndex < 0 || paramIndex >= m_methodArgCount[methodIndex])") << Qt::endl; + out << QStringLiteral(" return -1;") << Qt::endl; + out << QStringLiteral(" return m_methodArgTypes[methodIndex][paramIndex];") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; } else { - out << QStringLiteral(" int methodParameterCount(int index) const override { Q_UNUSED(index); return -1; }") << endl; - out << QStringLiteral(" int methodParameterType(int methodIndex, int paramIndex) const override") << endl; - out << QStringLiteral(" { Q_UNUSED(methodIndex); Q_UNUSED(paramIndex); return -1; }") << endl; + out << QStringLiteral(" int methodParameterCount(int index) const override { Q_UNUSED(index); return -1; }") << Qt::endl; + out << QStringLiteral(" int methodParameterType(int methodIndex, int paramIndex) const override") << Qt::endl; + out << QStringLiteral(" { Q_UNUSED(methodIndex); Q_UNUSED(paramIndex); return -1; }") << Qt::endl; } //propertyIndexFromSignal method - out << QStringLiteral(" int propertyIndexFromSignal(int index) const override") << endl; - out << QStringLiteral(" {") << endl; + out << QStringLiteral(" int propertyIndexFromSignal(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; if (!propertyChangeIndex.isEmpty()) { - out << QStringLiteral(" switch (index) {") << endl; + out << QStringLiteral(" switch (index) {") << Qt::endl; for (int i = 0; i < propertyChangeIndex.size(); ++i) - out << QString::fromLatin1(" case %1: return m_properties[%2];").arg(i).arg(propertyChangeIndex.at(i)) << endl; - out << QStringLiteral(" }") << endl; + out << QString::fromLatin1(" case %1: return m_properties[%2];").arg(i).arg(propertyChangeIndex.at(i)) << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; } else - out << QStringLiteral(" Q_UNUSED(index);") << endl; - out << QStringLiteral(" return -1;") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" Q_UNUSED(index);") << Qt::endl; + out << QStringLiteral(" return -1;") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; //propertyRawIndexFromSignal method - out << QStringLiteral(" int propertyRawIndexFromSignal(int index) const override") << endl; - out << QStringLiteral(" {") << endl; + out << QStringLiteral(" int propertyRawIndexFromSignal(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; if (!propertyChangeIndex.isEmpty()) { - out << QStringLiteral(" switch (index) {") << endl; + out << QStringLiteral(" switch (index) {") << Qt::endl; for (int i = 0; i < propertyChangeIndex.size(); ++i) - out << QString::fromLatin1(" case %1: return %2;").arg(i).arg(propertyChangeIndex.at(i)-1) << endl; - out << QStringLiteral(" }") << endl; + out << QString::fromLatin1(" case %1: return %2;").arg(i).arg(propertyChangeIndex.at(i)-1) << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; } else - out << QStringLiteral(" Q_UNUSED(index);") << endl; - out << QStringLiteral(" return -1;") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" Q_UNUSED(index);") << Qt::endl; + out << QStringLiteral(" return -1;") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; //signalSignature method - out << QStringLiteral(" const QByteArray signalSignature(int index) const override") << endl; - out << QStringLiteral(" {") << endl; + out << QStringLiteral(" const QByteArray signalSignature(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; if (signalCount+changedCount > 0) { - out << QStringLiteral(" switch (index) {") << endl; + out << QStringLiteral(" switch (index) {") << Qt::endl; for (int i = 0; i < changedCount; ++i) { const ASTProperty &prop = onChangeProperties.at(i); if (isClassEnum(astClass, prop.type)) out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"%2Changed($1)\").replace(\"$1\", QtPrivate::qtro_enum_signature<ObjectType>(\"%3\"));") - .arg(QString::number(i), prop.name, prop.type) << endl; + .arg(QString::number(i), prop.name, prop.type) << Qt::endl; else out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"%2Changed(%3)\");") - .arg(QString::number(i), prop.name, typeForMode(prop, SOURCE)) << endl; + .arg(QString::number(i), prop.name, typeForMode(prop, SOURCE)) << Qt::endl; } for (int i = 0; i < signalCount; ++i) { @@ -1219,36 +1219,36 @@ void RepCodeGenerator::generateSourceAPI(QTextStream &out, const ASTClass &astCl } } out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"%2(%3)\")%4;") - .arg(QString::number(i+changedCount), sig.name, paramsAsString, enumString) << endl; + .arg(QString::number(i+changedCount), sig.name, paramsAsString, enumString) << Qt::endl; } - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" }") << Qt::endl; } else - out << QStringLiteral(" Q_UNUSED(index);") << endl; - out << QStringLiteral(" return QByteArrayLiteral(\"\");") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" Q_UNUSED(index);") << Qt::endl; + out << QStringLiteral(" return QByteArrayLiteral(\"\");") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; //signalParameterNames method - out << QStringLiteral(" QList<QByteArray> signalParameterNames(int index) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" if (index < 0 || index >= m_signals[0])") << endl; - out << QStringLiteral(" return QList<QByteArray>();") << endl; - out << QStringLiteral(" return ObjectType::staticMetaObject.method(m_signals[index + 1]).parameterNames();") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" QList<QByteArray> signalParameterNames(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" if (index < 0 || index >= m_signals[0])") << Qt::endl; + out << QStringLiteral(" return QList<QByteArray>();") << Qt::endl; + out << QStringLiteral(" return ObjectType::staticMetaObject.method(m_signals[index + 1]).parameterNames();") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; //methodSignature method - out << QStringLiteral(" const QByteArray methodSignature(int index) const override") << endl; - out << QStringLiteral(" {") << endl; + out << QStringLiteral(" const QByteArray methodSignature(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; if (methodCount > 0) { - out << QStringLiteral(" switch (index) {") << endl; + out << QStringLiteral(" switch (index) {") << Qt::endl; for (int i = 0; i < pushCount; ++i) { const ASTProperty &prop = pushProps.at(i); if (isClassEnum(astClass, prop.type)) out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"push%2($1)\").replace(\"$1\", QtPrivate::qtro_enum_signature<ObjectType>(\"%3\"));") - .arg(QString::number(i), prop.name, prop.type) << endl; + .arg(QString::number(i), prop.name, prop.type) << Qt::endl; else out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"push%2(%3)\");") - .arg(QString::number(i), cap(prop.name), prop.type) << endl; + .arg(QString::number(i), cap(prop.name), prop.type) << Qt::endl; } for (int i = 0; i < slotCount; ++i) { @@ -1265,75 +1265,75 @@ void RepCodeGenerator::generateSourceAPI(QTextStream &out, const ASTClass &astCl } } out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"%2(%3)\")%4;") - .arg(QString::number(i+pushCount), slot.name, paramsAsString, enumString) << endl; + .arg(QString::number(i+pushCount), slot.name, paramsAsString, enumString) << Qt::endl; } - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" }") << Qt::endl; } else - out << QStringLiteral(" Q_UNUSED(index);") << endl; - out << QStringLiteral(" return QByteArrayLiteral(\"\");") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" Q_UNUSED(index);") << Qt::endl; + out << QStringLiteral(" return QByteArrayLiteral(\"\");") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; //methodType method - out << QStringLiteral(" QMetaMethod::MethodType methodType(int) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" return QMetaMethod::Slot;") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" QMetaMethod::MethodType methodType(int) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" return QMetaMethod::Slot;") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; //methodParameterNames method - out << QStringLiteral(" QList<QByteArray> methodParameterNames(int index) const override") << endl; - out << QStringLiteral(" {") << endl; - out << QStringLiteral(" if (index < 0 || index >= m_methods[0])") << endl; - out << QStringLiteral(" return QList<QByteArray>();") << endl; - out << QStringLiteral(" return ObjectType::staticMetaObject.method(m_methods[index + 1]).parameterNames();") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" QList<QByteArray> methodParameterNames(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; + out << QStringLiteral(" if (index < 0 || index >= m_methods[0])") << Qt::endl; + out << QStringLiteral(" return QList<QByteArray>();") << Qt::endl; + out << QStringLiteral(" return ObjectType::staticMetaObject.method(m_methods[index + 1]).parameterNames();") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; //typeName method - out << QStringLiteral(" const QByteArray typeName(int index) const override") << endl; - out << QStringLiteral(" {") << endl; + out << QStringLiteral(" const QByteArray typeName(int index) const override") << Qt::endl; + out << QStringLiteral(" {") << Qt::endl; if (methodCount > 0) { - out << QStringLiteral(" switch (index) {") << endl; + out << QStringLiteral(" switch (index) {") << Qt::endl; for (int i = 0; i < pushCount; ++i) { out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"void\");") - .arg(QString::number(i)) << endl; + .arg(QString::number(i)) << Qt::endl; } for (int i = 0; i < slotCount; ++i) { const ASTFunction &slot = astClass.slotsList.at(i); if (isClassEnum(astClass, slot.returnType)) out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"$1\").replace(\"$1\", QtPrivate::qtro_enum_signature<ObjectType>(\"%2\"));") - .arg(QString::number(i+pushCount), slot.returnType) << endl; + .arg(QString::number(i+pushCount), slot.returnType) << Qt::endl; else out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"%2\");") - .arg(QString::number(i+pushCount), slot.returnType) << endl; + .arg(QString::number(i+pushCount), slot.returnType) << Qt::endl; } - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" }") << Qt::endl; } else - out << QStringLiteral(" Q_UNUSED(index);") << endl; - out << QStringLiteral(" return QByteArrayLiteral(\"\");") << endl; - out << QStringLiteral(" }") << endl; + out << QStringLiteral(" Q_UNUSED(index);") << Qt::endl; + out << QStringLiteral(" return QByteArrayLiteral(\"\");") << Qt::endl; + out << QStringLiteral(" }") << Qt::endl; //objectSignature method out << QStringLiteral(" QByteArray objectSignature() const override { return QByteArray{\"") << QLatin1String(classSignature(astClass)) - << QStringLiteral("\"}; }") << endl; - - out << QStringLiteral("") << endl; - out << QString::fromLatin1(" int m_enums[%1];").arg(enumCount + 1) << endl; - out << QString::fromLatin1(" int m_properties[%1];").arg(propCount+1) << endl; - out << QString::fromLatin1(" int m_signals[%1];").arg(signalCount+changedCount+1) << endl; - out << QString::fromLatin1(" int m_methods[%1];").arg(methodCount+1) << endl; - out << QString::fromLatin1(" const QString m_name;") << endl; + << QStringLiteral("\"}; }") << Qt::endl; + + out << QStringLiteral("") << Qt::endl; + out << QString::fromLatin1(" int m_enums[%1];").arg(enumCount + 1) << Qt::endl; + out << QString::fromLatin1(" int m_properties[%1];").arg(propCount+1) << Qt::endl; + out << QString::fromLatin1(" int m_signals[%1];").arg(signalCount+changedCount+1) << Qt::endl; + out << QString::fromLatin1(" int m_methods[%1];").arg(methodCount+1) << Qt::endl; + out << QString::fromLatin1(" const QString m_name;") << Qt::endl; if (signalCount+changedCount > 0) { - out << QString::fromLatin1(" int m_signalArgCount[%1];").arg(signalCount+changedCount) << endl; - out << QString::fromLatin1(" const int* m_signalArgTypes[%1];").arg(signalCount+changedCount) << endl; + out << QString::fromLatin1(" int m_signalArgCount[%1];").arg(signalCount+changedCount) << Qt::endl; + out << QString::fromLatin1(" const int* m_signalArgTypes[%1];").arg(signalCount+changedCount) << Qt::endl; } if (methodCount > 0) { - out << QString::fromLatin1(" int m_methodArgCount[%1];").arg(methodCount) << endl; - out << QString::fromLatin1(" const int* m_methodArgTypes[%1];").arg(methodCount) << endl; + out << QString::fromLatin1(" int m_methodArgCount[%1];").arg(methodCount) << Qt::endl; + out << QString::fromLatin1(" const int* m_methodArgTypes[%1];").arg(methodCount) << Qt::endl; } - out << QStringLiteral("};") << endl; - out << "" << endl; + out << QStringLiteral("};") << Qt::endl; + out << "" << Qt::endl; } QT_END_NAMESPACE |