201 lines
5.8 KiB
C++
201 lines
5.8 KiB
C++
#include "CAlarmSetMng.h"
|
|
#include <QDomDocument>
|
|
#include "pub_logger_api/logger.h"
|
|
#include <QFile>
|
|
#include "pub_utility_api/FileUtil.h"
|
|
#include "CAlarmBaseData.h"
|
|
|
|
using namespace iot_public;
|
|
using namespace std;
|
|
|
|
CAlarmSetMng *CAlarmSetMng::pInstance = NULL;
|
|
|
|
|
|
CAlarmSetMng *CAlarmSetMng::instance()
|
|
{
|
|
if(pInstance == NULL)
|
|
{
|
|
pInstance = new CAlarmSetMng();
|
|
}
|
|
return pInstance;
|
|
}
|
|
|
|
CAlarmSetMng::~CAlarmSetMng()
|
|
{
|
|
LOGDEBUG("CAlarmSetMng::~CAlarmSetMng()");
|
|
}
|
|
|
|
bool CAlarmSetMng::isBindMediaPlayer()
|
|
{
|
|
return isSignalConnected(QMetaMethod::fromSignal(&CAlarmSetMng::sigLoadConfig));
|
|
}
|
|
|
|
CAlarmSetMng::CAlarmSetMng()
|
|
: QObject()
|
|
{
|
|
mutex = new QMutex();
|
|
m_priorityOrderDescriptionMap = CAlarmBaseData::instance()->getPriorityOrderMap();
|
|
loadXMLCfg();
|
|
}
|
|
|
|
void CAlarmSetMng::loadXMLCfg()
|
|
{
|
|
m_colorMap.clear();
|
|
QString filePath = QString::fromStdString(iot_public::CFileUtil::getCurModuleDir()) + 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();
|
|
|
|
QDomElement element = document.documentElement();
|
|
QDomNode node = element.firstChild();
|
|
while(!node.isNull())
|
|
{
|
|
QDomElement attr = node.toElement();
|
|
if(!attr.isNull())
|
|
{
|
|
if(QString("Level") == attr.tagName())
|
|
{
|
|
CAlarmColorInfo info;
|
|
info.priority = attr.attribute("priority").toInt();
|
|
info.background_color = QColor(attr.attribute("background_color"));
|
|
info.alternating_color = QColor(attr.attribute("alternating_color"));
|
|
info.confirm_color = QColor(attr.attribute("confirm_color"));
|
|
|
|
info.active_text_color = QColor(attr.attribute("active_text_color"));
|
|
info.confirm_text_color = QColor(attr.attribute("confirm_text_color"));
|
|
info.resume_text_color = QColor(attr.attribute("resume_text_color"));
|
|
info.icon = attr.attribute("icon");
|
|
m_colorMap[info.priority] = info;
|
|
}
|
|
else if(QString("Select") == attr.tagName())
|
|
{
|
|
m_select_background_color = QColor(attr.attribute("background_color"));
|
|
if(attr.attribute("text_color").isEmpty())
|
|
{
|
|
m_selectIsEmpty = true;
|
|
}else
|
|
{
|
|
m_selectIsEmpty = false;
|
|
m_select_text_color = QColor(attr.attribute("text_color"));
|
|
}
|
|
}
|
|
else if(QString("NoItem") == attr.tagName())
|
|
{
|
|
m_emptyBackgroundColor = QColor(attr.attribute("background_color"));
|
|
m_emptyTipColor = QColor(attr.attribute("tips_color"));
|
|
m_emptyTip = tr("当前无告警!");
|
|
}else if(QString("Alarm") == attr.tagName())
|
|
{
|
|
m_act =attr.attribute("act").toInt();
|
|
m_actDesc = attr.attribute("actDesc");
|
|
m_num =attr.attribute("num").toInt();
|
|
m_style = attr.attribute("style").toInt();
|
|
}else if(QString("VoiceEngine") == attr.tagName())
|
|
{
|
|
m_engine = attr.attribute("engine");
|
|
m_language = attr.attribute("language");
|
|
m_voiceName = attr.attribute("voice_name");
|
|
}
|
|
}
|
|
node = node.nextSibling();
|
|
}
|
|
}
|
|
|
|
void CAlarmSetMng::destory()
|
|
{
|
|
pInstance = NULL;
|
|
deleteLater();
|
|
}
|
|
|
|
void CAlarmSetMng::getPriorityInfo(QMap<int, QString> &priorityOrderDescriptionMap)
|
|
{
|
|
priorityOrderDescriptionMap.clear();
|
|
priorityOrderDescriptionMap = m_priorityOrderDescriptionMap;
|
|
}
|
|
|
|
void CAlarmSetMng::getColorMap(QMap<int, CAlarmColorInfo> &colorMap)
|
|
{
|
|
colorMap.clear();
|
|
colorMap = m_colorMap;
|
|
}
|
|
|
|
void CAlarmSetMng::getSelectInfo(bool &selectIsEmpty, QColor &select_background_color, QColor &select_text_color)
|
|
{
|
|
selectIsEmpty = m_selectIsEmpty;
|
|
select_background_color = m_select_background_color;
|
|
select_text_color = m_select_text_color;
|
|
}
|
|
|
|
void CAlarmSetMng::getEmptyInfo(QColor &emptyBackgroundColor, QColor &emptyTipColor, QString &emptyTip)
|
|
{
|
|
emptyBackgroundColor = m_emptyBackgroundColor;
|
|
emptyTipColor = m_emptyTipColor;
|
|
emptyTip = m_emptyTip;
|
|
}
|
|
|
|
void CAlarmSetMng::getActAndNum(int &act, int &num, int &style)
|
|
{
|
|
act = m_act;
|
|
num = m_num;
|
|
style = m_style;
|
|
}
|
|
|
|
void CAlarmSetMng::getEngine(QString &engine, QString &language, QString &voiceName)
|
|
{
|
|
engine = m_engine;
|
|
language = m_language;
|
|
voiceName = m_voiceName;
|
|
}
|
|
|
|
QString CAlarmSetMng::getPriorityDescByOrder(int order)
|
|
{
|
|
return m_priorityOrderDescriptionMap.value(order,tr("未知告警等级"));
|
|
}
|
|
|
|
void CAlarmSetMng::setColorMap(const QMap<int, CAlarmColorInfo> &colorMap)
|
|
{
|
|
m_colorMap = colorMap;
|
|
}
|
|
|
|
void CAlarmSetMng::setSelectInfo(const bool &selectIsEmpty,const QColor &select_background_color,const QColor &select_text_color)
|
|
{
|
|
m_selectIsEmpty = selectIsEmpty;
|
|
m_select_background_color = select_background_color;
|
|
m_select_text_color = select_text_color;
|
|
}
|
|
|
|
void CAlarmSetMng::setEmptyInfo(const QColor &emptyBackgroundColor, const QColor &emptyTipColor, const QString &emptyTip)
|
|
{
|
|
m_emptyBackgroundColor= emptyBackgroundColor;
|
|
m_emptyTipColor = emptyTipColor;
|
|
m_emptyTip = emptyTip;
|
|
}
|
|
|
|
void CAlarmSetMng::setActAndNum(const int &act, const int &num, const int &style)
|
|
{
|
|
m_act = act;
|
|
m_num = num;
|
|
m_style = style;
|
|
}
|
|
|
|
void CAlarmSetMng::setEngine(const QString &engine, const QString &language, const QString &voiceName)
|
|
{
|
|
m_engine = engine;
|
|
m_language = language;
|
|
m_voiceName = voiceName;
|
|
}
|
|
|
|
void CAlarmSetMng::sigUpdateColor()
|
|
{
|
|
emit sigLoadConfig();
|
|
}
|