DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
treeselection.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/messenger.hpp"
9#include "dbe/tree.hpp"
10
12 : QSortFilterProxyModel(parent)
14 , LevelRestriction(1000)
15 , Hide(false)
16{
18}
19
21
22bool
23dbe::models::treeselection::hasChildren(type_index const& index) const
24{
25 if (index.isValid()) {
26 QModelIndex sourceParent = mapToSource(index);
27 return sourceModel()->hasChildren(sourceParent);
28 } else {
29 return true;
30 }
31}
32
33bool
34dbe::models::treeselection::canFetchMore(type_index const& index) const
35{
36 if (index.isValid()) {
37 QModelIndex sourceParent = mapToSource(index);
38 return sourceModel()->canFetchMore(sourceParent);
39 } else {
40 return false;
41 }
42}
43
44void
46{
47 QModelIndex sourceParent = mapToSource(index);
48 sourceModel()->fetchMore(sourceParent);
49}
50
51void
56
57void
62
63void
65{
66 QueryObjects = Objects;
67}
68
69std::vector<dbe::tref>
74
76dbe::models::treeselection::getnode(type_index const& index) const
77{
78 if (index.isValid()) {
79 dbe::models::tree* UnderlyingModel = dynamic_cast<dbe::models::tree*>(sourceModel());
80
81 if (UnderlyingModel) {
82 return UnderlyingModel->getnode(index);
83 }
84 }
85
86 return nullptr;
87}
88
90dbe::models::treeselection::getobject(type_index const& index) const
91{
92
93 if (index.isValid()) {
94 QModelIndex sourceParent = mapToSource(index);
95 dbe::models::tree* my = dynamic_cast<dbe::models::tree*>(sourceModel());
96
97 if (my) {
98 return my->getobject(sourceParent);
99 }
100 }
101
102 throw daq::dbe::cannot_handle_invalid_qmodelindex(ERS_HERE);
103}
104
105dunedaq::conffwk::class_t
106dbe::models::treeselection::getclass(type_index const& index) const
107{
108 QModelIndex sourceParent = mapToSource(index);
109
110 if (dbe::models::tree* my = dynamic_cast<dbe::models::tree*>(sourceModel())) {
111 return my->getclass(sourceParent);
112 }
113
114 return dunedaq::conffwk::class_t();
115}
116
117QAbstractItemModel*
119{
120 return sourceModel();
121}
122
123void
128
129void
131{
132 beginResetModel();
133 endResetModel();
134}
135
136bool
137dbe::models::treeselection::filterAcceptsRow(int source_row, type_index const& source_parent) const
138{
139 treenode* NodeObject = getnode(sourceModel()->index(source_row, 0, source_parent));
140
141 if (dynamic_cast<AttributeNode*>(NodeObject)) {
142 return false;
143 }
144
145 if (Hide) {
146 if (!source_parent.isValid()) {
147 QModelIndex Index_1 = sourceModel()->index(source_row, 1, source_parent);
148
149 if (sourceModel()->data(Index_1).toUInt() == 0) {
150 return false;
151 }
152 }
153 }
154
155 switch (Type) {
156 case RegExpFilterType:
157 return RegexpFilter(source_row, source_parent);
158
159 case ObjectFilterType:
160 return ObjectFilter(source_row, source_parent);
161
162 default:
163 return true;
164 }
165}
166
167bool
168dbe::models::treeselection::lessThan(type_index const& left, type_index const& right) const
169{
170 if (left.parent() == QModelIndex() || left.parent().parent() == QModelIndex()) {
171 QVariant LeftData = sourceModel()->data(left);
172 QVariant RightData = sourceModel()->data(right);
173
174 switch (LeftData.type()) {
175 case QVariant::Bool:
176 case QVariant::UInt:
177 return (LeftData.toUInt() < RightData.toUInt());
178
179 case QVariant::Int:
180 return (LeftData.toInt() < RightData.toInt());
181
182 case QVariant::String:
183 return ((LeftData.toString()).compare(RightData.toString()) > 0);
184
185 default:
186 return false;
187 }
188
189 return true;
190 }
191
192 return false;
193}
194
195bool
196dbe::models::treeselection::AcceptItem(type_index const& SourceIndex, int LevelRestriction) const
197{
198 if (sourceModel()->canFetchMore(SourceIndex)) {
199 sourceModel()->fetchMore(SourceIndex);
200 }
201
202 if (sourceModel()->data(SourceIndex).toString().contains(filterRegExp())) {
203 return true;
204 }
205
206 if (LevelRestriction <= 1) {
207 return false;
208 }
209
210 for (int i = 0; i < sourceModel()->rowCount(SourceIndex); ++i) {
211 if (AcceptItem(sourceModel()->index(i, 0), --LevelRestriction)) {
212 return true;
213 }
214 }
215
216 return false;
217}
218
219bool
220dbe::models::treeselection::RegexpFilter(int sourceRow, type_index const& sourceParent) const
221{
222 if (AtDepth(sourceParent) <= LevelRestriction) {
223 QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
224 return AcceptItem(index0, LevelRestriction);
225 }
226
227 return true;
228}
229
230bool
231dbe::models::treeselection::ObjectFilter(int sourceRow, type_index const& sourceParent) const
232{
233 QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
234 QString id = sourceModel()->data(index0).toString();
235
236 if ((filterRegExp()).isEmpty()) {
237 return true;
238 }
239
240 if (AtDepth(sourceParent) > 2) {
241 return true;
242 }
243
244 if (!sourceParent.isValid()) {
245 for (size_t i = 0; i < QueryObjects.size(); ++i)
246 if (QString(QueryObjects.at(i).class_name().c_str()).compare(id) == 0) {
247 return true;
248 }
249 } else {
250 for (size_t i = 0; i < QueryObjects.size(); ++i)
251 if (id.compare(QString(QueryObjects.at(i).UID().c_str())) == 0) {
252 return true;
253 }
254 }
255
256 return false;
257}
258
259int
260dbe::models::treeselection::AtDepth(type_index const& SourceParent) const
261{
262 int Depth = 1;
263 QModelIndex CurrentIndex = SourceParent;
264
265 while (CurrentIndex.isValid()) {
266 CurrentIndex = CurrentIndex.parent();
267 Depth++;
268 }
269
270 return Depth;
271}
272
273void
275{
276 Hide = HideLocal;
277 ResetModel();
278}
279//----------------------------------------------------------------------------------------------------
280
281//----------------------------------------------------------------------------------------------------
283{
284 if (dbe::treenode* classnode = confaccessor::gethandler()->getnode(QString::fromStdString(obj.class_name()))) {
285
286 auto found = [&obj, classnode](int i) {
287 return obj.UID() == classnode->GetChild(i)->GetData(0).toString().toStdString();
288 };
289
290 int i = 0;
291 int const childs = classnode->ChildCount();
292
293 for (; i < childs and not found(i); ++i)
294 ;
295
296 return i == childs ? QModelIndex() : index(i, 0, QModelIndex());
297 }
298
299 return QModelIndex();
300}
301//----------------------------------------------------------------------------------------------------
302
303//----------------------------------------------------------------------------------------------------
305{
306 // This is a stub and nothing needs to be done since
307 // the real job happens in the slot defined in dbe::models::tree object from signal for treeselectionmodel
308 Q_UNUSED(index);
309 Q_UNUSED(obj);
310}
311
313{
314 // This is a stub and nothing needs to be done since
315 // the real job happens in the slot defined in dbe::models::tree
316 Q_UNUSED(index);
317}
318
320{
321 Q_UNUSED(obj);
322 type_index const mapped_index = this->mapFromSource(index);
323 emit dataChanged(mapped_index, mapped_index);
324}
325
327{
328 Q_UNUSED(obj);
329 type_index const mapped_index = this->mapFromSource(index);
330 emit dataChanged(mapped_index, mapped_index);
331}
332//----------------------------------------------------------------------------------------------------
333
334//----------------------------------------------------------------------------------------------------
335TREEMODEL_REMOVE_ROWS_DEF(dbe::models::treeselection)
336MODEL_COMMON_INTERFACE_SLOTS_DEF(dbe::models::treeselection)
337//----------------------------------------------------------------------------------------------------
#define ERS_HERE
#define TREEMODEL_REMOVE_ROWS_DEF(classname)
static cptr< datahandler > gethandler()
type_datum * getnode(const type_index &index) const override
Definition tree.cpp:306
int AtDepth(const QModelIndex &SourceParent) const
void SetFilterType(FilterType Filter)
bool canFetchMore(type_index const &index) const
treeselection(QObject *parent=0)
Including DBE.
std::vector< tref > QueryObjects
bool hasChildren(type_index const &index) const
bool RegexpFilter(int sourceRow, const QModelIndex &sourceParent) const
std::vector< dbe::tref > GetQueryObjects()
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
type_datum * getnode(type_index const &index) const override
bool ObjectFilter(int sourceRow, const QModelIndex &sourceParent) const
void ToggleEmptyClasses(bool HideLocal)
void SetQueryObjects(std::vector< tref > Objects)
bool lessThan(const QModelIndex &left, const QModelIndex &right) const
void SetFilterRestrictionLevel(int Levels)
bool AcceptItem(const QModelIndex &SourceIndex, int LevelRestriction) const
void fetchMore(type_index const &index)
#define MODEL_COMMON_INTERFACE_LOOKUP_IMPL(classname)
#define MODEL_COMMON_INTERFACE_RENAME_THAT_OBJ_IMPL(classname)
#define MODEL_COMMON_INTERFACE_UPDATE_THAT_OBJ_IMPL(classname)
#define MODEL_COMMON_INTERFACE_DELETE_THAT_OBJ_IMPL(classname)
#define MODEL_COMMON_INTERFACE_SLOTS_DEF(classname)
#define MODEL_COMMON_INTERFACE_CREATE_THAT_OBJ_IMPL(classname)
inner::configobject::tref tref
Definition tref.hpp:36
virtual type_class_info getclass(type_index const &index) const =0
virtual type_object_ref getobject(type_index const &index) const =0
virtual QAbstractItemModel * ReturnSourceModel() const =0