#include "commandcontroller.h"
-CommandController::CommandController(QObject *parent) : QObject(parent)
-{
+#include <QList>
+#include <QDebug>
+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<cm::framework::Command*> createClientViewContextCommands{};
+ };
+
+ CommandController::CommandController(QObject *parent) : QObject(parent)
+ {
+ implementation.reset(new Implementation(this));
+ }
+
+ CommandController::~CommandController()
+ {}
+
+ QQmlListProperty<cm::framework::Command> CommandController::ui_createClientViewContextCommands()
+ {
+ return QQmlListProperty<cm::framework::Command>(this, implementation->createClientViewContextCommands);
+ }
+
+ void CommandController::onCreateClientSaveExecuted()
+ {
+ qDebug() << "You executed the Save command!";
+ }
}
#define COMMANDCONTROLLER_H
#include <QObject>
+#include <QtQml/QQmlListProperty>
-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<cm::framework::Command>
+ ui_createClientViewContextCommands READ
+ ui_createClientViewContextCommands CONSTANT)
-#endif // COMMANDCONTROLLER_H
\ No newline at end of file
+ public:
+ explicit CommandController(QObject *parent = nullptr);
+
+ ~CommandController();
+
+ QQmlListProperty<framework::Command> ui_createClientViewContextCommands();
+
+ public slots:
+ void onCreateClientSaveExecuted();
+
+ private:
+ class Implementation;
+ QScopedPointer<Implementation> implementation;
+ };
+}
+#endif // COMMANDCONTROLLER_H
#include "command.h"
+#include <QtDebug>
-Command::Command(QObject *parent) : QObject(parent)
-{
+namespace cm::framework {
+ class Command::Implementation
+ {
+ public:
+ Implementation(const QString& _iconCharacter,
+ const QString& _description,
+ std::function<bool()> _canExecute):
+ iconCharacter(_iconCharacter),
+ description(_description),
+ canExecute(_canExecute)
+ {}
+
+ QString iconCharacter;
+ QString description;
+ std::function<bool()> canExecute;
+ };
+
+ Command::Command(QObject *parent,
+ const QString &iconCharacter,
+ const QString &description, std::function<bool()> 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();
+ }
}
#define COMMAND_H
#include <QObject>
+#include <QScopedPointer>
+#include <QString>
-class Command : public QObject
-{
- Q_OBJECT
-public:
- explicit Command(QObject *parent = nullptr);
+#include <functional>
-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<bool()> 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> implementation;
+ };
+}
+#endif // COMMAND_H