357 lines
13 KiB
C++
357 lines
13 KiB
C++
|
|
#include "dvieMainWindow.h"
|
|||
|
|
#include "./ui_dvieMainWindow.h"
|
|||
|
|
#include "transparentMask.h"
|
|||
|
|
#include "messageDialog.h"
|
|||
|
|
#include "dashboard.h"
|
|||
|
|
#include "dashboardNamingDialog.h"
|
|||
|
|
#include "panelSelectionDialog.h"
|
|||
|
|
#include "dateTimeWidget.h"
|
|||
|
|
|
|||
|
|
#include <QKeyEvent>
|
|||
|
|
#include <QMenu>
|
|||
|
|
#include <QDateTime>
|
|||
|
|
|
|||
|
|
DvieMainWindow::DvieMainWindow(QWidget *parent)
|
|||
|
|
: QMainWindow(parent)
|
|||
|
|
, ui(new Ui::dvieMainWindow)
|
|||
|
|
, m_pTransparentMask(nullptr)
|
|||
|
|
, m_pMessageDialog(nullptr)
|
|||
|
|
, m_pDashboardNamingDialog(nullptr)
|
|||
|
|
, m_curSelectedDashboard(nullptr)
|
|||
|
|
, m_curOperationDashboard(nullptr)
|
|||
|
|
, m_pPanelSelectionDialog(nullptr)
|
|||
|
|
{
|
|||
|
|
ui->setupUi(this);
|
|||
|
|
|
|||
|
|
m_pDateTimeWidget = new DateTimeWidget(this);
|
|||
|
|
ui->layout_dateTime->addWidget(m_pDateTimeWidget);
|
|||
|
|
connect(m_pDateTimeWidget, SIGNAL(showMask()), this, SLOT(onSignal_showMask()));
|
|||
|
|
connect(m_pDateTimeWidget, SIGNAL(hideMask()), this, SLOT(onSignal_hideMask()));
|
|||
|
|
connect(m_pDateTimeWidget, SIGNAL(viewHistoricalData(QDateTime)), this, SLOT(onSignal_viewHistoricalData(QDateTime)));
|
|||
|
|
|
|||
|
|
connect(ui->btnAddDashboard, SIGNAL(clicked()), this, SLOT(onBtnClicked_addDashboard()));
|
|||
|
|
connect(ui->btnAddPanel, SIGNAL(clicked()), this, SLOT(onBtnClicked_addDataPanel()));
|
|||
|
|
//connect(ui->btnDashboradList1, SIGNAL(clicked()), this, SLOT(onBtnClicked_dashboardList()));
|
|||
|
|
connect(ui->btnDashboradList2, SIGNAL(clicked()), this, SLOT(onBtnClicked_dashboardList()));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DvieMainWindow::~DvieMainWindow()
|
|||
|
|
{
|
|||
|
|
delete ui;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool DvieMainWindow::eventFilter(QObject* obj, QEvent* event)
|
|||
|
|
{
|
|||
|
|
QDialog *pDialog = qobject_cast<QDialog*>(obj);
|
|||
|
|
if(pDialog)
|
|||
|
|
{
|
|||
|
|
if(event->type() == QEvent::KeyPress)
|
|||
|
|
{
|
|||
|
|
QKeyEvent* pKeyEvent = static_cast<QKeyEvent*>(event);
|
|||
|
|
if (pKeyEvent->key() == Qt::Key_Escape)
|
|||
|
|
{
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return QObject::eventFilter(obj, event);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::showTransparentMask()
|
|||
|
|
{
|
|||
|
|
if(m_pTransparentMask == nullptr)
|
|||
|
|
m_pTransparentMask = new TransparentMask(this);
|
|||
|
|
|
|||
|
|
QPoint originPoint = this->mapToGlobal(QPoint(0, 0));
|
|||
|
|
m_pTransparentMask->setGeometry(originPoint.x(), originPoint.y(), this->width(), this->height());
|
|||
|
|
m_pTransparentMask->show();
|
|||
|
|
}
|
|||
|
|
void DvieMainWindow::hideTransparentMask()
|
|||
|
|
{
|
|||
|
|
if(m_pTransparentMask != nullptr && m_pTransparentMask->isVisible())
|
|||
|
|
m_pTransparentMask->hide();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::showMessageDialog(MessageDialogType type,const QString& strTitle,const QString& strContent)
|
|||
|
|
{
|
|||
|
|
if(m_pMessageDialog == nullptr)
|
|||
|
|
{
|
|||
|
|
m_pMessageDialog = new MessageDialog(this);
|
|||
|
|
m_pMessageDialog->installEventFilter(this);
|
|||
|
|
connect(m_pMessageDialog, SIGNAL(sgl_hide()), this, SLOT(onSignal_subDialogClose()));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_pMessageDialog->setMessage(type, strTitle, strContent);
|
|||
|
|
// QPoint originPoint = this->mapToGlobal(QPoint(0, 0));
|
|||
|
|
// int nX = originPoint.x() + (this->width() - m_pMessageDialog->width()) * 0.5;
|
|||
|
|
// int nY = originPoint.y() + (this->height() - m_pMessageDialog->height()) * 0.5;
|
|||
|
|
QPoint originPoint = ui->navigationPanel->mapToGlobal(QPoint(0, 0));
|
|||
|
|
int nX = originPoint.x() + (ui->navigationPanel->width() - m_pMessageDialog->width()) * 0.5;
|
|||
|
|
int nY = originPoint.y() + ui->navigationPanel->height() * 0.5;
|
|||
|
|
m_pMessageDialog->setGeometry(nX, nY, m_pMessageDialog->width(), m_pMessageDialog->height());
|
|||
|
|
if(type == type_question)
|
|||
|
|
m_pMessageDialog->exec();
|
|||
|
|
else
|
|||
|
|
m_pMessageDialog->show();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::addADashboard(const QString& strName)
|
|||
|
|
{
|
|||
|
|
Dashboard* dashboard = new Dashboard(strName, this);
|
|||
|
|
connect(dashboard, SIGNAL(sgl_rename()), this, SLOT(onSignal_renameDashboard()));
|
|||
|
|
connect(dashboard, SIGNAL(sgl_remove()), this, SLOT(onSignal_removeDashboard()));
|
|||
|
|
|
|||
|
|
QPushButton* tabButton = dashboard->tabButton();
|
|||
|
|
QWidget* displayArea = dashboard->displayArea();
|
|||
|
|
//添加tabButton
|
|||
|
|
int nCount = m_listDashboard.count();
|
|||
|
|
ui->hLayout_dashboardTab->insertWidget(nCount,tabButton); //已经内置好了一个水平spacer,所以要放置在其之前
|
|||
|
|
connect(tabButton, SIGNAL(clicked()), this, SLOT(onBtnClicked_dashboardTab()));
|
|||
|
|
//添加mdiArea
|
|||
|
|
QWidget* page = new QWidget(ui->dashboardStack);
|
|||
|
|
QString objName = "page_dashboard_" + strName;
|
|||
|
|
page->setObjectName(objName);
|
|||
|
|
ui->dashboardStack->addWidget(page);
|
|||
|
|
QHBoxLayout* pageLayout = new QHBoxLayout(page);
|
|||
|
|
pageLayout->setContentsMargins(0, 0, 0, 0);
|
|||
|
|
pageLayout->addWidget(displayArea);
|
|||
|
|
displayArea->setParent(page);
|
|||
|
|
ui->dashboardStack->setCurrentWidget(page);
|
|||
|
|
|
|||
|
|
m_listDashboard.push_back(dashboard);
|
|||
|
|
dashboard->setSelected(true);
|
|||
|
|
if(m_curSelectedDashboard)
|
|||
|
|
m_curSelectedDashboard->setSelected(false);
|
|||
|
|
m_curSelectedDashboard = dashboard;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::setCurrentDashboard(const QString& strName)
|
|||
|
|
{
|
|||
|
|
for(int n=0; n<m_listDashboard.count(); n++)
|
|||
|
|
{
|
|||
|
|
if(m_listDashboard.at(n)->getName() == strName)
|
|||
|
|
{
|
|||
|
|
if(m_listDashboard.at(n) == m_curSelectedDashboard)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
ui->dashboardStack->setCurrentIndex(n);
|
|||
|
|
m_listDashboard.at(n)->setSelected(true);
|
|||
|
|
m_curSelectedDashboard->setSelected(false);
|
|||
|
|
m_curSelectedDashboard = m_listDashboard.at(n);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onSignal_showMask()
|
|||
|
|
{
|
|||
|
|
showTransparentMask();
|
|||
|
|
}
|
|||
|
|
void DvieMainWindow::onSignal_hideMask()
|
|||
|
|
{
|
|||
|
|
hideTransparentMask();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onBtnClicked_addDashboard()
|
|||
|
|
{
|
|||
|
|
if(m_pDashboardNamingDialog == nullptr)
|
|||
|
|
{
|
|||
|
|
m_pDashboardNamingDialog = new DashboardNamingDialog(this);
|
|||
|
|
m_pDashboardNamingDialog->installEventFilter(this);
|
|||
|
|
connect(m_pDashboardNamingDialog, SIGNAL(sgl_hide()), this, SLOT(onSignal_subDialogClose()));
|
|||
|
|
connect(m_pDashboardNamingDialog, SIGNAL(dashboardName(const QString&, const QString&)), this, SLOT(onSignal_dashboardNaming(const QString&, const QString&)));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
showTransparentMask();
|
|||
|
|
QPoint originPoint = ui->navigationPanel->mapToGlobal(QPoint(0, 0));
|
|||
|
|
int nX = originPoint.x() + (ui->navigationPanel->width() - m_pDashboardNamingDialog->width()) * 0.5;
|
|||
|
|
int nY = originPoint.y() + ui->navigationPanel->height() * 0.5;
|
|||
|
|
m_pDashboardNamingDialog->setGeometry(nX, nY, m_pDashboardNamingDialog->width(), m_pDashboardNamingDialog->height());
|
|||
|
|
m_pDashboardNamingDialog->showUsedForCreat();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onBtnClicked_addDataPanel()
|
|||
|
|
{
|
|||
|
|
if(m_listDashboard.count() == 0)
|
|||
|
|
{
|
|||
|
|
showTransparentMask();
|
|||
|
|
showMessageDialog(type_warning, QString::fromWCharArray(L"错误"), QString::fromWCharArray(L"只能在数据看板内创建展项,请先创建一个数据看板"));
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(m_pPanelSelectionDialog == nullptr)
|
|||
|
|
{
|
|||
|
|
m_pPanelSelectionDialog = new PanelSelectionDialog(this);
|
|||
|
|
m_pPanelSelectionDialog->installEventFilter(this);
|
|||
|
|
connect(m_pPanelSelectionDialog, SIGNAL(sgl_hide()), this, SLOT(onSignal_subDialogClose()));
|
|||
|
|
connect(m_pPanelSelectionDialog, SIGNAL(panelType(const QString&)), this, SLOT(onSignal_panelSelectResult(const QString&)));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
showTransparentMask();
|
|||
|
|
QPoint originPoint = ui->navigationPanel->mapToGlobal(QPoint(0, 0));
|
|||
|
|
int nX = originPoint.x() + (ui->navigationPanel->width() - m_pPanelSelectionDialog->width()) * 0.5;
|
|||
|
|
int nY = originPoint.y() + ui->navigationPanel->height() * 0.5;
|
|||
|
|
m_pPanelSelectionDialog->setGeometry(nX, nY, m_pPanelSelectionDialog->width(), m_pPanelSelectionDialog->height());
|
|||
|
|
m_pPanelSelectionDialog->show();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onBtnClicked_dashboardList()
|
|||
|
|
{
|
|||
|
|
if(m_listDashboard.count() ==0 )
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
QMenu menu;
|
|||
|
|
menu.setStyleSheet("QMenu{\n"
|
|||
|
|
" background-color:rgb(36,43,50);\n"
|
|||
|
|
" border:1px solid rgb(6, 6, 6);\n"
|
|||
|
|
"}\n"
|
|||
|
|
"QMenu:scroller{\n"
|
|||
|
|
" show-arrows:true;\n"
|
|||
|
|
"}\n"
|
|||
|
|
"QMenu:item{\n"
|
|||
|
|
" padding-left:15px;\n"
|
|||
|
|
" padding-right:15px;\n"
|
|||
|
|
" font:9pt \"微软雅黑\";\n"
|
|||
|
|
" color:rgb(220,220,220);\n"
|
|||
|
|
" height:26px;\n"
|
|||
|
|
"}\n"
|
|||
|
|
"QMenu:item:selected{\n"
|
|||
|
|
" background-color: rgba(67,160,249, 80);\n"
|
|||
|
|
"}\n");
|
|||
|
|
for(int n=0; n<m_listDashboard.count(); n++)
|
|||
|
|
{
|
|||
|
|
menu.addAction(m_listDashboard.at(n)->getName(), this, SLOT(onMenuAction_dashboardList()));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QPoint originPoint = ui->btnDashboradList2->mapToGlobal(QPoint(0, 0));
|
|||
|
|
int nX = originPoint.x();
|
|||
|
|
originPoint = ui->navigationPanel->mapToGlobal(QPoint(0, 0));
|
|||
|
|
int nY = originPoint.y() + ui->navigationPanel->height();
|
|||
|
|
menu.exec(QPoint(nX, nY));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onBtnClicked_dashboardTab()
|
|||
|
|
{
|
|||
|
|
QPushButton* pBtn = qobject_cast<QPushButton*>(sender());
|
|||
|
|
QString strName = pBtn->text();
|
|||
|
|
setCurrentDashboard(strName);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onMenuAction_dashboardList()
|
|||
|
|
{
|
|||
|
|
QAction* action = qobject_cast<QAction*>(sender());
|
|||
|
|
QString strName = action->text();
|
|||
|
|
setCurrentDashboard(strName);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onSignal_subDialogClose()
|
|||
|
|
{
|
|||
|
|
hideTransparentMask();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onSignal_dashboardNaming(const QString& strName, const QString& strUsedFor)
|
|||
|
|
{
|
|||
|
|
for(int n=0; n<m_listDashboard.count(); n++)
|
|||
|
|
{
|
|||
|
|
if(m_listDashboard.at(n)->getName() == strName)
|
|||
|
|
{
|
|||
|
|
QString strError = QString::fromStdWString(L"已存在同名看板");
|
|||
|
|
m_pDashboardNamingDialog->showErrorInfo(strError);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(strUsedFor == "create")
|
|||
|
|
addADashboard(strName);
|
|||
|
|
else if(strUsedFor == "rename" && m_curOperationDashboard)
|
|||
|
|
m_curOperationDashboard->setName(strName);
|
|||
|
|
m_pDashboardNamingDialog->hide();
|
|||
|
|
hideTransparentMask();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onSignal_removeDashboard()
|
|||
|
|
{
|
|||
|
|
m_curOperationDashboard = qobject_cast<Dashboard*>(sender());
|
|||
|
|
if(m_curOperationDashboard)
|
|||
|
|
{
|
|||
|
|
showTransparentMask();
|
|||
|
|
QString strName = m_curOperationDashboard->getName();
|
|||
|
|
QString strMsg = QString::fromStdWString(L"确认删除名为 \"") + strName + QString::fromStdWString(L"\" 的数据看板吗?");
|
|||
|
|
showMessageDialog(type_question, QString::fromStdWString(L"删除看板"), strMsg);
|
|||
|
|
if(g_msgDlgBtn == btn_No)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
|
|||
|
|
QPushButton* tabButton = m_curOperationDashboard->tabButton();
|
|||
|
|
QWidget* displayArea = m_curOperationDashboard->displayArea();
|
|||
|
|
if(tabButton)
|
|||
|
|
{
|
|||
|
|
ui->dashboardStack->removeWidget(tabButton);
|
|||
|
|
delete tabButton;
|
|||
|
|
}
|
|||
|
|
if(displayArea)
|
|||
|
|
{
|
|||
|
|
QWidget* page = displayArea->parentWidget();
|
|||
|
|
if(page)
|
|||
|
|
{
|
|||
|
|
ui->dashboardStack->removeWidget(page);
|
|||
|
|
delete page;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int nIndex = 0;
|
|||
|
|
for(int n=0; n<m_listDashboard.count(); n++)
|
|||
|
|
{
|
|||
|
|
if(m_listDashboard.at(n) == m_curOperationDashboard)
|
|||
|
|
{
|
|||
|
|
nIndex = n;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if(m_curOperationDashboard == m_curSelectedDashboard) //如果删除的是当前选中且不是第一个,将其前一个置为选中状态
|
|||
|
|
{
|
|||
|
|
if(nIndex != 0)
|
|||
|
|
{
|
|||
|
|
m_curSelectedDashboard = m_listDashboard.at(nIndex - 1);
|
|||
|
|
m_curSelectedDashboard->setSelected(true);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
m_curSelectedDashboard = nullptr;
|
|||
|
|
}
|
|||
|
|
m_listDashboard.removeAt(nIndex);
|
|||
|
|
delete m_curOperationDashboard;
|
|||
|
|
m_curOperationDashboard = nullptr;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onSignal_renameDashboard()
|
|||
|
|
{
|
|||
|
|
m_curOperationDashboard = qobject_cast<Dashboard*>(sender());
|
|||
|
|
|
|||
|
|
if(m_pDashboardNamingDialog == nullptr)
|
|||
|
|
{
|
|||
|
|
m_pDashboardNamingDialog = new DashboardNamingDialog(this);
|
|||
|
|
connect(m_pDashboardNamingDialog, SIGNAL(dlgHide()), this, SLOT(onSignal_subDialogClose()));
|
|||
|
|
connect(m_pDashboardNamingDialog, SIGNAL(dashboardName(const QString&, const QString&)), this, SLOT(onSignal_dashboardNaming(const QString&, const QString&)));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
showTransparentMask();
|
|||
|
|
QPoint originPoint = ui->navigationPanel->mapToGlobal(QPoint(0, 0));
|
|||
|
|
int nX = originPoint.x() + (ui->navigationPanel->width() - m_pDashboardNamingDialog->width()) * 0.5;
|
|||
|
|
int nY = originPoint.y() + ui->navigationPanel->height() * 0.5;
|
|||
|
|
m_pDashboardNamingDialog->setGeometry(nX, nY, m_pDashboardNamingDialog->width(), m_pDashboardNamingDialog->height());
|
|||
|
|
m_pDashboardNamingDialog->showUsedForRename();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onSignal_panelSelectResult(const QString& strType)
|
|||
|
|
{
|
|||
|
|
//m_pPanelSelectionDialog->hide();
|
|||
|
|
hideTransparentMask();
|
|||
|
|
m_curSelectedDashboard->addPanel(strType);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DvieMainWindow::onSignal_viewHistoricalData(QDateTime dateTime)
|
|||
|
|
{
|
|||
|
|
qDebug() << "viewHistoricalData: " + dateTime.date().toString("yyyy/MM/dd");
|
|||
|
|
hideTransparentMask();
|
|||
|
|
}
|