summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@digia.com>2014-06-03 13:23:38 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-10 10:16:56 +0200
commit1a3d149174efca50de812c4f336a7ebfe069243c (patch)
tree6b66ad82b060ff07ae97615023eac82ce781905e /src/tools
parent360fd4a278a8827d9727b295a753e623502c7445 (diff)
qdoc: Revised logic for which example file to open in Qt Creator
qdoc stores the 'files to open' into the example manifest. These files are opened in Qt Creator's editor when an example is selected from the Welcome / Examples list. This change uses the following criteria (case insensitive), in order of preference: - .qml file matching the project name - .cpp file matching the project name - .h file matching the project name - main.qml - main.cpp A 'mainFile = "true"' argument is written for the file that is preferred to be the top-most file. Having a main.qml file take precedence over main.cpp ensures that most Qt Quick examples open into the relevant QML code instead of the boilerplate C++ used for launching the application. Task-number: QTBUG-37203 Change-Id: I2ea58a31b1284f4f7d424dd35d49a84a23a88c23 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com> Reviewed-by: Martin Smith <martin.smith@digia.com>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/qdoc/htmlgenerator.cpp57
1 files changed, 32 insertions, 25 deletions
diff --git a/src/tools/qdoc/htmlgenerator.cpp b/src/tools/qdoc/htmlgenerator.cpp
index 407253ff64..d1bf34f8e1 100644
--- a/src/tools/qdoc/htmlgenerator.cpp
+++ b/src/tools/qdoc/htmlgenerator.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the tools applications of the Qt Toolkit.
@@ -4399,36 +4399,43 @@ void HtmlGenerator::generateManifestFile(QString manifest, QString element)
}
QString ename = en->name().mid(en->name().lastIndexOf('/')+1);
- QSet<QString> usedNames;
+ QMap<int, const Node*> filesToOpen;
foreach (const Node* child, en->childNodes()) {
if (child->subType() == Node::File) {
- QString file = child->name();
- QString fileName = file.mid(file.lastIndexOf('/')+1);
- QString baseName = fileName;
- if ((fileName.count(QChar('.')) > 0) &&
- (fileName.endsWith(".cpp") ||
- fileName.endsWith(".h") ||
- fileName.endsWith(".qml")))
- baseName.truncate(baseName.lastIndexOf(QChar('.')));
- if (baseName.compare(ename, Qt::CaseInsensitive) == 0) {
- if (!usedNames.contains(fileName)) {
- writer.writeStartElement("fileToOpen");
- writer.writeCharacters(examplesPath + file);
- writer.writeEndElement(); // fileToOpen
- usedNames.insert(fileName);
- }
+ QFileInfo fileInfo(child->name());
+ QString fileName = fileInfo.fileName().toLower();
+ // open .qml, .cpp and .h files with a
+ // basename matching the example (project) name
+ // QMap key indicates the priority -
+ // the lowest value will be the top-most file
+ if ((fileInfo.baseName().compare(ename, Qt::CaseInsensitive) == 0)) {
+ if (fileName.endsWith(".qml"))
+ filesToOpen.insert(0, child);
+ else if (fileName.endsWith(".cpp"))
+ filesToOpen.insert(1, child);
+ else if (fileName.endsWith(".h"))
+ filesToOpen.insert(2, child);
}
- else if (fileName.toLower().endsWith("main.cpp") ||
- fileName.toLower().endsWith("main.qml")) {
- if (!usedNames.contains(fileName)) {
- writer.writeStartElement("fileToOpen");
- writer.writeCharacters(examplesPath + file);
- writer.writeEndElement(); // fileToOpen
- usedNames.insert(fileName);
- }
+ // main.qml takes precedence over main.cpp
+ else if (fileName.endsWith("main.qml")) {
+ filesToOpen.insert(3, child);
}
+ else if (fileName.endsWith("main.cpp")) {
+ filesToOpen.insert(4, child);
+ }
}
}
+
+ QMap<int, const Node*>::const_iterator it = filesToOpen.constEnd();
+ while (it != filesToOpen.constBegin()) {
+ writer.writeStartElement("fileToOpen");
+ if (--it == filesToOpen.constBegin()) {
+ writer.writeAttribute(QStringLiteral("mainFile"), QStringLiteral("true"));
+ }
+ writer.writeCharacters(examplesPath + it.value()->name());
+ writer.writeEndElement();
+ }
+
writer.writeEndElement(); // example
++i;
}