Skip to content
Permalink
Browse files
Use values from DockWidget instead of snapped ones
  • Loading branch information
lbartoletti authored and nyalldawson committed Sep 12, 2021
1 parent eb809bd commit a5fca0b9a5c073a5546ad2d8ef7b7ee7681d5703
@@ -453,6 +453,20 @@ Can be used to set constraints by external widgets.
unstable API (will likely change)

.. versionadded:: 3.8
%End

double getLineZ( ) const;
%Docstring
Convenient method to get the Z value from the line edit wiget

.. versionadded:: 3.22
%End

double getLineM( ) const;
%Docstring
Convenient method to get the M value from the line edit wiget

.. versionadded:: 3.22
%End

signals:
@@ -864,6 +864,20 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )
point.setZ( QgsMapToolEdit( mMapCanvas ).defaultZValue() );
point.setM( QgsMapToolEdit( mMapCanvas ).defaultMValue() );
}

/*
* And if M or Z lock button is activated get the value of the input.
*/
if ( mLockZButton->isChecked() )
{
point.setZ( mZLineEdit->text().toFloat() );
}
if ( mLockMButton->isChecked() )
{

point.setM( mMLineEdit->text().toFloat() );
}

// update the point list
updateCurrentPoint( point );

@@ -1546,5 +1560,15 @@ QgsPoint QgsAdvancedDigitizingDockWidget::penultimatePoint( bool *exist ) const

QgsPoint QgsAdvancedDigitizingDockWidget::pointXYToPoint( const QgsPointXY &point ) const
{
return QgsPoint( point.x(), point.y(), mZLineEdit->isEnabled() ? mZLineEdit->text().toFloat() : std::numeric_limits<double>::quiet_NaN(), mMLineEdit->isEnabled() ? mMLineEdit->text().toFloat() : std::numeric_limits<double>::quiet_NaN() );
return QgsPoint( point.x(), point.y(), getLineZ(), getLineM() );
}

double QgsAdvancedDigitizingDockWidget::getLineZ( ) const
{
return mZLineEdit->isEnabled() ? mZLineEdit->text().toFloat() : std::numeric_limits<double>::quiet_NaN();
}

double QgsAdvancedDigitizingDockWidget::getLineM( ) const
{
return mMLineEdit->isEnabled() ? mMLineEdit->text().toFloat() : std::numeric_limits<double>::quiet_NaN();
}
@@ -438,6 +438,18 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
*/
void setDistance( const QString &value, WidgetSetMode mode );

/**
* Convenient method to get the Z value from the line edit wiget
* \since QGIS 3.22
*/
double getLineZ( ) const;

/**
* Convenient method to get the M value from the line edit wiget
* \since QGIS 3.22
*/
double getLineM( ) const;

signals:

