Skip to content

Commit

Permalink
Adds QgsSettingsRegistryCore::settingsDigitizingDefaultMValue and fix…
Browse files Browse the repository at this point in the history
…es conflicts
  • Loading branch information
lbartoletti committed Apr 30, 2021
1 parent d11fe03 commit 09ca85c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 231 deletions.
3 changes: 3 additions & 0 deletions src/core/settings/qgssettingsregistrycore.h
Expand Up @@ -88,6 +88,9 @@ class CORE_EXPORT QgsSettingsRegistryCore : public QgsSettingsRegistry
//! Settings entry digitizing default z value
static const inline QgsSettingsEntryDouble settingsDigitizingDefaultZValue = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/default_z_value" ), QgsSettings::NoSection, Qgis::DEFAULT_Z_COORDINATE );

//! Settings entry digitizing default m value
static const inline QgsSettingsEntryDouble settingsDigitizingDefaultMValue = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/default_m_value" ), QgsSettings::NoSection, Qgis::DEFAULT_M_COORDINATE );

//! Settings entry digitizing default snap enabled
static const inline QgsSettingsEntryBool settingsDigitizingDefaultSnapEnabled = QgsSettingsEntryBool( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), QgsSettings::NoSection, false );

Expand Down
222 changes: 10 additions & 212 deletions tests/src/app/maptooladdfeatureline/testqgsmaptooladdfeatureline.cpp
Expand Up @@ -24,7 +24,7 @@
#include "qgsmaptooladdfeature.h"
#include "qgsmapcanvastracer.h"
#include "qgsproject.h"
#include "qgssettingsregistrycore.h"
#include "qgssettings.h"
#include "qgsvectorlayer.h"
#include "qgswkbtypes.h"
#include "qgsmapmouseevent.h"
Expand Down Expand Up @@ -193,7 +193,7 @@ void TestQgsMapToolAddFeatureLine::initTestCase()
mCanvas->hide();
QCOMPARE( mCanvas->mapSettings().outputSize(), QSize( 512, 512 ) );
QCOMPARE( mCanvas->mapSettings().visibleExtent(), QgsRectangle( 0, 0, 8, 8 ) );

// make 2D layer for snapping with a 3D layer
mLayerLine2D = new QgsVectorLayer( QStringLiteral( "LineString?crs=EPSG:27700" ), QStringLiteral( "layer line" ), QStringLiteral( "memory" ) );
QVERIFY( mLayerLine2D->isValid() );
Expand Down Expand Up @@ -431,7 +431,7 @@ void TestQgsMapToolAddFeatureLine::testTracingWithConvertToCurves()
QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();

// tracing enabled - without converting to curves
QgsSettingsRegistryCore::settingsDigitizingConvertToCurve.setValue( false );
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/convert_to_curve" ), false );

utils.mouseClick( 6, 1, Qt::LeftButton );
utils.mouseClick( 7, 1, Qt::LeftButton );
Expand All @@ -447,7 +447,7 @@ void TestQgsMapToolAddFeatureLine::testTracingWithConvertToCurves()
mLayerLineCurved->undoStack()->undo();

// we redo the same with convert to curves enabled
QgsSettingsRegistryCore::settingsDigitizingConvertToCurve.setValue( true );
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/convert_to_curve" ), true );

// tracing enabled - without converting to curves
utils.mouseClick( 6, 1, Qt::LeftButton );
Expand Down Expand Up @@ -476,8 +476,8 @@ void TestQgsMapToolAddFeatureLine::testTracingWithConvertToCurvesCustomTolerance
// At this distance, the arcs aren't correctly detected with the default tolerance
double offset = 100000000; // remember to change the feature geometry accordingly in initTestCase (sic)

QgsSettingsRegistryCore::settingsDigitizingConvertToCurveAngleTolerance.setValue( 1e-5 );
QgsSettingsRegistryCore::settingsDigitizingConvertToCurveDistanceTolerance.setValue( 1e-5 );
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/convert_to_curve_angle_tolerance" ), 1e-5 );
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/convert_to_curve_distance_tolerance" ), 1e-5 );

