Skip to content

Commit

Permalink
allow to lock scale to use magnification to zoom in/out
Browse files Browse the repository at this point in the history
this also removes the option for different behavior of mouse wheel
  • Loading branch information
3nids committed May 28, 2016
1 parent 69a1718 commit cf99817
Show file tree
Hide file tree
Showing 14 changed files with 491 additions and 264 deletions.
13 changes: 9 additions & 4 deletions python/core/qgsmapsettings.sip
Expand Up @@ -39,10 +39,15 @@ class QgsMapSettings
//! Set DPI used for conversion between real world units (e.g. mm) and pixels
void setOutputDpi( int dpi );

//! Set the magnification factor.
//! @note added in 2.16
void setMagnificationFactor( double factor );
//! Return the magnification factor.

/**
* @brief setMagnificationFactor set the magnification factor
* @param factor the factor of magnification
* @note added in 2.16
*/
void setMagnificationFactor( double factor );

//! Return the magnification factor.
//! @note added in 2.16
double magnificationFactor() const;

Expand Down
4 changes: 4 additions & 0 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -279,8 +279,12 @@ class QgsMapCanvas : QGraphicsView
QgsMapLayer* currentLayer();

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

//! set the wheel zoom factor
void setWheelFactor( double factor );

//! Zoom in with fixed factor
void zoomIn();

Expand Down
20 changes: 11 additions & 9 deletions src/app/qgisapp.cpp
Expand Up @@ -2136,13 +2136,15 @@ void QgisApp::createStatusBar()

mScaleWidget = new QgsStatusBarScaleWidget( mMapCanvas, statusBar() );
mScaleWidget->setFont( myFont );
connect( mScaleWidget, SIGNAL( scaleLockChanged( bool ) ), mMapCanvas, SLOT( setScaleLocked( bool ) ) );
statusBar()->addPermanentWidget( mScaleWidget, 0 );

// zoom widget
QSettings mySettings;
mMagnifierWidget = new QgsStatusBarMagnifierWidget( mMapCanvas, statusBar() );
mMagnifierWidget = new QgsStatusBarMagnifierWidget( statusBar() );
mMagnifierWidget->setFont( myFont );
mMagnifierWidget->setMagnificationLevel( mySettings.value( "/qgis/magnifier_level", 100 ).toInt() );
connect( mMapCanvas, SIGNAL( magnificationChanged( double ) ), mMagnifierWidget, SLOT( updateMagnification( double ) ) );
connect( mMagnifierWidget, SIGNAL( magnificationChanged( double ) ), mMapCanvas, SLOT( setMagnificationFactor( double ) ) );
mMagnifierWidget->updateMagnification( QSettings().value( "/qgis/magnifier_factor_default", 1.0 ).toDouble() );
statusBar()->addPermanentWidget( mMagnifierWidget, 0 );

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

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

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

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

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

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

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

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

mMagnifierWidget->setMagnificationLevel( mySettings.value( "/qgis/magnifier_level" ).toInt() );

//update any open compositions so they reflect new composer settings
//we have to push the changes to the compositions here, because compositions
//have no access to qgisapp and accordingly can't listen in to changes
Expand Down Expand Up @@ -8612,6 +8610,10 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString& currentPage )

mMapCanvas->setSegmentationTolerance( mySettings.value( "/qgis/segmentationTolerance", "0.01745" ).toDouble() );
mMapCanvas->setSegmentationToleranceType( QgsAbstractGeometryV2::SegmentationToleranceType( mySettings.value( "/qgis/segmentationToleranceType", "0" ).toInt() ) );

double factor = mySettings.value( "/qgis/magnifier_factor_default", 1.0 ).toDouble();
mMagnifierWidget->setDefaultFactor( factor );
mMagnifierWidget->updateMagnification( factor );
}

delete optionsDialog;
Expand Down
11 changes: 6 additions & 5 deletions src/app/qgsoptions.cpp
Expand Up @@ -607,11 +607,14 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
mSimplifyMaximumScaleComboBox->setScale( 1.0 / mSettings->value( "/qgis/simplifyMaxScale", 1 ).toFloat() );

// Magnifier
doubleSpinBoxMagnifierDefault->setRange( 100, 1000 );
double magnifierMin = 100 * mSettings->value( "/qgis/magnifier_factor_min", 0.1 ).toDouble();
double magnifierMax = 100 * mSettings->value( "/qgis/magnifier_factor_max", 10 ).toDouble();
double magnifierVal = 100 * mSettings->value( "/qgis/magnifier_factor_default", 1.0 ).toDouble();
doubleSpinBoxMagnifierDefault->setRange( magnifierMin, magnifierMax );
doubleSpinBoxMagnifierDefault->setSingleStep( 50 );
doubleSpinBoxMagnifierDefault->setDecimals( 0 );
doubleSpinBoxMagnifierDefault->setSuffix( "%" );
doubleSpinBoxMagnifierDefault->setValue( mSettings->value( "/qgis/magnifier_level", 100 ).toInt() );
doubleSpinBoxMagnifierDefault->setValue( magnifierVal );

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

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

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

// magnification
mSettings->setValue( "/qgis/magnifier_level", doubleSpinBoxMagnifierDefault->value() );
mSettings->setValue( "/qgis/magnifier_factor_default", doubleSpinBoxMagnifierDefault->value() / 100 );

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

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

