[ref]同步711 711更新

This commit is contained in:
shi_jq 2025-03-17 16:44:49 +08:00
parent 499b61b93e
commit 01f6a1ca4b
58 changed files with 1358 additions and 725 deletions

View File

@ -1,4 +1,4 @@
#include "CCurveLegendModel.h" #include "CCurveLegendModel.h"
#include "CTrendGraph.h" #include "CTrendGraph.h"
#include <QTableWidgetItem> #include <QTableWidgetItem>
#include <QDoubleSpinBox> #include <QDoubleSpinBox>

View File

@ -1,4 +1,4 @@
#ifndef CCURVELEGENDMODEL_H #ifndef CCURVELEGENDMODEL_H
#define CCURVELEGENDMODEL_H #define CCURVELEGENDMODEL_H
#include <QLabel> #include <QLabel>

View File

@ -1,7 +1,9 @@
#include "CCurveLegendView.h" #include "CCurveLegendView.h"
#include "CCurveLegendModel.h" #include "CCurveLegendModel.h"
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QMenu> #include <QMenu>
#include <QtMath>
#include <QHeaderView>
CCurveLegendView::CCurveLegendView(QWidget *parent) CCurveLegendView::CCurveLegendView(QWidget *parent)
: CTableView(parent) : CTableView(parent)
@ -9,6 +11,43 @@ CCurveLegendView::CCurveLegendView(QWidget *parent)
} }
void CCurveLegendView::adjustHeaderWidth()
{
QHeaderView *header = horizontalHeader();
int sectionCount = header->count();
if (sectionCount == 0 || !model()) {
return;
}
QFontMetrics fontMetrics(header->font());
const int maxWidthThreshold = 200;
const int baseHeight = 30;
int maxHeightMultiplier = 1;
for (int section = 0; section < sectionCount; ++section) {
QString headerText = model()->headerData(section, Qt::Horizontal).toString();
if (headerText.isEmpty()) {
continue;
}
int textWidth = fontMetrics.width(headerText) + 20; // 额外空间
int heightMultiplier = 1;
// 调整宽度和计算换行高度
if (textWidth > maxWidthThreshold) {
header->resizeSection(section, maxWidthThreshold);
heightMultiplier = qCeil(static_cast<qreal>(textWidth) / maxWidthThreshold);
} else {
header->resizeSection(section, textWidth);
}
maxHeightMultiplier = qMax(maxHeightMultiplier, heightMultiplier);
}
header->setFixedHeight(maxHeightMultiplier * baseHeight);
}
void CCurveLegendView::contextMenuEvent(QContextMenuEvent *event) void CCurveLegendView::contextMenuEvent(QContextMenuEvent *event)
{ {
CCurveLegendModel * pModel = dynamic_cast<CCurveLegendModel *>(model()); CCurveLegendModel * pModel = dynamic_cast<CCurveLegendModel *>(model());
@ -27,3 +66,9 @@ void CCurveLegendView::contextMenuEvent(QContextMenuEvent *event)
return; return;
} }
void CCurveLegendView::showEvent(QShowEvent *event)
{
QTableView::showEvent(event);
adjustHeaderWidth();
}

View File

@ -1,4 +1,4 @@
#ifndef CCURVELEGENDVIEW_H #ifndef CCURVELEGENDVIEW_H
#define CCURVELEGENDVIEW_H #define CCURVELEGENDVIEW_H
#include "CTableView.h" #include "CTableView.h"
@ -9,8 +9,11 @@ class CCurveLegendView : public CTableView
public: public:
CCurveLegendView(QWidget *parent = Q_NULLPTR); CCurveLegendView(QWidget *parent = Q_NULLPTR);
void adjustHeaderWidth();
protected: protected:
void contextMenuEvent(QContextMenuEvent *event); void contextMenuEvent(QContextMenuEvent *event);
void showEvent(QShowEvent *event) override ;
}; };
#endif // CCURVELEGENDVIEW_H #endif // CCURVELEGENDVIEW_H

View File

@ -1,7 +1,6 @@
#include "CHisDataManage.h" #include "CHisDataManage.h"
#include "db_his_query_api/DbHisQueryApi.h" #include "db_his_query_api/DbHisQueryApi.h"
#include "sample_server_api/SampleDefine.h" #include "sample_server_api/SampleDefine.h"
#include "CTrendInfoManage.h"
#include "pub_logger_api/logger.h" #include "pub_logger_api/logger.h"
using namespace iot_dbms; using namespace iot_dbms;
@ -10,9 +9,7 @@ int CHisDataManage::m_nProcessNumber = 0;
CHisDataManage::CHisDataManage(QObject *parent) CHisDataManage::CHisDataManage(QObject *parent)
: QObject(parent), : QObject(parent),
m_TsdbExcuting(false), m_TsdbExcuting(false),
m_bHasPendingCommandCurve(false), m_bHasPending(false),
m_bHasPendingCommandEvent(false),
m_bHasPendingCommandCompute(false),
m_tsdbConnPtr((CTsdbConn*)nullptr) m_tsdbConnPtr((CTsdbConn*)nullptr)
{ {
initTsdbApi(); initTsdbApi();
@ -28,26 +25,15 @@ CHisDataManage::~CHisDataManage()
releaseTsdbApi(); releaseTsdbApi();
} }
foreach (TsdbCommand cmd, m_listCommandCurve) foreach (QList<TsdbCommand> cmdList, m_listCommand) {
{ foreach (TsdbCommand cmd, cmdList)
cmd.pVecMpKey->clear(); {
delete cmd.pVecMpKey; cmd.pVecMpKey->clear();
delete cmd.pVecMpKey;
}
cmdList.clear();
} }
m_listCommandCurve.clear(); m_listCommand.clear();
foreach (TsdbCommand cmd, m_listCommandEvent)
{
cmd.pVecMpKey->clear();
delete cmd.pVecMpKey;
}
m_listCommandEvent.clear();
foreach (TsdbCommand cmd, m_listCommandCompute)
{
cmd.pVecMpKey->clear();
delete cmd.pVecMpKey;
}
m_listCommandCompute.clear();
} }
bool CHisDataManage::isTsdbExuting() bool CHisDataManage::isTsdbExuting()
@ -56,41 +42,47 @@ bool CHisDataManage::isTsdbExuting()
return m_TsdbExcuting; return m_TsdbExcuting;
} }
void CHisDataManage::postTsdbCommandQueue(E_His_Type type, std::vector<SMeasPointKey> *vecMpKey, double lower, double upper, int nGroupBySec, std::vector<EnComputeMethod> vecCM) void CHisDataManage::postTsdbCommandQueue(const QList<TsdbCommand> &cmd)
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
TsdbCommand cmd;
cmd.type = type;
cmd.pVecMpKey = vecMpKey;
cmd.lower = lower;
cmd.upper = upper;
cmd.nGroupBySec = nGroupBySec;
cmd.vecMethod = vecCM;
switch(type) m_bHasPending = true;
m_listCommand.push_back(cmd);
}
void CHisDataManage::queryHistoryRecord(const QList<TsdbCommand> &cmdList)
{
{ {
case E_ORIGINAL: QMutexLocker locker(&m_mutex);
case E_POLYMERIC: m_TsdbExcuting = true;
}
emit sigHisSearch(true);
foreach (TsdbCommand cmd, cmdList) {
if(E_ORIGINAL == cmd.type)
{
queryHistoryOriginalData(cmd.pVecMpKey, cmd.lower, cmd.upper, cmd.dataType);
}
else if(E_POLYMERIC == cmd.type)
{
queryHistoryPolymericData(cmd.pVecMpKey, cmd.lower, cmd.upper, cmd.nGroupBySec, cmd.vecMethod.front(), cmd.dataType);
}
else if(E_EVENTPOINT == cmd.type)
{
queryHistoryEvents(cmd.pVecMpKey, cmd.lower, cmd.upper, cmd.vecMethod.front(), cmd.nGroupBySec);
}
else if(E_COMPUTER == cmd.type)
{
queryHistoryComputeData(cmd.pVecMpKey, cmd.lower, cmd.upper, cmd.vecMethod, cmd.dataType);
}
}
emit sigHisSearch(false);
{ {
m_bHasPendingCommandCurve = true; QMutexLocker locker(&m_mutex);
m_listCommandCurve.push_back(cmd); m_TsdbExcuting = false;
break;
}
case E_EVENTPOINT:
{
m_bHasPendingCommandEvent = true;
m_listCommandEvent.push_back(cmd);
break;
}
case E_COMPUTER:
{
m_bHasPendingCommandCompute = true;
m_listCommandCompute.push_back(cmd);
break;
}
default:
break;
} }
checkTsdbCommandQueue();
} }
void CHisDataManage::release() void CHisDataManage::release()
@ -134,65 +126,41 @@ bool CHisDataManage::getValidTsdbConnPtr(iot_dbms::CTsdbConnPtr &ptr)
void CHisDataManage::checkTsdbCommandQueue() void CHisDataManage::checkTsdbCommandQueue()
{ {
checkTsdbCommandQueue(m_bHasPendingCommandCurve, m_listCommandCurve); if(m_bHasPending)
checkTsdbCommandQueue(m_bHasPendingCommandEvent, m_listCommandEvent);
checkTsdbCommandQueue(m_bHasPendingCommandCompute, m_listCommandCompute);
}
void CHisDataManage::checkTsdbCommandQueue(bool &bHasPend, QList<TsdbCommand> &listCommand)
{
if(bHasPend)
{ {
bHasPend = false; m_bHasPending = false;
TsdbCommand cmd; QList<TsdbCommand> cmdList;
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
if(!listCommand.isEmpty()) if(!m_listCommand.isEmpty())
{ {
cmd = listCommand.takeLast(); cmdList = m_listCommand.takeLast();
} }
} }
if(E_ORIGINAL == cmd.type) queryHistoryRecord(cmdList);
{
queryHistoryOriginalData(cmd.pVecMpKey, cmd.lower, cmd.upper);
}
else if(E_POLYMERIC == cmd.type)
{
queryHistoryPolymericData(cmd.pVecMpKey, cmd.lower, cmd.upper, cmd.nGroupBySec, cmd.vecMethod.front());
}
else if(E_EVENTPOINT == cmd.type)
{
queryHistoryEvents(cmd.pVecMpKey, cmd.lower, cmd.upper, cmd.vecMethod.front(), cmd.nGroupBySec);
}
else if(E_COMPUTER == cmd.type)
{
queryHistoryComputeData(cmd.pVecMpKey, cmd.lower, cmd.upper, cmd.vecMethod);
}
} }
else else
{ {
foreach (TsdbCommand cmd, listCommand) foreach (QList<TsdbCommand> cmdList, m_listCommand)
{ {
std::vector<SMeasPointKey>::iterator it = cmd.pVecMpKey->begin(); foreach (TsdbCommand cmd, cmdList) {
while(it != cmd.pVecMpKey->end()) std::vector<SMeasPointKey>::iterator it = cmd.pVecMpKey->begin();
{ while(it != cmd.pVecMpKey->end())
free( (char*)it->m_pszTagName ); {
++it; free( (char*)it->m_pszTagName );
++it;
}
cmd.pVecMpKey->clear();
delete cmd.pVecMpKey;
} }
cmd.pVecMpKey->clear(); cmdList.clear();
delete cmd.pVecMpKey;
} }
listCommand.clear(); m_listCommand.clear();
} }
} }
void CHisDataManage::queryHistoryOriginalData(std::vector<SMeasPointKey> *vecMpKey, double lower, double upper, E_Data_Type type) void CHisDataManage::queryHistoryOriginalData(std::vector<SMeasPointKey> *vecMpKey, double lower, double upper, E_Data_Type type)
{ {
{
QMutexLocker locker(&m_mutex);
m_TsdbExcuting = true;
}
double nIntervalSecs = SAMPLE_CYC_MIN * 60 * 1000; double nIntervalSecs = SAMPLE_CYC_MIN * 60 * 1000;
std::vector<std::vector<SVarHisSamplePoint> *> *vecResult = new std::vector<std::vector<SVarHisSamplePoint> *>(); std::vector<std::vector<SVarHisSamplePoint> *> *vecResult = new std::vector<std::vector<SVarHisSamplePoint> *>();
@ -203,13 +171,11 @@ void CHisDataManage::queryHistoryOriginalData(std::vector<SMeasPointKey> *vecMpK
{ {
vecResult->push_back(new std::vector<SVarHisSamplePoint>()); vecResult->push_back(new std::vector<SVarHisSamplePoint>());
} }
emit sigHisSearch(true);
if(!getHisSamplePoint(*tsdbConnPtr, 10000, *vecMpKey, lower - nIntervalSecs, upper + nIntervalSecs, if(!getHisSamplePoint(*tsdbConnPtr, 10000, *vecMpKey, lower - nIntervalSecs, upper + nIntervalSecs,
NULL, NULL, CM_NULL, 0, FM_NULL_METHOD, *vecResult)) NULL, NULL, CM_NULL, 0, FM_NULL_METHOD, *vecResult))
{ {
LOGINFO("TrendCurve CHisDataManage::queryHistoryOriginalData: 查询超时!"); LOGINFO("TrendCurve CHisDataManage::queryHistoryOriginalData: 查询超时!");
} }
emit sigHisSearch(false);
} }
else else
{ {
@ -217,21 +183,10 @@ void CHisDataManage::queryHistoryOriginalData(std::vector<SMeasPointKey> *vecMpK
} }
emit sigupdateHisOriginalData(vecMpKey, vecResult, type); emit sigupdateHisOriginalData(vecMpKey, vecResult, type);
{
QMutexLocker locker(&m_mutex);
m_TsdbExcuting = false;
}
checkTsdbCommandQueue();
} }
void CHisDataManage::queryHistoryPolymericData(std::vector<SMeasPointKey> *vecMpKey, double lower, double upper, int nGroupBySec, const EnComputeMethod &enCm) void CHisDataManage::queryHistoryPolymericData(std::vector<SMeasPointKey> *vecMpKey, double lower, double upper, int nGroupBySec, const EnComputeMethod &enCm, E_Data_Type type)
{ {
{
QMutexLocker locker(&m_mutex);
m_TsdbExcuting = true;
}
double nIntervalSecs = SAMPLE_CYC_MIN * 60 * 1000; double nIntervalSecs = SAMPLE_CYC_MIN * 60 * 1000;
std::vector<std::vector<SVarHisSamplePoint> *> *vecResult = new std::vector<std::vector<SVarHisSamplePoint> *>(); std::vector<std::vector<SVarHisSamplePoint> *> *vecResult = new std::vector<std::vector<SVarHisSamplePoint> *>();
@ -242,35 +197,22 @@ void CHisDataManage::queryHistoryPolymericData(std::vector<SMeasPointKey> *vecMp
{ {
vecResult->push_back(new std::vector<SVarHisSamplePoint>()); vecResult->push_back(new std::vector<SVarHisSamplePoint>());
} }
emit sigHisSearch(true);
if(!getHisSamplePoint(*tsdbConnPtr, 10000, *vecMpKey, lower - nIntervalSecs, upper + nIntervalSecs, if(!getHisSamplePoint(*tsdbConnPtr, 10000, *vecMpKey, lower - nIntervalSecs, upper + nIntervalSecs,
NULL, NULL, enCm, nGroupBySec * 1000, FM_NULL_METHOD, *vecResult)) NULL, NULL, enCm, nGroupBySec * 1000, FM_NULL_METHOD, *vecResult))
{ {
LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 查询超时!"); LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 查询超时!");
} }
emit sigHisSearch(false);
} }
else else
{ {
LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 未获取到有效的TSDB连接"); LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 未获取到有效的TSDB连接");
} }
emit sigHistoryPolymericData(vecMpKey, vecResult, nGroupBySec); emit sigHistoryPolymericData(vecMpKey, vecResult, nGroupBySec, type);
{
QMutexLocker locker(&m_mutex);
m_TsdbExcuting = false;
}
checkTsdbCommandQueue();
} }
void CHisDataManage::queryHistoryComputeData(std::vector<SMeasPointKey> *vecMpKey, double lower, double upper, const std::vector<EnComputeMethod> &vecCM) void CHisDataManage::queryHistoryComputeData(std::vector<SMeasPointKey> *vecMpKey, double lower, double upper, const std::vector<EnComputeMethod> &vecCM, E_Data_Type type)
{ {
{
QMutexLocker locker(&m_mutex);
m_TsdbExcuting = true;
}
std::vector<std::pair<iot_dbms::EnComputeMethod, std::vector<std::vector<iot_dbms::SVarHisValue> *> *> > cmResult; std::vector<std::pair<iot_dbms::EnComputeMethod, std::vector<std::vector<iot_dbms::SVarHisValue> *> *> > cmResult;
iot_dbms::CTsdbConnPtr tsdbConnPtr; iot_dbms::CTsdbConnPtr tsdbConnPtr;
@ -283,7 +225,6 @@ void CHisDataManage::queryHistoryComputeData(std::vector<SMeasPointKey> *vecMpKe
{ {
vecResult->push_back(new std::vector<SVarHisValue>()); vecResult->push_back(new std::vector<SVarHisValue>());
} }
emit sigHisSearch(true);
if(!getHisValue(*tsdbConnPtr, 10000, *vecMpKey, lower, upper, if(!getHisValue(*tsdbConnPtr, 10000, *vecMpKey, lower, upper,
NULL, NULL, NULL, NULL, NULL, vecCM[nCmIndex], 0, FM_NULL_METHOD, *vecResult)) NULL, NULL, NULL, NULL, NULL, vecCM[nCmIndex], 0, FM_NULL_METHOD, *vecResult))
{ {
@ -293,7 +234,6 @@ void CHisDataManage::queryHistoryComputeData(std::vector<SMeasPointKey> *vecMpKe
tmp.first = vecCM[nCmIndex]; tmp.first = vecCM[nCmIndex];
tmp.second = vecResult; tmp.second = vecResult;
cmResult.push_back(tmp); cmResult.push_back(tmp);
emit sigHisSearch(false);
} }
} }
else else
@ -301,22 +241,11 @@ void CHisDataManage::queryHistoryComputeData(std::vector<SMeasPointKey> *vecMpKe
LOGINFO("TrendCurve CHisDataManage::queryHistoryComputeData: 未获取到有效的TSDB连接"); LOGINFO("TrendCurve CHisDataManage::queryHistoryComputeData: 未获取到有效的TSDB连接");
} }
emit sigHistoryComputeData(vecMpKey, cmResult); emit sigHistoryComputeData(vecMpKey, cmResult, type);
{
QMutexLocker locker(&m_mutex);
m_TsdbExcuting = false;
}
checkTsdbCommandQueue();
} }
void CHisDataManage::queryHistoryEvents(std::vector<SMeasPointKey> *vecMpKey, double lower, double upper, const EnComputeMethod &enCM, int nGroupBySec) void CHisDataManage::queryHistoryEvents(std::vector<SMeasPointKey> *vecMpKey, double lower, double upper, const EnComputeMethod &enCM, int nGroupBySec)
{ {
{
QMutexLocker locker(&m_mutex);
m_TsdbExcuting = true;
}
std::vector<std::vector<SHisEventPoint> *> *vecResult = new std::vector<std::vector<SHisEventPoint> *>(); std::vector<std::vector<SHisEventPoint> *> *vecResult = new std::vector<std::vector<SHisEventPoint> *>();
iot_dbms::CTsdbConnPtr tsdbConnPtr; iot_dbms::CTsdbConnPtr tsdbConnPtr;
@ -326,22 +255,14 @@ void CHisDataManage::queryHistoryEvents(std::vector<SMeasPointKey> *vecMpKey, do
{ {
vecResult->push_back(new std::vector<SHisEventPoint>()); vecResult->push_back(new std::vector<SHisEventPoint>());
} }
emit sigHisSearch(true);
if(!getHisEventPoint(*tsdbConnPtr, 10000, *vecMpKey, lower, upper, enCM, nGroupBySec * 1000, *vecResult)) if(!getHisEventPoint(*tsdbConnPtr, 10000, *vecMpKey, lower, upper, enCM, nGroupBySec * 1000, *vecResult))
{ {
LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 查询超时Lower: %f, Upper: %f, GroupByMs: %d", lower, upper, nGroupBySec); LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 查询超时Lower: %f, Upper: %f, GroupByMs: %d", lower, upper, nGroupBySec);
} }
emit sigHisSearch(false);
} }
else else
{ {
LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 未获取到有效的TSDB连接"); LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 未获取到有效的TSDB连接");
} }
emit sigHistoryEvent(vecMpKey, vecResult); emit sigHistoryEvent(vecMpKey, vecResult);
{
QMutexLocker locker(&m_mutex);
m_TsdbExcuting = false;
}
checkTsdbCommandQueue();
} }

