From 0211037e649e21ba58e6b0d6c4fb664cc9b986b3 Mon Sep 17 00:00:00 2001 From: John Janus Date: Mon, 6 Mar 2017 17:10:00 +0100 Subject: [PATCH] small changes and todos... --- controller.cpp | 8 +++++--- humandatamodel.cpp | 12 ++++++++++++ humandatamodel.h | 4 +++- main.qml | 19 +++++++++++-------- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/controller.cpp b/controller.cpp index 56767a2..e29a42e 100644 --- a/controller.cpp +++ b/controller.cpp @@ -1,6 +1,7 @@ #include "controller.h" #include #include +#include #include "humandatamodel.h" Controller::Controller (DataBase* d, QObject* parent) : @@ -22,8 +23,9 @@ Controller::Controller (DataBase* d, QObject* parent) : QObject::connect (qmlRoot, SIGNAL (openAddService() ), this, SLOT (openAddService() ) ); QObject* humanslist = qmlRoot->findChild ("humanslist"); + QVariant model = QQmlProperty::read (humanslist, "model"); - QObject::connect (db, SIGNAL (humanChanged() ), humanslist, SLOT (dataChanged() ) ); + QObject::connect (db, SIGNAL (humanChanged() ), humanslist, SLOT (forceLayout () ) ); } @@ -31,7 +33,7 @@ Controller::Controller (DataBase* d, QObject* parent) : void Controller::openAddHuman() { QQmlComponent component (engine, QUrl (QStringLiteral ("qrc:/addhuman.qml") ), QQmlComponent::PreferSynchronous, - engine->rootObjects().first() ); + qmlRoot ); if (component.isReady() ) { QObject* dialog = component.create(); @@ -50,7 +52,7 @@ void Controller::openAddHuman() void Controller::openAddService() { QQmlComponent component (engine, QUrl (QStringLiteral ("qrc:/addservice.qml") ), QQmlComponent::PreferSynchronous, - engine->rootObjects().first() ); + qmlRoot ); if (component.isReady() ) { QObject* dialog = component.create(); diff --git a/humandatamodel.cpp b/humandatamodel.cpp index 1879f67..21c1309 100644 --- a/humandatamodel.cpp +++ b/humandatamodel.cpp @@ -40,3 +40,15 @@ QVariant HumanDataModel::data (const QModelIndex& index, int role) const } return data; } + +bool HumanDataModel::setData (const QModelIndex& index, const QVariant& value, int role) +{ + QSqlQueryModel::setData(index, value,role); + emit dataChanged(index, index); + return true; +} + +Qt::ItemFlags HumanDataModel::flags(const QModelIndex& index) const +{ + +} diff --git a/humandatamodel.h b/humandatamodel.h index c86353a..3daa8c7 100644 --- a/humandatamodel.h +++ b/humandatamodel.h @@ -6,7 +6,7 @@ #include #include "logging.h" - +// Use QSqlTableModel for human and service tables and QSqlRelationalTableModel for user class HumanDataModel : public QSqlQueryModel { public: @@ -15,6 +15,8 @@ public: QHash roleNames() const; QVariant data (const QModelIndex& model, int role) const; + bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); + Qt::ItemFlags flags (const QModelIndex& index) const; }; #endif // HUMANDATAMODEL_H diff --git a/main.qml b/main.qml index e14dba3..3e9a5ce 100644 --- a/main.qml +++ b/main.qml @@ -29,20 +29,23 @@ ApplicationWindow { } } + Button { + id: btnaddservice +// anchors.left: btnaddhuman.right + anchors.bottom: parent.bottom + anchors.right: parent.right + text: qsTr("Add Service") + onClicked: openAddService() + } + Button { id: btnaddhuman - anchors.left: parent.left anchors.bottom: parent.bottom + anchors.right: btnaddservice.left visible: true text: qsTr("Add Human") onClicked: openAddHuman() } - Button { - id: btnaddservice - anchors.left: btnaddhuman.right - anchors.bottom: parent.bottom - text: qsTr("Add Service") - onClicked: openAddService() - } + } -- 2.47.0