Skip to content

Commit 407d374

Browse files
committedSep 18, 2015
[GRASS] editing: polygon to boundary, set cat, refresh after commit
1 parent a1b05a1 commit 407d374

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed
 

‎src/providers/grass/qgsgrassfeatureiterator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ bool QgsGrassFeatureIterator::fetchFeature( QgsFeature& feature )
313313
cat = 0;
314314
type = 0;
315315
lid = 0;
316-
QgsDebugMsgLevel( QString( "mNextLid = %1 mNextCidx = %2 numLines() = %3" ).arg( mNextLid ).arg( mNextCidx ).arg( mSource->mLayer->map()->numLines() ), 3 );
316+
QgsDebugMsgLevel( QString( "mNextLid = %1 mNextCidx = %2 numLines() = %3 mCidxFieldNumCats = %4" )
317+
.arg( mNextLid ).arg( mNextCidx ).arg( mSource->mLayer->map()->numLines() )
318+
.arg( mSource->mCidxFieldNumCats ), 3 );
317319
if ( mSource->mEditing )
318320
{
319321
// TODO should be numLines before editing started (?), but another layer

‎src/providers/grass/qgsgrassprovider.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,12 @@ bool QgsGrassProvider::closeEdit( bool newMap )
554554
}
555555

556556
mEditBuffer = 0;
557-
return mLayer->map()->closeEdit( newMap );
557+
if ( mLayer->map()->closeEdit( newMap ) )
558+
{
559+
loadMapInfo();
560+
return true;
561+
}
562+
return false;
558563
}
559564

560565
void QgsGrassProvider::ensureUpdated()
@@ -1318,11 +1323,14 @@ void QgsGrassProvider::setPoints( struct line_pnts *points, const QgsAbstractGeo
13181323
const QgsPolygonV2* polygon = dynamic_cast<const QgsPolygonV2*>( geometry );
13191324
if ( polygon && polygon->exteriorRing() )
13201325
{
1321-
QList<QgsPointV2> pointsList;
1322-
polygon->exteriorRing()->points( pointsList );
1323-
Q_FOREACH ( QgsPointV2 point, pointsList )
1326+
QgsLineStringV2* lineString = polygon->exteriorRing()->curveToLine();
1327+
if ( lineString )
13241328
{
1325-
Vect_append_point( points, point.x(), point.y(), point.z() );
1329+
for ( int i = 0; i < lineString->numPoints(); i++ )
1330+
{
1331+
QgsPointV2 point = lineString->pointN( i );
1332+
Vect_append_point( points, point.x(), point.y(), point.z() );
1333+
}
13261334
}
13271335
}
13281336
}
@@ -1401,6 +1409,18 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
14011409
QgsDebugMsg( QString( "unknown type %1" ).arg( wkbType ) );
14021410
}
14031411

1412+
if ( FID_IS_NEW( fid ) )
1413+
{
1414+
// add new category
1415+
if ( wkbType != QgsWKBTypes::Polygon )
1416+
{
1417+
// TODO: redo of deleted new features - save new cats somewhere,
1418+
// resetting fid probably is not possible because it is stored in undo commands and used in buffer maps
1419+
int newCat = cidxGetMaxCat( mCidxFieldIndex ) + 1;
1420+
QgsDebugMsg( QString( "newCat = %1" ).arg( newCat ) );
1421+
Vect_cat_set( cats, mLayerField, newCat );
1422+
}
1423+
}
14041424
if ( cat > 0 )
14051425
{
14061426
// TODO: orig field, maybe different
@@ -1437,6 +1457,18 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
14371457
int idx = mLayer->fields().size() - 1;
14381458
QgsFeatureMap & addedFeatures = const_cast<QgsFeatureMap&>( mEditBuffer->addedFeatures() );
14391459
addedFeatures[fid].setAttribute( idx, QVariant( symbol ) );
1460+
1461+
if ( wkbType == QgsWKBTypes::Polygon )
1462+
{
1463+
// change polygon to linestring
1464+
const QgsPolygonV2* polygon = dynamic_cast<const QgsPolygonV2*>( addedFeatures[fid].geometry()->geometry() );
1465+
if ( polygon )
1466+
{
1467+
QgsLineStringV2* lineString = polygon->exteriorRing()->curveToLine();
1468+
addedFeatures[fid].setGeometry( new QgsGeometry( lineString ) );
1469+
}
1470+
// TODO: create also centroid and add it to undo
1471+
}
14401472
}
14411473
}
14421474

‎src/providers/grass/qgsgrassvectormap.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ bool QgsGrassVectorMap::closeEdit( bool newMap )
341341

342342
closeMap();
343343
openMap();
344+
reloadLayers();
344345
mVersion++;
345346
unlockOpenClose();
346347

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

386+
void QgsGrassVectorMap::reloadLayers()
387+
{
388+
QgsDebugMsg( "entered" );
389+
foreach ( QgsGrassVectorMapLayer *l, mLayers )
390+
{
391+
l->load();
392+
}
393+
}
394+
385395
void QgsGrassVectorMap::closeLayer( QgsGrassVectorMapLayer * layer )
386396
{
387397
if ( !layer || !layer->map() )
@@ -447,6 +457,7 @@ void QgsGrassVectorMap::update()
447457
closeAllIterators(); // blocking
448458
closeMap();
449459
openMap();
460+
reloadLayers();
450461
unlockOpenClose();
451462
}
452463

‎src/providers/grass/qgsgrassvectormap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class GRASS_LIB_EXPORT QgsGrassVectorMap : public QObject
9797
/** Close GRASS map, no open/close locking */
9898
void closeMap();
9999

100+
/** Reload layers from (reopened) map. The layers keep field/type. */
101+
void reloadLayers();
102+
100103
bool startEdit();
101104
bool closeEdit( bool newMap );
102105

0 commit comments

Comments
 (0)
Please sign in to comment.