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