Line data Source code
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 :
6 : /// Including Qt
7 : #include <QVBoxLayout>
8 : #include <QHeaderView>
9 : #include <QMimeData>
10 : #include <qevent.h>
11 :
12 : /// Including dbe
13 : #include "dbe/TableTab.hpp"
14 : #include "dbe/MainWindow.hpp"
15 :
16 : //------------------------------------------------------------------------------------------------------
17 : /**
18 : * Construct a Tabletab and let everything unitialized until first use
19 : *
20 : * Set the geometry and operational properties of the object
21 : *
22 : * @param parent a pointer to the parent widget
23 : */
24 0 : dbe::TableTab::TableTab ( QWidget * parent )
25 : : QWidget ( parent ),
26 0 : this_model ( nullptr ),
27 0 : this_filter ( nullptr ),
28 0 : this_delegate ( nullptr ),
29 0 : this_view ( nullptr )
30 : {
31 0 : this_view = new CustomTableView();
32 : /// Adjusting layout
33 0 : QVBoxLayout * TabLayout = new QVBoxLayout ( this );
34 0 : TabLayout->addWidget ( this_view );
35 0 : this_view->hide();
36 0 : setAcceptDrops ( true );
37 0 : this_holder = dynamic_cast<QTabWidget *> ( parent );
38 0 : }
39 :
40 0 : dbe::TableTab::~TableTab()
41 : {
42 0 : delete this_model;
43 0 : delete this_filter;
44 0 : delete this_delegate;
45 0 : delete this_view;
46 0 : }
47 : //------------------------------------------------------------------------------------------------------
48 :
49 : //------------------------------------------------------------------------------------------------------
50 0 : void dbe::TableTab::create_models()
51 : {
52 :
53 0 : if ( this_model == nullptr )
54 : {
55 0 : this_model = new dbe::models::table();
56 0 : connect ( this, SIGNAL ( sig_data_dropped ( QMimeData const &, Qt::DropAction ) ),
57 : this_model,
58 : SLOT ( slot_data_dropped ( QMimeData const &, Qt::DropAction ) ) );
59 : }
60 :
61 0 : this_delegate = this_delegate == nullptr ? new CustomDelegate() : this_delegate;
62 0 : this_filter = this_filter == nullptr ? new dbe::models::tableselection() : this_filter;
63 0 : }
64 :
65 0 : void dbe::TableTab::reset_models()
66 : {
67 0 : this_model->ResetModel();
68 0 : this_filter->ResetModel();
69 0 : }
70 :
71 0 : void dbe::TableTab::CreateModels()
72 : {
73 0 : if ( this_model == nullptr )
74 : {
75 0 : create_models();
76 : }
77 : else
78 : {
79 0 : reset_models();
80 : }
81 :
82 0 : connect ( this_model, SIGNAL ( ResetTab() ), this, SLOT ( ResetTabView() ) );
83 0 : }
84 : //------------------------------------------------------------------------------------------------------
85 :
86 : //------------------------------------------------------------------------------------------------------
87 0 : void dbe::TableTab::DisconnectView()
88 : {
89 0 : this_view->setModel ( NULL );
90 0 : }
91 :
92 0 : void dbe::TableTab::ResetTableView()
93 : {
94 0 : this_filter->setSourceModel ( this_model );
95 :
96 0 : this_view->setItemDelegate ( this_delegate );
97 0 : this_view->setModel ( this_filter );
98 0 : this_view->show();
99 :
100 0 : ResizeHeaders();
101 0 : }
102 :
103 0 : void dbe::TableTab::ResizeHeaders()
104 : {
105 : // TODO: at the moment the resize of columns creates too large columns when several data are in a cell
106 : // the resize of rows is a little bit expensive with large tables
107 : // to be re-evaluated
108 : //
109 : // if ( this_view->model() != nullptr )
110 : // {
111 : // this_view->resizeRowsToContents();
112 : // this_view->resizeColumnsToContents();
113 : // }
114 0 : }
115 :
116 0 : void dbe::TableTab::ResetTabView()
117 : {
118 0 : reset_models();
119 0 : ResetTableView();
120 0 : this_holder->setTabText ( this_holder->indexOf ( this ), this_model->get_class_name() );
121 0 : }
122 : //------------------------------------------------------------------------------------------------------
123 :
124 : //------------------------------------------------------------------------------------------------------
125 : /**
126 : * Capture event of the pointer entering the tabletab while dragging something
127 : *
128 : * @param event is a pointer to the associated qt event object
129 : */
130 0 : void dbe::TableTab::dragEnterEvent ( QDragEnterEvent * event )
131 : {
132 :
133 : // If there is nothing created then create as needed
134 0 : CreateModels();
135 :
136 : // Check that all mimetypes are supported
137 0 : for ( auto const & mimetype : this_model->mimeTypes() )
138 : {
139 0 : if ( not event->mimeData()->hasFormat( mimetype.toStdString().c_str() ) )
140 : {
141 0 : event->ignore();
142 0 : return;
143 : }
144 0 : }
145 :
146 : // Support only copy actions
147 0 : if ( event->proposedAction() != Qt::DropAction::CopyAction )
148 : {
149 : return;
150 : }
151 :
152 0 : event->acceptProposedAction();
153 :
154 : // connect signals
155 0 : MainWindow * mainwin = MainWindow::findthis();
156 0 : connect ( GetTableView(), SIGNAL ( OpenEditor ( tref ) ), mainwin,
157 : SLOT ( slot_launch_object_editor ( tref ) ), Qt::UniqueConnection );
158 0 : connect ( GetTableDelegate(), SIGNAL ( CreateObjectEditorSignal ( tref ) ), mainwin,
159 : SLOT ( slot_launch_object_editor ( tref ) ), Qt::UniqueConnection );
160 : }
161 : //------------------------------------------------------------------------------------------------------
162 :
163 : //------------------------------------------------------------------------------------------------------
164 : /**
165 : * Capture a mouse release event of a dragged object
166 : *
167 : * Properly emits a signal to the associated tablemodel, i.e. this is a thread safe operation
168 : *
169 : * @param event is a pointer to the associated qt event object
170 : */
171 0 : void dbe::TableTab::dropEvent ( QDropEvent * event )
172 : {
173 0 : emit sig_data_dropped ( *event->mimeData(), event->proposedAction() );
174 0 : }
175 : //------------------------------------------------------------------------------------------------------
176 :
177 : //------------------------------------------------------------------------------------------------------
178 0 : dbe::models::table * dbe::TableTab::GetTableModel() const
179 : {
180 0 : return this_model;
181 : }
182 :
183 0 : dbe::models::tableselection * dbe::TableTab::GetTableFilter() const
184 : {
185 0 : return this_filter;
186 : }
187 :
188 0 : dbe::CustomDelegate * dbe::TableTab::GetTableDelegate() const
189 : {
190 0 : return this_delegate;
191 : }
192 :
193 0 : dbe::CustomTableView * dbe::TableTab::GetTableView() const
194 : {
195 0 : return this_view;
196 : }
197 : //------------------------------------------------------------------------------------------------------
|