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