mCanvas->setExtent( QgsRectangle( offset + 0, offset + 0, offset + 8, offset + 8 ) );
QCOMPARE( mCanvas->mapSettings().visibleExtent(), QgsRectangle( offset + 0, offset + 0, offset + 8, offset + 8 ) );
Expand All @@ -492,7 +492,7 @@ void TestQgsMapToolAddFeatureLine::testTracingWithConvertToCurvesCustomTolerance
QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();

// tracing enabled - without converting to curves
QgsSettingsRegistryCore::settingsDigitizingConvertToCurve.setValue( false );
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/convert_to_curve" ), false );

utils.mouseClick( offset + 6, offset + 1, Qt::LeftButton );
utils.mouseClick( offset + 7, offset + 1, Qt::LeftButton );
Expand All @@ -508,7 +508,7 @@ void TestQgsMapToolAddFeatureLine::testTracingWithConvertToCurvesCustomTolerance
mLayerLineCurvedOffset->undoStack()->undo();

// we redo the same with convert to curves enabled
QgsSettingsRegistryCore::settingsDigitizingConvertToCurve.setValue( true );
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/convert_to_curve" ), true );

// tracing enabled - without converting to curves
utils.mouseClick( offset + 6, offset + 1, Qt::LeftButton );
Expand All @@ -535,209 +535,6 @@ void TestQgsMapToolAddFeatureLine::testTracingWithConvertToCurvesCustomTolerance

}

<<<<<<< HEAD:tests/src/app/testqgsmaptooladdfeatureline.cpp
void TestQgsMapToolAddFeatureLine::testZ()
{
TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool );

mCanvas->setCurrentLayer( mLayerLineZ );

// test with default Z value = 333
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 333 );

QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();
utils.mouseClick( 4, 0, Qt::LeftButton );
utils.mouseClick( 5, 0, Qt::LeftButton );
utils.mouseClick( 5, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId( oldFids );

QString wkt = "LineStringZ (4 0 333, 5 0 333, 5 1 333, 4 1 333)";
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLine->undoStack()->undo();

// test with default Z value = 222
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 222 );

oldFids = utils.existingFeatureIds();
utils.mouseClick( 4, 0, Qt::LeftButton );
utils.mouseClick( 5, 0, Qt::LeftButton );
utils.mouseClick( 5, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::RightButton );
newFid = utils.newFeatureId( oldFids );

wkt = "LineStringZ (4 0 222, 5 0 222, 5 1 222, 4 1 222)";
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLine->undoStack()->undo();

mCanvas->setCurrentLayer( mLayerLine );
}

void TestQgsMapToolAddFeatureLine::testM()
{
TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool );

mCanvas->setCurrentLayer( mLayerLineM );

// test with default M value = 333
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_m_value" ), 333 );

QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();
utils.mouseClick( 4, 0, Qt::LeftButton );
utils.mouseClick( 5, 0, Qt::LeftButton );
utils.mouseClick( 5, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId( oldFids );

QString wkt = "LineStringM (4 0 333, 5 0 333, 5 1 333, 4 1 333)";
QCOMPARE( mLayerLineM->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLine->undoStack()->undo();

// test with default M value = 222
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_m_value" ), 222 );

oldFids = utils.existingFeatureIds();
utils.mouseClick( 4, 0, Qt::LeftButton );
utils.mouseClick( 5, 0, Qt::LeftButton );
utils.mouseClick( 5, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::RightButton );
newFid = utils.newFeatureId( oldFids );

wkt = "LineStringM (4 0 222, 5 0 222, 5 1 222, 4 1 222)";
QCOMPARE( mLayerLineM->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLine->undoStack()->undo();

mCanvas->setCurrentLayer( mLayerLine );
}

void TestQgsMapToolAddFeatureLine::testZMSnapping()
{
TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool );

mCanvas->setCurrentLayer( mLayerLine );

QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();

QgsSnappingConfig cfg = mCanvas->snappingUtils()->config();
cfg.setMode( QgsSnappingConfig::AllLayers );
cfg.setEnabled( true );
mCanvas->snappingUtils()->setConfig( cfg );

// snap a on a layer with ZM support
utils.mouseClick( 6, 6, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseClick( 5, 0, Qt::LeftButton );
utils.mouseClick( 5, 0, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId( oldFids );

QCOMPARE( mLayerLine->getFeature( newFid ).geometry().get()->is3D(), false );
QCOMPARE( mLayerLine->getFeature( newFid ).geometry().get()->isMeasure(), false );

mLayerLine->undoStack()->undo();

mCanvas->setCurrentLayer( mLayerLineZ );
oldFids = utils.existingFeatureIds();
// test with default Z value = 222
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 222 );
// snap a on a layer without ZM support
utils.mouseClick( 9, 9, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseClick( 8, 7, Qt::LeftButton );
utils.mouseClick( 5, 0, Qt::RightButton );

newFid = utils.newFeatureId( oldFids );

QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry().get()->is3D(), true );

QString wkt = "LineStringZ (9 9 222, 8 7 222)";
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry().get()->isMeasure(), false );

mLayerLine->undoStack()->undo();


// Snap on middle Segment
mCanvas->setCurrentLayer( mLayerLineZ );
cfg.setTypeFlag( QgsSnappingConfig::MiddleOfSegmentFlag );
mCanvas->snappingUtils()->setConfig( cfg );

// create geometry will be snapped
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 123 );

oldFids = utils.existingFeatureIds();
utils.mouseClick( 20, 20, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseClick( 30, 20, Qt::LeftButton );
utils.mouseClick( 30, 20, Qt::RightButton );
newFid = utils.newFeatureId( oldFids );

QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry().get()->is3D(), true );
wkt = "LineStringZ (20 20 123, 30 20 123)";
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 321 );
oldFids = utils.existingFeatureIds();
utils.mouseClick( 25, 20, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseClick( 25, 25, Qt::LeftButton );
utils.mouseClick( 25, 25, Qt::RightButton );
newFid = utils.newFeatureId( oldFids );

QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry().get()->is3D(), true );
wkt = "LineStringZ (25 20 123, 25 25 321)";
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLineZ->undoStack()->undo();
mLayerLineZ->undoStack()->undo();

cfg.setEnabled( false );
mCanvas->snappingUtils()->setConfig( cfg );
}

void TestQgsMapToolAddFeatureLine::testTopologicalEditingZ()
{
TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool );

mCanvas->setCurrentLayer( mLayerTopoZ );

// test with default Z value = 333
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 333 );

QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();

QgsSnappingConfig cfg = mCanvas->snappingUtils()->config();
bool topologicalEditing = cfg.project()->topologicalEditing();
cfg.project()->setTopologicalEditing( true );

cfg.setMode( QgsSnappingConfig::AllLayers );
cfg.setEnabled( true );
mCanvas->snappingUtils()->setConfig( cfg );

