editor.h
Go to the documentation of this file.
1 #ifndef DNAI_EDITOR_H
2 #define DNAI_EDITOR_H
3 
4 #include <queue>
5 #include <tuple>
6 
7 #include <QSettings>
8 #include "interfaces/ieditor.h"
10 #include "dnai/solution.h"
11 #include "models/entity.h"
14 #include "dnai/ml/mlhandler.h"
15 
16 namespace dnai
17 {
18  class App;
19  class Project;
20  class Session;
21 
22  namespace views {
23  class GenericNode;
24  }
25 
26  class PropertyPanelProperties : public QObject {
27  Q_OBJECT
28  Q_PROPERTY(QStringList visibility READ visibility CONSTANT)
29  Q_PROPERTY(QStringList entityType READ entityType CONSTANT)
30 
31  public:
32  explicit PropertyPanelProperties(QObject *parent = nullptr);
33 
34  const QStringList &visibility() const;
35  const QStringList &entityType() const;
36 
37  private:
38  QStringList m_visibility;
39  QStringList m_entityType;
40  };
41 
42  class Editor : public QObject, public interfaces::IEditor
43  {
44  Q_OBJECT
45  Q_PROPERTY(dnai::Solution *solution READ getSolution WRITE setSolution NOTIFY solutionChanged)
46  Q_PROPERTY(dnai::Session *session READ session CONSTANT)
47  Q_PROPERTY(dnai::PropertyPanelProperties *propertyPanelProperties READ propertyPanelProperties CONSTANT)
48  Q_PROPERTY(bool loaded READ loaded WRITE setLoaded NOTIFY loadedChanged)
49  Q_PROPERTY(QString solutionName READ solutionName)
50  Q_PROPERTY(dnai::models::ContextMenuModel *contextMenuModel READ contextMenuModel WRITE setContextMenuModel NOTIFY contextMenuModelChanged)
51  Q_PROPERTY(dnai::ml::MlHandler * mlHandler READ mlHandler CONSTANT)
52 
53  protected:
54  Editor();
55  ~Editor();
56  public:
57  Editor(Editor const&) = delete; // Copy construct
58  Editor(Editor&&) = delete; // Move construct
59  Editor& operator=(Editor const&) = delete; // Copy assign
60  Editor& operator=(Editor &&) = delete; // Move assign
61  const QString& version() const override;
62  void setVersion(const QString& version) override;
63  void save() override;
64  void restoreViewState(const QJsonObject& obj) override;
65  void saveViewState() override;
66  void closeSolution() override;
67 
68  const QList<interfaces::ICommand*>& actions() const override;
69  const QObject& selection() const override;
70  const QList<QObject*>& selections() const override;
71  interfaces::ISolution *solution() const override;
72  dnai::Solution *getSolution() const;
73  void addView(QQuickItem* v) override;
74  views::EditorView *mainView() const;
75  bool loaded() const;
76  QString const &solutionName() const;
77 
78  void loadContextMenuModel();
79  dnai::models::ContextMenuModel* contextMenuModel() const;
80  void setContextMenuModel(dnai::models::ContextMenuModel* ctx);
81  Q_INVOKABLE void updateContextMenuModel(dnai::models::Entity* entity) const;
82 
83  void setLoaded(bool);
84  Q_INVOKABLE void registerEditorView(views::EditorView *view);
85 
86  Q_INVOKABLE const QList<QQuickItem *>& views() const override;
87  Q_INVOKABLE QQuickItem *selectedView() const override;
88  Q_INVOKABLE bool isSolutionLoad() const;
89  Q_INVOKABLE void selectView(QQuickItem *i);
90  Q_INVOKABLE void createNode(dnai::models::Entity* entity, dnai::models::ContextMenuItem *node, qint32 x, qint32 y);
91 
92  Q_INVOKABLE void openSolution() override;
93  Q_INVOKABLE void loadSolution(const QString& filename) override;
94  Q_INVOKABLE void newEditor(const QString &solutionToLoad = "");
95  Q_INVOKABLE void notifyInformation(QString const &, std::function<void ()> func = [](){});
96  Q_INVOKABLE void notifySuccess(QString const &text, std::function<void ()> func = []() {});
97  Q_INVOKABLE void notifyError(QString const &text, std::function<void ()> func = []() {});
98  Q_INVOKABLE void notifyWarning(QString const &text, std::function<void ()> func = []() {});
99 
100  Q_INVOKABLE void buildSolution();
101 
102  Q_INVOKABLE void startApp();
103  Q_INVOKABLE static void checkVersion();
104  //Q_INVOKABLE static dnai::models::EntityList *entities();
105  Q_INVOKABLE void registerMainView(QObject *);
106  Q_INVOKABLE void addProject(QString const &proj_name, QString const &proj_desc);
107  Q_INVOKABLE bool createSolution(const QString &name,
108  const QString &description,
109  const QString &path,
110  const QString &proj_name,
111  const QString &proj_desc);
112  Q_INVOKABLE QQuickWindow *mainView();
113  Q_INVOKABLE QQuickItem *qmlMainView();
114  Q_INVOKABLE void registerPropertyView(QQuickItem *view);
115  Q_INVOKABLE QQuickItem* propertyView() const;
116  Q_INVOKABLE void loadFunction(dnai::models::Entity *entity) const;
117  Q_INVOKABLE QSettings *settings();
118  Q_INVOKABLE void registerSettings(QSettings *settings);
119 
120  Q_INVOKABLE bool isNewVersionAvailable() const;
121  Q_INVOKABLE qreal getSettingNumber(const QString &path);
122 
123  public:
124  void selectProject(Project *proj);
125  static Editor &instance();
126  PropertyPanelProperties *propertyPanelProperties();
127 
128  public:
129  void setSolution(dnai::Solution *sol);
130  Session *session() const;
131 
132  public:
133  void setAppName(QString const &name);
134  void setSolutionName(QString const &name);
135 
136  dnai::ml::MlHandler * mlHandler();
137 
138  signals:
139  void solutionChanged(dnai::Solution *proj);
140  void loadedChanged(bool);
141  void contextMenuModelChanged(dnai::models::ContextMenuModel *m) const;
142 
143  public:
144  Q_INVOKABLE QQuickItem * createNodeQMLComponent(dnai::models::Entity *func, dnai::models::gui::Instruction *instruction, QQuickItem *parent) const;
145  Q_INVOKABLE void setAsEntryPoint(dnai::views::GenericNode *instruction, dnai::views::GenericNode *entry);
146  Q_INVOKABLE void createFlowLink(dnai::views::GenericNode *from, dnai::views::GenericNode *to, dnai::models::Entity *func, dnai::models::gui::Instruction *fromIns, qint32 outpin, dnai::models::gui::Instruction *toIns) const;
147  Q_INVOKABLE void removeFlowLink(dnai::views::GenericNode *instruction, qint32 outpin) const;
148  Q_INVOKABLE void createIOLink(dnai::views::GenericNode *from, dnai::views::GenericNode *to, dnai::models::Entity *func, dnai::models::gui::Instruction *instr, QString input) const;
149  Q_INVOKABLE void removeIOLink(dnai::views::GenericNode *instruction, dnai::models::gui::Instruction *instr, QString input) const;
150 
151  public:
152  Q_INVOKABLE void finishInstructionBuilding(dnai::models::Entity *func, dnai::models::gui::Instruction *instr);
153 
154  public slots:
155  void onAddInstructionError(quint32 func, quint32 type, QList<quint32> const &args, QString const &msg);
156 
157  private:
159  QQuickItem * m_seletedItem = nullptr;
160  QList<QQuickItem *> m_viewZones;
161  QList<QObject*> m_selections;
162  QObject *m_selection;
163  QList<interfaces::ICommand*> m_actions;
164  QString m_version = "0.0.1";
167  QQuickWindow *m_mainView = nullptr;
168  QQuickItem* m_propertyView;
170  QString m_appname;
171  QString m_solutionName;
173  QSettings *m_settings;
175 
176  private:
177  std::queue<std::tuple<models::ContextMenuItem *, quint32, quint32>> m_pendingInstruction;
178  bool m_loaded = false;
179 
180  private:
182  };
183  }
184 
185 #endif //DNAI_EDITOR_H
interfaces::ISolution * m_solution
Definition: editor.h:158
QSettings * m_settings
Definition: editor.h:173
Definition: genericnode.h:13
Definition: toastermanagerservice.h:10
Definition: instruction.h:15
dnai::models::ContextMenuModel * m_contextMenuModel
Definition: editor.h:172
const QStringList & entityType() const
Definition: editor.h:26
Definition: session.h:8
Definition: editor.h:42
const QStringList & visibility() const
QList< QQuickItem * > m_viewZones
Definition: editor.h:160
QObject * m_selection
Definition: editor.h:162
std::queue< std::tuple< models::ContextMenuItem *, quint32, quint32 > > m_pendingInstruction
Definition: editor.h:177
Definition: solution.h:14
PropertyPanelProperties(QObject *parent=nullptr)
Definition: editor.cpp:750
Definition: contextMenuModel.h:101
QList< QObject * > m_selections
Definition: editor.h:161
Definition: mlhandler.h:10
QQuickItem * m_propertyView
Definition: editor.h:168
views::EditorView * m_editorView
Definition: editor.h:165
QStringList m_visibility
Definition: editor.h:38
Definition: isolution.h:10
QStringList m_entityType
Definition: editor.h:39
dnai::ml::MlHandler m_mlHandler
Definition: editor.h:174
Definition: api.h:13
static Editor * m_instance
Definition: editor.h:181
Definition: editorview.h:9
dnai::PropertyPanelProperties * m_propertyPanelProperties
Definition: editor.h:169
QList< interfaces::ICommand * > m_actions
Definition: editor.h:163
QString m_solutionName
Definition: editor.h:171
ToasterManagerService m_toasterManagerService
Definition: editor.h:166
Definition: entity.h:71
QString m_appname
Definition: editor.h:170