872 lines
25 KiB
C++
872 lines
25 KiB
C++
#include "CAlarmItemModel.h"
|
|
#include "CAlarmMsgInfo.h"
|
|
#include <QModelIndex>
|
|
#include <QHeaderView>
|
|
#include <QMutexLocker>
|
|
#include <QSortFilterProxyModel>
|
|
#include "CAlarmDataCollect.h"
|
|
#include "CAlarmMsgManage.h"
|
|
#include "perm_mng_api/PermMngApi.h"
|
|
#include <QDebug>
|
|
|
|
//< 屏蔽xml_parser编译告警
|
|
#ifdef __GNUC__
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
|
|
#endif
|
|
|
|
#include "boost/property_tree/xml_parser.hpp"
|
|
|
|
#ifdef __GNUC__
|
|
#pragma GCC diagnostic pop
|
|
#endif
|
|
|
|
#include "boost/typeof/typeof.hpp"
|
|
#include "boost/filesystem.hpp"
|
|
#include "Common.h"
|
|
#include "pub_utility_api/FileUtil.h"
|
|
#include "pub_utility_api/CharUtil.h"
|
|
#include "pub_logger_api/logger.h"
|
|
#include <QDomDocument>
|
|
#include <QFile>
|
|
#include <QToolTip>
|
|
#include "CAlarmBaseData.h"
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
using namespace iot_public;
|
|
using namespace std;
|
|
const int DOCK_ROW_COUNT = 3;
|
|
const int MAX_ROW_COUNT = 15000;
|
|
|
|
CAlarmItemModel::CAlarmItemModel(E_Alarm_Mode mode, QObject *parent)
|
|
:QAbstractTableModel(parent),
|
|
m_mode(mode),
|
|
m_order(Qt::DescendingOrder)
|
|
{
|
|
m_nTotalSize = 0;
|
|
m_alternateFlag = true;
|
|
//增加复归状态
|
|
m_header <<tr("时间") << tr("优先级") << tr("位置") << tr("责任区") << tr("告警类型") << tr("告警状态") << tr("复归状态") << tr("确认状态")<< tr("告警内容");
|
|
LOGDEBUG("构造模型 start 模型:%d",int(mode));
|
|
if(E_Alarm_Dock == m_mode)
|
|
{
|
|
connect(CAlarmDataCollect::instance(), SIGNAL(sigMsgConfirm()), this, SLOT(slotMsgConfirm()), Qt::QueuedConnection);
|
|
m_sortKey= E_SORT_PRIORITY;
|
|
}else
|
|
{
|
|
m_sortKey = E_SORT_TIME;
|
|
}
|
|
initialize();
|
|
|
|
connect(CAlarmDataCollect::instance(), SIGNAL(sigMsgRefresh()), this, SLOT(slotMsgRefresh()), Qt::QueuedConnection);
|
|
connect(CAlarmMsgManage::instance(), SIGNAL(sigMsgArrived(QList<AlarmMsgPtr>)), this, SLOT(slotMsgArrived(QList<AlarmMsgPtr>)), Qt::QueuedConnection);
|
|
connect(CAlarmDataCollect::instance(), SIGNAL(sigAlarmStateChanged(int, int)), this, SLOT(slotAlarmStateChanged(int, int)), Qt::QueuedConnection);
|
|
|
|
connect(CAlarmDataCollect::instance(),&CAlarmDataCollect::sigMsgRemove,this,&CAlarmItemModel::slotMsgRemove,Qt::QueuedConnection);
|
|
}
|
|
|
|
CAlarmItemModel::~CAlarmItemModel()
|
|
{
|
|
m_listShowAlarmInfo.clear();
|
|
}
|
|
|
|
void CAlarmItemModel::initialize()
|
|
{
|
|
m_listHorAlignmentFlags.clear();
|
|
for (int nIndex(0); nIndex < m_header.size(); nIndex++)
|
|
{
|
|
m_listHorAlignmentFlags.append(Qt::AlignHCenter);
|
|
}
|
|
initFilter();
|
|
|
|
slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::initFilter()
|
|
{
|
|
m_isLevelFilterEnable = false;
|
|
m_isLocationFilterEnable = false;
|
|
m_isRegionFilterEnable = false;
|
|
m_isStatusFilterEnable = false;
|
|
m_isDeviceTypeFileter = false;
|
|
m_isKeywordEnable = false;
|
|
m_timeFilterEnable = false;
|
|
m_confirmFilterEnable = false;
|
|
m_returnFilterEnable = false;
|
|
if(m_mode != E_Alarm_Pop)
|
|
{
|
|
removeDeviceGroupFilter();
|
|
}
|
|
}
|
|
|
|
E_Alarm_Mode CAlarmItemModel::getAlarmMode() const
|
|
{
|
|
return m_mode;
|
|
}
|
|
|
|
int CAlarmItemModel::getShowAlarmCount() const
|
|
{
|
|
return m_listShowAlarmInfo.size();
|
|
}
|
|
|
|
AlarmMsgPtr CAlarmItemModel::getAlarmInfo(const QModelIndex &index)
|
|
{
|
|
if(index.row() < m_listShowAlarmInfo.size())
|
|
{
|
|
return m_listShowAlarmInfo.at(index.row());
|
|
}
|
|
return AlarmMsgPtr(Q_NULLPTR);
|
|
}
|
|
|
|
const QList<AlarmMsgPtr> CAlarmItemModel::getListShowAlarmInfo() const
|
|
{
|
|
return m_listShowAlarmInfo;
|
|
}
|
|
|
|
void CAlarmItemModel::setColumnAlign(const int &column, const int &alignFlag)
|
|
{
|
|
Qt::AlignmentFlag flag = Qt::AlignHCenter;
|
|
if(Qt::AlignLeft == (Qt::AlignmentFlag)alignFlag || Qt::AlignRight == (Qt::AlignmentFlag)alignFlag)
|
|
{
|
|
flag = (Qt::AlignmentFlag)alignFlag;
|
|
}
|
|
m_listHorAlignmentFlags.replace(column, flag);
|
|
}
|
|
|
|
void CAlarmItemModel::insertAlarmMsg(const QList<AlarmMsgPtr> &infoList)
|
|
{
|
|
if(infoList.size() > 1000 || E_Alarm_Dock == m_mode)
|
|
{
|
|
beginResetModel();
|
|
QList<AlarmMsgPtr>::const_iterator itpos = infoList.begin();
|
|
while(itpos != infoList.end())
|
|
{
|
|
int left = calcLeft(*itpos);
|
|
m_listShowAlarmInfo.insert(left, *itpos);
|
|
itpos++;
|
|
}
|
|
endResetModel();
|
|
}else
|
|
{
|
|
QList<AlarmMsgPtr>::const_iterator itpos = infoList.begin();
|
|
while(itpos != infoList.end())
|
|
{
|
|
int left = calcLeft(*itpos);
|
|
beginInsertRows(QModelIndex(), left, left);
|
|
m_listShowAlarmInfo.insert(left, *itpos);
|
|
endInsertRows();
|
|
itpos++;
|
|
}
|
|
}
|
|
}
|
|
|
|
int CAlarmItemModel::calcLeft(const AlarmMsgPtr &info)
|
|
{
|
|
int mid = -1;
|
|
int left = 0;
|
|
int right = m_listShowAlarmInfo.size() - 1;
|
|
while(left <= right)
|
|
{
|
|
mid = (left + right) / 2;
|
|
if (Qt::AscendingOrder == m_order)
|
|
{
|
|
if(info->lessThan(m_listShowAlarmInfo[mid], m_sortKey))
|
|
{
|
|
right = mid - 1;
|
|
}
|
|
else
|
|
{
|
|
left = mid + 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(m_listShowAlarmInfo[mid]->lessThan(info, m_sortKey))
|
|
{
|
|
right = mid - 1;
|
|
}
|
|
else
|
|
{
|
|
left = mid + 1;
|
|
}
|
|
}
|
|
}
|
|
return left;
|
|
}
|
|
|
|
bool CAlarmItemModel::alternate() const
|
|
{
|
|
return m_alternateFlag;
|
|
}
|
|
|
|
int CAlarmItemModel::filterCount()
|
|
{
|
|
if (0 == m_nTotalSize)
|
|
{
|
|
return 0;
|
|
}
|
|
int nCount = m_nTotalSize - m_listShowAlarmInfo.size();
|
|
if( nCount< 0)
|
|
{
|
|
return 0;
|
|
}else
|
|
{
|
|
return nCount;
|
|
}
|
|
}
|
|
|
|
QVariant CAlarmItemModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
{
|
|
if(Qt::DisplayRole == role && Qt::Horizontal == orientation)
|
|
{
|
|
return QVariant(m_header.at(section));
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
QVariant CAlarmItemModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if(!index.isValid() || index.row() >= m_listShowAlarmInfo.count())
|
|
{
|
|
return QVariant();
|
|
}
|
|
|
|
if(Qt::TextAlignmentRole == role)
|
|
{
|
|
if(index.column() == (int)CONTENT)
|
|
{
|
|
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
|
|
}else
|
|
{
|
|
return QVariant(m_listHorAlignmentFlags.at(index.column()) | Qt::AlignVCenter);
|
|
}
|
|
|
|
}
|
|
else if(Qt::DisplayRole == role)
|
|
{
|
|
switch ( index.column() )
|
|
{
|
|
case TIME :
|
|
{
|
|
return QDateTime::fromMSecsSinceEpoch(m_listShowAlarmInfo.at(index.row())->time_stamp).toString("yyyy-MM-dd hh:mm:ss.zzz");
|
|
}
|
|
case PRIORITY :
|
|
{
|
|
return CAlarmBaseData::instance()->queryPriorityDesc(m_listShowAlarmInfo.at(index.row())->priority);
|
|
}
|
|
case LOCATION :
|
|
{
|
|
return CAlarmBaseData::instance()->queryLocationDesc(m_listShowAlarmInfo.at(index.row())->location_id);
|
|
}
|
|
case REGION :
|
|
{
|
|
return CAlarmBaseData::instance()->queryRegionDesc(m_listShowAlarmInfo.at(index.row())->region_id);
|
|
}
|
|
case TYPE :
|
|
{
|
|
return CAlarmBaseData::instance()->queryAlarmTypeDesc(m_listShowAlarmInfo.at(index.row())->alm_type);
|
|
}
|
|
case STATUS :
|
|
{
|
|
return CAlarmBaseData::instance()->queryAlarmStatusDesc(m_listShowAlarmInfo.at(index.row())->alm_status);
|
|
}
|
|
case RETURNSTATUS:
|
|
{
|
|
if(E_ALS_ALARM == m_listShowAlarmInfo.at(index.row())->logic_state || E_ALS_ALARM_CFM == m_listShowAlarmInfo.at(index.row())->logic_state ||
|
|
E_ALS_ALARM_DEL == m_listShowAlarmInfo.at(index.row())->logic_state || E_ALS_ALARM_CFM_DEL == m_listShowAlarmInfo.at(index.row())->logic_state) //未复归
|
|
{
|
|
return tr("未复归");
|
|
}
|
|
else if(E_ALS_RETURN == m_listShowAlarmInfo.at(index.row())->logic_state || E_ALS_RETURN_CFM == m_listShowAlarmInfo.at(index.row())->logic_state ||
|
|
E_ALS_RETURN_DEL == m_listShowAlarmInfo.at(index.row())->logic_state || E_ALS_RETURN_CFM_DEL == m_listShowAlarmInfo.at(index.row())->logic_state)
|
|
{
|
|
return tr("已复归");
|
|
}else
|
|
{
|
|
return tr("-");
|
|
}
|
|
}
|
|
case CONFIRM :
|
|
{
|
|
if(E_ALS_ALARM == m_listShowAlarmInfo.at(index.row())->logic_state || E_ALS_RETURN == m_listShowAlarmInfo.at(index.row())->logic_state ||
|
|
E_ALS_ALARM_DEL == m_listShowAlarmInfo.at(index.row())->logic_state || E_ALS_RETURN_DEL == m_listShowAlarmInfo.at(index.row())->logic_state) //< 未确认
|
|
{
|
|
return tr("未确认");
|
|
}
|
|
else if(E_ALS_ALARM_CFM == m_listShowAlarmInfo.at(index.row())->logic_state || E_ALS_RETURN_CFM == m_listShowAlarmInfo.at(index.row())->logic_state ||
|
|
E_ALS_ALARM_CFM_DEL == m_listShowAlarmInfo.at(index.row())->logic_state || E_ALS_RETURN_CFM_DEL == m_listShowAlarmInfo.at(index.row())->logic_state ||
|
|
ALS_EVT_ONLY == m_listShowAlarmInfo.at(index.row())->logic_state) //< 已确认
|
|
{
|
|
return tr("已确认");
|
|
}
|
|
}
|
|
case CONTENT :
|
|
{
|
|
return m_listShowAlarmInfo.at(index.row())->content;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
else if(Qt::ToolTipRole == role)
|
|
{
|
|
if(index.column() == (int)CONTENT && !QToolTip::isVisible())
|
|
{
|
|
QString tip = m_listShowAlarmInfo.at(index.row())->content;
|
|
|
|
return tip;
|
|
}
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
int CAlarmItemModel::columnCount(const QModelIndex &index) const
|
|
{
|
|
if (index.isValid())
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return m_header.count();
|
|
}
|
|
|
|
int CAlarmItemModel::rowCount(const QModelIndex &index) const
|
|
{
|
|
if (index.isValid())
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
if(E_Alarm_Dock == m_mode)
|
|
{
|
|
return DOCK_ROW_COUNT;
|
|
}
|
|
else
|
|
{
|
|
return m_listShowAlarmInfo.count();
|
|
}
|
|
}
|
|
|
|
Qt::ItemFlags CAlarmItemModel::flags(const QModelIndex &index) const
|
|
{
|
|
if (!index.isValid())
|
|
{
|
|
return Qt::NoItemFlags;
|
|
}
|
|
|
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
}
|
|
|
|
void CAlarmItemModel::sortColumn(int column, Qt::SortOrder order)
|
|
{
|
|
if(order == Qt::AscendingOrder)
|
|
{
|
|
m_order = Qt::AscendingOrder;
|
|
}
|
|
else
|
|
{
|
|
m_order = Qt::DescendingOrder;
|
|
}
|
|
m_sortKey = (E_ALARM_SORTKEY)column;
|
|
beginResetModel();
|
|
sort();
|
|
endResetModel();
|
|
}
|
|
|
|
//<归并排序
|
|
void CAlarmItemModel::sort()
|
|
{
|
|
QMap<int, PAIRLISTALARMINFO> mapAlarmInfo;
|
|
//<分
|
|
for(int nIndex(0); nIndex < m_listShowAlarmInfo.count(); nIndex++)
|
|
{
|
|
AlarmMsgPtr temp = m_listShowAlarmInfo.at(nIndex);
|
|
mapAlarmInfo[nIndex / 1000].second.append(temp);
|
|
}
|
|
|
|
//<快速排序
|
|
for(int nMapIndex(0); nMapIndex < mapAlarmInfo.count(); nMapIndex++)
|
|
{
|
|
qucikSort(mapAlarmInfo[nMapIndex].second, 0, mapAlarmInfo[nMapIndex].second.count() - 1);
|
|
}
|
|
|
|
PAIRLISTALARMINFO tempListAlarmInfo = mapAlarmInfo[0];
|
|
for(int nPairIndex(1); nPairIndex < mapAlarmInfo.count(); nPairIndex++)
|
|
{
|
|
//<归并
|
|
tempListAlarmInfo.first = 0;
|
|
mapAlarmInfo[nPairIndex].first = 0;
|
|
while(mapAlarmInfo[nPairIndex].first < mapAlarmInfo[nPairIndex].second.count())
|
|
{
|
|
if(tempListAlarmInfo.first >= tempListAlarmInfo.second.count())
|
|
{
|
|
tempListAlarmInfo.second.append(mapAlarmInfo[nPairIndex].second.at(mapAlarmInfo[nPairIndex].first));
|
|
mapAlarmInfo[nPairIndex].first += 1;
|
|
}
|
|
else
|
|
{
|
|
if(Qt::AscendingOrder == m_order)
|
|
{
|
|
if(!tempListAlarmInfo.second[tempListAlarmInfo.first]->lessThan(mapAlarmInfo[nPairIndex].second.at(mapAlarmInfo[nPairIndex].first), m_sortKey))
|
|
{
|
|
tempListAlarmInfo.second.insert(tempListAlarmInfo.first, mapAlarmInfo[nPairIndex].second.at(mapAlarmInfo[nPairIndex].first));
|
|
mapAlarmInfo[nPairIndex].first += 1;
|
|
}
|
|
}
|
|
else if(Qt::DescendingOrder == m_order)
|
|
{
|
|
if(!tempListAlarmInfo.second[tempListAlarmInfo.first]->moreThan(mapAlarmInfo[nPairIndex].second.at(mapAlarmInfo[nPairIndex].first), m_sortKey))
|
|
{
|
|
tempListAlarmInfo.second.insert(tempListAlarmInfo.first, mapAlarmInfo[nPairIndex].second.at(mapAlarmInfo[nPairIndex].first));
|
|
mapAlarmInfo[nPairIndex].first += 1;
|
|
}
|
|
}
|
|
}
|
|
tempListAlarmInfo.first += 1;
|
|
}
|
|
}
|
|
m_listShowAlarmInfo = tempListAlarmInfo.second;
|
|
}
|
|
|
|
|
|
void CAlarmItemModel::qucikSort(QList<AlarmMsgPtr> &list, int start, int last)
|
|
{
|
|
int index;
|
|
while(start < last)
|
|
{
|
|
if(Qt::AscendingOrder == m_order)
|
|
{
|
|
index = partitionAscendingOrder(list, start, last);
|
|
}
|
|
else if(Qt::DescendingOrder == m_order)
|
|
{
|
|
index = partitionDescendingOrder(list, start, last);
|
|
}
|
|
qucikSort(list, start, index - 1);
|
|
start=index+1; //<尾优化
|
|
}
|
|
}
|
|
|
|
int CAlarmItemModel::partitionAscendingOrder(QList<AlarmMsgPtr> &list, int start, int last)
|
|
{
|
|
AlarmMsgPtr info = list[start];
|
|
int left = start;
|
|
int right = last;
|
|
while(left < right)
|
|
{
|
|
while(left < right && !list[right]->lessThan(info, m_sortKey))
|
|
{
|
|
--right;
|
|
}
|
|
list[left] = list[right];
|
|
|
|
while(left<right && list[left]->lessThan(info, m_sortKey))
|
|
{
|
|
++left;
|
|
}
|
|
list[right] = list[left];
|
|
}
|
|
list[left] = info;
|
|
return left;
|
|
}
|
|
|
|
int CAlarmItemModel::partitionDescendingOrder(QList<AlarmMsgPtr> &list, int start, int last)
|
|
{
|
|
AlarmMsgPtr info = list[start];
|
|
int left = start;
|
|
int right = last;
|
|
while(left < right)
|
|
{
|
|
while(left < right && !list[right]->moreThan(info, m_sortKey))
|
|
{
|
|
--right;
|
|
}
|
|
list[left] = list[right];
|
|
|
|
while(left<right && list[left]->moreThan(info, m_sortKey))
|
|
{
|
|
++left;
|
|
}
|
|
list[right] = list[left];
|
|
}
|
|
list[left] = info;
|
|
return left;
|
|
}
|
|
|
|
void CAlarmItemModel::setPriorityFilter(bool &isCheck, QList<int> &priorityFilter)
|
|
{
|
|
m_isLevelFilterEnable = isCheck;
|
|
m_levelFilter = priorityFilter;
|
|
slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::setLocationFilter(bool &isCheck, QList<int> &locationFilter)
|
|
{
|
|
m_isLocationFilterEnable = isCheck;
|
|
m_locationFilter = locationFilter;
|
|
slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::setAlarmTypeFilter(bool &isCheck, QList<int> &alarmTypeFilter,bool &other)
|
|
{
|
|
m_isStatusFilterEnable = isCheck;
|
|
m_statusFilter2 = alarmTypeFilter;
|
|
m_statusFilter = alarmTypeFilter;
|
|
if(other == true)
|
|
{
|
|
QMap<int, QString> otherStatusMap = CAlarmBaseData::instance()->getAlarmOtherStatus();
|
|
QMap<int, QString>::iterator it = otherStatusMap.begin();
|
|
for(;it != otherStatusMap.end(); ++it)
|
|
{
|
|
m_statusFilter.append(it.key());
|
|
}
|
|
}
|
|
slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::setAlarmTimeFilter(bool &isCheck, QDate &startTime, QDate &endTime)
|
|
{
|
|
m_timeFilterEnable = isCheck;
|
|
if(isCheck)
|
|
{
|
|
QTime time_1(0,0,0,0);
|
|
QTime time_2(23,59,59,999);
|
|
m_startTime.setDate(startTime);
|
|
m_startTime.setTime(time_1);
|
|
m_endTime.setDate(endTime);
|
|
m_endTime.setTime(time_2);
|
|
}
|
|
slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::setAlarmTimeFilter(bool &isCheck)
|
|
{
|
|
m_timeFilterEnable = isCheck;
|
|
slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::setFilter(const bool &isLevelFilterEnable, const QList<int> &levelFilter,
|
|
const bool &isStationFilterEnable, const QList<int> &stationFilter,
|
|
const bool &isRegionFilterEnable, const QList<int> ®ionFilter,
|
|
const bool &isStatusFilterEnable, const QList<int> &statusFilter,
|
|
const bool &isDeviceTypeFilter, const QString &subSystem, const QString &deviceType,
|
|
const bool &isKeywordFilterEnable, const QString &keyword,
|
|
const bool &timeFilterEnable, const QDateTime &startTime, const QDateTime &endTime,
|
|
const bool &confirmFilterEnable, const bool &isConfirm,
|
|
const bool &returnFilterEnable, const bool &isReturn)
|
|
{
|
|
m_isLevelFilterEnable = isLevelFilterEnable;
|
|
m_levelFilter = levelFilter;
|
|
m_isLocationFilterEnable = isStationFilterEnable;
|
|
m_locationFilter = stationFilter;
|
|
m_isRegionFilterEnable = isRegionFilterEnable;
|
|
m_regionFilter = regionFilter;
|
|
m_isStatusFilterEnable = isStatusFilterEnable;
|
|
m_statusFilter2 = statusFilter;
|
|
m_statusFilter = statusFilter;
|
|
if(statusFilter.contains(OTHERSTATUS))
|
|
{
|
|
QMap<int, QString> otherStatusMap = CAlarmBaseData::instance()->getAlarmOtherStatus();
|
|
QMap<int, QString>::iterator it = otherStatusMap.begin();
|
|
for(;it != otherStatusMap.end(); ++it)
|
|
{
|
|
m_statusFilter.append(it.key());
|
|
}
|
|
}
|
|
m_isDeviceTypeFileter = isDeviceTypeFilter;
|
|
m_subSystem = subSystem;
|
|
m_deviceType = deviceType;
|
|
m_isKeywordEnable = isKeywordFilterEnable;
|
|
m_keyowrd = keyword;
|
|
m_timeFilterEnable = timeFilterEnable;
|
|
m_startTime = startTime;
|
|
m_endTime = endTime;
|
|
m_confirmFilterEnable = confirmFilterEnable;
|
|
m_returnFilterEnable = returnFilterEnable;
|
|
m_isConfirm = isConfirm;
|
|
m_isReturn = isReturn;
|
|
|
|
slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::getFilter(bool &isLevelFilterEnable, QList<int> &levelFilter,
|
|
bool &isLocationFilterEnable, QList<int> &locationFilter,
|
|
bool &isRegionFilterEnable, QList<int> ®ionFilter,
|
|
bool &isStatusFilterEnable, QList<int> &alarmStatusFilter,
|
|
bool &deviceTypeFilter, QString &subSystem, QString &deviceType,
|
|
bool &keywordFilterEnable, QString &keyword,
|
|
bool &timeFilterEnable, QDateTime &startTime, QDateTime &endTime,
|
|
bool &confirmFilterEnable, bool &isConfirm,
|
|
bool &returnFilterEnable, bool &isReturn)
|
|
{
|
|
isLevelFilterEnable = m_isLevelFilterEnable;
|
|
levelFilter = m_levelFilter;
|
|
isLocationFilterEnable = m_isLocationFilterEnable;
|
|
locationFilter = m_locationFilter;
|
|
isRegionFilterEnable = m_isRegionFilterEnable;
|
|
regionFilter = m_regionFilter;
|
|
isStatusFilterEnable = m_isStatusFilterEnable;
|
|
alarmStatusFilter = m_statusFilter2;
|
|
subSystem = m_subSystem;
|
|
deviceTypeFilter = m_isDeviceTypeFileter;
|
|
deviceType = m_deviceType;
|
|
keywordFilterEnable = m_isKeywordEnable;
|
|
keyword = m_keyowrd;
|
|
timeFilterEnable = m_timeFilterEnable;
|
|
startTime = m_startTime;
|
|
endTime = m_endTime;
|
|
confirmFilterEnable = m_confirmFilterEnable;
|
|
isConfirm = m_isConfirm;
|
|
returnFilterEnable = m_returnFilterEnable;
|
|
isReturn = m_isReturn;
|
|
}
|
|
|
|
void CAlarmItemModel::addDeviceFilter(const QString &device)
|
|
{
|
|
m_deviceFilter.insert(device);
|
|
//slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::removeDeviceFilter(const QString &device)
|
|
{
|
|
m_deviceFilter.remove(device);
|
|
//slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::addPointTagFilter(const QList<QString> &pointList)
|
|
{
|
|
for(int i =0;i<pointList.size();i++)
|
|
{
|
|
m_pointFilter.insert(pointList.at(i));
|
|
}
|
|
//slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::addDeviceGroupFilter()
|
|
{
|
|
for(QString group : CAlarmBaseData::instance()->getDevGroupTagList())
|
|
{
|
|
m_deviceGroupFilter.insert(group);
|
|
}
|
|
slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::removeDeviceGroupFilter()
|
|
{
|
|
m_deviceGroupFilter.clear();
|
|
}
|
|
|
|
void CAlarmItemModel::addDeviceGroupFilter(const QString &device)
|
|
{
|
|
QString deviceG = device;
|
|
QStringList devGList = deviceG.split(",");
|
|
foreach (QString devG, devGList) {
|
|
m_deviceGroupFilter.insert(devG);
|
|
}
|
|
slotMsgRefresh();
|
|
}
|
|
|
|
void CAlarmItemModel::removeDeviceGroupFilter(const QString &device)
|
|
{
|
|
m_deviceGroupFilter.remove(device);
|
|
slotMsgRefresh();
|
|
}
|
|
|
|
bool CAlarmItemModel::conditionFilter(const AlarmMsgPtr &info)
|
|
{
|
|
//===========================错误优先级、车站、责任区、告警类型将显示==============================//
|
|
//< 等级
|
|
if(m_isLevelFilterEnable && !m_levelFilter.contains(info->priority))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//< 车站
|
|
if(m_isLocationFilterEnable && !m_locationFilter.contains(info->location_id))
|
|
{
|
|
return false;
|
|
}
|
|
//< 责任区
|
|
if(m_isRegionFilterEnable && !m_regionFilter.contains(info->region_id))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//< 类型
|
|
if(m_isStatusFilterEnable && !m_statusFilter.contains(info->alm_status))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//< 设备类型
|
|
if(m_isDeviceTypeFileter)
|
|
{
|
|
if(CAlarmBaseData::instance()->queryDevTypeByDesc(m_deviceType) != info->dev_type)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
//< 点-设备或设备组
|
|
if(E_Alarm_Pop == m_mode)
|
|
{
|
|
//点标签过滤
|
|
if(info->device.isEmpty() || !m_deviceGroupFilter.contains(info->dev_group_tag))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else if(m_deviceGroupFilter.contains(info->dev_group_tag))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
|
|
//< 关键字
|
|
if(m_isKeywordEnable && !info->content.contains(m_keyowrd))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//< 时间
|
|
if(m_timeFilterEnable)
|
|
{
|
|
if(m_startTime.toMSecsSinceEpoch() > (qint64)(info->time_stamp))
|
|
{
|
|
return false;
|
|
}
|
|
if(m_endTime.toMSecsSinceEpoch() < (qint64)(info->time_stamp))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
//< 是否已确认
|
|
if(m_confirmFilterEnable)
|
|
{
|
|
if(m_isConfirm)
|
|
{
|
|
if(info->logic_state == E_ALS_ALARM || info->logic_state == E_ALS_RETURN)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(info->logic_state == E_ALS_ALARM_CFM || info->logic_state == E_ALS_RETURN_CFM)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
if(m_returnFilterEnable)
|
|
{
|
|
if(m_isReturn)
|
|
{
|
|
if(info->logic_state == E_ALS_ALARM || info->logic_state == E_ALS_ALARM_CFM || info->logic_state == ALS_EVT_ONLY)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(info->logic_state == E_ALS_RETURN || info->logic_state == E_ALS_RETURN_CFM || info->logic_state == ALS_EVT_ONLY)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void CAlarmItemModel::updateAlternate()
|
|
{
|
|
m_alternateFlag = !m_alternateFlag;
|
|
}
|
|
|
|
|
|
void CAlarmItemModel::slotMsgRefresh()
|
|
{
|
|
beginResetModel();
|
|
m_listShowAlarmInfo.clear();
|
|
QList<AlarmMsgPtr> listAlarmInfo = CAlarmMsgManage::instance()->getListAlarmInfo();
|
|
foreach (AlarmMsgPtr info, listAlarmInfo)
|
|
{
|
|
if(conditionFilter(info))
|
|
{
|
|
m_listShowAlarmInfo.append(info);
|
|
}
|
|
}
|
|
sort();
|
|
endResetModel();
|
|
slotMsgConfirm();
|
|
}
|
|
|
|
void CAlarmItemModel::slotMsgArrived(QList<AlarmMsgPtr> listMsg)
|
|
{
|
|
//处理新告警消息
|
|
QList<AlarmMsgPtr>::const_iterator it = listMsg.constBegin();
|
|
QList<AlarmMsgPtr> addMsgList;
|
|
while (it != listMsg.constEnd())
|
|
{
|
|
if(conditionFilter(*it))
|
|
{
|
|
addMsgList.append(*it);
|
|
}
|
|
++it;
|
|
}
|
|
insertAlarmMsg(addMsgList);
|
|
}
|
|
|
|
void CAlarmItemModel::slotMsgConfirm()
|
|
{
|
|
if(E_Alarm_Dock == m_mode)
|
|
{
|
|
beginResetModel();
|
|
for(int nIndex = m_listShowAlarmInfo.size() - 1; nIndex >= 0; --nIndex)
|
|
{
|
|
E_ALARM_LOGICSTATE state = m_listShowAlarmInfo.at(nIndex)->logic_state;
|
|
if(state == E_ALS_ALARM_CFM || state == E_ALS_RETURN_CFM)
|
|
{
|
|
m_listShowAlarmInfo.removeAt(nIndex);
|
|
}
|
|
}
|
|
endResetModel();
|
|
}
|
|
}
|
|
|
|
void CAlarmItemModel::slotMsgRemove(int removeNum)
|
|
{
|
|
if(removeNum >1000 || E_Alarm_Dock == m_mode)
|
|
{
|
|
beginResetModel();
|
|
for(int nIndex = m_listShowAlarmInfo.size() - 1; nIndex >= 0; --nIndex)
|
|
{
|
|
if(m_listShowAlarmInfo.at(nIndex)->deleteFlag)
|
|
{
|
|
m_listShowAlarmInfo.removeAt(nIndex);
|
|
}
|
|
}
|
|
endResetModel();
|
|
}else
|
|
{
|
|
for(int nIndex = m_listShowAlarmInfo.size() - 1; nIndex >= 0; --nIndex)
|
|
{
|
|
if(m_listShowAlarmInfo.at(nIndex)->deleteFlag)
|
|
{
|
|
beginRemoveRows(QModelIndex(), nIndex, nIndex);
|
|
m_listShowAlarmInfo.removeAt(nIndex);
|
|
endRemoveRows();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CAlarmItemModel::slotAlarmStateChanged(int total, int unConfirm)
|
|
{
|
|
Q_UNUSED(unConfirm)
|
|
m_nTotalSize = total;
|
|
}
|