From 99162f9dcb25d755923f61e1c973a9dd46cb9d37 Mon Sep 17 00:00:00 2001 From: John Janus Date: Tue, 28 Aug 2018 22:34:05 +0200 Subject: [PATCH] fill command and commandcontroller --- cm-lib/src/controllers/commandcontroller.cpp | 40 ++++++++++++++++- cm-lib/src/controllers/commandcontroller.h | 35 +++++++++++---- cm-lib/src/framework/command.cpp | 46 +++++++++++++++++++- cm-lib/src/framework/command.h | 42 ++++++++++++++---- 4 files changed, 141 insertions(+), 22 deletions(-) diff --git a/cm-lib/src/controllers/commandcontroller.cpp b/cm-lib/src/controllers/commandcontroller.cpp index 56fb01f..9d99f64 100644 --- a/cm-lib/src/controllers/commandcontroller.cpp +++ b/cm-lib/src/controllers/commandcontroller.cpp @@ -1,6 +1,42 @@ #include "commandcontroller.h" -CommandController::CommandController(QObject *parent) : QObject(parent) -{ +#include +#include +namespace cm::controllers { + + class CommandController::Implementation { + public: + Implementation(CommandController* _commandController) + : commandController(_commandController) + { + cm::framework::Command* createClientSaveCommand = new cm::framework::Command( + commandController, QChar(0xf0c7), "Save"); + QObject::connect( createClientSaveCommand, &cm::framework::Command::executed, + commandController, &CommandController::onCreateClientSaveExecuted); + createClientViewContextCommands.append(createClientSaveCommand); + } + + CommandController* commandController{nullptr}; + + QList createClientViewContextCommands{}; + }; + + CommandController::CommandController(QObject *parent) : QObject(parent) + { + implementation.reset(new Implementation(this)); + } + + CommandController::~CommandController() + {} + + QQmlListProperty CommandController::ui_createClientViewContextCommands() + { + return QQmlListProperty(this, implementation->createClientViewContextCommands); + } + + void CommandController::onCreateClientSaveExecuted() + { + qDebug() << "You executed the Save command!"; + } } diff --git a/cm-lib/src/controllers/commandcontroller.h b/cm-lib/src/controllers/commandcontroller.h index a322c19..be38ab5 100644 --- a/cm-lib/src/controllers/commandcontroller.h +++ b/cm-lib/src/controllers/commandcontroller.h @@ -2,16 +2,33 @@ #define COMMANDCONTROLLER_H #include +#include -class CommandController : public QObject -{ - Q_OBJECT -public: - explicit CommandController(QObject *parent = nullptr); +#include "cm-lib_global.h" +#include "framework/command.h" -signals: +namespace cm::controllers { -public slots: -}; + class CMLIBSHARED_EXPORT CommandController : public QObject + { + Q_OBJECT + Q_PROPERTY(QQmlListProperty + ui_createClientViewContextCommands READ + ui_createClientViewContextCommands CONSTANT) -#endif // COMMANDCONTROLLER_H \ No newline at end of file + public: + explicit CommandController(QObject *parent = nullptr); + + ~CommandController(); + + QQmlListProperty ui_createClientViewContextCommands(); + + public slots: + void onCreateClientSaveExecuted(); + + private: + class Implementation; + QScopedPointer implementation; + }; +} +#endif // COMMANDCONTROLLER_H diff --git a/cm-lib/src/framework/command.cpp b/cm-lib/src/framework/command.cpp index 6080208..70fbcaf 100644 --- a/cm-lib/src/framework/command.cpp +++ b/cm-lib/src/framework/command.cpp @@ -1,6 +1,48 @@ #include "command.h" +#include -Command::Command(QObject *parent) : QObject(parent) -{ +namespace cm::framework { + class Command::Implementation + { + public: + Implementation(const QString& _iconCharacter, + const QString& _description, + std::function _canExecute): + iconCharacter(_iconCharacter), + description(_description), + canExecute(_canExecute) + {} + + QString iconCharacter; + QString description; + std::function canExecute; + }; + + Command::Command(QObject *parent, + const QString &iconCharacter, + const QString &description, std::function canExecute) : QObject(parent) + { + implementation.reset(new Implementation(iconCharacter, description, canExecute)); + } + + Command::~Command() + { + + } + + const QString& Command::iconCharacter() const + { + return implementation->iconCharacter; + } + + const QString& Command::description() const + { + return implementation->description; + } + + bool Command::canExecute() const + { + return implementation->canExecute(); + } } diff --git a/cm-lib/src/framework/command.h b/cm-lib/src/framework/command.h index 51f4c1a..8bf0fc6 100644 --- a/cm-lib/src/framework/command.h +++ b/cm-lib/src/framework/command.h @@ -2,16 +2,40 @@ #define COMMAND_H #include +#include +#include -class Command : public QObject -{ - Q_OBJECT -public: - explicit Command(QObject *parent = nullptr); +#include -signals: +#include "cm-lib_global.h" -public slots: -}; +namespace cm::framework { -#endif // COMMAND_H \ No newline at end of file + class CMLIBSHARED_EXPORT Command : public QObject + { + Q_OBJECT + Q_PROPERTY(QString ui_iconCharacter READ iconCharacter CONSTANT) + Q_PROPERTY(QString ui_description READ description CONSTANT) + Q_PROPERTY(bool ui_canExecute READ canExecute NOTIFY canExecuteChanged) + public: + explicit Command(QObject *parent = nullptr, + const QString& iconCharacter = "", + const QString& description = "", + std::function canExecute = []() { return true; } ); + + ~Command(); + + const QString& iconCharacter() const; + const QString& description() const; + bool canExecute() const; + + signals: + void canExecuteChanged(); + void executed(); + + private: + class Implementation; + QScopedPointer implementation; + }; +} +#endif // COMMAND_H -- 2.47.0