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 <QScrollBar>
12#include <QMenu>
13#include <QLabel>
14#include <QHBoxLayout>
15#include <QContextMenuEvent>
16#include <QDialog>
17#include <QLineEdit>
18#include <QVariant>
19#include <QHeaderView>
20
23#include "dbe/ObjectEditor.hpp"
24#include "dbe/ObjectCreator.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
64//-----------------------------------------------------------------------------------------------------
65void dbe::CustomTableView::contextMenuEvent ( QContextMenuEvent * Event )
66{
67 if ( m_context_menu == nullptr )
68 {
69 m_context_menu = new QMenu ( this );
71 }
72
73 QModelIndex Index = indexAt ( Event->pos() );
74
75 if ( Index.isValid() ) {
76 for (int item=0; item<m_last_object_item; ++item) {
77 m_context_menu->actions().at ( item )->setVisible ( true );
78 }
79 }
80 else {
81 for (int item=0; item<m_last_object_item; ++item) {
82 m_context_menu->actions().at ( item )->setVisible ( false );
83 }
84 }
85 m_context_menu->exec ( Event->globalPos() );
86}
87//-----------------------------------------------------------------------------------------------------
88
89//-----------------------------------------------------------------------------------------------------
91{
92 if ( m_find_object_dialog != nullptr )
93 {
95 m_find_object_dialog = nullptr;
96 }
97
98 m_find_object_dialog = new QDialog ( this );
99 m_find_object_dialog->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
100 m_find_object_dialog->setToolTip ( "Type string to edit line and press Enter." );
101 m_find_object_dialog->setWindowTitle ( "Search for an object in the table" );
102
103 QHBoxLayout * Layout = new QHBoxLayout ( m_find_object_dialog );
104 QLabel * Label = new QLabel ( QString ( "Find Object:" ), m_find_object_dialog );
105
106 NextButton = new QPushButton ( "Next" );
107 GoButton = new QPushButton ( "Go !" );
108
109 LineEdit = new QLineEdit ( m_find_object_dialog );
110 LineEdit->setToolTip ( "Type string and press Enter" );
111
112 Layout->addWidget ( Label );
113 Layout->addWidget ( LineEdit );
114 Layout->addWidget ( GoButton );
115 Layout->addWidget ( NextButton );
116
117 m_find_object_dialog->setLayout ( Layout );
118 m_find_object_dialog->show();
119 NextButton->setDisabled ( true );
120
121 connect ( LineEdit, SIGNAL ( textEdited ( QString ) ), this,
122 SLOT ( EditedSearchString ( QString ) ) );
123 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( slot_go_to_object() ) );
124 connect ( GoButton, SIGNAL ( clicked() ), this, SLOT ( slot_go_to_object() ) );
125 connect ( NextButton, SIGNAL ( clicked() ), this, SLOT ( GoToNext() ) );
126}
127//-----------------------------------------------------------------------------------------------------
128
129//-----------------------------------------------------------------------------------------------------
131{
132 ListIndex = 0;
133 ListOfMatch.clear();
134
135 QString UserType = LineEdit->text();
136
137 if ( UserType.isEmpty() )
138 {
139 return;
140 }
141
142 QAbstractItemModel * Model = model();
143
144 if ( Model != nullptr )
145 {
146 QVariant StringCriterium = QVariant ( UserType );
147 QModelIndex WhereToStartSearch = Model->index ( 0, 0 );
148 ListOfMatch = Model->match ( WhereToStartSearch, Qt::DisplayRole, StringCriterium, 1000,
149 Qt::MatchContains | Qt::MatchWrap );
150
151 if ( ListOfMatch.size() > 0 )
152 {
153 ListIndex = 0;
154 auto val=ListOfMatch.value ( ListIndex );
155 selectRow ( val.row() );
156// resizeColumnToContents ( val.row() );
157 scrollTo (val , QAbstractItemView::PositionAtCenter );
158
159 GoButton->setDisabled ( true );
160 NextButton->setEnabled ( true );
161
162 disconnect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( slot_go_to_object() ) );
163 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToNext() ) );
164 }
165 }
166}
167//-----------------------------------------------------------------------------------------------------
168
169//-----------------------------------------------------------------------------------------------------
171{
172 if ( ( LineEdit->text() ).isEmpty() )
173 {
174 ListIndex = 0;
175 ListOfMatch.clear();
176 return;
177 }
178
179 if ( ListOfMatch.size() > 0 )
180 {
181 if ( ( ++ListIndex ) < ListOfMatch.size() )
182 {
183 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
184 selectRow ( ListOfMatch.value ( ListIndex ).row() );
185 resizeColumnToContents ( ListIndex );
186 }
187 else
188 {
189 ListIndex = 0;
190 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
191 selectRow ( ListOfMatch.value ( ListIndex ).row() );
192 resizeColumnToContents ( ListIndex );
193 }
194 }
195}
196//-----------------------------------------------------------------------------------------------------
197
198//-----------------------------------------------------------------------------------------------------
200{
201 Q_UNUSED ( Text )
202
203 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( slot_go_to_object() ) );
204 disconnect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToNext() ) );
205
206 GoButton->setEnabled ( true );
207 NextButton->setDisabled ( true );
208}
209//-----------------------------------------------------------------------------------------------------
210
211//-----------------------------------------------------------------------------------------------------
213{
214 QModelIndex const & index = this->currentIndex();
215
216 if ( index.isValid() )
217 {
218 if ( models::tableselection const * selectionmodel =
219 dynamic_cast<models::tableselection const *> ( index.model() ) )
220 {
221 if ( models::table const * srcmodel =
222 dynamic_cast<const dbe::models::table *> ( selectionmodel->sourceModel() ) )
223 {
224 tref obj = srcmodel->GetTableObject ( selectionmodel->mapToSource ( index ).row() );
225
226 if ( not obj.is_null() )
227 {
228 emit OpenEditor ( obj );
229 }
230 }
231 }
232 }
233}
234//-----------------------------------------------------------------------------------------------------
235
236//-----------------------------------------------------------------------------------------------------
238{
239 QModelIndex const & Index = this->currentIndex();
240
241 const dbe::models::tableselection * Model =
242 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
243
244 const dbe::models::table * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
245 ->sourceModel() );
246
247 if ( !Index.isValid() || !Model )
248 {
249 return;
250 }
251
252 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
253 referencedBy ( obj, true );
254}
255//-----------------------------------------------------------------------------------------------------
256
257//-----------------------------------------------------------------------------------------------------
259{
260 QModelIndex const & Index = this->currentIndex();
261 const dbe::models::tableselection * Model =
262 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
263
264 dbe::models::table const * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
265 ->sourceModel() );
266
267 if ( !Index.isValid() || !Model )
268 {
269 return;
270 }
271
272 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
273 referencedBy ( obj, false );
274}
275//-----------------------------------------------------------------------------------------------------
276
277//-----------------------------------------------------------------------------------------------------
279{
280 QModelIndex const & Index = this->currentIndex();
281
282 dbe::models::tableselection const * Model =
283 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
284
285 dbe::models::table const * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
286 ->sourceModel() );
287
288 if ( Index.isValid() and Model )
289 {
290 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
291
292 if ( not obj.is_null() )
293 {
294 ( new ObjectCreator ( obj ) )->show();
295 }
296 }
297}
298//-----------------------------------------------------------------------------------------------------
299
300//-----------------------------------------------------------------------------------------------------
302{
303 // TODO implement dbe::CustomTableView::slot_create_object
304 throw std::string ( " dbe::CustomTableView::slot_create_object is not yet implemented " );
305}
306//-----------------------------------------------------------------------------------------------------
307
308//-----------------------------------------------------------------------------------------------------
310{
311 if ( this->model() != nullptr )
312 {
313 QModelIndexList qindices = this->selectedIndexes();
314 std::vector<QModelIndex> indices;
315
316 for ( QModelIndex q : qindices )
317 {
318 if ( q.isValid() )
319 {
320 indices.push_back ( q );
321 }
322 }
323
324 if ( dbe::models::tableselection * casted =
325 dynamic_cast<dbe::models::tableselection *> ( this->model() ) )
326 {
327 casted->delete_objects ( indices.begin(), indices.end() );
328 }
329 else if ( dbe::models::table * casted = dynamic_cast<dbe::models::table *>
330 ( this->model() ) )
331 {
332 casted->delete_objects ( indices.begin(), indices.end() );
333 }
334 else
335 {
336 WARN ( "Object Deleting",
337 "Object deletion failed due to the internal model being in invalid state",
338 "You are advised to restart the application before proceeding any further" );
339 }
340 }
341
342}
343//-----------------------------------------------------------------------------------------------------
344
345//-----------------------------------------------------------------------------------------------------
347{
348 editObject = new QAction ( tr ( "&Edit Object" ), this );
349 connect ( editObject, SIGNAL ( triggered() ), this, SLOT ( slot_edit_object() ) );
350 m_context_menu->addAction ( editObject );
351
352 deleteObjectAc = new QAction ( tr ( "&Delete Object" ), this );
353 connect ( deleteObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_delete_objects() ) );
354 m_context_menu->addAction ( deleteObjectAc );
355
356 refByAc = new QAction ( tr ( "Referenced B&y (All objects)" ), this );
357 refByAc->setToolTip ( "Find all objects which reference the selected object" );
358 refByAc->setStatusTip ( refByAc->toolTip() );
359 connect ( refByAc, SIGNAL ( triggered() ), this, SLOT ( referencedBy_All() ) );
360 m_context_menu->addAction ( refByAc );
361
362 refByAcOnlyComp = new QAction ( tr ( "Referenced B&y (Only Composite)" ), this );
363 refByAcOnlyComp->setToolTip (
364 "Find objects (ONLY Composite ones) which reference the selected object" );
365 refByAcOnlyComp->setStatusTip ( refByAcOnlyComp->toolTip() );
366 connect ( refByAcOnlyComp, SIGNAL ( triggered() ), this,
367 SLOT ( referencedBy_OnlyComposite() ) );
368 m_context_menu->addAction ( refByAcOnlyComp );
369
370 copyObjectAc = new QAction ( tr ( "Copy This Object Into A &New One" ), this );
371 connect ( copyObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_copy_object() ) );
372 m_context_menu->addAction ( copyObjectAc );
373
374 m_context_menu->addSeparator();
375 m_last_object_item = m_context_menu->actions().size();
376
377 FindObject = new QAction ( tr ( "&Find Object" ), this );
378 // FindObject->setShortcut ( QKeySequence ( tr ( "Ctrl+F" ) ) );
379 // FindObject->setShortcutContext ( Qt::WidgetShortcut );
380 connect ( FindObject, SIGNAL ( triggered() ), this, SLOT ( FindObjectSlot() ) );
381 // addAction (FindObject);
382 m_context_menu->addAction ( FindObject );
383
384}
385//-----------------------------------------------------------------------------------------------------
386
387//-----------------------------------------------------------------------------------------------------
388void dbe::CustomTableView::referencedBy ( tref obj, bool onlyComposite )
389{
390 if ( not obj.is_null() )
391 {
392 MainWindow::findthis()->get_view()->referencedBy ( onlyComposite, obj );
393 }
394}
395//-----------------------------------------------------------------------------------------------------
396
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()
tref GetTableObject(int ObjectIndex) const
Definition table.cpp:456
#define WARN(...)
Definition messenger.hpp:85
inner::configobject::tref tref
Definition tref.hpp:35