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 slot_go_to_object ()
 
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 * m_context_menu
 
QAction * FindObject
 
QAction * editObject
 
QAction * deleteObjectAc
 
QAction * refByAc
 
QAction * refByAcOnlyComp
 
QAction * copyObjectAc
 
QDialog * m_find_object_dialog
 File Dialog.
 
QLineEdit * LineEdit
 
QPushButton * NextButton
 
QPushButton * GoButton
 
int ListIndex
 Match Variables.
 
QModelIndexList ListOfMatch
 
int m_last_object_item
 

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 25 of file CustomTableView.cpp.

26 : QTableView ( parent ),
27 m_context_menu ( nullptr ),
28 FindObject ( nullptr ),
29 editObject ( nullptr ),
30 deleteObjectAc ( nullptr ),
31 refByAc ( nullptr ),
32 refByAcOnlyComp ( nullptr ),
33 copyObjectAc ( nullptr ),
34 m_find_object_dialog ( nullptr ),
35 LineEdit ( nullptr ),
36 NextButton ( nullptr ),
37 GoButton ( nullptr ),
38 ListIndex ( 0 )
39{
40 verticalHeader()->setVisible(true);
41 verticalHeader()->setSectionResizeMode ( QHeaderView::Interactive );
42
43 horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
44 horizontalHeader()->setMaximumSectionSize(750);
45 setSortingEnabled ( true );
46 setAlternatingRowColors ( true );
47 setSelectionMode ( SelectionMode::SingleSelection );
48 setSelectionBehavior ( QAbstractItemView::SelectionBehavior::SelectRows );
49 setHorizontalScrollMode(ScrollMode::ScrollPerPixel);
50 setVerticalScrollMode(ScrollMode::ScrollPerPixel);
51 setWordWrap(true);
52 setTextElideMode(Qt::ElideRight);
53
54 connect ( this, SIGNAL ( activated(const QModelIndex&) ), this, SLOT ( slot_edit_object() ) );
55
56}
int ListIndex
Match Variables.
QDialog * m_find_object_dialog
File Dialog.

Member Function Documentation

◆ contextMenuEvent()

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

Definition at line 60 of file CustomTableView.cpp.

61{
62 if ( m_context_menu == nullptr )
63 {
64 m_context_menu = new QMenu ( this );
66 }
67
68 QModelIndex Index = indexAt ( Event->pos() );
69
70 if ( Index.isValid() ) {
71 for (int item=0; item<m_last_object_item; ++item) {
72 m_context_menu->actions().at ( item )->setVisible ( true );
73 }
74 }
75 else {
76 for (int item=0; item<m_last_object_item; ++item) {
77 m_context_menu->actions().at ( item )->setVisible ( false );
78 }
79 }
80 m_context_menu->exec ( Event->globalPos() );
81}

◆ CreateActions()

void dbe::CustomTableView::CreateActions ( )
private

Definition at line 341 of file CustomTableView.cpp.

342{
343 editObject = new QAction ( tr ( "&Edit Object" ), this );
344 connect ( editObject, SIGNAL ( triggered() ), this, SLOT ( slot_edit_object() ) );
345 m_context_menu->addAction ( editObject );
346
347 deleteObjectAc = new QAction ( tr ( "&Delete Object" ), this );
348 connect ( deleteObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_delete_objects() ) );
349 m_context_menu->addAction ( deleteObjectAc );
350
351 refByAc = new QAction ( tr ( "Referenced B&y (All objects)" ), this );
352 refByAc->setToolTip ( "Find all objects which reference the selected object" );
353 refByAc->setStatusTip ( refByAc->toolTip() );
354 connect ( refByAc, SIGNAL ( triggered() ), this, SLOT ( referencedBy_All() ) );
355 m_context_menu->addAction ( refByAc );
356
357 refByAcOnlyComp = new QAction ( tr ( "Referenced B&y (Only Composite)" ), this );
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 m_context_menu->addAction ( refByAcOnlyComp );
364
365 copyObjectAc = new QAction ( tr ( "Copy This Object Into A &New One" ), this );
366 connect ( copyObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_copy_object() ) );
367 m_context_menu->addAction ( copyObjectAc );
368
369 m_context_menu->addSeparator();
370 m_last_object_item = m_context_menu->actions().size();
371
372 FindObject = new QAction ( tr ( "&Find Object" ), this );
373 // FindObject->setShortcut ( QKeySequence ( tr ( "Ctrl+F" ) ) );
374 // FindObject->setShortcutContext ( Qt::WidgetShortcut );
375 connect ( FindObject, SIGNAL ( triggered() ), this, SLOT ( FindObjectSlot() ) );
376 // addAction (FindObject);
377 m_context_menu->addAction ( FindObject );
378
379}

