aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2013-10-07 11:35:17 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-16 10:39:38 +0200
commit2f83bdbe5d536464c39d5e914efb1531e562eee7 (patch)
tree55674d3d7bd9ba40715204a65e296d94122a5f80 /src
parent54b73b8ab53ee41d9c8a855aa9a3da425e0a3f8f (diff)
Dialogs: use resources for QML and images
All the qml and image files are embedded in the QtQuick.Dialogs plugin. If DefaultFileDialog.qml is missing from the installation directory, loading from resources will be enabled. Otherwise, the files will be loaded from the local path. This is analogous to change b2e5d1acb1aca93157a6d4d0a026153134f9ad01 in Qt Quick Controls: it reduces the number of files that need to be installed, but also preserves ease of debugging whenever the QML files are separately installed. Task-number: QTBUG-31565 Change-Id: Idbe6be5d818eb6a25367f2053ea52bc7ac1485bc Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/imports/dialogs/dialogs.pro22
-rw-r--r--src/imports/dialogs/plugin.cpp57
2 files changed, 64 insertions, 15 deletions
diff --git a/src/imports/dialogs/dialogs.pro b/src/imports/dialogs/dialogs.pro
index 8db3d9ab58..d1ae8fb80c 100644
--- a/src/imports/dialogs/dialogs.pro
+++ b/src/imports/dialogs/dialogs.pro
@@ -69,4 +69,26 @@ QML_FILES += \
QT += quick-private gui gui-private core core-private qml
+# Create the resource file
+GENERATED_RESOURCE_FILE = $$OUT_PWD/dialogs.qrc
+
+RESOURCE_CONTENT = \
+ "<RCC>" \
+ "<qresource prefix=\"/QtQuick/Dialogs\">"
+
+for(resourcefile, QML_FILES) {
+ resourcefileabsolutepath = $$absolute_path($$resourcefile)
+ relativepath_in = $$relative_path($$resourcefileabsolutepath, $$_PRO_FILE_PWD_)
+ relativepath_out = $$relative_path($$resourcefileabsolutepath, $$OUT_PWD)
+ RESOURCE_CONTENT += "<file alias=\"$$relativepath_in\">$$relativepath_out</file>"
+}
+
+RESOURCE_CONTENT += \
+ "</qresource>" \
+ "</RCC>"
+
+write_file($$GENERATED_RESOURCE_FILE, RESOURCE_CONTENT)|error("Aborting.")
+
+RESOURCES += $$GENERATED_RESOURCE_FILE
+
load(qml_plugin)
diff --git a/src/imports/dialogs/plugin.cpp b/src/imports/dialogs/plugin.cpp
index e62e4efa34..1c852abae9 100644
--- a/src/imports/dialogs/plugin.cpp
+++ b/src/imports/dialogs/plugin.cpp
@@ -58,11 +58,12 @@
#include <qpa/qplatformintegration.h>
//#define PURE_QML_ONLY
+//#define DEBUG_REGISTRATION
QT_BEGIN_NAMESPACE
/*!
- \qmlmodule QtQuick.Dialogs 1
+ \qmlmodule QtQuick.Dialogs 1.1
\title Qt Quick Dialogs QML Types
\ingroup qmlmodules
\brief Provides QML types for standard file, color picker and message dialogs
@@ -82,24 +83,39 @@ class QtQuick2DialogsPlugin : public QQmlExtensionPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0")
public:
- QtQuick2DialogsPlugin() : QQmlExtensionPlugin() { }
+ QtQuick2DialogsPlugin() : QQmlExtensionPlugin(), m_useResources(true) { }
- virtual void initializeEngine(QQmlEngine *engine, const char * /*uri*/) {
- //qDebug() << Q_FUNC_INFO << uri << m_decorationComponentUrl;
+ virtual void initializeEngine(QQmlEngine *engine, const char * uri) {
+#ifdef DEBUG_REGISTRATION
+ qDebug() << Q_FUNC_INFO << uri << m_decorationComponentUrl;
+#else
+ Q_UNUSED(uri)
+#endif
QQuickAbstractDialog::m_decorationComponent =
new QQmlComponent(engine, m_decorationComponentUrl, QQmlComponent::Asynchronous);
}
virtual void registerTypes(const char *uri) {
+#ifdef DEBUG_REGISTRATION
+ qDebug() << Q_FUNC_INFO << uri;
+#endif
Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuick.Dialogs"));
bool hasTopLevelWindows = QGuiApplicationPrivate::platformIntegration()->
hasCapability(QPlatformIntegration::MultipleWindows);
QDir qmlDir(baseUrl().toLocalFile());
- m_decorationComponentUrl = QUrl::fromLocalFile(qmlDir.filePath(QString("qml/DefaultWindowDecoration.qml")));
QDir widgetsDir(baseUrl().toLocalFile());
// TODO: find the directory by searching rather than assuming a relative path
widgetsDir.cd("../PrivateWidgets");
+ // If at least one file was actually installed, then use installed qml files instead of resources.
+ // This makes debugging and incremental development easier, whereas the "normal" installation
+ // uses resources to save space and cut down on the number of files to deploy.
+ if (qmlDir.exists(QString("DefaultFileDialog.qml")))
+ m_useResources = false;
+ m_decorationComponentUrl = m_useResources ?
+ QUrl("qrc:/QtQuick/Dialogs/qml/DefaultWindowDecoration.qml") :
+ QUrl::fromLocalFile(qmlDir.filePath(QString("qml/DefaultWindowDecoration.qml")));
+
// Prefer the QPA dialog helpers if the platform supports them.
// Else if there is a QWidget-based implementation, check whether it's
// possible to instantiate it from Qt Quick.
@@ -143,8 +159,9 @@ protected:
template <class WrapperType>
void registerWidgetOrQmlImplementation(QDir widgetsDir, QDir qmlDir,
const char *qmlName, const char *uri, bool hasTopLevelWindows, int versionMajor, int versionMinor) {
- //qDebug() << Q_FUNC_INFO << qmlDir << qmlName << uri;
- bool needQml = true;
+ // qDebug() << "QtQuick2DialogsPlugin::registerWidgetOrQmlImplementation" << uri << qmlName << ": QML in" << qmlDir.absolutePath()
+ // << "using resources?" << m_useResources << "; widgets in" << widgetsDir.absolutePath();
+ bool needQmlImplementation = true;
#ifdef PURE_QML_ONLY
Q_UNUSED(widgetsDir)
@@ -154,22 +171,32 @@ protected:
// widget-free QGuiApplication), assume that the widget-based dialog will work.
if (hasTopLevelWindows && widgetsDir.exists("qmldir") &&
!qstrcmp(QCoreApplication::instance()->metaObject()->className(), "QApplication")) {
- QString dialogQmlPath = qmlDir.filePath(QString("Widget%1.qml").arg(qmlName));
- if (qmlRegisterType(QUrl::fromLocalFile(dialogQmlPath), uri, versionMajor, versionMinor, qmlName) >= 0)
- needQml = false;
- // qDebug() << "registering" << qmlName << " as " << dialogQmlPath << "success?" << !needQml;
+ QUrl dialogQmlPath = m_useResources ?
+ QUrl(QString("qrc:/QtQuick/Dialogs/Widget%1.qml").arg(qmlName)) :
+ QUrl::fromLocalFile(qmlDir.filePath(QString("Widget%1.qml").arg(qmlName)));
+ if (qmlRegisterType(dialogQmlPath, uri, versionMajor, versionMinor, qmlName) >= 0) {
+ needQmlImplementation = false;
+#ifdef DEBUG_REGISTRATION
+ qDebug() << " registering" << qmlName << " as " << dialogQmlPath << "success?" << !needQmlImplementation;
+#endif
+ }
}
#endif
- if (needQml) {
+ if (needQmlImplementation) {
QByteArray abstractTypeName = QByteArray("Abstract") + qmlName;
qmlRegisterType<WrapperType>(uri, versionMajor, versionMinor, abstractTypeName); // implementation wrapper
- QString dialogQmlPath = qmlDir.filePath(QString("Default%1.qml").arg(qmlName));
- // qDebug() << "registering" << qmlName << " as " << dialogQmlPath << "success?" <<
- qmlRegisterType(QUrl::fromLocalFile(dialogQmlPath), uri, versionMajor, versionMinor, qmlName);
+ QUrl dialogQmlPath = m_useResources ?
+ QUrl(QString("qrc:/QtQuick/Dialogs/Default%1.qml").arg(qmlName)) :
+ QUrl::fromLocalFile(qmlDir.filePath(QString("Default%1.qml").arg(qmlName)));
+#ifdef DEBUG_REGISTRATION
+ qDebug() << " registering" << qmlName << " as " << dialogQmlPath << "success?" <<
+#endif
+ qmlRegisterType(dialogQmlPath, uri, versionMajor, versionMinor, qmlName);
}
}
QUrl m_decorationComponentUrl;
+ bool m_useResources;
};
QT_END_NAMESPACE