Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix node tool. Change geometry type for memory layer to ..ZM.
  • Loading branch information
alisovenko committed Jan 4, 2017
1 parent 50962b0 commit eb1ab18
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -630,7 +630,9 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QgsMapMouseEvent* e )
vlayer->beginEditCommand( tr( "Inserted vertex" ) );

// add vertex
vlayer->insertVertex( layerCoords.x(), layerCoords.y(), mSelectedFeature->featureId(), snapResults.first().afterVertexNr );
QgsPointV2 p( layerCoords.x(), layerCoords.y() );
p.addZValue( defaultZValue() );
vlayer->insertVertex( p, mSelectedFeature->featureId(), snapResults.first().afterVertexNr );

if ( topologicalEditing )
{
Expand Down
26 changes: 26 additions & 0 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -508,6 +508,32 @@ bool QgsGeometry::insertVertex( double x, double y, int beforeVertex )
return d->geometry->insertVertex( id, QgsPointV2( x, y ) );
}

bool QgsGeometry::insertVertex( QgsPointV2& p, int beforeVertex )
{
if ( !d->geometry )
{
return false;
}

//maintain compatibility with < 2.10 API
if ( QgsWkbTypes::flatType( d->geometry->wkbType() ) == QgsWkbTypes::MultiPoint )
{
detach( true );
//insert geometry instead of point
return static_cast< QgsGeometryCollection* >( d->geometry )->insertGeometry( new QgsPointV2( p ), beforeVertex );
}

QgsVertexId id;
if ( !vertexIdFromVertexNr( beforeVertex, id ) )
{
return false;
}

detach( true );

return d->geometry->insertVertex( id, p );
}

QgsPoint QgsGeometry::vertexAt( int atVertex ) const
{
if ( !d->geometry )
Expand Down
13 changes: 13 additions & 0 deletions src/core/geometry/qgsgeometry.h
Expand Up @@ -268,6 +268,19 @@ class CORE_EXPORT QgsGeometry
*/
bool insertVertex( double x, double y, int beforeVertex );

/** Insert a new vertex before the given vertex index,
* ring and item (first number is index 0)
* If the requested vertex number (beforeVertex.back()) is greater
* than the last actual vertex on the requested ring and item,
* it is assumed that the vertex is to be appended instead of inserted.
* Returns false if atVertex does not correspond to a valid vertex
* on this geometry (including if this geometry is a Point).
* It is up to the caller to distinguish between
* these error conditions. (Or maybe we add another method to this
* object to help make the distinction?)
*/
bool insertVertex( QgsPointV2& p, int beforeVertex );

/** Moves the vertex at the given position number
* and item (first number is index 0)
* to the given coordinates.
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1023,6 +1023,19 @@ bool QgsVectorLayer::insertVertex( double x, double y, QgsFeatureId atFeatureId,
}


bool QgsVectorLayer::insertVertex( QgsPointV2& p, QgsFeatureId atFeatureId, int beforeVertex )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
return false;

QgsVectorLayerEditUtils utils( this );
bool result = utils.insertVertex( p, atFeatureId, beforeVertex );
if ( result )
updateExtents();
return result;
}


bool QgsVectorLayer::moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex )
{
if ( !mValid || !mEditBuffer || !mDataProvider )
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -939,6 +939,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );

/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature
* Not meaningful for Point geometries
*/
bool insertVertex( QgsPointV2& p, QgsFeatureId atFeatureId, int beforeVertex );

/** Moves the vertex at the given position number,
* ring and item (first number is index 0), and feature
* to the given coordinates
Expand Down
21 changes: 21 additions & 0 deletions src/core/qgsvectorlayereditutils.cpp
Expand Up @@ -56,6 +56,27 @@ bool QgsVectorLayerEditUtils::insertVertex( double x, double y, QgsFeatureId atF
return true;
}

bool QgsVectorLayerEditUtils::insertVertex( QgsPointV2& p, QgsFeatureId atFeatureId, int beforeVertex )
{
if ( !L->hasGeometryType() )
return false;

QgsGeometry geometry;
if ( !cache()->geometry( atFeatureId, geometry ) )
{
// it's not in cache: let's fetch it from layer
QgsFeature f;
if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( atFeatureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.hasGeometry() )
return false; // geometry not found

geometry = f.geometry();
}

geometry.insertVertex( p, beforeVertex );

L->editBuffer()->changeGeometry( atFeatureId, geometry );
return true;
}

bool QgsVectorLayerEditUtils::moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex )
{
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayereditutils.h
Expand Up @@ -41,6 +41,12 @@ class CORE_EXPORT QgsVectorLayerEditUtils
*/
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );

/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature
* Not meaningful for Point geometries
*/
bool insertVertex( QgsPointV2& p, QgsFeatureId atFeatureId, int beforeVertex );

/** Moves the vertex at the given position number,
* ring and item (first number is index 0), and feature
* to the given coordinates
Expand Down
5 changes: 0 additions & 5 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -611,11 +611,6 @@ void QgsMapToolCapture::deleteTempRubberBand()
}
}

double QgsMapToolCapture::defaultZValue()
{
QSettings().value( QStringLiteral( "/qgis/digitizing/default_z_value" ), Qgis::DEFAULT_Z_COORDINATE ).toDouble();
}

void QgsMapToolCapture::closePolygon()
{
mCaptureCurve.close();
Expand Down
6 changes: 0 additions & 6 deletions src/gui/qgsmaptoolcapture.h
Expand Up @@ -82,12 +82,6 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
*/
void deleteTempRubberBand();

/**
* Return default Z value
* Use for set Z coordinate to new vertex for 2.5d geometries
*/
double defaultZValue();

private slots:
void validationFinished();
void currentLayerChanged( QgsMapLayer *layer );
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmaptooledit.cpp
Expand Up @@ -34,6 +34,11 @@ QgsMapToolEdit::~QgsMapToolEdit()
}


double QgsMapToolEdit::defaultZValue()
{
QSettings().value( QStringLiteral( "/qgis/digitizing/default_z_value" ), Qgis::DEFAULT_Z_COORDINATE ).toDouble();
}

QgsRubberBand* QgsMapToolEdit::createRubberBand( QgsWkbTypes::GeometryType geometryType, bool alternativeBand )
{
QSettings settings;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmaptooledit.h
Expand Up @@ -37,6 +37,12 @@ class GUI_EXPORT QgsMapToolEdit: public QgsMapTool

virtual Flags flags() const override { return QgsMapTool::EditTool; }

/**
* Return default Z value
* Use for set Z coordinate to new vertex for 2.5d geometries
*/
double defaultZValue();

protected:

/** Creates a rubber band with the color/line width from
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsnewmemorylayerdialog.cpp
Expand Up @@ -110,7 +110,7 @@ QgsWkbTypes::Type QgsNewMemoryLayerDialog::selectedType() const
}

if ( mGeometryWithZCheckBox->isChecked() && wkbType != QgsWkbTypes::Unknown && wkbType != QgsWkbTypes::NoGeometry )
wkbType = QgsWkbTypes::zmType( wkbType, true, false );
wkbType = QgsWkbTypes::zmType( wkbType, true, true );

return wkbType;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/qgsnewmemorylayerdialogbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>444</width>
<height>293</height>
<height>304</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -81,7 +81,7 @@
<item>
<widget class="QCheckBox" name="mGeometryWithZCheckBox">
<property name="text">
<string>Geometries with Z coordinate</string>
<string>Geometries with Z/M coordinate</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit eb1ab18

Please sign in to comment.