QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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 "qgspoint.h"
18
20 : QObject( parent )
21{
22}
23
25{
26 if ( mMapSettings == mapSettings )
27 return;
28
29 if ( mMapSettings )
30 {
31 disconnect( mMapSettings, &QgsQuickMapSettings::extentChanged, this, &QgsQuickMapToScreen::transformPoint );
32 disconnect( mMapSettings, &QgsQuickMapSettings::rotationChanged, this, &QgsQuickMapToScreen::transformPoint );
33 disconnect( mMapSettings, &QgsQuickMapSettings::outputSizeChanged, this, &QgsQuickMapToScreen::transformPoint );
34 }
35
36 mMapSettings = mapSettings;
37
38 connect( mMapSettings, &QgsQuickMapSettings::extentChanged, this, &QgsQuickMapToScreen::transformPoint );
39 connect( mMapSettings, &QgsQuickMapSettings::rotationChanged, this, &QgsQuickMapToScreen::transformPoint );
40 connect( mMapSettings, &QgsQuickMapSettings::outputSizeChanged, this, &QgsQuickMapToScreen::transformPoint );
41
42 transformPoint();
43 transformDistance();
44
45 emit mapSettingsChanged();
46}
47
49{
50 return mMapSettings;
51}
52
54{
55 if ( mMapPoint == point )
56 return;
57
58 mMapPoint = point;
59 emit mapPointChanged();
60 transformPoint();
61}
62
64{
65 return mMapPoint;
66}
67
69{
70 return mScreenPoint;
71}
72
73void QgsQuickMapToScreen::transformPoint()
74{
75 if ( !mMapSettings )
76 {
77 mScreenPoint = QPointF();
78 }
79 else
80 {
81 mScreenPoint = mMapSettings->coordinateToScreen( mMapPoint );
82 }
83 emit screenPointChanged();
84}
85
86void QgsQuickMapToScreen::setMapDistance( const double distance )
87{
88 if ( mMapDistance == distance )
89 return;
90
91 mMapDistance = distance;
92 emit mapDistanceChanged();
93 transformDistance();
94}
95
97{
98 return mMapDistance;
99}
100
102{
103 return mScreenDistance;
104}
105
106void QgsQuickMapToScreen::transformDistance()
107{
108 if ( !mMapSettings || qgsDoubleNear( mMapDistance, 0.0 ) || qgsDoubleNear( mMapSettings->mapUnitsPerPoint(), 0.0 ) )
109 {
110 mScreenDistance = 0.0;
111 }
112 else
113 {
114 mScreenDistance = mMapDistance / mMapSettings->mapUnitsPerPoint();
115 }
117}
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:4332