Skip to content

Commit 6261a38

Browse files
committedOct 19, 2015
[GRASS] fixed split feature
1 parent 2aa2040 commit 6261a38

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed
 

‎src/plugins/grass/qgsgrasseditrenderer.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,6 @@
2727
class QgsGrassEditRenderer : public QgsFeatureRendererV2
2828
{
2929
public:
30-
enum TopoSymbol
31-
{
32-
TopoPoint,
33-
TopoLine,
34-
TopoBoundary0,
35-
TopoBoundary1,
36-
TopoBoundary2,
37-
TopoCentroidIn,
38-
TopoCentroidOut,
39-
TopoCentroidDupl,
40-
TopoNode0,
41-
TopoNode1,
42-
TopoNode2
43-
};
4430

4531
QgsGrassEditRenderer( );
4632

‎src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ void QgsGrassPlugin::initGui()
257257
mAddArea = new QgsGrassAddFeature( qGisInterface->mapCanvas(), QgsMapToolAdvancedDigitizing::CapturePolygon );
258258
mAddArea->setAction( mAddAreaAction );
259259

260+
connect( qGisInterface->actionSplitFeatures(), SIGNAL( triggered( bool ) ), SLOT( onSplitFeaturesTriggered( bool ) ) );
261+
260262
// Connect project
261263
QWidget* qgis = qGisInterface->mainWindow();
262264
connect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
@@ -523,6 +525,26 @@ void QgsGrassPlugin::addFeature()
523525
vectorLayer->setFeatureFormSuppress( formSuppress );
524526
}
525527

528+
void QgsGrassPlugin::onSplitFeaturesTriggered( bool checked )
529+
{
530+
QgsDebugMsg( "entered" );
531+
if ( checked )
532+
{
533+
QgsGrassProvider* grassProvider = 0;
534+
QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( qGisInterface->activeLayer() );
535+
if ( vectorLayer )
536+
{
537+
grassProvider = dynamic_cast<QgsGrassProvider*>( vectorLayer->dataProvider() );
538+
}
539+
if ( !grassProvider )
540+
{
541+
QgsDebugMsg( "grassProvider is null" );
542+
return;
543+
}
544+
grassProvider->setNewFeatureType( QgsGrassProvider::LAST_TYPE );
545+
}
546+
}
547+
526548
void QgsGrassPlugin::mapsetChanged()
527549
{
528550
QgsDebugMsg( "entered" );

‎src/plugins/grass/qgsgrassplugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
126126
// Start editing tools
127127
void addFeature();
128128

129+
void onSplitFeaturesTriggered( bool checked );
130+
129131
// Called when new layer was created in browser
130132
void onNewLayer( QString uri, QString name );
131133

‎src/providers/grass/qgsgrassprovider.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ Vect_delete_line_function_type *Vect_delete_line_function_pointer = ( Vect_delet
102102

103103
static QString GRASS_KEY = "grass";
104104

105+
int QgsGrassProvider::LAST_TYPE = -9999;
106+
105107
QgsGrassProvider::QgsGrassProvider( QString uri )
106108
: QgsVectorDataProvider( uri )
107109
, mLayerField( -1 )
@@ -116,6 +118,7 @@ QgsGrassProvider::QgsGrassProvider( QString uri )
116118
, mNewFeatureType( 0 )
117119
, mPoints( 0 )
118120
, mCats( 0 )
121+
, mLastType( 0 )
119122
{
120123
QgsDebugMsg( "uri = " + uri );
121124

@@ -1192,7 +1195,15 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
11921195

11931196
if ( FID_IS_NEW( fid ) )
11941197
{
1195-
type = mNewFeatureType == GV_AREA ? GV_BOUNDARY : mNewFeatureType;
1198+
if ( mNewFeatureType == QgsGrassProvider::LAST_TYPE )
1199+
{
1200+
type = mLastType;
1201+
QgsDebugMsg( QString( "use mLastType = %1" ).arg( mLastType ) );
1202+
}
1203+
else
1204+
{
1205+
type = mNewFeatureType == GV_AREA ? GV_BOUNDARY : mNewFeatureType;
1206+
}
11961207
// geometry
11971208
const QgsAbstractGeometryV2 *geometry = 0;
11981209
if ( !mEditBuffer->addedFeatures().contains( fid ) )
@@ -1598,6 +1609,7 @@ void QgsGrassProvider::onGeometryChanged( QgsFeatureId fid, QgsGeometry &geom )
15981609
{
15991610
return;
16001611
}
1612+
mLastType = type;
16011613

16021614
// store only the first original geometry if it is not new feature, changed geometries are stored in the buffer
16031615
if ( oldLid > 0 && !mLayer->map()->oldGeometries().contains( oldLid ) )
@@ -1814,7 +1826,9 @@ void QgsGrassProvider::setAddedFeaturesSymbol()
18141826
}
18151827
QgsDebugMsg( QString( "fid = %1 lid = %2 realLid = %3" ).arg( fid ).arg( lid ).arg( realLid ) );
18161828
QgsGrassVectorMap::TopoSymbol symbol = mLayer->map()->topoSymbol( realLid );
1817-
feature.setAttribute( QgsGrassVectorMap::topoSymbolFieldName(), symbol );
1829+
// the feature may be without fields and set attribute by name does not work
1830+
int index = mLayer->fields().indexFromName( QgsGrassVectorMap::topoSymbolFieldName() );
1831+
feature.setAttribute( index, symbol );
18181832
features[fid] = feature;
18191833
}
18201834
}

‎src/providers/grass/qgsgrassprovider.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
5757
Q_OBJECT
5858

5959
public:
60+
static int LAST_TYPE;
6061

6162
QgsGrassProvider( QString uri = QString() );
6263

@@ -471,6 +472,9 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
471472
struct line_pnts *mPoints;
472473
struct line_cats *mCats;
473474

475+
// last geometry GV_* type, used e.g. for splitting features
476+
int mLastType;
477+
474478
friend class QgsGrassFeatureSource;
475479
friend class QgsGrassFeatureIterator;
476480
};

0 commit comments

Comments
 (0)
Please sign in to comment.