]> Johnzone git - UserSheets.git/commitdiff
added controller
authorJohn Janus <mail@johnzone.org>
Wed, 1 Mar 2017 22:03:10 +0000 (23:03 +0100)
committerJohn Janus <mail@johnzone.org>
Wed, 1 Mar 2017 22:03:25 +0000 (23:03 +0100)
Does not work yet

UserSheets.pro
addhuman.qml [moved from AddHuman.qml with 94% similarity]
controller.cpp [new file with mode: 0644]
controller.h [new file with mode: 0644]
main.cpp
main.qml
qml.qrc
qtquickcontrols2.conf

index 9e2b8c60b42546c2506f171228aca64fe4797ba5..ac79a87a92be5182ce5d08ef7307f13097b9dd70 100644 (file)
@@ -3,7 +3,8 @@ QT += qml quick sql
 CONFIG += c++11
 
 SOURCES += main.cpp \
-    database.cpp
+    database.cpp \
+    controller.cpp
 
 RESOURCES += qml.qrc
 
@@ -30,4 +31,5 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += target
 
 HEADERS += \
-    database.h
+    database.h \
+    controller.h
similarity index 94%
rename from AddHuman.qml
rename to addhuman.qml
index d0b8befc75114d6586312247b41bfeb5fa110457..8c316274d8f8aa396276103d0b486fd5ed96b1ef 100644 (file)
@@ -3,8 +3,9 @@ import QtQuick.Controls 2.0
 import QtQuick.Layouts 1.0
 import QtQuick.Controls 1.4
 
-ApplicationWindow {
+Popup {
   id: addhumanroot
+  signal addHuman(var name, var firstname, var birthday)
   //width: 200
   //height: 200
 
diff --git a/controller.cpp b/controller.cpp
new file mode 100644 (file)
index 0000000..be53717
--- /dev/null
@@ -0,0 +1,29 @@
+#include "controller.h"
+
+Controller::Controller(QQmlApplicationEngine* e, DataBase* d, QObject *parent) :
+  QObject(parent),
+  engine{e}, db{d}
+{
+  this->engine->load(QUrl(QLatin1String("qrc:/main.qml")));
+  //connect qml Signals to controller
+  QList<QObject*> roots = engine->rootObjects();
+  QObject* qmlRoot = roots.first();
+
+  QObject::connect(qmlRoot,SIGNAL(openAddHuman()),
+                   this, SLOT(openAddHuman()));
+
+}
+
+
+void Controller::openAddHuman()
+{
+//  QQmlContext context(engine, engine->rootObjects().first());
+  QQmlComponent component(engine, QUrl(QStringLiteral("qrc:/addHuman.qml")));
+//  QQmlContext context = component.creationContext();
+  QObject* dialog = component.create(/*&context*/);
+//  dialog->setParent(engine->rootObjects().first());
+//  QObject::connect(dialog, SIGNAL(addHuman(QVariant, QVariant, QVariant)),
+//                   db, SLOT(addHuman(QVariant, QVariant, QVariant)));
+
+
+}
diff --git a/controller.h b/controller.h
new file mode 100644 (file)
index 0000000..090a96e
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef CONTROLLER_H
+#define CONTROLLER_H
+#include <QObject>
+#include <QQmlApplicationEngine>
+#include "database.h"
+#include <QQmlComponent>
+#include <QUrl>
+#include <QQmlContext>
+
+class Controller : public QObject
+{
+  Q_OBJECT
+public:
+  explicit Controller(QQmlApplicationEngine* engine, DataBase* db, QObject *parent = 0);
+
+signals:
+
+public slots:
+  void openAddHuman();
+
+private:
+  QQmlApplicationEngine* engine;
+  DataBase* db;
+};
+
+#endif // CONTROLLER_H
index 5b26229f5e157a91eaf2b919fb20b6d733554442..b1c77b616a785c80301313fb1013d14b730bb878 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,7 @@
 #include <QGuiApplication>
 #include <QQmlApplicationEngine>
 #include "database.h"
+#include "controller.h"
 #include <QList>
 #include <QVariant>
 
@@ -10,18 +11,8 @@ int main(int argc, char *argv[])
   QGuiApplication app(argc, argv);
 
   QQmlApplicationEngine engine;
-  engine.load(QUrl(QLatin1String("qrc:/main.qml")));
   DataBase db;
-
-  QList<QObject*> roots = engine.rootObjects();
-  QObject* addHuman = roots.first();
-  for (QObject* qo : roots) {
-    if (qo->objectName() == "root")
-    addHuman = qo;
-  }
-  if (addHuman != nullptr)
-    QObject::connect(addHuman,SIGNAL(addHuman(QVariant, QVariant, QVariant)),
-                     &db, SLOT(addHuman(QVariant, QVariant, QVariant)));
+  Controller c(&engine, &db);
 
   return app.exec();
 }
index b245609ab5b60aee1f773ec1764736530392600c..6f911779ec2a0197ccc776733c171ca989f30f93 100644 (file)
--- a/main.qml
+++ b/main.qml
@@ -8,7 +8,7 @@ ApplicationWindow {
   width: 640
   height: 480
   title: qsTr("Hello World")
-  signal addHuman(var name, var firstname, var birthday)
+  signal openAddHuman()
 
   Button {
     id: btnaddhuman
@@ -16,9 +16,7 @@ ApplicationWindow {
     visible: true
     text: "Add Human"
     onClicked: {
-      var addHumanDialog = Qt.createComponent("AddHuman.qml")
-      var window = addHumanDialog.createObject(root)
-      window.show();
+      openAddHuman()
     }
   }
 }
diff --git a/qml.qrc b/qml.qrc
index 3c1c2b5213e7c3be930707f3571190d3f85996e1..5ddf2b47f5424d4851adc327e96c8167c611c158 100644 (file)
--- a/qml.qrc
+++ b/qml.qrc
@@ -2,6 +2,6 @@
     <qresource prefix="/">
         <file>main.qml</file>
         <file>qtquickcontrols2.conf</file>
-        <file>AddHuman.qml</file>
+        <file>addhuman.qml</file>
     </qresource>
 </RCC>
index 1764b16fb484c91b7f90f5692ad728ddb5203c7b..9f9367b7af67623af5f81e01f614d9724f815204 100644 (file)
@@ -3,7 +3,7 @@
 ; http://doc.qt.io/qt-5/qtquickcontrols2-styles.html
 
 [Controls]
-Style=Default
+Style=Universal
 
 [Universal]
 Theme=Light