QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsquickmaptoscreen.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsquickmaptoscreen.cpp
3 ----------------------------------------------------
4 Date : 22.08.2018
5 Copyright : (C) 2018 by Denis Rouzaud
6 Email : denis (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
16#include "qgsquickmaptoscreen.h"
17#include "moc_qgsquickmaptoscreen.cpp"
18#include "qgspoint.h"
19
21 : QObject( parent )
22{
23}
24
26{
27 if ( mMapSettings == mapSettings )
28 return;
29
30 if ( mMapSettings )
31 {
32 disconnect( mMapSettings, &QgsQuickMapSettings::extentChanged, this, &QgsQuickMapToScreen::transformPoint );
33 disconnect( mMapSettings, &QgsQuickMapSettings::rotationChanged, this, &QgsQuickMapToScreen::transformPoint );
34 disconnect( mMapSettings, &QgsQuickMapSettings::outputSizeChanged, this, &QgsQuickMapToScreen::transformPoint );
35 }
36
37 mMapSettings = mapSettings;
38
39 connect( mMapSettings, &QgsQuickMapSettings::extentChanged, this, &QgsQuickMapToScreen::transformPoint );
40 connect( mMapSettings, &QgsQuickMapSettings::rotationChanged, this, &QgsQuickMapToScreen::transformPoint );
41 connect( mMapSettings, &QgsQuickMapSettings::outputSizeChanged, this, &QgsQuickMapToScreen::transformPoint );
42
43 transformPoint();
44 transformDistance();
45
46 emit mapSettingsChanged();
47}
48
50{
51 return mMapSettings;
52}
53
55{
56 if ( mMapPoint == point )
57 return;
58
59 mMapPoint = point;
60 emit mapPointChanged();
61 transformPoint();
62}
63
65{
66 return mMapPoint;
67}
68
70{
71 return mScreenPoint;
72}
73
74void QgsQuickMapToScreen::transformPoint()
75{
76 if ( !mMapSettings )
77 {
78 mScreenPoint = QPointF();
79 }
80 else
81 {
82 mScreenPoint = mMapSettings->coordinateToScreen( mMapPoint );
83 }
84 emit screenPointChanged();
85}
86
87void QgsQuickMapToScreen::setMapDistance( const double distance )
88{
89 if ( mMapDistance == distance )
90 return;
91
92 mMapDistance = distance;
93 emit mapDistanceChanged();
94 transformDistance();
95}
96
98{
99 return mMapDistance;
100}
101
103{
104 return mScreenDistance;
105}
106
107void QgsQuickMapToScreen::transformDistance()
108{
109 if ( !mMapSettings || qgsDoubleNear( mMapDistance, 0.0 ) || qgsDoubleNear( mMapSettings->mapUnitsPerPoint(), 0.0 ) )
110 {
111 mScreenDistance = 0.0;
112 }
113 else
114 {
115 mScreenDistance = mMapDistance / mMapSettings->mapUnitsPerPoint();
116 }
118}
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
void extentChanged()
Geographical coordinates of the rectangle that should be rendered.
void outputSizeChanged()
The size of the resulting map image.
double mapUnitsPerPoint
Returns the distance in geographical coordinates that equals to one point unit in the map.
void rotationChanged()
The rotation of the resulting map image, in degrees clockwise.
Q_INVOKABLE QPointF coordinateToScreen(const QgsPoint &point) const
Convert a map coordinate to screen pixel coordinates.
void mapPointChanged()
Point in map coordinates.
QPointF screenPoint
Point in screen coordinates (read-only)
QgsQuickMapSettings * mapSettings
Map settings used to define the map canvas CRS and detect any extent change.
void mapDistanceChanged()
Distance in map unit.
QgsQuickMapToScreen(QObject *parent=nullptr)
Creates a map to screen object.
void mapSettingsChanged()
Map settings used to define the map canvas CRS and detect any extent change.
void screenPointChanged()
Point in screen coordinates (read-only)
void screenDistanceChanged()
Distance in screen coordinates (read-only)
void setMapSettings(QgsQuickMapSettings *mapSettings)
Map settings used to define the map canvas CRS and detect any extent change.
double screenDistance
Distance in screen coordinates (read-only)
QgsPoint mapPoint
Point in map coordinates.
void setMapDistance(const double distance)
Distance in map unit.
void setMapPoint(const QgsPoint &point)
Point in map coordinates.
double mapDistance
Distance in map unit.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:6024