From fcf5c47bd46f85e442631652aec921736861137d Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Sun, 17 Dec 2023 19:09:02 +0200 Subject: [PATCH] Prevent undo/redo history when layer is being tracked --- src/core/featurehistory.cpp | 24 ++++++++++++++++++++++-- src/core/featurehistory.h | 7 ++++++- src/core/qgismobileapp.cpp | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/core/featurehistory.cpp b/src/core/featurehistory.cpp index 550bf60e86..8717ab3439 100644 --- a/src/core/featurehistory.cpp +++ b/src/core/featurehistory.cpp @@ -4,9 +4,11 @@ #include #include +#include -FeatureHistory::FeatureHistory( const QgsProject *project ) +FeatureHistory::FeatureHistory( const QgsProject *project, TrackingModel *trackingModel ) : mProject( project ) + , mTrackingModel( trackingModel ) { connect( mProject, &QgsProject::homePathChanged, this, &FeatureHistory::onHomePathChanged ); connect( mProject, &QgsProject::layersAdded, this, &FeatureHistory::onLayersAdded ); @@ -72,6 +74,12 @@ void FeatureHistory::onBeforeCommitChanges() return; } + Tracker *layerTracker = mTrackingModel->trackerForLayer( vl ); + if ( layerTracker && layerTracker->isActive() ) + { + return; + } + QgsVectorLayerEditBuffer *eb = vl->editBuffer(); if ( !eb ) @@ -117,13 +125,19 @@ void FeatureHistory::onCommittedFeaturesAdded( const QString &localLayerId, cons return; } - const QgsVectorLayer *vl = qobject_cast( sender() ); + QgsVectorLayer *vl = qobject_cast( sender() ); if ( !vl ) { return; } + Tracker *layerTracker = mTrackingModel->trackerForLayer( vl ); + if ( layerTracker && layerTracker->isActive() ) + { + return; + } + qDebug() << "FeatureHistory::onCommittedFeaturesAdded: adding create committed features"; FeatureModifications modifications = mTempHistoryStep.take( vl->id() ); @@ -160,6 +174,12 @@ void FeatureHistory::onAfterCommitChanges() return; } + Tracker *layerTracker = mTrackingModel->trackerForLayer( vl ); + if ( layerTracker && layerTracker->isActive() ) + { + return; + } + const QString layerId = vl->id(); FeatureModifications modifications = mTempHistoryStep.take( layerId ); QMap modifiedFeaturesOld = mTempModifiedFeaturesByLayerId.take( layerId ); diff --git a/src/core/featurehistory.h b/src/core/featurehistory.h index 43c2c898e9..70da756e85 100644 --- a/src/core/featurehistory.h +++ b/src/core/featurehistory.h @@ -5,9 +5,11 @@ #include #include +#include typedef QPair OldNewFeaturePair; + class FeatureHistory : public QObject { Q_OBJECT @@ -34,7 +36,7 @@ class FeatureHistory : public QObject * * @param project */ - explicit FeatureHistory( const QgsProject *project ); + explicit FeatureHistory( const QgsProject *project, TrackingModel *trackingModel ); //! Perform undo of the most recent modification step Q_INVOKABLE bool undo(); @@ -96,6 +98,9 @@ class FeatureHistory : public QObject //! The current project instance. const QgsProject *mProject = nullptr; + //! Tracking model. Used to check if the currently modified layer is in tracking, so all changes should be ignored to prevent cluttering the undo history. + TrackingModel *mTrackingModel = nullptr; + //! If currently applying undo or redo feature modifications. bool mIsApplyingModifications = false; diff --git a/src/core/qgismobileapp.cpp b/src/core/qgismobileapp.cpp index f021c66215..d5fd78d5b7 100644 --- a/src/core/qgismobileapp.cpp +++ b/src/core/qgismobileapp.cpp @@ -269,7 +269,7 @@ QgisMobileapp::QgisMobileapp( QgsApplication *app, QObject *parent ) mTrackingModel = new TrackingModel(); mGpkgFlusher = std::make_unique( mProject ); mLayerObserver = std::make_unique( mProject ); - mFeatureHistory = std::make_unique( mProject ); + mFeatureHistory = std::make_unique( mProject, mTrackingModel ); mFlatLayerTree = new FlatLayerTreeModel( mProject->layerTreeRoot(), mProject, this ); mLegendImageProvider = new LegendImageProvider( mFlatLayerTree->layerTreeModel() ); mLocalFilesImageProvider = new LocalFilesImageProvider();