summaryrefslogtreecommitdiff
path: root/src/qdoc/main.cpp
diff options
context:
space:
mode:
authorPaul Wicking <paul.wicking@qt.io>2019-07-26 06:54:17 +0200
committerPaul Wicking <paul.wicking@qt.io>2019-07-26 19:19:56 +0200
commit735e99d0e11c494592e3f878dc9740d6835bc3c7 (patch)
tree954bdb64b298115415cd1ab97027a1a32bb8adf5 /src/qdoc/main.cpp
parenta449cb8c4a7fd46c33e4977a91c5097676ad5c39 (diff)
downloadqttools-735e99d0e11c494592e3f878dc9740d6835bc3c7.tar.gz
QDoc: make the Config a parameter instead of a global
This shall make it easier to test QDoc, by making mocking possible. This change moves the instantiation of Config:: to reside inside main(), so that it can be passed as a parameter where it is needed. This object is then passed to QDocCommandLineParser::process(), so that it can be changed via the object itself rather than via statics/globals. This improves the testability of the QDocCommandLineParser class, as the Config object can easily be mocked. This change also replaces a couple of foreach() uses in main.cpp with range-based for. Task-number: QTBUG-71165 Task-number: QTBUG-71176 Change-Id: I7b98dfc36895cd88fe54dcc9ce31b75aab820b3b Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/qdoc/main.cpp')
-rw-r--r--src/qdoc/main.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/qdoc/main.cpp b/src/qdoc/main.cpp
index bd790aa28..a4598dcb3 100644
--- a/src/qdoc/main.cpp
+++ b/src/qdoc/main.cpp
@@ -197,22 +197,20 @@ static void loadIndexFiles(Config& config, const QSet<QString> &formats)
}
/*!
- Processes the qdoc config file \a fileName. This is the
- controller for all of qdoc.
+ Processes the qdoc config file \a fileName. This is the controller for all
+ of QDoc. The \a config instance represents the configuration data for QDoc.
+ All other classes are initialized with the same config.
*/
-static void processQdocconfFile(const QString &fileName)
+static void processQdocconfFile(const QString &fileName, Config &config)
{
/*
- The Config instance represents the configuration data for qdoc.
- All the other classes are initialized with the config. Below, we
- initialize the configuration with some default values.
+ Below, we initialize the configuration with some default values.
I don't think the call to translate() does anything here. For one
thing, the translators haven't been installed at this point. And
I doubt any translator would translate QDoc anyway. But I left it
here because it does no harm.
*/
- Config config(QCoreApplication::translate("QDoc", "qdoc"));
QHash<QString,QString>::iterator iter;
for (iter = qdocGlobals.defaults().begin(); iter != qdocGlobals.defaults().end(); ++iter)
@@ -571,9 +569,11 @@ int main(int argc, char **argv)
HtmlGenerator htmlGenerator;
WebXMLGenerator webXMLGenerator;
+ Config config(QCoreApplication::translate("QDoc", "qdoc"));
+
// Set the globals declared at the top of this file:
QDocCommandLineParser parser;
- parser.process(app.arguments(), qdocGlobals);
+ parser.process(app.arguments(), qdocGlobals, &config);
// Get the list of files to act on:
QStringList qdocFiles = parser.positionalArguments();
@@ -586,21 +586,21 @@ int main(int argc, char **argv)
if (Generator::singleExec()) {
// single qdoc process for prepare and generate phases
Generator::setQDocPass(Generator::Prepare);
- foreach (const QString &qf, qdocFiles) {
+ for (const auto &file : qAsConst(qdocFiles)) {
qdocGlobals.dependModules().clear();
- processQdocconfFile(qf);
+ processQdocconfFile(file, config);
}
Generator::setQDocPass(Generator::Generate);
QDocDatabase::qdocDB()->processForest();
- foreach (const QString &qf, qdocFiles) {
+ for (const auto &file : qAsConst(qdocFiles)) {
qdocGlobals.dependModules().clear();
- processQdocconfFile(qf);
+ processQdocconfFile(file, config);
}
} else {
// separate qdoc processes for prepare and generate phases
- foreach (const QString &qf, qdocFiles) {
+ for (const auto &file : qAsConst(qdocFiles)) {
qdocGlobals.dependModules().clear();
- processQdocconfFile(qf);
+ processQdocconfFile(file, config);
}
}