From: John Janus Date: Mon, 6 Mar 2017 16:10:00 +0000 (+0100) Subject: small changes and todos... X-Git-Url: https://git.johnzone.org/?a=commitdiff_plain;h=0211037e649e21ba58e6b0d6c4fb664cc9b986b3;p=UserSheets.git small changes and todos... --- 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() - } + }