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