3#include "../../global.hpp"
4#include "../../genapi/value_node.hpp"
5#include "../../genapi/integer_node.hpp"
6#include "detail_property.hpp"
7#include "detail_spinbox_slider.hpp"
8#include "detail_custom_lineedit.hpp"
9#include "detail_network.hpp"
21 inline QMetaType::Type GetTypeId(
const QVariant &var)
23#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
24 return static_cast<QMetaType::Type
>(var.typeId());
26 return static_cast<QMetaType::Type
>(var.type());
30 class IntegerProperty :
public Private::Property
36 IntegerProperty(
const ValueNodePtr &node, Property *parent)
37 : Property(node, PT_Integer, parent)
40 ipList_ <<
"Std::GevCurrentIPAddress" <<
"Std::GevCurrentSubnetMask" <<
"Std::GevCurrentDefaultGateway"
41 <<
"Std::GevPersistentIPAddress" <<
"Std::GevPersistentSubnetMask"
42 <<
"Std::GevPersistentDefaultGateway" <<
"Std::GevMCDA" <<
"Std::GevSCDA"
43 <<
"Std::GevPrimaryApplicationIPAddress";
45 ipList_ <<
"Cust::InterfaceSubnetIP" <<
"Cust::InterfaceSubnetMask" <<
"Cust::InterfaceGateway"
46 <<
"Cust::IPCfg_IP" <<
"Cust::IPCfg_Subnet" <<
"Cust::IPCfg_Gateway"
47 <<
"Cust::DeviceIP" <<
"Cust::DeviceGateway" <<
"Cust::StreamDestinationIP";
50 macList_ <<
"Std::GevMACAddress";
52 macList_ <<
"Cust::GevInterfaceMACAddress" <<
"Cust::InterfaceMAC" <<
"Cust::IPCfg_MAC" <<
"Cust::DeviceMAC";
55 QWidget *CreateEditor(QWidget *parent)
override
57 auto intNode = std::dynamic_pointer_cast<IntegerNode>(Node());
62 if (!intNode->IsAvailable())
65 auto rep = intNode->Representation();
67 return CreateIpEditor(intNode, parent);
69 return CreateMacEditor(intNode, parent);
70 return CreateIntEditor(intNode, parent);
73 QWidget *CreateIntEditor(
const IntegerNodePtr &node, QWidget *parent)
76 if (node->Min() == node->Max())
78 auto editor =
new SpinBox64(parent);
79 editor->setMinimum(node->Min());
80 editor->setMaximum(node->Max());
81 editor->setValue(node->Value());
82 editor->setSingleStep(node->Increment());
84 QObject::connect(editor, &SpinBox64::ValueChanged,
this, [
this](qint64 value) { SetValue(QVariant(value)); });
89 auto editor =
new SpinBoxSlider64(parent);
90 editor->SetMinimum(node->Min());
91 editor->SetMaximum(node->Max());
92 editor->SetValue(node->Value());
93 editor->SetSingleStep(node->Increment());
95 QObject::connect(editor, &SpinBoxSlider64::ValueChanged,
this,
96 [
this](qint64 value) { SetValue(QVariant(value)); });
101 QWidget *CreateIpEditor(
const IntegerNodePtr &node, QWidget *parent)
103 auto editor =
new IpLineEdit(parent);
104 editor->SetText(QString::fromStdString(IPV4AddressIntToString(
static_cast<std::uint32_t
>(node->Value()))));
106 QObject::connect(editor, &IpLineEdit::TextChanged,
this,
107 [
this](
const QString &text) { SetValue(QVariant(text)); });
112 QWidget *CreateMacEditor(
const IntegerNodePtr &node, QWidget *parent)
114 auto editor =
new MacLineEdit(parent);
115 MacAddress mac(node->Value());
116 editor->SetText(mac.ToQString());
118 QObject::connect(editor, &MacLineEdit::TextChanged,
this,
119 [
this](
const QString &text) { SetValue(QVariant(text)); });
124 bool SetEditorData(QWidget *editor,
const QVariant &data)
override
126 auto intNode = std::dynamic_pointer_cast<IntegerNode>(Node());
131 auto rep = intNode->Representation();
134 auto le =
dynamic_cast<IpLineEdit *
>(editor);
137 le->SetText(data.toString());
143 auto le =
dynamic_cast<MacLineEdit *
>(editor);
146 le->SetText(data.toString());
152 auto sb =
dynamic_cast<SpinBoxSlider64 *
>(editor);
155 sb->SetValue(data.toInt());
162 QVariant EditorData(QWidget *editor)
override
164 auto intNode = std::dynamic_pointer_cast<IntegerNode>(Node());
166 auto rep = intNode->Representation();
169 auto le =
dynamic_cast<IpLineEdit *
>(editor);
171 return QVariant(le->Text());
175 auto le =
dynamic_cast<MacLineEdit *
>(editor);
177 return QVariant(le->Text());
181 auto sb =
dynamic_cast<SpinBoxSlider64 *
>(editor);
183 return QVariant(sb->Value());
189 QVariant Value(
int column,
int role = Qt::UserRole)
override
193 case Qt::DisplayRole:
196 return Data(column, role);
198 auto intNode = std::dynamic_pointer_cast<IntegerNode>(Node());
199 if (intNode && intNode->IsAvailable())
201 int32_t intValue = -1;
204 intValue =
static_cast<std::uint32_t
>(intNode->Value());
206 catch (
const CvbException &e)
210 return QVariant(
"-");
213 auto rep = intNode->Representation();
216 return QString::fromStdString(IPV4AddressIntToString(intValue));
220 MacAddress mac(intValue);
221 return mac.ToQString();
225 return QVariant::fromValue(intValue);
233 void SetValue(
const QVariant &value)
override
235 if (
auto intNode = std::dynamic_pointer_cast<IntegerNode>(Node()))
237 auto rep = intNode->Representation();
240 if (GetTypeId(value) == QMetaType::QString)
244 intNode->SetValue(IPV4AddressStringToInt(value.toString().toStdString()));
246 catch (
const CvbException &)
254 if (GetTypeId(value) == QMetaType::QString)
256 MacAddress mac(value.toString());
259 intNode->SetValue(mac.ToInt64());
261 catch (
const CvbException &)
269 if (GetTypeId(value) == QMetaType::LongLong)
273 intNode->SetValue(value.toLongLong());
275 catch (
const CvbException &)
284 QString HtmlDescription()
override
286 if (
auto intNode = std::dynamic_pointer_cast<IntegerNode>(Node()))
288 auto txt = QString(
"<br><table>");
289 auto min = QString(
"-");
290 auto max = QString(
"-");
291 auto rep = QString(
"-");
292 auto inc = QString(
"");
294 auto representation = intNode->Representation();
298 && macList_.contains(
UI::CvbToQt(intNode->Name())))
301 inc = QString::number(intNode->Increment());
302 min = QString::number(intNode->Min());
303 max = QString::number(intNode->Max());
305 txt.append(
"<tr><td><b>Minimum:</b></td><td align=\"right\">" + min +
"</td></tr>");
306 txt.append(
"<tr><td><b>Maximum:</b></td><td align=\"right\">" + max +
"</td></tr>");
308 txt.append(
"<tr><td><b>Increment:</b></td><td align=\"right\">" + inc +
"</td></tr>");
309 txt.append(
"<tr><td><b>Representation:</b></td><td align=\"right\">" + rep +
"</td></tr>");
310 txt.append(
"</table>");
318 QStringList macList_;
const int CVB_TIMEOUT
Timeout in function.
Definition exception.hpp:29
std::shared_ptr< IntegerNode > IntegerNodePtr
Convenience shared pointer for IntegerNode.
Definition genapi.hpp:63
std::shared_ptr< ValueNode > ValueNodePtr
Convenience shared pointer for ValueNode.
Definition genapi.hpp:91
@ MAC
MAC address in an edit control.
Definition genapi.hpp:159
@ IPv4
IPv4 address in an edit control.
Definition genapi.hpp:157
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 version.hpp:11