DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::CustomTableView Class Reference

#include <CustomTableView.hpp>

Inheritance diagram for dbe::CustomTableView:
[legend]
Collaboration diagram for dbe::CustomTableView:
[legend]

Signals

void OpenEditor (tref Object)
 

Public Member Functions

 CustomTableView (QWidget *parent=0)
 Including QT#include <QHeaderView>
 
void contextMenuEvent (QContextMenuEvent *Event)
 
- Public Member Functions inherited from dbe::view_common_interface
virtual ~view_common_interface ()=default
 
virtual void slot_delete_objects ()=0
 
virtual void slot_create_object ()=0
 
virtual void slot_edit_object ()=0
 
virtual void slot_copy_object ()=0
 

Private Slots

void slot_delete_objects ()
 
void slot_create_object ()
 
void slot_edit_object ()
 
void slot_copy_object ()
 
void FindObjectSlot ()
 
void GoToFile ()
 
void GoToNext ()
 
void EditedSearchString (QString Text)
 
void referencedBy_OnlyComposite ()
 
void referencedBy_All ()
 

Private Member Functions

void CreateActions ()
 
void referencedBy (tref obj, bool onlyComposite)
 

Private Attributes

QMenu * ContextMenu
 
QAction * FindObject
 
QAction * editObject
 
QAction * deleteObjectAc
 
QAction * refByAc
 
QAction * refByAcOnlyComp
 
QAction * copyObjectAc
 
QDialog * FindFileDialog
 File Dialog.
 
QLineEdit * LineEdit
 
QPushButton * NextButton
 
QPushButton * GoButton
 
int ListIndex
 Match Variables.
 
QModelIndexList ListOfMatch
 

Detailed Description

Definition at line 17 of file CustomTableView.hpp.

Constructor & Destructor Documentation

◆ CustomTableView()

dbe::CustomTableView::CustomTableView ( QWidget * parent = 0)
explicit

Including QT#include <QHeaderView>

Including DBE

Definition at line 24 of file CustomTableView.cpp.

25 : QTableView ( parent ),
26 ContextMenu ( nullptr ),
27 FindObject ( nullptr ),
28 editObject ( nullptr ),
29 deleteObjectAc ( nullptr ),
30 refByAc ( nullptr ),
31 refByAcOnlyComp ( nullptr ),
32 copyObjectAc ( nullptr ),
33 FindFileDialog ( nullptr ),
34 LineEdit ( nullptr ),
35 NextButton ( nullptr ),
36 GoButton ( nullptr ),
37 ListIndex ( 0 )
38{
39 verticalHeader()->setVisible(true);
40 verticalHeader()->setSectionResizeMode ( QHeaderView::Interactive );
41 verticalHeader()->setMinimumSectionSize(40);
42 horizontalHeader()->setSectionResizeMode( QHeaderView::Interactive );
43 horizontalHeader()->setDefaultSectionSize(250);
44 setSortingEnabled ( true );
45 setAlternatingRowColors ( true );
46 setSelectionMode ( SelectionMode::SingleSelection );
47 setHorizontalScrollMode(ScrollMode::ScrollPerPixel);
48 setVerticalScrollMode(ScrollMode::ScrollPerPixel);
49 setWordWrap(true);
50 setTextElideMode(Qt::ElideRight);
51}
int ListIndex
Match Variables.
QDialog * FindFileDialog
File Dialog.

Member Function Documentation

◆ contextMenuEvent()

void dbe::CustomTableView::contextMenuEvent ( QContextMenuEvent * Event)

Definition at line 55 of file CustomTableView.cpp.

56{
57 if ( ContextMenu == nullptr )
58 {
59 ContextMenu = new QMenu ( this );
61 }
62
63 QModelIndex Index = indexAt ( Event->pos() );
64
65 if ( Index.isValid() )
66 {
67 ContextMenu->exec ( Event->globalPos() );
68 }
69}

◆ CreateActions()

void dbe::CustomTableView::CreateActions ( )
private

Definition at line 328 of file CustomTableView.cpp.

