diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 06b626a71..446c1c416 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -48,6 +48,12 @@ #include "version.h" #include "mapplication.h" // Should be last because of definning qApp +#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) +#include "../vmisc/backport/qscopeguard.h" +#else +#include +#endif + #include #include #include @@ -822,17 +828,16 @@ bool TMainWindow::FileSaveAs() QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir + QChar('/') + fName, filters); - auto RemoveTempDir = [usedNotExistedDir, dir]() + auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]() { if (usedNotExistedDir) { QDir(dir).rmpath(QChar('.')); } - }; + }); if (fileName.isEmpty()) { - RemoveTempDir(); return false; } @@ -850,7 +855,6 @@ bool TMainWindow::FileSaveAs() { qCCritical(tMainWindow, "%s", qUtf8Printable(tr("Failed to lock. This file already opened in another window."))); - RemoveTempDir(); return false; } } @@ -876,7 +880,6 @@ bool TMainWindow::FileSaveAs() // Restore previous state m->SetReadOnly(readOnly); mIsReadOnly = readOnly; - RemoveTempDir(); return false; } @@ -892,10 +895,8 @@ bool TMainWindow::FileSaveAs() { qCCritical(tMainWindow, "%s", qUtf8Printable(tr("Failed to lock. This file already opened in another window. " "Expect collissions when run 2 copies of the program."))); - RemoveTempDir(); return false; } - RemoveTempDir(); return true; } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index bac8bf388..1288aad7d 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -2809,18 +2809,17 @@ bool MainWindow::on_actionSaveAs_triggered() #endif ); - auto RemoveTempDir = [usedNotExistedDir, dir]() + auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]() { if (usedNotExistedDir) { QDir directory(dir); directory.rmpath(QChar('.')); } - }; + }); if (fileName.isEmpty()) { - RemoveTempDir(); return false; } @@ -2839,7 +2838,6 @@ bool MainWindow::on_actionSaveAs_triggered() { qCCritical(vMainWindow, "%s", qUtf8Printable(tr("Failed to lock. This file already opened in another window."))); - RemoveTempDir(); return false; } } @@ -2865,7 +2863,6 @@ bool MainWindow::on_actionSaveAs_triggered() doc->SetReadOnly(readOnly); doc->SetModified(wasModified); - RemoveTempDir(); return result; } else if (not oldFilePath.isEmpty()) @@ -2899,7 +2896,6 @@ bool MainWindow::on_actionSaveAs_triggered() "collissions when run 2 copies of the program."))); } - RemoveTempDir(); return result; }