Commit a27c9029 authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files
parent a4088b9d
......@@ -20,7 +20,6 @@ lessThan(QT_MAJOR_VERSION, 5) {
QT += phonon
}
DEFINES += QT_NO_DEBUG_OUTPUT
RESOURCES += alarm.qrc
INCLUDEPATH += src
......
......@@ -147,6 +147,8 @@ void AlarmTreeWidget::refresh(const CuData &v) {
double d = static_cast<int>(v["timestamp_us"].toDouble());
QString ts = QDateTime::fromSecsSinceEpoch(d).toString("HH:mm:ss");
ts += QString("+%1").arg(d - static_cast<int>(d));
// if a src in error is back online we must remove the item from the view
QString src_fixed;
QString src = QuString(v, "src");
QString dev = src.section('/', 0, src.count('/') - 1);
bool err = v["err"].toBool();
......@@ -154,20 +156,20 @@ void AlarmTreeWidget::refresh(const CuData &v) {
setToolTip(QuString(v, "msg"));
/* remove the filter */
if (err) {
src = dev;
data << m_gen_error_item(v);
perr("%s: %s\n", qstoc(src), qstoc(toolTip()));
m_dev_err.insert(dev);
printf("\e[1;31mAlarmTreeWidget::refresh: src \e[1;33m%s\e[1;31m is in ERRROR\e[0m\n", qstoc(src));
m_src_err.insert(src);
}
else {
m_dev_err.remove(dev);
if(m_src_err.contains(src)) {
m_src_err.remove(src);
src_fixed = src;
}
data = QuStringList(v, "value");
}
int scrollBarPos;
QStringList fields;
QStringList alrnames;
AlarmTreeWidgetItem* item = NULL;
QStringList high, medium, low, lowest, unknown_level;
// group by level in order to sort view
......@@ -187,17 +189,17 @@ void AlarmTreeWidget::refresh(const CuData &v) {
data = unknown_level + lowest + low + medium + high;
int index = 0;
const QSet<QString> oldset = mSrcAlarmHash.value(src);
QSet<QString> oldset = mSrcAlarmHash.value(src);
QSet<QString>& alsrcset = mSrcAlarmHash[src];
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");
alrnames << fields.at(AlarmTreeWidgetItem::Alarm);
/* save current scroll bar value */
scrollBarPos = verticalScrollBar()->value();
/* instead of GROUP information, show DEVICE */
fields[DEVICE] = src.section('/', 0, src.count('/') - 1);
fields[DEVICE] = dev;
item = mItemHash.value(fields.at(AlarmTreeWidgetItem::Alarm));
if(!item) /* create a new item */ {
......
......@@ -54,7 +54,7 @@ private:
bool _filter_enabled;
QHash<QString, AlarmTreeWidgetItem*> mItemHash;
QHash<QString, QSet<QString> >mSrcAlarmHash;
QSet<QString> m_dev_err;
QSet<QString> m_src_err;
Type m_type;
};
......
......@@ -31,6 +31,7 @@
#include "AlarmHistoryTree.h"
#include <QDebug>
#include <QMap>
#include <QDesktopServices> // open url
// cumbia
#include <qulogimpl.h>
......@@ -85,13 +86,16 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
ui->tWGroup->header()->setHidden(true);
ui->pBConfHistory->setHidden(true);
// // device list from Tango DB free prop
// device list from Tango DB free prop
QString devlist_prop;
args.contains("--device-list-prop") && args.size() > args.indexOf("--device-list-prop") + 1
? devlist_prop = args.at(args.indexOf("--device-list-prop") + 1) : devlist_prop = "DeviceList";
QuWatcher *db_dlist_w = new QuWatcher(this, cu_pool, m_ctrl_factory_pool); // device prop watcher
db_dlist_w->setObjectName("free_prop_w");
db_dlist_w->setSingleShot(true);
db_dlist_w->setAutoDestroy(true);
connect(db_dlist_w, SIGNAL(newData(CuData)), this, SLOT(onDevList(CuData)));
db_dlist_w->setSource("tango://#AlarmHandler#DeviceList");
db_dlist_w->setSource(QString("tango://#AlarmHandler#%1").arg(devlist_prop));
//---------------------------------------------------------------------------------------
if(args.contains("--alarm-test-devname") && args.size() > args.indexOf("--alarm-test-devname") + 1) {
......@@ -127,6 +131,7 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
connect(ui->cBGroup, SIGNAL(toggled(bool)), ui->tWGroup, SLOT(setEnabled(bool)));
ui->pbInfo->setEnabled(false);
ui->liViewInfo->setVisible(false);
connect(ui->liViewInfo, SIGNAL(urlClicked(QString)), this, SLOT(openUrl(QString)));
connect(ui->pbInfo, SIGNAL(toggled(bool)), this, SLOT(onInfoListViewVisibilityChange(bool)));
connect(ui->treeWidgetAlarms, SIGNAL(itemSelectionChanged()), this, SLOT(onItemSelectionChange()));
/* connections for test section */
......@@ -192,6 +197,10 @@ void Alarm::beep() {
sound->play();
}
void Alarm::openUrl(const QString &u) const {
QDesktopServices::openUrl(QUrl(u));
}
void Alarm::stopSound() {
Acmd acmd;
acmd.stop_new(ui->treeWidgetAlarms, true, cu_pool, m_ctrl_factory_pool);
......
......@@ -72,6 +72,8 @@ protected slots:
void beep();
void openUrl(const QString& u) const;
protected:
void closeEvent(QCloseEvent *);
......
......@@ -29,11 +29,11 @@
<attribute name="title">
<string>Alarms</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<widget class="AlarmTreeWidget" name="treeWidgetAlarms">
<property name="verticalScrollBarPolicy">
......@@ -51,20 +51,7 @@
<widget class="AlarmInfoW" name="liViewInfo"/>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pbInfo">
<property name="text">
<string>Info</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<item>
<widget class="QLabel" name="msgLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
......@@ -227,20 +214,6 @@
<property name="spacing">
<number>6</number>
</property>
<item row="2" column="6">
<widget class="QPushButton" name="pBApplyFilter">
<property name="text">
<string>Apply the Filter</string>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QCheckBox" name="cBDynamic">
<property name="text">
<string>Dynamic update</string>
</property>
</widget>
</item>
<item row="1" column="5">
<spacer>
<property name="orientation">
......@@ -296,6 +269,19 @@
</column>
</widget>
</item>
<item row="0" column="2">
<widget class="QRadioButton" name="rBNack">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>NACK</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QCheckBox" name="cBGroup">
<property name="sizePolicy">
......@@ -312,16 +298,13 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QRadioButton" name="rBNack">
<property name="enabled">
<bool>false</bool>
<item row="2" column="0">
<widget class="QCheckBox" name="cBStatus">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>NACK</string>
</property>
<property name="checked">
<bool>true</bool>
<string>Status</string>
</property>
</widget>
</item>
......@@ -342,33 +325,59 @@
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cBStatus">
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="comboLog">
<property name="enabled">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>log</string>
</property>
</item>
<item>
<property name="text">
<string>warning</string>
</property>
</item>
<item>
<property name="text">
<string>fault</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="cBAck">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Status</string>
<string>Ack</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="rBAck">
<property name="enabled">
<bool>false</bool>
<item row="1" column="6">
<widget class="QCheckBox" name="cBDynamic">
<property name="text">
<string>Dynamic update</string>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QPushButton" name="pBApplyFilter">
<property name="text">
<string>ACK</string>
<string>Apply the Filter</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="cBAck">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
<item row="0" column="1">
<widget class="QRadioButton" name="rBAck">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Ack</string>
<string>ACK</string>
</property>
</widget>
</item>
......@@ -382,28 +391,6 @@
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="comboLog">
<property name="enabled">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>log</string>
</property>
</item>
<item>
<property name="text">
<string>warning</string>
</property>
</item>
<item>
<property name="text">
<string>fault</string>
</property>
</item>
</widget>
</item>
<item row="0" column="6">
<widget class="QPushButton" name="pBClearFilter">
<property name="text">
......@@ -431,6 +418,19 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pbInfo">
<property name="text">
<string>Info</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
......
......@@ -15,6 +15,9 @@ AlarmInfoW::AlarmInfoW(QWidget *parent, CumbiaPool *cu_pool, const CuControlsFac
QStandardItemModel *m = new QStandardItemModel(this);
setHeaderHidden(true);
setModel(m);
setMouseTracking(true); // for hand cursor over urls
connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(onItemClicked(QModelIndex)));
connect(this, SIGNAL(entered(QModelIndex)), this, SLOT(onItemEntered(QModelIndex)));
}
void AlarmInfoW::update(const CuData &da) {
......@@ -26,9 +29,17 @@ void AlarmInfoW::update(const CuData &da) {
if(!da["err"].toBool()) {
QuStringList l(da["value"]);
foreach(QString s, l) {
QString t = m_line_break(s.section('=', 1), 120);
// break into lines if too long
QStandardItem *si1 = new QStandardItem(s.section('=', 0, 0));
QStandardItem *si2 = new QStandardItem(s.section('=', 1));
QStandardItem *si2 = new QStandardItem(t);
si2->setToolTip(si2->text());
if(si1->text() == "url" && si2->text().length() > 0) {
si2->setForeground(QColor(Qt::blue));
QFont f = si2->font();
f.setUnderline(true);
si2->setFont(f);
}
m->appendRow(QList<QStandardItem *>() << si1 << si2);
}
}/*
......@@ -48,3 +59,28 @@ void AlarmInfoW::activate(const QString&dev, const QString& arg) {
findChild<QuWatcher *>()->setSource(QString("%1->GetAlarmInfo(%2,)").arg(dev).arg(arg));
}
}
void AlarmInfoW::onItemClicked(const QModelIndex &mi) {
QString t = mi.data().toString();
QModelIndex sibling = model()->index(mi.row(), 0);
if(sibling.data() == "url" && !t.isEmpty())
emit urlClicked(t);
}
void AlarmInfoW::onItemEntered(const QModelIndex &mi) {
QString t = mi.data().toString();
QModelIndex sibling = model()->index(mi.row(), mi.column() - 1);
setCursor(QCursor(sibling.data() == "url" ? Qt::PointingHandCursor : Qt::ArrowCursor));
}
QString AlarmInfoW::m_line_break(const QString &s, int linelen) const
{
QString s1(s);
int l = s.length();
while(l > linelen) {
s1.insert(l - linelen, "↵\n");
l -= (linelen + 2);
}
return s1;
}
......@@ -16,6 +16,16 @@ public:
public slots:
void update(const CuData& da);
void activate(const QString&dev, const QString &arg);
private slots:
void onItemClicked(const QModelIndex &mi);
void onItemEntered(const QModelIndex &mi);
signals:
void urlClicked(const QString& url);
private:
QString m_line_break(const QString& s , int linelen) const;
};
#endif // ALARMINFOW_H
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