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

This commit is contained in:
alisovenko 2017-01-04 17:11:53 +03:00
parent 50962b02fd
commit eb1ab18af8
13 changed files with 102 additions and 15 deletions

View File

@ -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 )
{

View File

@ -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 )

View File

@ -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.

View File

@ -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 )

View File

@ -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

View File

@ -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 )
{

View File

@ -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

View File

@ -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();

View File

@ -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 );

View File

@ -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;

View File

@ -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

View File

@ -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;
}

View File

@ -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>