Skip to content
Permalink
Browse files

Fixes #17574 Add Z support in AddCircularString map tools

  • Loading branch information
pblottiere committed Feb 16, 2018
1 parent 45ca0eb commit 7a698f234d4850c21fb4e432570fd81a2dc0836b
@@ -102,6 +102,19 @@ convenient method to clean members

int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );

QgsPoint pointFromPointXY( const QgsPointXY &point ) const;
%Docstring
Creates a QgsPoint with ZM support if necessary (according to the
WkbType of the current layer) from a QgsPointXY.

\param point A QgsPointXY to convert

:return: a point if ZM support if necessary

.. versionadded:: 3.0
:rtype: QgsPoint
%End

int addVertex( const QgsPointXY &point );

int addVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match &match );
@@ -29,7 +29,7 @@ QgsMapToolCircularStringCurvePoint::QgsMapToolCircularStringCurvePoint( QgsMapTo

void QgsMapToolCircularStringCurvePoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint( e->mapPoint() );
QgsPoint mapPoint = pointFromPointXY( e->mapPoint() );

if ( e->button() == Qt::LeftButton )
{
@@ -43,7 +43,7 @@ void QgsMapToolCircularStringRadius::deactivate()

void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsPoint mapPoint( e->mapPoint() );
QgsPoint mapPoint = pointFromPointXY( e->mapPoint() );

if ( e->button() == Qt::LeftButton )
{
@@ -55,7 +55,7 @@ void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent *e
{
if ( mPoints.size() % 2 )
{
mTemporaryEndPoint = mapPoint;
mTemporaryEndPoint = pointFromPointXY( mapPoint );

//initial radius is distance( tempPoint - mPoints.last ) / 2.0
double minRadius = std::sqrt( QgsGeometryUtils::sqrDistance2D( mPoints.last(), mTemporaryEndPoint ) ) / 2.0;
@@ -136,7 +136,7 @@ void QgsMapToolCircularStringRadius::recalculateTempRubberBand( const QgsPointXY
else
{
rubberBandPoints.append( mPoints.last() );
rubberBandPoints.append( QgsPoint( mousePosition ) );
rubberBandPoints.append( pointFromPointXY( mousePosition ) );
}
QgsCircularString *cString = new QgsCircularString();
cString->setPoints( rubberBandPoints );
@@ -604,6 +604,24 @@ bool QgsGeometryUtils::segmentMidPoint( const QgsPoint &p1, const QgsPoint &p2,
}

result = possibleMidPoints.at( minDistIndex );

// add z support if necessary
if ( p1.is3D() && p2.is3D() )
{
result.convertTo( p1.wkbType() );
result.setZ( ( p1.z() + p2.z() ) / 2. );
}
else if ( p1.is3D() && !p2.is3D() )
{
result.convertTo( p1.wkbType() );
result.setZ( p1.z() );
}
else if ( !p1.is3D() && p2.is3D() )
{
result.convertTo( p2.wkbType() );
result.setZ( p2.z() );
}

return true;
}

@@ -768,3 +768,48 @@ void QgsMapToolCapture::setPoints( const QVector<QgsPointXY> &pointList )
mSnappingMatches.append( QgsPointLocator::Match() );
}

QgsPoint QgsMapToolCapture::pointFromPointXY( const QgsPointXY &point ) const
{
QgsPoint newPoint( QgsWkbTypes::Point, point.x(), point.y() );

// get current layer
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
return newPoint;
}

// convert to the corresponding type for a full ZM support
QgsWkbTypes::Type type = vlayer->wkbType();
if ( QgsWkbTypes::hasZ( type ) && !QgsWkbTypes::hasM( type ) )
{
newPoint.convertTo( QgsWkbTypes::PointZ );
}
else if ( !QgsWkbTypes::hasZ( type ) && QgsWkbTypes::hasM( type ) )
{
newPoint.convertTo( QgsWkbTypes::PointM );
}
else if ( QgsWkbTypes::hasZ( type ) && QgsWkbTypes::hasM( type ) )
{
newPoint.convertTo( QgsWkbTypes::PointZM );
}

// set default value for Z if necessary
if ( QgsWkbTypes::hasZ( newPoint.wkbType() ) )
newPoint.setZ( defaultZValue() );

return newPoint;
}

#ifdef Q_OS_WIN
bool QgsMapToolCapture::eventFilter( QObject *obj, QEvent *event )
{
if ( event->type() != QEvent::ContextMenu )
return false;

if ( --mSkipNextContextMenuEvent == 0 )
obj->removeEventFilter( this );

return mSkipNextContextMenuEvent >= 0;
}
#endif
@@ -147,6 +147,18 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
// TODO QGIS 3.0 returns an enum instead of a magic constant
int fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint );

/**
* Creates a QgsPoint with ZM support if necessary (according to the
* WkbType of the current layer) from a QgsPointXY.
*
* \param point A QgsPointXY to convert
*
* \returns a point if ZM support if necessary
*
* \since QGIS 3.0
*/
QgsPoint pointFromPointXY( const QgsPointXY &point ) const;

/**
* Adds a point to the rubber band (in map coordinates) and to the capture list (in layer coordinates)
* \returns 0 in case of success, 1 if current layer is not a vector layer, 2 if coordinate transformation failed

0 comments on commit 7a698f2

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