Skip to content

Commit

Permalink
Merge pull request #7045 from PeterPetrik/qgs-quick-position_and_tran…
Browse files Browse the repository at this point in the history
…sformer

[feature] [qgsquick] Add PositionKit, PositionMarker and CoordinateTransformer
  • Loading branch information
wonder-sk committed Jun 29, 2018
2 parents 7a68002 + b55db3d commit 569db8e
Show file tree
Hide file tree
Showing 27 changed files with 1,724 additions and 24 deletions.
5 changes: 3 additions & 2 deletions doc/qgsquick.dox
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ QGIS Quick consists of a Qt plugin that provides the QML components and of a sha

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

\subsubsection qgsquick_overview_widgets_messagelog MessageLog
A simple panel which can be used for publishing logs messages to a user such as basic information about the application or its status.
See also QgsQuickMessageLogModel.
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_additions/qgsunittypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# The following has been generated automatically from src/core/qgsunittypes.h
QgsUnitTypes.SystemOfMeasurement.baseClass = QgsUnitTypes
QgsUnitTypes.DistanceUnit.baseClass = QgsUnitTypes
QgsUnitTypes.AreaUnit.baseClass = QgsUnitTypes
QgsUnitTypes.AngleUnit.baseClass = QgsUnitTypes
Expand Down
8 changes: 8 additions & 0 deletions python/core/auto_generated/qgsunittypes.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ Helper functions for various unit types.
static const QMetaObject staticMetaObject;

public:
enum SystemOfMeasurement
{
UnknownSystem,
MetricSystem,
ImperialSystem,
USCSSystem
};

