DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
subtreeproxy.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
9#include "dbe/tree.hpp"
10#include "dbe/treenode.hpp"
11#include "dbe/confaccessor.hpp"
12#include "dbe/messenger.hpp"
13
15 const QStringList & Default,
16 QObject * parent )
17 : QSortFilterProxyModel ( parent ),
18 this_gui_windowname ( Name ),
19 this_default_filter ( Default ),
21{
24}
25
29
31{
32 beginResetModel();
33 endResetModel();
34}
35
37 const QModelIndex & source_parent ) const
38{
40 {
41 return ApplyDefaultFilter ( source_row, source_parent );
42 }
43 else
44 {
45 return ApplyUserFilter ( source_row, source_parent );
46 }
47}
48
49bool dbe::models::subtree_proxy::lessThan ( const QModelIndex & left,
50 const QModelIndex & right ) const
51{
52 if ( left.parent() == QModelIndex() || left.parent().parent() == QModelIndex() )
53 {
54 QVariant LeftData = sourceModel()->data ( left );
55 QVariant RightData = sourceModel()->data ( right );
56
57 switch ( LeftData.type() )
58 {
59 case QVariant::Bool:
60 case QVariant::UInt:
61 return ( LeftData.toUInt() < RightData.toUInt() );
62
63 case QVariant::Int:
64 return ( LeftData.toInt() < RightData.toInt() );
65
66 case QVariant::String:
67 return ( ( LeftData.toString() ).compare ( RightData.toString() ) > 0 );
68
69 default:
70 return false;
71 }
72
73 return true;
74 }
75
76 return false;
77}
78
80{
82 this_gui_windowname.toStdString() );
83
84 if ( this_window_config.Title.isEmpty() )
85 {
87 }
88}
89
91{
92 if ( this_apply_default_filter == false )
93 {
94 for ( QString const & i : this_window_config.GraphicalClassesList )
95 {
96 GraphicalClass Class = confaccessor::guiconfig()->graphical ( i.toStdString() );
97 QStringList ClassList = Class.DerivedClasses;
98 ClassList.append ( Class.DatabaseClassName );
99
100 for ( QString & ClassName : ClassList )
101 {
102 treenode * ClassNode = confaccessor::gethandler()->getnode ( ClassName );
103
104 if ( ClassNode )
105 {
106 dbe::models::tree * UnderlyingModel =
107 static_cast<dbe::models::tree *> ( sourceModel() );
108 QModelIndex ParentIndex = UnderlyingModel->getindex ( ClassNode );
109
110 if ( sourceModel()->canFetchMore ( ParentIndex ) ) sourceModel()->fetchMore (
111 ParentIndex );
112 }
113 }
114 }
115 }
116}
117
118dbe::tref dbe::models::subtree_proxy::getobject ( const QModelIndex & index ) const
119{
120 if ( index.isValid() )
121 {
122 QModelIndex sourceParent = mapToSource ( index );
123 dbe::models::tree * my = dynamic_cast<dbe::models::tree *> ( sourceModel() );
124
125 if ( my )
126 {
127 return my->getobject ( sourceParent );
128 }
129 }
130
131 throw daq::dbe::cannot_handle_invalid_qmodelindex ( ERS_HERE );
132}
133
134dbe::treenode * dbe::models::subtree_proxy::getnode ( const QModelIndex & index ) const
135{
136 QModelIndex sourceParent = mapToSource ( index );
137 dbe::models::tree * my = dynamic_cast<dbe::models::tree *> ( sourceModel() );
138
139 if ( my )
140 {
141 return my->getnode ( sourceParent );
142 }
143
144 return nullptr;
145}
146
148const
149{
150 QModelIndex sourceParent = mapToSource ( index );
151 dbe::models::tree * my = dynamic_cast<dbe::models::tree *> ( sourceModel() );
152
153 if ( my )
154 {
155 return my->getclass ( sourceParent );
156 }
157
159}
160
161QAbstractItemModel * dbe::models::subtree_proxy::ReturnSourceModel() const
162{
163 return sourceModel();
164}
165
167 const QModelIndex & source_parent ) const
168{
169 Q_UNUSED ( source_row )
170 Q_UNUSED ( source_parent )
171
172 return true;
173}
174
176 const QModelIndex & source_parent ) const
177{
178 dbe::models::tree * srcmodel = static_cast<tree *> ( sourceModel() );
179
180 QModelIndex const & nodeindex = srcmodel->index ( source_row, 0, source_parent );
181 treenode * tofilter = srcmodel->getnode ( nodeindex );
182 QString const nodename = srcmodel->data ( nodeindex ).toString();
183
184 if ( not source_parent.isValid() )
185 {
187
188 for ( QString const & admissible : this_window_config.GraphicalClassesList )
189 {
190 GraphicalClass candidate = confaccessor::guiconfig()->graphical (
191 admissible.toStdString() );
192
193 if ( candidate.DatabaseClassName == nodename
194 or candidate.DerivedClasses.contains ( nodename ) )
195 {
196 return true;
197 }
198 }
199 }
200 else if ( dynamic_cast<ObjectNode *> ( tofilter ) )
201 {
202 return true;
203 }
204 else if ( dynamic_cast<RelationshipNode *> ( tofilter ) )
205 {
207 QString const related = sourceModel()->data ( nodeindex.parent().parent() ).toString();
208
209 for ( QString const & admissible : this_window_config.GraphicalClassesList )
210 {
211 GraphicalClass candidate = confaccessor::guiconfig()->graphical (
212 admissible.toStdString() );
213
214 if ( candidate.DatabaseClassName == related or candidate.DerivedClasses.contains (
215 related ) )
216 {
217 return candidate.ShowAllRelationships or candidate.Relationships.contains ( nodename );
218 }
219
220 }
221 }
222
223 return false;
224}
225//----------------------------------------------------------------------------------------------------
226
227//----------------------------------------------------------------------------------------------------
229{
230 if ( treenode * classnode = confaccessor::gethandler()->getnode (
231 QString::fromStdString ( obj.class_name() ) ) )
232 {
233
234 auto found = [&obj, classnode] ( int i )
235 {
236 return obj.UID() == classnode->GetChild ( i )->GetData ( 0 ).toString().toStdString();
237 };
238
239 int i = 0;
240 int const childs = classnode->ChildCount();
241
242 for ( ; i < childs and not found ( i ); ++i )
243 ;
244
245 return i == childs ? QModelIndex() : index ( i, 0, QModelIndex() );
246 }
247
248 return QModelIndex();
249}
250
252{
253// TODO implement create object from signal for Subtreeproxymodel
254 Q_UNUSED(index);
255 Q_UNUSED(obj);
256}
257
259{
260 if ( index.isValid() )
261 {
262 this->removeRows ( index.row(), 1, index.parent() );
263 }
264}
265
267{
268 //TODO implement rename object
269 Q_UNUSED(index);
270 Q_UNUSED(obj);
271}
272
274{
275// TODO implement update object from signal for Subtreeproxymodel
276 Q_UNUSED(index);
277 Q_UNUSED(obj);
278}
279
280TREEMODEL_REMOVE_ROWS_DEF ( dbe::models::subtree_proxy )
281MODEL_COMMON_INTERFACE_SLOTS_DEF ( dbe::models::subtree_proxy )
282//----------------------------------------------------------------------------------------------------
283
#define ERS_HERE
#define TREEMODEL_REMOVE_ROWS_DEF(classname)
static cptr< datahandler > gethandler()
static cptr< ui::config::info > guiconfig()
treenode * getnode(const QModelIndex &index) const
bool lessThan(const QModelIndex &left, const QModelIndex &right) const
bool ApplyDefaultFilter(int source_row, const QModelIndex &source_parent) const
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
subtree_proxy(const QString &Name, const QStringList &Default, QObject *parent=nullptr)
Including DBE.
bool ApplyUserFilter(int source_row, const QModelIndex &source_parent) const
QVariant data(const type_index &index, int role=Qt::DisplayRole) const override
Definition tree.cpp:121
type_index getindex(treenode *NodeItem, type_index const &RootIndex=QModelIndex()) const
Definition tree.cpp:291
type_datum * getnode(const type_index &index) const override
Definition tree.cpp:321
type_index index(int row, int column, const type_index &parent) const override
Definition tree.cpp:37
#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