Skip to content
Permalink
Browse files

Fix node tool. Change geometry type for memory layer to ..ZM.

  • Loading branch information
alisovenko committed Jan 4, 2017
1 parent 50962b0 commit eb1ab18af8b0f99a24bc6ba022acc46b710e3ef0
@@ -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 )
{
@@ -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 )
@@ -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.
@@ -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 )
@@ -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
@@ -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 )
{
@@ -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
@@ -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();
@@ -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 );
@@ -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;
@@ -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
@@ -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;
}
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>444</width>
<height>293</height>
<height>304</height>
</rect>
</property>
<property name="sizePolicy">
@@ -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>

0 comments on commit eb1ab18

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