LCOV - code coverage report
Current view: top level - dbe/src/structure - tree.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 218 0
Test Date: 2026-07-12 15:23:06 Functions: 0.0 % 35 0

            Line data    Source code
       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              : 
       6              : #include "dbe/config_api.hpp"
       7              : #include "dbe/confaccessor.hpp"
       8              : #include "dbe/config_reference.hpp"
       9              : #include "dbe/tree.hpp"
      10              : #include "dbe/treenode.hpp"
      11              : #include "dbe/ui_constants.hpp"
      12              : #include "dbe/version.hpp"
      13              : 
      14              : #include <QMimeData>
      15              : 
      16              : char const * const dbe_lib_structure_version = dbe_compiled_version;
      17              : 
      18            0 : dbe::models::tree::tree ( const QStringList & Headers, QObject * parent )
      19              :   : QAbstractItemModel ( parent ),
      20            0 :     abstract_classes_selectable ( false )
      21              : {
      22            0 :   confaccessor::gethandler()->root = new dbe::treenode ( Headers );
      23              : 
      24            0 :   for ( std::string const & aclass : dbe::config::api::info::onclass::allnames <
      25            0 :         std::vector<std::string >> () )
      26              :   {
      27            0 :     new ClassNode ( dbe::config::api::info::onclass::definition ( aclass, false ),
      28            0 :                     confaccessor::gethandler()->root );
      29            0 :   }
      30              : 
      31            0 :   model_common_connections();
      32            0 : }
      33              : 
      34            0 : dbe::models::tree::~tree()
      35            0 : {}
      36              : 
      37            0 : dbe::models::tree::type_index dbe::models::tree::index ( int row, int column,
      38              :                                                          type_index const & parent ) const
      39              : {
      40              :   // This is standard qt implementation for a tree mode;
      41            0 :   dbe::treenode * up{parent.isValid() ? getnode ( parent ) : confaccessor::gethandler()->root};
      42              : 
      43            0 :   if ( dbe::treenode * down = up->GetChild ( row ) )
      44              :   {
      45            0 :     return createIndex ( row, column, down );
      46              :   }
      47              :   else
      48              :   {
      49            0 :     return QModelIndex();
      50              :   }
      51              : }
      52              : 
      53            0 : dbe::models::tree::type_index dbe::models::tree::parent ( const type_index & child ) const
      54              : {
      55            0 :   if ( child.isValid() )
      56              :   {
      57            0 :     dbe::treenode * up = getnode ( child )->GetParent();
      58              : 
      59            0 :     if ( up != confaccessor::gethandler()->root )
      60              :     {
      61            0 :       return createIndex ( up->GetRow(), 0, up );
      62              :     }
      63              :   }
      64              : 
      65            0 :   return QModelIndex();
      66              : }
      67              : 
      68            0 : int dbe::models::tree::rowCount ( const QModelIndex & parent ) const
      69              : {
      70            0 :   dbe::treenode * ParentNode;
      71              : 
      72            0 :   if ( !parent.isValid() )
      73              :   {
      74            0 :     ParentNode = confaccessor::gethandler()->getnode();
      75              :   }
      76              :   else
      77              :   {
      78            0 :     ParentNode = getnode ( parent );
      79              :   }
      80              : 
      81            0 :   return ParentNode->ChildCount();
      82              : }
      83              : 
      84            0 : int dbe::models::tree::columnCount ( const type_index & parent ) const
      85              : {
      86            0 :   if ( parent.isValid() )
      87              :   {
      88            0 :     dbe::treenode * DataNode = getnode ( parent );
      89              : 
      90            0 :     return DataNode->ColumnCount();
      91              :   }
      92              :   else
      93              :   {
      94            0 :     return confaccessor::gethandler()->root->ColumnCount();
      95              :   }
      96              : }
      97              : 
      98            0 : Qt::ItemFlags dbe::models::tree::flags ( type_index const & index ) const
      99              : {
     100            0 :   treenode * node = getnode ( index );
     101              : 
     102            0 :   if ( ClassNode * classnode = dynamic_cast<ClassNode *> ( node ) )
     103              :   {
     104            0 :     dunedaq::conffwk::class_t classinfo = classnode->GetClassInfo();
     105              : 
     106            0 :     if ( classinfo.p_abstract )
     107              :     {
     108            0 :       return
     109            0 :         abstract_classes_selectable ?
     110            0 :         ( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) : ( Qt::ItemIsSelectable );
     111              :     }
     112              :     else
     113              :     {
     114            0 :       return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
     115              :     }
     116            0 :   }
     117              : 
     118            0 :   return ( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
     119              : }
     120              : 
     121            0 : QVariant dbe::models::tree::data ( type_index const & index, int role ) const
     122              : {
     123            0 :   if ( index.isValid() )
     124              :   {
     125            0 :     switch ( role )
     126              :     {
     127            0 :     case Qt::ForegroundRole:
     128            0 :       if ( ObjectNode * onode = dynamic_cast<ObjectNode *> ( getnode ( index ) ) )
     129              :       {
     130            0 :         try
     131              :         {
     132            0 :           tref const & obj = onode->GetObject();
     133              : 
     134            0 :           if ( confaccessor::check_file_rw ( QString::fromStdString ( obj.contained_in() ) ) )
     135              :           {
     136            0 :             return QVariant ( QColor ( Qt::blue ) );
     137              :           }
     138              :           else
     139              :           {
     140            0 :             return QVariant ( QColor ( Qt::darkGray ) );
     141              :           }
     142            0 :         }
     143            0 :         catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
     144              :         {
     145              :           // nothing to do the onode refers to a removed object and has not yet been removed
     146            0 :           return QVariant();
     147            0 :         }
     148              :       }
     149              : 
     150              :       break;
     151              : 
     152            0 :     case Qt::ToolTipRole:
     153            0 :       if ( auto cnode = dynamic_cast<ClassNode *> ( getnode ( index ) ) )
     154              :       {
     155            0 :         return cnode->GetData ( index.column(), role );
     156              :       }
     157              :       break;
     158              : 
     159            0 :     case Qt::DisplayRole:
     160            0 :     case Qt::DecorationRole:
     161            0 :       return getnode ( index )->GetData ( index.column(), role );
     162              :     }
     163              :   }
     164              : 
     165            0 :   return QVariant();
     166              : }
     167              : 
     168            0 : QVariant dbe::models::tree::headerData ( int section, Qt::Orientation orientation,
     169              :                                          int role ) const
     170              : {
     171            0 :   if ( ( orientation == Qt::Horizontal ) && ( role == Qt::DisplayRole ) )
     172              :   {
     173            0 :     return confaccessor::gethandler()->root->GetData ( section );
     174              :   }
     175              : 
     176            0 :   return QVariant();
     177              : }
     178              : 
     179            0 : bool dbe::models::tree::insertRows ( int position, int rows, const QModelIndex & parent )
     180              : {
     181            0 :   if ( ClassNode * onode = dynamic_cast<ClassNode *> ( getnode ( parent ) ) )
     182              :   {
     183            0 :     rows = onode->ChildCount();
     184              : 
     185            0 :     beginInsertRows ( parent, position, position + rows - 1 );
     186              : 
     187            0 :     std::string const & classname = onode->GetData (
     188            0 :                                       static_cast<int> ( tablepositions::classname ) ).toString().toStdString();
     189              : 
     190            0 :     std::vector<tref> const & objects = config::api::info::onclass::objects ( classname,
     191            0 :                                                                               false );
     192              : 
     193            0 :     for ( auto const & i : objects )
     194              :     {
     195            0 :       new ObjectNode ( i, false, onode );
     196            0 :       emit ObjectFile(QString::fromStdString(i.contained_in()));
     197              :     }
     198              : 
     199            0 :     endInsertRows();
     200              : 
     201            0 :     return true;
     202            0 :   }
     203              :   else
     204              :   {
     205              :     return false;
     206              :   }
     207              : }
     208              : 
     209            0 : bool dbe::models::tree::canFetchMore ( type_index const & parent ) const
     210              : {
     211            0 :   if ( parent.isValid() )
     212              :   {
     213            0 :     treenode * ParentNode = getnode ( parent );
     214            0 :     return ( !ParentNode->GetWasFetched() );
     215              :   }
     216              : 
     217              :   return false;
     218              : }
     219              : 
     220            0 : void dbe::models::tree::fetchMore ( type_index const & parent )
     221              : {
     222            0 :   if ( parent.isValid() )
     223              :   {
     224            0 :     treenode * ParentNode = getnode ( parent );
     225              : 
     226            0 :     if ( !ParentNode->GetWasFetched() )
     227              :     {
     228            0 :       insertRows ( 0, 0, parent );
     229            0 :       ParentNode->SetWasFetched ( true );
     230              :     }
     231              :   }
     232            0 : }
     233              : 
     234            0 : bool dbe::models::tree::hasChildren ( const QModelIndex & parent ) const
     235              : {
     236            0 :   if ( parent.isValid() )
     237              :   {
     238            0 :     treenode * ParentNode = getnode ( parent );
     239            0 :     return ( ParentNode->GetHasStructure() );
     240              :   }
     241              : 
     242              :   return true;
     243              : }
     244              : 
     245            0 : bool dbe::models::tree::setData ( type_index const & index, const QVariant & value,
     246              :                                   int role )
     247              : {
     248            0 :   Q_UNUSED ( index )
     249            0 :   Q_UNUSED ( value )
     250            0 :   Q_UNUSED ( role )
     251              : 
     252            0 :   return true;
     253              : }
     254              : 
     255            0 : QStringList dbe::models::tree::mimeTypes() const
     256              : {
     257            0 :   QStringList types;
     258            0 :   types << "application/vnd.text.list";
     259            0 :   return types;
     260            0 : }
     261              : 
     262            0 : QMimeData * dbe::models::tree::mimeData ( const QModelIndexList & indexes ) const
     263              : {
     264            0 :   QMimeData * mimeData = new QMimeData();
     265            0 :   QByteArray encodedData;
     266              : 
     267            0 :   QDataStream stream ( &encodedData, QIODevice::WriteOnly );
     268              : 
     269            0 :   foreach ( QModelIndex index, indexes )
     270              :   {
     271            0 :     if ( index.isValid() && index.column() == 0 )
     272              :     {
     273            0 :       QStringList Text;
     274            0 :       treenode * NodeObject = getnode ( index );
     275              : 
     276            0 :       tref Object = NodeObject->GetObject();
     277            0 :       QString ObjectUid = QString::fromStdString ( Object.UID() );
     278            0 :       QString ObjectClassName = QString::fromStdString ( Object.class_name() );
     279              : 
     280            0 :       Text.append ( ObjectUid );
     281            0 :       Text.append ( ObjectClassName );
     282              : 
     283            0 :       stream << Text;
     284            0 :     }
     285            0 :   }
     286              : 
     287            0 :   mimeData->setData ( "application/vnd.text.list", encodedData );
     288            0 :   return mimeData;
     289            0 : }
     290              : 
     291            0 : QModelIndex dbe::models::tree::getindex ( treenode * NodeItem,
     292              :                                           type_index const & RootIndex ) const
     293              : {
     294            0 :   for ( int i = 0; i < rowCount ( RootIndex ); ++i )
     295              :   {
     296            0 :     QModelIndex ChildIndex = index ( i, 0, RootIndex );
     297            0 :     treenode * ChildNode = getnode ( ChildIndex );
     298              : 
     299            0 :     if ( NodeItem == ChildNode )
     300              :     {
     301            0 :       return ChildIndex;
     302              :     }
     303              : 
     304            0 :     QModelIndex ChildChildIndex = getindex ( NodeItem, ChildIndex );
     305              : 
     306            0 :     if ( ChildChildIndex.isValid() )
     307              :     {
     308            0 :       return ChildChildIndex;
     309              :     }
     310              :   }
     311              : 
     312            0 :   return QModelIndex();
     313              : }
     314              : 
     315            0 : void dbe::models::tree::ResetModel()
     316              : {
     317            0 :   beginResetModel();
     318            0 :   endResetModel();
     319            0 : }
     320              : 
     321            0 : dbe::models::tree::type_datum * dbe::models::tree::getnode ( type_index const & index )
     322              : const
     323              : {
     324            0 :   if ( index.isValid() )
     325              :   {
     326            0 :     return static_cast<treenode *> ( index.internalPointer() );
     327              :   }
     328              : 
     329            0 :   return confaccessor::gethandler()->root;
     330              : }
     331              : 
     332            0 : dbe::tref dbe::models::tree::getobject ( const QModelIndex & index ) const
     333              : {
     334            0 :   if ( index.isValid() )
     335              :   {
     336            0 :     if ( ObjectNode * ObjectItem = dynamic_cast<ObjectNode *> ( getnode ( index ) ) )
     337              :     {
     338            0 :       return ObjectItem->GetObject();
     339              :     }
     340              :   }
     341              : 
     342            0 :   throw daq::dbe::cannot_handle_invalid_qmodelindex ( ERS_HERE );
     343              : 
     344              : }
     345              : 
     346            0 : dunedaq::conffwk::class_t dbe::models::tree::getclass ( type_index const & index ) const
     347              : {
     348            0 :   treenode * Item = getnode ( index );
     349              : 
     350            0 :   if ( Item != 0 )
     351              :   {
     352            0 :     ClassNode * ClassItem = dynamic_cast<ClassNode *> ( Item );
     353              : 
     354            0 :     if ( ClassItem != nullptr )
     355              :     {
     356            0 :       return ClassItem->GetClassInfo();
     357              :     }
     358              : 
     359            0 :     ObjectNode * ObjectItem = dynamic_cast<ObjectNode *> ( Item );
     360              : 
     361            0 :     if ( ObjectItem != nullptr )
     362              :     {
     363            0 :       tref Object = ObjectItem->GetObject();
     364            0 :       return dbe::config::api::info::onclass::definition ( Object.class_name(), false );
     365            0 :     }
     366              : 
     367            0 :     RelationshipNode * RelationshipItem = dynamic_cast<RelationshipNode *> ( Item );
     368              : 
     369            0 :     if ( RelationshipItem != nullptr )
     370              :     {
     371            0 :       return dbe::config::api::info::onclass::definition (
     372            0 :                RelationshipItem->relation_t().p_type,
     373            0 :                false );
     374              :     }
     375              :   }
     376              : 
     377            0 :   return dunedaq::conffwk::class_t();
     378              : }
     379              : 
     380            0 : QAbstractItemModel * dbe::models::tree::ReturnSourceModel() const
     381              : {
     382            0 :   return nullptr;
     383              : }
     384              : 
     385            0 : void dbe::models::tree::ToggleAbstractClassesSelectable ( bool const val )
     386              : {
     387            0 :   abstract_classes_selectable = val;
     388            0 :   ResetModel();
     389            0 : }
     390              : 
     391            0 : void dbe::models::tree::objectsUpdated(const std::vector<dbe::dref>& objects) {
     392            0 :     update_multiple_objects(objects);
     393            0 : }
     394              : 
     395              : //----------------------------------------------------------------------------------------------------
     396              : 
     397              : //----------------------------------------------------------------------------------------------------
     398            0 : MODEL_COMMON_INTERFACE_LOOKUP_IMPL ( dbe::models::tree )
     399              : {
     400            0 :   if ( treenode * classnode = confaccessor::gethandler()->getnode (
     401            0 :                                 QString::fromStdString ( obj.class_name() ) ) )
     402              :   {
     403              : 
     404            0 :     auto found = [&obj, classnode] ( int i )
     405              :     {
     406            0 :       return obj.UID() == classnode->GetChild ( i )->GetData ( 0 ).toString().toStdString();
     407            0 :     };
     408              : 
     409            0 :     int i = 0;
     410            0 :     int const childs = classnode->ChildCount();
     411              : 
     412            0 :     for ( ; i < childs and not found ( i ); ++i )
     413              : 
     414              :       ;
     415              : 
     416            0 :     QModelIndex parent_index = getindex ( classnode );
     417              : 
     418            0 :     return childs == i ? QModelIndex() : index ( i, parent_index.column(), parent_index );
     419              :   }
     420              : 
     421            0 :   return QModelIndex();
     422              : }
     423              : 
     424            0 : MODEL_COMMON_INTERFACE_CREATE_THAT_OBJ_IMPL ( dbe::models::tree )
     425              : {
     426            0 :   Q_UNUSED(index);
     427            0 :   if ( treenode * classnode = confaccessor::gethandler()->getnode ( obj.class_name() ) )
     428              :   {
     429            0 :     if ( not dbe::datahandler::findchild ( classnode, QString::fromStdString ( obj.UID() ) ) )
     430              :     {
     431            0 :       layoutAboutToBeChanged();
     432            0 :       new ObjectNode ( obj, false, classnode );
     433              :       // Normally we would have to call changePersistentIndex.
     434              :       // Because an objectnode is created which had no index
     435              :       // before this creation had occured there is no need to call it.
     436            0 :       emit layoutChanged();
     437              :     }
     438              :   }
     439            0 : }
     440              : 
     441            0 : MODEL_COMMON_INTERFACE_DELETE_THAT_OBJ_IMPL ( dbe::models::tree )
     442              : {
     443            0 :   if ( index.isValid() )
     444              :   {
     445            0 :     this->removeRows ( index.row(), 1, index.parent() );
     446              :   }
     447            0 : }
     448              : 
     449            0 : MODEL_COMMON_INTERFACE_RENAME_THAT_OBJ_IMPL ( dbe::models::tree )
     450              : {
     451            0 :   if ( index.isValid() )
     452              :   {
     453            0 :     treenode * child = getnode ( index );
     454            0 :     child->rename ( QString::fromStdString ( obj.ref().UID() ) );
     455            0 :     emit dataChanged ( index, index );
     456              :   }
     457            0 : }
     458              : 
     459            0 : MODEL_COMMON_INTERFACE_UPDATE_THAT_OBJ_IMPL ( dbe::models::tree )
     460              : {
     461              :   // Some form of change has occured , we remove and insert a new object node
     462              :   // for the specified object
     463            0 :   if ( index.isValid() )
     464              :   {
     465              :     // This in the worst case return a pointer to root in the tree
     466            0 :     treenode * child = getnode ( index );
     467              : 
     468            0 :     if ( treenode * parent = child->GetParent() )
     469              :     {
     470            0 :       emit layoutAboutToBeChanged();
     471            0 :       parent->RemoveChild ( child );
     472            0 :       new ObjectNode ( obj, false, parent );
     473            0 :       emit layoutChanged();
     474              :     }
     475              :   }
     476            0 : }
     477              : 
     478              : //----------------------------------------------------------------------------------------------------
     479              : 
     480              : //----------------------------------------------------------------------------------------------------
     481            0 : TREEMODEL_REMOVE_ROWS_DEF ( dbe::models::tree )
     482            0 : MODEL_COMMON_INTERFACE_SLOTS_DEF ( dbe::models::tree )
     483              : //----------------------------------------------------------------------------------------------------
        

Generated by: LCOV version 2.0-1