Skip to content

Commit

Permalink
Merge pull request #42986 from lbartoletti/add_default_m_value
Browse files Browse the repository at this point in the history
[API][UI] Add default M value
  • Loading branch information
pblottiere committed May 3, 2021
2 parents 619036e + 09ca85c commit f00f89e
Show file tree
Hide file tree
Showing 23 changed files with 1,478 additions and 222 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -114,6 +114,8 @@ The development version

static const double DEFAULT_Z_COORDINATE;

static const double DEFAULT_M_COORDINATE;

static const double UI_SCALE_FACTOR;

static const double DEFAULT_SNAP_TOLERANCE;
Expand Down
12 changes: 10 additions & 2 deletions python/gui/auto_generated/qgsmaptooledit.sip.in
Expand Up @@ -25,8 +25,16 @@ Base class for map tools that edit vector geometry

double defaultZValue() const;
%Docstring
Returns default Z value
Use for set Z coordinate to new vertex for 2.5d geometries
Returns default Z value.
Used for setting Z coordinate to new vertex.
%End

double defaultMValue() const;
%Docstring
Returns default M value.
Used for setting M coordinate to new vertex.

.. versionadded:: 3.20
%End

protected:
Expand Down
6 changes: 6 additions & 0 deletions src/app/options/qgsoptions.cpp
Expand Up @@ -1072,6 +1072,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
mDefaultZValueSpinBox->setValue( QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.value() );
mDefaultZValueSpinBox->setClearValue( QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.defaultValue() );

mDefaultMValueSpinBox->setValue(
mSettings->value( QStringLiteral( "/qgis/digitizing/default_m_value" ), Qgis::DEFAULT_M_COORDINATE ).toDouble()
);
mDefaultMValueSpinBox->setClearValue( Qgis::DEFAULT_M_COORDINATE );

//default snap mode
mSnappingEnabledDefault->setChecked( QgsSettingsRegistryCore::settingsDigitizingDefaultSnapEnabled.value() );

Expand Down Expand Up @@ -1752,6 +1757,7 @@ void QgsOptions::saveOptions()
QgsSettingsRegistryCore::settingsDigitizingLineGhost.setValue( mLineGhostCheckBox->isChecked() );

QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.setValue( mDefaultZValueSpinBox->value() );
QgsSettingsRegistryCore::settingsDigitizingDefaultMValue.setValue( mDefaultMValueSpinBox->value() );

//default snap mode
QgsSettingsRegistryCore::settingsDigitizingDefaultSnapEnabled.setValue( mSnappingEnabledDefault->isChecked() );
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgis.cpp
Expand Up @@ -56,6 +56,8 @@ const double Qgis::SCALE_PRECISION = 0.9999999999;

const double Qgis::DEFAULT_Z_COORDINATE = 0.0;

const double Qgis::DEFAULT_M_COORDINATE = 0.0;

const double Qgis::DEFAULT_SNAP_TOLERANCE = 12.0;

const QgsTolerance::UnitType Qgis::DEFAULT_SNAP_UNITS = QgsTolerance::Pixels;
Expand Down
13 changes: 10 additions & 3 deletions src/core/qgis.h
Expand Up @@ -169,12 +169,19 @@ class CORE_EXPORT Qgis
static const double SCALE_PRECISION;

/**
* Default Z coordinate value for 2.5d geometry
* This value have to be assigned to the Z coordinate for the new 2.5d geometry vertex.
* \since QGIS 3.0
* Default Z coordinate value.
* This value have to be assigned to the Z coordinate for the vertex.
* \since QGIS 3.0
*/
static const double DEFAULT_Z_COORDINATE;

/**
* Default M coordinate value.
* This value have to be assigned to the M coordinate for the vertex.
* \since QGIS 3.20
*/
static const double DEFAULT_M_COORDINATE;

/**
* UI scaling factor. This should be applied to all widget sizes obtained from font metrics,
* to account for differences in the default font sizes across different platforms.
Expand Down
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
9 changes: 7 additions & 2 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -464,7 +464,7 @@ int QgsMapToolCapture::nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint
if ( QgsWkbTypes::hasZ( vlayer->wkbType() ) )
layerPoint.addZValue( defaultZValue() );
if ( QgsWkbTypes::hasM( vlayer->wkbType() ) )
layerPoint.addMValue( 0.0 );
layerPoint.addMValue( defaultMValue() );
}
catch ( QgsCsException &cse )
{
Expand Down Expand Up @@ -515,7 +515,7 @@ int QgsMapToolCapture::fetchLayerPoint( const QgsPointLocator::Match &match, Qgs
if ( QgsWkbTypes::hasZ( vlayer->wkbType() ) && !layerPoint.is3D() )
layerPoint.addZValue( defaultZValue() );
if ( QgsWkbTypes::hasM( vlayer->wkbType() ) && !layerPoint.isMeasure() )
layerPoint.addMValue( 0.0 );
layerPoint.addMValue( defaultMValue() );
}

// ZM support depends on the target layer
Expand Down Expand Up @@ -1007,6 +1007,11 @@ QgsPoint QgsMapToolCapture::mapPoint( const QgsPointXY &point ) const
{
newPoint.setZ( defaultZValue() );
}
// set m value if necessary
if ( QgsWkbTypes::hasM( newPoint.wkbType() ) )
{
newPoint.setM( defaultMValue() );
}

return newPoint;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptooldigitizefeature.cpp
Expand Up @@ -220,7 +220,7 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

if ( QgsWkbTypes::hasM( layerWKBType ) )
{
g.get()->addMValue();
g.get()->addMValue( defaultMValue() );
}

f.setGeometry( g );
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmaptooledit.cpp
Expand Up @@ -39,6 +39,11 @@ double QgsMapToolEdit::defaultZValue() const
return QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.value();
}

double QgsMapToolEdit::defaultMValue() const
{
return QgsSettings().value( QStringLiteral( "/qgis/digitizing/default_m_value" ), Qgis::DEFAULT_M_COORDINATE ).toDouble();
}

QColor QgsMapToolEdit::digitizingStrokeColor()
{
return QColor( QgsSettingsRegistryCore::settingsDigitizingLineColorRed.value(),
Expand Down
12 changes: 10 additions & 2 deletions src/gui/qgsmaptooledit.h
Expand Up @@ -39,11 +39,19 @@ class GUI_EXPORT QgsMapToolEdit: public QgsMapTool
Flags flags() const override { return QgsMapTool::EditTool; }

/**
* Returns default Z value
* Use for set Z coordinate to new vertex for 2.5d geometries
* Returns default Z value.
* Used for setting Z coordinate to new vertex.
*/
double defaultZValue() const;

