Skip to content

Commit

Permalink
[GRASS] keep added features symbol updated
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 2, 2015
1 parent d054e48 commit 00ea5b4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/providers/grass/qgsgrassprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,11 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
QgsDebugMsg( QString( "newCats[%1] = %2" ).arg( fid ).arg( newCat ) );
}
}

if ( type == GV_BOUNDARY )
{
setAddedFeaturesSymbol();
}
}

Vect_destroy_line_struct( points );
Expand Down Expand Up @@ -1358,9 +1363,12 @@ void QgsGrassProvider::onFeatureDeleted( QgsFeatureId fid )
}
}

int type = 0;
mLayer->map()->lockReadWrite();
G_TRY
{
type = Vect_read_line( map(), 0, 0, realLine ); // to know if symbols have to be updated

Vect_delete_line( map(), realLine );
// oldLids are maping to the very first, original version (used by undo)
int oldestLid = oldLid;
Expand All @@ -1377,6 +1385,11 @@ void QgsGrassProvider::onFeatureDeleted( QgsFeatureId fid )
QgsDebugMsg( QString( "Cannot delete line : %1" ).arg( e.what() ) );
}
mLayer->map()->unlockReadWrite();

if ( type == GV_BOUNDARY )
{
setAddedFeaturesSymbol();
}
}

void QgsGrassProvider::onGeometryChanged( QgsFeatureId fid, QgsGeometry &geom )
Expand All @@ -1392,7 +1405,7 @@ void QgsGrassProvider::onGeometryChanged( QgsFeatureId fid, QgsGeometry &geom )
struct line_pnts *points = Vect_new_line_struct();
struct line_cats *cats = Vect_new_cats_struct();

int type;
int type = 0;
G_TRY
{
type = Vect_read_line( map(), points, cats, realLine );
Expand Down Expand Up @@ -1450,6 +1463,11 @@ void QgsGrassProvider::onGeometryChanged( QgsFeatureId fid, QgsGeometry &geom )

Vect_destroy_line_struct( points );
Vect_destroy_cats_struct( cats );

if ( type == GV_BOUNDARY )
{
setAddedFeaturesSymbol();
}
}

void QgsGrassProvider::onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value )
Expand Down Expand Up @@ -1536,6 +1554,35 @@ void QgsGrassProvider::onAttributeDeleted( int idx )
}
}

void QgsGrassProvider::setAddedFeaturesSymbol()
{
QgsDebugMsg( "entered" );
if ( !mEditBuffer )
{
return;
}
QgsFeatureMap& features = const_cast<QgsFeatureMap&>( mEditBuffer->addedFeatures() );
Q_FOREACH ( QgsFeatureId fid, features.keys() )
{
QgsFeature feature = features[fid];
if ( !feature.geometry() || !feature.geometry()->geometry() ||
feature.geometry()->geometry()->wkbType() != QgsWKBTypes::LineString )
{
continue;
}
int lid = QgsGrassFeatureIterator::lidFromFid( fid );
int realLid = lid;
if ( mLayer->map()->newLids().contains( lid ) )
{
realLid = mLayer->map()->newLids().value( lid );
}
QgsDebugMsg( QString( "fid = %1 lid = %2 realLid = %3" ).arg( fid ).arg( lid ).arg( realLid ) );
QgsGrassVectorMap::TopoSymbol symbol = mLayer->map()->topoSymbol( realLid );
feature.setAttribute( QgsGrassVectorMap::topoSymbolFieldName(), symbol );
features[fid] = feature;
}
}

void QgsGrassProvider::onUndoIndexChanged( int index )
{
Q_UNUSED( index )
Expand Down
2 changes: 2 additions & 0 deletions src/providers/grass/qgsgrassprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
struct Map_info * map();
void setMapset();
bool openLayer();
// update topo symbol of new features
void setAddedFeaturesSymbol();

QgsGrassObject mGrassObject;
// field part of layer or -1 if no field specified
Expand Down

0 comments on commit 00ea5b4

Please sign in to comment.