完成dashboard的拖拽移动
This commit is contained in:
parent
2d6cf1b7f8
commit
8526de90b8
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QScrollArea>
|
||||
|
||||
class DashboardFrame;
|
||||
class QBoxLayout;
|
||||
class CustomTab;
|
||||
class CustomTabBar : public QScrollArea
|
||||
|
|
@ -13,6 +14,8 @@ public:
|
|||
CustomTabBar(QWidget *parent = nullptr);
|
||||
virtual ~CustomTabBar();
|
||||
|
||||
void setFrame(DashboardFrame*);
|
||||
DashboardFrame* frame();
|
||||
void insertTab(int, CustomTab*);
|
||||
void addTab(CustomTab*);
|
||||
void removeTab(CustomTab*);
|
||||
|
|
@ -34,10 +37,11 @@ signals:
|
|||
void tabMoved(int, int);
|
||||
|
||||
private:
|
||||
QWidget* m_pTabsContainerWidget;
|
||||
QBoxLayout* m_pTabsLayout;
|
||||
int m_nCurrentIndex;
|
||||
QWidget* m_pPosMarking;
|
||||
DashboardFrame* m_pFrame;
|
||||
QWidget* m_pTabsContainerWidget;
|
||||
QBoxLayout* m_pTabsLayout;
|
||||
int m_nCurrentIndex;
|
||||
QWidget* m_pPosMarking;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public:
|
|||
explicit Dashboard(const QString& strName, QObject *parent = nullptr);
|
||||
~Dashboard();
|
||||
|
||||
const QString& getName();
|
||||
const QString& name();
|
||||
void setName(const QString&);
|
||||
void setFrame(DashboardFrame*);
|
||||
DashboardFrame* frame();
|
||||
|
|
|
|||
|
|
@ -31,21 +31,17 @@ class DashboardFrame : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DashboardFrame(const QString&, QWidget *parent = nullptr);
|
||||
explicit DashboardFrame(const QString&, dashboardFrame::frameType, QWidget *parent = nullptr);
|
||||
~DashboardFrame();
|
||||
|
||||
CustomTabBar* tabBar();
|
||||
|
||||
void setType(dashboardFrame::frameType);
|
||||
void showMessageDialog(MessageDialogType,const QString&,const QString&);
|
||||
void addDashboard(Dashboard*);
|
||||
void insertDashboard(int, Dashboard*);
|
||||
void removeDashboard(const QString&, bool);
|
||||
|
||||
private:
|
||||
void showTransparentMask();
|
||||
void hideTransparentMask();
|
||||
|
||||
void addDashboard(const QString&);
|
||||
void setCurrentDashboard(const QString&);
|
||||
int dashboardCount();
|
||||
Dashboard* getDashboard(const QString&);
|
||||
Dashboard* takeDashboard(const QString&);
|
||||
DashboardFrame* getDashboardFrame(const QString&);
|
||||
void moveDashboardToNewDVIEWindow(const QString&, QPoint);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject*, QEvent*) override;
|
||||
|
|
@ -54,8 +50,13 @@ protected:
|
|||
void dragLeaveEvent(QDragLeaveEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
public:
|
||||
void showMessageDialog(MessageDialogType,const QString&,const QString&);
|
||||
private:
|
||||
void showTransparentMask();
|
||||
void hideTransparentMask();
|
||||
|
||||
void addDashboard(const QString&);
|
||||
void removeDashboard(const QString&, bool);
|
||||
void setCurrentDashboard(const QString&);
|
||||
|
||||
public slots:
|
||||
void onSignal_showMask();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class dvieMainWindow;
|
|||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class Dashboard;
|
||||
class DashboardFrame;
|
||||
class DvieSecondaryWindow;
|
||||
|
||||
|
|
@ -20,13 +21,15 @@ public:
|
|||
DvieMainWindow(QWidget *parent = nullptr);
|
||||
~DvieMainWindow();
|
||||
|
||||
public slots:
|
||||
|
||||
DashboardFrame* dashboardFrame();
|
||||
DashboardFrame* getDashboardFrame(const QString&);
|
||||
void creatSecondaryWindowAndAddDashboard(QPoint, Dashboard*);
|
||||
void removeSecondartWindow(QString&);
|
||||
|
||||
private:
|
||||
Ui::dvieMainWindow* ui;
|
||||
DashboardFrame* m_pDashboardFrame;
|
||||
QList<DvieSecondaryWindow*> m_listSecondaryWindow;
|
||||
Ui::dvieMainWindow* ui;
|
||||
DashboardFrame* m_pDashboardFrame;
|
||||
QHash<QString, DvieSecondaryWindow*> m_hashSecondaryWindow;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ class dvieSecondaryWindow;
|
|||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class DvieMainWindow;
|
||||
class Dashboard;
|
||||
class DashboardFrame;
|
||||
|
||||
class DvieSecondaryWindow : public QMainWindow
|
||||
|
|
@ -19,10 +21,19 @@ public:
|
|||
DvieSecondaryWindow(const QString&, QWidget *parent = nullptr);
|
||||
~DvieSecondaryWindow();
|
||||
|
||||
QString name();
|
||||
DashboardFrame* dashboardFrame();
|
||||
DashboardFrame* getDashboardFrame(const QString&);
|
||||
void creatSecondaryWindowAndAddDashboard(QPoint, Dashboard*);
|
||||
void setMainWindow(DvieMainWindow*);
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent*) override;
|
||||
|
||||
private:
|
||||
Ui::dvieSecondaryWindow* ui;
|
||||
QString m_strName;
|
||||
DvieMainWindow* m_pMainWindow;
|
||||
DashboardFrame* m_pDashboardFrame;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ void CustomTab::mouseMoveEvent(QMouseEvent* event)
|
|||
|
||||
QByteArray data;
|
||||
QDataStream dataStream(&data, QIODevice::WriteOnly);
|
||||
dataStream << text() << m_pDashboard->frame()->tabBar()->objectName();
|
||||
dataStream << text() << m_pDashboard->frame()->objectName();
|
||||
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
mimeData->setData("dragData/customTab", data);
|
||||
|
|
@ -95,6 +95,7 @@ void CustomTab::mouseMoveEvent(QMouseEvent* event)
|
|||
if(dropAction == Qt::IgnoreAction) //创建新的dvieSecondaryWindow
|
||||
{
|
||||
qDebug() << "create dvieSecondaryWindow on" << QCursor::pos();
|
||||
m_pDashboard->frame()->moveDashboardToNewDVIEWindow(text(), QCursor::pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "customTabBar.h"
|
||||
#include "customTab.h"
|
||||
#include "dashboardFrame.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QDragEnterEvent>
|
||||
|
|
@ -14,6 +15,8 @@ CustomTabBar::CustomTabBar(QWidget* parent)
|
|||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
|
||||
m_pFrame = nullptr;
|
||||
|
||||
m_pPosMarking = new QWidget(this);
|
||||
m_pPosMarking->setStyleSheet("QWidget{\n"
|
||||
" border:0px;\n"
|
||||
|
|
@ -59,6 +62,9 @@ void CustomTabBar::dragMoveEvent(QDragMoveEvent* event)
|
|||
//qDebug() << "dragMoveEvent";
|
||||
event->acceptProposedAction();
|
||||
|
||||
if(m_pTabsLayout->count() == 1) //没有tab
|
||||
return;
|
||||
|
||||
int toIndex = -1;
|
||||
int lastWidgetIndex = m_pTabsLayout->count() - 2;
|
||||
QWidget* lastWidget = m_pTabsLayout->itemAt(lastWidgetIndex)->widget();
|
||||
|
|
@ -120,10 +126,13 @@ void CustomTabBar::dropEvent(QDropEvent* event)
|
|||
QByteArray itemData = event->mimeData()->data("dragData/customTab");
|
||||
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
|
||||
QString strTabText = "";
|
||||
QString strFromBar = "";
|
||||
dataStream >> strTabText >> strFromBar;
|
||||
QString strFromFrame = "";
|
||||
dataStream >> strTabText >> strFromFrame;
|
||||
|
||||
if(strFromBar == objectName()) //同一组的tab,做移动操作
|
||||
if(!m_pFrame)
|
||||
return;
|
||||
|
||||
if(strFromFrame == m_pFrame->objectName()) //同一组的tab,做移动操作
|
||||
{
|
||||
CustomTab* sourceObj = qobject_cast<CustomTab*>(event->source());
|
||||
if(!sourceObj)
|
||||
|
|
@ -143,10 +152,24 @@ void CustomTabBar::dropEvent(QDropEvent* event)
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
DashboardFrame* fromFrame = m_pFrame->getDashboardFrame(strFromFrame);
|
||||
if(fromFrame != m_pFrame && fromFrame != nullptr)
|
||||
{
|
||||
Dashboard* dashboard = fromFrame->takeDashboard(strTabText);
|
||||
m_pFrame->insertDashboard(toIndex, dashboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CustomTabBar::setFrame(DashboardFrame* frame)
|
||||
{
|
||||
m_pFrame = frame;
|
||||
}
|
||||
DashboardFrame* CustomTabBar::frame()
|
||||
{
|
||||
return m_pFrame;
|
||||
}
|
||||
|
||||
int CustomTabBar::count()
|
||||
{
|
||||
//含有一个stretch
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ void Dashboard::deleteSubWidgets()
|
|||
}
|
||||
}
|
||||
|
||||
const QString& Dashboard::getName()
|
||||
const QString& Dashboard::name()
|
||||
{
|
||||
return m_strName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "dashboardFrame.h"
|
||||
#include "./ui_dashboardFrame.h"
|
||||
#include "dvieMainWindow.h"
|
||||
#include "dvieSecondaryWindow.h"
|
||||
#include "transparentMask.h"
|
||||
#include "messageDialog.h"
|
||||
#include "customTabBar.h"
|
||||
|
|
@ -14,7 +16,7 @@
|
|||
#include <QDateTime>
|
||||
#include <QMimeData>
|
||||
|
||||
DashboardFrame::DashboardFrame(const QString& strName, QWidget *parent)
|
||||
DashboardFrame::DashboardFrame(const QString& strName, dashboardFrame::frameType fType, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::dashboardFrame)
|
||||
, m_pParentWindow(nullptr)
|
||||
|
|
@ -30,8 +32,14 @@ DashboardFrame::DashboardFrame(const QString& strName, QWidget *parent)
|
|||
setAcceptDrops(true);
|
||||
|
||||
m_strName = strName;
|
||||
setObjectName(strName);
|
||||
m_pParentWindow = parent;
|
||||
m_type = dashboardFrame::ft_main;
|
||||
m_type = fType;
|
||||
if(m_type == dashboardFrame::ft_secondary) //只有主window具有报警提示
|
||||
{
|
||||
ui->btnEventNotication->setVisible(false);
|
||||
ui->btnAlarmNoticatio->setVisible(false);
|
||||
}
|
||||
|
||||
m_pDateTimeWidget = new DateTimeWidget(this);
|
||||
ui->layout_dateTime->addWidget(m_pDateTimeWidget);
|
||||
|
|
@ -40,7 +48,7 @@ DashboardFrame::DashboardFrame(const QString& strName, QWidget *parent)
|
|||
connect(m_pDateTimeWidget, SIGNAL(viewHistoricalData(QDateTime)), this, SLOT(onSignal_viewHistoricalData(QDateTime)));
|
||||
|
||||
m_pDashboardTabBar = new CustomTabBar(this);
|
||||
m_pDashboardTabBar->setObjectName(strName + "_tabBar");
|
||||
m_pDashboardTabBar->setFrame(this);
|
||||
ui->hLayout_dashboardTabBar->addWidget(m_pDashboardTabBar);
|
||||
connect(m_pDashboardTabBar, SIGNAL(tabMoved(int, int)), this, SLOT(onSignal_dashboardTabMoved(int, int)));
|
||||
|
||||
|
|
@ -55,22 +63,6 @@ DashboardFrame::~DashboardFrame()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
CustomTabBar* DashboardFrame::tabBar()
|
||||
{
|
||||
return m_pDashboardTabBar;
|
||||
}
|
||||
|
||||
void DashboardFrame::setType(dashboardFrame::frameType type)
|
||||
{
|
||||
if(type == dashboardFrame::ft_secondary) //只有主window具有报警提示
|
||||
{
|
||||
ui->btnEventNotication->setVisible(false);
|
||||
ui->btnAlarmNoticatio->setVisible(false);
|
||||
}
|
||||
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
bool DashboardFrame::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
QDialog *pDialog = qobject_cast<QDialog*>(obj);
|
||||
|
|
@ -91,7 +83,7 @@ bool DashboardFrame::eventFilter(QObject* obj, QEvent* event)
|
|||
void DashboardFrame::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
const QMimeData* mimeData = event->mimeData();
|
||||
if( mimeData->hasFormat("dragData/cutomTab") )
|
||||
if( mimeData->hasFormat("dragData/customTab") )
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
//qDebug() << "dragEnterEvent-frame";
|
||||
|
|
@ -109,15 +101,32 @@ void DashboardFrame::dropEvent(QDropEvent* event)
|
|||
event->setDropAction(Qt::MoveAction);
|
||||
event->accept();
|
||||
|
||||
QByteArray itemData = event->mimeData()->data("dragData/cutomTab");
|
||||
QByteArray itemData = event->mimeData()->data("dragData/customTab");
|
||||
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
|
||||
QString strTabText = "";
|
||||
QString strFromBar = "";
|
||||
dataStream >> strTabText >> strFromBar;
|
||||
QString strFromFrame = "";
|
||||
dataStream >> strTabText >> strFromFrame;
|
||||
|
||||
if(strFromBar != m_pDashboardTabBar->objectName()) //来自别的frame
|
||||
if(strFromFrame != this->objectName()) //来自别的frame
|
||||
{
|
||||
for(int n=0; n<m_listDashboard.count(); n++)
|
||||
{
|
||||
if(m_listDashboard.at(n)->name() == strTabText)
|
||||
{
|
||||
QString strError = QString::fromStdWString(L"已存在同名看板");
|
||||
showTransparentMask();
|
||||
showMessageDialog(type_warning, QString::fromWCharArray(L"错误"), strError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DashboardFrame* fromFrame = getDashboardFrame(strFromFrame);
|
||||
if(fromFrame != this && fromFrame != nullptr)
|
||||
{
|
||||
Dashboard* dashboard = fromFrame->takeDashboard(strTabText);
|
||||
addDashboard(dashboard);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -183,6 +192,10 @@ void DashboardFrame::addDashboard(const QString& strName)
|
|||
// dashboard->setActive(true);
|
||||
// m_curActiveDashboard = dashboard;
|
||||
}
|
||||
void DashboardFrame::addDashboard(Dashboard* dashboard)
|
||||
{
|
||||
insertDashboard(m_listDashboard.count(), dashboard);
|
||||
}
|
||||
void DashboardFrame::insertDashboard(int index, Dashboard* dashboard)
|
||||
{
|
||||
if(index < 0)
|
||||
|
|
@ -206,6 +219,54 @@ void DashboardFrame::insertDashboard(int index, Dashboard* dashboard)
|
|||
dashboard->setActive(true);
|
||||
m_curActiveDashboard = dashboard;
|
||||
}
|
||||
int DashboardFrame::dashboardCount()
|
||||
{
|
||||
return m_listDashboard.count();
|
||||
}
|
||||
|
||||
Dashboard* DashboardFrame::getDashboard(const QString& strName)
|
||||
{
|
||||
Dashboard* dashboard = nullptr;
|
||||
for(int n=0; n<m_listDashboard.count(); n++)
|
||||
{
|
||||
if(m_listDashboard.at(n)->name() == strName)
|
||||
{
|
||||
dashboard = m_listDashboard.at(n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dashboard;
|
||||
}
|
||||
Dashboard* DashboardFrame::takeDashboard(const QString& strName)
|
||||
{
|
||||
Dashboard* dashboard = getDashboard(strName);
|
||||
dashboard->setParent(nullptr);
|
||||
if(dashboard)
|
||||
removeDashboard(strName, false);
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
DashboardFrame* DashboardFrame::getDashboardFrame(const QString& strName)
|
||||
{
|
||||
DashboardFrame* frame = nullptr;
|
||||
if(strName == m_strName)
|
||||
frame = this;
|
||||
|
||||
if(m_type == dashboardFrame::ft_main)
|
||||
{
|
||||
DvieMainWindow* dvieWindow = qobject_cast<DvieMainWindow*>(m_pParentWindow);
|
||||
if(dvieWindow)
|
||||
frame = dvieWindow->getDashboardFrame(strName);
|
||||
}
|
||||
else if(m_type == dashboardFrame::ft_secondary)
|
||||
{
|
||||
DvieSecondaryWindow* dvieWindow = qobject_cast<DvieSecondaryWindow*>(m_pParentWindow);
|
||||
if(dvieWindow)
|
||||
frame = dvieWindow->getDashboardFrame(strName);
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
void DashboardFrame::removeDashboard(const QString& strName, bool bDelete) //右键删除和移动到别的frame下均会调用该函数,只有删除时才会delete
|
||||
{
|
||||
|
|
@ -213,7 +274,7 @@ void DashboardFrame::removeDashboard(const QString& strName, bool bDelete) //右
|
|||
Dashboard* dashboard = nullptr;
|
||||
for(int n=0; n<m_listDashboard.count(); n++)
|
||||
{
|
||||
if(m_listDashboard.at(n)->getName() == strName)
|
||||
if(m_listDashboard.at(n)->name() == strName)
|
||||
{
|
||||
nIndex = n;
|
||||
dashboard = m_listDashboard.at(n);
|
||||
|
|
@ -256,13 +317,20 @@ void DashboardFrame::removeDashboard(const QString& strName, bool bDelete) //右
|
|||
{
|
||||
dashboard->disconnect(this); //断开和当前frame的信号/槽链接
|
||||
}
|
||||
|
||||
if(m_type == dashboardFrame::ft_secondary && m_listDashboard.count() == 0)
|
||||
{
|
||||
DvieSecondaryWindow* dvieWindow = qobject_cast<DvieSecondaryWindow*>(m_pParentWindow);
|
||||
if(dvieWindow)
|
||||
dvieWindow->close();
|
||||
}
|
||||
}
|
||||
|
||||
void DashboardFrame::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)->name() == strName)
|
||||
{
|
||||
if(m_listDashboard.at(n) == m_curActiveDashboard)
|
||||
return;
|
||||
|
|
@ -276,6 +344,30 @@ void DashboardFrame::setCurrentDashboard(const QString& strName)
|
|||
}
|
||||
}
|
||||
|
||||
void DashboardFrame::moveDashboardToNewDVIEWindow(const QString& strDashboard, QPoint pos)
|
||||
{
|
||||
Dashboard* dashboard = takeDashboard(strDashboard);
|
||||
if(dashboard)
|
||||
{
|
||||
if(m_type == dashboardFrame::ft_main)
|
||||
{
|
||||
DvieMainWindow* dvieWindow = qobject_cast<DvieMainWindow*>(m_pParentWindow);
|
||||
if(dvieWindow)
|
||||
dvieWindow->creatSecondaryWindowAndAddDashboard(pos, dashboard);
|
||||
}
|
||||
else if(m_type == dashboardFrame::ft_secondary)
|
||||
{
|
||||
DvieSecondaryWindow* dvieWindow = qobject_cast<DvieSecondaryWindow*>(m_pParentWindow);
|
||||
if(dvieWindow)
|
||||
{
|
||||
dvieWindow->creatSecondaryWindowAndAddDashboard(pos, dashboard);
|
||||
// if(m_listDashboard.count() == 0)
|
||||
// dvieWindow->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DashboardFrame::onSignal_showMask()
|
||||
{
|
||||
showTransparentMask();
|
||||
|
|
@ -353,7 +445,7 @@ void DashboardFrame::onBtnClicked_dashboardList()
|
|||
"}\n");
|
||||
for(int n=0; n<m_listDashboard.count(); n++)
|
||||
{
|
||||
menu.addAction(m_listDashboard.at(n)->getName(), this, SLOT(onMenuAction_dashboardList()));
|
||||
menu.addAction(m_listDashboard.at(n)->name(), this, SLOT(onMenuAction_dashboardList()));
|
||||
}
|
||||
|
||||
QPoint originPoint = ui->btnDashboradList2->mapToGlobal(QPoint(0, 0));
|
||||
|
|
@ -386,7 +478,7 @@ void DashboardFrame::onSignal_dashboardNaming(const QString& strName, const QStr
|
|||
{
|
||||
for(int n=0; n<m_listDashboard.count(); n++)
|
||||
{
|
||||
if(m_listDashboard.at(n)->getName() == strName)
|
||||
if(m_listDashboard.at(n)->name() == strName)
|
||||
{
|
||||
QString strError = QString::fromStdWString(L"已存在同名看板");
|
||||
m_pDashboardNamingDialog->showErrorInfo(strError);
|
||||
|
|
@ -415,7 +507,7 @@ void DashboardFrame::onSignal_removeDashboard()
|
|||
if(dashboard)
|
||||
{
|
||||
showTransparentMask();
|
||||
QString strName = dashboard->getName();
|
||||
QString strName = dashboard->name();
|
||||
QString strMsg = QString::fromStdWString(L"确认删除名为 \"") + strName + QString::fromStdWString(L"\" 的数据看板吗?");
|
||||
showMessageDialog(type_question, QString::fromStdWString(L"删除看板"), strMsg);
|
||||
if(g_msgDlgBtn == btn_No)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include "dvieMainWindow.h"
|
||||
#include "./ui_dvieMainWindow.h"
|
||||
#include "dashboardFrame.h"
|
||||
#include "dvieSecondaryWindow.h"
|
||||
#include <QDateTime>
|
||||
|
||||
DvieMainWindow::DvieMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
|
|
@ -11,8 +13,7 @@ DvieMainWindow::DvieMainWindow(QWidget *parent)
|
|||
ui->setupUi(this);
|
||||
setProperty("windowType", "main");
|
||||
|
||||
m_pDashboardFrame = new DashboardFrame("mainDvie", this);
|
||||
m_pDashboardFrame->setType(dashboardFrame::ft_main);
|
||||
m_pDashboardFrame = new DashboardFrame("mainDVIE_dashboardFrame", dashboardFrame::ft_main, this);
|
||||
ui->centralLayout->addWidget(m_pDashboardFrame);
|
||||
}
|
||||
|
||||
|
|
@ -21,3 +22,47 @@ DvieMainWindow::~DvieMainWindow()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
DashboardFrame* DvieMainWindow::dashboardFrame()
|
||||
{
|
||||
return m_pDashboardFrame;
|
||||
}
|
||||
DashboardFrame* DvieMainWindow::getDashboardFrame(const QString& strName)
|
||||
{
|
||||
DashboardFrame* frame = nullptr;
|
||||
if(m_pDashboardFrame->objectName() == strName)
|
||||
frame = m_pDashboardFrame;
|
||||
else
|
||||
{
|
||||
int nIndex = strName.indexOf("_dashboardFrame");
|
||||
if(nIndex != -1)
|
||||
{
|
||||
QString strDVIEWindowName = strName.left(nIndex);
|
||||
qDebug() << strDVIEWindowName;
|
||||
auto itr = m_hashSecondaryWindow.find(strDVIEWindowName);
|
||||
if(itr != m_hashSecondaryWindow.end())
|
||||
frame = itr.value()->dashboardFrame();
|
||||
}
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
void DvieMainWindow::creatSecondaryWindowAndAddDashboard(QPoint pos, Dashboard* dashboard)
|
||||
{
|
||||
QString strName = "secondaryDVIE_" + QDateTime::currentDateTime().toString("yyMMdd-HHmmss");
|
||||
DvieSecondaryWindow* secondartWindow = new DvieSecondaryWindow(strName, this);
|
||||
if(secondartWindow->dashboardFrame())
|
||||
secondartWindow->dashboardFrame()->addDashboard(dashboard);
|
||||
secondartWindow->setMainWindow(this);
|
||||
secondartWindow->move(pos);
|
||||
secondartWindow->show();
|
||||
m_hashSecondaryWindow.insert(strName, secondartWindow);
|
||||
//qDebug() << m_hashSecondaryWindow.count();
|
||||
}
|
||||
void DvieMainWindow::removeSecondartWindow(QString& strName)
|
||||
{
|
||||
DvieSecondaryWindow* secondartWindow = m_hashSecondaryWindow.take(strName);
|
||||
if(secondartWindow)
|
||||
secondartWindow->deleteLater(); //不要直接delete,因为后续还需要该对象做一些其它工作
|
||||
//qDebug() << m_hashSecondaryWindow.count();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
#include "dvieSecondaryWindow.h"
|
||||
#include "./ui_dvieSecondaryWindow.h"
|
||||
#include "dvieMainWindow.h"
|
||||
#include "dashboardFrame.h"
|
||||
#include <QCloseEvent>
|
||||
|
||||
DvieSecondaryWindow::DvieSecondaryWindow(const QString& strName, QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::dvieSecondaryWindow)
|
||||
, m_pMainWindow(nullptr)
|
||||
, m_pDashboardFrame(nullptr)
|
||||
|
||||
{
|
||||
|
|
@ -13,9 +16,8 @@ DvieSecondaryWindow::DvieSecondaryWindow(const QString& strName, QWidget *parent
|
|||
|
||||
m_strName = strName;
|
||||
|
||||
QString strDashboard = strName + "_dashboard";
|
||||
m_pDashboardFrame = new DashboardFrame(strDashboard, this);
|
||||
m_pDashboardFrame->setType(dashboardFrame::ft_secondary);
|
||||
QString strDashboard = strName + "_dashboardFrame";
|
||||
m_pDashboardFrame = new DashboardFrame(strDashboard, dashboardFrame::ft_secondary, this);
|
||||
ui->centralLayout->addWidget(m_pDashboardFrame);
|
||||
}
|
||||
|
||||
|
|
@ -23,3 +25,41 @@ DvieSecondaryWindow::~DvieSecondaryWindow()
|
|||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DvieSecondaryWindow::closeEvent(QCloseEvent* e)
|
||||
{
|
||||
if(m_pMainWindow)
|
||||
m_pMainWindow->removeSecondartWindow(m_strName);
|
||||
else
|
||||
QMainWindow::closeEvent(e);
|
||||
}
|
||||
|
||||
QString DvieSecondaryWindow::name()
|
||||
{
|
||||
return m_strName;
|
||||
}
|
||||
|
||||
DashboardFrame* DvieSecondaryWindow::dashboardFrame()
|
||||
{
|
||||
return m_pDashboardFrame;
|
||||
}
|
||||
|
||||
DashboardFrame* DvieSecondaryWindow::getDashboardFrame(const QString& strName)
|
||||
{
|
||||
if(m_pMainWindow)
|
||||
return m_pMainWindow->getDashboardFrame(strName);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DvieSecondaryWindow::setMainWindow(DvieMainWindow* mainWindow)
|
||||
{
|
||||
m_pMainWindow = mainWindow;
|
||||
}
|
||||
|
||||
void DvieSecondaryWindow::creatSecondaryWindowAndAddDashboard(QPoint pos, Dashboard* dashboard)
|
||||
{
|
||||
if(m_pMainWindow)
|
||||
m_pMainWindow->creatSecondaryWindowAndAddDashboard(pos, dashboard);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1544</width>
|
||||
<height>956</height>
|
||||
<width>998</width>
|
||||
<height>607</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
|
|
|||
Loading…
Reference in New Issue