Skip to content

Commit

Permalink
[GRASS] fixed split feature
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 19, 2015
1 parent 2aa2040 commit 6261a38
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
14 changes: 0 additions & 14 deletions src/plugins/grass/qgsgrasseditrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@
class QgsGrassEditRenderer : public QgsFeatureRendererV2
{
public:
enum TopoSymbol
{
TopoPoint,
TopoLine,
TopoBoundary0,
TopoBoundary1,
TopoBoundary2,
TopoCentroidIn,
TopoCentroidOut,
TopoCentroidDupl,
TopoNode0,
TopoNode1,
TopoNode2
};

QgsGrassEditRenderer( );

Expand Down
22 changes: 22 additions & 0 deletions src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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" );
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/grass/qgsgrassplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
18 changes: 16 additions & 2 deletions src/providers/grass/qgsgrassprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -116,6 +118,7 @@ QgsGrassProvider::QgsGrassProvider( QString uri )
, mNewFeatureType( 0 )
, mPoints( 0 )
, mCats( 0 )
, mLastType( 0 )
{
QgsDebugMsg( "uri = " + uri );

Expand Down Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/providers/grass/qgsgrassprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
Q_OBJECT

public:
static int LAST_TYPE;

QgsGrassProvider( QString uri = QString() );

Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit 6261a38

Please sign in to comment.