Loading...
Searching...
No Matches
AddressLineEdit.hpp
1#pragma once
2#include <State/MessageListSerialization.hpp>
3#include <State/Widgets/AddressValidator.hpp>
4
5#include <Explorer/Explorer/DeviceExplorerModel.hpp>
6
7#include <QDropEvent>
8#include <QLineEdit>
9#include <QPalette>
10#include <QValidator>
11
12namespace Process
13{
19template <class Validator_T, class Parent_T>
20class AddressLineEditBase : public QLineEdit
21{
22public:
23 explicit AddressLineEditBase(Device::NodeBasedItemModel* model, QWidget* parent)
24 : QLineEdit{parent}
25 , m_model{model}
26 {
27 setAcceptDrops(true);
28 setMinimumHeight(24);
29 connect(this, &QLineEdit::textChanged, this, &AddressLineEditBase::updatePalette);
30 }
31
32 void updatePalette(const QString& str)
33 {
34 QString s = str;
35 int i = 0;
36 QPalette palette{this->palette()};
37 if(m_validator.validate(s, i) == QValidator::State::Acceptable)
38 {
39 if(m_model)
40 {
41 // Look into the tree to see if the node actually exists
42 auto addr = State::parseAddressAccessor(s);
43
44 if(Device::try_getNodeFromAddress(m_model->rootNode(), addr->address))
45 {
46 palette.setColor(QPalette::Base, QColor{"#161514"});
47 palette.setColor(QPalette::Light, QColor{"#c58014"});
48 palette.setColor(QPalette::Midlight, QColor{"#161514"});
49 }
50 else
51 {
52 palette.setColor(QPalette::Base, QColor{"#402500"});
53 palette.setColor(QPalette::Light, QColor{"#660000"});
54 palette.setColor(QPalette::Midlight, QColor{"#500000"});
55 }
56 }
57 else
58 {
59 palette.setColor(QPalette::Base, QColor{"#161514"});
60 palette.setColor(QPalette::Light, QColor{"#c58014"});
61 palette.setColor(QPalette::Midlight, QColor{"#161514"});
62 }
63 }
64 else
65 {
66 palette.setColor(QPalette::Base, QColor{"#300000"});
67 palette.setColor(QPalette::Light, QColor{"#660000"});
68 palette.setColor(QPalette::Midlight, QColor{"#500000"});
69 }
70 this->setPalette(palette);
71 }
72
73private:
74 void dragEnterEvent(QDragEnterEvent* ev) override
75 {
76 static_cast<Parent_T*>(parent())->dragEnterEvent(ev);
77 }
78 void dropEvent(QDropEvent* ev) override
79 {
80 static_cast<Parent_T*>(parent())->dropEvent(ev);
81 }
82
83 Validator_T m_validator;
85};
86
87template <typename Parent_T>
88class AddressLineEdit final
89 : public AddressLineEditBase<State::AddressValidator, Parent_T>
90{
91public:
92 using AddressLineEditBase<State::AddressValidator, Parent_T>::AddressLineEditBase;
93};
94
95template <typename Parent_T>
97 : public AddressLineEditBase<State::AddressAccessorValidator, Parent_T>
98{
99public:
101 State::AddressAccessorValidator, Parent_T>::AddressLineEditBase;
102};
103}
Definition NodeBasedItemModel.hpp:18
Definition AddressLineEdit.hpp:98
The AddressLineEdit class.
Definition AddressLineEdit.hpp:21
Definition AddressLineEdit.hpp:90
Definition AddressValidator.hpp:28
The AddressValidator class.
Definition AddressValidator.hpp:18
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324