Skip to content
Permalink
Browse files

Allow setting magnification factor for map views

  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent fa46e5a commit 843a72e5c8ed607b5669d2671c970ea3187c95b7
Showing with 63 additions and 13 deletions.
  1. +56 −11 src/app/qgsmapcanvasdockwidget.cpp
  2. +7 −2 src/app/qgsmapcanvasdockwidget.h
@@ -16,7 +16,9 @@
#include "qgsmapcanvas.h"
#include "qgsprojectionselectiondialog.h"
#include "qgsscalecombobox.h"
#include "qgsstatusbarmagnifierwidget.h"
#include "qgsdoublespinbox.h"
#include "qgssettings.h"
#include <QMessageBox>
#include <QMenu>
#include <QToolBar>
@@ -55,7 +57,8 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
QgsMapSettingsAction *settingsAction = new QgsMapSettingsAction( menu );
menu->addAction( settingsAction );
mScaleCombo = settingsAction->scaleCombo();
mRotationEdit = settingsAction->rotationEdit();
mRotationEdit = settingsAction->rotationSpinBox();
mMagnificationEdit = settingsAction->magnifierSpinBox();
connect( mScaleCombo, &QgsScaleComboBox::scaleChanged, this, [ = ]( double scale )
{
if ( !mBlockScaleUpdate )
@@ -95,6 +98,27 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
mBlockRotationUpdate = false;
}
} );

connect( mMagnificationEdit, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double value )
{
if ( !mBlockMagnificationUpdate )
{
mBlockMagnificationUpdate = true;
mMapCanvas->setMagnificationFactor( value / 100 );
mMapCanvas->refresh();
mBlockMagnificationUpdate = false;
}
} );

connect( mMapCanvas, &QgsMapCanvas::magnificationChanged, this, [ = ]( double factor )
{
if ( !mBlockMagnificationUpdate )
{
mBlockMagnificationUpdate = true;
mMagnificationEdit->setValue( factor * 100 );
mBlockMagnificationUpdate = false;
}
} );
}

QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas()
@@ -175,19 +199,40 @@ QgsMapSettingsAction::QgsMapSettingsAction( QWidget *parent )
mScaleCombo = new QgsScaleComboBox();
gLayout->addWidget( mScaleCombo, 0, 1 );

mRotationEdit = new QgsDoubleSpinBox();
mRotationEdit->setClearValue( 0.0 );
mRotationEdit->setKeyboardTracking( false );
mRotationEdit->setMaximumWidth( 120 );
mRotationEdit->setDecimals( 1 );
mRotationEdit->setRange( -180.0, 180.0 );
mRotationEdit->setWrapping( true );
mRotationEdit->setSingleStep( 5.0 );
mRotationEdit->setToolTip( tr( "Current clockwise map rotation in degrees" ) );
mRotationWidget = new QgsDoubleSpinBox();
mRotationWidget->setClearValue( 0.0 );
mRotationWidget->setKeyboardTracking( false );
mRotationWidget->setMaximumWidth( 120 );
mRotationWidget->setDecimals( 1 );
mRotationWidget->setRange( -180.0, 180.0 );
mRotationWidget->setWrapping( true );
mRotationWidget->setSingleStep( 5.0 );
mRotationWidget->setToolTip( tr( "Current clockwise map rotation in degrees" ) );

label = new QLabel( tr( "Rotation" ) );
gLayout->addWidget( label, 1, 0 );
gLayout->addWidget( mRotationEdit, 1, 1 );
gLayout->addWidget( mRotationWidget, 1, 1 );

QgsSettings settings;
int minimumFactor = 100 * QgisGui::CANVAS_MAGNIFICATION_MIN;
int maximumFactor = 100 * QgisGui::CANVAS_MAGNIFICATION_MAX;
int defaultFactor = 100 * settings.value( QStringLiteral( "/qgis/magnifier_factor_default" ), 1.0 ).toDouble();

mMagnifierWidget = new QgsDoubleSpinBox();
mMagnifierWidget->setSuffix( QStringLiteral( "%" ) );
mMagnifierWidget->setKeyboardTracking( false );
mMagnifierWidget->setDecimals( 0 );
mMagnifierWidget->setRange( minimumFactor, maximumFactor );
mMagnifierWidget->setWrapping( false );
mMagnifierWidget->setSingleStep( 50 );
mMagnifierWidget->setToolTip( tr( "Magnifier level" ) );
mMagnifierWidget->setClearValueMode( QgsDoubleSpinBox::CustomValue );
mMagnifierWidget->setClearValue( defaultFactor );
mMagnifierWidget->setValue( defaultFactor );

label = new QLabel( tr( "Magnification" ) );
gLayout->addWidget( label, 2, 0 );
gLayout->addWidget( mMagnifierWidget, 2, 1 );

QWidget *w = new QWidget();
w->setLayout( gLayout );
@@ -24,6 +24,7 @@
class QgsMapCanvas;
class QgsScaleComboBox;
class QgsDoubleSpinBox;
class QgsStatusBarMagnifierWidget;

/**
* \class QgsMapCanvasDockWidget
@@ -68,8 +69,10 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
bool mShowCloseWarning = true;
QgsScaleComboBox *mScaleCombo = nullptr;
QgsDoubleSpinBox *mRotationEdit = nullptr;
QgsDoubleSpinBox *mMagnificationEdit = nullptr;
bool mBlockScaleUpdate = false;
bool mBlockRotationUpdate = false;
bool mBlockMagnificationUpdate = false;
};

/**
@@ -87,11 +90,13 @@ class QgsMapSettingsAction: public QWidgetAction
QgsMapSettingsAction( QWidget *parent = nullptr );

QgsScaleComboBox *scaleCombo() { return mScaleCombo; }
QgsDoubleSpinBox *rotationEdit() { return mRotationEdit; }
QgsDoubleSpinBox *rotationSpinBox() { return mRotationWidget; }
QgsDoubleSpinBox *magnifierSpinBox() { return mMagnifierWidget; }

private:
QgsScaleComboBox *mScaleCombo = nullptr;
QgsDoubleSpinBox *mRotationEdit = nullptr;
QgsDoubleSpinBox *mRotationWidget = nullptr;
QgsDoubleSpinBox *mMagnifierWidget = nullptr;
};


0 comments on commit 843a72e

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