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
2#include <QValidator>
3#include <QApplication>
4#include <QMenu>
5#include <QContextMenuEvent>
9
10dbe::string_attr_text_edit::string_attr_text_edit ( QWidget * parent, bool IsNull, bool IsMulti )
11 : QTextEdit ( 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 ( ) ), this,
24 SLOT ( TryValidate ( ) ) );
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
68{
69 DefaultValue = ValueDefault;
70}
71
75
77{
78 setProperty ( "loadedDefaults", Loaded );
79}
80
81void dbe::string_attr_text_edit::SetValidator ( QValidator * ValidatorSet )
82{
83 Validator = ValidatorSet;
84}
85
87{
88 PopupMenu = true;
89}
90
92{
93 Dec = new QAction ( tr ( "Dec" ), this );
94 Dec->setShortcutContext ( Qt::WidgetShortcut );
95 connect ( Dec, SIGNAL ( triggered() ), this, SLOT ( EmitDecSlot() ) );
96 Dec->setCheckable ( true );
97 Dec->setChecked ( false );
98 ContextMenu->addAction ( Dec );
99
100 Oct = new QAction ( tr ( "Oct" ), this );
101 Oct->setShortcutContext ( Qt::WidgetShortcut );
102 connect ( Oct, SIGNAL ( triggered() ), this, SLOT ( EmitOctSlot() ) );
103 Oct->setCheckable ( true );
104 Oct->setChecked ( false );
105 ContextMenu->addAction ( Oct );
106
107 Hex = new QAction ( tr ( "Hex" ), this );
108 Hex->setShortcutContext ( Qt::WidgetShortcut );
109 Hex->setCheckable ( true );
110 Hex->setChecked ( false );
111 connect ( Hex, SIGNAL ( triggered() ), this, SLOT ( EmitHexSlot() ) );
112 ContextMenu->addAction ( Hex );
113}
114
116{
117 QString tmp_st = this->toPlainText();
118 int i = 0;
119
120 if ( tmp_st.isEmpty() && NullCheck )
121 {
122 Valid = false;
123
124 if ( !IsMultiValue )
125 {
126 this->setPalette ( StyleUtility::WarningStatusBarPallete );
127 setToolTip ( QString ( "Field cannot be empty!" ) );
128 }
129
130 emit StringValidated(); // it is caught by EditStringAttrWidget
131 }
132 else if ( Validator != 0 )
133 {
134 if ( ( Validator->validate ( tmp_st, i ) ) == QValidator::Acceptable )
135 {
136 Valid = true;
137 this->setPalette ( QApplication::palette ( this ) );
138 setToolTip ( QString ( "This new object ID is unique" ) );
139 }
140 else if ( ( Validator->validate ( tmp_st, i ) ) == QValidator::Intermediate )
141 {
142 Valid = false;
143 this->setPalette ( StyleUtility::AlertStatusBarPallete );
144 setToolTip ( QString ( "This UID is already used" ) );
145 }
146 }
147 else if ( Validator == 0 )
148 {
149 Valid = true;
150 setPalette ( QApplication::palette ( this ) );
151
152 if ( tmp_st == DefaultValue && CheckDefault )
153 {
154 this->setPalette ( StyleUtility::LoadedDefault );
155 }
156 else
157 {
158 this->setPalette ( QApplication::palette ( this ) );
159 }
160
161 emit StringValidated();
162 }
163}
164
166{
167 Dec->setChecked ( true );
168 Oct->setChecked ( false );
169 Hex->setChecked ( false );
170 emit DecChange();
171}
172
174{
175 Dec->setChecked ( false );
176 Oct->setChecked ( true );
177 Hex->setChecked ( false );
178 emit OctChange();
179}
180
182{
183 Dec->setChecked ( false );
184 Oct->setChecked ( false );
185 Hex->setChecked ( true );
186 emit HexChange();
187}
188
189void dbe::string_attr_text_edit::contextMenuEvent ( QContextMenuEvent * Event )
190{
191 if ( !PopupMenu )
192 {
193 return;
194 }
195
196 if ( ContextMenu == nullptr )
197 {
198 ContextMenu = new QMenu ( this );
199 CreateActions();
200 }
201
202 ContextMenu->exec ( Event->globalPos() );
203}
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)