Commit 76041d45 authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

introduced historical view

parent 56f5cd79
......@@ -316,7 +316,7 @@ void Alarm::onItemDoubleClicked(const QModelIndex &mi) {
}
void Alarm::tabChanged(int t) {
if(t == 2 && ui->twHistory->model()->rowCount() == 0)
if(t == 2)
queryDB();
if(t > 1) {
ui->pBAckAll->setHidden(true);
......@@ -386,8 +386,8 @@ void Alarm::queryDB()
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 "
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 "
......@@ -395,8 +395,8 @@ void Alarm::queryDB()
"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, "
"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 "
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' "
"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 "
......
......@@ -32,15 +32,21 @@ MySqlModel::MySqlModel(QObject *parent) : QSqlQueryModel(parent)
QVariant MySqlModel::data(const QModelIndex &index, int role) const
{
QVariant value = QSqlQueryModel::data(index, role);
// if (value.isValid() && role == Qt::DisplayRole) {
// if (index.column() == 0)
// {
// QDateTime data;
// double v = value.toDouble();
// data.setTime_t((int) v);
// data = data.addMSecs(1000 *(v - (int) v));
// return data.toString("d MMM yyyy hh:mm:ss.zzz");
// }
// }
if (value.isValid() && role == Qt::DisplayRole) {
if (index.column() == 0) {
QDateTime data = value.toDateTime();
return data.toString("yyyy-MM-dd hh:mm:ss.zzz");
}
else if(index.column() == 1) {
// remove long fully qualified name
QRegularExpression re("[tango://]*(.*):\\d+/(.*)");
QString s = value.toString();
QRegularExpressionMatch ma = re.match(s);
if(ma.capturedTexts().size() > 2) {
s = "[" + ma.capturedTexts().at(1).section('.', 0, 0) + "] " + ma.capturedTexts()[2];
return s;
}
}
}
return value;
}
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