DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
treenode.cpp
Go to the documentation of this file.
1
3#include "dbe/treenode.hpp"
9
10#include <QGraphicsPixmapItem>
11#include <QGraphicsScene>
12#include <QPainter>
13#include <QBitmap>
14#include <QDrag>
15#include <QGraphicsSceneMouseEvent>
16#include <QMimeData>
17#include <QApplication>
18#include <QMessageBox>
19#include <QComboBox>
20#include <QHBoxLayout>
21#include <QPushButton>
22#include <QLabel>
23
25 :
26 Parent ( ParentNode ),
27 HasStructure ( false ),
28 WasFetched ( false )
29{
30 if ( Parent != nullptr )
31 {
32 Parent->AddChild ( this );
33 }
34}
35
36dbe::treenode::treenode ( const QString & Datum, treenode * ParentNode )
37 :
38 treenode ( ParentNode )
39{
40 Data.append ( Datum );
41}
42
43dbe::treenode::treenode ( const QStringList & DataList, treenode * ParentNode )
44 :
45 treenode ( ParentNode )
46{
47
48 for ( auto & i : DataList )
49 {
50 Data.append ( i );
51 }
52}
53
55{
56 qDeleteAll ( Children );
57}
58
59QVariant dbe::treenode::GetData ( const int Column, int role ) const
60{
61 if ( role == Qt::DisplayRole )
62 {
63 return Data.value ( Column );
64 }
65 else
66 {
67 return QVariant();
68 }
69}
70
71void dbe::treenode::rename ( QString const & name )
72{
73 Data[0] = QVariant ( name );
74}
75
77{
78 throw daq::dbe::cannot_handle_invalid_qmodelindex ( ERS_HERE );
79}
80
82{
83 if ( Parent )
84 {
85 return Parent->Children.indexOf ( const_cast<treenode *> ( this ) );
86 }
87
88 return 0;
89}
90
92{
93 Children.append ( Child );
94}
95
97{
98 Children.removeOne ( Child );
99}
100
101dbe::treenode * dbe::treenode::GetChild ( const int Row ) const
102{
103 return Children.at ( Row );
104}
105
106QList<dbe::treenode *> dbe::treenode::GetChildren() const
107{
108 return Children;
109}
110
112{
113 return Parent;
114}
115
117{
118 return Children.size();
119}
120
122{
123 return Data.size();
124}
125
126void dbe::treenode::SetHasStructure ( bool Structure )
127{
128 HasStructure = Structure;
129}
130
132{
133 return HasStructure;
134}
135
136void dbe::treenode::SetWasFetched ( bool Fetched )
137{
138 WasFetched = Fetched;
139}
140
142{
143 return WasFetched;
144}
145
147 :
148 treenode ( ParentNode ),
149 ClassInfo ( Info ),
150 numObjects( 0 )
151{
152 Data.append ( QVariant ( QString::fromStdString ( ClassInfo.p_name ) ) );
153 Data.append ( QVariant ( numObjects ) );
154 m_tooltip = QVariant ( QString::fromStdString ( ClassInfo.p_description ) );
155}
156
160
161void dbe::ClassNode::updateData(bool addition) {
162 addition ? ++numObjects : --numObjects;
163
164 Data[1] = QVariant ( numObjects );
165
166 confaccessor::increase_total_objects ( addition == true ? 1 : -1 );
167
168 if ( numObjects == 0 )
169 {
170 SetWasFetched ( true );
171 }
172 else
173 {
174 SetHasStructure ( true );
175 }
176}
177
179{
181 updateData(true);
182}
183
185{
187 updateData(false);
188}
189
190QVariant dbe::ClassNode::GetData ( const int Column, int role ) const
191{
192 switch ( role )
193 {
194
195 case Qt::DisplayRole:
196 return Data.value ( Column );
197
198 case Qt::ToolTipRole:
199
200 return m_tooltip;
201
202 break;
203 case Qt::DecorationRole:
204
205 if ( Column == 0 )
206 {
207 return QIcon ( ":/Images/Folder.png" );
208 }
209 }
210
211 return QVariant();
212}
213
215{
216 return ClassInfo;
217}
218
219dbe::ObjectNode::ObjectNode ( dref obj, bool acopy, treenode * ParentNode )
220 :
221 treenode ( ParentNode ),
222 configdata ( obj )
223{
224 Data.append ( QVariant ( QString::fromStdString ( configdata.UID() ) ) );
225 if ( not acopy )
226 {
229 false );
230 std::vector<dunedaq::conffwk::attribute_t> Attributes = ClassInfo.p_attributes;
231 std::vector<dunedaq::conffwk::relationship_t> Relationships = ClassInfo.p_relationships;
232
233 if ( ( Relationships.size() > 0 ) )
234 {
235 SetHasStructure ( true );
236 }
237
238 for ( dunedaq::conffwk::attribute_t & Attribute : Attributes )
239 {
240 new AttributeNode ( Attribute, static_cast<treenode *> ( this ) );
241 }
242
243 for ( dunedaq::conffwk::relationship_t & Relationship : Relationships )
244 {
245 new RelationshipNode ( Relationship, static_cast<treenode *> ( this ) );
246 }
247 }
248
249 SetWasFetched ( true );
250}
251
253
254QVariant dbe::ObjectNode::GetData ( const int Column, int role ) const
255{
256 switch ( role )
257 {
258
259 case Qt::DisplayRole:
260 return Data.value ( Column );
261
262 case Qt::DecorationRole:
263
264 if ( Column == 0 )
265 {
266 return QIcon ( ":/Images/TextGeneric.png" );
267 }
268 break;
269 }
270
271 return QVariant();
272}
273
275{
276 return configdata.ref();
277}
278
280 treenode * ParentNode )
281 :
282 treenode ( ParentNode ),
283 attribute_t_definition ( AttributeData )
284{
285 Data.append ( QVariant ( QString::fromStdString ( AttributeData.p_name ) ) );
286
287 tref ObjectParent = GetParent()->GetObject();
288
289 QStringList DataList
290 { dbe::config::api::get::attribute::list<QStringList> ( ObjectParent, AttributeData ) };
291
292 for ( QString & ObjectData : DataList )
293 {
294 if ( !ObjectData.isEmpty() )
295 {
296 treenode * ChildNode = new treenode ( ObjectData, static_cast<treenode *> ( this ) );
297 ChildNode->SetWasFetched ( true );
298 }
299 }
300
301 if ( DataList.size() > 0 && !DataList.at ( 0 ).isNull() )
302 {
303 SetHasStructure ( true );
304 }
305
306 SetWasFetched ( true );
307}
308
310
311QVariant dbe::AttributeNode::GetData ( const int Column, int role ) const
312{
313 switch ( role )
314 {
315
316 case Qt::DisplayRole:
317 return Data.value ( Column );
318
319 case Qt::DecorationRole:
320
321 if ( Column == 0 )
322 {
323 return QIcon ( ":/Images/SLink.png" );
324 }
325 }
326
327 return QVariant();
328}
329
331{
332 return attribute_t_definition;
333}
334
336 treenode * ParentNode )
337 :
338 treenode ( ParentNode ),
339 relation_t_definition ( relation )
340{
341 Data.append ( QVariant ( QString::fromStdString ( relation.p_name ) ) );
342
343 std::vector<tref> DataList;
344 tref ObjectParent = GetParent()->GetObject();
345
350 {
351 try
352 {
353 tref Data =
354 dbe::config::api::graph::linked::through::relation<tref> (
355 ObjectParent,
356 relation );
357 DataList.push_back ( Data );
358 }
359 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
360 {
361 //nothing needs be done to handle the case that a relationship is not set
362 }
363 }
364 else
365 {
366 DataList =
368 ObjectParent,
369 relation );
370 }
371
372 for ( tref const & Object : DataList )
373 {
374 new ObjectNode ( Object, true, static_cast<treenode *> ( this ) );
375 }
376
377 if ( DataList.size() > 0 )
378 {
379 SetHasStructure ( true );
380 }
381
382 SetWasFetched ( true );
383}
384
386
387QVariant dbe::RelationshipNode::GetData ( const int Column, int role ) const
388{
389 switch ( role )
390 {
391
392 case Qt::DisplayRole:
393 return Data.value ( Column );
394
395 case Qt::DecorationRole:
396
397 if ( Column == 0 )
398 {
399 return QIcon ( ":/Images/SLink.png" );
400 }
401 }
402
403 return QVariant();
404}
405
407{
408 return relation_t_definition;
409}
#define ERS_HERE
virtual QVariant GetData(const int Column, int role=Qt::DisplayRole) const
Definition treenode.cpp:311
dunedaq::conffwk::attribute_t attribute_t() const
Definition treenode.cpp:330
AttributeNode(const dunedaq::conffwk::attribute_t &AttributeData, treenode *ParentNode)
Definition treenode.cpp:279
void AddChild(treenode *Child) override
Definition treenode.cpp:178
unsigned int numObjects
Definition treenode.hpp:74
dunedaq::conffwk::class_t GetClassInfo() const
Definition treenode.cpp:214
void updateData(bool addition)
Definition treenode.cpp:161
virtual QVariant GetData(int Column, int role=Qt::DisplayRole) const
Definition treenode.cpp:190
QVariant m_tooltip
Definition treenode.hpp:75
void RemoveChild(treenode *Child) override
Definition treenode.cpp:184
dunedaq::conffwk::class_t ClassInfo
Definition treenode.hpp:73
ClassNode(const dunedaq::conffwk::class_t &Info, treenode *ParentNode)
Definition treenode.cpp:146
ObjectNode(dref ObjectData, bool IsCopy, treenode *ParentNode)
Definition treenode.cpp:219
tref GetObject() const
Definition treenode.cpp:274
virtual QVariant GetData(const int Column, int role=Qt::DisplayRole) const
Definition treenode.cpp:254
virtual QVariant GetData(const int Column, int role=Qt::DisplayRole) const
Definition treenode.cpp:387
dunedaq::conffwk::relationship_t relation_t_definition
Definition treenode.hpp:109
dunedaq::conffwk::relationship_t relation_t() const
Definition treenode.cpp:406
RelationshipNode(const dunedaq::conffwk::relationship_t &RelationshipData, treenode *ParentNode)
Definition treenode.cpp:335
static void increase_total_objects(int const i)
static T list(dbe::inner::configobject::tref obj, dunedaq::conffwk::attribute_t const &attr)
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
dunedaq::conffwk::ConfigObject & ref(bool check_null=true) const
int ColumnCount() const
Definition treenode.cpp:121
virtual ~treenode()
Definition treenode.cpp:54
treenode * GetParent() const
Definition treenode.cpp:111
virtual void RemoveChild(treenode *Child)
Definition treenode.cpp:96
void rename(QString const &)
Definition treenode.cpp:71
void SetHasStructure(bool Structure)
Definition treenode.cpp:126
bool GetHasStructure() const
Definition treenode.cpp:131
virtual tref GetObject() const
Definition treenode.cpp:76
treenode(treenode *ParentNode=nullptr)
Including QT Headers.
Definition treenode.cpp:24
QList< treenode * > GetChildren() const
Definition treenode.cpp:106
treenode * GetChild(const int Row) const
Definition treenode.cpp:101
int ChildCount() const
Definition treenode.cpp:116
virtual void AddChild(treenode *Child)
Definition treenode.cpp:91
treenode * Parent
Definition treenode.hpp:50
bool GetWasFetched() const
Definition treenode.cpp:141
virtual QVariant GetData(const int Column, int role=Qt::DisplayRole) const
Definition treenode.cpp:59
void SetWasFetched(bool Fetched)
Definition treenode.cpp:136
int GetRow() const
Definition treenode.cpp:81
QList< QVariant > Data
Definition treenode.hpp:52
T relation(tref item, dunedaq::conffwk::relationship_t const &relation)
inner::configobject::tref tref
Definition tref.hpp:30
const std::vector< attribute_t > p_attributes
Definition Schema.hpp:163
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:164
std::string p_description
Definition Schema.hpp:158