/**
@@ -486,60 +486,68 @@ int QgsMapToolCapture::fetchLayerPoint( const QgsPointLocator::Match &match, Qgs
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer() );
QgsVectorLayer *sourceLayer = match.layer();
if ( match.isValid() && ( match.hasVertex() || match.hasLineEndpoint() || ( QgsProject::instance()->topologicalEditing() && ( match.hasEdge() || match.hasMiddleSegment() ) ) ) && sourceLayer &&
( sourceLayer->crs() == vlayer->crs() ) )
if ( mCadDockWidget && mCadDockWidget->cadEnabled() )
{
QgsFeature f;
QgsFeatureRequest request;
request.setFilterFid( match.featureId() );
const bool fetched = match.layer()->getFeatures( request ).nextFeature( f );
if ( fetched )
layerPoint = mCadDockWidget->currentPoint();
return 0;
}
else
{
if ( match.isValid() && ( match.hasVertex() || match.hasLineEndpoint() || ( QgsProject::instance()->topologicalEditing() && ( match.hasEdge() || match.hasMiddleSegment() ) ) ) && sourceLayer &&
( sourceLayer->crs() == vlayer->crs() ) )
{
QgsVertexId vId;
if ( !f.geometry().vertexIdFromVertexNr( match.vertexIndex(), vId ) )
return 2;

const QgsGeometry geom( f.geometry() );
if ( QgsProject::instance()->topologicalEditing() && ( match.hasEdge() || match.hasMiddleSegment() ) )
QgsFeature f;
QgsFeatureRequest request;
request.setFilterFid( match.featureId() );
const bool fetched = match.layer()->getFeatures( request ).nextFeature( f );
if ( fetched )
{
QgsVertexId vId2;
if ( !f.geometry().vertexIdFromVertexNr( match.vertexIndex() + 1, vId2 ) )
QgsVertexId vId;
if ( !f.geometry().vertexIdFromVertexNr( match.vertexIndex(), vId ) )
return 2;
const QgsLineString line( geom.constGet()->vertexAt( vId ), geom.constGet()->vertexAt( vId2 ) );

layerPoint = QgsGeometryUtils::closestPoint( line, QgsPoint( match.point() ) );
}
else
{
layerPoint = geom.constGet()->vertexAt( vId );
if ( QgsWkbTypes::hasZ( vlayer->wkbType() ) && !layerPoint.is3D() )
layerPoint.addZValue( mCadDockWidget && mCadDockWidget->cadEnabled() ? mCadDockWidget->currentPoint().z() : defaultZValue() );
if ( QgsWkbTypes::hasM( vlayer->wkbType() ) && !layerPoint.isMeasure() )
layerPoint.addMValue( mCadDockWidget && mCadDockWidget->cadEnabled() ? mCadDockWidget->currentPoint().m() : defaultMValue() );
}
const QgsGeometry geom( f.geometry() );
if ( QgsProject::instance()->topologicalEditing() && ( match.hasEdge() || match.hasMiddleSegment() ) )
{
QgsVertexId vId2;
if ( !f.geometry().vertexIdFromVertexNr( match.vertexIndex() + 1, vId2 ) )
return 2;
const QgsLineString line( geom.constGet()->vertexAt( vId ), geom.constGet()->vertexAt( vId2 ) );

// ZM support depends on the target layer
if ( !QgsWkbTypes::hasZ( vlayer->wkbType() ) )
{
layerPoint.dropZValue();
}
layerPoint = QgsGeometryUtils::closestPoint( line, QgsPoint( match.point() ) );
}
else
{
layerPoint = geom.constGet()->vertexAt( vId );
if ( QgsWkbTypes::hasZ( vlayer->wkbType() ) && !layerPoint.is3D() )
layerPoint.addZValue( defaultZValue() );
if ( QgsWkbTypes::hasM( vlayer->wkbType() ) && !layerPoint.isMeasure() )
layerPoint.addMValue( defaultMValue() );
}

if ( !QgsWkbTypes::hasM( vlayer->wkbType() ) )
// ZM support depends on the target layer
if ( !QgsWkbTypes::hasZ( vlayer->wkbType() ) )
{
layerPoint.dropZValue();
}

if ( !QgsWkbTypes::hasM( vlayer->wkbType() ) )
{
layerPoint.dropMValue();
}

return 0;
}
else
{
layerPoint.dropMValue();
return 2;
}

return 0;
}
else
{
return 2;
return 1;
}
}
else
{
return 1;
}
}

int QgsMapToolCapture::addVertex( const QgsPointXY &point )
@@ -1018,14 +1026,13 @@ QgsPoint QgsMapToolCapture::mapPoint( const QgsPointXY &point ) const
// set z value if necessary
if ( QgsWkbTypes::hasZ( newPoint.wkbType() ) )
{
newPoint.setZ( mCadDockWidget && mCadDockWidget->cadEnabled() ? mCadDockWidget->currentPoint().z() : defaultZValue() );
newPoint.setZ( mCadDockWidget && mCadDockWidget->cadEnabled() ? mCadDockWidget->getLineZ() : defaultZValue() );
}
// set m value if necessary
if ( QgsWkbTypes::hasM( newPoint.wkbType() ) )
{
newPoint.setM( mCadDockWidget && mCadDockWidget->cadEnabled() ? mCadDockWidget->currentPoint().m() : defaultMValue() );
newPoint.setM( mCadDockWidget && mCadDockWidget->cadEnabled() ? mCadDockWidget->getLineM() : defaultMValue() );
}

return newPoint;
}

0 comments on commit a5fca0b

Please sign in to comment.