Skip to content

Commit 569db8e

Browse files
authored
Merge pull request #7045 from PeterPetrik/qgs-quick-position_and_transformer
[feature] [qgsquick] Add PositionKit, PositionMarker and CoordinateTransformer
2 parents 7a68002 + b55db3d commit 569db8e

27 files changed

+1724
-24
lines changed

doc/qgsquick.dox

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ 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 QgsQuickPositionKit.
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
2022
text. See also QgsQuickScaleBarKit.
21-
2223
\subsubsection qgsquick_overview_widgets_messagelog MessageLog
2324
A simple panel which can be used for publishing logs messages to a user such as basic information about the application or its status.
2425
See also QgsQuickMessageLogModel.

python/core/auto_additions/qgsunittypes.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# The following has been generated automatically from src/core/qgsunittypes.h
2+
QgsUnitTypes.SystemOfMeasurement.baseClass = QgsUnitTypes
23
QgsUnitTypes.DistanceUnit.baseClass = QgsUnitTypes
34
QgsUnitTypes.AreaUnit.baseClass = QgsUnitTypes
45
QgsUnitTypes.AngleUnit.baseClass = QgsUnitTypes

python/core/auto_generated/qgsunittypes.sip.in

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ Helper functions for various unit types.
2626
static const QMetaObject staticMetaObject;
2727

2828
public:
29+
enum SystemOfMeasurement
30+
{
31+
UnknownSystem,
32+
MetricSystem,
33+
ImperialSystem,
34+
USCSSystem
35+
};
36+
2937
enum DistanceUnit
3038
{
3139
DistanceMeters,

src/core/qgsunittypes.h

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ class CORE_EXPORT QgsUnitTypes
3939
Q_GADGET
4040

4141
public:
42+
//! Systems of unit measurement
43+
enum SystemOfMeasurement
44+
{
45+
UnknownSystem = 0, //!< Unknown system of measurement
46+
MetricSystem, //!< International System of Units (SI)
47+
ImperialSystem, //!< British Imperial
48+
USCSSystem //!< United States customary system
49+
};
50+
Q_ENUM( SystemOfMeasurement )
51+
4252
//! Units of distance
4353
enum DistanceUnit
4454
{

src/quickgui/CMakeLists.txt

+10
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})
Loading

src/quickgui/images/images.qrc

+5
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

+3-1
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
)
@@ -108,8 +109,9 @@ IF(QMLPLUGINDUMP_FOUND)
108109
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qmldir ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
109110
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:qgis_quick_plugin> ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
110111
COMMAND ${QMLPLUGINDUMP_EXECUTABLE}
111-
ARGS QgsQuick ${QGIS_QUICK_VERSION} . --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
112+
ARGS QgsQuick ${QGIS_QUICK_VERSION} . -noinstantiate --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
112113
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
114+
COMMENT "Generating qgsquick.qmltypes with qmlplugindump"
113115
POST_BUILD
114116
)
115117
ENDIF()

src/quickgui/plugin/qgsquickplugin.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@
2828
#include "qgsrelationmanager.h"
2929
#include "qgscoordinatetransformcontext.h"
3030
#include "qgsvectorlayer.h"
31+
#include "qgsunittypes.h"
3132

3233
#include "qgsquickfeaturehighlight.h"
34+
#include "qgsquickcoordinatetransformer.h"
3335
#include "qgsquickidentifykit.h"
3436
#include "qgsquickfeaturelayerpair.h"
3537
#include "qgsquickmapcanvasmap.h"
3638
#include "qgsquickmapsettings.h"
3739
#include "qgsquickmaptransform.h"
3840
#include "qgsquickmessagelogmodel.h"
3941
#include "qgsquickplugin.h"
42+
#include "qgsquickpositionkit.h"
4043
#include "qgsquickscalebarkit.h"
4144
#include "qgsquickutils.h"
4245

@@ -58,14 +61,22 @@ void QgsQuickPlugin::registerTypes( const char *uri )
5861
qRegisterMetaType< QgsPoint >( "QgsPoint" );
5962
qRegisterMetaType< QgsPointXY >( "QgsPointXY" );
6063
qRegisterMetaType< QgsQuickFeatureLayerPair >( "QgsQuickFeatureLayerPair" );
64+
qRegisterMetaType< QgsUnitTypes::SystemOfMeasurement >( "QgsUnitTypes::SystemOfMeasurement" );
65+
qRegisterMetaType< QgsUnitTypes::DistanceUnit >( "QgsUnitTypes::DistanceUnit" );
66+
qRegisterMetaType< QgsCoordinateFormatter::FormatFlags >( "QgsCoordinateFormatter::FormatFlags" );
67+
qRegisterMetaType< QgsCoordinateFormatter::Format >( "QgsCoordinateFormatter::Format" );
68+
69+
qmlRegisterUncreatableType< QgsUnitTypes >( uri, 0, 1, "QgsUnitTypes", "Only enums from QgsUnitTypes can be used" );
6170

6271
qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
6372
qmlRegisterType< QgsQuickFeatureHighlight >( uri, 0, 1, "FeatureHighlight" );
73+
qmlRegisterType< QgsQuickCoordinateTransformer >( uri, 0, 1, "CoordinateTransformer" );
6474
qmlRegisterType< QgsQuickIdentifyKit >( uri, 0, 1, "IdentifyKit" );
6575
qmlRegisterType< QgsQuickMapCanvasMap >( uri, 0, 1, "MapCanvasMap" );
6676
qmlRegisterType< QgsQuickMapSettings >( uri, 0, 1, "MapSettings" );
6777
qmlRegisterType< QgsQuickMapTransform >( uri, 0, 1, "MapTransform" );
6878
qmlRegisterType< QgsQuickMessageLogModel >( uri, 0, 1, "MessageLogModel" );
79+
qmlRegisterType< QgsQuickPositionKit >( uri, 0, 1, "PositionKit" );
6980
qmlRegisterType< QgsQuickScaleBarKit >( uri, 0, 1, "ScaleBarKit" );
7081
qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );
7182

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 bool 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/qgsquickscalebar.qml

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Item {
3232
* representation
3333
*/
3434
property alias preferredWidth: scaleBarKit.preferredWidth
35+
/**
36+
* Preferred system of measurement for the resulting distance. Default is metric system
37+
*/
38+
property alias systemOfMeasurement: scaleBarKit.systemOfMeasurement
3539
/**
3640
* Kit for all calculation of width and text of the scalebar
3741
*

src/quickgui/plugin/qmldir

+1
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

0 commit comments

Comments
 (0)