DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
string_attr_text_edit.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>
12#include "dbe/StyleUtility.hpp"
14
15dbe::string_attr_text_edit::string_attr_text_edit(QWidget* parent, bool IsNull, bool IsMulti)
16 : QTextEdit(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()), this, SLOT(TryValidate()));
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
73
74void
76{
77 DefaultValue = ValueDefault;
78}
79
80void
84
85void
87{
88 setProperty("loadedDefaults", Loaded);
89}
90
91void
93{
94 Validator = ValidatorSet;
95}
96
97void
102
103void
105{
106 Dec = new QAction(tr("Dec"), this);
107 Dec->setShortcutContext(Qt::WidgetShortcut);
108 connect(Dec, SIGNAL(triggered()), this, SLOT(EmitDecSlot()));
109 Dec->setCheckable(true);
110 Dec->setChecked(false);
111 ContextMenu->addAction(Dec);
112
113 Oct = new QAction(tr("Oct"), this);
114 Oct->setShortcutContext(Qt::WidgetShortcut);
115 connect(Oct, SIGNAL(triggered()), this, SLOT(EmitOctSlot()));
116 Oct->setCheckable(true);
117 Oct->setChecked(false);
118 ContextMenu->addAction(Oct);
119
120 Hex = new QAction(tr("Hex"), this);
121 Hex->setShortcutContext(Qt::WidgetShortcut);
122 Hex->setCheckable(true);
123 Hex->setChecked(false);
124 connect(Hex, SIGNAL(triggered()), this, SLOT(EmitHexSlot()));
125 ContextMenu->addAction(Hex);
126}
127
128void
130{
131 QString tmp_st = this->toPlainText();
132 int i = 0;
133
134 if (tmp_st.isEmpty() && NullCheck) {
135 Valid = false;
136
137 if (!IsMultiValue) {
139 setToolTip(QString("Field cannot be empty!"));
140 }
141
142 emit StringValidated(); // it is caught by EditStringAttrWidget
143 } else if (Validator != 0) {
144 if ((Validator->validate(tmp_st, i)) == QValidator::Acceptable) {
145 Valid = true;
146 this->setPalette(QApplication::palette(this));
147 setToolTip(QString("This new object ID is unique"));
148 } else if ((Validator->validate(tmp_st, i)) == QValidator::Intermediate) {
149 Valid = false;
150 this->setPalette(StyleUtility::AlertStatusBarPallete);
151 setToolTip(QString("This UID is already used"));
152 }
153 } else if (Validator == 0) {
154 Valid = true;
155 setPalette(QApplication::palette(this));
156
157 if (tmp_st == DefaultValue && CheckDefault) {
158 this->setPalette(StyleUtility::LoadedDefault);
159 } else {
160 this->setPalette(QApplication::palette(this));
161 }
162
163 emit StringValidated();
164 }
165}
166
167void
169{
170 Dec->setChecked(true);
171 Oct->setChecked(false);
172 Hex->setChecked(false);
173 emit DecChange();
174}
175
176void
178{
179 Dec->setChecked(false);
180 Oct->setChecked(true);
181 Hex->setChecked(false);
182 emit OctChange();
183}
184
185void
187{
188 Dec->setChecked(false);
189 Oct->setChecked(false);
190 Hex->setChecked(true);
191 emit HexChange();
192}
193
194void
196{
197 if (!PopupMenu) {
198 return;
199 }
200
201 if (ContextMenu == nullptr) {
202 ContextMenu = new QMenu(this);
204 }
205
206 ContextMenu->exec(Event->globalPos());
207}
static QPalette AlertStatusBarPallete
static QPalette LoadedDefault
static QPalette WarningStatusBarPallete
void SetDefaultValue(QString ValueDefault)
string_attr_text_edit(QWidget *parent=0, bool IsNull=true, bool IsMulti=false)
Include Qt Headers.
void contextMenuEvent(QContextMenuEvent *Event)
void SetValidator(QValidator *ValidatorSet)