From e18b178d9a3bff54c92d80f1a0923ab72bf27267 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 14 Sep 2015 14:09:14 +0200 Subject: Register types in C++ (instead of qmldir) Later on, we can choose to register types from different style-subdirs based on a yet unknown style selector (app manifest file, env var, ...) This is also a step to the right direction to get QML types inherit enums and attached properties from the respective C++ base types. The qmlRegisterType(QUrl) overload for composite types probably needs a template argument to help figure out the missing meta-object link between the composite type and the C++ base type. Change-Id: I9b3c2afdd93fff56d1e7513879b3e9229f483cbf Reviewed-by: J-P Nurmi --- src/imports/controls/qmldir | 22 ------------ src/imports/controls/qtquickcontrols2plugin.cpp | 48 +++++++++++++++++++++++++ src/imports/extras/qmldir | 4 --- src/imports/extras/qtquickextras2plugin.cpp | 7 ++++ 4 files changed, 55 insertions(+), 26 deletions(-) (limited to 'src/imports') diff --git a/src/imports/controls/qmldir b/src/imports/controls/qmldir index 5de9450a..496eec5f 100644 --- a/src/imports/controls/qmldir +++ b/src/imports/controls/qmldir @@ -1,25 +1,3 @@ module QtQuick.Controls plugin qtquickcontrols2plugin classname QtQuickControls2Plugin -ApplicationWindow 2.0 ApplicationWindow.qml -BusyIndicator 2.0 BusyIndicator.qml -Button 2.0 Button.qml -CheckBox 2.0 CheckBox.qml -Frame 2.0 Frame.qml -GroupBox 2.0 GroupBox.qml -Label 2.0 Label.qml -PageIndicator 2.0 PageIndicator.qml -ProgressBar 2.0 ProgressBar.qml -RadioButton 2.0 RadioButton.qml -ScrollBar 2.0 ScrollBar.qml -ScrollIndicator 2.0 ScrollIndicator.qml -Slider 2.0 Slider.qml -StackView 2.0 StackView.qml -Switch 2.0 Switch.qml -TabBar 2.0 TabBar.qml -TabButton 2.0 TabButton.qml -TextArea 2.0 TextArea.qml -TextField 2.0 TextField.qml -ToggleButton 2.0 ToggleButton.qml -ToolBar 2.0 ToolBar.qml -ToolButton 2.0 ToolButton.qml diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index fb701a35..6c0f9ecc 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -35,7 +35,31 @@ ****************************************************************************/ #include +#include + #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "qquicktheme_p.h" void initResources() @@ -61,6 +85,30 @@ void QtQuickControls2Plugin::registerTypes(const char *uri) qmlRegisterType(uri, 2, 0, "ExclusiveGroup"); qmlRegisterType(); + + QDir baseDir(baseUrl().toLocalFile()); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("ApplicationWindow.qml"))), uri, 2, 0, "ApplicationWindow"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("BusyIndicator.qml"))), uri, 2, 0, "BusyIndicator"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("Button.qml"))), uri, 2, 0, "Button"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("CheckBox.qml"))), uri, 2, 0, "CheckBox"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("Frame.qml"))), uri, 2, 0, "Frame"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("GroupBox.qml"))), uri, 2, 0, "GroupBox"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("Label.qml"))), uri, 2, 0, "Label"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("PageIndicator.qml"))), uri, 2, 0, "PageIndicator"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("ProgressBar.qml"))), uri, 2, 0, "ProgressBar"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("RadioButton.qml"))), uri, 2, 0, "RadioButton"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("ScrollBar.qml"))), uri, 2, 0, "ScrollBar"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("ScrollIndicator.qml"))), uri, 2, 0, "ScrollIndicator"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("Slider.qml"))), uri, 2, 0, "Slider"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("StackView.qml"))), uri, 2, 0, "StackView"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("Switch.qml"))), uri, 2, 0, "Switch"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("TabBar.qml"))), uri, 2, 0, "TabBar"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("TabButton.qml"))), uri, 2, 0, "TabButton"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("TextArea.qml"))), uri, 2, 0, "TextArea"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("TextField.qml"))), uri, 2, 0, "TextField"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("ToggleButton.qml"))), uri, 2, 0, "ToggleButton"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("ToolBar.qml"))), uri, 2, 0, "ToolBar"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("ToolButton.qml"))), uri, 2, 0, "ToolButton"); } void QtQuickControls2Plugin::initializeEngine(QQmlEngine *engine, const char *uri) diff --git a/src/imports/extras/qmldir b/src/imports/extras/qmldir index 51c99e31..8822d83b 100644 --- a/src/imports/extras/qmldir +++ b/src/imports/extras/qmldir @@ -1,7 +1,3 @@ module QtQuick.Extras plugin qtquickextras2plugin classname QtQuickExtras2Plugin -Dial 2.0 Dial.qml -Drawer 2.0 Drawer.qml -SwipeView 2.0 SwipeView.qml -Tumbler 2.0 Tumbler.qml diff --git a/src/imports/extras/qtquickextras2plugin.cpp b/src/imports/extras/qtquickextras2plugin.cpp index 8b1ebb50..f1307558 100644 --- a/src/imports/extras/qtquickextras2plugin.cpp +++ b/src/imports/extras/qtquickextras2plugin.cpp @@ -35,6 +35,7 @@ ****************************************************************************/ #include +#include #include "qquickdial_p.h" #include "qquickdrawer_p.h" @@ -59,6 +60,12 @@ void QtQuickExtras2Plugin::registerTypes(const char *uri) qmlRegisterType(uri, 2, 0, "AbstractSwipeView"); qmlRegisterType(uri, 2, 0, "AbstractTumbler"); qmlRegisterType(); + + QDir baseDir(baseUrl().toLocalFile()); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("Dial.qml"))), uri, 2, 0, "Dial"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("Drawer.qml"))), uri, 2, 0, "Drawer"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("SwipeView.qml"))), uri, 2, 0, "SwipeView"); + qmlRegisterType(QUrl::fromLocalFile(baseDir.filePath(QStringLiteral("Tumbler.qml"))), uri, 2, 0, "Tumbler"); } QT_END_NAMESPACE -- cgit v1.2.3