qdbusxml2cpp: Use "\n" instead of Qt::endl

This program is non-interactive and its output does not need
to be flushed after each line of the generated code. Using "\n"
improves code size, performance and readability.

Change-Id: I7def2a207cf4e5c3960db6ba3d8a8574eb0d27c1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ievgenii Meshcheriakov 2023-05-25 14:40:53 +02:00
parent 4f65f91d6f
commit 464bcc0b6a

View File

@ -181,22 +181,21 @@ static QString moc(const QString &name)
static QTextStream &writeHeader(QTextStream &ts, bool changesWillBeLost) static QTextStream &writeHeader(QTextStream &ts, bool changesWillBeLost)
{ {
ts << "/*" << Qt::endl ts << "/*\n"
<< " * This file was generated by " PROGRAMNAME " version " PROGRAMVERSION << Qt::endl << " * This file was generated by " PROGRAMNAME " version " PROGRAMVERSION "\n"
<< " * Command line was: " << commandLine << Qt::endl << " * Command line was: " << commandLine << "\n"
<< " *" << Qt::endl << " *\n"
<< " * " PROGRAMNAME " is " PROGRAMCOPYRIGHT << Qt::endl << " * " PROGRAMNAME " is " PROGRAMCOPYRIGHT "\n"
<< " *" << Qt::endl << " *\n"
<< " * This is an auto-generated file." << Qt::endl; << " * This is an auto-generated file.\n";
if (changesWillBeLost) if (changesWillBeLost)
ts << " * Do not edit! All changes made to it will be lost." << Qt::endl; ts << " * Do not edit! All changes made to it will be lost.\n";
else else
ts << " * This file may have been hand-edited. Look for HAND-EDIT comments" << Qt::endl ts << " * This file may have been hand-edited. Look for HAND-EDIT comments\n"
<< " * before re-generating it." << Qt::endl; << " * before re-generating it.\n";
ts << " */" << Qt::endl ts << " */\n\n";
<< Qt::endl;
return ts; return ts;
} }
@ -484,77 +483,70 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
includeGuard = u"QDBUSXML2CPP_PROXY"_s; includeGuard = u"QDBUSXML2CPP_PROXY"_s;
} }
hs << "#ifndef " << includeGuard << Qt::endl hs << "#ifndef " << includeGuard << "\n"
<< "#define " << includeGuard << Qt::endl << "#define " << includeGuard << "\n\n";
<< Qt::endl;
// include our stuff: // include our stuff:
hs << "#include <QtCore/QObject>" << Qt::endl hs << "#include <QtCore/QObject>\n"
<< includeList; << includeList;
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
hs << "#include <QtDBus/QtDBus>" << Qt::endl; hs << "#include <QtDBus/QtDBus>\n";
#else #else
hs << "#include <QtDBus/QDBusAbstractInterface>" << Qt::endl; hs << "#include <QtDBus/QDBusAbstractInterface>\n";
hs << "#include <QtDBus/QDBusPendingReply>" << Qt::endl; hs << "#include <QtDBus/QDBusPendingReply>\n";
#endif #endif
for (const QString &include : std::as_const(includes)) { for (const QString &include : std::as_const(includes)) {
hs << "#include \"" << include << "\"" << Qt::endl; hs << "#include \"" << include << "\"\n";
if (headerName.isEmpty()) if (headerName.isEmpty())
cs << "#include \"" << include << "\"" << Qt::endl; cs << "#include \"" << include << "\"\n";
} }
for (const QString &include : std::as_const(globalIncludes)) { for (const QString &include : std::as_const(globalIncludes)) {
hs << "#include <" << include << ">" << Qt::endl; hs << "#include <" << include << ">\n";
if (headerName.isEmpty()) if (headerName.isEmpty())
cs << "#include <" << include << ">" << Qt::endl; cs << "#include <" << include << ">\n";
} }
hs << Qt::endl; hs << "\n";
if (cppName != headerName) { if (cppName != headerName) {
if (!headerName.isEmpty() && headerName != "-"_L1) if (!headerName.isEmpty() && headerName != "-"_L1)
cs << "#include \"" << headerName << "\"" << Qt::endl << Qt::endl; cs << "#include \"" << headerName << "\"\n\n";
} }
for (const QDBusIntrospection::Interface *interface : interfaces) { for (const QDBusIntrospection::Interface *interface : interfaces) {
QString className = classNameForInterface(interface->name, Proxy); QString className = classNameForInterface(interface->name, Proxy);
// comment: // comment:
hs << "/*" << Qt::endl hs << "/*\n"
<< " * Proxy class for interface " << interface->name << Qt::endl << " * Proxy class for interface " << interface->name << "\n"
<< " */" << Qt::endl; << " */\n";
cs << "/*" << Qt::endl cs << "/*\n"
<< " * Implementation of interface class " << className << Qt::endl << " * Implementation of interface class " << className << "\n"
<< " */" << Qt::endl << " */\n\n";
<< Qt::endl;
// class header: // class header:
hs << "class " << className << ": public QDBusAbstractInterface" << Qt::endl hs << "class " << className << ": public QDBusAbstractInterface\n"
<< "{" << Qt::endl << "{\n"
<< " Q_OBJECT" << Qt::endl; << " Q_OBJECT\n";
// the interface name // the interface name
hs << "public:" << Qt::endl hs << "public:\n"
<< " static inline const char *staticInterfaceName()" << Qt::endl << " static inline const char *staticInterfaceName()\n"
<< " { return \"" << interface->name << "\"; }" << Qt::endl << " { return \"" << interface->name << "\"; }\n\n";
<< Qt::endl;
// constructors/destructors: // constructors/destructors:
hs << "public:" << Qt::endl hs << "public:\n"
<< " " << className << "(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr);" << Qt::endl << " " << className << "(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr);\n\n"
<< Qt::endl << " ~" << className << "();\n\n";
<< " ~" << className << "();" << Qt::endl cs << className << "::" << className << "(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)\n"
<< Qt::endl; << " : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)\n"
cs << className << "::" << className << "(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)" << Qt::endl << "{\n"
<< " : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)" << Qt::endl << "}\n\n"
<< "{" << Qt::endl << className << "::~" << className << "()\n"
<< "}" << Qt::endl << "{\n"
<< Qt::endl << "}\n\n";
<< className << "::~" << className << "()" << Qt::endl
<< "{" << Qt::endl
<< "}" << Qt::endl
<< Qt::endl;
// properties: // properties:
for (const QDBusIntrospection::Property &property : interface->properties) { for (const QDBusIntrospection::Property &property : interface->properties) {
@ -574,27 +566,27 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
// it's writeable // it's writeable
hs << " WRITE " << setter; hs << " WRITE " << setter;
hs << ")" << Qt::endl; hs << ")\n";
// getter: // getter:
if (property.access != QDBusIntrospection::Property::Write) { if (property.access != QDBusIntrospection::Property::Write) {
hs << " inline " << type << " " << getter << "() const" << Qt::endl hs << " inline " << type << " " << getter << "() const\n"
<< " { return qvariant_cast< " << type << " >(property(\"" << " { return qvariant_cast< " << type << " >(property(\""
<< property.name << "\")); }" << Qt::endl; << property.name << "\")); }\n";
} }
// setter: // setter:
if (property.access != QDBusIntrospection::Property::Read) { if (property.access != QDBusIntrospection::Property::Read) {
hs << " inline void " << setter << "(" << constRefArg(type) << "value)" << Qt::endl hs << " inline void " << setter << "(" << constRefArg(type) << "value)\n"
<< " { setProperty(\"" << property.name << " { setProperty(\"" << property.name
<< "\", QVariant::fromValue(value)); }" << Qt::endl; << "\", QVariant::fromValue(value)); }\n";
} }
hs << Qt::endl; hs << "\n";
} }
// methods: // methods:
hs << "public Q_SLOTS: // METHODS" << Qt::endl; hs << "public Q_SLOTS: // METHODS\n";
for (const QDBusIntrospection::Method &method : interface->methods) { for (const QDBusIntrospection::Method &method : interface->methods) {
bool isDeprecated = method.annotations.value("org.freedesktop.DBus.Deprecated"_L1) == "true"_L1; bool isDeprecated = method.annotations.value("org.freedesktop.DBus.Deprecated"_L1) == "true"_L1;
bool isNoReply = bool isNoReply =
@ -627,26 +619,26 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
QStringList argNames = makeArgNames(method.inputArgs); QStringList argNames = makeArgNames(method.inputArgs);
writeArgList(hs, argNames, method.annotations, method.inputArgs); writeArgList(hs, argNames, method.annotations, method.inputArgs);
hs << ")" << Qt::endl hs << ")\n"
<< " {" << Qt::endl << " {\n"
<< " QList<QVariant> argumentList;" << Qt::endl; << " QList<QVariant> argumentList;\n";
if (!method.inputArgs.isEmpty()) { if (!method.inputArgs.isEmpty()) {
hs << " argumentList"; hs << " argumentList";
for (qsizetype argPos = 0; argPos < method.inputArgs.size(); ++argPos) for (qsizetype argPos = 0; argPos < method.inputArgs.size(); ++argPos)
hs << " << QVariant::fromValue(" << argNames.at(argPos) << ')'; hs << " << QVariant::fromValue(" << argNames.at(argPos) << ')';
hs << ";" << Qt::endl; hs << ";\n";
} }
if (isNoReply) if (isNoReply)
hs << " callWithArgumentList(QDBus::NoBlock, " hs << " callWithArgumentList(QDBus::NoBlock, "
<< "QStringLiteral(\"" << method.name << "\"), argumentList);" << Qt::endl; << "QStringLiteral(\"" << method.name << "\"), argumentList);\n";
else else
hs << " return asyncCallWithArgumentList(QStringLiteral(\"" hs << " return asyncCallWithArgumentList(QStringLiteral(\""
<< method.name << "\"), argumentList);" << Qt::endl; << method.name << "\"), argumentList);\n";
// close the function: // close the function:
hs << " }" << Qt::endl; hs << " }\n";
if (method.outputArgs.size() > 1) { if (method.outputArgs.size() > 1) {
// generate the old-form QDBusReply methods with multiple incoming parameters // generate the old-form QDBusReply methods with multiple incoming parameters
@ -659,40 +651,40 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
QStringList argNames = makeArgNames(method.inputArgs, method.outputArgs); QStringList argNames = makeArgNames(method.inputArgs, method.outputArgs);
writeArgList(hs, argNames, method.annotations, method.inputArgs, method.outputArgs); writeArgList(hs, argNames, method.annotations, method.inputArgs, method.outputArgs);
hs << ")" << Qt::endl hs << ")\n"
<< " {" << Qt::endl << " {\n"
<< " QList<QVariant> argumentList;" << Qt::endl; << " QList<QVariant> argumentList;\n";
qsizetype argPos = 0; qsizetype argPos = 0;
if (!method.inputArgs.isEmpty()) { if (!method.inputArgs.isEmpty()) {
hs << " argumentList"; hs << " argumentList";
for (argPos = 0; argPos < method.inputArgs.size(); ++argPos) for (argPos = 0; argPos < method.inputArgs.size(); ++argPos)
hs << " << QVariant::fromValue(" << argNames.at(argPos) << ')'; hs << " << QVariant::fromValue(" << argNames.at(argPos) << ')';
hs << ";" << Qt::endl; hs << ";\n";
} }
hs << " QDBusMessage reply = callWithArgumentList(QDBus::Block, " hs << " QDBusMessage reply = callWithArgumentList(QDBus::Block, "
<< "QStringLiteral(\"" << method.name << "\"), argumentList);" << Qt::endl; << "QStringLiteral(\"" << method.name << "\"), argumentList);\n";
argPos++; argPos++;
hs << " if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().size() == " hs << " if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().size() == "
<< method.outputArgs.size() << ") {" << Qt::endl; << method.outputArgs.size() << ") {\n";
// yes, starting from 1 // yes, starting from 1
for (qsizetype i = 1; i < method.outputArgs.size(); ++i) for (qsizetype i = 1; i < method.outputArgs.size(); ++i)
hs << " " << argNames.at(argPos++) << " = qdbus_cast<" hs << " " << argNames.at(argPos++) << " = qdbus_cast<"
<< templateArg(qtTypeName(method.outputArgs.at(i).name, method.outputArgs.at(i).type, << templateArg(qtTypeName(method.outputArgs.at(i).name, method.outputArgs.at(i).type,
method.annotations, i, "Out")) method.annotations, i, "Out"))
<< ">(reply.arguments().at(" << i << "));" << Qt::endl; << ">(reply.arguments().at(" << i << "));\n";
hs << " }" << Qt::endl hs << " }\n"
<< " return reply;" << Qt::endl << " return reply;\n"
<< " }" << Qt::endl; << " }\n";
} }
hs << Qt::endl; hs << "\n";
} }
hs << "Q_SIGNALS: // SIGNALS" << Qt::endl; hs << "Q_SIGNALS: // SIGNALS\n";
for (const QDBusIntrospection::Signal &signal : interface->signals_) { for (const QDBusIntrospection::Signal &signal : interface->signals_) {
hs << " "; hs << " ";
if (signal.annotations.value("org.freedesktop.DBus.Deprecated"_L1) == "true"_L1) if (signal.annotations.value("org.freedesktop.DBus.Deprecated"_L1) == "true"_L1)
@ -703,12 +695,11 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
QStringList argNames = makeArgNames(signal.outputArgs); QStringList argNames = makeArgNames(signal.outputArgs);
writeSignalArgList(hs, argNames, signal.annotations, signal.outputArgs); writeSignalArgList(hs, argNames, signal.annotations, signal.outputArgs);
hs << ");" << Qt::endl; // finished for header hs << ");\n"; // finished for header
} }
// close the class: // close the class:
hs << "};" << Qt::endl hs << "};\n\n";
<< Qt::endl;
} }
if (!skipNamespaces) { if (!skipNamespaces) {
@ -730,17 +721,17 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
// i parts matched // i parts matched
// close last.arguments().size() - i namespaces: // close last.arguments().size() - i namespaces:
for (qsizetype j = i; j < last.size(); ++j) for (qsizetype j = i; j < last.size(); ++j)
hs << QString((last.size() - j - 1 + i) * 2, u' ') << "}" << Qt::endl; hs << QString((last.size() - j - 1 + i) * 2, u' ') << "}\n";
// open current.arguments().size() - i namespaces // open current.arguments().size() - i namespaces
for (qsizetype j = i; j < current.size(); ++j) for (qsizetype j = i; j < current.size(); ++j)
hs << QString(j * 2, u' ') << "namespace " << current.at(j) << " {" << Qt::endl; hs << QString(j * 2, u' ') << "namespace " << current.at(j) << " {\n";
// add this class: // add this class:
if (!name.isEmpty()) { if (!name.isEmpty()) {
hs << QString(current.size() * 2, u' ') hs << QString(current.size() * 2, u' ')
<< "using " << name << " = ::" << classNameForInterface(it->constData()->name, Proxy) << "using " << name << " = ::" << classNameForInterface(it->constData()->name, Proxy)
<< ";" << Qt::endl; << ";\n";
} }
if (it == interfaces.constEnd()) if (it == interfaces.constEnd())
@ -751,12 +742,12 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
} }
// close the include guard // close the include guard
hs << "#endif" << Qt::endl; hs << "#endif\n";
QString mocName = moc(filename); QString mocName = moc(filename);
if (includeMocs && !mocName.isEmpty()) if (includeMocs && !mocName.isEmpty())
cs << Qt::endl cs << "\n"
<< "#include \"" << mocName << "\"" << Qt::endl; << "#include \"" << mocName << "\"\n";
cs.flush(); cs.flush();
hs.flush(); hs.flush();
@ -803,47 +794,46 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
includeGuard = u"QDBUSXML2CPP_ADAPTOR"_s; includeGuard = u"QDBUSXML2CPP_ADAPTOR"_s;
} }
hs << "#ifndef " << includeGuard << Qt::endl hs << "#ifndef " << includeGuard << "\n"
<< "#define " << includeGuard << Qt::endl << "#define " << includeGuard << "\n\n";
<< Qt::endl;
// include our stuff: // include our stuff:
hs << "#include <QtCore/QObject>" << Qt::endl; hs << "#include <QtCore/QObject>\n";
if (cppName == headerName) if (cppName == headerName)
hs << "#include <QtCore/QMetaObject>" << Qt::endl hs << "#include <QtCore/QMetaObject>\n"
<< "#include <QtCore/QVariant>" << Qt::endl; << "#include <QtCore/QVariant>\n";
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
hs << "#include <QtDBus/QtDBus>" << Qt::endl; hs << "#include <QtDBus/QtDBus>\n";
#else #else
hs << "#include <QtDBus/QDBusAbstractAdaptor>" << Qt::endl; hs << "#include <QtDBus/QDBusAbstractAdaptor>\n";
hs << "#include <QtDBus/QDBusObjectPath>" << Qt::endl; hs << "#include <QtDBus/QDBusObjectPath>\n";
#endif #endif
for (const QString &include : std::as_const(includes)) { for (const QString &include : std::as_const(includes)) {
hs << "#include \"" << include << "\"" << Qt::endl; hs << "#include \"" << include << "\"\n";
if (headerName.isEmpty()) if (headerName.isEmpty())
cs << "#include \"" << include << "\"" << Qt::endl; cs << "#include \"" << include << "\"\n";
} }
for (const QString &include : std::as_const(globalIncludes)) { for (const QString &include : std::as_const(globalIncludes)) {
hs << "#include <" << include << ">" << Qt::endl; hs << "#include <" << include << ">\n";
if (headerName.isEmpty()) if (headerName.isEmpty())
cs << "#include <" << include << ">" << Qt::endl; cs << "#include <" << include << ">\n";
} }
if (cppName != headerName) { if (cppName != headerName) {
if (!headerName.isEmpty() && headerName != "-"_L1) if (!headerName.isEmpty() && headerName != "-"_L1)
cs << "#include \"" << headerName << "\"" << Qt::endl; cs << "#include \"" << headerName << "\"\n";
cs << "#include <QtCore/QMetaObject>" << Qt::endl cs << "#include <QtCore/QMetaObject>\n"
<< includeList << includeList
<< Qt::endl; << "\n";
hs << forwardDeclarations; hs << forwardDeclarations;
} else { } else {
hs << includeList; hs << includeList;
} }
hs << Qt::endl; hs << "\n";
QString parent = parentClassName; QString parent = parentClassName;
if (parentClassName.isEmpty()) if (parentClassName.isEmpty())
@ -853,47 +843,42 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
QString className = classNameForInterface(interface->name, Adaptor); QString className = classNameForInterface(interface->name, Adaptor);
// comment: // comment:
hs << "/*" << Qt::endl hs << "/*\n"
<< " * Adaptor class for interface " << interface->name << Qt::endl << " * Adaptor class for interface " << interface->name << "\n"
<< " */" << Qt::endl; << " */\n";
cs << "/*" << Qt::endl cs << "/*\n"
<< " * Implementation of adaptor class " << className << Qt::endl << " * Implementation of adaptor class " << className << "\n"
<< " */" << Qt::endl << " */\n\n";
<< Qt::endl;
// class header: // class header:
hs << "class " << className << ": public QDBusAbstractAdaptor" << Qt::endl hs << "class " << className << ": public QDBusAbstractAdaptor\n"
<< "{" << Qt::endl << "{\n"
<< " Q_OBJECT" << Qt::endl << " Q_OBJECT\n"
<< " Q_CLASSINFO(\"D-Bus Interface\", \"" << interface->name << "\")" << Qt::endl << " Q_CLASSINFO(\"D-Bus Interface\", \"" << interface->name << "\")\n"
<< " Q_CLASSINFO(\"D-Bus Introspection\", \"\"" << Qt::endl << " Q_CLASSINFO(\"D-Bus Introspection\", \"\"\n"
<< stringify(interface->introspection) << stringify(interface->introspection)
<< " \"\")" << Qt::endl << " \"\")\n"
<< "public:" << Qt::endl << "public:\n"
<< " " << className << "(" << parent << " *parent);" << Qt::endl << " " << className << "(" << parent << " *parent);\n"
<< " virtual ~" << className << "();" << Qt::endl << " virtual ~" << className << "();\n\n";
<< Qt::endl;
if (!parentClassName.isEmpty()) if (!parentClassName.isEmpty())
hs << " inline " << parent << " *parent() const" << Qt::endl hs << " inline " << parent << " *parent() const\n"
<< " { return static_cast<" << parent << " *>(QObject::parent()); }" << Qt::endl << " { return static_cast<" << parent << " *>(QObject::parent()); }\n\n";
<< Qt::endl;
// constructor/destructor // constructor/destructor
cs << className << "::" << className << "(" << parent << " *parent)" << Qt::endl cs << className << "::" << className << "(" << parent << " *parent)\n"
<< " : QDBusAbstractAdaptor(parent)" << Qt::endl << " : QDBusAbstractAdaptor(parent)\n"
<< "{" << Qt::endl << "{\n"
<< " // constructor" << Qt::endl << " // constructor\n"
<< " setAutoRelaySignals(true);" << Qt::endl << " setAutoRelaySignals(true);\n"
<< "}" << Qt::endl << "}\n\n"
<< Qt::endl << className << "::~" << className << "()\n"
<< className << "::~" << className << "()" << Qt::endl << "{\n"
<< "{" << Qt::endl << " // destructor\n"
<< " // destructor" << Qt::endl << "}\n\n";
<< "}" << Qt::endl
<< Qt::endl;
hs << "public: // PROPERTIES" << Qt::endl; hs << "public: // PROPERTIES\n";
for (const QDBusIntrospection::Property &property : interface->properties) { for (const QDBusIntrospection::Property &property : interface->properties) {
QByteArray type = qtTypeName(property.name, property.type, property.annotations); QByteArray type = qtTypeName(property.name, property.type, property.annotations);
QString constRefType = constRefArg(type); QString constRefType = constRefArg(type);
@ -905,38 +890,36 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
hs << " READ " << getter; hs << " READ " << getter;
if (property.access != QDBusIntrospection::Property::Read) if (property.access != QDBusIntrospection::Property::Read)
hs << " WRITE " << setter; hs << " WRITE " << setter;
hs << ")" << Qt::endl; hs << ")\n";
// getter: // getter:
if (property.access != QDBusIntrospection::Property::Write) { if (property.access != QDBusIntrospection::Property::Write) {
hs << " " << type << " " << getter << "() const;" << Qt::endl; hs << " " << type << " " << getter << "() const;\n";
cs << type << " " cs << type << " "
<< className << "::" << getter << "() const" << Qt::endl << className << "::" << getter << "() const\n"
<< "{" << Qt::endl << "{\n"
<< " // get the value of property " << property.name << Qt::endl << " // get the value of property " << property.name << "\n"
<< " return qvariant_cast< " << type <<" >(parent()->property(\"" << property.name << "\"));" << Qt::endl << " return qvariant_cast< " << type <<" >(parent()->property(\"" << property.name << "\"));\n"
<< "}" << Qt::endl << "}\n\n";
<< Qt::endl;
} }
// setter // setter
if (property.access != QDBusIntrospection::Property::Read) { if (property.access != QDBusIntrospection::Property::Read) {
hs << " void " << setter << "(" << constRefType << "value);" << Qt::endl; hs << " void " << setter << "(" << constRefType << "value);\n";
cs << "void " << className << "::" << setter << "(" << constRefType << "value)" << Qt::endl cs << "void " << className << "::" << setter << "(" << constRefType << "value)\n"
<< "{" << Qt::endl << "{\n"
<< " // set the value of property " << property.name << Qt::endl << " // set the value of property " << property.name << "\n"
<< " parent()->setProperty(\"" << property.name << "\", QVariant::fromValue(value"; << " parent()->setProperty(\"" << property.name << "\", QVariant::fromValue(value";
if (constRefType.contains("QDBusVariant"_L1)) if (constRefType.contains("QDBusVariant"_L1))
cs << ".variant()"; cs << ".variant()";
cs << "));" << Qt::endl cs << "));\n"
<< "}" << Qt::endl << "}\n\n";
<< Qt::endl;
} }
hs << Qt::endl; hs << "\n";
} }
hs << "public Q_SLOTS: // METHODS" << Qt::endl; hs << "public Q_SLOTS: // METHODS\n";
for (const QDBusIntrospection::Method &method : interface->methods) { for (const QDBusIntrospection::Method &method : interface->methods) {
bool isNoReply = bool isNoReply =
method.annotations.value(ANNOTATION_NO_WAIT ""_L1) == "true"_L1; method.annotations.value(ANNOTATION_NO_WAIT ""_L1) == "true"_L1;
@ -969,10 +952,10 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
writeArgList(hs, argNames, method.annotations, method.inputArgs, method.outputArgs); writeArgList(hs, argNames, method.annotations, method.inputArgs, method.outputArgs);
writeArgList(cs, argNames, method.annotations, method.inputArgs, method.outputArgs); writeArgList(cs, argNames, method.annotations, method.inputArgs, method.outputArgs);
hs << ");" << Qt::endl; // finished for header hs << ");\n"; // finished for header
cs << ")" << Qt::endl cs << ")\n"
<< "{" << Qt::endl << "{\n"
<< " // handle method call " << interface->name << "." << methodName(method) << Qt::endl; << " // handle method call " << interface->name << "." << methodName(method) << "\n";
// make the call // make the call
bool usingInvokeMethod = false; bool usingInvokeMethod = false;
@ -984,7 +967,7 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
// we are using QMetaObject::invokeMethod // we are using QMetaObject::invokeMethod
if (!returnType.isEmpty()) if (!returnType.isEmpty())
cs << " " << returnType << " " << argNames.at(method.inputArgs.size()) cs << " " << returnType << " " << argNames.at(method.inputArgs.size())
<< ";" << Qt::endl; << ";\n";
static const char invoke[] = " QMetaObject::invokeMethod(parent(), \""; static const char invoke[] = " QMetaObject::invokeMethod(parent(), \"";
cs << invoke << name << "\""; cs << invoke << name << "\"";
@ -1001,10 +984,10 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
i, "In") i, "In")
<< ", " << argNames.at(i) << ")"; << ", " << argNames.at(i) << ")";
cs << ");" << Qt::endl; cs << ");\n";
if (!returnType.isEmpty()) if (!returnType.isEmpty())
cs << " return " << argNames.at(method.inputArgs.size()) << ";" << Qt::endl; cs << " return " << argNames.at(method.inputArgs.size()) << ";\n";
} else { } else {
if (parentClassName.isEmpty()) if (parentClassName.isEmpty())
cs << " //"; cs << " //";
@ -1032,34 +1015,32 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
first = false; first = false;
} }
cs << ");" << Qt::endl; cs << ");\n";
} }
cs << "}" << Qt::endl cs << "}\n\n";
<< Qt::endl;
} }
hs << "Q_SIGNALS: // SIGNALS" << Qt::endl; hs << "Q_SIGNALS: // SIGNALS\n";
for (const QDBusIntrospection::Signal &signal : interface->signals_) { for (const QDBusIntrospection::Signal &signal : interface->signals_) {
hs << " void " << signal.name << "("; hs << " void " << signal.name << "(";
QStringList argNames = makeArgNames(signal.outputArgs); QStringList argNames = makeArgNames(signal.outputArgs);
writeSignalArgList(hs, argNames, signal.annotations, signal.outputArgs); writeSignalArgList(hs, argNames, signal.annotations, signal.outputArgs);
hs << ");" << Qt::endl; // finished for header hs << ");\n"; // finished for header
} }
// close the class: // close the class:
hs << "};" << Qt::endl hs << "};\n\n";
<< Qt::endl;
} }
// close the include guard // close the include guard
hs << "#endif" << Qt::endl; hs << "#endif\n";
QString mocName = moc(filename); QString mocName = moc(filename);
if (includeMocs && !mocName.isEmpty()) if (includeMocs && !mocName.isEmpty())
cs << Qt::endl cs << "\n"
<< "#include \"" << mocName << "\"" << Qt::endl; << "#include \"" << mocName << "\"\n";
cs.flush(); cs.flush();
hs.flush(); hs.flush();