DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
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
8
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
23#include "dbe/ObjectCreator.hpp"
24#include "dbe/ObjectEditor.hpp"
25#include "dbe/messenger.hpp"
26
27#include "dbe/MainWindow.hpp"
28
29//-----------------------------------------------------------------------------------------------------
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//-----------------------------------------------------------------------------------------------------
64void
66{
67 if (m_context_menu == nullptr) {
68 m_context_menu = new QMenu(this);
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//-----------------------------------------------------------------------------------------------------
88void
90{
91 if (m_find_object_dialog != nullptr) {
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//-----------------------------------------------------------------------------------------------------
127void
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);
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//-----------------------------------------------------------------------------------------------------
165void
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//-----------------------------------------------------------------------------------------------------
190void
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//-----------------------------------------------------------------------------------------------------
204void
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//-----------------------------------------------------------------------------------------------------
224void
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//-----------------------------------------------------------------------------------------------------
243void
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//-----------------------------------------------------------------------------------------------------
261void
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//-----------------------------------------------------------------------------------------------------
281void
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//-----------------------------------------------------------------------------------------------------
290void
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//-----------------------------------------------------------------------------------------------------
317void
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()));
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//-----------------------------------------------------------------------------------------------------
357void
359{
360 if (not obj.is_null()) {
361 MainWindow::findthis()->get_view()->referencedBy(onlyComposite, obj);
362 }
363}
364//-----------------------------------------------------------------------------------------------------
int ListIndex
Match Variables.
CustomTableView(QWidget *parent=0)
Including QT::include <QHeaderView>.
void OpenEditor(tref Object)
QDialog * m_find_object_dialog
File Dialog.
void referencedBy(tref obj, bool onlyComposite)
void EditedSearchString(QString Text)
void contextMenuEvent(QContextMenuEvent *Event)
QModelIndexList ListOfMatch
cptr< dbe::CustomTreeView > get_view() const
static MainWindow * findthis()
ObjectCreator(dunedaq::conffwk::class_t const &classinfo, QWidget *parent=0)
tref GetTableObject(int ObjectIndex) const
Definition table.cpp:412
#define WARN(...)
Definition messenger.hpp:82
inner::configobject::tref tref
Definition tref.hpp:36