Skip to content

Commit 8b6000b

Browse files
committed
Fix autosync for related features
1 parent 1a91120 commit 8b6000b

File tree

5 files changed

+23
-26
lines changed

5 files changed

+23
-26
lines changed

app/autosynccontroller.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,7 @@ AutosyncController::AutosyncController(
3333
return;
3434
}
3535

36-
// Register for data change of project's vector layers
37-
const QMap<QString, QgsMapLayer *> layers = mQgsProject->mapLayers( true );
38-
for ( const QgsMapLayer *layer : layers )
39-
{
40-
const QgsVectorLayer *vecLayer = qobject_cast<const QgsVectorLayer *>( layer );
41-
if ( vecLayer )
42-
{
43-
if ( !vecLayer->readOnly() )
44-
{
45-
connect( vecLayer, &QgsVectorLayer::afterCommitChanges, this, [&]
46-
{
47-
mLastUpdateTime = QDateTime::currentDateTime();
48-
emit projectSyncRequested( SyncOptions::RequestOrigin::AutomaticRequest );
49-
} );
50-
}
51-
}
52-
}
53-
54-
//every 10 seconds check if last sync was a 60 seconds or more ago and sync if it's true
36+
//every 10 seconds check if last sync was 60 seconds or more ago and sync if it's true
5537
mTimer = std::make_unique<QTimer>( this );
5638
connect( mTimer.get(), &QTimer::timeout, this, [&]
5739
{
@@ -69,6 +51,12 @@ void AutosyncController::updateLastUpdateTime()
6951
mLastUpdateTime = QDateTime::currentDateTime();
7052
}
7153

54+
void AutosyncController::syncLayerChange()
55+
{
56+
mLastUpdateTime = QDateTime::currentDateTime();
57+
emit projectSyncRequested( SyncOptions::RequestOrigin::AutomaticRequest );
58+
}
59+
7260
void AutosyncController::checkSyncRequiredAfterAppStateChange( const Qt::ApplicationState state )
7361
{
7462
if ( state != Qt::ApplicationState::ApplicationActive )

app/autosynccontroller.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class AutosyncController : public QObject
2929
// Set mLastUpdateTime to "now", triggered by manual sync
3030
void updateLastUpdateTime();
3131

32+
// This triggers sync after a change has been saved to layer via attributeController
33+
Q_INVOKABLE void syncLayerChange();
34+
3235
signals:
3336
void projectSyncRequested( SyncOptions::RequestOrigin origin );
3437

app/qml/form/MMFormController.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Item {
3131
property var relationToApply
3232
property var controllerToApply
3333

34-
property alias formState: featureForm.state // add, edit, readOnly or multiEdit
34+
property alias formState: featureForm.state // add, addChild, edit, readOnly or multiEdit
3535
property alias panelState: statesManager.state
3636

3737
property bool layerIsReadOnly: featureLayerPair?.layer?.readOnly ?? false

app/qml/form/MMFormPage.qml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ Page {
7171
},
7272
State {
7373
name: "add"
74+
},
75+
State {
76+
name: "addChild"
7477
}
7578
]
7679

@@ -106,7 +109,7 @@ Page {
106109

107110

108111
title: {
109-
if ( root.state === "add" ) return qsTr( "New feature" )
112+
if ( root.state === "add" || root.state === "addChild" ) return qsTr( "New feature" )
110113
else if ( root.state === "edit" ) return qsTr( "Edit feature" )
111114
else if ( root.state === "multiEdit" ) return qsTr( "Edit selected features" )
112115
return __inputUtils.featureTitle( root.controller.featureLayerPair, __activeProject.qgsProject )
@@ -116,7 +119,7 @@ Page {
116119

117120
anchors.verticalCenter: parent.verticalCenter
118121

119-
visible: root.state === "add" || root.state === "edit" || root.state === "multiEdit"
122+
visible: root.state === "add" || root.state === "edit" || root.state === "multiEdit" || root.state === "addChild"
120123

121124
iconSource: __style.checkmarkIcon
122125
iconColor: controller.hasValidationErrors ? __style.grapeColor : __style.forestColor
@@ -316,7 +319,7 @@ Page {
316319
property var fieldFeatureLayerPair: root.controller.featureLayerPair
317320
property string fieldHomePath: root.project ? root.project.homePath : "" // for photo editor
318321

319-
property bool fieldRememberValueSupported: root.controller.rememberAttributesController.rememberValuesAllowed && root.state === "add" && model.EditorWidget !== "Hidden" && Type === MM.FormItem.Field
322+
property bool fieldRememberValueSupported: root.controller.rememberAttributesController.rememberValuesAllowed && ( root.state === "add" || root.state === "addChild" ) && model.EditorWidget !== "Hidden" && Type === MM.FormItem.Field
320323
property bool fieldRememberValueState: model.RememberValue ? true : false
321324

322325
active: fieldWidget !== 'Hidden'
@@ -433,6 +436,9 @@ Page {
433436

434437
function onChangesCommited() {
435438
root.saved()
439+
if ( root.state !== "addChild" ) {
440+
__activeProject.autosyncController?.syncLayerChange()
441+
}
436442
}
437443

438444
function onCommitFailed() {
@@ -458,10 +464,10 @@ Page {
458464
}
459465

460466
function rollbackAndClose() {
461-
// remove feature if we are in "add" mode and it already has valid ID
467+
// remove feature if we are in "add" or "addChild" mode and it already has valid ID
462468
// it was saved to prefill relation reference field in child layer
463469
let featureId = root.controller.featureLayerPair.feature.id
464-
let shouldRemoveFeature = root.state === "add" && __inputUtils.isFeatureIdValid( featureId )
470+
let shouldRemoveFeature = ( root.state === "add" || root.state === "addChild" ) && __inputUtils.isFeatureIdValid( featureId )
465471

466472
if ( shouldRemoveFeature ) {
467473
root.controller.deleteFeature()

app/qml/form/MMFormStackController.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Item {
167167
function addLinkedFeature( newPair, parentController, relation ) {
168168
let props = {
169169
featureLayerPair: newPair,
170-
formState: "add",
170+
formState: "addChild",
171171
panelState: "form",
172172
parentController: parentController,
173173
linkedRelation: relation

0 commit comments

Comments
 (0)