Use nicer signal for scale ratio widget updates

This commit is contained in:
Nyall Dawson 2025-08-14 12:59:15 +10:00
parent 6d8ac234a1
commit 3def1fbdf6
No known key found for this signature in database
GPG Key ID: AEA7D60D3DF12896
7 changed files with 50 additions and 18 deletions

View File

@ -1,6 +1,6 @@
# The following has been generated automatically from src/gui/elevation/qgselevationprofilecanvas.h
try:
QgsElevationProfileCanvas.__attribute_docs__ = {'activeJobCountChanged': 'Emitted when the number of active background jobs changes.\n', 'canvasPointHovered': 'Emitted when the mouse hovers over the specified point (in canvas\ncoordinates).\n\nThe ``profilePoint`` argument gives the hovered profile point, which may\nbe snapped.\n'}
QgsElevationProfileCanvas.__attribute_docs__ = {'activeJobCountChanged': 'Emitted when the number of active background jobs changes.\n', 'canvasPointHovered': 'Emitted when the mouse hovers over the specified point (in canvas\ncoordinates).\n\nThe ``profilePoint`` argument gives the hovered profile point, which may\nbe snapped.\n', 'scaleChanged': 'Emitted when the plot scale is changed.\n\n.. versionadded:: 4.0\n'}
QgsElevationProfileCanvas.__overridden_methods__ = ['crs', 'toMapCoordinates', 'toCanvasCoordinates', 'resizeEvent', 'paintEvent', 'panContentsBy', 'centerPlotOn', 'scalePlot', 'snapToPlot', 'zoomToRect', 'wheelZoom', 'mouseMoveEvent', 'refresh']
QgsElevationProfileCanvas.__signal_arguments__ = {'activeJobCountChanged': ['count: int'], 'canvasPointHovered': ['point: QgsPointXY', 'profilePoint: QgsProfilePoint']}
QgsElevationProfileCanvas.__group__ = ['elevation']

View File

@ -328,6 +328,13 @@ coordinates).
The ``profilePoint`` argument gives the hovered profile point, which may
be snapped.
%End
void scaleChanged();
%Docstring
Emitted when the plot scale is changed.
.. versionadded:: 4.0
%End
public slots:

View File

@ -1,6 +1,6 @@
# The following has been generated automatically from src/gui/elevation/qgselevationprofilecanvas.h
try:
QgsElevationProfileCanvas.__attribute_docs__ = {'activeJobCountChanged': 'Emitted when the number of active background jobs changes.\n', 'canvasPointHovered': 'Emitted when the mouse hovers over the specified point (in canvas\ncoordinates).\n\nThe ``profilePoint`` argument gives the hovered profile point, which may\nbe snapped.\n'}
QgsElevationProfileCanvas.__attribute_docs__ = {'activeJobCountChanged': 'Emitted when the number of active background jobs changes.\n', 'canvasPointHovered': 'Emitted when the mouse hovers over the specified point (in canvas\ncoordinates).\n\nThe ``profilePoint`` argument gives the hovered profile point, which may\nbe snapped.\n', 'scaleChanged': 'Emitted when the plot scale is changed.\n\n.. versionadded:: 4.0\n'}
QgsElevationProfileCanvas.__overridden_methods__ = ['crs', 'toMapCoordinates', 'toCanvasCoordinates', 'resizeEvent', 'paintEvent', 'panContentsBy', 'centerPlotOn', 'scalePlot', 'snapToPlot', 'zoomToRect', 'wheelZoom', 'mouseMoveEvent', 'refresh']
QgsElevationProfileCanvas.__signal_arguments__ = {'activeJobCountChanged': ['count: int'], 'canvasPointHovered': ['point: QgsPointXY', 'profilePoint: QgsProfilePoint']}
QgsElevationProfileCanvas.__group__ = ['elevation']

View File

@ -328,6 +328,13 @@ coordinates).
The ``profilePoint`` argument gives the hovered profile point, which may
be snapped.
%End
void scaleChanged();
%Docstring
Emitted when the plot scale is changed.
.. versionadded:: 4.0
%End
public slots:

View File

