Skip to content
Permalink
Browse files

[GRASS] fixed split feature

  • Loading branch information
blazek committed Oct 19, 2015
1 parent 2aa2040 commit 6261a38e0fbfbe98a5ed2b5325c85e5f6aff8a3a
@@ -27,20 +27,6 @@
class QgsGrassEditRenderer : public QgsFeatureRendererV2
{
public:
enum TopoSymbol
{
TopoPoint,
TopoLine,
TopoBoundary0,
TopoBoundary1,
TopoBoundary2,
TopoCentroidIn,
TopoCentroidOut,
TopoCentroidDupl,
TopoNode0,
TopoNode1,
TopoNode2
};

QgsGrassEditRenderer( );

@@ -257,6 +257,8 @@ void QgsGrassPlugin::initGui()
mAddArea = new QgsGrassAddFeature( qGisInterface->mapCanvas(), QgsMapToolAdvancedDigitizing::CapturePolygon );
mAddArea->setAction( mAddAreaAction );

connect( qGisInterface->actionSplitFeatures(), SIGNAL( triggered( bool ) ), SLOT( onSplitFeaturesTriggered( bool ) ) );

// Connect project
QWidget* qgis = qGisInterface->mainWindow();
connect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
@@ -523,6 +525,26 @@ void QgsGrassPlugin::addFeature()
vectorLayer->setFeatureFormSuppress( formSuppress );
}

void QgsGrassPlugin::onSplitFeaturesTriggered( bool checked )
{
QgsDebugMsg( "entered" );
if ( checked )
{
QgsGrassProvider* grassProvider = 0;
QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( qGisInterface->activeLayer() );
if ( vectorLayer )
{
grassProvider = dynamic_cast<QgsGrassProvider*>( vectorLayer->dataProvider() );
}
if ( !grassProvider )
{
QgsDebugMsg( "grassProvider is null" );
return;
}
grassProvider->setNewFeatureType( QgsGrassProvider::LAST_TYPE );
}
}

void QgsGrassPlugin::mapsetChanged()
{
QgsDebugMsg( "entered" );
@@ -126,6 +126,8 @@ class QgsGrassPlugin : public QObject, public QgisPlugin
// Start editing tools
void addFeature();

void onSplitFeaturesTriggered( bool checked );

// Called when new layer was created in browser
void onNewLayer( QString uri, QString name );

@@ -102,6 +102,8 @@ Vect_delete_line_function_type *Vect_delete_line_function_pointer = ( Vect_delet

static QString GRASS_KEY = "grass";

int QgsGrassProvider::LAST_TYPE = -9999;

QgsGrassProvider::QgsGrassProvider( QString uri )
: QgsVectorDataProvider( uri )
, mLayerField( -1 )
@@ -116,6 +118,7 @@ QgsGrassProvider::QgsGrassProvider( QString uri )
, mNewFeatureType( 0 )
, mPoints( 0 )
, mCats( 0 )
, mLastType( 0 )
{
QgsDebugMsg( "uri = " + uri );

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

if ( FID_IS_NEW( fid ) )
{
type = mNewFeatureType == GV_AREA ? GV_BOUNDARY : mNewFeatureType;
if ( mNewFeatureType == QgsGrassProvider::LAST_TYPE )
{
type = mLastType;
QgsDebugMsg( QString( "use mLastType = %1" ).arg( mLastType ) );
}
else
{
type = mNewFeatureType == GV_AREA ? GV_BOUNDARY : mNewFeatureType;
}
// geometry
const QgsAbstractGeometryV2 *geometry = 0;
if ( !mEditBuffer->addedFeatures().contains( fid ) )
@@ -1598,6 +1609,7 @@ void QgsGrassProvider::onGeometryChanged( QgsFeatureId fid, QgsGeometry &geom )
{
return;
}
mLastType = type;

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

public:
static int LAST_TYPE;

QgsGrassProvider( QString uri = QString() );

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

// last geometry GV_* type, used e.g. for splitting features
int mLastType;

friend class QgsGrassFeatureSource;
friend class QgsGrassFeatureIterator;
};

0 comments on commit 6261a38

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