enum DistanceUnit
{
DistanceMeters,
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsunittypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class CORE_EXPORT QgsUnitTypes
Q_GADGET

public:
//! Systems of unit measurement
enum SystemOfMeasurement
{
UnknownSystem = 0, //!< Unknown system of measurement
MetricSystem, //!< International System of Units (SI)
ImperialSystem, //!< British Imperial
USCSSystem //!< United States customary system
};
Q_ENUM( SystemOfMeasurement )

//! Units of distance
enum DistanceUnit
{
Expand Down
10 changes: 10 additions & 0 deletions src/quickgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
# sources
SET(QGIS_QUICK_GUI_MOC_HDRS
qgsquickfeaturelayerpair.h
qgsquickcoordinatetransformer.h
qgsquickfeaturehighlight.h
qgsquickidentifykit.h
qgsquickmapcanvasmap.h
qgsquickmapsettings.h
qgsquickmaptransform.h
qgsquickmessagelogmodel.h
qgsquickpositionkit.h
qgsquickscalebarkit.h
qgsquicksimulatedpositionsource.h
qgsquickutils.h
)

Expand All @@ -18,14 +21,17 @@ SET(QGIS_QUICK_GUI_HDRS

SET(QGIS_QUICK_GUI_SRC
qgsquickfeaturelayerpair.cpp
qgsquickcoordinatetransformer.cpp
qgsquickfeaturehighlight.cpp
qgsquickhighlightsgnode.cpp
qgsquickidentifykit.cpp
qgsquickmapcanvasmap.cpp
qgsquickmapsettings.cpp
qgsquickmaptransform.cpp
qgsquickmessagelogmodel.cpp
qgsquickpositionkit.cpp
qgsquickscalebarkit.cpp
qgsquicksimulatedpositionsource.cpp
qgsquickutils.cpp
)

Expand Down Expand Up @@ -69,6 +75,10 @@ INCLUDE_DIRECTORIES(SYSTEM

ADD_DEFINITIONS(-DCORE_EXPORT=)


SET(QGIS_QUICK_GUI_IMAGE_RCCS ./images/images.qrc)
QT5_ADD_RESOURCES(QGIS_QUICK_GUI_IMAGE_RCC_SRCS ${QGIS_QUICK_GUI_IMAGE_RCCS})

############################################################
# qgis_quick shared library
QT5_WRAP_CPP(QGIS_QUICK_GUI_MOC_SRCS ${QGIS_QUICK_GUI_MOC_HDRS})
Expand Down
4 changes: 4 additions & 0 deletions src/quickgui/images/ic_navigation_black.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/quickgui/images/images.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>ic_navigation_black.svg</file>
</qresource>
</RCC>
4 changes: 3 additions & 1 deletion src/quickgui/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ SET(QGIS_QUICK_PLUGIN_SRC
SET(QGIS_QUICK_PLUGIN_RESOURCES
qgsquickmapcanvas.qml
qgsquickmessagelog.qml
qgsquickpositionmarker.qml
qgsquickscalebar.qml
qmldir
)
Expand Down Expand Up @@ -108,8 +109,9 @@ IF(QMLPLUGINDUMP_FOUND)
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qmldir ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:qgis_quick_plugin> ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
COMMAND ${QMLPLUGINDUMP_EXECUTABLE}
ARGS QgsQuick ${QGIS_QUICK_VERSION} . --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
ARGS QgsQuick ${QGIS_QUICK_VERSION} . -noinstantiate --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Generating qgsquick.qmltypes with qmlplugindump"
POST_BUILD
)
ENDIF()
Expand Down
11 changes: 11 additions & 0 deletions src/quickgui/plugin/qgsquickplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@
#include "qgsrelationmanager.h"
#include "qgscoordinatetransformcontext.h"
#include "qgsvectorlayer.h"
#include "qgsunittypes.h"

#include "qgsquickfeaturehighlight.h"
#include "qgsquickcoordinatetransformer.h"
#include "qgsquickidentifykit.h"
#include "qgsquickfeaturelayerpair.h"
#include "qgsquickmapcanvasmap.h"
#include "qgsquickmapsettings.h"
#include "qgsquickmaptransform.h"
#include "qgsquickmessagelogmodel.h"
#include "qgsquickplugin.h"
#include "qgsquickpositionkit.h"
#include "qgsquickscalebarkit.h"
#include "qgsquickutils.h"

Expand All @@ -58,14 +61,22 @@ void QgsQuickPlugin::registerTypes( const char *uri )
qRegisterMetaType< QgsPoint >( "QgsPoint" );
qRegisterMetaType< QgsPointXY >( "QgsPointXY" );
qRegisterMetaType< QgsQuickFeatureLayerPair >( "QgsQuickFeatureLayerPair" );
qRegisterMetaType< QgsUnitTypes::SystemOfMeasurement >( "QgsUnitTypes::SystemOfMeasurement" );
qRegisterMetaType< QgsUnitTypes::DistanceUnit >( "QgsUnitTypes::DistanceUnit" );
qRegisterMetaType< QgsCoordinateFormatter::FormatFlags >( "QgsCoordinateFormatter::FormatFlags" );
qRegisterMetaType< QgsCoordinateFormatter::Format >( "QgsCoordinateFormatter::Format" );

qmlRegisterUncreatableType< QgsUnitTypes >( uri, 0, 1, "QgsUnitTypes", "Only enums from QgsUnitTypes can be used" );

qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
qmlRegisterType< QgsQuickFeatureHighlight >( uri, 0, 1, "FeatureHighlight" );
qmlRegisterType< QgsQuickCoordinateTransformer >( uri, 0, 1, "CoordinateTransformer" );
qmlRegisterType< QgsQuickIdentifyKit >( uri, 0, 1, "IdentifyKit" );
qmlRegisterType< QgsQuickMapCanvasMap >( uri, 0, 1, "MapCanvasMap" );
qmlRegisterType< QgsQuickMapSettings >( uri, 0, 1, "MapSettings" );
qmlRegisterType< QgsQuickMapTransform >( uri, 0, 1, "MapTransform" );
qmlRegisterType< QgsQuickMessageLogModel >( uri, 0, 1, "MessageLogModel" );
qmlRegisterType< QgsQuickPositionKit >( uri, 0, 1, "PositionKit" );
qmlRegisterType< QgsQuickScaleBarKit >( uri, 0, 1, "ScaleBarKit" );
qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );

Expand Down
115 changes: 115 additions & 0 deletions src/quickgui/plugin/qgsquickpositionmarker.qml
Original file line number Diff line number Diff line change
@@ -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 bool 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)
}
}
}

4 changes: 4 additions & 0 deletions src/quickgui/plugin/qgsquickscalebar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Item {
* representation
*/
property alias preferredWidth: scaleBarKit.preferredWidth
/**
* Preferred system of measurement for the resulting distance. Default is metric system
*/
property alias systemOfMeasurement: scaleBarKit.systemOfMeasurement
/**
* Kit for all calculation of width and text of the scalebar
*
Expand Down
1 change: 1 addition & 0 deletions src/quickgui/plugin/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module QgsQuick
plugin qgis_quick_plugin

MapCanvas 0.1 qgsquickmapcanvas.qml
PositionMarker 0.1 qgsquickpositionmarker.qml
ScaleBar 0.1 qgsquickscalebar.qml
MessageLog 0.1 qgsquickmessagelog.qml

Expand Down

0 comments on commit 569db8e

Please sign in to comment.