DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CustomLineEdit.cpp
Go to the documentation of this file.
1
2#include <QValidator>
3#include <QApplication>
4#include <QMenu>
5#include <QContextMenuEvent>
9
10dbe::CustomLineEdit::CustomLineEdit ( QWidget * parent, bool IsNull, bool IsMulti )
11 : QLineEdit ( parent ),
12 Valid ( false ),
13 NullCheck ( IsNull ),
14 CheckDefault ( true ),
15 PopupMenu ( false ),
16 IsMultiValue ( IsMulti ),
17 ContextMenu ( nullptr ),
18 Dec ( nullptr ),
19 Oct ( nullptr ),
20 Hex ( nullptr ),
21 Validator ( nullptr )
22{
23 connect ( this, SIGNAL ( textChanged ( QString ) ), this,
24 SLOT ( TryValidate ( QString ) ) );
25 this->setFixedHeight ( 30 );
26 //this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
27}
28
30{
31 if ( Validator != nullptr )
32 {
33 delete Validator;
34 }
35}
36
38{
39 NullCheck = IsNull;
40
41 if ( NullCheck == false )
42 {
43 setPalette ( QApplication::palette ( this ) );
44 }
45}
46
48{
49 IsMultiValue = IsMulti;
50}
51
53{
54 return NullCheck;
55}
56
58{
59 return Valid;
60}
61
63{
64 CheckDefault = Default;
65}
66
67void dbe::CustomLineEdit::SetDefaultValue ( QString ValueDefault )
68{
69 DefaultValue = ValueDefault;
70}
71
73{
74 QString Dummy ( "Dummy" );
75 TryValidate ( Dummy );
76}
77
79{
80 setProperty ( "loadedDefaults", Loaded );
81}
82
83void dbe::CustomLineEdit::SetValidator ( QValidator * ValidatorSet )
84{
85 Validator = ValidatorSet;
86}
87
89{
90 PopupMenu = true;
91}
92
94{
95 Dec = new QAction ( tr ( "Dec" ), this );
96 Dec->setShortcutContext ( Qt::WidgetShortcut );
97 connect ( Dec, SIGNAL ( triggered() ), this, SLOT ( EmitDecSlot() ) );
98 Dec->setCheckable ( true );
99 Dec->setChecked ( false );
100 ContextMenu->addAction ( Dec );
101
102 Oct = new QAction ( tr ( "Oct" ), this );
103 Oct->setShortcutContext ( Qt::WidgetShortcut );
104 connect ( Oct, SIGNAL ( triggered() ), this, SLOT ( EmitOctSlot() ) );
105 Oct->setCheckable ( true );
106 Oct->setChecked ( false );
107 ContextMenu->addAction ( Oct );
108
109 Hex = new QAction ( tr ( "Hex" ), this );
110 Hex->setShortcutContext ( Qt::WidgetShortcut );
111 Hex->setCheckable ( true );
112 Hex->setChecked ( false );
113 connect ( Hex, SIGNAL ( triggered() ), this, SLOT ( EmitHexSlot() ) );
114 ContextMenu->addAction ( Hex );
115}
116
118{
119 Q_UNUSED ( Dummy )
120
121 QString tmp_st = this->text();
122 int i = 0;
123
124 if ( tmp_st.isEmpty() && NullCheck )
125 {
126 Valid = false;
127
128 if ( !IsMultiValue )
129 {
130 this->setPalette ( StyleUtility::WarningStatusBarPallete );
131 setToolTip ( QString ( "Field cannot be empty!" ) );
132 }
133
134 emit StringValidated(); // it is caught by EditStringAttrWidget
135 }
136 else if ( Validator != 0 )
137 {
138 if ( ( Validator->validate ( tmp_st, i ) ) == QValidator::Acceptable )
139 {
140 Valid = true;
141 this->setPalette ( QApplication::palette ( this ) );
142 setToolTip ( QString ( "This new object ID is unique" ) );
143 }
144 else if ( ( Validator->validate ( tmp_st, i ) ) == QValidator::Intermediate )
145 {
146 Valid = false;
147 this->setPalette ( StyleUtility::AlertStatusBarPallete );
148 setToolTip ( QString ( "This UID is already used" ) );
149 }
150 }
151 else if ( Validator == 0 )
152 {
153 Valid = true;
154 setPalette ( QApplication::palette ( this ) );
155
156 if ( tmp_st == DefaultValue && CheckDefault )
157 {
158 this->setPalette ( StyleUtility::LoadedDefault );
159 }
160 else
161 {
162 this->setPalette ( QApplication::palette ( this ) );
163 }
164
165 emit StringValidated();
166 }
167}
168
170{
171 Dec->setChecked ( true );
172 Oct->setChecked ( false );
173 Hex->setChecked ( false );
174 emit DecChange();
175}
176
178{
179 Dec->setChecked ( false );
180 Oct->setChecked ( true );
181 Hex->setChecked ( false );
182 emit OctChange();
183}
184
186{
187 Dec->setChecked ( false );
188 Oct->setChecked ( false );
189 Hex->setChecked ( true );
190 emit HexChange();
191}
192
193void dbe::CustomLineEdit::contextMenuEvent ( QContextMenuEvent * Event )
194{
195 if ( !PopupMenu )
196 {
197 return;
198 }
199
200 if ( ContextMenu == nullptr )
201 {
202 ContextMenu = new QMenu ( this );
203 CreateActions();
204 }
205
206 ContextMenu->exec ( Event->globalPos() );
207}
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