From: John Janus Date: Wed, 15 Aug 2018 20:15:19 +0000 (+0200) Subject: finish chapter 3 user interface X-Git-Url: https://git.johnzone.org/?a=commitdiff_plain;h=c8aba8f8a9e9d277ebc7adceeb652985be63ad46;p=learnqt-cm.git finish chapter 3 user interface --- diff --git a/cm-lib/cm-lib.pro b/cm-lib/cm-lib.pro index e7987f6..4ca5c40 100644 --- a/cm-lib/cm-lib.pro +++ b/cm-lib/cm-lib.pro @@ -36,7 +36,8 @@ SOURCES += \ HEADERS += \ src/models/client.h \ src/cm-lib_global.h \ - src/controllers/master-controller.h + src/controllers/master-controller.h \ + src/controllers/navigation-controller.h unix { target.path = /usr/lib diff --git a/cm-lib/src/controllers/master-controller.cpp b/cm-lib/src/controllers/master-controller.cpp index 9601bc4..a1bf6f6 100644 --- a/cm-lib/src/controllers/master-controller.cpp +++ b/cm-lib/src/controllers/master-controller.cpp @@ -1,9 +1,39 @@ #include "master-controller.h" namespace cm::controllers { -MasterController::MasterController(QObject *parent) : QObject(parent) -{ -} + class MasterController::Implementation + { + public: + Implementation(MasterController* _masterController) + : masterController(_masterController) + { + navigationController = new NavigationController(_masterController); + } + + MasterController* masterController{nullptr}; + NavigationController* navigationController{nullptr}; + QString welcomeMessage = "This is MasterController to Major Tom"; + }; + + MasterController::MasterController(QObject *parent) : QObject(parent) + { + implementation.reset(new Implementation(this)); + } + + MasterController::~MasterController() + { + + } + + NavigationController* MasterController::navigationController() + { + return implementation->navigationController; + } + + const QString& MasterController::welcomeMessage() const + { + return implementation->welcomeMessage; + } } diff --git a/cm-lib/src/controllers/master-controller.h b/cm-lib/src/controllers/master-controller.h index 791dc5c..6856512 100644 --- a/cm-lib/src/controllers/master-controller.h +++ b/cm-lib/src/controllers/master-controller.h @@ -2,23 +2,29 @@ #define MASTERCONTROLLER_H #include +#include #include -#include +#include "cm-lib_global.h" +#include "controllers/navigation-controller.h" namespace cm::controllers { class CMLIBSHARED_EXPORT MasterController : public QObject { Q_OBJECT - Q_PROPERTY(QString ui_welcomeMessage MEMBER welcomeMessage CONSTANT) + Q_PROPERTY( QString ui_welcomeMessage READ welcomeMessage CONSTANT ) + Q_PROPERTY( cm::controllers::NavigationController* ui_navigationController READ navigationController CONSTANT ) + public: explicit MasterController(QObject *parent = nullptr); - QString welcomeMessage = "This is MasterController to Major Tom"; - -signals: + ~MasterController(); + NavigationController* navigationController(); + const QString& welcomeMessage() const; -public slots: +private: + class Implementation; + QScopedPointer implementation; }; } diff --git a/cm-lib/src/controllers/navigation-controller.h b/cm-lib/src/controllers/navigation-controller.h new file mode 100644 index 0000000..7d876a1 --- /dev/null +++ b/cm-lib/src/controllers/navigation-controller.h @@ -0,0 +1,27 @@ +#ifndef NAVIGATIONCONTROLLER_H +#define NAVIGATIONCONTROLLER_H + +#include + +#include "cm-lib_global.h" +#include "models/client.h" + +namespace cm::controllers { + class CMLIBSHARED_EXPORT NavigationController : public QObject + { + Q_OBJECT + + public: + explicit NavigationController(QObject* _parent = nullptr) + : QObject(_parent) + {} + + signals: + void goCreateClientView(); + void goDashboardView(); + void goEditClientView(cm::models::Client* client); + void goFindClientView(); + + }; +} +#endif // NAVIGATIONCONTROLLER_H diff --git a/cm-lib/src/models/client.cpp b/cm-lib/src/models/client.cpp index 5e8dcfb..e20037a 100644 --- a/cm-lib/src/models/client.cpp +++ b/cm-lib/src/models/client.cpp @@ -1,6 +1,7 @@ #include "client.h" - -Client::Client() -{ +namespace cm::models { + Client::Client() + { + } } diff --git a/cm-lib/src/models/client.h b/cm-lib/src/models/client.h index d917e02..098d11b 100644 --- a/cm-lib/src/models/client.h +++ b/cm-lib/src/models/client.h @@ -3,11 +3,13 @@ #include "cm-lib_global.h" +namespace cm::models { + class CMLIBSHARED_EXPORT Client { public: Client(); }; - +} #endif // CLIENT_H diff --git a/cm-ui/src/main.cpp b/cm-ui/src/main.cpp index e390e7e..1a78b0e 100644 --- a/cm-ui/src/main.cpp +++ b/cm-ui/src/main.cpp @@ -11,6 +11,7 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); qmlRegisterType("CM", 1, 0, "MasterController"); + qmlRegisterType("CM", 1, 0, "NavigationController"); cm::controllers::MasterController masterController; QQmlApplicationEngine engine; diff --git a/cm-ui/views/CreateClientView.qml b/cm-ui/views/CreateClientView.qml index 9c36e13..3086c3e 100644 --- a/cm-ui/views/CreateClientView.qml +++ b/cm-ui/views/CreateClientView.qml @@ -1,5 +1,13 @@ -import QtQuick 2.0 +import QtQuick 2.10 Item { + Rectangle { + anchors.fill: parent + color: "#f4c842" + Text { + anchors.centerIn: parent + text: "Create Client View" + } + } } diff --git a/cm-ui/views/DashboardView.qml b/cm-ui/views/DashboardView.qml index 9c36e13..21ea5cf 100644 --- a/cm-ui/views/DashboardView.qml +++ b/cm-ui/views/DashboardView.qml @@ -1,5 +1,13 @@ -import QtQuick 2.0 +import QtQuick 2.10 Item { + Rectangle { + anchors.fill: parent + color: "#208010" + Text { + anchors.centerIn: parent + text: "Dashboard View" + } + } } diff --git a/cm-ui/views/EditClientView.qml b/cm-ui/views/EditClientView.qml index 9c36e13..00e507a 100644 --- a/cm-ui/views/EditClientView.qml +++ b/cm-ui/views/EditClientView.qml @@ -1,5 +1,13 @@ -import QtQuick 2.0 +import QtQuick 2.10 Item { + Rectangle { + anchors.fill: parent + color: "#f4c842" + Text { + anchors.centerIn: parent + text: "Edit Client View" + } + } } diff --git a/cm-ui/views/FindClientView.qml b/cm-ui/views/FindClientView.qml index 9c36e13..f313b10 100644 --- a/cm-ui/views/FindClientView.qml +++ b/cm-ui/views/FindClientView.qml @@ -1,5 +1,13 @@ -import QtQuick 2.0 +import QtQuick 2.10 Item { + Rectangle { + anchors.fill: parent + color: "#f4c842" + Text { + anchors.centerIn: parent + text: "Find Client View" + } + } } diff --git a/cm-ui/views/MasterView.qml b/cm-ui/views/MasterView.qml index efb366b..b929166 100644 --- a/cm-ui/views/MasterView.qml +++ b/cm-ui/views/MasterView.qml @@ -1,5 +1,6 @@ import QtQuick 2.10 import QtQuick.Window 2.10 +import QtQuick.Controls 2.2 Window { visible: true @@ -7,7 +8,56 @@ Window { height: 480 title: qsTr("Client Management") - Text { - text: masterController.ui_welcomeMessage + Connections { + target: masterController.ui_navigationController + onGoCreateClientView: contentFrame.replace(Qt.resolvedUrl("qrc:/views/CreateClientView.qml")) + onGoDashboardView: contentFrame.replace(Qt.resolvedUrl("qrc:/views/DashboardView.qml")) + onGoEditClientView: contentFrame.replace(Qt.resolvedUrl("qrc:/views/EditClientView.qml"), { selectedClient: client }) + onGoFindClientView: contentFrame.replace(Qt.resolvedUrl("qrc:/views/FindClientView.qml")) } + + Rectangle { + id: navigationBar + anchors { + top: parent.top + bottom: parent.bottom + left: parent.left + } + width: 100 + color:"#000000" + Column { + + Button { + text: "Dashboard" + onClicked: masterController.ui_navigationController.goDashboardView() + } + + Button { + text: "New Client" + onClicked: masterController.ui_navigationController.goCreateClientView() + } + + Button { + text: "Find Client" + onClicked: masterController.ui_navigationController.goFindClientView() + } + + } + } + + StackView { + id: contentFrame + clip: true + anchors{ + top: parent.top + left: navigationBar.right + bottom: parent.bottom + right: parent.right + } + + initialItem: Qt.resolvedUrl("qrc:/views/SplashView.qml") + } + + Component.onCompleted: + contentFrame.replace(Qt.resolvedUrl("qrc:/views/DashboardView.qml")) } diff --git a/cm-ui/views/SplashView.qml b/cm-ui/views/SplashView.qml index 9c36e13..9c3fcb0 100644 --- a/cm-ui/views/SplashView.qml +++ b/cm-ui/views/SplashView.qml @@ -1,5 +1,13 @@ -import QtQuick 2.0 +import QtQuick 2.10 Item { + Rectangle { + anchors.fill: parent + color: "#f4c842" + Text { + anchors.centerIn: parent + text: "Splash View" + } + } } diff --git a/qmake-destination-path.pri b/qmake-destination-path.pri index 9d942d6..940b490 100644 --- a/qmake-destination-path.pri +++ b/qmake-destination-path.pri @@ -28,7 +28,7 @@ COMPILER_CLANG { } PROCESSOR_x64 { - processor_path = x64 + processor_path = x86_64 } PROCESSOR_x86 {