Skip to content

Commit f51582c

Browse files
YyZz-wyCodeJhF
andauthored
Fix Error problem and enhanced the error message logic (#3163)
Co-authored-by: markffan <markffan@tencent.com>
1 parent ac12903 commit f51582c

File tree

11 files changed

+73
-31
lines changed

11 files changed

+73
-31
lines changed

exporter/assets/qml/AlertError.qml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ PAGWindow {
2727
modality: Qt.ApplicationModal
2828

2929
onClosing: function (closeEvent) {
30-
closeEvent.accepted = true;
30+
closeEvent.accepted = false;
3131
alertWindow.onWindowClosing();
3232
}
3333

@@ -37,10 +37,37 @@ PAGWindow {
3737
}
3838
}
3939

40-
property string errorMessage: typeof alertInfoModel !== 'undefined' && alertInfoModel ? alertInfoModel.errorMessage : ""
40+
property string errorMessage: alertInfoModel ? alertInfoModel.errorMessage : ""
41+
property var alertDataModel: alertInfoModel ? alertInfoModel : null
42+
property string displayErrorText: {
43+
if (errorMessage && errorMessage.length > 0) {
44+
return errorMessage;
45+
}
46+
if (alertDataModel && alertDataModel.count > 0) {
47+
var infos = alertDataModel.getAlertInfos();
48+
var messages = [];
49+
for (var i = 0; i < infos.length; i++) {
50+
if (infos[i].errorInfo) {
51+
messages.push(infos[i].errorInfo);
52+
}
53+
}
54+
return messages.join("\n\n");
55+
}
56+
return "";
57+
}
58+
59+
Connections {
60+
target: alertInfoModel
61+
function onErrorMessageChanged() {
62+
mainWindow.errorMessage = alertInfoModel ? alertInfoModel.errorMessage : ""
63+
}
64+
function onAlertInfoChanged() {
65+
mainWindow.errorMessage = alertInfoModel ? alertInfoModel.errorMessage : ""
66+
}
67+
}
4168

4269
function setErrorMessage(message) {
43-
if (typeof alertInfoModel !== 'undefined' && alertInfoModel) {
70+
if (alertInfoModel) {
4471
alertInfoModel.errorMessage = message;
4572
}
4673
}
@@ -95,7 +122,7 @@ PAGWindow {
95122
id: errorTextArea
96123
anchors.fill: parent
97124
anchors.margins: 15
98-
text: errorMessage
125+
text: displayErrorText
99126
targetListView: null
100127
}
101128
}

exporter/assets/qml/AlertWarning.qml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,8 @@ PAGWindow {
175175
cursorShape: Qt.PointingHandCursor
176176

177177
onClicked: {
178-
if (mainWindow.model) {
179-
alertWindow.continueExport();
180-
mainWindow.close();
181-
}
178+
alertWindow.continueExport();
179+
mainWindow.close();
182180
}
183181
}
184182
}
@@ -208,10 +206,8 @@ PAGWindow {
208206
cursorShape: Qt.PointingHandCursor
209207

210208
onClicked: {
211-
if (mainWindow.model) {
212-
alertWindow.cancelAndModify();
213-
mainWindow.close();
214-
}
209+
alertWindow.cancelAndModify();
210+
mainWindow.close();
215211
}
216212
}
217213
}

exporter/assets/qml/ErrorTextArea.qml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import QtQuick.Controls
33

44
TextArea {
55
id: suggestText
6+
property var targetListView: null
7+
68
renderType: Text.NativeRendering
79
color: "white"
810
verticalAlignment: Text.AlignTop
@@ -27,21 +29,24 @@ TextArea {
2729
property var endPosition: 0
2830
property var isInit: false
2931
property var hasMoved: false
30-
property var targetListView: errorListView
3132
anchors.fill: parent
3233
acceptedButtons: Qt.LeftButton
3334
hoverEnabled: false
3435

3536
onPressed: function (pressed) {
3637
hasMoved = false;
37-
targetListView.interactive = false;
38+
if (suggestText.targetListView) {
39+
suggestText.targetListView.interactive = false;
40+
}
3841
clearSelect();
3942
targetTextArea.forceActiveFocus();
4043
console.log("pressed:" + pressed + ", activeFocus:" + targetTextArea.activeFocus);
4144
}
4245

4346
onReleased: {
44-
targetListView.interactive = true;
47+
if (suggestText.targetListView) {
48+
suggestText.targetListView.interactive = true;
49+
}
4550
isInit = false;
4651
if (!hasMoved) {
4752
return;

exporter/assets/qml/ExportCompositionsProgress.qml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,11 @@ PAGWindow {
132132
exportCompositionsWindow.onWindowClosing();
133133
}
134134
}
135+
136+
Connections {
137+
target: exportCompositionsWindow
138+
onCancelExport: {
139+
window.close();
140+
}
141+
}
135142
}

exporter/assets/qml/PAGListView.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Rectangle {
126126
id: suggestText
127127
text: suggestion
128128
visible: isFold
129+
targetListView: errorListView
129130
anchors.top: mainText.bottom
130131
anchors.left: compIcon.left
131132
anchors.right: root.showLocationBtn ? locationBtn.left : parent.right

exporter/src/export/PAGExport.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ std::shared_ptr<pag::File> PAGExport::exportAsFile() {
290290

291291
if (session->stopExport ||
292292
(session->showAlertInfo && !AlertInfoManager::GetInstance().showAlertInfo())) {
293+
canceled = true;
293294
return nullptr;
294295
}
295296

@@ -322,6 +323,7 @@ std::shared_ptr<pag::File> PAGExport::exportAsFile() {
322323
CheckGraphicsMemory(session, pagFile);
323324

324325
if (session->showAlertInfo && !AlertInfoManager::GetInstance().showAlertInfo()) {
326+
canceled = true;
325327
return nullptr;
326328
}
327329

exporter/src/export/PAGExport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class PAGExport {
4040

4141
bool exportFile();
4242

43+
bool canceled = false;
4344
AEGP_ItemH itemHandle = nullptr;
4445
std::shared_ptr<PAGExportSession> session = nullptr;
4546
ScopedTimeSetter timeSetter = {nullptr, 0};

exporter/src/ui/WindowManager.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,13 @@ WindowManager::WindowManager() {
4747
translator = std::make_unique<QTranslator>();
4848
}
4949

50-
void WindowManager::runEventLoopIfNeeded() {
51-
if (!QCoreApplication::instance()->property("_eventLoopRunning").toBool()) {
52-
QCoreApplication::instance()->setProperty("_eventLoopRunning", true);
53-
app->exec();
54-
QCoreApplication::instance()->setProperty("_eventLoopRunning", false);
55-
}
56-
}
57-
5850
void WindowManager::showExportPanelWindow() {
5951
init();
6052
if (exportPanelWindow == nullptr) {
6153
exportPanelWindow = std::make_unique<ExportPanelWindow>(app.get());
6254
}
6355
exportPanelWindow->show();
64-
runEventLoopIfNeeded();
56+
app->exec();
6557
}
6658

6759
void WindowManager::showPAGConfigWindow() {
@@ -70,7 +62,7 @@ void WindowManager::showPAGConfigWindow() {
7062
configWindow = std::make_unique<ConfigWindow>(app.get());
7163
}
7264
configWindow->show();
73-
runEventLoopIfNeeded();
65+
app->exec();
7466
}
7567

7668
void WindowManager::showExportPreviewWindow() {
@@ -80,7 +72,7 @@ void WindowManager::showExportPreviewWindow() {
8072
previewWindow = std::make_unique<ExportWindow>(app.get(), outputPath);
8173
}
8274
previewWindow->show();
83-
runEventLoopIfNeeded();
75+
app->exec();
8476
}
8577

8678
void WindowManager::showExportWindow() {
@@ -89,7 +81,7 @@ void WindowManager::showExportWindow() {
8981
exportWindow = std::make_unique<ExportWindow>(app.get());
9082
}
9183
exportWindow->show();
92-
runEventLoopIfNeeded();
84+
app->exec();
9385
}
9486

9587
bool WindowManager::showWarnings(const std::vector<AlertInfo>& infos) {
@@ -142,7 +134,6 @@ void WindowManager::initializeQtEnvironment() {
142134
defaultFonts.setStyleHint(QFont::SansSerif);
143135
QApplication::setFont(defaultFonts);
144136
#endif
145-
QApplication::setApplicationName("PAGExporter");
146137
app = std::make_unique<QApplication>(argc, argv);
147138
app->setObjectName("PAG-Exporter");
148139
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);

exporter/src/ui/export/ExportWindow.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,20 @@ std::string ExportWindow::getOutputPath() {
8585
void ExportWindow::init() {
8686
if (QThread::currentThread() != app->thread()) {
8787
qCritical() << "Must call init() in main thread";
88+
onWindowClosing();
8889
return;
8990
}
9091

9192
itemHandle = GetActiveCompositionItem();
9293
if (itemHandle == nullptr) {
94+
onWindowClosing();
9395
return;
9496
}
9597

9698
if (outputPath.empty()) {
9799
outputPath = getOutputPath();
98100
if (outputPath.empty()) {
101+
onWindowClosing();
99102
return;
100103
}
101104
qDebug() << "Select outputPath: " << outputPath.data();

exporter/src/ui/exportPanel/CompositionsModel.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,17 @@ void CompositionsModel::exportSelectedCompositions() {
198198
qDebug() << "Selected compositions: " << pagExports.size();
199199

200200
for (auto& pagExport : pagExports) {
201-
pagExport->session->progressModel.setExportStatus(pagExport->exportFile()
202-
? ProgressModel::ExportStatus::Success
203-
: ProgressModel::ExportStatus::Error);
201+
bool result = pagExport->exportFile();
202+
if (!result) {
203+
pagExport->session->progressModel.setExportStatus(ProgressModel::ExportStatus::Error);
204+
if (pagExport->canceled) {
205+
qDebug() << "cancel export";
206+
Q_EMIT cancelExport();
207+
break;
208+
}
209+
} else {
210+
pagExport->session->progressModel.setExportStatus(ProgressModel::ExportStatus::Success);
211+
}
204212
}
205213
pagExports.clear();
206214
context->setContextProperty("exportCompositionsWindow", nullptr);

0 commit comments

Comments
 (0)