Skip to content
Permalink
Browse files

Fix layer saving in transaction groups

  • Loading branch information
m-kuhn committed Jan 18, 2016
1 parent 75926f5 commit 433e3b8a37182fba9a404eae5d610f28cc2b03f0
@@ -31,6 +31,18 @@ class QgsTransactionGroup : QObject
*/
bool addLayer( QgsVectorLayer* layer );

/**
* Get the set of layers currently managed by this transaction group.
*
* @return Layer set
*/
QSet<QgsVectorLayer*> layers() const;

/**
* Returns true if any of the layers in this group reports a modification.
*/
bool modified() const;

/**
* Return the connection string used by this transaction group.
* Layers need be compatible when added.
@@ -7066,6 +7066,17 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )

bool res = true;

QString connString = QgsDataSourceURI( vlayer->source() ).connectionInfo();
QString key = vlayer->providerType();

QgsTransactionGroup* tg = mTransactionGroups.find( qMakePair( key, connString ) ).value();

bool isModified = false;

// Assume changes if: a) the layer reports modifications or b) its transaction group was modified
if ( vlayer->isModified() || ( tg && tg->layers().contains( vlayer ) && tg->modified() ) )
isModified = true;

if ( !vlayer->isEditable() && !vlayer->isReadOnly() )
{
if ( !( vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::EditingCapabilities ) )
@@ -7091,7 +7102,7 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
vlayer->triggerRepaint();
}
}
else if ( vlayer->isModified() )
else if ( isModified )
{
QMessageBox::StandardButtons buttons = QMessageBox::Save | QMessageBox::Discard;
if ( allowCancel )
@@ -59,6 +59,21 @@ bool QgsTransactionGroup::addLayer( QgsVectorLayer* layer )
return true;
}

QSet<QgsVectorLayer*> QgsTransactionGroup::layers() const
{
return mLayers;
}

bool QgsTransactionGroup::modified() const
{
Q_FOREACH ( QgsVectorLayer* layer, mLayers )
{
if ( layer->isModified() )
return true;
}
return false;
}

void QgsTransactionGroup::onEditingStarted()
{
if ( !mTransaction.isNull() )
@@ -37,6 +37,18 @@ class CORE_EXPORT QgsTransactionGroup : public QObject
*/
bool addLayer( QgsVectorLayer* layer );

/**
* Get the set of layers currently managed by this transaction group.
*
* @return Layer set
*/
QSet<QgsVectorLayer*> layers() const;

/**
* Returns true if any of the layers in this group reports a modification.
*/
bool modified() const;

/**
* Return the connection string used by this transaction group.
* Layers need be compatible when added.
@@ -378,6 +378,7 @@ struct CORE_EXPORT QgsVectorJoinInfo
*
* Provider to display vector data in a GRASS GIS layer.
*
* TODO QGIS3: Remove virtual from non-inherited methods (like isModified, isReadOnly)
*/


@@ -17,6 +17,17 @@
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"

QgsVectorLayerEditPassthrough::QgsVectorLayerEditPassthrough( QgsVectorLayer* layer )
: mModified( false )
{
L = layer;
}

bool QgsVectorLayerEditPassthrough::isModified() const
{
return mModified;
}

bool QgsVectorLayerEditPassthrough::addFeature( QgsFeature& f )
{

@@ -26,6 +37,7 @@ bool QgsVectorLayerEditPassthrough::addFeature( QgsFeature& f )
{
f = fl.first();
emit featureAdded( f.id() );
mModified = true;
return true;
}
return false;
@@ -39,6 +51,7 @@ bool QgsVectorLayerEditPassthrough::addFeatures( QgsFeatureList& features )
{
emit featureAdded( f.id() );
}
mModified = true;
return true;
}
return false;
@@ -49,6 +62,7 @@ bool QgsVectorLayerEditPassthrough::deleteFeature( QgsFeatureId fid )
if ( L->dataProvider()->deleteFeatures( QgsFeatureIds() << fid ) )
{
emit featureDeleted( fid );
mModified = true;
return true;
}
return false;
@@ -61,6 +75,7 @@ bool QgsVectorLayerEditPassthrough::deleteFeatures( QgsFeatureIds fids )
Q_FOREACH ( QgsFeatureId fid, fids )
emit featureDeleted( fid );

mModified = true;
return true;
}
return false;
@@ -73,6 +88,7 @@ bool QgsVectorLayerEditPassthrough::changeGeometry( QgsFeatureId fid, QgsGeometr
if ( L->dataProvider()->changeGeometryValues( geomMap ) )
{
emit geometryChanged( fid, *geom );
mModified = true;
return true;
}
return false;
@@ -87,6 +103,7 @@ bool QgsVectorLayerEditPassthrough::changeAttributeValue( QgsFeatureId fid, int
if ( L->dataProvider()->changeAttributeValues( attribMap ) )
{
emit attributeValueChanged( fid, field, newValue );
mModified = true;
return true;
}
return false;
@@ -97,6 +114,7 @@ bool QgsVectorLayerEditPassthrough::addAttribute( const QgsField &field )
if ( L->dataProvider()->addAttributes( QList<QgsField>() << field ) )
{
emit attributeAdded( L->dataProvider()->fieldNameIndex( field.name() ) );
mModified = true;
return true;
}
return false;
@@ -106,17 +124,21 @@ bool QgsVectorLayerEditPassthrough::deleteAttribute( int attr )
{
if ( L->dataProvider()->deleteAttributes( QgsAttributeIds() << attr ) )
{
mModified = true;
emit attributeDeleted( attr );
mModified = true;
return true;
}
return false;
}

bool QgsVectorLayerEditPassthrough::commitChanges( QStringList& /*commitErrors*/ )
{
mModified = false;
return true;
}

void QgsVectorLayerEditPassthrough::rollBack()
{
mModified = false;
}
@@ -23,8 +23,8 @@ class CORE_EXPORT QgsVectorLayerEditPassthrough : public QgsVectorLayerEditBuffe
{
Q_OBJECT
public:
QgsVectorLayerEditPassthrough( QgsVectorLayer* layer ) { L = layer; }
bool isModified() const override { return true; }
QgsVectorLayerEditPassthrough( QgsVectorLayer* layer );
bool isModified() const override;
bool addFeature( QgsFeature& f ) override;
bool addFeatures( QgsFeatureList& features ) override;
bool deleteFeature( QgsFeatureId fid ) override;
@@ -36,6 +36,8 @@ class CORE_EXPORT QgsVectorLayerEditPassthrough : public QgsVectorLayerEditBuffe
bool commitChanges( QStringList& commitErrors ) override;
void rollBack() override;

private:
bool mModified;
};

#endif // QGSVECTORLAYEREDITPASSTHROUGH_H
@@ -285,14 +285,21 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! return list of layers within map canvas.
QList<QgsMapLayer*> layers() const;

/** Freeze/thaw the map canvas. This is used to prevent the canvas from
/**
* Freeze/thaw the map canvas. This is used to prevent the canvas from
* responding to events while layers are being added/removed etc.
* @param frz Boolean specifying if the canvas should be frozen (true) or
* thawed (false). Default is true.
*
* TODO remove in QGIS 3
*/
void freeze( bool frz = true );

/** Accessor for frozen status of canvas */
/**
* Accessor for frozen status of canvas
*
* TODO remove in QGIS 3
*/
bool isFrozen();

//! Flag the canvas as dirty and needed a refresh

0 comments on commit 433e3b8

Please sign in to comment.
You can’t perform that action at this time.