DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CustomDelegate.cpp
Go to the documentation of this file.
5#include "dbe/TableNode.hpp"
6#include "dbe/Validator.hpp"
7//#include "dbe/MainWindow.hpp"
8
9#include <QKeyEvent>
10#include <QCompleter>
11
13 : QItemDelegate ( parent )
14{
15 setClipping ( true );
16}
17
18QWidget * dbe::CustomDelegate::createEditor ( QWidget * parent,
19 const QStyleOptionViewItem & option,
20 const QModelIndex & index ) const
21{
22 Q_UNUSED ( option );
23 const dbe::models::tableselection * Model =
24 dynamic_cast<const dbe::models::tableselection *> ( index.model() );
25
26 const dbe::models::table * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
27 ->sourceModel() );
28
29 TableNode * Item = Model->getnode ( index );
30
31 tref Object = SourceModel->GetTableObject ( Model->mapToSource ( index ).row() );
32
33 if ( Model == nullptr )
34 {
35 return nullptr;
36 }
37
38 if ( index.column() == 0 )
39 {
40 emit CreateObjectEditorSignal ( Object );
41 return nullptr;
42 }
43
44 if ( dynamic_cast<TableRelationshipNode *> ( Item ) )
45 {
46 TableRelationshipNode * RelationshipItem = dynamic_cast<TableRelationshipNode *> ( Item );
47 dunedaq::conffwk::relationship_t RelationshipData = RelationshipItem->GetRelationship();
48 widgets::editors::relation * Editor = new widgets::editors::relation ( RelationshipData );
49 connect ( Editor, SIGNAL ( signal_edit_end() ), this, SLOT ( CommitAndClose() ) );
50 connect ( Editor, SIGNAL ( signal_force_close() ), this, SLOT ( Close() ) );
51 return Editor;
52 }
53 else if ( dynamic_cast<TableAttributeNode *> ( Item ) )
54 {
55 TableAttributeNode * AttributeItem = dynamic_cast<TableAttributeNode *> ( Item );
56 dunedaq::conffwk::attribute_t AttributeData = AttributeItem->GetAttribute();
57
58 if ( AttributeData.p_is_multi_value )
59 {
60 widgets::editors::multiattr * widget = new widgets::editors::multiattr(AttributeData);
61 connect ( widget, SIGNAL ( signal_edit_end() ), this, SLOT ( CommitAndClose() ) );
62 connect ( widget, SIGNAL ( signal_force_close() ), this, SLOT ( Close() ) );
63 return widget;
64 }
65 else
66 {
67 switch ( AttributeData.p_type )
68 {
69
71
73
75 {
77 parent );
78 connect ( Editor, SIGNAL ( signal_edit_end() ), this, SLOT ( CommitAndClose() ) );
79 connect ( Editor, SIGNAL ( signal_force_close() ), this, SLOT ( Close() ) );
80 return Editor;
81 }
82
84
86
88
90
92
94
96
98
100
102 {
104 parent );
105 connect ( Editor, SIGNAL ( signal_edit_end() ), this, SLOT ( CommitAndClose() ) );
106 connect ( Editor, SIGNAL ( signal_force_close() ), this, SLOT ( Close() ) );
107 return Editor;
108 }
109
111
113 {
114 widgets::editors::combo * Editor = new widgets::editors::combo ( AttributeData, parent );
115 connect ( Editor, SIGNAL ( signal_value_change() ), this, SLOT ( CommitAndClose() ) );
116 connect ( Editor, SIGNAL ( signal_force_close() ), this, SLOT ( Close() ) );
117 return Editor;
118 }
119
121 {
122 widgets::editors::combo * Editor = new widgets::editors::combo ( AttributeData, parent );
123 connect ( Editor, SIGNAL ( signal_edit_end() ), this, SLOT ( CommitAndClose() ) );
124 connect ( Editor, SIGNAL ( signal_force_close() ), this, SLOT ( Close() ) );
125 return Editor;
126 }
127
128 default:
129 break;
130 }
131 }
132 }
133
134 return nullptr;
135}
136
138 const QModelIndex & index ) const
139{
140 const dbe::models::tableselection * mdl =
141 dynamic_cast<const dbe::models::tableselection *> ( index.model() );
142
143 if ( mdl != nullptr || editor != nullptr )
144 {
145 if ( widgets::editors::base * w = dynamic_cast<widgets::editors::base *> ( editor ) )
146 {
147 QStringList const & data = mdl->getnode ( index )->GetData();
148 w->setdata ( data );
149 w->SetEditor();
150 }
151 }
152}
153
154void dbe::CustomDelegate::setModelData ( QWidget * editor, QAbstractItemModel * model,
155 const QModelIndex & index ) const
156{
157 const dbe::models::tableselection * Model =
158 dynamic_cast<const dbe::models::tableselection *> ( index.model() );
159
160 if ( Model == nullptr || editor == nullptr )
161 {
162 return;
163 }
164
165 widgets::editors::base * WidgetInterface = dynamic_cast<widgets::editors::base *>
166 ( editor );
167
168 QStringList ValueList = WidgetInterface->getdata();
169
170 model->setData ( index, ValueList, Qt::EditRole );
171}
172
173void dbe::CustomDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option,
174 const QModelIndex & index ) const
175{
176 QItemDelegate::paint(painter, option, index);
177
178 // TODO: now commented-out because of small issues with text rendering
179 // indeed the text is too close to the cell's borders and some times artifacts are present
180 // the alternate colors have been anyway enabled in the table view
181 // so basically we miss the back-ground for the first column
182
183 // painter->save();
184 //
185 // QFont fontmodif = option.font;
186 //
187 // if ( option.state & QStyle::State_Selected )
188 // {
189 // painter->setBackground ( option.palette.mid() );
190 // painter->setRenderHint ( QPainter::Antialiasing, true );
191 // }
192 // else if ( index.column() == 0 )
193 // {
194 // painter->setBackground ( QColor::fromRgb ( 75, 222, 148 ) );
195 // fontmodif.setBold ( true );
196 // }
197 // else if ( index.row() % 2 == 1 )
198 // {
199 // painter->setBackground ( Qt::lightGray );
200 // }
201 // else
202 // {
203 // painter->setBackground ( Qt::white );
204 // }
205 //
206 // painter->setFont ( fontmodif );
207 // painter->fillRect ( option.rect, painter->background() );
208 // painter->drawText ( option.rect, option.displayAlignment, index.data().toString() );
209 //
210 // painter->restore();
211}
212
214 const QStyleOptionViewItem & option,
215 const QModelIndex & index ) const
216{
217 Q_UNUSED ( index );
218 editor->setGeometry ( option.rect );
219}
220
221bool dbe::CustomDelegate::eventFilter ( QObject * editor, QEvent * event )
222{
223 if ( event->type() == QEvent::KeyPress )
224 {
225 QKeyEvent * KeyEvent = static_cast<QKeyEvent *> ( event );
226
227 if ( KeyEvent->key() == Qt::Key_Enter || KeyEvent->key() == Qt::Key_Return )
228 {
229 if ( dynamic_cast<widgets::editors::combo *> ( editor ) != 0 )
230 {
231 return QItemDelegate::eventFilter (
232 editor, event );
233 }
234 else
235 {
236 return true;
237 }
238 }
239 }
240 else if ( event->type() == QEvent::FocusOut )
241 {
242 return true;
243 }
244
245 return QItemDelegate::eventFilter ( editor, event );
246}
247
248bool dbe::CustomDelegate::editorEvent ( QEvent * event, QAbstractItemModel * model,
249 const QStyleOptionViewItem & option,
250 const QModelIndex & index )
251{
252 if ( ! ( event->type() == QEvent::MouseButtonPress
253 || event->type() == QEvent::MouseButtonRelease ) )
254 {
255 if ( dynamic_cast<QKeyEvent *> ( event ) )
256 {
257 QKeyEvent * KeyEvent = static_cast<QKeyEvent *> ( event );
258
259 if ( KeyEvent->text() != "e" )
260 {
261 return true;
262 }
263 }
264 }
265
266 return QItemDelegate::editorEvent ( event, model, option, index );
267}
268
270{
271 widgets::editors::base * Editor = qobject_cast<widgets::editors::base *> ( sender() );
272
273 if ( Editor )
274 {
275 emit commitData ( Editor );
276 emit closeEditor ( Editor );
277 return;
278 }
279}
280
282{
283 widgets::editors::base * Editor = qobject_cast<widgets::editors::base *> ( sender() );
284
285 if ( Editor )
286 {
287 emit closeEditor ( Editor );
288 return;
289 }
290}
CustomDelegate(QObject *parent=0)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setEditorData(QWidget *editor, const QModelIndex &index) const
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
bool eventFilter(QObject *editor, QEvent *event)
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
dunedaq::conffwk::attribute_t GetAttribute() const
Definition TableNode.cpp:32
virtual QStringList GetData() const
Definition TableNode.cpp:13
dunedaq::conffwk::relationship_t GetRelationship() const
Definition TableNode.cpp:52
tref GetTableObject(int ObjectIndex) const
Definition table.cpp:430
TableNode * getnode(const QModelIndex &index) const