409 lines
17 KiB
C++
409 lines
17 KiB
C++
#include "CAiAlarmDelegate.h"
|
|
#include <QFile>
|
|
#include "pub_utility_api/FileUtil.h"
|
|
#include "pub_utility_api/FileStyle.h"
|
|
#include "pub_logger_api/logger.h"
|
|
#include <QDomDocument>
|
|
#include <QPainter>
|
|
#include <QMouseEvent>
|
|
#include <QApplication>
|
|
#include <QProcess>
|
|
|
|
CAiAlarmDelegate::CAiAlarmDelegate(CAiAlarmTreeModel *model, QObject *parent)
|
|
: QStyledItemDelegate(parent),
|
|
m_pModel(model),
|
|
m_enableTrend(true),
|
|
m_enableLevel(false),
|
|
m_enableVideo(true),
|
|
m_enableWave(true),
|
|
m_selectIsEmpty(false)
|
|
{
|
|
slotLoadConfig();
|
|
}
|
|
|
|
void CAiAlarmDelegate::setEnableTrend(bool isNeed)
|
|
{
|
|
m_enableTrend = isNeed;
|
|
}
|
|
|
|
void CAiAlarmDelegate::setEnableLevel(bool isNeed)
|
|
{
|
|
m_enableLevel = isNeed;
|
|
}
|
|
|
|
void CAiAlarmDelegate::setEnableVideo(bool isNeed)
|
|
{
|
|
m_enableVideo = isNeed;
|
|
}
|
|
|
|
void CAiAlarmDelegate::setEnableWave(bool isNeed)
|
|
{
|
|
m_enableWave = isNeed;
|
|
}
|
|
|
|
void CAiAlarmDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
{
|
|
if(!index.isValid())
|
|
{
|
|
return;
|
|
}
|
|
CAiAlarmTreeItem *item = m_pModel->getItem(index);
|
|
|
|
bool select = option.state & QStyle::State_Selected;
|
|
QColor fillColor;
|
|
QColor penColor;
|
|
if(item->isAi())
|
|
{
|
|
AiAlarmMsgPtr aiptr = NULL;
|
|
if(item->getAiPtr(aiptr) && aiptr != NULL)
|
|
{
|
|
painter->save();
|
|
|
|
if(CAlarmMsgManage::instance()->ifhaveNotConfirmAlmByuuid(aiptr->uuid_base64)) //包含的原始告警没有全部被确认
|
|
{
|
|
if(select)
|
|
{
|
|
fillColor = m_select_background_color;
|
|
if(m_selectIsEmpty)
|
|
{
|
|
penColor = m_colorMap.value(aiptr->priorityOrder).active_text_color;
|
|
}else
|
|
{
|
|
penColor = m_select_text_color;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if(aiptr->main_state == E_ALS_RETURN || aiptr->main_state == E_ALS_RETURN_CFM
|
|
|| aiptr->main_state == E_ALS_RETURN_DEL || aiptr->main_state == E_ALS_RETURN_CFM_DEL)
|
|
{
|
|
penColor = m_colorMap.value(aiptr->priorityOrder).resume_text_color;
|
|
}else
|
|
{
|
|
penColor = m_colorMap.value(aiptr->priorityOrder).active_text_color;
|
|
}
|
|
|
|
fillColor = m_colorMap.value(aiptr->priorityOrder).background_color;
|
|
}
|
|
}else //此条智能告警可以删除(置灰)
|
|
{
|
|
if(select)
|
|
{
|
|
fillColor = m_select_background_color;
|
|
}
|
|
else
|
|
{
|
|
fillColor = m_colorMap.value(aiptr->priorityOrder).confirm_color;
|
|
}
|
|
penColor = m_colorMap.value(aiptr->priorityOrder).confirm_text_color;
|
|
}
|
|
painter->setPen(penColor);
|
|
painter->fillRect(option.rect, fillColor);
|
|
if(m_enableVideo && BUTTON_COLUMN == index.column() && aiptr->m_needVideoAlm)
|
|
{
|
|
painter->save();
|
|
QStyleOptionButton button;
|
|
button.state |= QStyle::State_Enabled;
|
|
button.rect = option.rect;
|
|
|
|
button.rect.adjust(option.rect.width() - 40, option.rect.height()/2-10, -12, -(option.rect.height()/2-10));
|
|
button.iconSize = QSize(button.rect.width()+2,button.rect.height()+2);
|
|
button.icon = QIcon(m_strVideoPath);
|
|
button.features = QStyleOptionButton::Flat;
|
|
QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter);
|
|
painter->restore();
|
|
}
|
|
|
|
if(m_enableLevel && ICON_COLUMN == index.column())
|
|
{
|
|
painter->save();
|
|
QStyleOptionButton button;
|
|
button.state |= QStyle::State_Enabled;
|
|
button.rect = option.rect;
|
|
|
|
button.rect.adjust(12, option.rect.height()/2-10, -(option.rect.width()-40), -(option.rect.height()/2-10));
|
|
QString file = m_colorMap.value(aiptr->priorityOrder).icon;
|
|
button.iconSize = QSize(button.rect.width()+2,button.rect.height()+2);
|
|
button.icon = QIcon(file);
|
|
button.features = QStyleOptionButton::Flat;
|
|
QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter);
|
|
painter->restore();
|
|
}
|
|
|
|
if( m_enableTrend && BUTTON_COLUMN == index.column() && (aiptr->m_tagname_type == E_TAGNAME_ANA || aiptr->m_tagname_type == E_TAGNAME_ACC))
|
|
{
|
|
painter->save();
|
|
QStyleOptionButton button;
|
|
button.state |= QStyle::State_Enabled;
|
|
button.rect = option.rect;
|
|
|
|
button.rect.adjust(option.rect.width() - 40 -40, option.rect.height()/2-10, -12-40, -(option.rect.height()/2-10));
|
|
button.iconSize = QSize(button.rect.width()+2,button.rect.height()+2);
|
|
button.icon = QIcon(m_strTrendPath);
|
|
button.features = QStyleOptionButton::Flat;
|
|
QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter);
|
|
painter->restore();
|
|
}
|
|
painter->drawText(option.rect, m_pModel->data(index, Qt::TextAlignmentRole).toInt(), m_pModel->data(index).toString());
|
|
painter->restore();
|
|
}else
|
|
{
|
|
return ;
|
|
}
|
|
}else
|
|
{
|
|
AlarmMsgPtr ptr = NULL;
|
|
if(item->getPtr(ptr) && ptr != NULL)
|
|
{
|
|
painter->save();
|
|
if(ptr->logic_state == E_ALS_RETURN || ptr->logic_state == E_ALS_RETURN_DEL)//返回未确认
|
|
{
|
|
if(select)
|
|
{
|
|
fillColor = m_select_background_color;
|
|
if(m_selectIsEmpty)
|
|
{
|
|
penColor = m_colorMap.value(ptr->priorityOrder).resume_text_color;
|
|
}else
|
|
{
|
|
penColor = m_select_text_color;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
penColor = m_colorMap.value(ptr->priorityOrder).resume_text_color;
|
|
fillColor = m_colorMap.value(ptr->priorityOrder).background_color;
|
|
}
|
|
}else if(ptr->logic_state == E_ALS_ALARM || ptr->logic_state == E_ALS_ALARM_DEL)//告警未确认
|
|
{
|
|
if(select)
|
|
{
|
|
fillColor = m_select_background_color;
|
|
if(m_selectIsEmpty)
|
|
{
|
|
penColor = m_colorMap.value(ptr->priorityOrder).active_text_color;
|
|
}else
|
|
{
|
|
penColor = m_select_text_color;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
penColor = m_colorMap.value(ptr->priorityOrder).active_text_color;
|
|
fillColor = m_colorMap.value(ptr->priorityOrder).background_color;
|
|
}
|
|
}else
|
|
{
|
|
if(select)
|
|
{
|
|
fillColor = m_select_background_color;
|
|
}
|
|
else
|
|
{
|
|
fillColor = m_colorMap.value(ptr->priorityOrder).confirm_color;
|
|
}
|
|
penColor = m_colorMap.value(ptr->priorityOrder).confirm_text_color;
|
|
}
|
|
painter->setPen(penColor);
|
|
painter->fillRect(option.rect, fillColor);
|
|
|
|
if(m_enableVideo && BUTTON_COLUMN == index.column() && ptr->m_needVideoAlm)
|
|
{
|
|
painter->save();
|
|
QStyleOptionButton button;
|
|
button.state |= QStyle::State_Enabled;
|
|
button.rect = option.rect;
|
|
|
|
button.rect.adjust(option.rect.width() - 40, option.rect.height()/2-10, -12, -(option.rect.height()/2-10));
|
|
button.iconSize = QSize(button.rect.width()+2,button.rect.height()+2);
|
|
button.icon = QIcon(m_strVideoPath);
|
|
button.features = QStyleOptionButton::Flat;
|
|
QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter);
|
|
painter->restore();
|
|
}
|
|
|
|
if(m_enableLevel && ICON_COLUMN == index.column())
|
|
{
|
|
painter->save();
|
|
QStyleOptionButton button;
|
|
button.state |= QStyle::State_Enabled;
|
|
button.rect = option.rect;
|
|
|
|
button.rect.adjust(12, option.rect.height()/2-10, -(option.rect.width()-40), -(option.rect.height()/2-10));
|
|
QString file = m_colorMap.value(ptr->priorityOrder).icon;
|
|
button.iconSize = QSize(button.rect.width()+2,button.rect.height()+2);
|
|
button.icon = QIcon(file);
|
|
button.features = QStyleOptionButton::Flat;
|
|
|
|
QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter);
|
|
painter->restore();
|
|
}
|
|
|
|
if( m_enableTrend && BUTTON_COLUMN == index.column() && (ptr->m_tagname_type == E_TAGNAME_ANA || ptr->m_tagname_type == E_TAGNAME_ACC))
|
|
{
|
|
painter->save();
|
|
QStyleOptionButton button;
|
|
button.state |= QStyle::State_Enabled;
|
|
button.rect = option.rect;
|
|
|
|
button.rect.adjust(option.rect.width() - 40 -40, option.rect.height()/2-10, -12-40, -(option.rect.height()/2-10));
|
|
button.iconSize = QSize(button.rect.width()+2,button.rect.height()+2);
|
|
button.icon = QIcon(m_strTrendPath);
|
|
button.features = QStyleOptionButton::Flat;
|
|
QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter);
|
|
painter->restore();
|
|
}
|
|
|
|
if( m_enableWave && BUTTON_COLUMN == index.column() && !ptr->wave_file.isEmpty())
|
|
{
|
|
painter->save();
|
|
QStyleOptionButton button;
|
|
button.state |= QStyle::State_Enabled;
|
|
button.rect = option.rect;
|
|
|
|
button.rect.adjust(option.rect.width() - 40 -40 -40, option.rect.height()/2-10, -12-40-40, -(option.rect.height()/2-10));
|
|
button.iconSize = QSize(button.rect.width()+2,button.rect.height()+2);
|
|
button.icon = QIcon(m_strWavePath);
|
|
button.features = QStyleOptionButton::Flat;
|
|
QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter);
|
|
painter->restore();
|
|
}
|
|
|
|
painter->drawText(option.rect, m_pModel->data(index, Qt::TextAlignmentRole).toInt(), m_pModel->data(index).toString());
|
|
painter->restore();
|
|
}else
|
|
{
|
|
return ;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool CAiAlarmDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
|
|
{
|
|
if(!index.isValid())
|
|
{
|
|
return false;
|
|
}
|
|
if(index.column() != BUTTON_COLUMN)
|
|
{
|
|
return false;
|
|
}
|
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
|
|
CAiAlarmTreeItem *item = m_pModel->getItem(index);
|
|
if(item->isAi())
|
|
{
|
|
AiAlarmMsgPtr ptr = NULL;
|
|
if(item->getAiPtr(ptr) && ptr != NULL)
|
|
{
|
|
if(mouseEvent != NULL && mouseEvent->button() == Qt::LeftButton && mouseEvent->type() == QMouseEvent::MouseButtonPress)
|
|
{
|
|
if(m_enableVideo && ptr->m_needVideoAlm)
|
|
{
|
|
QStyleOptionButton button;
|
|
button.rect = option.rect;
|
|
button.rect.adjust(option.rect.width() - 42, option.rect.height()/2-10, -10, -(option.rect.height()/2-10));
|
|
QRect rect = button.rect;
|
|
if(rect.contains(mouseEvent->pos()))
|
|
{
|
|
QString pointTag = ptr->key_id_tag;
|
|
pointTag.remove(pointTag.length()-6,6);
|
|
emit openVideo(ptr->domain_id,ptr->app_id,pointTag,ptr->time_stamp-VIDEO_TIME,ptr->time_stamp+VIDEO_TIME);
|
|
}
|
|
}
|
|
if( m_enableTrend && (ptr->m_tagname_type == E_TAGNAME_ACC || ptr->m_tagname_type == E_TAGNAME_ANA))
|
|
{
|
|
QStyleOptionButton button;
|
|
button.rect = option.rect;
|
|
button.rect.adjust(option.rect.width() - 82, option.rect.height()/2-10, -50, -(option.rect.height()/2-10));
|
|
QRect rect = button.rect;
|
|
|
|
if(rect.contains(mouseEvent->pos()))
|
|
{
|
|
QStringList trendList;
|
|
trendList.append(ptr->key_id_tag);
|
|
emit openTrend(ptr->time_stamp,trendList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}else
|
|
{
|
|
AlarmMsgPtr ptr = NULL;
|
|
if(item->getPtr(ptr) && ptr != NULL)
|
|
{
|
|
if(m_enableVideo && ptr->m_needVideoAlm)
|
|
{
|
|
if(mouseEvent != NULL && mouseEvent->button() == Qt::LeftButton && mouseEvent->type() == QMouseEvent::MouseButtonPress)
|
|
{
|
|
QStyleOptionButton button;
|
|
button.rect = option.rect;
|
|
button.rect.adjust(option.rect.width() - 42, option.rect.height()/2-10, -10, -(option.rect.height()/2-10));
|
|
QRect rect = button.rect;
|
|
QString pointTag = ptr->key_id_tag;
|
|
pointTag.remove(pointTag.length()-6,6);
|
|
if(rect.contains(mouseEvent->pos()))
|
|
{
|
|
QString pointTag = ptr->key_id_tag;
|
|
pointTag.remove(pointTag.length()-6,6);
|
|
emit openVideo(ptr->domain_id,ptr->app_id,pointTag,ptr->time_stamp-VIDEO_TIME,ptr->time_stamp+VIDEO_TIME);
|
|
}
|
|
}
|
|
}
|
|
if(m_enableTrend && (ptr->m_tagname_type == E_TAGNAME_ACC || ptr->m_tagname_type == E_TAGNAME_ANA))
|
|
{
|
|
if(mouseEvent != NULL && mouseEvent->button() == Qt::LeftButton && mouseEvent->type() == QMouseEvent::MouseButtonPress)
|
|
{
|
|
QStyleOptionButton button;
|
|
button.rect = option.rect;
|
|
button.rect.adjust(option.rect.width() - 82, option.rect.height()/2-10, -50, -(option.rect.height()/2-10));
|
|
QRect rect = button.rect;
|
|
if(rect.contains(mouseEvent->pos()))
|
|
{
|
|
QStringList trendList;
|
|
trendList.append(ptr->key_id_tag);
|
|
emit openTrend(ptr->time_stamp,trendList);
|
|
}
|
|
}
|
|
}
|
|
if(m_enableWave && !ptr->wave_file.isEmpty())
|
|
{
|
|
if(mouseEvent != NULL && mouseEvent->button() == Qt::LeftButton && mouseEvent->type() == QMouseEvent::MouseButtonPress)
|
|
{
|
|
QStyleOptionButton button;
|
|
button.rect = option.rect;
|
|
button.rect.adjust(option.rect.width() - 122, option.rect.height()/2-10, -90, -(option.rect.height()/2-10));
|
|
QRect rect = button.rect;
|
|
if(rect.contains(mouseEvent->pos()))
|
|
{
|
|
QString wave = ptr->wave_file;
|
|
wave = QString("%1%2%3").arg("\"").arg(wave).arg("\"");
|
|
LOGINFO("录波文件为:%s",wave.toStdString().c_str());
|
|
|
|
const std::string strProc = std::move(kbd_public::CFileUtil::getPathOfBinFile(
|
|
std::string("WaveAnalyze") + kbd_public::CFileUtil::getProcSuffix()));
|
|
if(strProc.empty())
|
|
LOGERROR("未找到可执行文件WaveAnalyze");
|
|
else
|
|
QProcess::startDetached(QString("%1 %2").arg(strProc.c_str()).arg(wave));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
|
}
|
|
|
|
void CAiAlarmDelegate::slotLoadConfig()
|
|
{
|
|
CAlarmSetMng::instance()->getColorMap(m_colorMap);
|
|
CAlarmSetMng::instance()->getSelectInfo(m_selectIsEmpty,m_select_background_color,m_select_text_color);
|
|
CAlarmSetMng::instance()->getEmptyInfo(m_emptyBackgroundColor,m_emptyTipColor,m_emptyTip);
|
|
//CAlarmColorMng::instance()->getActAndFunc(m_act,m_func);
|
|
|
|
std::string style = kbd_public::CFileStyle::getCurStyle();
|
|
m_strTrendPath = kbd_public::CFileUtil::getPathOfResFile("gui/icon/alarm/trend_"+style+".png").c_str();
|
|
m_strVideoPath = kbd_public::CFileUtil::getPathOfResFile("gui/icon/alarm/video_"+style+".png").c_str();
|
|
m_strWavePath = kbd_public::CFileUtil::getPathOfResFile("gui/icon/alarm/wave_"+style+".png").c_str();
|
|
}
|