/**
* Returns default M value.
* Used for setting M coordinate to new vertex.
*
* \since QGIS 3.20
*/
double defaultMValue() const;

private slots:
//! Vector layers' editingStopped SIGNAL will eventually trigger a clean
void connectLayers( const QList<QgsMapLayer *> &layers );
Expand Down
29 changes: 29 additions & 0 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -4356,8 +4356,37 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mDefaultMValueLabel">
<property name="text">
<string>Default M value</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QgsDoubleSpinBox" name="mDefaultZValueSpinBox">
<property name="toolTip">
<string>Default Z Value</string>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-999999.998999999952503</double>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QgsDoubleSpinBox" name="mDefaultMValueSpinBox">
<property name="toolTip">
<string>Default Measure Value</string>
</property>
<property name="decimals">
<number>3</number>
</property>
Expand Down
5 changes: 3 additions & 2 deletions tests/src/app/CMakeLists.txt
Expand Up @@ -64,8 +64,6 @@ ADD_QGIS_TEST(attributetabletest testqgsattributetable.cpp)
ADD_QGIS_TEST(applocatorfilters testqgsapplocatorfilters.cpp)
ADD_QGIS_TEST(decorationscalebar testqgsdecorationscalebar.cpp)
ADD_QGIS_TEST(fieldcalculatortest testqgsfieldcalculator.cpp)
ADD_QGIS_TEST(maptooladdfeatureline testqgsmaptooladdfeatureline.cpp)
ADD_QGIS_TEST(maptooladdfeaturepoint testqgsmaptooladdfeaturepoint.cpp)
ADD_QGIS_TEST(maptoolidentifyaction testqgsmaptoolidentifyaction.cpp)
ADD_QGIS_TEST(maptoollabel testqgsmaptoollabel.cpp)
ADD_QGIS_TEST(maptoolselect testqgsmaptoolselect.cpp)
Expand All @@ -90,3 +88,6 @@ ADD_QGIS_TEST(layoutvaliditychecks testqgsapplayoutvaliditychecks.cpp)
ADD_QGIS_TEST(meshcalculator testqgsmeshcalculatordialog.cpp)
ADD_QGIS_TEST(gpsinformationwidget testqgsgpsinformationwidget.cpp)
ADD_QGIS_TEST(labelpropertydialog testqgslabelpropertydialog.cpp)

add_subdirectory(maptooladdfeaturepoint)
add_subdirectory(maptooladdfeatureline)
61 changes: 61 additions & 0 deletions tests/src/app/maptooladdfeatureline/CMakeLists.txt
@@ -0,0 +1,61 @@
#####################################################
# Don't forget to include output directory, otherwise
# the UI file won't be wrapped!
get_filename_component(PARENT_DIR ../ ABSOLUTE)

include_directories(
${PARENT_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/test
${CMAKE_CURRENT_BINARY_DIR}
)

#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
#and should not be compiled twice. Trying to include
#them in will cause an error at build time

#No relinking and full RPATH for the install tree
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree

macro (ADD_QGIS_TEST TESTSRC)
set (TESTNAME ${TESTSRC})
string(REPLACE "test" "" TESTNAME ${TESTNAME})
string(REPLACE "qgs" "qgis_" TESTNAME ${TESTNAME})
string(REPLACE ".cpp" "" TESTNAME ${TESTNAME})
add_executable(${TESTNAME} ${TESTSRC} ${util_SRCS})
target_compile_features(${TESTNAME} PRIVATE cxx_std_17)
target_link_libraries(${TESTNAME}
${Qt5Core_LIBRARIES}
${Qt5Xml_LIBRARIES}
${Qt5Sql_LIBRARIES}
${Qt5Svg_LIBRARIES}
${Qt5Test_LIBRARIES}
${PROJ_LIBRARY}
${GEOS_LIBRARY}
${GDAL_LIBRARY}
${QWT_LIBRARY}
qgis_core
qgis_gui
qgis_analysis
qgis_app)
add_test(${TESTNAME} ${CMAKE_BINARY_DIR}/output/bin/${TESTNAME} -maxwarnings 10000)
#set_target_properties(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )
endmacro (ADD_QGIS_TEST)

#############################################################
# Tests:

set(TESTS
testqgsmaptooladdfeatureline.cpp
testqgsmaptooladdfeaturelinez.cpp
testqgsmaptooladdfeaturelinem.cpp
testqgsmaptooladdfeaturelinezm.cpp
)

foreach(TESTSRC ${TESTS})
ADD_QGIS_TEST(${TESTSRC})
endforeach(TESTSRC)

0 comments on commit f00f89e

Please sign in to comment.