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

Generated by: LCOV version 2.0-1