Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add widget for setting profile tolerance
  • Loading branch information
nyalldawson committed Jan 27, 2023
1 parent 9caa96f commit f22cd83
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/layout/qgslayoutitem.sip.in
Expand Up @@ -255,6 +255,7 @@ Base class for graphical items within a :py:class:`QgsLayout`.
UndoArrowHeadWidth,
UndoArrowHeadFillColor,
UndoArrowHeadStrokeColor,
UndoElevationProfileTolerance,
UndoElevationProfileChartBackground,
UndoElevationProfileChartBorder,
UndoElevationProfileDistanceMajorGridlines,
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/layout/qgslayoutobject.sip.in
Expand Up @@ -196,6 +196,7 @@ A base class for objects which belong to a layout.
MapCrs,
StartDateTime,
EndDateTime,
ElevationProfileTolerance,
ElevationProfileDistanceMajorInterval,
ElevationProfileDistanceMinorInterval,
ElevationProfileDistanceLabelInterval,
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutitem.h
Expand Up @@ -306,6 +306,7 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
UndoArrowHeadWidth, //!< Arrow head width
UndoArrowHeadFillColor, //!< Arrow head fill color
UndoArrowHeadStrokeColor, //!< Arrow head stroke color
UndoElevationProfileTolerance, //!< Change elevation profile distance tolerance
UndoElevationProfileChartBackground, //!< Change elevation profile chart background
UndoElevationProfileChartBorder, //!< Change elevation profile chart border
UndoElevationProfileDistanceMajorGridlines, //!< Change elevation profile distance axis major gridlines
Expand Down
10 changes: 4 additions & 6 deletions src/core/layout/qgslayoutobject.cpp
Expand Up @@ -15,15 +15,11 @@
* *
***************************************************************************/

#include <QPainter>

#include "qgslayout.h"
#include "qgslayoutrendercontext.h"
#include "qgslayoutreportcontext.h"
#include "qgslayoutobject.h"
#include "qgsfeedback.h"
#include "qgsexpressioncontextutils.h"
#include "qgslayout.h"

#include <QPainter>

QgsPropertiesDefinition QgsLayoutObject::sPropertyDefinitions;

