2025-03-14 17:05:48 +08:00
|
|
|
#include "CMainWidget.h"
|
|
|
|
|
#include "CStatisWidget.h"
|
|
|
|
|
#include "ContrastWidget.h"
|
|
|
|
|
#include "CHisEventManage.h"
|
|
|
|
|
#include "tsdb_api/TsdbApi.h"
|
|
|
|
|
#include "pub_utility_api/FileStyle.h"
|
|
|
|
|
#include "pub_utility_api/FileUtil.h"
|
|
|
|
|
#include <QTabWidget>
|
|
|
|
|
#include <QGridLayout>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QDomDocument>
|
|
|
|
|
|
|
|
|
|
CMainWidget::CMainWidget(bool editMode, QVector<void *> ptrVec, QWidget *parent)
|
|
|
|
|
: QWidget(parent),
|
|
|
|
|
m_editMode(editMode),
|
|
|
|
|
m_pStatisWidget(Q_NULLPTR),
|
|
|
|
|
m_pContrastWidget(Q_NULLPTR),
|
|
|
|
|
m_pHisEventThread(Q_NULLPTR),
|
|
|
|
|
m_pHisEventManage(Q_NULLPTR)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(ptrVec)
|
|
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMainWidget::~CMainWidget()
|
|
|
|
|
{
|
|
|
|
|
if(!m_editMode)
|
|
|
|
|
{
|
2025-03-17 09:23:17 +08:00
|
|
|
iot_dbms::releaseTsdbApi();
|
2025-03-14 17:05:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(m_pHisEventManage)
|
|
|
|
|
{
|
|
|
|
|
emit releaseHisEventThread();
|
|
|
|
|
m_pHisEventManage = Q_NULLPTR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(m_pHisEventThread)
|
|
|
|
|
{
|
|
|
|
|
m_pHisEventThread->quit();
|
|
|
|
|
m_pHisEventThread->wait();
|
|
|
|
|
}
|
|
|
|
|
m_pHisEventThread = Q_NULLPTR;
|
|
|
|
|
|
|
|
|
|
if(m_pStatisWidget)
|
|
|
|
|
{
|
|
|
|
|
delete m_pStatisWidget;
|
|
|
|
|
}
|
|
|
|
|
m_pStatisWidget = Q_NULLPTR;
|
|
|
|
|
|
|
|
|
|
if(m_pContrastWidget)
|
|
|
|
|
{
|
|
|
|
|
delete m_pContrastWidget;
|
|
|
|
|
}
|
|
|
|
|
m_pContrastWidget = Q_NULLPTR;
|
|
|
|
|
|
|
|
|
|
CDataInfoManage::instance()->destory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMainWidget::initialize()
|
|
|
|
|
{
|
|
|
|
|
m_pStatisWidget = new CStatisWidget(m_editMode, this);
|
|
|
|
|
m_pContrastWidget = new ContrastWidget(m_editMode, this);
|
|
|
|
|
|
|
|
|
|
QTabWidget *widget = new QTabWidget();
|
|
|
|
|
widget->addTab(m_pStatisWidget, tr("告警统计"));
|
|
|
|
|
widget->addTab(m_pContrastWidget, tr("告警对比"));
|
|
|
|
|
QGridLayout *layout = new QGridLayout();
|
|
|
|
|
layout->addWidget(widget);
|
|
|
|
|
layout->setMargin(6);
|
|
|
|
|
setLayout(layout);
|
|
|
|
|
|
|
|
|
|
initStyleSheet();
|
|
|
|
|
|
|
|
|
|
if(!m_editMode)
|
|
|
|
|
{
|
2025-03-17 09:23:17 +08:00
|
|
|
iot_dbms::initTsdbApi();
|
2025-03-14 17:05:48 +08:00
|
|
|
|
|
|
|
|
loadAlarmColor();
|
|
|
|
|
|
|
|
|
|
initHisEventManage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMainWidget::initStyleSheet()
|
|
|
|
|
{
|
|
|
|
|
QString style = QString();
|
2025-03-17 09:23:17 +08:00
|
|
|
std::string strFullPath = iot_public::CFileStyle
|
2025-03-14 17:05:48 +08:00
|
|
|
::getPathOfStyleFile("public.qss") ;
|
|
|
|
|
QFile file1(QString::fromStdString(strFullPath));
|
|
|
|
|
if (file1.open(QIODevice::ReadOnly))
|
|
|
|
|
{
|
|
|
|
|
QTextStream styleStream(&file1);
|
|
|
|
|
style += styleStream.readAll();
|
|
|
|
|
//setStyleSheet(style);
|
|
|
|
|
}
|
|
|
|
|
file1.close();
|
|
|
|
|
|
2025-03-17 09:23:17 +08:00
|
|
|
strFullPath = iot_public::CFileStyle
|
2025-03-14 17:05:48 +08:00
|
|
|
::getPathOfStyleFile("AlarmStatisWidget.qss") ;
|
|
|
|
|
QFile file2(QString::fromStdString(strFullPath));
|
|
|
|
|
if (file2.open(QIODevice::ReadOnly))
|
|
|
|
|
{
|
|
|
|
|
QTextStream styleStream(&file2);
|
|
|
|
|
style += styleStream.readAll();
|
|
|
|
|
//setStyleSheet(style);
|
|
|
|
|
}
|
|
|
|
|
file2.close();
|
|
|
|
|
if(!style.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
setStyleSheet(style);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMainWidget::loadAlarmColor()
|
|
|
|
|
{
|
2025-03-17 09:23:17 +08:00
|
|
|
QString filePath = QString::fromStdString(iot_public::CFileUtil::getCurModuleDir())
|
2025-03-14 17:05:48 +08:00
|
|
|
+ QString("../../data/model/alarm_color_define.xml");
|
|
|
|
|
|
|
|
|
|
QDomDocument document;
|
|
|
|
|
QFile file(filePath);
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!document.setContent(&file))
|
|
|
|
|
{
|
|
|
|
|
file.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
QMap<int, QColor> almColorMap;
|
|
|
|
|
QDomElement element = document.documentElement();
|
|
|
|
|
QDomNode node = element.firstChild();
|
|
|
|
|
while(!node.isNull())
|
|
|
|
|
{
|
|
|
|
|
QDomElement attr = node.toElement();
|
|
|
|
|
if(!attr.isNull())
|
|
|
|
|
{
|
|
|
|
|
if(QString("Level") == attr.tagName())
|
|
|
|
|
{
|
|
|
|
|
int priority = attr.attribute("priority").toInt();
|
|
|
|
|
QColor color = QColor(attr.attribute("active_text_color"));
|
|
|
|
|
almColorMap[priority] = color;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
node = node.nextSibling();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QColor> listColor;
|
|
|
|
|
QMap<int, int> orderMap = CDataInfoManage::instance()->getAlarmOrder();
|
|
|
|
|
QMap<int, int>::const_iterator iter = orderMap.constBegin();
|
|
|
|
|
for(; iter != orderMap.constEnd(); iter++)
|
|
|
|
|
{
|
|
|
|
|
listColor.append(almColorMap.value(iter.value(), Qt::black));
|
|
|
|
|
}
|
|
|
|
|
m_pStatisWidget->setCurveColor(listColor);
|
|
|
|
|
m_pContrastWidget->setCurveColor(listColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMainWidget::initHisEventManage()
|
|
|
|
|
{
|
|
|
|
|
m_pHisEventManage = new CHisEventManage;
|
|
|
|
|
m_pHisEventThread = new QThread(this);
|
|
|
|
|
m_pHisEventManage->moveToThread(m_pHisEventThread);
|
|
|
|
|
connect(m_pHisEventThread, &QThread::finished, m_pHisEventThread, &QObject::deleteLater);
|
|
|
|
|
connect(this, &CMainWidget::releaseHisEventThread, m_pHisEventManage, &CHisEventManage::release, Qt::BlockingQueuedConnection);
|
|
|
|
|
|
|
|
|
|
connect(m_pStatisWidget, &CStatisWidget::sigQueryEvent, m_pHisEventManage, &CHisEventManage::queryHisEventStatis, Qt::QueuedConnection);
|
|
|
|
|
connect(m_pHisEventManage, &CHisEventManage::updateHisEventStatis, m_pStatisWidget, &CStatisWidget::updateEventNum ,Qt::QueuedConnection);
|
|
|
|
|
|
|
|
|
|
connect(m_pContrastWidget, &ContrastWidget::sigQueryEvent, m_pHisEventManage, &CHisEventManage::queryHisEventContrast, Qt::QueuedConnection);
|
|
|
|
|
connect(m_pHisEventManage, &CHisEventManage::updateHisEventContrast, m_pContrastWidget, &ContrastWidget::updateEventNum, Qt::QueuedConnection);
|
|
|
|
|
|
|
|
|
|
m_pHisEventThread->start();
|
|
|
|
|
}
|