LCOV - code coverage report
Current view: top level - /opt/artdaq/srcs/artdaq-mfextensions/ErrorHandler/Components - NodeInfo.cpp (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 0.0 % 122 0
Test Date: 2025-09-04 00:45:34 Functions: 0.0 % 8 0

            Line data    Source code
       1              : #include "ErrorHandler/Components/NodeInfo.h"
       2              : #include <sstream>
       3              : 
       4              : #include <QtGui/QPainter>
       5              : 
       6              : using namespace novadaq::errorhandler;
       7              : 
       8            0 : NodeInfo::NodeInfo(node_type_t type, std::string const& key, QListWidget* parent, bool aow, bool aoe)
       9            0 :     : msgs_ptr(new msgs_t)
      10            0 :     , highest_sev(SDEBUG)
      11            0 :     , item_ptr()
      12            0 :     , node_type(type)
      13            0 :     , key_str(key)
      14            0 :     , alarm_warning(aow)
      15            0 :     , alarm_error(aoe)
      16              : {
      17            0 :         QString cap = get_caption(key);
      18              : 
      19              :         // icon
      20            0 :         int icon_w = 0;
      21            0 :         int icon_h = 0;
      22            0 :         get_icon_geometry(icon_w, icon_h);
      23              : 
      24            0 :         QPixmap pm(icon_w, icon_h);
      25            0 :         QIcon icon(pm);
      26              : 
      27              :         // list widget item
      28            0 :         item_ptr = new QListWidgetItem(icon, cap, parent);
      29              : 
      30              :         // node size
      31            0 :         int node_w = 0;
      32            0 :         int node_h = 0;
      33            0 :         get_node_geometry(node_w, node_h);
      34            0 :         QSize sz(node_w, node_h);
      35            0 :         item_ptr->setSizeHint(sz);
      36              : 
      37              :         // user data
      38            0 :         QVariant v = QVariant::fromValue((void*)this);
      39            0 :         item_ptr->setData(Qt::UserRole, v);
      40              : 
      41              :         // item_ptr->setData(Qt::UserRole, QVariant(key.c_str()));
      42              :         // item_ptr->setData(Qt::UserRole, QVariant::fromValue<msgs_ptr_t>(msgs_ptr));
      43            0 : }
      44              : 
      45            0 : node_status NodeInfo::push_msg(qt_mf_msg const& msg)
      46              : {
      47            0 :         sev_code_t sev = msg.sev();
      48              : 
      49            0 :         node_status status = NORMAL;
      50              : 
      51            0 :         if (sev >= highest_sev)
      52              :         {
      53              :                 // push the message into the queue
      54            0 :                 if (msgs_ptr->size() > MAX_QUEUE) msgs_ptr->pop_front();
      55            0 :                 msgs_ptr->push_back(msg);
      56              : 
      57              :                 // update icon
      58            0 :                 if (sev > highest_sev)
      59              :                 {
      60            0 :                         if (sev == SWARNING && alarm_warning)
      61            0 :                                 status = FIRST_WARNING;
      62            0 :                         else if (sev == SERROR && alarm_error)
      63            0 :                                 status = FIRST_ERROR;
      64              : 
      65            0 :                         update_icon(sev);
      66              :                 }
      67              : 
      68              :                 // update hightest severity lvl
      69            0 :                 highest_sev = sev;
      70              :         }
      71              : 
      72            0 :         return status;
      73              : }
      74              : 
      75            0 : void NodeInfo::reset()
      76              : {
      77            0 :         highest_sev = SDEBUG;
      78            0 :         update_icon(highest_sev);
      79            0 : }
      80              : 
      81            0 : QString NodeInfo::msgs_to_string() const
      82              : {
      83            0 :         QString txt;
      84              : 
      85            0 :         msgs_t::const_iterator it = msgs_ptr->begin();
      86            0 :         while (it != msgs_ptr->end())
      87              :         {
      88            0 :                 txt += (*it).text(false);
      89            0 :                 ++it;
      90              :         }
      91              : 
      92            0 :         return txt;
      93            0 : }
      94              : 
      95            0 : void NodeInfo::update_icon(sev_code_t sev)
      96              : {
      97            0 :         int icon_w = 0;
      98            0 :         int icon_h = 0;
      99            0 :         get_icon_geometry(icon_w, icon_h);
     100              : 
     101            0 :         QPixmap pm(icon_w, icon_h);
     102            0 :         pm.fill(Qt::transparent);
     103              : 
     104            0 :         QColor background;
     105              : 
     106            0 :         switch (sev)
     107              :         {
     108            0 :                 case SERROR:
     109            0 :                         background = QColor(255, 0, 0, 255);
     110            0 :                         break;
     111              : 
     112            0 :                 case SWARNING:
     113            0 :                         background = QColor(224, 128, 0, 255);
     114            0 :                         break;
     115              : 
     116            0 :                 case SINFO:
     117            0 :                         background = QColor(0, 128, 0, 255);
     118            0 :                         break;
     119              : 
     120            0 :                 case SDEBUG:
     121            0 :                         background = QColor(80, 80, 80, 255);
     122            0 :                         break;
     123              : 
     124            0 :                 default:
     125            0 :                         background = QColor(200, 200, 200);
     126              :         }
     127              : 
     128            0 :         QPainter painter(&pm);
     129              : 
     130            0 :         QRect rect(2, 2, icon_w - 4, icon_h - 4);
     131            0 :         painter.setPen(Qt::NoPen);
     132            0 :         painter.fillRect(rect, background);
     133              : 
     134            0 :         QPen pen(Qt::black);
     135            0 :         painter.setPen(pen);
     136              : 
     137            0 :         QBrush brush(Qt::yellow);
     138              : 
     139            0 :         if (alarm_warning)
     140              :         {
     141            0 :                 int off = alarm_error ? 22 : 11;
     142            0 :                 QBrush brush(Qt::yellow);
     143            0 :                 painter.setBrush(brush);
     144            0 :                 painter.drawEllipse(icon_w - off, icon_h - 11, 10, 10);
     145            0 :         }
     146              : 
     147            0 :         if (alarm_error)
     148              :         {
     149            0 :                 QBrush brush(Qt::red);
     150            0 :                 painter.setBrush(brush);
     151            0 :                 painter.drawEllipse(icon_w - 11, icon_h - 11, 10, 10);
     152            0 :         }
     153              : 
     154            0 :         QIcon icon(pm);
     155              : 
     156            0 :         item_ptr->setIcon(icon);
     157            0 : }
     158              : 
     159            0 : void NodeInfo::get_icon_geometry(int& icon_w, int& icon_h) const
     160              : {
     161            0 :         switch (node_type)
     162              :         {
     163            0 :                 case External:
     164            0 :                         icon_w = BUFFERNODE_ICON_WIDTH;
     165            0 :                         icon_h = BUFFERNODE_ICON_HEIGHT;
     166            0 :                         break;
     167            0 :                 case UserCode:
     168            0 :                         icon_w = DCM_ICON_WIDTH;
     169            0 :                         icon_h = DCM_ICON_HEIGHT;
     170            0 :                         break;
     171            0 :                 case Framework:
     172              :                 default:
     173            0 :                         icon_w = MAINCOMPONENT_ICON_WIDTH;
     174            0 :                         icon_h = MAINCOMPONENT_ICON_HEIGHT;
     175              :         }
     176            0 : }
     177              : 
     178            0 : void NodeInfo::get_node_geometry(int& node_w, int& node_h) const
     179              : {
     180            0 :         switch (node_type)
     181              :         {
     182            0 :                 case External:
     183            0 :                         node_w = BUFFERNODE_NODE_WIDTH;
     184            0 :                         node_h = BUFFERNODE_NODE_HEIGHT;
     185            0 :                         break;
     186            0 :                 case UserCode:
     187            0 :                         node_w = DCM_NODE_WIDTH;
     188            0 :                         node_h = DCM_NODE_HEIGHT;
     189            0 :                         break;
     190            0 :                 case Framework:
     191              :                 default:
     192            0 :                         node_w = MAINCOMPONENT_NODE_WIDTH;
     193            0 :                         node_h = MAINCOMPONENT_NODE_HEIGHT;
     194              :         }
     195            0 : }
     196              : 
     197            0 : QString NodeInfo::get_caption(std::string const& key) const
     198              : {
     199              :         // if (node_type==BufferNode)  return key.substr(18).c_str();
     200              :         // if (node_type==DCM)         return key.substr(4 ).c_str();
     201              : 
     202            0 :         return key.c_str();
     203              : }
        

Generated by: LCOV version 2.0-1