Skip to content

Commit eb1ab18

Browse files
committed
Fix node tool. Change geometry type for memory layer to ..ZM.
1 parent 50962b0 commit eb1ab18

13 files changed

+102
-15
lines changed

src/app/nodetool/qgsmaptoolnodetool.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,9 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QgsMapMouseEvent* e )
630630
vlayer->beginEditCommand( tr( "Inserted vertex" ) );
631631

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

635637
if ( topologicalEditing )
636638
{

src/core/geometry/qgsgeometry.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,32 @@ bool QgsGeometry::insertVertex( double x, double y, int beforeVertex )
508508
return d->geometry->insertVertex( id, QgsPointV2( x, y ) );
509509
}
510510

511+
bool QgsGeometry::insertVertex( QgsPointV2& p, int beforeVertex )
512+
{
513+
if ( !d->geometry )
514+
{
515+
return false;
516+
}
517+
518+
//maintain compatibility with < 2.10 API
519+
if ( QgsWkbTypes::flatType( d->geometry->wkbType() ) == QgsWkbTypes::MultiPoint )
520+
{
521+
detach( true );
522+
//insert geometry instead of point
523+
return static_cast< QgsGeometryCollection* >( d->geometry )->insertGeometry( new QgsPointV2( p ), beforeVertex );
524+
}
525+
526+
QgsVertexId id;
527+
if ( !vertexIdFromVertexNr( beforeVertex, id ) )
528+
{
529+
return false;
530+
}
531+
532+
detach( true );
533+
534+
return d->geometry->insertVertex( id, p );
535+
}
536+
511537
QgsPoint QgsGeometry::vertexAt( int atVertex ) const
512538
{
513539
if ( !d->geometry )

src/core/geometry/qgsgeometry.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,19 @@ class CORE_EXPORT QgsGeometry
268268
*/
269269
bool insertVertex( double x, double y, int beforeVertex );
270270

271+
/** Insert a new vertex before the given vertex index,
272+
* ring and item (first number is index 0)
273+
* If the requested vertex number (beforeVertex.back()) is greater
274+
* than the last actual vertex on the requested ring and item,
275+
* it is assumed that the vertex is to be appended instead of inserted.
276+
* Returns false if atVertex does not correspond to a valid vertex
277+
* on this geometry (including if this geometry is a Point).
278+
* It is up to the caller to distinguish between
279+
* these error conditions. (Or maybe we add another method to this
280+
* object to help make the distinction?)
281+
*/
282+
bool insertVertex( QgsPointV2& p, int beforeVertex );
283+
271284
/** Moves the vertex at the given position number
272285
* and item (first number is index 0)
273286
* to the given coordinates.

src/core/qgsvectorlayer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,19 @@ bool QgsVectorLayer::insertVertex( double x, double y, QgsFeatureId atFeatureId,
10231023
}
10241024

10251025

1026+
bool QgsVectorLayer::insertVertex( QgsPointV2& p, QgsFeatureId atFeatureId, int beforeVertex )
1027+
{
1028+
if ( !mValid || !mEditBuffer || !mDataProvider )
1029+
return false;
1030+
1031+
QgsVectorLayerEditUtils utils( this );
1032+
bool result = utils.insertVertex( p, atFeatureId, beforeVertex );
1033+
if ( result )
1034+
updateExtents();
1035+
return result;
1036+
}
1037+
1038+
10261039
bool QgsVectorLayer::moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex )
10271040
{
10281041
if ( !mValid || !mEditBuffer || !mDataProvider )

src/core/qgsvectorlayer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
939939
*/
940940
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );
941941

