QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
qgsquickmaptransform.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsquickmaptransform.cpp
3 --------------------------------------
4 Date : 27.12.2014
5 Copyright : (C) 2014 by Matthias Kuhn
6 Email : matthias (at) opengis.ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18void QgsQuickMapTransform::applyTo( QMatrix4x4 *matrix ) const
19{
20 *matrix *= mMatrix;
21 matrix->optimize();
22}
23
25{
26 return mMapSettings;
27}
28
30{
31 if ( mapSettings == mMapSettings )
32 return;
33
34 if ( mMapSettings )
35 disconnect( mMapSettings, &QgsQuickMapSettings::visibleExtentChanged, this, &QgsQuickMapTransform::updateMatrix );
36
37 mMapSettings = mapSettings;
38
39 if ( mMapSettings )
40 connect( mMapSettings, &QgsQuickMapSettings::visibleExtentChanged, this, &QgsQuickMapTransform::updateMatrix );
41
42 updateMatrix();
43
44 emit mapSettingsChanged();
45}
46
47void QgsQuickMapTransform::updateMatrix()
48{
49 QMatrix4x4 matrix;
50 float scaleFactor = static_cast<float>( ( 1.0 / mMapSettings->mapUnitsPerPixel() ) / mMapSettings->devicePixelRatio() );
51
52 matrix.scale( scaleFactor, -scaleFactor );
53 matrix.translate( static_cast<float>( -mMapSettings->visibleExtent().xMinimum( ) ),
54 static_cast<float>( -mMapSettings->visibleExtent().yMaximum() ) );
55
56 mMatrix = matrix;
57 update();
58}
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
QgsRectangle visibleExtent
Returns the actual extent derived from requested extent that takes output image size into account.
void visibleExtentChanged()
Returns the actual extent derived from requested extent that takes output image size into account.
double mapUnitsPerPixel
Returns the distance in geographical coordinates that equals to one pixel in the map.
qreal devicePixelRatio() const
Returns the ratio between physical pixels and device-independent pixels.
void applyTo(QMatrix4x4 *matrix) const
Applies transformation based on current map settings to a matrix.
void setMapSettings(QgsQuickMapSettings *mapSettings)
Associated map settings.
QgsQuickMapSettings * mapSettings
Associated map settings.
void mapSettingsChanged()
Associated map settings.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).