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