1#ifndef COMPONENTMODEL_H
2#define COMPONENTMODEL_H
5#include <QtCore/QObject>
6#include <QtWidgets/QLabel>
11#include <nodes/NodeDataModel>
26 virtual void initModel(QtNodes::Node& node,
int nodeCnt,
bool darkMode) = 0;
27 virtual void simBcastRcv(
const QJsonObject& msg,
const QVariant& param) = 0;
34 void simBcastSnd(
const QJsonObject& msg,
const QVariant& param);
56 virtual void initModel(QtNodes::Node& node,
int nodeCnt,
bool darkMode)
override
59 setCaption(node.nodeDataModel()->caption() +
" #" + QString::number(nodeCnt));
67 connect((Derived*)
this, &Derived::requestRedraw, [&node] { node.nodeGraphicsObject().update(); });
76 _thread = std::make_unique<QThread>();
78 cds_info(
"Setting separate event loop for component {}",
_caption.toStdString());
80 this->moveToThread(
_thread.get());
115 virtual QString
name()
const override
124 virtual std::unique_ptr<QtNodes::NodeDataModel>
clone()
const override
126 return std::make_unique<Derived>();
133 virtual QJsonObject
save()
const override
136 json[
"name"] =
name();
145 virtual void restore(QJsonObject
const& json)
override
147 if (json.find(
"name") == json.end()) {
148 cds_error(
"Problem with validation of restore configuration: component model name tag not exist.");
152 if (json.find(
"caption") == json.end()) {
153 cds_error(
"Problem with validation of restore configuration: component model caption tag not exist.");
158 _name = json.find(
"name").value().toString();
159 _caption = json.find(
"caption").value().toString();
162 cds_info(
"Correct validation of restore configuration for {} modul",
_name.toStdString());
202 QColor bgColor = QColor(94, 94, 94);
209 _nodeStyle.FontColorFaded = QColor(125, 125, 125);
211 _nodeStyle.ConnectionPointColor = QColor(125, 125, 125);
212 _nodeStyle.FilledConnectionPointColor = QColor(206, 206, 206);
214 QColor bgColor = QColor(255, 255, 255);
221 _nodeStyle.FontColorFaded = QColor(189, 189, 189);
222 _nodeStyle.ShadowColor = QColor(170, 170, 170);
223 _nodeStyle.ConnectionPointColor = QColor(170, 170, 170);
224 _nodeStyle.FilledConnectionPointColor = QColor(110, 110, 110);
227 _nodeStyle.SelectedBoundaryColor = QColor(20, 146, 202);
242 void simBcastRcv(
const QJsonObject& msg,
const QVariant& param)
override
244 if (msg[
"id"].toString() !=
_id.toString()) {
246 }
else if (msg[
"msg"].toString() == BcastMsg::NodeCreated) {
247 QJsonObject msg2 = msg;
248 msg2[
"msg"] = BcastMsg::InitDone;
259 QJsonObject fillBcastMsg(
const QJsonObject& msg)
261 QJsonObject ret(msg);
263 ret[
"id"] =
_id.toString();
264 ret[
"name"] =
name();
Definition componentmodel.h:37
virtual ~ComponentModel()
Definition componentmodel.h:48
ComponentModel(const QString &name)
Definition componentmodel.h:42
QLabel * _label
Definition componentmodel.h:272
virtual QString name() const override
Used to identify model by data model name.
Definition componentmodel.h:115
bool _restored
Definition componentmodel.h:276
void simBcastSndSlot(const QJsonObject &msg, const QVariant ¶m) override
Definition componentmodel.h:253
C _component
Definition componentmodel.h:271
bool _resizable
Definition componentmodel.h:275
QUuid _id
Definition componentmodel.h:280
QString _caption
Definition componentmodel.h:273
virtual void setColorMode(bool darkMode) override
Definition componentmodel.h:197
bool _darkMode
Definition componentmodel.h:277
std::unique_ptr< QThread > _thread
Definition componentmodel.h:279
virtual void setCaption(const QString &caption) override
Sets model caption and updates widget title.
Definition componentmodel.h:101
virtual bool restored() override
Definition componentmodel.h:192
virtual QString caption() const override
Used to get node caption.
Definition componentmodel.h:92
virtual bool resizable() const override
Used to get information if node is resizable.
Definition componentmodel.h:178
QtNodes::NodeStyle _nodeStyle
Definition componentmodel.h:278
void simBcastRcv(const QJsonObject &msg, const QVariant ¶m) override
Definition componentmodel.h:242
virtual ComponentInterface & getComponent() override
Component getter.
Definition componentmodel.h:187
virtual std::unique_ptr< QtNodes::NodeDataModel > clone() const override
Creates new node of the same type.
Definition componentmodel.h:124
virtual QWidget * embeddedWidget() override
Used to get widget embedded in Node.
Definition componentmodel.h:169
virtual bool hasSeparateThread() const override
Definition componentmodel.h:236
virtual void initModel(QtNodes::Node &node, int nodeCnt, bool darkMode) override
Definition componentmodel.h:56
virtual void restore(QJsonObject const &json) override
Used to restore node configurations.
Definition componentmodel.h:145
virtual QJsonObject save() const override
Possibility to save node properties.
Definition componentmodel.h:133
QString _name
Definition componentmodel.h:274
#define cds_error(fmt,...)
Definition log.h:21
#define cds_info(fmt,...)
Definition log.h:25
Interface to be implemented by every component.
Definition componentinterface.h:15
Definition componentmodel.h:15
virtual void initModel(QtNodes::Node &node, int nodeCnt, bool darkMode)=0
virtual void simBcastRcv(const QJsonObject &msg, const QVariant ¶m)=0
virtual ComponentInterface & getComponent()=0
virtual ~ComponentModelInterface()=default
void handleDock(QWidget *widget)
virtual void setCaption(const QString &caption)=0
virtual bool restored()=0
virtual void setColorMode(bool darkMode)=0
virtual void simBcastSndSlot(const QJsonObject &msg, const QVariant ¶m)=0
void simBcastSnd(const QJsonObject &msg, const QVariant ¶m)
virtual bool hasSeparateThread() const =0