View File

@ -1,4 +1,4 @@
#ifndef CHISDATAMANAGE_H #ifndef CHISDATAMANAGE_H
#define CHISDATAMANAGE_H #define CHISDATAMANAGE_H
#include <QMutex> #include <QMutex>
@ -10,8 +10,8 @@
enum E_Data_Type enum E_Data_Type
{ {
E_REALTIME, E_HISTORY,
E_HISTORY E_PRECURVE,
}; };
enum E_His_Type enum E_His_Type
@ -41,6 +41,7 @@ struct TsdbCommand
vecMethod = std::vector<iot_dbms::EnComputeMethod>{iot_dbms::CM_NULL}; vecMethod = std::vector<iot_dbms::EnComputeMethod>{iot_dbms::CM_NULL};
} }
E_His_Type type; E_His_Type type;
E_Data_Type dataType;
std::vector<iot_dbms::SMeasPointKey> * pVecMpKey; std::vector<iot_dbms::SMeasPointKey> * pVecMpKey;
double lower; double lower;
double upper; double upper;
@ -64,10 +65,12 @@ signals:
void sigHistoryPolymericData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void sigHistoryPolymericData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
std::vector<std::vector<iot_dbms::SVarHisSamplePoint> *> *vecResult, std::vector<std::vector<iot_dbms::SVarHisSamplePoint> *> *vecResult,
int nGroupBySec); int nGroupBySec,
E_Data_Type type = E_HISTORY);
void sigHistoryComputeData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void sigHistoryComputeData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
std::vector<std::pair<iot_dbms::EnComputeMethod, std::vector<std::vector<iot_dbms::SVarHisValue> *> *> > cmResult); std::vector<std::pair<iot_dbms::EnComputeMethod, std::vector<std::vector<iot_dbms::SVarHisValue> *> *> > cmResult,
E_Data_Type type = E_HISTORY);
void sigHistoryEvent(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void sigHistoryEvent(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
std::vector<std::vector<iot_dbms::SHisEventPoint> *> *vecResult); std::vector<std::vector<iot_dbms::SHisEventPoint> *> *vecResult);
@ -77,11 +80,11 @@ signals:
public slots: public slots:
void release(); void release();
void postTsdbCommandQueue(E_His_Type type, std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void postTsdbCommandQueue(const QList<TsdbCommand> &cmd);
double lower, double upper,
int nGroupBySec = -1,
std::vector<iot_dbms::EnComputeMethod> vecCM = std::vector<iot_dbms::EnComputeMethod>{iot_dbms::CM_NULL});
void queryHistoryRecord(const QList<TsdbCommand> &cmdList);
private:
void queryHistoryOriginalData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void queryHistoryOriginalData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
double lower, double upper, double lower, double upper,
E_Data_Type type = E_HISTORY); E_Data_Type type = E_HISTORY);
@ -89,11 +92,13 @@ public slots:
void queryHistoryPolymericData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void queryHistoryPolymericData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
double lower, double upper, double lower, double upper,
int nGroupBySec, int nGroupBySec,
const iot_dbms::EnComputeMethod &enCm); const iot_dbms::EnComputeMethod &enCm,
E_Data_Type type = E_HISTORY);
void queryHistoryComputeData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void queryHistoryComputeData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
double lower, double upper, double lower, double upper,
const std::vector<iot_dbms::EnComputeMethod> &vecCM); const std::vector<iot_dbms::EnComputeMethod> &vecCM,
E_Data_Type type = E_HISTORY);
void queryHistoryEvents(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void queryHistoryEvents(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
double lower, double upper, double lower, double upper,
@ -103,18 +108,12 @@ public slots:
protected: protected:
bool getValidTsdbConnPtr(iot_dbms::CTsdbConnPtr &ptr); bool getValidTsdbConnPtr(iot_dbms::CTsdbConnPtr &ptr);
void checkTsdbCommandQueue(); void checkTsdbCommandQueue();
void checkTsdbCommandQueue(bool &bHasPend, QList<TsdbCommand> &listCommand);
private: private:
bool m_TsdbExcuting; bool m_TsdbExcuting;
bool m_bHasPendingCommandCurve; bool m_bHasPending;
bool m_bHasPendingCommandEvent;
bool m_bHasPendingCommandCompute;
iot_dbms::CTsdbConnPtr m_tsdbConnPtr; iot_dbms::CTsdbConnPtr m_tsdbConnPtr;
QList<QList<TsdbCommand>> m_listCommand;
QList<TsdbCommand> m_listCommandCurve;
QList<TsdbCommand> m_listCommandEvent;
QList<TsdbCommand> m_listCommandCompute;
QMutex m_mutex; QMutex m_mutex;
static int m_nProcessNumber; static int m_nProcessNumber;
}; };

View File

@ -1,4 +1,4 @@
#include "CHisEventManage.h" #include "CHisEventManage.h"
#include "service/alarm_server_api/AlarmCommonDef.h" #include "service/alarm_server_api/AlarmCommonDef.h"
#include <QDebug> #include <QDebug>
#include "pub_logger_api/logger.h" #include "pub_logger_api/logger.h"

View File