oldFids = utils.existingFeatureIds();
utils.mouseClick( 6, 6.5, Qt::LeftButton );
utils.mouseClick( 6.25, 6.5, Qt::LeftButton );
utils.mouseClick( 6.75, 6.5, Qt::LeftButton );
utils.mouseClick( 7.25, 6.5, Qt::LeftButton );
utils.mouseClick( 7.5, 6.5, Qt::LeftButton );
utils.mouseClick( 8, 6.5, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId( oldFids );

QString wkt = "LineStringZ (6 6.5 5, 6.25 6.5 333, 6.75 6.5 333, 7.25 6.5 333, 7.5 6.5 333)";
QCOMPARE( mLayerTopoZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );
wkt = "MultiLineStringZ ((7.25 6 0, 7.25 6.5 333, 7.25 7 0, 7.5 7 0, 7.5 6.5 333, 7.5 6 0, 7.25 6 0),(6 6 0, 6 6.5 5, 6 7 10, 7 7 0, 7 6 0, 6 6 0),(6.25 6.25 0, 6.75 6.25 0, 6.75 6.5 333, 6.75 6.75 0, 6.25 6.75 0, 6.25 6.5 333, 6.25 6.25 0))";
QCOMPARE( mLayerTopoZ->getFeature( qgis::setToList( oldFids ).last() ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLine->undoStack()->undo();

cfg.setEnabled( false );
mCanvas->snappingUtils()->setConfig( cfg );
cfg.project()->setTopologicalEditing( topologicalEditing );
}

void TestQgsMapToolAddFeatureLine::testCloseLine()
{
TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool );
Expand Down Expand Up @@ -1007,7 +804,8 @@ void TestQgsMapToolAddFeatureLine::testUndo()
void TestQgsMapToolAddFeatureLine::testStreamTolerance()
{
// test streaming mode digitizing with tolerance
QgsSettingsRegistryCore::settingsDigitizingStreamTolerance.setValue( 10 );
QgsSettings settings;
settings.setValue( QStringLiteral( "/qgis/digitizing/stream_tolerance" ), 10 );

TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool );

Expand Down
Expand Up @@ -25,6 +25,7 @@
#include "qgsmapcanvastracer.h"
#include "qgsproject.h"
#include "qgssettings.h"
#include "qgssettingsregistrycore.h"
#include "qgsvectorlayer.h"
#include "qgswkbtypes.h"
#include "qgsmapmouseevent.h"
Expand Down Expand Up @@ -181,7 +182,7 @@ void TestQgsMapToolAddFeatureLineM::testM()
mCanvas->setCurrentLayer( mLayerLineM );

// test with default M value = 333
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_m_value" ), 333 );
QgsSettingsRegistryCore::settingsDigitizingDefaultMValue.setValue( 333 );

QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();
utils.mouseClick( 4, 0, Qt::LeftButton );
Expand All @@ -197,7 +198,7 @@ void TestQgsMapToolAddFeatureLineM::testM()
mLayerLine->undoStack()->undo();

// test with default M value = 222
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_m_value" ), 222 );
QgsSettingsRegistryCore::settingsDigitizingDefaultMValue.setValue( 222 );

oldFids = utils.existingFeatureIds();
utils.mouseClick( 4, 0, Qt::LeftButton );
Expand All @@ -222,7 +223,7 @@ void TestQgsMapToolAddFeatureLineM::testTopologicalEditingM()
mCanvas->setCurrentLayer( mLayerTopoM );

// test with default M value = 333
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_m_value" ), 333 );
QgsSettingsRegistryCore::settingsDigitizingDefaultMValue.setValue( 333 );

QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();

Expand Down
Expand Up @@ -25,6 +25,7 @@
#include "qgsmapcanvastracer.h"
#include "qgsproject.h"
#include "qgssettings.h"
#include "qgssettingsregistrycore.h"
#include "qgsvectorlayer.h"
#include "qgswkbtypes.h"
#include "qgsmapmouseevent.h"
Expand Down Expand Up @@ -182,7 +183,7 @@ void TestQgsMapToolAddFeatureLineZ::testZ()
mCanvas->setCurrentLayer( mLayerLineZ );

// test with default Z value = 333
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 333 );
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 333 );

QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();
utils.mouseClick( 4, 0, Qt::LeftButton );
Expand All @@ -198,7 +199,7 @@ void TestQgsMapToolAddFeatureLineZ::testZ()
mLayerLine->undoStack()->undo();

// test with default Z value = 222
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 );
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 222 );

oldFids = utils.existingFeatureIds();
utils.mouseClick( 4, 0, Qt::LeftButton );
Expand All @@ -223,7 +224,7 @@ void TestQgsMapToolAddFeatureLineZ::testTopologicalEditingZ()
mCanvas->setCurrentLayer( mLayerTopoZ );

// test with default Z value = 333
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 333 );
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 333 );

QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();

Expand Down Expand Up @@ -283,7 +284,7 @@ void TestQgsMapToolAddFeatureLineZ::testZSnapping()
mCanvas->setCurrentLayer( mLayerLineZ );
oldFids = utils.existingFeatureIds();
// test with default Z value = 222
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 );
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 222 );
// snap a on a layer without ZM support
utils.mouseClick( 9, 9, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseClick( 8, 7, Qt::LeftButton );
Expand All @@ -305,7 +306,7 @@ void TestQgsMapToolAddFeatureLineZ::testZSnapping()
mCanvas->snappingUtils()->setConfig( cfg );

// create geometry will be snapped
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 123 );
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 123 );

oldFids = utils.existingFeatureIds();
utils.mouseClick( 20, 20, Qt::LeftButton, Qt::KeyboardModifiers(), true );
Expand All @@ -317,7 +318,7 @@ void TestQgsMapToolAddFeatureLineZ::testZSnapping()
wkt = "LineStringZ (20 20 123, 30 20 123)";
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 321 );
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( 321 );
oldFids = utils.existingFeatureIds();
utils.mouseClick( 25, 20, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseClick( 25, 25, Qt::LeftButton );
Expand Down

0 comments on commit 09ca85c

Please sign in to comment.