]> Johnzone git - learnqt-cm.git/commitdiff
fill command and commandcontroller
authorJohn Janus <mail@johnzone.org>
Tue, 28 Aug 2018 20:34:05 +0000 (22:34 +0200)
committerJohn Janus <mail@johnzone.org>
Tue, 28 Aug 2018 20:34:05 +0000 (22:34 +0200)
cm-lib/src/controllers/commandcontroller.cpp
cm-lib/src/controllers/commandcontroller.h
cm-lib/src/framework/command.cpp
cm-lib/src/framework/command.h

index 56fb01f10fb6f0423cdd127b6ebc43065190e050..9d99f6442eb60e18e20e922315fff79e0764019f 100644 (file)
@@ -1,6 +1,42 @@
 #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!";
+  }
 }
index a322c19d51a9bd526b4ef403b78ad3e4dcb24fb9..be38ab524b1951011e08e5de67a37d0f7a05a720 100644 (file)
@@ -2,16 +2,33 @@
 #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
index 608020894b9b6717f2209bb242522d44b3ffe4b6..70fbcafe858da772766efebcdc12e14c45f15247 100644 (file)
@@ -1,6 +1,48 @@
 #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();
+  }
 }
index 51f4c1a637945ae26f849f98d72bc58caec4bd9b..8bf0fc691afc9375f220db588803a91e919932f5 100644 (file)
@@ -2,16 +2,40 @@
 #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