//digitizing
Expand Down
49 changes: 18 additions & 31 deletions src/app/qgsstatusbarmagnifierwidget.cpp
Expand Up @@ -17,19 +17,20 @@
#include <QFont>
#include <QHBoxLayout>
#include <QLabel>
#include <QSettings>

#include <qgsapplication.h>
#include "qgsstatusbarmagnifierwidget.h"
#include "qgsmapcanvas.h"
#include "qgsdoublespinbox.h"

QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget(QgsMapCanvas *canvas, QWidget* parent) :
QWidget( parent ),
mCanvas( canvas ),
mMagnifier( 100 ),
mMagnifierMin( 100 ),
mMagnifierMax( 1000 )
QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget( QWidget* parent ) :
QWidget( parent )
{
QSettings settings;
int minimumFactor = ( int ) 100 * settings.value( "/qgis/magnifier_factor_min", 0.1 ).toDouble();
int maximumFactor = ( int ) 100 * settings.value( "/qgis/magnifier_factor_max", 10 ).toDouble();
int defaultFactor = ( int ) 100 * settings.value( "/qgis/magnifier_factor_default", 1.0 ).toDouble();

// label
mLabel = new QLabel( this );
mLabel->setMinimumWidth( 10 );
Expand All @@ -41,17 +42,17 @@ QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget(QgsMapCanvas *canvas, Q

mSpinBox = new QgsDoubleSpinBox( this );
mSpinBox->setSuffix( "%" );
mSpinBox->setClearValue( mMagnifierMin );
mSpinBox->setKeyboardTracking( false );
mSpinBox->setMaximumWidth( 120 );
mSpinBox->setDecimals( 0 );
mSpinBox->setRange( mMagnifierMin, mMagnifierMax );
mSpinBox->setRange( minimumFactor, maximumFactor );
mSpinBox->setWrapping( false );
mSpinBox->setSingleStep( 50 );
mSpinBox->setToolTip( tr( "Magnifier level" ) );
mSpinBox->setClearValueMode( QgsDoubleSpinBox::CustomValue );
mSpinBox->setClearValue( defaultFactor );

connect( mSpinBox, SIGNAL( valueChanged( double ) ), this,
SLOT( updateMagnifier() ) );
connect( mSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( setMagnification( double ) ) );

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

setLayout( mLayout );

updateMagnifier();
}

QgsStatusBarMagnifierWidget::~QgsStatusBarMagnifierWidget()
{
}

double QgsStatusBarMagnifierWidget::magnificationLevel()
void QgsStatusBarMagnifierWidget::setDefaultFactor( double factor )
{
return mMagnifier;
mSpinBox->setClearValue(( int )100*factor );
}

void QgsStatusBarMagnifierWidget::setFont( const QFont& myFont )
Expand All @@ -81,24 +80,12 @@ void QgsStatusBarMagnifierWidget::setFont( const QFont& myFont )
mSpinBox->setFont( myFont );
}

bool QgsStatusBarMagnifierWidget::setMagnificationLevel( int level )
void QgsStatusBarMagnifierWidget::updateMagnification( double factor )
{
bool rc = false;

if ( level >= mMagnifierMin && level <= mMagnifierMax )
{
mSpinBox->setValue( level );
rc = true;
}

return rc;
mSpinBox->setValue( factor * 100 );
}

void QgsStatusBarMagnifierWidget::updateMagnifier()
void QgsStatusBarMagnifierWidget::setMagnification( double value )
{
// get current data
mMagnifier = mSpinBox->value();

// update map canvas
mCanvas->setMagnificationFactor( mMagnifier / double( mMagnifierMin ) );
emit magnificationChanged( value / 100 );
}
28 changes: 12 additions & 16 deletions src/app/qgsstatusbarmagnifierwidget.h
Expand Up @@ -20,7 +20,6 @@
class QLabel;
class QFont;
class QHBoxLayout;
class QgsMapCanvas;
class QgsDoubleSpinBox;

#include <QWidget>
Expand All @@ -40,39 +39,36 @@ class APP_EXPORT QgsStatusBarMagnifierWidget : public QWidget
* @param parent is the parent widget
* @param canvas the map canvas
*/
QgsStatusBarMagnifierWidget( QgsMapCanvas *canvas, QWidget* parent = 0 );
QgsStatusBarMagnifierWidget( QWidget* parent = 0 );

/** Destructor */
virtual ~QgsStatusBarMagnifierWidget();

void setDefaultFactor( double factor );

/** Set the font of the text
* @param font the font to use
*/
void setFont( const QFont& font );

/** Returns the current magnification level
* @return magnification level
*/
double magnificationLevel();

/** Set the magnification level
* @param level the magnification level
* @return true if the level is valid, false otherwise
*/
bool setMagnificationLevel( int level );
public slots:
//! will be triggered from map canvas changes (from mouse wheel, zoom)
void updateMagnification( double factor );


private slots:
//! will be triggered form user input in spin box
void setMagnification( double value );

signals:
void magnificationChanged( double factor );

void updateMagnifier();

private:
QgsMapCanvas *mCanvas;
QHBoxLayout *mLayout;
QLabel *mLabel;
QgsDoubleSpinBox *mSpinBox;
int mMagnifier;
int mMagnifierMin;
int mMagnifierMax;
};

#endif

0 comments on commit cf99817

Please sign in to comment.