CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
pcimpl.h
Go to the documentation of this file.
1#ifndef __PCIMPL_H
2#define __PCIMPL_H
3
4#include <QObject>
5#include <QMenu>
6#include "pcinterface.h"
8#include "componentmodel.h"
10
11class PCImpl : public PCInterface {
12public:
13 virtual void setNodeCreatedCallback(QtNodes::FlowScene* scene, const node_t& cb) override
14 {
15 QObject::connect(scene, &QtNodes::FlowScene::nodeCreated, cb);
16 }
17
18 virtual void setNodeDeletedCallback(QtNodes::FlowScene* scene, const node_t& cb) override
19 {
20 QObject::connect(scene, &QtNodes::FlowScene::nodeDeleted, cb);
21 }
22
23 virtual void setNodeDoubleClickedCallback(QtNodes::FlowScene* scene, const node_t& cb) override
24 {
25 QObject::connect(scene, &QtNodes::FlowScene::nodeDoubleClicked, cb);
26 }
27
28 virtual void setNodeContextMenuCallback(QtNodes::FlowScene* scene, const menu_t& cb) override
29 {
30 QObject::connect(scene, &QtNodes::FlowScene::nodeContextMenu, cb);
31 }
32
33 virtual void setConfigChangedCbk(const node_t cb) override
34 {
35 _configUpdated = cb;
36 }
37
38 virtual void openProperties(QtNodes::Node& node) override
39 {
40 auto& component = getComponent(node);
41 auto conf = component.getQConfig();
42 conf->setProperty("name", node.nodeDataModel()->caption());
43
44 PropertyEditorDialog e(node.nodeDataModel()->name() + " properties", *conf.get());
45 if (e.exec() == QDialog::Accepted) {
46 auto& iface = getComponentModel(node);
47 conf = e.properties();
48 auto nodeCaption = conf->property("name");
49 if (nodeCaption.isValid()) {
50 iface.setCaption(nodeCaption.toString());
51 node.nodeGraphicsObject().update();
52 }
53
54 component.setConfig(*conf);
55 component.configChanged();
56
57 _configUpdated(node);
58 }
59 }
60
61 virtual void showContextMenu(QMenu &menu, const QPoint& pos) override
62 {
63 auto pos1 = pos;
64 pos1.setX(pos1.x() + 32); // FIXME: these values are hardcoded and should not be here
65 pos1.setY(pos1.y() + 10); // find the real cause of misalignment of context menu
66 menu.exec(pos1);
67 }
68
69private:
70 node_t _configUpdated;
71
72 ComponentInterface& getComponent(QtNodes::Node& node)
73 {
74 auto& iface = getComponentModel(node);
75 auto& component = iface.getComponent();
76 return component;
77 }
78
79 ComponentModelInterface& getComponentModel(QtNodes::Node& node)
80 {
81 auto dataModel = node.nodeDataModel();
82 assert(nullptr != dataModel);
83
84 auto iface = dynamic_cast<ComponentModelInterface*>(dataModel);
85 return *iface;
86 }
87};
88
89#endif /* !__PCIMPL_H */
Definition pcimpl.h:11
virtual void setNodeCreatedCallback(QtNodes::FlowScene *scene, const node_t &cb) override
Definition pcimpl.h:13
virtual void setNodeDeletedCallback(QtNodes::FlowScene *scene, const node_t &cb) override
Definition pcimpl.h:18
virtual void setNodeDoubleClickedCallback(QtNodes::FlowScene *scene, const node_t &cb) override
Definition pcimpl.h:23
virtual void setConfigChangedCbk(const node_t cb) override
Definition pcimpl.h:33
virtual void openProperties(QtNodes::Node &node) override
Definition pcimpl.h:38
virtual void showContextMenu(QMenu &menu, const QPoint &pos) override
Definition pcimpl.h:61
virtual void setNodeContextMenuCallback(QtNodes::FlowScene *scene, const menu_t &cb) override
Definition pcimpl.h:28
Definition propertyeditordialog.h:18
std::shared_ptr< QWidget > properties()
Definition propertyeditordialog.cpp:25
Interface to be implemented by every component.
Definition componentinterface.h:15
Definition componentmodel.h:15
Definition pcinterface.h:16
std::function< void(QtNodes::Node &)> node_t
Definition pcinterface.h:21
std::function< void(QtNodes::Node &, const QPointF &)> menu_t
Definition pcinterface.h:22