LCOV - code coverage report
Current view: top level - dbe/src/structure - treenode.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 185 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 38 0

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

Generated by: LCOV version 2.0-1