Skip to content

Commit

Permalink
Address review, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jun 2, 2024
1 parent 579bd2b commit fb3aa18
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ points that will not be part of a geometry being digitized.
%Docstring
Returns the vector layer within which construction guides are stored.

.. versionadded:: 3.38
.. versionadded:: 3.40
%End

bool showConstructionGuides() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ points that will not be part of a geometry being digitized.
%Docstring
Returns the vector layer within which construction guides are stored.

.. versionadded:: 3.38
.. versionadded:: 3.40
%End

bool showConstructionGuides() const;
Expand Down
14 changes: 7 additions & 7 deletions src/gui/qgsadvanceddigitizingdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
// Construction modes
QMenu *constructionSettingsMenu = new QMenu( this );

mRecordConstructionGuides = new QAction( tr( "Record construction guides" ), constructionSettingsMenu );
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 = new QAction( tr( "Show Construction Guides" ), constructionSettingsMenu );
mShowConstructionGuides->setCheckable( true );
mShowConstructionGuides->setChecked( settingsCadShowConstructionGuides->value() );
constructionSettingsMenu->addAction( mShowConstructionGuides );
Expand All @@ -216,15 +216,15 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
updateCadPaintItem();
} );

mSnapToConstructionGuides = new QAction( tr( "Snap to visible construction guides" ), constructionSettingsMenu );
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 );
mClearConstructionGuides = new QAction( tr( "Clear Construction Guides" ), constructionSettingsMenu );
constructionSettingsMenu->addAction( mClearConstructionGuides );
connect( mClearConstructionGuides, &QAction::triggered, this, [ = ]()
{
Expand Down Expand Up @@ -1957,7 +1957,7 @@ void QgsAdvancedDigitizingDockWidget::enable()
resetConstructionGuides();
}

if ( mDeferedUpdateConstructionGuidesCrs )
if ( mDeferredUpdateConstructionGuidesCrs )
{
updateConstructionGuidesCrs();
}
Expand Down Expand Up @@ -2310,7 +2310,7 @@ void QgsAdvancedDigitizingDockWidget::updateConstructionGuidesCrs()

if ( !cadEnabled() )
{
mDeferedUpdateConstructionGuidesCrs = true;
mDeferredUpdateConstructionGuidesCrs = true;
}

QgsCoordinateTransform transform = QgsCoordinateTransform( mConstructionGuidesLayer->crs(), mMapCanvas->mapSettings().destinationCrs(), QgsProject::instance()->transformContext() );
Expand All @@ -2324,7 +2324,7 @@ void QgsAdvancedDigitizingDockWidget::updateConstructionGuidesCrs()
mConstructionGuidesLayer->changeGeometry( feature.id(), geom );
}

mDeferedUpdateConstructionGuidesCrs = false;
mDeferredUpdateConstructionGuidesCrs = false;
}

void QgsAdvancedDigitizingDockWidget::resetConstructionGuides()
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsadvanceddigitizingdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private

/**
* Returns the vector layer within which construction guides are stored.
* \since QGIS 3.38
* \since QGIS 3.40
*/
QgsVectorLayer *constructionGuidesLayer() const { return mConstructionGuidesLayer.get(); }

Expand Down Expand Up @@ -1100,7 +1100,7 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
std::unique_ptr<QgsVectorLayer> mConstructionGuidesLayer;
QgsFeatureId mConstructionGuideId;
QgsLineString mConstructionGuideLine;
bool mDeferedUpdateConstructionGuidesCrs = false;
bool mDeferredUpdateConstructionGuidesCrs = false;

// Error message
std::unique_ptr<QgsMessageBarItem> mErrorMessage;
Expand Down
52 changes: 52 additions & 0 deletions tests/src/app/testqgsadvanceddigitizing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class TestQgsAdvancedDigitizing: public QObject

void releaseLockAfterDisable();

void constructionGuides();

private:
TestQgsMapToolAdvancedDigitizingUtils getMapToolDigitizingUtils( QgsVectorLayer *layer );
QString getWktFromLastAddedFeature( TestQgsMapToolAdvancedDigitizingUtils utils, QSet<QgsFeatureId> oldFeatures );
Expand Down Expand Up @@ -1163,5 +1165,55 @@ void TestQgsAdvancedDigitizing::releaseLockAfterDisable()
mAdvancedDigitizingDockWidget->enableAction()->trigger();
}

void TestQgsAdvancedDigitizing::constructionGuides()
{
auto utils = getMapToolDigitizingUtils( mLayer3950 );

QVERIFY( mAdvancedDigitizingDockWidget->cadEnabled() );

QCOMPARE( mAdvancedDigitizingDockWidget->constructionGuidesLayer()->featureCount(), 0 );

mAdvancedDigitizingDockWidget->mRecordConstructionGuides->setChecked( true );
mAdvancedDigitizingDockWidget->setConstructionMode( true );

// enter a few construction steps while guide recording is on
utils.mouseClick( 10, 10, Qt::LeftButton );
utils.mouseClick( 10, 11, Qt::LeftButton );
utils.mouseClick( 10, 12, Qt::LeftButton );
utils.mouseClick( 10, 13, Qt::LeftButton );
utils.mouseClick( 10, 14, Qt::LeftButton );
utils.mouseClick( 20, 01, Qt::RightButton );

QCOMPARE( mAdvancedDigitizingDockWidget->constructionGuidesLayer()->featureCount(), 1 );

mAdvancedDigitizingDockWidget->mRecordConstructionGuides->setChecked( false );

// enter a few construction steps while guide recording is off
utils.mouseClick( 10, 10, Qt::LeftButton );
utils.mouseClick( 10, 11, Qt::LeftButton );
utils.mouseClick( 10, 12, Qt::LeftButton );
utils.mouseClick( 10, 13, Qt::LeftButton );
utils.mouseClick( 10, 14, Qt::LeftButton );
utils.mouseClick( 20, 01, Qt::RightButton );

QCOMPARE( mAdvancedDigitizingDockWidget->constructionGuidesLayer()->featureCount(), 1 );

QgsSnappingConfig snapConfig = mCanvas->snappingUtils()->config();
snapConfig.setEnabled( true );
mCanvas->snappingUtils()->setConfig( snapConfig );

mAdvancedDigitizingDockWidget->mSnapToConstructionGuides->setChecked( true );

// snap on an existing constructio guide vertex
utils.mouseMove( 10.1, 10 );
QCOMPARE( mAdvancedDigitizingDockWidget->currentPointV2(), QgsPoint( 10, 10 ) );

mAdvancedDigitizingDockWidget->mSnapToConstructionGuides->setChecked( false );

// do not snap on an existing construction guide vertex
utils.mouseMove( 10.5, 14.5 );
QGSCOMPARENEARPOINT( mAdvancedDigitizingDockWidget->currentPointV2(), QgsPoint( 10.5, 14.5 ), 0.1 );
}

QGSTEST_MAIN( TestQgsAdvancedDigitizing )
#include "testqgsadvanceddigitizing.moc"

0 comments on commit fb3aa18

Please sign in to comment.