CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
componentinterface.h
Go to the documentation of this file.
1#ifndef __COMPONENTINTERFACE_H
2#define __COMPONENTINTERFACE_H
3
4#include <QVariant>
5#include <QtCore/QJsonObject>
6#include <functional>
7#include <map>
8#include <memory>
9
10class QWidget;
11
17
22 virtual void mainWidgetDockToggled(QWidget* widget) = 0;
23
27 virtual void stopSimulation() = 0;
28
32 virtual void startSimulation() = 0;
33
38 virtual void setConfig(const QJsonObject& json) = 0;
39
44 virtual void setConfig(const QWidget& qobject) = 0;
45
49 virtual void configChanged() = 0;
50
55 virtual QJsonObject getConfig() const = 0;
56
61 virtual std::shared_ptr<QWidget> getQConfig() const = 0;
62
63 using PropertyEditable = bool;
64 using CustomEditFieldCbk = std::function<QWidget*(void)>;
65 using ComponentProperty = std::tuple<QString, QVariant::Type, PropertyEditable, CustomEditFieldCbk>;
66 using ComponentProperties = std::vector<ComponentProperty>;
67 using PropertyContainer = std::map<QString, QVariant>;
68
69 static constexpr const QString& propertyName(const ComponentProperty& p)
70 {
71 return std::get<0>(p);
72 }
73
74 static constexpr const QVariant::Type& propertyType(const ComponentProperty& p)
75 {
76 return std::get<1>(p);
77 }
78
79 static constexpr const PropertyEditable& propertyEditability(const ComponentProperty& p)
80 {
81 return std::get<2>(p);
82 }
83
84 static constexpr const CustomEditFieldCbk& propertyField(const ComponentProperty& p)
85 {
86 return std::get<3>(p);
87 }
88
94
99 virtual QWidget* mainWidget() = 0;
100
105 virtual bool mainWidgetDocked() const = 0;
106
107 virtual void simBcastSnd(const QJsonObject &msg, const QVariant &param = QVariant()) = 0;
108 virtual void simBcastRcv(const QJsonObject &msg, const QVariant &param) = 0;
109};
110
111#endif /* !__COMPONENTINTERFACE_H */
Interface to be implemented by every component.
Definition componentinterface.h:15
virtual void startSimulation()=0
Slot to be implemented by Component to execute simulation start action.
virtual void setConfig(const QJsonObject &json)=0
Sets configuration for component.
virtual void simBcastRcv(const QJsonObject &msg, const QVariant &param)=0
virtual bool mainWidgetDocked() const =0
Main widget docking status.
static constexpr const CustomEditFieldCbk & propertyField(const ComponentProperty &p)
Definition componentinterface.h:84
bool PropertyEditable
Definition componentinterface.h:63
virtual ~ComponentInterface()
Definition componentinterface.h:16
static constexpr const QVariant::Type & propertyType(const ComponentProperty &p)
Definition componentinterface.h:74
virtual void configChanged()=0
Reconfigure component if necessary.
virtual ComponentProperties getSupportedProperties() const =0
virtual void simBcastSnd(const QJsonObject &msg, const QVariant &param=QVariant())=0
std::vector< ComponentProperty > ComponentProperties
Definition componentinterface.h:66
static constexpr const PropertyEditable & propertyEditability(const ComponentProperty &p)
Definition componentinterface.h:79
std::function< QWidget *(void)> CustomEditFieldCbk
Definition componentinterface.h:64
virtual void mainWidgetDockToggled(QWidget *widget)=0
Signal to be implemented by Component. Indicates when dock/undock action was invoked.
virtual void setConfig(const QWidget &qobject)=0
Sets configuration for component.
virtual QWidget * mainWidget()=0
Gets components's main widget.
std::tuple< QString, QVariant::Type, PropertyEditable, CustomEditFieldCbk > ComponentProperty
Definition componentinterface.h:65
std::map< QString, QVariant > PropertyContainer
Definition componentinterface.h:67
virtual QJsonObject getConfig() const =0
Gets current component configuation.
static constexpr const QString & propertyName(const ComponentProperty &p)
Definition componentinterface.h:69
virtual void stopSimulation()=0
Slot to be implemented by Component to execute simulation stop action.
virtual std::shared_ptr< QWidget > getQConfig() const =0
Gets current component configuation.