summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Gottfried <sebastiangottfried@web.de>2015-06-09 15:18:27 (GMT)
committerSebastian Gottfried <sebastiangottfried@web.de>2015-06-09 15:18:27 (GMT)
commit1d1ff6c5651bb95a61363628dc2ac3ca18b02e70 (patch)
treed715057d35fee6e14d56af0067a5cadeccba8253
parentc81b1d693abfc423e7c650986abb522ee58b3523 (diff)
Qt5: Add A Command Line Option For QML Import Dirs
This makes setting up a development envirnonment a bit easier since one can specify custom locations for locally installed QML plugins.
-rw-r--r--src/application.cpp11
-rw-r--r--src/application.h2
-rw-r--r--src/main.cpp10
3 files changed, 23 insertions, 0 deletions
diff --git a/src/application.cpp b/src/application.cpp
index fc8cb2c..e10f2dc 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -77,12 +77,23 @@ void Application::setupDeclarativeBindings(QQmlEngine* qmlEngine)
kDeclarative.setDeclarativeEngine(qmlEngine);
kDeclarative.setupBindings();
+ Application* app = static_cast<Application*>(Application::instance());
+ foreach (const QString& path, app->m_qmlImportPaths)
+ {
+ qmlEngine->addImportPath(path);
+ }
+
QQmlContext* rootContext = qmlEngine->rootContext();
rootContext->setContextProperty("utils", new Utils());
rootContext->setContextProperty("strFormatter", new StringFormatter());
}
+QStringList& Application::qmlImportPaths()
+{
+ return m_qmlImportPaths;
+}
+
void Application::registerQmlTypes()
{
qmlRegisterType<KeyboardLayout>("ktouch", 1, 0, "KeyboardLayout");
diff --git a/src/application.h b/src/application.h
index 4374784..2855222 100644
--- a/src/application.h
+++ b/src/application.h
@@ -34,10 +34,12 @@ public:
static DataIndex* dataIndex();
static void setupDeclarativeBindings(QQmlEngine* qmlEngine);
static QSharedPointer<ResourceEditor>& resourceEditorRef();
+ QStringList& qmlImportPaths();
private:
void registerQmlTypes();
DataIndex* m_dataIndex;
QSharedPointer<ResourceEditor> m_resourceEditorRef;
+ QStringList m_qmlImportPaths;
};
#endif // APPLICATION_H
diff --git a/src/main.cpp b/src/main.cpp
index 1aa4f0c..fda7e82 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -68,10 +68,20 @@ int main(int argc, char **argv)
parser.addOption(QCommandLineOption(QStringLiteral("resource-editor"), i18n("Launch the course and keyboard layout editor")));
+ parser.addOption({{"I", "import-path"}, i18n("Prepend the path to the list of QML import paths"), "path"});
+
parser.process(app);
about.processCommandLine(&parser);
+ if (parser.isSet("import-path"))
+ {
+ foreach (const QString& path, parser.values("import-path"))
+ {
+ app.qmlImportPaths().append(path);
+ }
+ }
+
if (app.isSessionRestored())
{