From b5f0d095c1d3d3ece04ceb0d382c2d8bcb689a28 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 25 May 2024 16:36:01 +0700 Subject: [PATCH] [advanced digitizing] Implement visual construction guides --- .../core/auto_generated/qgscadutils.sip.in | 1 - .../qgsadvanceddigitizingdockwidget.sip.in | 31 ++- python/core/auto_generated/qgscadutils.sip.in | 1 - .../qgsadvanceddigitizingdockwidget.sip.in | 31 ++- src/core/qgscadutils.cpp | 4 +- src/core/qgscadutils.h | 1 - src/gui/qgsadvanceddigitizingcanvasitem.cpp | 31 ++- src/gui/qgsadvanceddigitizingcanvasitem.h | 1 + src/gui/qgsadvanceddigitizingdockwidget.cpp | 195 ++++++++++++++++++ src/gui/qgsadvanceddigitizingdockwidget.h | 62 +++++- 10 files changed, 341 insertions(+), 17 deletions(-) diff --git a/python/PyQt6/core/auto_generated/qgscadutils.sip.in b/python/PyQt6/core/auto_generated/qgscadutils.sip.in index 6fe83fb37918..3c2c4438730b 100644 --- a/python/PyQt6/core/auto_generated/qgscadutils.sip.in +++ b/python/PyQt6/core/auto_generated/qgscadutils.sip.in @@ -132,7 +132,6 @@ Returns the recent CAD point at the specified ``index`` (in map coordinates). .. versionadded:: 3.22 %End - %Property( name = cadPointList, get = _cadPointList, set = _setCadPointList ) void _setCadPointList( const QList< QgsPointXY > &list ); QList< QgsPointXY > _cadPointList() const; diff --git a/python/PyQt6/gui/auto_generated/qgsadvanceddigitizingdockwidget.sip.in b/python/PyQt6/gui/auto_generated/qgsadvanceddigitizingdockwidget.sip.in index d1fcac710503..779eefd41c65 100644 --- a/python/PyQt6/gui/auto_generated/qgsadvanceddigitizingdockwidget.sip.in +++ b/python/PyQt6/gui/auto_generated/qgsadvanceddigitizingdockwidget.sip.in @@ -277,7 +277,36 @@ Sets whether M is enabled bool constructionMode() const; %Docstring -construction mode is used to draw intermediate points. These points won't be given any further (i.e. to the map tools) +Returns whether the construction mode is activated. The construction mode is used to draw intermediate +points that will not be part of a geometry being digitized. +%End + + QgsVectorLayer *constructionGuidesLayer() const; +%Docstring +Returns the vector layer within which construction guides are stored. + +.. versionadded:: 3.38 +%End + + bool showConstructionGuides() const; +%Docstring +Returns whether the construction guides are visible. + +.. versionadded:: 3.38 +%End + + bool snapToConstructionGuides() const; +%Docstring +Returns whether points should snap to construction guides. + +.. versionadded:: 3.38 +%End + + bool recordConstructionGuides() const; +%Docstring +Returns whether construction guides are being recorded. + +.. versionadded:: 3.38 %End Qgis::BetweenLineConstraint betweenLineConstraint() const; diff --git a/python/core/auto_generated/qgscadutils.sip.in b/python/core/auto_generated/qgscadutils.sip.in index 6fe83fb37918..3c2c4438730b 100644 --- a/python/core/auto_generated/qgscadutils.sip.in +++ b/python/core/auto_generated/qgscadutils.sip.in @@ -132,7 +132,6 @@ Returns the recent CAD point at the specified ``index`` (in map coordinates). .. versionadded:: 3.22 %End - %Property( name = cadPointList, get = _cadPointList, set = _setCadPointList ) void _setCadPointList( const QList< QgsPointXY > &list ); QList< QgsPointXY > _cadPointList() const; diff --git a/python/gui/auto_generated/qgsadvanceddigitizingdockwidget.sip.in b/python/gui/auto_generated/qgsadvanceddigitizingdockwidget.sip.in index 7b1058258bb9..2995e16307ea 100644 --- a/python/gui/auto_generated/qgsadvanceddigitizingdockwidget.sip.in +++ b/python/gui/auto_generated/qgsadvanceddigitizingdockwidget.sip.in @@ -277,7 +277,36 @@ Sets whether M is enabled bool constructionMode() const; %Docstring -construction mode is used to draw intermediate points. These points won't be given any further (i.e. to the map tools) +Returns whether the construction mode is activated. The construction mode is used to draw intermediate +points that will not be part of a geometry being digitized. +%End + + QgsVectorLayer *constructionGuidesLayer() const; +%Docstring +Returns the vector layer within which construction guides are stored. + +.. versionadded:: 3.38 +%End + + bool showConstructionGuides() const; +%Docstring +Returns whether the construction guides are visible. + +.. versionadded:: 3.38 +%End + + bool snapToConstructionGuides() const; +%Docstring +Returns whether points should snap to construction guides. + +.. versionadded:: 3.38 +%End + + bool recordConstructionGuides() const; +%Docstring +Returns whether construction guides are being recorded. + +.. versionadded:: 3.38 %End Qgis::BetweenLineConstraint betweenLineConstraint() const; diff --git a/src/core/qgscadutils.cpp b/src/core/qgscadutils.cpp index de2f2a2a33c0..ba0b9969e06d 100644 --- a/src/core/qgscadutils.cpp +++ b/src/core/qgscadutils.cpp @@ -48,8 +48,8 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o res.softLockX = std::numeric_limits::quiet_NaN(); res.softLockY = std::numeric_limits::quiet_NaN(); - // try to snap to anything - const QgsPointLocator::Match snapMatch = ctx.snappingUtils->snapToMap( originalMapPoint, nullptr, true ); + // try to snap to project layer(s) as well as visible construction guides + QgsPointLocator::Match snapMatch = ctx.snappingUtils->snapToMap( originalMapPoint, nullptr, true ); res.snapMatch = snapMatch; QgsPointXY point = snapMatch.isValid() ? snapMatch.point() : originalMapPoint; QgsPointXY edgePt0, edgePt1; diff --git a/src/core/qgscadutils.h b/src/core/qgscadutils.h index 1d9e59a9575a..f4783839369a 100644 --- a/src/core/qgscadutils.h +++ b/src/core/qgscadutils.h @@ -195,7 +195,6 @@ class CORE_EXPORT QgsCadUtils */ QQueue< QgsPointLocator::Match > lockedSnapVertices() const { return mLockedSnapVertices; } SIP_SKIP; - #ifdef SIP_RUN SIP_PROPERTY( name = cadPointList, get = _cadPointList, set = _setCadPointList ) #endif diff --git a/src/gui/qgsadvanceddigitizingcanvasitem.cpp b/src/gui/qgsadvanceddigitizingcanvasitem.cpp index fc68b3d9f596..2f9114837c8e 100644 --- a/src/gui/qgsadvanceddigitizingcanvasitem.cpp +++ b/src/gui/qgsadvanceddigitizingcanvasitem.cpp @@ -28,6 +28,7 @@ QgsAdvancedDigitizingCanvasItem::QgsAdvancedDigitizingCanvasItem( QgsMapCanvas * , mSnapPen( QPen( QColor( 127, 0, 0, 150 ), 1 ) ) , mSnapLinePen( QPen( QColor( 127, 0, 0, 150 ), 1, Qt::DashLine ) ) , mCursorPen( QPen( QColor( 127, 127, 127, 255 ), 1 ) ) + , mConstructionGuidesPen( QPen( QColor( 20, 210, 150 ), 1, Qt::DashLine ) ) , mAdvancedDigitizingDockWidget( cadDockWidget ) { } @@ -37,6 +38,31 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter ) if ( !mAdvancedDigitizingDockWidget->cadEnabled() ) return; + painter->setRenderHint( QPainter::Antialiasing ); + painter->setCompositionMode( QPainter::CompositionMode_Difference ); + + // Draw construction guides + if ( mAdvancedDigitizingDockWidget->showConstructionGuides() ) + { + if ( QgsVectorLayer *constructionGuidesLayer = mAdvancedDigitizingDockWidget->constructionGuidesLayer() ) + { + QgsFeatureIterator it = constructionGuidesLayer->getFeatures( mMapCanvas->mapSettings().visibleExtent() ); + QgsFeature feature; + painter->setPen( mConstructionGuidesPen ); + while ( it.nextFeature( feature ) ) + { + QgsPolylineXY line = feature.geometry().asPolyline(); + QPolygonF polygon( line.size() ); + for ( int i = 0; i < line.size(); i++ ) + { + polygon[i] = toCanvasCoordinates( line[i] ); + } + + painter->drawPolyline( polygon ); + } + } + } + // Use visible polygon rather than extent to properly handle rotated maps QPolygonF mapPoly = mMapCanvas->mapSettings().visiblePolygon(); const double canvasWidth = QLineF( mapPoly[0], mapPoly[1] ).length(); @@ -83,9 +109,6 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter ) snapSegmentPix2 = toCanvasCoordinates( snappedSegment[1] ); } - painter->setRenderHint( QPainter::Antialiasing ); - painter->setCompositionMode( QPainter::CompositionMode_Difference ); - // Draw point snap if ( curPointExist && snappedToVertex ) { @@ -226,7 +249,7 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter ) } } - // Draw constr + // Draw constraints if ( mAdvancedDigitizingDockWidget->betweenLineConstraint() == Qgis::BetweenLineConstraint::NoConstraint ) { if ( curPointExist && previousPointExist ) diff --git a/src/gui/qgsadvanceddigitizingcanvasitem.h b/src/gui/qgsadvanceddigitizingcanvasitem.h index 9678fffb793c..a6c90dfe025b 100644 --- a/src/gui/qgsadvanceddigitizingcanvasitem.h +++ b/src/gui/qgsadvanceddigitizingcanvasitem.h @@ -60,6 +60,7 @@ class GUI_EXPORT QgsAdvancedDigitizingCanvasItem : public QgsMapCanvasItem QPen mSnapPen; QPen mSnapLinePen; QPen mCursorPen; + QPen mConstructionGuidesPen; QgsAdvancedDigitizingDockWidget *mAdvancedDigitizingDockWidget = nullptr; }; diff --git a/src/gui/qgsadvanceddigitizingdockwidget.cpp b/src/gui/qgsadvanceddigitizingdockwidget.cpp index 741448e2fdf6..fa89b8117b7f 100644 --- a/src/gui/qgsadvanceddigitizingdockwidget.cpp +++ b/src/gui/qgsadvanceddigitizingdockwidget.cpp @@ -43,6 +43,9 @@ const QgsSettingsEntryBool *QgsAdvancedDigitizingDockWidget::settingsCadSnappingPriorityPrioritizeFeature = new QgsSettingsEntryBool( QStringLiteral( "cad-snapping-prioritize-feature" ), QgsSettingsTree::sTreeDigitizing, false, tr( "Determines if snapping to features has priority over snapping to common angles." ) ) ; +const QgsSettingsEntryBool *QgsAdvancedDigitizingDockWidget::settingsCadRecordConstructionGuides = new QgsSettingsEntryBool( QStringLiteral( "cad-record-construction-guides" ), QgsSettingsTree::sTreeDigitizing, false, tr( "Determines if construction guides are being recorded." ) ) ; +const QgsSettingsEntryBool *QgsAdvancedDigitizingDockWidget::settingsCadShowConstructionGuides = new QgsSettingsEntryBool( QStringLiteral( "cad-show-construction-guides" ), QgsSettingsTree::sTreeDigitizing, true, tr( "Determines whether construction guides are shown." ) ) ; +const QgsSettingsEntryBool *QgsAdvancedDigitizingDockWidget::settingsCadSnapToConstructionGuides = new QgsSettingsEntryBool( QStringLiteral( "cad-snap-to-construction-guides" ), QgsSettingsTree::sTreeDigitizing, false, tr( "Determines if points will snap to construction guides." ) ) ; QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *canvas, QWidget *parent ) @@ -194,6 +197,46 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas * mCommonAngleActions.insert( it->first, action ); } + // Construction modes + QMenu *constructionSettingsMenu = new QMenu( this ); + + mRecordConstructionGuides = new QAction( tr( "Record construction guides" ), constructionSettingsMenu ); + mRecordConstructionGuides->setCheckable( true ); + mRecordConstructionGuides->setChecked( settingsCadRecordConstructionGuides->value() ); + constructionSettingsMenu->addAction( mRecordConstructionGuides ); + connect( mRecordConstructionGuides, &QAction::triggered, this, [ = ]() { settingsCadRecordConstructionGuides->setValue( mRecordConstructionGuides->isChecked() ); } ); + + mShowConstructionGuides = new QAction( tr( "Show construction guides" ), constructionSettingsMenu ); + mShowConstructionGuides->setCheckable( true ); + mShowConstructionGuides->setChecked( settingsCadShowConstructionGuides->value() ); + constructionSettingsMenu->addAction( mShowConstructionGuides ); + connect( mShowConstructionGuides, &QAction::triggered, this, [ = ]() + { + settingsCadShowConstructionGuides->setValue( mShowConstructionGuides->isChecked() ); + updateCadPaintItem(); + } ); + + mSnapToConstructionGuides = new QAction( tr( "Snap to visible construction guides" ), constructionSettingsMenu ); + mSnapToConstructionGuides->setCheckable( true ); + mSnapToConstructionGuides->setChecked( settingsCadSnapToConstructionGuides->value() ); + constructionSettingsMenu->addAction( mSnapToConstructionGuides ); + connect( mSnapToConstructionGuides, &QAction::triggered, this, [ = ]() { settingsCadSnapToConstructionGuides->setValue( mSnapToConstructionGuides->isChecked() ); } ); + + constructionSettingsMenu->addSeparator(); + + mClearConstructionGuides = new QAction( tr( "Clear construction guides" ), constructionSettingsMenu ); + constructionSettingsMenu->addAction( mClearConstructionGuides ); + connect( mClearConstructionGuides, &QAction::triggered, this, [ = ]() + { + resetConstructionGuides(); + updateCadPaintItem(); + } ); + + QToolButton *constructionModeToolButton = qobject_cast< QToolButton *>( mToolbar->widgetForAction( mConstructionModeAction ) ); + constructionModeToolButton->setPopupMode( QToolButton::MenuButtonPopup ); + constructionModeToolButton->setMenu( constructionSettingsMenu ); + constructionModeToolButton->setObjectName( QStringLiteral( "ConstructionModeButton" ) ); + qobject_cast< QToolButton *>( mToolbar->widgetForAction( mSettingsAction ) )->setPopupMode( QToolButton::InstantPopup ); mSettingsAction->setMenu( mCommonAngleActionsMenu ); mSettingsAction->setCheckable( true ); @@ -368,6 +411,12 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas * updateCapacity( true ); connect( QgsProject::instance(), &QgsProject::snappingConfigChanged, this, [ = ] { updateCapacity( true ); } ); + connect( QgsProject::instance(), &QgsProject::cleared, this, [ = ]() + { + mConstructionGuidesLayer.reset(); + } ); + connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged, this, [ = ] { updateConstructionGuidesCrs(); } ); + disable(); } @@ -672,6 +721,14 @@ void QgsAdvancedDigitizingDockWidget::setConstructionMode( bool enabled ) { mConstructionMode = enabled; mConstructionModeAction->setChecked( enabled ); + + if ( recordConstructionGuides() ) + { + if ( enabled && mCadPointList.size() > 1 ) + { + mConstructionGuideLine.addVertex( mCadPointList.at( 1 ) ); + } + } } void QgsAdvancedDigitizingDockWidget::settingsButtonTriggered( QAction *action ) @@ -1195,6 +1252,11 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e ) context.setCadPoints( mCadPointList ); context.setLockedSnapVertices( mLockedSnapVertices ); + if ( snapToConstructionGuides() ) + { + context.snappingUtils->addExtraSnapLayer( mConstructionGuidesLayer.get() ); + } + context.commonAngleConstraint.locked = !mMapCanvas->mapSettings().destinationCrs().isGeographic(); context.commonAngleConstraint.relative = context.angleConstraint.relative; context.commonAngleConstraint.value = mCommonAngleConstraint; @@ -1254,6 +1316,7 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e ) * the point is not linked to a layer. */ e->setMapPoint( point ); + mSnapMatch = context.snappingUtils->snapToMap( point, nullptr, true ); if ( mSnapMatch.layer() ) { @@ -1265,6 +1328,8 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e ) } } + context.snappingUtils->removeExtraSnapLayer( mConstructionGuidesLayer.get() ); + if ( mSnapMatch.hasVertex() || mSnapMatch.hasLineEndpoint() ) { toggleLockedSnapVertex( mSnapMatch, mLastSnapMatch ); @@ -1501,6 +1566,11 @@ bool QgsAdvancedDigitizingDockWidget::canvasKeyPressEventFilter( QKeyEvent *e ) void QgsAdvancedDigitizingDockWidget::clear() { + if ( !mConstructionGuideLine.isEmpty() ) + { + mConstructionGuideLine.clear(); + } + clearPoints(); releaseLocks(); } @@ -1524,6 +1594,13 @@ void QgsAdvancedDigitizingDockWidget::keyPressEvent( QKeyEvent *e ) case Qt::Key_Escape: { releaseLocks(); + + if ( mConstructionGuideLine.numPoints() >= 2 ) + { + mConstructionGuidesLayer->deleteFeature( mConstructionGuideId ); + mConstructionGuideLine.clear(); + } + break; } default: @@ -1575,6 +1652,22 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e ) const QEvent::Type type = e->type(); switch ( e->key() ) { + case Qt::Key_Escape: + { + if ( mConstructionMode && mConstructionGuideLine.numPoints() >= 2 ) + { + mConstructionGuidesLayer->deleteFeature( mConstructionGuideId ); + mConstructionGuideLine.clear(); + + if ( mCadPointList.size() > 1 ) + { + mConstructionGuideLine.addVertex( mCadPointList.at( 1 ) ); + } + + updateCadPaintItem(); + } + break; + } case Qt::Key_X: { // modifier+x ONLY caught for ShortcutOverride events... @@ -1856,7 +1949,20 @@ void QgsAdvancedDigitizingDockWidget::enable() { show(); } + setCadEnabled( mSessionActive ); + + if ( !mConstructionGuidesLayer ) + { + resetConstructionGuides(); + } + + if ( mDeferedUpdateConstructionGuidesCrs ) + { + updateConstructionGuidesCrs(); + } + + updateCadPaintItem(); } void QgsAdvancedDigitizingDockWidget::disable() @@ -1903,6 +2009,39 @@ void QgsAdvancedDigitizingDockWidget::addPoint( const QgsPointXY &point ) mCadPointList.insert( 0, pt ); } + if ( recordConstructionGuides() ) + { + if ( constructionMode() ) + { + mConstructionGuideLine.addVertex( pt ); + + if ( mConstructionGuideLine.numPoints() == 2 ) + { + QgsFeature feature; + QgsGeometry geom( mConstructionGuideLine.clone() ); + feature.setGeometry( geom ); + mConstructionGuidesLayer->addFeature( feature, QgsFeatureSink::FastInsert ); + mConstructionGuideId = feature.id(); + } + else if ( mConstructionGuideLine.numPoints() > 2 ) + { + QgsGeometry geom( mConstructionGuideLine.clone() ); + mConstructionGuidesLayer->changeGeometry( mConstructionGuideId, geom ); + } + } + else + { + if ( !mConstructionGuideLine.isEmpty() ) + { + mConstructionGuideLine.addVertex( pt ); + + QgsGeometry geom( mConstructionGuideLine.clone() ); + mConstructionGuidesLayer->changeGeometry( mConstructionGuideId, geom ); + mConstructionGuideLine.clear(); + } + } + } + updateCapacity(); updateCadPaintItem(); } @@ -2146,3 +2285,59 @@ double QgsAdvancedDigitizingDockWidget::getLineM( ) const { return mMLineEdit->isEnabled() ? QLocale().toDouble( mMLineEdit->text() ) : std::numeric_limits::quiet_NaN(); } + +bool QgsAdvancedDigitizingDockWidget::showConstructionGuides() const +{ + return mShowConstructionGuides ? mShowConstructionGuides->isChecked() : false; +} + +bool QgsAdvancedDigitizingDockWidget::snapToConstructionGuides() const +{ + return mSnapToConstructionGuides ? mShowConstructionGuides->isChecked() && mSnapToConstructionGuides->isChecked() : false; +} + +bool QgsAdvancedDigitizingDockWidget::recordConstructionGuides() const +{ + return mRecordConstructionGuides ? mRecordConstructionGuides->isChecked() : false; +} + +void QgsAdvancedDigitizingDockWidget::updateConstructionGuidesCrs() +{ + if ( !mConstructionGuidesLayer ) + { + return; + } + + if ( !cadEnabled() ) + { + mDeferedUpdateConstructionGuidesCrs = true; + } + + QgsCoordinateTransform transform = QgsCoordinateTransform( mConstructionGuidesLayer->crs(), mMapCanvas->mapSettings().destinationCrs(), QgsProject::instance()->transformContext() ); + mConstructionGuidesLayer->setCrs( mMapCanvas->mapSettings().destinationCrs() ); + QgsFeatureIterator it = mConstructionGuidesLayer->getFeatures(); + QgsFeature feature; + while ( it.nextFeature( feature ) ) + { + QgsGeometry geom = feature.geometry(); + geom.transform( transform ); + mConstructionGuidesLayer->changeGeometry( feature.id(), geom ); + } + + mDeferedUpdateConstructionGuidesCrs = false; +} + +void QgsAdvancedDigitizingDockWidget::resetConstructionGuides() +{ + if ( mConstructionGuidesLayer ) + { + mConstructionGuidesLayer.reset(); + } + + const QgsVectorLayer::LayerOptions options( QgsProject::instance()->transformContext(), false, false ); + mConstructionGuidesLayer = std::make_unique( QStringLiteral( "LineString?crs=%1" ).arg( mMapCanvas->mapSettings().destinationCrs().authid() ), + QStringLiteral( "constructionGuides" ), + QStringLiteral( "memory" ), + options ); + mConstructionGuidesLayer->startEditing(); +} diff --git a/src/gui/qgsadvanceddigitizingdockwidget.h b/src/gui/qgsadvanceddigitizingdockwidget.h index 4d76b4d216b8..f4c441c14784 100644 --- a/src/gui/qgsadvanceddigitizingdockwidget.h +++ b/src/gui/qgsadvanceddigitizingdockwidget.h @@ -305,9 +305,36 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private */ void setEnabledM( bool enable ); - //! construction mode is used to draw intermediate points. These points won't be given any further (i.e. to the map tools) + /** + * Returns whether the construction mode is activated. The construction mode is used to draw intermediate + * points that will not be part of a geometry being digitized. + */ bool constructionMode() const { return mConstructionMode; } + /** + * Returns the vector layer within which construction guides are stored. + * \since QGIS 3.38 + */ + QgsVectorLayer *constructionGuidesLayer() const { return mConstructionGuidesLayer.get(); } + + /** + * Returns whether the construction guides are visible. + * \since QGIS 3.38 + */ + bool showConstructionGuides() const; + + /** + * Returns whether points should snap to construction guides. + * \since QGIS 3.38 + */ + bool snapToConstructionGuides() const; + + /** + * Returns whether construction guides are being recorded. + * \since QGIS 3.38 + */ + bool recordConstructionGuides() const; + /** * Returns the between line constraints which are used to place * perpendicular/parallel segments to snapped segments on the canvas @@ -1013,7 +1040,6 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private //! Updates values of constraints that are not locked based on the current point void updateUnlockedConstraintValues( const QgsPoint &point ); - /** * Adds or removes the snap match if it is already in the locked snap queue or not. * \param snapMatch the snap match to add or remove. @@ -1021,6 +1047,17 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private */ void toggleLockedSnapVertex( const QgsPointLocator::Match &snapMatch, QgsPointLocator::Match previouslySnap ); + /** + * Resets the vector layer and point locator objects handling construction guides. + */ + void resetConstructionGuides(); + + /** + * Updates the construction guides layer CRS to match the map canvas' destination CRS + * and reproject pre-existing construction guides. + */ + void updateConstructionGuidesCrs(); + QgsMapCanvas *mMapCanvas = nullptr; QgsAdvancedDigitizingCanvasItem *mCadPaintItem = nullptr; //! Snapping indicator @@ -1053,19 +1090,29 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private //! Flag that controls whether snapping to features has priority over common angle bool mSnappingPrioritizeFeatures = false; - // point list and current snap point / segment + // Point list and current snap point / segment QList mCadPointList; QList mSnappedSegment; bool mSessionActive = false; - // error message + // Construction path history + std::unique_ptr mConstructionGuidesLayer; + QgsFeatureId mConstructionGuideId; + QgsLineString mConstructionGuideLine; + bool mDeferedUpdateConstructionGuidesCrs = false; + + // Error message std::unique_ptr mErrorMessage; // UI QMap< double, QAction *> mCommonAngleActions; // map the common angle actions with their angle values - QAction *mLineExtensionAction; - QAction *mXyVertexAction; + QAction *mLineExtensionAction = nullptr; + QAction *mXyVertexAction = nullptr; + QAction *mRecordConstructionGuides = nullptr; + QAction *mShowConstructionGuides = nullptr; + QAction *mSnapToConstructionGuides = nullptr; + QAction *mClearConstructionGuides = nullptr; // Snap indicator QgsPointLocator::Match mSnapMatch; @@ -1088,6 +1135,9 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private QMenu *mFloaterActionsMenu = nullptr; static const QgsSettingsEntryBool *settingsCadSnappingPriorityPrioritizeFeature; + static const QgsSettingsEntryBool *settingsCadRecordConstructionGuides; + static const QgsSettingsEntryBool *settingsCadShowConstructionGuides; + static const QgsSettingsEntryBool *settingsCadSnapToConstructionGuides; friend class TestQgsAdvancedDigitizing; friend class TestQgsAdvancedDigitizingDockWidget;