diff options
author | Sune Vuorela <sune@vuorela.dk> | 2016-06-16 00:23:55 +0200 |
---|---|---|
committer | Sune Vuorela <sune@vuorela.dk> | 2016-06-16 11:53:05 +0000 |
commit | fb20b2637368365b76ccfac30dcf8fdd38d0fd36 (patch) | |
tree | dbbcda2f83e37dcd2e85f72f4ce784da028ed693 | |
parent | 5b8f8c801a958568772079b2f1b7b67bcdc81bc1 (diff) | |
download | qttools-fb20b2637368365b76ccfac30dcf8fdd38d0fd36.tar.gz |
Less randomness in qdoc output part II
Sort more lists before writing output
Extract an existing function for comparing nodes, and use it across the code base
Fix up the function to also sort private nodes, it is needed for reliable sorting.
Change-Id: I934c875ef3e8a36d0e684f5b67d0ca1b81e5716f
Reviewed-by: Martin Smith <martin.smith@theqtcompany.com>
-rw-r--r-- | src/qdoc/cppcodeparser.cpp | 5 | ||||
-rw-r--r-- | src/qdoc/helpprojectwriter.cpp | 10 | ||||
-rw-r--r-- | src/qdoc/htmlgenerator.cpp | 6 | ||||
-rw-r--r-- | src/qdoc/node.cpp | 57 | ||||
-rw-r--r-- | src/qdoc/node.h | 8 | ||||
-rw-r--r-- | src/qdoc/qdocindexfiles.cpp | 78 |
6 files changed, 79 insertions, 85 deletions
diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp index c1295c3a7..27cf92042 100644 --- a/src/qdoc/cppcodeparser.cpp +++ b/src/qdoc/cppcodeparser.cpp @@ -1031,8 +1031,9 @@ void CppCodeParser::processOtherMetaCommand(const Doc& doc, */ void CppCodeParser::processOtherMetaCommands(const Doc& doc, Node *node) { - const QSet<QString> metaCommands = doc.metaCommandsUsed(); - QSet<QString>::ConstIterator cmd = metaCommands.constBegin(); + QStringList metaCommands = doc.metaCommandsUsed().toList(); + metaCommands.sort(); + QStringList::ConstIterator cmd = metaCommands.constBegin(); while (cmd != metaCommands.constEnd()) { ArgList args = doc.metaCommandArgs(*cmd); ArgList::ConstIterator arg = args.constBegin(); diff --git a/src/qdoc/helpprojectwriter.cpp b/src/qdoc/helpprojectwriter.cpp index 035f781a6..f816fdb56 100644 --- a/src/qdoc/helpprojectwriter.cpp +++ b/src/qdoc/helpprojectwriter.cpp @@ -46,14 +46,6 @@ QT_BEGIN_NAMESPACE -// helper for sorting Node's based on their name -// once we can use C++11, this function can be moved -// to where it is actually used inside as a lambda function. -static bool nodeNameLessThan(const Node *first, const Node *second) -{ - return first->name() < second->name(); -} - HelpProjectWriter::HelpProjectWriter(const Config &config, const QString &defaultFileName, Generator* g) @@ -830,7 +822,7 @@ void HelpProjectWriter::generateProject(HelpProject &project) if (!contentsFound) { QList<const Node*> subnodes = subproject.nodes.values(); - std::sort(subnodes.begin(), subnodes.end(), nodeNameLessThan); + std::sort(subnodes.begin(), subnodes.end(), Node::nodeNameLessThan); foreach (const Node *node, subnodes) writeNode(project, writer, node); diff --git a/src/qdoc/htmlgenerator.cpp b/src/qdoc/htmlgenerator.cpp index d3b65de3a..684fa417d 100644 --- a/src/qdoc/htmlgenerator.cpp +++ b/src/qdoc/htmlgenerator.cpp @@ -2891,6 +2891,8 @@ void HtmlGenerator::generateAnnotatedList(const Node *relative, out() << "<div class=\"table\"><table class=\"annotated\">\n"; int row = 0; NodeList nodes = nmm.values(); + std::sort(nodes.begin(), nodes.end(), Node::nodeNameLessThan); + foreach (const Node* node, nodes) { if (++row % 2 == 1) out() << "<tr class=\"odd topAlign\">"; @@ -4909,7 +4911,9 @@ void HtmlGenerator::generateAssociatedPropertyNotes(const FunctionNode* fn) { if (fn->hasAssociatedProperties()) { out() << "<p><b>Note:</b> "; - foreach (const PropertyNode* pn, fn->associatedProperties()) { + PropNodeList propertyNodes = fn->associatedProperties(); + std::sort(propertyNodes.begin(), propertyNodes.end(), Node::nodeNameLessThan); + foreach (const PropertyNode* pn, propertyNodes) { QString msg; switch (pn->role(fn)) { case PropertyNode::Getter: diff --git a/src/qdoc/node.cpp b/src/qdoc/node.cpp index 7384e8245..81a6d1923 100644 --- a/src/qdoc/node.cpp +++ b/src/qdoc/node.cpp @@ -78,6 +78,63 @@ void Node::initialize() goals_.insert("namespace", Node::Namespace); } +bool Node::nodeNameLessThan(const Node *n1, const Node *n2) +{ + if (n1->location().filePath() < n2->location().filePath()) + return true; + else if (n1->location().filePath() > n2->location().filePath()) + return false; + + if (n1->type() < n2->type()) + return true; + else if (n1->type() > n2->type()) + return false; + + if (n1->name() < n2->name()) + return true; + else if (n1->name() > n2->name()) + return false; + + if (n1->access() < n2->access()) + return true; + else if (n1->access() > n2->access()) + return false; + + if (n1->type() == Node::Function && n2->type() == Node::Function) { + const FunctionNode* f1 = static_cast<const FunctionNode*>(n1); + const FunctionNode* f2 = static_cast<const FunctionNode*>(n2); + + if (f1->isConst() < f2->isConst()) + return true; + else if (f1->isConst() > f2->isConst()) + return false; + + if (f1->signature(false) < f2->signature(false)) + return true; + else if (f1->signature(false) > f2->signature(false)) + return false; + } + + if (n1->isDocumentNode() && n2->isDocumentNode()) { + const DocumentNode* f1 = static_cast<const DocumentNode*>(n1); + const DocumentNode* f2 = static_cast<const DocumentNode*>(n2); + if (f1->fullTitle() < f2->fullTitle()) + return true; + else if (f1->fullTitle() > f2->fullTitle()) + return false; + } + else if (n1->isCollectionNode() && n2->isCollectionNode()) { + const CollectionNode* f1 = static_cast<const CollectionNode*>(n1); + const CollectionNode* f2 = static_cast<const CollectionNode*>(n2); + if (f1->fullTitle() < f2->fullTitle()) + return true; + else if (f1->fullTitle() > f2->fullTitle()) + return false; + } + + return false; +} + /*! Increment the number of property groups seen in the current file, and return the new value. diff --git a/src/qdoc/node.h b/src/qdoc/node.h index 870a55cdf..183a729a3 100644 --- a/src/qdoc/node.h +++ b/src/qdoc/node.h @@ -338,6 +338,14 @@ public: static void initialize(); static NodeType goal(const QString& t) { return goals_.value(t); } +/*! + Returns \c true if the node \a n1 is less than node \a n2. The + comparison is performed by comparing properties of the nodes + in order of increasing complexity. +*/ + static bool nodeNameLessThan(const Node *first, const Node *second); + + protected: Node(NodeType type, Aggregate* parent, const QString& name); void removeRelates(); diff --git a/src/qdoc/qdocindexfiles.cpp b/src/qdoc/qdocindexfiles.cpp index 421e75569..e7d66ce76 100644 --- a/src/qdoc/qdocindexfiles.cpp +++ b/src/qdoc/qdocindexfiles.cpp @@ -1192,13 +1192,12 @@ bool QDocIndexFiles::generateIndexSection(QXmlStreamWriter& writer, writer.writeAttribute("relates", functionNode->relates()->name()); } if (functionNode->hasAssociatedProperties()) { - QString associatedProperties; + QStringList associatedProperties; foreach (PropertyNode* pn, functionNode->associatedProperties()) { - if (!associatedProperties.isEmpty()) - associatedProperties += QLatin1String(", "); - associatedProperties += pn->name(); + associatedProperties << pn->name(); } - writer.writeAttribute("associated-property", associatedProperties); + associatedProperties.sort(); + writer.writeAttribute("associated-property", associatedProperties.join(",")); } writer.writeAttribute("type", functionNode->returnType()); if (!brief.isEmpty()) @@ -1392,73 +1391,6 @@ bool QDocIndexFiles::generateIndexSection(QXmlStreamWriter& writer, } /*! - Returns \c true if the node \a n1 is less than node \a n2. The - comparison is performed by comparing properties of the nodes - in order of increasing complexity. -*/ -bool compareNodes(const Node* n1, const Node* n2) -{ - // Private nodes can occur in any order since they won't normally be - // written to the index. - if (n1->access() == Node::Private && n2->access() == Node::Private) - return false; - - if (n1->location().filePath() < n2->location().filePath()) - return true; - else if (n1->location().filePath() > n2->location().filePath()) - return false; - - if (n1->type() < n2->type()) - return true; - else if (n1->type() > n2->type()) - return false; - - if (n1->name() < n2->name()) - return true; - else if (n1->name() > n2->name()) - return false; - - if (n1->access() < n2->access()) - return true; - else if (n1->access() > n2->access()) - return false; - - if (n1->type() == Node::Function && n2->type() == Node::Function) { - const FunctionNode* f1 = static_cast<const FunctionNode*>(n1); - const FunctionNode* f2 = static_cast<const FunctionNode*>(n2); - - if (f1->isConst() < f2->isConst()) - return true; - else if (f1->isConst() > f2->isConst()) - return false; - - if (f1->signature(false) < f2->signature(false)) - return true; - else if (f1->signature(false) > f2->signature(false)) - return false; - } - - if (n1->isDocumentNode() && n2->isDocumentNode()) { - const DocumentNode* f1 = static_cast<const DocumentNode*>(n1); - const DocumentNode* f2 = static_cast<const DocumentNode*>(n2); - if (f1->fullTitle() < f2->fullTitle()) - return true; - else if (f1->fullTitle() > f2->fullTitle()) - return false; - } - else if (n1->isCollectionNode() && n2->isCollectionNode()) { - const CollectionNode* f1 = static_cast<const CollectionNode*>(n1); - const CollectionNode* f2 = static_cast<const CollectionNode*>(n2); - if (f1->fullTitle() < f2->fullTitle()) - return true; - else if (f1->fullTitle() > f2->fullTitle()) - return false; - } - - return false; -} - -/*! Generate index sections for the child nodes of the given \a node using the \a writer specified. If \a generateInternalNodes is true, nodes marked as internal will be included in the index; otherwise, @@ -1480,7 +1412,7 @@ void QDocIndexFiles::generateIndexSections(QXmlStreamWriter& writer, const Aggregate* inner = static_cast<const Aggregate*>(node); NodeList cnodes = inner->childNodes(); - std::sort(cnodes.begin(), cnodes.end(), compareNodes); + std::sort(cnodes.begin(), cnodes.end(), Node::nodeNameLessThan); foreach (Node* child, cnodes) { generateIndexSections(writer, child, generateInternalNodes); |