mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Merge pull request #3009 from pblottiere/magnifier
[FEATURE] add a map canvas magnifier
This commit is contained in:
commit
1602c02df7
@ -17,7 +17,7 @@ class QgsMapSettings
|
|||||||
//! The actual visible extent used for rendering could be slightly different
|
//! The actual visible extent used for rendering could be slightly different
|
||||||
//! since the given extent may be expanded in order to fit the aspect ratio
|
//! since the given extent may be expanded in order to fit the aspect ratio
|
||||||
//! of output size. Use visibleExtent() to get the resulting extent.
|
//! of output size. Use visibleExtent() to get the resulting extent.
|
||||||
void setExtent( const QgsRectangle& rect );
|
void setExtent( const QgsRectangle& rect, bool magnified = true );
|
||||||
|
|
||||||
//! Return the size of the resulting map image
|
//! Return the size of the resulting map image
|
||||||
QSize outputSize() const;
|
QSize outputSize() const;
|
||||||
@ -39,6 +39,13 @@ class QgsMapSettings
|
|||||||
//! Set DPI used for conversion between real world units (e.g. mm) and pixels
|
//! Set DPI used for conversion between real world units (e.g. mm) and pixels
|
||||||
void setOutputDpi( int dpi );
|
void setOutputDpi( int dpi );
|
||||||
|
|
||||||
|
//! Set the magnification factor.
|
||||||
|
//! @note added in 2.16
|
||||||
|
void setMagnificationFactor( double factor );
|
||||||
|
//! Return the magnification factor.
|
||||||
|
//! @note added in 2.16
|
||||||
|
double magnificationFactor() const;
|
||||||
|
|
||||||
//! Get list of layer IDs for map rendering
|
//! Get list of layer IDs for map rendering
|
||||||
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
|
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
|
||||||
QStringList layers() const;
|
QStringList layers() const;
|
||||||
|
@ -50,6 +50,16 @@ class QgsMapCanvas : QGraphicsView
|
|||||||
//! Destructor
|
//! Destructor
|
||||||
~QgsMapCanvas();
|
~QgsMapCanvas();
|
||||||
|
|
||||||
|
//! Sets the factor of magnification to apply to the map canvas. Indeed, we
|
||||||
|
//! increase/decrease the DPI of the map settings according to this factor
|
||||||
|
//! in order to render marker point, labels, ... bigger.
|
||||||
|
//! @note added in 2.16
|
||||||
|
void setMagnificationFactor( double level );
|
||||||
|
|
||||||
|
//! Returns the magnification factor
|
||||||
|
//! @note added in 2.16
|
||||||
|
double magnificationFactor() const;
|
||||||
|
|
||||||
void setLayerSet( QList<QgsMapCanvasLayer>& layers );
|
void setLayerSet( QList<QgsMapCanvasLayer>& layers );
|
||||||
|
|
||||||
void setCurrentLayer( QgsMapLayer* layer );
|
void setCurrentLayer( QgsMapLayer* layer );
|
||||||
|
@ -51,6 +51,7 @@ SET(QGIS_APP_SRCS
|
|||||||
qgsrulebasedlabelingwidget.cpp
|
qgsrulebasedlabelingwidget.cpp
|
||||||
qgssavestyletodbdialog.cpp
|
qgssavestyletodbdialog.cpp
|
||||||
qgsstatusbarcoordinateswidget.cpp
|
qgsstatusbarcoordinateswidget.cpp
|
||||||
|
qgsstatusbarmagnifierwidget.cpp
|
||||||
qgsversioninfo.cpp
|
qgsversioninfo.cpp
|
||||||
qgswelcomepageitemsmodel.cpp
|
qgswelcomepageitemsmodel.cpp
|
||||||
qgswelcomepage.cpp
|
qgswelcomepage.cpp
|
||||||
@ -229,6 +230,7 @@ SET (QGIS_APP_MOC_HDRS
|
|||||||
qgssavestyletodbdialog.h
|
qgssavestyletodbdialog.h
|
||||||
qgsshortcutsmanager.h
|
qgsshortcutsmanager.h
|
||||||
qgsstatusbarcoordinateswidget.h
|
qgsstatusbarcoordinateswidget.h
|
||||||
|
qgsstatusbarmagnifierwidget.h
|
||||||
qgsversioninfo.h
|
qgsversioninfo.h
|
||||||
qgswelcomepageitemsmodel.h
|
qgswelcomepageitemsmodel.h
|
||||||
qgswelcomepage.h
|
qgswelcomepage.h
|
||||||
|
@ -123,6 +123,7 @@
|
|||||||
#include "qgscomposermanager.h"
|
#include "qgscomposermanager.h"
|
||||||
#include "qgscomposerview.h"
|
#include "qgscomposerview.h"
|
||||||
#include "qgsstatusbarcoordinateswidget.h"
|
#include "qgsstatusbarcoordinateswidget.h"
|
||||||
|
#include "qgsstatusbarmagnifierwidget.h"
|
||||||
#include "qgsconfigureshortcutsdialog.h"
|
#include "qgsconfigureshortcutsdialog.h"
|
||||||
#include "qgscoordinatetransform.h"
|
#include "qgscoordinatetransform.h"
|
||||||
#include "qgscoordinateutils.h"
|
#include "qgscoordinateutils.h"
|
||||||
@ -545,6 +546,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
|
|||||||
, mScaleLabel( nullptr )
|
, mScaleLabel( nullptr )
|
||||||
, mScaleEdit( nullptr )
|
, mScaleEdit( nullptr )
|
||||||
, mScaleEditValidator( nullptr )
|
, mScaleEditValidator( nullptr )
|
||||||
|
, mMagnifierWidget( nullptr )
|
||||||
, mCoordsEdit( nullptr )
|
, mCoordsEdit( nullptr )
|
||||||
, mRotationLabel( nullptr )
|
, mRotationLabel( nullptr )
|
||||||
, mRotationEdit( nullptr )
|
, mRotationEdit( nullptr )
|
||||||
@ -1001,6 +1003,7 @@ QgisApp::QgisApp()
|
|||||||
, mScaleLabel( nullptr )
|
, mScaleLabel( nullptr )
|
||||||
, mScaleEdit( nullptr )
|
, mScaleEdit( nullptr )
|
||||||
, mScaleEditValidator( nullptr )
|
, mScaleEditValidator( nullptr )
|
||||||
|
, mMagnifierWidget( nullptr )
|
||||||
, mCoordsEdit( nullptr )
|
, mCoordsEdit( nullptr )
|
||||||
, mRotationLabel( nullptr )
|
, mRotationLabel( nullptr )
|
||||||
, mRotationEdit( nullptr )
|
, mRotationEdit( nullptr )
|
||||||
@ -2161,6 +2164,13 @@ void QgisApp::createStatusBar()
|
|||||||
statusBar()->addPermanentWidget( mScaleEdit, 0 );
|
statusBar()->addPermanentWidget( mScaleEdit, 0 );
|
||||||
connect( mScaleEdit, SIGNAL( scaleChanged( double ) ), this, SLOT( userScale() ) );
|
connect( mScaleEdit, SIGNAL( scaleChanged( double ) ), this, SLOT( userScale() ) );
|
||||||
|
|
||||||
|
// zoom widget
|
||||||
|
QSettings mySettings;
|
||||||
|
mMagnifierWidget = new QgsStatusBarMagnifierWidget( statusBar(), mMapCanvas );
|
||||||
|
mMagnifierWidget->setFont( myFont );
|
||||||
|
mMagnifierWidget->setMagnificationLevel( mySettings.value( "/qgis/magnifier_level", 100 ).toInt() );
|
||||||
|
statusBar()->addPermanentWidget( mMagnifierWidget, 0 );
|
||||||
|
|
||||||
if ( QgsMapCanvas::rotationEnabled() )
|
if ( QgsMapCanvas::rotationEnabled() )
|
||||||
{
|
{
|
||||||
// add a widget to show/set current rotation
|
// add a widget to show/set current rotation
|
||||||
@ -8602,6 +8612,8 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString& currentPage )
|
|||||||
layer->setLayerName( layer->originalName() );
|
layer->setLayerName( layer->originalName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMagnifierWidget->setMagnificationLevel( mySettings.value( "/qgis/magnifier_level" ).toInt() );
|
||||||
|
|
||||||
//update any open compositions so they reflect new composer settings
|
//update any open compositions so they reflect new composer settings
|
||||||
//we have to push the changes to the compositions here, because compositions
|
//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
|
//have no access to qgisapp and accordingly can't listen in to changes
|
||||||
|
@ -45,6 +45,7 @@ class QgsComposer;
|
|||||||
class QgsComposerManager;
|
class QgsComposerManager;
|
||||||
class QgsComposerView;
|
class QgsComposerView;
|
||||||
class QgsStatusBarCoordinatesWidget;
|
class QgsStatusBarCoordinatesWidget;
|
||||||
|
class QgsStatusBarMagnifierWidget;
|
||||||
class QgsContrastEnhancement;
|
class QgsContrastEnhancement;
|
||||||
class QgsCustomLayerOrderWidget;
|
class QgsCustomLayerOrderWidget;
|
||||||
class QgsDoubleSpinBox;
|
class QgsDoubleSpinBox;
|
||||||
@ -1595,6 +1596,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
|
|||||||
//! The validator for the mScaleEdit
|
//! The validator for the mScaleEdit
|
||||||
QValidator * mScaleEditValidator;
|
QValidator * mScaleEditValidator;
|
||||||
|
|
||||||
|
//! zoom widget
|
||||||
|
QgsStatusBarMagnifierWidget *mMagnifierWidget;
|
||||||
|
|
||||||
//! Widget that will live in the statusbar to display and edit coords
|
//! Widget that will live in the statusbar to display and edit coords
|
||||||
QgsStatusBarCoordinatesWidget *mCoordsEdit;
|
QgsStatusBarCoordinatesWidget *mCoordsEdit;
|
||||||
|
|
||||||
|
@ -589,6 +589,13 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
|
|||||||
mSimplifyMaximumScaleComboBox->updateScales( myScalesList );
|
mSimplifyMaximumScaleComboBox->updateScales( myScalesList );
|
||||||
mSimplifyMaximumScaleComboBox->setScale( 1.0 / mSettings->value( "/qgis/simplifyMaxScale", 1 ).toFloat() );
|
mSimplifyMaximumScaleComboBox->setScale( 1.0 / mSettings->value( "/qgis/simplifyMaxScale", 1 ).toFloat() );
|
||||||
|
|
||||||
|
// Magnifier
|
||||||
|
doubleSpinBoxMagnifierDefault->setRange( 100, 1000 );
|
||||||
|
doubleSpinBoxMagnifierDefault->setSingleStep( 50 );
|
||||||
|
doubleSpinBoxMagnifierDefault->setDecimals( 0 );
|
||||||
|
doubleSpinBoxMagnifierDefault->setSuffix( "%" );
|
||||||
|
doubleSpinBoxMagnifierDefault->setValue( mSettings->value( "/qgis/magnifier_level", 100 ).toInt() );
|
||||||
|
|
||||||
// Slightly awkard here at the settings value is true to use QImage,
|
// Slightly awkard here at the settings value is true to use QImage,
|
||||||
// but the checkbox is true to use QPixmap
|
// but the checkbox is true to use QPixmap
|
||||||
chkAddedVisibility->setChecked( mSettings->value( "/qgis/new_layers_visible", true ).toBool() );
|
chkAddedVisibility->setChecked( mSettings->value( "/qgis/new_layers_visible", true ).toBool() );
|
||||||
@ -1192,6 +1199,9 @@ void QgsOptions::saveOptions()
|
|||||||
mSettings->setValue( "/qgis/simplifyLocal", !mSimplifyDrawingAtProvider->isChecked() );
|
mSettings->setValue( "/qgis/simplifyLocal", !mSimplifyDrawingAtProvider->isChecked() );
|
||||||
mSettings->setValue( "/qgis/simplifyMaxScale", 1.0 / mSimplifyMaximumScaleComboBox->scale() );
|
mSettings->setValue( "/qgis/simplifyMaxScale", 1.0 / mSimplifyMaximumScaleComboBox->scale() );
|
||||||
|
|
||||||
|
// magnification
|
||||||
|
mSettings->setValue( "/qgis/magnifier_level", doubleSpinBoxMagnifierDefault->value() );
|
||||||
|
|
||||||
// project
|
// project
|
||||||
mSettings->setValue( "/qgis/projOpenAtLaunch", mProjectOnLaunchCmbBx->currentIndex() );
|
mSettings->setValue( "/qgis/projOpenAtLaunch", mProjectOnLaunchCmbBx->currentIndex() );
|
||||||
mSettings->setValue( "/qgis/projOpenAtLaunchPath", mProjectOnLaunchLineEdit->text() );
|
mSettings->setValue( "/qgis/projOpenAtLaunchPath", mProjectOnLaunchLineEdit->text() );
|
||||||
|
105
src/app/qgsstatusbarmagnifierwidget.cpp
Normal file
105
src/app/qgsstatusbarmagnifierwidget.cpp
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsstatusbarmagnifierwidget.cpp
|
||||||
|
begin : April 2016
|
||||||
|
copyright : (C) 2016 Paul Blottiere, Oslandia
|
||||||
|
email : paul dot blottiere at oslandia dot com
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <QFont>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
#include <qgsapplication.h>
|
||||||
|
#include "qgsstatusbarmagnifierwidget.h"
|
||||||
|
#include "qgsmapcanvas.h"
|
||||||
|
#include "qgsdoublespinbox.h"
|
||||||
|
|
||||||
|
QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget( QWidget* parent,
|
||||||
|
QgsMapCanvas *canvas ) :
|
||||||
|
QWidget( parent ),
|
||||||
|
mCanvas( canvas ),
|
||||||
|
mMagnifier( 100 ),
|
||||||
|
mMagnifierMin( 100 ),
|
||||||
|
mMagnifierMax( 1000 )
|
||||||
|
{
|
||||||
|
// label
|
||||||
|
mLabel = new QLabel( this );
|
||||||
|
mLabel->setMinimumWidth( 10 );
|
||||||
|
mLabel->setMargin( 3 );
|
||||||
|
mLabel->setAlignment( Qt::AlignCenter );
|
||||||
|
mLabel->setFrameStyle( QFrame::NoFrame );
|
||||||
|
mLabel->setText( tr( "Magnifier" ) );
|
||||||
|
mLabel->setToolTip( tr( "Magnifier" ) );
|
||||||
|
|
||||||
|
mSpinBox = new QgsDoubleSpinBox( this );
|
||||||
|
mSpinBox->setSuffix( "%" );
|
||||||
|
mSpinBox->setClearValue( mMagnifierMin );
|
||||||
|
mSpinBox->setKeyboardTracking( false );
|
||||||
|
mSpinBox->setMaximumWidth( 120 );
|
||||||
|
mSpinBox->setDecimals( 0 );
|
||||||
|
mSpinBox->setRange( mMagnifierMin, mMagnifierMax );
|
||||||
|
mSpinBox->setWrapping( false );
|
||||||
|
mSpinBox->setSingleStep( 50 );
|
||||||
|
mSpinBox->setToolTip( tr( "Magnifier level" ) );
|
||||||
|
|
||||||
|
connect( mSpinBox, SIGNAL( valueChanged( double ) ), this,
|
||||||
|
SLOT( updateMagnifier() ) );
|
||||||
|
|
||||||
|
// layout
|
||||||
|
mLayout = new QHBoxLayout( this );
|
||||||
|
mLayout->addWidget( mLabel );
|
||||||
|
mLayout->addWidget( mSpinBox );
|
||||||
|
mLayout->setContentsMargins( 0, 0, 0, 0 );
|
||||||
|
mLayout->setAlignment( Qt::AlignRight );
|
||||||
|
mLayout->setSpacing( 0 );
|
||||||
|
|
||||||
|
setLayout( mLayout );
|
||||||
|
|
||||||
|
updateMagnifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsStatusBarMagnifierWidget::~QgsStatusBarMagnifierWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double QgsStatusBarMagnifierWidget::magnificationLevel()
|
||||||
|
{
|
||||||
|
return mMagnifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsStatusBarMagnifierWidget::setFont( const QFont& myFont )
|
||||||
|
{
|
||||||
|
mLabel->setFont( myFont );
|
||||||
|
mSpinBox->setFont( myFont );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QgsStatusBarMagnifierWidget::setMagnificationLevel( int level )
|
||||||
|
{
|
||||||
|
bool rc = false;
|
||||||
|
|
||||||
|
if ( level >= mMagnifierMin && level <= mMagnifierMax )
|
||||||
|
{
|
||||||
|
mSpinBox->setValue( level );
|
||||||
|
rc = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsStatusBarMagnifierWidget::updateMagnifier()
|
||||||
|
{
|
||||||
|
// get current data
|
||||||
|
mMagnifier = mSpinBox->value();
|
||||||
|
|
||||||
|
// update map canvas
|
||||||
|
mCanvas->setMagnificationFactor( mMagnifier / double( mMagnifierMin ) );
|
||||||
|
}
|
78
src/app/qgsstatusbarmagnifierwidget.h
Normal file
78
src/app/qgsstatusbarmagnifierwidget.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsstatusbarmagnifierwidget.h
|
||||||
|
begin : April 2016
|
||||||
|
copyright : (C) 2016 Paul Blottiere, Oslandia
|
||||||
|
email : paul dot blottiere at oslandia dot com
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef QGSSTATUSBARMAGNIFIERWIDGET_H
|
||||||
|
#define QGSSTATUSBARMAGNIFIERWIDGET_H
|
||||||
|
|
||||||
|
class QLabel;
|
||||||
|
class QFont;
|
||||||
|
class QHBoxLayout;
|
||||||
|
class QgsMapCanvas;
|
||||||
|
class QgsDoubleSpinBox;
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A widget which lets the user select the current level of magnification to
|
||||||
|
* apply to the canvas.
|
||||||
|
* @note added in 2.16
|
||||||
|
*/
|
||||||
|
class APP_EXPORT QgsStatusBarMagnifierWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** Constructor
|
||||||
|
* @param parent is the parent widget
|
||||||
|
* @param canvas the map canvas
|
||||||
|
*/
|
||||||
|
QgsStatusBarMagnifierWidget( QWidget* parent, QgsMapCanvas *canvas );
|
||||||
|
|
||||||
|
/** Destructor */
|
||||||
|
virtual ~QgsStatusBarMagnifierWidget();
|
||||||
|
|
||||||
|
/** 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 );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void updateMagnifier();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QgsMapCanvas *mCanvas;
|
||||||
|
QHBoxLayout *mLayout;
|
||||||
|
QLabel *mLabel;
|
||||||
|
QgsDoubleSpinBox *mSpinBox;
|
||||||
|
int mMagnifier;
|
||||||
|
int mMagnifierMin;
|
||||||
|
int mMagnifierMax;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -35,6 +35,7 @@ QgsMapSettings::QgsMapSettings()
|
|||||||
, mSize( QSize( 0, 0 ) )
|
, mSize( QSize( 0, 0 ) )
|
||||||
, mExtent()
|
, mExtent()
|
||||||
, mRotation( 0.0 )
|
, mRotation( 0.0 )
|
||||||
|
, mMagnificationFactor( 1.0 )
|
||||||
, mProjectionsEnabled( false )
|
, mProjectionsEnabled( false )
|
||||||
, mDestCRS( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId ) // WGS 84
|
, mDestCRS( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId ) // WGS 84
|
||||||
, mDatumTransformStore( mDestCRS )
|
, mDatumTransformStore( mDestCRS )
|
||||||
@ -53,15 +54,42 @@ QgsMapSettings::QgsMapSettings()
|
|||||||
setMapUnits( QGis::Degrees );
|
setMapUnits( QGis::Degrees );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsMapSettings::setMagnificationFactor( double factor )
|
||||||
|
{
|
||||||
|
double ratio = mMagnificationFactor / factor;
|
||||||
|
mMagnificationFactor = factor;
|
||||||
|
|
||||||
|
double rot = rotation();
|
||||||
|
setRotation( 0.0 );
|
||||||
|
|
||||||
|
QgsRectangle ext = visibleExtent();
|
||||||
|
ext.scale( ratio );
|
||||||
|
|
||||||
|
mRotation = rot;
|
||||||
|
mExtent = ext;
|
||||||
|
mDpi = outputDpi() / ratio;
|
||||||
|
|
||||||
|
updateDerived();
|
||||||
|
}
|
||||||
|
|
||||||
|
double QgsMapSettings::magnificationFactor() const
|
||||||
|
{
|
||||||
|
return mMagnificationFactor;
|
||||||
|
}
|
||||||
|
|
||||||
QgsRectangle QgsMapSettings::extent() const
|
QgsRectangle QgsMapSettings::extent() const
|
||||||
{
|
{
|
||||||
return mExtent;
|
return mExtent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapSettings::setExtent( const QgsRectangle& extent )
|
void QgsMapSettings::setExtent( const QgsRectangle& extent, bool magnified )
|
||||||
{
|
{
|
||||||
mExtent = extent;
|
QgsRectangle magnifiedExtent = extent;
|
||||||
|
|
||||||
|
if ( !magnified )
|
||||||
|
magnifiedExtent.scale( 1 / mMagnificationFactor );
|
||||||
|
|
||||||
|
mExtent = magnifiedExtent;
|
||||||
|
|
||||||
updateDerived();
|
updateDerived();
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ class CORE_EXPORT QgsMapSettings
|
|||||||
//! The actual visible extent used for rendering could be slightly different
|
//! The actual visible extent used for rendering could be slightly different
|
||||||
//! since the given extent may be expanded in order to fit the aspect ratio
|
//! since the given extent may be expanded in order to fit the aspect ratio
|
||||||
//! of output size. Use visibleExtent() to get the resulting extent.
|
//! of output size. Use visibleExtent() to get the resulting extent.
|
||||||
void setExtent( const QgsRectangle& rect );
|
void setExtent( const QgsRectangle& rect, bool magnified = true );
|
||||||
|
|
||||||
//! Return the size of the resulting map image
|
//! Return the size of the resulting map image
|
||||||
QSize outputSize() const;
|
QSize outputSize() const;
|
||||||
@ -86,6 +86,13 @@ class CORE_EXPORT QgsMapSettings
|
|||||||
//! Set DPI used for conversion between real world units (e.g. mm) and pixels
|
//! Set DPI used for conversion between real world units (e.g. mm) and pixels
|
||||||
void setOutputDpi( int dpi );
|
void setOutputDpi( int dpi );
|
||||||
|
|
||||||
|
//! Set the magnification factor.
|
||||||
|
//! @note added in 2.16
|
||||||
|
void setMagnificationFactor( double factor );
|
||||||
|
//! Return the magnification factor.
|
||||||
|
//! @note added in 2.16
|
||||||
|
double magnificationFactor() const;
|
||||||
|
|
||||||
//! Get list of layer IDs for map rendering
|
//! Get list of layer IDs for map rendering
|
||||||
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
|
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
|
||||||
QStringList layers() const;
|
QStringList layers() const;
|
||||||
@ -261,6 +268,7 @@ class CORE_EXPORT QgsMapSettings
|
|||||||
QgsRectangle mExtent;
|
QgsRectangle mExtent;
|
||||||
|
|
||||||
double mRotation;
|
double mRotation;
|
||||||
|
double mMagnificationFactor;
|
||||||
|
|
||||||
QStringList mLayers;
|
QStringList mLayers;
|
||||||
QMap<QString, QString> mLayerStyleOverrides;
|
QMap<QString, QString> mLayerStyleOverrides;
|
||||||
@ -283,7 +291,6 @@ class CORE_EXPORT QgsMapSettings
|
|||||||
double mMapUnitsPerPixel;
|
double mMapUnitsPerPixel;
|
||||||
double mScale;
|
double mScale;
|
||||||
|
|
||||||
|
|
||||||
// utiity stuff
|
// utiity stuff
|
||||||
QgsScaleCalculator mScaleCalculator;
|
QgsScaleCalculator mScaleCalculator;
|
||||||
QgsMapToPixel mMapToPixel;
|
QgsMapToPixel mMapToPixel;
|
||||||
|
@ -80,10 +80,11 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
|
|||||||
virtual double valueFromText( const QString & text ) const override;
|
virtual double valueFromText( const QString & text ) const override;
|
||||||
virtual QValidator::State validate( QString & input, int & pos ) const override;
|
virtual QValidator::State validate( QString & input, int & pos ) const override;
|
||||||
|
|
||||||
|
void paintEvent( QPaintEvent* e ) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void resizeEvent( QResizeEvent* event ) override;
|
virtual void resizeEvent( QResizeEvent* event ) override;
|
||||||
virtual void changeEvent( QEvent* event ) override;
|
virtual void changeEvent( QEvent* event ) override;
|
||||||
virtual void paintEvent( QPaintEvent* event ) override;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void changed( double value );
|
void changed( double value );
|
||||||
@ -92,6 +93,8 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
|
|||||||
int frameWidth() const;
|
int frameWidth() const;
|
||||||
bool shouldShowClearForValue( const double value ) const;
|
bool shouldShowClearForValue( const double value ) const;
|
||||||
|
|
||||||
|
void updateStyleSheet( const QColor& backgroundColor = QColor() );
|
||||||
|
|
||||||
bool mShowClearButton;
|
bool mShowClearButton;
|
||||||
ClearValueMode mClearValueMode;
|
ClearValueMode mClearValueMode;
|
||||||
double mCustomClearValue;
|
double mCustomClearValue;
|
||||||
|
@ -189,6 +189,7 @@ void QgsMapCanvasRendererSync::onLayersC2R()
|
|||||||
QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
|
QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
|
||||||
: QGraphicsView( parent )
|
: QGraphicsView( parent )
|
||||||
, mCanvasProperties( new CanvasProperties )
|
, mCanvasProperties( new CanvasProperties )
|
||||||
|
, mMagnificationFactor( 1.0 )
|
||||||
, mJob( nullptr )
|
, mJob( nullptr )
|
||||||
, mJobCancelled( false )
|
, mJobCancelled( false )
|
||||||
, mLabelingResults( nullptr )
|
, mLabelingResults( nullptr )
|
||||||
@ -310,6 +311,17 @@ QgsMapCanvas::~QgsMapCanvas()
|
|||||||
|
|
||||||
} // dtor
|
} // dtor
|
||||||
|
|
||||||
|
void QgsMapCanvas::setMagnificationFactor( double level )
|
||||||
|
{
|
||||||
|
mSettings.setMagnificationFactor( level );
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
double QgsMapCanvas::magnificationFactor() const
|
||||||
|
{
|
||||||
|
return mSettings.magnificationFactor();
|
||||||
|
}
|
||||||
|
|
||||||
void QgsMapCanvas::enableAntiAliasing( bool theFlag )
|
void QgsMapCanvas::enableAntiAliasing( bool theFlag )
|
||||||
{
|
{
|
||||||
mSettings.setFlag( QgsMapSettings::Antialiasing, theFlag );
|
mSettings.setFlag( QgsMapSettings::Antialiasing, theFlag );
|
||||||
@ -757,7 +769,7 @@ void QgsMapCanvas::rendererJobFinished()
|
|||||||
|
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
mMap->setContent( img, imageRect( img, mJob->mapSettings() ) );
|
mMap->setContent( img, imageRect( img, mSettings ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// now we are in a slot called from mJob - do not delete it immediately
|
// now we are in a slot called from mJob - do not delete it immediately
|
||||||
@ -782,7 +794,7 @@ QgsRectangle QgsMapCanvas::imageRect( const QImage& img, const QgsMapSettings& m
|
|||||||
void QgsMapCanvas::mapUpdateTimeout()
|
void QgsMapCanvas::mapUpdateTimeout()
|
||||||
{
|
{
|
||||||
const QImage& img = mJob->renderedImage();
|
const QImage& img = mJob->renderedImage();
|
||||||
mMap->setContent( img, imageRect( img, mJob->mapSettings() ) );
|
mMap->setContent( img, imageRect( img, mSettings ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapCanvas::stopRendering()
|
void QgsMapCanvas::stopRendering()
|
||||||
@ -896,11 +908,11 @@ QgsRectangle QgsMapCanvas::fullExtent() const
|
|||||||
} // extent
|
} // extent
|
||||||
|
|
||||||
|
|
||||||
void QgsMapCanvas::setExtent( QgsRectangle const & r )
|
void QgsMapCanvas::setExtent( QgsRectangle const & r, bool magnified )
|
||||||
{
|
{
|
||||||
QgsRectangle current = extent();
|
QgsRectangle current = extent();
|
||||||
|
|
||||||
if ( r == current )
|
if (( r == current ) && magnified )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( r.isEmpty() )
|
if ( r.isEmpty() )
|
||||||
@ -918,7 +930,7 @@ void QgsMapCanvas::setExtent( QgsRectangle const & r )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mSettings.setExtent( r );
|
mSettings.setExtent( r, magnified );
|
||||||
}
|
}
|
||||||
emit extentsChanged();
|
emit extentsChanged();
|
||||||
updateScale();
|
updateScale();
|
||||||
@ -959,7 +971,8 @@ void QgsMapCanvas::setCenter( const QgsPoint& center )
|
|||||||
QgsRectangle(
|
QgsRectangle(
|
||||||
x - r.width() / 2.0, y - r.height() / 2.0,
|
x - r.width() / 2.0, y - r.height() / 2.0,
|
||||||
x + r.width() / 2.0, y + r.height() / 2.0
|
x + r.width() / 2.0, y + r.height() / 2.0
|
||||||
)
|
),
|
||||||
|
true
|
||||||
);
|
);
|
||||||
} // setCenter
|
} // setCenter
|
||||||
|
|
||||||
@ -1527,7 +1540,7 @@ void QgsMapCanvas::zoomWithCenter( int x, int y, bool zoomIn )
|
|||||||
QgsPoint center = getCoordinateTransform()->toMapPoint( x, y );
|
QgsPoint center = getCoordinateTransform()->toMapPoint( x, y );
|
||||||
QgsRectangle r = mapSettings().visibleExtent();
|
QgsRectangle r = mapSettings().visibleExtent();
|
||||||
r.scale( scaleFactor, ¢er );
|
r.scale( scaleFactor, ¢er );
|
||||||
setExtent( r );
|
setExtent( r, true );
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2007,7 +2020,7 @@ void QgsMapCanvas::zoomByFactor( double scaleFactor, const QgsPoint* center )
|
|||||||
{
|
{
|
||||||
QgsRectangle r = mapSettings().extent();
|
QgsRectangle r = mapSettings().extent();
|
||||||
r.scale( scaleFactor, center );
|
r.scale( scaleFactor, center );
|
||||||
setExtent( r );
|
setExtent( r, true );
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +119,16 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
|||||||
//! Destructor
|
//! Destructor
|
||||||
~QgsMapCanvas();
|
~QgsMapCanvas();
|
||||||
|
|
||||||
|
//! Sets the factor of magnification to apply to the map canvas. Indeed, we
|
||||||
|
//! increase/decrease the DPI of the map settings according to this factor
|
||||||
|
//! in order to render marker point, labels, ... bigger.
|
||||||
|
//! @note added in 2.16
|
||||||
|
void setMagnificationFactor( double level );
|
||||||
|
|
||||||
|
//! Returns the magnification factor
|
||||||
|
//! @note added in 2.16
|
||||||
|
double magnificationFactor() const;
|
||||||
|
|
||||||
void setLayerSet( QList<QgsMapCanvasLayer>& layers );
|
void setLayerSet( QList<QgsMapCanvasLayer>& layers );
|
||||||
|
|
||||||
void setCurrentLayer( QgsMapLayer* layer );
|
void setCurrentLayer( QgsMapLayer* layer );
|
||||||
@ -207,7 +217,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
|||||||
QgsRectangle fullExtent() const;
|
QgsRectangle fullExtent() const;
|
||||||
|
|
||||||
//! Set the extent of the map canvas
|
//! Set the extent of the map canvas
|
||||||
void setExtent( const QgsRectangle &r );
|
void setExtent( const QgsRectangle &r, bool magnified = false );
|
||||||
|
|
||||||
//! Get the current map canvas rotation in clockwise degrees
|
//! Get the current map canvas rotation in clockwise degrees
|
||||||
//! @note added in 2.8
|
//! @note added in 2.8
|
||||||
@ -722,6 +732,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
|||||||
//! Timer that periodically fires while map rendering is in progress to update the visible map
|
//! Timer that periodically fires while map rendering is in progress to update the visible map
|
||||||
QTimer mMapUpdateTimer;
|
QTimer mMapUpdateTimer;
|
||||||
|
|
||||||
|
//! magnification factor
|
||||||
|
double mMagnificationFactor;
|
||||||
|
|
||||||
//! Job that takes care of map rendering in background
|
//! Job that takes care of map rendering in background
|
||||||
QgsMapRendererQImageJob* mJob;
|
QgsMapRendererQImageJob* mJob;
|
||||||
|
|
||||||
|
@ -2045,6 +2045,39 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelMagnifier">
|
||||||
|
<property name="text">
|
||||||
|
<string>Magnification level</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBoxMagnifierDefault"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_4">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Expanding</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -17,7 +17,11 @@
|
|||||||
|
|
||||||
#include <qgsapplication.h>
|
#include <qgsapplication.h>
|
||||||
#include <qgsmapcanvas.h>
|
#include <qgsmapcanvas.h>
|
||||||
|
#include <qgsvectorlayer.h>
|
||||||
#include <qgsmaprenderer.h>
|
#include <qgsmaprenderer.h>
|
||||||
|
#include <qgsmaplayerregistry.h>
|
||||||
|
#include <qgsrenderchecker.h>
|
||||||
|
#include <qgsvectordataprovider.h>
|
||||||
|
|
||||||
namespace QTest
|
namespace QTest
|
||||||
{
|
{
|
||||||
@ -43,6 +47,9 @@ class TestQgsMapCanvas : public QObject
|
|||||||
|
|
||||||
void testMapRendererInteraction();
|
void testMapRendererInteraction();
|
||||||
void testPanByKeyboard();
|
void testPanByKeyboard();
|
||||||
|
void testMagnification();
|
||||||
|
void testMagnificationExtent();
|
||||||
|
void testMagnificationScale();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QgsMapCanvas* mCanvas;
|
QgsMapCanvas* mCanvas;
|
||||||
@ -53,6 +60,7 @@ class TestQgsMapCanvas : public QObject
|
|||||||
void TestQgsMapCanvas::initTestCase()
|
void TestQgsMapCanvas::initTestCase()
|
||||||
{
|
{
|
||||||
QgsApplication::init(); // init paths for CRS lookup
|
QgsApplication::init(); // init paths for CRS lookup
|
||||||
|
QgsApplication::initQgis();
|
||||||
|
|
||||||
mCanvas = new QgsMapCanvas();
|
mCanvas = new QgsMapCanvas();
|
||||||
}
|
}
|
||||||
@ -154,6 +162,203 @@ void TestQgsMapCanvas::testPanByKeyboard()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgsMapCanvas::testMagnification()
|
||||||
|
{
|
||||||
|
// test directory
|
||||||
|
QString testDataDir = QString( TEST_DATA_DIR ) + '/';
|
||||||
|
QString controlImageDir = testDataDir + "control_images/expected_map_magnification/";
|
||||||
|
|
||||||
|
// prepare spy and unit testing stuff
|
||||||
|
QgsRenderChecker checker;
|
||||||
|
checker.setControlPathPrefix( "mapcanvas" );
|
||||||
|
checker.setColorTolerance( 5 );
|
||||||
|
|
||||||
|
QSignalSpy spy( mCanvas, SIGNAL( mapCanvasRefreshed() ) );
|
||||||
|
|
||||||
|
QEventLoop loop;
|
||||||
|
QObject::connect( mCanvas, SIGNAL( mapCanvasRefreshed() ), &loop, SLOT( quit() ) );
|
||||||
|
|
||||||
|
QTimer timer;
|
||||||
|
QObject::connect( &timer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
|
||||||
|
|
||||||
|
QTemporaryFile tmpFile;
|
||||||
|
tmpFile.setAutoRemove( false );
|
||||||
|
tmpFile.open(); // fileName is not available until open
|
||||||
|
QString tmpName = tmpFile.fileName();
|
||||||
|
tmpFile.close();
|
||||||
|
|
||||||
|
// build vector layer
|
||||||
|
QString myPointsFileName = testDataDir + "points.shp";
|
||||||
|
QFileInfo myPointFileInfo( myPointsFileName );
|
||||||
|
QgsVectorLayer *layer = new QgsVectorLayer( myPointFileInfo.filePath(),
|
||||||
|
myPointFileInfo.completeBaseName(), "ogr" );
|
||||||
|
|
||||||
|
// prepare map canvas
|
||||||
|
QList<QgsMapCanvasLayer> layers;
|
||||||
|
layers.append( layer );
|
||||||
|
mCanvas->setLayerSet( layers );
|
||||||
|
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer *>() << layer );
|
||||||
|
|
||||||
|
mCanvas->setExtent( layer->extent() );
|
||||||
|
|
||||||
|
// refresh and wait for rendering
|
||||||
|
mCanvas->refresh();
|
||||||
|
timer.start( 3000 );
|
||||||
|
loop.exec();
|
||||||
|
QCOMPARE( spy.count(), 1 );
|
||||||
|
spy.clear();
|
||||||
|
|
||||||
|
// control image with magnification factor 1.0
|
||||||
|
mCanvas->saveAsImage( tmpName );
|
||||||
|
|
||||||
|
checker.setControlName( "expected_map_magnification" );
|
||||||
|
checker.setRenderedImage( tmpName );
|
||||||
|
checker.setSizeTolerance( 2, 2 );
|
||||||
|
QCOMPARE( checker.compareImages( "map_magnification", 100 ), true );
|
||||||
|
|
||||||
|
// set magnification factor (auto refresh)
|
||||||
|
mCanvas->setMagnificationFactor( 6.5 );
|
||||||
|
QCOMPARE( mCanvas->magnificationFactor(), 6.5 );
|
||||||
|
|
||||||
|
// wait for rendering
|
||||||
|
timer.start( 3000 );
|
||||||
|
loop.exec();
|
||||||
|
QCOMPARE( spy.count(), 1 );
|
||||||
|
spy.clear();
|
||||||
|
|
||||||
|
// control image with magnification factor 6.5
|
||||||
|
mCanvas->saveAsImage( tmpName );
|
||||||
|
|
||||||
|
checker.setRenderedImage( tmpName );
|
||||||
|
checker.setControlName( "expected_map_magnification_6_5" );
|
||||||
|
controlImageDir = testDataDir + "control_images/";
|
||||||
|
checker.setSizeTolerance( 2, 2 );
|
||||||
|
QCOMPARE( checker.compareImages( "map_magnification_6_5", 100 ), true );
|
||||||
|
|
||||||
|
// set magnification factor (auto refresh)
|
||||||
|
mCanvas->setMagnificationFactor( 1.0 );
|
||||||
|
QCOMPARE( mCanvas->magnificationFactor(), 1.0 );
|
||||||
|
|
||||||
|
// wait for rendering
|
||||||
|
timer.start( 3000 );
|
||||||
|
loop.exec();
|
||||||
|
QCOMPARE( spy.count(), 1 );
|
||||||
|
spy.clear();
|
||||||
|
|
||||||
|
// control image with magnification factor 1.0
|
||||||
|
mCanvas->saveAsImage( tmpName );
|
||||||
|
|
||||||
|
checker.setControlName( "expected_map_magnification" );
|
||||||
|
checker.setRenderedImage( tmpName );
|
||||||
|
checker.setSizeTolerance( 2, 2 );
|
||||||
|
QCOMPARE( checker.compareImages( "map_magnification", 100 ), true );
|
||||||
|
}
|
||||||
|
|
||||||
|
void compareExtent( const QgsRectangle &initialExtent,
|
||||||
|
const QgsRectangle &extent )
|
||||||
|
{
|
||||||
|
QVERIFY( qgsDoubleNear( initialExtent.xMinimum(), extent.xMinimum(), 0.00000000001 ) );
|
||||||
|
QVERIFY( qgsDoubleNear( initialExtent.xMaximum(), extent.xMaximum(), 0.00000000001 ) );
|
||||||
|
QVERIFY( qgsDoubleNear( initialExtent.yMinimum(), extent.yMinimum(), 0.00000000001 ) );
|
||||||
|
QVERIFY( qgsDoubleNear( initialExtent.yMaximum(), extent.yMaximum(), 0.00000000001 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQgsMapCanvas::testMagnificationExtent()
|
||||||
|
{
|
||||||
|
// build vector layer
|
||||||
|
QString testDataDir = QString( TEST_DATA_DIR ) + '/';
|
||||||
|
QString myPointsFileName = testDataDir + "points.shp";
|
||||||
|
QFileInfo myPointFileInfo( myPointsFileName );
|
||||||
|
QgsVectorLayer *layer = new QgsVectorLayer( myPointFileInfo.filePath(),
|
||||||
|
myPointFileInfo.completeBaseName(), "ogr" );
|
||||||
|
|
||||||
|
// prepare map canvas
|
||||||
|
QList<QgsMapCanvasLayer> layers;
|
||||||
|
layers.append( layer );
|
||||||
|
mCanvas->setLayerSet( layers );
|
||||||
|
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer *>() << layer );
|
||||||
|
|
||||||
|
// zoomToFullExtent
|
||||||
|
mCanvas->zoomToFullExtent();
|
||||||
|
QgsRectangle initialExtent = mCanvas->extent();
|
||||||
|
|
||||||
|
mCanvas->setMagnificationFactor( 4.0 );
|
||||||
|
mCanvas->setMagnificationFactor( 1.0 );
|
||||||
|
|
||||||
|
compareExtent( mCanvas->extent(), initialExtent );
|
||||||
|
|
||||||
|
// setExtent with layer extent
|
||||||
|
mCanvas->setExtent( layer->extent() );
|
||||||
|
initialExtent = mCanvas->extent();
|
||||||
|
|
||||||
|
mCanvas->setMagnificationFactor( 4.0 );
|
||||||
|
mCanvas->setMagnificationFactor( 1.0 );
|
||||||
|
|
||||||
|
compareExtent( mCanvas->extent(), initialExtent );
|
||||||
|
|
||||||
|
// zoomToSelected
|
||||||
|
QgsFeature f1( layer->dataProvider()->fields(), 1 );
|
||||||
|
QgsFeature f2( layer->dataProvider()->fields(), 2 );
|
||||||
|
QgsFeatureIds ids;
|
||||||
|
ids << f1.id() << f2.id();
|
||||||
|
layer->setSelectedFeatures( ids );
|
||||||
|
|
||||||
|
mCanvas->zoomToSelected( layer );
|
||||||
|
initialExtent = mCanvas->extent();
|
||||||
|
|
||||||
|
mCanvas->setMagnificationFactor( 4.0 );
|
||||||
|
mCanvas->setMagnificationFactor( 1.0 );
|
||||||
|
|
||||||
|
compareExtent( mCanvas->extent(), initialExtent );
|
||||||
|
|
||||||
|
// zoomToFeatureIds
|
||||||
|
mCanvas->zoomToFeatureIds( layer, ids );
|
||||||
|
initialExtent = mCanvas->extent();
|
||||||
|
|
||||||
|
mCanvas->setMagnificationFactor( 4.0 );
|
||||||
|
mCanvas->setMagnificationFactor( 1.0 );
|
||||||
|
|
||||||
|
compareExtent( mCanvas->extent(), initialExtent );
|
||||||
|
|
||||||
|
// zoomIn / zoomOut
|
||||||
|
initialExtent = mCanvas->extent();
|
||||||
|
mCanvas->zoomIn();
|
||||||
|
|
||||||
|
mCanvas->setMagnificationFactor( 4.0 );
|
||||||
|
mCanvas->zoomIn();
|
||||||
|
mCanvas->zoomOut();
|
||||||
|
mCanvas->setMagnificationFactor( 1.0 );
|
||||||
|
|
||||||
|
mCanvas->zoomOut();
|
||||||
|
|
||||||
|
compareExtent( mCanvas->extent(), initialExtent );
|
||||||
|
|
||||||
|
// zoomScale
|
||||||
|
initialExtent = mCanvas->extent();
|
||||||
|
double scale = mCanvas->scale();
|
||||||
|
mCanvas->zoomScale( 6.052017*10e7 );
|
||||||
|
|
||||||
|
mCanvas->setMagnificationFactor( 4.0 );
|
||||||
|
mCanvas->setMagnificationFactor( 1.0 );
|
||||||
|
|
||||||
|
mCanvas->zoomScale( scale );
|
||||||
|
compareExtent( mCanvas->extent(), initialExtent );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQgsMapCanvas::testMagnificationScale()
|
||||||
|
{
|
||||||
|
mCanvas->setMagnificationFactor( 1.0 );
|
||||||
|
double initialScale = mCanvas->scale();
|
||||||
|
|
||||||
|
mCanvas->setMagnificationFactor( 4.0 );
|
||||||
|
QCOMPARE( initialScale, mCanvas->scale() );
|
||||||
|
|
||||||
|
mCanvas->setMagnificationFactor( 7.5 );
|
||||||
|
QCOMPARE( initialScale, mCanvas->scale() );
|
||||||
|
|
||||||
|
mCanvas->setMagnificationFactor( 1.0 );
|
||||||
|
QCOMPARE( initialScale, mCanvas->scale() );
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN( TestQgsMapCanvas )
|
QTEST_MAIN( TestQgsMapCanvas )
|
||||||
#include "testqgsmapcanvas.moc"
|
#include "testqgsmapcanvas.moc"
|
||||||
|
BIN
tests/testdata/control_images/mapcanvas/expected_map_magnification/expected_map_magnification.png
vendored
Normal file
BIN
tests/testdata/control_images/mapcanvas/expected_map_magnification/expected_map_magnification.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
Loading…
x
Reference in New Issue
Block a user