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