Skip to content
Permalink
Browse files

Update widget state when scale locked state is changed from API

  • Loading branch information
troopa81 authored and nyalldawson committed Mar 31, 2021
1 parent 4638aa9 commit f4028405544b4a466d3b57c67fd5b1a381cf578d
@@ -1040,6 +1040,18 @@ Emits current mouse position
Emitted when the scale of the map changes
%End

void scaleLockChanged( bool locked );
%Docstring
Emitted when the scale locked state of the map changes

:param locked: true if the scale is locked

.. versionadded:: 3.18

.. seealso:: :py:func:`setScaleLocked`
%End


void extentsChanged();
%Docstring
Emitted when the extents of the map change
@@ -3816,9 +3816,9 @@ void QgisApp::createStatusBar()
mMagnifierWidget->setObjectName( QStringLiteral( "mMagnifierWidget" ) );
mMagnifierWidget->setFont( statusBarFont );
connect( mMapCanvas, &QgsMapCanvas::magnificationChanged, mMagnifierWidget, &QgsStatusBarMagnifierWidget::updateMagnification );
connect( mMapCanvas, &QgsMapCanvas::scaleLockChanged, mMagnifierWidget, &QgsStatusBarMagnifierWidget::updateScaleLock );
connect( mMagnifierWidget, &QgsStatusBarMagnifierWidget::magnificationChanged, mMapCanvas, [ = ]( double factor ) { mMapCanvas->setMagnificationFactor( factor ); } );
connect( mMagnifierWidget, &QgsStatusBarMagnifierWidget::scaleLockChanged, mMapCanvas, &QgsMapCanvas::setScaleLocked );
connect( mMagnifierWidget, &QgsStatusBarMagnifierWidget::scaleLockChanged, mScaleWidget, &QgsStatusBarScaleWidget::setLocked );
mMagnifierWidget->updateMagnification( QSettings().value( QStringLiteral( "/qgis/magnifier_factor_default" ), 1.0 ).toDouble() );
mStatusBar->addPermanentWidget( mMagnifierWidget, 0 );

@@ -93,6 +93,11 @@ void QgsStatusBarMagnifierWidget::updateMagnification( double factor )
mSpinBox->setValue( factor * 100 );
}

void QgsStatusBarMagnifierWidget::updateScaleLock( bool locked )
{
mLockButton->setChecked( locked );
}

void QgsStatusBarMagnifierWidget::setMagnification( double value )
{
emit magnificationChanged( value / 100 );
@@ -56,6 +56,12 @@ class APP_EXPORT QgsStatusBarMagnifierWidget : public QWidget
//! will be triggered from map canvas changes (from mouse wheel, zoom)
void updateMagnification( double factor );

/**
* Will be triggered from map canvas API changes
* \param locked true if the scale is locked
* \since 3.18
*/
void updateScaleLock( bool locked );

private slots:
//! will be triggered form user input in spin box
@@ -60,6 +60,7 @@ QgsStatusBarScaleWidget::QgsStatusBarScaleWidget( QgsMapCanvas *canvas, QWidget
setLayout( mLayout );

connect( mScale, &QgsScaleComboBox::scaleChanged, this, &QgsStatusBarScaleWidget::userScale );
connect( mMapCanvas, &QgsMapCanvas::scaleLockChanged, this, &QgsStatusBarScaleWidget::setLocked );
}

void QgsStatusBarScaleWidget::setScale( double scale )
@@ -2123,7 +2123,11 @@ void QgsMapCanvas::zoomWithCenter( int x, int y, bool zoomIn )

void QgsMapCanvas::setScaleLocked( bool isLocked )
{
mScaleLocked = isLocked;
if ( mScaleLocked != isLocked )
{
mScaleLocked = isLocked;
emit scaleLockChanged( mScaleLocked );
}
}

void QgsMapCanvas::mouseMoveEvent( QMouseEvent *e )
@@ -953,6 +953,15 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Emitted when the scale of the map changes
void scaleChanged( double );

/**
* Emitted when the scale locked state of the map changes
* \param locked true if the scale is locked
* \since QGIS 3.18
* \see setScaleLocked
*/
void scaleLockChanged( bool locked );


//! Emitted when the extents of the map change
void extentsChanged();

0 comments on commit f402840

Please sign in to comment.