@ -1,4 +1,4 @@
#ifndef CHISEVENTMANAGE_H #ifndef CHISEVENTMANAGE_H
#define CHISEVENTMANAGE_H #define CHISEVENTMANAGE_H
#include "dbms/db_api_ex/CDbApi.h" #include "dbms/db_api_ex/CDbApi.h"

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
#ifndef CPLOTWIDGET_H #ifndef CPLOTWIDGET_H
#define CPLOTWIDGET_H #define CPLOTWIDGET_H
#include <QWidget> #include <QWidget>
@ -85,10 +85,14 @@ public:
void setClearVisible(bool visible); void setClearVisible(bool visible);
void setEnableAddNanFlag(bool bEnable);
void setAdaptVisible(bool visible); void setAdaptVisible(bool visible);
void setAlarmPointVisible(bool visible); void setAlarmPointVisible(bool visible);
void setPreCurveVisible(bool visible);
void insertCurve(Curve curve); void insertCurve(Curve curve);
void clear(bool clearTitle = false); void clear(bool clearTitle = false);
@ -115,6 +119,10 @@ public:
QColor plotTickPen(); QColor plotTickPen();
void setPlotTickPen(const QColor &color); void setPlotTickPen(const QColor &color);
//用于重新设置自定义界面中的周期间隔
void clearCustomInterval();
void addCustomInterval(const QString &desc,const int &sec);
signals: signals:
void clearCurve(); void clearCurve();
void queryHisEvent(const QString &tag, const int &type, const qint64 &time); void queryHisEvent(const QString &tag, const int &type, const qint64 &time);
@ -122,22 +130,7 @@ signals:
void updateTagCheckState(const QString &tag, const bool &outOfRange); void updateTagCheckState(const QString &tag, const bool &outOfRange);
void releaseHisDataThread(); void releaseHisDataThread();
void releaseHisEventThread(); void releaseHisEventThread();
void sigQueryHistoryRecord(const QList<TsdbCommand> &cmdList);
void sigQueryHistoryOriginalData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
double lower, double upper,
E_Data_Type type = E_HISTORY);
void sigQueryHistoryPolymericData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
double lower, double upper, int nGroupByMinute, iot_dbms::EnComputeMethod method);
void sigQueryHistoryComputeData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
double lower, double upper,
std::vector<iot_dbms::EnComputeMethod> method);
void sigQueryHistoryEvent(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
double lower, double upper,
iot_dbms::EnComputeMethod enCM,
int nGroupByMinute);
void sigAddCollect(int x, int y); void sigAddCollect(int x, int y);
void sigHideCollect(); void sigHideCollect();
@ -165,13 +158,14 @@ private slots:
void updateTrendShowMode(int nIndex, bool updateXAxisRange = true); void updateTrendShowMode(int nIndex, bool updateXAxisRange = true);
void updateComputeValue(double lower, double upper, std::vector<iot_dbms::EnComputeMethod> vecMethod); TsdbCommand getHisCurveCmd(double lower, double upper, int nGroupBy, E_Data_Type type);
TsdbCommand getComputeCmd(double lower, double upper, std::vector<iot_dbms::EnComputeMethod> vecMethod, E_Data_Type type);
void updateCurves(); void updateCurves();
void updateRealTimeCurveRecord(); void updateRealTimeCurveRecord();
void updateHistoryCurveRecord(double lower, double upper); void updateHistoryCurveRecord();
void updateHisOriginalData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void updateHisOriginalData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
std::vector<std::vector<iot_dbms::SVarHisSamplePoint> *> *vecResult, std::vector<std::vector<iot_dbms::SVarHisSamplePoint> *> *vecResult,
@ -179,23 +173,28 @@ private slots:
void updateHisPolymericData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void updateHisPolymericData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
std::vector<std::vector<iot_dbms::SVarHisSamplePoint> *> *vecResult, std::vector<std::vector<iot_dbms::SVarHisSamplePoint> *> *vecResult,
int nGroupBySec); int nGroupBySec,
E_Data_Type type = E_HISTORY);
void updateHisComputeData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void updateHisComputeData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
std::vector<std::pair<iot_dbms::EnComputeMethod, std::vector<std::vector<iot_dbms::SVarHisValue> *> *> > cmResult); std::vector<std::pair<iot_dbms::EnComputeMethod, std::vector<std::vector<iot_dbms::SVarHisValue> *> *> > cmResult,
E_Data_Type type = E_HISTORY);
void updateHistoryGraph(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void updateHistoryGraph(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
std::vector< QSharedPointer<QCPGraphDataContainer> > &vecContainer, std::vector< QSharedPointer<QCPGraphDataContainer> > &vecContainer,
std::vector< QSharedPointer<Range> > &vecRange); std::vector< QSharedPointer<Range> > &vecRange,
E_Data_Type type);
void updateHistoryData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void updateHistoryData(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
std::vector< QSharedPointer<QCPGraphDataContainer> > &vecContainer, std::vector< QSharedPointer<QCPGraphDataContainer> > &vecContainer,
std::vector< QSharedPointer<Range> > &vecRange); std::vector< QSharedPointer<Range> > &vecRange,
E_Data_Type type);
void updateCurveHisData(double lower, double upper, void updateCurveHisData(double lower, double upper,
QCPGraph * graph, int index, QCPGraph * graph, int index,
QSharedPointer<QCPGraphDataContainer> container, QSharedPointer<QCPGraphDataContainer> container,
QSharedPointer<Range> range); QSharedPointer<Range> range,
E_Data_Type type);
void updatePhaseTracer(std::vector<iot_dbms::SMeasPointKey> *vecMpKey, void updatePhaseTracer(std::vector<iot_dbms::SMeasPointKey> *vecMpKey,
std::vector<std::vector<iot_dbms::SHisEventPoint> *> *vecResult); std::vector<std::vector<iot_dbms::SHisEventPoint> *> *vecResult);
@ -204,6 +203,7 @@ private slots:
void updateAxisFormat(bool updateXAxisRange); void updateAxisFormat(bool updateXAxisRange);
QPair<double, double> getFatureDataTime(E_Trend_Type type, QDateTime curTime = QDateTime()); QPair<double, double> getFatureDataTime(E_Trend_Type type, QDateTime curTime = QDateTime());
void updateAdaptState(bool isAdapt); void updateAdaptState(bool isAdapt);
void updatePreCurveState(bool isPreCurve);
void addCollect(); void addCollect();
void slotPrint(); void slotPrint();
void slotExport(); void slotExport();
@ -263,6 +263,7 @@ private:
std::vector< QSharedPointer<Range> > &vecRange, std::vector< QSharedPointer<Range> > &vecRange,
std::vector< QSharedPointer<QCPGraphDataContainer> > &vecContainer, std::vector< QSharedPointer<QCPGraphDataContainer> > &vecContainer,
double lower, double upper, double lower, double upper,
E_Data_Type type,
bool isAddVirtualPoint = false, bool isAddVirtualPoint = false,
int nGroupBySec = 0); int nGroupBySec = 0);
@ -272,7 +273,7 @@ private:
template<typename _Tp> template<typename _Tp>
bool checkStatus(const iot_dbms::SVarHisSamplePoint &var, const int &nInvalid); bool checkStatus(const iot_dbms::SVarHisSamplePoint &var, const int &nInvalid);
void setCurveStatisData(const QString &tag, iot_dbms::EnComputeMethod method, bool reset, const double &value = 0, const double &time = 0); void setCurveStatisData(const QString &tag, const int &curType, iot_dbms::EnComputeMethod method, bool reset, const double &value = 0, const double &time = 0);
bool isMutation(const double &preValue, const double &curValue); bool isMutation(const double &preValue, const double &curValue);
@ -289,11 +290,15 @@ private:
void resetCurveData(const QMap<QString, QVector<QCPGraphData>>& dataMap, const QStringList& headerList, bool ascs = true); void resetCurveData(const QMap<QString, QVector<QCPGraphData>>& dataMap, const QStringList& headerList, bool ascs = true);
void enableSearch(bool enable); void enableSearch(bool enable);
void afterModeSwitch();
QPair<double, double> getOffsetRange(const double &lower, const double &upper, int direction);
double getOffsetTime(const double &time);
private: private:
Ui::CPlotWidget *ui; Ui::CPlotWidget *ui;
E_Trend_Type m_type; E_Trend_Type m_type;
E_Show_Type m_showType; E_Show_Type m_showType;
bool m_bHisAdaption; bool m_bHisAdaption;
bool m_bShowPreCurve;
QButtonGroup * m_TrendTypeButton; QButtonGroup * m_TrendTypeButton;
CCurveLegendModel * m_pLengedModel; CCurveLegendModel * m_pLengedModel;
CTableDataModel * m_pTableDataModel; CTableDataModel * m_pTableDataModel;
@ -331,6 +336,10 @@ private:
bool m_isTooltip; bool m_isTooltip;
bool m_isAdaptShow; bool m_isAdaptShow;
bool m_isAlarmShow; bool m_isAlarmShow;
bool m_isPreCurveShow;
bool m_bEnableNan;//caodingfa:定时存盘周期可变时原有逻辑会导致每个间隔插入一个Nan值导致无效为不影响原逻辑增加一个开关
const int THREE_DAY = 3*24*60*60; // 查询全部数据时, 最多查询3天, 避免数据过多导致界面卡顿
}; };
#endif // CPLOTWIDGET_H #endif // CPLOTWIDGET_H

View File

@ -83,26 +83,28 @@
<property name="verticalSpacing"> <property name="verticalSpacing">
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="2"> <item row="0" column="10">
<widget class="QCheckBox" name="adapt"> <widget class="QWidget" name="widget_2" native="true">
<property name="sizePolicy"> <layout class="QGridLayout" name="gridLayout_4">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred"> <property name="leftMargin">
<horstretch>0</horstretch> <number>0</number>
<verstretch>0</verstretch> </property>
</sizepolicy> <property name="topMargin">
</property> <number>0</number>
<property name="minimumSize"> </property>
<size> <property name="rightMargin">
<width>42</width> <number>0</number>
<height>24</height> </property>
</size> <property name="bottomMargin">
</property> <number>0</number>
<property name="text"> </property>
<string>对比</string> <property name="spacing">
</property> <number>0</number>
<property name="checkable"> </property>
<bool>true</bool> <item row="0" column="0">
</property> <widget class="CSWitchButton" name="switchBtn" native="true"/>
</item>
</layout>
</widget> </widget>
</item> </item>
<item row="0" column="4"> <item row="0" column="4">
@ -124,30 +126,59 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="5"> <item row="0" column="2">
<widget class="QCheckBox" name="adapt">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>24</height>
</size>
</property>
<property name="text">
<string>对比</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QComboBox" name="comboBox_alarmStatus"> <widget class="QComboBox" name="comboBox_alarmStatus">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>130</width> <width>208</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="6"> <item row="0" column="7">
<widget class="QPushButton" name="collectCurve"> <widget class="QPushButton" name="collectCurve">
<property name="text"> <property name="text">
<string>收藏</string> <string>收藏</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="7"> <item row="0" column="8">
<widget class="QPushButton" name="plotExport"> <widget class="QPushButton" name="plotExport">
<property name="text"> <property name="text">
<string>导出</string> <string>导出</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="9">
<widget class="QPushButton" name="plotPrint">
<property name="text">
<string>打印</string>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">
@ -164,13 +195,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="8">
<widget class="QPushButton" name="plotPrint">
<property name="text">
<string>打印</string>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="timeLayout"> <layout class="QGridLayout" name="timeLayout">
<property name="leftMargin"> <property name="leftMargin">
@ -249,28 +273,23 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="9"> <item row="0" column="3">
<widget class="QWidget" name="widget_2" native="true"> <widget class="QCheckBox" name="preCurve">
<layout class="QGridLayout" name="gridLayout_4"> <property name="sizePolicy">
<property name="leftMargin"> <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<number>0</number> <horstretch>0</horstretch>
</property> <verstretch>0</verstretch>
<property name="topMargin"> </sizepolicy>
<number>0</number> </property>
</property> <property name="minimumSize">
<property name="rightMargin"> <size>
<number>0</number> <width>0</width>
</property> <height>24</height>
<property name="bottomMargin"> </size>
<number>0</number> </property>
</property> <property name="text">
<property name="spacing"> <string>昨日曲线</string>
<number>0</number> </property>
</property>
<item row="0" column="0">
<widget class="CSWitchButton" name="switchBtn" native="true"/>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -1,4 +1,4 @@
#include "CRealTimeDataCollect.h" #include "CRealTimeDataCollect.h"
#include "MessageChannel.h" #include "MessageChannel.h"
#include "DataProcMessage.pb.h" #include "DataProcMessage.pb.h"
#include "pub_logger_api/logger.h" #include "pub_logger_api/logger.h"

View File

@ -1,4 +1,4 @@
#ifndef CREALTIMEDATACOLLECT_H #ifndef CREALTIMEDATACOLLECT_H
#define CREALTIMEDATACOLLECT_H #define CREALTIMEDATACOLLECT_H
#include <QThread> #include <QThread>

View File

@ -1,4 +1,4 @@
#include "CTableDataModel.h" #include "CTableDataModel.h"
CTableDataModel::CTableDataModel(QObject *parent) CTableDataModel::CTableDataModel(QObject *parent)
: QAbstractTableModel(parent), : QAbstractTableModel(parent),
@ -20,7 +20,7 @@ void CTableDataModel::clear()
{ {
beginResetModel(); beginResetModel();
m_curveDataMap.clear(); m_curveDataMap.clear();
m_header.clear(); //m_header.clear();
m_timeList.clear(); m_timeList.clear();
m_bAscs = true; m_bAscs = true;
endResetModel(); endResetModel();
@ -227,3 +227,31 @@ QVariant CTableDataModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
CustomHeaderView::CustomHeaderView(Qt::Orientation orientation ,QWidget *parent)
:QHeaderView(orientation,parent)
{
}
CustomHeaderView::~CustomHeaderView()
{
}
void CustomHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
//就简单几句
//拿到text数据在写数据的时候设置textwordwrap,居中。
QString textstr = model()->headerData(visualIndex(logicalIndex),Qt::Horizontal).toString();
painter->save();
//painter->drawText(rect,Qt::TextWordWrap | Qt::AlignCenter, textstr);
// 从当前样式中获取边框颜色
QStyleOptionHeader opt;
initStyleOption(&opt);
opt.rect = rect;
opt.section = logicalIndex;
// 使用样式绘制边框
style()->drawControl(QStyle::CE_HeaderSection, &opt, painter, this);
painter->drawText(rect,Qt::TextWordWrap | Qt::AlignCenter, textstr);
painter->restore();
}

View File

@ -1,4 +1,4 @@
#ifndef CTABLEDATAMODEL_H #ifndef CTABLEDATAMODEL_H
#define CTABLEDATAMODEL_H #define CTABLEDATAMODEL_H
#include <QAbstractTableModel> #include <QAbstractTableModel>
@ -37,5 +37,15 @@ private:
QList<double> m_timeList; QList<double> m_timeList;
bool m_bAscs; bool m_bAscs;
}; };
class CustomHeaderView : public QHeaderView
{
Q_OBJECT
public:
CustomHeaderView(Qt::Orientation orientation = Qt::Horizontal,QWidget *parent = nullptr); //这里为了省事,给默认值为水平表头,因为我正好使用水平的表头
~CustomHeaderView();
protected:
virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
};
#endif // CTABLEDATAMODEL_H #endif // CTABLEDATAMODEL_H

View File

@ -1,4 +1,4 @@
#include "CTableView.h" #include "CTableView.h"
#include <QHeaderView> #include <QHeaderView>
CTableView::CTableView(QWidget *parent) CTableView::CTableView(QWidget *parent)
@ -30,3 +30,35 @@ void CTableView::setTableRowHeight(const int &nHeight)
verticalHeader()->setDefaultSectionSize(m_nTableRowHeight); verticalHeader()->setDefaultSectionSize(m_nTableRowHeight);
} }
void CTableView::showEvent(QShowEvent *event){
QTableView::showEvent(event);
adjustHeaderWidth();
}
// 自动调整表头宽度以适应文本
void CTableView::adjustHeaderWidth() {
QHeaderView *header = horizontalHeader();
int sections = header->count();
int maxWidth = 0;
QFontMetrics fm(header->font());
int maxWidthThreshold = 200; // 设置换行的阈值
for (int i = 0; i < sections; ++i) {
QString text = model()->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
int width = fm.width(text) + 10; // 加上一些额外空间
maxWidth = qMax(maxWidth, width);
}
for (int i = 0; i < sections; ++i) {
QString text = model()->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
int width = fm.width(text) + 10; // 加上一些额外空间
// 如果宽度超过阈值,则换行
if (width > maxWidthThreshold) {
header->resizeSection(i, maxWidthThreshold);
} else {
header->resizeSection(i, maxWidth);
}
}
}

