Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions app/autosynccontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QTimer>( 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 );
Expand All @@ -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 )
Expand Down
9 changes: 9 additions & 0 deletions app/autosynccontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
void syncLayerChange();

private:

QgsProject *mQgsProject = nullptr; // not owned
QDateTime mLastUpdateTime;
std::unique_ptr<QTimer> mTimer = nullptr;
bool mIsSyncPaused = false;
};

#endif // AUTOSYNCCONTROLLER_H
1 change: 1 addition & 0 deletions app/qml/form/MMFormController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Item {
StateChangeScript {
script: {
featureForm.forceActiveFocus()
__activeProject.autosyncController?.setIsSyncPaused(true)
}
}
},
Expand Down
1 change: 0 additions & 1 deletion app/qml/form/MMFormPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ Page {

// rollback all changes if the layer is still editable
root.controller.rollback()

root.canceled()
}

Expand Down
6 changes: 6 additions & 0 deletions app/qml/form/MMFormStackController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ Item {
focus: true

anchors.fill: parent

onDepthChanged: {
if (depth === 0) {
__activeProject.autosyncController?.setIsSyncPaused(false)
}
}
}

Component {
Expand Down
12 changes: 6 additions & 6 deletions app/test/testmerginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Loading