2025-03-17 16:46:46 +08:00

1592 lines
55 KiB
C++

#include "CEventForm.h"
#include "ui_CEventForm.h"
#include "CEventMsgInfo.h"
#include <QContextMenuEvent>
#include "CEventItemModel.h"
#include "CEventHistoryModel.h"
#include "CEventFilterDialog.h"
#include "CEventMsgManage.h"
#include "CEventDataCollect.h"
#include "CTableViewPrinter.h"
#include <QSortFilterProxyModel>
#include <QMessageBox>
#include <QFileDialog>
#include <QPrinter>
#include <QMenu>
#include <QCheckBox>
#include <CMyListWidget.h>
#include <QWidgetAction>
#include <QItemSelection>
#include <CMyCheckBox.h>
#include "CEventDelegate.h"
#include "pub_utility_api/FileStyle.h"
#include <QButtonGroup>
#include "pub_logger_api/logger.h"
#include "CAccidentReviewDialog.h"
#include "CEventDeviceTreeModel.h"
#include "CEventDeviceTreeItem.h"
CEventForm::CEventForm(QWidget *parent, bool editMode) :
QWidget(parent),
ui(new Ui::CEventForm),
m_pRealDelegate(NULL),
m_pHistoryDelegate(NULL),
m_pRealTimeModel(NULL),
m_pHistoryModel(NULL),
m_pDeviceModel(NULL),
m_pDeviceHisModel(NULL),
m_isEditMode(editMode),
m_thread(NULL),
m_hisSearch(NULL),
m_enableWave(false),
m_isNeedAccidentReview(true),
m_buttonGroup(Q_NULLPTR),
m_ncurIndex(0),
m_strAccidenPath(QString())
{
qRegisterMetaType<CEventMsgInfo>("CEventMsgInfo");
qRegisterMetaType<EventMsgPtr>("EventMsgPtr");
qRegisterMetaType<QList<EventMsgPtr> >("SetEventMsgPtr");
qRegisterMetaType<ST_FILTER>("ST_FILTER");
ui->setupUi(this);
initilize();
if(!m_isEditMode)
{
m_hisSearch = new QThread();
m_hisWork = new CEventHisThread();
m_hisWork->moveToThread(m_hisSearch);
connect(m_hisSearch,&QThread::started,m_hisWork,&CEventHisThread::init,Qt::QueuedConnection);
connect(m_hisSearch,&QThread::finished,m_hisWork,&CEventHisThread::deleteLater,Qt::QueuedConnection);
m_buttonGroup = new QButtonGroup;
m_buttonGroup->setExclusive(true);
m_buttonGroup->addButton(ui->realEventButton,0);
m_buttonGroup->addButton(ui->hisEventButton,1);
connect(m_buttonGroup,SIGNAL(buttonClicked(int)),this,SLOT(updateStack(int)));
m_hisSearch->start();
initModel();
updateStack(0);
//< 放到构造函数中(打开两个窗口,关闭其中一个有问题)
// CEventDataCollect::instance()->initialize();
initFilter();
connect(CEventDataCollect::instance(), SIGNAL(sigEventStateChanged()), this, SLOT(slotRTEventStateChanged()), Qt::QueuedConnection);
connect(ui->clear, &QPushButton::clicked, this, &CEventForm::slotClearRTEvent);
connect(ui->closeBtn, &QPushButton::clicked, this, &CEventForm::closeBtnClicked);
}
QString qss = QString();
std::string strFullPath = iot_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 = iot_public::CFileStyle::getPathOfStyleFile("event.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);
}
{
//< 初始化实时设备树搜索框
QHBoxLayout * pHBoxLayout = new QHBoxLayout(ui->treeView->header());
m_pRealSearchEdit = new QLineEdit(ui->treeView->header());
m_pRealSearchEdit->setObjectName("realSearchEdit");
m_pRealSearchEdit->setTextMargins(0, 0, 21, 0);
m_pRealSearchEdit->setPlaceholderText(tr("按设备组关键字搜索"));
pHBoxLayout->addWidget(m_pRealSearchEdit);
pHBoxLayout->setContentsMargins(2,0,2,0);
pHBoxLayout->setSpacing(0);
ui->treeView->header()->setLayout(pHBoxLayout);
ui->treeView->header()->setObjectName("realDeviceHeader");
m_pRealSearchButton = new QPushButton(this);
m_pRealSearchButton->setObjectName("realSearchButton");
m_pRealSearchButton->setText("");
m_pRealSearchButton->setMaximumSize(21, 22);
m_pRealSearchButton->setCursor(QCursor(Qt::ArrowCursor));
QHBoxLayout * pSearchLayout = new QHBoxLayout();
pSearchLayout->setContentsMargins(1, 1, 1, 1);
pSearchLayout->addStretch();
pSearchLayout->addWidget(m_pRealSearchButton);
m_pRealSearchEdit->setLayout(pSearchLayout);
connect(m_pRealSearchEdit, &QLineEdit::returnPressed, this, &CEventForm::searchRealDeviceName);
connect(m_pRealSearchButton, &QPushButton::clicked, this, &CEventForm::searchRealDeviceName);
}
{
//< 初始化历史设备树搜索框
QHBoxLayout * pHBoxLayout = new QHBoxLayout(ui->treeView_2->header());
m_pHistorySearchEdit = new QLineEdit(ui->treeView_2->header());
m_pHistorySearchEdit->setObjectName("hisSearchEdit");
m_pHistorySearchEdit->setTextMargins(0, 0, 21, 0);
m_pHistorySearchEdit->setPlaceholderText(tr("按设备组关键字搜索"));
pHBoxLayout->addWidget(m_pHistorySearchEdit);
pHBoxLayout->setContentsMargins(2,0,2,0);
pHBoxLayout->setSpacing(0);
ui->treeView_2->header()->setLayout(pHBoxLayout);
ui->treeView_2->header()->setObjectName("hisDeviceHeader");
m_pHistorySearchButton = new QPushButton(this);
m_pHistorySearchButton->setObjectName("hisSearchButton");
m_pHistorySearchButton->setText("");
m_pHistorySearchButton->setMaximumSize(21, 22);
m_pHistorySearchButton->setCursor(QCursor(Qt::ArrowCursor));
QHBoxLayout * pSearchLayout = new QHBoxLayout();
pSearchLayout->setContentsMargins(1, 1, 1, 1);
pSearchLayout->addStretch();
pSearchLayout->addWidget(m_pHistorySearchButton);
m_pHistorySearchEdit->setLayout(pSearchLayout);
connect(m_pHistorySearchEdit, &QLineEdit::returnPressed, this, &CEventForm::searchHistoryDeviceName);
connect(m_pHistorySearchButton, &QPushButton::clicked, this, &CEventForm::searchHistoryDeviceName);
}
m_timeIcon = new QPushButton(this);
m_myCalendar = new CMyCalendar(this);
QWidgetAction *widgetAction=new QWidgetAction(this);
m_timeMenu = new QMenu(this);
widgetAction->setDefaultWidget(m_myCalendar);
m_timeMenu->addAction(widgetAction);
m_timeIcon->setObjectName("iconButton");
m_timeIcon->setText("");
m_timeIcon->setMaximumSize(21, 22);
m_timeIcon->setCursor(QCursor(Qt::ArrowCursor));
QHBoxLayout * pTimeLayout = new QHBoxLayout();
pTimeLayout->setContentsMargins(1, 1, 1, 1);
pTimeLayout->addStretch();
pTimeLayout->addWidget(m_timeIcon);
ui->lineEdit->setLayout(pTimeLayout);
connect(m_timeIcon,&QPushButton::clicked,this,&CEventForm::myCalendarShow);
connect(m_myCalendar,&CMyCalendar::sig_endTimeClick,this,&CEventForm::myCalendarHide);
connect(m_myCalendar,&CMyCalendar::sig_cancle,this,&CEventForm::cancleTimeFilter);
ui->lineEdit->setText(tr("请选择时间"));
ui->lineEdit->setReadOnly(true);
ui->lineEdit->setObjectName("iconLineEdit");
ui->splitter->setStretchFactor(0,1);
ui->splitter->setStretchFactor(1,6);
ui->splitter_2->setStretchFactor(0,1);
ui->splitter_2->setStretchFactor(1,6);
m_excelPrinter = new CExcelPrinter();
m_thread = new QThread();
m_excelPrinter->moveToThread(m_thread);
connect(m_thread,&QThread::started,m_excelPrinter,&CExcelPrinter::initialize);
connect(m_thread,&QThread::finished,m_excelPrinter,&CExcelPrinter::deleteLater);
connect(this,&CEventForm::printExcel,m_excelPrinter,&CExcelPrinter::printerByModel);
connect(this,&CEventForm::printExcelHis,m_excelPrinter,&CExcelPrinter::printerHisByModel);
connect(m_excelPrinter,&CExcelPrinter::sigShowResult,this,&CEventForm::slotShowResult);
m_thread->start();
}
CEventForm::~CEventForm()
{
CEventDataCollect::instance()->release();
if(m_pRealTimeModel)
{
delete m_pRealTimeModel;
}
m_pRealTimeModel = Q_NULLPTR;
if(m_pHistoryModel)
{
delete m_pHistoryModel;
}
m_pHistoryModel = Q_NULLPTR;
if(m_pRealDelegate)
{
delete m_pRealDelegate;
}
m_pRealDelegate = Q_NULLPTR;
if(m_pHistoryDelegate)
{
delete m_pHistoryDelegate;
}
m_pHistoryDelegate = Q_NULLPTR;
if(m_excelPrinter)
{
delete m_excelPrinter;
}
m_excelPrinter = Q_NULLPTR;
if(m_thread)
{
m_thread->quit();
m_thread->wait();
}
if(m_hisSearch)
{
m_hisSearch->quit();
m_hisSearch->wait();
}
delete CEventDataCollect::instance();
delete CEventMsgManage::instance();
delete ui;
qDebug() << "~CEventForm()";
}
void CEventForm::initilize()
{
//< lingdaoyaoqiu
{
QSettings columFlags1("IOT_HMI", "eventReal config");
if(!columFlags1.contains(QString("eventReal/colum_0")))
{
columFlags1.setValue(QString("eventReal/colum_0"), false); //< 时间
columFlags1.setValue(QString("eventReal/colum_1"), false); //< 优先级
columFlags1.setValue(QString("eventReal/colum_2"), false); //< 位置
columFlags1.setValue(QString("eventReal/colum_3"), true); //< 责任区
columFlags1.setValue(QString("eventReal/colum_4"), false); //< 事件类型
columFlags1.setValue(QString("eventReal/colum_5"), true); //< 事件状态
columFlags1.setValue(QString("eventReal/colum_6"), false); //< 复归状态
}
}
{
QSettings columFlags2("IOT_HMI", "eventHis config");
if(!columFlags2.contains(QString("eventHis/colum_0")))
{
columFlags2.setValue(QString("eventHis/colum_0"), false); //< 时间
columFlags2.setValue(QString("eventHis/colum_1"), false); //< 优先级
columFlags2.setValue(QString("eventHis/colum_2"), false); //< 位置
columFlags2.setValue(QString("eventHis/colum_3"), true); //< 责任区
columFlags2.setValue(QString("eventHis/colum_4"), false); //< 事件类型
columFlags2.setValue(QString("eventHis/colum_5"), true); //< 事件状态
columFlags2.setValue(QString("eventHis/colum_6"), false); //< 复归状态
columFlags2.setValue(QString("eventHis/colum_7"), true); //< 确认人
columFlags2.setValue(QString("eventHis/colum_8"), true); //< 确认时间
}
}
m_pListWidget1 = new CMyListWidget(this);
m_pListWidget2 = new CMyListWidget(this);
m_pListWidget3 = new CMyListWidget(this);
m_pLineEdit1 = new QLineEdit(this);
m_pLineEdit2 = new QLineEdit(this);
m_pLineEdit3 = new QLineEdit(this);
ui->comboBox->setModel(m_pListWidget1->model());
ui->comboBox->setView(m_pListWidget1);
ui->comboBox->setLineEdit(m_pLineEdit1);
m_strText1 = tr("请选择优先级");
m_pLineEdit1->setText(tr("请选择优先级"));
m_pLineEdit1->setReadOnly(true);
connect(m_pLineEdit1, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged1(const QString &))); //为了解决点击下拉框白色部分导致lineedit无数据问题
ui->comboBox_2->setModel(m_pListWidget2->model());
ui->comboBox_2->setView(m_pListWidget2);
ui->comboBox_2->setLineEdit(m_pLineEdit2);
m_strText2 = tr("请选择位置");
m_pLineEdit2->setText(tr("请选择位置"));
m_pLineEdit2->setReadOnly(true);
connect(m_pLineEdit2, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged2(const QString &)));
ui->comboBox_3->setModel(m_pListWidget3->model());
ui->comboBox_3->setView(m_pListWidget3);
ui->comboBox_3->setLineEdit(m_pLineEdit3);
m_strText3 = tr("请选择告警状态");
m_pLineEdit3->setText(tr("请选择告警状态"));
m_pLineEdit3->setReadOnly(true);
connect(m_pLineEdit3, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged3(const QString &)));
}
void CEventForm::initModel()
{
initHisModel();
initRealModel();
loadDeviceGroupFilterWidget();
}
void CEventForm::initHisModel()
{
if(m_pHistoryDelegate == NULL)
{
m_pHistoryDelegate = new CEventDelegate(ui->eventView_2);
}
ui->eventView_2->setItemDelegate(m_pHistoryDelegate);
ui->eventView_2->setSortingEnabled(false);
if(NULL == m_pHistoryModel)
{
m_pHistoryModel = new CEventHistoryModel(this);
connect(m_pHistoryModel, &CEventHistoryModel::sigPermInvalid, this, &CEventForm::slotPermInvalid,Qt::QueuedConnection);
connect(m_pHistoryModel, &CEventHistoryModel::sigHisEventRequesting, this, &CEventForm::slotUpdateHISTipsRequesting,Qt::QueuedConnection);
if(m_hisSearch != NULL)
{
connect(m_pHistoryModel, &CEventHistoryModel::requestHistory, m_hisWork,&CEventHisThread::doWork,Qt::QueuedConnection);
connect(m_hisWork, &CEventHisThread::sigUpdateHisEvent, m_pHistoryModel, &CEventHistoryModel::updateEvents, Qt::QueuedConnection);
}
connect(m_pHistoryModel, &CEventHistoryModel::sigHisEventSizeChanged, this, &CEventForm::slotUpdateHISTips,Qt::QueuedConnection);
connect(m_pHistoryModel, &CEventHistoryModel::sigHISRecordOutOfRangeTips, this, &CEventForm::slotHISRecordOutOfRangeTips,Qt::QueuedConnection);
connect(m_pHistoryModel, &CEventHistoryModel::sigOutOfRangeTips, this, &CEventForm::slotHisOutOfRangeTips,Qt::QueuedConnection);
}
ui->eventView_2->setModel(m_pHistoryModel);
m_pHistoryDelegate->setHisEventModel(m_pHistoryModel);
ui->eventView_2->setColumnWidth(8, 250);
QSettings columFlags2("IOT_HMI", "eventHis config");
for(int nColumnIndex(0); nColumnIndex < m_pHistoryModel->columnCount() - 1; nColumnIndex++)
{
bool visible = columFlags2.value(QString("eventHis/colum_%1").arg(nColumnIndex)).toBool();
ui->eventView_2->setColumnHidden(nColumnIndex, visible);
}
ui->eventView_2->setColumnHidden(m_pHistoryModel->columnCount() - 1, false);
ui->eventView_2->setColumnWidth(0, 250);
ui->eventView_2->setColumnWidth(1, 150);
ui->eventView_2->setColumnWidth(2, 150);
ui->eventView_2->setColumnWidth(3, 150);
ui->eventView_2->setColumnWidth(4, 150);
ui->eventView_2->setColumnWidth(5, 150);
ui->eventView_2->setColumnWidth(6, 150);
ui->eventView_2->setColumnWidth(7, 150);
slotUpdateHISTips();
if(m_pDeviceHisModel == NULL)
{
m_pDeviceHisModel = new CEventDeviceTreeModel(this);
ui->treeView_2->setModel(m_pDeviceHisModel);
connect(m_pDeviceHisModel, &CEventDeviceTreeModel::itemCheckStateChanged, this, &CEventForm::hisDeviceGroupFilterChanged);
if(m_hisSearch != NULL)
{
connect(m_hisWork, &CEventHisThread::sigUpdateHisEvent, this, &CEventForm::updateHisDeviceGroupHiddenState, Qt::QueuedConnection);
}
}
}
void CEventForm::initRealModel()
{
if(m_pRealDelegate == NULL)
{
m_pRealDelegate = new CEventDelegate(this);
ui->eventView->setItemDelegate(m_pRealDelegate);
}
ui->eventView->setSortingEnabled(true);
if(NULL == m_pRealTimeModel)
{
m_pRealTimeModel = new CEventItemModel(this);
connect(ui->eventView->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), m_pRealTimeModel, SLOT(sortColumn(int,Qt::SortOrder)));
ui->eventView->horizontalHeader()->setSortIndicator(0, Qt::DescendingOrder);
}
ui->eventView->setModel(m_pRealTimeModel);
m_pRealDelegate->setEventModel(m_pRealTimeModel);
QSettings columFlags1("IOT_HMI", "eventReal config");
for(int nColumnIndex(0); nColumnIndex < m_pRealTimeModel->columnCount() - 1; nColumnIndex++)
{
bool visible = columFlags1.value(QString("eventReal/colum_%1").arg(nColumnIndex)).toBool();
ui->eventView->setColumnHidden(nColumnIndex, visible);
}
ui->eventView->setColumnHidden(m_pRealTimeModel->columnCount() - 1, false);
ui->eventView->setColumnWidth(0, 250);
ui->eventView->setColumnWidth(1, 150);
ui->eventView->setColumnWidth(2, 150);
ui->eventView->setColumnWidth(3, 150);
ui->eventView->setColumnWidth(4, 150);
ui->eventView->setColumnWidth(5, 150);
slotUpdateRTTips();
if(m_pDeviceModel == NULL)
{
m_pDeviceModel = new CEventDeviceTreeModel(this);
ui->treeView->setModel(m_pDeviceModel);
connect(m_pDeviceModel, &CEventDeviceTreeModel::itemCheckStateChanged, this, &CEventForm::deviceGroupFilterChanged);
connect(CEventDataCollect::instance(),&CEventDataCollect::sigDevTreeUpdate,m_pDeviceModel,&CEventDeviceTreeModel::slotDevTreeUpdate);
connect(CEventDataCollect::instance(),&CEventDataCollect::sigDevTreeUpdate,this,&CEventForm::updateDeviceGroupHiddenState);
}
}
void CEventForm::login()
{
if(!m_isEditMode)
{
CEventDataCollect::instance()->release();
if(m_pRealTimeModel)
{
m_pRealTimeModel->initialize();
}
if(m_pHistoryModel)
{
m_pHistoryModel->initialize();
}
if(m_pRealDelegate == NULL)
{
m_pRealDelegate = new CEventDelegate(ui->eventView);
m_pRealDelegate->setEventModel(m_pRealTimeModel);
}
if(m_pHistoryDelegate == NULL)
{
m_pHistoryDelegate = new CEventDelegate(ui->eventView_2);
m_pHistoryDelegate->setHisEventModel(m_pHistoryModel);
}
CEventDataCollect::instance()->initialize();
initFilter();
if(ui->hisEventButton->isChecked())
{
m_pHistoryModel->loadEventHistoryData();
slotUpdateHISTips();
}
}
}
void CEventForm::logout()
{
if(!m_isEditMode)
{
CEventDataCollect::instance()->release();
}
}
void CEventForm::slotShowResult(QString result)
{
Q_UNUSED(result);
QMessageBox::information( 0, tr("提示"), tr("导出成功"));
}
void CEventForm::setHiddenLocation(bool hide)
{
ui->label_2->setHidden(hide);
ui->comboBox_2->setHidden(hide);
}
void CEventForm::setHiddenTime(bool hide)
{
ui->label_4->setHidden(hide);
ui->lineEdit->setHidden(hide);
}
void CEventForm::setHiddenStatus(bool hide)
{
ui->label_3->setHidden(hide);
ui->comboBox_3->setHidden(hide);
}
void CEventForm::setHiddenPriority(bool hide)
{
ui->label->setHidden(hide);
ui->comboBox->setHidden(hide);
}
void CEventForm::setHiddenCloseButton(bool hide)
{
ui->closeBtn->setHidden(hide);
}
void CEventForm::setRowHeight(int height)
{
if(ui->eventView != Q_NULLPTR)
{
ui->eventView->setDefaultRowHeight(height);
}
if(ui->eventView_2 != Q_NULLPTR)
{
ui->eventView_2->setDefaultRowHeight(height);
}
}
void CEventForm::setColumnWidth(const int &column, const int &width)
{
if(column<0 ||column >=9)
{
return ;
}
if(column < 7)
{
if(ui->eventView != Q_NULLPTR)
{
ui->eventView->setColumnWidth(column, width);
}
if(ui->eventView_2 != Q_NULLPTR)
{
ui->eventView_2->setColumnWidth(column, width);
}
}else if(column >= 7)
{
if(ui->eventView_2 != Q_NULLPTR)
{
ui->eventView_2->setColumnWidth(column, width);
}
}
}
void CEventForm::setColumnVisible(const int &column, const bool &visible)
{
if(ui->eventView != Q_NULLPTR)
{
ui->eventView->setColumnHidden(column, !visible);
}
}
void CEventForm::setHisColumnWidth(const int &column, const int &width)
{
if(ui->eventView_2 != Q_NULLPTR)
{
ui->eventView_2->setColumnWidth(column, width);
}
}
void CEventForm::setHisColumnVisible(const int &column, const bool &visible)
{
if(ui->eventView_2 != Q_NULLPTR)
{
ui->eventView_2->setColumnHidden(column, !visible);
}
}
void CEventForm::setEnableAccidentReview(bool isNeed)
{
m_isNeedAccidentReview = isNeed;
}
void CEventForm::setEnableWave(bool isNeed)
{
if(m_pRealDelegate)
{
m_pRealDelegate->setEnableWave(isNeed);
}
if(m_pHistoryDelegate)
{
m_pHistoryDelegate->setEnableWave(isNeed);
}
}
void CEventForm::setAccidentReviewPath(const QString &path)
{
m_strAccidenPath = path;
}
void CEventForm::initFilter()
{
m_pListWidget1->clear();
m_pListWidget2->clear();
m_pListWidget3->clear();
QMap<int, QString> priority = CEventDataCollect::instance()->priorityDescriptionMap();
QMap<int, QString> alarmStatus = CEventDataCollect::instance()->eventShowStatusDescriptionMap();
for(QMap<int, QString>::iterator it1 = priority.begin();it1 != priority.end();++it1)
{
QListWidgetItem *pItem = new QListWidgetItem(m_pListWidget1);
pItem->setData(Qt::UserRole, it1.key());
CMyCheckBox *pCheckBox = new CMyCheckBox(this);
pCheckBox->setText(it1.value());
m_pListWidget1->addItem(pItem);
m_pListWidget1->setItemWidget(pItem, pCheckBox);
connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(stateChanged1(int)));
}
QList<int> locOrder = CEventDataCollect::instance()->locationOrderList();
foreach (const int &locId, locOrder) {
QListWidgetItem *pItem = new QListWidgetItem(m_pListWidget2);
pItem->setData(Qt::UserRole, locId);
CMyCheckBox *pCheckBox = new CMyCheckBox(this);
pCheckBox->setText(CEventDataCollect::instance()->locationDescription(locId));
m_pListWidget2->addItem(pItem);
m_pListWidget2->setItemWidget(pItem, pCheckBox);
connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(stateChanged2(int)));
}
for(QMap<int, QString>::iterator it3 = alarmStatus.begin();it3 != alarmStatus.end();++it3)
{
QListWidgetItem *pItem = new QListWidgetItem(m_pListWidget3);
pItem->setData(Qt::UserRole, it3.key());
CMyCheckBox *pCheckBox = new CMyCheckBox(this);
pCheckBox->setText(it3.value());
m_pListWidget3->addItem(pItem);
m_pListWidget3->setItemWidget(pItem, pCheckBox);
connect(pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(stateChanged3(int)));
}
if(m_pDeviceModel)
{
m_pDeviceModel->setAllDeviceCheckState(Qt::Checked);
}
if(m_pDeviceHisModel)
{
m_pDeviceHisModel->setAllDeviceCheckState(Qt::Checked);
}
}
void CEventForm::setLevelComboBox(bool &isLevelFilter, QList<int> &listLevel)
{
if(isLevelFilter == true && listLevel.size() > 0)
{
QString strText("");
for (int i = 0; i < ui->comboBox->count(); ++i)
{
QListWidgetItem *pItem = m_pListWidget1->item(i);
QWidget *pWidget = m_pListWidget1->itemWidget(pItem);
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
int nData = pItem->data(Qt::UserRole).toInt();
if(listLevel.contains(nData))
{
pCheckBox->blockSignals(true);
pCheckBox->setChecked(true);
strText.append(pCheckBox->text()).append(" ");
pCheckBox->blockSignals(false);
}else
{
pCheckBox->blockSignals(true);
pCheckBox->setChecked(false);
pCheckBox->blockSignals(false);
}
}
m_strText1 = strText;
m_pLineEdit1->setText(strText);
}else
{
for (int i = 0; i < ui->comboBox->count(); ++i)
{
QListWidgetItem *pItem = m_pListWidget1->item(i);
QWidget *pWidget = m_pListWidget1->itemWidget(pItem);
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
pCheckBox->blockSignals(true);
pCheckBox->setChecked(false);
pCheckBox->blockSignals(false);
}
m_strText1 = tr("请选择优先级");
m_pLineEdit1->setText(tr("请选择优先级"));
}
}
void CEventForm::setLocationComboBox(bool &isLocationFilter, QList<int> &listLocation)
{
if(isLocationFilter == true && listLocation.size() > 0)
{
QString strText("");
for (int i = 0; i < ui->comboBox_2->count(); ++i)
{
QListWidgetItem *pItem = m_pListWidget2->item(i);
QWidget *pWidget = m_pListWidget2->itemWidget(pItem);
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
int nData = pItem->data(Qt::UserRole).toInt();
if(listLocation.contains(nData))
{
pCheckBox->blockSignals(true);
pCheckBox->setChecked(true);
strText.append(pCheckBox->text()).append(" ");
pCheckBox->blockSignals(false);
}else
{
pCheckBox->blockSignals(true);
pCheckBox->setChecked(false);
pCheckBox->blockSignals(false);
}
}
m_strText2 = strText;
m_pLineEdit2->setText(strText);
}else
{
for (int i = 0; i < ui->comboBox_2->count(); ++i)
{
QListWidgetItem *pItem = m_pListWidget2->item(i);
QWidget *pWidget = m_pListWidget2->itemWidget(pItem);
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
pCheckBox->blockSignals(true);
pCheckBox->setChecked(false);
pCheckBox->blockSignals(false);
}
m_strText2 = tr("请选择位置");
m_pLineEdit2->setText(tr("请选择位置"));
}
}
void CEventForm::setEventStatusComboBox(bool &isEventStatusFilter, QList<int> &listEventStatus)
{
if(isEventStatusFilter == true && listEventStatus.size() > 0)
{
QString strText("");
for (int i = 0; i < ui->comboBox_3->count(); ++i)
{
QListWidgetItem *pItem = m_pListWidget3->item(i);
QWidget *pWidget = m_pListWidget3->itemWidget(pItem);
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
int nData = pItem->data(Qt::UserRole).toInt();
if(listEventStatus.contains(nData))
{
pCheckBox->blockSignals(true);
pCheckBox->setChecked(true);
strText.append(pCheckBox->text()).append(" ");
pCheckBox->blockSignals(false);
}else
{
pCheckBox->blockSignals(true);
pCheckBox->setChecked(false);
pCheckBox->blockSignals(false);
}
}
m_strText3 = strText;
m_pLineEdit3->setText(strText);
}else
{
for (int i = 0; i < ui->comboBox_3->count(); ++i)
{
QListWidgetItem *pItem = m_pListWidget3->item(i);
QWidget *pWidget = m_pListWidget3->itemWidget(pItem);
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
pCheckBox->blockSignals(true);
pCheckBox->setChecked(false);
pCheckBox->blockSignals(false);
}
m_strText3 = tr("请选择事件状态");
m_pLineEdit3->setText(tr("请选择事件状态"));
}
}
void CEventForm::setEventTimeLineEdit(bool &isTimeFilter, QDateTime &startTime, QDateTime &endTime)
{
if(isTimeFilter == true)
{
ui->lineEdit->setText(startTime.date().toString("yyyy-MM-dd")+"~"+endTime.date().toString("yyyy-MM-dd"));
}else
{
ui->lineEdit->setText(tr("请选择时间"));
}
}
void CEventForm::slotClearRTEvent()
{
CEventDataCollect::instance()->handleClearRTEvent();
}
void CEventForm::deviceGroupFilterChanged(const QString &device, const bool &checked)
{
if(checked)
{
if(m_pRealTimeModel)
{
m_pRealTimeModel->addDeviceGroupFilter(device);
}
}
else
{
if(m_pRealTimeModel)
{
m_pRealTimeModel->removeDeviceGroupFilter(device);
}
}
}
void CEventForm::hisDeviceGroupFilterChanged(const QString &device, const bool &checked)
{
if(checked)
{
if(m_pHistoryModel)
{
m_pHistoryModel->addDeviceGroupFilter(device);
m_pHistoryModel->updateShowEvents();
}
}
else
{
if(m_pHistoryModel)
{
m_pHistoryModel->removeDeviceGroupFilter(device);
m_pHistoryModel->updateShowEvents();
}
}
}
void CEventForm::updateFilter()
{
CEventFilterDialog filterDlg(this);
bool isLevelFilter;
QList<int> levelFilter;
bool isLocationFilter;
QList<int> locationFilter;
bool isRegionFilter;
QList<int> regionFilter;
bool isAlarmTypeFilter;
QList<int> typeFilter;
bool deviceTypeFilter;
QString subSystem;
QString deviceType;
bool keywordFilter;
QString keyword;
bool isTimeFilterEnable;
QDateTime startTime;
QDateTime endTime;
bool isReturnFilterEnable;
bool isReturn;
if(ui->realEventButton->isChecked())
{
m_pRealTimeModel->getFilter(isLevelFilter, levelFilter,
isLocationFilter, locationFilter,
isRegionFilter, regionFilter,
isAlarmTypeFilter, typeFilter,
deviceTypeFilter, subSystem, deviceType,
keywordFilter, keyword,
isTimeFilterEnable, startTime, endTime,isReturnFilterEnable,isReturn);
filterDlg.initialize(E_ALARM_REAL_EVENT);
}
else if(ui->hisEventButton->isChecked())
{
m_pHistoryModel->getFilter(isLevelFilter, levelFilter,
isLocationFilter, locationFilter,
isRegionFilter, regionFilter,
isAlarmTypeFilter, typeFilter,
deviceTypeFilter, subSystem, deviceType,
keywordFilter, keyword,
isTimeFilterEnable, startTime, endTime,isReturnFilterEnable,isReturn);
filterDlg.initialize(E_ALARM_HIS_EVENT);
}
filterDlg.setLevelFilterEnable(isLevelFilter);
filterDlg.setLevelFilter(levelFilter);
filterDlg.setLocationFilterEnable(isLocationFilter);
filterDlg.setLocationFilter(locationFilter);
filterDlg.setRegionFilterEnable(isRegionFilter);
filterDlg.setRegionFilter(regionFilter);
filterDlg.setAlarmTypeFilterEnable(isAlarmTypeFilter);
filterDlg.setAlarmTypeFilter(typeFilter);
filterDlg.setDeviceFilterEnable(deviceTypeFilter);
filterDlg.setSubSystem(subSystem);
filterDlg.setDeviceType(deviceType);
filterDlg.setkeyWordFilterEnable(keywordFilter);
filterDlg.setkeyWordFilteContent(keyword);
filterDlg.setTimeFilterEnable(isTimeFilterEnable);
filterDlg.setStartTimeFilter(startTime);
filterDlg.setEndTimeFilter(endTime);
filterDlg.setReturnFilterEnable(isReturnFilterEnable);;
filterDlg.setReturnFilter(isReturn);
connect(&filterDlg, SIGNAL(sig_updateFilter(bool, QList<int>, bool, QList<int>, bool, QList<int>, bool, QList<int>, bool, QString, QString, bool, QString, bool, QDateTime, QDateTime,bool,bool)),
this, SLOT(slot_updateFilter(bool, QList<int>, bool, QList<int>, bool, QList<int>, bool, QList<int>, bool, QString, QString, bool, QString, bool, QDateTime, QDateTime,bool,bool)));
filterDlg.exec();
}
void CEventForm::slot_updateFilter(bool isLevelFilter, QList<int> listLevel, bool isLocationFilter, QList<int> listLocation, bool isRegionFilter, QList<int> listRegion, bool isEventStatusFilter, QList<int> listEventStatus,
bool isDeviceTypeFilter, QString subSystem, QString deviceType, bool isKeywordFilterEnable, QString keyword, bool isTimeFilter, QDateTime startTime, QDateTime endTime, bool isReturnFilter, bool isReturn)
{
if(ui->realEventButton->isChecked())
{
m_pRealTimeModel->setFilter(isLevelFilter, listLevel, isLocationFilter, listLocation, isRegionFilter, listRegion, isEventStatusFilter, listEventStatus, isDeviceTypeFilter, subSystem, deviceType, isKeywordFilterEnable, keyword, isTimeFilter, startTime, endTime,isReturnFilter,isReturn);
setLevelComboBox(isLevelFilter,listLevel);
setLocationComboBox(isLocationFilter,listLocation);
setEventStatusComboBox(isEventStatusFilter,listEventStatus);
setEventTimeLineEdit(isTimeFilter, startTime, endTime);
slotUpdateRTTips();
}
else if(ui->hisEventButton->isChecked())
{
m_pHistoryModel->setFilter(isLevelFilter, listLevel, isLocationFilter, listLocation, isRegionFilter, listRegion, isEventStatusFilter, listEventStatus, isDeviceTypeFilter, subSystem, deviceType, isKeywordFilterEnable, keyword, isTimeFilter, startTime, endTime,isReturnFilter,isReturn);
setLevelComboBox(isLevelFilter,listLevel);
setLocationComboBox(isLocationFilter,listLocation);
setEventStatusComboBox(isEventStatusFilter,listEventStatus);
setEventTimeLineEdit(isTimeFilter, startTime, endTime);
m_pHistoryModel->loadEventHistoryData();
}
}
void CEventForm::slotRTEventStateChanged()
{
if(dynamic_cast<CEventItemModel*>(ui->eventView->model()))
{
slotUpdateRTTips();
}
}
void CEventForm::slotUpdateRTTips()
{
ui->typeLabel->setText(tr("实时事件总数:"));
if(m_pRealTimeModel)
{
ui->eventCount->setText(QString::number(m_pRealTimeModel->rowCount()));
}
}
void CEventForm::slotUpdateHISTipsRequesting()
{
ui->typeLabel_2->setText(tr("正在查询历史事件..."));
ui->eventCount_2->setText("");
ui->label_his_tip->setText("");
}
void CEventForm::slotPermInvalid()
{
QMessageBox::critical(this, tr("错误"), tr("当前用户不具备事件浏览权限"), QMessageBox::Ok);
}
void CEventForm::slotUpdateHISTips()
{
ui->typeLabel_2->setText(tr("历史事件数量:"));
if(m_pHistoryModel)
{
int count = m_pHistoryModel->rowCount();
ui->eventCount_2->setText(QString::number(count));
if(count >= LIMIT_HIS_RECORD)
{
ui->label_his_tip->setText(tr("历史事件数量超出10000条,超出部分不显示"));
}else
{
ui->label_his_tip->setText("");
}
}
}
void CEventForm::slotHISRecordOutOfRangeTips(QStringList stDescList)
{
QString stMess = "";
for( int index(0);index!=stDescList.size() ; ++index )
{
stMess += stDescList.at(index);
if(index != stDescList.size()-1)
stMess += "/";
}
if(stDescList.size() != 0)
{
QMessageBox::information(this, tr("提示"),
QString(tr("历史事件数量超出%1条,未予显示!")).arg(LIMIT_HIS_RECORD),
QMessageBox::Ok);
}
}
void CEventForm::slotHisOutOfRangeTips()
{
QMessageBox::information(this, tr("提示"),
QString(tr("历史事件数量超出%1条,未予显示!")).arg(LIMIT_HIS_RECORD),
QMessageBox::Ok);
}
void CEventForm::print()
{
QString fileName=QFileDialog::getSaveFileName(this,tr("Save File"),QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),"*.xlsx");//获取保存路径*.xls
if(!fileName.isEmpty())
{
if(ui->realEventButton->isChecked())
{
if(!fileName.endsWith(".xlsx",Qt::CaseInsensitive))
fileName = fileName + ".xlsx";
emit printExcel(m_pRealTimeModel,fileName);
}else if(ui->hisEventButton->isChecked())
{
if(!fileName.endsWith(".xlsx",Qt::CaseInsensitive))
fileName = fileName + ".xlsx";
emit printExcelHis(m_pHistoryModel,fileName);
}
}
}
void CEventForm::stateChanged1(int state)
{
Q_UNUSED(state);
QString strText("");
m_priorityList.clear();
int nCount = m_pListWidget1->count();
for (int i = 0; i < nCount; ++i)
{
QListWidgetItem *pItem = m_pListWidget1->item(i);
QWidget *pWidget = m_pListWidget1->itemWidget(pItem);
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
if (pCheckBox->isChecked())
{
int nData = pItem->data(Qt::UserRole).toInt();
QString strtext = pCheckBox->text();
strText.append(strtext).append(" ");
m_priorityList.append(nData);
}
}
if (!strText.isEmpty())
{
m_strText1 = strText;
m_pLineEdit1->setText(strText);
}
else
{
m_pLineEdit1->clear();
m_strText1 = tr("请选择优先级");
m_pLineEdit1->setText(tr("请选择优先级"));
}
bool isCheck = false;
if(ui->realEventButton->isChecked())
{
if(m_priorityList.size() == 0)
{
m_pRealTimeModel->setPriorityFilter(isCheck,m_priorityList);
}else
{
isCheck = true;
m_pRealTimeModel->setPriorityFilter(isCheck,m_priorityList);
}
slotUpdateRTTips();
updateDeviceGroupHiddenState();
}
else if(ui->hisEventButton->isChecked())
{
if(m_priorityList.size() == 0)
{
m_pHistoryModel->setPriorityFilter(isCheck,m_priorityList);
}else
{
isCheck = true;
m_pHistoryModel->setPriorityFilter(isCheck,m_priorityList);
}
m_pHistoryModel->loadEventHistoryData();
}
}
void CEventForm::stateChanged2(int state)
{
Q_UNUSED(state);
QString strText("");
m_locationList.clear();
int nCount = m_pListWidget2->count();
for (int i = 0; i < nCount; ++i)
{
QListWidgetItem *pItem = m_pListWidget2->item(i);
QWidget *pWidget = m_pListWidget2->itemWidget(pItem);
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
if (pCheckBox->isChecked())
{
int nData = pItem->data(Qt::UserRole).toInt();
QString strtext = pCheckBox->text();
strText.append(strtext).append(" ");
m_locationList.append(nData);
}
}
if (!strText.isEmpty())
{
m_strText2 = strText;
m_pLineEdit2->setText(strText);
}
else
{
m_pLineEdit2->clear();
m_strText2 = tr("请选择位置");
m_pLineEdit2->setText(tr("请选择位置"));
}
bool isCheck = false;
if(ui->realEventButton->isChecked())
{
if(m_locationList.size() == 0)
{
m_pRealTimeModel->setLocationFilter(isCheck,m_locationList);
}else
{
isCheck = true;
m_pRealTimeModel->setLocationFilter(isCheck,m_locationList);
}
slotUpdateRTTips();
updateDeviceGroupHiddenState();
}
else if(ui->hisEventButton->isChecked())
{
if(m_locationList.size() == 0)
{
m_pHistoryModel->setLocationFilter(isCheck,m_locationList);
}else
{
isCheck = true;
m_pHistoryModel->setLocationFilter(isCheck,m_locationList);
}
m_pHistoryModel->loadEventHistoryData();
}
}
void CEventForm::stateChanged3(int state)
{
Q_UNUSED(state);
QString strText("");
m_eventStatusList.clear();
bool other = false;
int nCount = m_pListWidget3->count();
for (int i = 0; i < nCount; ++i)
{
QListWidgetItem *pItem = m_pListWidget3->item(i);
QWidget *pWidget = m_pListWidget3->itemWidget(pItem);
CMyCheckBox *pCheckBox = (CMyCheckBox *)pWidget;
if (pCheckBox->isChecked())
{
int nData = pItem->data(Qt::UserRole).toInt();
if(nData == OTHERSTATUS)
{
other = true;
}
QString strtext = pCheckBox->text();
strText.append(strtext).append(" ");
m_eventStatusList.append(nData);
}
}
if (!strText.isEmpty())
{
m_strText3 = strText;
m_pLineEdit3->setText(strText);
}
else
{
m_pLineEdit3->clear();
m_strText3 = tr("请选择事件状态");
m_pLineEdit3->setText(tr("请选择事件状态"));
}
bool isCheck = false;
if(ui->realEventButton->isChecked())
{
if(m_eventStatusList.size() == 0)
{
m_pRealTimeModel->setEventTypeFilter(isCheck,m_eventStatusList,other);
}else
{
isCheck = true;
m_pRealTimeModel->setEventTypeFilter(isCheck,m_eventStatusList,other);
}
slotUpdateRTTips();
updateDeviceGroupHiddenState();
}
else if(ui->hisEventButton->isChecked())
{
if(m_eventStatusList.size() == 0)
{
m_pHistoryModel->setEventTypeFilter(isCheck,m_eventStatusList,other);
}else
{
isCheck = true;
m_pHistoryModel->setEventTypeFilter(isCheck,m_eventStatusList,other);
}
m_pHistoryModel->loadEventHistoryData();
}
}
void CEventForm::textChanged1(const QString &text)
{
Q_UNUSED(text);
m_pLineEdit1->setText(m_strText1);
}
void CEventForm::textChanged2(const QString &text)
{
Q_UNUSED(text);
m_pLineEdit2->setText(m_strText2);
}
void CEventForm::textChanged3(const QString &text)
{
Q_UNUSED(text);
m_pLineEdit3->setText(m_strText3);
}
void CEventForm::myCalendarHide(QDate startTime, QDate endTime)
{
ui->lineEdit->setText(startTime.toString("yyyy-MM-dd") +"~"+endTime.toString("yyyy-MM-dd"));
//开始过滤
bool isCheck = false;
if(ui->realEventButton->isChecked())
{
isCheck = true;
m_pRealTimeModel->setEventTimeFilter(isCheck,startTime,endTime);
}else if(ui->hisEventButton->isChecked())
{
isCheck = true;
m_pHistoryModel->setEventTimeFilter(isCheck,startTime,endTime);
m_pHistoryModel->loadEventHistoryData();
}
m_timeMenu->hide();
}
void CEventForm::myCalendarShow()
{
QPoint point(QCursor::pos().x()-500,QCursor::pos().y()+15);
if(ui->realEventButton->isChecked())
{
m_myCalendar->setView(E_ALARM_REAL_EVENT);
}else if(ui->hisEventButton->isChecked())
{
m_myCalendar->setView(E_ALARM_HIS_EVENT);
}
m_timeMenu->move(point);
m_timeMenu->show();
}
void CEventForm::cancleTimeFilter()
{
ui->lineEdit->setText(tr("请选择时间"));
//取消过滤
bool isCheck = false;
if(ui->realEventButton->isChecked())
{
m_pRealTimeModel->setEventTimeFilter(isCheck);
}else if(ui->hisEventButton->isChecked())
{
m_pHistoryModel->setEventTimeFilter(isCheck);
m_pHistoryModel->loadEventHistoryData();
}
m_timeMenu->hide();
}
void CEventForm::searchRealDeviceName()
{
QItemSelection selection;
QString content = m_pRealSearchEdit->text();
ui->treeView->selectionModel()->select(selection, QItemSelectionModel::Clear);
if(content.isEmpty())
{
return;
}
const QHash< QString, QModelIndex > &indexNameList = m_pDeviceModel->indexNameList();
QHash< QString, QModelIndex >::const_iterator iter = indexNameList.constBegin();
while (iter != indexNameList.constEnd())
{
if(ui->treeView->isRowHidden(iter.value().row(), iter.value().parent()))
{
iter++;
continue;
}
if(iter.key().section(".", 1).contains(content, Qt::CaseInsensitive))
{
selection.append(QItemSelectionRange(iter.value(), iter.value()));
selection.append(QItemSelectionRange(iter.value().parent(), iter.value().parent()));
}
iter++;
}
ui->treeView->selectionModel()->select(selection, QItemSelectionModel::Select);
}
void CEventForm::searchHistoryDeviceName()
{
QItemSelection selection;
QString content = m_pHistorySearchEdit->text();
ui->treeView_2->selectionModel()->select(selection, QItemSelectionModel::Clear);
if(content.isEmpty())
{
return;
}
const QHash< QString, QModelIndex > &indexNameList = m_pDeviceHisModel->indexNameList();
QHash< QString, QModelIndex >::const_iterator iter = indexNameList.constBegin();
while (iter != indexNameList.constEnd())
{
if(ui->treeView_2->isRowHidden(iter.value().row(), iter.value().parent()))
{
iter++;
continue;
}
if(iter.key().section(".", 1).contains(content, Qt::CaseInsensitive))
{
selection.append(QItemSelectionRange(iter.value(), iter.value()));
selection.append(QItemSelectionRange(iter.value().parent(), iter.value().parent()));
}
iter++;
}
ui->treeView_2->selectionModel()->select(selection, QItemSelectionModel::Select);
}
void CEventForm::contextMenuEvent(QContextMenuEvent *event)
{
QWidget::contextMenuEvent(event);
if(ui->realEventButton->isChecked())
{
contextMenuRealEvent(event);
}else if(ui->hisEventButton->isChecked())
{
contextMenuHisEvent(event);
}
}
void CEventForm::contextMenuRealEvent(QContextMenuEvent *event)
{
if(event->pos().x() < ui->eventView->pos().x())
{
return;
}
QRect headerRect = ui->eventView->horizontalHeader()->rect();
headerRect.moveTopLeft(ui->eventView->mapTo(this, QPoint()));
if(headerRect.contains(event->pos()))
{
QMenu columnMenu(this);
for(int nColumnIndex(0); nColumnIndex < m_pRealTimeModel->columnCount()-1; nColumnIndex++)
{
QAction * action = columnMenu.addAction(m_pRealTimeModel->headerData(nColumnIndex, Qt::Horizontal, Qt::DisplayRole).toString());
action->setCheckable(true);
action->setChecked(!ui->eventView->isColumnHidden(nColumnIndex));
connect(action, &QAction::triggered, [=](){
ui->eventView->setColumnHidden(nColumnIndex, !action->isChecked());
QSettings columFlags1("IOT_HMI", "eventReal config");
columFlags1.setValue(QString("eventReal/colum_%1").arg(nColumnIndex), !action->isChecked());
});
}
columnMenu.exec(QCursor::pos());
}else
{
QModelIndex index_ = ui->eventView->indexAt(ui->eventView->mapFromGlobal(event->globalPos() - QPoint(0, headerRect.height())));
if(!index_.isValid())
{
return;
}
QMenu menu(this);
QModelIndex index = ui->eventView->currentIndex();
if(!index.isValid())
{
return ;
}
QModelIndexList indexLists = ui->eventView->selectionModel()->selectedIndexes();
//判断右键位置是否在选中区
if(!indexLists.contains(index))
{
ui->eventView->clearSelection();
ui->eventView->setCurrentIndex(index);
}
if(m_isNeedAccidentReview)
{
QAction * accidentReviewAction = menu.addAction(tr("事故追忆"));
connect(accidentReviewAction,&QAction::triggered,[=](){
rightAccidentReviewReal();
});
}
menu.exec(QCursor::pos());
}
}
void CEventForm::contextMenuHisEvent(QContextMenuEvent *event)
{
if(event->pos().x() < ui->eventView_2->pos().x())
{
return;
}
QRect headerRect = ui->eventView_2->horizontalHeader()->rect();
headerRect.moveTopLeft(ui->eventView_2->mapTo(this, QPoint()));
if(headerRect.contains(event->pos()))
{
QMenu columnMenu(this);
for(int nColumnIndex(0); nColumnIndex < m_pHistoryModel->columnCount()-1; nColumnIndex++)
{
QAction * action = columnMenu.addAction(m_pHistoryModel->headerData(nColumnIndex, Qt::Horizontal, Qt::DisplayRole).toString());
action->setCheckable(true);
action->setChecked(!ui->eventView_2->isColumnHidden(nColumnIndex));
connect(action, &QAction::triggered, [=](){
ui->eventView_2->setColumnHidden(nColumnIndex, !action->isChecked());
QSettings columFlags2("IOT_HMI", "eventHis config");
columFlags2.setValue(QString("eventHis/colum_%1").arg(nColumnIndex), !action->isChecked());
});
}
columnMenu.exec(QCursor::pos());
}else
{
QModelIndex index_ = ui->eventView_2->indexAt(ui->eventView_2->mapFromGlobal(event->globalPos() - QPoint(0, headerRect.height())));
if(!index_.isValid())
{
return;
}
QMenu menu(this);
QModelIndex index = ui->eventView_2->currentIndex();
if(!index.isValid())
{
return ;
}
QModelIndexList indexLists = ui->eventView_2->selectionModel()->selectedIndexes();
//判断右键位置是否在选中区
if(!indexLists.contains(index))
{
ui->eventView_2->clearSelection();
ui->eventView_2->setCurrentIndex(index);
}
if(m_isNeedAccidentReview)
{
QAction * accidentReviewAction = menu.addAction(tr("事故追忆"));
connect(accidentReviewAction,&QAction::triggered,[=](){
rightAccidentReviewHis();
});
}
menu.exec(QCursor::pos());
}
}
void CEventForm::loadDeviceGroupFilterWidget()
{
if(!m_pDeviceModel && !m_pDeviceHisModel)
{
return;
}
iot_dbms::CDbApi objReader(DB_CONN_MODEL_READ);
if(!objReader.open())
{
LOGERROR("load deviceGroup info error, database open failed, %s", objReader.getLastErrorString().toStdString().c_str());
return;
}
QMap< int, QVector< QPair< QString, QString > > > locationInfos;
QList<int> locationList = CEventDataCollect::instance()->locationOrderList();
for(int nIndex(0); nIndex<locationList.length(); nIndex++)
{
QVector< QPair< QString, QString > > dev;
QSqlQuery query;
QString sqlSequenceQuery = QString("select tag_name, description from dev_group where location_id = %1;").arg(locationList[nIndex]);
if(objReader.execute(sqlSequenceQuery, query))
{
while(query.next())
{
dev.append(qMakePair<QString, QString>(query.value(0).toString(), query.value(1).toString()));
}
locationInfos.insert(locationList[nIndex], dev);
}else
{
LOGERROR("load device info error, dbInterface execute failed!");
}
}
if(m_pDeviceModel)
{
m_pDeviceModel->removeData();
m_pDeviceModel->setupModelData(locationInfos,locationList);
updateDeviceGroupHiddenState();
ui->treeView->expandAll();
}
if(m_pDeviceHisModel)
{
m_pDeviceHisModel->removeData();
m_pDeviceHisModel->setupModelData(locationInfos,locationList);
updateHisDeviceGroupHiddenState(QList<EventMsgPtr>());
ui->treeView_2->expandAll();
}
}
void CEventForm::updateDeviceGroupHiddenState()
{
m_pDeviceModel->slotHisDevTreeUpdate(m_pRealTimeModel->getListShowAlarmInfo());
QHash<QString, int> listDeviceStatisticalInfo = m_pDeviceModel->getDeviceStatisticalInfo();
for(int nTopLevelRow(0); nTopLevelRow < m_pDeviceModel->rowCount(); nTopLevelRow++)
{
QModelIndex topLevelIndex = m_pDeviceModel->index(nTopLevelRow, 0);
for(int nChildRow(0); nChildRow < m_pDeviceModel->rowCount(topLevelIndex); nChildRow++)
{
CEventDeviceTreeItem *item = static_cast<CEventDeviceTreeItem*>(m_pDeviceModel->index(nChildRow, 0, topLevelIndex).internalPointer());
ui->treeView->setRowHidden(nChildRow, topLevelIndex, !listDeviceStatisticalInfo.value(item->data(Qt::UserRole).toString(), 0));
}
}
}
void CEventForm::updateHisDeviceGroupHiddenState(QList<EventMsgPtr> eventList)
{
m_pDeviceHisModel->slotHisDevTreeUpdate(eventList);
QHash<QString, int> listDeviceStatisticalInfo = m_pDeviceHisModel->getDeviceStatisticalInfo();
for(int nTopLevelRow(0); nTopLevelRow < m_pDeviceHisModel->rowCount(); nTopLevelRow++)
{
QModelIndex topLevelIndex = m_pDeviceHisModel->index(nTopLevelRow, 0);
for(int nChildRow(0); nChildRow < m_pDeviceHisModel->rowCount(topLevelIndex); nChildRow++)
{
CEventDeviceTreeItem *item = static_cast<CEventDeviceTreeItem*>(m_pDeviceHisModel->index(nChildRow, 0, topLevelIndex).internalPointer());
ui->treeView_2->setRowHidden(nChildRow, topLevelIndex, !listDeviceStatisticalInfo.value(item->data(Qt::UserRole).toString(), 0));
}
}
}
void CEventForm::updateStack(int index)
{
if(m_ncurIndex == index)
{
return ;
}
if(index==0)
{
bool isLevelFilterEnable = false;
QList<int> priorityFilterList;
m_pRealTimeModel->getPriorityFilter(isLevelFilterEnable,priorityFilterList);
bool isLocationFilterEnable = false;
QList<int> locationFilterList;
m_pRealTimeModel->getLocationFilter(isLocationFilterEnable,locationFilterList);
bool isStatusFilterEnable = false;
QList<int> statusFilterList;
m_pRealTimeModel->getEventStatusFilter(isStatusFilterEnable,statusFilterList);
bool timeFilterEnable = false;
QDateTime startTime;
QDateTime endTime;
m_pRealTimeModel->getEventTimeFilter(timeFilterEnable,startTime,endTime);
setLevelComboBox(isLevelFilterEnable,priorityFilterList);
setLocationComboBox(isLocationFilterEnable,locationFilterList);
setEventStatusComboBox(isStatusFilterEnable,statusFilterList);
setEventTimeLineEdit(timeFilterEnable, startTime, endTime);
ui->clear->setEnabled(true);
m_ncurIndex = index;
ui->eventStackWidget->setCurrentIndex(0);
}else if(index == 1)
{
bool isLevelFilterEnable = false;
QList<int> priorityFilterList;
m_pHistoryModel->getPriorityFilter(isLevelFilterEnable,priorityFilterList);
bool isLocationFilterEnable = false;
QList<int> locationFilterList;
m_pHistoryModel->getLocationFilter(isLocationFilterEnable,locationFilterList);
bool isStatusFilterEnable = false;
QList<int> statusFilterList;
m_pHistoryModel->getEventStatusFilter(isStatusFilterEnable,statusFilterList);
setLevelComboBox(isLevelFilterEnable,priorityFilterList);
setLocationComboBox(isLocationFilterEnable,locationFilterList);
setEventStatusComboBox(isStatusFilterEnable,statusFilterList);
QDate startData = QDate::currentDate().addDays(-6);
QDate endData = QDate::currentDate();
bool check = true;
m_pHistoryModel->setEventTimeFilter(check,startData,endData);
ui->lineEdit->setText(startData.toString("yyyy-MM-dd")+"~"+endData.toString("yyyy-MM-dd"));
m_pHistoryModel->loadEventHistoryData();
ui->clear->setEnabled(false);
m_ncurIndex = index;
ui->eventStackWidget->setCurrentIndex(1);
}
}
void CEventForm::rightAccidentReviewReal()
{
QModelIndex index = ui->eventView->currentIndex();
if(!index.isValid())
{
return ;
}
QList<EventMsgPtr> listInfo = m_pRealTimeModel->getListEventInfo();
EventMsgPtr info = listInfo.at(index.row());
if(info != NULL)
{
CAccidentReviewDialog *dialog = new CAccidentReviewDialog(m_strAccidenPath, this);
if(dialog->exec() == QDialog::Accepted)
{
emit openAccidentReviewDialog(info->time_stamp-30000,30000*2,dialog->getCurrentGraph());
}
delete dialog;
dialog = NULL;
}
}
void CEventForm::rightAccidentReviewHis()
{
QModelIndex index = ui->eventView_2->currentIndex();
if(!index.isValid())
{
return ;
}
QList<EventMsgPtr> listInfo = m_pHistoryModel->getListEventInfo();
EventMsgPtr info = listInfo.at(index.row());
if(info != NULL)
{
CAccidentReviewDialog *dialog = new CAccidentReviewDialog(m_strAccidenPath, this);
if(dialog->exec() == QDialog::Accepted)
{
emit openAccidentReviewDialog(info->time_stamp-30000,30000*2,dialog->getCurrentGraph());
}
delete dialog;
dialog = NULL;
}
}