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