Skip to content

Commit

Permalink
[GRASS] editing: polygon to boundary, set cat, refresh after commit
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Sep 18, 2015
1 parent a1b05a1 commit 407d374
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/providers/grass/qgsgrassfeatureiterator.cpp
Expand Up @@ -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
Expand Down
42 changes: 37 additions & 5 deletions src/providers/grass/qgsgrassprovider.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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() );
}
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/providers/grass/qgsgrassvectormap.cpp
Expand Up @@ -341,6 +341,7 @@ bool QgsGrassVectorMap::closeEdit( bool newMap )

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

Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -447,6 +457,7 @@ void QgsGrassVectorMap::update()
closeAllIterators(); // blocking
closeMap();
openMap();
reloadLayers();
unlockOpenClose();
}

Expand Down
3 changes: 3 additions & 0 deletions src/providers/grass/qgsgrassvectormap.h
Expand Up @@ -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 );

Expand Down

0 comments on commit 407d374

Please sign in to comment.