DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
src
structure
CustomDelegate.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
6
#include "
dbe/confaccessor.hpp
"
7
#include "
dbe/tableselection.hpp
"
8
#include "
dbe/CustomDelegate.hpp
"
9
#include "
dbe/BuildingBlockEditors.hpp
"
10
#include "
dbe/TableNode.hpp
"
11
#include "
dbe/Validator.hpp
"
12
//#include "dbe/MainWindow.hpp"
13
14
#include <QKeyEvent>
15
#include <QCompleter>
16
17
dbe::CustomDelegate::CustomDelegate
( QObject * parent )
18
: QItemDelegate ( parent )
19
{
20
setClipping (
true
);
21
}
22
23
QWidget *
dbe::CustomDelegate::createEditor
( QWidget * parent,
24
const
QStyleOptionViewItem & option,
25
const
QModelIndex & index )
const
26
{
27
Q_UNUSED ( option );
28
const
dbe::models::tableselection
* Model =
29
dynamic_cast<
const
dbe::models::tableselection
*
>
( index.model() );
30
31
const
dbe::models::table
* SourceModel =
dynamic_cast<
const
dbe::models::table
*
>
( Model
32
->sourceModel() );
33
34
TableNode
*
Item
= Model->
getnode
( index );
35
36
tref
Object = SourceModel->
GetTableObject
( Model->mapToSource ( index ).row() );
37
38
if
( Model ==
nullptr
)
39
{
40
return
nullptr
;
41
}
42
43
if
( index.column() == 0 )
44
{
45
emit
CreateObjectEditorSignal
( Object );
46
return
nullptr
;
47
}
48
49
if
(
dynamic_cast<
TableRelationshipNode
*
>
(
Item
) )
50
{
51
TableRelationshipNode
* RelationshipItem =
dynamic_cast<
TableRelationshipNode
*
>
(
Item
);
52
dunedaq::conffwk::relationship_t
RelationshipData = RelationshipItem->
GetRelationship
();
53
widgets::editors::relation
* Editor =
new
widgets::editors::relation
( RelationshipData );
54
connect ( Editor, SIGNAL ( signal_edit_end() ),
this
, SLOT (
CommitAndClose
() ) );
55
connect ( Editor, SIGNAL ( signal_force_close() ),
this
, SLOT (
Close
() ) );
56
return
Editor;
57
}
58
else
if
(
dynamic_cast<
TableAttributeNode
*
>
(
Item
) )
59
{
60
TableAttributeNode
* AttributeItem =
dynamic_cast<
TableAttributeNode
*
>
(
Item
);
61
dunedaq::conffwk::attribute_t
AttributeData = AttributeItem->
GetAttribute
();
62
63
if
( AttributeData.
p_is_multi_value
)
64
{
65
widgets::editors::multiattr
* widget =
new
widgets::editors::multiattr
(AttributeData);
66
connect ( widget, SIGNAL ( signal_edit_end() ),
this
, SLOT (
CommitAndClose
() ) );
67
connect ( widget, SIGNAL ( signal_force_close() ),
this
, SLOT (
Close
() ) );
68
return
widget;
69
}
70
else
71
{
72
switch
( AttributeData.
p_type
)
73
{
74
75
case
dunedaq::conffwk::date_type
:
76
77
case
dunedaq::conffwk::time_type
:
78
79
case
dunedaq::conffwk::string_type
:
80
{
81
widgets::editors::stringattr
* Editor =
new
widgets::editors::stringattr
( AttributeData,
82
parent );
83
connect ( Editor, SIGNAL ( signal_edit_end() ),
this
, SLOT (
CommitAndClose
() ) );
84
connect ( Editor, SIGNAL ( signal_force_close() ),
this
, SLOT (
Close
() ) );
85
return
Editor;
86
}
87
88
case
dunedaq::conffwk::double_type
:
89
90
case
dunedaq::conffwk::float_type
:
91
92
case
dunedaq::conffwk::s8_type
:
93
94
case
dunedaq::conffwk::s16_type
:
95
96
case
dunedaq::conffwk::s32_type
:
97
98
case
dunedaq::conffwk::s64_type
:
99
100
case
dunedaq::conffwk::u8_type
:
101
102
case
dunedaq::conffwk::u16_type
:
103
104
case
dunedaq::conffwk::u32_type
:
105
106
case
dunedaq::conffwk::u64_type
:
107
{
108
widgets::editors::numericattr
* Editor =
new
widgets::editors::numericattr
( AttributeData,
109
parent );
110
connect ( Editor, SIGNAL ( signal_edit_end() ),
this
, SLOT (
CommitAndClose
() ) );
111
connect ( Editor, SIGNAL ( signal_force_close() ),
this
, SLOT (
Close
() ) );
112
return
Editor;
113
}
114
115
case
dunedaq::conffwk::bool_type
:
116
117
case
dunedaq::conffwk::enum_type
:
118
{
119
widgets::editors::combo
* Editor =
new
widgets::editors::combo
( AttributeData, parent );
120
connect ( Editor, SIGNAL ( signal_value_change() ),
this
, SLOT (
CommitAndClose
() ) );
121
connect ( Editor, SIGNAL ( signal_force_close() ),
this
, SLOT (
Close
() ) );
122
return
Editor;
123
}
124
125
case
dunedaq::conffwk::class_type
:
126
{
127
widgets::editors::combo
* Editor =
new
widgets::editors::combo
( AttributeData, parent );
128
connect ( Editor, SIGNAL ( signal_edit_end() ),
this
, SLOT (
CommitAndClose
() ) );
129
connect ( Editor, SIGNAL ( signal_force_close() ),
this
, SLOT (
Close
() ) );
130
return
Editor;
131
}
132
133
default
:
134
break
;
135
}
136
}
137
}
138
139
return
nullptr
;
140
}
141
142
void
dbe::CustomDelegate::setEditorData
( QWidget * editor,
143
const
QModelIndex & index )
const
144
{
145
const
dbe::models::tableselection
* mdl =
146
dynamic_cast<
const
dbe::models::tableselection
*
>
( index.model() );
147
148
if
( mdl !=
nullptr
|| editor !=
nullptr
)
149
{
150
if
(
widgets::editors::base
* w =
dynamic_cast<
widgets::editors::base
*
>
( editor ) )
151
{
152
QStringList
const
& data = mdl->
getnode
( index )->
GetData
();
153
w->setdata ( data );
154
w->SetEditor();
155
}
156
}
157
}
158
159
void
dbe::CustomDelegate::setModelData
( QWidget * editor, QAbstractItemModel * model,
160
const
QModelIndex & index )
const
161
{
162
const
dbe::models::tableselection
* Model =
163
dynamic_cast<
const
dbe::models::tableselection
*
>
( index.model() );
164
165
if
( Model ==
nullptr
|| editor ==
nullptr
)
166
{
167
return
;
168
}
169
170
widgets::editors::base
* WidgetInterface =
dynamic_cast<
widgets::editors::base
*
>
171
( editor );
172
173
QStringList ValueList = WidgetInterface->
getdata
();
174
175
model->setData ( index, ValueList, Qt::EditRole );
176
}
177
178
void
dbe::CustomDelegate::paint
( QPainter * painter,
const
QStyleOptionViewItem & option,
179
const
QModelIndex & index )
const
180
{
181
QItemDelegate::paint(painter, option, index);
182
183
// TODO: now commented-out because of small issues with text rendering
184
// indeed the text is too close to the cell's borders and some times artifacts are present
185
// the alternate colors have been anyway enabled in the table view
186
// so basically we miss the back-ground for the first column
187
188
// painter->save();
189
//
190
// QFont fontmodif = option.font;
191
//
192
// if ( option.state & QStyle::State_Selected )
193
// {
194
// painter->setBackground ( option.palette.mid() );
195
// painter->setRenderHint ( QPainter::Antialiasing, true );
196
// }
197
// else if ( index.column() == 0 )
198
// {
199
// painter->setBackground ( QColor::fromRgb ( 75, 222, 148 ) );
200
// fontmodif.setBold ( true );
201
// }
202
// else if ( index.row() % 2 == 1 )
203
// {
204
// painter->setBackground ( Qt::lightGray );
205
// }
206
// else
207
// {
208
// painter->setBackground ( Qt::white );
209
// }
210
//
211
// painter->setFont ( fontmodif );
212
// painter->fillRect ( option.rect, painter->background() );
213
// painter->drawText ( option.rect, option.displayAlignment, index.data().toString() );
214
//
215
// painter->restore();
216
}
217
218
void
dbe::CustomDelegate::updateEditorGeometry
( QWidget * editor,
219
const
QStyleOptionViewItem & option,
220
const
QModelIndex & index )
const
221
{
222
Q_UNUSED ( index );
223
editor->setGeometry ( option.rect );
224
}
225
226
bool
dbe::CustomDelegate::eventFilter
( QObject * editor, QEvent * event )
227
{
228
if
( event->type() == QEvent::KeyPress )
229
{
230
QKeyEvent * KeyEvent =
static_cast<
QKeyEvent *
>
( event );
231
232
if
( KeyEvent->key() == Qt::Key_Enter || KeyEvent->key() == Qt::Key_Return )
233
{
234
if
(
dynamic_cast<
widgets::editors::combo
*
>
( editor ) != 0 )
235
{
236
return
QItemDelegate::eventFilter (
237
editor, event );
238
}
239
else
240
{
241
return
true
;
242
}
243
}
244
}
245
else
if
( event->type() == QEvent::FocusOut )
246
{
247
return
true
;
248
}
249
250
return
QItemDelegate::eventFilter ( editor, event );
251
}
252
253
bool
dbe::CustomDelegate::editorEvent
( QEvent * event, QAbstractItemModel * model,
254
const
QStyleOptionViewItem & option,
255
const
QModelIndex & index )
256
{
257
if
( ! ( event->type() == QEvent::MouseButtonPress
258
|| event->type() == QEvent::MouseButtonRelease ) )
259
{
260
if
(
dynamic_cast<
QKeyEvent *
>
( event ) )
261
{
262
QKeyEvent * KeyEvent =
static_cast<
QKeyEvent *
>
( event );
263
264
if
( KeyEvent->text() !=
"e"
)
265
{
266
return
true
;
267
}
268
}
269
}
270
271
return
QItemDelegate::editorEvent ( event, model, option, index );
272
}
273
274
void
dbe::CustomDelegate::CommitAndClose
()
275
{
276
widgets::editors::base
* Editor = qobject_cast<widgets::editors::base *> ( sender() );
277
278
if
( Editor )
279
{
280
emit commitData ( Editor );
281
emit closeEditor ( Editor );
282
return
;
283
}
284
}
285
286
void
dbe::CustomDelegate::Close
()
287
{
288
widgets::editors::base
* Editor = qobject_cast<widgets::editors::base *> ( sender() );
289
290
if
( Editor )
291
{
292
emit closeEditor ( Editor );
293
return
;
294
}
295
}
BuildingBlockEditors.hpp
CustomDelegate.hpp
TableNode.hpp
Validator.hpp
Item
Definition
AddressTable.hh:14
dbe::CustomDelegate::CustomDelegate
CustomDelegate(QObject *parent=0)
Definition
CustomDelegate.cpp:17
dbe::CustomDelegate::createEditor
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition
CustomDelegate.cpp:23
dbe::CustomDelegate::CommitAndClose
void CommitAndClose()
Definition
CustomDelegate.cpp:274
dbe::CustomDelegate::Close
void Close()
Definition
CustomDelegate.cpp:286
dbe::CustomDelegate::editorEvent
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
Definition
CustomDelegate.cpp:253
dbe::CustomDelegate::updateEditorGeometry
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition
CustomDelegate.cpp:218
dbe::CustomDelegate::setEditorData
void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition
CustomDelegate.cpp:142
dbe::CustomDelegate::CreateObjectEditorSignal
void CreateObjectEditorSignal(tref Object) const
dbe::CustomDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition
CustomDelegate.cpp:178
dbe::CustomDelegate::eventFilter
bool eventFilter(QObject *editor, QEvent *event)
Definition
CustomDelegate.cpp:226
dbe::CustomDelegate::setModelData
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Definition
CustomDelegate.cpp:159
dbe::TableAttributeNode
Definition
TableNode.hpp:27
dbe::TableAttributeNode::GetAttribute
dunedaq::conffwk::attribute_t GetAttribute() const
Definition
TableNode.cpp:38
dbe::TableNode
Definition
TableNode.hpp:14
dbe::TableNode::GetData
virtual QStringList GetData() const
Definition
TableNode.cpp:18
dbe::TableRelationshipNode
Definition
TableNode.hpp:38
dbe::TableRelationshipNode::GetRelationship
dunedaq::conffwk::relationship_t GetRelationship() const
Definition
TableNode.cpp:59
dbe::models::table
Definition
table.hpp:27
dbe::models::table::GetTableObject
tref GetTableObject(int ObjectIndex) const
Definition
table.cpp:456
dbe::models::tableselection
Definition
tableselection.hpp:26
dbe::models::tableselection::getnode
TableNode * getnode(const QModelIndex &index) const
Definition
tableselection.cpp:23
dbe::widgets::editors::base
Definition
BuildingBlockEditors.hpp:119
dbe::widgets::editors::base::getdata
virtual QStringList getdata()
Definition
BuildingBlockEditors.cpp:69
dbe::widgets::editors::combo
Definition
BuildingBlockEditors.hpp:342
dbe::widgets::editors::multiattr
Definition
BuildingBlockEditors.hpp:380
dbe::widgets::editors::numericattr
Definition
BuildingBlockEditors.hpp:295
dbe::widgets::editors::relation
Definition
BuildingBlockEditors.hpp:171
dbe::widgets::editors::stringattr
Definition
BuildingBlockEditors.hpp:241
confaccessor.hpp
dbe::tref
inner::configobject::tref tref
Definition
tref.hpp:35
dunedaq::conffwk::date_type
@ date_type
Definition
Schema.hpp:39
dunedaq::conffwk::u64_type
@ u64_type
Definition
Schema.hpp:36
dunedaq::conffwk::float_type
@ float_type
Definition
Schema.hpp:37
dunedaq::conffwk::s32_type
@ s32_type
Definition
Schema.hpp:33
dunedaq::conffwk::string_type
@ string_type
Definition
Schema.hpp:41
dunedaq::conffwk::s16_type
@ s16_type
Definition
Schema.hpp:31
dunedaq::conffwk::u32_type
@ u32_type
Definition
Schema.hpp:34
dunedaq::conffwk::enum_type
@ enum_type
Definition
Schema.hpp:42
dunedaq::conffwk::bool_type
@ bool_type
Definition
Schema.hpp:28
dunedaq::conffwk::class_type
@ class_type
Definition
Schema.hpp:43
dunedaq::conffwk::s8_type
@ s8_type
Definition
Schema.hpp:29
dunedaq::conffwk::time_type
@ time_type
Definition
Schema.hpp:40
dunedaq::conffwk::u8_type
@ u8_type
Definition
Schema.hpp:30
dunedaq::conffwk::s64_type
@ s64_type
Definition
Schema.hpp:35
dunedaq::conffwk::double_type
@ double_type
Definition
Schema.hpp:38
dunedaq::conffwk::u16_type
@ u16_type
Definition
Schema.hpp:32
dunedaq::conffwk::attribute_t
Definition
Schema.hpp:59
dunedaq::conffwk::attribute_t::p_is_multi_value
bool p_is_multi_value
Definition
Schema.hpp:66
dunedaq::conffwk::attribute_t::p_type
type_t p_type
Definition
Schema.hpp:62
dunedaq::conffwk::relationship_t
Definition
Schema.hpp:120
tableselection.hpp
Generated on
for DUNE-DAQ by
1.17.0