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