Skip to content

Commit 00ea5b4

Browse files
committedOct 2, 2015
[GRASS] keep added features symbol updated
1 parent d054e48 commit 00ea5b4

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed
 

‎src/providers/grass/qgsgrassprovider.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,11 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
13241324
QgsDebugMsg( QString( "newCats[%1] = %2" ).arg( fid ).arg( newCat ) );
13251325
}
13261326
}
1327+
1328+
if ( type == GV_BOUNDARY )
1329+
{
1330+
setAddedFeaturesSymbol();
1331+
}
13271332
}
13281333

13291334
Vect_destroy_line_struct( points );
@@ -1358,9 +1363,12 @@ void QgsGrassProvider::onFeatureDeleted( QgsFeatureId fid )
13581363
}
13591364
}
13601365

1366+
int type = 0;
13611367
mLayer->map()->lockReadWrite();
13621368
G_TRY
13631369
{
1370+
type = Vect_read_line( map(), 0, 0, realLine ); // to know if symbols have to be updated
1371+
13641372
Vect_delete_line( map(), realLine );
13651373
// oldLids are maping to the very first, original version (used by undo)
13661374
int oldestLid = oldLid;
@@ -1377,6 +1385,11 @@ void QgsGrassProvider::onFeatureDeleted( QgsFeatureId fid )
13771385
QgsDebugMsg( QString( "Cannot delete line : %1" ).arg( e.what() ) );
13781386
}
13791387
mLayer->map()->unlockReadWrite();
1388+
1389+
if ( type == GV_BOUNDARY )
1390+
{
1391+
setAddedFeaturesSymbol();
1392+
}
13801393
}
13811394

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

1395-
int type;
1408+
int type = 0;
13961409
G_TRY
13971410
{
13981411
type = Vect_read_line( map(), points, cats, realLine );
@@ -1450,6 +1463,11 @@ void QgsGrassProvider::onGeometryChanged( QgsFeatureId fid, QgsGeometry &geom )
14501463

14511464
Vect_destroy_line_struct( points );
14521465
Vect_destroy_cats_struct( cats );
1466+
1467+
if ( type == GV_BOUNDARY )
1468+
{
1469+
setAddedFeaturesSymbol();
1470+
}
14531471
}
14541472

14551473
void QgsGrassProvider::onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value )
@@ -1536,6 +1554,35 @@ void QgsGrassProvider::onAttributeDeleted( int idx )
15361554
}
15371555
}
15381556

1557+
void QgsGrassProvider::setAddedFeaturesSymbol()
1558+
{
1559+
QgsDebugMsg( "entered" );
1560+
if ( !mEditBuffer )
1561+
{
1562+
return;
1563+
}
1564+
QgsFeatureMap& features = const_cast<QgsFeatureMap&>( mEditBuffer->addedFeatures() );
1565+
Q_FOREACH ( QgsFeatureId fid, features.keys() )
1566+
{
1567+
QgsFeature feature = features[fid];
1568+
if ( !feature.geometry() || !feature.geometry()->geometry() ||
1569+
feature.geometry()->geometry()->wkbType() != QgsWKBTypes::LineString )
1570+
{
1571+
continue;
1572+
}
1573+
int lid = QgsGrassFeatureIterator::lidFromFid( fid );
1574+
int realLid = lid;
1575+
if ( mLayer->map()->newLids().contains( lid ) )
1576+
{
1577+
realLid = mLayer->map()->newLids().value( lid );
1578+
}
1579+
QgsDebugMsg( QString( "fid = %1 lid = %2 realLid = %3" ).arg( fid ).arg( lid ).arg( realLid ) );
1580+
QgsGrassVectorMap::TopoSymbol symbol = mLayer->map()->topoSymbol( realLid );
1581+
feature.setAttribute( QgsGrassVectorMap::topoSymbolFieldName(), symbol );
1582+
features[fid] = feature;
1583+
}
1584+
}
1585+
15391586
void QgsGrassProvider::onUndoIndexChanged( int index )
15401587
{
15411588
Q_UNUSED( index )

‎src/providers/grass/qgsgrassprovider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
404404
struct Map_info * map();
405405
void setMapset();
406406
bool openLayer();
407+
// update topo symbol of new features
408+
void setAddedFeaturesSymbol();
407409

408410
QgsGrassObject mGrassObject;
409411
// field part of layer or -1 if no field specified

0 commit comments

Comments
 (0)
Please sign in to comment.