diff options
author | Luca Di Sera <luca.disera@qt.io> | 2022-05-11 14:56:07 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-05-18 07:06:38 +0000 |
commit | ceddeb22b667063b42812c7b6691f1d33b7afe2c (patch) | |
tree | a1d3a5f4a3158b3720ee81d7d20a320da9fac145 | |
parent | 93f75f5ca6d70d359cf17ae063ab8f0466bcabc9 (diff) |
QDoc: Save QML methods return type/parameters in index files
QDoc saves information about the elements of a specific documentation
project inside an xml-formatted index file that are later used by
dependent projects to provide information about or linking to elements
of the dependent upon project.
Previously, QDoc would save basic information about QML methods but
would not save any information about the return type or
parameters of the same.
This generated some discrepancies between the information available to
the project that contains those elements and the one provided by
projects that depends on those elements.
For example, it was impossible for `\sincelist` commands in `qtdoc` to
show return type information for QML methods in `qtquick3d`.
To avoid those discrepancies, the return type and parameters information
for QML methods, or more generally non CPP nodes, are now saved in the
index files.
The changes to the code specifically tried to preserve the format and
ordering of internal parameters for the index files as much as possible,
albeit this might sligthly impact the readability of the code.
As a side effect of the change some of the all-members pages for QML
related classes now show the full information for their members, making
them consistent with the all members pages for CPP classes.
Fixes: QTBUG-103368
Change-Id: I664d7c4cb4df1e11372b11ae3537068c0c6fa9db
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
(cherry picked from commit f0f9c1d99a360ead849ab2c199c9801b80fff6a9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qdoc/qdocindexfiles.cpp | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/src/qdoc/qdocindexfiles.cpp b/src/qdoc/qdocindexfiles.cpp index 3ff4ecb8c..a347d01bc 100644 --- a/src/qdoc/qdocindexfiles.cpp +++ b/src/qdoc/qdocindexfiles.cpp @@ -506,8 +506,10 @@ void QDocIndexFiles::readIndexSection(QXmlStreamReader &reader, Node *current, if (attributes.value(QLatin1String("attached")) == QLatin1String("true")) attached = true; auto *fn = new FunctionNode(metaness, parent, name, attached); + + fn->setReturnType(attributes.value(QLatin1String("type")).toString()); + if (fn->isCppNode()) { - fn->setReturnType(attributes.value(QLatin1String("type")).toString()); fn->setVirtualness(attributes.value(QLatin1String("virtual")).toString()); fn->setConst(attributes.value(QLatin1String("const")) == QLatin1String("true")); fn->setStatic(attributes.value(QLatin1String("static")) == QLatin1String("true")); @@ -528,28 +530,29 @@ void QDocIndexFiles::readIndexSection(QXmlStreamReader &reader, Node *current, fn->setOverloadNumber(attributes.value(QLatin1String("overload-number")).toUInt()); else fn->setOverloadNumber(0); - /* - Note: The "signature" attribute was written to the - index file, but it is not read back in. That is ok - because we reconstruct the parameter list and the - return type, from which the signature was built in - the first place and from which it can be rebuilt. - */ - while (reader.readNextStartElement()) { - QXmlStreamAttributes childAttributes = reader.attributes(); - if (reader.name() == QLatin1String("parameter")) { - // Do not use the default value for the parameter; it is not - // required, and has been known to cause problems. - QString type = childAttributes.value(QLatin1String("type")).toString(); - QString name = childAttributes.value(QLatin1String("name")).toString(); - fn->parameters().append(type, name); - } else if (reader.name() == QLatin1String("keyword")) { - insertTarget(TargetRec::Keyword, childAttributes, fn); - } else if (reader.name() == QLatin1String("target")) { - insertTarget(TargetRec::Target, childAttributes, fn); - } - reader.skipCurrentElement(); + } + + /* + Note: The "signature" attribute was written to the + index file, but it is not read back in. That is ok + because we reconstruct the parameter list and the + return type, from which the signature was built in + the first place and from which it can be rebuilt. + */ + while (reader.readNextStartElement()) { + QXmlStreamAttributes childAttributes = reader.attributes(); + if (reader.name() == QLatin1String("parameter")) { + // Do not use the default value for the parameter; it is not + // required, and has been known to cause problems. + QString type = childAttributes.value(QLatin1String("type")).toString(); + QString name = childAttributes.value(QLatin1String("name")).toString(); + fn->parameters().append(type, name); + } else if (reader.name() == QLatin1String("keyword")) { + insertTarget(TargetRec::Keyword, childAttributes, fn); + } else if (reader.name() == QLatin1String("target")) { + insertTarget(TargetRec::Target, childAttributes, fn); } + reader.skipCurrentElement(); } node = fn; @@ -1374,13 +1377,18 @@ void QDocIndexFiles::generateFunctionSection(QXmlStreamWriter &writer, FunctionN writer.writeAttribute("associated-property", associatedProperties.join(QLatin1Char(','))); } - writer.writeAttribute("type", fn->returnType()); + } + + writer.writeAttribute("type", fn->returnType()); + + if (fn->isCppNode()) { if (!brief.isEmpty()) writer.writeAttribute("brief", brief); + /* - Note: The "signature" attribute is written to the - index file, but it is not read back in by qdoc. However, - we need it for the webxml generator. + Note: The "signature" attribute is written to the + index file, but it is not read back in by qdoc. However, + we need it for the webxml generator. */ QString signature = fn->signature(false, false); // 'const' is already part of FunctionNode::signature() @@ -1395,15 +1403,15 @@ void QDocIndexFiles::generateFunctionSection(QXmlStreamWriter &writer, FunctionN QStringList groups = m_qdb->groupNamesForNode(fn); if (!groups.isEmpty()) writer.writeAttribute("groups", groups.join(QLatin1Char(','))); + } - for (int i = 0; i < fn->parameters().count(); ++i) { - const Parameter ¶meter = fn->parameters().at(i); - writer.writeStartElement("parameter"); - writer.writeAttribute("type", parameter.type()); - writer.writeAttribute("name", parameter.name()); - writer.writeAttribute("default", parameter.defaultValue()); - writer.writeEndElement(); // parameter - } + for (int i = 0; i < fn->parameters().count(); ++i) { + const Parameter ¶meter = fn->parameters().at(i); + writer.writeStartElement("parameter"); + writer.writeAttribute("type", parameter.type()); + writer.writeAttribute("name", parameter.name()); + writer.writeAttribute("default", parameter.defaultValue()); + writer.writeEndElement(); // parameter } // Append to the section if the callback object was set |