View File

@ -1,4 +1,4 @@
#ifndef CTABLEVIEW_H #ifndef CTABLEVIEW_H
#define CTABLEVIEW_H #define CTABLEVIEW_H
#include <QTableView> #include <QTableView>
@ -17,6 +17,9 @@ public:
int tableRowHeight(); int tableRowHeight();
void setTableRowHeight(const int &nHeight); void setTableRowHeight(const int &nHeight);
void adjustHeaderWidth();
protected:
void showEvent(QShowEvent *event) override ;
private: private:
int m_nTableColWidth; int m_nTableColWidth;

View File

@ -1,9 +1,10 @@
#include <QMessageBox> #include <QMessageBox>
#include "CTrendEditDialog.h" #include "CTrendEditDialog.h"
#include "ui_CTrendEditDialog.h" #include "ui_CTrendEditDialog.h"
#include "CTrendEditModel.h" #include "CTrendEditModel.h"
#include "GraphTool/Retriever/CRetriever.h" #include "GraphTool/Retriever/CRetriever.h"
#include "pub_utility_api/FileUtil.h" #include "pub_utility_api/FileUtil.h"
#include "CTableDataModel.h"
using namespace iot_dbms; using namespace iot_dbms;
@ -16,6 +17,10 @@ CTrendEditDialog::CTrendEditDialog(QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
ui->m_retrieverWidget->setWindowFlags(Qt::Widget); ui->m_retrieverWidget->setWindowFlags(Qt::Widget);
ui->m_retrieverWidget->setMultVisible(false); ui->m_retrieverWidget->setMultVisible(false);
ui->m_retrieverWidget->setCloseBtnVisible(false);
ui->m_retrieverWidget->installEventFilter(this);
ui->frame->setFixedWidth(320);
setMinimumWidth(1200);
//setWindowModality(Qt::WindowModal); //setWindowModality(Qt::WindowModal);
initialize(); initialize();
connect(ui->addCurve, SIGNAL(clicked()), this, SLOT(slot_addCureve())); connect(ui->addCurve, SIGNAL(clicked()), this, SLOT(slot_addCureve()));
@ -53,6 +58,8 @@ void CTrendEditDialog::initTrendView()
ui->trendView->setAlternatingRowColors(true); ui->trendView->setAlternatingRowColors(true);
ui->trendView->horizontalHeader()->setStretchLastSection(true); ui->trendView->horizontalHeader()->setStretchLastSection(true);
ui->trendView->setHorizontalHeader(new CustomHeaderView(Qt::Horizontal,ui->trendView));
connect(ui->trendView->horizontalHeader(),&QHeaderView::sectionCountChanged,ui->trendView,&CTrendEditView::adjustHeaderWidth);
connect(ui->m_retrieverWidget, &CRetriever::itemTagTriggered, ui->trendView, &CTrendEditView::appendTagName); connect(ui->m_retrieverWidget, &CRetriever::itemTagTriggered, ui->trendView, &CTrendEditView::appendTagName);
} }
@ -68,6 +75,16 @@ void CTrendEditDialog::resizeEvent(QResizeEvent *event)
updateTrendViewColumnWidth(); updateTrendViewColumnWidth();
} }
bool CTrendEditDialog::eventFilter(QObject *o, QEvent *e)
{
if( e->type() == QEvent::MouseMove )
{
return true;
}
return QDialog::eventFilter(o, e);
}
void CTrendEditDialog::updateTrendViewColumnWidth() void CTrendEditDialog::updateTrendViewColumnWidth()
{ {

View File

@ -1,4 +1,4 @@
#ifndef CTRENDEDITDIALOG_H #ifndef CTRENDEDITDIALOG_H
#define CTRENDEDITDIALOG_H #define CTRENDEDITDIALOG_H
#include <QDialog> #include <QDialog>
@ -28,6 +28,7 @@ public:
protected: protected:
void showEvent(QShowEvent *event); void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
bool eventFilter(QObject *o, QEvent *e);
protected slots: protected slots:
void slot_updateTrend(); void slot_updateTrend();

View File

@ -1,4 +1,4 @@
#include <QUuid> #include <QUuid>
#include <QPainter> #include <QPainter>
#include <QSpinBox> #include <QSpinBox>
#include "CTrendGraph.h" #include "CTrendGraph.h"

View File

@ -1,4 +1,4 @@
#ifndef CTRENDEDITMODEL_H #ifndef CTRENDEDITMODEL_H
#define CTRENDEDITMODEL_H #define CTRENDEDITMODEL_H
/***************************************** /*****************************************

View File

@ -1,4 +1,4 @@
#include "CTrendEditView.h" #include "CTrendEditView.h"
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QDragMoveEvent> #include <QDragMoveEvent>
#include <QDropEvent> #include <QDropEvent>
@ -50,6 +50,42 @@ void CTrendEditView::appendTagName(const QString &strTagName, const QString &str
} }
} }
void CTrendEditView::adjustHeaderWidth()
{
QHeaderView *header = horizontalHeader();
int sectionCount = header->count();
if (sectionCount == 0 || !model()) {
return;
}
QFontMetrics fontMetrics(header->font());
const int maxWidthThreshold = 200;
const int baseHeight = 30;
int maxHeightMultiplier = 1;
for (int section = 0; section < sectionCount; ++section) {
QString headerText = model()->headerData(section, Qt::Horizontal).toString();
if (headerText.isEmpty()) {
continue;
}
int textWidth = fontMetrics.width(headerText) + 20; // 额外空间
int heightMultiplier = 1;
// 调整宽度和计算换行高度
if (textWidth > maxWidthThreshold) {
header->resizeSection(section, maxWidthThreshold);
heightMultiplier = qCeil(static_cast<qreal>(textWidth) / maxWidthThreshold);
} else {
header->resizeSection(section, textWidth);
}
maxHeightMultiplier = qMax(maxHeightMultiplier, heightMultiplier);
}
header->setFixedHeight(maxHeightMultiplier * baseHeight);
}
void CTrendEditView::dragEnterEvent(QDragEnterEvent *event) void CTrendEditView::dragEnterEvent(QDragEnterEvent *event)
{ {
if (event->mimeData()->hasText()) if (event->mimeData()->hasText())
@ -96,3 +132,9 @@ void CTrendEditView::dropEvent(QDropEvent *event)
} }
event->accept(); event->accept();
} }
void CTrendEditView::showEvent(QShowEvent *event)
{
QTableView::showEvent(event);
adjustHeaderWidth();
}

View File

@ -1,4 +1,4 @@
#ifndef CTRENDEDITVIEW_H #ifndef CTRENDEDITVIEW_H
#define CTRENDEDITVIEW_H #define CTRENDEDITVIEW_H
#include "CTableView.h" #include "CTableView.h"
@ -12,10 +12,12 @@ public:
public slots: public slots:
void appendTagName(const QString &strTagName, const QString &strTagDesc, bool isMulti); void appendTagName(const QString &strTagName, const QString &strTagDesc, bool isMulti);
void adjustHeaderWidth();
protected: protected:
void dragEnterEvent(QDragEnterEvent *event); void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event); void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event);
void showEvent(QShowEvent *event) override ;
}; };
#endif // CTRENDEDITVIEW_H #endif // CTRENDEDITVIEW_H

View File

@ -1,4 +1,4 @@
#include "CTrendFavTreeWidget.h" #include "CTrendFavTreeWidget.h"
#include "CTrendEditDialog.h" #include "CTrendEditDialog.h"
#include <QDir> #include <QDir>
#include <QMenu> #include <QMenu>
@ -159,12 +159,26 @@ void CTrendFavTreeWidget::slotEditTrendEdit()
void CTrendFavTreeWidget::slotRemoveTrendEdit() void CTrendFavTreeWidget::slotRemoveTrendEdit()
{ {
QList<QTreeWidgetItem*> selectItem = selectedItems(); int ret=QMessageBox::question(this, tr("提示"), tr("确定删除所选项吗?"), QMessageBox::Yes,QMessageBox::No);
foreach (QTreeWidgetItem *item, selectItem) { if(QMessageBox::Yes==ret)
int index = indexOfTopLevelItem(item); {
takeTopLevelItem(index); QList<QTreeWidgetItem*> selectItem = selectedItems();
foreach (QTreeWidgetItem *item, selectItem) {
if( m_trendGraphMap.contains(item) )
{
CTrendGraph* graph = m_trendGraphMap[item];
if( graph != NULL )
{
graph->clear();
emit showTrendGraph(graph, "趋势图");
}
}
int index = indexOfTopLevelItem(item);
takeTopLevelItem(index);
}
savaTrendGraph();
} }
savaTrendGraph();
} }
void CTrendFavTreeWidget::slotItemChanged(QTreeWidgetItem *item, int column) void CTrendFavTreeWidget::slotItemChanged(QTreeWidgetItem *item, int column)
@ -181,6 +195,8 @@ void CTrendFavTreeWidget::slotItemChanged(QTreeWidgetItem *item, int column)
return; return;
} }
} }
emit updateTitle(content);
} }
void CTrendFavTreeWidget::slotImport() void CTrendFavTreeWidget::slotImport()
@ -213,7 +229,7 @@ void CTrendFavTreeWidget::slotExport()
QString CTrendFavTreeWidget::getNewValidTitle() QString CTrendFavTreeWidget::getNewValidTitle()
{ {
QString title = QString("自定义趋势_"); QString title = QString(tr("自定义趋势_"));
QStringList listItemText; QStringList listItemText;
for(int nIndex(0); nIndex < topLevelItemCount(); nIndex++) for(int nIndex(0); nIndex < topLevelItemCount(); nIndex++)
{ {
@ -348,6 +364,10 @@ void CTrendFavTreeWidget::savaTrendGraph(const QString &filePath, const QList<QT
for(int nCurveIndex(0); nCurveIndex < listCurve.size(); nCurveIndex++) for(int nCurveIndex(0); nCurveIndex < listCurve.size(); nCurveIndex++)
{ {
Curve curve = listCurve.at(nCurveIndex); Curve curve = listCurve.at(nCurveIndex);
if(curve.curveType != enRealCurve)
{
continue;
}
QDomElement item = document.createElement("item"); QDomElement item = document.createElement("item");
item.setAttribute("tag", curve.tag); item.setAttribute("tag", curve.tag);
item.setAttribute("color", curve.color.rgb()); item.setAttribute("color", curve.color.rgb());

View File

@ -1,4 +1,4 @@
#ifndef CTRENDFAVTREEWIDGET_H #ifndef CTRENDFAVTREEWIDGET_H
#define CTRENDFAVTREEWIDGET_H #define CTRENDFAVTREEWIDGET_H
#include <QTreeWidget> #include <QTreeWidget>
@ -20,6 +20,7 @@ public:
signals: signals:
void showTrendGraph(CTrendGraph * graph, QString name); void showTrendGraph(CTrendGraph * graph, QString name);
void updateTitle(QString name);
public slots: public slots:
void collectGraph(const QString &title, const CTrendGraph &graph); void collectGraph(const QString &title, const CTrendGraph &graph);

View File

@ -1,4 +1,4 @@
#include "CTrendGraph.h" #include "CTrendGraph.h"
#include <QDateTime> #include <QDateTime>
#include "plot/qcustomplot.h" #include "plot/qcustomplot.h"
@ -34,24 +34,28 @@ const QList<QColor> CTrendGraph::curveColors() const
return list; return list;
} }
const Curve &CTrendGraph::curve(const QString &tag) const const Curve &CTrendGraph::curve(const QString &tag, const int &curType) const
{ {
for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++) for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++)
{ {
if(m_listCurve.at(nIndex).tag == tag) if(m_listCurve.at(nIndex).tag == tag && m_listCurve.at(nIndex).curveType == curType)
{ {
return m_listCurve.at(nIndex); return m_listCurve.at(nIndex);
} }
} }
Q_ASSERT_X(false, "CTrendGraph::curve", "curve is not exists"); Q_ASSERT_X(false, "CTrendGraph::curve", "curve is not exists");
static Curve invalid;
return invalid;
} }
int CTrendGraph::index(const QString &tag) const int CTrendGraph::index(const QString &tag, const int &curType) const
{ {
//< TODO 性能
for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++) for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++)
{ {
if(m_listCurve.at(nIndex).tag == tag) if(m_listCurve.at(nIndex).tag == tag && m_listCurve.at(nIndex).curveType == curType)
{ {
return nIndex; return nIndex;
} }
@ -69,17 +73,28 @@ void CTrendGraph::addCurve(const Curve &curve)
m_listCurve.append(curve); m_listCurve.append(curve);
} }
int CTrendGraph::removeCurve(const QString &tag) QList<int> CTrendGraph::removeCurve(const QString &tag)
{ {
QList<int> removeList;
for(int nIndex(m_listCurve.size() - 1); nIndex >= 0; nIndex--) for(int nIndex(m_listCurve.size() - 1); nIndex >= 0; nIndex--)
{ {
if(m_listCurve.at(nIndex).tag == tag) if(m_listCurve.at(nIndex).tag == tag)
{ {
m_listCurve.removeAt(nIndex); m_listCurve.removeAt(nIndex);
return nIndex; removeList.append(nIndex);
} }
} }
return -1; return removeList;
}
bool CTrendGraph::removeCurve(const int &nIndex)
{
if(nIndex < 0 || nIndex >= m_listCurve.size())
{
return false;
}
m_listCurve.removeAt(nIndex);
return true;
} }
void CTrendGraph::setCurveVisible(const int &nIndex, const bool &visible) void CTrendGraph::setCurveVisible(const int &nIndex, const bool &visible)
@ -112,11 +127,11 @@ void CTrendGraph::setCurveGraphOffset(const int &nIndex, const double &offset)
m_listCurve[nIndex].graphOffset = offset; m_listCurve[nIndex].graphOffset = offset;
} }
void CTrendGraph::setCurveHisDataValue(const QString &tag, const double &max, const double &min, const double &maxTime, const double &minTime, const double &average, const double &accuml, const Range &range) void CTrendGraph::setCurveHisDataValue(const QString &tag, const int &curType, const double &max, const double &min, const double &maxTime, const double &minTime, const double &average, const double &accuml, const Range &range)
{ {
for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++) for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++)
{ {
if(m_listCurve.at(nIndex).tag == tag) if(m_listCurve.at(nIndex).tag == tag && m_listCurve.at(nIndex).curveType == curType)
{ {
m_listCurve[nIndex].hisMax = max; m_listCurve[nIndex].hisMax = max;
m_listCurve[nIndex].hisMin = min; m_listCurve[nIndex].hisMin = min;
@ -132,7 +147,7 @@ void CTrendGraph::setCurveHisDataValue(const QString &tag, const double &max, co
void CTrendGraph::pushCurveRTDataValue(const QString &tag, const double &key, const double &value, const int &status) void CTrendGraph::pushCurveRTDataValue(const QString &tag, const double &key, const double &value, const int &status)
{ {
//< 保留20min实时数据 //< 保留20min实时数据
int nIndex = m_listCurve.indexOf(tag); int nIndex = m_listCurve.indexOf(tag); //< 实时数据索引一定在前面
if (-1 == nIndex || qIsNaN(value)) if (-1 == nIndex || qIsNaN(value))
{ {
return; return;
@ -148,11 +163,11 @@ void CTrendGraph::pushCurveRTDataValue(const QString &tag, const double &key, co
} }
} }
void CTrendGraph::setCurveStatisMax(const QString &tag, const double &max, const double &maxTime) void CTrendGraph::setCurveStatisMax(const QString &tag, const int &curType, const double &max, const double &maxTime)
{ {
for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++) for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++)
{ {
if(m_listCurve.at(nIndex).tag == tag) if(m_listCurve.at(nIndex).tag == tag && m_listCurve.at(nIndex).curveType == curType)
{ {
m_listCurve[nIndex].sHisMax = max; m_listCurve[nIndex].sHisMax = max;
m_listCurve[nIndex].sHisMaxTime = maxTime; m_listCurve[nIndex].sHisMaxTime = maxTime;
@ -160,11 +175,11 @@ void CTrendGraph::setCurveStatisMax(const QString &tag, const double &max, const
} }
} }
void CTrendGraph::setCurveStatisMin(const QString &tag, const double &min, const double &minTime) void CTrendGraph::setCurveStatisMin(const QString &tag, const int &curType, const double &min, const double &minTime)
{ {
for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++) for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++)
{ {
if(m_listCurve.at(nIndex).tag == tag) if(m_listCurve.at(nIndex).tag == tag && m_listCurve.at(nIndex).curveType == curType)
{ {
m_listCurve[nIndex].sHisMin = min; m_listCurve[nIndex].sHisMin = min;
m_listCurve[nIndex].sHisMinTime = minTime; m_listCurve[nIndex].sHisMinTime = minTime;
@ -172,11 +187,11 @@ void CTrendGraph::setCurveStatisMin(const QString &tag, const double &min, const
} }
} }
void CTrendGraph::resetCurveStatisMax(const QString &tag) void CTrendGraph::resetCurveStatisMax(const QString &tag, const int &curType)
{ {
for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++) for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++)
{ {
if(m_listCurve.at(nIndex).tag == tag) if(m_listCurve.at(nIndex).tag == tag && m_listCurve.at(nIndex).curveType == curType)
{ {
m_listCurve[nIndex].sHisMax = -DBL_MAX; m_listCurve[nIndex].sHisMax = -DBL_MAX;
m_listCurve[nIndex].sHisMaxTime = -DBL_MAX; m_listCurve[nIndex].sHisMaxTime = -DBL_MAX;
@ -184,11 +199,11 @@ void CTrendGraph::resetCurveStatisMax(const QString &tag)
} }
} }
void CTrendGraph::resetCurveStatisMin(const QString &tag) void CTrendGraph::resetCurveStatisMin(const QString &tag, const int &curType)
{ {
for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++) for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++)
{ {
if(m_listCurve.at(nIndex).tag == tag) if(m_listCurve.at(nIndex).tag == tag && m_listCurve.at(nIndex).curveType == curType)
{ {
m_listCurve[nIndex].sHisMin = DBL_MAX; m_listCurve[nIndex].sHisMin = DBL_MAX;
m_listCurve[nIndex].sHisMinTime = DBL_MAX; m_listCurve[nIndex].sHisMinTime = DBL_MAX;
@ -196,11 +211,11 @@ void CTrendGraph::resetCurveStatisMin(const QString &tag)
} }
} }
void CTrendGraph::updateRTCurveStatisticsInfo(const QString &strTagName) void CTrendGraph::updateRTCurveStatisticsInfo(const QString &strTagName, const int &curType)
{ {
for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++) for(int nIndex(0); nIndex < m_listCurve.size(); nIndex++)
{ {
if(m_listCurve.at(nIndex).tag == strTagName) if(m_listCurve.at(nIndex).tag == strTagName && m_listCurve.at(nIndex).curveType == curType)
{ {
updateRTCurveStatisticsInfo(m_listCurve[nIndex]); updateRTCurveStatisticsInfo(m_listCurve[nIndex]);
return; return;

View File

@ -1,4 +1,4 @@
#ifndef CTRENDGRAPH_H #ifndef CTRENDGRAPH_H
#define CTRENDGRAPH_H #define CTRENDGRAPH_H
#include <QString> #include <QString>
@ -28,9 +28,15 @@ struct Range
double max; double max;
}; };
enum Type
{
enRealCurve = 0, //< 实际测点曲线
enPrevCurve //< 昨日曲线
};
struct Curve struct Curve
{ {
Curve(const QString &strTagName = QString()) Curve(const QString &strTagName = QString(), Type type = enRealCurve)
: visible(true), : visible(true),
rtMax(-DBL_MAX), rtMax(-DBL_MAX),
rtMin(DBL_MAX), rtMin(DBL_MAX),
@ -56,11 +62,12 @@ struct Curve
desc(QString()), desc(QString()),
type(QString()), type(QString()),
unit(QString()), unit(QString()),
color(QColor()){} color(QColor()),
curveType(type){}
inline bool operator==(const Curve &curve) const inline bool operator==(const Curve &curve) const
{ {
return tag == curve.tag; return ((tag == curve.tag) && (curveType == curve.curveType));
} }
inline bool operator==(const QString &strTagName) const inline bool operator==(const QString &strTagName) const
@ -97,6 +104,7 @@ struct Curve
QString type; QString type;
QString unit; QString unit;
QColor color; QColor color;
Type curveType;
QVector< QPair <double, QPair< double, int > > > values; QVector< QPair <double, QPair< double, int > > > values;
}; };
@ -113,13 +121,14 @@ public:
const QList<QColor> curveColors() const; const QList<QColor> curveColors() const;
const Curve &curve(const QString &tag) const; const Curve &curve(const QString &tag, const int &curType) const;
int index(const QString &tag) const; int index(const QString &tag, const int &curType = enRealCurve) const;
void clear(); void clear();
void addCurve(const Curve &curve); void addCurve(const Curve &curve);
int removeCurve(const QString &tag); QList<int> removeCurve(const QString &tag);
bool removeCurve(const int &nIndex);
void setCurveVisible(const int &nIndex, const bool &visible); void setCurveVisible(const int &nIndex, const bool &visible);
@ -127,20 +136,20 @@ public:
void setCurveFactor(const int &nIndex, const double &factor); void setCurveFactor(const int &nIndex, const double &factor);
void setCurveOffset(const int &nIndex, const double &offset); void setCurveOffset(const int &nIndex, const double &offset);
void setCurveHisDataValue(const QString &tag, const double &max, const double &min, const double &maxTime, const double &minTime, const double &average, const double &accuml, const Range &range); void setCurveHisDataValue(const QString &tag, const int &curType, const double &max, const double &min, const double &maxTime, const double &minTime, const double &average, const double &accuml, const Range &range);
void pushCurveRTDataValue(const QString &tag, const double &key, const double &value, const int &status); void pushCurveRTDataValue(const QString &tag, const double &key, const double &value, const int &status);
void setCurveStatisMax(const QString &tag, const double &max, const double &maxTime); void setCurveStatisMax(const QString &tag, const int &curType, const double &max, const double &maxTime);
void setCurveStatisMin(const QString &tag, const double &min, const double &minTime); void setCurveStatisMin(const QString &tag, const int &curType, const double &min, const double &minTime);
void resetCurveStatisMax(const QString &tag); void resetCurveStatisMax(const QString &tag, const int &curType);
void resetCurveStatisMin(const QString &tag); void resetCurveStatisMin(const QString &tag, const int &curType);
void setCurveGraphFactor(const int &nIndex, const double &factor); void setCurveGraphFactor(const int &nIndex, const double &factor);
void setCurveGraphOffset(const int &nIndex, const double &offset); void setCurveGraphOffset(const int &nIndex, const double &offset);
//< 更新实时曲线统计信息 //< 更新实时曲线统计信息
void updateRTCurveStatisticsInfo(const QString &strTagName); void updateRTCurveStatisticsInfo(const QString &strTagName, const int &curType);
void updateRTCurveStatisticsInfo(Curve &curve); void updateRTCurveStatisticsInfo(Curve &curve);
private: private:

View File

@ -1,10 +1,11 @@
#include "CTrendInfoManage.h" #include "CTrendInfoManage.h"
#include "service/perm_mng_api/PermMngApi.h" #include "service/perm_mng_api/PermMngApi.h"
#include "pub_sysinfo_api/SysInfoApi.h" #include "pub_sysinfo_api/SysInfoApi.h"
#include "pub_utility_api/CharUtil.h" #include "pub_utility_api/CharUtil.h"
#include "pub_utility_api/FileUtil.h" #include "pub_utility_api/FileUtil.h"
#include "perm_mng_api/PermMngApi.h" #include "perm_mng_api/PermMngApi.h"
#include "pub_logger_api/logger.h" #include "pub_logger_api/logger.h"
#include <QDomDocument>
using namespace iot_dbms; using namespace iot_dbms;
using namespace iot_public; using namespace iot_public;
@ -23,6 +24,8 @@ CTrendInfoManage *CTrendInfoManage::instance()
CTrendInfoManage::CTrendInfoManage() CTrendInfoManage::CTrendInfoManage()
{ {
m_bLoadTagInfoWhenInit = false; //默认加载所有信息
loadCfg(); //加载配置文件,会重新覆盖掉默认参数值
//< 实时库 //< 实时库
m_rtdbAccess = new iot_dbms::CRdbAccess(); m_rtdbAccess = new iot_dbms::CRdbAccess();
@ -40,7 +43,13 @@ CTrendInfoManage::CTrendInfoManage()
loadRTLocation(); loadRTLocation();
loadDevGroupInfo(pReadDb); loadDevGroupInfo(pReadDb);
loadDeviceInfo(pReadDb); loadDeviceInfo(pReadDb);
loadTagInfo(pReadDb);
//通过setEnableDynamicLoadTag函数加载了默认不加载测点防止测点太多打开趋势页面太慢
//loadAllTagInfo(pReadDb);
if(m_bLoadTagInfoWhenInit)
{
loadAllTagInfo(pReadDb);
}
loadStateDefine(); loadStateDefine();
loadAlarmStatusDefine(); loadAlarmStatusDefine();
loadAlarmStatus(); loadAlarmStatus();
@ -61,7 +70,6 @@ void CTrendInfoManage::destory()
m_locationInfo.clear(); m_locationInfo.clear();
m_devGroupInfo.clear(); m_devGroupInfo.clear();
m_devLocation.clear();
m_deviceInfo.clear(); m_deviceInfo.clear();
m_listTagName.clear(); m_listTagName.clear();
m_listTagInfo.clear(); m_listTagInfo.clear();
@ -255,6 +263,50 @@ QMap<int, QString> CTrendInfoManage::getAlarmOtherStatus()
return m_alarmOtherStatus; return m_alarmOtherStatus;
} }
bool CTrendInfoManage::loadTagInfoByDevGroup(const QString &strDevGrpTag)
{
auto iter = m_deviceInfo.find(strDevGrpTag);
if(iter == m_deviceInfo.end())
{
return false;
}
return loadTagInfoByDevTag(iter.value().keys());
}
bool CTrendInfoManage::loadTagInfoByDevTag(const QStringList &listDevTag)
{
QStringList queryDevTag;
foreach (QString strCur, listDevTag)
{
if(m_listTagName.contains(strCur)) //已经加载过了就不再加载了
{
continue;
}
queryDevTag.push_back(strCur);
}
if(queryDevTag.isEmpty())
{
return false;
}
CDbApi * pReadDb = new CDbApi(DB_CONN_MODEL_READ);
if(!pReadDb->open())
{
delete pReadDb;
pReadDb = Q_NULLPTR;
return false;
}
bool bRet = loadTagInfo(pReadDb,listDevTag);
delete pReadDb;
pReadDb = Q_NULLPTR;
return bRet;
}
void CTrendInfoManage::loadRTLocation() void CTrendInfoManage::loadRTLocation()
{ {
iot_service::CPermMngApiPtr permMngPtr = iot_service::getPermMngInstance("base"); iot_service::CPermMngApiPtr permMngPtr = iot_service::getPermMngInstance("base");
@ -377,18 +429,21 @@ void CTrendInfoManage::loadDeviceInfo(CDbApi *pReadDb)
pReadDb->execute(sqlSequenceQuery, query); pReadDb->execute(sqlSequenceQuery, query);
while(query.next()) while(query.next())
{ {
const QString &tag_name = query.value(0).toString(); //const QString &tag_name = query.value(0).toString();
const QString &description = query.value(1).toString(); //const QString &description = query.value(1).toString();
const QString &group_tag_name = query.value(2).toString(); //const QString &group_tag_name = query.value(2).toString();
const int location_id = query.value(0).toInt();
m_deviceInfo[group_tag_name].insert(tag_name, description); m_deviceInfo[query.value(2).toString()].insert(query.value(0).toString(), query.value(1).toString());
m_devLocation[location_id].insert(tag_name, description);
} }
} }
void CTrendInfoManage::loadTagInfo(CDbApi *pReadDb) bool CTrendInfoManage::loadTagInfo(CDbApi *pReadDb, const QStringList &listDevice)
{ {
if(listDevice.isEmpty())
{
return false;
}
QSqlQuery query; QSqlQuery query;
QStringList listType; QStringList listType;
listType.append(QStringLiteral("analog")); listType.append(QStringLiteral("analog"));
@ -396,19 +451,8 @@ void CTrendInfoManage::loadTagInfo(CDbApi *pReadDb)
listType.append(QStringLiteral("accuml")); listType.append(QStringLiteral("accuml"));
// listType.append(QString("mix")); // listType.append(QString("mix"));
QString strDeviceFilter; QString strDeviceFilter = "'" % listDevice.join("', '") % "'";
if(!m_deviceInfo.isEmpty()) strDeviceFilter = QString("(%1 in (%2))").arg("device").arg(strDeviceFilter);
{
QStringList listDevice;
QMap<QString, QMap<QString, QString> >::const_iterator iter = m_deviceInfo.constBegin();
while (iter != m_deviceInfo.constEnd())
{
listDevice.append(iter.value().keys());
++iter;
}
strDeviceFilter = "'" % listDevice.join("', '") % "'";
strDeviceFilter = QString("(%1 in (%2))").arg("device").arg(strDeviceFilter);
}
query.setForwardOnly(true); query.setForwardOnly(true);
for(int nIndex(0); nIndex < listType.size(); nIndex++) for(int nIndex(0); nIndex < listType.size(); nIndex++)
@ -425,6 +469,7 @@ FROM %2 as t1 left join dev_info as t2 on t1.device = t2.tag_name").arg(strUnitF
{ {
sqlSequenceQuery.append(QString(" WHERE %1 ORDER BY SEQ_NO asc;").arg(strDeviceFilter)); sqlSequenceQuery.append(QString(" WHERE %1 ORDER BY SEQ_NO asc;").arg(strDeviceFilter));
} }
pReadDb->execute(sqlSequenceQuery, query); pReadDb->execute(sqlSequenceQuery, query);
while(query.next()) while(query.next())
{ {
@ -436,18 +481,25 @@ FROM %2 as t1 left join dev_info as t2 on t1.device = t2.tag_name").arg(strUnitF
//const QString devDesc = query.value(5).toString(); //const QString devDesc = query.value(5).toString();
const QString strDescription = m_locationInfo[location] % QChar('.') % m_devGroupInfo[location][query.value(0).toString()] % QChar('.') % query.value(5).toString() % QChar('.') % query.value(2).toString(); const QString strDescription = m_locationInfo[location] % QChar('.') % m_devGroupInfo[location][query.value(0).toString()] % QChar('.') % query.value(5).toString() % QChar('.') % query.value(2).toString();
m_listTagName[device] << tagName; m_listTagName[device] << tagName;
//QString strUnitDesc = m_listTagUnit.value(query.value(5).toInt(), QString()); //QString strUnitDesc = m_listTagUnit.value(query.value(5).toInt(), QString());
// m_listTagInfo[tagName] = QStringList() << strDescription << strCurType << m_listTagUnit.value(query.value(5).toInt(), QString()); m_listTagInfo[tagName] = QStringList() << strDescription << strCurType << m_listTagUnit.value(query.value(6).toInt(), QString());
QString strUnitDesc ="";
if(QStringLiteral("analog") == strCurType || QStringLiteral("accuml") == strCurType)
{
strUnitDesc = m_listTagUnit.value(query.value(6).toInt(), QString());
}
m_listTagInfo[tagName] = QStringList() << strDescription << strCurType << strUnitDesc;
} }
} }
return true;
}
void CTrendInfoManage::loadAllTagInfo(iot_dbms::CDbApi *pReadDb)
{
QStringList listDevice;
QMap<QString, QMap<QString, QString> >::const_iterator iter = m_deviceInfo.constBegin();
while (iter != m_deviceInfo.constEnd())
{
listDevice.append(iter.value().keys());
++iter;
}
loadTagInfo(pReadDb,listDevice);
} }
void CTrendInfoManage::loadUnit(CDbApi *pReadDb) void CTrendInfoManage::loadUnit(CDbApi *pReadDb)
@ -608,3 +660,47 @@ void CTrendInfoManage::initInvalidStatus()
m_nInvalidDigital |= (temp << getStateActualValue("MENU_STATE_DI_SINHIBIT_REF")); //< 屏蔽禁止刷新 m_nInvalidDigital |= (temp << getStateActualValue("MENU_STATE_DI_SINHIBIT_REF")); //< 屏蔽禁止刷新
m_nInvalidDigital |= (temp << getStateActualValue("MENU_STATE_DI_SOURCE_ABNORMAL"));//< 数据来源不正常 m_nInvalidDigital |= (temp << getStateActualValue("MENU_STATE_DI_SOURCE_ABNORMAL"));//< 数据来源不正常
} }
void CTrendInfoManage::loadCfg()
{
QDomDocument document;
QString strFileName = QString::fromStdString(iot_public::CFileUtil::getCurModuleDir()) + QString("../../data/model/trend.xml");
QFile file(strFileName);
if (!file.open(QIODevice::ReadOnly))
{
return;
}
if (!document.setContent(&file))
{
file.close();
return;
}
file.close();
QDomElement root = document.documentElement();
if(root.isNull())
{
return;
}
QDomNodeList paramNodeList = root.elementsByTagName("param");
for(int graphIndex(0); graphIndex < paramNodeList.size(); graphIndex++)
{
QDomNode paramNode = paramNodeList.at(graphIndex);
if(paramNode.isNull())
{
continue;
}
QDomElement paramElement = paramNode.toElement();
if(!paramElement.isNull())
{
QString name = paramElement.attribute("name", QString());
QString value = paramElement.attribute("value", QString());
if(name == "loadTagInfoWhenInit")
{
m_bLoadTagInfoWhenInit = (value == "1");
}
}
}
}

View File

@ -1,4 +1,4 @@
#ifndef CTRENDINFOMANAGE_H #ifndef CTRENDINFOMANAGE_H
#define CTRENDINFOMANAGE_H #define CTRENDINFOMANAGE_H
#include <QMap> #include <QMap>
@ -7,7 +7,19 @@
#include <QStringList> #include <QStringList>
#include "dbms/rdb_api/CRdbAccess.h" #include "dbms/rdb_api/CRdbAccess.h"
#include "dbms/db_api_ex/CDbApi.h" #include "dbms/db_api_ex/CDbApi.h"
//< 屏蔽xml_parser编译告警
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#endif
#include "boost/property_tree/xml_parser.hpp" #include "boost/property_tree/xml_parser.hpp"
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#include "boost/typeof/typeof.hpp" #include "boost/typeof/typeof.hpp"
#include "boost/filesystem.hpp" #include "boost/filesystem.hpp"
@ -62,13 +74,20 @@ public:
QMap<int, QString> getAlarmOtherStatus(); QMap<int, QString> getAlarmOtherStatus();
//加载指定设备组下测点的信息,为空代表加载所有设备组的测点
bool loadTagInfoByDevGroup(const QString &strDevGrpTag);
//加载指定设备下的测点信息,为空代表加载所有设备
bool loadTagInfoByDevTag(const QStringList &listDevTag);
private: private:
CTrendInfoManage(); CTrendInfoManage();
void loadRTLocation(); void loadRTLocation();
void loadDevGroupInfo(iot_dbms::CDbApi *pReadDb); //新增设备组 void loadDevGroupInfo(iot_dbms::CDbApi *pReadDb); //新增设备组
void loadDeviceInfo(iot_dbms::CDbApi *pReadDb); //新增设备组时修改 void loadDeviceInfo(iot_dbms::CDbApi *pReadDb); //新增设备组时修改
void loadTagInfo(iot_dbms::CDbApi *pReadDb); //strDevGrpTag为空加载所有设备组如果不为空加载指定的设备组
bool loadTagInfo(iot_dbms::CDbApi *pReadDb,const QStringList &listDevice = QStringList());
void loadAllTagInfo(iot_dbms::CDbApi *pReadDb);
void loadUnit(iot_dbms::CDbApi *pReadDb); void loadUnit(iot_dbms::CDbApi *pReadDb);
void loadStateDefine(); void loadStateDefine();
void loadAlarmStatusDefine(); void loadAlarmStatusDefine();
@ -76,12 +95,13 @@ private:
void loadAlarmOtherStatus(); void loadAlarmOtherStatus();
void initInvalidStatus(); void initInvalidStatus();
void loadCfg();
private: private:
iot_dbms::CRdbAccess * m_rtdbAccess; iot_dbms::CRdbAccess * m_rtdbAccess;
QMap<int, QString> m_locationInfo; //< LocationID-LocationDesc QMap<int, QString> m_locationInfo; //< LocationID-LocationDesc
QMap<int, QMap<QString, QString> > m_devGroupInfo; //< LocationID-<DevGroupName-DevGroupDesc> 新增设备组 QMap<int, QMap<QString, QString> > m_devGroupInfo; //< LocationID-<DevGroupName-DevGroupDesc> 新增设备组
QMap<int, QList<QPair<QString,QString > > > m_devGroupInfoMap; QMap<int, QList<QPair<QString,QString > > > m_devGroupInfoMap;
QMap<int, QMap<QString, QString> > m_devLocation; //< LocationID-<DeviceName-DeviceDesc> 新增设备组
QMap<QString, QMap<QString, QString> > m_deviceInfo; //< DevGroupName-<DeviceName-DeviceDesc> 新增设备组时修改 QMap<QString, QMap<QString, QString> > m_deviceInfo; //< DevGroupName-<DeviceName-DeviceDesc> 新增设备组时修改
QMap<QString, QStringList> m_listTagName; //< DeviceName-list<TagName> QMap<QString, QStringList> m_listTagName; //< DeviceName-list<TagName>
QHash<QString, QStringList> m_listTagInfo; //< TagName-TagInfo<desc, type, unit> QHash<QString, QStringList> m_listTagInfo; //< TagName-TagInfo<desc, type, unit>
@ -93,7 +113,7 @@ private:
QList<int> m_locationOrderList; //< location_id: 按location_no排序 QList<int> m_locationOrderList; //< location_id: 按location_no排序
int m_nInvalidAnalog; int m_nInvalidAnalog;
int m_nInvalidDigital; int m_nInvalidDigital;
bool m_bLoadTagInfoWhenInit; //第一次是否加载所有的测点数据,默认加载
static CTrendInfoManage * m_pInstance; static CTrendInfoManage * m_pInstance;
}; };

View File

@ -1,4 +1,4 @@
#include <QWidget> #include <QWidget>
#include "CTrendPluginWidget.h" #include "CTrendPluginWidget.h"
#include "CTrendWindow.h" #include "CTrendWindow.h"

View File

@ -1,4 +1,4 @@
#ifndef CTRENDPLUGINWIDGET_H #ifndef CTRENDPLUGINWIDGET_H
#define CTRENDPLUGINWIDGET_H #define CTRENDPLUGINWIDGET_H
#include <QObject> #include <QObject>
@ -7,7 +7,7 @@
class CTrendPluginWidget : public QObject, public CPluginWidgetInterface class CTrendPluginWidget : public QObject, public CPluginWidgetInterface
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "kbd.PluginWidgetInterface/1.0") Q_PLUGIN_METADATA(IID HMI_WidgetPlugin_IID)
Q_INTERFACES(CPluginWidgetInterface) Q_INTERFACES(CPluginWidgetInterface)
public: public:

View File

@ -1,4 +1,4 @@
#include <QStringList> #include <QStringList>
#include "CTrendTreeItem.h" #include "CTrendTreeItem.h"
CTrendTreeItem::CTrendTreeItem(int type) CTrendTreeItem::CTrendTreeItem(int type)

View File

@ -1,4 +1,4 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/

View File

@ -1,4 +1,4 @@
#include "CTrendTreeModel.h" #include "CTrendTreeModel.h"
#include "CTrendInfoManage.h" #include "CTrendInfoManage.h"
#include <QTimer> #include <QTimer>
#include "pub_logger_api/logger.h" #include "pub_logger_api/logger.h"
@ -65,13 +65,12 @@ void CTrendTreeModel::initTrendTagInfo()
++iter_device; ++iter_device;
continue; continue;
} }
// QTreeWidgetItem * devItem = new QTreeWidgetItem(devGroupItem, QStringList() << iter_device.value(), DEV_TYPE); QTreeWidgetItem * devItem = new QTreeWidgetItem(devGroupItem, QStringList() << iter_device.value(), DEV_TYPE);
// devItem->setData(0, ItemTagRole, iter_device.key()); devItem->setData(0, ItemTagRole, iter_device.key());
QStringList::const_iterator iter_tag = listTagName.constBegin(); QStringList::const_iterator iter_tag = listTagName.constBegin();
while (iter_tag != listTagName.constEnd()) while (iter_tag != listTagName.constEnd())
{ {
// QTreeWidgetItem * tagItem = new QTreeWidgetItem(devItem, QStringList() << CTrendInfoManage::instance()->getTagDescription(*iter_tag).section(".", -1), TAG_TYPE); QTreeWidgetItem * tagItem = new QTreeWidgetItem(devItem, QStringList() << CTrendInfoManage::instance()->getTagDescription(*iter_tag).section(".", -1), TAG_TYPE);
QTreeWidgetItem * tagItem = new QTreeWidgetItem(devGroupItem, QStringList() << CTrendInfoManage::instance()->getTagDescription(*iter_tag).section(".", -1), TAG_TYPE);
tagItem->setData(0, ItemTagRole, *iter_tag); tagItem->setData(0, ItemTagRole, *iter_tag);
tagItem->setToolTip(0, *iter_tag); tagItem->setToolTip(0, *iter_tag);
++iter_tag; ++iter_tag;
@ -86,10 +85,10 @@ void CTrendTreeModel::initTrendTagInfo()
{ {
return; return;
} }
for(int n=0; n<m_rootItem->childCount(); n++) // for(int n=0; n<m_rootItem->childCount(); n++)
{ // {
m_pView->expand(index(n,0)); // m_pView->expand(index(n,0));
} // }
} }
void CTrendTreeModel::clearTrendTagInfo() void CTrendTreeModel::clearTrendTagInfo()
@ -210,7 +209,6 @@ QVariant CTrendTreeModel::data(const QModelIndex &index, int role) const
bool CTrendTreeModel::setData(const QModelIndex &index, const QVariant &value, int role) bool CTrendTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
if(!index.isValid()) if(!index.isValid())
{ {
return false; return false;
@ -221,7 +219,11 @@ bool CTrendTreeModel::setData(const QModelIndex &index, const QVariant &value, i
{ {
if(Qt::CheckStateRole == role) if(Qt::CheckStateRole == role)
{ {
emit itemCheckStateChanged(item->data(0, ItemTagRole).toString(), value.toInt()); //只有状态发生变化才更新,否则在单个设备测点数量过多的时候,清空动作会时间很长
if(item->checkState(0) != value.toInt())
{
emit itemCheckStateChanged(item->data(0, ItemTagRole).toString(), value.toInt());
}
} }
item->setData(index.column(), role, value); item->setData(index.column(), role, value);
} }
@ -254,8 +256,7 @@ void CTrendTreeModel::setChildrenCheckState(const QModelIndex &index, const Qt::
{ {
return; return;
} }
// if(DEV_TYPE == item->type()) if(DEV_TYPE == item->type())
if(DEV_GROUP_TYPE == item->type())
{ {
for(int nChildIndex(0); nChildIndex < item->childCount(); nChildIndex++) for(int nChildIndex(0); nChildIndex < item->childCount(); nChildIndex++)
{ {
@ -279,6 +280,22 @@ void CTrendTreeModel::updateNodeVisualState(const QString &content, QItemSelecti
} }
} }
void CTrendTreeModel::loadTagInfoByDevGroup(const QString &strDevGrpTag)
{
if(CTrendInfoManage::instance()->loadTagInfoByDevGroup(strDevGrpTag))
{
initTrendTagInfo();
}
}
void CTrendTreeModel::loadTagInfoByDevTag(const QStringList &listDevTag)
{
if(CTrendInfoManage::instance()->loadTagInfoByDevTag(listDevTag))
{
initTrendTagInfo();
}
}
bool CTrendTreeModel::traverNode(const QString &content, const QModelIndex &index, QItemSelection &selection) bool CTrendTreeModel::traverNode(const QString &content, const QModelIndex &index, QItemSelection &selection)
{ {
if(!index.isValid()) if(!index.isValid())
@ -378,16 +395,16 @@ void CTrendTreeModel::updateTagCheckState(const QString &tag, const bool &checke
QTreeWidgetItem * deviceGroupItem = locationItem->child(nDeviceGroupRow); QTreeWidgetItem * deviceGroupItem = locationItem->child(nDeviceGroupRow);
for(int nDeviceRow(0); nDeviceRow < deviceGroupItem->childCount(); nDeviceRow++) for(int nDeviceRow(0); nDeviceRow < deviceGroupItem->childCount(); nDeviceRow++)
{ {
// QTreeWidgetItem * deviceItem = deviceGroupItem->child(nDeviceRow); QTreeWidgetItem * deviceItem = deviceGroupItem->child(nDeviceRow);
// for(int nTagRow(0); nTagRow < deviceItem->childCount(); nTagRow++) for(int nTagRow(0); nTagRow < deviceItem->childCount(); nTagRow++)
// { {
QTreeWidgetItem * tagItem = deviceGroupItem->child(nDeviceRow); QTreeWidgetItem * tagItem = deviceItem->child(nTagRow);
if(tag == tagItem->data(0, ItemTagRole).toString()) if(tag == tagItem->data(0, ItemTagRole).toString())
{ {
tagItem->setCheckState(0, checked ? Qt::Checked : Qt::Unchecked); tagItem->setCheckState(0, checked ? Qt::Checked : Qt::Unchecked);
return; return;
} }
// } }
} }
} }
} }

View File

@ -1,4 +1,4 @@
#ifndef CTRENDTREEMODEL_H #ifndef CTRENDTREEMODEL_H
#define CTRENDTREEMODEL_H #define CTRENDTREEMODEL_H
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
@ -45,6 +45,12 @@ public:
void updateNodeVisualState(const QString &content, QItemSelection &selection); void updateNodeVisualState(const QString &content, QItemSelection &selection);
//加载指定设备组下测点的信息,为空代表加载所有设备组的测点
void loadTagInfoByDevGroup(const QString &strDevGrpTag);
//加载指定设备下的测点信息,为空代表加载所有设备
void loadTagInfoByDevTag(const QStringList &listDevTag);
signals: signals:
void itemCheckStateChanged(const QString &strTagName, const int &checkedState); void itemCheckStateChanged(const QString &strTagName, const int &checkedState);

View File

@ -1,4 +1,4 @@
#include "CTrendTreeView.h" #include "CTrendTreeView.h"
#include "CTrendTreeModel.h" #include "CTrendTreeModel.h"
#include <QMenu> #include <QMenu>
#include <QMouseEvent> #include <QMouseEvent>
@ -18,8 +18,7 @@ void CTrendTreeView::contextMenuEvent(QContextMenuEvent *event)
QTreeWidgetItem * pItem = static_cast<QTreeWidgetItem*>(indexAt(event->pos()).internalPointer()); QTreeWidgetItem * pItem = static_cast<QTreeWidgetItem*>(indexAt(event->pos()).internalPointer());
if(Q_NULLPTR != pItem) if(Q_NULLPTR != pItem)
{ {
// if(DEV_TYPE == pItem->type()) if(DEV_TYPE == pItem->type())
if(DEV_GROUP_TYPE == pItem->type())
{ {
QMenu menu; QMenu menu;
menu.addAction(tr("全选"), [=](){ pModel->setChildrenCheckState(indexAt(event->pos()), Qt::Checked); }); menu.addAction(tr("全选"), [=](){ pModel->setChildrenCheckState(indexAt(event->pos()), Qt::Checked); });
@ -54,6 +53,12 @@ void CTrendTreeView::mouseDoubleClickEvent(QMouseEvent *event)
pModel->setData(index, state, Qt::CheckStateRole); pModel->setData(index, state, Qt::CheckStateRole);
update(); update();
} }
else if(DEV_GROUP_TYPE == pItem->type())
{
int row=pModel->parent(index).row();
pModel->loadTagInfoByDevGroup(pItem->data(0,ItemTagRole).toString());
expand(pModel->index(row,0));
}
} }
} }
return QTreeView::mouseDoubleClickEvent(event); return QTreeView::mouseDoubleClickEvent(event);

View File

@ -1,4 +1,4 @@
#include "CTrendWindow.h" #include "CTrendWindow.h"
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include <QSplitter> #include <QSplitter>
@ -218,6 +218,14 @@ void CTrendWindow::setAlarmPointVisible(bool visible)
} }
} }
void CTrendWindow::setPreCurveVisible(bool visible)
{
if(m_plotWidget)
{
m_plotWidget->setPreCurveVisible(visible);
}
}
void CTrendWindow::initWindow() void CTrendWindow::initWindow()
{ {
m_pTagWidget = new QTabWidget(this); m_pTagWidget = new QTabWidget(this);
@ -246,6 +254,8 @@ void CTrendWindow::initWindow()
m_pTagWidget->addTab(pFavoritesTreeWidget, tr("收藏夹")); m_pTagWidget->addTab(pFavoritesTreeWidget, tr("收藏夹"));
m_pTagWidget->setContentsMargins(1,1,1,1); m_pTagWidget->setContentsMargins(1,1,1,1);
m_pTagWidget->setCurrentIndex(1); m_pTagWidget->setCurrentIndex(1);
m_pTagWidget->setMinimumWidth(290);
m_plotWidget = new CPlotWidget(this); m_plotWidget = new CPlotWidget(this);
m_plotWidget->initialize(); m_plotWidget->initialize();
m_pSplitter = new QSplitter(this); m_pSplitter = new QSplitter(this);
@ -264,6 +274,7 @@ void CTrendWindow::initWindow()
connect(m_plotWidget, &CPlotWidget::updateTagCheckState, m_pTrendTreeModel, &CTrendTreeModel::updateTagCheckState, Qt::QueuedConnection); connect(m_plotWidget, &CPlotWidget::updateTagCheckState, m_pTrendTreeModel, &CTrendTreeModel::updateTagCheckState, Qt::QueuedConnection);
connect(m_pTrendTreeModel, &CTrendTreeModel::itemCheckStateChanged, this, &CTrendWindow::itemCheckStateChanged); connect(m_pTrendTreeModel, &CTrendTreeModel::itemCheckStateChanged, this, &CTrendWindow::itemCheckStateChanged);
connect(pFavoritesTreeWidget, &CTrendFavTreeWidget::showTrendGraph, this, &CTrendWindow::showTrendGraph); connect(pFavoritesTreeWidget, &CTrendFavTreeWidget::showTrendGraph, this, &CTrendWindow::showTrendGraph);
connect(pFavoritesTreeWidget, &CTrendFavTreeWidget::updateTitle, this, &CTrendWindow::setTitle);
if(!m_isEditMode) if(!m_isEditMode)
{ {
@ -480,6 +491,13 @@ void CTrendWindow::updateTrendName(const QString &title)
void CTrendWindow::showTrendGraph(CTrendGraph *graph, const QString &name) void CTrendWindow::showTrendGraph(CTrendGraph *graph, const QString &name)
{ {
QStringList devList;
foreach (Curve cur, graph->curves()) {
devList << cur.tag.left(cur.tag.lastIndexOf("."));
}
m_pTrendTreeModel->loadTagInfoByDevTag(devList);
m_plotWidget->clear(); m_plotWidget->clear();
if(!name.isEmpty()) if(!name.isEmpty())
{ {
@ -541,3 +559,27 @@ bool CTrendWindow::eventFilter(QObject *watched, QEvent *event)
return QWidget::eventFilter(watched, event); return QWidget::eventFilter(watched, event);
} }
void CTrendWindow::setEnableAddNanFlag(bool bEnable)
{
if(m_plotWidget)
{
m_plotWidget->setEnableAddNanFlag(bEnable);
}
}
void CTrendWindow::clearCustomInterval()
{
if(m_plotWidget)
{
m_plotWidget->clearCustomInterval();
}
}
void CTrendWindow::addCustomInterval(const QString &desc, const int &sec)
{
if(m_plotWidget)
{
m_plotWidget->addCustomInterval(desc,sec);
}
}

View File

@ -1,4 +1,4 @@
#ifndef CTRENDWINDOW_H #ifndef CTRENDWINDOW_H
#define CTRENDWINDOW_H #define CTRENDWINDOW_H
#include <QWidget> #include <QWidget>
@ -48,6 +48,12 @@ public slots:
void setDevTreeVisible(bool visible); void setDevTreeVisible(bool visible);
void setAdaptVisible(bool visible); void setAdaptVisible(bool visible);
void setAlarmPointVisible(bool visible); void setAlarmPointVisible(bool visible);
void setPreCurveVisible(bool visible);
void setEnableAddNanFlag(bool bEnable); //caodingfa:定时存盘周期可变时原有逻辑会导致每个间隔插入一个Nan值导致无效为不影响原逻辑增加一个开关
//用于重新设置自定义界面中的周期间隔
void clearCustomInterval();
void addCustomInterval(const QString &desc,const int &sec);
void login(); void login();
void logout(); void logout();

View File

@ -7,6 +7,7 @@
QT += core gui widgets sql xml printsupport QT += core gui widgets sql xml printsupport
TARGET = TrendCurves TARGET = TrendCurves
TEMPLATE = lib TEMPLATE = lib
@ -14,6 +15,7 @@ CONFIG += plugin
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
SOURCES += \ SOURCES += \
$$PWD/plot/qcustomplot.cpp \ $$PWD/plot/qcustomplot.cpp \
$$PWD/widgets/CTabButton.cpp \ $$PWD/widgets/CTabButton.cpp \
@ -23,6 +25,8 @@ SOURCES += \
$$PWD/widgets/QxtSpanSlider.cpp \ $$PWD/widgets/QxtSpanSlider.cpp \
$$PWD/widgets/CSWitchButton.cpp \ $$PWD/widgets/CSWitchButton.cpp \
$$PWD/widgets/CSliderRangeWidget.cpp \ $$PWD/widgets/CSliderRangeWidget.cpp \
$$PWD/widgets/CMyCheckBox.cpp \
$$PWD/widgets/CMyListWidget.cpp \
CTrendWindow.cpp \ CTrendWindow.cpp \
CTrendGraph.cpp \ CTrendGraph.cpp \
CPlotWidget.cpp \ CPlotWidget.cpp \
@ -39,11 +43,8 @@ SOURCES += \
CTrendTreeView.cpp \ CTrendTreeView.cpp \
CHisDataManage.cpp \ CHisDataManage.cpp \
CCurveLegendView.cpp \ CCurveLegendView.cpp \
CMyCheckBox.cpp \
CMyListWidget.cpp \
CTableDataModel.cpp \ CTableDataModel.cpp \
CTableView.cpp CTableView.cpp
# main.cpp
HEADERS += \ HEADERS += \
$$PWD/plot/qcustomplot.h \ $$PWD/plot/qcustomplot.h \
@ -55,6 +56,8 @@ HEADERS += \
$$PWD/widgets/QxtSpanSlider_p.h \ $$PWD/widgets/QxtSpanSlider_p.h \
$$PWD/widgets/CSWitchButton.h \ $$PWD/widgets/CSWitchButton.h \
$$PWD/widgets/CSliderRangeWidget.h \ $$PWD/widgets/CSliderRangeWidget.h \
$$PWD/widgets/CMyCheckBox.h \
$$PWD/widgets/CMyListWidget.h \
CTrendWindow.h \ CTrendWindow.h \
CTrendGraph.h \ CTrendGraph.h \
CPlotWidget.h \ CPlotWidget.h \
@ -71,8 +74,6 @@ HEADERS += \
CTrendTreeView.h \ CTrendTreeView.h \
CHisDataManage.h \ CHisDataManage.h \
CCurveLegendView.h \ CCurveLegendView.h \
CMyCheckBox.h \
CMyListWidget.h \
CTableDataModel.h \ CTableDataModel.h \
CTableView.h CTableView.h
@ -83,7 +84,7 @@ FORMS += \
LIBS += -llog4cplus -lboost_system -lprotobuf -lpub_logger_api -lmodel_excel LIBS += -llog4cplus -lboost_system -lprotobuf -lpub_logger_api -lmodel_excel
LIBS += -lpub_utility_api -lpub_sysinfo_api LIBS += -lpub_utility_api -lpub_sysinfo_api
LIBS += -ldb_base_api -ldb_api_ex -lrdb_api -lrdb_net_api -ltsdb_api -ldb_his_query_api LIBS += -ldb_base_api -ldb_api_ex -lrdb_api -lrdb_net_api -ltsdb_api -ldb_his_query_api
LIBS += -lnet_msg_bus_api -lperm_mng_api -ldp_chg_data_api -lRetriever LIBS += -lnet_msg_bus_api -lperm_mng_api -ldp_chg_data_api -lRetriever -lpub_widget
include($$PWD/../../../idl_files/idl_files.pri) include($$PWD/../../../idl_files/idl_files.pri)

View File

@ -1,4 +1,4 @@
#include <QApplication> #include <QApplication>
#include "CTrendWindow.h" #include "CTrendWindow.h"
#include "pub_logger_api/logger.h" #include "pub_logger_api/logger.h"
#include "dp_chg_data_api/CDpcdaForApp.h" #include "dp_chg_data_api/CDpcdaForApp.h"
@ -18,7 +18,7 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
if(perm->SysLogin("1", "1", 1, 12*60*60, "hmi") != 0) if(perm->SysLogin("admin", "admin", 1, 12*60*60, "hmi") != 0)
{ {
return -1; return -1;
} }

View File

@ -1,4 +1,4 @@
/*************************************************************************** /***************************************************************************
** ** ** **
** QCustomPlot, an easy to use, modern plotting widget for Qt ** ** QCustomPlot, an easy to use, modern plotting widget for Qt **
** Copyright (C) 2011-2017 Emanuel Eichhammer ** ** Copyright (C) 2011-2017 Emanuel Eichhammer **
@ -6062,16 +6062,23 @@ QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale,
QVector<double> QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) QVector<double> QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range)
{ {
QVector<double> result = QCPAxisTicker::createTickVector(tickStep, range); QVector<double> result = QCPAxisTicker::createTickVector(tickStep, range);
if (!result.isEmpty()) if (!result.isEmpty())
{ {
if (mDateStrategy == dsUniformTimeInDay) if (mDateStrategy == dsUniformTimeInDay)
{ {
QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible
QDateTime tickDateTime; QDateTime tickDateTime;
int nOffsetToUTC = 0 - uniformDateTime.offsetFromUtc();
for (int i=0; i<result.size(); ++i) for (int i=0; i<result.size(); ++i)
{ {
tickDateTime = keyToDateTime(result.at(i)); tickDateTime = keyToDateTime(result.at(i));
tickDateTime.setTime(uniformDateTime.time()); tickDateTime.setTime(uniformDateTime.time());
if(i != 0 && i != result.size() - 1)
{
tickDateTime = tickDateTime.addSecs(nOffsetToUTC);
}
result[i] = dateTimeToKey(tickDateTime); result[i] = dateTimeToKey(tickDateTime);
} }
} else if (mDateStrategy == dsUniformDayInMonth) } else if (mDateStrategy == dsUniformDayInMonth)
@ -6090,7 +6097,16 @@ QVector<double> QCPAxisTickerDateTime::createTickVector(double tickStep, const Q
tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay));
result[i] = dateTimeToKey(tickDateTime); result[i] = dateTimeToKey(tickDateTime);
} }
} else if(tickStep >= 43200000)
{
QDateTime curTime = QDateTime::currentDateTime();
int nOffset = curTime.offsetFromUtc() * 1000;
for(int i = 1; i < result.size() - 1;++i)
{
result[i] = result[i] - nOffset;
}
} }
} }
return result; return result;
} }
@ -10732,6 +10748,11 @@ void QCPAbstractPlottable::setDesc(const QString &desc)
mDesc = desc; mDesc = desc;
} }
void QCPAbstractPlottable::setType(const int &type)
{
mType = type;
}
/*! /*!
Sets whether fills of this plottable are drawn antialiased or not. Sets whether fills of this plottable are drawn antialiased or not.

View File

@ -1,4 +1,4 @@
/*************************************************************************** /***************************************************************************
** ** ** **
** QCustomPlot, an easy to use, modern plotting widget for Qt ** ** QCustomPlot, an easy to use, modern plotting widget for Qt **
** Copyright (C) 2011-2017 Emanuel Eichhammer ** ** Copyright (C) 2011-2017 Emanuel Eichhammer **
@ -3310,6 +3310,7 @@ public:
// getters: // getters:
QString name() const { return mName; } QString name() const { return mName; }
QString desc() const { return mDesc; } QString desc() const { return mDesc; }
int type() const { return mType; }
bool antialiasedFill() const { return mAntialiasedFill; } bool antialiasedFill() const { return mAntialiasedFill; }
bool antialiasedScatters() const { return mAntialiasedScatters; } bool antialiasedScatters() const { return mAntialiasedScatters; }
QPen pen() const { return mPen; } QPen pen() const { return mPen; }
@ -3324,6 +3325,7 @@ public:
// setters: // setters:
void setName(const QString &name); void setName(const QString &name);
void setDesc(const QString &desc); void setDesc(const QString &desc);
void setType(const int &type);
void setAntialiasedFill(bool enabled); void setAntialiasedFill(bool enabled);
void setAntialiasedScatters(bool enabled); void setAntialiasedScatters(bool enabled);
void setPen(const QPen &pen); void setPen(const QPen &pen);
@ -3362,6 +3364,7 @@ protected:
// property members: // property members:
QString mName; QString mName;
QString mDesc; QString mDesc;
int mType;
bool mAntialiasedFill, mAntialiasedScatters; bool mAntialiasedFill, mAntialiasedScatters;
QPen mPen; QPen mPen;
QBrush mBrush; QBrush mBrush;

View File

@ -1,4 +1,4 @@
#include "CEditCollectWidget.h" #include "CEditCollectWidget.h"
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel> #include <QLabel>

View File

@ -1,4 +1,4 @@
#ifndef CEDITCOLLECTWIDGET_H #ifndef CEDITCOLLECTWIDGET_H
#define CEDITCOLLECTWIDGET_H #define CEDITCOLLECTWIDGET_H
#include <QDialog> #include <QDialog>

View File

@ -1,4 +1,4 @@
#include "CMyCheckBox.h" #include "CMyCheckBox.h"
#include <QMouseEvent> #include <QMouseEvent>
CMyCheckBox::CMyCheckBox(QString text, QWidget *parent) CMyCheckBox::CMyCheckBox(QString text, QWidget *parent)

View File

@ -1,4 +1,4 @@
#ifndef MYCHECKBOX_H #ifndef MYCHECKBOX_H
#define MYCHECKBOX_H #define MYCHECKBOX_H
#include <QCheckBox> #include <QCheckBox>

View File

@ -1,4 +1,4 @@
#include "CMyListWidget.h" #include "CMyListWidget.h"
CMyListWidget::CMyListWidget(QWidget *parent):QListWidget(parent) CMyListWidget::CMyListWidget(QWidget *parent):QListWidget(parent)
{ {

View File

@ -1,4 +1,4 @@
#ifndef CMYLISTWIDGET_H #ifndef CMYLISTWIDGET_H
#define CMYLISTWIDGET_H #define CMYLISTWIDGET_H
#include <QListWidget> #include <QListWidget>

View File

@ -1,4 +1,4 @@
#include <QPainter> #include <QPainter>
#include <QMouseEvent> #include <QMouseEvent>
#include <QPainterPath> #include <QPainterPath>
#include "CSWitchButton.h" #include "CSWitchButton.h"
@ -34,15 +34,18 @@ void CSWitchButton::paintEvent(QPaintEvent *event)
QColor background; QColor background;
QColor handleColor; QColor handleColor;
QString text; QString text;
QString unSelectText;
if (isEnabled()) { // 可用状态 if (isEnabled()) { // 可用状态
if (m_bChecked) { // 打开状态 if (m_bChecked) { // 打开状态
background = m_checkedColor; background = m_checkedColor;
handleColor = m_handleColor; handleColor = m_handleColor;
text = m_strText; text = m_strText;
unSelectText=m_strCheckText;
} else { //关闭状态 } else { //关闭状态
background = m_background; background = m_background;
handleColor = m_handleColor; handleColor = m_handleColor;
text = m_strCheckText; text = m_strCheckText;
unSelectText=m_strText;
} }
} else { // 不可用状态 } else { // 不可用状态
background = m_disabledColor; background = m_disabledColor;
@ -59,6 +62,7 @@ void CSWitchButton::paintEvent(QPaintEvent *event)
painter.drawRoundedRect(QRectF(m_nX - (m_nHeight / 2), m_nY - (m_nHeight / 2), width()/2, height()), m_radius, m_radius); painter.drawRoundedRect(QRectF(m_nX - (m_nHeight / 2), m_nY - (m_nHeight / 2), width()/2, height()), m_radius, m_radius);
painter.setPen(m_textColor); painter.setPen(m_textColor);
painter.drawText(QRectF(width()/2 - m_nX + (m_nHeight / 2), height()/5, width()/2, height()), text); painter.drawText(QRectF(width()/2 - m_nX + (m_nHeight / 2), height()/5, width()/2, height()), text);
painter.drawText(QRectF(m_nX, height()/5, width()/2, height()), unSelectText);
} }
// 鼠标按下事件 // 鼠标按下事件

View File

@ -1,4 +1,4 @@
#ifndef SWITCHBUTTON_H #ifndef SWITCHBUTTON_H
#define SWITCHBUTTON_H #define SWITCHBUTTON_H
#include <QWidget> #include <QWidget>

View File

@ -1,4 +1,4 @@
#include "CSliderRangeWidget.h" #include "CSliderRangeWidget.h"
#include <QGridLayout> #include <QGridLayout>
#include <QLabel> #include <QLabel>
#include <QSpinBox> #include <QSpinBox>

View File

@ -1,4 +1,4 @@
#ifndef CSLIDERRANGEWIDGET_H #ifndef CSLIDERRANGEWIDGET_H
#define CSLIDERRANGEWIDGET_H #define CSLIDERRANGEWIDGET_H
#include <QDialog> #include <QDialog>

View File

@ -1,4 +1,4 @@
#include "CTabButton.h" #include "CTabButton.h"
#include <QPainter> #include <QPainter>
#include "CCalendarWidget.h" #include "CCalendarWidget.h"

View File

@ -1,4 +1,4 @@
#ifndef CTABBUTTON_H #ifndef CTABBUTTON_H
#define CTABBUTTON_H #define CTABBUTTON_H
#include <QPushButton> #include <QPushButton>

View File

@ -1,4 +1,4 @@
#include "CToolTip.h" #include "CToolTip.h"
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QHBoxLayout> #include <QHBoxLayout>
@ -74,7 +74,7 @@ void CToolTip::on_pushButton_clicked()
QString alarmTime,alarmContent; QString alarmTime,alarmContent;
QStringList header; QStringList header;
header<<tr("时间")<<tr("告警内容"); header<<tr("时间")<<tr("告警内容");
model->setHorizontalHeaderLabels(header); model->setHorizontalHeaderLabels(header);
QHeaderView *rowHeader = alarmTable->verticalHeader(); QHeaderView *rowHeader = alarmTable->verticalHeader();
rowHeader->setHidden(true); rowHeader->setHidden(true);
for(int i = 0;i < rowCount;i++) for(int i = 0;i < rowCount;i++)
@ -91,7 +91,7 @@ void CToolTip::on_pushButton_clicked()
alarmTable->setModel(model); alarmTable->setModel(model);
alarmTable->resizeColumnsToContents(); alarmTable->resizeColumnsToContents();
alarmTable->setObjectName("m_tipAlarmTable"); alarmTable->setObjectName("m_tipAlarmTable");
alarmTable->resize(470,300); alarmTable->resize(800,400);
alarmTable->setWindowFlags(alarmTable->windowFlags()&~(Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint)); alarmTable->setWindowFlags(alarmTable->windowFlags()&~(Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint));
alarmTable->horizontalHeader()->setStretchLastSection(true); alarmTable->horizontalHeader()->setStretchLastSection(true);
alarmTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); alarmTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

View File

@ -1,4 +1,4 @@
#ifndef CTOOLTIP_H #ifndef CTOOLTIP_H
#define CTOOLTIP_H #define CTOOLTIP_H
#include <QDialog> #include <QDialog>

View File

@ -1,4 +1,4 @@
#include "QxtSpanSlider.h" #include "QxtSpanSlider.h"
/**************************************************************************** /****************************************************************************
** Copyright (c) 2006 - 2011, the LibQxt project. ** Copyright (c) 2006 - 2011, the LibQxt project.
** See the Qxt AUTHORS file for a list of authors and copyright holders. ** See the Qxt AUTHORS file for a list of authors and copyright holders.

View File

@ -1,4 +1,4 @@
#ifndef QXTSPANSLIDER_H #ifndef QXTSPANSLIDER_H
/**************************************************************************** /****************************************************************************
** Copyright (c) 2006 - 2011, the LibQxt project. ** Copyright (c) 2006 - 2011, the LibQxt project.
** See the Qxt AUTHORS file for a list of authors and copyright holders. ** See the Qxt AUTHORS file for a list of authors and copyright holders.