@ -355,15 +355,6 @@ QgsElevationProfileWidget::QgsElevationProfileWidget( const QString &name )
mOptionsMenu->addAction( mLockRatioAction );
mScaleRatioSettingsAction = new QgsElevationProfileScaleRatioWidgetSettingsAction( mOptionsMenu );
connect( mScaleRatioSettingsAction->scaleRatioWidget(), &QgsScaleComboBox::scaleChanged, this, [this]( double scale ) {
const double distanceToElevationRatio = 1.0 / scale;
if ( mBlockScaleRatioChanges )
return;
mCanvas->setAxisScaleRatio( distanceToElevationRatio );
createOrUpdateRubberBands();
scheduleUpdate();
} );
mOptionsMenu->addAction( mScaleRatioSettingsAction );
@ -457,13 +448,6 @@ QgsElevationProfileWidget::QgsElevationProfileWidget( const QString &name )
toolBar->addWidget( mBtnOptions );
connect( mOptionsMenu, &QMenu::aboutToShow, this, [this] {
mBlockScaleRatioChanges++;
const double distanceToElevationScaleRatio = mCanvas->axisScaleRatio();
mScaleRatioSettingsAction->scaleRatioWidget()->setScale( 1.0 / distanceToElevationScaleRatio );
mBlockScaleRatioChanges--;
} );
mProgressPendingJobs = new QProgressBar( this );
mProgressPendingJobs->setRange( 0, 0 );
mProgressPendingJobs->hide();
@ -518,6 +502,23 @@ QgsElevationProfileWidget::QgsElevationProfileWidget( const QString &name )
connect( QgsProject::instance()->elevationProperties(), &QgsProjectElevationProperties::changed, this, &QgsElevationProfileWidget::onProjectElevationPropertiesChanged );
connect( QgsProject::instance(), &QgsProject::crs3DChanged, this, &QgsElevationProfileWidget::onProjectElevationPropertiesChanged );
connect( mCanvas, &QgsElevationProfileCanvas::scaleChanged, this, [this] {
mBlockScaleRatioChanges++;
const double distanceToElevationScaleRatio = mCanvas->axisScaleRatio();
mScaleRatioSettingsAction->scaleRatioWidget()->setScale( 1.0 / distanceToElevationScaleRatio );
mBlockScaleRatioChanges--;
} );
connect( mScaleRatioSettingsAction->scaleRatioWidget(), &QgsScaleComboBox::scaleChanged, this, [this]( double scale ) {
const double distanceToElevationRatio = 1.0 / scale;
if ( mBlockScaleRatioChanges )
return;
mCanvas->setAxisScaleRatio( distanceToElevationRatio );
createOrUpdateRubberBands();
scheduleUpdate();
} );
updateCanvasLayers();
}

View File

@ -639,6 +639,7 @@ void QgsElevationProfileCanvas::setDistanceUnit( Qgis::DistanceUnit unit )
mPlotItem->setXMinimum( oldMin / mPlotItem->mXScaleFactor );
mPlotItem->setXMaximum( oldMax / mPlotItem->mXScaleFactor );
mPlotItem->updatePlot();
emit scaleChanged();
}
void QgsElevationProfileCanvas::setBackgroundColor( const QColor &color )
@ -700,6 +701,7 @@ void QgsElevationProfileCanvas::setLockAxisScales( bool lock )
refineResults();
mPlotItem->updatePlot();
emit plotAreaChanged();
emit scaleChanged();
}
}
@ -727,6 +729,7 @@ void QgsElevationProfileCanvas::setAxisScaleRatio( double scale )
refineResults();
mPlotItem->updatePlot();
emit plotAreaChanged();
emit scaleChanged();
}
QgsPointXY QgsElevationProfileCanvas::snapToPlot( QPoint point )
@ -774,6 +777,7 @@ void QgsElevationProfileCanvas::scalePlot( double xFactor, double yFactor )
refineResults();
mPlotItem->updatePlot();
emit plotAreaChanged();
emit scaleChanged();
}
void QgsElevationProfileCanvas::zoomToRect( const QRectF &rect )
@ -798,6 +802,7 @@ void QgsElevationProfileCanvas::zoomToRect( const QRectF &rect )
refineResults();
mPlotItem->updatePlot();
emit plotAreaChanged();
emit scaleChanged();
}
void QgsElevationProfileCanvas::wheelZoom( QWheelEvent *event )
@ -854,6 +859,7 @@ void QgsElevationProfileCanvas::wheelZoom( QWheelEvent *event )
scalePlot( 1 / zoomFactor );
}
emit plotAreaChanged();
emit scaleChanged();
}
void QgsElevationProfileCanvas::mouseMoveEvent( QMouseEvent *e )
@ -1226,6 +1232,8 @@ void QgsElevationProfileCanvas::resizeEvent( QResizeEvent *event )
mPlotItem->updateRect();
mCrossHairsItem->updateRect();
emit scaleChanged();
}
void QgsElevationProfileCanvas::paintEvent( QPaintEvent *event )
@ -1344,6 +1352,7 @@ void QgsElevationProfileCanvas::zoomFull()
refineResults();
mPlotItem->updatePlot();
emit plotAreaChanged();
emit scaleChanged();
}
void QgsElevationProfileCanvas::setVisiblePlotRange( double minimumDistance, double maximumDistance, double minimumElevation, double maximumElevation )
@ -1360,6 +1369,7 @@ void QgsElevationProfileCanvas::setVisiblePlotRange( double minimumDistance, dou
refineResults();
mPlotItem->updatePlot();
emit plotAreaChanged();
emit scaleChanged();
}
QgsDoubleRange QgsElevationProfileCanvas::visibleDistanceRange() const

View File

@ -322,6 +322,13 @@ class GUI_EXPORT QgsElevationProfileCanvas : public QgsPlotCanvas
*/
void canvasPointHovered( const QgsPointXY &point, const QgsProfilePoint &profilePoint );
/**
* Emitted when the plot scale is changed.
*
* \since QGIS 4.0
*/
void scaleChanged();
public slots:
/**