364 lines
9.5 KiB
C++
364 lines
9.5 KiB
C++
#include "CTrendWindow.h"
|
|
#include <QFile>
|
|
#include <QTextStream>
|
|
#include <QSplitter>
|
|
#include <QHBoxLayout>
|
|
#include <QGridLayout>
|
|
#include <QDir>
|
|
#include "CPlotWidget.h"
|
|
#include <QTreeView>
|
|
#include <QTabWidget>
|
|
#include "CTrendTreeView.h"
|
|
#include "CTrendTreeModel.h"
|
|
#include "CTrendInfoManage.h"
|
|
#include "CTrendFavTreeWidget.h"
|
|
#include "pub_utility_api/FileUtil.h"
|
|
#include "pub_utility_api/FileStyle.h"
|
|
|
|
CTrendWindow::CTrendWindow(bool editMode, QVector<void *> ptrVec, QWidget *parent)
|
|
: QWidget(parent),
|
|
m_isEditMode(editMode),
|
|
// m_pTagWidget(Q_NULLPTR),
|
|
m_plotWidget(Q_NULLPTR),
|
|
m_pTagTreeView(Q_NULLPTR),
|
|
m_pTrendTreeModel(Q_NULLPTR),
|
|
// m_pSearchButton(Q_NULLPTR),
|
|
// m_pSearchTextEdit(Q_NULLPTR),
|
|
m_pSplitter(Q_NULLPTR),
|
|
m_pFavoritesTreeWidget(Q_NULLPTR)
|
|
{
|
|
Q_UNUSED(ptrVec)
|
|
QString qss = QString();
|
|
std::string strFullPath = kbd_public::CFileStyle::getPathOfStyleFile("public.qss") ;
|
|
QFile qssfile1(QString::fromStdString(strFullPath));
|
|
qssfile1.open(QFile::ReadOnly);
|
|
if (qssfile1.isOpen())
|
|
{
|
|
qss += QLatin1String(qssfile1.readAll());
|
|
//setStyleSheet(qss);
|
|
qssfile1.close();
|
|
}
|
|
|
|
strFullPath = kbd_public::CFileStyle::getPathOfStyleFile("trendCurves.qss") ;
|
|
QFile qssfile2(QString::fromStdString(strFullPath));
|
|
qssfile2.open(QFile::ReadOnly);
|
|
if (qssfile2.isOpen())
|
|
{
|
|
qss += QLatin1String(qssfile2.readAll());
|
|
//setStyleSheet(qss);
|
|
qssfile2.close();
|
|
}
|
|
if(!qss.isEmpty())
|
|
{
|
|
setStyleSheet(qss);
|
|
}
|
|
}
|
|
|
|
CTrendWindow::~CTrendWindow()
|
|
{
|
|
CTrendInfoManage::instance()->destory();
|
|
}
|
|
|
|
void CTrendWindow::initialize(const int &mode)
|
|
{
|
|
if(m_isEditMode)
|
|
{
|
|
initWindow();
|
|
return;
|
|
}
|
|
|
|
clearChildren();
|
|
if(E_Trend_Window == (E_Trend_Mode)mode)
|
|
{
|
|
initWindow();
|
|
}
|
|
else if(E_Trend_Widget == (E_Trend_Mode)mode)
|
|
{
|
|
initWidget();
|
|
}
|
|
|
|
if(m_plotWidget)
|
|
{
|
|
QString strColorConfig;
|
|
QFile colorFile("://resource/color.cfg");
|
|
if (colorFile.open(QIODevice::ReadOnly))
|
|
{
|
|
QTextStream colorStream(&colorFile);
|
|
strColorConfig= colorStream.readAll();
|
|
}
|
|
QStringList listColor = strColorConfig.split("\n");
|
|
m_plotWidget->setColorList(listColor);
|
|
}
|
|
|
|
}
|
|
|
|
void CTrendWindow::setTitle(const QString &title)
|
|
{
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->setTitle(title);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::setTitleVisible(bool visible)
|
|
{
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->setTitleVisible(visible);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::setTickCount(const int &count)
|
|
{
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->setTickCount(count);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::insertTag(const QString &tag)
|
|
{
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->insertTag(tag);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::insertTag(const QStringList &listTag)
|
|
{
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->insertTag(listTag);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::removeTag(const QString &tag)
|
|
{
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->removeTag(tag);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::setDisplayTime(const int &trendType, const double &dateTime)
|
|
{
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->setDisplayTime(trendType, dateTime);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::setTagVisible(const QString &tag, const bool &visible)
|
|
{
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->setTagVisible(tag, visible);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::clearTag()
|
|
{
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->clear();
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::setClearVisible(bool visible)
|
|
{
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->setClearVisible(visible);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::initWindow()
|
|
{
|
|
// m_pTagWidget = new QTabWidget(this);
|
|
// m_pTagWidget->setTabPosition(QTabWidget::North);
|
|
m_pTagTreeView = new CTrendTreeView(this);
|
|
m_pTagTreeView->setVisible(false);
|
|
m_pTrendTreeModel = new CTrendTreeModel(this, m_pTagTreeView);
|
|
m_pTagTreeView->setModel(m_pTrendTreeModel);
|
|
// m_pTagTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
// m_pTagTreeView->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu);
|
|
|
|
// m_pTagTreeView->header()->setObjectName("devHeader");
|
|
// QGridLayout * pHBoxLayout = new QGridLayout(m_pTagTreeView->header());
|
|
// m_pSearchTextEdit = new QLineEdit(m_pTagTreeView->header());
|
|
// m_pSearchTextEdit->setObjectName("searchTextEdit");
|
|
// m_pSearchButton = new QPushButton(m_pTagTreeView->header());
|
|
// m_pSearchButton->setObjectName("searchButton");
|
|
|
|
// connect(m_pSearchTextEdit, &QLineEdit::returnPressed, this, &CTrendWindow::FindTagName);
|
|
// connect(m_pSearchButton, &QPushButton::clicked, this, &CTrendWindow::FindTagName);
|
|
// pHBoxLayout->addWidget(m_pSearchTextEdit, 0, 0);
|
|
// pHBoxLayout->addWidget(m_pSearchButton, 0, 1);
|
|
// pHBoxLayout->setContentsMargins(5,0,5,0);
|
|
// pHBoxLayout->setSpacing(0);
|
|
// m_pTagTreeView->header()->setLayout(pHBoxLayout);
|
|
// m_pTagWidget->addTab(m_pTagTreeView, tr("设备/点"));
|
|
m_pFavoritesTreeWidget = new CTrendFavTreeWidget(this);
|
|
m_pFavoritesTreeWidget->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu);
|
|
// m_pTagWidget->addTab(m_pFavoritesTreeWidget, tr("收藏夹"));
|
|
// m_pTagWidget->setContentsMargins(1,1,1,1);
|
|
// m_pTagWidget->setCurrentIndex(1);
|
|
m_plotWidget = new CPlotWidget(this);
|
|
m_plotWidget->initialize();
|
|
m_pSplitter = new QSplitter(this);
|
|
// m_pSplitter->addWidget(m_pFavoritesTreeWidget);
|
|
m_pSplitter->addWidget(m_pFavoritesTreeWidget);
|
|
m_pSplitter->addWidget(m_plotWidget);
|
|
m_pSplitter->setStretchFactor(0, 1);
|
|
m_pSplitter->setStretchFactor(1, 2);
|
|
m_pSplitter->setContentsMargins(6, 6, 6, 6);
|
|
m_pSplitter->setHandleWidth(10);
|
|
QHBoxLayout * layout = new QHBoxLayout(this);
|
|
layout->addWidget(m_pSplitter);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
setLayout(layout);
|
|
connect(m_plotWidget, &CPlotWidget::clearCurve, m_pTrendTreeModel, &CTrendTreeModel::clearCheckState);
|
|
connect(m_plotWidget, &CPlotWidget::collectGraph, m_pFavoritesTreeWidget, &CTrendFavTreeWidget::collectGraph);
|
|
connect(m_plotWidget, &CPlotWidget::updateTagCheckState, m_pTrendTreeModel, &CTrendTreeModel::updateTagCheckState, Qt::QueuedConnection);
|
|
connect(m_pTrendTreeModel, &CTrendTreeModel::itemCheckStateChanged, this, &CTrendWindow::itemCheckStateChanged);
|
|
connect(m_pFavoritesTreeWidget, &CTrendFavTreeWidget::showTrendGraph, this, &CTrendWindow::showTrendGraph);
|
|
}
|
|
|
|
void CTrendWindow::initWidget()
|
|
{
|
|
m_plotWidget = new CPlotWidget(this);
|
|
m_plotWidget->initialize();
|
|
m_plotWidget->setTickCount(5);
|
|
m_plotWidget->setWindowMode(false);
|
|
QHBoxLayout * layout = new QHBoxLayout(this);
|
|
layout->addWidget(m_plotWidget);
|
|
layout->setMargin(3);
|
|
setLayout(layout);
|
|
}
|
|
|
|
void CTrendWindow::clearChildren()
|
|
{
|
|
// if(m_pSearchButton)
|
|
// {
|
|
// delete m_pSearchButton;
|
|
// }
|
|
// m_pSearchButton = Q_NULLPTR;
|
|
|
|
// if(m_pSearchTextEdit)
|
|
// {
|
|
// delete m_pSearchTextEdit;
|
|
// }
|
|
// m_pSearchTextEdit = Q_NULLPTR;
|
|
|
|
if(m_pTagTreeView)
|
|
{
|
|
delete m_pTagTreeView;
|
|
}
|
|
m_pTagTreeView = Q_NULLPTR;
|
|
|
|
// if(m_pTagWidget)
|
|
// {
|
|
// delete m_pTagWidget;
|
|
// }
|
|
// m_pTagWidget = Q_NULLPTR;
|
|
|
|
if(m_plotWidget)
|
|
{
|
|
delete m_plotWidget;
|
|
}
|
|
m_plotWidget = Q_NULLPTR;
|
|
|
|
if(m_pTrendTreeModel)
|
|
{
|
|
delete m_pTrendTreeModel;
|
|
}
|
|
m_pTrendTreeModel = Q_NULLPTR;
|
|
|
|
if(m_pSplitter)
|
|
{
|
|
delete m_pSplitter;
|
|
}
|
|
m_pSplitter = Q_NULLPTR;
|
|
|
|
if(m_pFavoritesTreeWidget)
|
|
{
|
|
delete m_pFavoritesTreeWidget;
|
|
}
|
|
m_pFavoritesTreeWidget = Q_NULLPTR;
|
|
|
|
if(layout())
|
|
{
|
|
delete layout();
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::login()
|
|
{
|
|
if(m_pTrendTreeModel)
|
|
{
|
|
m_pTrendTreeModel->initTrendTagInfo();
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::logout()
|
|
{
|
|
if(m_pTrendTreeModel)
|
|
{
|
|
m_pTrendTreeModel->clearTrendTagInfo();
|
|
}
|
|
|
|
if(m_plotWidget)
|
|
{
|
|
m_plotWidget->clear(true);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::itemCheckStateChanged(const QString &strTagName, const int &checkedState)
|
|
{
|
|
if(Qt::Checked == (Qt::CheckState)checkedState)
|
|
{
|
|
m_plotWidget->insertTag(strTagName);
|
|
}
|
|
else if(Qt::Unchecked == (Qt::CheckState)checkedState)
|
|
{
|
|
m_plotWidget->removeTag(strTagName);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::updateTrendName(const QString &title)
|
|
{
|
|
m_plotWidget->setTitle(title);
|
|
}
|
|
|
|
void CTrendWindow::showTrendGraph(CTrendGraph *graph, const QString &name)
|
|
{
|
|
m_plotWidget->clear();
|
|
if(!name.isEmpty())
|
|
{
|
|
updateTrendName(name);
|
|
}
|
|
foreach (Curve curve, graph->curves())
|
|
{
|
|
m_plotWidget->insertCurve(curve);
|
|
}
|
|
}
|
|
|
|
void CTrendWindow::FindTagName()
|
|
{
|
|
// QString content = m_pSearchTextEdit->text();
|
|
// m_pTagTreeView->collapseAll();
|
|
// m_pTagTreeView->selectionModel()->clear();
|
|
// QItemSelection selection;
|
|
// m_pTrendTreeModel->updateNodeVisualState(content, selection);
|
|
// m_pTagTreeView->selectionModel()->select(selection, QItemSelectionModel::Select);
|
|
|
|
// if(content.isEmpty())
|
|
// {
|
|
// m_pTagTreeView->collapseAll();
|
|
// }
|
|
// else
|
|
// {
|
|
// m_pTagTreeView->expandAll();
|
|
// }
|
|
}
|