329{
330 FindObject = new QAction ( tr ( "Find Object" ), this );
331 FindObject->setShortcutContext ( Qt::WidgetShortcut );
332 connect ( FindObject, SIGNAL ( triggered() ), this, SLOT ( FindObjectSlot() ) );
333 ContextMenu->addAction ( FindObject );
334
335 editObject = new QAction ( tr ( "&Edit Object" ), this );
336 editObject->setShortcut ( tr ( "Ctrl+E" ) );
337 editObject->setShortcutContext ( Qt::WidgetShortcut );
338 connect ( editObject, SIGNAL ( triggered() ), this, SLOT ( slot_edit_object() ) );
339 ContextMenu->addAction ( editObject );
340
341 deleteObjectAc = new QAction ( tr ( "&Delete Object" ), this );
342 deleteObjectAc->setShortcut ( tr ( "Ctrl+D" ) );
343 deleteObjectAc->setShortcutContext ( Qt::WidgetShortcut );
344 connect ( deleteObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_delete_objects() ) );
345 ContextMenu->addAction ( deleteObjectAc );
346
347 refByAc = new QAction ( tr ( "Referenced B&y (All objects)" ), this );
348 refByAc->setShortcut ( tr ( "Ctrl+Y" ) );
349 refByAc->setShortcutContext ( Qt::WidgetShortcut );
350 refByAc->setToolTip ( "Find all objects which reference the selected object" );
351 refByAc->setStatusTip ( refByAc->toolTip() );
352 connect ( refByAc, SIGNAL ( triggered() ), this, SLOT ( referencedBy_All() ) );
353 ContextMenu->addAction ( refByAc );
354
355 refByAcOnlyComp = new QAction ( tr ( "Referenced B&y (Only Composite)" ), this );
356 refByAcOnlyComp->setShortcut ( tr ( "Ctrl+Shift+Y" ) );
357 refByAcOnlyComp->setShortcutContext ( Qt::WidgetShortcut );
358 refByAcOnlyComp->setToolTip (
359 "Find objects (ONLY Composite ones) which reference the selected object" );
360 refByAcOnlyComp->setStatusTip ( refByAcOnlyComp->toolTip() );
361 connect ( refByAcOnlyComp, SIGNAL ( triggered() ), this,
362 SLOT ( referencedBy_OnlyComposite() ) );
363 ContextMenu->addAction ( refByAcOnlyComp );
364
365 copyObjectAc = new QAction ( tr ( "Copy This Object Into A &New One" ), this );
366 copyObjectAc->setShortcut ( tr ( "Ctrl+Shift+N" ) );
367 copyObjectAc->setShortcutContext ( Qt::WidgetShortcut );
368 connect ( copyObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_copy_object() ) );
369 ContextMenu->addAction ( copyObjectAc );
370}

◆ EditedSearchString

void dbe::CustomTableView::EditedSearchString ( QString Text)
privateslot

Definition at line 181 of file CustomTableView.cpp.

182{
183 Q_UNUSED ( Text )
184
185 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToFile() ) );
186 disconnect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToNext() ) );
187
188 GoButton->setEnabled ( true );
189 NextButton->setDisabled ( true );
190}

◆ FindObjectSlot

void dbe::CustomTableView::FindObjectSlot ( )
privateslot

Definition at line 73 of file CustomTableView.cpp.

74{
75 if ( FindFileDialog != nullptr )
76 {
77 delete FindFileDialog;
78 FindFileDialog = nullptr;
79 }
80
81 FindFileDialog = new QDialog ( this );
82 FindFileDialog->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
83 FindFileDialog->setToolTip ( "Type string to edit line and press Enter." );
84 FindFileDialog->setWindowTitle ( "Search for an object in the table" );
85
86 QHBoxLayout * Layout = new QHBoxLayout ( FindFileDialog );
87 QLabel * Label = new QLabel ( QString ( "Find Object:" ), FindFileDialog );
88
89 NextButton = new QPushButton ( "Next" );
90 GoButton = new QPushButton ( "Go !" );
91
92 LineEdit = new QLineEdit ( FindFileDialog );
93 LineEdit->setToolTip ( "Type string and press Enter" );
94
95 Layout->addWidget ( Label );
96 Layout->addWidget ( LineEdit );
97 Layout->addWidget ( GoButton );
98 Layout->addWidget ( NextButton );
99
100 FindFileDialog->setLayout ( Layout );
101 FindFileDialog->show();
102 NextButton->setDisabled ( true );
103
104 connect ( LineEdit, SIGNAL ( textEdited ( QString ) ), this,
105 SLOT ( EditedSearchString ( QString ) ) );
106 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToFile() ) );
107 connect ( GoButton, SIGNAL ( clicked() ), this, SLOT ( GoToFile() ) );
108 connect ( NextButton, SIGNAL ( clicked() ), this, SLOT ( GoToNext() ) );
109}
void EditedSearchString(QString Text)

