move magnification in map settings

This commit is contained in:
Blottiere Paul 2016-05-18 14:36:02 +02:00
parent 95038b143d
commit d23a110cb6
6 changed files with 57 additions and 22 deletions

View File

@ -17,7 +17,7 @@ class QgsMapSettings
//! 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
//! 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
QSize outputSize() const;
@ -39,6 +39,13 @@ 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.
//! @note added in 2.16
double magnificationFactor() const;
//! 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)
QStringList layers() const;

View File

@ -57,6 +57,7 @@ class QgsMapCanvas : QGraphicsView
void setMagnificationFactor( double level );
//! Returns the magnification factor
//! @note added in 2.16
double magnificationFactor() const;
void setLayerSet( QList<QgsMapCanvasLayer>& layers );

View File

@ -35,6 +35,7 @@ QgsMapSettings::QgsMapSettings()
, mSize( QSize( 0, 0 ) )
, mExtent()
, mRotation( 0.0 )
, mMagnificationFactor( 1.0 )
, mProjectionsEnabled( false )
, mDestCRS( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId ) // WGS 84
, mDatumTransformStore( mDestCRS )
@ -53,15 +54,42 @@ QgsMapSettings::QgsMapSettings()
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
{
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();
}

View File

@ -64,7 +64,7 @@ class CORE_EXPORT QgsMapSettings
//! 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
//! 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
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
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
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
QStringList layers() const;
@ -261,6 +268,7 @@ class CORE_EXPORT QgsMapSettings
QgsRectangle mExtent;
double mRotation;
double mMagnificationFactor;
QStringList mLayers;
QMap<QString, QString> mLayerStyleOverrides;

View File

@ -313,21 +313,15 @@ QgsMapCanvas::~QgsMapCanvas()
void QgsMapCanvas::setMagnificationFactor( double level )
{
QgsMapSettings settings = mSettings;
settings.setRotation( 0.0 );
double ratio = mMagnificationFactor / level;
mMagnificationFactor = level;
QgsRectangle ext = settings.visibleExtent();
ext.scale( ratio );
mSettings.setOutputDpi( mSettings.outputDpi() / ratio );
setExtent( ext, true );
mSettings.setMagnificationFactor( level );
refresh();
}
double QgsMapCanvas::magnificationFactor() const
{
return mSettings.magnificationFactor();
}
void QgsMapCanvas::enableAntiAliasing( bool theFlag )
{
mSettings.setFlag( QgsMapSettings::Antialiasing, theFlag );
@ -905,11 +899,7 @@ void QgsMapCanvas::setExtent( QgsRectangle const & r, bool magnified )
}
else
{
QgsRectangle magnifiedExtent = r;
if ( ! magnified )
magnifiedExtent.scale( 1 / mMagnificationFactor );
mSettings.setExtent( magnifiedExtent );
mSettings.setExtent( r, magnified );
}
emit extentsChanged();
updateScale();

View File

@ -126,7 +126,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
void setMagnificationFactor( double level );
//! Returns the magnification factor
double magnificationFactor() const { return mMagnificationFactor; };
//! @note added in 2.16
double magnificationFactor() const;
void setLayerSet( QList<QgsMapCanvasLayer>& layers );