[gegl-qt] Examples: Move operation listing code to common



commit 6686520327c722d2befe8a3fae03a78f2a4ee81d
Author: Jon Nordby <jononor gmail com>
Date:   Tue Apr 3 00:03:39 2012 +0200

    Examples: Move operation listing code to common

 examples/common/common.pro                         |    9 ++++++-
 .../operation.cpp => common/operations.cpp}        |   15 +++++++------
 .../operation.h => common/operations.h}            |   21 ++++++++++++++-----
 examples/qml-operations/qml-operations.cpp         |    8 +++---
 examples/qml-operations/qml-operations.pro         |    7 +-----
 5 files changed, 35 insertions(+), 25 deletions(-)
---
diff --git a/examples/common/common.pro b/examples/common/common.pro
index 767d8f4..e149662 100644
--- a/examples/common/common.pro
+++ b/examples/common/common.pro
@@ -5,8 +5,13 @@ TEMPLATE = lib
 CONFIG += staticlib
 TARGET = $$GEGLQT_LIBNAME-examples-common
 
-SOURCES += paint-engine.cpp
-HEADERS += paint-engine.h
+SOURCES += \
+    paint-engine.cpp \
+    operations.cpp \
+
+HEADERS += \
+    paint-engine.h \
+    operations.h \
 
 CONFIG += link_pkgconfig
 PKGCONFIG += $$GEGL_PKG
diff --git a/examples/qml-operations/operation.cpp b/examples/common/operations.cpp
similarity index 95%
rename from examples/qml-operations/operation.cpp
rename to examples/common/operations.cpp
index 7c67725..dabfdc3 100644
--- a/examples/qml-operations/operation.cpp
+++ b/examples/common/operations.cpp
@@ -1,6 +1,6 @@
-#include "operation.h"
+#include "operations.h"
 
-#include <gegl-qt.h>
+#include <gegl.h>
 #include <gegl-0.1/gegl-plugin.h> // For GeglOperationClass
 
 enum ValueAttribute {
@@ -103,7 +103,7 @@ getOperationsClasses(QList<GeglOperationClass *> *list, GType type)
     GeglOperationClass *klass;
     GType *classes;
     guint  no_children;
-    gint   no;
+    guint  no;
 
     if (!type)
       return list;
@@ -124,9 +124,10 @@ getOperationsClasses(QList<GeglOperationClass *> *list, GType type)
 }
 
 
-QMap<QString, Operation*> *
-getOperationMap() {
-    QMap<QString, Operation*> *operationMap = new QMap<QString, Operation*>();
+QMap<QString, Operation*>
+Operations::all()
+{
+    QMap<QString, Operation*> operationMap;
 
     QList<GeglOperationClass *> *operations = new QList<GeglOperationClass *>;
     operations = getOperationsClasses(operations, GEGL_TYPE_OPERATION);
@@ -137,7 +138,7 @@ getOperationMap() {
         QString description = QString::fromUtf8(op_class->description);
 
         Operation *operation = new Operation(name, getPropertyMap(name));
-        operationMap->insert(name, operation);
+        operationMap.insert(name, operation);
     }
 
     return operationMap;
diff --git a/examples/qml-operations/operation.h b/examples/common/operations.h
similarity index 87%
rename from examples/qml-operations/operation.h
rename to examples/common/operations.h
index 77a8dce..3a5566d 100644
--- a/examples/qml-operations/operation.h
+++ b/examples/common/operations.h
@@ -1,9 +1,9 @@
-#ifndef OPERATION_H
-#define OPERATION_H
+#ifndef OPERATIONS_H
+#define OPERATIONS_H
 
 #include <QObject>
-
-#include <gegl-qt.h>
+#include <QtCore>
+#include <glib-object.h>
 
 /* OperationProperty:
  *
@@ -63,6 +63,15 @@ private:
     QMap<QString, OperationProperty *> mProperties;
 };
 
-QMap<QString, Operation*> *getOperationMap();
 
-#endif // OPERATION_H
+class Operations
+{
+
+public:
+    /* Return all available operations. */
+    static QMap<QString, Operation*> all();
+};
+
+
+
+#endif // OPERATIONS_H
diff --git a/examples/qml-operations/qml-operations.cpp b/examples/qml-operations/qml-operations.cpp
index d3c565e..dcf7d3a 100644
--- a/examples/qml-operations/qml-operations.cpp
+++ b/examples/qml-operations/qml-operations.cpp
@@ -22,7 +22,7 @@
 #include <QtCore>
 #include <QtDeclarative>
 
-#include "operation.h"
+#include <examples/common/operations.h>
 
 int main(int argc, char *argv[])
 { 
@@ -30,9 +30,9 @@ int main(int argc, char *argv[])
     gegl_init(&argc, &argv);
     Q_INIT_RESOURCE(qmloperations);
 
-    QMap<QString, Operation *> *operationMap = getOperationMap();
-    QStringList operations = operationMap->keys();
-    Operation *selectedOperation = operationMap->value("gegl:dropshadow");
+    QMap<QString, Operation *> operationMap = Operations::all();
+    QStringList operations = operationMap.keys();
+    Operation *selectedOperation = operationMap.value("gegl:dropshadow");
 
 
     QDeclarativeView view;
diff --git a/examples/qml-operations/qml-operations.pro b/examples/qml-operations/qml-operations.pro
index a3f8cae..24e0699 100644
--- a/examples/qml-operations/qml-operations.pro
+++ b/examples/qml-operations/qml-operations.pro
@@ -1,11 +1,6 @@
 include(../../config.pri)
 include(../examples-common.pri)
 
-
-SOURCES += qml-operations.cpp \
-    operation.cpp
+SOURCES += qml-operations.cpp
 RESOURCES += qmloperations.qrc
 OTHER_FILES += qml-operations.qml
-
-HEADERS += \
-    operation.h



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