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
10#include "dbe/messenger.hpp"
11#include "dbe/tree.hpp"
12#include "dbe/treenode.hpp"
13
14dbe::models::subtree_proxy::subtree_proxy(const QString& Name, const QStringList& Default, QObject* parent)
15 : QSortFilterProxyModel(parent)
17 , this_default_filter(Default)
19{
22}
23
25
26void
28{
29 beginResetModel();
30 endResetModel();
31}
32
33bool
34dbe::models::subtree_proxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
35{
37 return ApplyDefaultFilter(source_row, source_parent);
38 } else {
39 return ApplyUserFilter(source_row, source_parent);
40 }
41}
42
43bool
44dbe::models::subtree_proxy::lessThan(const QModelIndex& left, const QModelIndex& right) const
45{
46 if (left.parent() == QModelIndex() || left.parent().parent() == QModelIndex()) {
47 QVariant LeftData = sourceModel()->data(left);
48 QVariant RightData = sourceModel()->data(right);
49
50 switch (LeftData.type()) {
51 case QVariant::Bool:
52 case QVariant::UInt:
53 return (LeftData.toUInt() < RightData.toUInt());
54
55 case QVariant::Int:
56 return (LeftData.toInt() < RightData.toInt());
57
58 case QVariant::String:
59 return ((LeftData.toString()).compare(RightData.toString()) > 0);
60
61 default:
62 return false;
63 }
64
65 return true;
66 }
67
68 return false;
69}
70
71void
80
81void
83{
84 if (this_apply_default_filter == false) {
85 for (QString const& i : this_window_config.GraphicalClassesList) {
86 GraphicalClass Class = confaccessor::guiconfig()->graphical(i.toStdString());
87 QStringList ClassList = Class.DerivedClasses;
88 ClassList.append(Class.DatabaseClassName);
89
90 for (QString& ClassName : ClassList) {
91 treenode* ClassNode = confaccessor::gethandler()->getnode(ClassName);
92
93 if (ClassNode) {
94 dbe::models::tree* UnderlyingModel = static_cast<dbe::models::tree*>(sourceModel());
95 QModelIndex ParentIndex = UnderlyingModel->getindex(ClassNode);
96
97 if (sourceModel()->canFetchMore(ParentIndex))
98 sourceModel()->fetchMore(ParentIndex);
99 }
100 }
101 }
102 }
103}
104
106dbe::models::subtree_proxy::getobject(const QModelIndex& index) const
107{
108 if (index.isValid()) {
109 QModelIndex sourceParent = mapToSource(index);
110 dbe::models::tree* my = dynamic_cast<dbe::models::tree*>(sourceModel());
111
112 if (my) {
113 return my->getobject(sourceParent);
114 }
115 }
116
117 throw daq::dbe::cannot_handle_invalid_qmodelindex(ERS_HERE);
118}
119
120dbe::treenode*
121dbe::models::subtree_proxy::getnode(const QModelIndex& index) const
122{
123 QModelIndex sourceParent = mapToSource(index);
124 dbe::models::tree* my = dynamic_cast<dbe::models::tree*>(sourceModel());
125
126 if (my) {
127 return my->getnode(sourceParent);
128 }
129
130 return nullptr;
131}
132
134dbe::models::subtree_proxy::getclass(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 return my->getclass(sourceParent);
141 }
142
144}
145
146QAbstractItemModel*
148{
149 return sourceModel();
150}
151
152bool
153dbe::models::subtree_proxy::ApplyDefaultFilter(int source_row, const QModelIndex& source_parent) const
154{
155 Q_UNUSED(source_row)
156 Q_UNUSED(source_parent)
157
158 return true;
159}
160
161bool
162dbe::models::subtree_proxy::ApplyUserFilter(int source_row, const QModelIndex& source_parent) const
163{
164 dbe::models::tree* srcmodel = static_cast<tree*>(sourceModel());
165
166 QModelIndex const& nodeindex = srcmodel->index(source_row, 0, source_parent);
167 treenode* tofilter = srcmodel->getnode(nodeindex);
168 QString const nodename = srcmodel->data(nodeindex).toString();
169
170 if (not source_parent.isValid()) {
172
173 for (QString const& admissible : this_window_config.GraphicalClassesList) {
174 GraphicalClass candidate = confaccessor::guiconfig()->graphical(admissible.toStdString());
175
176 if (candidate.DatabaseClassName == nodename or candidate.DerivedClasses.contains(nodename)) {
177 return true;
178 }
179 }
180 } else if (dynamic_cast<ObjectNode*>(tofilter)) {
181 return true;
182 } else if (dynamic_cast<RelationshipNode*>(tofilter)) {
184 QString const related = sourceModel()->data(nodeindex.parent().parent()).toString();
185
186 for (QString const& admissible : this_window_config.GraphicalClassesList) {
187 GraphicalClass candidate = confaccessor::guiconfig()->graphical(admissible.toStdString());
188
189 if (candidate.DatabaseClassName == related or candidate.DerivedClasses.contains(related)) {
190 return candidate.ShowAllRelationships or candidate.Relationships.contains(nodename);
191 }
192 }
193 }
194
195 return false;
196}
197//----------------------------------------------------------------------------------------------------
198
199//----------------------------------------------------------------------------------------------------
201{
202 if (treenode* classnode = confaccessor::gethandler()->getnode(QString::fromStdString(obj.class_name()))) {
203
204 auto found = [&obj, classnode](int i) {
205 return obj.UID() == classnode->GetChild(i)->GetData(0).toString().toStdString();
206 };
207
208 int i = 0;
209 int const childs = classnode->ChildCount();
210
211 for (; i < childs and not found(i); ++i)
212 ;
213
214 return i == childs ? QModelIndex() : index(i, 0, QModelIndex());
215 }
216
217 return QModelIndex();
218}
219
221{
222 // TODO implement create object from signal for Subtreeproxymodel
223 Q_UNUSED(index);
224 Q_UNUSED(obj);
225}
226
228{
229 if (index.isValid()) {
230 this->removeRows(index.row(), 1, index.parent());
231 }
232}
233
235{
236 // TODO implement rename object
237 Q_UNUSED(index);
238 Q_UNUSED(obj);
239}
240
242{
243 // TODO implement update object from signal for Subtreeproxymodel
244 Q_UNUSED(index);
245 Q_UNUSED(obj);
246}
247
248TREEMODEL_REMOVE_ROWS_DEF(dbe::models::subtree_proxy)
249MODEL_COMMON_INTERFACE_SLOTS_DEF(dbe::models::subtree_proxy)
250//----------------------------------------------------------------------------------------------------
#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:106
type_index getindex(treenode *NodeItem, type_index const &RootIndex=QModelIndex()) const
Definition tree.cpp:278
type_datum * getnode(const type_index &index) const override
Definition tree.cpp:306
type_index index(int row, int column, const type_index &parent) const override
Definition tree.cpp:35
#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