Skip to content
Permalink
Browse files

Merge pull request #3131 from 3nids/lockscale

allow to lock scale to use magnification to zoom in/out
  • Loading branch information
3nids committed May 28, 2016
2 parents bae8a0e + c3e7a56 commit b9baf2e95a3c9bd350c5b978be3199eace33c957
@@ -184,7 +184,7 @@ class QgsMapRenderer : QObject
//! sets whether map image will be for overview
void enableOverviewMode( bool isOverview = true );

void setOutputSize( QSize size, int dpi );
void setOutputSize( QSize size, double dpi );
void setOutputSize( QSizeF size, double dpi );

//!accessor for output dpi
@@ -35,14 +35,19 @@ class QgsMapSettings

//! Return DPI used for conversion between real world units (e.g. mm) and pixels
//! Default value is 96
int outputDpi() const;
double outputDpi() const;
//! Set DPI used for conversion between real world units (e.g. mm) and pixels
void setOutputDpi( int dpi );
void setOutputDpi( double 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;

@@ -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();

@@ -52,6 +52,7 @@ SET(QGIS_APP_SRCS
qgssavestyletodbdialog.cpp
qgsstatusbarcoordinateswidget.cpp
qgsstatusbarmagnifierwidget.cpp
qgsstatusbarscalewidget.cpp
qgsversioninfo.cpp
qgswelcomepageitemsmodel.cpp
qgswelcomepage.cpp
@@ -231,6 +232,7 @@ SET (QGIS_APP_MOC_HDRS
qgsshortcutsmanager.h
qgsstatusbarcoordinateswidget.h
qgsstatusbarmagnifierwidget.h
qgsstatusbarscalewidget.h
qgsversioninfo.h
qgswelcomepageitemsmodel.h
qgswelcomepage.h
@@ -122,8 +122,6 @@
#include "qgscomposer.h"
#include "qgscomposermanager.h"
#include "qgscomposerview.h"
#include "qgsstatusbarcoordinateswidget.h"
#include "qgsstatusbarmagnifierwidget.h"
#include "qgsconfigureshortcutsdialog.h"
#include "qgscoordinatetransform.h"
#include "qgscoordinateutils.h"
@@ -207,17 +205,19 @@
#include "qgsrasterrenderer.h"
#include "qgsrasterlayersaveasdialog.h"
#include "qgsrectangle.h"
#include "qgsscalecombobox.h"
#include "qgsscalevisibilitydialog.h"
#include "qgsgroupwmsdatadialog.h"
#include "qgsshortcutsmanager.h"
#include "qgssinglebandgrayrenderer.h"
#include "qgssnappingdialog.h"
#include "qgssponsors.h"
#include "qgsstatisticalsummarydockwidget.h"
#include "qgssymbolv2selectordialog.h"
#include "qgsstatusbarcoordinateswidget.h"
#include "qgsstatusbarmagnifierwidget.h"
#include "qgsstatusbarscalewidget.h"
#include "qgsstylev2.h"
#include "qgssvgannotationitem.h"
#include "qgssymbolv2selectordialog.h"
#include "qgstextannotationitem.h"
#include "qgstipgui.h"
#include "qgsundowidget.h"
@@ -543,9 +543,7 @@ QgisApp *QgisApp::smInstance = nullptr;
QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCheck, QWidget * parent, Qt::WindowFlags fl )
: QMainWindow( parent, fl )
, mNonEditMapTool( nullptr )
, mScaleLabel( nullptr )
, mScaleEdit( nullptr )
, mScaleEditValidator( nullptr )
, mScaleWidget( nullptr )
, mMagnifierWidget( nullptr )
, mCoordsEdit( nullptr )
, mRotationLabel( nullptr )
@@ -1001,9 +999,7 @@ QgisApp::QgisApp()
, mpGpsDock( nullptr )
, mLogDock( nullptr )
, mNonEditMapTool( nullptr )
, mScaleLabel( nullptr )
, mScaleEdit( nullptr )
, mScaleEditValidator( nullptr )
, mScaleWidget( nullptr )
, mMagnifierWidget( nullptr )
, mCoordsEdit( nullptr )
, mRotationLabel( nullptr )
@@ -2138,38 +2134,17 @@ void QgisApp::createStatusBar()
mCoordsEdit->setFont( myFont );
statusBar()->addPermanentWidget( mCoordsEdit, 0 );

// add a label to show current scale
mScaleLabel = new QLabel( QString(), statusBar() );
mScaleLabel->setObjectName( "mScaleLable" );
mScaleLabel->setFont( myFont );
mScaleLabel->setMinimumWidth( 10 );
//mScaleLabel->setMaximumHeight( 20 );
mScaleLabel->setMargin( 3 );
mScaleLabel->setAlignment( Qt::AlignCenter );
mScaleLabel->setFrameStyle( QFrame::NoFrame );
mScaleLabel->setText( tr( "Scale" ) );
mScaleLabel->setToolTip( tr( "Current map scale" ) );
statusBar()->addPermanentWidget( mScaleLabel, 0 );

mScaleEdit = new QgsScaleComboBox( statusBar() );
mScaleEdit->setObjectName( "mScaleEdit" );
mScaleEdit->setFont( myFont );
// seems setFont() change font only for popup not for line edit,
// so we need to set font for it separately
mScaleEdit->lineEdit()->setFont( myFont );
mScaleEdit->setMinimumWidth( 10 );
mScaleEdit->setContentsMargins( 0, 0, 0, 0 );
mScaleEdit->setWhatsThis( tr( "Displays the current map scale" ) );
mScaleEdit->setToolTip( tr( "Current map scale (formatted as x:y)" ) );

statusBar()->addPermanentWidget( mScaleEdit, 0 );
connect( mScaleEdit, SIGNAL( scaleChanged( double ) ), this, SLOT( userScale() ) );
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( statusBar(), mMapCanvas );
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() )
@@ -2227,7 +2202,7 @@ void QgisApp::createStatusBar()
mOnTheFlyProjectionStatusButton->setObjectName( "mOntheFlyProjectionStatusButton" );
// Maintain uniform widget height in status bar by setting button height same as labels
// For Qt/Mac 3.3, the default toolbutton height is 30 and labels were expanding to match
mOnTheFlyProjectionStatusButton->setMaximumHeight( mScaleLabel->height() );
mOnTheFlyProjectionStatusButton->setMaximumHeight( mScaleWidget->height() );
mOnTheFlyProjectionStatusButton->setIcon( QgsApplication::getThemeIcon( "mIconProjectionEnabled.png" ) );
mOnTheFlyProjectionStatusButton->setWhatsThis( tr( "This icon shows whether "
"on the fly coordinate reference system transformation is enabled or not. "
@@ -2247,7 +2222,7 @@ void QgisApp::createStatusBar()
mMessageButton->setWhatsThis( tr( "Messages" ) );
mMessageButton->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
mMessageButton->setObjectName( "mMessageLogViewerButton" );
mMessageButton->setMaximumHeight( mScaleLabel->height() );
mMessageButton->setMaximumHeight( mScaleWidget->height() );
mMessageButton->setCheckable( true );
statusBar()->addPermanentWidget( mMessageButton, 0 );
}
@@ -2716,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() );

@@ -4198,7 +4172,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
mMapCanvas->refresh();
mMapCanvas->clearExtentHistory();
mMapCanvas->setRotation( 0.0 );
mScaleEdit->updateScales();
mScaleWidget->updateScales();

// set project CRS
QString defCrs = settings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
@@ -4648,7 +4622,7 @@ bool QgisApp::addProject( const QString& projectFile )
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
if ( projectScales )
{
mScaleEdit->updateScales( QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ) );
mScaleWidget->updateScales( QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ) );
}

mMapCanvas->updateScale();
@@ -7906,21 +7880,15 @@ void QgisApp::saveLastMousePosition( const QgsPoint & p )
void QgisApp::showScale( double theScale )
{
// Why has MapCanvas the scale inverted?
mScaleEdit->setScale( 1.0 / theScale );
mScaleWidget->setScale( 1.0 / theScale );

// Not sure if the lines below do anything meaningful /Homann
if ( mScaleEdit->width() > mScaleEdit->minimumWidth() )
if ( mScaleWidget->width() > mScaleWidget->minimumWidth() )
{
mScaleEdit->setMinimumWidth( mScaleEdit->width() );
mScaleWidget->setMinimumWidth( mScaleWidget->width() );
}
}

void QgisApp::userScale()
{
// Why has MapCanvas the scale inverted?
mMapCanvas->zoomScale( 1.0 / mScaleEdit->scale() );
}


void QgisApp::userRotation()
{
@@ -8596,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() );

@@ -8613,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
@@ -8633,7 +8598,7 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString& currentPage )

if ( oldScales != mySettings.value( "Map/scales", PROJECT_SCALES ).toString() )
{
mScaleEdit->updateScales();
mScaleWidget->updateScales();
}

qobject_cast<QgsMeasureTool*>( mMapTools.mMeasureDist )->updateSettings();
@@ -8645,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;
@@ -9964,7 +9933,7 @@ void QgisApp::projectProperties()
connect( pp, SIGNAL( displayPrecisionChanged() ), this,
SLOT( updateMouseCoordinatePrecision() ) );

connect( pp, SIGNAL( scalesChanged( const QStringList & ) ), mScaleEdit,
connect( pp, SIGNAL( scalesChanged( const QStringList & ) ), mScaleWidget,
SLOT( updateScales( const QStringList & ) ) );
QApplication::restoreOverrideCursor();

@@ -46,6 +46,7 @@ class QgsComposerManager;
class QgsComposerView;
class QgsStatusBarCoordinatesWidget;
class QgsStatusBarMagnifierWidget;
class QgsStatusBarScaleWidget;
class QgsContrastEnhancement;
class QgsCustomLayerOrderWidget;
class QgsDoubleSpinBox;
@@ -90,8 +91,6 @@ class QgsDecorationItem;
class QgsMessageLogViewer;
class QgsMessageBar;

class QgsScaleComboBox;

class QgsDataItem;
class QgsTileScaleWidget;

@@ -736,8 +735,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void saveLastMousePosition( const QgsPoint & );
//! Slot to show current map scale;
void showScale( double theScale );
//! Slot to handle user scale input;
void userScale();
//! Slot to handle user rotation input;
//! @note added in 2.8
void userRotation();
@@ -1589,12 +1586,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QgsMapTool *mNonEditMapTool;

//! Widget that will live on the statusbar to display "scale 1:"
QLabel *mScaleLabel;
//! Widget that will live on the statusbar to display scale value
QgsScaleComboBox *mScaleEdit;
//! The validator for the mScaleEdit
QValidator * mScaleEditValidator;
QgsStatusBarScaleWidget* mScaleWidget;

//! zoom widget
QgsStatusBarMagnifierWidget *mMagnifierWidget;
@@ -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 );
@@ -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
@@ -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();
@@ -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

0 comments on commit b9baf2e

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