fix editor create dialog
This commit is contained in:
parent
bb768f474d
commit
343617cf43
|
|
@ -30,6 +30,7 @@ protected:
|
|||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
private:
|
||||
void setupUI();
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ TitleBar::TitleBar(QWidget *parent,bool bClose,bool bMaxMin)
|
|||
)";
|
||||
|
||||
setStyleSheet(style);
|
||||
|
||||
if (m_parentWindow) {
|
||||
m_parentWindow->installEventFilter(this);
|
||||
}
|
||||
}
|
||||
|
||||
void TitleBar::setupUI()
|
||||
|
|
@ -138,3 +142,29 @@ void TitleBar::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
emit maximizeClicked();
|
||||
}
|
||||
}
|
||||
|
||||
bool TitleBar::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == m_parentWindow && event->type() == QEvent::Show) {
|
||||
|
||||
// 防止最大化/全屏时干扰
|
||||
if (m_parentWindow->isMaximized() ||
|
||||
m_parentWindow->isFullScreen()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
if (!screen)
|
||||
return false;
|
||||
|
||||
QRect screenRect = screen->availableGeometry();
|
||||
QRect windowRect = m_parentWindow->geometry(); // ✅ 正确
|
||||
|
||||
int x = screenRect.x() + (screenRect.width() - windowRect.width()) / 2;
|
||||
int y = screenRect.y() + (screenRect.height() - windowRect.height()) / 2;
|
||||
|
||||
m_parentWindow->move(x, y);
|
||||
}
|
||||
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ DiagramCavas::DiagramCavas(QWidget *parent)
|
|||
,_extraPropertyManager(nullptr)
|
||||
{
|
||||
_pageIndex = 0;
|
||||
setViewMode(QMdiArea::TabbedView);
|
||||
}
|
||||
|
||||
DiagramCavas::~DiagramCavas()
|
||||
|
|
|
|||
|
|
@ -8,23 +8,26 @@ namespace Ui { class createEditor; }
|
|||
QT_END_NAMESPACE
|
||||
|
||||
class TitleBar;
|
||||
class DiagramView;
|
||||
|
||||
class CreateEditor : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CreateEditor(QWidget *parent = nullptr);
|
||||
CreateEditor(QWidget *parent = nullptr,DiagramView* p = nullptr);
|
||||
~CreateEditor();
|
||||
|
||||
void initial();
|
||||
void showDlg();
|
||||
|
||||
signals:
|
||||
void projectCreated();
|
||||
public slots:
|
||||
void onOkClicked();
|
||||
void onCancelClicked();
|
||||
private:
|
||||
Ui::createEditor *ui;
|
||||
TitleBar* m_titleBar;
|
||||
DiagramView* m_pView;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ public:
|
|||
|
||||
void initial();
|
||||
void loadTopologyFromDB(); //加载拓扑关系
|
||||
void clearProjectTree();
|
||||
bool projectExist(); //判断工程存在
|
||||
signals:
|
||||
void diagramCreate(DiagramInfo);
|
||||
void diagramChange(DiagramInfo);
|
||||
|
|
|
|||
|
|
@ -4,12 +4,15 @@
|
|||
#include "projectManager.h"
|
||||
#include "ui_createEditor.h"
|
||||
#include "titleBar.h"
|
||||
#include "diagramView.h"
|
||||
|
||||
CreateEditor::CreateEditor(QWidget *parent)
|
||||
CreateEditor::CreateEditor(QWidget *parent,DiagramView* p)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::createEditor)
|
||||
, m_pView(p)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowModality(Qt::ApplicationModal);
|
||||
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
||||
initial();
|
||||
}
|
||||
|
|
@ -37,6 +40,27 @@ void CreateEditor::showDlg()
|
|||
|
||||
void CreateEditor::onOkClicked()
|
||||
{
|
||||
bool val = m_pView->projectExist();
|
||||
if(val){
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QString::fromWCharArray(L"提示"));
|
||||
msgBox.setInformativeText(QString::fromWCharArray(L"该操作将导致未保存数据丢失,是否继续"));
|
||||
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
int ret = msgBox.exec();
|
||||
|
||||
switch (ret) {
|
||||
case QMessageBox::Ok:
|
||||
break;
|
||||
case QMessageBox::Cancel:
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
// should never be reached
|
||||
break;
|
||||
}
|
||||
}
|
||||
emit projectCreated();
|
||||
bool res = ProjectManager::instance().createEditorProject(ui->le_name->text());
|
||||
if(res){
|
||||
QMessageBox::information(NULL, QString("提示"), QString::fromWCharArray(L"项目名已存在"));
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void DiagramView::initial()
|
|||
// 展开所有节点
|
||||
ui->treeView->expandAll();
|
||||
// 显示树视图
|
||||
ui->treeView->setWindowTitle(QObject::tr("组态图结构"));
|
||||
//ui->treeView->setWindowTitle(QObject::tr("组态图结构"));
|
||||
}
|
||||
|
||||
void DiagramView::loadTopologyFromDB()
|
||||
|
|
@ -68,6 +68,21 @@ void DiagramView::loadTopologyFromDB()
|
|||
|
||||
}
|
||||
|
||||
void DiagramView::clearProjectTree()
|
||||
{
|
||||
ui->treeWidget->clear();
|
||||
}
|
||||
|
||||
bool DiagramView::projectExist()
|
||||
{
|
||||
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); ++i) {
|
||||
if (ui->treeWidget->topLevelItem(i)->columnCount() > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DiagramView::onIndexRbtnClicked(const QPoint &pos)
|
||||
{
|
||||
// 获取当前点击的位置对应的索引
|
||||
|
|
@ -339,8 +354,6 @@ void DiagramView::onEditorSaved(const QString& strPro,const QString& autor,QUuid
|
|||
|
||||
void DiagramView::onNewEditorClicked()
|
||||
{
|
||||
ProjectManager::instance().unloadEditorProject(QString());
|
||||
ui->treeWidget->clear();
|
||||
emit createProject();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ LoadPageDlg::LoadPageDlg(QWidget *parent)
|
|||
, ui(new Ui::loadPageDlg)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowModality(Qt::ApplicationModal);
|
||||
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
||||
initial();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -349,11 +349,15 @@ void CMainWindow::onSignal_loadProject()
|
|||
void CMainWindow::onAction_createEditor()
|
||||
{
|
||||
if(m_pCreateEdiotr == nullptr){
|
||||
m_pCreateEdiotr = new CreateEditor(this);
|
||||
m_pCreateEdiotr = new CreateEditor(this,m_pDiagramView);
|
||||
connect(&ProjectManager::instance(),&ProjectManager::createNewEditor,m_pDiagramCavas,&DiagramCavas::onSignal_createEditPanel);
|
||||
connect(&ProjectManager::instance(),&ProjectManager::prepareSaveEditor,m_pDiagramCavas,&DiagramCavas::onSignal_prepareSaveEdit);
|
||||
connect(&ProjectManager::instance(),&ProjectManager::prepareDeleteBaseSetting,m_pDiagramCavas,&DiagramCavas::onSignal_prepareDeleteEditor);
|
||||
connect(&ProjectManager::instance(),&ProjectManager::prepareOpenSetting,m_pDiagramCavas,&DiagramCavas::onSignal_prepareOpenSetting);
|
||||
connect(m_pCreateEdiotr,&CreateEditor::projectCreated,this,[&](){
|
||||
ProjectManager::instance().unloadEditorProject(QString());
|
||||
m_pDiagramView->clearProjectTree();
|
||||
});
|
||||
}
|
||||
|
||||
m_pCreateEdiotr->showDlg();
|
||||
|
|
|
|||
|
|
@ -91,13 +91,7 @@ QTabBar::tab:selected {
|
|||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
<widget class="QTreeWidget" name="treeWidget"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
|
|
|
|||
Loading…
Reference in New Issue