Skip to content
Permalink
Browse files

Merge pull request #8310 from borysiasty/scale_lock_button

Move the scale lock button from the QgsStatusBarScaleWidget to QgsStatusBarMagnifierWidget
  • Loading branch information
borysiasty committed Oct 25, 2018
2 parents 2633006 + 83065a4 commit 531f3663726c469e8b4b3a73c02d1495ebd87066
@@ -3034,7 +3034,6 @@ void QgisApp::createStatusBar()
mScaleWidget = new QgsStatusBarScaleWidget( mMapCanvas, mStatusBar );
mScaleWidget->setObjectName( QStringLiteral( "mScaleWidget" ) );
mScaleWidget->setFont( statusBarFont );
connect( mScaleWidget, &QgsStatusBarScaleWidget::scaleLockChanged, mMapCanvas, &QgsMapCanvas::setScaleLocked );
mStatusBar->addPermanentWidget( mScaleWidget, 0 );

// zoom widget
@@ -3043,6 +3042,8 @@ void QgisApp::createStatusBar()
mMagnifierWidget->setFont( statusBarFont );
connect( mMapCanvas, &QgsMapCanvas::magnificationChanged, mMagnifierWidget, &QgsStatusBarMagnifierWidget::updateMagnification );
connect( mMagnifierWidget, &QgsStatusBarMagnifierWidget::magnificationChanged, mMapCanvas, &QgsMapCanvas::setMagnificationFactor );
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 );

@@ -17,6 +17,7 @@
#include <QFont>
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>

#include "qgssettings.h"
#include "qgsapplication.h"
@@ -55,8 +56,18 @@ QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget( QWidget *parent )

connect( mSpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsStatusBarMagnifierWidget::setMagnification );

mLockButton = new QToolButton();
mLockButton->setIcon( QIcon( QgsApplication::getThemeIcon( "/lockedGray.svg" ) ) );
mLockButton->setToolTip( tr( "Lock the scale to use magnifier to zoom in or out." ) );
mLockButton->setCheckable( true );
mLockButton->setChecked( false );
mLockButton->setAutoRaise( true );

connect( mLockButton, &QAbstractButton::toggled, this, &QgsStatusBarMagnifierWidget::scaleLockChanged );

// layout
mLayout = new QHBoxLayout( this );
mLayout->addWidget( mLockButton );
mLayout->addWidget( mLabel );
mLayout->addWidget( mSpinBox );
mLayout->setContentsMargins( 0, 0, 0, 0 );
@@ -20,6 +20,7 @@
class QLabel;
class QFont;
class QHBoxLayout;
class QToolButton;
class QgsDoubleSpinBox;

#include <QWidget>
@@ -63,11 +64,13 @@ class APP_EXPORT QgsStatusBarMagnifierWidget : public QWidget
signals:
void magnificationChanged( double factor );

void scaleLockChanged( bool );

private:
QHBoxLayout *mLayout = nullptr;
QLabel *mLabel = nullptr;
QgsDoubleSpinBox *mSpinBox = nullptr;
QToolButton *mLockButton = nullptr;
};

#endif
@@ -17,7 +17,6 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QToolButton>
#include <QValidator>

#include "qgsstatusbarscalewidget.h"
@@ -49,28 +48,17 @@ QgsStatusBarScaleWidget::QgsStatusBarScaleWidget( QgsMapCanvas *canvas, QWidget
mScale->setWhatsThis( tr( "Displays the current map scale" ) );
mScale->setToolTip( tr( "Current map scale (formatted as x:y)" ) );

mLockButton = new QToolButton();
mLockButton->setIcon( QIcon( QgsApplication::getThemeIcon( "/lockedGray.svg" ) ) );
mLockButton->setToolTip( tr( "Lock the scale to use magnifier to zoom in or out." ) );
mLockButton->setCheckable( true );
mLockButton->setChecked( false );
mLockButton->setAutoRaise( true );

// layout
mLayout = new QHBoxLayout( this );
mLayout->addWidget( mLabel );
mLayout->addWidget( mScale );
mLayout->addWidget( mLockButton );
mLayout->setContentsMargins( 0, 0, 0, 0 );
mLayout->setAlignment( Qt::AlignRight );
mLayout->setSpacing( 0 );

setLayout( mLayout );

connect( mScale, &QgsScaleComboBox::scaleChanged, this, &QgsStatusBarScaleWidget::userScale );

connect( mLockButton, &QAbstractButton::toggled, this, &QgsStatusBarScaleWidget::scaleLockChanged );
connect( mLockButton, &QAbstractButton::toggled, mScale, &QWidget::setDisabled );
}

void QgsStatusBarScaleWidget::setScale( double scale )
@@ -87,7 +75,12 @@ void QgsStatusBarScaleWidget::setScale( double scale )

bool QgsStatusBarScaleWidget::isLocked() const
{
return mLockButton->isChecked();
return !mScale->isEnabled();
}

void QgsStatusBarScaleWidget::setLocked( bool state )
{
mScale->setDisabled( state );
}

void QgsStatusBarScaleWidget::setFont( const QFont &font )
@@ -20,7 +20,6 @@
class QFont;
class QHBoxLayout;
class QLabel;
class QToolButton;
class QValidator;

class QgsMapCanvas;
@@ -46,6 +45,13 @@ class APP_EXPORT QgsStatusBarScaleWidget : public QWidget
*/
void setScale( double scale );

/**
* Lock the scale widget.
* \param state the lock state
* \since QGIS 3.4
*/
void setLocked( bool state );

/**
* \brief isLocked check if the scale should be locked to use magnifier instead of scale to zoom in/out
* \returns True if the scale shall be locked
@@ -64,13 +70,9 @@ class APP_EXPORT QgsStatusBarScaleWidget : public QWidget
private slots:
void userScale() const;

signals:
void scaleLockChanged( bool );

private:
QgsMapCanvas *mMapCanvas = nullptr;
QHBoxLayout *mLayout = nullptr;
QToolButton *mLockButton = nullptr;

//! Widget that will live on the statusbar to display "scale 1:"
QLabel *mLabel = nullptr;

0 comments on commit 531f366

Please sign in to comment.
You can’t perform that action at this time.