DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TableTab.cpp
Go to the documentation of this file.
1
2#include <QVBoxLayout>
3#include <QHeaderView>
4#include <QMimeData>
5#include <qevent.h>
6
8#include "dbe/TableTab.hpp"
9#include "dbe/MainWindow.hpp"
10
11//------------------------------------------------------------------------------------------------------
19dbe::TableTab::TableTab ( QWidget * parent )
20 : QWidget ( parent ),
21 this_model ( nullptr ),
22 this_filter ( nullptr ),
23 this_delegate ( nullptr ),
24 this_view ( nullptr )
25{
28 QVBoxLayout * TabLayout = new QVBoxLayout ( this );
29 TabLayout->addWidget ( this_view );
30 this_view->hide();
31 setAcceptDrops ( true );
32 this_holder = dynamic_cast<QTabWidget *> ( parent );
33}
34
36{
37 delete this_model;
38 delete this_filter;
39 delete this_delegate;
40 delete this_view;
41}
42//------------------------------------------------------------------------------------------------------
43
44//------------------------------------------------------------------------------------------------------
46{
47
48 if ( this_model == nullptr )
49 {
50 this_model = new dbe::models::table();
51 connect ( this, SIGNAL ( sig_data_dropped ( QMimeData const &, Qt::DropAction ) ),
52 this_model,
53 SLOT ( slot_data_dropped ( QMimeData const &, Qt::DropAction ) ) );
54 }
55
56 this_delegate = this_delegate == nullptr ? new CustomDelegate() : this_delegate;
57 this_filter = this_filter == nullptr ? new dbe::models::tableselection() : this_filter;
58}
59
61{
62 this_model->ResetModel();
63 this_filter->ResetModel();
64}
65
67{
68 if ( this_model == nullptr )
69 {
70 create_models();
71 }
72 else
73 {
74 reset_models();
75 }
76
77 connect ( this_model, SIGNAL ( ResetTab() ), this, SLOT ( ResetTabView() ) );
78}
79//------------------------------------------------------------------------------------------------------
80
81//------------------------------------------------------------------------------------------------------
83{
84 this_view->setModel ( NULL );
85}
86
88{
89 this_filter->setSourceModel ( this_model );
90
91 this_view->setItemDelegate ( this_delegate );
92 this_view->setModel ( this_filter );
93 this_view->show();
94
95 ResizeHeaders();
96}
97
99{
100 // TODO: at the moment the resize of columns creates too large columns when several data are in a cell
101 // the resize of rows is a little bit expensive with large tables
102 // to be re-evaluated
103 //
104 // if ( this_view->model() != nullptr )
105 // {
106 // this_view->resizeRowsToContents();
107 // this_view->resizeColumnsToContents();
108 // }
109}
110
112{
113 reset_models();
114 ResetTableView();
115 this_holder->setTabText ( this_holder->indexOf ( this ), this_model->get_class_name() );
116}
117//------------------------------------------------------------------------------------------------------
118
119//------------------------------------------------------------------------------------------------------
125void dbe::TableTab::dragEnterEvent ( QDragEnterEvent * event )
126{
127
128 // If there is nothing created then create as needed
129 CreateModels();
130
131 // Check that all mimetypes are supported
132 for ( auto const & mimetype : this_model->mimeTypes() )
133 {
134 if ( not event->mimeData()->hasFormat( mimetype.toStdString().c_str() ) )
135 {
136 event->ignore();
137 return;
138 }
139 }
140
141 // Support only copy actions
142 if ( event->proposedAction() != Qt::DropAction::CopyAction )
143 {
144 return;
145 }
146
147 event->acceptProposedAction();
148
149 // connect signals
150 MainWindow * mainwin = MainWindow::findthis();
151 connect ( GetTableView(), SIGNAL ( OpenEditor ( tref ) ), mainwin,
152 SLOT ( slot_launch_object_editor ( tref ) ), Qt::UniqueConnection );
153 connect ( GetTableDelegate(), SIGNAL ( CreateObjectEditorSignal ( tref ) ), mainwin,
154 SLOT ( slot_launch_object_editor ( tref ) ), Qt::UniqueConnection );
155}
156//------------------------------------------------------------------------------------------------------
157
158//------------------------------------------------------------------------------------------------------
166void dbe::TableTab::dropEvent ( QDropEvent * event )
167{
168 emit sig_data_dropped ( *event->mimeData(), event->proposedAction() );
169}
170//------------------------------------------------------------------------------------------------------
171
172//------------------------------------------------------------------------------------------------------
174{
175 return this_model;
176}
177
179{
180 return this_filter;
181}
182
184{
185 return this_delegate;
186}
187
189{
190 return this_view;
191}
192//------------------------------------------------------------------------------------------------------
static MainWindow * findthis()
void ResetTableView()
Definition TableTab.cpp:87
void create_models()
Definition TableTab.cpp:45
CustomTableView * this_view
Definition TableTab.hpp:40
void CreateModels()
Definition TableTab.cpp:66
QTabWidget * this_holder
Definition TableTab.hpp:41
void ResizeHeaders()
Definition TableTab.cpp:98
TableTab(QWidget *parent=0)
Including Qt.
Definition TableTab.cpp:19
void DisconnectView()
Definition TableTab.cpp:82
void ResetTabView()
Definition TableTab.cpp:111
dbe::models::table * GetTableModel() const
Definition TableTab.cpp:173
void reset_models()
Definition TableTab.cpp:60
dbe::models::tableselection * GetTableFilter() const
Definition TableTab.cpp:178
void dragEnterEvent(QDragEnterEvent *event) override
Definition TableTab.cpp:125
CustomTableView * GetTableView() const
Definition TableTab.cpp:188
void dropEvent(QDropEvent *event) override
Definition TableTab.cpp:166
CustomDelegate * GetTableDelegate() const
Definition TableTab.cpp:183