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