diff --git a/app/autosynccontroller.cpp b/app/autosynccontroller.cpp index 6416d39e2..63d011d49 100644 --- a/app/autosynccontroller.cpp +++ b/app/autosynccontroller.cpp @@ -42,23 +42,18 @@ AutosyncController::AutosyncController( { if ( !vecLayer->readOnly() ) { - connect( vecLayer, &QgsVectorLayer::afterCommitChanges, this, [&] - { - mLastUpdateTime = QDateTime::currentDateTime(); - emit projectSyncRequested( SyncOptions::RequestOrigin::AutomaticRequest ); - } ); + connect( vecLayer, &QgsVectorLayer::afterCommitChanges, this, &AutosyncController::syncLayerChange ); } } } - //every 10 seconds check if last sync was a 60 seconds or more ago and sync if it's true + //every 10 seconds check if last sync was 60 seconds or more ago and sync if it's true mTimer = std::make_unique( this ); connect( mTimer.get(), &QTimer::timeout, this, [&] { if ( QDateTime::currentDateTime() - mLastUpdateTime >= std::chrono::milliseconds( SYNC_INTERVAL ) ) { - mLastUpdateTime = QDateTime::currentDateTime(); - emit projectSyncRequested( SyncOptions::RequestOrigin::AutomaticRequest ); + syncLayerChange(); } } ); mTimer->start( SYNC_CHECK_TIMEOUT ); @@ -69,6 +64,15 @@ void AutosyncController::updateLastUpdateTime() mLastUpdateTime = QDateTime::currentDateTime(); } +void AutosyncController::syncLayerChange() +{ + if ( !mIsSyncPaused ) + { + mLastUpdateTime = QDateTime::currentDateTime(); + emit projectSyncRequested( SyncOptions::RequestOrigin::AutomaticRequest ); + } +} + void AutosyncController::checkSyncRequiredAfterAppStateChange( const Qt::ApplicationState state ) { if ( state != Qt::ApplicationState::ApplicationActive ) diff --git a/app/autosynccontroller.h b/app/autosynccontroller.h index fc1f3f32a..6d7e8c9c2 100644 --- a/app/autosynccontroller.h +++ b/app/autosynccontroller.h @@ -29,17 +29,26 @@ class AutosyncController : public QObject // Set mLastUpdateTime to "now", triggered by manual sync void updateLastUpdateTime(); + Q_INVOKABLE void setIsSyncPaused( const bool isSyncPaused ) + { + mIsSyncPaused = isSyncPaused; + } + + signals: void projectSyncRequested( SyncOptions::RequestOrigin origin ); public slots: void checkSyncRequiredAfterAppStateChange( Qt::ApplicationState state ); + // This triggers sync after a change has been saved to layer + Q_INVOKABLE void syncLayerChange(); private: QgsProject *mQgsProject = nullptr; // not owned QDateTime mLastUpdateTime; std::unique_ptr mTimer = nullptr; + bool mIsSyncPaused = false; }; #endif // AUTOSYNCCONTROLLER_H diff --git a/app/qml/form/MMFormController.qml b/app/qml/form/MMFormController.qml index b736770cb..c0abccd6d 100644 --- a/app/qml/form/MMFormController.qml +++ b/app/qml/form/MMFormController.qml @@ -40,6 +40,7 @@ Item { property real drawerHeight: drawer.height signal closed() + signal saveRequested() signal editGeometry( var pair ) signal openLinkedFeature( var linkedFeature ) signal createLinkedFeature( var targetLayer, var parentPair ) @@ -79,6 +80,7 @@ Item { StateChangeScript { script: { featureForm.forceActiveFocus() + __activeProject.autosyncController?.setIsSyncPaused(true) } } }, @@ -198,7 +200,10 @@ Item { layerIsReadOnly: root.layerIsReadOnly layerIsSpatial: root.layerIsSpatial - onSaved: drawer.close() + onSaved: { + root.saveRequested() + drawer.close() + } onCanceled: drawer.close() onEditGeometryRequested: function( pair ) { diff --git a/app/qml/form/MMFormPage.qml b/app/qml/form/MMFormPage.qml index 0d804e61b..fe13097ba 100644 --- a/app/qml/form/MMFormPage.qml +++ b/app/qml/form/MMFormPage.qml @@ -471,7 +471,6 @@ Page { // rollback all changes if the layer is still editable root.controller.rollback() - root.canceled() } diff --git a/app/qml/form/MMFormStackController.qml b/app/qml/form/MMFormStackController.qml index 79ddd8f84..bf79856c7 100644 --- a/app/qml/form/MMFormStackController.qml +++ b/app/qml/form/MMFormStackController.qml @@ -255,6 +255,8 @@ Item { StackView { id: formsStack + property bool saveRequested: false + function popOneOrClose() { if ( formsStack.depth > 1 ) { formsStack.pop() @@ -272,6 +274,16 @@ Item { focus: true anchors.fill: parent + + onDepthChanged: { + if (depth === 0) { + __activeProject.autosyncController?.setIsSyncPaused(false) + if (saveRequested) { + __activeProject.autosyncController?.syncLayerChange() + saveRequested = false + } + } + } } Component { @@ -288,6 +300,10 @@ Item { } } + onSaveRequested: { + formsStack.saveRequested = true + } + onPreviewPanelChanged: function( panelHeight ) { root.previewPanelChanged( panelHeight ) } diff --git a/app/test/testmerginapi.cpp b/app/test/testmerginapi.cpp index b066163d5..db56d812a 100644 --- a/app/test/testmerginapi.cpp +++ b/app/test/testmerginapi.cpp @@ -2368,22 +2368,22 @@ void TestMerginApi::testAutosync() // 5. make sure autosync controller triggers that data has changed // - QString projectname = QStringLiteral( "testAutosync" ); - QString projectdir = QDir::tempPath() + "/" + projectname; - QString projectfilename = "quickapp_project.qgs"; + QString projectName = QStringLiteral( "testAutosync" ); + QString projectDir = QDir::tempPath() + "/" + projectName; + QString projectFilename = QStringLiteral( "quickapp_project.qgs" ); - InputUtils::cpDir( TestUtils::testDataDir() + "/planes", projectdir ); + InputUtils::cpDir( TestUtils::testDataDir() + QStringLiteral( "/planes" ), projectDir ); MapThemesModel mtm; AppSettings as; ActiveLayer al; ActiveProject activeProject( as, al, mApi->localProjectsManager() ); - mApi->localProjectsManager().addLocalProject( projectdir, projectname ); + mApi->localProjectsManager().addLocalProject( projectDir, projectName ); as.setAutosyncAllowed( true ); - QVERIFY( activeProject.load( projectdir + "/" + projectfilename ) ); + QVERIFY( activeProject.load( projectDir + QStringLiteral( "/" ) + projectFilename ) ); QVERIFY( activeProject.localProject().isValid() ); QSignalSpy syncSpy( &activeProject, &ActiveProject::syncActiveProject );