CVB++ 15.0
detail_property.hpp
1#pragma once
2
3#pragma warning(push)
4#pragma warning(disable : 4800)
5#pragma warning(disable : 4251)
6#pragma warning(disable : 4244)
7#include <QObject>
8#include <QVariant>
9#include <QList>
10#include <QVector>
11#include <QFile>
12#include <QTextStream>
13#pragma warning(pop)
14
15#include "../../global.hpp"
16#include "../../genapi/value_node.hpp"
17#include "../../genapi/node_map.hpp"
18#include "../ui.hpp"
19
20#include <iostream>
21
22namespace Cvb
23{
24
25 CVB_BEGIN_INLINE_NS
26
27 namespace UI
28 {
29 namespace Private
30 {
31
32 class Property : public QObject
33 {
34
35 Q_OBJECT
36
37 public:
38 enum PropertyType
39 {
40 PT_Invalid,
41 PT_Unknown,
42 PT_Boolean,
43 PT_Category,
44 PT_Command,
45 PT_Enumeration,
46 PT_EnumEntry,
47 PT_Float,
48 PT_Integer,
49 PT_String,
50 PT_Port,
51 PT_Node
52 };
53
54 public:
55 explicit Property(const NodePtr &node, PropertyType type = PT_Unknown, Property *parent = 0)
56 : parent_(parent)
57 , node_(node)
58 , type_(type)
59 {
60 children_ = QList<Property *>();
61 if (node_)
62 {
63 itemData_ << UI::CvbToQt(node_->DisplayName());
64 eventCookie_ = node_->RegisterEventUpdated([this](const GenApi::Node &value) { OnNodeUpdated(value); });
65 }
66 }
67
68 Property(const Property &other) = delete;
69 Property &operator=(const Property &other) = delete;
70 Property(Property &&other) = delete;
71 Property &operator=(Property &&other) = delete;
72 virtual ~Property()
73 {
74 qDeleteAll(children_);
75 parent_ = 0;
76 if (node_)
77 {
78 node_->UnregisterEventUpdated(eventCookie_);
79 node_.reset();
80 }
81 }
82
83 int ChildCount() const
84 {
85 return children_.size();
86 }
87
88 int ColumnCount() const
89 {
90 return itemData_.size();
91 }
92
93 Property *Child(int number)
94 {
95 return children_.value(number);
96 }
97
98 Property *Parent()
99 {
100 return parent_;
101 }
102
103 int Position()
104 {
105 if (parent_)
106 return parent_->children_.indexOf(this);
107 return 0;
108 }
109
110 QVariant Data(int column, int /*role = Qt::UserRole*/) const
111 {
112 if (column < itemData_.size())
113 return itemData_.value(column);
114 return QVariant();
115 }
116
117 bool InsertChild(int position, Property *child)
118 {
119 if (position < 0 || position > children_.size())
120 return false;
121
122 children_.insert(position, child);
123 return true;
124 }
125
126 NodePtr Node() const
127 {
128 return node_;
129 }
130
131 String NodeType() const
132 {
133 if (auto catNode = std::dynamic_pointer_cast<CategoryNode>(node_))
134 return CVB_LIT("Category");
135 else if (auto strNode = std::dynamic_pointer_cast<StringNode>(node_))
136 return CVB_LIT("String");
137 else if (auto cmdNode = std::dynamic_pointer_cast<CommandNode>(node_))
138 return CVB_LIT("Command");
139 else if (auto fNode = std::dynamic_pointer_cast<FloatNode>(node_))
140 return CVB_LIT("Float");
141 else if (auto boolNode = std::dynamic_pointer_cast<BooleanNode>(node_))
142 return CVB_LIT("Boolean");
143 else if (auto enumNode = std::dynamic_pointer_cast<EnumerationNode>(node_))
144 return CVB_LIT("Enumeration");
145 else if (auto enumEntryNode = std::dynamic_pointer_cast<EnumEntryNode>(node_))
146 return CVB_LIT("Enumeration Entry");
147 else if (auto iNode = std::dynamic_pointer_cast<IntegerNode>(node_))
148 return CVB_LIT("Integer");
149 else
150 return CVB_LIT("Unknown");
151 }
152
153 String NodeAccessMode() const
154 {
155 if (!node_)
156 return CVB_LIT("");
157
158 switch (node_->AccessMode())
159 {
161 return CVB_LIT("Not implemented");
163 return CVB_LIT("Not available");
165 return CVB_LIT("Read only");
167 return CVB_LIT("Read/Write");
169 return CVB_LIT("Write only");
170 default:
171 return CVB_LIT("");
172 }
173 }
174
175 String NodeVisibility() const
176 {
177 if (!node_)
178 return CVB_LIT("");
179
180 switch (node_->Visibility())
181 {
183 return CVB_LIT("Beginner");
185 return CVB_LIT("Expert");
187 return CVB_LIT("Guru");
189 return CVB_LIT("Invisible");
190 default:
191 return CVB_LIT("");
192 }
193 }
194
195 String NodeCachingMode() const
196 {
197 if (!node_)
198 return CVB_LIT("");
199
200 switch (node_->CacheMode())
201 {
203 return CVB_LIT("No Cache");
205 return CVB_LIT("Write Around");
207 return CVB_LIT("Write Through");
208 default:
209 return CVB_LIT("");
210 }
211 }
212
213 String NodeRepresentation(GenApi::NumberRepresentation representation) const
214 {
215 switch (representation)
216 {
218 return CVB_LIT("Boolean");
220 return CVB_LIT("Hexadecimal Number");
222 return CVB_LIT("IPv4 Address");
224 return CVB_LIT("Linear");
226 return CVB_LIT("Logarithmic");
228 return CVB_LIT("MAC Address");
230 return CVB_LIT("Pure Number");
232 default:
233 return CVB_LIT("Undefined");
234 }
235 }
236
237 PropertyType Type() const
238 {
239 return type_;
240 }
241
242 bool IsRoot() const
243 {
244 return (parent_ == 0);
245 }
246
247 bool NodeHasPolling() const
248 {
249 if (auto n = std::dynamic_pointer_cast<ValueNode>(node_))
250 {
251 return (n->PollingTime() > std::chrono::milliseconds(0));
252 }
253 return false;
254 }
255
256 bool NodeIsStreamable() const
257 {
258 if (auto n = std::dynamic_pointer_cast<ValueNode>(node_))
259 {
260 return (n->IsStreamable());
261 }
262 return false;
263 }
264
265 int FindChildProperty(const NodePtr &node)
266 {
267 for (int i = 0; i < children_.size(); i++)
268 {
269 auto child = children_.at(i);
270 if (child && child->Node() == node)
271 return i;
272 }
273 return -1;
274 }
275
276 Property *ChildProperty(int position)
277 {
278 if (position < children_.size())
279 return children_.at(position);
280 return 0;
281 }
282
283 void RemoveChild(int position)
284 {
285 auto p = ChildProperty(position);
286 if (p)
287 {
288 children_.removeAt(position);
289 delete p; // NOLINT(cppcoreguidelines-owning-memory)
290 p = 0;
291 }
292 }
293
294 QWidget *EmptyEditor()
295 {
296 QWidget *editor = 0;
297 return editor;
298 }
299
300 void OnNodeUpdated(const GenApi::Node & /*node*/)
301 {
302 NodeUpdated(this); // send signal
303 }
304
305 bool IsReadOnly()
306 {
307 if (node_)
308 {
309 if (!node_->IsWriteable() || !node_->IsAvailable())
310 return true;
311 }
312 return false;
313 }
314
315 virtual QVariant Value(int column, int role = Qt::UserRole) = 0;
316 virtual void SetValue(const QVariant &value) = 0;
317 virtual QWidget *CreateEditor(QWidget *parent) = 0;
318 virtual bool SetEditorData(QWidget *editor, const QVariant &data) = 0;
319 virtual QVariant EditorData(QWidget *editor) = 0;
320 virtual QString HtmlDescription() = 0;
321
322 Q_SIGNALS:
323
324 void NodeUpdated(Property *p);
325 void TimeoutOccurred();
326
327 private:
328 QList<Property *> children_;
329 PropertyType type_;
330 Property *parent_;
331 NodePtr node_;
332 QVector<QVariant> itemData_;
333 EventCookie eventCookie_;
334
335 }; /* class PropertyModel */
336
337 } /* namespace Private */
338 } /* namespace UI */
339
340 CVB_END_INLINE_NS
341
342} /* namespace Cvb */
std::shared_ptr< Node > NodePtr
Convenience shared pointer for Node.
Definition genapi.hpp:71
@ Expert
More complex feature, that requires deeper knowledge about the feature.
Definition genapi.hpp:244
@ Beginner
Simple feature usable by everybody.
Definition genapi.hpp:242
@ Guru
Definition genapi.hpp:251
@ Invisible
Node should not be displayed.
Definition genapi.hpp:240
@ NoCache
No caching used.
Definition genapi.hpp:225
@ WriteAround
Write to register, cache written on next read.
Definition genapi.hpp:229
@ WriteThrough
Write to cache and register.
Definition genapi.hpp:227
@ ReadOnly
Node can only be read.
Definition genapi.hpp:214
@ NotAvailable
Definition genapi.hpp:202
@ WriteOnly
Node can only be written to.
Definition genapi.hpp:216
@ ReadWrite
Node can be read and written to.
Definition genapi.hpp:218
@ NotImplemented
Definition genapi.hpp:196
NumberRepresentation
Defines how a number is to be interpreted/displayed in a graphical user interface.
Definition genapi.hpp:143
@ Boolean
True / False representation.
Definition genapi.hpp:151
@ MAC
MAC address in an edit control.
Definition genapi.hpp:159
@ Logarithmic
Slider with logarithmic behavior.
Definition genapi.hpp:149
@ Linear
Slider with linear behavior.
Definition genapi.hpp:147
@ IPv4
IPv4 address in an edit control.
Definition genapi.hpp:157
@ HexNumber
Hex number in an edit control.
Definition genapi.hpp:155
@ PureNumber
Decimal number in an edit control.
Definition genapi.hpp:153
@ Undefined
Not set in XML (treated as linear)
Definition genapi.hpp:145
Namespace for user interface components.
Definition decl_image_scene.hpp:39
QString CvbToQt(const Cvb::String &text) noexcept
Convenience converter for strings.
Definition ui.hpp:257
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49