◆ GoToFile

void dbe::CustomTableView::GoToFile ( )
privateslot

Definition at line 113 of file CustomTableView.cpp.

114{
115 ListIndex = 0;
116 ListOfMatch.clear();
117
118 QString UserType = LineEdit->text();
119
120 if ( UserType.isEmpty() )
121 {
122 return;
123 }
124
125 QAbstractItemModel * Model = model();
126
127 if ( Model != nullptr )
128 {
129 QVariant StringCriterium = QVariant ( UserType );
130 QModelIndex WhereToStartSearch = Model->index ( 0, 0 );
131 ListOfMatch = Model->match ( WhereToStartSearch, Qt::DisplayRole, StringCriterium, 1000,
132 Qt::MatchContains | Qt::MatchWrap );
133
134 if ( ListOfMatch.size() > 0 )
135 {
136 ListIndex = 0;
137 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
138 selectRow ( ListOfMatch.value ( ListIndex ).row() );
139 resizeColumnToContents ( ListIndex );
140
141 GoButton->setDisabled ( true );
142 NextButton->setEnabled ( true );
143
144 disconnect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToFile() ) );
145 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToNext() ) );
146 }
147 }
148}
QModelIndexList ListOfMatch

◆ GoToNext

void dbe::CustomTableView::GoToNext ( )
privateslot

Definition at line 152 of file CustomTableView.cpp.

153{
154 if ( ( LineEdit->text() ).isEmpty() )
155 {
156 ListIndex = 0;
157 ListOfMatch.clear();
158 return;
159 }
160
161 if ( ListOfMatch.size() > 0 )
162 {
163 if ( ( ++ListIndex ) < ListOfMatch.size() )
164 {
165 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
166 selectRow ( ListOfMatch.value ( ListIndex ).row() );
167 resizeColumnToContents ( ListIndex );
168 }
169 else
170 {
171 ListIndex = 0;
172 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
173 selectRow ( ListOfMatch.value ( ListIndex ).row() );
174 resizeColumnToContents ( ListIndex );
175 }
176 }
177}

◆ OpenEditor

void dbe::CustomTableView::OpenEditor ( tref Object)
signal

◆ referencedBy()

void dbe::CustomTableView::referencedBy ( tref obj,
bool onlyComposite )
private

Definition at line 374 of file CustomTableView.cpp.

375{
376 if ( not obj.is_null() )
377 {
378 MainWindow::findthis()->get_view()->referencedBy ( onlyComposite, obj );
379 }
380}
cptr< dbe::CustomTreeView > get_view() const
static MainWindow * findthis()

◆ referencedBy_All

void dbe::CustomTableView::referencedBy_All ( )
privateslot

Definition at line 240 of file CustomTableView.cpp.

241{
242 QModelIndex const & Index = this->currentIndex();
243 const dbe::models::tableselection * Model =
244 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
245
246 dbe::models::table const * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
247 ->sourceModel() );
248
249 if ( !Index.isValid() || !Model )
250 {
251 return;
252 }
253
254 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
255 referencedBy ( obj, false );
256}
void referencedBy(tref obj, bool onlyComposite)
tref GetTableObject(int ObjectIndex) const
Definition table.cpp:430
inner::configobject::tref tref
Definition tref.hpp:30

◆ referencedBy_OnlyComposite

void dbe::CustomTableView::referencedBy_OnlyComposite ( )
privateslot

Definition at line 219 of file CustomTableView.cpp.

220{
221 QModelIndex const & Index = this->currentIndex();
222
223 const dbe::models::tableselection * Model =
224 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
225
226 const dbe::models::table * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
227 ->sourceModel() );
228
229 if ( !Index.isValid() || !Model )
230 {
231 return;
232 }
233
234 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
235 referencedBy ( obj, true );
236}

◆ slot_copy_object

void dbe::CustomTableView::slot_copy_object ( )
privateslot

Definition at line 260 of file CustomTableView.cpp.

261{
262 QModelIndex const & Index = this->currentIndex();
263
264 dbe::models::tableselection const * Model =
265 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
266
267 dbe::models::table const * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
268 ->sourceModel() );
269
270 if ( Index.isValid() and Model )
271 {
272 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
273
274 if ( not obj.is_null() )
275 {
276 ( new ObjectCreator ( obj ) )->show();
277 }
278 }
279}

◆ slot_create_object

void dbe::CustomTableView::slot_create_object ( )
privateslot

Definition at line 283 of file CustomTableView.cpp.

284{
285 // TODO implement dbe::CustomTableView::slot_create_object
286 throw std::string ( " dbe::CustomTableView::slot_create_object is not yet implemented " );
287}

◆ slot_delete_objects

void dbe::CustomTableView::slot_delete_objects ( )
privateslot

Definition at line 291 of file CustomTableView.cpp.

292{
293 if ( this->model() != nullptr )
294 {
295 QModelIndexList qindices = this->selectedIndexes();
296 std::vector<QModelIndex> indices;
297
298 for ( QModelIndex q : qindices )
299 {
300 if ( q.isValid() )
301 {
302 indices.push_back ( q );
303 }
304 }
305
306 if ( dbe::models::tableselection * casted =
307 dynamic_cast<dbe::models::tableselection *> ( this->model() ) )
308 {
309 casted->delete_objects ( indices.begin(), indices.end() );
310 }
311 else if ( dbe::models::table * casted = dynamic_cast<dbe::models::table *>
312 ( this->model() ) )
313 {
314 casted->delete_objects ( indices.begin(), indices.end() );
315 }
316 else
317 {
318 WARN ( "Object Deleting",
319 "Object deletion failed due to the internal model being in invalid state",
320 "You are advised to restart the application before proceeding any further" );
321 }
322 }
323
324}
#define WARN(...)
Definition messenger.hpp:80

◆ slot_edit_object

void dbe::CustomTableView::slot_edit_object ( )
privateslot

Definition at line 194 of file CustomTableView.cpp.

195{
196 QModelIndex const & index = this->currentIndex();
197
198 if ( index.isValid() )
199 {
200 if ( models::tableselection const * selectionmodel =
201 dynamic_cast<models::tableselection const *> ( index.model() ) )
202 {
203 if ( models::table const * srcmodel =
204 dynamic_cast<const dbe::models::table *> ( selectionmodel->sourceModel() ) )
205 {
206 tref obj = srcmodel->GetTableObject ( selectionmodel->mapToSource ( index ).row() );
207
208 if ( not obj.is_null() )
209 {
210 emit OpenEditor ( obj );
211 }
212 }
213 }
214 }
215}
void OpenEditor(tref Object)

Member Data Documentation

◆ ContextMenu

QMenu* dbe::CustomTableView::ContextMenu
private

Definition at line 49 of file CustomTableView.hpp.

◆ copyObjectAc

QAction* dbe::CustomTableView::copyObjectAc
private

Definition at line 55 of file CustomTableView.hpp.

◆ deleteObjectAc

QAction* dbe::CustomTableView::deleteObjectAc
private

Definition at line 52 of file CustomTableView.hpp.

◆ editObject

QAction* dbe::CustomTableView::editObject
private

Definition at line 51 of file CustomTableView.hpp.

◆ FindFileDialog

QDialog* dbe::CustomTableView::FindFileDialog
private

File Dialog.

Definition at line 58 of file CustomTableView.hpp.

◆ FindObject

QAction* dbe::CustomTableView::FindObject
private

Definition at line 50 of file CustomTableView.hpp.

◆ GoButton

QPushButton* dbe::CustomTableView::GoButton
private

Definition at line 61 of file CustomTableView.hpp.

◆ LineEdit

QLineEdit* dbe::CustomTableView::LineEdit
private

Definition at line 59 of file CustomTableView.hpp.

◆ ListIndex

int dbe::CustomTableView::ListIndex
private

Match Variables.

Definition at line 64 of file CustomTableView.hpp.

◆ ListOfMatch

QModelIndexList dbe::CustomTableView::ListOfMatch
private

Definition at line 65 of file CustomTableView.hpp.

◆ NextButton

QPushButton* dbe::CustomTableView::NextButton
private

Definition at line 60 of file CustomTableView.hpp.

◆ refByAc

QAction* dbe::CustomTableView::refByAc
private

Definition at line 53 of file CustomTableView.hpp.

◆ refByAcOnlyComp

QAction* dbe::CustomTableView::refByAcOnlyComp
private

Definition at line 54 of file CustomTableView.hpp.


The documentation for this class was generated from the following files: