Skip to content

Commit cf99817

Browse files
committed
allow to lock scale to use magnification to zoom in/out
this also removes the option for different behavior of mouse wheel
1 parent 69a1718 commit cf99817

14 files changed

+491
-264
lines changed

python/core/qgsmapsettings.sip

+9-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ class QgsMapSettings
3939
//! Set DPI used for conversion between real world units (e.g. mm) and pixels
4040
void setOutputDpi( int dpi );
4141

42-
//! Set the magnification factor.
43-
//! @note added in 2.16
44-
void setMagnificationFactor( double factor );
45-
//! Return the magnification factor.
42+
43+
/**
44+
* @brief setMagnificationFactor set the magnification factor
45+
* @param factor the factor of magnification
46+
* @note added in 2.16
47+
*/
48+
void setMagnificationFactor( double factor );
49+
50+
//! Return the magnification factor.
4651
//! @note added in 2.16
4752
double magnificationFactor() const;
4853

python/gui/qgsmapcanvas.sip

+4
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,12 @@ class QgsMapCanvas : QGraphicsView
279279
QgsMapLayer* currentLayer();
280280

281281
//! set wheel action and zoom factor (should be greater than 1)
282+
//! @deprecated
282283
void setWheelAction( WheelAction action, double factor = 2 );
283284

285+
//! set the wheel zoom factor
286+
void setWheelFactor( double factor );
287+
284288
//! Zoom in with fixed factor
285289
void zoomIn();
286290

src/app/qgisapp.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -2136,13 +2136,15 @@ void QgisApp::createStatusBar()
21362136

21372137
mScaleWidget = new QgsStatusBarScaleWidget( mMapCanvas, statusBar() );
21382138
mScaleWidget->setFont( myFont );
2139+
connect( mScaleWidget, SIGNAL( scaleLockChanged( bool ) ), mMapCanvas, SLOT( setScaleLocked( bool ) ) );
21392140
statusBar()->addPermanentWidget( mScaleWidget, 0 );
21402141

21412142
// zoom widget
2142-
QSettings mySettings;
2143-
mMagnifierWidget = new QgsStatusBarMagnifierWidget( mMapCanvas, statusBar() );
2143+
mMagnifierWidget = new QgsStatusBarMagnifierWidget( statusBar() );
21442144
mMagnifierWidget->setFont( myFont );
2145-
mMagnifierWidget->setMagnificationLevel( mySettings.value( "/qgis/magnifier_level", 100 ).toInt() );
2145+
connect( mMapCanvas, SIGNAL( magnificationChanged( double ) ), mMagnifierWidget, SLOT( updateMagnification( double ) ) );
2146+
connect( mMagnifierWidget, SIGNAL( magnificationChanged( double ) ), mMapCanvas, SLOT( setMagnificationFactor( double ) ) );
2147+
mMagnifierWidget->updateMagnification( QSettings().value( "/qgis/magnifier_factor_default", 1.0 ).toDouble() );
21462148
statusBar()->addPermanentWidget( mMagnifierWidget, 0 );
21472149

21482150
if ( QgsMapCanvas::rotationEnabled() )
@@ -2689,9 +2691,8 @@ void QgisApp::createOverview()
26892691
// Anti Aliasing enabled by default as of QGIS 1.7
26902692
mMapCanvas->enableAntiAliasing( mySettings.value( "/qgis/enable_anti_aliasing", true ).toBool() );
26912693

2692-
int action = mySettings.value( "/qgis/wheel_action", 2 ).toInt();
26932694
double zoomFactor = mySettings.value( "/qgis/zoom_factor", 2 ).toDouble();
2694-
mMapCanvas->setWheelAction( static_cast< QgsMapCanvas::WheelAction >( action ), zoomFactor );
2695+
mMapCanvas->setWheelFactor( zoomFactor );
26952696

26962697
mMapCanvas->setCachingEnabled( mySettings.value( "/qgis/enable_render_caching", true ).toBool() );
26972698

@@ -8563,9 +8564,8 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString& currentPage )
85638564

85648565
mMapCanvas->enableAntiAliasing( mySettings.value( "/qgis/enable_anti_aliasing" ).toBool() );
85658566

8566-
int action = mySettings.value( "/qgis/wheel_action", 2 ).toInt();
85678567
double zoomFactor = mySettings.value( "/qgis/zoom_factor", 2 ).toDouble();
8568-
mMapCanvas->setWheelAction( static_cast< QgsMapCanvas::WheelAction >( action ), zoomFactor );
8568+
mMapCanvas->setWheelFactor( zoomFactor );
85698569

85708570
mMapCanvas->setCachingEnabled( mySettings.value( "/qgis/enable_render_caching", true ).toBool() );
85718571

@@ -8580,8 +8580,6 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString& currentPage )
85808580
layer->setLayerName( layer->originalName() );
85818581
}
85828582

8583-
mMagnifierWidget->setMagnificationLevel( mySettings.value( "/qgis/magnifier_level" ).toInt() );
8584-
85858583
//update any open compositions so they reflect new composer settings
85868584
//we have to push the changes to the compositions here, because compositions
85878585
//have no access to qgisapp and accordingly can't listen in to changes
@@ -8612,6 +8610,10 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString& currentPage )
86128610

86138611
mMapCanvas->setSegmentationTolerance( mySettings.value( "/qgis/segmentationTolerance", "0.01745" ).toDouble() );
86148612
mMapCanvas->setSegmentationToleranceType( QgsAbstractGeometryV2::SegmentationToleranceType( mySettings.value( "/qgis/segmentationToleranceType", "0" ).toInt() ) );
8613+
8614+
double factor = mySettings.value( "/qgis/magnifier_factor_default", 1.0 ).toDouble();
8615+
mMagnifierWidget->setDefaultFactor( factor );
8616+
mMagnifierWidget->updateMagnification( factor );
86158617
}
86168618

86178619
delete optionsDialog;

src/app/qgsoptions.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,14 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
607607
mSimplifyMaximumScaleComboBox->setScale( 1.0 / mSettings->value( "/qgis/simplifyMaxScale", 1 ).toFloat() );
608608

609609
// Magnifier
610-
doubleSpinBoxMagnifierDefault->setRange( 100, 1000 );
610+
double magnifierMin = 100 * mSettings->value( "/qgis/magnifier_factor_min", 0.1 ).toDouble();
611+
double magnifierMax = 100 * mSettings->value( "/qgis/magnifier_factor_max", 10 ).toDouble();
612+
double magnifierVal = 100 * mSettings->value( "/qgis/magnifier_factor_default", 1.0 ).toDouble();
613+
doubleSpinBoxMagnifierDefault->setRange( magnifierMin, magnifierMax );
611614
doubleSpinBoxMagnifierDefault->setSingleStep( 50 );
612615
doubleSpinBoxMagnifierDefault->setDecimals( 0 );
613616
doubleSpinBoxMagnifierDefault->setSuffix( "%" );
614-
doubleSpinBoxMagnifierDefault->setValue( mSettings->value( "/qgis/magnifier_level", 100 ).toInt() );
617+
doubleSpinBoxMagnifierDefault->setValue( magnifierVal );
615618

616619
// Default local simplification algorithm
617620
mSimplifyAlgorithmComboBox->addItem( tr( "Distance" ), ( int )QgsVectorSimplifyMethod::Distance );
@@ -731,7 +734,6 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
731734
}
732735
leTemplateFolder->setText( templateDirName );
733736

734-
cmbWheelAction->setCurrentIndex( mSettings->value( "/qgis/wheel_action", 2 ).toInt() );
735737
spinZoomFactor->setValue( mSettings->value( "/qgis/zoom_factor", 2 ).toDouble() );
736738

737739
// predefined scales for scale combobox
@@ -1224,7 +1226,7 @@ void QgsOptions::saveOptions()
12241226
mSettings->setValue( "/qgis/simplifyMaxScale", 1.0 / mSimplifyMaximumScaleComboBox->scale() );
12251227

12261228
// magnification
1227-
mSettings->setValue( "/qgis/magnifier_level", doubleSpinBoxMagnifierDefault->value() );
1229+
mSettings->setValue( "/qgis/magnifier_factor_default", doubleSpinBoxMagnifierDefault->value() / 100 );
12281230

12291231
//curve segmentation
12301232
int segmentationType = mToleranceTypeComboBox->itemData( mToleranceTypeComboBox->currentIndex() ).toInt();
@@ -1341,7 +1343,6 @@ void QgsOptions::saveOptions()
13411343
mSettings->setValue( "/qgis/default_measure_color_green", myColor.green() );
13421344
mSettings->setValue( "/qgis/default_measure_color_blue", myColor.blue() );
13431345

1344-
mSettings->setValue( "/qgis/wheel_action", cmbWheelAction->currentIndex() );
13451346
mSettings->setValue( "/qgis/zoom_factor", spinZoomFactor->value() );
13461347

13471348
//digitizing

src/app/qgsstatusbarmagnifierwidget.cpp

+18-31
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@
1717
#include <QFont>
1818
#include <QHBoxLayout>
1919
#include <QLabel>
20+
#include <QSettings>
2021

2122
#include <qgsapplication.h>
2223
#include "qgsstatusbarmagnifierwidget.h"
23-
#include "qgsmapcanvas.h"
2424
#include "qgsdoublespinbox.h"
2525

26-
QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget(QgsMapCanvas *canvas, QWidget* parent) :
27-
QWidget( parent ),
28-
mCanvas( canvas ),
29-
mMagnifier( 100 ),
30-
mMagnifierMin( 100 ),
31-
mMagnifierMax( 1000 )
26+
QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget( QWidget* parent ) :
27+
QWidget( parent )
3228
{
29+
QSettings settings;
30+
int minimumFactor = ( int ) 100 * settings.value( "/qgis/magnifier_factor_min", 0.1 ).toDouble();
31+
int maximumFactor = ( int ) 100 * settings.value( "/qgis/magnifier_factor_max", 10 ).toDouble();
32+
int defaultFactor = ( int ) 100 * settings.value( "/qgis/magnifier_factor_default", 1.0 ).toDouble();
33+
3334
// label
3435
mLabel = new QLabel( this );
3536
mLabel->setMinimumWidth( 10 );
@@ -41,17 +42,17 @@ QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget(QgsMapCanvas *canvas, Q
4142

4243
mSpinBox = new QgsDoubleSpinBox( this );
4344
mSpinBox->setSuffix( "%" );
44-
mSpinBox->setClearValue( mMagnifierMin );
4545
mSpinBox->setKeyboardTracking( false );
4646
mSpinBox->setMaximumWidth( 120 );
4747
mSpinBox->setDecimals( 0 );
48-
mSpinBox->setRange( mMagnifierMin, mMagnifierMax );
48+
mSpinBox->setRange( minimumFactor, maximumFactor );
4949
mSpinBox->setWrapping( false );
5050
mSpinBox->setSingleStep( 50 );
5151
mSpinBox->setToolTip( tr( "Magnifier level" ) );
52+
mSpinBox->setClearValueMode( QgsDoubleSpinBox::CustomValue );
53+
mSpinBox->setClearValue( defaultFactor );
5254

53-
connect( mSpinBox, SIGNAL( valueChanged( double ) ), this,
54-
SLOT( updateMagnifier() ) );
55+
connect( mSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( setMagnification( double ) ) );
5556

5657
// layout
5758
mLayout = new QHBoxLayout( this );
@@ -62,17 +63,15 @@ QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget(QgsMapCanvas *canvas, Q
6263
mLayout->setSpacing( 0 );
6364

6465
setLayout( mLayout );
65-
66-
updateMagnifier();
6766
}
6867

6968
QgsStatusBarMagnifierWidget::~QgsStatusBarMagnifierWidget()
7069
{
7170
}
7271

73-
double QgsStatusBarMagnifierWidget::magnificationLevel()
72+
void QgsStatusBarMagnifierWidget::setDefaultFactor( double factor )
7473
{
75-
return mMagnifier;
74+
mSpinBox->setClearValue(( int )100*factor );
7675
}
7776

7877
void QgsStatusBarMagnifierWidget::setFont( const QFont& myFont )
@@ -81,24 +80,12 @@ void QgsStatusBarMagnifierWidget::setFont( const QFont& myFont )
8180
mSpinBox->setFont( myFont );
8281
}
8382

84-
bool QgsStatusBarMagnifierWidget::setMagnificationLevel( int level )
83+
void QgsStatusBarMagnifierWidget::updateMagnification( double factor )
8584
{
86-
bool rc = false;
87-
88-
if ( level >= mMagnifierMin && level <= mMagnifierMax )
89-
{
90-
mSpinBox->setValue( level );
91-
rc = true;
92-
}
93-
94-
return rc;
85+
mSpinBox->setValue( factor * 100 );
9586
}
9687

97-
void QgsStatusBarMagnifierWidget::updateMagnifier()
88+
void QgsStatusBarMagnifierWidget::setMagnification( double value )
9889
{
99-
// get current data
100-
mMagnifier = mSpinBox->value();
101-
102-
// update map canvas
103-
mCanvas->setMagnificationFactor( mMagnifier / double( mMagnifierMin ) );
90+
emit magnificationChanged( value / 100 );
10491
}

src/app/qgsstatusbarmagnifierwidget.h

+12-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
class QLabel;
2121
class QFont;
2222
class QHBoxLayout;
23-
class QgsMapCanvas;
2423
class QgsDoubleSpinBox;
2524

2625
#include <QWidget>
@@ -40,39 +39,36 @@ class APP_EXPORT QgsStatusBarMagnifierWidget : public QWidget
4039
* @param parent is the parent widget
4140
* @param canvas the map canvas
4241
*/
43-
QgsStatusBarMagnifierWidget( QgsMapCanvas *canvas, QWidget* parent = 0 );
42+
QgsStatusBarMagnifierWidget( QWidget* parent = 0 );
4443

4544
/** Destructor */
4645
virtual ~QgsStatusBarMagnifierWidget();
4746

47+
void setDefaultFactor( double factor );
48+
4849
/** Set the font of the text
4950
* @param font the font to use
5051
*/
5152
void setFont( const QFont& font );
5253

53-
/** Returns the current magnification level
54-
* @return magnification level
55-
*/
56-
double magnificationLevel();
5754

58-
/** Set the magnification level
59-
* @param level the magnification level
60-
* @return true if the level is valid, false otherwise
61-
*/
62-
bool setMagnificationLevel( int level );
55+
public slots:
56+
//! will be triggered from map canvas changes (from mouse wheel, zoom)
57+
void updateMagnification( double factor );
58+
6359

6460
private slots:
61+
//! will be triggered form user input in spin box
62+
void setMagnification( double value );
63+
64+
signals:
65+
void magnificationChanged( double factor );
6566

66-
void updateMagnifier();
6767

6868
private:
69-
QgsMapCanvas *mCanvas;
7069
QHBoxLayout *mLayout;
7170
QLabel *mLabel;
7271
QgsDoubleSpinBox *mSpinBox;
73-
int mMagnifier;
74-
int mMagnifierMin;
75-
int mMagnifierMax;
7672
};
7773

7874
#endif

0 commit comments

Comments
 (0)