942+
/** Insert a new vertex before the given vertex number,
943+
* in the given ring, item (first number is index 0), and feature
944+
* Not meaningful for Point geometries
945+
*/
946+
bool insertVertex( QgsPointV2& p, QgsFeatureId atFeatureId, int beforeVertex );
947+
942948
/** Moves the vertex at the given position number,
943949
* ring and item (first number is index 0), and feature
944950
* to the given coordinates

src/core/qgsvectorlayereditutils.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,27 @@ bool QgsVectorLayerEditUtils::insertVertex( double x, double y, QgsFeatureId atF
5656
return true;
5757
}
5858

59+
bool QgsVectorLayerEditUtils::insertVertex( QgsPointV2& p, QgsFeatureId atFeatureId, int beforeVertex )
60+
{
61+
if ( !L->hasGeometryType() )
62+
return false;
63+
64+
QgsGeometry geometry;
65+
if ( !cache()->geometry( atFeatureId, geometry ) )
66+
{
67+
// it's not in cache: let's fetch it from layer
68+
QgsFeature f;
69+
if ( !L->getFeatures( QgsFeatureRequest().setFilterFid( atFeatureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.hasGeometry() )
70+
return false; // geometry not found
71+
72+
geometry = f.geometry();
73+
}
74+
75+
geometry.insertVertex( p, beforeVertex );
76+
77+
L->editBuffer()->changeGeometry( atFeatureId, geometry );
78+
return true;
79+
}
5980

6081
bool QgsVectorLayerEditUtils::moveVertex( double x, double y, QgsFeatureId atFeatureId, int atVertex )
6182
{

src/core/qgsvectorlayereditutils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ class CORE_EXPORT QgsVectorLayerEditUtils
4141
*/
4242
bool insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex );
4343

44+
/** Insert a new vertex before the given vertex number,
45+
* in the given ring, item (first number is index 0), and feature
46+
* Not meaningful for Point geometries
47+
*/
48+
bool insertVertex( QgsPointV2& p, QgsFeatureId atFeatureId, int beforeVertex );
49+
4450
/** Moves the vertex at the given position number,
4551
* ring and item (first number is index 0), and feature
4652
* to the given coordinates

src/gui/qgsmaptoolcapture.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,6 @@ void QgsMapToolCapture::deleteTempRubberBand()
611611
}
612612
}
613613

614-
double QgsMapToolCapture::defaultZValue()
615-
{
616-
QSettings().value( QStringLiteral( "/qgis/digitizing/default_z_value" ), Qgis::DEFAULT_Z_COORDINATE ).toDouble();
617-
}
618-
619614
void QgsMapToolCapture::closePolygon()
620615
{
621616
mCaptureCurve.close();

src/gui/qgsmaptoolcapture.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
8282
*/
8383
void deleteTempRubberBand();
8484

85-
/**
86-
* Return default Z value
87-
* Use for set Z coordinate to new vertex for 2.5d geometries
88-
*/
89-
double defaultZValue();
90-
9185
private slots:
9286
void validationFinished();
9387
void currentLayerChanged( QgsMapLayer *layer );

src/gui/qgsmaptooledit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ QgsMapToolEdit::~QgsMapToolEdit()
3434
}
3535

3636

37+
double QgsMapToolEdit::defaultZValue()
38+
{
39+
QSettings().value( QStringLiteral( "/qgis/digitizing/default_z_value" ), Qgis::DEFAULT_Z_COORDINATE ).toDouble();
40+
}
41+
3742
QgsRubberBand* QgsMapToolEdit::createRubberBand( QgsWkbTypes::GeometryType geometryType, bool alternativeBand )
3843
{
3944
QSettings settings;

src/gui/qgsmaptooledit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ class GUI_EXPORT QgsMapToolEdit: public QgsMapTool
3737

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

40+
/**
41+
* Return default Z value
42+
* Use for set Z coordinate to new vertex for 2.5d geometries
43+
*/
44+
double defaultZValue();
45+
4046
protected:
4147

4248
/** Creates a rubber band with the color/line width from

src/gui/qgsnewmemorylayerdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ QgsWkbTypes::Type QgsNewMemoryLayerDialog::selectedType() const
110110
}
111111

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

115115
return wkbType;
116116
}

src/ui/qgsnewmemorylayerdialogbase.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>444</width>
10-
<height>293</height>
10+
<height>304</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
@@ -81,7 +81,7 @@
8181
<item>
8282
<widget class="QCheckBox" name="mGeometryWithZCheckBox">
8383
<property name="text">
84-
<string>Geometries with Z coordinate</string>
84+
<string>Geometries with Z/M coordinate</string>
8585
</property>
8686
</widget>
8787
</item>

0 commit comments

Comments
 (0)