diff options
author | Topi Reinio <topi.reinio@qt.io> | 2017-10-26 14:53:28 +0200 |
---|---|---|
committer | Topi Reiniƶ <topi.reinio@qt.io> | 2017-10-27 14:36:53 +0000 |
commit | 45559920921336d27baf155dd67d747de3051cd6 (patch) | |
tree | 833994e2d0ccf109a6acccffbb3e821eb73e98d7 /src/qdoc | |
parent | c7a77b7d6e8b0b009364636c1011cf4551d04ac0 (diff) | |
download | qttools-45559920921336d27baf155dd67d747de3051cd6.tar.gz |
qdoc: Improve linking of QML types
QML types and QML basic types were not autolinked correctly in many
instances.
- Provide correct context (genus) for code quote commands. This
guarantees that the types resolve correctly for a \qml snippet
even if there are colliding C++ target names.
Note: we do not enforce 'CPP' genus for \code command, as
it is commonly used also with QML code.
- Similarly for examples, each .qml source file is set to have QML
genus.
- Remove QML basic types from the hard-coded map for known (C++)
types/keywords. This prevented linking to these types.
Task-number: QTBUG-62440
Change-Id: I578d8d4675e99cb4ba54171031efd8dc93040160
Reviewed-by: Martin Smith <martin.smith@qt.io>
Diffstat (limited to 'src/qdoc')
-rw-r--r-- | src/qdoc/cppcodeparser.cpp | 4 | ||||
-rw-r--r-- | src/qdoc/htmlgenerator.cpp | 14 | ||||
-rw-r--r-- | src/qdoc/htmlgenerator.h | 3 | ||||
-rw-r--r-- | src/qdoc/node.cpp | 2 | ||||
-rw-r--r-- | src/qdoc/qdocdatabase.cpp | 17 | ||||
-rw-r--r-- | src/qdoc/qdocdatabase.h | 7 |
6 files changed, 23 insertions, 24 deletions
diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp index 7298d1ec2..29e1c0fe6 100644 --- a/src/qdoc/cppcodeparser.cpp +++ b/src/qdoc/cppcodeparser.cpp @@ -2678,10 +2678,12 @@ void CppCodeParser::createExampleFileNodes(DocumentNode *dn) } foreach (const QString &exampleFile, exampleFiles) { - new DocumentNode(dn, + DocumentNode *fileNode = new DocumentNode(dn, exampleFile.mid(sizeOfBoringPartOfName), Node::File, Node::NoPageType); + if (fileNode->name().endsWith(".qml")) + fileNode->setGenus(Node::QML); } foreach (const QString &imageFile, imageFiles) { new DocumentNode(dn, diff --git a/src/qdoc/htmlgenerator.cpp b/src/qdoc/htmlgenerator.cpp index 82fcf0ffc..aa7943287 100644 --- a/src/qdoc/htmlgenerator.cpp +++ b/src/qdoc/htmlgenerator.cpp @@ -579,12 +579,12 @@ int HtmlGenerator::generateAtom(const Atom *atom, const Node *relative, CodeMark break; case Atom::Qml: out() << "<pre class=\"qml\">" - << trimmedTrailing(highlightedCode(indent(codeIndent,atom->string()),relative), codePrefix, codeSuffix) + << trimmedTrailing(highlightedCode(indent(codeIndent,atom->string()),relative, false, Node::QML), codePrefix, codeSuffix) << "</pre>\n"; break; case Atom::JavaScript: out() << "<pre class=\"js\">" - << trimmedTrailing(highlightedCode(indent(codeIndent,atom->string()),relative), codePrefix, codeSuffix) + << trimmedTrailing(highlightedCode(indent(codeIndent,atom->string()),relative, false, Node::JS), codePrefix, codeSuffix) << "</pre>\n"; break; case Atom::CodeNew: @@ -3244,7 +3244,7 @@ void HtmlGenerator::generateQmlItem(const Node *node, marked.remove("<@type>"); marked.remove("</@type>"); } - out() << highlightedCode(marked, relative, false); + out() << highlightedCode(marked, relative, false, Node::QML); } void HtmlGenerator::generateList(const Node* relative, CodeMarker* marker, const QString& selector) @@ -3498,7 +3498,7 @@ void HtmlGenerator::generateSynopsis(const Node *node, QString HtmlGenerator::highlightedCode(const QString& markedCode, const Node* relative, - bool alignNames) + bool alignNames, Node::Genus genus) { QString src = markedCode; QString html; @@ -3533,17 +3533,17 @@ QString HtmlGenerator::highlightedCode(const QString& markedCode, html += QLatin1String("</b>"); } else if (parseArg(src, funcTag, &i, srcSize, &arg, &par1)) { - const Node* n = qdb_->findFunctionNode(par1.toString(), relative, Node::DontCare); + const Node* n = qdb_->findFunctionNode(par1.toString(), relative, genus); QString link = linkForNode(n, relative); addLink(link, arg, &html); par1 = QStringRef(); } else if (parseArg(src, typeTag, &i, srcSize, &arg, &par1)) { par1 = QStringRef(); - const Node* n = qdb_->findTypeNode(arg.toString(), relative); + const Node* n = qdb_->findTypeNode(arg.toString(), relative, genus); html += QLatin1String("<span class=\"type\">"); if (n && (n->isQmlBasicType() || n->isJsBasicType())) { - if (relative && (relative->isQmlType() || relative->isJsType())) + if (relative && (relative->genus() == n->genus() || genus == n->genus())) addLink(linkForNode(n,relative), arg, &html); else html += arg; diff --git a/src/qdoc/htmlgenerator.h b/src/qdoc/htmlgenerator.h index c9c0f1a24..c36a2e835 100644 --- a/src/qdoc/htmlgenerator.h +++ b/src/qdoc/htmlgenerator.h @@ -201,7 +201,8 @@ private: void generateSectionInheritedList(const Section& section, const Node *relative); QString highlightedCode(const QString& markedCode, const Node* relative, - bool alignNames = false); + bool alignNames = false, + Node::Genus genus = Node::DontCare); void generateFullName(const Node *apparentNode, const Node *relative, const Node *actualNode = 0); void generateDetailedMember(const Node *node, diff --git a/src/qdoc/node.cpp b/src/qdoc/node.cpp index 9919317f2..8ec635868 100644 --- a/src/qdoc/node.cpp +++ b/src/qdoc/node.cpp @@ -860,6 +860,8 @@ Node *Aggregate::findChildNode(const QString& name, Node::Genus genus) const } } } + if (genus != Node::DontCare && this->genus() != genus) + return nullptr; return primaryFunctionMap_.value(name); } diff --git a/src/qdoc/qdocdatabase.cpp b/src/qdoc/qdocdatabase.cpp index c6650e830..63ae433e7 100644 --- a/src/qdoc/qdocdatabase.cpp +++ b/src/qdoc/qdocdatabase.cpp @@ -466,12 +466,15 @@ void QDocDatabase::destroyQdocDB() In particular, the type node map is initialized with a lot type names that don't refer to documented types. For example, - the C++ standard types are included. These might be documented + many C++ standard types are included. These might be documented here at some point, but for now they are not. Other examples include \c array and \c data, which are just generic names used as place holders in function signatures that appear in the documentation. + \note Do not add QML basic types into this list as it will + break linking to those types. + Also calls Node::initialize() to initialize the search goal map. */ void QDocDatabase::initializeDB() @@ -487,7 +490,6 @@ void QDocDatabase::initializeDB() typeNodeMap_.insert( "autoSearch", 0); typeNodeMap_.insert( "axis", 0); typeNodeMap_.insert( "backClicked", 0); - typeNodeMap_.insert( "bool", 0); typeNodeMap_.insert( "boomTime", 0); typeNodeMap_.insert( "border", 0); typeNodeMap_.insert( "buttonClicked", 0); @@ -496,7 +498,6 @@ void QDocDatabase::initializeDB() typeNodeMap_.insert( "clicked", 0); typeNodeMap_.insert( "close", 0); typeNodeMap_.insert( "closed", 0); - typeNodeMap_.insert( "color", 0); typeNodeMap_.insert( "cond", 0); typeNodeMap_.insert( "data", 0); typeNodeMap_.insert( "dataReady", 0); @@ -505,10 +506,8 @@ void QDocDatabase::initializeDB() typeNodeMap_.insert( "datetime", 0); typeNodeMap_.insert( "day", 0); typeNodeMap_.insert( "deactivated", 0); - typeNodeMap_.insert( "double", 0); typeNodeMap_.insert( "drag", 0); typeNodeMap_.insert( "easing", 0); - typeNodeMap_.insert( "enumeration", 0); typeNodeMap_.insert( "error", 0); typeNodeMap_.insert( "exposure", 0); typeNodeMap_.insert( "fatalError", 0); @@ -530,14 +529,12 @@ void QDocDatabase::initializeDB() typeNodeMap_.insert( "imageProcessing", 0); typeNodeMap_.insert( "index", 0); typeNodeMap_.insert( "initialized", 0); - typeNodeMap_.insert( "int", 0); typeNodeMap_.insert( "isLoaded", 0); typeNodeMap_.insert( "item", 0); typeNodeMap_.insert( "jsdict", 0); typeNodeMap_.insert( "jsobject", 0); typeNodeMap_.insert( "key", 0); typeNodeMap_.insert( "keysequence", 0); - typeNodeMap_.insert( "list", 0); typeNodeMap_.insert( "listViewClicked", 0); typeNodeMap_.insert( "loadRequest", 0); typeNodeMap_.insert( "locale", 0); @@ -567,7 +564,6 @@ void QDocDatabase::initializeDB() typeNodeMap_.insert( "progress", 0); typeNodeMap_.insert( "puzzleLost", 0); typeNodeMap_.insert( "qmlSignal", 0); - typeNodeMap_.insert( "real", 0); typeNodeMap_.insert( "rectangle", 0); typeNodeMap_.insert( "request", 0); typeNodeMap_.insert( "requestId", 0); @@ -591,7 +587,6 @@ void QDocDatabase::initializeDB() typeNodeMap_.insert( "std::pair", 0); typeNodeMap_.insert( "std::string", 0); typeNodeMap_.insert( "std::vector", 0); - typeNodeMap_.insert( "string", 0); typeNodeMap_.insert( "stringlist", 0); typeNodeMap_.insert( "swapPlayers", 0); typeNodeMap_.insert( "symbol", 0); @@ -1453,7 +1448,7 @@ const Node* QDocDatabase::findFunctionNode(const QString& target, When searching the index trees, the search begins at the root. */ -const Node* QDocDatabase::findTypeNode(const QString& type, const Node* relative) +const Node* QDocDatabase::findTypeNode(const QString& type, const Node* relative, Node::Genus genus) { QStringList path = type.split("::"); if ((path.size() == 1) && (path.at(0)[0].isLower() || path.at(0) == QString("T"))) { @@ -1461,7 +1456,7 @@ const Node* QDocDatabase::findTypeNode(const QString& type, const Node* relative if (i != typeNodeMap_.end()) return i.value(); } - return forest_.findTypeNode(path, relative); + return forest_.findTypeNode(path, relative, genus); } /*! diff --git a/src/qdoc/qdocdatabase.h b/src/qdoc/qdocdatabase.h index 0af094878..c3861bf57 100644 --- a/src/qdoc/qdocdatabase.h +++ b/src/qdoc/qdocdatabase.h @@ -143,11 +143,10 @@ class QDocForest Node::Genus genus, QString& ref); - const Node* findTypeNode(const QStringList& path, const Node* relative) + const Node* findTypeNode(const QStringList& path, const Node* relative, Node::Genus genus) { int flags = SearchBaseClasses | SearchEnumValues | NonFunction; - Node::Genus genus = Node::DontCare; - if (relative) + if (relative && genus == Node::DontCare && relative->genus() != Node::DOC) genus = relative->genus(); foreach (Tree* t, searchOrder()) { const Node* n = t->findNode(path, relative, flags, genus); @@ -338,7 +337,7 @@ class QDocDatabase const Node* findFunctionNode(const QString& target, const Node* relative, Node::Genus genus) { return forest_.findFunctionNode(target, relative, genus); } - const Node* findTypeNode(const QString& type, const Node* relative); + const Node* findTypeNode(const QString& type, const Node* relative, Node::Genus genus); const Node* findNodeForTarget(const QString& target, const Node* relative); const DocumentNode* findDocumentNodeByTitle(const QString& title) { return forest_.findDocumentNodeByTitle(title); |