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