26 : QTableView ( parent ),
27 m_context_menu ( nullptr ),
28 FindObject ( nullptr ),
29 editObject ( nullptr ),
30 deleteObjectAc ( nullptr ),
32 refByAcOnlyComp ( nullptr ),
33 copyObjectAc ( nullptr ),
34 m_find_object_dialog ( nullptr ),
36 NextButton ( nullptr ),
40 verticalHeader()->setVisible(
true);
41 verticalHeader()->setSectionResizeMode ( QHeaderView::Interactive );
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);
52 setTextElideMode(Qt::ElideRight);
54 connect (
this, SIGNAL ( activated(
const QModelIndex&) ),
this, SLOT (
slot_edit_object() ) );
62 if ( m_context_menu ==
nullptr )
64 m_context_menu =
new QMenu (
this );
68 QModelIndex Index = indexAt ( Event->pos() );
70 if ( Index.isValid() ) {
71 for (
int item=0; item<m_last_object_item; ++item) {
72 m_context_menu->actions().at ( item )->setVisible (
true );
76 for (
int item=0; item<m_last_object_item; ++item) {
77 m_context_menu->actions().at ( item )->setVisible (
false );
80 m_context_menu->exec ( Event->globalPos() );
87 if ( m_find_object_dialog !=
nullptr )
89 delete m_find_object_dialog;
90 m_find_object_dialog =
nullptr;
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" );
98 QHBoxLayout * Layout =
new QHBoxLayout ( m_find_object_dialog );
99 QLabel * Label =
new QLabel ( QString (
"Find Object:" ), m_find_object_dialog );
101 NextButton =
new QPushButton (
"Next" );
102 GoButton =
new QPushButton (
"Go !" );
104 LineEdit =
new QLineEdit ( m_find_object_dialog );
105 LineEdit->setToolTip (
"Type string and press Enter" );
107 Layout->addWidget ( Label );
108 Layout->addWidget ( LineEdit );
109 Layout->addWidget ( GoButton );
110 Layout->addWidget ( NextButton );
112 m_find_object_dialog->setLayout ( Layout );
113 m_find_object_dialog->show();
114 NextButton->setDisabled (
true );
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() ) );
130 QString UserType = LineEdit->text();
132 if ( UserType.isEmpty() )
137 QAbstractItemModel * Model = model();
139 if ( Model !=
nullptr )
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 );
146 if ( ListOfMatch.size() > 0 )
149 auto val=ListOfMatch.value ( ListIndex );
150 selectRow ( val.row() );
152 scrollTo (val , QAbstractItemView::PositionAtCenter );
154 GoButton->setDisabled (
true );
155 NextButton->setEnabled (
true );
157 disconnect ( LineEdit, SIGNAL ( returnPressed() ),
this, SLOT ( slot_go_to_object() ) );
158 connect ( LineEdit, SIGNAL ( returnPressed() ),
this, SLOT ( GoToNext() ) );
167 if ( ( LineEdit->text() ).isEmpty() )
174 if ( ListOfMatch.size() > 0 )
176 if ( ( ++ListIndex ) < ListOfMatch.size() )
178 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
179 selectRow ( ListOfMatch.value ( ListIndex ).row() );
180 resizeColumnToContents ( ListIndex );
185 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
186 selectRow ( ListOfMatch.value ( ListIndex ).row() );
187 resizeColumnToContents ( ListIndex );
198 connect ( LineEdit, SIGNAL ( returnPressed() ),
this, SLOT ( slot_go_to_object() ) );
199 disconnect ( LineEdit, SIGNAL ( returnPressed() ),
this, SLOT ( GoToNext() ) );
201 GoButton->setEnabled (
true );
202 NextButton->setDisabled (
true );
306 if ( this->model() !=
nullptr )
308 QModelIndexList qindices = this->selectedIndexes();
309 std::vector<QModelIndex> indices;
311 for ( QModelIndex q : qindices )
315 indices.push_back ( q );
322 casted->delete_objects ( indices.begin(), indices.end() );
327 casted->delete_objects ( indices.begin(), indices.end() );
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" );
343 editObject =
new QAction ( tr (
"&Edit Object" ),
this );
344 connect ( editObject, SIGNAL ( triggered() ),
this, SLOT ( slot_edit_object() ) );
345 m_context_menu->addAction ( editObject );
347 deleteObjectAc =
new QAction ( tr (
"&Delete Object" ),
this );
348 connect ( deleteObjectAc, SIGNAL ( triggered() ),
this, SLOT ( slot_delete_objects() ) );
349 m_context_menu->addAction ( deleteObjectAc );
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 );
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 );
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 );
369 m_context_menu->addSeparator();
370 m_last_object_item = m_context_menu->actions().size();
372 FindObject =
new QAction ( tr (
"&Find Object" ),
this );
375 connect ( FindObject, SIGNAL ( triggered() ),
this, SLOT ( FindObjectSlot() ) );
377 m_context_menu->addAction ( FindObject );
cptr< dbe::CustomTreeView > get_view() const
static MainWindow * findthis()