◆ EditedSearchString

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

Definition at line 194 of file CustomTableView.cpp.

195{
196 Q_UNUSED ( Text )
197
198 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( slot_go_to_object() ) );
199 disconnect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToNext() ) );
200
201 GoButton->setEnabled ( true );
202 NextButton->setDisabled ( true );
203}

◆ FindObjectSlot

void dbe::CustomTableView::FindObjectSlot ( )
privateslot

Definition at line 85 of file CustomTableView.cpp.

86{
87 if ( m_find_object_dialog != nullptr )
88 {
90 m_find_object_dialog = nullptr;
91 }
92
93 m_find_object_dialog = new QDialog ( this );
94 m_find_object_dialog->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
95 m_find_object_dialog->setToolTip ( "Type string to edit line and press Enter." );
96 m_find_object_dialog->setWindowTitle ( "Search for an object in the table" );
97
98 QHBoxLayout * Layout = new QHBoxLayout ( m_find_object_dialog );
99 QLabel * Label = new QLabel ( QString ( "Find Object:" ), m_find_object_dialog );
100
101 NextButton = new QPushButton ( "Next" );
102 GoButton = new QPushButton ( "Go !" );
103
104 LineEdit = new QLineEdit ( m_find_object_dialog );
105 LineEdit->setToolTip ( "Type string and press Enter" );
106
107 Layout->addWidget ( Label );
108 Layout->addWidget ( LineEdit );
109 Layout->addWidget ( GoButton );
110 Layout->addWidget ( NextButton );
111
112 m_find_object_dialog->setLayout ( Layout );
113 m_find_object_dialog->show();
114 NextButton->setDisabled ( true );
115
116 connect ( LineEdit, SIGNAL ( textEdited ( QString ) ), this,
117 SLOT ( EditedSearchString ( QString ) ) );
118 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( slot_go_to_object() ) );
119 connect ( GoButton, SIGNAL ( clicked() ), this, SLOT ( slot_go_to_object() ) );
120 connect ( NextButton, SIGNAL ( clicked() ), this, SLOT ( GoToNext() ) );
121}
void EditedSearchString(QString Text)

◆ GoToNext

void dbe::CustomTableView::GoToNext ( )
privateslot

Definition at line 165 of file CustomTableView.cpp.

166{
167 if ( ( LineEdit->text() ).isEmpty() )
168 {
169 ListIndex = 0;
170 ListOfMatch.clear();
171 return;
172 }
173
174 if ( ListOfMatch.size() > 0 )
175 {
176 if ( ( ++ListIndex ) < ListOfMatch.size() )
177 {
178 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
179 selectRow ( ListOfMatch.value ( ListIndex ).row() );
180 resizeColumnToContents ( ListIndex );
181 }
182 else
183 {
184 ListIndex = 0;
185 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
186 selectRow ( ListOfMatch.value ( ListIndex ).row() );
187 resizeColumnToContents ( ListIndex );
188 }
189 }
190}
QModelIndexList ListOfMatch

◆ OpenEditor

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

◆ referencedBy()

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

Definition at line 383 of file CustomTableView.cpp.

384{
385 if ( not obj.is_null() )
386 {
387 MainWindow::findthis()->get_view()->referencedBy ( onlyComposite, obj );
388 }
389}
cptr< dbe::CustomTreeView > get_view() const
static MainWindow * findthis()

◆ referencedBy_All

void dbe::CustomTableView::referencedBy_All ( )
privateslot

Definition at line 253 of file CustomTableView.cpp.

254{
255 QModelIndex const & Index = this->currentIndex();
256 const dbe::models::tableselection * Model =
257 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
258
259 dbe::models::table const * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
260 ->sourceModel() );
261
262 if ( !Index.isValid() || !Model )
263 {
264 return;
265 }
266
267 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
268 referencedBy ( obj, false );
269}
void referencedBy(tref obj, bool onlyComposite)
tref GetTableObject(int ObjectIndex) const
Definition table.cpp:451
inner::configobject::tref tref
Definition tref.hpp:30

◆ referencedBy_OnlyComposite

void dbe::CustomTableView::referencedBy_OnlyComposite ( )
privateslot

Definition at line 232 of file CustomTableView.cpp.

