summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@qt.io>2020-07-27 13:39:36 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-08-07 12:52:26 +0000
commitd3410daf9d498a857597ef46ff6c50cce478518a (patch)
treec8d7d8bbeb4cee48d2a0f25086d9f91aa1caa3d9
parent4588e08b95f2c50dcdd9f7ab78062752afa0138b (diff)
qdoc: Correctly handle default values for \qmlmethod parameters
The QML parser in QDoc was already able to parse default parameter values listed for \qmlmethod in a .qml file, but they were not handled when the command appeared in a .cpp or .qdoc file as a different code path is used for those. Fixes: QTBUG-85756 Change-Id: I671a19b66f82e1a6cd81b8bb487dffa2133ee65d Reviewed-by: Paul Wicking <paul.wicking@qt.io> (cherry picked from commit 98cca5ff823fe2d4e41f45173e0675bcdf9e2542) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qdoc/parameters.cpp11
-rw-r--r--src/qdoc/parameters.h9
-rw-r--r--tests/auto/qdoc/generatedoutput/expected_output/docbook/qml-qdoc-test-abstractparent.xml2
-rw-r--r--tests/auto/qdoc/generatedoutput/expected_output/docbook/qml-qdoc-test-child.xml2
-rw-r--r--tests/auto/qdoc/generatedoutput/expected_output/qml-qdoc-test-abstractparent.html4
-rw-r--r--tests/auto/qdoc/generatedoutput/expected_output/qml-qdoc-test-child.html4
-rw-r--r--tests/auto/qdoc/generatedoutput/testdata/qml/parent.qdoc2
7 files changed, 17 insertions, 17 deletions
diff --git a/src/qdoc/parameters.cpp b/src/qdoc/parameters.cpp
index 736f50483..3d5effeef 100644
--- a/src/qdoc/parameters.cpp
+++ b/src/qdoc/parameters.cpp
@@ -469,12 +469,19 @@ void Parameters::set(const QString &signature)
parameters_.resize(commaSplit.size());
int i = 0;
for (const auto &item : qAsConst(commaSplit)) {
- QStringList blankSplit = item.split(' ');
+ QStringList blankSplit = item.split(' ', Qt::SkipEmptyParts);
+ QString pDefault;
+ int defaultIdx = blankSplit.indexOf(QStringLiteral("="));
+ if (defaultIdx != -1) {
+ if (++defaultIdx < blankSplit.size())
+ pDefault = blankSplit.mid(defaultIdx).join(' ');
+ blankSplit = blankSplit.mid(0, defaultIdx - 1);
+ }
QString pName = blankSplit.takeLast();
QString pType = blankSplit.join(' ');
if (pType.isEmpty() && pName == QLatin1String("..."))
qSwap(pType, pName);
- parameters_[i++].set(pType, pName);
+ parameters_[i++].set(pType, pName, pDefault);
}
}
}
diff --git a/src/qdoc/parameters.h b/src/qdoc/parameters.h
index e049fed51..f0ead7691 100644
--- a/src/qdoc/parameters.h
+++ b/src/qdoc/parameters.h
@@ -56,14 +56,7 @@ public:
const QString &defaultValue() const { return defaultValue_; }
void setDefaultValue(const QString &t) { defaultValue_ = t; }
- void set(const QString &type, const QString &name)
- {
- type_ = type;
- name_ = name;
- defaultValue_.clear();
- }
-
- void set(const QString &type, const QString &name, const QString &defaultValue)
+ void set(const QString &type, const QString &name, const QString &defaultValue = QString())
{
type_ = type;
name_ = name;
diff --git a/tests/auto/qdoc/generatedoutput/expected_output/docbook/qml-qdoc-test-abstractparent.xml b/tests/auto/qdoc/generatedoutput/expected_output/docbook/qml-qdoc-test-abstractparent.xml
index 479b70685..ceac4f33f 100644
--- a/tests/auto/qdoc/generatedoutput/expected_output/docbook/qml-qdoc-test-abstractparent.xml
+++ b/tests/auto/qdoc/generatedoutput/expected_output/docbook/qml-qdoc-test-abstractparent.xml
@@ -46,7 +46,7 @@
<db:section xml:id="method-documentation">
<db:title>Method Documentation</db:title>
<db:section xml:id="rear-method">
-<db:title>void rear(Child <db:emphasis>child</db:emphasis>, var <db:emphasis>method</db:emphasis>)</db:title>
+<db:title>void rear(Child <db:emphasis>child</db:emphasis>, var <db:emphasis>method</db:emphasis> = Strict)</db:title>
<db:para>Do some abstract parenting on <db:code role="parameter">child</db:code> using a specific <db:code role="parameter">method</db:code>.</db:para>
</db:section>
</db:section>
diff --git a/tests/auto/qdoc/generatedoutput/expected_output/docbook/qml-qdoc-test-child.xml b/tests/auto/qdoc/generatedoutput/expected_output/docbook/qml-qdoc-test-child.xml
index 657c54d0d..21b3fbc05 100644
--- a/tests/auto/qdoc/generatedoutput/expected_output/docbook/qml-qdoc-test-child.xml
+++ b/tests/auto/qdoc/generatedoutput/expected_output/docbook/qml-qdoc-test-child.xml
@@ -46,7 +46,7 @@
<db:section xml:id="method-documentation">
<db:title>Method Documentation</db:title>
<db:section xml:id="rear-method">
-<db:title>void rear(Child <db:emphasis>child</db:emphasis>, var <db:emphasis>method</db:emphasis>)</db:title>
+<db:title>void rear(Child <db:emphasis>child</db:emphasis>, var <db:emphasis>method</db:emphasis> = Strict)</db:title>
<db:para>Do some abstract parenting on <db:code role="parameter">child</db:code> using a specific <db:code role="parameter">method</db:code>.</db:para>
</db:section>
</db:section>
diff --git a/tests/auto/qdoc/generatedoutput/expected_output/qml-qdoc-test-abstractparent.html b/tests/auto/qdoc/generatedoutput/expected_output/qml-qdoc-test-abstractparent.html
index 04fde634b..96d573abc 100644
--- a/tests/auto/qdoc/generatedoutput/expected_output/qml-qdoc-test-abstractparent.html
+++ b/tests/auto/qdoc/generatedoutput/expected_output/qml-qdoc-test-abstractparent.html
@@ -34,7 +34,7 @@
<a name="methods"></a>
<h2 id="methods">Methods</h2>
<ul>
-<li class="fn">void <b><b><a href="qml-qdoc-test-abstractparent.html#rear-method">rear</a></b></b>(Child <i>child</i>, var <i>method</i>)</li>
+<li class="fn">void <b><b><a href="qml-qdoc-test-abstractparent.html#rear-method">rear</a></b></b>(Child <i>child</i>, var <i>method</i>)</li>
</ul>
<!-- $$$AbstractParent-description -->
<a name="details"></a>
@@ -57,7 +57,7 @@
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="rear-method">
<td class="tblQmlFuncNode"><p>
-<a name="rear-method"></a><span class="type">void</span> <span class="name">rear</span>(<span class="type"><a href="qml-qdoc-test-child.html">Child</a></span> <i>child</i>, <span class="type">var</span> <i>method</i>)</p></td></tr>
+<a name="rear-method"></a><span class="type">void</span> <span class="name">rear</span>(<span class="type"><a href="qml-qdoc-test-child.html">Child</a></span> <i>child</i>, <span class="type">var</span> <i>method</i> = Strict)</p></td></tr>
</table></div></div>
<div class="qmldoc"><p>Do some abstract parenting on <i>child</i> using a specific <i>method</i>.</p>
</div></div><!-- @@@rear -->
diff --git a/tests/auto/qdoc/generatedoutput/expected_output/qml-qdoc-test-child.html b/tests/auto/qdoc/generatedoutput/expected_output/qml-qdoc-test-child.html
index c21e6e4e8..f5ba33fd1 100644
--- a/tests/auto/qdoc/generatedoutput/expected_output/qml-qdoc-test-child.html
+++ b/tests/auto/qdoc/generatedoutput/expected_output/qml-qdoc-test-child.html
@@ -34,7 +34,7 @@
<a name="methods"></a>
<h2 id="methods">Methods</h2>
<ul>
-<li class="fn">void <b><b><a href="qml-qdoc-test-child.html#rear-method">rear</a></b></b>(Child <i>child</i>, var <i>method</i>)</li>
+<li class="fn">void <b><b><a href="qml-qdoc-test-child.html#rear-method">rear</a></b></b>(Child <i>child</i>, var <i>method</i>)</li>
</ul>
<!-- $$$Child-description -->
<a name="details"></a>
@@ -57,7 +57,7 @@
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="rear-method">
<td class="tblQmlFuncNode"><p>
-<a name="rear-method"></a><span class="type">void</span> <span class="name">rear</span>(<span class="type"><a href="qml-qdoc-test-child.html">Child</a></span> <i>child</i>, <span class="type">var</span> <i>method</i>)</p></td></tr>
+<a name="rear-method"></a><span class="type">void</span> <span class="name">rear</span>(<span class="type"><a href="qml-qdoc-test-child.html">Child</a></span> <i>child</i>, <span class="type">var</span> <i>method</i> = Strict)</p></td></tr>
</table></div></div>
<div class="qmldoc"><p>Do some abstract parenting on <i>child</i> using a specific <i>method</i>.</p>
</div></div><!-- @@@rear -->
diff --git a/tests/auto/qdoc/generatedoutput/testdata/qml/parent.qdoc b/tests/auto/qdoc/generatedoutput/testdata/qml/parent.qdoc
index a2842f0d6..5bcdbb31d 100644
--- a/tests/auto/qdoc/generatedoutput/testdata/qml/parent.qdoc
+++ b/tests/auto/qdoc/generatedoutput/testdata/qml/parent.qdoc
@@ -40,7 +40,7 @@
*/
/*!
- \qmlmethod void AbstractParent::rear(Child child, var method)
+ \qmlmethod void AbstractParent::rear(Child child, var method = Strict)
\brief Do some abstract parenting on \a child using a specific \a method.
*/