2025-11-21 19:22:41 +08:00
|
|
|
#include "monitorConfigDlg.h"
|
|
|
|
|
#include "ui_monitorConfigDlg.h"
|
|
|
|
|
#include "monitorPanel.h"
|
|
|
|
|
#include "global.h"
|
|
|
|
|
|
|
|
|
|
MonitorConfigDlg::MonitorConfigDlg(QWidget *parent)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
, ui(new Ui::monitorConfigDlg)
|
|
|
|
|
,_parent(nullptr)
|
|
|
|
|
,_curItemModel(nullptr)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
|
|
|
|
_parent = dynamic_cast<MonitorPanel*>(parent);
|
|
|
|
|
initial();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MonitorConfigDlg::~MonitorConfigDlg()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::initial()
|
|
|
|
|
{
|
|
|
|
|
ui->treeView_item->setModel(_parent->getLstModel());
|
|
|
|
|
connect(ui->btn_ok,&QPushButton::clicked,this,&MonitorConfigDlg::onOkClicked);
|
|
|
|
|
connect(ui->btn_cancel,&QPushButton::clicked,this,&MonitorConfigDlg::onCancelClicked);
|
|
|
|
|
connect(ui->cb_type,&QComboBox::currentIndexChanged,this,&MonitorConfigDlg::onTypeChanged);
|
|
|
|
|
connect(ui->treeView_item->selectionModel(), &QItemSelectionModel::selectionChanged,
|
|
|
|
|
this, &MonitorConfigDlg::onItemSelectionChanged);
|
|
|
|
|
ui->treeView_item->setHeaderHidden(true);
|
|
|
|
|
ui->treeView_para->setHeaderHidden(true);
|
|
|
|
|
ui->le_searchPara->setPlaceholderText("搜索参数");
|
|
|
|
|
_curItemModel = new QStandardItemModel(this);
|
|
|
|
|
ui->treeView_para->setModel(_curItemModel);
|
|
|
|
|
connect(_curItemModel,&QStandardItemModel::itemChanged, this,&MonitorConfigDlg::onPropertyCheckChanged);
|
|
|
|
|
connect(ui->treeView_para->selectionModel(), &QItemSelectionModel::currentChanged,
|
|
|
|
|
this, &MonitorConfigDlg::onPropertySelectionChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::updateSelectedItems()
|
|
|
|
|
{
|
|
|
|
|
ui->treeView_item->expandAll();
|
|
|
|
|
_tempConfig = _parent->getModelController()->getMonitorPara();
|
|
|
|
|
int a = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::onOkClicked()
|
|
|
|
|
{
|
|
|
|
|
if (ui->treeView_para->currentIndex().isValid()) { //确定前先保存当前属性
|
|
|
|
|
savePropertyData(ui->treeView_para->currentIndex(),_curUuid);
|
|
|
|
|
}
|
|
|
|
|
_parent->getModelController()->getMonitorPara() = _tempConfig; //保存临时数据
|
2025-11-26 20:33:13 +08:00
|
|
|
_parent->getModelController()->monitorItemSet(_curUuid);
|
2025-11-21 19:22:41 +08:00
|
|
|
hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::onCancelClicked()
|
|
|
|
|
{
|
|
|
|
|
hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::onTypeChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
ui->stackedWidget->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::onItemSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
|
|
|
|
{
|
|
|
|
|
if (ui->treeView_para->currentIndex().isValid()) { //如果切换设备,先保存属性到上个设备
|
|
|
|
|
savePropertyData(ui->treeView_para->currentIndex(),_curUuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearProperty();
|
|
|
|
|
|
|
|
|
|
QStandardItem *root = _curItemModel->invisibleRootItem(); //先清空model
|
|
|
|
|
int rowCount = root->rowCount();
|
|
|
|
|
if (rowCount > 0) {
|
|
|
|
|
_curItemModel->removeRows(0, rowCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndexList indexes = selected.indexes();
|
|
|
|
|
if(indexes.size() == 1){
|
|
|
|
|
auto index = indexes.first();
|
|
|
|
|
int nCategory = index.data(Qt::UserRole+1).toInt();
|
|
|
|
|
if(nCategory == 0){ //是设备
|
|
|
|
|
QUuid uid = index.data(Qt::UserRole+3).toUuid();
|
|
|
|
|
_curUuid = uid;
|
|
|
|
|
if(_tempConfig.contains(uid)){
|
|
|
|
|
auto lstPara = _tempConfig.value(uid);
|
|
|
|
|
for(auto& para:lstPara){
|
|
|
|
|
auto pParent = findStandardItemAtLevel(_curItemModel,0,para.sGroup,nullptr,0);
|
|
|
|
|
if(pParent){ //组已存在
|
|
|
|
|
QStandardItem *pItem = new QStandardItem(para.sName);
|
|
|
|
|
pItem->setCheckable(true);
|
|
|
|
|
pItem->setCheckState(para.bSelected ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
pItem->setData(nCategory,Qt::UserRole+1);
|
|
|
|
|
pItem->setData(para.sTag,Qt::UserRole+2);
|
|
|
|
|
pParent->appendRow(pItem);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
QStandardItem *pPar = new QStandardItem(para.sGroup);
|
|
|
|
|
pPar->setData(1,Qt::UserRole+1);
|
|
|
|
|
QStandardItem *pItem = new QStandardItem(para.sName);
|
|
|
|
|
pItem->setCheckable(true);
|
|
|
|
|
pItem->setCheckState(para.bSelected ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
pItem->setData(nCategory,Qt::UserRole+1);
|
|
|
|
|
pItem->setData(para.sTag,Qt::UserRole+2);
|
|
|
|
|
pPar->appendRow(pItem);
|
|
|
|
|
_curItemModel->appendRow(pPar);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ui->treeView_para->expandAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::onPropertyCheckChanged(QStandardItem *item)
|
|
|
|
|
{
|
|
|
|
|
if(_tempConfig.contains(_curUuid)){
|
|
|
|
|
Qt::CheckState state = item->checkState();
|
|
|
|
|
QString itemText = item->text();
|
|
|
|
|
if (state == Qt::Checked) {
|
|
|
|
|
for(auto &info:_tempConfig[_curUuid]){
|
|
|
|
|
if(info.sName == itemText){
|
|
|
|
|
info.bSelected = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (state == Qt::Unchecked) {
|
|
|
|
|
for(auto &info:_tempConfig[_curUuid]){
|
|
|
|
|
if(info.sName == itemText){
|
|
|
|
|
info.bSelected = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::onPropertySelectionChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
|
|
|
|
{
|
|
|
|
|
if (previous.isValid()) {
|
|
|
|
|
savePropertyData(previous,_curUuid);
|
|
|
|
|
}
|
|
|
|
|
if (current.isValid()) {
|
|
|
|
|
loadPropertyData(current,_curUuid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::savePropertyData(const QModelIndex &previous,QUuid uid)
|
|
|
|
|
{
|
|
|
|
|
if(_tempConfig.contains(uid)){
|
|
|
|
|
if(previous.isValid()){ //保存数据
|
|
|
|
|
QString itemText = previous.data().toString();
|
|
|
|
|
for(auto &info:_tempConfig[uid]){
|
|
|
|
|
if(info.sName == itemText){
|
|
|
|
|
info.sTag = ui->le_name->text();
|
|
|
|
|
info.sConnectPara = ui->le_query->text();
|
|
|
|
|
info.nShowType = ui->cb_type->currentIndex();
|
|
|
|
|
info.bShowDiagram = ui->cb_outVisible->currentIndex();
|
|
|
|
|
info.nGraphType = ui->cb_graphType->currentIndex();
|
|
|
|
|
info.sTimeRange = ui->cb_timeRange->currentText();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::loadPropertyData(const QModelIndex ¤t,QUuid uid)
|
|
|
|
|
{
|
|
|
|
|
QList<monitorItemAttributeInfo> lst;
|
|
|
|
|
if(_tempConfig.contains(uid)){
|
|
|
|
|
lst = _tempConfig.value(uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(current.isValid()){ //加载新数据
|
|
|
|
|
QString itemText = current.data().toString();
|
|
|
|
|
for(auto &info:lst){
|
|
|
|
|
if(info.sName == itemText){
|
|
|
|
|
ui->le_name->setText(info.sTag);
|
|
|
|
|
ui->le_query->setText(info.sConnectPara);
|
|
|
|
|
ui->cb_type->setCurrentIndex(info.nShowType);
|
|
|
|
|
if(info.nShowType == 0){ //字符
|
|
|
|
|
ui->cb_outVisible->setCurrentIndex(info.bShowDiagram);
|
|
|
|
|
}else{ //图表
|
|
|
|
|
ui->cb_graphType->setCurrentIndex(info.nGraphType);
|
|
|
|
|
ui->cb_timeRange->setCurrentText(info.sTimeRange);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MonitorConfigDlg::clearProperty()
|
|
|
|
|
{
|
|
|
|
|
ui->le_name->clear();
|
|
|
|
|
ui->le_query->clear();
|
|
|
|
|
ui->cb_type->setCurrentIndex(0);
|
|
|
|
|
ui->cb_outVisible->setCurrentIndex(0);
|
|
|
|
|
ui->cb_graphType->setCurrentIndex(0);
|
|
|
|
|
ui->cb_timeRange->setCurrentIndex(0);
|
|
|
|
|
}
|