diff options
author | Martin Smith <martin.smith@digia.com> | 2015-08-06 13:47:44 +0200 |
---|---|---|
committer | Martin Smith <martin.smith@digia.com> | 2015-08-16 14:47:58 +0000 |
commit | 8c5ce68fcf09d128072c31d74878fcb0fd9b9c7a (patch) | |
tree | 7f548c676454ee99f6220e06f033a2a71f1b3af9 /src/tools/qdoc/qdocdatabase.cpp | |
parent | 6dde874c3203464f76170834234c026e02dc7abc (diff) |
qdoc: Allow formal parameters in link targets
This update allows qdoc to handle \l commands for linking
to functions, where the formal parameters are included in
the link target.
For example, \l {QWidget::find(QString name)} will only match
a member function of QWidget that has a single parameter of type
QString. The parameter name is not used in the search.
Change-Id: I8a31c9a7ed632f12a0e6d8a33cbb5cd361098317
Task-number: QTBUG-47286
Reviewed-by: Martin Smith <martin.smith@digia.com>
Diffstat (limited to 'src/tools/qdoc/qdocdatabase.cpp')
-rw-r--r-- | src/tools/qdoc/qdocdatabase.cpp | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/src/tools/qdoc/qdocdatabase.cpp b/src/tools/qdoc/qdocdatabase.cpp index 5f2a61bb76..7f2e64b00c 100644 --- a/src/tools/qdoc/qdocdatabase.cpp +++ b/src/tools/qdoc/qdocdatabase.cpp @@ -380,6 +380,30 @@ QString QDocForest::getLinkCounts(QStringList& strings, QVector<int>& counts) return depends; } +/*! + */ +const Node* QDocForest::findFunctionNode(const QString& target, + const Node* relative, + Node::Genus genus) +{ + QString function, params; + int length = target.length(); + if (target.endsWith(QChar(')'))) { + int position = target.lastIndexOf(QChar('(')); + params = target.mid(position+1, length-position-2); + function = target.left(position); + } + else + function = target; + foreach (Tree* t, searchOrder()) { + const Node* n = t->findFunctionNode(function, params, relative, genus); + if (n) + return n; + relative = 0; + } + return 0; +} + /*! \class QDocDatabase This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a lot of maps and @@ -1342,8 +1366,16 @@ void QDocDatabase::resolveNamespaces() } } } - - +#if 0 +/*! + */ +const Node* QDocDatabase::findFunctionNode(const QString& target, + const Node* relative, + Node::Genus genus) +{ + return forest_.findFunctionNode(target, relative, genus); +} +#endif /*! This function is called for autolinking to a \a type, which could be a function return type or a parameter @@ -1641,6 +1673,8 @@ const Node* QDocDatabase::findNodeForAtom(const Atom* a, const Node* relative, Q Atom* atom = const_cast<Atom*>(a); QStringList targetPath = atom->string().split("#"); QString first = targetPath.first().trimmed(); + if (Generator::debugging()) + qDebug() << " first:" << first; Tree* domain = 0; Node::Genus genus = Node::DontCare; @@ -1659,8 +1693,14 @@ const Node* QDocDatabase::findNodeForAtom(const Atom* a, const Node* relative, Q else if (domain) { if (first.endsWith(".html")) node = domain->findNodeByNameAndType(QStringList(first), Node::Document); - else if (first.endsWith("()")) - node = domain->findFunctionNode(first, 0, genus); + else if (first.endsWith(QChar(')'))) { + QString function, params; + int length = first.length(); + int position = first.lastIndexOf(QChar('(')); + params = first.mid(position+1, length-position-2); + function = first.left(position); + node = domain->findFunctionNode(function, params, 0, genus); + } else { int flags = SearchBaseClasses | SearchEnumValues; QStringList nodePath = first.split("::"); @@ -1683,8 +1723,11 @@ const Node* QDocDatabase::findNodeForAtom(const Atom* a, const Node* relative, Q if (!node && first.contains("/")) return findNodeForTarget(targetPath, relative, genus, ref); } - else if (first.endsWith("()")) + else if (first.endsWith(QChar(')'))) { node = findFunctionNode(first, relative, genus); + if (Generator::debugging()) + qDebug() << " node:" << node; + } else { node = findNodeForTarget(targetPath, relative, genus, ref); return node; |