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

            Line data    Source code
       1              : /// Including DBE
       2              : #include "dbe/tree.hpp"
       3              : #include "dbe/treeselection.hpp"
       4              : #include "dbe/messenger.hpp"
       5              : 
       6            0 : dbe::models::treeselection::treeselection ( QObject * parent )
       7              :   : QSortFilterProxyModel ( parent ),
       8            0 :     Type ( RegExpFilterType ),
       9            0 :     LevelRestriction ( 1000 ),
      10            0 :     Hide ( false )
      11              : {
      12            0 :   model_common_connections();
      13            0 : }
      14              : 
      15            0 : dbe::models::treeselection::~treeselection()
      16              : {
      17            0 : }
      18              : 
      19            0 : bool dbe::models::treeselection::hasChildren ( type_index const & index ) const
      20              : {
      21            0 :   if ( index.isValid() )
      22              :   {
      23            0 :     QModelIndex sourceParent = mapToSource ( index );
      24            0 :     return sourceModel()->hasChildren ( sourceParent );
      25              :   }
      26              :   else
      27              :   {
      28              :     return true;
      29              :   }
      30              : }
      31              : 
      32            0 : bool dbe::models::treeselection::canFetchMore ( type_index const & index ) const
      33              : {
      34            0 :   if ( index.isValid() )
      35              :   {
      36            0 :     QModelIndex sourceParent = mapToSource ( index );
      37            0 :     return sourceModel()->canFetchMore ( sourceParent );
      38              :   }
      39              :   else
      40              :   {
      41              :     return false;
      42              :   }
      43              : }
      44              : 
      45            0 : void dbe::models::treeselection::fetchMore ( type_index const & index )
      46              : {
      47            0 :   QModelIndex sourceParent = mapToSource ( index );
      48            0 :   sourceModel()->fetchMore ( sourceParent );
      49            0 : }
      50              : 
      51            0 : void dbe::models::treeselection::SetFilterRestrictionLevel ( int Levels )
      52              : {
      53            0 :   LevelRestriction = Levels;
      54            0 : }
      55              : 
      56            0 : void dbe::models::treeselection::SetFilterType (
      57              :   dbe::models::treeselection::FilterType Filter )
      58              : {
      59            0 :   Type = Filter;
      60            0 : }
      61              : 
      62            0 : void dbe::models::treeselection::SetQueryObjects ( std::vector<tref> Objects )
      63              : {
      64            0 :   QueryObjects = Objects;
      65            0 : }
      66              : 
      67            0 : std::vector<dbe::tref> dbe::models::treeselection::GetQueryObjects()
      68              : {
      69            0 :   return QueryObjects;
      70              : }
      71              : 
      72            0 : dbe::treenode * dbe::models::treeselection::getnode ( type_index const & index ) const
      73              : {
      74            0 :   if ( index.isValid() )
      75              :   {
      76            0 :     dbe::models::tree * UnderlyingModel = dynamic_cast<dbe::models::tree *> ( sourceModel() );
      77              : 
      78            0 :     if ( UnderlyingModel )
      79              :     {
      80            0 :       return UnderlyingModel->getnode ( index );
      81              :     }
      82              :   }
      83              : 
      84              :   return nullptr;
      85              : }
      86              : 
      87            0 : dbe::tref dbe::models::treeselection::getobject ( type_index const & index ) const
      88              : {
      89              : 
      90            0 :   if ( index.isValid() )
      91              :   {
      92            0 :     QModelIndex sourceParent = mapToSource ( index );
      93            0 :     dbe::models::tree * my = dynamic_cast<dbe::models::tree *> ( sourceModel() );
      94              : 
      95            0 :     if ( my )
      96              :     {
      97            0 :       return my->getobject ( sourceParent );
      98              :     }
      99              :   }
     100              : 
     101            0 :   throw daq::dbe::cannot_handle_invalid_qmodelindex ( ERS_HERE );
     102              : }
     103              : 
     104            0 : dunedaq::conffwk::class_t dbe::models::treeselection::getclass ( type_index const & index ) const
     105              : {
     106            0 :   QModelIndex sourceParent = mapToSource ( index );
     107              : 
     108            0 :   if ( dbe::models::tree * my = dynamic_cast<dbe::models::tree *> ( sourceModel() ) )
     109              :   {
     110            0 :     return my->getclass ( sourceParent );
     111              :   }
     112              : 
     113            0 :   return dunedaq::conffwk::class_t();
     114              : }
     115              : 
     116            0 : QAbstractItemModel * dbe::models::treeselection::ReturnSourceModel() const
     117              : {
     118            0 :   return sourceModel();
     119              : }
     120              : 
     121            0 : void dbe::models::treeselection::ResetQueryObjects()
     122              : {
     123            0 :   QueryObjects.clear();
     124            0 : }
     125              : 
     126            0 : void dbe::models::treeselection::ResetModel()
     127              : {
     128            0 :   beginResetModel();
     129            0 :   endResetModel();
     130            0 : }
     131              : 
     132            0 : bool dbe::models::treeselection::filterAcceptsRow ( int source_row,
     133              :                                                     type_index const & source_parent ) const
     134              : {
     135            0 :   treenode * NodeObject = getnode ( sourceModel()->index ( source_row, 0, source_parent ) );
     136              : 
     137            0 :   if ( dynamic_cast<AttributeNode *> ( NodeObject ) )
     138              :   {
     139              :     return false;
     140              :   }
     141              : 
     142            0 :   if ( Hide )
     143              :   {
     144            0 :     if ( !source_parent.isValid() )
     145              :     {
     146            0 :       QModelIndex Index_1 = sourceModel()->index ( source_row, 1, source_parent );
     147              : 
     148            0 :       if ( sourceModel()->data ( Index_1 ).toUInt() == 0 )
     149              :       {
     150            0 :         return false;
     151              :       }
     152              :     }
     153              :   }
     154              : 
     155            0 :   switch ( Type )
     156              :   {
     157            0 :   case RegExpFilterType:
     158            0 :     return RegexpFilter ( source_row, source_parent );
     159              : 
     160            0 :   case ObjectFilterType:
     161            0 :     return ObjectFilter ( source_row, source_parent );
     162              : 
     163              :   default:
     164              :     return true;
     165              :   }
     166              : }
     167              : 
     168            0 : bool dbe::models::treeselection::lessThan ( type_index const & left,
     169              :                                             type_index const & right ) const
     170              : {
     171            0 :   if ( left.parent() == QModelIndex() || left.parent().parent() == QModelIndex() )
     172              :   {
     173            0 :     QVariant LeftData = sourceModel()->data ( left );
     174            0 :     QVariant RightData = sourceModel()->data ( right );
     175              : 
     176            0 :     switch ( LeftData.type() )
     177              :     {
     178            0 :     case QVariant::Bool:
     179            0 :     case QVariant::UInt:
     180            0 :       return ( LeftData.toUInt() < RightData.toUInt() );
     181              : 
     182            0 :     case QVariant::Int:
     183            0 :       return ( LeftData.toInt() < RightData.toInt() );
     184              : 
     185            0 :     case QVariant::String:
     186            0 :       return ( ( LeftData.toString() ).compare ( RightData.toString() ) > 0 );
     187              : 
     188              :     default:
     189              :       return false;
     190              :     }
     191              : 
     192              :     return true;
     193            0 :   }
     194              : 
     195              :   return false;
     196              : }
     197              : 
     198            0 : bool dbe::models::treeselection::AcceptItem ( type_index const & SourceIndex,
     199              :                                               int LevelRestriction ) const
     200              : {
     201            0 :   if ( sourceModel()->canFetchMore ( SourceIndex ) )
     202              :   {
     203            0 :     sourceModel()->fetchMore ( SourceIndex );
     204              :   }
     205              : 
     206            0 :   if ( sourceModel()->data ( SourceIndex ).toString().contains ( filterRegExp() ) )
     207              :   {
     208              :     return true;
     209              :   }
     210              : 
     211            0 :   if ( LevelRestriction <= 1 )
     212              :   {
     213              :     return false;
     214              :   }
     215              : 
     216            0 :   for ( int i = 0; i < sourceModel()->rowCount ( SourceIndex ); ++i )
     217              :   {
     218            0 :     if ( AcceptItem ( sourceModel()->index ( i, 0 ), --LevelRestriction ) )
     219              :     {
     220              :       return true;
     221              :     }
     222              :   }
     223              : 
     224              :   return false;
     225              : }
     226              : 
     227            0 : bool dbe::models::treeselection::RegexpFilter ( int sourceRow,
     228              :                                                 type_index const & sourceParent ) const
     229              : {
     230            0 :   if ( AtDepth ( sourceParent ) <= LevelRestriction )
     231              :   {
     232            0 :     QModelIndex index0 = sourceModel()->index ( sourceRow, 0, sourceParent );
     233            0 :     return AcceptItem ( index0, LevelRestriction );
     234              :   }
     235              : 
     236              :   return true;
     237              : }
     238              : 
     239            0 : bool dbe::models::treeselection::ObjectFilter ( int sourceRow,
     240              :                                                 type_index const & sourceParent ) const
     241              : {
     242            0 :   QModelIndex index0 = sourceModel()->index ( sourceRow, 0, sourceParent );
     243            0 :   QString id = sourceModel()->data ( index0 ).toString();
     244              : 
     245            0 :   if ( ( filterRegExp() ).isEmpty() )
     246              :   {
     247              :     return true;
     248              :   }
     249              : 
     250            0 :   if ( AtDepth ( sourceParent ) > 2 )
     251              :   {
     252              :     return true;
     253              :   }
     254              : 
     255            0 :   if ( !sourceParent.isValid() )
     256              :   {
     257            0 :     for ( size_t i = 0; i < QueryObjects.size(); ++i )
     258            0 :       if ( QString ( QueryObjects.at ( i ).class_name().c_str() ).compare ( id ) == 0 )
     259              :       {
     260              :         return true;
     261              :       }
     262              :   }
     263              :   else
     264              :   {
     265            0 :     for ( size_t i = 0; i < QueryObjects.size(); ++i )
     266            0 :       if ( id.compare ( QString ( QueryObjects.at ( i ).UID().c_str() ) ) == 0 )
     267              :       {
     268              :         return true;
     269              :       }
     270              :   }
     271              : 
     272              :   return false;
     273            0 : }
     274              : 
     275            0 : int dbe::models::treeselection::AtDepth ( type_index const & SourceParent ) const
     276              : {
     277            0 :   int Depth = 1;
     278            0 :   QModelIndex CurrentIndex = SourceParent;
     279              : 
     280            0 :   while ( CurrentIndex.isValid() )
     281              :   {
     282            0 :     CurrentIndex = CurrentIndex.parent();
     283            0 :     Depth++;
     284              :   }
     285              : 
     286            0 :   return Depth;
     287              : }
     288              : 
     289            0 : void dbe::models::treeselection::ToggleEmptyClasses ( bool HideLocal )
     290              : {
     291            0 :   Hide = HideLocal;
     292            0 :   ResetModel();
     293            0 : }
     294              : //----------------------------------------------------------------------------------------------------
     295              : 
     296              : //----------------------------------------------------------------------------------------------------
     297            0 : MODEL_COMMON_INTERFACE_LOOKUP_IMPL ( dbe::models::treeselection )
     298              : {
     299            0 :   if ( dbe::treenode * classnode = confaccessor::gethandler()->getnode (
     300            0 :                                      QString::fromStdString ( obj.class_name() ) ) )
     301              :   {
     302              : 
     303            0 :     auto found = [&obj, classnode] ( int i )
     304              :     {
     305            0 :       return obj.UID() == classnode->GetChild ( i )->GetData ( 0 ).toString().toStdString();
     306            0 :     };
     307              : 
     308            0 :     int i = 0;
     309            0 :     int const childs = classnode->ChildCount();
     310              : 
     311            0 :     for ( ; i < childs and not found ( i ); ++i )
     312              :       ;
     313              : 
     314            0 :     return i == childs ? QModelIndex() : index ( i, 0, QModelIndex() );
     315              :   }
     316              : 
     317            0 :   return QModelIndex();
     318              : }
     319              : //----------------------------------------------------------------------------------------------------
     320              : 
     321              : //----------------------------------------------------------------------------------------------------
     322            0 : MODEL_COMMON_INTERFACE_CREATE_THAT_OBJ_IMPL ( dbe::models::treeselection )
     323              : {
     324              : // This is a stub and nothing needs to be done since
     325              : // the real job happens in the slot defined in dbe::models::tree object from signal for treeselectionmodel
     326            0 :   Q_UNUSED(index);
     327            0 :   Q_UNUSED(obj);
     328            0 : }
     329              : 
     330            0 : MODEL_COMMON_INTERFACE_DELETE_THAT_OBJ_IMPL ( dbe::models::treeselection )
     331              : {
     332              : // This is a stub and nothing needs to be done since
     333              : // the real job happens in the slot defined in dbe::models::tree
     334            0 :   Q_UNUSED(index);
     335            0 : }
     336              : 
     337            0 : MODEL_COMMON_INTERFACE_UPDATE_THAT_OBJ_IMPL ( dbe::models::treeselection )
     338              : {
     339            0 :   Q_UNUSED(obj);
     340            0 :   type_index const mapped_index = this->mapFromSource ( index );
     341            0 :   emit dataChanged ( mapped_index, mapped_index );
     342            0 : }
     343              : 
     344            0 : MODEL_COMMON_INTERFACE_RENAME_THAT_OBJ_IMPL ( dbe::models::treeselection )
     345              : {
     346            0 :   Q_UNUSED(obj);
     347            0 :   type_index const mapped_index = this->mapFromSource ( index );
     348            0 :   emit dataChanged ( mapped_index, mapped_index );
     349            0 : }
     350              : //----------------------------------------------------------------------------------------------------
     351              : 
     352              : //----------------------------------------------------------------------------------------------------
     353            0 : TREEMODEL_REMOVE_ROWS_DEF ( dbe::models::treeselection )
     354            0 : MODEL_COMMON_INTERFACE_SLOTS_DEF ( dbe::models::treeselection )
     355              : //----------------------------------------------------------------------------------------------------
     356              : 
        

Generated by: LCOV version 2.0-1