CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
confighelpers.h
Go to the documentation of this file.
1#ifndef SRC_COMMON_CONFIGHELPERS_H_
2#define SRC_COMMON_CONFIGHELPERS_H_
3
5#include <QVariant>
6#include <QWidget>
7
8#include <map>
9#include <memory>
10#include <propertyfields.h>
11
13
14public:
15 static std::shared_ptr<QWidget> getQConfig(
16 const ComponentInterface::ComponentProperties& sp, const std::map<QString, QVariant>& properties)
17 {
18 std::shared_ptr<QWidget> q = std::make_shared<QWidget>();
19
20 QStringList props;
21 for (auto& p : sp) {
23 // property editable
24 const QString& propName = ComponentInterface::propertyName(p);
25 props.push_back(propName);
26 q->setProperty(propName.toStdString().c_str(), properties.at(propName));
27
29 QWidget* w;
30
31 if (fun) {
32 w = fun();
33 } else {
34 w = new PropertyFieldText();
35 }
36
37 w->setParent(q.get());
38 w->setObjectName(propName + "Widget");
39 }
40 }
41
42 q->setProperty("exposedProperties", props);
43
44 return q;
45 }
46
47 static void setQConfig(const QWidget& qobject, const ComponentInterface::ComponentProperties& sp,
48 std::map<QString, QVariant>& properties)
49 {
50 for (auto& p : sp) {
51 const QString& propName = ComponentInterface::propertyName(p);
52 QVariant v = qobject.property(propName.toStdString().c_str());
53 if (v.isValid() && v.type() == ComponentInterface::propertyType(p)) {
54 properties[propName] = v;
55 }
56 }
57 }
58};
59
60#endif /* SRC_COMMON_CONFIGHELPERS_H_ */
Definition confighelpers.h:12
static void setQConfig(const QWidget &qobject, const ComponentInterface::ComponentProperties &sp, std::map< QString, QVariant > &properties)
Definition confighelpers.h:47
static std::shared_ptr< QWidget > getQConfig(const ComponentInterface::ComponentProperties &sp, const std::map< QString, QVariant > &properties)
Definition confighelpers.h:15
static constexpr const CustomEditFieldCbk & propertyField(const ComponentProperty &p)
Definition componentinterface.h:84
static constexpr const QVariant::Type & propertyType(const ComponentProperty &p)
Definition componentinterface.h:74
std::vector< ComponentProperty > ComponentProperties
Definition componentinterface.h:66
static constexpr const PropertyEditable & propertyEditability(const ComponentProperty &p)
Definition componentinterface.h:79
static constexpr const QString & propertyName(const ComponentProperty &p)
Definition componentinterface.h:69
Definition propertyfields.h:17