Commit 56f5cd79 authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

introduced historical view

parent 2e10210a
......@@ -25,9 +25,9 @@ AlarmHistoryTree::AlarmHistoryTree(QWidget *parent) : QTreeView(parent)
QString sqlErr = db.lastError().text();
QMessageBox::critical(0, "Error", QString("Can't establish connection with db \"alarm\" on host log:\n%1").arg(sqlErr));
}
model = new MySqlModel();
model->setHeaderData(0, Qt::Horizontal, "Timestamp");
setModel(model);
m_sql_model = new MySqlModel();
m_sql_model->setHeaderData(0, Qt::Horizontal, "Timestamp");
setModel(m_sql_model);
}
void AlarmHistoryTree::applyFilter(AlarmFilter f)
......@@ -37,15 +37,15 @@ void AlarmHistoryTree::applyFilter(AlarmFilter f)
if(_filter_enabled)
removeFilter();
int rowCount = model->rowCount();
int colCount = model->columnCount();
int rowCount = m_sql_model->rowCount();
int colCount = m_sql_model->columnCount();
QModelIndex root = rootIndex();
for(i = 0; i < rowCount; i++)
{
rowEls.clear();
for(j = 0; j < colCount; j++)
rowEls << model->data(model->index(i, j), Qt::DisplayRole);
rowEls << m_sql_model->data(m_sql_model->index(i, j), Qt::DisplayRole);
if(f.ack_enable)
{
......@@ -89,13 +89,17 @@ void AlarmHistoryTree::applyFilter(AlarmFilter f)
void AlarmHistoryTree::removeFilter() {
int i;
QModelIndex root = rootIndex();
for(i = 0; i < model->rowCount(); i++) {
for(i = 0; i < m_sql_model->rowCount(); i++) {
if(isRowHidden(i, root))
setRowHidden(i, root, false);
}
_filter_enabled = false;
}
QAbstractItemModel *AlarmHistoryTree::model() const {
return m_sql_model;
}
void AlarmHistoryTree::executeQuery(QString &q)
{
if (!db.isOpen())
......@@ -106,8 +110,8 @@ void AlarmHistoryTree::executeQuery(QString &q)
return;
}
}
model->setQuery(q);
QSqlError error = model->lastError();
m_sql_model->setQuery(q);
QSqlError error = m_sql_model->lastError();
if (error.type() != QSqlError::NoError)
{
QMessageBox::critical(0, "Database Error", QString("Error reading from Db:\n") + error.text() + "\nreconnecting");
......
......@@ -18,6 +18,7 @@ class AlarmHistoryTree : public QTreeView
enum columns { DATET, MICROSEC, STATUS, ACK, NAME, LEVEL, GROUP, MSG };
void applyFilter(AlarmFilter f);
void removeFilter();
QAbstractItemModel * model() const;
protected:
......@@ -25,7 +26,7 @@ class AlarmHistoryTree : public QTreeView
//void updateView(QString &);
private:
QSqlDatabase db;
MySqlModel *model;
MySqlModel *m_sql_model;
bool _filter_enabled;
};
......
......@@ -28,6 +28,7 @@
#include <QCloseEvent>
#include "AlarmHistoryTree.h"
#include <QDebug>
#include <QAbstractItemModel>
#include <QDesktopServices> // open url
// cumbia
......@@ -182,8 +183,8 @@ void Alarm::onDevList(const CuData &da) {
perr("Alarm.onDevList: error fetching device list from database: src: \"%s\" msg: \"%s\"", vtoc2(da, "src"), vtoc2(da, "msg"));
}
else {
QuStringList devs(da, "value");
m_connect_devs(devs);
m_handlers = QuStringList(da, "value");
m_connect_devs(m_handlers);
}
}
......@@ -311,12 +312,11 @@ void Alarm::onItemSelectionChange() {
}
void Alarm::onItemDoubleClicked(const QModelIndex &mi) {
// if(mi.column() == AlarmTreeWidgetItem::Alarm)
ui->pbInfo->setChecked(true);
}
void Alarm::tabChanged(int t) {
if(t == 2)
if(t == 2 && ui->twHistory->model()->rowCount() == 0)
queryDB();
if(t > 1) {
ui->pBAckAll->setHidden(true);
......@@ -379,14 +379,20 @@ void Alarm::queryDB()
break;
}
QString ored_handlers;
int i = 0;
if(m_handlers.size() > 0)
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()) {
query = QString("SELECT asd.data_time,ac.att_name, "
"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 value_r "
"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 att_name LIKE '%alarm/test/0/%' OR att_name LIKE '%alarm/fermi/test/%') "
"AND asd.data_time > '%1' ORDER BY asd.data_time DESC;").arg(startSearch.toString("yyyy-MM-dd hh:mm:ss.zzz"));
"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,ac.att_name, "
......@@ -394,8 +400,8 @@ void Alarm::queryDB()
"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 att_name LIKE '%alarm/test/0/%' OR att_name LIKE '%alarm/fermi/test/%') "
"AND asd.data_time > '%1' AND asd.data_time < '%2' ORDER BY asd.data_time DESC;").arg(dts.toString("yyyy-MM-dd hh:mm:ss.zzz")).arg(dte.toString("yyyy-MM-dd hh:mm:ss.zzz"));
"WHERE ac.att_name in (SELECT att_name FROM att_conf WHERE %1) "
"AND asd.data_time > '%2' AND asd.data_time < '%3' ORDER BY asd.data_time DESC;").arg(ored_handlers).arg(dts.toString("yyyy-MM-dd hh:mm:ss.zzz")).arg(dte.toString("yyyy-MM-dd hh:mm:ss.zzz"));
}
else if(dts.isValid() && dte.isValid() && dts >= dte)
QMessageBox::information(this, "Invalid date / time range", "Stop date/time is ahead of start date/time");
......
......@@ -96,6 +96,7 @@ private:
CumbiaPool *cu_pool;
QuLogImpl m_log_impl;
CuControlsFactoryPool m_ctrl_factory_pool;
QStringList m_handlers;
// cumbia
};
......
......@@ -87,7 +87,7 @@
<string>Configure History Parameters</string>
</property>
<property name="checkable">
<bool>true</bool>
<bool>false</bool>
</property>
<layout class="QGridLayout" name="_2">
<property name="leftMargin">
......@@ -236,7 +236,7 @@
<item row="1" column="3">
<widget class="QPushButton" name="pBApplyHistory">
<property name="text">
<string>Apply</string>
<string>Update</string>
</property>
</widget>
</item>
......
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