Skip to content
Permalink
Browse files
Merge pull request #42986 from lbartoletti/add_default_m_value
[API][UI] Add default M value
  • Loading branch information
pblottiere committed May 3, 2021
2 parents 619036e + 09ca85c commit f00f89eb31811111007894c0d7309b49f529de59
@@ -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;
@@ -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:
@@ -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() );

@@ -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() );
@@ -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;
@@ -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.
@@ -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 );

@@ -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 )
{
@@ -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
@@ -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;
}
@@ -220,7 +220,7 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

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

f.setGeometry( g );
@@ -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(),
@@ -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 );
@@ -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>
@@ -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)
@@ -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)
@@ -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.