DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
src
structure
CustomTableView.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 "
dbe/tableselection.hpp
"
8
9
#include "
dbe/confaccessor.hpp
"
10
#include <QAbstractItemView>
11
#include <QContextMenuEvent>
12
#include <QDialog>
13
#include <QHBoxLayout>
14
#include <QHeaderView>
15
#include <QLabel>
16
#include <QLineEdit>
17
#include <QMenu>
18
#include <QScrollBar>
19
#include <QVariant>
20
22
#include "
dbe/CustomTableView.hpp
"
23
#include "
dbe/ObjectCreator.hpp
"
24
#include "
dbe/ObjectEditor.hpp
"
25
#include "
dbe/messenger.hpp
"
26
27
#include "
dbe/MainWindow.hpp
"
28
29
//-----------------------------------------------------------------------------------------------------
30
dbe::CustomTableView::CustomTableView
(QWidget* parent)
31
: QTableView(parent)
32
,
m_context_menu
(nullptr)
33
,
FindObject
(nullptr)
34
,
editObject
(nullptr)
35
,
deleteObjectAc
(nullptr)
36
,
refByAc
(nullptr)
37
,
refByAcOnlyComp
(nullptr)
38
,
copyObjectAc
(nullptr)
39
,
m_find_object_dialog
(nullptr)
40
,
LineEdit
(nullptr)
41
,
NextButton
(nullptr)
42
,
GoButton
(nullptr)
43
,
ListIndex
(0)
44
{
45
verticalHeader()->setVisible(
true
);
46
verticalHeader()->setSectionResizeMode(QHeaderView::Interactive);
47
48
horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
49
horizontalHeader()->setMaximumSectionSize(750);
50
setSortingEnabled(
true
);
51
setAlternatingRowColors(
true
);
52
setSelectionMode(SelectionMode::SingleSelection);
53
setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows);
54
setHorizontalScrollMode(ScrollMode::ScrollPerPixel);
55
setVerticalScrollMode(ScrollMode::ScrollPerPixel);
56
setWordWrap(
true
);
57
setTextElideMode(Qt::ElideRight);
58
59
connect(
this
, SIGNAL(activated(
const
QModelIndex&)),
this
, SLOT(
slot_edit_object
()));
60
}
61
//-----------------------------------------------------------------------------------------------------
62
63
//-----------------------------------------------------------------------------------------------------
64
void
65
dbe::CustomTableView::contextMenuEvent
(QContextMenuEvent* Event)
66
{
67
if
(
m_context_menu
==
nullptr
) {
68
m_context_menu
=
new
QMenu(
this
);
69
CreateActions
();
70
}
71
72
QModelIndex Index = indexAt(Event->pos());
73
74
if
(Index.isValid()) {
75
for
(
int
item = 0; item <
m_last_object_item
; ++item) {
76
m_context_menu
->actions().at(item)->setVisible(
true
);
77
}
78
}
else
{
79
for
(
int
item = 0; item <
m_last_object_item
; ++item) {
80
m_context_menu
->actions().at(item)->setVisible(
false
);
81
}
82
}
83
m_context_menu
->exec(Event->globalPos());
84
}
85
//-----------------------------------------------------------------------------------------------------
86
87
//-----------------------------------------------------------------------------------------------------
88
void
89
dbe::CustomTableView::FindObjectSlot
()
90
{
91
if
(
m_find_object_dialog
!=
nullptr
) {
92
delete
m_find_object_dialog
;
93
m_find_object_dialog
=
nullptr
;
94
}
95
96
m_find_object_dialog
=
new
QDialog(
this
);
97
m_find_object_dialog
->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
98
m_find_object_dialog
->setToolTip(
"Type string to edit line and press Enter."
);
99
m_find_object_dialog
->setWindowTitle(
"Search for an object in the table"
);
100
101
QHBoxLayout* Layout =
new
QHBoxLayout(
m_find_object_dialog
);
102
QLabel* Label =
new
QLabel(QString(
"Find Object:"
),
m_find_object_dialog
);
103
104
NextButton
=
new
QPushButton(
"Next"
);
105
GoButton
=
new
QPushButton(
"Go !"
);
106
107
LineEdit
=
new
QLineEdit(
m_find_object_dialog
);
108
LineEdit
->setToolTip(
"Type string and press Enter"
);
109
110
Layout->addWidget(Label);
111
Layout->addWidget(
LineEdit
);
112
Layout->addWidget(
GoButton
);
113
Layout->addWidget(
NextButton
);
114
115
m_find_object_dialog
->setLayout(Layout);
116
m_find_object_dialog
->show();
117
NextButton
->setDisabled(
true
);
118
119
connect(
LineEdit
, SIGNAL(textEdited(QString)),
this
, SLOT(
EditedSearchString
(QString)));
120
connect(
LineEdit
, SIGNAL(returnPressed()),
this
, SLOT(
slot_go_to_object
()));
121
connect(
GoButton
, SIGNAL(clicked()),
this
, SLOT(
slot_go_to_object
()));
122
connect(
NextButton
, SIGNAL(clicked()),
this
, SLOT(
GoToNext
()));
123
}
124
//-----------------------------------------------------------------------------------------------------
125
126
//-----------------------------------------------------------------------------------------------------
127
void
128
dbe::CustomTableView::slot_go_to_object
()
129
{
130
ListIndex
= 0;
131
ListOfMatch
.clear();
132
133
QString UserType =
LineEdit
->text();
134
135
if
(UserType.isEmpty()) {
136
return
;
137
}
138
139
QAbstractItemModel* Model = model();
140
141
if
(Model !=
nullptr
) {
142
QVariant StringCriterium = QVariant(UserType);
143
QModelIndex WhereToStartSearch = Model->index(0, 0);
144
ListOfMatch
=
145
Model->match(WhereToStartSearch, Qt::DisplayRole, StringCriterium, 1000, Qt::MatchContains | Qt::MatchWrap);
146
147
if
(
ListOfMatch
.size() > 0) {
148
ListIndex
= 0;
149
auto
val =
ListOfMatch
.value(
ListIndex
);
150
selectRow(val.row());
151
// resizeColumnToContents ( val.row() );
152
scrollTo(val, QAbstractItemView::PositionAtCenter);
153
154
GoButton
->setDisabled(
true
);
155
NextButton
->setEnabled(
true
);
156
157
disconnect(
LineEdit
, SIGNAL(returnPressed()),
this
, SLOT(
slot_go_to_object
()));
158
connect(
LineEdit
, SIGNAL(returnPressed()),
this
, SLOT(
GoToNext
()));
159
}
160
}
161
}
162
//-----------------------------------------------------------------------------------------------------
163
164
//-----------------------------------------------------------------------------------------------------
165
void
166
dbe::CustomTableView::GoToNext
()
167
{
168
if
((
LineEdit
->text()).isEmpty()) {
169
ListIndex
= 0;
170
ListOfMatch
.clear();
171
return
;
172
}
173
174
if
(
ListOfMatch
.size() > 0) {
175
if
((++
ListIndex
) <
ListOfMatch
.size()) {
176
scrollTo(
ListOfMatch
.value(
ListIndex
), QAbstractItemView::EnsureVisible);
177
selectRow(
ListOfMatch
.value(
ListIndex
).row());
178
resizeColumnToContents(
ListIndex
);
179
}
else
{
180
ListIndex
= 0;
181
scrollTo(
ListOfMatch
.value(
ListIndex
), QAbstractItemView::EnsureVisible);
182
selectRow(
ListOfMatch
.value(
ListIndex
).row());
183
resizeColumnToContents(
ListIndex
);
184
}
185
}
186
}
187
//-----------------------------------------------------------------------------------------------------
188
189
//-----------------------------------------------------------------------------------------------------
190
void
191
dbe::CustomTableView::EditedSearchString
(QString Text)
192
{
193
Q_UNUSED(Text)
194
195
connect(
LineEdit
, SIGNAL(returnPressed()),
this
, SLOT(
slot_go_to_object
()));
196
disconnect(
LineEdit
, SIGNAL(returnPressed()),
this
, SLOT(
GoToNext
()));
197
198
GoButton
->setEnabled(
true
);
199
NextButton
->setDisabled(
true
);
200
}
201
//-----------------------------------------------------------------------------------------------------
202
203
//-----------------------------------------------------------------------------------------------------
204
void
205
dbe::CustomTableView::slot_edit_object
()
206
{
207
QModelIndex
const
& index = this->currentIndex();
208
209
if
(index.isValid()) {
210
if
(
models::tableselection
const
* selectionmodel =
dynamic_cast<
models::tableselection
const*
>
(index.model())) {
211
if
(
models::table
const
* srcmodel =
dynamic_cast<
const
dbe::models::table
*
>
(selectionmodel->sourceModel())) {
212
tref
obj = srcmodel->GetTableObject(selectionmodel->mapToSource(index).row());
213
214
if
(not obj.is_null()) {
215
emit
OpenEditor
(obj);
216
}
217
}
218
}
219
}
220
}
221
//-----------------------------------------------------------------------------------------------------
222
223
//-----------------------------------------------------------------------------------------------------
224
void
225
dbe::CustomTableView::referencedBy_OnlyComposite
()
226
{
227
QModelIndex
const
& Index = this->currentIndex();
228
229
const
dbe::models::tableselection
* Model =
dynamic_cast<
const
dbe::models::tableselection
*
>
(Index.model());
230
231
const
dbe::models::table
* SourceModel =
dynamic_cast<
const
dbe::models::table
*
>
(Model->sourceModel());
232
233
if
(!Index.isValid() || !Model) {
234
return
;
235
}
236
237
tref
obj = SourceModel->
GetTableObject
(Model->mapToSource(Index).row());
238
referencedBy
(obj,
true
);
239
}
240
//-----------------------------------------------------------------------------------------------------
241
242
//-----------------------------------------------------------------------------------------------------
243
void
244
dbe::CustomTableView::referencedBy_All
()
245
{
246
QModelIndex
const
& Index = this->currentIndex();
247
const
dbe::models::tableselection
* Model =
dynamic_cast<
const
dbe::models::tableselection
*
>
(Index.model());
248
249
dbe::models::table
const
* SourceModel =
dynamic_cast<
const
dbe::models::table
*
>
(Model->sourceModel());
250
251
if
(!Index.isValid() || !Model) {
252
return
;
253
}
254
255
tref
obj = SourceModel->
GetTableObject
(Model->mapToSource(Index).row());
256
referencedBy
(obj,
false
);
257
}
258
//-----------------------------------------------------------------------------------------------------
259
260
//-----------------------------------------------------------------------------------------------------
261
void
262
dbe::CustomTableView::slot_copy_object
()
263
{
264
QModelIndex
const
& Index = this->currentIndex();
265
266
dbe::models::tableselection
const
* Model =
dynamic_cast<
const
dbe::models::tableselection
*
>
(Index.model());
267
268
dbe::models::table
const
* SourceModel =
dynamic_cast<
const
dbe::models::table
*
>
(Model->sourceModel());
269
270
if
(Index.isValid() and Model) {
271
tref
obj = SourceModel->
GetTableObject
(Model->mapToSource(Index).row());
272
273
if
(not obj.is_null()) {
274
(
new
ObjectCreator
(obj))->show();
275
}
276
}
277
}
278
//-----------------------------------------------------------------------------------------------------
279
280
//-----------------------------------------------------------------------------------------------------
281
void
282
dbe::CustomTableView::slot_create_object
()
283
{
284
// TODO implement dbe::CustomTableView::slot_create_object
285
throw
std::string(
" dbe::CustomTableView::slot_create_object is not yet implemented "
);
286
}
287
//-----------------------------------------------------------------------------------------------------
288
289
//-----------------------------------------------------------------------------------------------------
290
void
291
dbe::CustomTableView::slot_delete_objects
()
292
{
293
if
(this->model() !=
nullptr
) {
294
QModelIndexList qindices = this->selectedIndexes();
295
std::vector<QModelIndex> indices;
296
297
for
(QModelIndex q : qindices) {
298
if
(q.isValid()) {
299
indices.push_back(q);
300
}
301
}
302
303
if
(
dbe::models::tableselection
* casted =
dynamic_cast<
dbe::models::tableselection
*
>
(this->model())) {
304
casted->delete_objects(indices.begin(), indices.end());
305
}
else
if
(
dbe::models::table
* casted =
dynamic_cast<
dbe::models::table
*
>
(this->model())) {
306
casted->delete_objects(indices.begin(), indices.end());
307
}
else
{
308
WARN
(
"Object Deleting"
,
309
"Object deletion failed due to the internal model being in invalid state"
,
310
"You are advised to restart the application before proceeding any further"
);
311
}
312
}
313
}
314
//-----------------------------------------------------------------------------------------------------
315
316
//-----------------------------------------------------------------------------------------------------
317
void
318
dbe::CustomTableView::CreateActions
()
319
{
320
editObject
=
new
QAction(tr(
"&Edit Object"
),
this
);
321
connect(
editObject
, SIGNAL(triggered()),
this
, SLOT(
slot_edit_object
()));
322
m_context_menu
->addAction(
editObject
);
323
324
deleteObjectAc
=
new
QAction(tr(
"&Delete Object"
),
this
);
325
connect(
deleteObjectAc
, SIGNAL(triggered()),
this
, SLOT(
slot_delete_objects
()));
326
m_context_menu
->addAction(
deleteObjectAc
);
327
328
refByAc
=
new
QAction(tr(
"Referenced B&y (All objects)"
),
this
);
329
refByAc
->setToolTip(
"Find all objects which reference the selected object"
);
330
refByAc
->setStatusTip(
refByAc
->toolTip());
331
connect(
refByAc
, SIGNAL(triggered()),
this
, SLOT(
referencedBy_All
()));
332
m_context_menu
->addAction(
refByAc
);
333
334
refByAcOnlyComp
=
new
QAction(tr(
"Referenced B&y (Only Composite)"
),
this
);
335
refByAcOnlyComp
->setToolTip(
"Find objects (ONLY Composite ones) which reference the selected object"
);
336
refByAcOnlyComp
->setStatusTip(
refByAcOnlyComp
->toolTip());
337
connect(
refByAcOnlyComp
, SIGNAL(triggered()),
this
, SLOT(
referencedBy_OnlyComposite
()));
338
m_context_menu
->addAction(
refByAcOnlyComp
);
339
340
copyObjectAc
=
new
QAction(tr(
"Copy This Object Into A &New One"
),
this
);
341
connect(
copyObjectAc
, SIGNAL(triggered()),
this
, SLOT(
slot_copy_object
()));
342
m_context_menu
->addAction(
copyObjectAc
);
343
344
m_context_menu
->addSeparator();
345
m_last_object_item
=
m_context_menu
->actions().size();
346
347
FindObject
=
new
QAction(tr(
"&Find Object"
),
this
);
348
// FindObject->setShortcut ( QKeySequence ( tr ( "Ctrl+F" ) ) );
349
// FindObject->setShortcutContext ( Qt::WidgetShortcut );
350
connect(
FindObject
, SIGNAL(triggered()),
this
, SLOT(
FindObjectSlot
()));
351
// addAction (FindObject);
352
m_context_menu
->addAction(
FindObject
);
353
}
354
//-----------------------------------------------------------------------------------------------------
355
356
//-----------------------------------------------------------------------------------------------------
357
void
358
dbe::CustomTableView::referencedBy
(
tref
obj,
bool
onlyComposite)
359
{
360
if
(not obj.is_null()) {
361
MainWindow::findthis
()->
get_view
()->referencedBy(onlyComposite, obj);
362
}
363
}
364
//-----------------------------------------------------------------------------------------------------
CustomTableView.hpp
MainWindow.hpp
ObjectCreator.hpp
ObjectEditor.hpp
dbe::CustomTableView::deleteObjectAc
QAction * deleteObjectAc
Definition
CustomTableView.hpp:58
dbe::CustomTableView::m_context_menu
QMenu * m_context_menu
Definition
CustomTableView.hpp:55
dbe::CustomTableView::ListIndex
int ListIndex
Match Variables.
Definition
CustomTableView.hpp:70
dbe::CustomTableView::refByAcOnlyComp
QAction * refByAcOnlyComp
Definition
CustomTableView.hpp:60
dbe::CustomTableView::GoToNext
void GoToNext()
Definition
CustomTableView.cpp:166
dbe::CustomTableView::CustomTableView
CustomTableView(QWidget *parent=0)
Including QT::include <QHeaderView>.
Definition
CustomTableView.cpp:30
dbe::CustomTableView::OpenEditor
void OpenEditor(tref Object)
dbe::CustomTableView::GoButton
QPushButton * GoButton
Definition
CustomTableView.hpp:67
dbe::CustomTableView::editObject
QAction * editObject
Definition
CustomTableView.hpp:57
dbe::CustomTableView::slot_go_to_object
void slot_go_to_object()
Definition
CustomTableView.cpp:128
dbe::CustomTableView::FindObject
QAction * FindObject
Definition
CustomTableView.hpp:56
dbe::CustomTableView::copyObjectAc
QAction * copyObjectAc
Definition
CustomTableView.hpp:61
dbe::CustomTableView::m_find_object_dialog
QDialog * m_find_object_dialog
File Dialog.
Definition
CustomTableView.hpp:64
dbe::CustomTableView::FindObjectSlot
void FindObjectSlot()
Definition
CustomTableView.cpp:89
dbe::CustomTableView::referencedBy_All
void referencedBy_All()
Definition
CustomTableView.cpp:244
dbe::CustomTableView::refByAc
QAction * refByAc
Definition
CustomTableView.hpp:59
dbe::CustomTableView::m_last_object_item
int m_last_object_item
Definition
CustomTableView.hpp:73
dbe::CustomTableView::slot_create_object
void slot_create_object()
Definition
CustomTableView.cpp:282
dbe::CustomTableView::referencedBy
void referencedBy(tref obj, bool onlyComposite)
Definition
CustomTableView.cpp:358
dbe::CustomTableView::CreateActions
void CreateActions()
Definition
CustomTableView.cpp:318
dbe::CustomTableView::EditedSearchString
void EditedSearchString(QString Text)
Definition
CustomTableView.cpp:191
dbe::CustomTableView::slot_copy_object
void slot_copy_object()
Definition
CustomTableView.cpp:262
dbe::CustomTableView::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *Event)
Definition
CustomTableView.cpp:65
dbe::CustomTableView::NextButton
QPushButton * NextButton
Definition
CustomTableView.hpp:66
dbe::CustomTableView::LineEdit
QLineEdit * LineEdit
Definition
CustomTableView.hpp:65
dbe::CustomTableView::slot_delete_objects
void slot_delete_objects()
Definition
CustomTableView.cpp:291
dbe::CustomTableView::referencedBy_OnlyComposite
void referencedBy_OnlyComposite()
Definition
CustomTableView.cpp:225
dbe::CustomTableView::slot_edit_object
void slot_edit_object()
Definition
CustomTableView.cpp:205
dbe::CustomTableView::ListOfMatch
QModelIndexList ListOfMatch
Definition
CustomTableView.hpp:71
dbe::MainWindow::get_view
cptr< dbe::CustomTreeView > get_view() const
Definition
MainWindow.cpp:1653
dbe::MainWindow::findthis
static MainWindow * findthis()
Definition
MainWindow.cpp:1562
dbe::ObjectCreator::ObjectCreator
ObjectCreator(dunedaq::conffwk::class_t const &classinfo, QWidget *parent=0)
Definition
ObjectCreator.cpp:45
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
confaccessor.hpp
messenger.hpp
WARN
#define WARN(...)
Definition
messenger.hpp:82
dbe::tref
inner::configobject::tref tref
Definition
tref.hpp:36
tableselection.hpp
Generated on
for DUNE-DAQ by
1.18.0