summaryrefslogtreecommitdiff
path: root/src/controls
diff options
context:
space:
mode:
authorCaroline Chao <caroline.chao@digia.com>2013-07-31 13:51:58 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-21 13:10:10 +0200
commitb2e5d1acb1aca93157a6d4d0a026153134f9ad01 (patch)
tree8b095329722d5781e3499a12bdc1534a0863dfa0 /src/controls
parentffbf8d724f39e9c8d05ae2049e8b79a61570e235 (diff)
downloadqtquickcontrols-b2e5d1acb1aca93157a6d4d0a026153134f9ad01.tar.gz
Add qml/js files in resource
All the qml and js files are embedded in the Qt Quick Controls plugin (for Controls, Styles and Private). If ApplicationWindow.qml is missing, loading the files from resource will be enabled. Otherwise, the files will be loaded from the local path. The purpose of this change is to make the deployment of Qt Quick Controls easier while keeping the development tasks convenient. With this solution: - It is only necessary to deploy the qmldir and the plugin qtquickcontrolsplugin found in the QtQuick/Controls folder. - By default the files used are the ones found in the local folder. Autocompletion and debugging capabilities remain unchanged. Task-number: QTBUG-31565 Change-Id: I938ebe261c3c35f9e3b066d82c81accd9750edc9 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/controls')
-rw-r--r--src/controls/Private/qquickcontrolsettings.cpp22
-rw-r--r--src/controls/Private/qquickcontrolsettings_p.h2
-rw-r--r--src/controls/controls.pro27
-rw-r--r--src/controls/plugin.cpp54
-rw-r--r--src/controls/plugin.h3
-rw-r--r--src/controls/qmldir26
6 files changed, 104 insertions, 30 deletions
diff --git a/src/controls/Private/qquickcontrolsettings.cpp b/src/controls/Private/qquickcontrolsettings.cpp
index e2daa17f..48e71917 100644
--- a/src/controls/Private/qquickcontrolsettings.cpp
+++ b/src/controls/Private/qquickcontrolsettings.cpp
@@ -63,18 +63,27 @@ static QString styleImportName()
return QFileInfo(name).fileName();
}
+static bool fromResource(const QString &path)
+{
+ return path.startsWith("qrc:");
+}
+
static QString styleImportPath(QQmlEngine *engine, const QString &styleName)
{
QString path = qgetenv("QT_QUICK_CONTROLS_STYLE");
QFileInfo info(path);
if (info.isRelative()) {
+ bool found = false;
foreach (const QString &import, engine->importPathList()) {
QDir dir(import + QLatin1String("/QtQuick/Controls/Styles"));
if (dir.exists(styleName)) {
+ found = true;
path = dir.absolutePath();
break;
}
}
+ if (!found)
+ path = "qrc:/QtQuick/Controls/Styles";
} else {
path = info.absolutePath();
}
@@ -86,7 +95,11 @@ QQuickControlSettings::QQuickControlSettings(QQmlEngine *engine)
m_name = styleImportName();
m_path = styleImportPath(engine, m_name);
- if (!QFile::exists(styleFilePath())) {
+ QString path = styleFilePath();
+ if (fromResource(path))
+ path = path.remove(0, 3); // remove qrc from the path
+
+ if (!QDir(path).exists()) {
QString unknownStyle = m_name;
m_name = defaultStyleName();
m_path = styleImportPath(engine, m_name);
@@ -97,9 +110,12 @@ QQuickControlSettings::QQuickControlSettings(QQmlEngine *engine)
connect(this, SIGNAL(stylePathChanged()), SIGNAL(styleChanged()));
}
-QUrl QQuickControlSettings::style() const
+QString QQuickControlSettings::style() const
{
- return QUrl::fromLocalFile(styleFilePath());
+ if (fromResource(styleFilePath()))
+ return styleFilePath();
+ else
+ return QUrl::fromLocalFile(styleFilePath()).toString();
}
QString QQuickControlSettings::styleName() const
diff --git a/src/controls/Private/qquickcontrolsettings_p.h b/src/controls/Private/qquickcontrolsettings_p.h
index 8ff0ecbf..552c4820 100644
--- a/src/controls/Private/qquickcontrolsettings_p.h
+++ b/src/controls/Private/qquickcontrolsettings_p.h
@@ -60,7 +60,7 @@ class QQuickControlSettings : public QObject
public:
QQuickControlSettings(QQmlEngine *engine);
- QUrl style() const;
+ QString style() const;
QString styleName() const;
void setStyleName(const QString &name);
diff --git a/src/controls/controls.pro b/src/controls/controls.pro
index 78eadf36..38018353 100644
--- a/src/controls/controls.pro
+++ b/src/controls/controls.pro
@@ -45,5 +45,32 @@ include(Styles/styles.pri)
osx: LIBS += -framework Carbon
+# Create the resource file
+GENERATED_RESOURCE_FILE = $$OUT_PWD/controls.qrc
+
+INCLUDED_RESOURCE_FILES = \
+ $$CONTROLS_QML_FILES \
+ $$PRIVATE_QML_FILES \
+ $$STYLES_QML_FILES
+
+RESOURCE_CONTENT = \
+ "<RCC>" \
+ "<qresource prefix=\"/QtQuick/Controls\">"
+
+for(resourcefile, INCLUDED_RESOURCE_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
+
CONFIG += no_cxx_module
load(qml_plugin)
diff --git a/src/controls/plugin.cpp b/src/controls/plugin.cpp
index 1e842237..b98e7908 100644
--- a/src/controls/plugin.cpp
+++ b/src/controls/plugin.cpp
@@ -62,6 +62,38 @@
QT_BEGIN_NAMESPACE
+static const struct {
+ const char *type;
+ int major, minor;
+} qmldir [] = {
+ { "ApplicationWindow", 1, 0 },
+ { "Button", 1, 0 },
+ { "CheckBox", 1, 0 },
+ { "ComboBox", 1, 0 },
+ { "GroupBox", 1, 0 },
+ { "Label", 1, 0 },
+ { "MenuBar", 1, 0 },
+ { "Menu", 1, 0 },
+ { "StackView", 1, 0 },
+ { "ProgressBar", 1, 0 },
+ { "RadioButton", 1, 0 },
+ { "ScrollView", 1, 0 },
+ { "Slider", 1, 0 },
+ { "SpinBox", 1, 0 },
+ { "SplitView", 1, 0 },
+ { "StackViewDelegate", 1, 0 },
+ { "StackViewTransition", 1, 0 },
+ { "StatusBar", 1, 0 },
+ { "Tab", 1, 0 },
+ { "TabView", 1, 0 },
+ { "TableView", 1, 0 },
+ { "TableViewColumn", 1, 0 },
+ { "TextArea", 1, 0 },
+ { "TextField", 1, 0 },
+ { "ToolBar", 1, 0 },
+ { "ToolButton", 1, 0 }
+};
+
void QtQuickControlsPlugin::registerTypes(const char *uri)
{
qmlRegisterType<QQuickAction>(uri, 1, 0, "Action");
@@ -76,6 +108,10 @@ void QtQuickControlsPlugin::registerTypes(const char *uri)
QLatin1String("Do not create objects of type MenuBase"));
qmlRegisterUncreatableType<QQuickStack>(uri, 1, 0, "Stack", QLatin1String("Do not create objects of type Stack"));
+
+ const QString filesLocation = fileLocation();
+ for (int i = 0; i < int(sizeof(qmldir)/sizeof(qmldir[0])); i++)
+ qmlRegisterType(QUrl(filesLocation + "/" + qmldir[i].type + ".qml"), uri, qmldir[i].major, qmldir[i].minor, qmldir[i].type);
}
void QtQuickControlsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
@@ -96,6 +132,24 @@ void QtQuickControlsPlugin::initializeEngine(QQmlEngine *engine, const char *uri
#endif
engine->addImageProvider("desktoptheme", new QQuickDesktopIconProvider);
+ if (isLoadedFromResource())
+ engine->addImportPath(QStringLiteral("qrc:/"));
+}
+
+QString QtQuickControlsPlugin::fileLocation() const
+{
+ if (isLoadedFromResource())
+ return "qrc:/QtQuick/Controls";
+ return baseUrl().toString();
+}
+
+bool QtQuickControlsPlugin::isLoadedFromResource() const
+{
+ // If one file is missing, it will load all the files from the resource
+ QFile file(baseUrl().toLocalFile() + "/ApplicationWindow.qml");
+ if (!file.exists())
+ return true;
+ return false;
}
QT_END_NAMESPACE
diff --git a/src/controls/plugin.h b/src/controls/plugin.h
index fe06e806..2acdf02a 100644
--- a/src/controls/plugin.h
+++ b/src/controls/plugin.h
@@ -55,6 +55,9 @@ class QtQuickControlsPlugin: public QQmlExtensionPlugin
public:
void registerTypes(const char *uri);
void initializeEngine(QQmlEngine *engine, const char *uri);
+private:
+ QString fileLocation() const;
+ bool isLoadedFromResource() const;
};
QT_END_NAMESPACE
diff --git a/src/controls/qmldir b/src/controls/qmldir
index c243360c..41d4d512 100644
--- a/src/controls/qmldir
+++ b/src/controls/qmldir
@@ -1,28 +1,2 @@
module QtQuick.Controls
plugin qtquickcontrolsplugin
-ApplicationWindow 1.0 ApplicationWindow.qml
-Button 1.0 Button.qml
-CheckBox 1.0 CheckBox.qml
-ComboBox 1.0 ComboBox.qml
-GroupBox 1.0 GroupBox.qml
-Label 1.0 Label.qml
-MenuBar 1.0 MenuBar.qml
-Menu 1.0 Menu.qml
-StackView 1.0 StackView.qml
-ProgressBar 1.0 ProgressBar.qml
-RadioButton 1.0 RadioButton.qml
-ScrollView 1.0 ScrollView.qml
-Slider 1.0 Slider.qml
-SpinBox 1.0 SpinBox.qml
-SplitView 1.0 SplitView.qml
-StackViewDelegate 1.0 StackViewDelegate.qml
-StackViewTransition 1.0 StackViewTransition.qml
-StatusBar 1.0 StatusBar.qml
-Tab 1.0 Tab.qml
-TabView 1.0 TabView.qml
-TableView 1.0 TableView.qml
-TableViewColumn 1.0 TableViewColumn.qml
-TextArea 1.0 TextArea.qml
-TextField 1.0 TextField.qml
-ToolBar 1.0 ToolBar.qml
-ToolButton 1.0 ToolButton.qml