diff options
author | Topi Reinio <topi.reinio@qt.io> | 2021-03-18 16:39:30 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-03-19 12:03:02 +0000 |
commit | b554c4db5c672108448f072ba210783f2bc378b5 (patch) | |
tree | 8994c7f1b86f3196eadfc203ee8dc7b1cd684999 | |
parent | 3394f0b9e57a0dfc39f019ee9325706094ba1e79 (diff) |
qdoc: Correctly handle const property types
The property type defined in Q_PROPERTY may contain the const
qualifier. Store the qualifier and make the code a bit more
robust against ill-formatted property declarations.
Fixes: QTBUG-91990
Change-Id: I6b06e4c8af8bb9dec3c467c6e19d9987b8340110
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
(cherry picked from commit 526604ea5705ba9c61161da98dafda93cafc5fba)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
8 files changed, 71 insertions, 14 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index 3bc36f220..866b8119d 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -974,14 +974,22 @@ bool ClangVisitor::parseProperty(const QString &spelling, const Location &loc) QString signature = spelling.mid(lpIdx + 1, rpIdx - lpIdx - 1); signature = signature.simplified(); - QStringList part; - part = signature.split(QChar(' ')); - if (part.first() == QLatin1String("enum")) - part.takeFirst(); // QTBUG-80027 - if (part.size() < 2) + QString type; + QString name; + QStringList parts = signature.split(QChar(' '), Qt::SkipEmptyParts); + if (parts.size() < 2) + return false; + if (parts.first() == QLatin1String("enum")) + parts.removeFirst(); // QTBUG-80027 + + type = parts.takeFirst(); + if (type == QLatin1String("const") && parts.size() > 0) + type += " " + parts.takeFirst(); + + if (parts.size() > 0) + name = parts.takeFirst(); + else return false; - QString type = part.at(0); - QString name = part.at(1); if (name.front() == QChar('*')) { type.append(QChar('*')); @@ -992,9 +1000,9 @@ bool ClangVisitor::parseProperty(const QString &spelling, const Location &loc) property->setLocation(loc); property->setDataType(type); - int i = 2; - while (i < part.size()) { - QString key = part.at(i++); + int i = 0; + while (i < parts.size()) { + const QString &key = parts.at(i++); // Keywords with no associated values if (key == "CONSTANT") { property->setConstant(); @@ -1003,8 +1011,8 @@ bool ClangVisitor::parseProperty(const QString &spelling, const Location &loc) } else if (key == "REQUIRED") { property->setRequired(); } - if (i < part.size()) { - QString value = part.at(i++); + if (i < parts.size()) { + QString value = parts.at(i++); if (key == "READ") { qdb_->addPropertyFunction(property, value, PropertyNode::Getter); } else if (key == "WRITE") { diff --git a/src/qdoc/propertynode.cpp b/src/qdoc/propertynode.cpp index 77a7e249d..aaa0aeb41 100644 --- a/src/qdoc/propertynode.cpp +++ b/src/qdoc/propertynode.cpp @@ -83,7 +83,7 @@ void PropertyNode::setOverriddenFrom(const PropertyNode *baseProperty) */ QString PropertyNode::qualifiedDataType() const { - if (m_propertyType != Standard) + if (m_propertyType != Standard || m_type.startsWith(QLatin1String("const "))) return m_type; if (setters().isEmpty() && resetters().isEmpty()) { diff --git a/tests/auto/qdoc/generatedoutput/expected_output/properties-docbook/testqdoc-testderived.xml b/tests/auto/qdoc/generatedoutput/expected_output/properties-docbook/testqdoc-testderived.xml index b38e08f5e..a292a981a 100644 --- a/tests/auto/qdoc/generatedoutput/expected_output/properties-docbook/testqdoc-testderived.xml +++ b/tests/auto/qdoc/generatedoutput/expected_output/properties-docbook/testqdoc-testderived.xml @@ -145,6 +145,29 @@ </db:listitem> </db:itemizedlist> </db:section> +<db:section xml:id="name-prop"> +<db:title>[read-only] name : const QString*</db:title> +<db:fieldsynopsis> +<db:modifier>(Qt property)</db:modifier> +<db:type>const QString*</db:type> +<db:varname>name</db:varname> +<db:synopsisinfo db:role="access">public</db:synopsisinfo> +<db:synopsisinfo db:role="status">active</db:synopsisinfo> +<db:synopsisinfo db:role="threadsafeness">unspecified</db:synopsisinfo> +<db:synopsisinfo db:role="module">TestCPP</db:synopsisinfo> +<db:synopsisinfo db:role="getter">name</db:synopsisinfo> +</db:fieldsynopsis> +<db:para>This property holds a name.</db:para> +<db:para> +<db:emphasis role="bold">Access functions: +</db:emphasis> +</db:para> +<db:itemizedlist> +<db:listitem> +<db:para>const <db:type>QString</db:type> *<db:emphasis role="bold"><db:link xlink:href="">name</db:link></db:emphasis>() const</db:para> +</db:listitem> +</db:itemizedlist> +</db:section> <db:section xml:id="someProp-prop"> <db:title>[bindable read-only] someProp : QString</db:title> <db:fieldsynopsis> diff --git a/tests/auto/qdoc/generatedoutput/expected_output/properties/testcpp.index b/tests/auto/qdoc/generatedoutput/expected_output/properties/testcpp.index index ea9022fa3..b08864064 100644 --- a/tests/auto/qdoc/generatedoutput/expected_output/properties/testcpp.index +++ b/tests/auto/qdoc/generatedoutput/expected_output/properties/testcpp.index @@ -55,6 +55,7 @@ <function name="boolPropChanged" fullname="TestQDoc::TestDerived::boolPropChanged" href="testqdoc-testderived.html#boolProp-prop" status="active" access="public" location="testcpp.h" meta="signal" virtual="non" const="false" static="false" final="false" override="false" associated-property="boolProp" type="void" signature="void boolPropChanged()"/> <function name="emitSomething" fullname="TestQDoc::TestDerived::emitSomething" href="testqdoc-testderived.html#emitSomething" status="active" access="public" location="testcpp.h" documented="true" meta="signal" virtual="non" const="false" static="false" final="false" override="false" type="void" signature="void emitSomething()"/> <function name="getInt" fullname="TestQDoc::TestDerived::getInt" href="testqdoc-testderived.html#intProp-prop" status="active" access="public" location="testcpp.h" meta="plain" virtual="non" const="false" static="false" final="false" override="false" associated-property="intProp" type="int *" signature="int * getInt()"/> + <function name="name" fullname="TestQDoc::TestDerived::name" href="testqdoc-testderived.html#name-prop" status="active" access="public" location="testcpp.h" meta="plain" virtual="non" const="true" static="false" final="false" override="false" associated-property="name" type="const QString *" signature="const QString * name() const"/> <function name="resetBoolProp" fullname="TestQDoc::TestDerived::resetBoolProp" href="testqdoc-testderived.html#boolProp-prop" status="active" access="public" location="testcpp.h" meta="slot" virtual="non" const="false" static="false" final="false" override="false" associated-property="boolProp" type="void" signature="void resetBoolProp()"/> <function name="setBindableProp" fullname="TestQDoc::TestDerived::setBindableProp" href="testqdoc-testderived.html#bindableProp-prop" status="active" access="public" location="testcpp.h" meta="slot" virtual="non" const="false" static="false" final="false" override="false" associated-property="bindableProp" type="void" signature="void setBindableProp(const QString &s)"> <parameter type="const QString &" name="s" default=""/> @@ -81,6 +82,9 @@ <property name="intProp" fullname="TestQDoc::TestDerived::intProp" href="testqdoc-testderived.html#intProp-prop" status="active" access="public" location="testcpp.h" documented="true"> <getter name="getInt"/> </property> + <property name="name" fullname="TestQDoc::TestDerived::name" href="testqdoc-testderived.html#name-prop" status="active" access="public" location="testcpp.h" documented="true" brief="This property holds a name"> + <getter name="name"/> + </property> <property name="someProp" fullname="TestQDoc::TestDerived::someProp" href="testqdoc-testderived.html#someProp-prop" status="active" access="public" location="testcpp.h" documented="true" bindable="true"> <getter name="someProp"/> </property> diff --git a/tests/auto/qdoc/generatedoutput/expected_output/properties/testqdoc-testderived-members.html b/tests/auto/qdoc/generatedoutput/expected_output/properties/testqdoc-testderived-members.html index 7e4dde4c5..b3284d993 100644 --- a/tests/auto/qdoc/generatedoutput/expected_output/properties/testqdoc-testderived-members.html +++ b/tests/auto/qdoc/generatedoutput/expected_output/properties/testqdoc-testderived-members.html @@ -28,6 +28,7 @@ <li class="fn"><span class="name"><b><a href="testqdoc-test.html#funcPtr">funcPtr</a></b></span>(bool, const char *) : void (*)(bool)</li> <li class="fn"><span class="name"><b><a href="testqdoc-testderived.html#intProp-prop">getInt</a></b></span>() : int *</li> <li class="fn"><span class="name"><b><a href="testqdoc-test.html#inlineFunction">inlineFunction</a></b></span>()</li> +<li class="fn"><span class="name"><b><a href="testqdoc-testderived.html#name-prop">name</a></b></span>() const : const QString *</li> <li class="fn"><span class="name"><b><a href="testqdoc-test.html#overload">overload</a></b></span>()</li> <li class="fn"><span class="name"><b><a href="testqdoc-test.html#overload-1">overload</a></b></span>(bool)</li> <li class="fn"><span class="name"><b><a href="testqdoc-test.html#someFunction">someFunction</a></b></span>(int, int) : int</li> diff --git a/tests/auto/qdoc/generatedoutput/expected_output/properties/testqdoc-testderived.html b/tests/auto/qdoc/generatedoutput/expected_output/properties/testqdoc-testderived.html index f0f43e32a..33c605df9 100644 --- a/tests/auto/qdoc/generatedoutput/expected_output/properties/testqdoc-testderived.html +++ b/tests/auto/qdoc/generatedoutput/expected_output/properties/testqdoc-testderived.html @@ -41,18 +41,24 @@ target_link_libraries(mytarget PRIVATE Qt6::QDocTest)</td></tr><tr><td class="me </table></div> <a name="properties"></a> <h2 id="properties">Properties</h2> -<ul> +<div class="table"><table class="propsummary"> +<tr><td class="topAlign"><ul> <li class="fn"><b><a href="testqdoc-testderived.html#bindableProp-prop">bindableProp</a></b> : QString</li> <li class="fn"><b><a href="testqdoc-testderived.html#boolProp-prop">boolProp</a></b> : bool</li> <li class="fn"><b><a href="testqdoc-testderived.html#intProp-prop">intProp</a></b> : int* const</li> +</ul></td><td class="topAlign"><ul> +<li class="fn"><b><a href="testqdoc-testderived.html#name-prop">name</a></b> : const QString*</li> <li class="fn"><b><a href="testqdoc-testderived.html#someProp-prop">someProp</a></b> : QString</li> </ul> +</td></tr> +</table></div> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> QBindable<QString> </td><td class="memItemRight bottomAlign"><b><a href="testqdoc-testderived.html#bindableProp-prop">bindableProp</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="testqdoc-testderived.html#boolProp-prop">boolProp</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int *</td><td class="memItemRight bottomAlign"><b><a href="testqdoc-testderived.html#intProp-prop">getInt</a></b>()</td></tr> +<tr><td class="memItemLeft rightAlign topAlign"> const QString *</td><td class="memItemRight bottomAlign"><b><a href="testqdoc-testderived.html#name-prop">name</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const QString &</td><td class="memItemRight bottomAlign"><b><a href="testqdoc-testderived.html#someProp-prop">someProp</a></b>()</td></tr> </table></div> <a name="reimplemented-public-functions"></a> @@ -120,6 +126,14 @@ target_link_libraries(mytarget PRIVATE Qt6::QDocTest)</td></tr><tr><td class="me <tr><td class="memItemLeft topAlign rightAlign"> int *</td><td class="memItemRight bottomAlign"><span class="name"><b>getInt</b></span>()</td></tr> </table></div> <!-- @@@intProp --> +<!-- $$$name-prop$$$name --> +<h3 class="fn" id="name-prop"><a name="name-prop"></a><code>[read-only] </code><span class="name">name</span> : const <span class="type">QString</span>*</h3> +<p>This property holds a name.</p> +<p><b>Access functions:</b></p> +<div class="table"><table class="alignedsummary"> +<tr><td class="memItemLeft topAlign rightAlign"> const QString *</td><td class="memItemRight bottomAlign"><span class="name"><b>name</b></span>() const</td></tr> +</table></div> +<!-- @@@name --> <!-- $$$someProp-prop$$$someProp --> <h3 class="fn" id="someProp-prop"><a name="someProp-prop"></a><code>[bindable read-only] </code><span class="name">someProp</span> : <span class="type">QString</span></h3> <p><b>Note: </b>This property supports <a href="https://wiki.qt.io/QProperty">QProperty</a> bindings.</p> diff --git a/tests/auto/qdoc/generatedoutput/testdata/testcpp/properties.qdoc b/tests/auto/qdoc/generatedoutput/testdata/testcpp/properties.qdoc index a7ebd3960..d225636a7 100644 --- a/tests/auto/qdoc/generatedoutput/testdata/testcpp/properties.qdoc +++ b/tests/auto/qdoc/generatedoutput/testdata/testcpp/properties.qdoc @@ -37,6 +37,11 @@ */ /*! + \property TestQDoc::TestDerived::name + \brief a name. +*/ + +/*! \property TestQDoc::TestDerived::intProp An integer property. */ diff --git a/tests/auto/qdoc/generatedoutput/testdata/testcpp/testcpp.h b/tests/auto/qdoc/generatedoutput/testdata/testcpp/testcpp.h index 800858ca0..8a8ad1c7a 100644 --- a/tests/auto/qdoc/generatedoutput/testdata/testcpp/testcpp.h +++ b/tests/auto/qdoc/generatedoutput/testdata/testcpp/testcpp.h @@ -90,6 +90,7 @@ class TestDerived : public Test { Q_PROPERTY(QString bindableProp READ bindableProp WRITE setBindableProp NOTIFY bindablePropChanged BINDABLE bindableProp) Q_PROPERTY(QString someProp READ someProp BINDABLE somBindableProp) Q_PROPERTY(int *intProp READ getInt STORED false CONSTANT FINAL) + Q_PROPERTY(const QString *name READ name) QDOC_PROPERTY(bool boolProp READ boolProp WRITE setBoolProp NOTIFY boolPropChanged RESET resetBoolProp REVISION 1) #endif @@ -104,6 +105,7 @@ public: const QString &someProp(); int *getInt(); bool boolProp(); + const QString *name() const; Q_SIGNALS: void emitSomething(QPrivateSignal); |