Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[feature ] Add PositionKit, PositionMarker and other related classes …
…to QgsQuick. For background information see the associated QEP (qgis/QGIS-Enhancement-Proposals#109
- Loading branch information
Showing
with
1,343 additions
and 9 deletions.
- +3 −1 doc/qgsquick.dox
- +10 −0 src/quickgui/CMakeLists.txt
- +4 −0 src/quickgui/images/ic_navigation_black.svg
- +5 −0 src/quickgui/images/images.qrc
- +1 −0 src/quickgui/plugin/CMakeLists.txt
- +4 −0 src/quickgui/plugin/qgsquickplugin.cpp
- +115 −0 src/quickgui/plugin/qgsquickpositionmarker.qml
- +1 −0 src/quickgui/plugin/qmldir
- +102 −0 src/quickgui/qgsquickcoordinatetransformer.cpp
- +103 −0 src/quickgui/qgsquickcoordinatetransformer.h
- +311 −0 src/quickgui/qgsquickpositionkit.cpp
- +255 −0 src/quickgui/qgsquickpositionkit.h
- +84 −0 src/quickgui/qgsquicksimulatedpositionsource.cpp
- +81 −0 src/quickgui/qgsquicksimulatedpositionsource.h
- +71 −1 src/quickgui/qgsquickutils.cpp
- +51 −7 src/quickgui/qgsquickutils.h
- +1 −0 tests/src/quickgui/CMakeLists.txt
- +4 −0 tests/src/quickgui/app/main.cpp
- +10 −0 tests/src/quickgui/app/main.qml
- +63 −0 tests/src/quickgui/testqgsquickpositionkit.cpp
- +64 −0 tests/src/quickgui/testqgsquickutils.cpp
@@ -0,0 +1,4 @@ | ||
<svg fill="#000000" height="48" viewBox="0 0 24 24" width="48" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M0 0h24v24H0z" fill="none"/> | ||
<path d="M12 2L4.5 20.29l.71.71L12 18l6.79 3 .71-.71z"/> | ||
</svg> |
@@ -0,0 +1,5 @@ | ||
<RCC> | ||
<qresource prefix="/"> | ||
<file>ic_navigation_black.svg</file> | ||
</qresource> | ||
</RCC> |
@@ -0,0 +1,115 @@ | ||
/*************************************************************************** | ||
qgsquickpositionmarker.qml | ||
-------------------------------------- | ||
Date : Dec 2017 | ||
Copyright : (C) 2017 by Peter Petrik | ||
Email : zilolv at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
import QtQuick 2.3 | ||
import QtQuick.Controls 2.2 | ||
import QtQml 2.2 | ||
import QtGraphicalEffects 1.0 | ||
import QgsQuick 0.1 as QgsQuick | ||
|
||
/** | ||
* \brief Graphical representation of physical location on the map. | ||
* | ||
* Source position and accuracy taken from PositionKit is drawn as a marker on the map. | ||
* Marker is grayed out when position is not available. When PositionKit support reading of the accuracy, | ||
* the circle is drawn around the marker. PositionKit must be connected, for example GPS position source from QgsQuickPositionKit. | ||
*/ | ||
Item { | ||
id: positionMarker | ||
property int size: 48 * QgsQuick.Utils.dp | ||
|
||
/** | ||
* Utils for handling position. | ||
*/ | ||
property QgsQuick.PositionKit positionKit | ||
|
||
/** | ||
* Color of the marker when position is known. | ||
*/ | ||
property color baseColor: "darkblue" | ||
/** | ||
* Color of the marker when position is unknown (e.g. GPS signal lost). | ||
*/ | ||
property color unavailableColor: "gray" | ||
|
||
/** | ||
* Whether circle representing accuracy of the position should be rendered. | ||
*/ | ||
property var withAccuracy: true | ||
|
||
/** | ||
* Icon for position marker. | ||
*/ | ||
property var markerIcon: QgsQuick.Utils.getThemeIcon("ic_navigation_black") | ||
|
||
/** | ||
* Source position accuracy circle-shaped indicator around positionMarker. | ||
*/ | ||
Rectangle { | ||
id: accuracyIndicator | ||
visible: withAccuracy && | ||
positionKit.hasPosition && | ||
(positionKit.accuracy > 0) && | ||
(accuracyIndicator.width > positionMarker.size / 2.0) | ||
x: positionKit.screenPosition.x - width/2 | ||
y: positionKit.screenPosition.y - height/2 | ||
width:positionKit.screenAccuracy | ||
height: accuracyIndicator.width | ||
color: baseColor | ||
border.color: "black" | ||
border.width: 3 * QgsQuick.Utils.dp | ||
radius: width*0.5 | ||
opacity: 0.1 | ||
} | ||
|
||
/** | ||
* Position marker. | ||
*/ | ||
Rectangle { | ||
id: navigationMarker | ||
property int borderWidth: 2 * QgsQuick.Utils.dp | ||
width: positionMarker.size + 20 * QgsQuick.Utils.dp | ||
height: width | ||
color: "white" | ||
border.color: baseColor | ||
border.width: borderWidth | ||
radius: width*0.5 | ||
antialiasing: true | ||
x: positionKit.screenPosition.x - width/2 | ||
y: positionKit.screenPosition.y - height/2 | ||
|
||
Image { | ||
id: navigation | ||
source: positionMarker.markerIcon | ||
fillMode: Image.PreserveAspectFit | ||
rotation: positionKit.direction | ||
anchors.centerIn: parent | ||
width: positionMarker.size | ||
height: width | ||
} | ||
|
||
/** | ||
* Makes positionMarker (navigation) grey if position is unknown. | ||
*/ | ||
ColorOverlay { | ||
anchors.fill: navigation | ||
source: navigation | ||
color: positionKit.hasPosition ? baseColor : unavailableColor | ||
rotation: positionKit.direction | ||
visible: !(positionKit.hasPosition) | ||
} | ||
} | ||
} | ||
|
@@ -0,0 +1,102 @@ | ||
/*************************************************************************** | ||
qgsquickcoordinatetransformer.cpp | ||
-------------------------------------- | ||
Date : 1.6.2017 | ||
Copyright : (C) 2017 by Matthias Kuhn | ||
Email : matthias (at) opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include <QtDebug> | ||
|
||
#include "qgsquickcoordinatetransformer.h" | ||
|
||
QgsQuickCoordinateTransformer::QgsQuickCoordinateTransformer( QObject *parent ) | ||
: QObject( parent ) | ||
{ | ||
mCoordinateTransform.setSourceCrs( QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) ); | ||
mCoordinateTransform.setContext( QgsCoordinateTransformContext() ); | ||
} | ||
|
||
QgsPoint QgsQuickCoordinateTransformer::projectedPosition() const | ||
{ | ||
return mProjectedPosition; | ||
} | ||
|
||
QgsPoint QgsQuickCoordinateTransformer::sourcePosition() const | ||
{ | ||
return mSourcePosition; | ||
} | ||
|
||
void QgsQuickCoordinateTransformer::setSourcePosition( QgsPoint sourcePosition ) | ||
{ | ||
if ( mSourcePosition == sourcePosition ) | ||
return; | ||
|
||
mSourcePosition = sourcePosition; | ||
|
||
emit sourcePositionChanged(); | ||
updatePosition(); | ||
} | ||
|
||
QgsCoordinateReferenceSystem QgsQuickCoordinateTransformer::destinationCrs() const | ||
{ | ||
return mCoordinateTransform.destinationCrs(); | ||
} | ||
|
||
void QgsQuickCoordinateTransformer::setDestinationCrs( const QgsCoordinateReferenceSystem &destinationCrs ) | ||
{ | ||
if ( destinationCrs == mCoordinateTransform.destinationCrs() ) | ||
return; | ||
|
||
mCoordinateTransform.setDestinationCrs( destinationCrs ); | ||
emit destinationCrsChanged(); | ||
updatePosition(); | ||
} | ||
|
||
QgsCoordinateReferenceSystem QgsQuickCoordinateTransformer::sourceCrs() const | ||
{ | ||
return mCoordinateTransform.sourceCrs(); | ||
} | ||
|
||
void QgsQuickCoordinateTransformer::setSourceCrs( const QgsCoordinateReferenceSystem &sourceCrs ) | ||
{ | ||
if ( sourceCrs == mCoordinateTransform.sourceCrs() ) | ||
return; | ||
|
||
mCoordinateTransform.setSourceCrs( sourceCrs ); | ||
|
||
emit sourceCrsChanged(); | ||
updatePosition(); | ||
} | ||
|
||
void QgsQuickCoordinateTransformer::updatePosition() | ||
{ | ||
double x = mSourcePosition.x(); | ||
double y = mSourcePosition.y(); | ||
double z = mSourcePosition.z(); | ||
|
||
// If Z is NaN, coordinate transformation (proj4) will | ||
// also set X and Y to NaN. But we also want to get projected | ||
// coords if we do not have any Z coordinate. | ||
if ( qIsNaN( z ) ) | ||
{ | ||
z = 0; | ||
} | ||
|
||
if ( mMapSettings ) | ||
mCoordinateTransform.setContext( mMapSettings->transformContext() ); | ||
|
||
mCoordinateTransform.transformInPlace( x, y, z ); | ||
|
||
mProjectedPosition = QgsPoint( x, y ); | ||
mProjectedPosition.addZValue( mSourcePosition.z() ); | ||
|
||
emit projectedPositionChanged(); | ||
} |
Oops, something went wrong.