Commit 213d3ab4 authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

https://gitlab.elettra.eu/cs/gui/alarm-ng/-/issues/ [200~Handle alarms with...

https://gitlab.elettra.eu/cs/gui/alarm-ng/-/issues/ [200~Handle alarms with same name in different alarm-handler~
parent a27c9029
......@@ -188,20 +188,22 @@ void AlarmTreeWidget::refresh(const CuData &v) {
}
data = unknown_level + lowest + low + medium + high;
QString alanam, alkey; // alarm name, alarm key (=src/alarm_name)
int index = 0;
QSet<QString> oldset = mSrcAlarmHash.value(src);
QSet<QString>& alsrcset = mSrcAlarmHash[src];
// sets of alarms for the given src
QSet<QString> oldset = mSrcAlarmHash.value(src); // save current
QSet<QString>& alsrcset = mSrcAlarmHash[src]; // modify with new data (see (*) )
alsrcset.clear(); // empty set for src
/* add items to the tree(s) if not already present */
for (int i = data.size() - 1; i >= 0; i--) {
fields = data[i].split("\t");
alanam = fields.at(AlarmTreeWidgetItem::Alarm);
alkey = m_make_key(alanam, src);
/* save current scroll bar value */
scrollBarPos = verticalScrollBar()->value();
/* instead of GROUP information, show DEVICE */
fields[DEVICE] = dev;
item = mItemHash.value(fields.at(AlarmTreeWidgetItem::Alarm));
item = mItemHash.value(alkey);
if(!item) /* create a new item */ {
index = findPos(fields[0].toUInt(), fields[AlarmTreeWidgetItem::Level], fields[AlarmTreeWidgetItem::Status]);
m_insert_item(src, fields, index);
......@@ -215,17 +217,17 @@ void AlarmTreeWidget::refresh(const CuData &v) {
/* restore scrollbar value */
verticalScrollBar()->setValue(scrollBarPos);
// add alarm name to set of alarm names for this src
alsrcset.insert(fields.at(AlarmTreeWidgetItem::Alarm));
// (*) add alarm name to set of alarm names for this src
alsrcset.insert(alanam); // alsrcset is a reference
// notify new alarm detected. connected to Alarm::beep
if(fields.size() > 5 && (fields[3] == "ALARM" || fields[3] == "ERROR") && fields.last() == "NEW")
emit newAlarmDetected();
}
/* remove stale items */
/* remove stale items: alarm names for src */
QSet<QString> stale = oldset - alsrcset;
m_remove_stale_items(stale);
m_remove_stale_items(stale, src); // works on mItemHash as well as on the tree
}
......@@ -310,7 +312,7 @@ void AlarmTreeWidget::m_insert_item(const QString& src, const QStringList &list,
item->setNew(isNew);
}
/* add the couple identifier/AlarmTreeWidgetItem to the hash */
mItemHash.insert(fields.at(AlarmTreeWidgetItem::Alarm), item);
mItemHash.insert(m_make_key(fields.at(AlarmTreeWidgetItem::Alarm), src), item);
}
QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const {
......@@ -323,12 +325,21 @@ QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const {
return l.join("\t");
}
AlarmTreeWidgetItem *AlarmTreeWidget::m_findItem(const QString &alarm, const QString &src) const {
return mItemHash.value(m_make_key(alarm, src));
}
QString AlarmTreeWidget::m_make_key(const QString &alarm, const QString &src) const {
return QString("%1/%2").arg(src).arg(alarm);
}
void AlarmTreeWidget::m_remove_stale_items(const QSet<QString> stale_names) {
void AlarmTreeWidget::m_remove_stale_items(const QSet<QString> stale_names, const QString& src) {
foreach(const QString& name, stale_names) {
AlarmTreeWidgetItem *item = mItemHash.value(name);
const QString& key = m_make_key(name, src);
AlarmTreeWidgetItem *item = mItemHash.value(key);
if(item) {
mItemHash.remove(name);
mItemHash.remove(key);
delete item;
}
}
......
......@@ -47,14 +47,16 @@ protected:
private:
int m_pri_to_int(const QString& pri) const;
int m_status_to_int(const QString& stat);
void m_remove_stale_items(const QSet<QString> stale_names);
void m_remove_stale_items(const QSet<QString> stale_names, const QString& src);
void m_insert_item(const QString &src, const QStringList &list, int index);
QString m_gen_error_item(const CuData& da) const;
AlarmTreeWidgetItem *m_findItem(const QString& alarm, const QString& handler) const;
bool _filter_enabled;
QHash<QString, AlarmTreeWidgetItem*> mItemHash;
QHash<QString, QSet<QString> >mSrcAlarmHash;
QSet<QString> m_src_err;
QString m_make_key(const QString& alarm, const QString& handler) const;
Type m_type;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment