Skip to content
Permalink
Browse files

[GRASS] editing: polygon to boundary, set cat, refresh after commit

  • Loading branch information
blazek committed Sep 18, 2015
1 parent a1b05a1 commit 407d374f439406f8049a9eb59f33fc2e609c4187
@@ -313,7 +313,9 @@ bool QgsGrassFeatureIterator::fetchFeature( QgsFeature& feature )
cat = 0;
type = 0;
lid = 0;
QgsDebugMsgLevel( QString( "mNextLid = %1 mNextCidx = %2 numLines() = %3" ).arg( mNextLid ).arg( mNextCidx ).arg( mSource->mLayer->map()->numLines() ), 3 );
QgsDebugMsgLevel( QString( "mNextLid = %1 mNextCidx = %2 numLines() = %3 mCidxFieldNumCats = %4" )
.arg( mNextLid ).arg( mNextCidx ).arg( mSource->mLayer->map()->numLines() )
.arg( mSource->mCidxFieldNumCats ), 3 );
if ( mSource->mEditing )
{
// TODO should be numLines before editing started (?), but another layer
@@ -554,7 +554,12 @@ bool QgsGrassProvider::closeEdit( bool newMap )
}

mEditBuffer = 0;
return mLayer->map()->closeEdit( newMap );
if ( mLayer->map()->closeEdit( newMap ) )
{
loadMapInfo();
return true;
}
return false;
}

void QgsGrassProvider::ensureUpdated()
@@ -1318,11 +1323,14 @@ void QgsGrassProvider::setPoints( struct line_pnts *points, const QgsAbstractGeo
const QgsPolygonV2* polygon = dynamic_cast<const QgsPolygonV2*>( geometry );
if ( polygon && polygon->exteriorRing() )
{
QList<QgsPointV2> pointsList;
polygon->exteriorRing()->points( pointsList );
Q_FOREACH ( QgsPointV2 point, pointsList )
QgsLineStringV2* lineString = polygon->exteriorRing()->curveToLine();
if ( lineString )
{
Vect_append_point( points, point.x(), point.y(), point.z() );
for ( int i = 0; i < lineString->numPoints(); i++ )
{
QgsPointV2 point = lineString->pointN( i );
Vect_append_point( points, point.x(), point.y(), point.z() );
}
}
}
}
@@ -1401,6 +1409,18 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
QgsDebugMsg( QString( "unknown type %1" ).arg( wkbType ) );
}

if ( FID_IS_NEW( fid ) )
{
// add new category
if ( wkbType != QgsWKBTypes::Polygon )
{
// TODO: redo of deleted new features - save new cats somewhere,
// resetting fid probably is not possible because it is stored in undo commands and used in buffer maps
int newCat = cidxGetMaxCat( mCidxFieldIndex ) + 1;
QgsDebugMsg( QString( "newCat = %1" ).arg( newCat ) );
Vect_cat_set( cats, mLayerField, newCat );
}
}
if ( cat > 0 )
{
// TODO: orig field, maybe different
@@ -1437,6 +1457,18 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
int idx = mLayer->fields().size() - 1;
QgsFeatureMap & addedFeatures = const_cast<QgsFeatureMap&>( mEditBuffer->addedFeatures() );
addedFeatures[fid].setAttribute( idx, QVariant( symbol ) );

if ( wkbType == QgsWKBTypes::Polygon )
{
// change polygon to linestring
const QgsPolygonV2* polygon = dynamic_cast<const QgsPolygonV2*>( addedFeatures[fid].geometry()->geometry() );
if ( polygon )
{
QgsLineStringV2* lineString = polygon->exteriorRing()->curveToLine();
addedFeatures[fid].setGeometry( new QgsGeometry( lineString ) );
}
// TODO: create also centroid and add it to undo
}
}
}

@@ -341,6 +341,7 @@ bool QgsGrassVectorMap::closeEdit( bool newMap )

closeMap();
openMap();
reloadLayers();
mVersion++;
unlockOpenClose();

@@ -382,6 +383,15 @@ QgsGrassVectorMapLayer * QgsGrassVectorMap::openLayer( int field )
return layer;
}

void QgsGrassVectorMap::reloadLayers()
{
QgsDebugMsg( "entered" );
foreach ( QgsGrassVectorMapLayer *l, mLayers )
{
l->load();
}
}

void QgsGrassVectorMap::closeLayer( QgsGrassVectorMapLayer * layer )
{
if ( !layer || !layer->map() )
@@ -447,6 +457,7 @@ void QgsGrassVectorMap::update()
closeAllIterators(); // blocking
closeMap();
openMap();
reloadLayers();
unlockOpenClose();
}

@@ -97,6 +97,9 @@ class GRASS_LIB_EXPORT QgsGrassVectorMap : public QObject
/** Close GRASS map, no open/close locking */
void closeMap();

/** Reload layers from (reopened) map. The layers keep field/type. */
void reloadLayers();

bool startEdit();
bool closeEdit( bool newMap );

0 comments on commit 407d374

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