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

            Line data    Source code
       1              : /// Including DBE
       2              : #include "dbe/config_ui_info.hpp"
       3              : #include "dbe/subtreeproxy.hpp"
       4              : #include "dbe/tree.hpp"
       5              : #include "dbe/treenode.hpp"
       6              : #include "dbe/confaccessor.hpp"
       7              : #include "dbe/messenger.hpp"
       8              : 
       9            0 : dbe::models::subtree_proxy::subtree_proxy ( const QString & Name,
      10              :                                             const QStringList & Default,
      11            0 :                                             QObject * parent )
      12              :   : QSortFilterProxyModel ( parent ),
      13            0 :     this_gui_windowname ( Name ),
      14            0 :     this_default_filter ( Default ),
      15            0 :     this_apply_default_filter ( false )
      16              : {
      17            0 :   check_view_type();
      18            0 :   model_common_connections();
      19            0 : }
      20              : 
      21            0 : dbe::models::subtree_proxy::~subtree_proxy()
      22              : {
      23            0 : }
      24              : 
      25            0 : void dbe::models::subtree_proxy::ResetModel()
      26              : {
      27            0 :   beginResetModel();
      28            0 :   endResetModel();
      29            0 : }
      30              : 
      31            0 : bool dbe::models::subtree_proxy::filterAcceptsRow ( int source_row,
      32              :                                                     const QModelIndex & source_parent ) const
      33              : {
      34            0 :   if ( this_apply_default_filter )
      35              :   {
      36            0 :     return ApplyDefaultFilter ( source_row, source_parent );
      37              :   }
      38              :   else
      39              :   {
      40            0 :     return ApplyUserFilter ( source_row, source_parent );
      41              :   }
      42              : }
      43              : 
      44            0 : bool dbe::models::subtree_proxy::lessThan ( const QModelIndex & left,
      45              :                                             const QModelIndex & right ) const
      46              : {
      47            0 :   if ( left.parent() == QModelIndex() || left.parent().parent() == QModelIndex() )
      48              :   {
      49            0 :     QVariant LeftData = sourceModel()->data ( left );
      50            0 :     QVariant RightData = sourceModel()->data ( right );
      51              : 
      52            0 :     switch ( LeftData.type() )
      53              :     {
      54            0 :     case QVariant::Bool:
      55            0 :     case QVariant::UInt:
      56            0 :       return ( LeftData.toUInt() < RightData.toUInt() );
      57              : 
      58            0 :     case QVariant::Int:
      59            0 :       return ( LeftData.toInt() < RightData.toInt() );
      60              : 
      61            0 :     case QVariant::String:
      62            0 :       return ( ( LeftData.toString() ).compare ( RightData.toString() ) > 0 );
      63              : 
      64              :     default:
      65              :       return false;
      66              :     }
      67              : 
      68              :     return true;
      69            0 :   }
      70              : 
      71              :   return false;
      72              : }
      73              : 
      74            0 : void dbe::models::subtree_proxy::check_view_type()
      75              : {
      76            0 :   this_window_config = confaccessor::guiconfig()->window (
      77            0 :                          this_gui_windowname.toStdString() );
      78              : 
      79            0 :   if ( this_window_config.Title.isEmpty() )
      80              :   {
      81            0 :     this_apply_default_filter = true;
      82              :   }
      83            0 : }
      84              : 
      85            0 : void dbe::models::subtree_proxy::LoadClasses()
      86              : {
      87            0 :   if ( this_apply_default_filter == false )
      88              :   {
      89            0 :     for ( QString const & i : this_window_config.GraphicalClassesList )
      90              :     {
      91            0 :       GraphicalClass Class = confaccessor::guiconfig()->graphical ( i.toStdString() );
      92            0 :       QStringList ClassList = Class.DerivedClasses;
      93            0 :       ClassList.append ( Class.DatabaseClassName );
      94              : 
      95            0 :       for ( QString & ClassName : ClassList )
      96              :       {
      97            0 :         treenode * ClassNode = confaccessor::gethandler()->getnode ( ClassName );
      98              : 
      99            0 :         if ( ClassNode )
     100              :         {
     101            0 :           dbe::models::tree * UnderlyingModel =
     102            0 :             static_cast<dbe::models::tree *> ( sourceModel() );
     103            0 :           QModelIndex ParentIndex = UnderlyingModel->getindex ( ClassNode );
     104              : 
     105            0 :           if ( sourceModel()->canFetchMore ( ParentIndex ) ) sourceModel()->fetchMore (
     106              :               ParentIndex );
     107              :         }
     108              :       }
     109            0 :     }
     110              :   }
     111            0 : }
     112              : 
     113            0 : dbe::tref dbe::models::subtree_proxy::getobject ( const QModelIndex & index ) const
     114              : {
     115            0 :   if ( index.isValid() )
     116              :   {
     117            0 :     QModelIndex sourceParent = mapToSource ( index );
     118            0 :     dbe::models::tree * my = dynamic_cast<dbe::models::tree *> ( sourceModel() );
     119              : 
     120            0 :     if ( my )
     121              :     {
     122            0 :       return my->getobject ( sourceParent );
     123              :     }
     124              :   }
     125              : 
     126            0 :   throw daq::dbe::cannot_handle_invalid_qmodelindex ( ERS_HERE );
     127              : }
     128              : 
     129            0 : dbe::treenode * dbe::models::subtree_proxy::getnode ( const QModelIndex & index ) const
     130              : {
     131            0 :   QModelIndex sourceParent = mapToSource ( index );
     132            0 :   dbe::models::tree * my = dynamic_cast<dbe::models::tree *> ( sourceModel() );
     133              : 
     134            0 :   if ( my )
     135              :   {
     136            0 :     return my->getnode ( sourceParent );
     137              :   }
     138              : 
     139              :   return nullptr;
     140              : }
     141              : 
     142            0 : dunedaq::conffwk::class_t dbe::models::subtree_proxy::getclass ( const QModelIndex & index )
     143              : const
     144              : {
     145            0 :   QModelIndex sourceParent = mapToSource ( index );
     146            0 :   dbe::models::tree * my = dynamic_cast<dbe::models::tree *> ( sourceModel() );
     147              : 
     148            0 :   if ( my )
     149              :   {
     150            0 :     return my->getclass ( sourceParent );
     151              :   }
     152              : 
     153            0 :   return dunedaq::conffwk::class_t();
     154              : }
     155              : 
     156            0 : QAbstractItemModel * dbe::models::subtree_proxy::ReturnSourceModel() const
     157              : {
     158            0 :   return sourceModel();
     159              : }
     160              : 
     161            0 : bool dbe::models::subtree_proxy::ApplyDefaultFilter ( int source_row,
     162              :                                                       const QModelIndex & source_parent ) const
     163              : {
     164            0 :   Q_UNUSED ( source_row )
     165            0 :   Q_UNUSED ( source_parent )
     166              : 
     167            0 :   return true;
     168              : }
     169              : 
     170            0 : bool dbe::models::subtree_proxy::ApplyUserFilter ( int source_row,
     171              :                                                    const QModelIndex & source_parent ) const
     172              : {
     173            0 :   dbe::models::tree * srcmodel = static_cast<tree *> ( sourceModel() );
     174              : 
     175            0 :   QModelIndex const & nodeindex = srcmodel->index ( source_row, 0, source_parent );
     176            0 :   treenode * tofilter = srcmodel->getnode ( nodeindex );
     177            0 :   QString const nodename = srcmodel->data ( nodeindex ).toString();
     178              : 
     179            0 :   if ( not source_parent.isValid() )
     180              :   {
     181              :     /// Process classes
     182              : 
     183            0 :     for ( QString const & admissible : this_window_config.GraphicalClassesList )
     184              :     {
     185            0 :       GraphicalClass candidate = confaccessor::guiconfig()->graphical (
     186            0 :                                    admissible.toStdString() );
     187              : 
     188            0 :       if ( candidate.DatabaseClassName == nodename
     189            0 :            or candidate.DerivedClasses.contains ( nodename ) )
     190              :       {
     191            0 :         return true;
     192              :       }
     193            0 :     }
     194              :   }
     195            0 :   else if ( dynamic_cast<ObjectNode *> ( tofilter ) )
     196              :   {
     197              :     return true;
     198              :   }
     199            0 :   else if ( dynamic_cast<RelationshipNode *> ( tofilter ) )
     200              :   {
     201              :     /// Process objects
     202            0 :     QString const related = sourceModel()->data ( nodeindex.parent().parent() ).toString();
     203              : 
     204            0 :     for ( QString const & admissible : this_window_config.GraphicalClassesList )
     205              :     {
     206            0 :       GraphicalClass candidate = confaccessor::guiconfig()->graphical (
     207            0 :                                    admissible.toStdString() );
     208              : 
     209            0 :       if ( candidate.DatabaseClassName == related or candidate.DerivedClasses.contains (
     210              :              related ) )
     211              :       {
     212            0 :         return candidate.ShowAllRelationships or candidate.Relationships.contains ( nodename );
     213              :       }
     214              : 
     215            0 :     }
     216            0 :   }
     217              : 
     218              :   return false;
     219            0 : }
     220              : //----------------------------------------------------------------------------------------------------
     221              : 
     222              : //----------------------------------------------------------------------------------------------------
     223            0 : MODEL_COMMON_INTERFACE_LOOKUP_IMPL ( dbe::models::subtree_proxy )
     224              : {
     225            0 :   if ( treenode * classnode = confaccessor::gethandler()->getnode (
     226            0 :                                 QString::fromStdString ( obj.class_name() ) ) )
     227              :   {
     228              : 
     229            0 :     auto found = [&obj, classnode] ( int i )
     230              :     {
     231            0 :       return obj.UID() == classnode->GetChild ( i )->GetData ( 0 ).toString().toStdString();
     232            0 :     };
     233              : 
     234            0 :     int i = 0;
     235            0 :     int const childs = classnode->ChildCount();
     236              : 
     237            0 :     for ( ; i < childs and not found ( i ); ++i )
     238              :       ;
     239              : 
     240            0 :     return i == childs ? QModelIndex() : index ( i, 0, QModelIndex() );
     241              :   }
     242              : 
     243            0 :   return QModelIndex();
     244              : }
     245              : 
     246            0 : MODEL_COMMON_INTERFACE_CREATE_THAT_OBJ_IMPL ( dbe::models::subtree_proxy )
     247              : {
     248              : // TODO implement create object from signal for Subtreeproxymodel
     249            0 :   Q_UNUSED(index);
     250            0 :   Q_UNUSED(obj);
     251            0 : }
     252              : 
     253            0 : MODEL_COMMON_INTERFACE_DELETE_THAT_OBJ_IMPL ( dbe::models::subtree_proxy )
     254              : {
     255            0 :   if ( index.isValid() )
     256              :   {
     257            0 :     this->removeRows ( index.row(), 1, index.parent() );
     258              :   }
     259            0 : }
     260              : 
     261            0 : MODEL_COMMON_INTERFACE_RENAME_THAT_OBJ_IMPL ( dbe::models::subtree_proxy )
     262              : {
     263              :   //TODO implement rename object
     264            0 :   Q_UNUSED(index);
     265            0 :   Q_UNUSED(obj);
     266            0 : }
     267              : 
     268            0 : MODEL_COMMON_INTERFACE_UPDATE_THAT_OBJ_IMPL ( dbe::models::subtree_proxy )
     269              : {
     270              : // TODO implement update object from signal for Subtreeproxymodel
     271            0 :   Q_UNUSED(index);
     272            0 :   Q_UNUSED(obj);
     273            0 : }
     274              : 
     275            0 : TREEMODEL_REMOVE_ROWS_DEF ( dbe::models::subtree_proxy )
     276            0 : MODEL_COMMON_INTERFACE_SLOTS_DEF ( dbe::models::subtree_proxy )
     277              : //----------------------------------------------------------------------------------------------------
     278              : 
        

Generated by: LCOV version 2.0-1