Commit 5c5b7dda authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

added filtering options in historical view

parent 76041d45
......@@ -41,46 +41,16 @@ void AlarmHistoryTree::applyFilter(AlarmFilter f)
int colCount = m_sql_model->columnCount();
QModelIndex root = rootIndex();
for(i = 0; i < rowCount; i++)
{
for(i = 0; i < rowCount; i++) {
rowEls.clear();
for(j = 0; j < colCount; j++)
rowEls << m_sql_model->data(m_sql_model->index(i, j), Qt::DisplayRole);
if(f.ack_enable)
{
QString sack = f.ack ? "ACK" : "NACK";
if(rowEls.size() > ACK && rowEls[ACK] != sack)
setRowHidden(i, root, true);
}
if(f.lev)
{
/* must not have been hidden previously */
if(rowEls.size() > LEVEL && rowEls[LEVEL] != f.level && !isRowHidden(i, root))
setRowHidden(i, root, true);
}
if(f.stat)
{
if(f.stat) {
/* must not have been hidden previously */
printf("AlarmHistoryTree.applyFilter: status %s row status %s\n", qstoc(f.status), qstoc(rowEls[STATUS].toString()));
if(rowEls.size() > STATUS && rowEls[STATUS] != f.status && !isRowHidden(i, root))
setRowHidden(i, root, true);
}
if(f.grp)
{
/* must not have been hidden previously */
for(int k = 0; k < f.groups.size(); k++)
{
if(rowEls.size() > GROUP && rowEls[GROUP].canConvert(QVariant::String) && !rowEls[GROUP].toString().
contains(f.groups[k]) && !isRowHidden(i, root))
{
setRowHidden(i, root, true);
break;
}
}
}
}
}
_filter_enabled = true;
......@@ -100,8 +70,13 @@ QAbstractItemModel *AlarmHistoryTree::model() const {
return m_sql_model;
}
void AlarmHistoryTree::executeQuery(QString &q)
{
void AlarmHistoryTree::onFilterNameChanged(const QString &f) {
for(int i = 0; i < m_sql_model->rowCount(); i++) {
setRowHidden(i, QModelIndex(), !f.isEmpty() && !m_sql_model->data(m_sql_model->index(i, NAME), Qt::DisplayRole).toString().contains(f));
}
}
void AlarmHistoryTree::executeQuery(QString &q) {
if (!db.isOpen())
{
if (!db.open())
......
......@@ -15,11 +15,14 @@ class AlarmHistoryTree : public QTreeView
public:
AlarmHistoryTree(QWidget* parent);
void executeQuery(QString &q);
enum columns { DATET, MICROSEC, STATUS, ACK, NAME, LEVEL, GROUP, MSG };
enum columns { DATET, NAME, STATUS };
void applyFilter(AlarmFilter f);
void removeFilter();
QAbstractItemModel * model() const;
public slots:
void onFilterNameChanged(const QString& f);
protected:
protected slots:
......
......@@ -69,18 +69,12 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
connect(ui->treeWidgetAlarms, SIGNAL(silence()), this, SLOT(stopSound()));
/* ack. Also uses QTWriter to impart StopNew command */
connect(ui->treeWidgetAlarms, SIGNAL(ack()), this, SLOT(ack()));
connect(ui->pBApplyFilter, SIGNAL(clicked()), this, SLOT(applyFilter()));
connect(ui->pBClearFilter, SIGNAL(clicked()), this, SLOT(clearFilter()));
connect(ui->pBStopSound, SIGNAL(clicked()), this, SLOT(stopSound()));
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
/* message label */
ui->msgLabel->setVisible(false);
ui->pBClearFilter->setDisabled(true);
ui->tWGroup->sortItems(0, Qt::AscendingOrder);
ui->tWGroup->header()->setHidden(true);
ui->pBConfHistory->setHidden(true);
// device list from Tango DB free prop
......@@ -128,12 +122,8 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
ui->groupBoxFilter->setHidden(true);
connect(ui->pBFilter, SIGNAL(toggled(bool)), ui->groupBoxFilter, SLOT(setVisible(bool)));
/* connections for filter group box */
connect(ui->cBAck, SIGNAL(toggled(bool)), ui->rBAck, SLOT(setEnabled(bool)));
connect(ui->cBAck, SIGNAL(toggled(bool)), ui->rBNack, SLOT(setEnabled(bool)));
connect(ui->cBLevel, SIGNAL(toggled(bool)), ui->comboLog, SLOT(setEnabled(bool)));
connect(ui->cBStatus, SIGNAL(toggled(bool)), ui->comboStatus, SLOT(setEnabled(bool)));
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)));
......@@ -158,6 +148,9 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
ui->timeStop->setTime(QTime::currentTime());
connect(ui->pBApplyHistory, SIGNAL(clicked()), this, SLOT(queryDB()));
connect(ui->comboPeriod, SIGNAL(currentIndexChanged(int)), this, SLOT(enableFrameHistoryInterval(int)));
connect(ui->leFilterName, SIGNAL(textChanged(QString)), this, SLOT(onFilterNameChanged(QString)));
connect(ui->comboStatus, SIGNAL(currentTextChanged(QString)), this, SLOT(onFilterStatusChanged(QString)));
connect(ui->cBStatus, SIGNAL(toggled(bool)), this, SLOT(onFilterStatusEnabled(bool)));
}
Alarm::~Alarm() {
......@@ -171,8 +164,6 @@ void Alarm::refresh(const CuData &da) {
const QString& att = QuString(da, "src").section('/', -1, -1);
AlarmTreeWidget *tw = att == "alarm" ? ui->treeWidgetAlarms : ui->twDisabledAlarms;
tw->refresh(da);
if(filtering && ui->cBDynamic->isChecked())
applyFilter();
QString tn = "%1 [%2]";
if(att == "alarm") ui->tabWidget->setTabText(0, tn.arg("Alarm").arg(tw->countAlarmed()));
else ui->tabWidget->setTabText(1, tn.arg("Disabled Alarms").arg(tw->countAll()));
......@@ -190,8 +181,8 @@ void Alarm::onDevList(const CuData &da) {
void Alarm::onGroupList(const CuData &da) {
if(!da["err"].toBool() && da.containsKey("value")) {
foreach(QString g, QuStringList(da, "value"))
new QTreeWidgetItem(ui->tWGroup, QStringList() << g.remove("gr_"));
// foreach(QString g, QuStringList(da, "value"))
// new QTreeWidgetItem(ui->tWGroup, QStringList() << g.remove("gr_"));
} else
perr("Alarm.onGroupList: error fetching groups from %s: %s", vtoc2(da, "src"), vtoc2(da, "msg"));
}
......@@ -251,44 +242,6 @@ void Alarm::ackAll() {
acmd.ack(ui->treeWidgetAlarms, true, cu_pool, m_ctrl_factory_pool);
}
void Alarm::applyFilter()
{
AlarmFilter filter;
filter.ack_enable = ui->cBAck->isChecked();
if(filter.ack_enable)
filter.ack = ui->rBAck->isChecked();
filter.lev = ui->cBLevel->isChecked();
if(filter.lev)
filter.level = ui->comboLog->currentText();
filter.stat = ui->cBStatus->isChecked();
if(filter.stat)
filter.status = ui->comboStatus->currentText();
filter.grp = ui->cBGroup->isChecked();
if(filter.grp)
{
QList<QTreeWidgetItem* >groups = ui->tWGroup->selectedItems();
for(int i = 0; i < groups.size(); i++)
filter.groups << groups[i]->text(0);
}
ui->treeWidgetAlarms->applyFilter(filter);
ui->twDisabledAlarms->applyFilter(filter);
filtering = true;
ui->pBClearFilter->setDisabled(false);
}
void Alarm::clearFilter() {
ui->treeWidgetAlarms->removeFilter();
ui->twDisabledAlarms->removeFilter();
ui->pBClearFilter->setDisabled(true);
ui->cBDynamic->setChecked(false);
filtering = false;
}
void Alarm::onInfoListViewVisibilityChange(bool vis) {
if(!vis)
ui->liViewInfo->activate("", "");
......@@ -315,15 +268,31 @@ void Alarm::onItemDoubleClicked(const QModelIndex &mi) {
ui->pbInfo->setChecked(true);
}
void Alarm::onFilterNameChanged(const QString &n) {
AlarmFilter f;
f.filter(ui->twHistory, "Alarm", n);
}
void Alarm::onFilterStatusChanged(const QString &s) {
AlarmFilter f;
f.filter(ui->twHistory, "Status", s);
}
void Alarm::onFilterStatusEnabled(bool en) {
onFilterStatusChanged(en ? ui->comboStatus->currentText() : "");
}
void Alarm::tabChanged(int t) {
if(t == 2)
queryDB();
ui->pBFilter->setVisible(t == 2);
ui->groupBoxFilter->setEnabled(t ==2 );
if(t == 2) {
QApplication::setOverrideCursor(Qt::WaitCursor);
QTimer::singleShot(500, this, SLOT(queryDB()));
}
if(t > 1) {
ui->pBAckAll->setHidden(true);
ui->pBConfHistory->setHidden(false);
ui->pBConfHistory->setChecked(true);
ui->groupBoxFilter->setDisabled(true);
ui->pBFilter->setHidden(true);
ui->pBConfHistory->setHidden(true);
ui->pBStopSound->setHidden(true);
}
......@@ -331,8 +300,6 @@ void Alarm::tabChanged(int t) {
ui->pBStopSound->setHidden(false);
ui->pBAckAll->setHidden(false);
ui->pBConfHistory->setHidden(true);
ui->groupBoxFilter->setDisabled(false);
ui->pBFilter->setHidden(false);
onInfoListViewVisibilityChange(ui->liViewInfo->isVisible());
}
}
......@@ -357,19 +324,21 @@ void Alarm::closeEvent(QCloseEvent *e)
void Alarm::queryDB()
{
QDateTime startSearch;
QDateTime now = QDateTime::currentDateTime();
QDateTime dts = QDateTime::currentDateTime();
QString query;
QDateTime dts, dte;
QDateTime dte(dts);
switch(ui->comboPeriod->currentIndex()) {
case 0:
startSearch = now.addDays(-1);
dts = dts.addDays(-1);
dte = dts.addDays(1); // somewhere in the future
break;
case 1:
startSearch = now.addDays(-7);
dts = dts.addDays(-7);
dte = dts.addDays(1); // somewhere in the future
break;
case 2:
startSearch = now.addMonths(-1);
dts = dts.addMonths(-1);
dte = dts.addDays(1); // somewhere in the future
break;
case 3:
dts.setDate(ui->dateStart->date());
......@@ -385,18 +354,9 @@ void Alarm::queryDB()
ored_handlers = "att_name LIKE '%" + m_handlers[0] + "' ";
for(i = 1; i < m_handlers.size(); i++)
ored_handlers += " OR att_name LIKE '%" + m_handlers[i] + "%' ";
if(startSearch.isValid()) {
if(dts.isValid() && dte.isValid() && dts < dte && ored_handlers.length() > 0) {
query = QString("SELECT asd.data_time AS 'Date/Time',ac.att_name AS 'Alarm', "
"COALESCE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(asd.value_r,'0','NORMAL'),'1','ALARM UNACK'),'2','ALARM ACKED'),'3','RETURNED NORMAL'),'4','SHELVED'),'6','DISABLED'),aed.error_desc) AS 'Status' "
"FROM att_scalar_devenum_ro asd "
"JOIN att_conf ac ON asd.att_conf_id=ac.att_conf_id "
"LEFT OUTER JOIN att_error_desc aed ON aed.att_error_desc_id=asd.att_error_desc_id "
"WHERE ac.att_name in (SELECT att_name FROM att_conf WHERE %1) "
"AND asd.data_time > '%2' ORDER BY asd.data_time DESC;").arg(ored_handlers).arg(startSearch.toString("yyyy-MM-dd hh:mm:ss.zzz"));
}
else if(dts.isValid() && dte.isValid() && dts < dte) {
query = QString("SELECT asd.data_time AS 'Date/Time',ac.att_name AS 'Alarm', "
"COALESCE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(asd.value_r,'0','NORMAL'),'1','ALARM UNACK'),'2','ALARM ACKED'),'3','RETURNED NORMAL'),'4','SHELVED'),'6','DISABLED'),aed.error_desc) as AS 'Status' "
"COALESCE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(asd.value_r,'0','NORMAL'),'1','ALARM UNACK'),'2','ALARM ACKED'),'3','RETURNED NORMAL'),'4','SHELVED'),'6','DISABLED'),aed.error_desc) AS 'Status' "
"FROM att_scalar_devenum_ro asd "
"JOIN att_conf ac ON asd.att_conf_id=ac.att_conf_id "
"LEFT OUTER JOIN att_error_desc aed ON aed.att_error_desc_id=asd.att_error_desc_id "
......@@ -405,15 +365,15 @@ void Alarm::queryDB()
}
else if(dts.isValid() && dte.isValid() && dts >= dte)
QMessageBox::information(this, "Invalid date / time range", "Stop date/time is ahead of start date/time");
else if(ored_handlers.isEmpty())
QMessageBox::information(this, "No handlers", "No alarm handlers");
if(query.length() > 0)
ui->twHistory->executeQuery(query);
printf("executing query \"%s\"\n", qstoc(query));
if(ui->cBDynamic->isChecked()) {
applyFilter();
}
QApplication::restoreOverrideCursor();
}
void Alarm::enableFrameHistoryInterval(int i) {
......
......@@ -63,8 +63,6 @@ protected slots:
void ack();
void ackAll();
void silence();
void applyFilter();
void clearFilter();
void stopSound();
void testSound();
void tabChanged(int);
......@@ -72,6 +70,9 @@ protected slots:
void onItemSelectionChange();
void onItemDoubleClicked(const QModelIndex &mi);
void onFilterNameChanged(const QString& n);
void onFilterStatusChanged(const QString& s);
void onFilterStatusEnabled(bool en);
void beep();
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>855</width>
<height>718</height>
<width>744</width>
<height>751</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -408,66 +408,7 @@
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="4" rowspan="3">
<widget class="QTreeWidget" name="tWGroup">
<property name="enabled">
<bool>false</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<property name="columnCount">
<number>1</number>
</property>
<column>
<property name="text">
<string>group</string>
</property>
</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">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Group</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QCheckBox" name="cBStatus">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
......@@ -477,7 +418,10 @@
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<item row="2" column="1">
<widget class="QLineEdit" name="leFilterName"/>
</item>
<item row="4" column="1" colspan="2">
<widget class="QComboBox" name="comboStatus">
<property name="enabled">
<bool>false</bool>
......@@ -489,96 +433,43 @@
</item>
<item>
<property name="text">
<string>ERROR</string>
<string>ALARM ACKED</string>
</property>
</item>
<item>
<property name="text">
<string>NORMAL</string>
</property>
</item>
</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>highest</string>
<string>ALARM UNACK</string>
</property>
</item>
<item>
<property name="text">
<string>high</string>
<string>DISABLED</string>
</property>
</item>
<item>
<property name="text">
<string>medium</string>
<string>RETURNED NORMAL</string>
</property>
</item>
<item>
<property name="text">
<string>low</string>
<string>ERROR</string>
</property>
</item>
<item>
<property name="text">
<string>lowest</string>
<string>NORMAL</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>Ack</string>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QCheckBox" name="cBDynamic">
<property name="text">
<string>Dynamic update</string>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QPushButton" name="pBApplyFilter">
<property name="text">
<string>Apply the Filter</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="rBAck">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>ACK</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="cBLevel">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Level</string>
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QPushButton" name="pBClearFilter">
<property name="text">
<string>Clear the Filter</string>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
......
......@@ -4,16 +4,36 @@
#include <QStringList>
#define ICON_PATH QString("/runtime/elettra/share/icons/")
#include <QAbstractItemModel>
#include <QModelIndex>
#include <QTreeView>
class QAbstractItemModel;
class AlarmFilter
{
public:
AlarmFilter() { ack_enable = ack = lev = stat = grp = false; }
bool ack_enable, ack, lev, stat, grp;
public:
AlarmFilter() { ack_enable = ack = lev = stat = grp = false; }
bool ack_enable, ack, lev, stat, grp;
QString level, status;
QStringList groups;
QString level, status;
QStringList groups;
void filter(QTreeView *m, const QString &column, const QString& f);
};
inline void AlarmFilter::filter(QTreeView *v, const QString& column, const QString& f)
{
QAbstractItemModel *m = v->model();
int c;
for(c = 0; c < m->columnCount(); c++)
if(m->headerData(c, Qt::Horizontal).toString() == column)
break;
for(int i = 0; i < m->rowCount(); i++) {
v->setRowHidden(i, QModelIndex(), !f.isEmpty() && !m->data(m->index(i, c), Qt::DisplayRole).toString().contains(f));
}
}
#endif
......
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