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