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 15 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 255 of file CustomDelegate.cpp.

256{
257 widgets::editors::base* Editor = qobject_cast<widgets::editors::base*>(sender());
258
259 if (Editor) {
260 emit closeEditor(Editor);
261 return;
262 }
263}

◆ CommitAndClose

void dbe::CustomDelegate::CommitAndClose ( )
privateslot

This trigger : this->setModelData

Definition at line 243 of file CustomDelegate.cpp.

244{
245 widgets::editors::base* Editor = qobject_cast<widgets::editors::base*>(sender());
246
247 if (Editor) {
248 emit commitData(Editor);
249 emit closeEditor(Editor);
250 return;
251 }
252}

◆ createEditor()

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

Definition at line 24 of file CustomDelegate.cpp.

25{
26 Q_UNUSED(option);
27 const dbe::models::tableselection* Model = dynamic_cast<const dbe::models::tableselection*>(index.model());
28
29 const dbe::models::table* SourceModel = dynamic_cast<const dbe::models::table*>(Model->sourceModel());
30
31 TableNode* Item = Model->getnode(index);
32
33 tref Object = SourceModel->GetTableObject(Model->mapToSource(index).row());
34
35 if (Model == nullptr) {
36 return nullptr;
37 }
38
39 if (index.column() == 0) {
40 emit CreateObjectEditorSignal(Object);
41 return nullptr;
42 }
43
44 if (dynamic_cast<TableRelationshipNode*>(Item)) {
45 TableRelationshipNode* RelationshipItem = dynamic_cast<TableRelationshipNode*>(Item);
46 dunedaq::conffwk::relationship_t RelationshipData = RelationshipItem->GetRelationship();
47 widgets::editors::relation* Editor = new widgets::editors::relation(RelationshipData);
48 connect(Editor, SIGNAL(signal_edit_end()), this, SLOT(CommitAndClose()));
49 connect(Editor, SIGNAL(signal_force_close()), this, SLOT(Close()));
50 return Editor;
51 } else if (dynamic_cast<TableAttributeNode*>(Item)) {
52 TableAttributeNode* AttributeItem = dynamic_cast<TableAttributeNode*>(Item);
53 dunedaq::conffwk::attribute_t AttributeData = AttributeItem->GetAttribute();
54
55 if (AttributeData.p_is_multi_value) {
56 widgets::editors::multiattr* widget = new widgets::editors::multiattr(AttributeData);
57 connect(widget, SIGNAL(signal_edit_end()), this, SLOT(CommitAndClose()));
58 connect(widget, SIGNAL(signal_force_close()), this, SLOT(Close()));
59 return widget;
60 } else {
61 switch (AttributeData.p_type) {
62
64
66
68 widgets::editors::stringattr* Editor = new widgets::editors::stringattr(AttributeData, parent);
69 connect(Editor, SIGNAL(signal_edit_end()), this, SLOT(CommitAndClose()));
70 connect(Editor, SIGNAL(signal_force_close()), this, SLOT(Close()));
71 return Editor;
72 }
73
75
77
79
81
83
85
87
89
91
93 widgets::editors::numericattr* Editor = new widgets::editors::numericattr(AttributeData, parent);
94 connect(Editor, SIGNAL(signal_edit_end()), this, SLOT(CommitAndClose()));
95 connect(Editor, SIGNAL(signal_force_close()), this, SLOT(Close()));
96 return Editor;
97 }
98
100
102 widgets::editors::combo* Editor = new widgets::editors::combo(AttributeData, parent);
103 connect(Editor, SIGNAL(signal_value_change()), this, SLOT(CommitAndClose()));
104 connect(Editor, SIGNAL(signal_force_close()), this, SLOT(Close()));
105 return Editor;
106 }
107
109 widgets::editors::combo* Editor = new widgets::editors::combo(AttributeData, 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
115 default:
116 break;
117 }
118 }
119 }
120
121 return nullptr;
122}
void CreateObjectEditorSignal(tref Object) const
tref GetTableObject(int ObjectIndex) const
Definition table.cpp:412
TableNode * getnode(const QModelIndex &index) const
inner::configobject::tref tref
Definition tref.hpp:36

◆ 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 224 of file CustomDelegate.cpp.

228{
229 if (!(event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease)) {
230 if (dynamic_cast<QKeyEvent*>(event)) {
231 QKeyEvent* KeyEvent = static_cast<QKeyEvent*>(event);
232
233 if (KeyEvent->text() != "e") {
234 return true;
235 }
236 }
237 }
238
239 return QItemDelegate::editorEvent(event, model, option, index);
240}

◆ eventFilter()

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

Definition at line 204 of file CustomDelegate.cpp.

205{
206 if (event->type() == QEvent::KeyPress) {
207 QKeyEvent* KeyEvent = static_cast<QKeyEvent*>(event);
208
209 if (KeyEvent->key() == Qt::Key_Enter || KeyEvent->key() == Qt::Key_Return) {
210 if (dynamic_cast<widgets::editors::combo*>(editor) != 0) {
211 return QItemDelegate::eventFilter(editor, event);
212 } else {
213 return true;
214 }
215 }
216 } else if (event->type() == QEvent::FocusOut) {
217 return true;
218 }
219
220 return QItemDelegate::eventFilter(editor, event);
221}

◆ paint()

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

Definition at line 155 of file CustomDelegate.cpp.

156{
157 QItemDelegate::paint(painter, option, index);
158
159 // TODO: now commented-out because of small issues with text rendering
160 // indeed the text is too close to the cell's borders and some times artifacts are present
161 // the alternate colors have been anyway enabled in the table view
162 // so basically we miss the back-ground for the first column
163
164 // painter->save();
165 //
166 // QFont fontmodif = option.font;
167 //
168 // if ( option.state & QStyle::State_Selected )
169 // {
170 // painter->setBackground ( option.palette.mid() );
171 // painter->setRenderHint ( QPainter::Antialiasing, true );
172 // }
173 // else if ( index.column() == 0 )
174 // {
175 // painter->setBackground ( QColor::fromRgb ( 75, 222, 148 ) );
176 // fontmodif.setBold ( true );
177 // }
178 // else if ( index.row() % 2 == 1 )
179 // {
180 // painter->setBackground ( Qt::lightGray );
181 // }
182 // else
183 // {
184 // painter->setBackground ( Qt::white );
185 // }
186 //
187 // painter->setFont ( fontmodif );
188 // painter->fillRect ( option.rect, painter->background() );
189 // painter->drawText ( option.rect, option.displayAlignment, index.data().toString() );
190 //
191 // painter->restore();
192}

◆ setEditorData()

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

Definition at line 125 of file CustomDelegate.cpp.

126{
127 const dbe::models::tableselection* mdl = dynamic_cast<const dbe::models::tableselection*>(index.model());
128
129 if (mdl != nullptr || editor != nullptr) {
130 if (widgets::editors::base* w = dynamic_cast<widgets::editors::base*>(editor)) {
131 QStringList const& data = mdl->getnode(index)->GetData();
132 w->setdata(data);
133 w->SetEditor();
134 }
135 }
136}
virtual QStringList GetData() const
Definition TableNode.cpp:18

◆ setModelData()

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

Definition at line 139 of file CustomDelegate.cpp.

140{
141 const dbe::models::tableselection* Model = dynamic_cast<const dbe::models::tableselection*>(index.model());
142
143 if (Model == nullptr || editor == nullptr) {
144 return;
145 }
146
147 widgets::editors::base* WidgetInterface = dynamic_cast<widgets::editors::base*>(editor);
148
149 QStringList ValueList = WidgetInterface->getdata();
150
151 model->setData(index, ValueList, Qt::EditRole);
152}

◆ updateEditorGeometry()

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

Definition at line 195 of file CustomDelegate.cpp.

198{
199 Q_UNUSED(index);
200 editor->setGeometry(option.rect);
201}

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