233{
234 QModelIndex const & Index = this->currentIndex();
235
236 const dbe::models::tableselection * Model =
237 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
238
239 const dbe::models::table * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
240 ->sourceModel() );
241
242 if ( !Index.isValid() || !Model )
243 {
244 return;
245 }
246
247 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
248 referencedBy ( obj, true );
249}

◆ slot_copy_object

void dbe::CustomTableView::slot_copy_object ( )
privateslot

Definition at line 273 of file CustomTableView.cpp.

274{
275 QModelIndex const & Index = this->currentIndex();
276
277 dbe::models::tableselection const * Model =
278 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
279
280 dbe::models::table const * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
281 ->sourceModel() );
282
283 if ( Index.isValid() and Model )
284 {
285 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
286
287 if ( not obj.is_null() )
288 {
289 ( new ObjectCreator ( obj ) )->show();
290 }
291 }
292}

◆ slot_create_object

void dbe::CustomTableView::slot_create_object ( )
privateslot

Definition at line 296 of file CustomTableView.cpp.

297{
298 // TODO implement dbe::CustomTableView::slot_create_object
299 throw std::string ( " dbe::CustomTableView::slot_create_object is not yet implemented " );
300}

◆ slot_delete_objects

void dbe::CustomTableView::slot_delete_objects ( )
privateslot

Definition at line 304 of file CustomTableView.cpp.

305{
306 if ( this->model() != nullptr )
307 {
308 QModelIndexList qindices = this->selectedIndexes();
309 std::vector<QModelIndex> indices;
310
311 for ( QModelIndex q : qindices )
312 {
313 if ( q.isValid() )
314 {
315 indices.push_back ( q );
316 }
317 }
318
319 if ( dbe::models::tableselection * casted =
320 dynamic_cast<dbe::models::tableselection *> ( this->model() ) )
321 {
322 casted->delete_objects ( indices.begin(), indices.end() );
323 }
324 else if ( dbe::models::table * casted = dynamic_cast<dbe::models::table *>
325 ( this->model() ) )
326 {
327 casted->delete_objects ( indices.begin(), indices.end() );
328 }
329 else
330 {
331 WARN ( "Object Deleting",
332 "Object deletion failed due to the internal model being in invalid state",
333 "You are advised to restart the application before proceeding any further" );
334 }
335 }
336
337}
#define WARN(...)
Definition messenger.hpp:80

◆ slot_edit_object

void dbe::CustomTableView::slot_edit_object ( )
privateslot

Definition at line 207 of file CustomTableView.cpp.

208{
209 QModelIndex const & index = this->currentIndex();
210
211 if ( index.isValid() )
212 {
213 if ( models::tableselection const * selectionmodel =
214 dynamic_cast<models::tableselection const *> ( index.model() ) )
215 {
216 if ( models::table const * srcmodel =
217 dynamic_cast<const dbe::models::table *> ( selectionmodel->sourceModel() ) )
218 {
219 tref obj = srcmodel->GetTableObject ( selectionmodel->mapToSource ( index ).row() );
220
221 if ( not obj.is_null() )
222 {
223 emit OpenEditor ( obj );
224 }
225 }
226 }
227 }
228}
void OpenEditor(tref Object)

◆ slot_go_to_object

void dbe::CustomTableView::slot_go_to_object ( )
privateslot

Definition at line 125 of file CustomTableView.cpp.

126{
127 ListIndex = 0;
128 ListOfMatch.clear();
129
130 QString UserType = LineEdit->text();
131
132 if ( UserType.isEmpty() )
133 {
134 return;
135 }
136
137 QAbstractItemModel * Model = model();
138
139 if ( Model != nullptr )
140 {
141 QVariant StringCriterium = QVariant ( UserType );
142 QModelIndex WhereToStartSearch = Model->index ( 0, 0 );
143 ListOfMatch = Model->match ( WhereToStartSearch, Qt::DisplayRole, StringCriterium, 1000,
144 Qt::MatchContains | Qt::MatchWrap );
145
146 if ( ListOfMatch.size() > 0 )
147 {
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}

Member Data Documentation

◆ 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.

◆ 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.

◆ m_context_menu

QMenu* dbe::CustomTableView::m_context_menu
private

Definition at line 49 of file CustomTableView.hpp.

◆ m_find_object_dialog

QDialog* dbe::CustomTableView::m_find_object_dialog
private

File Dialog.

Definition at line 58 of file CustomTableView.hpp.

◆ m_last_object_item

int dbe::CustomTableView::m_last_object_item
private

Definition at line 67 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: