[gegl-qt] QML: Add QDeclarativeExtensionPlugin



commit 663db196edd7f8ac7b5e501071dbd03a82389191
Author: Jon Nordby <jononor gmail com>
Date:   Tue Aug 30 20:12:43 2011 +0200

    QML: Add QDeclarativeExtensionPlugin
    
    Registers the components/items we provide, so that applications
    do not have to do it manually.

 .gitignore                        |    1 +
 config.pri                        |   10 +++++++++-
 examples/qml-basic/qml-basic.cpp  |    3 ---
 examples/qml-paint/qml-paint.cpp  |    3 ---
 gegl-qt.pro                       |    2 +-
 plugins/plugins.pro               |    6 ++++++
 plugins/qml-plugin/.gitignore     |    1 +
 plugins/qml-plugin/qml-plugin.cpp |   20 ++++++++++++++++++++
 plugins/qml-plugin/qml-plugin.h   |   15 +++++++++++++++
 plugins/qml-plugin/qml-plugin.pro |   27 +++++++++++++++++++++++++++
 plugins/qml-plugin/qmldir.in      |    1 +
 11 files changed, 81 insertions(+), 8 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 809097b..db82dc4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,5 @@ moc_*
 qrc_*
 *.pro.user
 gegl-qt-build-*
+gegl-qt-*.*
 *~
diff --git a/config.pri b/config.pri
index e44816a..46cb557 100644
--- a/config.pri
+++ b/config.pri
@@ -1,11 +1,18 @@
 
 GEGLQT_CONFIG = TRUE # Must always be set in this file. Used to detect if the file was found or not
+
 GEGLQT_PROJECTNAME = gegl-qt
-GEGLQT_API_VERSION = 0.1
 GEGLQT_VERSION = 0.0.1
+
+GEGLQT_API_VERSION = 0.1
 GEGLQT_BASELIBNAME = gegl-qt4
 GEGLQT_LIBNAME = $$GEGLQT_BASELIBNAME-$$GEGLQT_API_VERSION
 
+GEGLQT_QML_API_NAME = GeglQt
+GEGLQT_QML_API_VERSION_MAJOR = 0
+GEGLQT_QML_API_VERSION_MINOR = 1
+GEGLQT_QML_API_VERSION = 0.1
+
 OBJECTS_DIR = .obj
 MOC_DIR = .moc
 
@@ -43,6 +50,7 @@ GEGLQT_INSTALL_DATA = $$GEGLQT_INSTALL_PREFIX/share
 SUBST_VARIABLES += \
     GEGLQT_API_VERSION \
     GEGLQT_VERSION \
+    GEGLQT_BASELIBNAME \
     GEGLQT_LIBNAME \
     GEGLQT_INSTALL_PREFIX \
     GEGLQT_INSTALL_BIN \
diff --git a/examples/qml-basic/qml-basic.cpp b/examples/qml-basic/qml-basic.cpp
index 7fdcef1..a16fedc 100644
--- a/examples/qml-basic/qml-basic.cpp
+++ b/examples/qml-basic/qml-basic.cpp
@@ -46,9 +46,6 @@ int main(int argc, char *argv[])
     gegl_node_process(node);
     QVariant nodeVariant = qVariantFromValue(static_cast<void*>(node));
 
-    // TODO: Create an QDeclarativeExtensionPlugin which does this?
-    qmlRegisterType<NodeViewDeclarativeItem>("GeglQt", 0, 1, "NodeView");
-
     QDeclarativeView view;
     // Expose the gegl node to QML, so it can be used there
     view.rootContext()->setContextProperty("globalNode", nodeVariant);
diff --git a/examples/qml-paint/qml-paint.cpp b/examples/qml-paint/qml-paint.cpp
index ce4f4f9..c3d6756 100644
--- a/examples/qml-paint/qml-paint.cpp
+++ b/examples/qml-paint/qml-paint.cpp
@@ -36,9 +36,6 @@ int main(int argc, char *argv[])
     // Does all the GEGL graph stuff
     PaintEngine paintEngine;
 
-    // TODO: Create an QDeclarativeExtensionPlugin which does this?
-    qmlRegisterType<NodeViewDeclarativeItem>("GeglQt", 0, 1, "NodeView");
-
     QDeclarativeView view;
     // Expose the paint engine to QML, so it can be used there
     view.rootContext()->setContextProperty("paintEngine", &paintEngine);
diff --git a/gegl-qt.pro b/gegl-qt.pro
index b8763f0..c9c604e 100644
--- a/gegl-qt.pro
+++ b/gegl-qt.pro
@@ -5,7 +5,7 @@ TEMPLATE = subdirs
 CONFIG += ordered
 
 isEmpty(USE_EXTERNAL_GEGLQT) {
-    SUBDIRS += gegl-qt operations
+    SUBDIRS += gegl-qt operations plugins
 } else {
     !system(pkg-config --exists $$GEGLQT_LIBNAME):error("Could not find required dependency: GEGL-QT")
 }
diff --git a/plugins/plugins.pro b/plugins/plugins.pro
new file mode 100644
index 0000000..6d9a667
--- /dev/null
+++ b/plugins/plugins.pro
@@ -0,0 +1,6 @@
+include(../config.pri)
+
+TEMPLATE = subdirs
+contains(HAVE_QT_DECLARATIVE, yes) {
+    SUBDIRS += qml-plugin
+}
diff --git a/plugins/qml-plugin/.gitignore b/plugins/qml-plugin/.gitignore
new file mode 100644
index 0000000..69448a3
--- /dev/null
+++ b/plugins/qml-plugin/.gitignore
@@ -0,0 +1 @@
+qmldir
diff --git a/plugins/qml-plugin/qml-plugin.cpp b/plugins/qml-plugin/qml-plugin.cpp
new file mode 100644
index 0000000..b36f074
--- /dev/null
+++ b/plugins/qml-plugin/qml-plugin.cpp
@@ -0,0 +1,20 @@
+#include "qml-plugin.h"
+
+#include <gegl-qt.h>
+#include <gegl-qt-declarative.h>
+
+#include <QtDeclarative>
+
+using namespace GeglQt;
+
+QmlPlugin::QmlPlugin(QObject *parent) :
+    QDeclarativeExtensionPlugin(parent)
+{
+}
+
+void QmlPlugin::registerTypes(const char *uri)
+{
+    qmlRegisterType<NodeViewDeclarativeItem>(uri, 0, 1, "NodeView");
+}
+
+Q_EXPORT_PLUGIN2(qmlplugin, QmlPlugin)
diff --git a/plugins/qml-plugin/qml-plugin.h b/plugins/qml-plugin/qml-plugin.h
new file mode 100644
index 0000000..1165ad5
--- /dev/null
+++ b/plugins/qml-plugin/qml-plugin.h
@@ -0,0 +1,15 @@
+#ifndef QMLPLUGIN_H
+#define QMLPLUGIN_H
+
+#include <QDeclarativeExtensionPlugin>
+
+class QmlPlugin : public QDeclarativeExtensionPlugin
+{
+    Q_OBJECT
+public:
+    explicit QmlPlugin(QObject *parent = 0);
+
+    virtual void registerTypes(const char *uri);
+};
+
+#endif // QMLPLUGIN_H
diff --git a/plugins/qml-plugin/qml-plugin.pro b/plugins/qml-plugin/qml-plugin.pro
new file mode 100644
index 0000000..e43aa7a
--- /dev/null
+++ b/plugins/qml-plugin/qml-plugin.pro
@@ -0,0 +1,27 @@
+include(../../config.pri)
+
+TEMPLATE = lib
+CONFIG += qt plugin no_keywords
+QT += declarative
+TARGET = $$GEGLQT_LIBNAME
+
+target.path = $$[QT_INSTALL_IMPORTS]/$$GEGLQT_QML_API_NAME
+
+HEADERS += qml-plugin.h
+SOURCES += qml-plugin.cpp
+
+INCLUDEPATH += ../../gegl-qt ../.. # .. because public include have gegl-qt/ prefix
+LIBS += -L../../gegl-qt -l$$GEGLQT_LIBNAME
+
+CONFIG += link_pkgconfig
+PKGCONFIG += gegl
+
+OTHER_FILES += \
+    qmldir.in
+
+outputFiles(qmldir)
+
+qmldir_install.files += qmldir
+qmldir_install.path += $$target.path
+
+INSTALLS += target qmldir_install
diff --git a/plugins/qml-plugin/qmldir.in b/plugins/qml-plugin/qmldir.in
new file mode 100644
index 0000000..88efedb
--- /dev/null
+++ b/plugins/qml-plugin/qmldir.in
@@ -0,0 +1 @@
+plugin @GEGLQT_LIBNAME@



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]