summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-01-14 09:42:29 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2019-01-15 20:04:49 +0000
commit7d9d64b40718ace6ffa68e06808bcdf1a3f5099b (patch)
tree8d0410cc6a12d9e69797d55943b3259751f80780 /tools
parent749e6295712eb1dbdcd9becce0f0de8bfe136345 (diff)
Clean up LoadWatcher in the Qml Runtime
Name the variables in a self-documenting way. While we're at it, do initialization at declaration when possible, reorder the public sections before the private ones, fix comment spacing, and use function-pointer connect syntax where possible. Change-Id: I3fddc8f6d27afa197d425fb7ae3baee02acedceb Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qml/main.cpp72
1 files changed, 35 insertions, 37 deletions
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index 7dfae2b53d..409d227579 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 Research In Motion.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the tools applications of the Qt Toolkit.
@@ -164,54 +165,42 @@ class LoadWatcher : public QObject
public:
LoadWatcher(QQmlApplicationEngine *e, int expected)
: QObject(e)
- , earlyExit(false)
- , returnCode(0)
- , expect(expected)
- , haveOne(false)
+ , expectedFileCount(expected)
{
- connect(e, SIGNAL(objectCreated(QObject*,QUrl)),
- this, SLOT(checkFinished(QObject*)));
+ connect(e, &QQmlApplicationEngine::objectCreated, this, &LoadWatcher::checkFinished);
// QQmlApplicationEngine also connects quit() to QCoreApplication::quit
// and exit() to QCoreApplication::exit but if called before exec()
// then QCoreApplication::quit or QCoreApplication::exit does nothing
- connect(e, SIGNAL(quit()),
- this, SLOT(quit()));
- connect(e, &QQmlEngine::exit,
- this, &LoadWatcher::exit);
+ connect(e, &QQmlEngine::quit, this, &LoadWatcher::quit);
+ connect(e, &QQmlEngine::exit, this, &LoadWatcher::exit);
}
- bool earlyExit;
- int returnCode;
-
-private:
- void contain(QObject *o, const QUrl &containPath);
- void checkForWindow(QObject *o);
-
- int expect;
- bool haveOne;
+ bool earlyExit = false;
+ int returnCode = 0;
public Q_SLOTS:
- void checkFinished(QObject *o)
+ void checkFinished(QObject *o, const QUrl &url)
{
+ Q_UNUSED(url)
if (o) {
checkForWindow(o);
- haveOne = true;
+ haveWindow = true;
if (conf && qae)
for (PartialScene *ps : qAsConst(conf->completers))
if (o->inherits(ps->itemType().toUtf8().constData()))
contain(o, ps->container());
}
- if (haveOne)
+ if (haveWindow)
return;
- if (! --expect) {
+ if (! --expectedFileCount) {
printf("qml: Did not load any objects, exiting.\n");
- std::exit(2);//Different return code from qFatal
+ std::exit(2); // Different return code from qFatal
}
}
void quit() {
- //Will be checked before calling exec()
+ // Will be checked before calling exec()
earlyExit = true;
returnCode = 0;
}
@@ -223,6 +212,14 @@ public Q_SLOTS:
#if defined(QT_GUI_LIB) && QT_CONFIG(opengl)
void onOpenGlContextCreated(QOpenGLContext *context);
#endif
+
+private:
+ void contain(QObject *o, const QUrl &containPath);
+ void checkForWindow(QObject *o);
+
+private:
+ int expectedFileCount;
+ bool haveWindow = false;
};
void LoadWatcher::contain(QObject *o, const QUrl &containPath)
@@ -237,7 +234,7 @@ void LoadWatcher::contain(QObject *o, const QUrl &containPath)
if ((idx = o2->metaObject()->indexOfProperty("containedObject")) != -1)
success = o2->metaObject()->property(idx).write(o2, QVariant::fromValue<QObject*>(o));
if (!success)
- o->setParent(o2); //Set QObject parent, and assume container will react as needed
+ o->setParent(o2); // Set QObject parent, and assume container will react as needed
}
void LoadWatcher::checkForWindow(QObject *o)
@@ -274,7 +271,7 @@ void quietMessageHandler(QtMsgType type, const QMessageLogContext &ctxt, const Q
{
Q_UNUSED(ctxt);
Q_UNUSED(msg);
- //Doesn't print anything
+ // Doesn't print anything
switch (type) {
case QtFatalMsg:
exit(-1);
@@ -361,7 +358,7 @@ void noFilesGiven()
exit(1);
}
-//Called before application initialization, removes arguments it uses
+// Called before application initialization, removes arguments it uses
void getAppFlags(int &argc, char **argv)
{
#ifdef QT_GUI_LIB
@@ -471,7 +468,7 @@ int main(int argc, char *argv[])
QString translationFile;
QString dummyDir;
- //Handle main arguments
+ // Handle main arguments
const QStringList argList = app->arguments();
for (int i = 1; i < argList.count(); i++) {
const QString &arg = argList[i];
@@ -493,27 +490,27 @@ int main(int argc, char *argv[])
#endif
else if (arg == QLatin1String("-I")) {
if (i+1 == argList.count())
- continue;//Invalid usage, but just ignore it
+ continue; // Invalid usage, but just ignore it
e.addImportPath(argList[i+1]);
i++;
} else if (arg == QLatin1String("-f")) {
if (i+1 == argList.count())
- continue;//Invalid usage, but just ignore it
+ continue; // Invalid usage, but just ignore it
files << argList[i+1];
i++;
} else if (arg == QLatin1String("-config")){
if (i+1 == argList.count())
- continue;//Invalid usage, but just ignore it
+ continue; // Invalid usage, but just ignore it
confFile = argList[i+1];
i++;
} else if (arg == QLatin1String("-translation")){
if (i+1 == argList.count())
- continue;//Invalid usage, but just ignore it
+ continue; // Invalid usage, but just ignore it
translationFile = argList[i+1];
i++;
} else if (arg == QLatin1String("-dummy-data")){
if (i+1 == argList.count())
- continue;//Invalid usage, but just ignore it
+ continue; // Invalid usage, but just ignore it
dummyDir = argList[i+1];
i++;
} else if (arg == QLatin1String("-gles")) {
@@ -569,7 +566,7 @@ int main(int argc, char *argv[])
qae = &e;
loadConf(confFile, !verboseMode);
- //Load files
+ // Load files
QScopedPointer<LoadWatcher> lw(new LoadWatcher(&e, files.count()));
// Load dummy data before loading QML-files
@@ -582,8 +579,9 @@ int main(int argc, char *argv[])
printf("qml: loading %s\n", qPrintable(url.toString()));
QByteArray strippedFile;
if (getFileSansBangLine(path, strippedFile))
- e.loadData(strippedFile, e.baseUrl().resolved(url)); //QQmlComponent won't resolve it for us, it doesn't know it's a valid file if we loadData
- else //Errors or no bang line
+ // QQmlComponent won't resolve it for us: it doesn't know it's a valid file if we loadData
+ e.loadData(strippedFile, e.baseUrl().resolved(url));
+ else // Errors or no bang line
e.load(url);
}