diff --git a/ChangeLog.txt b/ChangeLog.txt index 39db02f83..14647ee41 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -53,6 +53,7 @@ - Regression in method DialogTool::GetNodeName. - Fix visualization for tool Point from arc and tangent. - Changing settings for move and rotate tools through property browser does not take in count previous change for label point and Show label option. +- Fix locking file after double save as. # Version 0.6.1 October 23, 2018 - [#885] Regression. Broken support for multi size measurements. diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index f7237f00c..06b626a71 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -39,7 +39,6 @@ #include "../ifc/xml/vvitconverter.h" #include "../ifc/xml/vvstconverter.h" #include "../ifc/xml/vpatternconverter.h" -#include "../vmisc/vlockguard.h" #include "../vmisc/vsysexits.h" #include "../vmisc/qxtcsvmodel.h" #include "../vmisc/dialogs/dialogexporttocsv.h" @@ -843,7 +842,7 @@ bool TMainWindow::FileSaveAs() fileName += QChar('.') + suffix; } - if (QFileInfo::exists(fileName)) + if (QFileInfo::exists(fileName) && curFile != fileName) { // Temporary try to lock the file before saving VLockGuard tmp(fileName); @@ -884,6 +883,10 @@ bool TMainWindow::FileSaveAs() UpdatePadlock(false); UpdateWindowTitle(); + if (curFile == fileName && not lock.isNull()) + { + lock->Unlock(); + } VlpCreateLock(lock, fileName); if (not lock->IsLocked()) { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 05bad7bab..35bef80c0 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -141,7 +141,7 @@ private: QComboBox *gradationSizes; QComboBox *comboBoxUnits; int formulaBaseHeight; - std::shared_ptr> lock; + QSharedPointer> lock; QSharedPointer search; QLabel *labelGradationHeights; QLabel *labelGradationSizes; diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index 073a316cb..dcaf81865 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -518,7 +518,7 @@ void VApplication::BeginLogging() { if (lockLog->GetProtected()->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { - out.reset(new QTextStream(lockLog->GetProtected().get())); + out.reset(new QTextStream(lockLog->GetProtected().data())); qInstallMessageHandler(noisyFailureMsgHandler); qCDebug(vApp, "Log file %s was locked.", qUtf8Printable(LogPath())); } diff --git a/src/app/valentina/core/vapplication.h b/src/app/valentina/core/vapplication.h index 423c2dc98..e4d178904 100644 --- a/src/app/valentina/core/vapplication.h +++ b/src/app/valentina/core/vapplication.h @@ -90,7 +90,7 @@ private: VTranslateVars *trVars; QTimer *autoSaveTimer; - std::shared_ptr> lockLog; + QSharedPointer> lockLog; std::shared_ptr out; QString LogDirPath()const; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 4ccf8d572..bac8bf388 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -2830,7 +2830,7 @@ bool MainWindow::on_actionSaveAs_triggered() fileName += QLatin1String(".val"); } - if (f.exists()) + if (f.exists() && qApp->GetPatternPath() != fileName) { // Temporary try to lock the file before saving // Also help to rewite current read-only pattern @@ -2880,6 +2880,10 @@ bool MainWindow::on_actionSaveAs_triggered() patternReadOnly = false; qCDebug(vMainWindow, "Locking file"); + if (qApp->GetPatternPath() == fileName && not lock.isNull()) + { + lock->Unlock(); + } VlpCreateLock(lock, fileName); if (lock->IsLocked()) diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 2533a7ab0..407e81f8e 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -271,7 +271,7 @@ private: VToolOptionsPropertyBrowser *toolOptions; VWidgetGroups *groupsWidget; VWidgetDetails *detailsWidget; - std::shared_ptr> lock; + QSharedPointer> lock; QList toolButtonPointerList; diff --git a/src/libs/vmisc/vlockguard.h b/src/libs/vmisc/vlockguard.h index c38980e25..717d938f5 100644 --- a/src/libs/vmisc/vlockguard.h +++ b/src/libs/vmisc/vlockguard.h @@ -32,12 +32,12 @@ #include #include -#include #include "../vmisc/diagnostic.h" #include #include +#include #if defined(Q_OS_WIN) #include #endif @@ -61,18 +61,19 @@ public: template VLockGuard(const QString& lockName, Alloc a, Delete d, int stale = 0, int timeout=0); - const std::shared_ptr &GetProtected() const; + const QSharedPointer &GetProtected() const; int GetLockError() const; bool IsLocked() const; + void Unlock(); QString GetLockFile() const; private: Q_DISABLE_COPY(VLockGuard) - std::shared_ptr holder; - int lockError; - QString lockFile; - std::shared_ptr lock; + QSharedPointer holder; + int lockError; + QString lockFile; + QSharedPointer lock; // cppcheck-suppress functionStatic bool TryLock(const QString &lockName, int stale, int timeout); @@ -115,23 +116,33 @@ VLockGuard::VLockGuard(const QString& lockName, Alloc a, Delete d, int //--------------------------------------------------------------------------------------------------------------------- template -const std::shared_ptr &VLockGuard::GetProtected() const +inline const QSharedPointer &VLockGuard::GetProtected() const { return holder; } //--------------------------------------------------------------------------------------------------------------------- template -int VLockGuard::GetLockError() const +inline int VLockGuard::GetLockError() const { return lockError; } //--------------------------------------------------------------------------------------------------------------------- template -bool VLockGuard::IsLocked() const +inline bool VLockGuard::IsLocked() const { - return holder != nullptr; + return not holder.isNull(); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +inline void VLockGuard::Unlock() +{ + if (IsLocked()) + { + lock->unlock(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -187,20 +198,20 @@ QT_WARNING_PUSH QT_WARNING_DISABLE_INTEL(1418) template -void VlpCreateLock(std::shared_ptr>& r, const QString& lockName, int stale = 0, int timeout = 0) +void VlpCreateLock(QSharedPointer>& r, const QString& lockName, int stale = 0, int timeout = 0) { r.reset(new VLockGuard(lockName, stale, timeout)); } template -void VlpCreateLock(std::shared_ptr>& r, const QString& lockName, Alloc a, int stale = 0, +void VlpCreateLock(QSharedPointer>& r, const QString& lockName, Alloc a, int stale = 0, int timeout = 0) { r.reset(new VLockGuard(lockName, a, stale, timeout)); } template -void VlpCreateLock(std::shared_ptr>& r, const QString& lockName, Alloc a, Del d, int stale = 0, +void VlpCreateLock(QSharedPointer>& r, const QString& lockName, Alloc a, Del d, int stale = 0, int timeout = 0) { r.reset(new VLockGuard(lockName, a, d, stale, timeout)); diff --git a/src/test/ValentinaTest/tst_vlockguard.cpp b/src/test/ValentinaTest/tst_vlockguard.cpp index 98efacc5b..962ea5884 100644 --- a/src/test/ValentinaTest/tst_vlockguard.cpp +++ b/src/test/ValentinaTest/tst_vlockguard.cpp @@ -42,7 +42,7 @@ TST_VLockGuard::TST_VLockGuard(QObject *parent) void TST_VLockGuard::TryLock() const { QString fileName(QCoreApplication::applicationDirPath() + "/lockFile.txt"); - std::shared_ptr> lock; + QSharedPointer> lock; VlpCreateLock(lock, fileName); fileName = lock->GetLockFile();