From 01f6a1ca4bdf4452ee673c3393cff15f044cf07a Mon Sep 17 00:00:00 2001 From: shi_jq Date: Mon, 17 Mar 2025 16:44:49 +0800 Subject: [PATCH] =?UTF-8?q?[ref]=E5=90=8C=E6=AD=A5711=20711=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/TrendCurves/CCurveLegendModel.cpp | 2 +- .../plugin/TrendCurves/CCurveLegendModel.h | 2 +- .../plugin/TrendCurves/CCurveLegendView.cpp | 47 +- .../gui/plugin/TrendCurves/CCurveLegendView.h | 5 +- .../gui/plugin/TrendCurves/CHisDataManage.cpp | 213 ++--- .../gui/plugin/TrendCurves/CHisDataManage.h | 37 +- .../plugin/TrendCurves/CHisEventManage.cpp | 2 +- .../gui/plugin/TrendCurves/CHisEventManage.h | 2 +- .../gui/plugin/TrendCurves/CPlotWidget.cpp | 892 +++++++++++------- .../src/gui/plugin/TrendCurves/CPlotWidget.h | 59 +- .../src/gui/plugin/TrendCurves/CPlotWidget.ui | 125 +-- .../TrendCurves/CRealTimeDataCollect.cpp | 2 +- .../plugin/TrendCurves/CRealTimeDataCollect.h | 2 +- .../plugin/TrendCurves/CTableDataModel.cpp | 32 +- .../gui/plugin/TrendCurves/CTableDataModel.h | 12 +- .../src/gui/plugin/TrendCurves/CTableView.cpp | 34 +- .../src/gui/plugin/TrendCurves/CTableView.h | 5 +- .../plugin/TrendCurves/CTrendEditDialog.cpp | 19 +- .../gui/plugin/TrendCurves/CTrendEditDialog.h | 3 +- .../plugin/TrendCurves/CTrendEditModel.cpp | 2 +- .../gui/plugin/TrendCurves/CTrendEditModel.h | 2 +- .../gui/plugin/TrendCurves/CTrendEditView.cpp | 44 +- .../gui/plugin/TrendCurves/CTrendEditView.h | 4 +- .../TrendCurves/CTrendFavTreeWidget.cpp | 34 +- .../plugin/TrendCurves/CTrendFavTreeWidget.h | 3 +- .../gui/plugin/TrendCurves/CTrendGraph.cpp | 57 +- .../src/gui/plugin/TrendCurves/CTrendGraph.h | 35 +- .../plugin/TrendCurves/CTrendInfoManage.cpp | 160 +++- .../gui/plugin/TrendCurves/CTrendInfoManage.h | 28 +- .../plugin/TrendCurves/CTrendPluginWidget.cpp | 2 +- .../plugin/TrendCurves/CTrendPluginWidget.h | 4 +- .../gui/plugin/TrendCurves/CTrendTreeItem.cpp | 2 +- .../gui/plugin/TrendCurves/CTrendTreeItem.h | 2 +- .../plugin/TrendCurves/CTrendTreeModel.cpp | 53 +- .../gui/plugin/TrendCurves/CTrendTreeModel.h | 8 +- .../gui/plugin/TrendCurves/CTrendTreeView.cpp | 11 +- .../gui/plugin/TrendCurves/CTrendWindow.cpp | 44 +- .../src/gui/plugin/TrendCurves/CTrendWindow.h | 8 +- .../gui/plugin/TrendCurves/TrendCurves.pro | 13 +- product/src/gui/plugin/TrendCurves/main.cpp | 4 +- .../plugin/TrendCurves/plot/qcustomplot.cpp | 23 +- .../gui/plugin/TrendCurves/plot/qcustomplot.h | 5 +- .../widgets/CEditCollectWidget.cpp | 2 +- .../TrendCurves/widgets/CEditCollectWidget.h | 2 +- .../TrendCurves/{ => widgets}/CMyCheckBox.cpp | 2 +- .../TrendCurves/{ => widgets}/CMyCheckBox.h | 2 +- .../{ => widgets}/CMyListWidget.cpp | 2 +- .../TrendCurves/{ => widgets}/CMyListWidget.h | 2 +- .../TrendCurves/widgets/CSWitchButton.cpp | 6 +- .../TrendCurves/widgets/CSWitchButton.h | 2 +- .../widgets/CSliderRangeWidget.cpp | 2 +- .../TrendCurves/widgets/CSliderRangeWidget.h | 2 +- .../plugin/TrendCurves/widgets/CTabButton.cpp | 2 +- .../plugin/TrendCurves/widgets/CTabButton.h | 2 +- .../plugin/TrendCurves/widgets/CToolTip.cpp | 6 +- .../gui/plugin/TrendCurves/widgets/CToolTip.h | 2 +- .../TrendCurves/widgets/QxtSpanSlider.cpp | 2 +- .../TrendCurves/widgets/QxtSpanSlider.h | 2 +- 58 files changed, 1358 insertions(+), 725 deletions(-) rename product/src/gui/plugin/TrendCurves/{ => widgets}/CMyCheckBox.cpp (91%) rename product/src/gui/plugin/TrendCurves/{ => widgets}/CMyCheckBox.h (92%) rename product/src/gui/plugin/TrendCurves/{ => widgets}/CMyListWidget.cpp (86%) rename product/src/gui/plugin/TrendCurves/{ => widgets}/CMyListWidget.h (89%) diff --git a/product/src/gui/plugin/TrendCurves/CCurveLegendModel.cpp b/product/src/gui/plugin/TrendCurves/CCurveLegendModel.cpp index 276bc1d7..a8a602b6 100644 --- a/product/src/gui/plugin/TrendCurves/CCurveLegendModel.cpp +++ b/product/src/gui/plugin/TrendCurves/CCurveLegendModel.cpp @@ -1,4 +1,4 @@ -#include "CCurveLegendModel.h" +#include "CCurveLegendModel.h" #include "CTrendGraph.h" #include #include diff --git a/product/src/gui/plugin/TrendCurves/CCurveLegendModel.h b/product/src/gui/plugin/TrendCurves/CCurveLegendModel.h index da41db03..98dce1b9 100644 --- a/product/src/gui/plugin/TrendCurves/CCurveLegendModel.h +++ b/product/src/gui/plugin/TrendCurves/CCurveLegendModel.h @@ -1,4 +1,4 @@ -#ifndef CCURVELEGENDMODEL_H +#ifndef CCURVELEGENDMODEL_H #define CCURVELEGENDMODEL_H #include diff --git a/product/src/gui/plugin/TrendCurves/CCurveLegendView.cpp b/product/src/gui/plugin/TrendCurves/CCurveLegendView.cpp index 4d91a875..26799592 100644 --- a/product/src/gui/plugin/TrendCurves/CCurveLegendView.cpp +++ b/product/src/gui/plugin/TrendCurves/CCurveLegendView.cpp @@ -1,7 +1,9 @@ -#include "CCurveLegendView.h" +#include "CCurveLegendView.h" #include "CCurveLegendModel.h" #include #include +#include +#include CCurveLegendView::CCurveLegendView(QWidget *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(textWidth) / maxWidthThreshold); + } else { + header->resizeSection(section, textWidth); + } + + maxHeightMultiplier = qMax(maxHeightMultiplier, heightMultiplier); + } + + header->setFixedHeight(maxHeightMultiplier * baseHeight); +} + + void CCurveLegendView::contextMenuEvent(QContextMenuEvent *event) { CCurveLegendModel * pModel = dynamic_cast(model()); @@ -27,3 +66,9 @@ void CCurveLegendView::contextMenuEvent(QContextMenuEvent *event) return; } +void CCurveLegendView::showEvent(QShowEvent *event) +{ + QTableView::showEvent(event); + adjustHeaderWidth(); +} + diff --git a/product/src/gui/plugin/TrendCurves/CCurveLegendView.h b/product/src/gui/plugin/TrendCurves/CCurveLegendView.h index 832dc223..fbda0eec 100644 --- a/product/src/gui/plugin/TrendCurves/CCurveLegendView.h +++ b/product/src/gui/plugin/TrendCurves/CCurveLegendView.h @@ -1,4 +1,4 @@ -#ifndef CCURVELEGENDVIEW_H +#ifndef CCURVELEGENDVIEW_H #define CCURVELEGENDVIEW_H #include "CTableView.h" @@ -9,8 +9,11 @@ class CCurveLegendView : public CTableView public: CCurveLegendView(QWidget *parent = Q_NULLPTR); + void adjustHeaderWidth(); + protected: void contextMenuEvent(QContextMenuEvent *event); + void showEvent(QShowEvent *event) override ; }; #endif // CCURVELEGENDVIEW_H diff --git a/product/src/gui/plugin/TrendCurves/CHisDataManage.cpp b/product/src/gui/plugin/TrendCurves/CHisDataManage.cpp index 7918993d..705a3e0f 100644 --- a/product/src/gui/plugin/TrendCurves/CHisDataManage.cpp +++ b/product/src/gui/plugin/TrendCurves/CHisDataManage.cpp @@ -1,7 +1,6 @@ -#include "CHisDataManage.h" +#include "CHisDataManage.h" #include "db_his_query_api/DbHisQueryApi.h" #include "sample_server_api/SampleDefine.h" -#include "CTrendInfoManage.h" #include "pub_logger_api/logger.h" using namespace iot_dbms; @@ -10,9 +9,7 @@ int CHisDataManage::m_nProcessNumber = 0; CHisDataManage::CHisDataManage(QObject *parent) : QObject(parent), m_TsdbExcuting(false), - m_bHasPendingCommandCurve(false), - m_bHasPendingCommandEvent(false), - m_bHasPendingCommandCompute(false), + m_bHasPending(false), m_tsdbConnPtr((CTsdbConn*)nullptr) { initTsdbApi(); @@ -28,26 +25,15 @@ CHisDataManage::~CHisDataManage() releaseTsdbApi(); } - foreach (TsdbCommand cmd, m_listCommandCurve) - { - cmd.pVecMpKey->clear(); - delete cmd.pVecMpKey; + foreach (QList cmdList, m_listCommand) { + foreach (TsdbCommand cmd, cmdList) + { + cmd.pVecMpKey->clear(); + delete cmd.pVecMpKey; + } + cmdList.clear(); } - m_listCommandCurve.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(); + m_listCommand.clear(); } bool CHisDataManage::isTsdbExuting() @@ -56,41 +42,47 @@ bool CHisDataManage::isTsdbExuting() return m_TsdbExcuting; } -void CHisDataManage::postTsdbCommandQueue(E_His_Type type, std::vector *vecMpKey, double lower, double upper, int nGroupBySec, std::vector vecCM) +void CHisDataManage::postTsdbCommandQueue(const QList &cmd) { 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 &cmdList) +{ { - case E_ORIGINAL: - case E_POLYMERIC: + QMutexLocker locker(&m_mutex); + 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; - m_listCommandCurve.push_back(cmd); - 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; + QMutexLocker locker(&m_mutex); + m_TsdbExcuting = false; } + checkTsdbCommandQueue(); } void CHisDataManage::release() @@ -134,65 +126,41 @@ bool CHisDataManage::getValidTsdbConnPtr(iot_dbms::CTsdbConnPtr &ptr) void CHisDataManage::checkTsdbCommandQueue() { - checkTsdbCommandQueue(m_bHasPendingCommandCurve, m_listCommandCurve); - checkTsdbCommandQueue(m_bHasPendingCommandEvent, m_listCommandEvent); - checkTsdbCommandQueue(m_bHasPendingCommandCompute, m_listCommandCompute); -} - -void CHisDataManage::checkTsdbCommandQueue(bool &bHasPend, QList &listCommand) -{ - if(bHasPend) + if(m_bHasPending) { - bHasPend = false; - TsdbCommand cmd; + m_bHasPending = false; + QList cmdList; { QMutexLocker locker(&m_mutex); - if(!listCommand.isEmpty()) + if(!m_listCommand.isEmpty()) { - cmd = listCommand.takeLast(); + cmdList = m_listCommand.takeLast(); } } - if(E_ORIGINAL == cmd.type) - { - 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); - } + queryHistoryRecord(cmdList); } else { - foreach (TsdbCommand cmd, listCommand) + foreach (QList cmdList, m_listCommand) { - std::vector::iterator it = cmd.pVecMpKey->begin(); - while(it != cmd.pVecMpKey->end()) - { - free( (char*)it->m_pszTagName ); - ++it; + foreach (TsdbCommand cmd, cmdList) { + std::vector::iterator it = cmd.pVecMpKey->begin(); + while(it != cmd.pVecMpKey->end()) + { + free( (char*)it->m_pszTagName ); + ++it; + } + cmd.pVecMpKey->clear(); + delete cmd.pVecMpKey; } - cmd.pVecMpKey->clear(); - delete cmd.pVecMpKey; + cmdList.clear(); } - listCommand.clear(); + m_listCommand.clear(); } } void CHisDataManage::queryHistoryOriginalData(std::vector *vecMpKey, double lower, double upper, E_Data_Type type) { - { - QMutexLocker locker(&m_mutex); - m_TsdbExcuting = true; - } - double nIntervalSecs = SAMPLE_CYC_MIN * 60 * 1000; std::vector *> *vecResult = new std::vector *>(); @@ -203,13 +171,11 @@ void CHisDataManage::queryHistoryOriginalData(std::vector *vecMpK { vecResult->push_back(new std::vector()); } - emit sigHisSearch(true); if(!getHisSamplePoint(*tsdbConnPtr, 10000, *vecMpKey, lower - nIntervalSecs, upper + nIntervalSecs, NULL, NULL, CM_NULL, 0, FM_NULL_METHOD, *vecResult)) { LOGINFO("TrendCurve CHisDataManage::queryHistoryOriginalData: 查询超时!"); } - emit sigHisSearch(false); } else { @@ -217,21 +183,10 @@ void CHisDataManage::queryHistoryOriginalData(std::vector *vecMpK } emit sigupdateHisOriginalData(vecMpKey, vecResult, type); - - { - QMutexLocker locker(&m_mutex); - m_TsdbExcuting = false; - } - checkTsdbCommandQueue(); } -void CHisDataManage::queryHistoryPolymericData(std::vector *vecMpKey, double lower, double upper, int nGroupBySec, const EnComputeMethod &enCm) +void CHisDataManage::queryHistoryPolymericData(std::vector *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; std::vector *> *vecResult = new std::vector *>(); @@ -242,35 +197,22 @@ void CHisDataManage::queryHistoryPolymericData(std::vector *vecMp { vecResult->push_back(new std::vector()); } - emit sigHisSearch(true); if(!getHisSamplePoint(*tsdbConnPtr, 10000, *vecMpKey, lower - nIntervalSecs, upper + nIntervalSecs, NULL, NULL, enCm, nGroupBySec * 1000, FM_NULL_METHOD, *vecResult)) { LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 查询超时!"); } - emit sigHisSearch(false); } else { LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 未获取到有效的TSDB连接!"); } - emit sigHistoryPolymericData(vecMpKey, vecResult, nGroupBySec); - - { - QMutexLocker locker(&m_mutex); - m_TsdbExcuting = false; - } - checkTsdbCommandQueue(); + emit sigHistoryPolymericData(vecMpKey, vecResult, nGroupBySec, type); } -void CHisDataManage::queryHistoryComputeData(std::vector *vecMpKey, double lower, double upper, const std::vector &vecCM) +void CHisDataManage::queryHistoryComputeData(std::vector *vecMpKey, double lower, double upper, const std::vector &vecCM, E_Data_Type type) { - { - QMutexLocker locker(&m_mutex); - m_TsdbExcuting = true; - } - std::vector *> *> > cmResult; iot_dbms::CTsdbConnPtr tsdbConnPtr; @@ -283,7 +225,6 @@ void CHisDataManage::queryHistoryComputeData(std::vector *vecMpKe { vecResult->push_back(new std::vector()); } - emit sigHisSearch(true); if(!getHisValue(*tsdbConnPtr, 10000, *vecMpKey, lower, upper, NULL, NULL, NULL, NULL, NULL, vecCM[nCmIndex], 0, FM_NULL_METHOD, *vecResult)) { @@ -293,7 +234,6 @@ void CHisDataManage::queryHistoryComputeData(std::vector *vecMpKe tmp.first = vecCM[nCmIndex]; tmp.second = vecResult; cmResult.push_back(tmp); - emit sigHisSearch(false); } } else @@ -301,22 +241,11 @@ void CHisDataManage::queryHistoryComputeData(std::vector *vecMpKe LOGINFO("TrendCurve CHisDataManage::queryHistoryComputeData: 未获取到有效的TSDB连接!"); } - emit sigHistoryComputeData(vecMpKey, cmResult); - - { - QMutexLocker locker(&m_mutex); - m_TsdbExcuting = false; - } - checkTsdbCommandQueue(); + emit sigHistoryComputeData(vecMpKey, cmResult, type); } void CHisDataManage::queryHistoryEvents(std::vector *vecMpKey, double lower, double upper, const EnComputeMethod &enCM, int nGroupBySec) { - { - QMutexLocker locker(&m_mutex); - m_TsdbExcuting = true; - } - std::vector *> *vecResult = new std::vector *>(); iot_dbms::CTsdbConnPtr tsdbConnPtr; @@ -326,22 +255,14 @@ void CHisDataManage::queryHistoryEvents(std::vector *vecMpKey, do { vecResult->push_back(new std::vector()); } - emit sigHisSearch(true); if(!getHisEventPoint(*tsdbConnPtr, 10000, *vecMpKey, lower, upper, enCM, nGroupBySec * 1000, *vecResult)) { LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 查询超时!Lower: %f, Upper: %f, GroupByMs: %d", lower, upper, nGroupBySec); } - emit sigHisSearch(false); } else { LOGINFO("TrendCurve CHisDataManage::queryHistoryPolymericData: 未获取到有效的TSDB连接!"); } emit sigHistoryEvent(vecMpKey, vecResult); - - { - QMutexLocker locker(&m_mutex); - m_TsdbExcuting = false; - } - checkTsdbCommandQueue(); } diff --git a/product/src/gui/plugin/TrendCurves/CHisDataManage.h b/product/src/gui/plugin/TrendCurves/CHisDataManage.h index bcfdf675..dce041ac 100644 --- a/product/src/gui/plugin/TrendCurves/CHisDataManage.h +++ b/product/src/gui/plugin/TrendCurves/CHisDataManage.h @@ -1,4 +1,4 @@ -#ifndef CHISDATAMANAGE_H +#ifndef CHISDATAMANAGE_H #define CHISDATAMANAGE_H #include @@ -10,8 +10,8 @@ enum E_Data_Type { - E_REALTIME, - E_HISTORY + E_HISTORY, + E_PRECURVE, }; enum E_His_Type @@ -41,6 +41,7 @@ struct TsdbCommand vecMethod = std::vector{iot_dbms::CM_NULL}; } E_His_Type type; + E_Data_Type dataType; std::vector * pVecMpKey; double lower; double upper; @@ -64,10 +65,12 @@ signals: void sigHistoryPolymericData(std::vector *vecMpKey, std::vector *> *vecResult, - int nGroupBySec); + int nGroupBySec, + E_Data_Type type = E_HISTORY); void sigHistoryComputeData(std::vector *vecMpKey, - std::vector *> *> > cmResult); + std::vector *> *> > cmResult, + E_Data_Type type = E_HISTORY); void sigHistoryEvent(std::vector *vecMpKey, std::vector *> *vecResult); @@ -77,11 +80,11 @@ signals: public slots: void release(); - void postTsdbCommandQueue(E_His_Type type, std::vector *vecMpKey, - double lower, double upper, - int nGroupBySec = -1, - std::vector vecCM = std::vector{iot_dbms::CM_NULL}); + void postTsdbCommandQueue(const QList &cmd); + void queryHistoryRecord(const QList &cmdList); + +private: void queryHistoryOriginalData(std::vector *vecMpKey, double lower, double upper, E_Data_Type type = E_HISTORY); @@ -89,11 +92,13 @@ public slots: void queryHistoryPolymericData(std::vector *vecMpKey, double lower, double upper, int nGroupBySec, - const iot_dbms::EnComputeMethod &enCm); + const iot_dbms::EnComputeMethod &enCm, + E_Data_Type type = E_HISTORY); void queryHistoryComputeData(std::vector *vecMpKey, double lower, double upper, - const std::vector &vecCM); + const std::vector &vecCM, + E_Data_Type type = E_HISTORY); void queryHistoryEvents(std::vector *vecMpKey, double lower, double upper, @@ -103,18 +108,12 @@ public slots: protected: bool getValidTsdbConnPtr(iot_dbms::CTsdbConnPtr &ptr); void checkTsdbCommandQueue(); - void checkTsdbCommandQueue(bool &bHasPend, QList &listCommand); private: bool m_TsdbExcuting; - bool m_bHasPendingCommandCurve; - bool m_bHasPendingCommandEvent; - bool m_bHasPendingCommandCompute; + bool m_bHasPending; iot_dbms::CTsdbConnPtr m_tsdbConnPtr; - - QList m_listCommandCurve; - QList m_listCommandEvent; - QList m_listCommandCompute; + QList> m_listCommand; QMutex m_mutex; static int m_nProcessNumber; }; diff --git a/product/src/gui/plugin/TrendCurves/CHisEventManage.cpp b/product/src/gui/plugin/TrendCurves/CHisEventManage.cpp index e1a32a2a..42569e4b 100644 --- a/product/src/gui/plugin/TrendCurves/CHisEventManage.cpp +++ b/product/src/gui/plugin/TrendCurves/CHisEventManage.cpp @@ -1,4 +1,4 @@ -#include "CHisEventManage.h" +#include "CHisEventManage.h" #include "service/alarm_server_api/AlarmCommonDef.h" #include #include "pub_logger_api/logger.h" diff --git a/product/src/gui/plugin/TrendCurves/CHisEventManage.h b/product/src/gui/plugin/TrendCurves/CHisEventManage.h index 228a072a..c9dabc8a 100644 --- a/product/src/gui/plugin/TrendCurves/CHisEventManage.h +++ b/product/src/gui/plugin/TrendCurves/CHisEventManage.h @@ -1,4 +1,4 @@ -#ifndef CHISEVENTMANAGE_H +#ifndef CHISEVENTMANAGE_H #define CHISEVENTMANAGE_H #include "dbms/db_api_ex/CDbApi.h" diff --git a/product/src/gui/plugin/TrendCurves/CPlotWidget.cpp b/product/src/gui/plugin/TrendCurves/CPlotWidget.cpp index dc062909..cefb68e5 100644 --- a/product/src/gui/plugin/TrendCurves/CPlotWidget.cpp +++ b/product/src/gui/plugin/TrendCurves/CPlotWidget.cpp @@ -1,4 +1,4 @@ -#include "CPlotWidget.h" +#include "CPlotWidget.h" #include "ui_CPlotWidget.h" #include "CCurveLegendModel.h" #include "CTableDataModel.h" @@ -9,8 +9,8 @@ #include "./widgets/CEditCollectWidget.h" #include "./widgets/CSWitchButton.h" #include "./widgets/CToolTip.h" -#include "CMyCheckBox.h" -#include "CMyListWidget.h" +#include "./widgets/CMyCheckBox.h" +#include "./widgets/CMyListWidget.h" #include "model_excel/xlsx/xlsxdocument.h" using namespace iot_dbms; @@ -21,6 +21,7 @@ CPlotWidget::CPlotWidget(QWidget *parent) : m_type(E_Trend_Invalid), m_showType(E_Show_Curve), m_bHisAdaption(false), + m_bShowPreCurve(false), m_TrendTypeButton(Q_NULLPTR), m_pLengedModel(Q_NULLPTR), m_pTableDataModel(Q_NULLPTR), @@ -39,7 +40,9 @@ CPlotWidget::CPlotWidget(QWidget *parent) : m_isSetSliderValue(false), m_isTooltip(true), m_isAdaptShow(true), - m_isAlarmShow(true) + m_isAlarmShow(true), + m_isPreCurveShow(true), + m_bEnableNan(true) { ui->setupUi(this); setContentsMargins(1, 1, 1, 1); @@ -51,6 +54,7 @@ CPlotWidget::CPlotWidget(QWidget *parent) : qRegisterMetaType< std::vector *> >("std::vector *>"); qRegisterMetaType< std::vector *> *> > >( "std::vector *> *> >"); + qRegisterMetaType< QList >("QList"); } CPlotWidget::~CPlotWidget() @@ -161,6 +165,7 @@ void CPlotWidget::initialize() ui->interval->addItem(tr("一小时"), 60*60); ui->interval->addItem(tr("八小时"), 8*60*60); ui->interval->addItem(tr("一天"), 24*60*60); + ui->interval->addItem(tr("全部"), 0); connect(ui->interval, &QComboBox::currentTextChanged, this, &CPlotWidget::slotIntervalChanged); connect(ui->customSearch, &QPushButton::clicked, this, &CPlotWidget::slotCustomSearch); connect(ui->startData, &QDateTimeEdit::dateTimeChanged, this, &CPlotWidget::slotStartDateChanged); @@ -208,10 +213,13 @@ void CPlotWidget::initialize() ui->m_dataView->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu); ui->m_dataView->setSelectionBehavior(QAbstractItemView::SelectRows); // ui->m_dataView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); -// ui->m_dataView->horizontalHeader()->setMinimumSectionSize(200); - ui->m_dataView->horizontalHeader()->setDefaultSectionSize(200); +// ui->m_dataView->horizontalHeader()->setDefaultSectionSize(200); + ui->m_dataView->setHorizontalHeader(new CustomHeaderView(Qt::Horizontal,ui->m_dataView)); + ui->m_dataView->horizontalHeader()->setMinimumSectionSize(200); connect(ui->m_dataView, SIGNAL(clicked(QModelIndex)), this, SLOT(tableSelectionChanged(QModelIndex))); + + connect(ui->m_dataView->horizontalHeader(),&QHeaderView::sectionCountChanged,ui->m_dataView,&CTableView::adjustHeaderWidth); //< initTableView m_pLengedModel = new CCurveLegendModel(ui->lengedView); ui->lengedView->setModel(m_pLengedModel); @@ -225,6 +233,9 @@ void CPlotWidget::initialize() ui->lengedView->setSelectionMode(QAbstractItemView::SingleSelection); ui->lengedView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); ui->lengedView->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu); + ui->lengedView->setHorizontalHeader(new CustomHeaderView(Qt::Horizontal,ui->lengedView)); + connect(ui->lengedView->horizontalHeader(),&QHeaderView::sectionCountChanged,ui->lengedView,&CCurveLegendView::adjustHeaderWidth); + connect(m_pLengedModel, &CCurveLegendModel::graphVisibleChanged, this, &CPlotWidget::graphVisibleChanged); connect(m_pLengedModel, &CCurveLegendModel::graphPropertyChanged, this, &CPlotWidget::graphPropertyChanged); @@ -237,10 +248,11 @@ void CPlotWidget::initialize() ui->clear->setEnabled(false); ui->collectCurve->setVisible(false); ui->switchBtn->setToggle(false); - ui->switchBtn->setText(tr("曲线")); - ui->switchBtn->setCheckedText(tr("表格")); + ui->switchBtn->setText(tr("表格")); + ui->switchBtn->setCheckedText(tr("曲线")); ui->m_dataView->setVisible(false); connect(ui->adapt, &QCheckBox::toggled, this, &CPlotWidget::updateAdaptState); + connect(ui->preCurve, &QCheckBox::toggled, this, &CPlotWidget::updatePreCurveState); connect(ui->collectCurve, &QPushButton::clicked, this, &CPlotWidget::addCollect); connect(ui->plotPrint, &QPushButton::clicked, this, &CPlotWidget::slotPrint); connect(ui->plotExport, &QPushButton::clicked, this, &CPlotWidget::slotExport); @@ -264,13 +276,10 @@ void CPlotWidget::initialize() m_pHisDataManage->moveToThread(m_pHisDataThread); connect(m_pHisDataThread, &QThread::finished, m_pHisDataThread, &QObject::deleteLater); connect(this, &CPlotWidget::releaseHisDataThread, m_pHisDataManage, &CHisDataManage::release, Qt::BlockingQueuedConnection); - connect(this, &CPlotWidget::sigQueryHistoryOriginalData, m_pHisDataManage, &CHisDataManage::queryHistoryOriginalData, Qt::QueuedConnection); - connect(this, &CPlotWidget::sigQueryHistoryPolymericData, m_pHisDataManage, &CHisDataManage::queryHistoryPolymericData, Qt::QueuedConnection); - connect(this, &CPlotWidget::sigQueryHistoryComputeData, m_pHisDataManage, &CHisDataManage::queryHistoryComputeData, Qt::QueuedConnection); + connect(this, &CPlotWidget::sigQueryHistoryRecord, m_pHisDataManage, &CHisDataManage::queryHistoryRecord, Qt::QueuedConnection); connect(m_pHisDataManage, &CHisDataManage::sigupdateHisOriginalData, this, &CPlotWidget::updateHisOriginalData, Qt::QueuedConnection); connect(m_pHisDataManage, &CHisDataManage::sigHistoryPolymericData, this, &CPlotWidget::updateHisPolymericData, Qt::QueuedConnection); connect(m_pHisDataManage, &CHisDataManage::sigHistoryComputeData, this, &CPlotWidget::updateHisComputeData, Qt::QueuedConnection); - connect(this, &CPlotWidget::sigQueryHistoryEvent, m_pHisDataManage, &CHisDataManage::queryHistoryEvents, Qt::QueuedConnection); connect(m_pHisDataManage, &CHisDataManage::sigHistoryEvent, this, &CPlotWidget::updatePhaseTracer, Qt::QueuedConnection); connect(m_pHisDataManage, &CHisDataManage::sigHisSearch, this, &CPlotWidget::slotEnableSearch, Qt::QueuedConnection); m_pHisDataThread->start(); @@ -366,7 +375,6 @@ void CPlotWidget::updateLengedColumnWidth() ui->lengedView->setColumnWidth(CCurveLegendModel::MIN, nLengedWidth / 12.); ui->lengedView->setColumnWidth(CCurveLegendModel::MINTIME, nLengedWidth / 12. * 1.5); ui->lengedView->setColumnWidth(CCurveLegendModel::AVE, nLengedWidth / 12.); - //单位目前未查询处理为空,屏蔽显示 ui->lengedView->setColumnWidth(CCurveLegendModel::UNIT, nLengedWidth / 12. * 1.5); // ui->lengedView->setColumnWidth(CCurveLegendModel::FACTOR, nLengedWidth / 12.); // ui->lengedView->setColumnWidth(CCurveLegendModel::OFFSET, nLengedWidth / 12.); @@ -513,6 +521,12 @@ void CPlotWidget::insertTag(const QString &tag, const bool &resetTitle) { setTitle(tr("趋势图")); } + + //如果是动态加载设备的话,需要在此尝试加载一下本设备数据,如果已经加载会跳过 + QStringList devList; + devList << tag.left(tag.lastIndexOf(".")); + CTrendInfoManage::instance()->loadTagInfoByDevTag(devList); + Curve curve; curve.tag = tag; QList list = m_pTrendGraph->curveColors(); @@ -553,14 +567,14 @@ void CPlotWidget::removeTag(const QString &tag, const bool &resetTitle) } m_isSetSliderValue = false; setAllLengedShow(); - int nIndex = m_pTrendGraph->removeCurve(tag); - if(nIndex != -1) + QList removeList = m_pTrendGraph->removeCurve(tag); + for(int nIndex = 0; nIndex < removeList.length(); ++nIndex) { if(m_showType == E_Show_Table) { m_pTableDataModel->removeCurveData(ui->plot->graph(nIndex)->desc()); } - ui->plot->removeGraph(nIndex); + ui->plot->removeGraph(removeList[nIndex]); } m_pLengedModel->setTrendGraph(m_pTrendGraph); @@ -586,6 +600,7 @@ void CPlotWidget::removeTag(const QString &tag, const bool &resetTitle) groupQueryHistoryEvent(); } } + m_isSetSliderValue = true; rescaleYAxisRange(); ui->plot->replot(); } @@ -656,19 +671,26 @@ void CPlotWidget::setClearVisible(bool visible) void CPlotWidget::setAdaptVisible(bool visible) { - m_isAdaptShow = false; + m_isAdaptShow = visible; ui->adapt->setVisible(visible); } void CPlotWidget::setAlarmPointVisible(bool visible) { - m_isAlarmShow = false; + m_isAlarmShow = visible; ui->checkBox_alarmPoint->setVisible(visible); ui->comboBox_alarmStatus->setVisible(visible); } +void CPlotWidget::setPreCurveVisible(bool visible) +{ + m_isPreCurveShow = visible; + + ui->preCurve->setVisible(visible); +} + void CPlotWidget::insertCurve(Curve curve) { m_isSetSliderValue = true; @@ -716,6 +738,7 @@ void CPlotWidget::insertCurve(Curve curve) QCPGraph * graph = ui->plot->addGraph(); graph->setName(curve.tag); graph->setDesc(curve.desc); + graph->setType(curve.curveType); QPen pen; pen.setWidth(1); pen.setColor(curve.color); @@ -733,19 +756,34 @@ void CPlotWidget::insertCurve(Curve curve) graph->setLineStyle(QCPGraph::lsStepLeft); } - //< 查询最新十分钟数据 -// double upper = QDateTime::currentMSecsSinceEpoch(); -// double lower = upper - (10 * 60 * 1000); -// SMeasPointKey key; -// std::string tmp = curve.tag.toStdString(); -// char * tag = (char*)malloc(tmp.size() + 1); -// memset(tag, 0, tmp.size() + 1); -// memcpy(tag, tmp.c_str(), tmp.size()); -// key.m_pszTagName = tag; -// key.m_enType = getMeasType(curve.type); -// std::vector * vecMpKey = new std::vector(); -// vecMpKey->push_back(key); -// emit sigQueryHistoryOriginalData(vecMpKey, lower, upper, E_REALTIME); + if(m_bShowPreCurve) + { + Curve preCurve; + preCurve.visible = curve.visible; + preCurve.tag = curve.tag; + preCurve.desc = tr("昨日曲线-") + curve.desc; + preCurve.type = curve.type; + preCurve.unit = curve.unit; + preCurve.color = curve.color.darker(200); + preCurve.curveType = enPrevCurve; + m_pTrendGraph->addCurve(preCurve); + QCPGraph * graph = ui->plot->addGraph(); + graph->setName(preCurve.tag); + graph->setDesc(preCurve.desc); + graph->setType(preCurve.curveType); + QPen pen; + pen.setWidth(1); + pen.setColor(preCurve.color.darker(200)); + graph->setPen(pen); + updateCurveSelectionColor(graph); + connect(graph, SIGNAL(selectionChanged(bool)), this, SLOT(graphSelectionChanged(bool)), Qt::QueuedConnection); + //< 方波 + QString type = CTrendInfoManage::instance()->getTagType(preCurve.tag); + if(type == "digital" || type == "mix") + { + graph->setLineStyle(QCPGraph::lsStepLeft); + } + } updateCurves(); @@ -892,6 +930,21 @@ void CPlotWidget::setPlotTickPen(const QColor &color) ui->plot->yAxis2->setSubTickPen(color); } +void CPlotWidget::clearCustomInterval() +{ + ui->interval->clear(); +} + +void CPlotWidget::addCustomInterval(const QString &desc, const int &sec) +{ + if(desc.isEmpty() || sec <=0) + { + return; + } + + ui->interval->addItem(desc,sec); +} + void CPlotWidget::realTimeElapsed() { //< 刷新X轴 @@ -904,7 +957,7 @@ void CPlotWidget::realTimeElapsed() for(int nIndex(0); nIndex < ui->plot->graphCount(); nIndex++) { QCPGraph * graph = ui->plot->graph(nIndex); - m_pTrendGraph->updateRTCurveStatisticsInfo(graph->name()); + m_pTrendGraph->updateRTCurveStatisticsInfo(graph->name(), graph->type()); QVector * pCPGraphData = graph->data()->data(); if(pCPGraphData->isEmpty()) @@ -975,7 +1028,12 @@ void CPlotWidget::updateRealTimeTableData() { continue; } - const QVector< QPair > > &values = m_pTrendGraph->curve(ui->plot->graph(nIndex)->name()).values; + if(ui->plot->graph(nIndex)->type() == enPrevCurve) + { + continue; + } + const QVector< QPair > > &values = m_pTrendGraph->curve(ui->plot->graph(nIndex)->name(), + ui->plot->graph(nIndex)->type()).values; QVector vecGraphData; double preValue = DBL_MAX; QVector< QPair > >::const_iterator iter = values.constBegin(); @@ -996,9 +1054,6 @@ void CPlotWidget::updateRealTimeTableData() headerList.append(ui->plot->graph(nIndex)->desc()); } resetCurveData(curveData, headerList, false); - - - graphVisibleChanged(true); } void CPlotWidget::plotAxisRangeChanged(const QCPRange &newRange, const QCPRange &oldRange) @@ -1161,10 +1216,7 @@ void CPlotWidget::plotAxisRangeChanged(const QCPRange &newRange, const QCPRange void CPlotWidget::updateTrendShowMode(int nIndex, bool updateXAxisRange) { m_type = (E_Trend_Type)nIndex; - m_isSetSliderValue = true; - updateGraphTitle(nIndex); - if(Q_NULLPTR != m_pTimer && m_pTimer->isActive()) { m_pTimer->stop(); @@ -1183,57 +1235,25 @@ void CPlotWidget::updateTrendShowMode(int nIndex, bool updateXAxisRange) ui->plot->axisRect()->setRangeZoom(Qt::Horizontal); //< 水平缩放 ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); ui->plot->xAxis->setScaleType(QCPAxis::stLinear); - + updateGraphTitle(nIndex); + updateAxisFormat(updateXAxisRange); + //< clear view int count = ui->plot->graphCount(); for(int n(0); nplot->graph(n); graph->data()->clear(); } - ui->plot->clearItems(); m_listTracer.clear(); + m_pTableDataModel->clear(); + afterModeSwitch(); - updateAxisFormat(updateXAxisRange); - - if (m_type == E_Trend_RealTime || m_type == E_Trend_Invalid) + if (m_type == E_Trend_His_Custom) { - ui->dataWidget->setVisible(false); - ui->customWidget->setVisible(false); - ui->adapt->setVisible(false); - ui->checkBox_alarmPoint->setVisible(false); - ui->comboBox_alarmStatus->setVisible(false); - } - else if (m_type == E_Trend_His_Custom) - { - ui->customWidget->setVisible(true); - ui->dataWidget->setVisible(false); slotCustomSearch(); } - else - { - ui->dataWidget->setVisible(true); - ui->customWidget->setVisible(false); - if(m_isAdaptShow) - { - ui->adapt->setVisible(true); - } - if(m_isAlarmShow) - { - ui->checkBox_alarmPoint->setVisible(true); - ui->comboBox_alarmStatus->setVisible(true); - } - ui->date->setDateTime(QDateTime::currentDateTime()); - } - if(m_showType == E_Show_Table) - { - ui->adapt->setVisible(false); - ui->checkBox_alarmPoint->setVisible(false); - ui->comboBox_alarmStatus->setVisible(false); - m_pTableDataModel->clear(); - } - - // if(m_type == E_Trend_RealTime) + else if (m_type == E_Trend_RealTime) { if(E_Show_Table == m_showType) { @@ -1241,19 +1261,22 @@ void CPlotWidget::updateTrendShowMode(int nIndex, bool updateXAxisRange) } updateCurves(); } + else + { + ui->date->setDateTime(QDateTime::currentDateTime()); + } } -void CPlotWidget::updateComputeValue(double lower, double upper, std::vector vecMethod) +TsdbCommand CPlotWidget::getHisCurveCmd(double lower, double upper, int nGroupBy, E_Data_Type type) { - if(!ui->plot->graphCount()) - { - return; - } - std::vector * vecMpKey = new std::vector(); for(int nIndex(0); nIndex < ui->plot->graphCount(); ++nIndex) { - const Curve &curve = m_pTrendGraph->curve(ui->plot->graph(nIndex)->name()); + if(ui->plot->graph(nIndex)->type() != type) + { + continue; + } + const Curve &curve = m_pTrendGraph->curve(ui->plot->graph(nIndex)->name(), ui->plot->graph(nIndex)->type()); SMeasPointKey key; std::string tmp = curve.tag.toStdString(); char * tag = (char*)malloc(tmp.size() + 1); @@ -1264,14 +1287,53 @@ void CPlotWidget::updateComputeValue(double lower, double upper, std::vectorpush_back(key); } - if(!m_pHisDataManage->isTsdbExuting()) + TsdbCommand cmd; + if(E_Trend_His_Hour == m_type || E_Trend_His_Minute == m_type || nGroupBy <= 0) { - emit sigQueryHistoryComputeData(vecMpKey, lower, upper, vecMethod); + cmd.type = E_ORIGINAL; } else { - m_pHisDataManage->postTsdbCommandQueue(E_COMPUTER, vecMpKey, lower, upper, -1, vecMethod); + cmd.type = E_POLYMERIC; } + cmd.dataType = type; + cmd.pVecMpKey = vecMpKey; + cmd.lower = lower; + cmd.upper = upper; + cmd.nGroupBySec = nGroupBy; + cmd.vecMethod = std::vector{iot_dbms::CM_FIRST}; + return cmd; +} + +TsdbCommand CPlotWidget::getComputeCmd(double lower, double upper, std::vector vecMethod, E_Data_Type type) +{ + std::vector * vecMpKey = new std::vector(); + for(int nIndex(0); nIndex < ui->plot->graphCount(); ++nIndex) + { + if(ui->plot->graph(nIndex)->type() != type) + { + continue; + } + const Curve &curve = m_pTrendGraph->curve(ui->plot->graph(nIndex)->name(), ui->plot->graph(nIndex)->type()); + SMeasPointKey key; + std::string tmp = curve.tag.toStdString(); + char * tag = (char*)malloc(tmp.size() + 1); + memset(tag, 0, tmp.size() + 1); + memcpy(tag, tmp.c_str(), tmp.size()); + key.m_pszTagName = tag; + key.m_enType = getMeasType(curve.type); + vecMpKey->push_back(key); + } + + TsdbCommand cmd; + cmd.type = E_COMPUTER; + cmd.dataType = type; + cmd.pVecMpKey = vecMpKey; + cmd.lower = lower; + cmd.upper = upper; + cmd.nGroupBySec = -1; + cmd.vecMethod = vecMethod; + return cmd; } void CPlotWidget::updateGraphTitle(int nIndex) @@ -1322,7 +1384,7 @@ void CPlotWidget::updateCurves() } else { - updateHistoryCurveRecord(ui->plot->xAxis->range().lower, ui->plot->xAxis->range().upper); + updateHistoryCurveRecord(); } } @@ -1339,7 +1401,7 @@ void CPlotWidget::updateRealTimeCurveRecord() //< 清空数据 QSharedPointer container(new QCPGraphDataContainer()); - const QVector< QPair > > &values = m_pTrendGraph->curve(graph->name()).values; + const QVector< QPair > > &values = m_pTrendGraph->curve(graph->name(), graph->type()).values; QVector< QPair > >::const_iterator it = values.constBegin(); double preValue = DBL_MAX; while (it != values.constEnd()) @@ -1369,7 +1431,7 @@ void CPlotWidget::updateRealTimeCurveRecord() ui->plot->replot(); } -void CPlotWidget::updateHistoryCurveRecord(double lower, double upper) +void CPlotWidget::updateHistoryCurveRecord() { if(!ui->plot->graphCount()) { @@ -1381,46 +1443,32 @@ void CPlotWidget::updateHistoryCurveRecord(double lower, double upper) return; } - std::vector * vecMpKey = new std::vector(); - for(int nIndex(0); nIndex < ui->plot->graphCount(); ++nIndex) - { - const Curve &curve = m_pTrendGraph->curve(ui->plot->graph(nIndex)->name()); - SMeasPointKey key; - std::string tmp = curve.tag.toStdString(); - char * tag = (char*)malloc(tmp.size() + 1); - memset(tag, 0, tmp.size() + 1); - memcpy(tag, tmp.c_str(), tmp.size()); - key.m_pszTagName = tag; - key.m_enType = getMeasType(curve.type); - vecMpKey->push_back(key); + QPair range = getFatureDataTime(m_type, ui->date->dateTime()); + std::vector vecMethod{iot_dbms::CM_MAX, iot_dbms::CM_MIN}; + + QList cmdList; + TsdbCommand curve = getHisCurveCmd(ui->plot->xAxis->range().lower, ui->plot->xAxis->range().upper, currentGroupByMinute() * 60, E_HISTORY); + TsdbCommand computer = getComputeCmd(range.first, range.second, vecMethod, E_HISTORY); + cmdList.push_back(curve); + cmdList.push_back(computer); + + if(m_bShowPreCurve){ + QPair preCurveRange = getOffsetRange(ui->plot->xAxis->range().lower, ui->plot->xAxis->range().upper, -1); + QPair preComputeRange = getOffsetRange(range.first, range.second, -1); + TsdbCommand preCurve = getHisCurveCmd(preCurveRange.first, preCurveRange.second, currentGroupByMinute() * 60, E_PRECURVE); + TsdbCommand perComputer = getComputeCmd(preComputeRange.first, preComputeRange.second, vecMethod, E_PRECURVE); + cmdList.push_back(preCurve); + cmdList.push_back(perComputer); } if(!m_pHisDataManage->isTsdbExuting()) { - if(E_Trend_His_Hour == m_type || E_Trend_His_Minute == m_type) - { - emit sigQueryHistoryOriginalData(vecMpKey, lower, upper); - } - else - { - emit sigQueryHistoryPolymericData(vecMpKey, lower, upper, currentGroupByMinute() * 60, iot_dbms::CM_FIRST); - } + emit sigQueryHistoryRecord(cmdList); } else { - if(E_Trend_His_Hour == m_type || E_Trend_His_Minute == m_type) - { - m_pHisDataManage->postTsdbCommandQueue(E_ORIGINAL, vecMpKey, lower, upper); - } - else - { - m_pHisDataManage->postTsdbCommandQueue(E_POLYMERIC, vecMpKey, lower, upper, currentGroupByMinute() * 60, std::vector{iot_dbms::CM_FIRST}); - } + m_pHisDataManage->postTsdbCommandQueue(cmdList); } - - QPair range = getFatureDataTime(m_type, ui->date->dateTime()); - std::vector vecMethod{iot_dbms::CM_MAX, iot_dbms::CM_MIN}; - updateComputeValue(range.first, range.second, vecMethod); } void CPlotWidget::updateHisOriginalData(std::vector *vecMpKey, std::vector *> *vecResult, E_Data_Type type) @@ -1434,37 +1482,21 @@ void CPlotWidget::updateHisOriginalData(std::vector *vecMpKey, st if(m_showType == E_Show_Table) { isAddVirtualPoint = false; - if(m_type == E_Trend_His_Custom) - { - lower = ui->startData->dateTime().toMSecsSinceEpoch(); - upper = ui->endData->dateTime().toMSecsSinceEpoch(); - } } - updateHisData(vecMpKey, vecResult, vecRange, vecContainer, lower, upper, isAddVirtualPoint); + if(m_type == E_Trend_His_Custom) + { + lower = ui->startData->dateTime().toMSecsSinceEpoch(); + upper = ui->endData->dateTime().toMSecsSinceEpoch(); + } + updateHisData(vecMpKey, vecResult, vecRange, vecContainer, lower, upper, type, isAddVirtualPoint); - if(E_REALTIME == type) + if(m_showType == E_Show_Curve) { - for(size_t nIndex(0); nIndex < vecContainer.size(); ++nIndex) - { - QCPGraphDataContainer::iterator it = vecContainer.at(nIndex)->begin(); - while(it != vecContainer.at(nIndex)->end()) - { - m_pTrendGraph->pushCurveRTDataValue(vecMpKey->at(nIndex).m_pszTagName, it->key, it->value, it->status); - ++it; - } - } - updateCurves(); + updateHistoryGraph(vecMpKey, vecContainer, vecRange, type); } - else if(E_HISTORY == type) + else if(m_showType == E_Show_Table) { - if(m_showType == E_Show_Curve) - { - updateHistoryGraph(vecMpKey, vecContainer, vecRange); - } - else if(m_showType == E_Show_Table) - { - updateHistoryData(vecMpKey, vecContainer, vecRange); - } + updateHistoryData(vecMpKey, vecContainer, vecRange, type); } m_pLengedModel->update(); @@ -1490,7 +1522,7 @@ void CPlotWidget::updateHisOriginalData(std::vector *vecMpKey, st delete vecMpKey; } -void CPlotWidget::updateHisPolymericData(std::vector *vecMpKey, std::vector *> *vecResult, int nGroupBySec) +void CPlotWidget::updateHisPolymericData(std::vector *vecMpKey, std::vector *> *vecResult, int nGroupBySec, E_Data_Type type) { std::vector< QSharedPointer > vecRange; std::vector< QSharedPointer > vecContainer; @@ -1499,25 +1531,33 @@ void CPlotWidget::updateHisPolymericData(std::vector *vecMpKey, s { if(m_showType == E_Show_Curve) { - updateHisData(vecMpKey, vecResult, vecRange, vecContainer, ui->plot->xAxis->range().lower, - ui->plot->xAxis->range().upper, true, nGroupBySec); + if(m_type == E_Trend_His_Custom) + { + updateHisData(vecMpKey, vecResult, vecRange, vecContainer, ui->startData->dateTime().toMSecsSinceEpoch(), + ui->endData->dateTime().toMSecsSinceEpoch(), type, true, nGroupBySec); + } + else + { + updateHisData(vecMpKey, vecResult, vecRange, vecContainer, ui->plot->xAxis->range().lower, + ui->plot->xAxis->range().upper, type, true, nGroupBySec); + } - updateHistoryGraph(vecMpKey, vecContainer, vecRange); + updateHistoryGraph(vecMpKey, vecContainer, vecRange, type); } else if(m_showType == E_Show_Table) { if(m_type == E_Trend_His_Custom) { updateHisData(vecMpKey, vecResult, vecRange, vecContainer, ui->startData->dateTime().toMSecsSinceEpoch(), - ui->endData->dateTime().toMSecsSinceEpoch(), false, nGroupBySec); + ui->endData->dateTime().toMSecsSinceEpoch(), type, false, nGroupBySec); } else { updateHisData(vecMpKey, vecResult, vecRange, vecContainer, ui->plot->xAxis->range().lower, - ui->plot->xAxis->range().upper, false, nGroupBySec); + ui->plot->xAxis->range().upper, type, false, nGroupBySec); } - updateHistoryData(vecMpKey, vecContainer, vecRange); + updateHistoryData(vecMpKey, vecContainer, vecRange, type); } } m_pLengedModel->update(); @@ -1543,7 +1583,7 @@ void CPlotWidget::updateHisPolymericData(std::vector *vecMpKey, s delete vecMpKey; } -void CPlotWidget::updateHisComputeData(std::vector *vecMpKey, std::vector *> *> > cmResult) +void CPlotWidget::updateHisComputeData(std::vector *vecMpKey, std::vector *> *> > cmResult, E_Data_Type type) { typename std::vector *> *> >::const_iterator resultIter = cmResult.begin(); while(resultIter != cmResult.end()) @@ -1553,22 +1593,17 @@ void CPlotWidget::updateHisComputeData(std::vector *vecMpKey, std while(it != resultIter->second->end()) { int nIndex = it - resultIter->second->begin(); - if(nIndex > ui->plot->graphCount()-1) + int nGraphIndex = m_pTrendGraph->index(vecMpKey->at(nIndex).m_pszTagName, type); + if(nGraphIndex == -1) { - ++it; - continue; - } - QCPGraph * graph = ui->plot->graph(nIndex); - if(graph->name() != QString(vecMpKey->at(nIndex).m_pszTagName)) - { - ++it; continue; } + QCPGraph * graph = ui->plot->graph(nGraphIndex); std::vector * vecPoint = *it; if(vecPoint->empty()) { ++it; - setCurveStatisData(graph->name(), method, true); + setCurveStatisData(graph->name(), graph->type(), method, true); continue; } @@ -1588,10 +1623,10 @@ void CPlotWidget::updateHisComputeData(std::vector *vecMpKey, std if(std::isnan(value)) { ++pt; - setCurveStatisData(graph->name(), method, true); + setCurveStatisData(graph->name(), graph->type(), method, true); continue; } - setCurveStatisData(graph->name(), method, false, value, pt->m_nTime); + setCurveStatisData(graph->name(), graph->type(), method, false, value, pt->m_nTime); ++pt; } ++it; @@ -1620,7 +1655,7 @@ void CPlotWidget::updateHisComputeData(std::vector *vecMpKey, std delete vecMpKey; } -void CPlotWidget::updateHistoryGraph(std::vector *vecMpKey, std::vector > &vecContainer, std::vector > &vecRange) +void CPlotWidget::updateHistoryGraph(std::vector *vecMpKey, std::vector > &vecContainer, std::vector > &vecRange, E_Data_Type type) { double lower = ui->plot->xAxis->range().lower; double upper = ui->plot->xAxis->range().upper; @@ -1638,18 +1673,13 @@ void CPlotWidget::updateHistoryGraph(std::vector *vecMpKey, std:: for(int nIndex(0); nIndex < (int)vecContainer.size(); ++nIndex) { - if(nIndex > ui->plot->graphCount()-1) + int nGraphIndex = m_pTrendGraph->index(vecMpKey->at(nIndex).m_pszTagName, type); + if(nGraphIndex == -1) { continue; } - QCPGraph * graph = ui->plot->graph(nIndex); - { - if(graph->name() != QString(vecMpKey->at(nIndex).m_pszTagName)) - { - continue; - } - } - updateCurveHisData(lower, upper, graph, nIndex, vecContainer.at(nIndex), vecRange.at(nIndex)); + QCPGraph * graph = ui->plot->graph(nGraphIndex); + updateCurveHisData(lower, upper, graph, nGraphIndex, vecContainer.at(nIndex), vecRange.at(nIndex), type); graph->data()->clear(); graph->setData(vecContainer.at(nIndex)); } @@ -1659,7 +1689,7 @@ void CPlotWidget::updateHistoryGraph(std::vector *vecMpKey, std:: ui->plot->replot(); } -void CPlotWidget::updateHistoryData(std::vector *vecMpKey, std::vector > &vecContainer, std::vector > &vecRange) +void CPlotWidget::updateHistoryData(std::vector *vecMpKey, std::vector > &vecContainer, std::vector > &vecRange, E_Data_Type type) { double lower,upper; if(m_type == E_Trend_His_Custom) @@ -1677,22 +1707,13 @@ void CPlotWidget::updateHistoryData(std::vector *vecMpKey, std::v QStringList headerList; for(int nIndex(0); nIndex < (int)vecContainer.size(); ++nIndex) { - if(nIndex > ui->plot->graphCount()-1) + int nGraphIndex = m_pTrendGraph->index(vecMpKey->at(nIndex).m_pszTagName, type); + if(nGraphIndex == -1) { continue; } - QCPGraph * graph = ui->plot->graph(nIndex); - { - if(graph->name() == "curve.tag") - { - continue; - } - if(graph->name() != QString(vecMpKey->at(nIndex).m_pszTagName)) - { - continue; - } - } - updateCurveHisData(lower, upper, graph, nIndex, vecContainer.at(nIndex), vecRange.at(nIndex)); + QCPGraph * graph = ui->plot->graph(nGraphIndex); + updateCurveHisData(lower, upper, graph, nGraphIndex, vecContainer.at(nIndex), vecRange.at(nIndex), type); QVector vecGraphData; QCPGraphDataContainer::const_iterator iter = vecContainer.at(nIndex)->constBegin(); @@ -1712,14 +1733,14 @@ void CPlotWidget::updateHistoryData(std::vector *vecMpKey, std::v enableSearch(true); } -void CPlotWidget::updateCurveHisData(double lower, double upper, QCPGraph *graph, int index, QSharedPointer container, QSharedPointer range) +void CPlotWidget::updateCurveHisData(double lower, double upper, QCPGraph *graph, int index, QSharedPointer container, QSharedPointer range, E_Data_Type type) { int count = 0; //< accuml size double offset = 0.; double factor = 1.; double accuml = 0.; - const Curve &curve = m_pTrendGraph->curve(graph->name()); + const Curve &curve = m_pTrendGraph->curve(graph->name(), type); if(m_bHisAdaption && m_type != E_Trend_RealTime) { double maxVal = range->max; @@ -1792,7 +1813,7 @@ void CPlotWidget::updateCurveHisData(double lower, double upper, QCPGraph *graph average = accuml / count; } } - m_pTrendGraph->setCurveHisDataValue(graph->name(), max, min, maxTime, minTime, average, accuml, *range); + m_pTrendGraph->setCurveHisDataValue(graph->name(), type, max, min, maxTime, minTime, average, accuml, *range); } void CPlotWidget::updatePhaseTracer(std::vector *vecMpKey, std::vector *> *vecResult) @@ -1819,7 +1840,6 @@ void CPlotWidget::updatePhaseTracer(std::vector *vecMpK } } QPointF prePt(-1000., -1000.); - //< 1min 显示所有事件 bool bMinRange = ui->plot->xAxis->range().size() > 60; QMultiMap< double, QStringList >::iterator rIter = map.begin(); @@ -2181,6 +2201,63 @@ void CPlotWidget::updateAdaptState(bool isAdapt) updateYAxisTicker(); } +void CPlotWidget::updatePreCurveState(bool isPreCurve) +{ + m_bShowPreCurve = isPreCurve; + if(m_bShowPreCurve) + { + const QList curves = m_pTrendGraph->curves(); + for(int n = 0; n < curves.length(); ++n) + { + if(curves[n].tag == "curve.tag") + { + continue; + } + Curve preCurve; + preCurve.tag = curves[n].tag; + preCurve.desc = tr("昨日曲线-") + curves[n].desc; + preCurve.type = curves[n].type; + preCurve.unit = curves[n].unit; + preCurve.color = curves[n].color.darker(200); + preCurve.curveType = enPrevCurve; + m_pTrendGraph->addCurve(preCurve); + QCPGraph * graph = ui->plot->addGraph(); + graph->setName(preCurve.tag); + graph->setDesc(preCurve.desc); + graph->setType(preCurve.curveType); + QPen pen; + pen.setWidth(1); + pen.setColor(preCurve.color.darker(200)); + graph->setPen(pen); + updateCurveSelectionColor(graph); + connect(graph, SIGNAL(selectionChanged(bool)), this, SLOT(graphSelectionChanged(bool)), Qt::QueuedConnection); + //< 方波 + QString type = CTrendInfoManage::instance()->getTagType(preCurve.tag); + if(type == "digital" || type == "mix") + { + graph->setLineStyle(QCPGraph::lsStepLeft); + } + } + updateCurves(); + } + else + { + const QList curves = m_pTrendGraph->curves(); + for(int n = curves.length() - 1; n >= 0; --n) + { + if(curves[n].curveType != enPrevCurve) + { + continue; + } + m_pTrendGraph->removeCurve(n); + ui->plot->removeGraph(n); + } + rescaleYAxisRange(); + ui->plot->replot(); + } + m_pLengedModel->setTrendGraph(m_pTrendGraph); +} + void CPlotWidget::slotCollectGraph(const QString &text) { emit collectGraph(text, *m_pTrendGraph); @@ -2261,33 +2338,6 @@ void CPlotWidget::slotExport() xlsx.write(hexTo26(col)+QString::number(row+2), m_pTableDataModel->data(index), format); } } - //m_pTrendGraph - int curRow = xlsx.dimension().lastRow(); - xlsx.write(hexTo26(0)+QString::number(curRow+1) , "最大值" ,format); - xlsx.write(hexTo26(0)+QString::number(curRow+2) , "最大值时间" ,format); - xlsx.write(hexTo26(0)+QString::number(curRow+3) , "最小值" ,format); - xlsx.write(hexTo26(0)+QString::number(curRow+4) , "最小值时间" ,format); - xlsx.write(hexTo26(0)+QString::number(curRow+5) , "平均值" ,format); - for(int col = 1,r = 0; col <= m_pTableDataModel->rowCount(); col++,r++) - { - xlsx.write(hexTo26(col)+QString::number(curRow+1) , - m_pLengedModel->data(m_pLengedModel->index(r,CCurveLegendModel::ColumnField::MAX) , - Qt::DisplayRole) ,format); - xlsx.write(hexTo26(col)+QString::number(curRow+2) , - m_pLengedModel->data(m_pLengedModel->index(r,CCurveLegendModel::ColumnField::MAXTIME) , - Qt::DisplayRole) ,format); - - xlsx.write(hexTo26(col)+QString::number(curRow+3) , - m_pLengedModel->data(m_pLengedModel->index(r,CCurveLegendModel::ColumnField::MIN) , - Qt::DisplayRole) ,format); - - xlsx.write(hexTo26(col)+QString::number(curRow+4) , - m_pLengedModel->data(m_pLengedModel->index(r,CCurveLegendModel::ColumnField::MINTIME) , - Qt::DisplayRole) ,format); - xlsx.write(hexTo26(col)+QString::number(curRow+5) , - m_pLengedModel->data(m_pLengedModel->index(r,CCurveLegendModel::ColumnField::AVE) , - Qt::DisplayRole) ,format); - } if(xlsx.saveAs(strFileName)) { @@ -2397,12 +2447,14 @@ void CPlotWidget::nextPage() void CPlotWidget::graphVisibleChanged(const bool &check) { + Q_UNUSED(check); + //< 脚本调用setTagVisible导致无法自适应 // m_isSetSliderValue = check; for(int nIndex(0); nIndex < ui->plot->graphCount(); nIndex++) { QCPGraph * graph = ui->plot->graph(nIndex); - const Curve &curve = m_pTrendGraph->curve(graph->name()); + const Curve &curve = m_pTrendGraph->curve(graph->name(), graph->type()); graph->setVisible(curve.visible); if(!curve.visible || curve.tag == "curve.tag") { @@ -2427,7 +2479,7 @@ void CPlotWidget::graphPropertyChanged() for(int nIndex(0); nIndex < ui->plot->graphCount(); nIndex++) { QCPGraph * graph = ui->plot->graph(nIndex); - const Curve &curve = m_pTrendGraph->curve(graph->name()); + const Curve &curve = m_pTrendGraph->curve(graph->name(), graph->type()); graph->setPen(curve.color); updateCurveSelectionColor(graph); } @@ -2441,7 +2493,7 @@ void CPlotWidget::deleteCurrentGraph() if(m_pTrendGraph->curves().size() > 0 && index >= 0) { QCPGraph * graph = ui->plot->graph(index); - const Curve &curve = m_pTrendGraph->curve(graph->name()); + const Curve &curve = m_pTrendGraph->curve(graph->name(), graph->type()); QString tag = curve.tag; if(tag != "curve.tag") { @@ -2488,7 +2540,7 @@ void CPlotWidget::updateLengedValue(const double &dateTime) { QCPGraph * graph = ui->plot->graph(nIndex); double graphValue = graph->value(dateTime); - const Curve &curve = m_pTrendGraph->curve(graph->name()); + const Curve &curve = m_pTrendGraph->curve(graph->name(), graph->type()); double value = graphValue; if(m_bHisAdaption && m_type != E_Trend_RealTime) @@ -2508,7 +2560,7 @@ void CPlotWidget::graphSelectionChanged(bool select) QCPGraph * graph = dynamic_cast(sender()); if(Q_NULLPTR != graph && select) { - ui->lengedView->selectRow(m_pTrendGraph->index(graph->name())); + ui->lengedView->selectRow(m_pTrendGraph->index(graph->name(), graph->type())); } ui->plot->replot(QCustomPlot::rpQueuedRefresh); } @@ -2572,7 +2624,7 @@ void CPlotWidget::updateYAxisTicker() if(m_bHisAdaption && m_type != E_Trend_RealTime) { QSharedPointer ticker(new QCPAxisTickerText); - const Curve &curve = m_pTrendGraph->curve(graphs.first()->name()); + const Curve &curve = m_pTrendGraph->curve(graphs.first()->name(), graphs.first()->type()); if(!curve.visible) { return; @@ -2677,9 +2729,6 @@ EnMeasPiontType CPlotWidget::getMeasType(const QString &type) void CPlotWidget::setLegendCurveTransformColumnVisible(const bool &visible) { Q_UNUSED(visible) - //单位未赋值,隐藏 - //ui->lengedView->setColumnHidden(CCurveLegendModel::UNIT, true); - ui->lengedView->setColumnHidden(CCurveLegendModel::FACTOR, true); ui->lengedView->setColumnHidden(CCurveLegendModel::OFFSET, true); } @@ -2862,18 +2911,18 @@ void CPlotWidget::setSliderRange(double lower, double upper, bool setValue) } } -void CPlotWidget::setCurveStatisData(const QString &tag, EnComputeMethod method, bool reset, const double &value, const double &time) +void CPlotWidget::setCurveStatisData(const QString &tag, const int &curType, EnComputeMethod method, bool reset, const double &value, const double &time) { switch (method) { case CM_MAX: { if(reset) { - m_pTrendGraph->resetCurveStatisMax(tag); + m_pTrendGraph->resetCurveStatisMax(tag, curType); } else { - m_pTrendGraph->setCurveStatisMax(tag, value, time); + m_pTrendGraph->setCurveStatisMax(tag, curType, value, time); } break; } @@ -2881,11 +2930,11 @@ void CPlotWidget::setCurveStatisData(const QString &tag, EnComputeMethod method, { if(reset) { - m_pTrendGraph->resetCurveStatisMin(tag); + m_pTrendGraph->resetCurveStatisMin(tag, curType); } else { - m_pTrendGraph->setCurveStatisMin(tag, value, time); + m_pTrendGraph->setCurveStatisMin(tag, curType, value, time); } break; } @@ -2948,10 +2997,14 @@ bool CPlotWidget::isMutation(const double &preValue, const double &curValue) template void CPlotWidget::updateHisData(std::vector *vecMpKey, std::vector*> *vecResult, std::vector > &vecRange, std::vector< QSharedPointer > &vecContainer, - double lower, double upper, + double lower, double upper, E_Data_Type type, bool isAddVirtualPoint, int nGroupBySec) { int nMaxIntervalSecs = SAMPLE_CYC_MIN * 60 * 1000 + nGroupBySec * 1000; + QPair offsetRange = qMakePair(lower, upper); + if(type == E_PRECURVE){ + offsetRange = getOffsetRange(lower, upper, -1); + } typename std::vector *>::const_iterator it = vecResult->begin(); while(it != vecResult->end()) { @@ -2970,16 +3023,16 @@ void CPlotWidget::updateHisData(std::vector *vecMpKey, std::vecto //< Graph Bound _Tp left; - left.m_nTime = lower; - typename std::vector<_Tp>::const_iterator varHisLeft = std::upper_bound((*vecPoint).begin(), (*vecPoint).end(), left, compareVarPoint<_Tp>); + left.m_nTime = offsetRange.first; + typename std::vector<_Tp>::iterator varHisLeft = std::upper_bound((*vecPoint).begin(), (*vecPoint).end(), left, compareVarPoint<_Tp>); if(varHisLeft != (*vecPoint).begin() && varHisLeft != (*vecPoint).end()) { --varHisLeft; } _Tp right; - right.m_nTime = upper; - typename std::vector<_Tp>::const_iterator varHisRight = std::lower_bound((*vecPoint).begin(), (*vecPoint).end(), right, compareVarPoint<_Tp>); + right.m_nTime = offsetRange.second; + typename std::vector<_Tp>::iterator varHisRight = std::lower_bound((*vecPoint).begin(), (*vecPoint).end(), right, compareVarPoint<_Tp>); if(varHisRight == (*vecPoint).end()) { varHisRight = (*vecPoint).end() - 1; @@ -3014,9 +3067,17 @@ void CPlotWidget::updateHisData(std::vector *vecMpKey, std::vecto int lastStatus = 0; //< Handle Data - typename std::vector<_Tp>::const_iterator pt = varHisLeft; + typename std::vector<_Tp>::iterator pt = varHisLeft; + double offsetTime = 0; + if(pt != varHisRight) + { + if(type == E_PRECURVE){ + offsetTime = getOffsetTime(pt->m_nTime); + } + } while(pt != varHisRight) { + pt->m_nTime += offsetTime; double value = qSqrt(-1.); if (typeid(boost::int32_t) == pt->m_varValue.type()) { @@ -3044,7 +3105,7 @@ void CPlotWidget::updateHisData(std::vector *vecMpKey, std::vecto qint64 timeStamp = pt->m_nTime; int status = CTrendInfoManage::instance()->getInvalidStatus(pointType, pt->m_nStatus); - if(lastTimeStamp > 0 && lastTimeStamp + nMaxIntervalSecs < timeStamp) + if(lastTimeStamp > 0 && lastTimeStamp + nMaxIntervalSecs < timeStamp && m_bEnableNan) { container->add(QCPGraphData(lastTimeStamp+nGroupBySec*1000, qSqrt(-1.), lastStatus)); } @@ -3155,29 +3216,31 @@ void CPlotWidget::groupQueryHistoryEvent() int ByMinute = currentGroupByMinute(); int g_groupByDuration = ByMinute * 60; - if(!m_pHisDataManage->isTsdbExuting()) + QList cmdList; + TsdbCommand cmd; + cmd.type = E_EVENTPOINT; + cmd.dataType = E_HISTORY; + cmd.pVecMpKey = vecMpKey; + cmd.lower = ui->plot->xAxis->range().lower; + cmd.upper = ui->plot->xAxis->range().upper; + cmd.nGroupBySec = g_groupByDuration; + if(g_groupByDuration == 0) { - if(g_groupByDuration == 0) - { - emit sigQueryHistoryEvent(vecMpKey, ui->plot->xAxis->range().lower, ui->plot->xAxis->range().upper, iot_dbms::CM_NULL, g_groupByDuration); - } - else - { - emit sigQueryHistoryEvent(vecMpKey, ui->plot->xAxis->range().lower, ui->plot->xAxis->range().upper, iot_dbms::CM_SAMPLE, g_groupByDuration); - } + cmd.vecMethod = std::vector{iot_dbms::CM_NULL}; } else { - if(g_groupByDuration == 0) - { - m_pHisDataManage->postTsdbCommandQueue(E_EVENTPOINT, vecMpKey, ui->plot->xAxis->range().lower, ui->plot->xAxis->range().upper, g_groupByDuration, - std::vector{iot_dbms::CM_NULL}); - } - else - { - m_pHisDataManage->postTsdbCommandQueue(E_EVENTPOINT, vecMpKey, ui->plot->xAxis->range().lower, ui->plot->xAxis->range().upper, g_groupByDuration, - std::vector{iot_dbms::CM_SAMPLE}); - } + cmd.vecMethod = std::vector{iot_dbms::CM_SAMPLE}; + } + cmdList.push_back(cmd); + + if(!m_pHisDataManage->isTsdbExuting()) + { + emit sigQueryHistoryRecord(cmdList); + } + else + { + m_pHisDataManage->postTsdbCommandQueue(cmdList); } ui->plot->replot(); @@ -3241,6 +3304,7 @@ void CPlotWidget::addHorizontalLine() m_horizontalGraph->setData(xLineVector,yLineVector,statusVector); m_horizontalGraph->setName("curve.tag"); + m_horizontalGraph->setType(enRealCurve); m_horizontalGraph->removeFromLegend(); horizontalCurve.tag = "curve.tag"; horizontalCurve.visible = false; @@ -3327,16 +3391,187 @@ void CPlotWidget::enableSearch(bool enable) { if(enable) { + ui->preCurve->setEnabled(true); ui->customSearch->setEnabled(true); ui->customSearch->setText(tr("查询")); } else { + ui->preCurve->setEnabled(false); ui->customSearch->setEnabled(false); ui->customSearch->setText(tr("查询中")); } } +void CPlotWidget::afterModeSwitch() +{ + bool isTool = true; + switch (m_type) { + case E_Trend_Invalid: + case E_Trend_RealTime:{ + isTool = false; + ui->dataWidget->setVisible(false); + ui->customWidget->setVisible(false); + ui->customSearch->setVisible(false); + ui->preCurve->setChecked(false); + break; + } + case E_Trend_His_Minute: + case E_Trend_His_Hour: + case E_Trend_His_Day: + case E_Trend_His_Week: + case E_Trend_His_Month: + case E_Trend_His_Quarter: + case E_Trend_His_Year:{ + isTool = true; + ui->dataWidget->setVisible(true); + ui->customWidget->setVisible(false); + ui->customSearch->setVisible(false); + break; + } + case E_Trend_His_Custom:{ + isTool = true; + ui->dataWidget->setVisible(false); + ui->customWidget->setVisible(true); + ui->customSearch->setVisible(false); + break; + } + default: + break; + } + + if(m_showType == E_Show_Table){ + isTool = false; + ui->customSearch->setVisible(true); + ui->preCurve->setChecked(false); + } + + ui->checkBox_alarmPoint->setVisible(isTool); + ui->comboBox_alarmStatus->setVisible(isTool); + ui->adapt->setVisible(isTool); + ui->preCurve->setVisible(isTool); + if(!m_isAlarmShow){ + ui->checkBox_alarmPoint->setVisible(false); + ui->comboBox_alarmStatus->setVisible(false); + } + if(!m_isAdaptShow){ + ui->adapt->setVisible(false); + } + if(!m_isPreCurveShow){ + ui->preCurve->setVisible(false); + } + + bool isTable = m_showType == E_Show_Table ? true : false; + ui->plot->setVisible(!isTable); + ui->widget->setVisible(!isTable); + ui->m_dataView->setVisible(isTable); + ui->plotExport->setVisible(isTable); + ui->plotPrint->setVisible(!isTable); +} + +QPair CPlotWidget::getOffsetRange(const double &lower, const double &upper, int direction) +{ + QPair result; + QDateTime lowDate = QDateTime::fromMSecsSinceEpoch(lower); + QDateTime upDate = QDateTime::fromMSecsSinceEpoch(upper); + switch (m_type) { + case E_Trend_Invalid: + case E_Trend_RealTime:{ + break; + } + case E_Trend_His_Minute:{ + result.first = lower + 600000 * direction; + result.second = upper + 600000 * direction; + break; + } + case E_Trend_His_Hour:{ + result.first = lower + 3600000 * direction; + result.second = upper + 3600000 * direction; + break; + } + case E_Trend_His_Day:{ + result.first = lower + 86400000 * direction; + result.second = upper + 86400000 * direction; + break; + } + case E_Trend_His_Week:{ + result.first = lower + 604800000 * direction; + result.second = upper + 604800000 * direction; + break; + } + case E_Trend_His_Month:{ + result.first = lowDate.addMonths(1 * direction).toMSecsSinceEpoch(); + result.second = upDate.addMonths(1 * direction).toMSecsSinceEpoch(); + break; + } + case E_Trend_His_Quarter:{ + result.first = lowDate.addMonths(3 * direction).toMSecsSinceEpoch(); + result.second = upDate.addMonths(3 * direction).toMSecsSinceEpoch(); + break; + } + case E_Trend_His_Year:{ + result.first = lowDate.addYears(1 * direction).toMSecsSinceEpoch(); + result.second = upDate.addYears(1 * direction).toMSecsSinceEpoch(); + break; + } + case E_Trend_His_Custom:{ + result.first = lower + (upper - lower) * direction; + result.second = upper + (upper - lower) * direction; + break; + } + default: + break; + } + return result; +} + +double CPlotWidget::getOffsetTime(const double &time) +{ + double result = 0; + QDateTime origin = QDateTime::fromMSecsSinceEpoch(time); + switch (m_type) { + case E_Trend_Invalid: + case E_Trend_RealTime:{ + break; + } + case E_Trend_His_Minute:{ + result = 600000; + break; + } + case E_Trend_His_Hour:{ + result = 3600000; + break; + } + case E_Trend_His_Day:{ + result = 86400000; + break; + } + case E_Trend_His_Week:{ + result = 604800000; + break; + } + case E_Trend_His_Month:{ + result = origin.addMonths(1).toMSecsSinceEpoch() - time; + break; + } + case E_Trend_His_Quarter:{ + result = origin.addMonths(3).toMSecsSinceEpoch() - time; + break; + } + case E_Trend_His_Year:{ + result = origin.addYears(1).toMSecsSinceEpoch() - time; + break; + } + case E_Trend_His_Custom:{ + result = ui->endData->dateTime().toMSecsSinceEpoch() - ui->startData->dateTime().toMSecsSinceEpoch(); + break; + } + default: + break; + } + return result; +} + void CPlotWidget::alarmTextChanged(const QString &text) { Q_UNUSED(text) @@ -3420,67 +3655,51 @@ void CPlotWidget::alarmPointCheckStateChanged() void CPlotWidget::showTypeChanged(bool checked) { m_pTableDataModel->clear(); - if(checked) - { - m_showType = E_Show_Table; - - } - else - { - m_showType = E_Show_Curve; - } - ui->plot->setVisible(!checked); - ui->widget->setVisible(!checked); - ui->m_dataView->setVisible(checked); - ui->plotExport->setVisible(checked); - ui->plotPrint->setVisible(!checked); - ui->customSearch->setVisible(checked); + checked ? m_showType = E_Show_Table : m_showType = E_Show_Curve; if(m_type == E_Trend_RealTime) { - ui->adapt->setVisible(false); - ui->checkBox_alarmPoint->setVisible(false); - ui->comboBox_alarmStatus->setVisible(false); - /*if(E_Show_Table == m_showType) + if(E_Show_Table == m_showType) { updateRealTimeTableData(); - }*/ - } - else - { - if(m_isAdaptShow) - { - ui->adapt->setVisible(!checked); - } - if(m_isAlarmShow) - { - ui->checkBox_alarmPoint->setVisible(!checked); - ui->comboBox_alarmStatus->setVisible(!checked); } } - - - updateRealTimeTableData(); + afterModeSwitch(); updateCurves(); - - + graphVisibleChanged(true); } void CPlotWidget::slotStartDateChanged(const QDateTime &dateTime) { - if(ui->endData->dateTime() > dateTime) + int sec = ui->interval->currentData().toInt(); + + QDateTime endTime = ui->endData->dateTime(); + + if( endTime > dateTime ) { ui->plot->xAxis->setRangeLower(dateTime.toMSecsSinceEpoch()); + + if( (sec == 0) && (endTime.toSecsSinceEpoch() - dateTime.toSecsSinceEpoch() > THREE_DAY) ) + { + sec = THREE_DAY; + ui->startData->setDateTime(endTime.addSecs(-sec)); + } } else { - int sec = ui->interval->currentData().toInt(); - if(sec < 600) + if( sec == 0 ) + { + sec = THREE_DAY; + } + else if( sec < 600 ) { sec = 600; } - ui->startData->setDateTime(ui->endData->dateTime().addSecs(-sec)); + else + {} + + ui->startData->setDateTime(endTime.addSecs(-sec)); } if(E_Show_Curve == m_showType) @@ -3491,18 +3710,33 @@ void CPlotWidget::slotStartDateChanged(const QDateTime &dateTime) void CPlotWidget::slotEndDateChanged(const QDateTime &dateTime) { - if(ui->startData->dateTime() < dateTime) + int sec = ui->interval->currentData().toInt(); + + QDateTime startTime = ui->startData->dateTime(); + if(startTime < dateTime) { ui->plot->xAxis->setRangeUpper(dateTime.toMSecsSinceEpoch()); + + if( (sec == 0) && (dateTime.toSecsSinceEpoch() - startTime.toSecsSinceEpoch() > THREE_DAY) ) + { + sec = THREE_DAY; + ui->endData->setDateTime(startTime.addSecs(sec)); + } } else { - int sec = ui->interval->currentData().toInt(); - if(sec < 600) + if( sec == 0 ) + { + sec = THREE_DAY; + } + else if(sec < 600) { sec = 600; } - ui->endData->setDateTime(ui->startData->dateTime().addSecs(sec)); + else + {} + + ui->endData->setDateTime(startTime.addSecs(sec)); } if(E_Show_Curve == m_showType) @@ -3548,30 +3782,27 @@ void CPlotWidget::slotCustomSearch(bool isForce) enableSearch(false); std::vector vecMethod{iot_dbms::CM_MAX, iot_dbms::CM_MIN}; - updateComputeValue(lower, upper, vecMethod); - std::vector * vecMpKey = new std::vector(); - for(int nIndex(0); nIndex < ui->plot->graphCount(); ++nIndex) - { - const Curve &curve = m_pTrendGraph->curve(ui->plot->graph(nIndex)->name()); - SMeasPointKey key; - std::string tmp = curve.tag.toStdString(); - char * tag = (char*)malloc(tmp.size() + 1); - memset(tag, 0, tmp.size() + 1); - memcpy(tag, tmp.c_str(), tmp.size()); - key.m_pszTagName = tag; - key.m_enType = getMeasType(curve.type); - vecMpKey->push_back(key); + double nIntervalSecs = SAMPLE_CYC_MIN * 60 * 1000; + QList cmdList; + TsdbCommand curve = getHisCurveCmd(lower + nIntervalSecs, upper - nIntervalSecs, sec, E_HISTORY); + TsdbCommand computer = getComputeCmd(lower, upper, vecMethod, E_HISTORY); + cmdList.push_back(curve); + cmdList.push_back(computer); + if(m_bShowPreCurve){ + QPair preRange = getOffsetRange(lower, upper, -1); + TsdbCommand preCurve = getHisCurveCmd(preRange.first + nIntervalSecs, preRange.second - nIntervalSecs, sec, E_PRECURVE); + TsdbCommand perComputer = getComputeCmd(preRange.first, preRange.second, vecMethod, E_PRECURVE); + cmdList.push_back(preCurve); + cmdList.push_back(perComputer); } - double nIntervalSecs = SAMPLE_CYC_MIN * 60 * 1000; -// if(!m_pHisDataManage->isTsdbExuting()) -// { -// emit sigQueryHistoryPolymericData(vecMpKey, lower + nIntervalSecs, upper - nIntervalSecs, sec, iot_dbms::CM_FIRST); -// } -// else + if(!m_pHisDataManage->isTsdbExuting()) { - //< 添加多条曲线时,可能存在顺序混乱,导致显示列缺失,因此都使用post的方式查询 - m_pHisDataManage->postTsdbCommandQueue(E_POLYMERIC, vecMpKey, lower + nIntervalSecs, upper - nIntervalSecs, sec, std::vector{iot_dbms::CM_FIRST}); + emit sigQueryHistoryRecord(cmdList); + } + else + { + m_pHisDataManage->postTsdbCommandQueue(cmdList); } } @@ -3579,3 +3810,8 @@ void CPlotWidget::slotEnableSearch(bool enable) { enableSearch(!enable); } + +void CPlotWidget::setEnableAddNanFlag(bool bEnable) +{ + m_bEnableNan = bEnable; +} diff --git a/product/src/gui/plugin/TrendCurves/CPlotWidget.h b/product/src/gui/plugin/TrendCurves/CPlotWidget.h index 294e8bb9..cb4dfd17 100644 --- a/product/src/gui/plugin/TrendCurves/CPlotWidget.h +++ b/product/src/gui/plugin/TrendCurves/CPlotWidget.h @@ -1,4 +1,4 @@ -#ifndef CPLOTWIDGET_H +#ifndef CPLOTWIDGET_H #define CPLOTWIDGET_H #include @@ -85,10 +85,14 @@ public: void setClearVisible(bool visible); + void setEnableAddNanFlag(bool bEnable); + void setAdaptVisible(bool visible); void setAlarmPointVisible(bool visible); + void setPreCurveVisible(bool visible); + void insertCurve(Curve curve); void clear(bool clearTitle = false); @@ -115,6 +119,10 @@ public: QColor plotTickPen(); void setPlotTickPen(const QColor &color); + //用于重新设置自定义界面中的周期间隔 + void clearCustomInterval(); + void addCustomInterval(const QString &desc,const int &sec); + signals: void clearCurve(); 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 releaseHisDataThread(); void releaseHisEventThread(); - - void sigQueryHistoryOriginalData(std::vector *vecMpKey, - double lower, double upper, - E_Data_Type type = E_HISTORY); - - void sigQueryHistoryPolymericData(std::vector *vecMpKey, - double lower, double upper, int nGroupByMinute, iot_dbms::EnComputeMethod method); - - void sigQueryHistoryComputeData(std::vector *vecMpKey, - double lower, double upper, - std::vector method); - - void sigQueryHistoryEvent(std::vector *vecMpKey, - double lower, double upper, - iot_dbms::EnComputeMethod enCM, - int nGroupByMinute); + void sigQueryHistoryRecord(const QList &cmdList); void sigAddCollect(int x, int y); void sigHideCollect(); @@ -165,13 +158,14 @@ private slots: void updateTrendShowMode(int nIndex, bool updateXAxisRange = true); - void updateComputeValue(double lower, double upper, std::vector vecMethod); + TsdbCommand getHisCurveCmd(double lower, double upper, int nGroupBy, E_Data_Type type); + TsdbCommand getComputeCmd(double lower, double upper, std::vector vecMethod, E_Data_Type type); void updateCurves(); void updateRealTimeCurveRecord(); - void updateHistoryCurveRecord(double lower, double upper); + void updateHistoryCurveRecord(); void updateHisOriginalData(std::vector *vecMpKey, std::vector *> *vecResult, @@ -179,23 +173,28 @@ private slots: void updateHisPolymericData(std::vector *vecMpKey, std::vector *> *vecResult, - int nGroupBySec); + int nGroupBySec, + E_Data_Type type = E_HISTORY); void updateHisComputeData(std::vector *vecMpKey, - std::vector *> *> > cmResult); + std::vector *> *> > cmResult, + E_Data_Type type = E_HISTORY); void updateHistoryGraph(std::vector *vecMpKey, std::vector< QSharedPointer > &vecContainer, - std::vector< QSharedPointer > &vecRange); + std::vector< QSharedPointer > &vecRange, + E_Data_Type type); void updateHistoryData(std::vector *vecMpKey, std::vector< QSharedPointer > &vecContainer, - std::vector< QSharedPointer > &vecRange); + std::vector< QSharedPointer > &vecRange, + E_Data_Type type); void updateCurveHisData(double lower, double upper, QCPGraph * graph, int index, QSharedPointer container, - QSharedPointer range); + QSharedPointer range, + E_Data_Type type); void updatePhaseTracer(std::vector *vecMpKey, std::vector *> *vecResult); @@ -204,6 +203,7 @@ private slots: void updateAxisFormat(bool updateXAxisRange); QPair getFatureDataTime(E_Trend_Type type, QDateTime curTime = QDateTime()); void updateAdaptState(bool isAdapt); + void updatePreCurveState(bool isPreCurve); void addCollect(); void slotPrint(); void slotExport(); @@ -263,6 +263,7 @@ private: std::vector< QSharedPointer > &vecRange, std::vector< QSharedPointer > &vecContainer, double lower, double upper, + E_Data_Type type, bool isAddVirtualPoint = false, int nGroupBySec = 0); @@ -272,7 +273,7 @@ private: template 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); @@ -289,11 +290,15 @@ private: void resetCurveData(const QMap>& dataMap, const QStringList& headerList, bool ascs = true); void enableSearch(bool enable); + void afterModeSwitch(); + QPair getOffsetRange(const double &lower, const double &upper, int direction); + double getOffsetTime(const double &time); private: Ui::CPlotWidget *ui; E_Trend_Type m_type; E_Show_Type m_showType; bool m_bHisAdaption; + bool m_bShowPreCurve; QButtonGroup * m_TrendTypeButton; CCurveLegendModel * m_pLengedModel; CTableDataModel * m_pTableDataModel; @@ -331,6 +336,10 @@ private: bool m_isTooltip; bool m_isAdaptShow; bool m_isAlarmShow; + bool m_isPreCurveShow; + bool m_bEnableNan;//caodingfa:定时存盘周期可变时,原有逻辑会导致每个间隔插入一个Nan值,导致无效,为不影响原逻辑,增加一个开关 + + const int THREE_DAY = 3*24*60*60; // 查询全部数据时, 最多查询3天, 避免数据过多导致界面卡顿 }; #endif // CPLOTWIDGET_H diff --git a/product/src/gui/plugin/TrendCurves/CPlotWidget.ui b/product/src/gui/plugin/TrendCurves/CPlotWidget.ui index 82ecce4d..c9217a8a 100644 --- a/product/src/gui/plugin/TrendCurves/CPlotWidget.ui +++ b/product/src/gui/plugin/TrendCurves/CPlotWidget.ui @@ -83,26 +83,28 @@ 0 - - - - - 0 - 0 - - - - - 42 - 24 - - - - 对比 - - - true - + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + @@ -124,30 +126,59 @@ - + + + + + 0 + 0 + + + + + 50 + 24 + + + + 对比 + + + true + + + + - 130 + 208 0 - + 收藏 - + 导出 + + + + 打印 + + + @@ -164,13 +195,6 @@ - - - - 打印 - - - @@ -249,28 +273,23 @@ - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - + + + + + 0 + 0 + + + + + 0 + 24 + + + + 昨日曲线 + diff --git a/product/src/gui/plugin/TrendCurves/CRealTimeDataCollect.cpp b/product/src/gui/plugin/TrendCurves/CRealTimeDataCollect.cpp index 33affd25..e19b6bf4 100644 --- a/product/src/gui/plugin/TrendCurves/CRealTimeDataCollect.cpp +++ b/product/src/gui/plugin/TrendCurves/CRealTimeDataCollect.cpp @@ -1,4 +1,4 @@ -#include "CRealTimeDataCollect.h" +#include "CRealTimeDataCollect.h" #include "MessageChannel.h" #include "DataProcMessage.pb.h" #include "pub_logger_api/logger.h" diff --git a/product/src/gui/plugin/TrendCurves/CRealTimeDataCollect.h b/product/src/gui/plugin/TrendCurves/CRealTimeDataCollect.h index c2ca4818..e3894dfb 100644 --- a/product/src/gui/plugin/TrendCurves/CRealTimeDataCollect.h +++ b/product/src/gui/plugin/TrendCurves/CRealTimeDataCollect.h @@ -1,4 +1,4 @@ -#ifndef CREALTIMEDATACOLLECT_H +#ifndef CREALTIMEDATACOLLECT_H #define CREALTIMEDATACOLLECT_H #include diff --git a/product/src/gui/plugin/TrendCurves/CTableDataModel.cpp b/product/src/gui/plugin/TrendCurves/CTableDataModel.cpp index 4db96557..beefe8b6 100644 --- a/product/src/gui/plugin/TrendCurves/CTableDataModel.cpp +++ b/product/src/gui/plugin/TrendCurves/CTableDataModel.cpp @@ -1,4 +1,4 @@ -#include "CTableDataModel.h" +#include "CTableDataModel.h" CTableDataModel::CTableDataModel(QObject *parent) : QAbstractTableModel(parent), @@ -20,7 +20,7 @@ void CTableDataModel::clear() { beginResetModel(); m_curveDataMap.clear(); - m_header.clear(); + //m_header.clear(); m_timeList.clear(); m_bAscs = true; endResetModel(); @@ -227,3 +227,31 @@ QVariant CTableDataModel::data(const QModelIndex &index, int role) const 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(); +} diff --git a/product/src/gui/plugin/TrendCurves/CTableDataModel.h b/product/src/gui/plugin/TrendCurves/CTableDataModel.h index f78e7282..7b56d70b 100644 --- a/product/src/gui/plugin/TrendCurves/CTableDataModel.h +++ b/product/src/gui/plugin/TrendCurves/CTableDataModel.h @@ -1,4 +1,4 @@ -#ifndef CTABLEDATAMODEL_H +#ifndef CTABLEDATAMODEL_H #define CTABLEDATAMODEL_H #include @@ -37,5 +37,15 @@ private: QList m_timeList; 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 diff --git a/product/src/gui/plugin/TrendCurves/CTableView.cpp b/product/src/gui/plugin/TrendCurves/CTableView.cpp index 5a5658ac..83bf25dc 100644 --- a/product/src/gui/plugin/TrendCurves/CTableView.cpp +++ b/product/src/gui/plugin/TrendCurves/CTableView.cpp @@ -1,4 +1,4 @@ -#include "CTableView.h" +#include "CTableView.h" #include CTableView::CTableView(QWidget *parent) @@ -30,3 +30,35 @@ void CTableView::setTableRowHeight(const int &nHeight) 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); + } + } +} diff --git a/product/src/gui/plugin/TrendCurves/CTableView.h b/product/src/gui/plugin/TrendCurves/CTableView.h index 6335001f..b200ded1 100644 --- a/product/src/gui/plugin/TrendCurves/CTableView.h +++ b/product/src/gui/plugin/TrendCurves/CTableView.h @@ -1,4 +1,4 @@ -#ifndef CTABLEVIEW_H +#ifndef CTABLEVIEW_H #define CTABLEVIEW_H #include @@ -17,6 +17,9 @@ public: int tableRowHeight(); void setTableRowHeight(const int &nHeight); + void adjustHeaderWidth(); +protected: + void showEvent(QShowEvent *event) override ; private: int m_nTableColWidth; diff --git a/product/src/gui/plugin/TrendCurves/CTrendEditDialog.cpp b/product/src/gui/plugin/TrendCurves/CTrendEditDialog.cpp index 799c6de7..c67af848 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendEditDialog.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendEditDialog.cpp @@ -1,9 +1,10 @@ -#include +#include #include "CTrendEditDialog.h" #include "ui_CTrendEditDialog.h" #include "CTrendEditModel.h" #include "GraphTool/Retriever/CRetriever.h" #include "pub_utility_api/FileUtil.h" +#include "CTableDataModel.h" using namespace iot_dbms; @@ -16,6 +17,10 @@ CTrendEditDialog::CTrendEditDialog(QWidget *parent) : ui->setupUi(this); ui->m_retrieverWidget->setWindowFlags(Qt::Widget); ui->m_retrieverWidget->setMultVisible(false); + ui->m_retrieverWidget->setCloseBtnVisible(false); + ui->m_retrieverWidget->installEventFilter(this); + ui->frame->setFixedWidth(320); + setMinimumWidth(1200); //setWindowModality(Qt::WindowModal); initialize(); connect(ui->addCurve, SIGNAL(clicked()), this, SLOT(slot_addCureve())); @@ -53,6 +58,8 @@ void CTrendEditDialog::initTrendView() ui->trendView->setAlternatingRowColors(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); } @@ -68,6 +75,16 @@ void CTrendEditDialog::resizeEvent(QResizeEvent *event) updateTrendViewColumnWidth(); } +bool CTrendEditDialog::eventFilter(QObject *o, QEvent *e) +{ + if( e->type() == QEvent::MouseMove ) + { + return true; + } + + return QDialog::eventFilter(o, e); +} + void CTrendEditDialog::updateTrendViewColumnWidth() { diff --git a/product/src/gui/plugin/TrendCurves/CTrendEditDialog.h b/product/src/gui/plugin/TrendCurves/CTrendEditDialog.h index 39153e53..b0d056f1 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendEditDialog.h +++ b/product/src/gui/plugin/TrendCurves/CTrendEditDialog.h @@ -1,4 +1,4 @@ -#ifndef CTRENDEDITDIALOG_H +#ifndef CTRENDEDITDIALOG_H #define CTRENDEDITDIALOG_H #include @@ -28,6 +28,7 @@ public: protected: void showEvent(QShowEvent *event); void resizeEvent(QResizeEvent *event); + bool eventFilter(QObject *o, QEvent *e); protected slots: void slot_updateTrend(); diff --git a/product/src/gui/plugin/TrendCurves/CTrendEditModel.cpp b/product/src/gui/plugin/TrendCurves/CTrendEditModel.cpp index a46deb26..08fcc893 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendEditModel.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendEditModel.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include "CTrendGraph.h" diff --git a/product/src/gui/plugin/TrendCurves/CTrendEditModel.h b/product/src/gui/plugin/TrendCurves/CTrendEditModel.h index 93c9367f..17089c63 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendEditModel.h +++ b/product/src/gui/plugin/TrendCurves/CTrendEditModel.h @@ -1,4 +1,4 @@ -#ifndef CTRENDEDITMODEL_H +#ifndef CTRENDEDITMODEL_H #define CTRENDEDITMODEL_H /***************************************** diff --git a/product/src/gui/plugin/TrendCurves/CTrendEditView.cpp b/product/src/gui/plugin/TrendCurves/CTrendEditView.cpp index d6425e44..8d2d6e12 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendEditView.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendEditView.cpp @@ -1,4 +1,4 @@ -#include "CTrendEditView.h" +#include "CTrendEditView.h" #include #include #include @@ -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(textWidth) / maxWidthThreshold); + } else { + header->resizeSection(section, textWidth); + } + + maxHeightMultiplier = qMax(maxHeightMultiplier, heightMultiplier); + } + + header->setFixedHeight(maxHeightMultiplier * baseHeight); +} + void CTrendEditView::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasText()) @@ -96,3 +132,9 @@ void CTrendEditView::dropEvent(QDropEvent *event) } event->accept(); } + +void CTrendEditView::showEvent(QShowEvent *event) +{ + QTableView::showEvent(event); + adjustHeaderWidth(); +} diff --git a/product/src/gui/plugin/TrendCurves/CTrendEditView.h b/product/src/gui/plugin/TrendCurves/CTrendEditView.h index 313e06a4..0e0b8480 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendEditView.h +++ b/product/src/gui/plugin/TrendCurves/CTrendEditView.h @@ -1,4 +1,4 @@ -#ifndef CTRENDEDITVIEW_H +#ifndef CTRENDEDITVIEW_H #define CTRENDEDITVIEW_H #include "CTableView.h" @@ -12,10 +12,12 @@ public: public slots: void appendTagName(const QString &strTagName, const QString &strTagDesc, bool isMulti); + void adjustHeaderWidth(); protected: void dragEnterEvent(QDragEnterEvent *event); void dragMoveEvent(QDragMoveEvent *event); void dropEvent(QDropEvent *event); + void showEvent(QShowEvent *event) override ; }; #endif // CTRENDEDITVIEW_H diff --git a/product/src/gui/plugin/TrendCurves/CTrendFavTreeWidget.cpp b/product/src/gui/plugin/TrendCurves/CTrendFavTreeWidget.cpp index a44f2cbb..46574f7d 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendFavTreeWidget.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendFavTreeWidget.cpp @@ -1,4 +1,4 @@ -#include "CTrendFavTreeWidget.h" +#include "CTrendFavTreeWidget.h" #include "CTrendEditDialog.h" #include #include @@ -159,12 +159,26 @@ void CTrendFavTreeWidget::slotEditTrendEdit() void CTrendFavTreeWidget::slotRemoveTrendEdit() { - QList selectItem = selectedItems(); - foreach (QTreeWidgetItem *item, selectItem) { - int index = indexOfTopLevelItem(item); - takeTopLevelItem(index); + int ret=QMessageBox::question(this, tr("提示"), tr("确定删除所选项吗?"), QMessageBox::Yes,QMessageBox::No); + if(QMessageBox::Yes==ret) + { + QList 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) @@ -181,6 +195,8 @@ void CTrendFavTreeWidget::slotItemChanged(QTreeWidgetItem *item, int column) return; } } + + emit updateTitle(content); } void CTrendFavTreeWidget::slotImport() @@ -213,7 +229,7 @@ void CTrendFavTreeWidget::slotExport() QString CTrendFavTreeWidget::getNewValidTitle() { - QString title = QString("自定义趋势_"); + QString title = QString(tr("自定义趋势_")); QStringList listItemText; for(int nIndex(0); nIndex < topLevelItemCount(); nIndex++) { @@ -348,6 +364,10 @@ void CTrendFavTreeWidget::savaTrendGraph(const QString &filePath, const QList @@ -20,6 +20,7 @@ public: signals: void showTrendGraph(CTrendGraph * graph, QString name); + void updateTitle(QString name); public slots: void collectGraph(const QString &title, const CTrendGraph &graph); diff --git a/product/src/gui/plugin/TrendCurves/CTrendGraph.cpp b/product/src/gui/plugin/TrendCurves/CTrendGraph.cpp index cd61158b..950566c1 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendGraph.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendGraph.cpp @@ -1,4 +1,4 @@ -#include "CTrendGraph.h" +#include "CTrendGraph.h" #include #include "plot/qcustomplot.h" @@ -34,24 +34,28 @@ const QList CTrendGraph::curveColors() const 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++) { - 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); } } 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++) { - if(m_listCurve.at(nIndex).tag == tag) + if(m_listCurve.at(nIndex).tag == tag && m_listCurve.at(nIndex).curveType == curType) { return nIndex; } @@ -69,17 +73,28 @@ void CTrendGraph::addCurve(const Curve &curve) m_listCurve.append(curve); } -int CTrendGraph::removeCurve(const QString &tag) +QList CTrendGraph::removeCurve(const QString &tag) { + QList removeList; for(int nIndex(m_listCurve.size() - 1); nIndex >= 0; nIndex--) { if(m_listCurve.at(nIndex).tag == tag) { 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) @@ -112,11 +127,11 @@ void CTrendGraph::setCurveGraphOffset(const int &nIndex, const double &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++) { - 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].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) { //< 保留20min实时数据 - int nIndex = m_listCurve.indexOf(tag); + int nIndex = m_listCurve.indexOf(tag); //< 实时数据索引一定在前面 if (-1 == nIndex || qIsNaN(value)) { 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++) { - 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].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++) { - 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].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++) { - 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].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++) { - 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].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++) { - if(m_listCurve.at(nIndex).tag == strTagName) + if(m_listCurve.at(nIndex).tag == strTagName && m_listCurve.at(nIndex).curveType == curType) { updateRTCurveStatisticsInfo(m_listCurve[nIndex]); return; diff --git a/product/src/gui/plugin/TrendCurves/CTrendGraph.h b/product/src/gui/plugin/TrendCurves/CTrendGraph.h index f17e5ee8..1563aa0f 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendGraph.h +++ b/product/src/gui/plugin/TrendCurves/CTrendGraph.h @@ -1,4 +1,4 @@ -#ifndef CTRENDGRAPH_H +#ifndef CTRENDGRAPH_H #define CTRENDGRAPH_H #include @@ -28,9 +28,15 @@ struct Range double max; }; +enum Type +{ + enRealCurve = 0, //< 实际测点曲线 + enPrevCurve //< 昨日曲线 +}; + struct Curve { - Curve(const QString &strTagName = QString()) + Curve(const QString &strTagName = QString(), Type type = enRealCurve) : visible(true), rtMax(-DBL_MAX), rtMin(DBL_MAX), @@ -56,11 +62,12 @@ struct Curve desc(QString()), type(QString()), unit(QString()), - color(QColor()){} + color(QColor()), + curveType(type){} 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 @@ -97,6 +104,7 @@ struct Curve QString type; QString unit; QColor color; + Type curveType; QVector< QPair > > values; }; @@ -113,13 +121,14 @@ public: const QList curveColors() const; - const Curve &curve(const QString &tag) const; - int index(const QString &tag) const; + const Curve &curve(const QString &tag, const int &curType) const; + int index(const QString &tag, const int &curType = enRealCurve) const; void clear(); void addCurve(const Curve &curve); - int removeCurve(const QString &tag); + QList removeCurve(const QString &tag); + bool removeCurve(const int &nIndex); void setCurveVisible(const int &nIndex, const bool &visible); @@ -127,20 +136,20 @@ public: void setCurveFactor(const int &nIndex, const double &factor); 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 setCurveStatisMax(const QString &tag, const double &max, const double &maxTime); - void setCurveStatisMin(const QString &tag, const double &min, const double &minTime); + void setCurveStatisMax(const QString &tag, const int &curType, const double &max, const double &maxTime); + void setCurveStatisMin(const QString &tag, const int &curType, const double &min, const double &minTime); - void resetCurveStatisMax(const QString &tag); - void resetCurveStatisMin(const QString &tag); + void resetCurveStatisMax(const QString &tag, const int &curType); + void resetCurveStatisMin(const QString &tag, const int &curType); void setCurveGraphFactor(const int &nIndex, const double &factor); 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); private: diff --git a/product/src/gui/plugin/TrendCurves/CTrendInfoManage.cpp b/product/src/gui/plugin/TrendCurves/CTrendInfoManage.cpp index cc4a8d7a..617a24b4 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendInfoManage.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendInfoManage.cpp @@ -1,10 +1,11 @@ -#include "CTrendInfoManage.h" +#include "CTrendInfoManage.h" #include "service/perm_mng_api/PermMngApi.h" #include "pub_sysinfo_api/SysInfoApi.h" #include "pub_utility_api/CharUtil.h" #include "pub_utility_api/FileUtil.h" #include "perm_mng_api/PermMngApi.h" #include "pub_logger_api/logger.h" +#include using namespace iot_dbms; using namespace iot_public; @@ -23,6 +24,8 @@ CTrendInfoManage *CTrendInfoManage::instance() CTrendInfoManage::CTrendInfoManage() { + m_bLoadTagInfoWhenInit = false; //默认加载所有信息 + loadCfg(); //加载配置文件,会重新覆盖掉默认参数值 //< 实时库 m_rtdbAccess = new iot_dbms::CRdbAccess(); @@ -40,7 +43,13 @@ CTrendInfoManage::CTrendInfoManage() loadRTLocation(); loadDevGroupInfo(pReadDb); loadDeviceInfo(pReadDb); - loadTagInfo(pReadDb); + + //通过setEnableDynamicLoadTag函数加载了,默认不加载测点,防止测点太多打开趋势页面太慢 + //loadAllTagInfo(pReadDb); + if(m_bLoadTagInfoWhenInit) + { + loadAllTagInfo(pReadDb); + } loadStateDefine(); loadAlarmStatusDefine(); loadAlarmStatus(); @@ -61,7 +70,6 @@ void CTrendInfoManage::destory() m_locationInfo.clear(); m_devGroupInfo.clear(); - m_devLocation.clear(); m_deviceInfo.clear(); m_listTagName.clear(); m_listTagInfo.clear(); @@ -255,6 +263,50 @@ QMap CTrendInfoManage::getAlarmOtherStatus() 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() { iot_service::CPermMngApiPtr permMngPtr = iot_service::getPermMngInstance("base"); @@ -377,18 +429,21 @@ void CTrendInfoManage::loadDeviceInfo(CDbApi *pReadDb) pReadDb->execute(sqlSequenceQuery, query); while(query.next()) { - const QString &tag_name = query.value(0).toString(); - const QString &description = query.value(1).toString(); - const QString &group_tag_name = query.value(2).toString(); - const int location_id = query.value(0).toInt(); + //const QString &tag_name = query.value(0).toString(); + //const QString &description = query.value(1).toString(); + //const QString &group_tag_name = query.value(2).toString(); - m_deviceInfo[group_tag_name].insert(tag_name, description); - m_devLocation[location_id].insert(tag_name, description); + m_deviceInfo[query.value(2).toString()].insert(query.value(0).toString(), query.value(1).toString()); } } -void CTrendInfoManage::loadTagInfo(CDbApi *pReadDb) +bool CTrendInfoManage::loadTagInfo(CDbApi *pReadDb, const QStringList &listDevice) { + if(listDevice.isEmpty()) + { + return false; + } + QSqlQuery query; QStringList listType; listType.append(QStringLiteral("analog")); @@ -396,19 +451,8 @@ void CTrendInfoManage::loadTagInfo(CDbApi *pReadDb) listType.append(QStringLiteral("accuml")); // listType.append(QString("mix")); - QString strDeviceFilter; - if(!m_deviceInfo.isEmpty()) - { - QStringList listDevice; - QMap >::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); - } + QString strDeviceFilter = "'" % listDevice.join("', '") % "'"; + strDeviceFilter = QString("(%1 in (%2))").arg("device").arg(strDeviceFilter); query.setForwardOnly(true); 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)); } + pReadDb->execute(sqlSequenceQuery, query); 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 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; - - //QString strUnitDesc = m_listTagUnit.value(query.value(5).toInt(), QString()); - // m_listTagInfo[tagName] = QStringList() << strDescription << strCurType << m_listTagUnit.value(query.value(5).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; + m_listTagInfo[tagName] = QStringList() << strDescription << strCurType << m_listTagUnit.value(query.value(6).toInt(), QString()); } } + + return true; +} + +void CTrendInfoManage::loadAllTagInfo(iot_dbms::CDbApi *pReadDb) +{ + QStringList listDevice; + QMap >::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) @@ -608,3 +660,47 @@ void CTrendInfoManage::initInvalidStatus() m_nInvalidDigital |= (temp << getStateActualValue("MENU_STATE_DI_SINHIBIT_REF")); //< 屏蔽禁止刷新 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"); + } + } + } +} diff --git a/product/src/gui/plugin/TrendCurves/CTrendInfoManage.h b/product/src/gui/plugin/TrendCurves/CTrendInfoManage.h index 7ab066e3..23b07248 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendInfoManage.h +++ b/product/src/gui/plugin/TrendCurves/CTrendInfoManage.h @@ -1,4 +1,4 @@ -#ifndef CTRENDINFOMANAGE_H +#ifndef CTRENDINFOMANAGE_H #define CTRENDINFOMANAGE_H #include @@ -7,7 +7,19 @@ #include #include "dbms/rdb_api/CRdbAccess.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" + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #include "boost/typeof/typeof.hpp" #include "boost/filesystem.hpp" @@ -62,13 +74,20 @@ public: QMap getAlarmOtherStatus(); + //加载指定设备组下测点的信息,为空代表加载所有设备组的测点 + bool loadTagInfoByDevGroup(const QString &strDevGrpTag); + //加载指定设备下的测点信息,为空代表加载所有设备 + bool loadTagInfoByDevTag(const QStringList &listDevTag); + private: CTrendInfoManage(); void loadRTLocation(); void loadDevGroupInfo(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 loadStateDefine(); void loadAlarmStatusDefine(); @@ -76,12 +95,13 @@ private: void loadAlarmOtherStatus(); void initInvalidStatus(); + void loadCfg(); + private: iot_dbms::CRdbAccess * m_rtdbAccess; QMap m_locationInfo; //< LocationID-LocationDesc QMap > m_devGroupInfo; //< LocationID- 新增设备组 QMap > > m_devGroupInfoMap; - QMap > m_devLocation; //< LocationID- 新增设备组 QMap > m_deviceInfo; //< DevGroupName- 新增设备组时修改 QMap m_listTagName; //< DeviceName-list QHash m_listTagInfo; //< TagName-TagInfo @@ -93,7 +113,7 @@ private: QList m_locationOrderList; //< location_id: 按location_no排序 int m_nInvalidAnalog; int m_nInvalidDigital; - + bool m_bLoadTagInfoWhenInit; //第一次是否加载所有的测点数据,默认加载 static CTrendInfoManage * m_pInstance; }; diff --git a/product/src/gui/plugin/TrendCurves/CTrendPluginWidget.cpp b/product/src/gui/plugin/TrendCurves/CTrendPluginWidget.cpp index b857fe30..e8b1fdd8 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendPluginWidget.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendPluginWidget.cpp @@ -1,4 +1,4 @@ -#include +#include #include "CTrendPluginWidget.h" #include "CTrendWindow.h" diff --git a/product/src/gui/plugin/TrendCurves/CTrendPluginWidget.h b/product/src/gui/plugin/TrendCurves/CTrendPluginWidget.h index 620317a8..06c92ce7 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendPluginWidget.h +++ b/product/src/gui/plugin/TrendCurves/CTrendPluginWidget.h @@ -1,4 +1,4 @@ -#ifndef CTRENDPLUGINWIDGET_H +#ifndef CTRENDPLUGINWIDGET_H #define CTRENDPLUGINWIDGET_H #include @@ -7,7 +7,7 @@ class CTrendPluginWidget : public QObject, public CPluginWidgetInterface { Q_OBJECT - Q_PLUGIN_METADATA(IID "kbd.PluginWidgetInterface/1.0") + Q_PLUGIN_METADATA(IID HMI_WidgetPlugin_IID) Q_INTERFACES(CPluginWidgetInterface) public: diff --git a/product/src/gui/plugin/TrendCurves/CTrendTreeItem.cpp b/product/src/gui/plugin/TrendCurves/CTrendTreeItem.cpp index a4946827..0285a476 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendTreeItem.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendTreeItem.cpp @@ -1,4 +1,4 @@ -#include +#include #include "CTrendTreeItem.h" CTrendTreeItem::CTrendTreeItem(int type) diff --git a/product/src/gui/plugin/TrendCurves/CTrendTreeItem.h b/product/src/gui/plugin/TrendCurves/CTrendTreeItem.h index b172400a..2adc9aaa 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendTreeItem.h +++ b/product/src/gui/plugin/TrendCurves/CTrendTreeItem.h @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ diff --git a/product/src/gui/plugin/TrendCurves/CTrendTreeModel.cpp b/product/src/gui/plugin/TrendCurves/CTrendTreeModel.cpp index 343a9228..52989220 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendTreeModel.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendTreeModel.cpp @@ -1,4 +1,4 @@ -#include "CTrendTreeModel.h" +#include "CTrendTreeModel.h" #include "CTrendInfoManage.h" #include #include "pub_logger_api/logger.h" @@ -65,13 +65,12 @@ void CTrendTreeModel::initTrendTagInfo() ++iter_device; continue; } -// QTreeWidgetItem * devItem = new QTreeWidgetItem(devGroupItem, QStringList() << iter_device.value(), DEV_TYPE); -// devItem->setData(0, ItemTagRole, iter_device.key()); + QTreeWidgetItem * devItem = new QTreeWidgetItem(devGroupItem, QStringList() << iter_device.value(), DEV_TYPE); + devItem->setData(0, ItemTagRole, iter_device.key()); QStringList::const_iterator iter_tag = listTagName.constBegin(); while (iter_tag != listTagName.constEnd()) { -// 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); + QTreeWidgetItem * tagItem = new QTreeWidgetItem(devItem, QStringList() << CTrendInfoManage::instance()->getTagDescription(*iter_tag).section(".", -1), TAG_TYPE); tagItem->setData(0, ItemTagRole, *iter_tag); tagItem->setToolTip(0, *iter_tag); ++iter_tag; @@ -86,10 +85,10 @@ void CTrendTreeModel::initTrendTagInfo() { return; } - for(int n=0; nchildCount(); n++) - { - m_pView->expand(index(n,0)); - } +// for(int n=0; nchildCount(); n++) +// { +// m_pView->expand(index(n,0)); +// } } 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) { - if(!index.isValid()) { return false; @@ -221,7 +219,11 @@ bool CTrendTreeModel::setData(const QModelIndex &index, const QVariant &value, i { 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); } @@ -254,8 +256,7 @@ void CTrendTreeModel::setChildrenCheckState(const QModelIndex &index, const Qt:: { return; } -// if(DEV_TYPE == item->type()) - if(DEV_GROUP_TYPE == item->type()) + if(DEV_TYPE == item->type()) { 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) { if(!index.isValid()) @@ -378,16 +395,16 @@ void CTrendTreeModel::updateTagCheckState(const QString &tag, const bool &checke QTreeWidgetItem * deviceGroupItem = locationItem->child(nDeviceGroupRow); for(int nDeviceRow(0); nDeviceRow < deviceGroupItem->childCount(); nDeviceRow++) { -// QTreeWidgetItem * deviceItem = deviceGroupItem->child(nDeviceRow); -// for(int nTagRow(0); nTagRow < deviceItem->childCount(); nTagRow++) -// { - QTreeWidgetItem * tagItem = deviceGroupItem->child(nDeviceRow); + QTreeWidgetItem * deviceItem = deviceGroupItem->child(nDeviceRow); + for(int nTagRow(0); nTagRow < deviceItem->childCount(); nTagRow++) + { + QTreeWidgetItem * tagItem = deviceItem->child(nTagRow); if(tag == tagItem->data(0, ItemTagRole).toString()) { tagItem->setCheckState(0, checked ? Qt::Checked : Qt::Unchecked); return; } -// } + } } } } diff --git a/product/src/gui/plugin/TrendCurves/CTrendTreeModel.h b/product/src/gui/plugin/TrendCurves/CTrendTreeModel.h index 6240ebe1..36748ab0 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendTreeModel.h +++ b/product/src/gui/plugin/TrendCurves/CTrendTreeModel.h @@ -1,4 +1,4 @@ -#ifndef CTRENDTREEMODEL_H +#ifndef CTRENDTREEMODEL_H #define CTRENDTREEMODEL_H #include @@ -45,6 +45,12 @@ public: void updateNodeVisualState(const QString &content, QItemSelection &selection); + //加载指定设备组下测点的信息,为空代表加载所有设备组的测点 + void loadTagInfoByDevGroup(const QString &strDevGrpTag); + + //加载指定设备下的测点信息,为空代表加载所有设备 + void loadTagInfoByDevTag(const QStringList &listDevTag); + signals: void itemCheckStateChanged(const QString &strTagName, const int &checkedState); diff --git a/product/src/gui/plugin/TrendCurves/CTrendTreeView.cpp b/product/src/gui/plugin/TrendCurves/CTrendTreeView.cpp index 7429b244..c4c9fc7d 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendTreeView.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendTreeView.cpp @@ -1,4 +1,4 @@ -#include "CTrendTreeView.h" +#include "CTrendTreeView.h" #include "CTrendTreeModel.h" #include #include @@ -18,8 +18,7 @@ void CTrendTreeView::contextMenuEvent(QContextMenuEvent *event) QTreeWidgetItem * pItem = static_cast(indexAt(event->pos()).internalPointer()); if(Q_NULLPTR != pItem) { -// if(DEV_TYPE == pItem->type()) - if(DEV_GROUP_TYPE == pItem->type()) + if(DEV_TYPE == pItem->type()) { QMenu menu; 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); 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); diff --git a/product/src/gui/plugin/TrendCurves/CTrendWindow.cpp b/product/src/gui/plugin/TrendCurves/CTrendWindow.cpp index ed7cc732..32f5ff54 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendWindow.cpp +++ b/product/src/gui/plugin/TrendCurves/CTrendWindow.cpp @@ -1,4 +1,4 @@ -#include "CTrendWindow.h" +#include "CTrendWindow.h" #include #include #include @@ -218,6 +218,14 @@ void CTrendWindow::setAlarmPointVisible(bool visible) } } +void CTrendWindow::setPreCurveVisible(bool visible) +{ + if(m_plotWidget) + { + m_plotWidget->setPreCurveVisible(visible); + } +} + void CTrendWindow::initWindow() { m_pTagWidget = new QTabWidget(this); @@ -246,6 +254,8 @@ void CTrendWindow::initWindow() m_pTagWidget->addTab(pFavoritesTreeWidget, tr("收藏夹")); m_pTagWidget->setContentsMargins(1,1,1,1); m_pTagWidget->setCurrentIndex(1); + m_pTagWidget->setMinimumWidth(290); + m_plotWidget = new CPlotWidget(this); m_plotWidget->initialize(); 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_pTrendTreeModel, &CTrendTreeModel::itemCheckStateChanged, this, &CTrendWindow::itemCheckStateChanged); connect(pFavoritesTreeWidget, &CTrendFavTreeWidget::showTrendGraph, this, &CTrendWindow::showTrendGraph); + connect(pFavoritesTreeWidget, &CTrendFavTreeWidget::updateTitle, this, &CTrendWindow::setTitle); if(!m_isEditMode) { @@ -480,6 +491,13 @@ void CTrendWindow::updateTrendName(const QString &title) 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(); if(!name.isEmpty()) { @@ -541,3 +559,27 @@ bool CTrendWindow::eventFilter(QObject *watched, QEvent *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); + } +} + diff --git a/product/src/gui/plugin/TrendCurves/CTrendWindow.h b/product/src/gui/plugin/TrendCurves/CTrendWindow.h index 452d9201..0769381a 100644 --- a/product/src/gui/plugin/TrendCurves/CTrendWindow.h +++ b/product/src/gui/plugin/TrendCurves/CTrendWindow.h @@ -1,4 +1,4 @@ -#ifndef CTRENDWINDOW_H +#ifndef CTRENDWINDOW_H #define CTRENDWINDOW_H #include @@ -48,6 +48,12 @@ public slots: void setDevTreeVisible(bool visible); void setAdaptVisible(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 logout(); diff --git a/product/src/gui/plugin/TrendCurves/TrendCurves.pro b/product/src/gui/plugin/TrendCurves/TrendCurves.pro index 64b6db69..e6c2902c 100644 --- a/product/src/gui/plugin/TrendCurves/TrendCurves.pro +++ b/product/src/gui/plugin/TrendCurves/TrendCurves.pro @@ -7,6 +7,7 @@ QT += core gui widgets sql xml printsupport + TARGET = TrendCurves TEMPLATE = lib @@ -14,6 +15,7 @@ CONFIG += plugin INCLUDEPATH += $$PWD + SOURCES += \ $$PWD/plot/qcustomplot.cpp \ $$PWD/widgets/CTabButton.cpp \ @@ -23,6 +25,8 @@ SOURCES += \ $$PWD/widgets/QxtSpanSlider.cpp \ $$PWD/widgets/CSWitchButton.cpp \ $$PWD/widgets/CSliderRangeWidget.cpp \ + $$PWD/widgets/CMyCheckBox.cpp \ + $$PWD/widgets/CMyListWidget.cpp \ CTrendWindow.cpp \ CTrendGraph.cpp \ CPlotWidget.cpp \ @@ -39,11 +43,8 @@ SOURCES += \ CTrendTreeView.cpp \ CHisDataManage.cpp \ CCurveLegendView.cpp \ - CMyCheckBox.cpp \ - CMyListWidget.cpp \ CTableDataModel.cpp \ CTableView.cpp -# main.cpp HEADERS += \ $$PWD/plot/qcustomplot.h \ @@ -55,6 +56,8 @@ HEADERS += \ $$PWD/widgets/QxtSpanSlider_p.h \ $$PWD/widgets/CSWitchButton.h \ $$PWD/widgets/CSliderRangeWidget.h \ + $$PWD/widgets/CMyCheckBox.h \ + $$PWD/widgets/CMyListWidget.h \ CTrendWindow.h \ CTrendGraph.h \ CPlotWidget.h \ @@ -71,8 +74,6 @@ HEADERS += \ CTrendTreeView.h \ CHisDataManage.h \ CCurveLegendView.h \ - CMyCheckBox.h \ - CMyListWidget.h \ CTableDataModel.h \ CTableView.h @@ -83,7 +84,7 @@ FORMS += \ LIBS += -llog4cplus -lboost_system -lprotobuf -lpub_logger_api -lmodel_excel 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 += -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) diff --git a/product/src/gui/plugin/TrendCurves/main.cpp b/product/src/gui/plugin/TrendCurves/main.cpp index f3ccb082..4e651cea 100644 --- a/product/src/gui/plugin/TrendCurves/main.cpp +++ b/product/src/gui/plugin/TrendCurves/main.cpp @@ -1,4 +1,4 @@ -#include +#include #include "CTrendWindow.h" #include "pub_logger_api/logger.h" #include "dp_chg_data_api/CDpcdaForApp.h" @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) 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; } diff --git a/product/src/gui/plugin/TrendCurves/plot/qcustomplot.cpp b/product/src/gui/plugin/TrendCurves/plot/qcustomplot.cpp index b23489a2..bfd47151 100644 --- a/product/src/gui/plugin/TrendCurves/plot/qcustomplot.cpp +++ b/product/src/gui/plugin/TrendCurves/plot/qcustomplot.cpp @@ -1,4 +1,4 @@ -/*************************************************************************** +/*************************************************************************** ** ** ** QCustomPlot, an easy to use, modern plotting widget for Qt ** ** Copyright (C) 2011-2017 Emanuel Eichhammer ** @@ -6062,16 +6062,23 @@ QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) { QVector result = QCPAxisTicker::createTickVector(tickStep, range); + if (!result.isEmpty()) { if (mDateStrategy == dsUniformTimeInDay) { QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible QDateTime tickDateTime; + int nOffsetToUTC = 0 - uniformDateTime.offsetFromUtc(); for (int i=0; i QCPAxisTickerDateTime::createTickVector(double tickStep, const Q tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); 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; } @@ -10732,6 +10748,11 @@ void QCPAbstractPlottable::setDesc(const QString &desc) mDesc = desc; } +void QCPAbstractPlottable::setType(const int &type) +{ + mType = type; +} + /*! Sets whether fills of this plottable are drawn antialiased or not. diff --git a/product/src/gui/plugin/TrendCurves/plot/qcustomplot.h b/product/src/gui/plugin/TrendCurves/plot/qcustomplot.h index 8af1c48a..e630f91f 100644 --- a/product/src/gui/plugin/TrendCurves/plot/qcustomplot.h +++ b/product/src/gui/plugin/TrendCurves/plot/qcustomplot.h @@ -1,4 +1,4 @@ -/*************************************************************************** +/*************************************************************************** ** ** ** QCustomPlot, an easy to use, modern plotting widget for Qt ** ** Copyright (C) 2011-2017 Emanuel Eichhammer ** @@ -3310,6 +3310,7 @@ public: // getters: QString name() const { return mName; } QString desc() const { return mDesc; } + int type() const { return mType; } bool antialiasedFill() const { return mAntialiasedFill; } bool antialiasedScatters() const { return mAntialiasedScatters; } QPen pen() const { return mPen; } @@ -3324,6 +3325,7 @@ public: // setters: void setName(const QString &name); void setDesc(const QString &desc); + void setType(const int &type); void setAntialiasedFill(bool enabled); void setAntialiasedScatters(bool enabled); void setPen(const QPen &pen); @@ -3362,6 +3364,7 @@ protected: // property members: QString mName; QString mDesc; + int mType; bool mAntialiasedFill, mAntialiasedScatters; QPen mPen; QBrush mBrush; diff --git a/product/src/gui/plugin/TrendCurves/widgets/CEditCollectWidget.cpp b/product/src/gui/plugin/TrendCurves/widgets/CEditCollectWidget.cpp index 5ef41100..e6c02728 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/CEditCollectWidget.cpp +++ b/product/src/gui/plugin/TrendCurves/widgets/CEditCollectWidget.cpp @@ -1,4 +1,4 @@ -#include "CEditCollectWidget.h" +#include "CEditCollectWidget.h" #include #include #include diff --git a/product/src/gui/plugin/TrendCurves/widgets/CEditCollectWidget.h b/product/src/gui/plugin/TrendCurves/widgets/CEditCollectWidget.h index 6657c7ab..35b5f0c1 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/CEditCollectWidget.h +++ b/product/src/gui/plugin/TrendCurves/widgets/CEditCollectWidget.h @@ -1,4 +1,4 @@ -#ifndef CEDITCOLLECTWIDGET_H +#ifndef CEDITCOLLECTWIDGET_H #define CEDITCOLLECTWIDGET_H #include diff --git a/product/src/gui/plugin/TrendCurves/CMyCheckBox.cpp b/product/src/gui/plugin/TrendCurves/widgets/CMyCheckBox.cpp similarity index 91% rename from product/src/gui/plugin/TrendCurves/CMyCheckBox.cpp rename to product/src/gui/plugin/TrendCurves/widgets/CMyCheckBox.cpp index 888168ca..2b37e36c 100644 --- a/product/src/gui/plugin/TrendCurves/CMyCheckBox.cpp +++ b/product/src/gui/plugin/TrendCurves/widgets/CMyCheckBox.cpp @@ -1,4 +1,4 @@ -#include "CMyCheckBox.h" +#include "CMyCheckBox.h" #include CMyCheckBox::CMyCheckBox(QString text, QWidget *parent) diff --git a/product/src/gui/plugin/TrendCurves/CMyCheckBox.h b/product/src/gui/plugin/TrendCurves/widgets/CMyCheckBox.h similarity index 92% rename from product/src/gui/plugin/TrendCurves/CMyCheckBox.h rename to product/src/gui/plugin/TrendCurves/widgets/CMyCheckBox.h index bdba8dbc..1dad82e3 100644 --- a/product/src/gui/plugin/TrendCurves/CMyCheckBox.h +++ b/product/src/gui/plugin/TrendCurves/widgets/CMyCheckBox.h @@ -1,4 +1,4 @@ -#ifndef MYCHECKBOX_H +#ifndef MYCHECKBOX_H #define MYCHECKBOX_H #include diff --git a/product/src/gui/plugin/TrendCurves/CMyListWidget.cpp b/product/src/gui/plugin/TrendCurves/widgets/CMyListWidget.cpp similarity index 86% rename from product/src/gui/plugin/TrendCurves/CMyListWidget.cpp rename to product/src/gui/plugin/TrendCurves/widgets/CMyListWidget.cpp index ded92615..fa73a493 100644 --- a/product/src/gui/plugin/TrendCurves/CMyListWidget.cpp +++ b/product/src/gui/plugin/TrendCurves/widgets/CMyListWidget.cpp @@ -1,4 +1,4 @@ -#include "CMyListWidget.h" +#include "CMyListWidget.h" CMyListWidget::CMyListWidget(QWidget *parent):QListWidget(parent) { diff --git a/product/src/gui/plugin/TrendCurves/CMyListWidget.h b/product/src/gui/plugin/TrendCurves/widgets/CMyListWidget.h similarity index 89% rename from product/src/gui/plugin/TrendCurves/CMyListWidget.h rename to product/src/gui/plugin/TrendCurves/widgets/CMyListWidget.h index 3e92461e..728f308d 100644 --- a/product/src/gui/plugin/TrendCurves/CMyListWidget.h +++ b/product/src/gui/plugin/TrendCurves/widgets/CMyListWidget.h @@ -1,4 +1,4 @@ -#ifndef CMYLISTWIDGET_H +#ifndef CMYLISTWIDGET_H #define CMYLISTWIDGET_H #include diff --git a/product/src/gui/plugin/TrendCurves/widgets/CSWitchButton.cpp b/product/src/gui/plugin/TrendCurves/widgets/CSWitchButton.cpp index e8bce0f9..af418f62 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/CSWitchButton.cpp +++ b/product/src/gui/plugin/TrendCurves/widgets/CSWitchButton.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include "CSWitchButton.h" @@ -34,15 +34,18 @@ void CSWitchButton::paintEvent(QPaintEvent *event) QColor background; QColor handleColor; QString text; + QString unSelectText; if (isEnabled()) { // 可用状态 if (m_bChecked) { // 打开状态 background = m_checkedColor; handleColor = m_handleColor; text = m_strText; + unSelectText=m_strCheckText; } else { //关闭状态 background = m_background; handleColor = m_handleColor; text = m_strCheckText; + unSelectText=m_strText; } } else { // 不可用状态 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.setPen(m_textColor); 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); } // 鼠标按下事件 diff --git a/product/src/gui/plugin/TrendCurves/widgets/CSWitchButton.h b/product/src/gui/plugin/TrendCurves/widgets/CSWitchButton.h index f477243e..80f188f2 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/CSWitchButton.h +++ b/product/src/gui/plugin/TrendCurves/widgets/CSWitchButton.h @@ -1,4 +1,4 @@ -#ifndef SWITCHBUTTON_H +#ifndef SWITCHBUTTON_H #define SWITCHBUTTON_H #include diff --git a/product/src/gui/plugin/TrendCurves/widgets/CSliderRangeWidget.cpp b/product/src/gui/plugin/TrendCurves/widgets/CSliderRangeWidget.cpp index 507cbad0..cc2ca2e0 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/CSliderRangeWidget.cpp +++ b/product/src/gui/plugin/TrendCurves/widgets/CSliderRangeWidget.cpp @@ -1,4 +1,4 @@ -#include "CSliderRangeWidget.h" +#include "CSliderRangeWidget.h" #include #include #include diff --git a/product/src/gui/plugin/TrendCurves/widgets/CSliderRangeWidget.h b/product/src/gui/plugin/TrendCurves/widgets/CSliderRangeWidget.h index dc902e99..e851dea1 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/CSliderRangeWidget.h +++ b/product/src/gui/plugin/TrendCurves/widgets/CSliderRangeWidget.h @@ -1,4 +1,4 @@ -#ifndef CSLIDERRANGEWIDGET_H +#ifndef CSLIDERRANGEWIDGET_H #define CSLIDERRANGEWIDGET_H #include diff --git a/product/src/gui/plugin/TrendCurves/widgets/CTabButton.cpp b/product/src/gui/plugin/TrendCurves/widgets/CTabButton.cpp index abd2c898..f6e1e452 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/CTabButton.cpp +++ b/product/src/gui/plugin/TrendCurves/widgets/CTabButton.cpp @@ -1,4 +1,4 @@ -#include "CTabButton.h" +#include "CTabButton.h" #include #include "CCalendarWidget.h" diff --git a/product/src/gui/plugin/TrendCurves/widgets/CTabButton.h b/product/src/gui/plugin/TrendCurves/widgets/CTabButton.h index 56a7c409..f43a01ea 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/CTabButton.h +++ b/product/src/gui/plugin/TrendCurves/widgets/CTabButton.h @@ -1,4 +1,4 @@ -#ifndef CTABBUTTON_H +#ifndef CTABBUTTON_H #define CTABBUTTON_H #include diff --git a/product/src/gui/plugin/TrendCurves/widgets/CToolTip.cpp b/product/src/gui/plugin/TrendCurves/widgets/CToolTip.cpp index d2764cd9..3c455114 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/CToolTip.cpp +++ b/product/src/gui/plugin/TrendCurves/widgets/CToolTip.cpp @@ -1,4 +1,4 @@ -#include "CToolTip.h" +#include "CToolTip.h" #include #include #include @@ -74,7 +74,7 @@ void CToolTip::on_pushButton_clicked() QString alarmTime,alarmContent; QStringList header; header<setHorizontalHeaderLabels(header); + model->setHorizontalHeaderLabels(header); QHeaderView *rowHeader = alarmTable->verticalHeader(); rowHeader->setHidden(true); for(int i = 0;i < rowCount;i++) @@ -91,7 +91,7 @@ void CToolTip::on_pushButton_clicked() alarmTable->setModel(model); alarmTable->resizeColumnsToContents(); alarmTable->setObjectName("m_tipAlarmTable"); - alarmTable->resize(470,300); + alarmTable->resize(800,400); alarmTable->setWindowFlags(alarmTable->windowFlags()&~(Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint)); alarmTable->horizontalHeader()->setStretchLastSection(true); alarmTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); diff --git a/product/src/gui/plugin/TrendCurves/widgets/CToolTip.h b/product/src/gui/plugin/TrendCurves/widgets/CToolTip.h index 1d7378cb..e4e691a9 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/CToolTip.h +++ b/product/src/gui/plugin/TrendCurves/widgets/CToolTip.h @@ -1,4 +1,4 @@ -#ifndef CTOOLTIP_H +#ifndef CTOOLTIP_H #define CTOOLTIP_H #include diff --git a/product/src/gui/plugin/TrendCurves/widgets/QxtSpanSlider.cpp b/product/src/gui/plugin/TrendCurves/widgets/QxtSpanSlider.cpp index b45b3a8a..6a3cfe30 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/QxtSpanSlider.cpp +++ b/product/src/gui/plugin/TrendCurves/widgets/QxtSpanSlider.cpp @@ -1,4 +1,4 @@ -#include "QxtSpanSlider.h" +#include "QxtSpanSlider.h" /**************************************************************************** ** Copyright (c) 2006 - 2011, the LibQxt project. ** See the Qxt AUTHORS file for a list of authors and copyright holders. diff --git a/product/src/gui/plugin/TrendCurves/widgets/QxtSpanSlider.h b/product/src/gui/plugin/TrendCurves/widgets/QxtSpanSlider.h index cf09f570..fd9ad794 100644 --- a/product/src/gui/plugin/TrendCurves/widgets/QxtSpanSlider.h +++ b/product/src/gui/plugin/TrendCurves/widgets/QxtSpanSlider.h @@ -1,4 +1,4 @@ -#ifndef QXTSPANSLIDER_H +#ifndef QXTSPANSLIDER_H /**************************************************************************** ** Copyright (c) 2006 - 2011, the LibQxt project. ** See the Qxt AUTHORS file for a list of authors and copyright holders.