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 <QValidator>
8#include <QApplication>
9#include <QMenu>
10#include <QContextMenuEvent>
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,
29 SLOT ( TryValidate ( QString ) ) );
30 this->setFixedHeight ( 30 );
31 //this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
32}
33
35{
36 if ( Validator != nullptr )
37 {
38 delete Validator;
39 }
40}
41
43{
44 NullCheck = IsNull;
45
46 if ( NullCheck == false )
47 {
48 setPalette ( QApplication::palette ( this ) );
49 }
50}
51
53{
54 IsMultiValue = IsMulti;
55}
56
61
63{
64 return Valid;
65}
66
68{
69 CheckDefault = Default;
70}
71
72void dbe::CustomLineEdit::SetDefaultValue ( QString ValueDefault )
73{
74 DefaultValue = ValueDefault;
75}
76
78{
79 QString Dummy ( "Dummy" );
80 TryValidate ( Dummy );
81}
82
84{
85 setProperty ( "loadedDefaults", Loaded );
86}
87
88void dbe::CustomLineEdit::SetValidator ( QValidator * ValidatorSet )
89{
90 Validator = ValidatorSet;
91}
92
97
99{
100 Dec = new QAction ( tr ( "Dec" ), this );
101 Dec->setShortcutContext ( Qt::WidgetShortcut );
102 connect ( Dec, SIGNAL ( triggered() ), this, SLOT ( EmitDecSlot() ) );
103 Dec->setCheckable ( true );
104 Dec->setChecked ( false );
105 ContextMenu->addAction ( Dec );
106
107 Oct = new QAction ( tr ( "Oct" ), this );
108 Oct->setShortcutContext ( Qt::WidgetShortcut );
109 connect ( Oct, SIGNAL ( triggered() ), this, SLOT ( EmitOctSlot() ) );
110 Oct->setCheckable ( true );
111 Oct->setChecked ( false );
112 ContextMenu->addAction ( Oct );
113
114 Hex = new QAction ( tr ( "Hex" ), this );
115 Hex->setShortcutContext ( Qt::WidgetShortcut );
116 Hex->setCheckable ( true );
117 Hex->setChecked ( false );
118 connect ( Hex, SIGNAL ( triggered() ), this, SLOT ( EmitHexSlot() ) );
119 ContextMenu->addAction ( Hex );
120}
121
123{
124 Q_UNUSED ( Dummy )
125
126 QString tmp_st = this->text();
127 int i = 0;
128
129 if ( tmp_st.isEmpty() && NullCheck )
130 {
131 Valid = false;
132
133 if ( !IsMultiValue )
134 {
135 this->setPalette ( StyleUtility::WarningStatusBarPallete );
136 setToolTip ( QString ( "Field cannot be empty!" ) );
137 }
138
139 emit StringValidated(); // it is caught by EditStringAttrWidget
140 }
141 else if ( Validator != 0 )
142 {
143 if ( ( Validator->validate ( tmp_st, i ) ) == QValidator::Acceptable )
144 {
145 Valid = true;
146 this->setPalette ( QApplication::palette ( this ) );
147 setToolTip ( QString ( "This new object ID is unique" ) );
148 }
149 else if ( ( Validator->validate ( tmp_st, i ) ) == QValidator::Intermediate )
150 {
151 Valid = false;
152 this->setPalette ( StyleUtility::AlertStatusBarPallete );
153 setToolTip ( QString ( "This UID is already used" ) );
154 }
155 }
156 else if ( Validator == 0 )
157 {
158 Valid = true;
159 setPalette ( QApplication::palette ( this ) );
160
161 if ( tmp_st == DefaultValue && CheckDefault )
162 {
163 this->setPalette ( StyleUtility::LoadedDefault );
164 }
165 else
166 {
167 this->setPalette ( QApplication::palette ( this ) );
168 }
169
170 emit StringValidated();
171 }
172}
173
175{
176 Dec->setChecked ( true );
177 Oct->setChecked ( false );
178 Hex->setChecked ( false );
179 emit DecChange();
180}
181
183{
184 Dec->setChecked ( false );
185 Oct->setChecked ( true );
186 Hex->setChecked ( false );
187 emit OctChange();
188}
189
191{
192 Dec->setChecked ( false );
193 Oct->setChecked ( false );
194 Hex->setChecked ( true );
195 emit HexChange();
196}
197
198void dbe::CustomLineEdit::contextMenuEvent ( QContextMenuEvent * Event )
199{
200 if ( !PopupMenu )
201 {
202 return;
203 }
204
205 if ( ContextMenu == nullptr )
206 {
207 ContextMenu = new QMenu ( this );
209 }
210
211 ContextMenu->exec ( Event->globalPos() );
212}
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