diff options
author | Topi Reinio <topi.reinio@digia.com> | 2015-05-15 14:35:43 +0200 |
---|---|---|
committer | Topi Reiniƶ <topi.reinio@digia.com> | 2015-05-19 11:19:05 +0000 |
commit | f1fdac97abe2d9fedcf83469505f5704b3e2a26c (patch) | |
tree | 7ca59281c619cb0e03d7eb8268eb62deeba5cbc3 /src/tools | |
parent | e994f39a84b58975ed46ebb60401b5f153362471 (diff) |
qdoc: Improve logic for automatic example tag generation
QDoc generates tags for examples based on the example title and the
name of the module. This change makes the following improvements:
- Edit regular expression to match strings like 'OpenGL' and
'Qt3D' as a single tag.
- Strip off enclosing parentheses.
- Filter out common words ('and', 'the')
- When cleaning/modifying generated tags, keep them in a QSet
to eliminate duplicates.
Change-Id: I288104df12bf23a224068d40bce1f980148a412a
Reviewed-by: Martin Smith <martin.smith@digia.com>
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/qdoc/htmlgenerator.cpp | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/src/tools/qdoc/htmlgenerator.cpp b/src/tools/qdoc/htmlgenerator.cpp index 710ce08abb..8d84019ab5 100644 --- a/src/tools/qdoc/htmlgenerator.cpp +++ b/src/tools/qdoc/htmlgenerator.cpp @@ -4543,33 +4543,49 @@ void HtmlGenerator::generateManifestFile(const QString &manifest, const QString writer.writeCDATA(QString("No description available")); writer.writeEndElement(); // description - // Add words from module name as tags (QtQuickControls -> qt,quick,controls) - QRegExp re("([A-Z]+[a-z0-9]*)"); + // Add words from module name as tags + // QtQuickControls -> qt,quick,controls + // QtOpenGL -> qt,opengl + QRegExp re("([A-Z]+[a-z0-9]*(3D|GL)?)"); int pos = 0; while ((pos = re.indexIn(project, pos)) != -1) { tags << re.cap(1).toLower(); pos += re.matchedLength(); } tags += QSet<QString>::fromList(en->title().toLower().split(QLatin1Char(' '))); + + // Clean up tags, exclude invalid and common words + QSet<QString>::iterator tag_it = tags.begin(); + QSet<QString> modified; + while (tag_it != tags.end()) { + QString s = *tag_it; + if (s.at(0) == '(') + s.remove(0, 1).chop(1); + if (s.endsWith(QLatin1Char(':'))) + s.chop(1); + + if (s.length() < 2 + || s.at(0).isDigit() + || s.at(0) == '-' + || s == QStringLiteral("qt") + || s == QStringLiteral("the") + || s == QStringLiteral("and") + || s.startsWith(QStringLiteral("example")) + || s.startsWith(QStringLiteral("chapter"))) + tag_it = tags.erase(tag_it); + else if (s != *tag_it) { + modified << s; + tag_it = tags.erase(tag_it); + } + else + ++tag_it; + } + tags += modified; + if (!tags.isEmpty()) { writer.writeStartElement("tags"); bool wrote_one = false; - // Exclude invalid and common words foreach (QString tag, tags) { - if (tag.length() < 2) - continue; - if (tag.at(0).isDigit()) - continue; - if (tag.at(0) == '-') - continue; - if (tag == QLatin1String("qt")) - continue; - if (tag.startsWith("example")) - continue; - if (tag.startsWith("chapter")) - continue; - if (tag.endsWith(QLatin1Char(':'))) - tag.chop(1); if (wrote_one) writer.writeCharacters(","); writer.writeCharacters(tag); |