Skip to content

Commit 5f07851

Browse files
viktor.sklencar@lutraconsulting.co.ukPeterPetrik
viktor.sklencar@lutraconsulting.co.uk
authored andcommittedJun 25, 2018
[feature ] Add PositionKit, PositionMarker and other related classes to QgsQuick.
For background information see the associated QEP (qgis/QGIS-Enhancement-Proposals#109
1 parent 7acfe03 commit 5f07851

21 files changed

+1343
-9
lines changed
 

‎doc/qgsquick.dox

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ QGIS Quick consists of a Qt plugin that provides the QML components and of a sha
1313

1414
\subsection qgsquick_overview_widgets QML Classes
1515
\subsubsection qgsquick_overview_widgets_mapcanvas MapCanvas
16-
Similarly to QgsMapCanvas, this component can be used for displaying GIS data on a canvas. See also QgsQuickMapCanvasMap.
16+
\subsubsection qgsquick_overview_widgets_positionmarker PositionMarker
17+
The element refers to current position according gps location device connected to it. It holds information about longitude, latitude, altitude,
18+
direction of the movement and accuracy of the signal. See also QgsQuickPostionKit.
1719
\subsubsection qgsquick_overview_widgets_scalebar ScaleBar
1820
A QML component that shows the scale ratio between its length and distance on the MapCanvas. There are predefined rounded values
1921
for several zooming levels with 'm' or 'km' postfixes. After any zoom in/out event on canvas recalculates its properties and updates

‎src/quickgui/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
# sources
33
SET(QGIS_QUICK_GUI_MOC_HDRS
44
qgsquickfeaturelayerpair.h
5+
qgsquickcoordinatetransformer.h
56
qgsquickfeaturehighlight.h
67
qgsquickidentifykit.h
78
qgsquickmapcanvasmap.h
89
qgsquickmapsettings.h
910
qgsquickmaptransform.h
1011
qgsquickmessagelogmodel.h
12+
qgsquickpositionkit.h
1113
qgsquickscalebarkit.h
14+
qgsquicksimulatedpositionsource.h
1215
qgsquickutils.h
1316
)
1417

@@ -18,14 +21,17 @@ SET(QGIS_QUICK_GUI_HDRS
1821

1922
SET(QGIS_QUICK_GUI_SRC
2023
qgsquickfeaturelayerpair.cpp
24+
qgsquickcoordinatetransformer.cpp
2125
qgsquickfeaturehighlight.cpp
2226
qgsquickhighlightsgnode.cpp
2327
qgsquickidentifykit.cpp
2428
qgsquickmapcanvasmap.cpp
2529
qgsquickmapsettings.cpp
2630
qgsquickmaptransform.cpp
2731
qgsquickmessagelogmodel.cpp
32+
qgsquickpositionkit.cpp
2833
qgsquickscalebarkit.cpp
34+
qgsquicksimulatedpositionsource.cpp
2935
qgsquickutils.cpp
3036
)
3137

@@ -69,6 +75,10 @@ INCLUDE_DIRECTORIES(SYSTEM
6975

7076
ADD_DEFINITIONS(-DCORE_EXPORT=)
7177

78+
79+
SET(QGIS_QUICK_GUI_IMAGE_RCCS ./images/images.qrc)
80+
QT5_ADD_RESOURCES(QGIS_QUICK_GUI_IMAGE_RCC_SRCS ${QGIS_QUICK_GUI_IMAGE_RCCS})
81+
7282
############################################################
7383
# qgis_quick shared library
7484
QT5_WRAP_CPP(QGIS_QUICK_GUI_MOC_SRCS ${QGIS_QUICK_GUI_MOC_HDRS})
Lines changed: 4 additions & 0 deletions
Loading

‎src/quickgui/images/images.qrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>ic_navigation_black.svg</file>
4+
</qresource>
5+
</RCC>

‎src/quickgui/plugin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SET(QGIS_QUICK_PLUGIN_SRC
1212
SET(QGIS_QUICK_PLUGIN_RESOURCES
1313
qgsquickmapcanvas.qml
1414
qgsquickmessagelog.qml
15+
qgsquickpositionmarker.qml
1516
qgsquickscalebar.qml
1617
qmldir
1718
)

‎src/quickgui/plugin/qgsquickplugin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
#include "qgsvectorlayer.h"
3131

3232
#include "qgsquickfeaturehighlight.h"
33+
#include "qgsquickcoordinatetransformer.h"
3334
#include "qgsquickidentifykit.h"
3435
#include "qgsquickfeaturelayerpair.h"
3536
#include "qgsquickmapcanvasmap.h"
3637
#include "qgsquickmapsettings.h"
3738
#include "qgsquickmaptransform.h"
3839
#include "qgsquickmessagelogmodel.h"
3940
#include "qgsquickplugin.h"
41+
#include "qgsquickpositionkit.h"
4042
#include "qgsquickscalebarkit.h"
4143
#include "qgsquickutils.h"
4244

@@ -61,11 +63,13 @@ void QgsQuickPlugin::registerTypes( const char *uri )
6163

6264
qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
6365
qmlRegisterType< QgsQuickFeatureHighlight >( uri, 0, 1, "FeatureHighlight" );
66+
qmlRegisterType< QgsQuickCoordinateTransformer >( uri, 0, 1, "CoordinateTransformer" );
6467
qmlRegisterType< QgsQuickIdentifyKit >( uri, 0, 1, "IdentifyKit" );
6568
qmlRegisterType< QgsQuickMapCanvasMap >( uri, 0, 1, "MapCanvasMap" );
6669
qmlRegisterType< QgsQuickMapSettings >( uri, 0, 1, "MapSettings" );
6770
qmlRegisterType< QgsQuickMapTransform >( uri, 0, 1, "MapTransform" );
6871
qmlRegisterType< QgsQuickMessageLogModel >( uri, 0, 1, "MessageLogModel" );
72+
qmlRegisterType< QgsQuickPositionKit >( uri, 0, 1, "PositionKit" );
6973
qmlRegisterType< QgsQuickScaleBarKit >( uri, 0, 1, "ScaleBarKit" );
7074
qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );
7175

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/***************************************************************************
2+
qgsquickpositionmarker.qml
3+
--------------------------------------
4+
Date : Dec 2017
5+
Copyright : (C) 2017 by Peter Petrik
6+
Email : zilolv at gmail dot com
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+
import QtQuick 2.3
17+
import QtQuick.Controls 2.2
18+
import QtQml 2.2
19+
import QtGraphicalEffects 1.0
20+
import QgsQuick 0.1 as QgsQuick
21+
22+
/**
23+
* \brief Graphical representation of physical location on the map.
24+
*
25+
* Source position and accuracy taken from PositionKit is drawn as a marker on the map.
26+
* Marker is grayed out when position is not available. When PositionKit support reading of the accuracy,
27+
* the circle is drawn around the marker. PositionKit must be connected, for example GPS position source from QgsQuickPositionKit.
28+
*/
29+
Item {
30+
id: positionMarker
31+
property int size: 48 * QgsQuick.Utils.dp
32+
33+
/**
34+
* Utils for handling position.
35+
*/
36+
property QgsQuick.PositionKit positionKit
37+
38+
/**
39+
* Color of the marker when position is known.
40+
*/
41+
property color baseColor: "darkblue"
42+
/**
43+
* Color of the marker when position is unknown (e.g. GPS signal lost).
44+
*/
45+
property color unavailableColor: "gray"
46+
47+
/**
48+
* Whether circle representing accuracy of the position should be rendered.
49+
*/
50+
property var withAccuracy: true
51+
52+
/**
53+
* Icon for position marker.
54+
*/
55+
property var markerIcon: QgsQuick.Utils.getThemeIcon("ic_navigation_black")
56+
57+
/**
58+
* Source position accuracy circle-shaped indicator around positionMarker.
59+
*/
60+
Rectangle {
61+
id: accuracyIndicator
62+
visible: withAccuracy &&
63+
positionKit.hasPosition &&
64+
(positionKit.accuracy > 0) &&
65+
(accuracyIndicator.width > positionMarker.size / 2.0)
66+
x: positionKit.screenPosition.x - width/2
67+
y: positionKit.screenPosition.y - height/2
68+
width:positionKit.screenAccuracy
69+
height: accuracyIndicator.width
70+
color: baseColor
71+
border.color: "black"
72+
border.width: 3 * QgsQuick.Utils.dp
73+
radius: width*0.5
74+
opacity: 0.1
75+
}
76+
77+
/**
78+
* Position marker.
79+
*/
80+
Rectangle {
81+
id: navigationMarker
82+
property int borderWidth: 2 * QgsQuick.Utils.dp
83+
width: positionMarker.size + 20 * QgsQuick.Utils.dp
84+
height: width
85+
color: "white"
86+
border.color: baseColor
87+
border.width: borderWidth
88+
radius: width*0.5
89+
antialiasing: true
90+
x: positionKit.screenPosition.x - width/2
91+
y: positionKit.screenPosition.y - height/2
92+
93+
Image {
94+
id: navigation
95+
source: positionMarker.markerIcon
96+
fillMode: Image.PreserveAspectFit
97+
rotation: positionKit.direction
98+
anchors.centerIn: parent
99+
width: positionMarker.size
100+
height: width
101+
}
102+
103+
/**
104+
* Makes positionMarker (navigation) grey if position is unknown.
105+
*/
106+
ColorOverlay {
107+
anchors.fill: navigation
108+
source: navigation
109+
color: positionKit.hasPosition ? baseColor : unavailableColor
110+
rotation: positionKit.direction
111+
visible: !(positionKit.hasPosition)
112+
}
113+
}
114+
}
115+

‎src/quickgui/plugin/qmldir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module QgsQuick
1414
plugin qgis_quick_plugin
1515

1616
MapCanvas 0.1 qgsquickmapcanvas.qml
17+
PositionMarker 0.1 qgsquickpositionmarker.qml
1718
ScaleBar 0.1 qgsquickscalebar.qml
1819
MessageLog 0.1 qgsquickmessagelog.qml
1920

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/***************************************************************************
2+
qgsquickcoordinatetransformer.cpp
3+
--------------------------------------
4+
Date : 1.6.2017
5+
Copyright : (C) 2017 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+
16+
#include <QtDebug>
17+
18+
#include "qgsquickcoordinatetransformer.h"
19+
20+
QgsQuickCoordinateTransformer::QgsQuickCoordinateTransformer( QObject *parent )
21+
: QObject( parent )
22+
{
23+
mCoordinateTransform.setSourceCrs( QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );
24+
mCoordinateTransform.setContext( QgsCoordinateTransformContext() );
25+
}
26+
27+
QgsPoint QgsQuickCoordinateTransformer::projectedPosition() const
28+
{
29+
return mProjectedPosition;
30+
}
31+
32+
QgsPoint QgsQuickCoordinateTransformer::sourcePosition() const
33+
{
34+
return mSourcePosition;
35+
}
36+
37+
void QgsQuickCoordinateTransformer::setSourcePosition( QgsPoint sourcePosition )
38+
{
39+
if ( mSourcePosition == sourcePosition )
40+
return;
41+
42+
mSourcePosition = sourcePosition;
43+
44+
emit sourcePositionChanged();
45+
updatePosition();
46+
}
47+
48+
QgsCoordinateReferenceSystem QgsQuickCoordinateTransformer::destinationCrs() const
49+
{
50+
return mCoordinateTransform.destinationCrs();
51+
}
52+
53+
void QgsQuickCoordinateTransformer::setDestinationCrs( const QgsCoordinateReferenceSystem &destinationCrs )
54+
{
55+
if ( destinationCrs == mCoordinateTransform.destinationCrs() )
56+
return;
57+
58+
mCoordinateTransform.setDestinationCrs( destinationCrs );
59+
emit destinationCrsChanged();
60+
updatePosition();
61+
}
62+
63+
QgsCoordinateReferenceSystem QgsQuickCoordinateTransformer::sourceCrs() const
64+
{
65+
return mCoordinateTransform.sourceCrs();
66+
}
67+
68+
void QgsQuickCoordinateTransformer::setSourceCrs( const QgsCoordinateReferenceSystem &sourceCrs )
69+
{
70+
if ( sourceCrs == mCoordinateTransform.sourceCrs() )
71+
return;
72+
73+
mCoordinateTransform.setSourceCrs( sourceCrs );
74+
75+
emit sourceCrsChanged();
76+
updatePosition();
77+
}
78+
79+
void QgsQuickCoordinateTransformer::updatePosition()
80+
{
81+
double x = mSourcePosition.x();
82+
double y = mSourcePosition.y();
83+
double z = mSourcePosition.z();
84+
85+
// If Z is NaN, coordinate transformation (proj4) will
86+
// also set X and Y to NaN. But we also want to get projected
87+
// coords if we do not have any Z coordinate.
88+
if ( qIsNaN( z ) )
89+
{
90+
z = 0;
91+
}
92+
93+
if ( mMapSettings )
94+
mCoordinateTransform.setContext( mMapSettings->transformContext() );
95+
96+
mCoordinateTransform.transformInPlace( x, y, z );
97+
98+
mProjectedPosition = QgsPoint( x, y );
99+
mProjectedPosition.addZValue( mSourcePosition.z() );
100+
101+
emit projectedPositionChanged();
102+
}

0 commit comments

Comments
 (0)
Please sign in to comment.