|
|
@@ -26,6 +26,7 @@ |
|
|
#include <QActionGroup> |
|
|
#include <QActionGroup> |
|
|
#include <QAbstractSpinBox> |
|
|
#include <QAbstractSpinBox> |
|
|
#include <QApplication> |
|
|
#include <QApplication> |
|
|
|
|
|
#include <QCloseEvent> |
|
|
#include <QEvent> |
|
|
#include <QEvent> |
|
|
#include <QFileDialog> |
|
|
#include <QFileDialog> |
|
|
#include <QGraphicsScene> |
|
|
#include <QGraphicsScene> |
|
|
@@ -315,6 +316,16 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) |
|
|
return QMainWindow::eventFilter(watched, event); |
|
|
return QMainWindow::eventFilter(watched, event); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!confirmSaveBeforeDestructiveAction()) |
|
|
|
|
|
{ |
|
|
|
|
|
event->ignore(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
QMainWindow::closeEvent(event); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const std::string &MainWindow::currentHmiPageId() const |
|
|
const std::string &MainWindow::currentHmiPageId() const |
|
|
{ |
|
|
{ |
|
|
return current_hmi_page_id_; |
|
|
return current_hmi_page_id_; |
|
|
@@ -1035,6 +1046,44 @@ void MainWindow::refreshProjectUi() |
|
|
{ |
|
|
{ |
|
|
project_workspace_controller_->refresh(); |
|
|
project_workspace_controller_->refresh(); |
|
|
updateEditActions(); |
|
|
updateEditActions(); |
|
|
|
|
|
updateWindowTitle(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::updateWindowTitle() |
|
|
|
|
|
{ |
|
|
|
|
|
QString title = tr("综合平台编程器"); |
|
|
|
|
|
if (project_service_.isModified()) |
|
|
|
|
|
{ |
|
|
|
|
|
title += QStringLiteral("*"); |
|
|
|
|
|
} |
|
|
|
|
|
setWindowTitle(title); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool MainWindow::confirmSaveBeforeDestructiveAction() |
|
|
|
|
|
{ |
|
|
|
|
|
if (!project_service_.isModified()) |
|
|
|
|
|
{ |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const QString project_name = fromUtf8(project_service_.project().metadata.name); |
|
|
|
|
|
const QMessageBox::StandardButton choice = QMessageBox::warning( |
|
|
|
|
|
this, |
|
|
|
|
|
tr("工程尚未保存"), |
|
|
|
|
|
tr("工程“%1”有未保存的修改,是否先保存?").arg(project_name), |
|
|
|
|
|
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, |
|
|
|
|
|
QMessageBox::Save); |
|
|
|
|
|
if (choice == QMessageBox::Cancel) |
|
|
|
|
|
{ |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (choice == QMessageBox::Discard) |
|
|
|
|
|
{ |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
saveProject(); |
|
|
|
|
|
return !project_service_.isModified(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void MainWindow::updateProjectTreeActions() |
|
|
void MainWindow::updateProjectTreeActions() |
|
|
@@ -1245,6 +1294,10 @@ void MainWindow::deleteSelectedLogicObject() |
|
|
|
|
|
|
|
|
void MainWindow::createNewProject() |
|
|
void MainWindow::createNewProject() |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (!confirmSaveBeforeDestructiveAction()) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
const QString name = QInputDialog::getText( |
|
|
const QString name = QInputDialog::getText( |
|
|
this, tr("新建工程"), tr("工程名称")); |
|
|
this, tr("新建工程"), tr("工程名称")); |
|
|
if (name.isEmpty()) |
|
|
if (name.isEmpty()) |
|
|
@@ -1273,12 +1326,18 @@ void MainWindow::createNewProject() |
|
|
|
|
|
|
|
|
void MainWindow::saveProject() |
|
|
void MainWindow::saveProject() |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (!project_service_.hasCurrentFile()) |
|
|
|
|
|
{ |
|
|
|
|
|
saveProjectAs(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
const ProjectOperationResult result = project_service_.save(); |
|
|
const ProjectOperationResult result = project_service_.save(); |
|
|
if (!result.succeeded) |
|
|
if (!result.succeeded) |
|
|
{ |
|
|
{ |
|
|
saveProjectAs(); |
|
|
|
|
|
|
|
|
showProjectResult(tr("保存工程"), fromUtf8(result.message), false); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
updateWindowTitle(); |
|
|
showProjectResult(tr("保存工程"), tr("工程已保存"), true); |
|
|
showProjectResult(tr("保存工程"), tr("工程已保存"), true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -1291,6 +1350,10 @@ void MainWindow::saveProjectAs() |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
const ProjectOperationResult result = project_service_.saveAs(toUtf8(path)); |
|
|
const ProjectOperationResult result = project_service_.saveAs(toUtf8(path)); |
|
|
|
|
|
if (result.succeeded) |
|
|
|
|
|
{ |
|
|
|
|
|
updateWindowTitle(); |
|
|
|
|
|
} |
|
|
showProjectResult( |
|
|
showProjectResult( |
|
|
tr("保存工程"), |
|
|
tr("保存工程"), |
|
|
result.succeeded ? tr("工程已保存") : fromUtf8(result.message), |
|
|
result.succeeded ? tr("工程已保存") : fromUtf8(result.message), |
|
|
@@ -1299,6 +1362,10 @@ void MainWindow::saveProjectAs() |
|
|
|
|
|
|
|
|
void MainWindow::loadProject() |
|
|
void MainWindow::loadProject() |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (!confirmSaveBeforeDestructiveAction()) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
const QString path = QFileDialog::getOpenFileName( |
|
|
const QString path = QFileDialog::getOpenFileName( |
|
|
this, tr("加载工程"), {}, tr("工程文件 (*.json)")); |
|
|
this, tr("加载工程"), {}, tr("工程文件 (*.json)")); |
|
|
if (path.isEmpty()) |
|
|
if (path.isEmpty()) |
|
|
|