DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CustomLineEdit.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: no.
5
7#include <QApplication>
8#include <QContextMenuEvent>
9#include <QMenu>
10#include <QValidator>
13#include "dbe/StyleUtility.hpp"
14
15dbe::CustomLineEdit::CustomLineEdit(QWidget* parent, bool IsNull, bool IsMulti)
16 : QLineEdit(parent)
17 , Valid(false)
18 , NullCheck(IsNull)
19 , CheckDefault(true)
20 , PopupMenu(false)
21 , IsMultiValue(IsMulti)
22 , ContextMenu(nullptr)
23 , Dec(nullptr)
24 , Oct(nullptr)
25 , Hex(nullptr)
26 , Validator(nullptr)
27{
28 connect(this, SIGNAL(textChanged(QString)), this, SLOT(TryValidate(QString)));
29 this->setFixedHeight(30);
30 // this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
31}
32
34{
35 if (Validator != nullptr) {
36 delete Validator;
37 }
38}
39
40void
42{
43 NullCheck = IsNull;
44
45 if (NullCheck == false) {
46 setPalette(QApplication::palette(this));
47 }
48}
49
50void
52{
53 IsMultiValue = IsMulti;
54}
55
56bool
61
62bool
67
68void
70{
71 CheckDefault = Default;
72}
73
74void
76{
77 DefaultValue = ValueDefault;
78}
79
80void
82{
83 QString Dummy("Dummy");
84 TryValidate(Dummy);
85}
86
87void
89{
90 setProperty("loadedDefaults", Loaded);
91}
92
93void
94dbe::CustomLineEdit::SetValidator(QValidator* ValidatorSet)
95{
96 Validator = ValidatorSet;
97}
98
99void
104
105void
107{
108 Dec = new QAction(tr("Dec"), this);
109 Dec->setShortcutContext(Qt::WidgetShortcut);
110 connect(Dec, SIGNAL(triggered()), this, SLOT(EmitDecSlot()));
111 Dec->setCheckable(true);
112 Dec->setChecked(false);
113 ContextMenu->addAction(Dec);
114
115 Oct = new QAction(tr("Oct"), this);
116 Oct->setShortcutContext(Qt::WidgetShortcut);
117 connect(Oct, SIGNAL(triggered()), this, SLOT(EmitOctSlot()));
118 Oct->setCheckable(true);
119 Oct->setChecked(false);
120 ContextMenu->addAction(Oct);
121
122 Hex = new QAction(tr("Hex"), this);
123 Hex->setShortcutContext(Qt::WidgetShortcut);
124 Hex->setCheckable(true);
125 Hex->setChecked(false);
126 connect(Hex, SIGNAL(triggered()), this, SLOT(EmitHexSlot()));
127 ContextMenu->addAction(Hex);
128}
129
130void
132{
133 Q_UNUSED(Dummy)
134
135 QString tmp_st = this->text();
136 int i = 0;
137
138 if (tmp_st.isEmpty() && NullCheck) {
139 Valid = false;
140
141 if (!IsMultiValue) {
143 setToolTip(QString("Field cannot be empty!"));
144 }
145
146 emit StringValidated(); // it is caught by EditStringAttrWidget
147 } else if (Validator != 0) {
148 if ((Validator->validate(tmp_st, i)) == QValidator::Acceptable) {
149 Valid = true;
150 this->setPalette(QApplication::palette(this));
151 setToolTip(QString("This new object ID is unique"));
152 } else if ((Validator->validate(tmp_st, i)) == QValidator::Intermediate) {
153 Valid = false;
154 this->setPalette(StyleUtility::AlertStatusBarPallete);
155 setToolTip(QString("This UID is already used"));
156 }
157 } else if (Validator == 0) {
158 Valid = true;
159 setPalette(QApplication::palette(this));
160
161 if (tmp_st == DefaultValue && CheckDefault) {
162 this->setPalette(StyleUtility::LoadedDefault);
163 } else {
164 this->setPalette(QApplication::palette(this));
165 }
166
167 emit StringValidated();
168 }
169}
170
171void
173{
174 Dec->setChecked(true);
175 Oct->setChecked(false);
176 Hex->setChecked(false);
177 emit DecChange();
178}
179
180void
182{
183 Dec->setChecked(false);
184 Oct->setChecked(true);
185 Hex->setChecked(false);
186 emit OctChange();
187}
188
189void
191{
192 Dec->setChecked(false);
193 Oct->setChecked(false);
194 Hex->setChecked(true);
195 emit HexChange();
196}
197
198void
200{
201 if (!PopupMenu) {
202 return;
203 }
204
205 if (ContextMenu == nullptr) {
206 ContextMenu = new QMenu(this);
208 }
209
210 ContextMenu->exec(Event->globalPos());
211}
void SetValidator(QValidator *ValidatorSet)
void SetLoadedDefaultFlag(bool Loaded)
void SetCheckDefault(bool Default)
CustomLineEdit(QWidget *parent=0, bool IsNull=true, bool IsMulti=false)
Include Qt Headers.
void SetMultiCheck(bool IsMulti)
void SetNullCheck(bool IsNull)
void contextMenuEvent(QContextMenuEvent *Event)
void SetDefaultValue(QString ValueDefault)
void TryValidate(QString Dummy)
static QPalette AlertStatusBarPallete
static QPalette LoadedDefault
static QPalette WarningStatusBarPallete