DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::CustomDelegate Class Reference

#include <CustomDelegate.hpp>

Inheritance diagram for dbe::CustomDelegate:
[legend]
Collaboration diagram for dbe::CustomDelegate:
[legend]

Signals

void CreateObjectEditorSignal (tref Object) const

Public Member Functions

 CustomDelegate (QObject *parent=0)
QWidget * createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setEditorData (QWidget *editor, const QModelIndex &index) const
void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
bool eventFilter (QObject *editor, QEvent *event)
bool editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const

Private Slots

void CommitAndClose ()
void Close ()

Detailed Description

Definition at line 16 of file CustomDelegate.hpp.

Constructor & Destructor Documentation

◆ CustomDelegate()

dbe::CustomDelegate::CustomDelegate ( QObject * parent = 0)
explicit

Definition at line 17 of file CustomDelegate.cpp.

18 : QItemDelegate ( parent )
19{
20 setClipping ( true );
21}

Member Function Documentation

◆ Close

void dbe::CustomDelegate::Close ( )
privateslot

Definition at line 286 of file CustomDelegate.cpp.

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}

◆ CommitAndClose

void dbe::CustomDelegate::CommitAndClose ( )
privateslot

This trigger : this->setModelData

Definition at line 274 of file CustomDelegate.cpp.

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}

◆ createEditor()

QWidget * dbe::CustomDelegate::createEditor ( QWidget * parent,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const

Definition at line 23 of file CustomDelegate.cpp.

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 {
81 widgets::editors::stringattr * Editor = new widgets::editors::stringattr ( AttributeData,
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 {
108 widgets::editors::numericattr * Editor = new widgets::editors::numericattr ( AttributeData,
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}
void CreateObjectEditorSignal(tref Object) const
tref GetTableObject(int ObjectIndex) const
Definition table.cpp:456
TableNode * getnode(const QModelIndex &index) const
inner::configobject::tref tref
Definition tref.hpp:35

◆ CreateObjectEditorSignal

void dbe::CustomDelegate::CreateObjectEditorSignal ( tref Object) const
signal

◆ editorEvent()

bool dbe::CustomDelegate::editorEvent ( QEvent * event,
QAbstractItemModel * model,
const QStyleOptionViewItem & option,
const QModelIndex & index )

Definition at line 253 of file CustomDelegate.cpp.

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}

◆ eventFilter()

bool dbe::CustomDelegate::eventFilter ( QObject * editor,
QEvent * event )

Definition at line 226 of file CustomDelegate.cpp.

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}

◆ paint()

void dbe::CustomDelegate::paint ( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const

Definition at line 178 of file CustomDelegate.cpp.

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}

◆ setEditorData()

void dbe::CustomDelegate::setEditorData ( QWidget * editor,
const QModelIndex & index ) const

Definition at line 142 of file CustomDelegate.cpp.

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}
virtual QStringList GetData() const
Definition TableNode.cpp:18

◆ setModelData()

void dbe::CustomDelegate::setModelData ( QWidget * editor,
QAbstractItemModel * model,
const QModelIndex & index ) const

Definition at line 159 of file CustomDelegate.cpp.

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}

◆ updateEditorGeometry()

void dbe::CustomDelegate::updateEditorGeometry ( QWidget * editor,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const

Definition at line 218 of file CustomDelegate.cpp.

221{
222 Q_UNUSED ( index );
223 editor->setGeometry ( option.rect );
224}

The documentation for this class was generated from the following files: