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
8#include "dbe/TableNode.hpp"
9#include "dbe/Validator.hpp"
10#include "dbe/confaccessor.hpp"
12// #include "dbe/MainWindow.hpp"
13
14#include <QCompleter>
15#include <QKeyEvent>
16
18 : QItemDelegate(parent)
19{
20 setClipping(true);
21}
22
23QWidget*
24dbe::CustomDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
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) {
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}
123
124void
125dbe::CustomDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
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}
137
138void
139dbe::CustomDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
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}
153
154void
155dbe::CustomDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
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}
193
194void
196 const QStyleOptionViewItem& option,
197 const QModelIndex& index) const
198{
199 Q_UNUSED(index);
200 editor->setGeometry(option.rect);
201}
202
203bool
204dbe::CustomDelegate::eventFilter(QObject* editor, QEvent* event)
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}
222
223bool
225 QAbstractItemModel* model,
226 const QStyleOptionViewItem& option,
227 const QModelIndex& index)
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}
241
242void
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}
253
254void
256{
257 widgets::editors::base* Editor = qobject_cast<widgets::editors::base*>(sender());
258
259 if (Editor) {
260 emit closeEditor(Editor);
261 return;
262 }
263}
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:412
TableNode * getnode(const QModelIndex &index) const
inner::configobject::tref tref
Definition tref.hpp:36