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