Expand Down Expand Up @@ -113,6 +109,7 @@ void QgsLayoutObject::initPropertyDefinitions()
{ QgsLayoutObject::ScalebarHeight, QgsPropertyDefinition( "dataDefinedScalebarHeight", QObject::tr( "Scalebar height in mm" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsLayoutObject::ScalebarSubdivisionHeight, QgsPropertyDefinition( "dataDefinedScalebarSubdivisionHeight", QObject::tr( "Subdivision height in mm" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsLayoutObject::ScalebarRightSegmentSubdivisions, QgsPropertyDefinition( "dataDefinedScalebarRightSegmentSubdivisions", QObject::tr( "Number of subdivisions in segments to the right of 0" ), QgsPropertyDefinition::IntegerPositive ) },
{ QgsLayoutObject::ElevationProfileTolerance, QgsPropertyDefinition( "dataDefinedElevationProfileTolerance", QObject::tr( "Tolerance" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsLayoutObject::ElevationProfileDistanceMajorInterval, QgsPropertyDefinition( "dataDefinedElevationProfileDistanceMajorInterval", QObject::tr( "Major grid line interval for elevation axis" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsLayoutObject::ElevationProfileDistanceMinorInterval, QgsPropertyDefinition( "dataDefinedElevationProfileDistanceMinorInterval", QObject::tr( "Minor grid line interval for elevation axis" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsLayoutObject::ElevationProfileDistanceLabelInterval, QgsPropertyDefinition( "dataDefinedElevationProfileDistanceLabelInterval", QObject::tr( "Label interval for elevation axis" ), QgsPropertyDefinition::DoublePositive ) },
Expand Down Expand Up @@ -209,6 +206,7 @@ bool QgsLayoutObject::propertyAssociatesWithParentMultiframe( QgsLayoutObject::D
case QgsLayoutObject::MapCrs:
case QgsLayoutObject::StartDateTime:
case QgsLayoutObject::EndDateTime:
case QgsLayoutObject::ElevationProfileTolerance:
case QgsLayoutObject::ElevationProfileDistanceMajorInterval:
case QgsLayoutObject::ElevationProfileDistanceMinorInterval:
case QgsLayoutObject::ElevationProfileDistanceLabelInterval:
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutobject.h
Expand Up @@ -224,6 +224,7 @@ class CORE_EXPORT QgsLayoutObject: public QObject, public QgsExpressionContextGe
MapCrs, //!< Map CRS
StartDateTime, //!< Temporal range's start DateTime
EndDateTime, //!< Temporal range's end DateTime
ElevationProfileTolerance, //!< Tolerance distance for elevation profiles (since QGIS 3.30)
ElevationProfileDistanceMajorInterval, //!< Major grid line interval for elevation profile distance axis (since QGIS 3.30)
ElevationProfileDistanceMinorInterval, //!< Minor grid line interval for elevation profile distance axis (since QGIS 3.30)
ElevationProfileDistanceLabelInterval, //!< Label interval for elevation profile distance axis (since QGIS 3.30)
Expand Down
20 changes: 20 additions & 0 deletions src/gui/layout/qgslayoutelevationprofilewidget.cpp
Expand Up @@ -67,6 +67,19 @@ QgsLayoutElevationProfileWidget::QgsLayoutElevationProfileWidget( QgsLayoutItemE
connect( mLayerTree.get(), &QgsLayerTree::layerOrderChanged, this, &QgsLayoutElevationProfileWidget::updateItemLayers );
connect( mLayerTree.get(), &QgsLayerTreeGroup::visibilityChanged, this, &QgsLayoutElevationProfileWidget::updateItemLayers );

mSpinTolerance->setClearValue( 0 );
connect( mSpinTolerance, qOverload< double >( &QDoubleSpinBox::valueChanged ), this, [ = ]( double value )
{
if ( !mProfile || mBlockChanges )
return;

mProfile->beginCommand( tr( "Change Profile Tolerance Distance" ), QgsLayoutItem::UndoElevationProfileTolerance );
mProfile->setTolerance( value );
mProfile->invalidateCache();
mProfile->update();
mProfile->endCommand();
} );

mSpinMinDistance->setClearValue( 0 );
connect( mSpinMinDistance, qOverload< double >( &QDoubleSpinBox::valueChanged ), this, [ = ]( double value )
{
Expand Down Expand Up @@ -376,6 +389,7 @@ QgsLayoutElevationProfileWidget::QgsLayoutElevationProfileWidget( QgsLayoutItemE
mProfile->endCommand();
} );

registerDataDefinedButton( mDDBtnTolerance, QgsLayoutObject::ElevationProfileTolerance );
registerDataDefinedButton( mDDBtnMinDistance, QgsLayoutObject::ElevationProfileMinimumDistance );
registerDataDefinedButton( mDDBtnMaxDistance, QgsLayoutObject::ElevationProfileMaximumDistance );
registerDataDefinedButton( mDDBtnMinElevation, QgsLayoutObject::ElevationProfileMinimumElevation );
Expand Down Expand Up @@ -462,7 +476,10 @@ void QgsLayoutElevationProfileWidget::copySettingsFromProfileCanvas( QgsElevatio
mBlockChanges++;

mProfile->setCrs( canvas->crs() );

mSpinTolerance->setValue( canvas->tolerance() );
mProfile->setTolerance( canvas->tolerance() );

if ( const QgsCurve *curve = canvas->profileCurve() )
mProfile->setProfileCurve( curve->clone() );

Expand Down Expand Up @@ -557,6 +574,8 @@ void QgsLayoutElevationProfileWidget::setGuiElementValues()
{
mBlockChanges++;

mSpinTolerance->setValue( mProfile->tolerance() );

mSpinMinDistance->setValue( mProfile->plot()->xMinimum() );
mSpinMaxDistance->setValue( mProfile->plot()->xMaximum() );
mSpinMinElevation->setValue( mProfile->plot()->yMinimum() );
Expand Down Expand Up @@ -599,6 +618,7 @@ void QgsLayoutElevationProfileWidget::setGuiElementValues()
}
mLayerTree->reorderGroupLayers( mProfile->layers() );

updateDataDefinedButton( mDDBtnTolerance );
updateDataDefinedButton( mDDBtnMinDistance );
updateDataDefinedButton( mDDBtnMaxDistance );
updateDataDefinedButton( mDDBtnMinElevation );
Expand Down
35 changes: 34 additions & 1 deletion src/ui/layout/qgslayoutelevationprofilewidgetbase.ui
Expand Up @@ -78,7 +78,7 @@
<x>0</x>
<y>0</y>
<width>548</width>
<height>1267</height>
<height>1345</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -107,6 +107,39 @@
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="groupChartRanges_2">
<property name="title">
<string>Profile Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_5" columnstretch="1,2,0">
<item row="0" column="1">
<widget class="QgsDoubleSpinBox" name="mSpinTolerance">
<property name="decimals">
<number>6</number>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QgsPropertyOverrideButton" name="mDDBtnTolerance">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_27">
<property name="text">
<string>Tolerance</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="groupChartRanges">
<property name="title">
Expand Down

0 comments on commit f22cd83

Please sign in to comment.