From d35d28017d731dba9e2a4f2622d2cec97e724e55 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 16 Aug 2013 10:02:13 +0200 Subject: Split QtLocation into QtPositioning and QtLocation QtPositioning is not dependent on any gui component and mostly covers everything around the retrieval of position information. QtLocation covers place, map and navigation APIs. Several documentation issues were fixed during the process. Change-Id: I98e2a53065549a2fc43f93a75b4f65b5bc884c92 Reviewed-by: Alex Blasche --- src/imports/imports.pro | 3 +- .../declarativeplaces/qdeclarativeplace.cpp | 2 +- .../qdeclarativeplaceattribute.cpp | 2 +- .../qdeclarativesearchmodelbase.cpp | 2 +- .../qdeclarativesearchresultmodel.cpp | 7 +- .../qdeclarativesearchsuggestionmodel.cpp | 4 +- src/imports/location/location.cpp | 45 -- src/imports/location/location.pro | 27 +- src/imports/location/locationsingleton.cpp | 164 ---- src/imports/location/locationsingleton.h | 75 -- src/imports/location/locationvaluetypehelper.cpp | 122 +++ src/imports/location/locationvaluetypehelper_p.h | 54 ++ src/imports/location/locationvaluetypeprovider.cpp | 310 ------- src/imports/location/locationvaluetypeprovider.h | 172 ---- src/imports/location/plugins.qmltypes | 165 +--- src/imports/location/qdeclarativecirclemapitem.cpp | 4 +- src/imports/location/qdeclarativecoordinate.cpp | 271 ------- src/imports/location/qdeclarativecoordinate_p.h | 85 -- src/imports/location/qdeclarativegeoaddress.cpp | 360 --------- src/imports/location/qdeclarativegeoaddress_p.h | 113 --- src/imports/location/qdeclarativegeocircle.cpp | 186 ----- src/imports/location/qdeclarativegeocircle.h | 75 -- src/imports/location/qdeclarativegeocodemodel.cpp | 9 +- src/imports/location/qdeclarativegeocodemodel_p.h | 4 +- src/imports/location/qdeclarativegeolocation.cpp | 193 ----- src/imports/location/qdeclarativegeolocation_p.h | 94 --- src/imports/location/qdeclarativegeomaneuver_p.h | 2 +- src/imports/location/qdeclarativegeomap.cpp | 1 - .../location/qdeclarativegeomapgesturearea.cpp | 1 - .../location/qdeclarativegeomapitembase_p.h | 1 - .../location/qdeclarativegeomapmousearea_p.h | 1 - .../location/qdeclarativegeomapmouseevent_p.h | 2 +- .../location/qdeclarativegeomapquickitem.cpp | 1 - .../location/qdeclarativegeomapquickitem_p.h | 1 - src/imports/location/qdeclarativegeorectangle.cpp | 296 ------- src/imports/location/qdeclarativegeorectangle.h | 89 -- src/imports/location/qdeclarativegeoroute.cpp | 8 +- src/imports/location/qdeclarativegeoroute_p.h | 1 + src/imports/location/qdeclarativegeoroutemodel.cpp | 18 +- src/imports/location/qdeclarativegeoroutemodel_p.h | 4 +- .../location/qdeclarativegeoroutesegment.cpp | 2 +- src/imports/location/qdeclarativegeoshape.cpp | 197 ----- src/imports/location/qdeclarativegeoshape.h | 86 -- .../location/qdeclarativepolygonmapitem.cpp | 11 +- .../location/qdeclarativepolylinemapitem.cpp | 6 +- src/imports/location/qdeclarativeposition.cpp | 376 --------- src/imports/location/qdeclarativeposition_p.h | 132 --- .../location/qdeclarativepositionsource.cpp | 647 --------------- .../location/qdeclarativepositionsource_p.h | 150 ---- .../location/qdeclarativerectanglemapitem.cpp | 4 +- src/imports/location/qdeclarativeroutemapitem.cpp | 4 +- src/imports/location/qdeclarativeroutemapitem_p.h | 1 - src/imports/positioning/error_messages.cpp | 48 ++ src/imports/positioning/error_messages.h | 54 ++ src/imports/positioning/locationsingleton.cpp | 163 ++++ src/imports/positioning/locationsingleton.h | 75 ++ .../positioning/locationvaluetypeprovider.cpp | 231 ++++++ .../positioning/locationvaluetypeprovider.h | 164 ++++ src/imports/positioning/plugin.json | 2 + src/imports/positioning/plugins.qmltypes | 167 ++++ src/imports/positioning/positioning.cpp | 123 +++ src/imports/positioning/positioning.pro | 32 + src/imports/positioning/qdeclarativecoordinate.cpp | 320 ++++++++ src/imports/positioning/qdeclarativecoordinate_p.h | 85 ++ src/imports/positioning/qdeclarativegeocircle.cpp | 206 +++++ src/imports/positioning/qdeclarativegeocircle.h | 75 ++ .../positioning/qdeclarativegeorectangle.cpp | 357 ++++++++ src/imports/positioning/qdeclarativegeorectangle.h | 89 ++ src/imports/positioning/qdeclarativegeoshape.cpp | 220 +++++ src/imports/positioning/qdeclarativegeoshape.h | 86 ++ src/imports/positioning/qdeclarativeposition.cpp | 375 +++++++++ src/imports/positioning/qdeclarativeposition_p.h | 132 +++ .../positioning/qdeclarativepositionsource.cpp | 646 +++++++++++++++ .../positioning/qdeclarativepositionsource_p.h | 150 ++++ src/imports/positioning/qmldir | 3 + src/location/doc/images/example-weatherinfo.png | Bin 82081 -> 0 bytes src/location/doc/images/flickr-demo.jpg | Bin 35647 -> 0 bytes src/location/doc/images/qml-flickr-1.jpg | Bin 58111 -> 0 bytes src/location/doc/qtlocation.qdocconf | 3 +- src/location/doc/snippets/cpp/cppqml.cpp | 20 - .../snippets/declarative/declarative-location.qml | 2 +- .../doc/snippets/declarative/declarative-map.qml | 168 ---- src/location/doc/snippets/declarative/maps.qml | 9 +- src/location/doc/snippets/declarative/places.qml | 13 +- .../doc/snippets/declarative/places_loader.qml | 9 +- src/location/doc/src/cpp-qml.qdoc | 24 +- .../doc/src/examples/declarative-flickr.qdoc | 83 -- .../doc/src/examples/logfilepositionsource.qdoc | 87 -- .../doc/src/examples/qtlocation-examples.qdoc | 1 - src/location/doc/src/examples/weatherinfo.qdoc | 109 --- src/location/doc/src/maps.qdoc | 38 +- src/location/doc/src/place-caveats.qdocinc | 2 +- src/location/doc/src/place-definition.qdocinc | 2 +- src/location/doc/src/plugins/nokia_terms.qdoc | 2 +- src/location/doc/src/position.qdoc | 191 ----- src/location/doc/src/qml-maps.qdoc | 33 +- src/location/doc/src/qml-position.qdoc | 136 ---- src/location/doc/src/qtlocation-cpp.qdoc | 25 +- src/location/doc/src/qtlocation-geoservices.qdoc | 62 +- src/location/doc/src/qtlocation-qml.qdoc | 30 +- src/location/doc/src/qtlocation.qdoc | 25 +- src/location/location.pro | 42 +- src/location/maps/qgeocodereply.h | 4 +- src/location/maps/qgeocodingmanager.h | 2 +- src/location/maps/qgeocodingmanagerengine.cpp | 2 +- src/location/maps/qgeocoordinateinterpolator_p.h | 3 +- src/location/maps/qgeoprojection_p.h | 2 +- src/location/maps/qgeoroute.h | 2 +- src/location/maps/qgeorouterequest.h | 2 +- src/location/maps/qgeoserviceprovider.cpp | 9 +- src/location/maps/qgeoserviceproviderfactory.cpp | 2 + src/location/places/qplace.h | 8 +- src/location/qgeoaddress.cpp | 637 --------------- src/location/qgeoaddress.h | 108 --- src/location/qgeoaddress_p.h | 82 -- src/location/qgeoareamonitor.cpp | 256 ------ src/location/qgeoareamonitor.h | 85 -- src/location/qgeocircle.cpp | 311 ------- src/location/qgeocircle.h | 105 --- src/location/qgeocircle_p.h | 83 -- src/location/qgeocoordinate.cpp | 644 --------------- src/location/qgeocoordinate.h | 127 --- src/location/qgeocoordinate_p.h | 79 -- src/location/qgeolocation.cpp | 203 ----- src/location/qgeolocation.h | 90 --- src/location/qgeolocation_p.h | 71 -- src/location/qgeopositioninfo.cpp | 332 -------- src/location/qgeopositioninfo.h | 113 --- src/location/qgeopositioninfosource.cpp | 462 ----------- src/location/qgeopositioninfosource.h | 114 --- src/location/qgeopositioninfosource_p.h | 73 -- src/location/qgeopositioninfosourcefactory.cpp | 90 --- src/location/qgeopositioninfosourcefactory.h | 68 -- src/location/qgeorectangle.cpp | 899 --------------------- src/location/qgeorectangle.h | 141 ---- src/location/qgeorectangle_p.h | 83 -- src/location/qgeosatelliteinfo.cpp | 315 -------- src/location/qgeosatelliteinfo.h | 114 --- src/location/qgeosatelliteinfosource.cpp | 320 -------- src/location/qgeosatelliteinfosource.h | 97 --- src/location/qgeoshape.cpp | 307 ------- src/location/qgeoshape.h | 103 --- src/location/qgeoshape_p.h | 90 --- src/location/qlocationutils.cpp | 357 -------- src/location/qlocationutils_p.h | 118 --- src/location/qnmeapositioninfosource.cpp | 623 -------------- src/location/qnmeapositioninfosource.h | 96 --- src/location/qnmeapositioninfosource_p.h | 176 ---- .../nokia/NOKIA_TERMS_AND_CONDITIONS.txt.qdocinc | 315 ++++++++ .../nokia/placesv2/jsonparserhelpers.cpp | 2 +- .../geoservices/nokia/qgeocodereply_nokia.cpp | 2 +- .../geoservices/nokia/qgeocodexmlparser.cpp | 6 +- .../geoservices/nokia/qgeoroutexmlparser.cpp | 2 +- .../nokia/qgeoroutingmanagerengine_nokia.cpp | 2 +- .../nokia/qgeotiledmappingmanagerengine_nokia.h | 2 +- .../nokia/qplacemanagerengine_nokiav2.cpp | 2 +- src/plugins/geoservices/osm/qgeocodereplyosm.cpp | 8 +- .../geoservices/osm/qgeocodingmanagerengineosm.cpp | 8 +- src/plugins/plugins.pro | 4 +- src/plugins/position/geoclue/geoclue.pro | 2 +- src/plugins/position/geoclue/qgeocluemaster.cpp | 2 +- src/plugins/position/geoclue/qgeocluemaster.h | 2 +- .../qgeopositioninfosource_geocluemaster.cpp | 2 +- .../qgeopositioninfosource_geocluemaster_p.h | 2 +- .../qgeopositioninfosourcefactory_geoclue.cpp | 4 +- .../qgeopositioninfosourcefactory_geoclue.h | 2 +- .../qgeosatelliteinfosource_geocluemaster.cpp | 2 +- .../qgeosatelliteinfosource_geocluemaster.h | 4 +- src/plugins/position/gypsy/gypsy.pro | 2 +- .../gypsy/qgeopositioninfosourcefactory_gypsy.cpp | 2 +- .../gypsy/qgeopositioninfosourcefactory_gypsy.h | 2 +- .../gypsy/qgeosatelliteinfosource_gypsy.cpp | 2 +- .../gypsy/qgeosatelliteinfosource_gypsy_p.h | 2 +- src/plugins/position/positionpoll/positionpoll.pro | 2 +- .../position/positionpoll/positionpollfactory.cpp | 2 +- .../position/positionpoll/positionpollfactory.h | 2 +- .../positionpoll/qgeoareamonitor_polling.cpp | 2 +- .../positionpoll/qgeoareamonitor_polling.h | 2 +- .../simulator/qgeopositioninfosource_simulator.cpp | 2 +- .../simulator/qgeopositioninfosource_simulator_p.h | 2 +- .../qgeopositioninfosourcefactory_simulator.cpp | 2 +- .../qgeopositioninfosourcefactory_simulator.h | 2 +- .../qgeosatelliteinfosource_simulator.cpp | 2 +- .../qgeosatelliteinfosource_simulator_p.h | 2 +- .../simulator/qlocationconnection_simulator.cpp | 2 +- .../simulator/qlocationconnection_simulator_p.h | 2 +- .../position/simulator/qlocationdata_simulator.cpp | 2 +- .../position/simulator/qlocationdata_simulator_p.h | 2 +- src/plugins/position/simulator/simulator.pro | 2 +- src/positioning/doc/images/example-weatherinfo.png | Bin 0 -> 82081 bytes src/positioning/doc/images/qml-flickr-1.jpg | Bin 0 -> 58111 bytes src/positioning/doc/qtpositioning.qdocconf | 56 ++ src/positioning/doc/snippets/cpp/cpp.pro | 8 + src/positioning/doc/snippets/cpp/cppqml.cpp | 64 ++ src/positioning/doc/snippets/cpp/main.cpp | 45 ++ .../doc/snippets/doc_src_qtpositioning.qml | 47 ++ src/positioning/doc/src/cpp-position.qdoc | 191 +++++ src/positioning/doc/src/cpp-qml-positioning.qdoc | 55 ++ .../doc/src/examples/declarative-flickr.qdoc | 85 ++ .../doc/src/examples/logfilepositionsource.qdoc | 87 ++ .../doc/src/examples/qtpositioning-examples.qdoc | 38 + src/positioning/doc/src/examples/weatherinfo.qdoc | 109 +++ src/positioning/doc/src/qml-position.qdoc | 107 +++ src/positioning/doc/src/qtpositioning-plugins.qdoc | 82 ++ src/positioning/doc/src/qtpositioning-qml.qdoc | 65 ++ src/positioning/doc/src/qtpositioning.qdoc | 124 +++ src/positioning/positioning.pro | 58 ++ src/positioning/qdeclarativegeoaddress.cpp | 358 ++++++++ src/positioning/qdeclarativegeoaddress_p.h | 113 +++ src/positioning/qdeclarativegeolocation.cpp | 192 +++++ src/positioning/qdeclarativegeolocation_p.h | 94 +++ src/positioning/qgeoaddress.cpp | 637 +++++++++++++++ src/positioning/qgeoaddress.h | 108 +++ src/positioning/qgeoaddress_p.h | 82 ++ src/positioning/qgeoareamonitor.cpp | 256 ++++++ src/positioning/qgeoareamonitor.h | 85 ++ src/positioning/qgeocircle.cpp | 311 +++++++ src/positioning/qgeocircle.h | 105 +++ src/positioning/qgeocircle_p.h | 83 ++ src/positioning/qgeocoordinate.cpp | 644 +++++++++++++++ src/positioning/qgeocoordinate.h | 127 +++ src/positioning/qgeocoordinate_p.h | 79 ++ src/positioning/qgeolocation.cpp | 203 +++++ src/positioning/qgeolocation.h | 90 +++ src/positioning/qgeolocation_p.h | 71 ++ src/positioning/qgeopositioninfo.cpp | 332 ++++++++ src/positioning/qgeopositioninfo.h | 113 +++ src/positioning/qgeopositioninfosource.cpp | 462 +++++++++++ src/positioning/qgeopositioninfosource.h | 114 +++ src/positioning/qgeopositioninfosource_p.h | 73 ++ src/positioning/qgeopositioninfosourcefactory.cpp | 89 ++ src/positioning/qgeopositioninfosourcefactory.h | 68 ++ src/positioning/qgeorectangle.cpp | 899 +++++++++++++++++++++ src/positioning/qgeorectangle.h | 141 ++++ src/positioning/qgeorectangle_p.h | 83 ++ src/positioning/qgeosatelliteinfo.cpp | 315 ++++++++ src/positioning/qgeosatelliteinfo.h | 114 +++ src/positioning/qgeosatelliteinfosource.cpp | 320 ++++++++ src/positioning/qgeosatelliteinfosource.h | 97 +++ src/positioning/qgeoshape.cpp | 307 +++++++ src/positioning/qgeoshape.h | 103 +++ src/positioning/qgeoshape_p.h | 90 +++ src/positioning/qlocationutils.cpp | 357 ++++++++ src/positioning/qlocationutils_p.h | 118 +++ src/positioning/qnmeapositioninfosource.cpp | 623 ++++++++++++++ src/positioning/qnmeapositioninfosource.h | 96 +++ src/positioning/qnmeapositioninfosource_p.h | 176 ++++ src/positioning/qpositioningglobal.h | 61 ++ src/src.pro | 2 +- 249 files changed, 14599 insertions(+), 13347 deletions(-) delete mode 100644 src/imports/location/locationsingleton.cpp delete mode 100644 src/imports/location/locationsingleton.h create mode 100644 src/imports/location/locationvaluetypehelper.cpp create mode 100644 src/imports/location/locationvaluetypehelper_p.h delete mode 100644 src/imports/location/locationvaluetypeprovider.cpp delete mode 100644 src/imports/location/locationvaluetypeprovider.h delete mode 100644 src/imports/location/qdeclarativecoordinate.cpp delete mode 100644 src/imports/location/qdeclarativecoordinate_p.h delete mode 100644 src/imports/location/qdeclarativegeoaddress.cpp delete mode 100644 src/imports/location/qdeclarativegeoaddress_p.h delete mode 100644 src/imports/location/qdeclarativegeocircle.cpp delete mode 100644 src/imports/location/qdeclarativegeocircle.h delete mode 100644 src/imports/location/qdeclarativegeolocation.cpp delete mode 100644 src/imports/location/qdeclarativegeolocation_p.h delete mode 100644 src/imports/location/qdeclarativegeorectangle.cpp delete mode 100644 src/imports/location/qdeclarativegeorectangle.h delete mode 100644 src/imports/location/qdeclarativegeoshape.cpp delete mode 100644 src/imports/location/qdeclarativegeoshape.h delete mode 100644 src/imports/location/qdeclarativeposition.cpp delete mode 100644 src/imports/location/qdeclarativeposition_p.h delete mode 100644 src/imports/location/qdeclarativepositionsource.cpp delete mode 100644 src/imports/location/qdeclarativepositionsource_p.h create mode 100644 src/imports/positioning/error_messages.cpp create mode 100644 src/imports/positioning/error_messages.h create mode 100644 src/imports/positioning/locationsingleton.cpp create mode 100644 src/imports/positioning/locationsingleton.h create mode 100644 src/imports/positioning/locationvaluetypeprovider.cpp create mode 100644 src/imports/positioning/locationvaluetypeprovider.h create mode 100644 src/imports/positioning/plugin.json create mode 100644 src/imports/positioning/plugins.qmltypes create mode 100644 src/imports/positioning/positioning.cpp create mode 100644 src/imports/positioning/positioning.pro create mode 100644 src/imports/positioning/qdeclarativecoordinate.cpp create mode 100644 src/imports/positioning/qdeclarativecoordinate_p.h create mode 100644 src/imports/positioning/qdeclarativegeocircle.cpp create mode 100644 src/imports/positioning/qdeclarativegeocircle.h create mode 100644 src/imports/positioning/qdeclarativegeorectangle.cpp create mode 100644 src/imports/positioning/qdeclarativegeorectangle.h create mode 100644 src/imports/positioning/qdeclarativegeoshape.cpp create mode 100644 src/imports/positioning/qdeclarativegeoshape.h create mode 100644 src/imports/positioning/qdeclarativeposition.cpp create mode 100644 src/imports/positioning/qdeclarativeposition_p.h create mode 100644 src/imports/positioning/qdeclarativepositionsource.cpp create mode 100644 src/imports/positioning/qdeclarativepositionsource_p.h create mode 100644 src/imports/positioning/qmldir delete mode 100644 src/location/doc/images/example-weatherinfo.png delete mode 100644 src/location/doc/images/flickr-demo.jpg delete mode 100644 src/location/doc/images/qml-flickr-1.jpg delete mode 100644 src/location/doc/snippets/declarative/declarative-map.qml delete mode 100644 src/location/doc/src/examples/declarative-flickr.qdoc delete mode 100644 src/location/doc/src/examples/logfilepositionsource.qdoc delete mode 100644 src/location/doc/src/examples/weatherinfo.qdoc delete mode 100644 src/location/doc/src/position.qdoc delete mode 100644 src/location/doc/src/qml-position.qdoc delete mode 100644 src/location/qgeoaddress.cpp delete mode 100644 src/location/qgeoaddress.h delete mode 100644 src/location/qgeoaddress_p.h delete mode 100644 src/location/qgeoareamonitor.cpp delete mode 100644 src/location/qgeoareamonitor.h delete mode 100644 src/location/qgeocircle.cpp delete mode 100644 src/location/qgeocircle.h delete mode 100644 src/location/qgeocircle_p.h delete mode 100644 src/location/qgeocoordinate.cpp delete mode 100644 src/location/qgeocoordinate.h delete mode 100644 src/location/qgeocoordinate_p.h delete mode 100644 src/location/qgeolocation.cpp delete mode 100644 src/location/qgeolocation.h delete mode 100644 src/location/qgeolocation_p.h delete mode 100644 src/location/qgeopositioninfo.cpp delete mode 100644 src/location/qgeopositioninfo.h delete mode 100644 src/location/qgeopositioninfosource.cpp delete mode 100644 src/location/qgeopositioninfosource.h delete mode 100644 src/location/qgeopositioninfosource_p.h delete mode 100644 src/location/qgeopositioninfosourcefactory.cpp delete mode 100644 src/location/qgeopositioninfosourcefactory.h delete mode 100644 src/location/qgeorectangle.cpp delete mode 100644 src/location/qgeorectangle.h delete mode 100644 src/location/qgeorectangle_p.h delete mode 100644 src/location/qgeosatelliteinfo.cpp delete mode 100644 src/location/qgeosatelliteinfo.h delete mode 100644 src/location/qgeosatelliteinfosource.cpp delete mode 100644 src/location/qgeosatelliteinfosource.h delete mode 100644 src/location/qgeoshape.cpp delete mode 100644 src/location/qgeoshape.h delete mode 100644 src/location/qgeoshape_p.h delete mode 100644 src/location/qlocationutils.cpp delete mode 100644 src/location/qlocationutils_p.h delete mode 100644 src/location/qnmeapositioninfosource.cpp delete mode 100644 src/location/qnmeapositioninfosource.h delete mode 100644 src/location/qnmeapositioninfosource_p.h create mode 100644 src/plugins/geoservices/nokia/NOKIA_TERMS_AND_CONDITIONS.txt.qdocinc create mode 100644 src/positioning/doc/images/example-weatherinfo.png create mode 100644 src/positioning/doc/images/qml-flickr-1.jpg create mode 100644 src/positioning/doc/qtpositioning.qdocconf create mode 100644 src/positioning/doc/snippets/cpp/cpp.pro create mode 100644 src/positioning/doc/snippets/cpp/cppqml.cpp create mode 100644 src/positioning/doc/snippets/cpp/main.cpp create mode 100644 src/positioning/doc/snippets/doc_src_qtpositioning.qml create mode 100644 src/positioning/doc/src/cpp-position.qdoc create mode 100644 src/positioning/doc/src/cpp-qml-positioning.qdoc create mode 100644 src/positioning/doc/src/examples/declarative-flickr.qdoc create mode 100644 src/positioning/doc/src/examples/logfilepositionsource.qdoc create mode 100644 src/positioning/doc/src/examples/qtpositioning-examples.qdoc create mode 100644 src/positioning/doc/src/examples/weatherinfo.qdoc create mode 100644 src/positioning/doc/src/qml-position.qdoc create mode 100644 src/positioning/doc/src/qtpositioning-plugins.qdoc create mode 100644 src/positioning/doc/src/qtpositioning-qml.qdoc create mode 100644 src/positioning/doc/src/qtpositioning.qdoc create mode 100644 src/positioning/positioning.pro create mode 100644 src/positioning/qdeclarativegeoaddress.cpp create mode 100644 src/positioning/qdeclarativegeoaddress_p.h create mode 100644 src/positioning/qdeclarativegeolocation.cpp create mode 100644 src/positioning/qdeclarativegeolocation_p.h create mode 100644 src/positioning/qgeoaddress.cpp create mode 100644 src/positioning/qgeoaddress.h create mode 100644 src/positioning/qgeoaddress_p.h create mode 100644 src/positioning/qgeoareamonitor.cpp create mode 100644 src/positioning/qgeoareamonitor.h create mode 100644 src/positioning/qgeocircle.cpp create mode 100644 src/positioning/qgeocircle.h create mode 100644 src/positioning/qgeocircle_p.h create mode 100644 src/positioning/qgeocoordinate.cpp create mode 100644 src/positioning/qgeocoordinate.h create mode 100644 src/positioning/qgeocoordinate_p.h create mode 100644 src/positioning/qgeolocation.cpp create mode 100644 src/positioning/qgeolocation.h create mode 100644 src/positioning/qgeolocation_p.h create mode 100644 src/positioning/qgeopositioninfo.cpp create mode 100644 src/positioning/qgeopositioninfo.h create mode 100644 src/positioning/qgeopositioninfosource.cpp create mode 100644 src/positioning/qgeopositioninfosource.h create mode 100644 src/positioning/qgeopositioninfosource_p.h create mode 100644 src/positioning/qgeopositioninfosourcefactory.cpp create mode 100644 src/positioning/qgeopositioninfosourcefactory.h create mode 100644 src/positioning/qgeorectangle.cpp create mode 100644 src/positioning/qgeorectangle.h create mode 100644 src/positioning/qgeorectangle_p.h create mode 100644 src/positioning/qgeosatelliteinfo.cpp create mode 100644 src/positioning/qgeosatelliteinfo.h create mode 100644 src/positioning/qgeosatelliteinfosource.cpp create mode 100644 src/positioning/qgeosatelliteinfosource.h create mode 100644 src/positioning/qgeoshape.cpp create mode 100644 src/positioning/qgeoshape.h create mode 100644 src/positioning/qgeoshape_p.h create mode 100644 src/positioning/qlocationutils.cpp create mode 100644 src/positioning/qlocationutils_p.h create mode 100644 src/positioning/qnmeapositioninfosource.cpp create mode 100644 src/positioning/qnmeapositioninfosource.h create mode 100644 src/positioning/qnmeapositioninfosource_p.h create mode 100644 src/positioning/qpositioningglobal.h (limited to 'src') diff --git a/src/imports/imports.pro b/src/imports/imports.pro index ad697cfb..ac340141 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs -qtHaveModule(3d): SUBDIRS += location +qtHaveModule(positioning): SUBDIRS += positioning +qtHaveModule(3d):qtHaveModule(location): SUBDIRS += location diff --git a/src/imports/location/declarativeplaces/qdeclarativeplace.cpp b/src/imports/location/declarativeplaces/qdeclarativeplace.cpp index 5c60594b..208d955f 100644 --- a/src/imports/location/declarativeplaces/qdeclarativeplace.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativeplace.cpp @@ -441,7 +441,7 @@ QPlace QDeclarativePlace::place() } /*! - \qmlproperty QtLocation5::Location Place::location + \qmlproperty QtPositioning5::Location Place::location This property holds the location of the place which can be used to retrieve the coordinate, address and the bounding box. diff --git a/src/imports/location/declarativeplaces/qdeclarativeplaceattribute.cpp b/src/imports/location/declarativeplaces/qdeclarativeplaceattribute.cpp index a2c596b6..fc3bb15c 100644 --- a/src/imports/location/declarativeplaces/qdeclarativeplaceattribute.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativeplaceattribute.cpp @@ -101,7 +101,7 @@ \snippet declarative/places.qml ExtendedAttributes read The following example shows how to assign and modify an attribute: - \snippet declarative/places.qml + \snippet declarative/places.qml ExtendedAttributes write \sa PlaceAttribute, QQmlPropertyMap */ diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp index 46edd91e..217ff9da 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp @@ -48,7 +48,7 @@ #include #include #include -#include +#include QDeclarativeSearchModelBase::QDeclarativeSearchModelBase(QObject *parent) : QAbstractListModel(parent), m_plugin(0), m_reply(0), m_complete(false), m_status(Null) diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp index 9a44dac1..8d182ea8 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp @@ -149,10 +149,9 @@ QT_USE_NAMESPACE fetch search results, but rather performs a single fetch when \l update() is run. The \l count is set to the number of search results returned during the fetch. - \snippet declarative/places.qml QtQuick import - \snippet declarative/places.qml QtLocation import + \snippet places_list/places_list.qml Imports \codeline - \snippet declarative/places.qml PlaceSearchModel + \snippet places_list/places_list.qml PlaceSearchModel \sa CategoryModel, {QPlaceManager} @@ -278,7 +277,7 @@ QT_USE_NAMESPACE PlaceSearchModel { id: model plugin: backendPlugin - searchArea: QtLocation.circle(QtLocation.coordinate(10, 10)) + searchArea: QtPositioning.circle(QtPositioning.coordinate(10, 10)) ... } diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchsuggestionmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchsuggestionmodel.cpp index e344d8ea..f190cc4f 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchsuggestionmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchsuggestionmodel.cpp @@ -106,7 +106,7 @@ QT_USE_NAMESPACE */ /*! - \qmlproperty GeoShape PlaceSearchSuggestionModel::searchArea + \qmlproperty geoshape PlaceSearchSuggestionModel::searchArea This property holds the search area. Search suggestion results returned by the model will be relevant to the given search area. @@ -172,7 +172,7 @@ QT_USE_NAMESPACE PlaceSeachSuggestionModel { id: model plugin: backendPlugin - searchArea: QtLocation.circle(QtLocation.coordinate(10, 10)) + searchArea: QtPositioning.circle(QtPositioning.coordinate(10, 10)) ... } diff --git a/src/imports/location/location.cpp b/src/imports/location/location.cpp index b3313c71..894d555e 100644 --- a/src/imports/location/location.cpp +++ b/src/imports/location/location.cpp @@ -39,17 +39,6 @@ ** ****************************************************************************/ -#include "locationvaluetypeprovider.h" - -#include "qdeclarativepositionsource_p.h" -#include "qdeclarativeposition_p.h" - -#include "qdeclarativegeoshape.h" -#include "qdeclarativegeorectangle.h" -#include "qdeclarativegeocircle.h" -#include "qdeclarativegeoaddress_p.h" -#include "qdeclarativecoordinate_p.h" - #include "qdeclarativegeoserviceprovider_p.h" #include "qdeclarativegeomap_p.h" @@ -71,7 +60,6 @@ //Place includes #include "qdeclarativecategory_p.h" -#include "qdeclarativegeolocation_p.h" #include "qdeclarativeplace_p.h" #include "qdeclarativeplaceattribute_p.h" #include "qdeclarativeplaceicon_p.h" @@ -85,34 +73,16 @@ #include "qdeclarativesearchsuggestionmodel_p.h" #include "error_messages.h" -#include "locationsingleton.h" - #include #include #include #include #include -#include -#include - #include QT_BEGIN_NAMESPACE -static QObject *singleton_type_factory(QQmlEngine *engine, QJSEngine *jsEngine) -{ - Q_UNUSED(engine) - Q_UNUSED(jsEngine) - - return new LocationSingleton; -} - -static LocationValueTypeProvider *getValueTypeProvider() -{ - static LocationValueTypeProvider provider; - return &provider; -} class QLocationDeclarativeModule: public QQmlExtensionPlugin { @@ -132,15 +102,6 @@ public: // @uri QtLocation 5.0 - qmlRegisterSingletonType(uri, 5, 0, "QtLocation", singleton_type_factory); - - QQml_addValueTypeProvider(getValueTypeProvider()); - qmlRegisterValueTypeEnums(uri, 5, 0, "GeoShape"); - - qmlRegisterType(uri, 5, 0, "Position"); - qmlRegisterType(uri, 5, 0, "PositionSource"); - qmlRegisterType(uri, 5, 0, "Address"); - qmlRegisterType(uri, 5, 0, "Plugin"); qmlRegisterType(uri, 5, 0, "PluginParameter"); qmlRegisterUncreatableType(uri, 5, 0, "PluginRequirements", QCoreApplication::translate(CONTEXT_NAME, NOT_INSTANTIABLE_BY_DEVELOPER).arg("PluginRequirements")); @@ -163,7 +124,6 @@ public: qmlRegisterUncreatableType(uri, 5, 0, "MapType", QCoreApplication::translate(CONTEXT_NAME, NOT_INSTANTIABLE_BY_DEVELOPER).arg("MapType")); qmlRegisterType(uri, 5, 0, "Category"); qmlRegisterType(uri, 5, 0, "EditorialModel"); - qmlRegisterType(uri, 5, 0, "Location"); qmlRegisterType(uri, 5, 0, "ImageModel"); qmlRegisterType(uri, 5, 0, "Place"); qmlRegisterType(uri, 5, 0, "Icon"); @@ -189,11 +149,6 @@ public: qmlRegisterUncreatableType(uri, 5, 0, "ContactDetails", "ContactDetails instances cannot be instantiated. " "Only Place types have ContactDetails and they cannot " "be re-assigned (but can be modified)."); - qRegisterMetaType("QGeoCoordinate"); - qRegisterMetaType("QGeoAddress"); - qRegisterMetaType("QGeoRectangle"); - qRegisterMetaType("QGeoCircle"); - qRegisterMetaType("QGeoLocation"); qRegisterMetaType("QPlaceCategory"); qRegisterMetaType("QPlace"); qRegisterMetaType("QPlaceIcon"); diff --git a/src/imports/location/location.pro b/src/imports/location/location.pro index 4c110ddd..8dccfa2d 100644 --- a/src/imports/location/location.pro +++ b/src/imports/location/location.pro @@ -1,7 +1,8 @@ -QT += quick-private network location-private qml-private 3d core-private gui-private +QT += quick-private network positioning-private location-private qml-private 3d core-private gui-private INCLUDEPATH += ../../location INCLUDEPATH += ../../location/maps +INCLUDEPATH += ../../positioning INCLUDEPATH *= $$PWD LIBS += -L../../3rdparty/poly2tri -lpoly2tri @@ -14,18 +15,11 @@ win32 { } } -HEADERS += qdeclarativeposition_p.h \ - qdeclarativepositionsource_p.h \ - qdeclarativecoordinate_p.h \ - qdeclarativegeolocation_p.h \ +HEADERS += \ qdeclarativegeomapitemview_p.h \ qdeclarativegeomapmouseevent_p.h \ qdeclarativegeomapmousearea_p.h \ qdeclarativegeoserviceprovider_p.h \ - qdeclarativegeoaddress_p.h \ - qdeclarativegeoshape.h \ - qdeclarativegeorectangle.h \ - qdeclarativegeocircle.h \ qdeclarativegeocodemodel_p.h \ qdeclarativegeoroutemodel_p.h \ qdeclarativegeoroute_p.h \ @@ -45,22 +39,14 @@ HEADERS += qdeclarativeposition_p.h \ qdeclarativegeomapcopyrightsnotice_p.h \ qdeclarativegeomapgesturearea_p.h \ error_messages.h \ - locationvaluetypeprovider.h \ - locationsingleton.h + locationvaluetypehelper_p.h -SOURCES += qdeclarativeposition.cpp \ +SOURCES += \ location.cpp \ - qdeclarativepositionsource.cpp \ - qdeclarativecoordinate.cpp \ - qdeclarativegeolocation.cpp \ qdeclarativegeomapitemview.cpp \ qdeclarativegeomapmouseevent.cpp \ qdeclarativegeomapmousearea.cpp \ qdeclarativegeoserviceprovider.cpp \ - qdeclarativegeoaddress.cpp \ - qdeclarativegeoshape.cpp \ - qdeclarativegeorectangle.cpp \ - qdeclarativegeocircle.cpp \ qdeclarativegeocodemodel.cpp \ qdeclarativegeoroutemodel.cpp \ qdeclarativegeoroute.cpp \ @@ -80,8 +66,7 @@ SOURCES += qdeclarativeposition.cpp \ qdeclarativegeomapcopyrightsnotice.cpp \ qdeclarativegeomapgesturearea.cpp \ error_messages.cpp \ - locationvaluetypeprovider.cpp \ - locationsingleton.cpp + locationvaluetypehelper.cpp include(declarativeplaces/declarativeplaces.pri) diff --git a/src/imports/location/locationsingleton.cpp b/src/imports/location/locationsingleton.cpp deleted file mode 100644 index e4f9a833..00000000 --- a/src/imports/location/locationsingleton.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "locationsingleton.h" - -/*! - \qmltype QtLocation - \instantiates LocationSingleton - \inqmlmodule QtLocation 5.0 - \ingroup qml-QtLocation5-common - - \brief The QtLocation global object provides useful functions for working with Qt Location - types in QML. - - \qml - import QtLocation 5.0 - - Item { - property variant coordinate: QtLocation.coordinate(-27.5, 153.1) - } - \endqml -*/ - -LocationSingleton::LocationSingleton(QObject *parent) -: QObject(parent) -{ -} - -/*! - \qmlmethod coordinate QtLocation5::QtLocation::coordinate() - - Constructs an invalid coordinate. - -*/ -QGeoCoordinate LocationSingleton::coordinate() const -{ - return QGeoCoordinate(); -} - -/*! - \qmlmethod coordinate QtLocation5::QtLocation::coordinate(real latitude, real longitue, real altitude) const - - Constructs a coordinate with the specified \a latitude, \a longitude and optional \a altitude. - Both \a latitude and \a longitude must be valid, otherwise an invalid coordinate is returned. - - \sa {coordinate} -*/ -QGeoCoordinate LocationSingleton::coordinate(double latitude, double longitude, double altitude) const -{ - return QGeoCoordinate(latitude, longitude, altitude); -} - -/*! - \qmlmethod geoshape QtLocation5::QtLocation::shape() const - - Constructs an invalid geoshape. - - \sa {geoshape} -*/ -QGeoShape LocationSingleton::shape() const -{ - return QGeoShape(); -} - -/*! - \qmlmethod georectangle QtLocation5::QtLocation::rectangle() const - - Constructs an invalid georectangle. - - \sa {georectangle} -*/ -QGeoRectangle LocationSingleton::rectangle() const -{ - return QGeoRectangle(); -} - -/*! - \qmlmethod georectangle QtLocation5::QtLocation::rectangle(coordinate center, real width, real height) const - - Constructs a georectangle centered at \a center with a width of \a width degrees and a hight of - \a height degrees. - - \sa {georectangle} -*/ -QGeoRectangle LocationSingleton::rectangle(const QGeoCoordinate ¢er, - double width, double height) const -{ - return QGeoRectangle(center, width, height); -} - -/*! - \qmlmethod georectangle QtLocation5::QtLocation::rectangle(coordinate topLeft, coordinate bottomRight) const - - Constructs a georectangle with its top left corner positioned at \a topLeft and its bottom - right corner positioned at \a {bottomLeft}. - - \sa {georectangle} -*/ -QGeoRectangle LocationSingleton::rectangle(const QGeoCoordinate &topLeft, - const QGeoCoordinate &bottomRight) const -{ - return QGeoRectangle(topLeft, bottomRight); -} - -/*! - \qmlmethod geocircle QtLocation5::QtLocation::circle() const - - Constructs an invalid geocircle. - - \sa {geocircle} -*/ -QGeoCircle LocationSingleton::circle() const -{ - return QGeoCircle(); -} - -/*! - \qmlmethod geocircle QtLocation5::QtLocation::circle(coordinate center, real radius) const - - Constructs a geocircle centered at \a center with a radius of \a radius meters. -*/ -QGeoCircle LocationSingleton::circle(const QGeoCoordinate ¢er, qreal radius) const -{ - return QGeoCircle(center, radius); -} - diff --git a/src/imports/location/locationsingleton.h b/src/imports/location/locationsingleton.h deleted file mode 100644 index b3839ba5..00000000 --- a/src/imports/location/locationsingleton.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef LOCATIONSINGLETON_H -#define LOCATIONSINGLETON_H - -#include -#include -#include -#include -#include -#include - -class LocationSingleton : public QObject -{ - Q_OBJECT - -public: - explicit LocationSingleton(QObject *parent = 0); - - Q_INVOKABLE QGeoCoordinate coordinate() const; - Q_INVOKABLE QGeoCoordinate coordinate(double latitude, double longitude, - double altitude = qQNaN()) const; - - Q_INVOKABLE QGeoShape shape() const; - - Q_INVOKABLE QGeoRectangle rectangle() const; - Q_INVOKABLE QGeoRectangle rectangle(const QGeoCoordinate ¢er, - double width, double height) const; - Q_INVOKABLE QGeoRectangle rectangle(const QGeoCoordinate &topLeft, - const QGeoCoordinate &bottomRight) const; - - Q_INVOKABLE QGeoCircle circle() const; - Q_INVOKABLE QGeoCircle circle(const QGeoCoordinate ¢er, qreal radius = -1.0) const; -}; - -#endif // LOCATIONSINGLETON_H diff --git a/src/imports/location/locationvaluetypehelper.cpp b/src/imports/location/locationvaluetypehelper.cpp new file mode 100644 index 00000000..95790955 --- /dev/null +++ b/src/imports/location/locationvaluetypehelper.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "locationvaluetypehelper_p.h" + + +QGeoCoordinate parseCoordinate(const QJSValue &value, bool *ok) +{ + QGeoCoordinate c; + + if (value.isObject()) { + if (value.hasProperty(QStringLiteral("latitude"))) + c.setLatitude(value.property(QStringLiteral("latitude")).toNumber()); + if (value.hasProperty(QStringLiteral("longitude"))) + c.setLongitude(value.property(QStringLiteral("longitude")).toNumber()); + if (value.hasProperty(QStringLiteral("altitude"))) + c.setAltitude(value.property(QStringLiteral("altitude")).toNumber()); + + if (ok) + *ok = true; + } + + return c; +} + +QGeoRectangle parseRectangle(const QJSValue &value, bool *ok) +{ + QGeoRectangle r; + + *ok = false; + + if (value.isObject()) { + if (value.hasProperty(QStringLiteral("bottomLeft"))) { + QGeoCoordinate c = parseCoordinate(value.property(QStringLiteral("bottomLeft")), ok); + if (*ok) + r.setBottomLeft(c); + } + if (value.hasProperty(QStringLiteral("bottomRight"))) { + QGeoCoordinate c = parseCoordinate(value.property(QStringLiteral("bottomRight")), ok); + if (*ok) + r.setBottomRight(c); + } + if (value.hasProperty(QStringLiteral("topLeft"))) { + QGeoCoordinate c = parseCoordinate(value.property(QStringLiteral("topLeft")), ok); + if (*ok) + r.setTopLeft(c); + } + if (value.hasProperty(QStringLiteral("topRight"))) { + QGeoCoordinate c = parseCoordinate(value.property(QStringLiteral("topRight")), ok); + if (*ok) + r.setTopRight(c); + } + if (value.hasProperty(QStringLiteral("center"))) { + QGeoCoordinate c = parseCoordinate(value.property(QStringLiteral("center")), ok); + if (*ok) + r.setCenter(c); + } + if (value.hasProperty(QStringLiteral("height"))) + r.setHeight(value.property(QStringLiteral("height")).toNumber()); + if (value.hasProperty(QStringLiteral("width"))) + r.setWidth(value.property(QStringLiteral("width")).toNumber()); + } + + return r; +} + +QGeoCircle parseCircle(const QJSValue &value, bool *ok) +{ + QGeoCircle c; + + *ok = false; + + if (value.isObject()) { + if (value.hasProperty(QStringLiteral("center"))) { + QGeoCoordinate coord = parseCoordinate(value.property(QStringLiteral("center")), ok); + if (*ok) + c.setCenter(coord); + } + if (value.hasProperty(QStringLiteral("radius"))) + c.setRadius(value.property(QStringLiteral("radius")).toNumber()); + } + + return c; +} diff --git a/src/imports/location/locationvaluetypehelper_p.h b/src/imports/location/locationvaluetypehelper_p.h new file mode 100644 index 00000000..9c5bb481 --- /dev/null +++ b/src/imports/location/locationvaluetypehelper_p.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LOCATION_VALUE_TYPE_HELPER +#define LOCATION_VALUE_TYPE_HELPER + +#include +#include +#include +#include + +QGeoCoordinate parseCoordinate(const QJSValue &value, bool *ok); +QGeoRectangle parseRectangle(const QJSValue &value, bool *ok); +QGeoCircle parseCircle(const QJSValue &value, bool *ok); + +#endif diff --git a/src/imports/location/locationvaluetypeprovider.cpp b/src/imports/location/locationvaluetypeprovider.cpp deleted file mode 100644 index 0477e72a..00000000 --- a/src/imports/location/locationvaluetypeprovider.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "locationvaluetypeprovider.h" -#include "qdeclarativecoordinate_p.h" -#include "qdeclarativegeoshape.h" -#include "qdeclarativegeorectangle.h" -#include "qdeclarativegeocircle.h" -#include -#include - -QT_BEGIN_NAMESPACE - -QGeoCoordinate parseCoordinate(const QJSValue &value, bool *ok) -{ - QGeoCoordinate c; - - if (value.isObject()) { - if (value.hasProperty(QStringLiteral("latitude"))) - c.setLatitude(value.property(QStringLiteral("latitude")).toNumber()); - if (value.hasProperty(QStringLiteral("longitude"))) - c.setLongitude(value.property(QStringLiteral("longitude")).toNumber()); - if (value.hasProperty(QStringLiteral("altitude"))) - c.setAltitude(value.property(QStringLiteral("altitude")).toNumber()); - - if (ok) - *ok = true; - } - - return c; -} - -QGeoRectangle parseRectangle(const QJSValue &value, bool *ok) -{ - QGeoRectangle r; - - *ok = false; - - if (value.isObject()) { - if (value.hasProperty(QStringLiteral("bottomLeft"))) { - QGeoCoordinate c = parseCoordinate(value.property(QStringLiteral("bottomLeft")), ok); - if (*ok) - r.setBottomLeft(c); - } - if (value.hasProperty(QStringLiteral("bottomRight"))) { - QGeoCoordinate c = parseCoordinate(value.property(QStringLiteral("bottomRight")), ok); - if (*ok) - r.setBottomRight(c); - } - if (value.hasProperty(QStringLiteral("topLeft"))) { - QGeoCoordinate c = parseCoordinate(value.property(QStringLiteral("topLeft")), ok); - if (*ok) - r.setTopLeft(c); - } - if (value.hasProperty(QStringLiteral("topRight"))) { - QGeoCoordinate c = parseCoordinate(value.property(QStringLiteral("topRight")), ok); - if (*ok) - r.setTopRight(c); - } - if (value.hasProperty(QStringLiteral("center"))) { - QGeoCoordinate c = parseCoordinate(value.property(QStringLiteral("center")), ok); - if (*ok) - r.setCenter(c); - } - if (value.hasProperty(QStringLiteral("height"))) - r.setHeight(value.property(QStringLiteral("height")).toNumber()); - if (value.hasProperty(QStringLiteral("width"))) - r.setWidth(value.property(QStringLiteral("width")).toNumber()); - } - - return r; -} - -QGeoCircle parseCircle(const QJSValue &value, bool *ok) -{ - QGeoCircle c; - - *ok = false; - - if (value.isObject()) { - if (value.hasProperty(QStringLiteral("center"))) { - QGeoCoordinate coord = parseCoordinate(value.property(QStringLiteral("center")), ok); - if (*ok) - c.setCenter(coord); - } - if (value.hasProperty(QStringLiteral("radius"))) - c.setRadius(value.property(QStringLiteral("radius")).toNumber()); - } - - return c; -} - -LocationValueTypeProvider::LocationValueTypeProvider() -: QQmlValueTypeProvider() -{ -} - -bool LocationValueTypeProvider::create(int type, QQmlValueType *&v) -{ - if (type == qMetaTypeId()) - return typedCreate(v); - else if (type == qMetaTypeId()) - return typedCreate(v); - else if (type == qMetaTypeId()) - return typedCreate(v); - else if (type == qMetaTypeId()) - return typedCreate(v); - - return false; -} - -bool LocationValueTypeProvider::init(int type, void *data, size_t dataSize) -{ - if (type == qMetaTypeId()) - return typedInit(data, dataSize); - else if (type == qMetaTypeId()) - return typedInit(data, dataSize); - else if (type == qMetaTypeId()) - return typedInit(data, dataSize); - else if (type == qMetaTypeId()) - return typedInit(data, dataSize); - - return false; -} - -bool LocationValueTypeProvider::destroy(int type, void *data, size_t dataSize) -{ - if (type == qMetaTypeId()) - return typedDestroy(data, dataSize); - else if (type == qMetaTypeId()) - return typedDestroy(data, dataSize); - else if (type == qMetaTypeId()) - return typedDestroy(data, dataSize); - else if (type == qMetaTypeId()) - return typedDestroy(data, dataSize); - - return false; -} - -bool LocationValueTypeProvider::copy(int type, const void *src, void *dst, size_t dstSize) -{ - if (type == qMetaTypeId()) - return typedCopyConstruct(src, dst, dstSize); - else if (type == qMetaTypeId()) - return typedCopyConstruct(src, dst, dstSize); - else if (type == qMetaTypeId()) - return typedCopyConstruct(src, dst, dstSize); - else if (type == qMetaTypeId()) - return typedCopyConstruct(src, dst, dstSize); - - return false; -} - -bool LocationValueTypeProvider::create(int type, int argc, const void *argv[], QVariant *v) -{ - if (type == qMetaTypeId()) { - if (argc == 2) { - const float *a = reinterpret_cast(argv[0]); - const float *b = reinterpret_cast(argv[1]); - *v = QVariant::fromValue(QGeoCoordinate(*a, *b)); - return true; - } else if (argc == 3) { - const float *a = reinterpret_cast(argv[0]); - const float *b = reinterpret_cast(argv[1]); - const float *c = reinterpret_cast(argv[2]); - *v = QVariant::fromValue(QGeoCoordinate(*a, *b, *c)); - return true; - } - } - - return false; -} - -bool LocationValueTypeProvider::createFromString(int type, const QString &s, void *data, size_t dataSize) -{ - Q_UNUSED(data) - Q_UNUSED(dataSize) - - if (type == qMetaTypeId() || type == qMetaTypeId() || - type == qMetaTypeId() || type == qMetaTypeId()) { - qWarning("Cannot create value type %d from string '%s'", type, qPrintable(s)); - } - - return false; -} - -bool LocationValueTypeProvider::createStringFrom(int type, const void *data, QString *s) -{ - Q_UNUSED(data) - Q_UNUSED(s) - - if (type == qMetaTypeId() || type == qMetaTypeId() || - type == qMetaTypeId() || type == qMetaTypeId()) { - qWarning("Cannot create string from value type %d", type); - } - - return false; -} - -bool LocationValueTypeProvider::variantFromJsObject(int type, QQmlV4Handle h, QV8Engine *e, QVariant *v) -{ - Q_UNUSED(h) - Q_UNUSED(e) - Q_UNUSED(v) - - if (type == qMetaTypeId() || type == qMetaTypeId() || - type == qMetaTypeId() || type == qMetaTypeId()) { - qWarning("Cannot create variant from js object for type %d", type); - } - - return false; -} - -bool LocationValueTypeProvider::equal(int type, const void *lhs, const void *rhs, size_t rhsSize) -{ - Q_UNUSED(rhsSize) - - if (type == qMetaTypeId()) - return typedEqual(lhs, rhs); - else if (type == qMetaTypeId()) - return typedEqual(lhs, rhs); - else if (type == qMetaTypeId()) - return typedEqual(lhs, rhs); - else if (type == qMetaTypeId()) - return typedEqual(lhs, rhs); - - return false; -} - -bool LocationValueTypeProvider::store(int type, const void *src, void *dst, size_t dstSize) -{ - if (type == qMetaTypeId()) - return typedStore(src, dst, dstSize); - else if (type == qMetaTypeId()) - return typedStore(src, dst, dstSize); - else if (type == qMetaTypeId()) - return typedStore(src, dst, dstSize); - else if (type == qMetaTypeId()) - return typedStore(src, dst, dstSize); - - return false; -} - -bool LocationValueTypeProvider::read(int srcType, const void *src, size_t srcSize, int dstType, void *dst) -{ - if (srcType == qMetaTypeId()) - return typedRead(srcType, src, srcSize, dstType, dst); - else if (srcType == qMetaTypeId()) - return typedRead(srcType, src, srcSize, dstType, dst); - else if (srcType == qMetaTypeId()) - return typedRead(srcType, src, srcSize, dstType, dst); - else if (srcType == qMetaTypeId()) - return typedRead(srcType, src, srcSize, dstType, dst); - - return false; -} - -bool LocationValueTypeProvider::write(int type, const void *src, void *dst, size_t dstSize) -{ - if (type == qMetaTypeId()) - return typedWrite(src, dst, dstSize); - else if (type == qMetaTypeId()) - return typedWrite(src, dst, dstSize); - else if (type == qMetaTypeId()) - return typedWrite(src, dst, dstSize); - else if (type == qMetaTypeId()) - return typedWrite(src, dst, dstSize); - - return false; -} - -QT_END_NAMESPACE diff --git a/src/imports/location/locationvaluetypeprovider.h b/src/imports/location/locationvaluetypeprovider.h deleted file mode 100644 index 2d204aa5..00000000 --- a/src/imports/location/locationvaluetypeprovider.h +++ /dev/null @@ -1,172 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef LOCATIONVALUETYPEPROVIDER_H -#define LOCATIONVALUETYPEPROVIDER_H - -#include - -QT_BEGIN_NAMESPACE - -class QGeoCoordinate; -class QGeoRectangle; -class QGeoCircle; - -QGeoCoordinate parseCoordinate(const QJSValue &value, bool *ok); -QGeoRectangle parseRectangle(const QJSValue &value, bool *ok); -QGeoCircle parseCircle(const QJSValue &value, bool *ok); - -class LocationValueTypeProvider : public QQmlValueTypeProvider -{ -public: - LocationValueTypeProvider(); - -private: - template - bool typedCreate(QQmlValueType *&v) - { - v = new T; - return true; - } - - bool create(int type, QQmlValueType *&v) Q_DECL_OVERRIDE; - - template - bool typedInit(void *data, size_t dataSize) - { - Q_ASSERT(dataSize >= sizeof(T)); - Q_UNUSED(dataSize); - T *t = reinterpret_cast(data); - new (t) T(); - return true; - } - - bool init(int type, void *data, size_t dataSize) Q_DECL_OVERRIDE; - - template - bool typedDestroy(void *data, size_t dataSize) - { - Q_ASSERT(dataSize >= sizeof(T)); - Q_UNUSED(dataSize); - T *t = reinterpret_cast(data); - t->~T(); - return true; - } - - bool destroy(int type, void *data, size_t dataSize) Q_DECL_OVERRIDE; - - template - bool typedCopyConstruct(const void *src, void *dst, size_t dstSize) - { - Q_ASSERT(dstSize >= sizeof(T)); - Q_UNUSED(dstSize); - const T *srcT = reinterpret_cast(src); - T *dstT = reinterpret_cast(dst); - new (dstT) T(*srcT); - return true; - } - - bool copy(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE; - - bool create(int type, int argc, const void *argv[], QVariant *v) Q_DECL_OVERRIDE; - bool createFromString(int type, const QString &s, void *data, size_t dataSize) Q_DECL_OVERRIDE; - bool createStringFrom(int type, const void *data, QString *s) Q_DECL_OVERRIDE; - - bool variantFromJsObject(int type, QQmlV4Handle h, QV8Engine *e, QVariant *v) Q_DECL_OVERRIDE; - - template - bool typedEqual(const void *lhs, const void *rhs) - { - return *reinterpret_cast(lhs) == *reinterpret_cast(rhs); - } - - bool equal(int type, const void *lhs, const void *rhs, size_t rhsSize) Q_DECL_OVERRIDE; - - template - bool typedStore(const void *src, void *dst, size_t dstSize) - { - Q_ASSERT(dstSize >= sizeof(T)); - Q_UNUSED(dstSize); - const T *srcT = reinterpret_cast(src); - T *dstT = reinterpret_cast(dst); - new (dstT) T(*srcT); - return true; - } - - bool store(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE; - - template - bool typedRead(int srcType, const void *src, size_t srcSize, int dstType, void *dst) - { - T *dstT = reinterpret_cast(dst); - if (srcType == dstType) { - Q_ASSERT(srcSize >= sizeof(T)); - Q_UNUSED(srcSize); - const T *srcT = reinterpret_cast(src); - *dstT = *srcT; - } else { - *dstT = T(); - } - return true; - } - - bool read(int srcType, const void *src, size_t srcSize, int dstType, void *dst) Q_DECL_OVERRIDE; - - template - bool typedWrite(const void *src, void *dst, size_t dstSize) - { - Q_ASSERT(dstSize >= sizeof(T)); - Q_UNUSED(dstSize); - const T *srcT = reinterpret_cast(src); - T *dstT = reinterpret_cast(dst); - if (*dstT != *srcT) { - *dstT = *srcT; - return true; - } - return false; - } - - bool write(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE; -}; - -QT_END_NAMESPACE - -#endif // LOCATIONVALUETYPEPROVIDER_H diff --git a/src/imports/location/plugins.qmltypes b/src/imports/location/plugins.qmltypes index bb59436e..c4319665 100644 --- a/src/imports/location/plugins.qmltypes +++ b/src/imports/location/plugins.qmltypes @@ -6,75 +6,6 @@ import QtQuick.tooling 1.1 // This file was auto-generated with the command 'qmlplugindump -notrelocatable QtLocation 5.0'. Module { - Component { - name: "GeoShapeValueType" - prototype: "QQmlValueType" - exports: ["QtLocation/GeoShape 5.0"] - exportMetaObjectRevisions: [0] - Enum { - name: "ShapeType" - values: { - "UnknownType": 0, - "RectangleType": 1, - "CircleType": 2 - } - } - Property { name: "type"; type: "ShapeType"; isReadonly: true } - Property { name: "isValid"; type: "bool"; isReadonly: true } - Property { name: "isEmpty"; type: "bool"; isReadonly: true } - Method { - name: "contains" - type: "bool" - Parameter { name: "coordinate"; type: "QGeoCoordinate" } - } - } - Component { - name: "LocationSingleton" - prototype: "QObject" - exports: ["QtLocation/QtLocation 5.0"] - exportMetaObjectRevisions: [0] - Method { name: "coordinate"; type: "QGeoCoordinate" } - Method { - name: "coordinate" - type: "QGeoCoordinate" - Parameter { name: "latitude"; type: "double" } - Parameter { name: "longitude"; type: "double" } - Parameter { name: "altitude"; type: "double" } - } - Method { - name: "coordinate" - type: "QGeoCoordinate" - Parameter { name: "latitude"; type: "double" } - Parameter { name: "longitude"; type: "double" } - } - Method { name: "shape"; type: "QGeoShape" } - Method { name: "rectangle"; type: "QGeoRectangle" } - Method { - name: "rectangle" - type: "QGeoRectangle" - Parameter { name: "center"; type: "QGeoCoordinate" } - Parameter { name: "width"; type: "double" } - Parameter { name: "height"; type: "double" } - } - Method { - name: "rectangle" - type: "QGeoRectangle" - Parameter { name: "topLeft"; type: "QGeoCoordinate" } - Parameter { name: "bottomRight"; type: "QGeoCoordinate" } - } - Method { name: "circle"; type: "QGeoCircle" } - Method { - name: "circle" - type: "QGeoCircle" - Parameter { name: "center"; type: "QGeoCoordinate" } - Parameter { name: "radius"; type: "double" } - } - Method { - name: "circle" - type: "QGeoCircle" - Parameter { name: "center"; type: "QGeoCoordinate" } - } - } Component { name: "QDeclarativeCategory" prototype: "QObject" @@ -156,33 +87,6 @@ Module { exports: ["QtLocation/ContactDetails 5.0"] exportMetaObjectRevisions: [0] } - Component { - name: "QDeclarativeGeoAddress" - prototype: "QObject" - exports: ["QtLocation/Address 5.0"] - exportMetaObjectRevisions: [0] - Property { name: "address"; type: "QGeoAddress" } - Property { name: "text"; type: "string" } - Property { name: "country"; type: "string" } - Property { name: "countryCode"; type: "string" } - Property { name: "state"; type: "string" } - Property { name: "county"; type: "string" } - Property { name: "city"; type: "string" } - Property { name: "district"; type: "string" } - Property { name: "street"; type: "string" } - Property { name: "postalCode"; type: "string" } - Property { name: "isTextGenerated"; type: "bool"; isReadonly: true } - } - Component { - name: "QDeclarativeGeoLocation" - prototype: "QObject" - exports: ["QtLocation/Location 5.0"] - exportMetaObjectRevisions: [0] - Property { name: "location"; type: "QGeoLocation" } - Property { name: "address"; type: "QDeclarativeGeoAddress"; isPointer: true } - Property { name: "coordinate"; type: "QGeoCoordinate" } - Property { name: "boundingBox"; type: "QGeoRectangle" } - } Component { name: "QDeclarativeGeoManeuver" prototype: "QObject" @@ -1083,68 +987,6 @@ Module { Parameter { name: "coordinate"; type: "QGeoCoordinate" } } } - Component { - name: "QDeclarativePosition" - prototype: "QObject" - exports: ["QtLocation/Position 5.0"] - exportMetaObjectRevisions: [0] - Property { name: "latitudeValid"; type: "bool"; isReadonly: true } - Property { name: "longitudeValid"; type: "bool"; isReadonly: true } - Property { name: "altitudeValid"; type: "bool"; isReadonly: true } - Property { name: "coordinate"; type: "QGeoCoordinate"; isReadonly: true } - Property { name: "timestamp"; type: "QDateTime"; isReadonly: true } - Property { name: "speed"; type: "double"; isReadonly: true } - Property { name: "speedValid"; type: "bool"; isReadonly: true } - Property { name: "horizontalAccuracy"; type: "double" } - Property { name: "verticalAccuracy"; type: "double" } - Property { name: "horizontalAccuracyValid"; type: "bool"; isReadonly: true } - Property { name: "verticalAccuracyValid"; type: "bool"; isReadonly: true } - } - Component { - name: "QDeclarativePositionSource" - prototype: "QObject" - exports: ["QtLocation/PositionSource 5.0"] - exportMetaObjectRevisions: [0] - Enum { - name: "PositioningMethod" - values: { - "NoPositioningMethod": 0, - "SatellitePositioningMethod": 255, - "NonSatellitePositioningMethod": -256, - "AllPositioningMethods": -1 - } - } - Enum { - name: "PositioningMethods" - values: { - "NoPositioningMethod": 0, - "SatellitePositioningMethod": 255, - "NonSatellitePositioningMethod": -256, - "AllPositioningMethods": -1 - } - } - Enum { - name: "SourceError" - values: { - "AccessError": 0, - "ClosedError": 1, - "UnknownSourceError": -1 - } - } - Property { name: "position"; type: "QDeclarativePosition"; isReadonly: true; isPointer: true } - Property { name: "active"; type: "bool" } - Property { name: "valid"; type: "bool"; isReadonly: true } - Property { name: "nmeaSource"; type: "QUrl" } - Property { name: "updateInterval"; type: "int" } - Property { name: "supportedPositioningMethods"; type: "PositioningMethods"; isReadonly: true } - Property { name: "preferredPositioningMethods"; type: "PositioningMethods" } - Property { name: "sourceError"; type: "SourceError"; isReadonly: true } - Property { name: "name"; type: "string" } - Signal { name: "validityChanged" } - Method { name: "update" } - Method { name: "start" } - Method { name: "stop" } - } Component { name: "QDeclarativeRatings" prototype: "QObject" @@ -1238,7 +1080,8 @@ Module { name: "SearchResultType" values: { "UnknownSearchResult": 0, - "PlaceResult": 1 + "PlaceResult": 1, + "ProposedSearchResult": 2 } } Enum { @@ -1265,6 +1108,10 @@ Module { Parameter { name: "index"; type: "int" } Parameter { name: "roleName"; type: "string" } } + Method { + name: "updateWith" + Parameter { name: "proposedSearchIndex"; type: "int" } + } } Component { name: "QDeclarativeSearchSuggestionModel" diff --git a/src/imports/location/qdeclarativecirclemapitem.cpp b/src/imports/location/qdeclarativecirclemapitem.cpp index 7ffaa406..eb9d1272 100644 --- a/src/imports/location/qdeclarativecirclemapitem.cpp +++ b/src/imports/location/qdeclarativecirclemapitem.cpp @@ -319,10 +319,12 @@ QDeclarativeCircleMapItem::~QDeclarativeCircleMapItem() } /*! + \qmlpropertygroup Location::MapCircle::border \qmlproperty int MapCircle::border.width \qmlproperty color MapCircle::border.color - These properties hold the width and color used to draw the border of the circle. + This property is part of the border group property. + The border property holds the width and color used to draw the border of the circle. The width is in pixels and is independent of the zoom level of the map. The default values correspond to a black border with a width of 1 pixel. diff --git a/src/imports/location/qdeclarativecoordinate.cpp b/src/imports/location/qdeclarativecoordinate.cpp deleted file mode 100644 index f832d4f2..00000000 --- a/src/imports/location/qdeclarativecoordinate.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativecoordinate_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \qmlbasictype coordinate - \inqmlmodule QtLocation 5.0 - \ingroup qml-QtLocation5-basictypes - \since Qt Location 5.0 - - \brief The coordinate type represents and stores a geographic position. - - The \c coordinate type represents a geographic position in the form of \c {latitude}, - \c longitude and \c altitude attributes. The \c latitude attribute specifies the number of - decimal degrees above and below the equator. A positive latitude indicates the Northern - Hemisphere and a negative latitude indicates the Southern Hemisphere. The \c longitude - attribute specifies the number of decimal degrees east and west. A positive longitude - indicates the Eastern Hemisphere and a negative longitude indicates the Western Hemisphere. - The \c altitude attribute specifies the number of meters above sea level. Together, these - attributes specify a 3-dimensional position anywhere on or near the Earth's surface. - - The \c isValid attribute can be used to test if a coordinate is valid. A coordinate is - considered valid if it has a valid latitude and longitude. A valid altitude is not required. - The latitude must be between -90 and 90 inclusive and the longitude must be between -180 and - 180 inclusive. - - The coordinate type is used by many other types in the Qt Location module, for specifying - the position of an object on a Map, the current position of a device and many other tasks. - They also feature a number of important utility methods that make otherwise complex - calculations simple to use, such as \l atDistanceAndAzimuth(). - - \section2 Accuracy - - The latitude, longitude and altitude attributes stored in the coordinate type are represented - as doubles, giving them approximately 16 decimal digits of precision -- enough to specify - micrometers. The calculations performed in coordinate's methods such as \l azimuthTo() and - \l distanceTo() also use doubles for all intermediate values, but the inherent inaccuracies in - their spherical Earth model dominate the amount of error in their output. - - \section2 Example Usage - - Use properties of type \l variant to store a \c {coordinate}. To create a \c coordinate use - one of the methods described below. In all cases, specifying the \c altitude attribute is - optional. - - To create a \c coordinate value, use the \l{QtLocation5::QtLocation}{QtLocation.coordinate()} - function: - - \qml - import QtLocation 5.0 - - Location { coordinate: QtLocation.coordinate(-27.5, 153.1) } - \endqml - - or as separate \c {latitude}, \c longitude and \c altitude components: - - \qml - Location { - coordinate { - latitude: -27.5 - longitude: 153.1 - } - } - \endqml - - When integrating with C++, note that any QGeoCoordinate value passed into QML from C++ is - automatically converted into a \c coordinate value, and vice-versa. - - \section2 Methods - - \section3 distanceTo() - - \code - real distanceTo(coordinate other) - \endcode - - Returns the distance (in meters) from this coordinate to the coordinate specified by \a other. - Altitude is not used in the calculation. - - This calculation returns the great-circle distance between the two coordinates, with an - assumption that the Earth is spherical for the purpose of this calculation. - - \section3 azimuthTo() - - \code - real azimuth(coordinate other) - \endcode - - Returns the azimuth (or bearing) in degrees from this coordinate to the coordinate specified by - \a other. Altitude is not used in the calculation. - - There is an assumption that the Earth is spherical for the purpose of this calculation. - - \section3 atDistanceAndAzimuth() - - \code - coordinate atDistanceAndAzimuth(real distance, real azimuth) - \endcode - - Returns the coordinate that is reached by traveling \a distance metres from this coordinate at - \a azimuth degrees along a great-circle. - - There is an assumption that the Earth is spherical for the purpose of this calculation. -*/ - - -CoordinateValueType::CoordinateValueType(QObject *parent) -: QQmlValueTypeBase(qMetaTypeId(), parent) -{ -} - -CoordinateValueType::~CoordinateValueType() -{ -} - -/* - This property holds the value of altitude (meters above sea level). - If the property has not been set, its default value is NaN. - -*/ -void CoordinateValueType::setAltitude(double altitude) -{ - v.setAltitude(altitude); -} - -double CoordinateValueType::altitude() const -{ - return v.altitude(); -} - -/* - This property holds the longitude value of the geographical position - (decimal degrees). A positive longitude indicates the Eastern Hemisphere, - and a negative longitude indicates the Western Hemisphere - If the property has not been set, its default value is NaN. -*/ -void CoordinateValueType::setLongitude(double longitude) -{ - v.setLongitude(longitude); -} - -double CoordinateValueType::longitude() const -{ - return v.longitude(); -} - -/* - This property holds latitude value of the geographical position - (decimal degrees). A positive latitude indicates the Northern Hemisphere, - and a negative latitude indicates the Southern Hemisphere. - If the property has not been set, its default value is NaN. -*/ -void CoordinateValueType::setLatitude(double latitude) -{ - v.setLatitude(latitude); -} - -double CoordinateValueType::latitude() const -{ - return v.latitude(); -} - -/* - This property holds the current validity of the coordinate. Coordinates - are considered valid if they have been set with a valid latitude and - longitude (altitude is not required). - - The latitude must be between -90 to 90 inclusive to be considered valid, - and the longitude must be between -180 to 180 inclusive to be considered - valid. -*/ -bool CoordinateValueType::isValid() const -{ - return v.isValid(); -} - -QString CoordinateValueType::toString() const -{ - return QStringLiteral("QGeoCoordinate(%1,%2,%3)") - .arg(v.latitude()).arg(v.longitude()).arg(v.altitude()); -} - -bool CoordinateValueType::isEqual(const QVariant &other) const -{ - if (other.userType() != qMetaTypeId()) - return false; - - return v == other.value(); -} - -/* - Returns the distance (in meters) from this coordinate to the - coordinate specified by other. Altitude is not used in the calculation. - - This calculation returns the great-circle distance between the two - coordinates, with an assumption that the Earth is spherical for the - purpose of this calculation. -*/ -qreal CoordinateValueType::distanceTo(const QGeoCoordinate &coordinate) const -{ - return v.distanceTo(coordinate); -} - -/* - Returns the azimuth (or bearing) in degrees from this coordinate to the - coordinate specified by other. Altitude is not used in the calculation. - - There is an assumption that the Earth is spherical for the purpose of - this calculation. -*/ -qreal CoordinateValueType::azimuthTo(const QGeoCoordinate &coordinate) const -{ - return v.azimuthTo(coordinate); -} - -/* - Returns the coordinate that is reached by traveling distance metres - from the current coordinate at azimuth degrees along a great-circle. - - There is an assumption that the Earth is spherical for the purpose - of this calculation. -*/ -QGeoCoordinate CoordinateValueType::atDistanceAndAzimuth(qreal distance, qreal azimuth) const -{ - return v.atDistanceAndAzimuth(distance, azimuth); -} - -#include "moc_qdeclarativecoordinate_p.cpp" - -QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativecoordinate_p.h b/src/imports/location/qdeclarativecoordinate_p.h deleted file mode 100644 index 1e4e6dd5..00000000 --- a/src/imports/location/qdeclarativecoordinate_p.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#ifndef QDECLARATIVECOORDINATE_H -#define QDECLARATIVECOORDINATE_H - -#include -#include - -QT_BEGIN_NAMESPACE - -class CoordinateValueType : public QQmlValueTypeBase -{ - Q_OBJECT - - Q_PROPERTY(double latitude READ latitude WRITE setLatitude) - Q_PROPERTY(double longitude READ longitude WRITE setLongitude) - Q_PROPERTY(double altitude READ altitude WRITE setAltitude) - Q_PROPERTY(bool isValid READ isValid) - -public: - explicit CoordinateValueType(QObject *parent = 0); - ~CoordinateValueType(); - - Q_INVOKABLE qreal distanceTo(const QGeoCoordinate &coordinate) const; - Q_INVOKABLE qreal azimuthTo(const QGeoCoordinate &coordinate) const; - - Q_INVOKABLE QGeoCoordinate atDistanceAndAzimuth(qreal distance, qreal azimuth) const; - - double latitude() const; - void setLatitude(double latitude); - - double longitude() const; - void setLongitude(double longitude); - - double altitude() const; - void setAltitude(double altitude); - - bool isValid() const; - - QString toString() const Q_DECL_OVERRIDE; - bool isEqual(const QVariant &other) const Q_DECL_OVERRIDE; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/imports/location/qdeclarativegeoaddress.cpp b/src/imports/location/qdeclarativegeoaddress.cpp deleted file mode 100644 index 3244cfc8..00000000 --- a/src/imports/location/qdeclarativegeoaddress.cpp +++ /dev/null @@ -1,360 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#include "qdeclarativegeoaddress_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \qmltype Address - \instantiates QDeclarativeGeoAddress - \inqmlmodule QtLocation 5.0 - \ingroup qml-QtLocation5-positioning - \since Qt Location 5.0 - - \brief The Address QML type represents a specific location as a street address. - - An Address is used as a unit of data for queries such as (Reverse) Geocoding - or Places searches -- many of these operations either accept an Address - or return one. - - Not all properties of an Address are necessarily available or relevant - in all parts of the world and all locales. The \l district, \l state and - \l county properties are particularly area-specific for many data sources - (including the provided Nokia plugin), and often only one or two of these - is available or useful. - - The Address has a \l text property which holds a formatted string. It - is the recommended way to display an address to the user and typically - takes the format of an address as found on an envelope, but this is not always - the case. The \l text may be automatically generated from constituent - address properties such as \l street, \l city and and so on, but can also - be explicitly assigned. See \l text for details. - - \section2 Example Usage - - The following code snippet shows the declaration of an Address object. - - \code - Address { - id: address - street: "53 Brandl St" - city: "Eight Mile Plains" - country: "Australia" - countryCode: "AUS" - } - \endcode - - This could then be used, for example, as the value of a \l{GeocodeModel}'s - \l{GeocodeModel::query}{query} property, to get an exact longitude and - latitude for the address. - - \sa {QGeoAddress} -*/ - -QDeclarativeGeoAddress::QDeclarativeGeoAddress(QObject *parent) : - QObject(parent) -{ -} - -QDeclarativeGeoAddress::QDeclarativeGeoAddress(const QGeoAddress &address, QObject *parent) : - QObject(parent), m_address(address) -{ -} - -/*! - \qmlproperty QGeoAddress QtLocation5::Address::address - - For details on how to use this property to interface between C++ and QML see - "\l {location-cpp-qml.html#geoaddress} {Interfaces between C++ and QML Code}". -*/ -QGeoAddress QDeclarativeGeoAddress::address() const -{ - return m_address; -} - -void QDeclarativeGeoAddress::setAddress(const QGeoAddress &address) -{ - // Elaborate but takes care of emiting needed signals - setText(address.text()); - setCountry(address.country()); - setCountryCode(address.countryCode()); - setState(address.state()); - setCounty(address.county()); - setCity(address.city()); - setDistrict(address.district()); - setStreet(address.street()); - setPostalCode(address.postalCode()); - m_address = address; -} - -/*! - \qmlproperty string QtLocation5::Address::text - - This property holds the address as a single formatted string. It is the recommended - string to use to display the address to the user. It typically takes the format of - an address as found on an envelope, but this is not always necessarily the case. - - The adddress \c text is either automatically generated or explicitly assigned, - this can be determined by checking \l isTextGenerated. - - If an empty string is assigned to \c text, then \l isTextGenerated will be set - to true and \c text will return a string which is locally formatted according to - \l countryCode and based on the properties of the address. Modifying the address - properties such as \l street, \l city and so on may cause the contents of \c text to - change. - - If a non-empty string is assigned to \c text, then \l isTextGenerated will be - set to false and \c text will always return the explicitly assigned string. - Modifying address properties will not affect the \c text property. -*/ -QString QDeclarativeGeoAddress::text() const -{ - return m_address.text(); -} - -void QDeclarativeGeoAddress::setText(const QString &address) -{ - QString oldText = m_address.text(); - bool oldIsTextGenerated = m_address.isTextGenerated(); - m_address.setText(address); - - if (oldText != m_address.text()) - emit textChanged(); - if (oldIsTextGenerated != m_address.isTextGenerated()) - emit isTextGeneratedChanged(); -} - -/*! - \qmlproperty string QtLocation5::Address::country - - This property holds the country of the address as a single formatted string. -*/ -QString QDeclarativeGeoAddress::country() const -{ - return m_address.country(); -} - -void QDeclarativeGeoAddress::setCountry(const QString &country) -{ - if (m_address.country() == country) - return; - QString oldText = m_address.text(); - m_address.setCountry(country); - emit countryChanged(); - - if (m_address.isTextGenerated() && oldText != m_address.text()) - emit textChanged(); -} - -/*! - \qmlproperty string QtLocation5::Address::countryCode - - This property holds the country code of the address as a single formatted string. -*/ -QString QDeclarativeGeoAddress::countryCode() const -{ - return m_address.countryCode(); -} - -void QDeclarativeGeoAddress::setCountryCode(const QString &countryCode) -{ - if (m_address.countryCode() == countryCode) - return; - QString oldText = m_address.text(); - m_address.setCountryCode(countryCode); - emit countryCodeChanged(); - - if (m_address.isTextGenerated() && oldText != m_address.text()) - emit textChanged(); -} - -/*! - \qmlproperty string QtLocation5::Address::state - - This property holds the state of the address as a single formatted string. -*/ -QString QDeclarativeGeoAddress::state() const -{ - return m_address.state(); -} - -void QDeclarativeGeoAddress::setState(const QString &state) -{ - if (m_address.state() == state) - return; - QString oldText = m_address.text(); - m_address.setState(state); - emit stateChanged(); - - if (m_address.isTextGenerated() && oldText != m_address.text()) - emit textChanged(); -} - -/*! - \qmlproperty string QtLocation5::Address::county - - This property holds the county of the address as a single formatted string. -*/ -QString QDeclarativeGeoAddress::county() const -{ - return m_address.county(); -} - -void QDeclarativeGeoAddress::setCounty(const QString &county) -{ - if (m_address.county() == county) - return; - QString oldText = m_address.text(); - m_address.setCounty(county); - emit countyChanged(); - - if (m_address.isTextGenerated() && oldText != m_address.text()) - emit textChanged(); -} - -/*! - \qmlproperty string QtLocation5::Address::city - - This property holds the city of the address as a single formatted string. -*/ -QString QDeclarativeGeoAddress::city() const -{ - return m_address.city(); -} - -void QDeclarativeGeoAddress::setCity(const QString &city) -{ - if (m_address.city() == city) - return; - QString oldText = m_address.text(); - m_address.setCity(city); - emit cityChanged(); - - if (m_address.isTextGenerated() && oldText != m_address.text()) - emit textChanged(); -} - -/*! - \qmlproperty string QtLocation5::Address::district - - This property holds the district of the address as a single formatted string. -*/ -QString QDeclarativeGeoAddress::district() const -{ - return m_address.district(); -} - -void QDeclarativeGeoAddress::setDistrict(const QString &district) -{ - if (m_address.district() == district) - return; - QString oldText = m_address.text(); - m_address.setDistrict(district); - emit districtChanged(); - - if (m_address.isTextGenerated() && oldText != m_address.text()) - emit textChanged(); -} - -/*! - \qmlproperty string QtLocation5::Address::street - - This property holds the street of the address but - may also contain things like a unit number, a building - name, or anything else that might be used to - distinguish one address from another. -*/ -QString QDeclarativeGeoAddress::street() const -{ - return m_address.street(); -} - -void QDeclarativeGeoAddress::setStreet(const QString &street) -{ - if (m_address.street() == street) - return; - QString oldText = m_address.text(); - m_address.setStreet(street); - emit streetChanged(); - - if (m_address.isTextGenerated() && oldText != m_address.text()) - emit textChanged(); -} - -/*! - \qmlproperty string QtLocation5::Address::postalCode - - This property holds the postal code of the address as a single formatted string. -*/ -QString QDeclarativeGeoAddress::postalCode() const -{ - return m_address.postalCode(); -} - -void QDeclarativeGeoAddress::setPostalCode(const QString &postalCode) -{ - if (m_address.postalCode() == postalCode) - return; - QString oldText = m_address.text(); - m_address.setPostalCode(postalCode); - emit postalCodeChanged(); - - if (m_address.isTextGenerated() && oldText != m_address.text()) - emit textChanged(); -} - -/*! - \qmlproperty bool QtLocation5::Address::isTextGenerated - - This property holds a boolean that if true, indicates that \l text is automatically - generated from address properties. If false, it indicates that the \l text has been - explicitly assigned. - -*/ -bool QDeclarativeGeoAddress::isTextGenerated() const -{ - return m_address.isTextGenerated(); -} - -#include "moc_qdeclarativegeoaddress_p.cpp" - -QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeoaddress_p.h b/src/imports/location/qdeclarativegeoaddress_p.h deleted file mode 100644 index 660145be..00000000 --- a/src/imports/location/qdeclarativegeoaddress_p.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#ifndef QDECLARATIVEGEOADDRESS_P_H -#define QDECLARATIVEGEOADDRESS_P_H - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QDeclarativeGeoAddress : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QGeoAddress address READ address WRITE setAddress) - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged) - Q_PROPERTY(QString countryCode READ countryCode WRITE setCountryCode NOTIFY countryCodeChanged) - Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(QString county READ county WRITE setCounty NOTIFY countyChanged) - Q_PROPERTY(QString city READ city WRITE setCity NOTIFY cityChanged) - Q_PROPERTY(QString district READ district WRITE setDistrict NOTIFY districtChanged) - Q_PROPERTY(QString street READ street WRITE setStreet NOTIFY streetChanged) - Q_PROPERTY(QString postalCode READ postalCode WRITE setPostalCode NOTIFY postalCodeChanged) - Q_PROPERTY(bool isTextGenerated READ isTextGenerated NOTIFY isTextGeneratedChanged) - -public: - explicit QDeclarativeGeoAddress(QObject *parent = 0); - QDeclarativeGeoAddress(const QGeoAddress &address, QObject *parent = 0); - QGeoAddress address() const; - void setAddress(const QGeoAddress &address); - - QString text() const; - void setText(const QString &address); - - QString country() const; - void setCountry(const QString &country); - QString countryCode() const; - void setCountryCode(const QString &countryCode); - QString state() const; - void setState(const QString &state); - QString county() const; - void setCounty(const QString &county); - QString city() const; - void setCity(const QString &city); - QString district() const; - void setDistrict(const QString &district); - QString street() const; - void setStreet(const QString &street); - QString postalCode() const; - void setPostalCode(const QString &postalCode); - bool isTextGenerated() const; - -Q_SIGNALS: - void textChanged(); - void countryChanged(); - void countryCodeChanged(); - void stateChanged(); - void countyChanged(); - void cityChanged(); - void districtChanged(); - void streetChanged(); - void postalCodeChanged(); - void isTextGeneratedChanged(); - -private: - QGeoAddress m_address; -}; - -QT_END_NAMESPACE -QML_DECLARE_TYPE(QDeclarativeGeoAddress) - -#endif // QDECLARATIVEGEOADDRESS_P_H diff --git a/src/imports/location/qdeclarativegeocircle.cpp b/src/imports/location/qdeclarativegeocircle.cpp deleted file mode 100644 index cfa533a9..00000000 --- a/src/imports/location/qdeclarativegeocircle.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#include "qdeclarativegeocircle.h" - -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmlbasictype geocircle - \inqmlmodule QtLocation 5.0 - \ingroup qml-QtLocation5-positioning - \since Qt Location 5.0 - - \brief The geocircle type represents a circular geographic area. - - The \c geocircle type is a \l {geoshape} that represents a circular - geographic area. It is defined in terms of a \l {coordinate} which - specifies the \c center of the circle and a qreal which specifies the \c radius of the circle - in meters. - - The circle is considered invalid if the center coordinate is invalid or if the radius is less - than zero. - - \section2 Example Usage - - Use properties of type \l variant to store a \c {geocircle}. To create a \c geocircle value, - use the \l {QtLocation::circle}{QtLocation.circle()} function: - - \qml - import QtLocation 5.0 - - Item { - property variant region: QtLocation.circle(QtLocation.coordinate(-27.5, 153.1), 1000) - } - \endqml - - When integrating with C++, note that any QGeoCircle value passed into QML from C++ is - automatically converted into a \c geocircle value, and vise-versa. -*/ - -GeoCircleValueType::GeoCircleValueType(QObject *parent) -: GeoShapeValueType(qMetaTypeId(), parent) -{ -} - -GeoCircleValueType::~GeoCircleValueType() -{ -} - -/* - This property holds the coordinate of the center of the geocircle. -*/ -QGeoCoordinate GeoCircleValueType::center() -{ - return QGeoCircle(v).center(); -} - -void GeoCircleValueType::setCenter(const QGeoCoordinate &coordinate) -{ - QGeoCircle c = v; - - if (c.center() == coordinate) - return; - - c.setCenter(coordinate); - v = c; -} - -/*! - This property holds the radius of the geocircle in meters. - - The default value for the radius is -1 indicating an invalid geocircle area. -*/ -qreal GeoCircleValueType::radius() const -{ - return QGeoCircle(v).radius(); -} - -void GeoCircleValueType::setRadius(qreal radius) -{ - QGeoCircle c = v; - - if (c.radius() == radius) - return; - - c.setRadius(radius); - v = c; -} - -QString GeoCircleValueType::toString() const -{ - if (v.type() != QGeoShape::CircleType) { - qWarning("Not a circle"); - return QStringLiteral("QGeoCircle(not a circle)"); - } - - QGeoCircle c = v; - return QStringLiteral("QGeoCircle({%1, %2}, %3)") - .arg(c.center().latitude()) - .arg(c.center().longitude()) - .arg(c.radius()); -} - -void GeoCircleValueType::setValue(const QVariant &value) -{ - if (value.userType() == qMetaTypeId()) - v = value.value(); - else if (value.userType() == qMetaTypeId()) - v = value.value(); - else - v = QGeoCircle(); - - onLoad(); -} - -QVariant GeoCircleValueType::value() -{ - return QVariant::fromValue(QGeoCircle(v)); -} - -void GeoCircleValueType::write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) -{ - QGeoCircle c = v; - writeProperty(obj, idx, flags, &c); -} - -void GeoCircleValueType::writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags, QVariant *from) -{ - if (from->userType() == qMetaTypeId()) { - writeProperty(obj, idx, flags, from); - } else if (from->userType() == qMetaTypeId()) { - QGeoCircle c = from->value(); - QVariant v = QVariant::fromValue(c); - writeProperty(obj, idx, flags, &v); - } else { - QVariant v = QVariant::fromValue(QGeoCircle()); - writeProperty(obj, idx, flags, &v); - } -} - -#include "moc_qdeclarativegeocircle.cpp" - -QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeocircle.h b/src/imports/location/qdeclarativegeocircle.h deleted file mode 100644 index 7345d697..00000000 --- a/src/imports/location/qdeclarativegeocircle.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#ifndef QDECLARATIVEGEOCIRCLE_H -#define QDECLARATIVEGEOCIRCLE_H - -#include "qdeclarativegeoshape.h" - -QT_BEGIN_NAMESPACE - -class GeoCircleValueType : public GeoShapeValueType -{ - Q_OBJECT - - Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter) - Q_PROPERTY(qreal radius READ radius WRITE setRadius) - -public: - explicit GeoCircleValueType(QObject *parent = 0); - ~GeoCircleValueType(); - - QGeoCoordinate center(); - void setCenter(const QGeoCoordinate &coordinate); - - qreal radius() const; - void setRadius(qreal radius); - - QString toString() const Q_DECL_OVERRIDE; - void setValue(const QVariant &value) Q_DECL_OVERRIDE; - QVariant value() Q_DECL_OVERRIDE; - void write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) Q_DECL_OVERRIDE; - void writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags, QVariant *from) Q_DECL_OVERRIDE; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/imports/location/qdeclarativegeocodemodel.cpp b/src/imports/location/qdeclarativegeocodemodel.cpp index ca22a270..d242ec75 100644 --- a/src/imports/location/qdeclarativegeocodemodel.cpp +++ b/src/imports/location/qdeclarativegeocodemodel.cpp @@ -41,12 +41,11 @@ #include "qdeclarativegeocodemodel_p.h" #include "error_messages.h" -#include "qdeclarativegeolocation_p.h" #include #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -332,10 +331,10 @@ void QDeclarativeGeocodeModel::setBounds(const QVariant &boundingArea) } /*! - \qmlproperty GeoShape QtLocation5::GeocodeModel::bounds + \qmlproperty geoshape QtLocation5::GeocodeModel::bounds This property holds the bounding area used to limit the results to those - within the area. his is particularly useful if query is only partially filled out, + within the area. This is particularly useful if query is only partially filled out, as the service will attempt to (reverse) geocode all matches for the specified data. Accepted types are \l {georectangle} and @@ -498,7 +497,7 @@ int QDeclarativeGeocodeModel::count() const } /*! - \qmlmethod QtLocation5::GeocodeModel::get(int) + \qmlmethod Location QtLocation5::GeocodeModel::get(int) Returns the Location at given index. Use \l count property to check the amount of locations available. The locations are indexed from zero, so the accessible range diff --git a/src/imports/location/qdeclarativegeocodemodel_p.h b/src/imports/location/qdeclarativegeocodemodel_p.h index 66d34d6d..f5b16a25 100644 --- a/src/imports/location/qdeclarativegeocodemodel_p.h +++ b/src/imports/location/qdeclarativegeocodemodel_p.h @@ -44,12 +44,12 @@ #include "qdeclarativegeoserviceprovider_p.h" -#include "qdeclarativegeocircle.h" #include +#include +#include #include #include -#include "qdeclarativegeolocation_p.h" #include #include diff --git a/src/imports/location/qdeclarativegeolocation.cpp b/src/imports/location/qdeclarativegeolocation.cpp deleted file mode 100644 index 404a821d..00000000 --- a/src/imports/location/qdeclarativegeolocation.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativegeolocation_p.h" - -QT_USE_NAMESPACE - -/*! - \qmltype Location - \instantiates QDeclarativeGeoLocation - \inqmlmodule QtLocation 5.0 - \ingroup qml-QtLocation5-positioning - \since Qt Location 5.0 - - \brief The Location type holds location data. - - Location types represent a geographic "location", in a human sense. This - consists of a specific \l {coordinate}, an \l {address} and a \l {boundingBox}{bounding box}. - The \l {boundingBox}{bounding box} represents the recommended region - to display when viewing this location. - - The Location type is most commonly seen as the contents of a search - model such as the GeocodeModel. When a GeocodeModel returns the list of - locations found for a given query, it represents these as Location objects. - - \section2 Example Usage - - The following example shows a simple Location object being declared: - - \code - Location { - coordinate { - latitude: -27.3 - longitude: 153.1 - } - address: Address { - ... - } - } - \endcode -*/ - -QDeclarativeGeoLocation::QDeclarativeGeoLocation(QObject *parent) -: QObject(parent), m_address(0) - -{ - setLocation(QGeoLocation()); -} - -QDeclarativeGeoLocation::QDeclarativeGeoLocation(const QGeoLocation &src, QObject *parent) -: QObject(parent), m_address(0) -{ - setLocation(src); -} - -QDeclarativeGeoLocation::~QDeclarativeGeoLocation() -{ -} - -/*! - \qmlproperty QGeoLocation QtLocation5::Location::location - - For details on how to use this property to interface between C++ and QML see - "\l {location-cpp-qml.html#location} {Interfaces between C++ and QML Code}". -*/ -void QDeclarativeGeoLocation::setLocation(const QGeoLocation &src) -{ - if (m_address && m_address->parent() == this) { - m_address->setAddress(src.address()); - } else if (!m_address || m_address->parent() != this) { - m_address = new QDeclarativeGeoAddress(src.address(), this); - emit addressChanged(); - } - - setCoordinate(src.coordinate()); - setBoundingBox(src.boundingBox()); -} - -QGeoLocation QDeclarativeGeoLocation::location() const -{ - QGeoLocation retValue; - retValue.setAddress(m_address ? m_address->address() : QGeoAddress()); - retValue.setCoordinate(m_coordinate); - retValue.setBoundingBox(m_boundingBox); - return retValue; -} - -/*! - \qmlproperty Address QtLocation5::Location::address - - This property holds the address of the location which can be use to retrieve address details of the location. -*/ -void QDeclarativeGeoLocation::setAddress(QDeclarativeGeoAddress *address) -{ - if (m_address == address) - return; - - if (m_address && m_address->parent() == this) - delete m_address; - - m_address = address; - emit addressChanged(); -} - -QDeclarativeGeoAddress *QDeclarativeGeoLocation::address() const -{ - return m_address; -} - -/*! - \qmlproperty coordinate QtLocation5::Location::coordinate - - This property holds the exact geographical coordinate of the location which can be used to retrieve the latitude, longitude and altitude of the location. - - \note this property's changed() signal is currently emitted only if the - whole object changes, not if only the contents of the object change. -*/ -void QDeclarativeGeoLocation::setCoordinate(const QGeoCoordinate coordinate) -{ - if (m_coordinate == coordinate) - return; - - m_coordinate = coordinate; - emit coordinateChanged(); -} - -QGeoCoordinate QDeclarativeGeoLocation::coordinate() const -{ - return m_coordinate; -} - -/*! - \qmlproperty GeoRectangle QtLocation5::Location::boundingBox - - This property holds the recommended region to use when displaying the location. - For example, a building's location may have a region centered around the building, - but the region is large enough to show it's immediate surrounding geographical - context. - - Note: this property's changed() signal is currently emitted only if the - whole object changes, not if only the contents of the object change. -*/ -void QDeclarativeGeoLocation::setBoundingBox(const QGeoRectangle &boundingBox) -{ - if (m_boundingBox == boundingBox) - return; - - m_boundingBox = boundingBox; - emit boundingBoxChanged(); -} - -QGeoRectangle QDeclarativeGeoLocation::boundingBox() const -{ - return m_boundingBox; -} diff --git a/src/imports/location/qdeclarativegeolocation_p.h b/src/imports/location/qdeclarativegeolocation_p.h deleted file mode 100644 index 4435eeec..00000000 --- a/src/imports/location/qdeclarativegeolocation_p.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEGEOLOCATION_P_H -#define QDECLARATIVEGEOLOCATION_P_H - -#include "qdeclarativegeoaddress_p.h" - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QDeclarativeGeoLocation : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QGeoLocation location READ location WRITE setLocation) - Q_PROPERTY(QDeclarativeGeoAddress *address READ address WRITE setAddress NOTIFY addressChanged) - Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) - Q_PROPERTY(QGeoRectangle boundingBox READ boundingBox WRITE setBoundingBox NOTIFY boundingBoxChanged) - -public: - explicit QDeclarativeGeoLocation(QObject *parent = 0); - explicit QDeclarativeGeoLocation(const QGeoLocation &src, QObject *parent = 0); - ~QDeclarativeGeoLocation(); - - QGeoLocation location() const; - void setLocation(const QGeoLocation &src); - - QDeclarativeGeoAddress *address() const; - void setAddress(QDeclarativeGeoAddress *address); - QGeoCoordinate coordinate() const; - void setCoordinate(const QGeoCoordinate coordinate); - - QGeoRectangle boundingBox() const; - void setBoundingBox(const QGeoRectangle &boundingBox); - -Q_SIGNALS: - void addressChanged(); - void coordinateChanged(); - void boundingBoxChanged(); - -private: - QDeclarativeGeoAddress *m_address; - QGeoRectangle m_boundingBox; - QGeoCoordinate m_coordinate; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeGeoLocation) - -#endif // QDECLARATIVELOCATION_P_H diff --git a/src/imports/location/qdeclarativegeomaneuver_p.h b/src/imports/location/qdeclarativegeomaneuver_p.h index e03f9b81..f81124fa 100644 --- a/src/imports/location/qdeclarativegeomaneuver_p.h +++ b/src/imports/location/qdeclarativegeomaneuver_p.h @@ -44,7 +44,7 @@ #include -#include "qdeclarativecoordinate_p.h" +#include #include diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index 2283e22a..2b860eb3 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -45,7 +45,6 @@ #include "qdeclarativecirclemapitem_p.h" #include "qdeclarativegeomapquickitem_p.h" -#include "qdeclarativecoordinate_p.h" #include "qdeclarativegeoserviceprovider_p.h" #include #include diff --git a/src/imports/location/qdeclarativegeomapgesturearea.cpp b/src/imports/location/qdeclarativegeomapgesturearea.cpp index 22eeba07..e75b41f1 100644 --- a/src/imports/location/qdeclarativegeomapgesturearea.cpp +++ b/src/imports/location/qdeclarativegeomapgesturearea.cpp @@ -41,7 +41,6 @@ #include "qdeclarativegeomapgesturearea_p.h" #include "qdeclarativegeomap_p.h" -#include "qdeclarativecoordinate_p.h" #include "error_messages.h" #include diff --git a/src/imports/location/qdeclarativegeomapitembase_p.h b/src/imports/location/qdeclarativegeomapitembase_p.h index 2cb482d4..78424124 100644 --- a/src/imports/location/qdeclarativegeomapitembase_p.h +++ b/src/imports/location/qdeclarativegeomapitembase_p.h @@ -45,7 +45,6 @@ #include #include "qdeclarativegeomap_p.h" -#include "qdeclarativecoordinate_p.h" QT_BEGIN_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomapmousearea_p.h b/src/imports/location/qdeclarativegeomapmousearea_p.h index 7a23ea2f..3c89ef0b 100644 --- a/src/imports/location/qdeclarativegeomapmousearea_p.h +++ b/src/imports/location/qdeclarativegeomapmousearea_p.h @@ -42,7 +42,6 @@ #ifndef QDECLARATIVEGEOMAPMOUSEAREA_H #define QDECLARATIVEGEOMAPMOUSEAREA_H -#include "qdeclarativecoordinate_p.h" #include "qdeclarativegeomap_p.h" #include "qdeclarativegeomapmouseevent_p.h" diff --git a/src/imports/location/qdeclarativegeomapmouseevent_p.h b/src/imports/location/qdeclarativegeomapmouseevent_p.h index 0529419f..34341d07 100644 --- a/src/imports/location/qdeclarativegeomapmouseevent_p.h +++ b/src/imports/location/qdeclarativegeomapmouseevent_p.h @@ -42,7 +42,7 @@ #ifndef QDECLARATIVEGEOMAPMOUSEEVENT_H #define QDECLARATIVEGEOMAPMOUSEEVENT_H -#include "qdeclarativecoordinate_p.h" +#include #include diff --git a/src/imports/location/qdeclarativegeomapquickitem.cpp b/src/imports/location/qdeclarativegeomapquickitem.cpp index 8a9b0c6e..3db74289 100644 --- a/src/imports/location/qdeclarativegeomapquickitem.cpp +++ b/src/imports/location/qdeclarativegeomapquickitem.cpp @@ -41,7 +41,6 @@ #include "qdeclarativegeomapquickitem_p.h" #include "qdeclarativegeomapmousearea_p.h" -#include "qdeclarativecoordinate_p.h" #include #include diff --git a/src/imports/location/qdeclarativegeomapquickitem_p.h b/src/imports/location/qdeclarativegeomapquickitem_p.h index c67dd170..1ed658d9 100644 --- a/src/imports/location/qdeclarativegeomapquickitem_p.h +++ b/src/imports/location/qdeclarativegeomapquickitem_p.h @@ -46,7 +46,6 @@ #include #include "qdeclarativegeomap_p.h" -#include "qdeclarativecoordinate_p.h" #include "qdeclarativegeomapitembase_p.h" QT_BEGIN_NAMESPACE diff --git a/src/imports/location/qdeclarativegeorectangle.cpp b/src/imports/location/qdeclarativegeorectangle.cpp deleted file mode 100644 index 8dc0dd6a..00000000 --- a/src/imports/location/qdeclarativegeorectangle.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#include "qdeclarativegeorectangle.h" - -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmlbasictype georectangle - \inqmlmodule QtLocation 5.0 - \ingroup qml-QtLocation5-positioning - \since Qt Location 5.0 - - \brief The georectangle type represents a rectangular geographic area. - - The \c georectangle type is a \l {geoshape} that represents a - rectangular geographic area. It is defined by a pair of - \l {coordinate}{coordinates} which represent the top-left and bottom-right corners - of the \c {georectangle}. The coordinates are accessible from the \c topLeft and - \c bottomRight attributes. - - A \c georectangle is considered invalid if the top-left or bottom-right coordinates are invalid - or if the top-left coordinate is South of the bottom-right coordinate. - - The coordinates of the four corners of the \c georectangle can be accessed with the - \c {topLeft}, \c {topRight}, \c {bottomLeft} and \c {bottomRight} attributes. The \c center - attribute can be used to get the coordinate of the center of the \c georectangle. The \c width - and \c height attributes can be used to get the width and height of the \c georectangle in - degrees. Setting one of these attributes will cause the other attributes to be adjusted - accordingly. - - \section2 Limitations - - A \c georectangle can never cross the poles. - - If the height or center of a \c georectangle is adjusted such that it would cross one of the - poles the height is modified such that the \c georectangle touches but does not cross the pole - and that the center coordinate is still in the center of the \c georectangle. - - \section2 Example Usage - - Use properties of type \l variant to store a \c {georectangle}. To create a \c georectangle - value, use the \l {QtLocation::rectangle}{QtLocation.rectangle()} function: - - \qml - import QtLocation 5.0 - - Item { - property variant region: QtLocation.rectangle(QtLocation.coordinate(-27.5, 153.1), QtLocation.coordinate(-27.6, 153.2)) - } - \endqml - - When integrating with C++, note that any QGeoRectangle value passed into QML from C++ is - automatically converted into a \c georectangle value, and vice-versa. -*/ - -GeoRectangleValueType::GeoRectangleValueType(QObject *parent) -: GeoShapeValueType(qMetaTypeId(), parent) -{ -} - -GeoRectangleValueType::~GeoRectangleValueType() -{ -} - -QGeoCoordinate GeoRectangleValueType::bottomLeft() -{ - return QGeoRectangle(v).bottomLeft(); -} - -/* - This property holds the bottom left coordinate of this georectangle. -*/ -void GeoRectangleValueType::setBottomLeft(const QGeoCoordinate &coordinate) -{ - QGeoRectangle r = v; - - if (r.bottomLeft() == coordinate) - return; - - r.setBottomLeft(coordinate); - v = r; -} - -QGeoCoordinate GeoRectangleValueType::bottomRight() -{ - return QGeoRectangle(v).bottomRight(); -} - -/* - This property holds the bottom right coordinate of this georectangle. -*/ -void GeoRectangleValueType::setBottomRight(const QGeoCoordinate &coordinate) -{ - QGeoRectangle r = v; - - if (r.bottomRight() == coordinate) - return; - - r.setBottomRight(coordinate); - v = r; -} - -QGeoCoordinate GeoRectangleValueType::topLeft() -{ - return QGeoRectangle(v).topLeft(); -} - -/* - This property holds the top left coordinate of this georectangle. -*/ -void GeoRectangleValueType::setTopLeft(const QGeoCoordinate &coordinate) -{ - QGeoRectangle r = v; - - if (r.topLeft() == coordinate) - return; - - r.setTopLeft(coordinate); - v = r; -} - -QGeoCoordinate GeoRectangleValueType::topRight() -{ - return QGeoRectangle(v).topRight(); -} - -/* - This property holds the top right coordinate of this georectangle. -*/ -void GeoRectangleValueType::setTopRight(QGeoCoordinate &coordinate) -{ - QGeoRectangle r = v; - - if (r.topRight() == coordinate) - return; - - r.setTopRight(coordinate); - v = r; -} - -QGeoCoordinate GeoRectangleValueType::center() -{ - return QGeoRectangle(v).center(); -} - -/* - This property holds the center coordinate of this georectangle. -*/ -void GeoRectangleValueType::setCenter(const QGeoCoordinate &coordinate) -{ - QGeoRectangle r = v; - - if (r.center() == coordinate) - return; - - r.setCenter(coordinate); - v = r; -} - -double GeoRectangleValueType::height() -{ - return QGeoRectangle(v).height(); -} - -/* - This property holds the height of this georectangle (in degrees). -*/ -void GeoRectangleValueType::setHeight(double height) -{ - QGeoRectangle r = v; - - if (!r.isValid()) - r.setCenter(QGeoCoordinate(0.0, 0.0)); - - r.setHeight(height); - v = r; -} - -double GeoRectangleValueType::width() -{ - return QGeoRectangle(v).width(); -} - -/* - This property holds the width of this georectangle (in degrees). -*/ -void GeoRectangleValueType::setWidth(double width) -{ - QGeoRectangle r = v; - - if (!r.isValid()) - r.setCenter(QGeoCoordinate(0.0, 0.0)); - - r.setWidth(width); - v = r; -} - -QString GeoRectangleValueType::toString() const -{ - if (v.type() != QGeoShape::RectangleType) { - qWarning("Not a rectangle a %d\n", v.type()); - return QStringLiteral("QGeoRectangle(not a rectangle)"); - } - - QGeoRectangle r = v; - return QStringLiteral("QGeoRectangle({%1, %2}, {%3, %4})") - .arg(r.topLeft().latitude()) - .arg(r.topLeft().longitude()) - .arg(r.bottomRight().latitude()) - .arg(r.bottomRight().longitude()); -} - -void GeoRectangleValueType::setValue(const QVariant &value) -{ - if (value.userType() == qMetaTypeId()) - v = value.value(); - else if (value.userType() == qMetaTypeId()) - v = value.value(); - else - v = QGeoRectangle(); - - onLoad(); -} - -QVariant GeoRectangleValueType::value() -{ - return QVariant::fromValue(QGeoRectangle(v)); -} - -void GeoRectangleValueType::write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) -{ - QGeoRectangle r = v; - writeProperty(obj, idx, flags, &r); -} - -void GeoRectangleValueType::writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags, QVariant *from) -{ - if (from->userType() == qMetaTypeId()) { - writeProperty(obj, idx, flags, from); - } else if (from->userType() == qMetaTypeId()) { - QGeoRectangle r = from->value(); - QVariant v = QVariant::fromValue(r); - writeProperty(obj, idx, flags, &v); - } else { - QVariant v = QVariant::fromValue(QGeoRectangle()); - writeProperty(obj, idx, flags, &v); - } -} - -#include "moc_qdeclarativegeorectangle.cpp" - -QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeorectangle.h b/src/imports/location/qdeclarativegeorectangle.h deleted file mode 100644 index 98c93d79..00000000 --- a/src/imports/location/qdeclarativegeorectangle.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#ifndef QDECLARATIVEGEORECTANGLE_H -#define QDECLARATIVEGEORECTANGLE_H - -#include "qdeclarativegeoshape.h" - -QT_BEGIN_NAMESPACE - -class GeoRectangleValueType : public GeoShapeValueType -{ - Q_OBJECT - - Q_PROPERTY(QGeoCoordinate bottomLeft READ bottomLeft WRITE setBottomLeft) - Q_PROPERTY(QGeoCoordinate bottomRight READ bottomRight WRITE setBottomRight) - Q_PROPERTY(QGeoCoordinate topLeft READ topLeft WRITE setTopLeft) - Q_PROPERTY(QGeoCoordinate topRight READ topRight WRITE setTopRight) - Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter) - Q_PROPERTY(double height READ height WRITE setHeight) - Q_PROPERTY(double width READ width WRITE setWidth) - -public: - explicit GeoRectangleValueType(QObject *parent = 0); - ~GeoRectangleValueType(); - - QGeoCoordinate bottomLeft(); - void setBottomLeft(const QGeoCoordinate &coordinate); - QGeoCoordinate bottomRight(); - void setBottomRight(const QGeoCoordinate &coordinate); - QGeoCoordinate topLeft(); - void setTopLeft(const QGeoCoordinate &coordinate); - QGeoCoordinate topRight(); - void setTopRight(QGeoCoordinate &coordinate); - QGeoCoordinate center(); - void setCenter(const QGeoCoordinate &coordinate); - double height(); - void setHeight(double height); - double width(); - void setWidth(double width); - - QString toString() const Q_DECL_OVERRIDE; - void setValue(const QVariant &value) Q_DECL_OVERRIDE; - QVariant value() Q_DECL_OVERRIDE; - void write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) Q_DECL_OVERRIDE; - void writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags, QVariant *from) Q_DECL_OVERRIDE; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/imports/location/qdeclarativegeoroute.cpp b/src/imports/location/qdeclarativegeoroute.cpp index 87c49e1f..3430a2b9 100644 --- a/src/imports/location/qdeclarativegeoroute.cpp +++ b/src/imports/location/qdeclarativegeoroute.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qdeclarativegeoroute_p.h" -#include "locationvaluetypeprovider.h" +#include "locationvaluetypehelper_p.h" #include #include @@ -48,7 +48,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -114,7 +114,7 @@ QList QDeclarativeGeoRoute::routePath() } /*! - \qmlproperty GeoRectangle QtLocation5::Route::bounds + \qmlproperty georectangle QtLocation5::Route::bounds Read-only property which holds a bounding box which encompasses the entire route. @@ -160,7 +160,7 @@ qreal QDeclarativeGeoRoute::distance() const indicates the number of objects and 'path[index starting from zero]' gives the actual object. - \sa QtLocation::coordinate + \sa QtPositioning::coordinate */ QJSValue QDeclarativeGeoRoute::path() const diff --git a/src/imports/location/qdeclarativegeoroute_p.h b/src/imports/location/qdeclarativegeoroute_p.h index 8ea0e078..d9b9e718 100644 --- a/src/imports/location/qdeclarativegeoroute_p.h +++ b/src/imports/location/qdeclarativegeoroute_p.h @@ -45,6 +45,7 @@ #include "qdeclarativegeoroutesegment_p.h" #include +#include #include #include diff --git a/src/imports/location/qdeclarativegeoroutemodel.cpp b/src/imports/location/qdeclarativegeoroutemodel.cpp index 8afac048..9ace5174 100644 --- a/src/imports/location/qdeclarativegeoroutemodel.cpp +++ b/src/imports/location/qdeclarativegeoroutemodel.cpp @@ -42,7 +42,7 @@ #include "qdeclarativegeoroutemodel_p.h" #include "qdeclarativegeoroute_p.h" #include "error_messages.h" -#include "locationvaluetypeprovider.h" +#include "locationvaluetypehelper_p.h" #include #include @@ -52,7 +52,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -777,7 +777,7 @@ void QDeclarativeGeoRouteQuery::setWaypoints(const QJSValue &value) } /*! - \qmlproperty QQmlListProperty RouteQuery::excludedAreas + \qmlproperty list RouteQuery::excludedAreas Areas that the route must not cross. @@ -835,7 +835,7 @@ void QDeclarativeGeoRouteQuery::setExcludedAreas(const QJSValue &value) } /*! - \qmlmethod QtLocation5::RouteQuery::addExcludedArea(GeoRectangle) + \qmlmethod QtLocation5::RouteQuery::addExcludedArea(georectangle) Adds the given area to excluded areas (areas that the route must not cross). Same area can only be added once. @@ -865,7 +865,7 @@ void QDeclarativeGeoRouteQuery::addExcludedArea(const QGeoRectangle &area) } /*! - \qmlmethod QtLocation5::RouteQuery::removeExcludedArea(GeoRectangle) + \qmlmethod QtLocation5::RouteQuery::removeExcludedArea(georectangle) Removes the given area to excluded areas (areas that the route must not cross). @@ -1086,10 +1086,9 @@ void QDeclarativeGeoRouteQuery::setTravelModes(QDeclarativeGeoRouteQuery::Travel /*! - \qmlproperty SegmentDetail RouteQuery::segmentDetail + \qmlproperty enumeration RouteQuery::segmentDetail The level of detail which will be used in the representation of routing segments. - Values can be combined with OR ('|') -operator. \list \li RouteQuery.NoSegmentData - No segment data should be included with the route @@ -1116,10 +1115,9 @@ QDeclarativeGeoRouteQuery::SegmentDetail QDeclarativeGeoRouteQuery::segmentDetai } /*! - \qmlproperty ManeuverDetail RouteQuery::maneuverDetail + \qmlproperty enumeration RouteQuery::maneuverDetail The level of detail which will be used in the representation of routing maneuvers. - Values can be combined with OR ('|') -operator. \list \li RouteQuery.NoManeuvers - No maneuvers should be included with the route @@ -1182,7 +1180,7 @@ QDeclarativeGeoRouteQuery::TravelModes QDeclarativeGeoRouteQuery::travelModes() } /*! - \qmlproperty RouteOptimizations RouteQuery::routeOptimizations + \qmlproperty enumeration RouteQuery::routeOptimizations The route optimizations which should be considered during the planning of the route. Values can be combined with OR ('|') -operator. diff --git a/src/imports/location/qdeclarativegeoroutemodel_p.h b/src/imports/location/qdeclarativegeoroutemodel_p.h index bf3984d5..0d663eed 100644 --- a/src/imports/location/qdeclarativegeoroutemodel_p.h +++ b/src/imports/location/qdeclarativegeoroutemodel_p.h @@ -44,8 +44,8 @@ #include "qdeclarativegeoserviceprovider_p.h" -#include "qdeclarativecoordinate_p.h" -#include "qdeclarativegeorectangle.h" +#include +#include #include #include diff --git a/src/imports/location/qdeclarativegeoroutesegment.cpp b/src/imports/location/qdeclarativegeoroutesegment.cpp index 8199f9ec..3dbe06f8 100644 --- a/src/imports/location/qdeclarativegeoroutesegment.cpp +++ b/src/imports/location/qdeclarativegeoroutesegment.cpp @@ -146,7 +146,7 @@ QDeclarativeGeoManeuver *QDeclarativeGeoRouteSegment::maneuver() const indicates the number of objects and 'path[index starting from zero]' gives the actual object. - \sa QtLocation::coordinate + \sa QtPositioning::coordinate */ QJSValue QDeclarativeGeoRouteSegment::path() const diff --git a/src/imports/location/qdeclarativegeoshape.cpp b/src/imports/location/qdeclarativegeoshape.cpp deleted file mode 100644 index e08f8edc..00000000 --- a/src/imports/location/qdeclarativegeoshape.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativegeoshape.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmlbasictype geoshape - \inqmlmodule QtLocation 5.0 - \ingroup qml-QtLocation5-basictypes - \since Qt Location 5.0 - - \brief A geoshape type represents an abstract geographic area. - - The \c geoshape type represents an abstract geographic area. It includes attributes and - methods common to all geographic areas. To create objects that represent a valid geographic - area use \l {georectangle}{georectangle} or - \l {geocircle}{geocircle}. - - The \c isValid attribute can be used to test if the geoshape represents a valid geographic - area. - - The \c isEmpty attribute can be used to test if the geoshape represents a region with a - geomatrical area of 0. - - The \l contains() method can be used to test if a \l {QtLocation::coordinate}{coordinate} is - within the geoshape. - - \section2 Example Usage - - Use properties of type \l variant to store a \c {geoshape}. To create a \c geoshape use one - of the methods described below. - - To create a \c geoshape value, specify it as a "shape()" string: - - \qml - import QtLocation - - Item { - property variant region: "shape()" - } - \endqml - - or with the \l {QtLocation::QtLocation}{QtLocation.shape()} function: - - \qml - import QtLocation 5.0 - - Item { - property variant region: QtLocation.shape() - } - \endqml - - When integrating with C++, note that any QGeoShape value passed into QML from C++ is - automatically converted into a \c geoshape value, and vice-versa. - - \section2 Methods - - \section3 contains() - - \code - bool contains(coordinate coord) - \endcode - - Returns true if the \l {QtLocation::coordinate}{coordinate} specified by \a coord is within - this geoshape; Otherwise returns false. -*/ - -GeoShapeValueType::GeoShapeValueType(QObject *parent) -: QQmlValueTypeBase(qMetaTypeId(), parent) -{ -} - -GeoShapeValueType::~GeoShapeValueType() -{ -} - -GeoShapeValueType::ShapeType GeoShapeValueType::type() const -{ - return static_cast(v.type()); -} - -bool GeoShapeValueType::isValid() const -{ - return v.isValid(); -} - -bool GeoShapeValueType::isEmpty() const -{ - return v.isEmpty(); -} - -bool GeoShapeValueType::contains(const QGeoCoordinate &coordinate) const -{ - return v.contains(coordinate); -} - -QString GeoShapeValueType::toString() const -{ - switch (v.type()) { - case QGeoShape::UnknownType: - return QStringLiteral("QGeoShape()"); - case QGeoShape::RectangleType: { - QGeoRectangle r = v; - return QStringLiteral("QGeoRectangle({%1, %2}, {%3, %4})") - .arg(r.topLeft().latitude()) - .arg(r.topLeft().longitude()) - .arg(r.bottomRight().latitude()) - .arg(r.bottomRight().longitude()); - } - case QGeoShape::CircleType: { - QGeoCircle c = v; - return QStringLiteral("QGeoCircle({%1, %2}, %3)") - .arg(c.center().latitude()) - .arg(c.center().longitude()) - .arg(c.radius()); - } - } - - return QStringLiteral("QGeoShape(%1)").arg(v.type()); -} - -void GeoShapeValueType::setValue(const QVariant &value) -{ - if (value.userType() == qMetaTypeId()) - v = value.value(); - else if (value.userType() == qMetaTypeId()) - v = value.value(); - else if (value.userType() == qMetaTypeId()) - v = value.value(); - else - v = QGeoShape(); - - onLoad(); -} - -bool GeoShapeValueType::isEqual(const QVariant &other) const -{ - if (other.userType() == qMetaTypeId()) - return v == other.value(); - else if (other.userType() == qMetaTypeId()) - return v == other.value(); - else if (other.userType() == qMetaTypeId()) - return v == other.value(); - else - return false; -} - -GeoShapeValueType::GeoShapeValueType(int userType, QObject *parent) -: QQmlValueTypeBase(userType, parent) -{ - QMetaType::construct(userType, &v, 0); -} - -QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeoshape.h b/src/imports/location/qdeclarativegeoshape.h deleted file mode 100644 index 9f0c16db..00000000 --- a/src/imports/location/qdeclarativegeoshape.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#ifndef QDECLARATIVEGEOSHAPE_H -#define QDECLARATIVEGEOSHAPE_H - -#include -#include - -QT_BEGIN_NAMESPACE - -class GeoShapeValueType : public QQmlValueTypeBase -{ - Q_OBJECT - - Q_PROPERTY(ShapeType type READ type) - Q_PROPERTY(bool isValid READ isValid) - Q_PROPERTY(bool isEmpty READ isEmpty) - - Q_ENUMS(ShapeType) - -public: - explicit GeoShapeValueType(QObject *parent = 0); - ~GeoShapeValueType(); - - enum ShapeType { - UnknownType = QGeoShape::UnknownType, - RectangleType = QGeoShape::RectangleType, - CircleType = QGeoShape::CircleType - }; - - ShapeType type() const; - bool isValid() const; - bool isEmpty() const; - - Q_INVOKABLE bool contains(const QGeoCoordinate &coordinate) const; - - QString toString() const Q_DECL_OVERRIDE; - void setValue(const QVariant &value) Q_DECL_OVERRIDE; - bool isEqual(const QVariant &other) const Q_DECL_OVERRIDE; - -protected: - explicit GeoShapeValueType(int userType, QObject *parent = 0); -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/imports/location/qdeclarativepolygonmapitem.cpp b/src/imports/location/qdeclarativepolygonmapitem.cpp index 6eedb2c7..c10fe03a 100644 --- a/src/imports/location/qdeclarativepolygonmapitem.cpp +++ b/src/imports/location/qdeclarativepolygonmapitem.cpp @@ -43,7 +43,7 @@ #include "qgeocameracapabilities_p.h" #include "qlocationutils_p.h" #include "error_messages.h" -#include "locationvaluetypeprovider.h" +#include "locationvaluetypehelper_p.h" #include #include @@ -71,10 +71,10 @@ QT_BEGIN_NAMESPACE \brief The MapPolygon type displays a polygon on a Map The MapPolygon type displays a polygon on a Map, specified in terms of an ordered list of - \l {QtLocation::coordinate}{coordinates}. For best appearance and results, polygons should be + \l {QtPositioning::coordinate}{coordinates}. For best appearance and results, polygons should be simple (not self-intersecting). - The \l {QtLocation::coordinate}{coordinates} on the path cannot be directly changed after + The \l {QtPositioning::coordinate}{coordinates} on the path cannot be directly changed after being added to the Polygon. Instead, copy the \l path into a var, modify the copy and reassign the copy back to the \l path. @@ -344,10 +344,13 @@ QDeclarativePolygonMapItem::~QDeclarativePolygonMapItem() } /*! + \qmlpropertygroup Location::MapPolygon::border \qmlproperty int MapPolygon::border.width \qmlproperty color MapPolygon::border.color - These properties hold the width and color used to draw the border of the circle. + This property is part of the border property group. The border property + group holds the width and color used to draw the border of the circle. + The width is in pixels and is independent of the zoom level of the map. The default values correspond to a black border with a width of 1 pixel. diff --git a/src/imports/location/qdeclarativepolylinemapitem.cpp b/src/imports/location/qdeclarativepolylinemapitem.cpp index abdf9d53..144f55ec 100644 --- a/src/imports/location/qdeclarativepolylinemapitem.cpp +++ b/src/imports/location/qdeclarativepolylinemapitem.cpp @@ -43,7 +43,7 @@ #include "qgeocameracapabilities_p.h" #include "qlocationutils_p.h" #include "error_messages.h" -#include "locationvaluetypeprovider.h" +#include "locationvaluetypehelper_p.h" #include #include @@ -590,10 +590,12 @@ void QDeclarativePolylineMapItem::removeCoordinate(const QGeoCoordinate &coordin } /*! + \qmlpropertygroup Location::MapPolyline::line \qmlproperty int MapPolyline::line.width \qmlproperty color MapPolyline::line.color - These properties hold the width and color used to draw the line. + This property is part of the line property group. The line + property group holds the width and color used to draw the line. The width is in pixels and is independent of the zoom level of the map. The default values correspond to a black border with a width of 1 pixel. diff --git a/src/imports/location/qdeclarativeposition.cpp b/src/imports/location/qdeclarativeposition.cpp deleted file mode 100644 index bbd53423..00000000 --- a/src/imports/location/qdeclarativeposition.cpp +++ /dev/null @@ -1,376 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativeposition_p.h" -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmltype Position - \instantiates QDeclarativePosition - \inqmlmodule QtLocation 5.0 - \ingroup qml-QtLocation5-positioning - \since Qt Location 5.0 - - \brief The Position type holds positional data at a particular point in time, - such as coordinate (longitude, latitude, altitude) and speed. - - The Position type holds values related to geographic location such as - a \l coordinate (longitude, latitude, and altitude), the \l timestamp when - the Position was obtained, the \l speed at that time, and the accuracy of - the data. - - Primarily, it is used in the \l{PositionSource::position}{position} property - of a \l{PositionSource}, as the basic unit of data available from the system - location data source. - - Not all properties of a Position object are necessarily valid or available - (for example latitude and longitude may be valid, but speed update has not been - received or set manually). As a result, corresponding "valid" properties - are available (for example \l{coordinate} and \l{longitudeValid}, \l{latitudeValid} - etc) to discern whether the data is available and valid in this position - update. - - Position objects are read-only and can only be produced by a PositionSource. - - \section2 Example Usage - - See the example given for the \l{PositionSource} type, or the - \l{declarative/flickr}{Flickr} example application. - - \sa PositionSource, coordinate - -*/ - -QDeclarativePosition::QDeclarativePosition(QObject *parent) - : QObject(parent), m_latitudeValid(false), m_longitudeValid(false), - m_altitudeValid(false), m_speed(-1), m_speedValid(false), m_horizontalAccuracyValid(false), - m_verticalAccuracyValid(false), m_horizontalAccuracy(-1), m_verticalAccuracy(-1) -{ -} - -QDeclarativePosition::~QDeclarativePosition() -{ -} - -/*! - \qmlproperty coordinate Position::coordinate - - This property holds the latitude, longitude, and altitude value of the Position. - - It is a read-only property. - - \sa longitudeValid, latitudeValid, altitudeValid -*/ - -void QDeclarativePosition::setCoordinate(const QGeoCoordinate &coordinate) -{ - if (m_coordinate == coordinate) - return; - - m_coordinate = coordinate; - - if (coordinate.type() == QGeoCoordinate::Coordinate3D && !m_altitudeValid) { - m_altitudeValid = true; - emit altitudeValidChanged(); - } else if (m_altitudeValid) { - m_altitudeValid = false; - emit altitudeValidChanged(); - } - if (coordinate.isValid()) { - if (!m_longitudeValid) { - m_longitudeValid = true; - emit longitudeValidChanged(); - } - if (!m_latitudeValid) { - m_latitudeValid = true; - emit latitudeValidChanged(); - } - } else { - if (m_longitudeValid) { - m_longitudeValid = false; - emit longitudeValidChanged(); - } - if (m_latitudeValid) { - m_latitudeValid = false; - emit latitudeValidChanged(); - } - } - emit coordinateChanged(); -} - -QGeoCoordinate QDeclarativePosition::coordinate() -{ - return m_coordinate; -} - -/*! - \qmlproperty bool Position::latitudeValid - - This property is true if coordinate's latitude has been set - (to indicate whether that data has been received or not, as every update - does not necessarily contain all data). - - \sa coordinate - -*/ - -bool QDeclarativePosition::isLatitudeValid() const -{ - return m_latitudeValid; -} - - -/*! - \qmlproperty bool Position::longitudeValid - - This property is true if coordinate's longitude has been set - (to indicate whether that data has been received or not, as every update - does not necessarily contain all data). - - \sa coordinate - -*/ - -bool QDeclarativePosition::isLongitudeValid() const -{ - return m_longitudeValid; -} - - -/*! - \qmlproperty bool Position::speedValid - - This property is true if \l speed has been set - (to indicate whether that data has been received or not, as every update - does not necessarily contain all data). - - \sa speed - -*/ - -bool QDeclarativePosition::isSpeedValid() const -{ - return m_speedValid; -} - -/*! - \qmlproperty bool Position::altitudeValid - - This property is true if coordinate's altitude has been set - (to indicate whether that data has been received or not, as every update - does not necessarily contain all data). - - \sa coordinate - -*/ - -bool QDeclarativePosition::isAltitudeValid() const -{ - return m_altitudeValid; -} - -/*! - \qmlproperty double Position::speed - - This property holds the value of speed (groundspeed, meters / second). - - It is a read-only property. - - \sa speedValid, coordinate -*/ - -void QDeclarativePosition::setSpeed(double speed) -{ - if (speed == m_speed) - return; - m_speed = speed; - if (!m_speedValid) { - m_speedValid = true; - emit speedValidChanged(); - } - emit speedChanged(); -} - -double QDeclarativePosition::speed() const -{ - return m_speed; -} - -/*! - \qmlproperty real Position::horizontalAccuracy - - This property holds the horizontal accuracy of the coordinate (in meters). - - \sa horizontalAccuracyValid, coordinate -*/ - -void QDeclarativePosition::setHorizontalAccuracy(qreal horizontalAccuracy) -{ - if (horizontalAccuracy == m_horizontalAccuracy) - return; - m_horizontalAccuracy = horizontalAccuracy; - if (!m_horizontalAccuracyValid) { - m_horizontalAccuracyValid = true; - emit horizontalAccuracyValidChanged(); - } - emit horizontalAccuracyChanged(); -} - -qreal QDeclarativePosition::horizontalAccuracy() const -{ - return m_horizontalAccuracy; -} - -/*! - \qmlproperty bool Position::horizontalAccuracyValid - - This property is true if \l horizontalAccuracy has been set - (to indicate whether that data has been received or not, as every update - does not necessarily contain all data). - - \sa horizontalAccuracy - -*/ - -bool QDeclarativePosition::isHorizontalAccuracyValid() const -{ - return m_horizontalAccuracyValid; -} - -/*! - \qmlproperty real Position::verticalAccuracy - - This property holds the vertical accuracy of the coordinate (in meters). - - \sa verticalAccuracyValid, coordinate -*/ - -void QDeclarativePosition::setVerticalAccuracy(qreal verticalAccuracy) -{ - if (verticalAccuracy == m_verticalAccuracy) - return; - m_verticalAccuracy = verticalAccuracy; - if (!m_verticalAccuracyValid) { - m_verticalAccuracyValid = true; - emit verticalAccuracyValidChanged(); - } - emit verticalAccuracyChanged(); -} - -qreal QDeclarativePosition::verticalAccuracy() const -{ - return m_verticalAccuracy; -} - -/*! - \qmlproperty bool Position::verticalAccuracyValid - - This property is true if \l verticalAccuracy has been set - (to indicate whether that data has been received or not, as every update - does not necessarily contain all data). - - \sa verticalAccuracy - -*/ - -bool QDeclarativePosition::isVerticalAccuracyValid() const -{ - return m_verticalAccuracyValid; -} - -/*! - \qmlproperty date Position::timestamp - - This property holds the timestamp when this position - was received. If the property has not been set, it is invalid. - - It is a read-only property. -*/ - -void QDeclarativePosition::setTimestamp(const QDateTime ×tamp) -{ - if (timestamp == m_timestamp) - return; - m_timestamp = timestamp; - emit timestampChanged(); -} - -QDateTime QDeclarativePosition::timestamp() const -{ - return m_timestamp; -} - -void QDeclarativePosition::invalidate() -{ - // Invalidate all data - if (m_latitudeValid) { - m_latitudeValid = false; - emit latitudeValidChanged(); - } - if (m_longitudeValid) { - m_longitudeValid = false; - emit longitudeValidChanged(); - } - if (m_altitudeValid) { - m_altitudeValid = false; - emit altitudeValidChanged(); - } - if (m_speedValid) { - m_speedValid = false; - emit speedValidChanged(); - } - if (m_horizontalAccuracyValid) { - m_horizontalAccuracyValid = false; - emit horizontalAccuracyValidChanged(); - } - if (m_verticalAccuracyValid) { - m_verticalAccuracyValid = false; - emit verticalAccuracyValidChanged(); - } -} - -#include "moc_qdeclarativeposition_p.cpp" - -QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativeposition_p.h b/src/imports/location/qdeclarativeposition_p.h deleted file mode 100644 index bf424176..00000000 --- a/src/imports/location/qdeclarativeposition_p.h +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#ifndef QDECLARATIVEPOSITION_H -#define QDECLARATIVEPOSITION_H - -#include -#include -#include -#include -#include "qdeclarativecoordinate_p.h" -#include - -// Define this to get qDebug messages -// #define QDECLARATIVE_POSITION_DEBUG - -#ifdef QDECLARATIVE_POSITION_DEBUG -#include -#endif - -QT_BEGIN_NAMESPACE - -class QDeclarativePosition : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool latitudeValid READ isLatitudeValid NOTIFY latitudeValidChanged) - Q_PROPERTY(bool longitudeValid READ isLongitudeValid NOTIFY longitudeValidChanged) - Q_PROPERTY(bool altitudeValid READ isAltitudeValid NOTIFY altitudeValidChanged) - Q_PROPERTY(QGeoCoordinate coordinate READ coordinate NOTIFY coordinateChanged) - Q_PROPERTY(QDateTime timestamp READ timestamp NOTIFY timestampChanged) - Q_PROPERTY(double speed READ speed NOTIFY speedChanged) - Q_PROPERTY(bool speedValid READ isSpeedValid NOTIFY speedValidChanged) - Q_PROPERTY(qreal horizontalAccuracy READ horizontalAccuracy WRITE setHorizontalAccuracy NOTIFY horizontalAccuracyChanged) - Q_PROPERTY(qreal verticalAccuracy READ verticalAccuracy WRITE setVerticalAccuracy NOTIFY verticalAccuracyChanged) - Q_PROPERTY(bool horizontalAccuracyValid READ isHorizontalAccuracyValid NOTIFY horizontalAccuracyValidChanged) - Q_PROPERTY(bool verticalAccuracyValid READ isVerticalAccuracyValid NOTIFY verticalAccuracyValidChanged) - -public: - - explicit QDeclarativePosition(QObject *parent = 0); - ~QDeclarativePosition(); - - bool isLatitudeValid() const; - bool isLongitudeValid() const; - bool isAltitudeValid() const; - QDateTime timestamp() const; - void setTimestamp(const QDateTime ×tamp); - double speed() const; - void setSpeed(double speed); - bool isSpeedValid() const; - QGeoCoordinate coordinate(); - bool isHorizontalAccuracyValid() const; - qreal horizontalAccuracy() const; - void setHorizontalAccuracy(qreal horizontalAccuracy); - bool isVerticalAccuracyValid() const; - qreal verticalAccuracy() const; - void setVerticalAccuracy(qreal verticalAccuracy); - - // C++ - void setCoordinate(const QGeoCoordinate &coordinate); - void invalidate(); - -Q_SIGNALS: - void latitudeValidChanged(); - void longitudeValidChanged(); - void altitudeValidChanged(); - void timestampChanged(); - void speedChanged(); - void speedValidChanged(); - void coordinateChanged(); - void horizontalAccuracyChanged(); - void horizontalAccuracyValidChanged(); - void verticalAccuracyChanged(); - void verticalAccuracyValidChanged(); - -private: - bool m_latitudeValid; - bool m_longitudeValid; - bool m_altitudeValid; - QDateTime m_timestamp; - double m_speed; - bool m_speedValid; - bool m_horizontalAccuracyValid; - bool m_verticalAccuracyValid; - qreal m_horizontalAccuracy; - qreal m_verticalAccuracy; - QGeoCoordinate m_coordinate; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativePosition) - -#endif diff --git a/src/imports/location/qdeclarativepositionsource.cpp b/src/imports/location/qdeclarativepositionsource.cpp deleted file mode 100644 index d4605a42..00000000 --- a/src/imports/location/qdeclarativepositionsource.cpp +++ /dev/null @@ -1,647 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativepositionsource_p.h" -#include "qdeclarativeposition_p.h" -#include "error_messages.h" - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmltype PositionSource - \instantiates QDeclarativePositionSource - \inqmlmodule QtLocation 5.0 - \ingroup qml-QtLocation5-positioning - \since Qt Location 5.0 - - \brief The PositionSource type provides the device's current position. - - The PositionSource type provides information about the user device's - current position. The position is available as a \l{Position} type, which - contains all the standard parameters typically available from GPS and other - similar systems, including longitude, latitude, speed and accuracy details. - - As different position sources are available on different platforms and - devices, these are categorized by their basic type (Satellite, NonSatellite, - and AllPositioningMethods). The available methods for the current platform - can be enumerated in the \l{supportedPositioningMethods} property. - - To indicate which methods are suitable for your application, set the - \l{preferredPositioningMethods} property. If the preferred methods are not - available, the default source of location data for the platform will be - chosen instead. If no default source is available (because none are installed - for the runtime platform, or because it is disabled), the \l{valid} property - will be set to false. - - The \l updateInterval property can then be used to indicate how often your - application wishes to receive position updates. The \l{start}(), - \l{stop}() and \l{update}() methods can be used to control the operation - of the PositionSource, as well as the \l{active} property, which when set - is equivalent to calling \l{start}() or \l{stop}(). - - When the PositionSource is active, position updates can be retrieved - either by simply using the \l{position} property in a binding (as the - value of another item's property), or by providing an implementation of - the \c {onPositionChanged} signal-handler. - - \section2 Example Usage - - The following example shows a simple PositionSource used to receive - updates every second and print the longitude and latitude out to - the console. - - \code - PositionSource { - id: src - updateInterval: 1000 - active: true - - onPositionChanged: { - var coord = src.position.coordinate; - console.log("Coordinate:", coord.longitude, coord.latitude); - } - } - \endcode - - The \l{declarative/flickr}{Flickr} example application shows how to use - a PositionSource in your application to retrieve local data for users - from a REST web service. - - \sa {QtLocation5::Position}, {QGeoPositionInfoSource} - -*/ - -QDeclarativePositionSource::QDeclarativePositionSource() -: m_positionSource(0), m_preferredPositioningMethods(NoPositioningMethod), m_nmeaFile(0), - m_active(false), m_singleUpdate(false), m_updateInterval(0), m_sourceError(UnknownSourceError) -{ -} - -QDeclarativePositionSource::~QDeclarativePositionSource() -{ - delete m_nmeaFile; - delete m_positionSource; -} - - -/*! - \qmlproperty string PositionSource::name - - This property holds the unique internal name for the plugin currently - providing position information. - - Setting the property causes the PositionSource to use a particular positioning provider. If - the PositionSource is active at the time that the name property is changed, it will become - inactive. If the specified positioning provider cannot be loaded the position source will - become invalid. - - Changing the name property may cause the \l {updateInterval}, \l {supportedPositioningMethods} - and \l {preferredPositioningMethods} properties to change as well. -*/ - - -QString QDeclarativePositionSource::name() const -{ - if (m_positionSource) - return m_positionSource->sourceName(); - else - return QString(); -} - -void QDeclarativePositionSource::setName(const QString &newName) -{ - if (m_positionSource && m_positionSource->sourceName() == newName) - return; - - const QString previousName = name(); - int previousUpdateInterval = updateInterval(); - PositioningMethods previousPositioningMethods = supportedPositioningMethods(); - PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods(); - - delete m_positionSource; - if (newName.isEmpty()) - m_positionSource = QGeoPositionInfoSource::createDefaultSource(this); - else - m_positionSource = QGeoPositionInfoSource::createSource(newName, this); - - if (m_positionSource) { - connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), - this, SLOT(positionUpdateReceived(QGeoPositionInfo))); - connect(m_positionSource, SIGNAL(error(QGeoPositionInfoSource::Error)), - this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error))); - - m_positionSource->setUpdateInterval(m_updateInterval); - m_positionSource->setPreferredPositioningMethods( - static_cast(int(m_preferredPositioningMethods))); - } - - if (previousUpdateInterval != updateInterval()) - emit updateIntervalChanged(); - - if (previousPreferredPositioningMethods != preferredPositioningMethods()) - emit preferredPositioningMethodsChanged(); - - if (previousPositioningMethods != supportedPositioningMethods()) - emit supportedPositioningMethodsChanged(); - - emit validityChanged(); - - if (m_active) { - m_active = false; - emit activeChanged(); - } - - if (previousName != name()) - emit nameChanged(); -} - -/*! - \qmlproperty bool PositionSource::valid - - This property is true if the PositionSource object has acquired a valid - backend plugin to provide data. If false, other methods on the PositionSource - will have no effect. - - Applications should check this property to determine whether positioning is - available and enabled on the runtime platform, and react accordingly. -*/ -bool QDeclarativePositionSource::isValid() const -{ - return (m_positionSource != 0); -} - -/*! - \internal -*/ -void QDeclarativePositionSource::setNmeaSource(const QUrl &nmeaSource) -{ - // Strip the filename. This is clumsy but the file may be prefixed in several - // ways: "file:///", "qrc:///", "/", "" in platform dependant manner. - QString localFileName = nmeaSource.toString(); - if (!QFile::exists(localFileName)) { - if (localFileName.startsWith("qrc:///")) { - localFileName.remove(0, 7); - } else if (localFileName.startsWith("file:///")) { - localFileName.remove(0, 7); - } - if (!QFile::exists(localFileName) && localFileName.startsWith("/")) { - localFileName.remove(0,1); - } - } - if (m_nmeaFileName == localFileName) - return; - m_nmeaFileName = localFileName; - m_nmeaSource = nmeaSource; - - PositioningMethods previousPositioningMethods = supportedPositioningMethods(); - - // The current position source needs to be deleted - // because QNmeaPositionInfoSource can be bound only to a one file. - delete m_positionSource; - m_positionSource = 0; - // Create the NMEA source based on the given data. QML has automatically set QUrl - // type to point to correct path. If the file is not found, check if the file actually - // was an embedded resource file. - delete m_nmeaFile; - m_nmeaFile = new QFile(localFileName); - if (!m_nmeaFile->exists()) { - localFileName.prepend(":"); - m_nmeaFile->setFileName(localFileName); - } - if (m_nmeaFile->exists()) { -#ifdef QDECLARATIVE_POSITION_DEBUG - qDebug() << "QDeclarativePositionSource NMEA File was found: " << localFileName; -#endif - m_positionSource = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode); - (qobject_cast(m_positionSource))->setDevice(m_nmeaFile); - connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), - this, SLOT(positionUpdateReceived(QGeoPositionInfo))); - if (m_active && !m_singleUpdate) { - // Keep on updating even though source changed - QTimer::singleShot(0, this, SLOT(start())); - } - } else { - qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, MISSED_NMEA_FILE) << localFileName; -#ifdef QDECLARATIVE_POSITION_DEBUG - qDebug() << "QDeclarativePositionSource NMEA File was not found: " << localFileName; -#endif - if (m_active) { - m_active = false; - m_singleUpdate = false; - emit activeChanged(); - } - } - - if (previousPositioningMethods != supportedPositioningMethods()) - emit supportedPositioningMethodsChanged(); - - emit nmeaSourceChanged(); -} - -/*! - \internal -*/ -void QDeclarativePositionSource::setUpdateInterval(int updateInterval) -{ - if (m_positionSource) { - int previousUpdateInterval = m_positionSource->updateInterval(); - - m_updateInterval = updateInterval; - - if (previousUpdateInterval != updateInterval) { - m_positionSource->setUpdateInterval(updateInterval); - if (previousUpdateInterval != m_positionSource->updateInterval()) - emit updateIntervalChanged(); - } - } else { - if (m_updateInterval != updateInterval) { - m_updateInterval = updateInterval; - emit updateIntervalChanged(); - } - } -} - -/*! - \qmlproperty url PositionSource::nmeaSource - - This property holds the source for NMEA (National Marine Electronics Association) - position-specification data (file). One purpose of this property is to be of - development convenience. - - Setting this property will override any other position source. Currently only - files local to the .qml -file are supported. The NMEA source is created in simulation mode, - meaning that the data and time information in the NMEA source data is used to provide - positional updates at the rate at which the data was originally recorded. - - If nmeaSource has been set for a PositionSource object, there is no way to revert - back to non-file sources. -*/ - -QUrl QDeclarativePositionSource::nmeaSource() const -{ - return m_nmeaSource; -} - -/*! - \qmlproperty int PositionSource::updateInterval - - This property holds the desired interval between updates (milliseconds). - - \sa {QGeoPositionInfoSource::updateInterval()} -*/ - -int QDeclarativePositionSource::updateInterval() const -{ - if (!m_positionSource) - return m_updateInterval; - - return m_positionSource->updateInterval(); -} - -/*! - \qmlproperty enumeration PositionSource::supportedPositioningMethods - - This property holds the supported positioning methods of the - current source. - - \list - \li PositionSource.NoPositioningMethod - No positioning methods supported (no source). - \li PositionSource.SatellitePositioningMethod - Satellite-based positioning methods such as GPS are supported. - \li PositionSource.NonSatellitePositioningMethod - Non-satellite-based methods are supported. - \li PositionSource.AllPositioningMethods - Both satellite-based and non-satellite positioning methods are supported. - \endlist - -*/ - -QDeclarativePositionSource::PositioningMethods QDeclarativePositionSource::supportedPositioningMethods() const -{ - if (m_positionSource) { - QGeoPositionInfoSource::PositioningMethods methods = m_positionSource->supportedPositioningMethods(); - if ( (methods & QGeoPositionInfoSource::AllPositioningMethods) == methods ) { - return QDeclarativePositionSource::AllPositioningMethods; - } else if (methods & QGeoPositionInfoSource::SatellitePositioningMethods) { - return QDeclarativePositionSource::SatellitePositioningMethod; - } else if (methods & QGeoPositionInfoSource::NonSatellitePositioningMethods) { - return QDeclarativePositionSource::NonSatellitePositioningMethod; - } - } - return QDeclarativePositionSource::NoPositioningMethod; -} - -/*! - \qmlproperty enumeration PositionSource::preferredPositioningMethods - - This property holds the preferred positioning methods of the - current source. - - \list - \li PositionSource.SatellitePositioningMethod - Satellite-based positioning methods such as GPS should be preferred. - \li PositionSource.NonSatellitePositioningMethod - Non-satellite-based methods should be preferred. - \li PositionSource.AllPositioningMethods - Any positioning methods are acceptable. - \endlist - -*/ - -void QDeclarativePositionSource::setPreferredPositioningMethods(PositioningMethods methods) -{ - if (m_positionSource) { - PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods(); - - m_preferredPositioningMethods = methods; - - if (previousPreferredPositioningMethods != methods) { - m_positionSource->setPreferredPositioningMethods( - static_cast(int(methods))); - if (previousPreferredPositioningMethods != m_positionSource->preferredPositioningMethods()) - emit preferredPositioningMethodsChanged(); - } - } else { - if (m_preferredPositioningMethods != methods) { - m_preferredPositioningMethods = methods; - emit preferredPositioningMethodsChanged(); - } - } -} - -QDeclarativePositionSource::PositioningMethods QDeclarativePositionSource::preferredPositioningMethods() const -{ - if (m_positionSource) { - QGeoPositionInfoSource::PositioningMethods methods = - m_positionSource->preferredPositioningMethods(); - if ( (methods & QGeoPositionInfoSource::AllPositioningMethods) == methods) { - return QDeclarativePositionSource::AllPositioningMethods; - } else if (methods & QGeoPositionInfoSource::SatellitePositioningMethods) { - return QDeclarativePositionSource::SatellitePositioningMethod; - } else if (methods & QGeoPositionInfoSource::NonSatellitePositioningMethods) { - return QDeclarativePositionSource::NonSatellitePositioningMethod; - } - } - return m_preferredPositioningMethods; -} - -/*! - \qmlmethod PositionSource::start() - - Requests updates from the location source. - Uses \l updateInterval if set, default interval otherwise. - If there is no source available, this method has no effect. - - \sa stop, update, active -*/ - -void QDeclarativePositionSource::start() -{ - if (!m_positionSource) - return; - - m_positionSource->startUpdates(); - if (!m_active) { - m_active = true; - emit activeChanged(); - } -} - -/*! - \qmlmethod PositionSource::update() - - A convenience method to request single update from the location source. - If there is no source available, this method has no effect. - - If the position source is not active, it will be activated for as - long as it takes to receive an update, or until the request times - out. The request timeout period is source-specific. - - \sa start, stop, active -*/ - -void QDeclarativePositionSource::update() -{ - if (m_positionSource) { - if (!m_active) { - m_active = true; - m_singleUpdate = true; - emit activeChanged(); - } - // Use default timeout value. Set active before calling the - // update request because on some platforms there may - // be results immediately. - m_positionSource->requestUpdate(); - } -} - -/*! - \qmlmethod PositionSource::stop() - - Stops updates from the location source. - If there is no source available or it is not active, - this method has no effect. - - \sa start, update, active -*/ - -void QDeclarativePositionSource::stop() -{ - if (m_positionSource) { - m_positionSource->stopUpdates(); - if (m_active) { - m_active = false; - emit activeChanged(); - } - } -} - -/*! - \qmlproperty bool PositionSource::active - - This property indicates whether the position source is active. - Setting this property to false equals calling \l stop, and - setting this property true equals calling \l start. - - \sa start, stop, update -*/ -void QDeclarativePositionSource::setActive(bool active) -{ - if (active == m_active) - return; - - if (active) - QTimer::singleShot(0, this, SLOT(start())); // delay ensures all properties have been set - else - stop(); -} - -bool QDeclarativePositionSource::isActive() const -{ - return m_active; -} - -/*! - \qmlproperty Position PositionSource::position - - This property holds the last known positional data. - It is a read-only property. - - The Position type has different positional member variables, - whose validity can be checked with appropriate validity functions - (for example sometimes an update does not have speed or altitude data). - - However, whenever a \c {positionChanged} signal has been received, at least - position::coordinate::latitude, position::coordinate::longitude, and position::timestamp can - be assumed to be valid. - - \sa start, stop, update -*/ - -QDeclarativePosition *QDeclarativePositionSource::position() -{ - return &m_position; -} - -void QDeclarativePositionSource::positionUpdateReceived(const QGeoPositionInfo &update) -{ - if (update.isValid()) { - m_position.setTimestamp(update.timestamp()); - m_position.setCoordinate(update.coordinate()); - if (update.hasAttribute(QGeoPositionInfo::GroundSpeed)) { - m_position.setSpeed(update.attribute(QGeoPositionInfo::GroundSpeed)); - } - if (update.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) { - m_position.setHorizontalAccuracy(update.attribute(QGeoPositionInfo::HorizontalAccuracy)); - } - if (update.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) { - m_position.setVerticalAccuracy(update.attribute(QGeoPositionInfo::VerticalAccuracy)); - } - emit positionChanged(); - } else { - m_position.invalidate(); - } - if (m_singleUpdate && m_active) { - m_active = false; - m_singleUpdate = false; - emit activeChanged(); - } -} - - -/*! - \qmlproperty enumeration PositionSource::sourceError - - This property holds the error which last occured with the PositionSource. - - \list - \li PositionSource.AccessError - The connection setup to the remote positioning backend failed because the - application lacked the required privileges. - \li PositionSource.ClosedError - The remote positioning backend closed the connection, which happens for example in case - the user is switching location services to off. This object becomes invalid and should be deleted. - A new source can be declared later on to check whether the positioning backend is up again. - \li PositionSource.UnknownSourceError - An unidentified error occurred. - \endlist - -*/ - -QDeclarativePositionSource::SourceError QDeclarativePositionSource::sourceError() const -{ - return m_sourceError; -} - -void QDeclarativePositionSource::componentComplete() -{ - if (!m_positionSource) { - int previousUpdateInterval = updateInterval(); - PositioningMethods previousPositioningMethods = supportedPositioningMethods(); - PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods(); - - m_positionSource = QGeoPositionInfoSource::createDefaultSource(this); - if (m_positionSource) { - connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), - this, SLOT(positionUpdateReceived(QGeoPositionInfo))); - connect(m_positionSource, SIGNAL(error(QGeoPositionInfoSource::Error)), - this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error))); - - m_positionSource->setUpdateInterval(m_updateInterval); - m_positionSource->setPreferredPositioningMethods( - static_cast(int(m_preferredPositioningMethods))); - } - - if (previousUpdateInterval != updateInterval()) - emit updateIntervalChanged(); - - if (previousPreferredPositioningMethods != preferredPositioningMethods()) - emit preferredPositioningMethodsChanged(); - - if (previousPositioningMethods != supportedPositioningMethods()) - emit supportedPositioningMethodsChanged(); - - emit validityChanged(); - - if (m_active) { - m_active = false; - emit activeChanged(); - } - - emit nameChanged(); - } -} - -/*! - \internal -*/ -void QDeclarativePositionSource::sourceErrorReceived(const QGeoPositionInfoSource::Error error) -{ - if (error == QGeoPositionInfoSource::AccessError) { - m_sourceError = QDeclarativePositionSource::AccessError; - } else if (error == QGeoPositionInfoSource::ClosedError) { - m_sourceError = QDeclarativePositionSource::ClosedError; - } else { - m_sourceError = QDeclarativePositionSource::UnknownSourceError; - } - emit sourceErrorChanged(); -} - -#include "moc_qdeclarativepositionsource_p.cpp" - -QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativepositionsource_p.h b/src/imports/location/qdeclarativepositionsource_p.h deleted file mode 100644 index dea18b62..00000000 --- a/src/imports/location/qdeclarativepositionsource_p.h +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#ifndef QDECLARATIVEPOSITIONSOURCE_H -#define QDECLARATIVEPOSITIONSOURCE_H - -#include "qdeclarativeposition_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QFile; - -class QDeclarativePositionSource : public QObject, public QQmlParserStatus -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativePosition *position READ position NOTIFY positionChanged) - Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) - Q_PROPERTY(bool valid READ isValid NOTIFY validityChanged) - Q_PROPERTY(QUrl nmeaSource READ nmeaSource WRITE setNmeaSource NOTIFY nmeaSourceChanged) - Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval NOTIFY updateIntervalChanged) - Q_PROPERTY(PositioningMethods supportedPositioningMethods READ supportedPositioningMethods NOTIFY supportedPositioningMethodsChanged) - Q_PROPERTY(PositioningMethods preferredPositioningMethods READ preferredPositioningMethods WRITE setPreferredPositioningMethods NOTIFY preferredPositioningMethodsChanged) - Q_PROPERTY(SourceError sourceError READ sourceError NOTIFY sourceErrorChanged) - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_ENUMS(PositioningMethod) - - Q_INTERFACES(QQmlParserStatus) - -public: - enum PositioningMethod { - NoPositioningMethod = 0, - SatellitePositioningMethod = QGeoPositionInfoSource::SatellitePositioningMethods, - NonSatellitePositioningMethod = QGeoPositionInfoSource::NonSatellitePositioningMethods, - AllPositioningMethods = QGeoPositionInfoSource::AllPositioningMethods - }; - - Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod) - Q_FLAGS(PositioningMethods) - - enum SourceError { - AccessError = QGeoPositionInfoSource::AccessError, - ClosedError = QGeoPositionInfoSource::ClosedError, - UnknownSourceError = QGeoPositionInfoSource::UnknownSourceError - }; - Q_ENUMS(SourceError) - - QDeclarativePositionSource(); - ~QDeclarativePositionSource(); - void setNmeaSource(const QUrl &nmeaSource); - void setUpdateInterval(int updateInterval); - void setActive(bool active); - void setPreferredPositioningMethods(PositioningMethods methods); - - QString name() const; - void setName(const QString &name); - - QUrl nmeaSource() const; - int updateInterval() const; - bool isActive() const; - bool isValid() const; - QDeclarativePosition *position(); - PositioningMethods supportedPositioningMethods() const; - PositioningMethods preferredPositioningMethods() const; - SourceError sourceError() const; - - // Virtuals from QQmlParserStatus - void classBegin() { } - void componentComplete(); - -public Q_SLOTS: - void update(); - void start(); - void stop(); - -Q_SIGNALS: - void positionChanged(); - void activeChanged(); - void nmeaSourceChanged(); - void updateIntervalChanged(); - void supportedPositioningMethodsChanged(); - void preferredPositioningMethodsChanged(); - void sourceErrorChanged(); - void nameChanged(); - void validityChanged(); - - -private Q_SLOTS: - void positionUpdateReceived(const QGeoPositionInfo &update); - void sourceErrorReceived(const QGeoPositionInfoSource::Error error); -private: - QGeoPositionInfoSource *m_positionSource; - QDeclarativePosition m_position; - PositioningMethods m_preferredPositioningMethods; - QFile *m_nmeaFile; - QString m_nmeaFileName; - QUrl m_nmeaSource; - bool m_active; - bool m_singleUpdate; - int m_updateInterval; - SourceError m_sourceError; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativePositionSource) - -#endif diff --git a/src/imports/location/qdeclarativerectanglemapitem.cpp b/src/imports/location/qdeclarativerectanglemapitem.cpp index ffb0a2c3..8573ec51 100644 --- a/src/imports/location/qdeclarativerectanglemapitem.cpp +++ b/src/imports/location/qdeclarativerectanglemapitem.cpp @@ -205,10 +205,12 @@ void QDeclarativeRectangleMapItem::setMap(QDeclarativeGeoMap *quickMap, QGeoMap } /*! + \qmlpropertygroup Location::MapRectangle::border \qmlproperty int MapRectangle::border.width \qmlproperty color MapRectangle::border.color - These properties hold the width and color used to draw the border of the rectangle. + This property is part of the border property group. The border property group + holds the width and color used to draw the border of the rectangle. The width is in pixels and is independent of the zoom level of the map. The default values correspond to a black border with a width of 1 pixel. diff --git a/src/imports/location/qdeclarativeroutemapitem.cpp b/src/imports/location/qdeclarativeroutemapitem.cpp index 264ee835..1af8e120 100644 --- a/src/imports/location/qdeclarativeroutemapitem.cpp +++ b/src/imports/location/qdeclarativeroutemapitem.cpp @@ -173,10 +173,12 @@ QSGNode *QDeclarativeRouteMapItem::updateMapItemPaintNode(QSGNode *oldNode, Upda } /*! + \qmlpropertygroup Location::MapRoute::line \qmlproperty int MapRoute::line.width \qmlproperty color MapRoute::line.color - These properties hold the width and color used to draw the line. + This property is part of the line property group. + The line property group holds the width and color used to draw the line. The width is in pixels and is independent of the zoom level of the map. The default values correspond to a black border with a width of 1 pixel. diff --git a/src/imports/location/qdeclarativeroutemapitem_p.h b/src/imports/location/qdeclarativeroutemapitem_p.h index 099b333f..479a621d 100644 --- a/src/imports/location/qdeclarativeroutemapitem_p.h +++ b/src/imports/location/qdeclarativeroutemapitem_p.h @@ -43,7 +43,6 @@ #define QDECLARATIVEROUTEMAPITEM_H_ #include "qdeclarativegeomapitembase_p.h" -#include "qdeclarativecoordinate_p.h" #include "qdeclarativegeomap_p.h" #include "qdeclarativepolylinemapitem_p.h" #include diff --git a/src/imports/positioning/error_messages.cpp b/src/imports/positioning/error_messages.cpp new file mode 100644 index 00000000..45b85e0a --- /dev/null +++ b/src/imports/positioning/error_messages.cpp @@ -0,0 +1,48 @@ +/*************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "error_messages.h" + +QT_BEGIN_NAMESPACE + +const char CONTEXT_NAME[] = "QtPositioningQML"; +const char MISSED_NMEA_FILE[] = QT_TRANSLATE_NOOP("QtPositioningQML", "Nmea file not found."); + +QT_END_NAMESPACE diff --git a/src/imports/positioning/error_messages.h b/src/imports/positioning/error_messages.h new file mode 100644 index 00000000..3c888dff --- /dev/null +++ b/src/imports/positioning/error_messages.h @@ -0,0 +1,54 @@ + +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef ERROR_MESSAGES_H +#define ERROR_MESSAGES_H + +#include + +QT_BEGIN_NAMESPACE + +extern const char CONTEXT_NAME[]; +extern const char MISSED_NMEA_FILE[]; + +QT_END_NAMESPACE + +#endif // ERROR_MESSAGES_H diff --git a/src/imports/positioning/locationsingleton.cpp b/src/imports/positioning/locationsingleton.cpp new file mode 100644 index 00000000..c44db946 --- /dev/null +++ b/src/imports/positioning/locationsingleton.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "locationsingleton.h" + +/*! + \qmltype QtPositioning + \instantiates LocationSingleton + \inqmlmodule QtPositioning 5.0 + + \brief The QtPositioning global object provides useful functions for working with location-based + types in QML. + + \qml + import QtPositioning 5.0 + + Item { + property variant coordinate: QtPositioning.coordinate(-27.5, 153.1) + } + \endqml +*/ + +LocationSingleton::LocationSingleton(QObject *parent) +: QObject(parent) +{ +} + +/*! + \qmlmethod coordinate ::QtPositioning::coordinate() + + Constructs an invalid coordinate. + +*/ +QGeoCoordinate LocationSingleton::coordinate() const +{ + return QGeoCoordinate(); +} + +/*! + \qmlmethod coordinate QtPositioning::coordinate(real latitude, real longitue, real altitude) const + + Constructs a coordinate with the specified \a latitude, \a longitude and optional \a altitude. + Both \a latitude and \a longitude must be valid, otherwise an invalid coordinate is returned. + + \sa {coordinate} +*/ +QGeoCoordinate LocationSingleton::coordinate(double latitude, double longitude, double altitude) const +{ + return QGeoCoordinate(latitude, longitude, altitude); +} + +/*! + \qmlmethod geoshape QtPositioning::shape() const + + Constructs an invalid geoshape. + + \sa {geoshape} +*/ +QGeoShape LocationSingleton::shape() const +{ + return QGeoShape(); +} + +/*! + \qmlmethod georectangle QtPositioning::rectangle() const + + Constructs an invalid georectangle. + + \sa {georectangle} +*/ +QGeoRectangle LocationSingleton::rectangle() const +{ + return QGeoRectangle(); +} + +/*! + \qmlmethod georectangle QtPositioning::rectangle(coordinate center, real width, real height) const + + Constructs a georectangle centered at \a center with a width of \a width degrees and a hight of + \a height degrees. + + \sa {georectangle} +*/ +QGeoRectangle LocationSingleton::rectangle(const QGeoCoordinate ¢er, + double width, double height) const +{ + return QGeoRectangle(center, width, height); +} + +/*! + \qmlmethod georectangle QtPositioning::rectangle(coordinate topLeft, coordinate bottomRight) const + + Constructs a georectangle with its top left corner positioned at \a topLeft and its bottom + right corner positioned at \a {bottomLeft}. + + \sa {georectangle} +*/ +QGeoRectangle LocationSingleton::rectangle(const QGeoCoordinate &topLeft, + const QGeoCoordinate &bottomRight) const +{ + return QGeoRectangle(topLeft, bottomRight); +} + +/*! + \qmlmethod geocircle QtPositioning::circle() const + + Constructs an invalid geocircle. + + \sa {geocircle} +*/ +QGeoCircle LocationSingleton::circle() const +{ + return QGeoCircle(); +} + +/*! + \qmlmethod geocircle QtPositioning::circle(coordinate center, real radius) const + + Constructs a geocircle centered at \a center with a radius of \a radius meters. +*/ +QGeoCircle LocationSingleton::circle(const QGeoCoordinate ¢er, qreal radius) const +{ + return QGeoCircle(center, radius); +} + diff --git a/src/imports/positioning/locationsingleton.h b/src/imports/positioning/locationsingleton.h new file mode 100644 index 00000000..b5e6476e --- /dev/null +++ b/src/imports/positioning/locationsingleton.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LOCATIONSINGLETON_H +#define LOCATIONSINGLETON_H + +#include +#include +#include +#include +#include +#include + +class LocationSingleton : public QObject +{ + Q_OBJECT + +public: + explicit LocationSingleton(QObject *parent = 0); + + Q_INVOKABLE QGeoCoordinate coordinate() const; + Q_INVOKABLE QGeoCoordinate coordinate(double latitude, double longitude, + double altitude = qQNaN()) const; + + Q_INVOKABLE QGeoShape shape() const; + + Q_INVOKABLE QGeoRectangle rectangle() const; + Q_INVOKABLE QGeoRectangle rectangle(const QGeoCoordinate ¢er, + double width, double height) const; + Q_INVOKABLE QGeoRectangle rectangle(const QGeoCoordinate &topLeft, + const QGeoCoordinate &bottomRight) const; + + Q_INVOKABLE QGeoCircle circle() const; + Q_INVOKABLE QGeoCircle circle(const QGeoCoordinate ¢er, qreal radius = -1.0) const; +}; + +#endif // LOCATIONSINGLETON_H diff --git a/src/imports/positioning/locationvaluetypeprovider.cpp b/src/imports/positioning/locationvaluetypeprovider.cpp new file mode 100644 index 00000000..9ee93dbe --- /dev/null +++ b/src/imports/positioning/locationvaluetypeprovider.cpp @@ -0,0 +1,231 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "locationvaluetypeprovider.h" +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeoshape.h" +#include "qdeclarativegeorectangle.h" +#include "qdeclarativegeocircle.h" +#include +#include + +QT_BEGIN_NAMESPACE + +LocationValueTypeProvider::LocationValueTypeProvider() +: QQmlValueTypeProvider() +{ +} + +bool LocationValueTypeProvider::create(int type, QQmlValueType *&v) +{ + if (type == qMetaTypeId()) + return typedCreate(v); + else if (type == qMetaTypeId()) + return typedCreate(v); + else if (type == qMetaTypeId()) + return typedCreate(v); + else if (type == qMetaTypeId()) + return typedCreate(v); + + return false; +} + +bool LocationValueTypeProvider::init(int type, void *data, size_t dataSize) +{ + if (type == qMetaTypeId()) + return typedInit(data, dataSize); + else if (type == qMetaTypeId()) + return typedInit(data, dataSize); + else if (type == qMetaTypeId()) + return typedInit(data, dataSize); + else if (type == qMetaTypeId()) + return typedInit(data, dataSize); + + return false; +} + +bool LocationValueTypeProvider::destroy(int type, void *data, size_t dataSize) +{ + if (type == qMetaTypeId()) + return typedDestroy(data, dataSize); + else if (type == qMetaTypeId()) + return typedDestroy(data, dataSize); + else if (type == qMetaTypeId()) + return typedDestroy(data, dataSize); + else if (type == qMetaTypeId()) + return typedDestroy(data, dataSize); + + return false; +} + +bool LocationValueTypeProvider::copy(int type, const void *src, void *dst, size_t dstSize) +{ + if (type == qMetaTypeId()) + return typedCopyConstruct(src, dst, dstSize); + else if (type == qMetaTypeId()) + return typedCopyConstruct(src, dst, dstSize); + else if (type == qMetaTypeId()) + return typedCopyConstruct(src, dst, dstSize); + else if (type == qMetaTypeId()) + return typedCopyConstruct(src, dst, dstSize); + + return false; +} + +bool LocationValueTypeProvider::create(int type, int argc, const void *argv[], QVariant *v) +{ + if (type == qMetaTypeId()) { + if (argc == 2) { + const float *a = reinterpret_cast(argv[0]); + const float *b = reinterpret_cast(argv[1]); + *v = QVariant::fromValue(QGeoCoordinate(*a, *b)); + return true; + } else if (argc == 3) { + const float *a = reinterpret_cast(argv[0]); + const float *b = reinterpret_cast(argv[1]); + const float *c = reinterpret_cast(argv[2]); + *v = QVariant::fromValue(QGeoCoordinate(*a, *b, *c)); + return true; + } + } + + return false; +} + +bool LocationValueTypeProvider::createFromString(int type, const QString &s, void *data, size_t dataSize) +{ + Q_UNUSED(data) + Q_UNUSED(dataSize) + + if (type == qMetaTypeId() || type == qMetaTypeId() || + type == qMetaTypeId() || type == qMetaTypeId()) { + qWarning("Cannot create value type %d from string '%s'", type, qPrintable(s)); + } + + return false; +} + +bool LocationValueTypeProvider::createStringFrom(int type, const void *data, QString *s) +{ + Q_UNUSED(data) + Q_UNUSED(s) + + if (type == qMetaTypeId() || type == qMetaTypeId() || + type == qMetaTypeId() || type == qMetaTypeId()) { + qWarning("Cannot create string from value type %d", type); + } + + return false; +} + +bool LocationValueTypeProvider::variantFromJsObject(int type, QQmlV4Handle h, QV8Engine *e, QVariant *v) +{ + Q_UNUSED(h) + Q_UNUSED(e) + Q_UNUSED(v) + + if (type == qMetaTypeId() || type == qMetaTypeId() || + type == qMetaTypeId() || type == qMetaTypeId()) { + qWarning("Cannot create variant from js object for type %d", type); + } + + return false; +} + +bool LocationValueTypeProvider::equal(int type, const void *lhs, const void *rhs, size_t rhsSize) +{ + Q_UNUSED(rhsSize) + + if (type == qMetaTypeId()) + return typedEqual(lhs, rhs); + else if (type == qMetaTypeId()) + return typedEqual(lhs, rhs); + else if (type == qMetaTypeId()) + return typedEqual(lhs, rhs); + else if (type == qMetaTypeId()) + return typedEqual(lhs, rhs); + + return false; +} + +bool LocationValueTypeProvider::store(int type, const void *src, void *dst, size_t dstSize) +{ + if (type == qMetaTypeId()) + return typedStore(src, dst, dstSize); + else if (type == qMetaTypeId()) + return typedStore(src, dst, dstSize); + else if (type == qMetaTypeId()) + return typedStore(src, dst, dstSize); + else if (type == qMetaTypeId()) + return typedStore(src, dst, dstSize); + + return false; +} + +bool LocationValueTypeProvider::read(int srcType, const void *src, size_t srcSize, int dstType, void *dst) +{ + if (srcType == qMetaTypeId()) + return typedRead(srcType, src, srcSize, dstType, dst); + else if (srcType == qMetaTypeId()) + return typedRead(srcType, src, srcSize, dstType, dst); + else if (srcType == qMetaTypeId()) + return typedRead(srcType, src, srcSize, dstType, dst); + else if (srcType == qMetaTypeId()) + return typedRead(srcType, src, srcSize, dstType, dst); + + return false; +} + +bool LocationValueTypeProvider::write(int type, const void *src, void *dst, size_t dstSize) +{ + if (type == qMetaTypeId()) + return typedWrite(src, dst, dstSize); + else if (type == qMetaTypeId()) + return typedWrite(src, dst, dstSize); + else if (type == qMetaTypeId()) + return typedWrite(src, dst, dstSize); + else if (type == qMetaTypeId()) + return typedWrite(src, dst, dstSize); + + return false; +} + +QT_END_NAMESPACE diff --git a/src/imports/positioning/locationvaluetypeprovider.h b/src/imports/positioning/locationvaluetypeprovider.h new file mode 100644 index 00000000..b60d2c99 --- /dev/null +++ b/src/imports/positioning/locationvaluetypeprovider.h @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LOCATIONVALUETYPEPROVIDER_H +#define LOCATIONVALUETYPEPROVIDER_H + +#include + +QT_BEGIN_NAMESPACE + +class LocationValueTypeProvider : public QQmlValueTypeProvider +{ +public: + LocationValueTypeProvider(); + +private: + template + bool typedCreate(QQmlValueType *&v) + { + v = new T; + return true; + } + + bool create(int type, QQmlValueType *&v) Q_DECL_OVERRIDE; + + template + bool typedInit(void *data, size_t dataSize) + { + Q_ASSERT(dataSize >= sizeof(T)); + Q_UNUSED(dataSize); + T *t = reinterpret_cast(data); + new (t) T(); + return true; + } + + bool init(int type, void *data, size_t dataSize) Q_DECL_OVERRIDE; + + template + bool typedDestroy(void *data, size_t dataSize) + { + Q_ASSERT(dataSize >= sizeof(T)); + Q_UNUSED(dataSize); + T *t = reinterpret_cast(data); + t->~T(); + return true; + } + + bool destroy(int type, void *data, size_t dataSize) Q_DECL_OVERRIDE; + + template + bool typedCopyConstruct(const void *src, void *dst, size_t dstSize) + { + Q_ASSERT(dstSize >= sizeof(T)); + Q_UNUSED(dstSize); + const T *srcT = reinterpret_cast(src); + T *dstT = reinterpret_cast(dst); + new (dstT) T(*srcT); + return true; + } + + bool copy(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE; + + bool create(int type, int argc, const void *argv[], QVariant *v) Q_DECL_OVERRIDE; + bool createFromString(int type, const QString &s, void *data, size_t dataSize) Q_DECL_OVERRIDE; + bool createStringFrom(int type, const void *data, QString *s) Q_DECL_OVERRIDE; + + bool variantFromJsObject(int type, QQmlV4Handle h, QV8Engine *e, QVariant *v) Q_DECL_OVERRIDE; + + template + bool typedEqual(const void *lhs, const void *rhs) + { + return *reinterpret_cast(lhs) == *reinterpret_cast(rhs); + } + + bool equal(int type, const void *lhs, const void *rhs, size_t rhsSize) Q_DECL_OVERRIDE; + + template + bool typedStore(const void *src, void *dst, size_t dstSize) + { + Q_ASSERT(dstSize >= sizeof(T)); + Q_UNUSED(dstSize); + const T *srcT = reinterpret_cast(src); + T *dstT = reinterpret_cast(dst); + new (dstT) T(*srcT); + return true; + } + + bool store(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE; + + template + bool typedRead(int srcType, const void *src, size_t srcSize, int dstType, void *dst) + { + T *dstT = reinterpret_cast(dst); + if (srcType == dstType) { + Q_ASSERT(srcSize >= sizeof(T)); + Q_UNUSED(srcSize); + const T *srcT = reinterpret_cast(src); + *dstT = *srcT; + } else { + *dstT = T(); + } + return true; + } + + bool read(int srcType, const void *src, size_t srcSize, int dstType, void *dst) Q_DECL_OVERRIDE; + + template + bool typedWrite(const void *src, void *dst, size_t dstSize) + { + Q_ASSERT(dstSize >= sizeof(T)); + Q_UNUSED(dstSize); + const T *srcT = reinterpret_cast(src); + T *dstT = reinterpret_cast(dst); + if (*dstT != *srcT) { + *dstT = *srcT; + return true; + } + return false; + } + + bool write(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif // LOCATIONVALUETYPEPROVIDER_H diff --git a/src/imports/positioning/plugin.json b/src/imports/positioning/plugin.json new file mode 100644 index 00000000..2c63c085 --- /dev/null +++ b/src/imports/positioning/plugin.json @@ -0,0 +1,2 @@ +{ +} diff --git a/src/imports/positioning/plugins.qmltypes b/src/imports/positioning/plugins.qmltypes new file mode 100644 index 00000000..3f5b1ff7 --- /dev/null +++ b/src/imports/positioning/plugins.qmltypes @@ -0,0 +1,167 @@ +import QtQuick.tooling 1.1 + +// This file describes the plugin-supplied types contained in the library. +// It is used for QML tooling purposes only. +// +// This file was auto-generated with the command 'qmlplugindump -notrelocatable QtPositioning 5.0'. + +Module { + Component { + name: "GeoShapeValueType" + prototype: "QQmlValueType" + exports: ["QtPositioning/GeoShape 5.0"] + exportMetaObjectRevisions: [0] + Enum { + name: "ShapeType" + values: { + "UnknownType": 0, + "RectangleType": 1, + "CircleType": 2 + } + } + Property { name: "type"; type: "ShapeType"; isReadonly: true } + Property { name: "isValid"; type: "bool"; isReadonly: true } + Property { name: "isEmpty"; type: "bool"; isReadonly: true } + Method { + name: "contains" + type: "bool" + Parameter { name: "coordinate"; type: "QGeoCoordinate" } + } + } + Component { + name: "LocationSingleton" + prototype: "QObject" + exports: ["QtPositioning/QtPositioning 5.0"] + exportMetaObjectRevisions: [0] + Method { name: "coordinate"; type: "QGeoCoordinate" } + Method { + name: "coordinate" + type: "QGeoCoordinate" + Parameter { name: "latitude"; type: "double" } + Parameter { name: "longitude"; type: "double" } + Parameter { name: "altitude"; type: "double" } + } + Method { + name: "coordinate" + type: "QGeoCoordinate" + Parameter { name: "latitude"; type: "double" } + Parameter { name: "longitude"; type: "double" } + } + Method { name: "shape"; type: "QGeoShape" } + Method { name: "rectangle"; type: "QGeoRectangle" } + Method { + name: "rectangle" + type: "QGeoRectangle" + Parameter { name: "center"; type: "QGeoCoordinate" } + Parameter { name: "width"; type: "double" } + Parameter { name: "height"; type: "double" } + } + Method { + name: "rectangle" + type: "QGeoRectangle" + Parameter { name: "topLeft"; type: "QGeoCoordinate" } + Parameter { name: "bottomRight"; type: "QGeoCoordinate" } + } + Method { name: "circle"; type: "QGeoCircle" } + Method { + name: "circle" + type: "QGeoCircle" + Parameter { name: "center"; type: "QGeoCoordinate" } + Parameter { name: "radius"; type: "double" } + } + Method { + name: "circle" + type: "QGeoCircle" + Parameter { name: "center"; type: "QGeoCoordinate" } + } + } + Component { + name: "QDeclarativeGeoAddress" + prototype: "QObject" + exports: ["QtPositioning/Address 5.0"] + exportMetaObjectRevisions: [0] + Property { name: "address"; type: "QGeoAddress" } + Property { name: "text"; type: "string" } + Property { name: "country"; type: "string" } + Property { name: "countryCode"; type: "string" } + Property { name: "state"; type: "string" } + Property { name: "county"; type: "string" } + Property { name: "city"; type: "string" } + Property { name: "district"; type: "string" } + Property { name: "street"; type: "string" } + Property { name: "postalCode"; type: "string" } + Property { name: "isTextGenerated"; type: "bool"; isReadonly: true } + } + Component { + name: "QDeclarativeGeoLocation" + prototype: "QObject" + exports: ["QtPositioning/Location 5.0"] + exportMetaObjectRevisions: [0] + Property { name: "location"; type: "QGeoLocation" } + Property { name: "address"; type: "QDeclarativeGeoAddress"; isPointer: true } + Property { name: "coordinate"; type: "QGeoCoordinate" } + Property { name: "boundingBox"; type: "QGeoRectangle" } + } + Component { + name: "QDeclarativePosition" + prototype: "QObject" + exports: ["QtPositioning/Position 5.0"] + exportMetaObjectRevisions: [0] + Property { name: "latitudeValid"; type: "bool"; isReadonly: true } + Property { name: "longitudeValid"; type: "bool"; isReadonly: true } + Property { name: "altitudeValid"; type: "bool"; isReadonly: true } + Property { name: "coordinate"; type: "QGeoCoordinate"; isReadonly: true } + Property { name: "timestamp"; type: "QDateTime"; isReadonly: true } + Property { name: "speed"; type: "double"; isReadonly: true } + Property { name: "speedValid"; type: "bool"; isReadonly: true } + Property { name: "horizontalAccuracy"; type: "double" } + Property { name: "verticalAccuracy"; type: "double" } + Property { name: "horizontalAccuracyValid"; type: "bool"; isReadonly: true } + Property { name: "verticalAccuracyValid"; type: "bool"; isReadonly: true } + } + Component { + name: "QDeclarativePositionSource" + prototype: "QObject" + exports: ["QtPositioning/PositionSource 5.0"] + exportMetaObjectRevisions: [0] + Enum { + name: "PositioningMethod" + values: { + "NoPositioningMethod": 0, + "SatellitePositioningMethod": 255, + "NonSatellitePositioningMethod": -256, + "AllPositioningMethods": -1 + } + } + Enum { + name: "PositioningMethods" + values: { + "NoPositioningMethod": 0, + "SatellitePositioningMethod": 255, + "NonSatellitePositioningMethod": -256, + "AllPositioningMethods": -1 + } + } + Enum { + name: "SourceError" + values: { + "AccessError": 0, + "ClosedError": 1, + "UnknownSourceError": -1 + } + } + Property { name: "position"; type: "QDeclarativePosition"; isReadonly: true; isPointer: true } + Property { name: "active"; type: "bool" } + Property { name: "valid"; type: "bool"; isReadonly: true } + Property { name: "nmeaSource"; type: "QUrl" } + Property { name: "updateInterval"; type: "int" } + Property { name: "supportedPositioningMethods"; type: "PositioningMethods"; isReadonly: true } + Property { name: "preferredPositioningMethods"; type: "PositioningMethods" } + Property { name: "sourceError"; type: "SourceError"; isReadonly: true } + Property { name: "name"; type: "string" } + Signal { name: "validityChanged" } + Method { name: "update" } + Method { name: "start" } + Method { name: "stop" } + } +} diff --git a/src/imports/positioning/positioning.cpp b/src/imports/positioning/positioning.cpp new file mode 100644 index 00000000..031b06b2 --- /dev/null +++ b/src/imports/positioning/positioning.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "locationvaluetypeprovider.h" + +#include +#include + +#include "qdeclarativepositionsource_p.h" +#include "qdeclarativeposition_p.h" + +#include "qdeclarativegeoshape.h" +#include "qdeclarativegeorectangle.h" +#include "qdeclarativegeocircle.h" +#include "qdeclarativecoordinate_p.h" + +#include "locationsingleton.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +static QObject *singleton_type_factory(QQmlEngine *engine, QJSEngine *jsEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(jsEngine) + + return new LocationSingleton; +} + +static LocationValueTypeProvider *getValueTypeProvider() +{ + static LocationValueTypeProvider provider; + return &provider; +} + +class QLocationDeclarativeModule: public QQmlExtensionPlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0" + FILE "plugin.json") + +public: + virtual void registerTypes(const char *uri) + { + if (QLatin1String(uri) == QLatin1String("QtPositioning")) { + + // @uri QtPositioning 5.0 + + qmlRegisterSingletonType(uri, 5, 0, "QtPositioning", singleton_type_factory); + + QQml_addValueTypeProvider(getValueTypeProvider()); + qmlRegisterValueTypeEnums(uri, 5, 0, "GeoShape"); + + qmlRegisterType(uri, 5, 0, "Position"); + qmlRegisterType(uri, 5, 0, "PositionSource"); + qmlRegisterType(uri, 5, 0, "Address"); + + qmlRegisterType(uri, 5, 0, "Location"); + + qRegisterMetaType("QGeoCoordinate"); + qRegisterMetaType("QGeoAddress"); + qRegisterMetaType("QGeoRectangle"); + qRegisterMetaType("QGeoCircle"); + qRegisterMetaType("QGeoLocation"); + } else { + qDebug() << "Unsupported URI given to load positioning QML plugin: " << QLatin1String(uri); + } + } +}; + +#include "positioning.moc" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/positioning.pro b/src/imports/positioning/positioning.pro new file mode 100644 index 00000000..2d396463 --- /dev/null +++ b/src/imports/positioning/positioning.pro @@ -0,0 +1,32 @@ +QT += quick-private positioning-private qml-private core-private + +INCLUDEPATH *= $$PWD +DEFINES += TOUCH_EVENT_WORKAROUND + +HEADERS += qdeclarativeposition_p.h \ + qdeclarativepositionsource_p.h \ + qdeclarativecoordinate_p.h \ + qdeclarativegeoshape.h \ + qdeclarativegeorectangle.h \ + qdeclarativegeocircle.h \ + locationvaluetypeprovider.h \ + locationsingleton.h \ + error_messages.h \ + locationvaluetypehelper_p.h + +SOURCES += qdeclarativeposition.cpp \ + positioning.cpp \ + qdeclarativepositionsource.cpp \ + qdeclarativecoordinate.cpp \ + qdeclarativegeoshape.cpp \ + qdeclarativegeorectangle.cpp \ + qdeclarativegeocircle.cpp \ + locationvaluetypeprovider.cpp \ + locationsingleton.cpp \ + error_messages.cpp + +load(qml_plugin) + +OTHER_FILES += \ + plugin.json \ + qmldir diff --git a/src/imports/positioning/qdeclarativecoordinate.cpp b/src/imports/positioning/qdeclarativecoordinate.cpp new file mode 100644 index 00000000..20dd5cef --- /dev/null +++ b/src/imports/positioning/qdeclarativecoordinate.cpp @@ -0,0 +1,320 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativecoordinate_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmlbasictype coordinate + \inqmlmodule QtPositioning 5.0 + \ingroup qml-QtPositioning5-basictypes + \since Qt Positioning 5.0 + + \brief The coordinate type represents and stores a geographic position. + + The \c coordinate type represents a geographic position in the form of \l {latitude}, + \l longitude and \l altitude attributes. The \l latitude attribute specifies the number of + decimal degrees above and below the equator. A positive latitude indicates the Northern + Hemisphere and a negative latitude indicates the Southern Hemisphere. The \l longitude + attribute specifies the number of decimal degrees east and west. A positive longitude + indicates the Eastern Hemisphere and a negative longitude indicates the Western Hemisphere. + The \l altitude attribute specifies the number of meters above sea level. Together, these + attributes specify a 3-dimensional position anywhere on or near the Earth's surface. + + The \l isValid attribute can be used to test if a coordinate is valid. A coordinate is + considered valid if it has a valid latitude and longitude. A valid altitude is not required. + The latitude must be between -90 and 90 inclusive and the longitude must be between -180 and + 180 inclusive. + + The coordinate type is used by many other types in the Qt Location module, for specifying + the position of an object on a Map, the current position of a device and many other tasks. + They also feature a number of important utility methods that make otherwise complex + calculations simple to use, such as \l atDistanceAndAzimuth(). + + \section2 Accuracy + + The latitude, longitude and altitude attributes stored in the coordinate type are represented + as doubles, giving them approximately 16 decimal digits of precision -- enough to specify + micrometers. The calculations performed in coordinate's methods such as \l azimuthTo() and + \l distanceTo() also use doubles for all intermediate values, but the inherent inaccuracies in + their spherical Earth model dominate the amount of error in their output. + + \section2 Example Usage + + Use properties of type \l variant to store a \c {coordinate}. To create a \c coordinate use + one of the methods described below. In all cases, specifying the \l altitude attribute is + optional. + + To create a \c coordinate value, use the \l{QtPositioning::coordinate}{QtPositioning.coordinate()} + function: + + \qml + import QtPositioning 5.0 + + Location { coordinate: QtPositioning.coordinate(-27.5, 153.1) } + \endqml + + or as separate \l latitude, \l longitude and \l altitude components: + + \qml + Location { + coordinate { + latitude: -27.5 + longitude: 153.1 + } + } + \endqml + + When integrating with C++, note that any QGeoCoordinate value passed into QML from C++ is + automatically converted into a \c coordinate value, and vice-versa. + + \section2 Properties + + \section3 latitude + + \code + real latitude + \endcode + + This property holds latitude value of the geographical position + (decimal degrees). A positive latitude indicates the Northern Hemisphere, + and a negative latitude indicates the Southern Hemisphere. + If the property has not been set, its default value is NaN. + + \section3 longitude + + \code + real longitude + \endcode + + This property holds the longitude value of the geographical position + (decimal degrees). A positive longitude indicates the Eastern Hemisphere, + and a negative longitude indicates the Western Hemisphere + If the property has not been set, its default value is NaN. + + \section3 altitude + + \code + real altitude + \endcode + + This property holds the value of altitude (meters above sea level). + If the property has not been set, its default value is NaN. + + \section3 isValid + + \code + bool isValid + \endcode + + This property holds the current validity of the coordinate. Coordinates + are considered valid if they have been set with a valid latitude and + longitude (altitude is not required). + + The latitude must be between -90 to 90 inclusive to be considered valid, + and the longitude must be between -180 to 180 inclusive to be considered + valid. + + This is a read-only property. + + \section2 Methods + + \section3 distanceTo() + + \code + real distanceTo(coordinate other) + \endcode + + Returns the distance (in meters) from this coordinate to the coordinate specified by \a other. + Altitude is not used in the calculation. + + This calculation returns the great-circle distance between the two coordinates, with an + assumption that the Earth is spherical for the purpose of this calculation. + + \section3 azimuthTo() + + \code + real azimuth(coordinate other) + \endcode + + Returns the azimuth (or bearing) in degrees from this coordinate to the coordinate specified by + \a other. Altitude is not used in the calculation. + + There is an assumption that the Earth is spherical for the purpose of this calculation. + + \section3 atDistanceAndAzimuth() + + \code + coordinate atDistanceAndAzimuth(real distance, real azimuth) + \endcode + + Returns the coordinate that is reached by traveling \a distance metres from this coordinate at + \a azimuth degrees along a great-circle. + + There is an assumption that the Earth is spherical for the purpose of this calculation. +*/ + + +CoordinateValueType::CoordinateValueType(QObject *parent) +: QQmlValueTypeBase(qMetaTypeId(), parent) +{ +} + +CoordinateValueType::~CoordinateValueType() +{ +} + +/* + This property holds the value of altitude (meters above sea level). + If the property has not been set, its default value is NaN. + +*/ +void CoordinateValueType::setAltitude(double altitude) +{ + v.setAltitude(altitude); +} + +double CoordinateValueType::altitude() const +{ + return v.altitude(); +} + +/* + This property holds the longitude value of the geographical position + (decimal degrees). A positive longitude indicates the Eastern Hemisphere, + and a negative longitude indicates the Western Hemisphere + If the property has not been set, its default value is NaN. +*/ +void CoordinateValueType::setLongitude(double longitude) +{ + v.setLongitude(longitude); +} + +double CoordinateValueType::longitude() const +{ + return v.longitude(); +} + +/* + This property holds latitude value of the geographical position + (decimal degrees). A positive latitude indicates the Northern Hemisphere, + and a negative latitude indicates the Southern Hemisphere. + If the property has not been set, its default value is NaN. +*/ +void CoordinateValueType::setLatitude(double latitude) +{ + v.setLatitude(latitude); +} + +double CoordinateValueType::latitude() const +{ + return v.latitude(); +} + +/* + This property holds the current validity of the coordinate. Coordinates + are considered valid if they have been set with a valid latitude and + longitude (altitude is not required). + + The latitude must be between -90 to 90 inclusive to be considered valid, + and the longitude must be between -180 to 180 inclusive to be considered + valid. +*/ +bool CoordinateValueType::isValid() const +{ + return v.isValid(); +} + +QString CoordinateValueType::toString() const +{ + return QStringLiteral("QGeoCoordinate(%1,%2,%3)") + .arg(v.latitude()).arg(v.longitude()).arg(v.altitude()); +} + +bool CoordinateValueType::isEqual(const QVariant &other) const +{ + if (other.userType() != qMetaTypeId()) + return false; + + return v == other.value(); +} + +/* + Returns the distance (in meters) from this coordinate to the + coordinate specified by other. Altitude is not used in the calculation. + + This calculation returns the great-circle distance between the two + coordinates, with an assumption that the Earth is spherical for the + purpose of this calculation. +*/ +qreal CoordinateValueType::distanceTo(const QGeoCoordinate &coordinate) const +{ + return v.distanceTo(coordinate); +} + +/* + Returns the azimuth (or bearing) in degrees from this coordinate to the + coordinate specified by other. Altitude is not used in the calculation. + + There is an assumption that the Earth is spherical for the purpose of + this calculation. +*/ +qreal CoordinateValueType::azimuthTo(const QGeoCoordinate &coordinate) const +{ + return v.azimuthTo(coordinate); +} + +/* + Returns the coordinate that is reached by traveling distance metres + from the current coordinate at azimuth degrees along a great-circle. + + There is an assumption that the Earth is spherical for the purpose + of this calculation. +*/ +QGeoCoordinate CoordinateValueType::atDistanceAndAzimuth(qreal distance, qreal azimuth) const +{ + return v.atDistanceAndAzimuth(distance, azimuth); +} + +#include "moc_qdeclarativecoordinate_p.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativecoordinate_p.h b/src/imports/positioning/qdeclarativecoordinate_p.h new file mode 100644 index 00000000..8f7a47e5 --- /dev/null +++ b/src/imports/positioning/qdeclarativecoordinate_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVECOORDINATE_H +#define QDECLARATIVECOORDINATE_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class CoordinateValueType : public QQmlValueTypeBase +{ + Q_OBJECT + + Q_PROPERTY(double latitude READ latitude WRITE setLatitude) + Q_PROPERTY(double longitude READ longitude WRITE setLongitude) + Q_PROPERTY(double altitude READ altitude WRITE setAltitude) + Q_PROPERTY(bool isValid READ isValid) + +public: + explicit CoordinateValueType(QObject *parent = 0); + ~CoordinateValueType(); + + Q_INVOKABLE qreal distanceTo(const QGeoCoordinate &coordinate) const; + Q_INVOKABLE qreal azimuthTo(const QGeoCoordinate &coordinate) const; + + Q_INVOKABLE QGeoCoordinate atDistanceAndAzimuth(qreal distance, qreal azimuth) const; + + double latitude() const; + void setLatitude(double latitude); + + double longitude() const; + void setLongitude(double longitude); + + double altitude() const; + void setAltitude(double altitude); + + bool isValid() const; + + QString toString() const Q_DECL_OVERRIDE; + bool isEqual(const QVariant &other) const Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/imports/positioning/qdeclarativegeocircle.cpp b/src/imports/positioning/qdeclarativegeocircle.cpp new file mode 100644 index 00000000..4424d2d7 --- /dev/null +++ b/src/imports/positioning/qdeclarativegeocircle.cpp @@ -0,0 +1,206 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativegeocircle.h" + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmlbasictype geocircle + \inqmlmodule QtPositioning 5.0 + \ingroup qml-QtPositioning5-basictypes + \since Qt Positioning 5.0 + + \brief The geocircle type represents a circular geographic area. + + The \c geocircle type is a \l {geoshape} that represents a circular + geographic area. It is defined in terms of a \l {coordinate} which + specifies the \l center of the circle and a qreal which specifies the \l radius of the circle + in meters. + + The circle is considered invalid if the \l center coordinate is invalid or if the \l radius is less + than zero. + + \section2 Example Usage + + Use properties of type \l variant to store a \c {geocircle}. To create a \c geocircle value, + use the \l {QtPositioning::circle}{QtPositioning.circle()} function: + + \qml + import QtPositioning 5.0 + + Item { + property variant region: QtPositioning.circle(QtPositioning.coordinate(-27.5, 153.1), 1000) + } + \endqml + + When integrating with C++, note that any QGeoCircle value passed into QML from C++ is + automatically converted into a \c geocircle value, and vise-versa. + + \section2 Properties + + \section3 center + + \code + coordinate radius + \endcode + + This property holds the coordinate of the center of the geocircle. + + \section3 radius + + \code + real radius + \endcode + + This property holds the radius of the geocircle in meters. + + The default value for the radius is -1 indicating an invalid geocircle area. +*/ + +GeoCircleValueType::GeoCircleValueType(QObject *parent) +: GeoShapeValueType(qMetaTypeId(), parent) +{ +} + +GeoCircleValueType::~GeoCircleValueType() +{ +} + +/* + This property holds the coordinate of the center of the geocircle. +*/ +QGeoCoordinate GeoCircleValueType::center() +{ + return QGeoCircle(v).center(); +} + +void GeoCircleValueType::setCenter(const QGeoCoordinate &coordinate) +{ + QGeoCircle c = v; + + if (c.center() == coordinate) + return; + + c.setCenter(coordinate); + v = c; +} + +/* + This property holds the radius of the geocircle in meters. + + The default value for the radius is -1 indicating an invalid geocircle area. +*/ +qreal GeoCircleValueType::radius() const +{ + return QGeoCircle(v).radius(); +} + +void GeoCircleValueType::setRadius(qreal radius) +{ + QGeoCircle c = v; + + if (c.radius() == radius) + return; + + c.setRadius(radius); + v = c; +} + +QString GeoCircleValueType::toString() const +{ + if (v.type() != QGeoShape::CircleType) { + qWarning("Not a circle"); + return QStringLiteral("QGeoCircle(not a circle)"); + } + + QGeoCircle c = v; + return QStringLiteral("QGeoCircle({%1, %2}, %3)") + .arg(c.center().latitude()) + .arg(c.center().longitude()) + .arg(c.radius()); +} + +void GeoCircleValueType::setValue(const QVariant &value) +{ + if (value.userType() == qMetaTypeId()) + v = value.value(); + else if (value.userType() == qMetaTypeId()) + v = value.value(); + else + v = QGeoCircle(); + + onLoad(); +} + +QVariant GeoCircleValueType::value() +{ + return QVariant::fromValue(QGeoCircle(v)); +} + +void GeoCircleValueType::write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) +{ + QGeoCircle c = v; + writeProperty(obj, idx, flags, &c); +} + +void GeoCircleValueType::writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags, QVariant *from) +{ + if (from->userType() == qMetaTypeId()) { + writeProperty(obj, idx, flags, from); + } else if (from->userType() == qMetaTypeId()) { + QGeoCircle c = from->value(); + QVariant v = QVariant::fromValue(c); + writeProperty(obj, idx, flags, &v); + } else { + QVariant v = QVariant::fromValue(QGeoCircle()); + writeProperty(obj, idx, flags, &v); + } +} + +#include "moc_qdeclarativegeocircle.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativegeocircle.h b/src/imports/positioning/qdeclarativegeocircle.h new file mode 100644 index 00000000..82948f8f --- /dev/null +++ b/src/imports/positioning/qdeclarativegeocircle.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEGEOCIRCLE_H +#define QDECLARATIVEGEOCIRCLE_H + +#include "qdeclarativegeoshape.h" + +QT_BEGIN_NAMESPACE + +class GeoCircleValueType : public GeoShapeValueType +{ + Q_OBJECT + + Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter) + Q_PROPERTY(qreal radius READ radius WRITE setRadius) + +public: + explicit GeoCircleValueType(QObject *parent = 0); + ~GeoCircleValueType(); + + QGeoCoordinate center(); + void setCenter(const QGeoCoordinate &coordinate); + + qreal radius() const; + void setRadius(qreal radius); + + QString toString() const Q_DECL_OVERRIDE; + void setValue(const QVariant &value) Q_DECL_OVERRIDE; + QVariant value() Q_DECL_OVERRIDE; + void write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) Q_DECL_OVERRIDE; + void writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags, QVariant *from) Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/imports/positioning/qdeclarativegeorectangle.cpp b/src/imports/positioning/qdeclarativegeorectangle.cpp new file mode 100644 index 00000000..f1162b77 --- /dev/null +++ b/src/imports/positioning/qdeclarativegeorectangle.cpp @@ -0,0 +1,357 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativegeorectangle.h" + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmlbasictype georectangle + \inqmlmodule QtPositioning 5.0 + \ingroup qml-QtPositioning5-basictypes + \since Qt Positioning 5.0 + + \brief The georectangle type represents a rectangular geographic area. + + The \c georectangle type is a \l {geoshape} that represents a + rectangular geographic area. It is defined by a pair of + \l {coordinate}{coordinates} which represent the top-left and bottom-right corners + of the \c {georectangle}. The coordinates are accessible from the \l topLeft and + \l bottomRight attributes. + + A \c georectangle is considered invalid if the top-left or bottom-right coordinates are invalid + or if the top-left coordinate is South of the bottom-right coordinate. + + The coordinates of the four corners of the \c georectangle can be accessed with the + \l {topLeft}, \l {topRight}, \l {bottomLeft} and \l {bottomRight} attributes. The \l center + attribute can be used to get the coordinate of the center of the \c georectangle. The \l width + and \l height attributes can be used to get the width and height of the \c georectangle in + degrees. Setting one of these attributes will cause the other attributes to be adjusted + accordingly. + + \section2 Limitations + + A \c georectangle can never cross the poles. + + If the height or center of a \c georectangle is adjusted such that it would cross one of the + poles the height is modified such that the \c georectangle touches but does not cross the pole + and that the center coordinate is still in the center of the \c georectangle. + + \section2 Example Usage + + Use properties of type \l variant to store a \c {georectangle}. To create a \c georectangle + value, use the \l {QtPositioning::rectangle}{QtPositioning.rectangle()} function: + + \qml + import QtPositioning 5.0 + + Item { + property variant region: QtPositioning.rectangle(QtPositioning.coordinate(-27.5, 153.1), QtPositioning.coordinate(-27.6, 153.2)) + } + \endqml + + When integrating with C++, note that any QGeoRectangle value passed into QML from C++ is + automatically converted into a \c georectangle value, and vice-versa. + + \section2 Properties + + \section3 bottomLeft + + \code + coordinate bottomLeft + \endcode + + This property holds the bottom left coordinate of this georectangle. + + \section3 bottomRight + + \code + coordinate bottomRight + \endcode + + This property holds the bottom right coordinate of this georectangle. + + \section3 center + + \code + coordinate center + \endcode + + This property holds the center coordinate of this georectangle. For more details + see \l {QGeoRectangle::setCenter()}. + + \section3 height + + \code + double height + \endcode + + This property holds the height of this georectangle (in degrees). For more details + see \l {QGeoRectangle::setHeight()}. + + \section3 topLeft + + \code + coordinate topLeft + \endcode + + This property holds the top left coordinate of this georectangle. + + \section3 topRight + + \code + coordinate topRight + \endcode + + This property holds the top right coordinate of this georectangle. + + \section3 width + + \code + double width + \endcode + + This property holds the width of this georectangle (in degrees). For more details + see \l {QGeoRectangle::setWidth()}. +*/ + +GeoRectangleValueType::GeoRectangleValueType(QObject *parent) +: GeoShapeValueType(qMetaTypeId(), parent) +{ +} + +GeoRectangleValueType::~GeoRectangleValueType() +{ +} + +QGeoCoordinate GeoRectangleValueType::bottomLeft() +{ + return QGeoRectangle(v).bottomLeft(); +} + +/* + This property holds the bottom left coordinate of this georectangle. +*/ +void GeoRectangleValueType::setBottomLeft(const QGeoCoordinate &coordinate) +{ + QGeoRectangle r = v; + + if (r.bottomLeft() == coordinate) + return; + + r.setBottomLeft(coordinate); + v = r; +} + +QGeoCoordinate GeoRectangleValueType::bottomRight() +{ + return QGeoRectangle(v).bottomRight(); +} + +/* + This property holds the bottom right coordinate of this georectangle. +*/ +void GeoRectangleValueType::setBottomRight(const QGeoCoordinate &coordinate) +{ + QGeoRectangle r = v; + + if (r.bottomRight() == coordinate) + return; + + r.setBottomRight(coordinate); + v = r; +} + +QGeoCoordinate GeoRectangleValueType::topLeft() +{ + return QGeoRectangle(v).topLeft(); +} + +/* + This property holds the top left coordinate of this georectangle. +*/ +void GeoRectangleValueType::setTopLeft(const QGeoCoordinate &coordinate) +{ + QGeoRectangle r = v; + + if (r.topLeft() == coordinate) + return; + + r.setTopLeft(coordinate); + v = r; +} + +QGeoCoordinate GeoRectangleValueType::topRight() +{ + return QGeoRectangle(v).topRight(); +} + +/* + This property holds the top right coordinate of this georectangle. +*/ +void GeoRectangleValueType::setTopRight(QGeoCoordinate &coordinate) +{ + QGeoRectangle r = v; + + if (r.topRight() == coordinate) + return; + + r.setTopRight(coordinate); + v = r; +} + +QGeoCoordinate GeoRectangleValueType::center() +{ + return QGeoRectangle(v).center(); +} + +/* + This property holds the center coordinate of this georectangle. +*/ +void GeoRectangleValueType::setCenter(const QGeoCoordinate &coordinate) +{ + QGeoRectangle r = v; + + if (r.center() == coordinate) + return; + + r.setCenter(coordinate); + v = r; +} + +double GeoRectangleValueType::height() +{ + return QGeoRectangle(v).height(); +} + +/* + This property holds the height of this georectangle (in degrees). +*/ +void GeoRectangleValueType::setHeight(double height) +{ + QGeoRectangle r = v; + + if (!r.isValid()) + r.setCenter(QGeoCoordinate(0.0, 0.0)); + + r.setHeight(height); + v = r; +} + +double GeoRectangleValueType::width() +{ + return QGeoRectangle(v).width(); +} + +/* + This property holds the width of this georectangle (in degrees). +*/ +void GeoRectangleValueType::setWidth(double width) +{ + QGeoRectangle r = v; + + if (!r.isValid()) + r.setCenter(QGeoCoordinate(0.0, 0.0)); + + r.setWidth(width); + v = r; +} + +QString GeoRectangleValueType::toString() const +{ + if (v.type() != QGeoShape::RectangleType) { + qWarning("Not a rectangle a %d\n", v.type()); + return QStringLiteral("QGeoRectangle(not a rectangle)"); + } + + QGeoRectangle r = v; + return QStringLiteral("QGeoRectangle({%1, %2}, {%3, %4})") + .arg(r.topLeft().latitude()) + .arg(r.topLeft().longitude()) + .arg(r.bottomRight().latitude()) + .arg(r.bottomRight().longitude()); +} + +void GeoRectangleValueType::setValue(const QVariant &value) +{ + if (value.userType() == qMetaTypeId()) + v = value.value(); + else if (value.userType() == qMetaTypeId()) + v = value.value(); + else + v = QGeoRectangle(); + + onLoad(); +} + +QVariant GeoRectangleValueType::value() +{ + return QVariant::fromValue(QGeoRectangle(v)); +} + +void GeoRectangleValueType::write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) +{ + QGeoRectangle r = v; + writeProperty(obj, idx, flags, &r); +} + +void GeoRectangleValueType::writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags, QVariant *from) +{ + if (from->userType() == qMetaTypeId()) { + writeProperty(obj, idx, flags, from); + } else if (from->userType() == qMetaTypeId()) { + QGeoRectangle r = from->value(); + QVariant v = QVariant::fromValue(r); + writeProperty(obj, idx, flags, &v); + } else { + QVariant v = QVariant::fromValue(QGeoRectangle()); + writeProperty(obj, idx, flags, &v); + } +} + +#include "moc_qdeclarativegeorectangle.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativegeorectangle.h b/src/imports/positioning/qdeclarativegeorectangle.h new file mode 100644 index 00000000..eaf63dce --- /dev/null +++ b/src/imports/positioning/qdeclarativegeorectangle.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEGEORECTANGLE_H +#define QDECLARATIVEGEORECTANGLE_H + +#include "qdeclarativegeoshape.h" + +QT_BEGIN_NAMESPACE + +class GeoRectangleValueType : public GeoShapeValueType +{ + Q_OBJECT + + Q_PROPERTY(QGeoCoordinate bottomLeft READ bottomLeft WRITE setBottomLeft) + Q_PROPERTY(QGeoCoordinate bottomRight READ bottomRight WRITE setBottomRight) + Q_PROPERTY(QGeoCoordinate topLeft READ topLeft WRITE setTopLeft) + Q_PROPERTY(QGeoCoordinate topRight READ topRight WRITE setTopRight) + Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter) + Q_PROPERTY(double height READ height WRITE setHeight) + Q_PROPERTY(double width READ width WRITE setWidth) + +public: + explicit GeoRectangleValueType(QObject *parent = 0); + ~GeoRectangleValueType(); + + QGeoCoordinate bottomLeft(); + void setBottomLeft(const QGeoCoordinate &coordinate); + QGeoCoordinate bottomRight(); + void setBottomRight(const QGeoCoordinate &coordinate); + QGeoCoordinate topLeft(); + void setTopLeft(const QGeoCoordinate &coordinate); + QGeoCoordinate topRight(); + void setTopRight(QGeoCoordinate &coordinate); + QGeoCoordinate center(); + void setCenter(const QGeoCoordinate &coordinate); + double height(); + void setHeight(double height); + double width(); + void setWidth(double width); + + QString toString() const Q_DECL_OVERRIDE; + void setValue(const QVariant &value) Q_DECL_OVERRIDE; + QVariant value() Q_DECL_OVERRIDE; + void write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) Q_DECL_OVERRIDE; + void writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags, QVariant *from) Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/imports/positioning/qdeclarativegeoshape.cpp b/src/imports/positioning/qdeclarativegeoshape.cpp new file mode 100644 index 00000000..d79f5622 --- /dev/null +++ b/src/imports/positioning/qdeclarativegeoshape.cpp @@ -0,0 +1,220 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeoshape.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmlbasictype geoshape + \inqmlmodule QtPositioning 5.0 + \ingroup qml-QtPositioning5-basictypes + \since Qt Positioning 5.0 + + \brief A geoshape type represents an abstract geographic area. + + The \c geoshape type represents an abstract geographic area. It includes attributes and + methods common to all geographic areas. To create objects that represent a valid geographic + area use \l {georectangle} or \l {geocircle}. + + The \l isValid attribute can be used to test if the geoshape represents a valid geographic + area. + + The \l isEmpty attribute can be used to test if the geoshape represents a region with a + geomatrical area of 0. + + The \l contains() method can be used to test if a \l {coordinate} is + within the geoshape. + + \section2 Example Usage + + Use properties of type \l variant to store a \c {geoshape}. To create a \c geoshape use one + of the methods described below. + + To create a \c geoshape value, specify it as a "shape()" string: + + \qml + import QtPositioning + + Item { + property variant region: "shape()" + } + \endqml + + or with the \l {QtPositioning::shape}{QtPositioning.shape()} function: + + \qml + import QtPositioning 5.0 + + Item { + property variant region: QtPositioning.shape() + } + \endqml + + When integrating with C++, note that any QGeoShape value passed into QML from C++ is + automatically converted into a \c geoshape value, and vice-versa. + + \section2 Properties + + \section3 isEmpty + + \code + bool isEmpty + \endcode + + Returns whether this geo shape is empty. An empty geo shape is a region which has + a geometrical area of 0. + + \section3 isValid + + \code + bool isValid + \endcode + + Returns whether this geo shape is valid. + + A geo shape is considered to be invalid if some of the data that is required to + unambiguously describe the geo shape has not been set or has been set to an + unsuitable value. + + + \section2 Methods + + \section3 contains() + + \code + bool contains(coordinate coord) + \endcode + + Returns true if the \l {QtPositioning::coordinate}{coordinate} specified by \a coord is within + this geoshape; Otherwise returns false. +*/ + +GeoShapeValueType::GeoShapeValueType(QObject *parent) +: QQmlValueTypeBase(qMetaTypeId(), parent) +{ +} + +GeoShapeValueType::~GeoShapeValueType() +{ +} + +GeoShapeValueType::ShapeType GeoShapeValueType::type() const +{ + return static_cast(v.type()); +} + +bool GeoShapeValueType::isValid() const +{ + return v.isValid(); +} + +bool GeoShapeValueType::isEmpty() const +{ + return v.isEmpty(); +} + +bool GeoShapeValueType::contains(const QGeoCoordinate &coordinate) const +{ + return v.contains(coordinate); +} + +QString GeoShapeValueType::toString() const +{ + switch (v.type()) { + case QGeoShape::UnknownType: + return QStringLiteral("QGeoShape()"); + case QGeoShape::RectangleType: { + QGeoRectangle r = v; + return QStringLiteral("QGeoRectangle({%1, %2}, {%3, %4})") + .arg(r.topLeft().latitude()) + .arg(r.topLeft().longitude()) + .arg(r.bottomRight().latitude()) + .arg(r.bottomRight().longitude()); + } + case QGeoShape::CircleType: { + QGeoCircle c = v; + return QStringLiteral("QGeoCircle({%1, %2}, %3)") + .arg(c.center().latitude()) + .arg(c.center().longitude()) + .arg(c.radius()); + } + } + + return QStringLiteral("QGeoShape(%1)").arg(v.type()); +} + +void GeoShapeValueType::setValue(const QVariant &value) +{ + if (value.userType() == qMetaTypeId()) + v = value.value(); + else if (value.userType() == qMetaTypeId()) + v = value.value(); + else if (value.userType() == qMetaTypeId()) + v = value.value(); + else + v = QGeoShape(); + + onLoad(); +} + +bool GeoShapeValueType::isEqual(const QVariant &other) const +{ + if (other.userType() == qMetaTypeId()) + return v == other.value(); + else if (other.userType() == qMetaTypeId()) + return v == other.value(); + else if (other.userType() == qMetaTypeId()) + return v == other.value(); + else + return false; +} + +GeoShapeValueType::GeoShapeValueType(int userType, QObject *parent) +: QQmlValueTypeBase(userType, parent) +{ + QMetaType::construct(userType, &v, 0); +} + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativegeoshape.h b/src/imports/positioning/qdeclarativegeoshape.h new file mode 100644 index 00000000..e75830b0 --- /dev/null +++ b/src/imports/positioning/qdeclarativegeoshape.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEGEOSHAPE_H +#define QDECLARATIVEGEOSHAPE_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class GeoShapeValueType : public QQmlValueTypeBase +{ + Q_OBJECT + + Q_PROPERTY(ShapeType type READ type) + Q_PROPERTY(bool isValid READ isValid) + Q_PROPERTY(bool isEmpty READ isEmpty) + + Q_ENUMS(ShapeType) + +public: + explicit GeoShapeValueType(QObject *parent = 0); + ~GeoShapeValueType(); + + enum ShapeType { + UnknownType = QGeoShape::UnknownType, + RectangleType = QGeoShape::RectangleType, + CircleType = QGeoShape::CircleType + }; + + ShapeType type() const; + bool isValid() const; + bool isEmpty() const; + + Q_INVOKABLE bool contains(const QGeoCoordinate &coordinate) const; + + QString toString() const Q_DECL_OVERRIDE; + void setValue(const QVariant &value) Q_DECL_OVERRIDE; + bool isEqual(const QVariant &other) const Q_DECL_OVERRIDE; + +protected: + explicit GeoShapeValueType(int userType, QObject *parent = 0); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/imports/positioning/qdeclarativeposition.cpp b/src/imports/positioning/qdeclarativeposition.cpp new file mode 100644 index 00000000..bce1b1fa --- /dev/null +++ b/src/imports/positioning/qdeclarativeposition.cpp @@ -0,0 +1,375 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativeposition_p.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Position + \instantiates QDeclarativePosition + \inqmlmodule QtPositioning 5.0 + \since Qt Positioning 5.0 + + \brief The Position type holds positional data at a particular point in time, + such as coordinate (longitude, latitude, altitude) and speed. + + The Position type holds values related to geographic location such as + a \l coordinate (longitude, latitude, and altitude), the \l timestamp when + the Position was obtained, the \l speed at that time, and the accuracy of + the data. + + Primarily, it is used in the \l{PositionSource::position}{position} property + of a \l{PositionSource}, as the basic unit of data available from the system + location data source. + + Not all properties of a Position object are necessarily valid or available + (for example latitude and longitude may be valid, but speed update has not been + received or set manually). As a result, corresponding "valid" properties + are available (for example \l{coordinate} and \l{longitudeValid}, \l{latitudeValid} + etc) to discern whether the data is available and valid in this position + update. + + Position objects are read-only and can only be produced by a PositionSource. + + \section2 Example Usage + + See the example given for the \l{PositionSource} type, or the + \l{declarative/flickr}{Flickr} example application. + + \sa PositionSource, coordinate + +*/ + +QDeclarativePosition::QDeclarativePosition(QObject *parent) + : QObject(parent), m_latitudeValid(false), m_longitudeValid(false), + m_altitudeValid(false), m_speed(-1), m_speedValid(false), m_horizontalAccuracyValid(false), + m_verticalAccuracyValid(false), m_horizontalAccuracy(-1), m_verticalAccuracy(-1) +{ +} + +QDeclarativePosition::~QDeclarativePosition() +{ +} + +/*! + \qmlproperty coordinate Position::coordinate + + This property holds the latitude, longitude, and altitude value of the Position. + + It is a read-only property. + + \sa longitudeValid, latitudeValid, altitudeValid +*/ + +void QDeclarativePosition::setCoordinate(const QGeoCoordinate &coordinate) +{ + if (m_coordinate == coordinate) + return; + + m_coordinate = coordinate; + + if (coordinate.type() == QGeoCoordinate::Coordinate3D && !m_altitudeValid) { + m_altitudeValid = true; + emit altitudeValidChanged(); + } else if (m_altitudeValid) { + m_altitudeValid = false; + emit altitudeValidChanged(); + } + if (coordinate.isValid()) { + if (!m_longitudeValid) { + m_longitudeValid = true; + emit longitudeValidChanged(); + } + if (!m_latitudeValid) { + m_latitudeValid = true; + emit latitudeValidChanged(); + } + } else { + if (m_longitudeValid) { + m_longitudeValid = false; + emit longitudeValidChanged(); + } + if (m_latitudeValid) { + m_latitudeValid = false; + emit latitudeValidChanged(); + } + } + emit coordinateChanged(); +} + +QGeoCoordinate QDeclarativePosition::coordinate() +{ + return m_coordinate; +} + +/*! + \qmlproperty bool Position::latitudeValid + + This property is true if coordinate's latitude has been set + (to indicate whether that data has been received or not, as every update + does not necessarily contain all data). + + \sa coordinate + +*/ + +bool QDeclarativePosition::isLatitudeValid() const +{ + return m_latitudeValid; +} + + +/*! + \qmlproperty bool Position::longitudeValid + + This property is true if coordinate's longitude has been set + (to indicate whether that data has been received or not, as every update + does not necessarily contain all data). + + \sa coordinate + +*/ + +bool QDeclarativePosition::isLongitudeValid() const +{ + return m_longitudeValid; +} + + +/*! + \qmlproperty bool Position::speedValid + + This property is true if \l speed has been set + (to indicate whether that data has been received or not, as every update + does not necessarily contain all data). + + \sa speed + +*/ + +bool QDeclarativePosition::isSpeedValid() const +{ + return m_speedValid; +} + +/*! + \qmlproperty bool Position::altitudeValid + + This property is true if coordinate's altitude has been set + (to indicate whether that data has been received or not, as every update + does not necessarily contain all data). + + \sa coordinate + +*/ + +bool QDeclarativePosition::isAltitudeValid() const +{ + return m_altitudeValid; +} + +/*! + \qmlproperty double Position::speed + + This property holds the value of speed (groundspeed, meters / second). + + It is a read-only property. + + \sa speedValid, coordinate +*/ + +void QDeclarativePosition::setSpeed(double speed) +{ + if (speed == m_speed) + return; + m_speed = speed; + if (!m_speedValid) { + m_speedValid = true; + emit speedValidChanged(); + } + emit speedChanged(); +} + +double QDeclarativePosition::speed() const +{ + return m_speed; +} + +/*! + \qmlproperty real Position::horizontalAccuracy + + This property holds the horizontal accuracy of the coordinate (in meters). + + \sa horizontalAccuracyValid, coordinate +*/ + +void QDeclarativePosition::setHorizontalAccuracy(qreal horizontalAccuracy) +{ + if (horizontalAccuracy == m_horizontalAccuracy) + return; + m_horizontalAccuracy = horizontalAccuracy; + if (!m_horizontalAccuracyValid) { + m_horizontalAccuracyValid = true; + emit horizontalAccuracyValidChanged(); + } + emit horizontalAccuracyChanged(); +} + +qreal QDeclarativePosition::horizontalAccuracy() const +{ + return m_horizontalAccuracy; +} + +/*! + \qmlproperty bool Position::horizontalAccuracyValid + + This property is true if \l horizontalAccuracy has been set + (to indicate whether that data has been received or not, as every update + does not necessarily contain all data). + + \sa horizontalAccuracy + +*/ + +bool QDeclarativePosition::isHorizontalAccuracyValid() const +{ + return m_horizontalAccuracyValid; +} + +/*! + \qmlproperty real Position::verticalAccuracy + + This property holds the vertical accuracy of the coordinate (in meters). + + \sa verticalAccuracyValid, coordinate +*/ + +void QDeclarativePosition::setVerticalAccuracy(qreal verticalAccuracy) +{ + if (verticalAccuracy == m_verticalAccuracy) + return; + m_verticalAccuracy = verticalAccuracy; + if (!m_verticalAccuracyValid) { + m_verticalAccuracyValid = true; + emit verticalAccuracyValidChanged(); + } + emit verticalAccuracyChanged(); +} + +qreal QDeclarativePosition::verticalAccuracy() const +{ + return m_verticalAccuracy; +} + +/*! + \qmlproperty bool Position::verticalAccuracyValid + + This property is true if \l verticalAccuracy has been set + (to indicate whether that data has been received or not, as every update + does not necessarily contain all data). + + \sa verticalAccuracy + +*/ + +bool QDeclarativePosition::isVerticalAccuracyValid() const +{ + return m_verticalAccuracyValid; +} + +/*! + \qmlproperty date Position::timestamp + + This property holds the timestamp when this position + was received. If the property has not been set, it is invalid. + + It is a read-only property. +*/ + +void QDeclarativePosition::setTimestamp(const QDateTime ×tamp) +{ + if (timestamp == m_timestamp) + return; + m_timestamp = timestamp; + emit timestampChanged(); +} + +QDateTime QDeclarativePosition::timestamp() const +{ + return m_timestamp; +} + +void QDeclarativePosition::invalidate() +{ + // Invalidate all data + if (m_latitudeValid) { + m_latitudeValid = false; + emit latitudeValidChanged(); + } + if (m_longitudeValid) { + m_longitudeValid = false; + emit longitudeValidChanged(); + } + if (m_altitudeValid) { + m_altitudeValid = false; + emit altitudeValidChanged(); + } + if (m_speedValid) { + m_speedValid = false; + emit speedValidChanged(); + } + if (m_horizontalAccuracyValid) { + m_horizontalAccuracyValid = false; + emit horizontalAccuracyValidChanged(); + } + if (m_verticalAccuracyValid) { + m_verticalAccuracyValid = false; + emit verticalAccuracyValidChanged(); + } +} + +#include "moc_qdeclarativeposition_p.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativeposition_p.h b/src/imports/positioning/qdeclarativeposition_p.h new file mode 100644 index 00000000..99c2d8fc --- /dev/null +++ b/src/imports/positioning/qdeclarativeposition_p.h @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEPOSITION_H +#define QDECLARATIVEPOSITION_H + +#include +#include +#include +#include +#include "qdeclarativecoordinate_p.h" +#include + +// Define this to get qDebug messages +// #define QDECLARATIVE_POSITION_DEBUG + +#ifdef QDECLARATIVE_POSITION_DEBUG +#include +#endif + +QT_BEGIN_NAMESPACE + +class QDeclarativePosition : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool latitudeValid READ isLatitudeValid NOTIFY latitudeValidChanged) + Q_PROPERTY(bool longitudeValid READ isLongitudeValid NOTIFY longitudeValidChanged) + Q_PROPERTY(bool altitudeValid READ isAltitudeValid NOTIFY altitudeValidChanged) + Q_PROPERTY(QGeoCoordinate coordinate READ coordinate NOTIFY coordinateChanged) + Q_PROPERTY(QDateTime timestamp READ timestamp NOTIFY timestampChanged) + Q_PROPERTY(double speed READ speed NOTIFY speedChanged) + Q_PROPERTY(bool speedValid READ isSpeedValid NOTIFY speedValidChanged) + Q_PROPERTY(qreal horizontalAccuracy READ horizontalAccuracy WRITE setHorizontalAccuracy NOTIFY horizontalAccuracyChanged) + Q_PROPERTY(qreal verticalAccuracy READ verticalAccuracy WRITE setVerticalAccuracy NOTIFY verticalAccuracyChanged) + Q_PROPERTY(bool horizontalAccuracyValid READ isHorizontalAccuracyValid NOTIFY horizontalAccuracyValidChanged) + Q_PROPERTY(bool verticalAccuracyValid READ isVerticalAccuracyValid NOTIFY verticalAccuracyValidChanged) + +public: + + explicit QDeclarativePosition(QObject *parent = 0); + ~QDeclarativePosition(); + + bool isLatitudeValid() const; + bool isLongitudeValid() const; + bool isAltitudeValid() const; + QDateTime timestamp() const; + void setTimestamp(const QDateTime ×tamp); + double speed() const; + void setSpeed(double speed); + bool isSpeedValid() const; + QGeoCoordinate coordinate(); + bool isHorizontalAccuracyValid() const; + qreal horizontalAccuracy() const; + void setHorizontalAccuracy(qreal horizontalAccuracy); + bool isVerticalAccuracyValid() const; + qreal verticalAccuracy() const; + void setVerticalAccuracy(qreal verticalAccuracy); + + // C++ + void setCoordinate(const QGeoCoordinate &coordinate); + void invalidate(); + +Q_SIGNALS: + void latitudeValidChanged(); + void longitudeValidChanged(); + void altitudeValidChanged(); + void timestampChanged(); + void speedChanged(); + void speedValidChanged(); + void coordinateChanged(); + void horizontalAccuracyChanged(); + void horizontalAccuracyValidChanged(); + void verticalAccuracyChanged(); + void verticalAccuracyValidChanged(); + +private: + bool m_latitudeValid; + bool m_longitudeValid; + bool m_altitudeValid; + QDateTime m_timestamp; + double m_speed; + bool m_speedValid; + bool m_horizontalAccuracyValid; + bool m_verticalAccuracyValid; + qreal m_horizontalAccuracy; + qreal m_verticalAccuracy; + QGeoCoordinate m_coordinate; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativePosition) + +#endif diff --git a/src/imports/positioning/qdeclarativepositionsource.cpp b/src/imports/positioning/qdeclarativepositionsource.cpp new file mode 100644 index 00000000..97ad1bbc --- /dev/null +++ b/src/imports/positioning/qdeclarativepositionsource.cpp @@ -0,0 +1,646 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativepositionsource_p.h" +#include "qdeclarativeposition_p.h" +#include "error_messages.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmltype PositionSource + \instantiates QDeclarativePositionSource + \inqmlmodule QtPositioning 5.0 + \since Qt Positioning 5.0 + + \brief The PositionSource type provides the device's current position. + + The PositionSource type provides information about the user device's + current position. The position is available as a \l{Position} type, which + contains all the standard parameters typically available from GPS and other + similar systems, including longitude, latitude, speed and accuracy details. + + As different position sources are available on different platforms and + devices, these are categorized by their basic type (Satellite, NonSatellite, + and AllPositioningMethods). The available methods for the current platform + can be enumerated in the \l{supportedPositioningMethods} property. + + To indicate which methods are suitable for your application, set the + \l{preferredPositioningMethods} property. If the preferred methods are not + available, the default source of location data for the platform will be + chosen instead. If no default source is available (because none are installed + for the runtime platform, or because it is disabled), the \l{valid} property + will be set to false. + + The \l updateInterval property can then be used to indicate how often your + application wishes to receive position updates. The \l{start}(), + \l{stop}() and \l{update}() methods can be used to control the operation + of the PositionSource, as well as the \l{active} property, which when set + is equivalent to calling \l{start}() or \l{stop}(). + + When the PositionSource is active, position updates can be retrieved + either by simply using the \l{position} property in a binding (as the + value of another item's property), or by providing an implementation of + the \c {onPositionChanged} signal-handler. + + \section2 Example Usage + + The following example shows a simple PositionSource used to receive + updates every second and print the longitude and latitude out to + the console. + + \code + PositionSource { + id: src + updateInterval: 1000 + active: true + + onPositionChanged: { + var coord = src.position.coordinate; + console.log("Coordinate:", coord.longitude, coord.latitude); + } + } + \endcode + + The \l{declarative/flickr}{Flickr} example application shows how to use + a PositionSource in your application to retrieve local data for users + from a REST web service. + + \sa {QtPositioning5::Position}, {QGeoPositionInfoSource} + +*/ + +QDeclarativePositionSource::QDeclarativePositionSource() +: m_positionSource(0), m_preferredPositioningMethods(NoPositioningMethod), m_nmeaFile(0), + m_active(false), m_singleUpdate(false), m_updateInterval(0), m_sourceError(UnknownSourceError) +{ +} + +QDeclarativePositionSource::~QDeclarativePositionSource() +{ + delete m_nmeaFile; + delete m_positionSource; +} + + +/*! + \qmlproperty string PositionSource::name + + This property holds the unique internal name for the plugin currently + providing position information. + + Setting the property causes the PositionSource to use a particular positioning provider. If + the PositionSource is active at the time that the name property is changed, it will become + inactive. If the specified positioning provider cannot be loaded the position source will + become invalid. + + Changing the name property may cause the \l {updateInterval}, \l {supportedPositioningMethods} + and \l {preferredPositioningMethods} properties to change as well. +*/ + + +QString QDeclarativePositionSource::name() const +{ + if (m_positionSource) + return m_positionSource->sourceName(); + else + return QString(); +} + +void QDeclarativePositionSource::setName(const QString &newName) +{ + if (m_positionSource && m_positionSource->sourceName() == newName) + return; + + const QString previousName = name(); + int previousUpdateInterval = updateInterval(); + PositioningMethods previousPositioningMethods = supportedPositioningMethods(); + PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods(); + + delete m_positionSource; + if (newName.isEmpty()) + m_positionSource = QGeoPositionInfoSource::createDefaultSource(this); + else + m_positionSource = QGeoPositionInfoSource::createSource(newName, this); + + if (m_positionSource) { + connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), + this, SLOT(positionUpdateReceived(QGeoPositionInfo))); + connect(m_positionSource, SIGNAL(error(QGeoPositionInfoSource::Error)), + this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error))); + + m_positionSource->setUpdateInterval(m_updateInterval); + m_positionSource->setPreferredPositioningMethods( + static_cast(int(m_preferredPositioningMethods))); + } + + if (previousUpdateInterval != updateInterval()) + emit updateIntervalChanged(); + + if (previousPreferredPositioningMethods != preferredPositioningMethods()) + emit preferredPositioningMethodsChanged(); + + if (previousPositioningMethods != supportedPositioningMethods()) + emit supportedPositioningMethodsChanged(); + + emit validityChanged(); + + if (m_active) { + m_active = false; + emit activeChanged(); + } + + if (previousName != name()) + emit nameChanged(); +} + +/*! + \qmlproperty bool PositionSource::valid + + This property is true if the PositionSource object has acquired a valid + backend plugin to provide data. If false, other methods on the PositionSource + will have no effect. + + Applications should check this property to determine whether positioning is + available and enabled on the runtime platform, and react accordingly. +*/ +bool QDeclarativePositionSource::isValid() const +{ + return (m_positionSource != 0); +} + +/*! + \internal +*/ +void QDeclarativePositionSource::setNmeaSource(const QUrl &nmeaSource) +{ + // Strip the filename. This is clumsy but the file may be prefixed in several + // ways: "file:///", "qrc:///", "/", "" in platform dependant manner. + QString localFileName = nmeaSource.toString(); + if (!QFile::exists(localFileName)) { + if (localFileName.startsWith("qrc:///")) { + localFileName.remove(0, 7); + } else if (localFileName.startsWith("file:///")) { + localFileName.remove(0, 7); + } + if (!QFile::exists(localFileName) && localFileName.startsWith("/")) { + localFileName.remove(0,1); + } + } + if (m_nmeaFileName == localFileName) + return; + m_nmeaFileName = localFileName; + m_nmeaSource = nmeaSource; + + PositioningMethods previousPositioningMethods = supportedPositioningMethods(); + + // The current position source needs to be deleted + // because QNmeaPositionInfoSource can be bound only to a one file. + delete m_positionSource; + m_positionSource = 0; + // Create the NMEA source based on the given data. QML has automatically set QUrl + // type to point to correct path. If the file is not found, check if the file actually + // was an embedded resource file. + delete m_nmeaFile; + m_nmeaFile = new QFile(localFileName); + if (!m_nmeaFile->exists()) { + localFileName.prepend(":"); + m_nmeaFile->setFileName(localFileName); + } + if (m_nmeaFile->exists()) { +#ifdef QDECLARATIVE_POSITION_DEBUG + qDebug() << "QDeclarativePositionSource NMEA File was found: " << localFileName; +#endif + m_positionSource = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode); + (qobject_cast(m_positionSource))->setDevice(m_nmeaFile); + connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), + this, SLOT(positionUpdateReceived(QGeoPositionInfo))); + if (m_active && !m_singleUpdate) { + // Keep on updating even though source changed + QTimer::singleShot(0, this, SLOT(start())); + } + } else { + qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, MISSED_NMEA_FILE) << localFileName; +#ifdef QDECLARATIVE_POSITION_DEBUG + qDebug() << "QDeclarativePositionSource NMEA File was not found: " << localFileName; +#endif + if (m_active) { + m_active = false; + m_singleUpdate = false; + emit activeChanged(); + } + } + + if (previousPositioningMethods != supportedPositioningMethods()) + emit supportedPositioningMethodsChanged(); + + emit nmeaSourceChanged(); +} + +/*! + \internal +*/ +void QDeclarativePositionSource::setUpdateInterval(int updateInterval) +{ + if (m_positionSource) { + int previousUpdateInterval = m_positionSource->updateInterval(); + + m_updateInterval = updateInterval; + + if (previousUpdateInterval != updateInterval) { + m_positionSource->setUpdateInterval(updateInterval); + if (previousUpdateInterval != m_positionSource->updateInterval()) + emit updateIntervalChanged(); + } + } else { + if (m_updateInterval != updateInterval) { + m_updateInterval = updateInterval; + emit updateIntervalChanged(); + } + } +} + +/*! + \qmlproperty url PositionSource::nmeaSource + + This property holds the source for NMEA (National Marine Electronics Association) + position-specification data (file). One purpose of this property is to be of + development convenience. + + Setting this property will override any other position source. Currently only + files local to the .qml -file are supported. The NMEA source is created in simulation mode, + meaning that the data and time information in the NMEA source data is used to provide + positional updates at the rate at which the data was originally recorded. + + If nmeaSource has been set for a PositionSource object, there is no way to revert + back to non-file sources. +*/ + +QUrl QDeclarativePositionSource::nmeaSource() const +{ + return m_nmeaSource; +} + +/*! + \qmlproperty int PositionSource::updateInterval + + This property holds the desired interval between updates (milliseconds). + + \sa {QGeoPositionInfoSource::updateInterval()} +*/ + +int QDeclarativePositionSource::updateInterval() const +{ + if (!m_positionSource) + return m_updateInterval; + + return m_positionSource->updateInterval(); +} + +/*! + \qmlproperty enumeration PositionSource::supportedPositioningMethods + + This property holds the supported positioning methods of the + current source. + + \list + \li PositionSource.NoPositioningMethod - No positioning methods supported (no source). + \li PositionSource.SatellitePositioningMethod - Satellite-based positioning methods such as GPS are supported. + \li PositionSource.NonSatellitePositioningMethod - Non-satellite-based methods are supported. + \li PositionSource.AllPositioningMethods - Both satellite-based and non-satellite positioning methods are supported. + \endlist + +*/ + +QDeclarativePositionSource::PositioningMethods QDeclarativePositionSource::supportedPositioningMethods() const +{ + if (m_positionSource) { + QGeoPositionInfoSource::PositioningMethods methods = m_positionSource->supportedPositioningMethods(); + if ( (methods & QGeoPositionInfoSource::AllPositioningMethods) == methods ) { + return QDeclarativePositionSource::AllPositioningMethods; + } else if (methods & QGeoPositionInfoSource::SatellitePositioningMethods) { + return QDeclarativePositionSource::SatellitePositioningMethod; + } else if (methods & QGeoPositionInfoSource::NonSatellitePositioningMethods) { + return QDeclarativePositionSource::NonSatellitePositioningMethod; + } + } + return QDeclarativePositionSource::NoPositioningMethod; +} + +/*! + \qmlproperty enumeration PositionSource::preferredPositioningMethods + + This property holds the preferred positioning methods of the + current source. + + \list + \li PositionSource.SatellitePositioningMethod - Satellite-based positioning methods such as GPS should be preferred. + \li PositionSource.NonSatellitePositioningMethod - Non-satellite-based methods should be preferred. + \li PositionSource.AllPositioningMethods - Any positioning methods are acceptable. + \endlist + +*/ + +void QDeclarativePositionSource::setPreferredPositioningMethods(PositioningMethods methods) +{ + if (m_positionSource) { + PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods(); + + m_preferredPositioningMethods = methods; + + if (previousPreferredPositioningMethods != methods) { + m_positionSource->setPreferredPositioningMethods( + static_cast(int(methods))); + if (previousPreferredPositioningMethods != m_positionSource->preferredPositioningMethods()) + emit preferredPositioningMethodsChanged(); + } + } else { + if (m_preferredPositioningMethods != methods) { + m_preferredPositioningMethods = methods; + emit preferredPositioningMethodsChanged(); + } + } +} + +QDeclarativePositionSource::PositioningMethods QDeclarativePositionSource::preferredPositioningMethods() const +{ + if (m_positionSource) { + QGeoPositionInfoSource::PositioningMethods methods = + m_positionSource->preferredPositioningMethods(); + if ( (methods & QGeoPositionInfoSource::AllPositioningMethods) == methods) { + return QDeclarativePositionSource::AllPositioningMethods; + } else if (methods & QGeoPositionInfoSource::SatellitePositioningMethods) { + return QDeclarativePositionSource::SatellitePositioningMethod; + } else if (methods & QGeoPositionInfoSource::NonSatellitePositioningMethods) { + return QDeclarativePositionSource::NonSatellitePositioningMethod; + } + } + return m_preferredPositioningMethods; +} + +/*! + \qmlmethod PositionSource::start() + + Requests updates from the location source. + Uses \l updateInterval if set, default interval otherwise. + If there is no source available, this method has no effect. + + \sa stop, update, active +*/ + +void QDeclarativePositionSource::start() +{ + if (!m_positionSource) + return; + + m_positionSource->startUpdates(); + if (!m_active) { + m_active = true; + emit activeChanged(); + } +} + +/*! + \qmlmethod PositionSource::update() + + A convenience method to request single update from the location source. + If there is no source available, this method has no effect. + + If the position source is not active, it will be activated for as + long as it takes to receive an update, or until the request times + out. The request timeout period is source-specific. + + \sa start, stop, active +*/ + +void QDeclarativePositionSource::update() +{ + if (m_positionSource) { + if (!m_active) { + m_active = true; + m_singleUpdate = true; + emit activeChanged(); + } + // Use default timeout value. Set active before calling the + // update request because on some platforms there may + // be results immediately. + m_positionSource->requestUpdate(); + } +} + +/*! + \qmlmethod PositionSource::stop() + + Stops updates from the location source. + If there is no source available or it is not active, + this method has no effect. + + \sa start, update, active +*/ + +void QDeclarativePositionSource::stop() +{ + if (m_positionSource) { + m_positionSource->stopUpdates(); + if (m_active) { + m_active = false; + emit activeChanged(); + } + } +} + +/*! + \qmlproperty bool PositionSource::active + + This property indicates whether the position source is active. + Setting this property to false equals calling \l stop, and + setting this property true equals calling \l start. + + \sa start, stop, update +*/ +void QDeclarativePositionSource::setActive(bool active) +{ + if (active == m_active) + return; + + if (active) + QTimer::singleShot(0, this, SLOT(start())); // delay ensures all properties have been set + else + stop(); +} + +bool QDeclarativePositionSource::isActive() const +{ + return m_active; +} + +/*! + \qmlproperty Position PositionSource::position + + This property holds the last known positional data. + It is a read-only property. + + The Position type has different positional member variables, + whose validity can be checked with appropriate validity functions + (for example sometimes an update does not have speed or altitude data). + + However, whenever a \c {positionChanged} signal has been received, at least + position::coordinate::latitude, position::coordinate::longitude, and position::timestamp can + be assumed to be valid. + + \sa start, stop, update +*/ + +QDeclarativePosition *QDeclarativePositionSource::position() +{ + return &m_position; +} + +void QDeclarativePositionSource::positionUpdateReceived(const QGeoPositionInfo &update) +{ + if (update.isValid()) { + m_position.setTimestamp(update.timestamp()); + m_position.setCoordinate(update.coordinate()); + if (update.hasAttribute(QGeoPositionInfo::GroundSpeed)) { + m_position.setSpeed(update.attribute(QGeoPositionInfo::GroundSpeed)); + } + if (update.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) { + m_position.setHorizontalAccuracy(update.attribute(QGeoPositionInfo::HorizontalAccuracy)); + } + if (update.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) { + m_position.setVerticalAccuracy(update.attribute(QGeoPositionInfo::VerticalAccuracy)); + } + emit positionChanged(); + } else { + m_position.invalidate(); + } + if (m_singleUpdate && m_active) { + m_active = false; + m_singleUpdate = false; + emit activeChanged(); + } +} + + +/*! + \qmlproperty enumeration PositionSource::sourceError + + This property holds the error which last occured with the PositionSource. + + \list + \li PositionSource.AccessError - The connection setup to the remote positioning backend failed because the + application lacked the required privileges. + \li PositionSource.ClosedError - The remote positioning backend closed the connection, which happens for example in case + the user is switching location services to off. This object becomes invalid and should be deleted. + A new source can be declared later on to check whether the positioning backend is up again. + \li PositionSource.UnknownSourceError - An unidentified error occurred. + \endlist + +*/ + +QDeclarativePositionSource::SourceError QDeclarativePositionSource::sourceError() const +{ + return m_sourceError; +} + +void QDeclarativePositionSource::componentComplete() +{ + if (!m_positionSource) { + int previousUpdateInterval = updateInterval(); + PositioningMethods previousPositioningMethods = supportedPositioningMethods(); + PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods(); + + m_positionSource = QGeoPositionInfoSource::createDefaultSource(this); + if (m_positionSource) { + connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), + this, SLOT(positionUpdateReceived(QGeoPositionInfo))); + connect(m_positionSource, SIGNAL(error(QGeoPositionInfoSource::Error)), + this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error))); + + m_positionSource->setUpdateInterval(m_updateInterval); + m_positionSource->setPreferredPositioningMethods( + static_cast(int(m_preferredPositioningMethods))); + } + + if (previousUpdateInterval != updateInterval()) + emit updateIntervalChanged(); + + if (previousPreferredPositioningMethods != preferredPositioningMethods()) + emit preferredPositioningMethodsChanged(); + + if (previousPositioningMethods != supportedPositioningMethods()) + emit supportedPositioningMethodsChanged(); + + emit validityChanged(); + + if (m_active) { + m_active = false; + emit activeChanged(); + } + + emit nameChanged(); + } +} + +/*! + \internal +*/ +void QDeclarativePositionSource::sourceErrorReceived(const QGeoPositionInfoSource::Error error) +{ + if (error == QGeoPositionInfoSource::AccessError) { + m_sourceError = QDeclarativePositionSource::AccessError; + } else if (error == QGeoPositionInfoSource::ClosedError) { + m_sourceError = QDeclarativePositionSource::ClosedError; + } else { + m_sourceError = QDeclarativePositionSource::UnknownSourceError; + } + emit sourceErrorChanged(); +} + +#include "moc_qdeclarativepositionsource_p.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativepositionsource_p.h b/src/imports/positioning/qdeclarativepositionsource_p.h new file mode 100644 index 00000000..70506c00 --- /dev/null +++ b/src/imports/positioning/qdeclarativepositionsource_p.h @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEPOSITIONSOURCE_H +#define QDECLARATIVEPOSITIONSOURCE_H + +#include "qdeclarativeposition_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QFile; + +class QDeclarativePositionSource : public QObject, public QQmlParserStatus +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativePosition *position READ position NOTIFY positionChanged) + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) + Q_PROPERTY(bool valid READ isValid NOTIFY validityChanged) + Q_PROPERTY(QUrl nmeaSource READ nmeaSource WRITE setNmeaSource NOTIFY nmeaSourceChanged) + Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval NOTIFY updateIntervalChanged) + Q_PROPERTY(PositioningMethods supportedPositioningMethods READ supportedPositioningMethods NOTIFY supportedPositioningMethodsChanged) + Q_PROPERTY(PositioningMethods preferredPositioningMethods READ preferredPositioningMethods WRITE setPreferredPositioningMethods NOTIFY preferredPositioningMethodsChanged) + Q_PROPERTY(SourceError sourceError READ sourceError NOTIFY sourceErrorChanged) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_ENUMS(PositioningMethod) + + Q_INTERFACES(QQmlParserStatus) + +public: + enum PositioningMethod { + NoPositioningMethod = 0, + SatellitePositioningMethod = QGeoPositionInfoSource::SatellitePositioningMethods, + NonSatellitePositioningMethod = QGeoPositionInfoSource::NonSatellitePositioningMethods, + AllPositioningMethods = QGeoPositionInfoSource::AllPositioningMethods + }; + + Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod) + Q_FLAGS(PositioningMethods) + + enum SourceError { + AccessError = QGeoPositionInfoSource::AccessError, + ClosedError = QGeoPositionInfoSource::ClosedError, + UnknownSourceError = QGeoPositionInfoSource::UnknownSourceError + }; + Q_ENUMS(SourceError) + + QDeclarativePositionSource(); + ~QDeclarativePositionSource(); + void setNmeaSource(const QUrl &nmeaSource); + void setUpdateInterval(int updateInterval); + void setActive(bool active); + void setPreferredPositioningMethods(PositioningMethods methods); + + QString name() const; + void setName(const QString &name); + + QUrl nmeaSource() const; + int updateInterval() const; + bool isActive() const; + bool isValid() const; + QDeclarativePosition *position(); + PositioningMethods supportedPositioningMethods() const; + PositioningMethods preferredPositioningMethods() const; + SourceError sourceError() const; + + // Virtuals from QQmlParserStatus + void classBegin() { } + void componentComplete(); + +public Q_SLOTS: + void update(); + void start(); + void stop(); + +Q_SIGNALS: + void positionChanged(); + void activeChanged(); + void nmeaSourceChanged(); + void updateIntervalChanged(); + void supportedPositioningMethodsChanged(); + void preferredPositioningMethodsChanged(); + void sourceErrorChanged(); + void nameChanged(); + void validityChanged(); + + +private Q_SLOTS: + void positionUpdateReceived(const QGeoPositionInfo &update); + void sourceErrorReceived(const QGeoPositionInfoSource::Error error); +private: + QGeoPositionInfoSource *m_positionSource; + QDeclarativePosition m_position; + PositioningMethods m_preferredPositioningMethods; + QFile *m_nmeaFile; + QString m_nmeaFileName; + QUrl m_nmeaSource; + bool m_active; + bool m_singleUpdate; + int m_updateInterval; + SourceError m_sourceError; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativePositionSource) + +#endif diff --git a/src/imports/positioning/qmldir b/src/imports/positioning/qmldir new file mode 100644 index 00000000..4143e0d5 --- /dev/null +++ b/src/imports/positioning/qmldir @@ -0,0 +1,3 @@ +module QtPositioning +plugin declarative_positioning +typeinfo plugins.qmltypes diff --git a/src/location/doc/images/example-weatherinfo.png b/src/location/doc/images/example-weatherinfo.png deleted file mode 100644 index 6557b57b..00000000 Binary files a/src/location/doc/images/example-weatherinfo.png and /dev/null differ diff --git a/src/location/doc/images/flickr-demo.jpg b/src/location/doc/images/flickr-demo.jpg deleted file mode 100644 index cfd12819..00000000 Binary files a/src/location/doc/images/flickr-demo.jpg and /dev/null differ diff --git a/src/location/doc/images/qml-flickr-1.jpg b/src/location/doc/images/qml-flickr-1.jpg deleted file mode 100644 index 14fc5c92..00000000 Binary files a/src/location/doc/images/qml-flickr-1.jpg and /dev/null differ diff --git a/src/location/doc/qtlocation.qdocconf b/src/location/doc/qtlocation.qdocconf index a5b10857..8e000634 100644 --- a/src/location/doc/qtlocation.qdocconf +++ b/src/location/doc/qtlocation.qdocconf @@ -36,13 +36,14 @@ qhp.QtLocation.subprojects.examples.selectors = fake:example tagfile = ../../../doc/qtlocation/qtlocation.tags -depends += qtcore qtdoc qtquick qtqml qtnetwork +depends += qtcore qtdoc qtquick qtqml qtnetwork qtpositioning headerdirs += .. \ ../../imports/location sourcedirs += .. \ ../../imports/location \ + ../../plugins/geoservices/nokia exampledirs += ../../../examples \ ../../../examples/declarative \ diff --git a/src/location/doc/snippets/cpp/cppqml.cpp b/src/location/doc/snippets/cpp/cppqml.cpp index 93d2b603..34386ca8 100644 --- a/src/location/doc/snippets/cpp/cppqml.cpp +++ b/src/location/doc/snippets/cpp/cppqml.cpp @@ -48,10 +48,6 @@ #include #include #include -#include -#include -#include -#include void cppQmlInterface(QObject *qmlObject) { @@ -118,21 +114,5 @@ void cppQmlInterface(QObject *qmlObject) //! [Supplier set] qmlObject->setProperty("supplier", QVariant::fromValue(placeSupplier)); //! [Supplier set] - - //! [Address get] - QGeoAddress geoAddress = qmlObject->property("address").value(); - //! [Address get] - - //! [Address set] - qmlObject->setProperty("address", QVariant::fromValue(geoAddress)); - //! [Address set] - - //! [Location get] - QGeoLocation geoLocation = qmlObject->property("location").value(); - //! [Location get] - - //! [Location set] - qmlObject->setProperty("location", QVariant::fromValue(geoLocation)); - //! [Location set] } diff --git a/src/location/doc/snippets/declarative/declarative-location.qml b/src/location/doc/snippets/declarative/declarative-location.qml index 111fe727..9b0efa42 100644 --- a/src/location/doc/snippets/declarative/declarative-location.qml +++ b/src/location/doc/snippets/declarative/declarative-location.qml @@ -40,7 +40,7 @@ //![0] import QtQuick 2.0 -import QtLocation 5.0 +import QtPositioning 5.0 Rectangle { id: page diff --git a/src/location/doc/snippets/declarative/declarative-map.qml b/src/location/doc/snippets/declarative/declarative-map.qml deleted file mode 100644 index d517580e..00000000 --- a/src/location/doc/snippets/declarative/declarative-map.qml +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Mobility Components. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import Qt 4.7 -import QtMobility.location 1.2 - -Item { - id: page - width: 320 - height: 480 - focus: true - - PositionSource { - id: myPositionSource - active: true - updateInterval: 2000 - nmeaSource: 'nmealog.txt' - onPositionChanged: console.log("Position changed in PositionSource") - } - LandmarkBoxFilter { - id: boxFilter - topLeft: map.toCoordinate(Qt.point(0,0)) - bottomRight: map.toCoordinate(Qt.point(page.width, page.height)) - } - - LandmarkProximityFilter { - id: proximityFilter - center: myPositionSource.position.coordinate - //center: Coordinate {latitude: -27; longitude: 153} - radius: 500000 - } - - LandmarkModel { - id: landmarkModelAll - autoUpdate: true - filter: boxFilter - limit: 50 - onModelChanged: { - console.log("All landmark model changed, landmark count: " + count) - } - } - - //! [LandmarkModel proximity filter] - LandmarkModel { - id: landmarkModelNear - autoUpdate: true - filter: proximityFilter - limit: 50 - onModelChanged: { - console.log("Near landmark model changed, landmark count: " + count) - } - } - //! [LandmarkModel proximity filter] - - Rectangle { - id: dataArea - anchors.fill: parent - color: "#343434" - - //![Basic MapObjects and View on Map] - Map { - id: map - plugin : Plugin {name : "nokia"} - anchors.fill: parent - size.width: parent.width - size.height: parent.height - zoomLevel: 10 - - MapObjectView { - id: allLandmarks - model: landmarkModelAll - delegate: Component { - MapCircle { - color: "green" - radius: 1000 - center: Coordinate { - latitude: landmark.coordinate.latitude - longitude: landmark.coordinate.longitude - } - } - } - } - - MapCircle { - id: myPosition - color: "yellow" - radius: 1000 - center: myPositionSource.position.coordinate - } - //![Basic MapObjects and View on Map] - - MapObjectView { - id: landmarksNearMe - model: landmarkModelNear - delegate: Component { - MapGroup { - MapCircle { - color: "red" - radius: 1000 - center: Coordinate { - latitude: landmark.coordinate.latitude - longitude: landmark.coordinate.longitude - } - } - } - } - } - - // center: Coordinate {latitude: -27; longitude: 153} - center: myPositionSource.position.coordinate - - onZoomLevelChanged: { - console.log("Zoom changed") - updateFilters(); - } - onCenterChanged: { - console.log("Center changed") - updateFilters(); - } - function updateFilters () { - // The pixel coordinates used are the map's pixel coordinates, not - // the absolute pixel coordinates of the application. Hence e.g. (0,0) is always - // the top left point - var topLeftCoordinate = map.toCoordinate(Qt.point(0,0)) - var bottomRightCoordinate = map.toCoordinate(Qt.point(map.size.width, map.size.height)) - boxFilter.topLeft = topLeftCoordinate; - boxFilter.bottomRight = bottomRightCoordinate; - } - } // map - } // dataArea -} // page diff --git a/src/location/doc/snippets/declarative/maps.qml b/src/location/doc/snippets/declarative/maps.qml index fbb60b82..eb5d5bc1 100644 --- a/src/location/doc/snippets/declarative/maps.qml +++ b/src/location/doc/snippets/declarative/maps.qml @@ -41,11 +41,18 @@ //! [QtQuick import] import QtQuick 2.0 //! [QtQuick import] +import QtPositioning 5.0 //! [QtLocation import] import QtLocation 5.0 //! [QtLocation import] Item { + id: page + + Plugin { + id: myPlugin + } + //! [MapRoute] Map { RouteModel { @@ -81,7 +88,7 @@ Item { property MapCircle circle Component.onCompleted: { - circle = Qt.createQmlObject('import QtLocation 5.0; MapCircle {}') + circle = Qt.createQmlObject('import QtLocation 5.0; MapCircle {}', page) circle.center = positionSource.position.coordinate circle.radius = 5000.0 circle.color = 'green' diff --git a/src/location/doc/snippets/declarative/places.qml b/src/location/doc/snippets/declarative/places.qml index 66c62cf7..862ab182 100644 --- a/src/location/doc/snippets/declarative/places.qml +++ b/src/location/doc/snippets/declarative/places.qml @@ -42,10 +42,15 @@ import QtQuick 2.0 //! [QtQuick import] //! [QtLocation import] +import QtPositioning 5.0 import QtLocation 5.0 //! [QtLocation import] Item { + Plugin { + id: myPlugin + } + Place { id: place } @@ -110,6 +115,9 @@ Item { //! [ExtendedAttributes write] } + Icon { + id: icon + } //! [Icon] Image { source: icon.url(Qt.size(64, 64)) @@ -118,7 +126,7 @@ Item { Image { //! [Icon default] - source: icon.url() + source: icon.url() //! [Icon default] } @@ -207,7 +215,6 @@ Item { ListView { anchors.top: parent.top - anchors.bottom: position.top width: parent.width spacing: 10 @@ -303,7 +310,7 @@ Item { id: myPlace plugin: myPlugin - name: "Nokia Brisbane" + name: "Brisbane Technology Park" location: Location { address: Address { street: "53 Brandl Street" diff --git a/src/location/doc/snippets/declarative/places_loader.qml b/src/location/doc/snippets/declarative/places_loader.qml index 9f10faf7..06301064 100644 --- a/src/location/doc/snippets/declarative/places_loader.qml +++ b/src/location/doc/snippets/declarative/places_loader.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import QtPositioning 5.0 import QtLocation 5.0 Rectangle { @@ -60,13 +61,7 @@ Rectangle { plugin: myPlugin searchTerm: "pizza" - searchArea: GeoCircle { - center { - // Brisbane - longitude: 153.02778 - latitude: -27.46778 - } - } + searchArea: QtLocation.circle( -27.46778, 153.02778 ) Component.onCompleted: update() } diff --git a/src/location/doc/src/cpp-qml.qdoc b/src/location/doc/src/cpp-qml.qdoc index 3e38edb0..aabf1f8a 100644 --- a/src/location/doc/src/cpp-qml.qdoc +++ b/src/location/doc/src/cpp-qml.qdoc @@ -27,7 +27,7 @@ /*! \page location-cpp-qml.html -\title Interfaces between C++ and QML Code +\title Interfaces between C++ and QML Code in Qt Positioning \brief Some of the location QML types providing interfaces to access and modify properties in C++. @@ -120,26 +120,4 @@ The following gets the QPlaceSupplier representing this object from C++: The following sets the properties of this object based on a QPlaceSupplier object from C++: \snippet cpp/cppqml.cpp Supplier set - -\section2 Address - QGeoAddress -\target geoaddress -The \l {Address::address} {Address.address} property is used to provide an interface between C++ and QML code. First a pointer to a -Address object must be obtained from C++, then use the \l {QObject::property()}{property()} and -\l {QObject::setProperty()}{setProperty()} functions to get and set the \c address property. -The following gets the QGeoAddress representing this object from C++: -\snippet cpp/cppqml.cpp Address get -The following sets the properties of this object based on a QGeoAddress object from C++: -\snippet cpp/cppqml.cpp Address set - - -\section2 Location - QGeoLocation -\target location -The \l {Location::location} {Location.location} property is used to provide an interface between C++ and QML code. First a pointer to a -Location object must be obtained from C++, then use the \l {QObject::property()}{property()} and -\l {QObject::setProperty()}{setProperty()} functions to get and set the \c location property. -The following gets the QGeoLocation representing this object from C++: -\snippet cpp/cppqml.cpp Location get -The following sets the properties of this object based on a QGeoLocation object from C++: -\snippet cpp/cppqml.cpp Location set - */ diff --git a/src/location/doc/src/examples/declarative-flickr.qdoc b/src/location/doc/src/examples/declarative-flickr.qdoc deleted file mode 100644 index 99c2792d..00000000 --- a/src/location/doc/src/examples/declarative-flickr.qdoc +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example declarative/flickr - \title Flickr (QML) - \ingroup qtlocation-examples - - \brief The Flickr example shows how to use the user's current location to - fetch local content from a web service. - - This is a small example, illustrating one of the very core parts of the - Qt Location API: the ability to retrieve and use the user's current - geographic location. - - Key QML types shown in this example: - \list - \li \l{QtLocation5::PositionSource}{PositionSource} - \li \l{XmlListModel}{XmlListModel} - \endlist - - \image qml-flickr-1.jpg - - \section2 Retrieving the Current Location - - Retrieving the user's current location is achieved using the PositionSource - type. In this example, we instantiate the PositionSource as part of the - GeoTab component (the floating "window" describing current location and - status). - - \snippet flickr/flickrmobile/GeoTab.qml possrc - - When the "Locate and update" button is pressed, we first interrogate the - PositionSource to check if it has an available backend for positioning - data. If it does not, we fall back to using a pre-recorded NMEA log - for demonstration. We then instruct the PositionSource to update. - - \snippet flickr/flickrmobile/GeoTab.qml locatebutton-top - \snippet flickr/flickrmobile/GeoTab.qml locatebutton-clicked - - To share the new position data with the rest of the application, we use - properties that we have created on the GeoTab component: - - \snippet flickr/flickrmobile/GeoTab.qml props - - The longitude and latitude values retrieved here are eventually set on - in properties on the RestModel component. The RestModel is an XmlListModel, - which retrieves XML data from a URL and creates a data model by performing - XPath queries on it. - - In this case, it retrieves data from the Flickr REST API online, based on - our current location - - \snippet flickr/flickrcommon/RestModel.qml restmodel - - This model data is then shown in a variety of Qt Quick views to produce - the example application. - -*/ diff --git a/src/location/doc/src/examples/logfilepositionsource.qdoc b/src/location/doc/src/examples/logfilepositionsource.qdoc deleted file mode 100644 index 0e7ac773..00000000 --- a/src/location/doc/src/examples/logfilepositionsource.qdoc +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! -\example logfilepositionsource -\title Log File Position Source (C++) -\ingroup qtlocation-examples - -\brief The Logfile Position Source shows how to create and work with a custom NMEA position source, - for platforms without GPS. - -The data is read from a file which has positional data in NMEA format. The resulting time and -position information is then displayed to the screen as simple text in date/time and -latitude/longitude format. - -This example class reads location data from a text file, \e log.txt. The file specifies location -data using a simple text format: it contains one location update per line, where each line contains -a date/time, a latitude and a longitude, separated by spaces. The date/time is in ISO 8601 format -and the latitude and longitude are in degrees decimal format. Here is an excerpt from \e log.txt: - -\code -2009-08-24T22:25:01 -27.576082 153.092415 -2009-08-24T22:25:02 -27.576223 153.092530 -2009-08-24T22:25:03 -27.576364 153.092648 -\endcode - -The class reads this data and distributes it via the -\l{QGeoPositionInfoSource::positionUpdated()}{positionUpdated()} signal. - -Here is the definition of the \c LogFilePositionSource class: - -\quotefromfile logfilepositionsource/logfilepositionsource.h -\skipto class LogFilePositionSource -\printuntil }; - -The main methods overrided by the subclass are: - -\list - \li \l{QGeoPositionInfoSource::startUpdates()}{startUpdates()}: called by client applications - to start regular position updates. - \li \l{QGeoPositionInfoSource::stopUpdates()}{stopUpdates()}: called by client applications to - stop regular position updates. - \li \l{QGeoPositionInfoSource::requestUpdate()}{requestUpdate()}: called by client applications - to request a single update, with a specified timeout. -\endlist - -When a position update is available, the subclass emits the -\l{QGeoPositionInfoSource::positionUpdated()}{positionUpdated()} signal. - -Here are the key methods in the class implementation: - -\quotefromfile logfilepositionsource/logfilepositionsource.cpp -\skipto LogFilePositionSource::LogFilePositionSource -\printuntil /^\}/ -\skipto LogFilePositionSource::startUpdates -\printuntil /^\}/ -\skipto LogFilePositionSource::stopUpdates -\printuntil /^\}/ -\skipto LogFilePositionSource::requestUpdate -\printuntil /^\}/ -\printuntil LogFilePositionSource::readNextPosition -\printuntil /^\}/ -*/ diff --git a/src/location/doc/src/examples/qtlocation-examples.qdoc b/src/location/doc/src/examples/qtlocation-examples.qdoc index 8a7fe532..146dba76 100644 --- a/src/location/doc/src/examples/qtlocation-examples.qdoc +++ b/src/location/doc/src/examples/qtlocation-examples.qdoc @@ -34,6 +34,5 @@ These are the Qt Location examples. - \generatelist related */ diff --git a/src/location/doc/src/examples/weatherinfo.qdoc b/src/location/doc/src/examples/weatherinfo.qdoc deleted file mode 100644 index ad5ad5d5..00000000 --- a/src/location/doc/src/examples/weatherinfo.qdoc +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example weatherinfo - \title Weather Info (C++/QML) - - \brief The Weather Info example shows how to use the user's current position - to retrieve local content from a web service in a C++ plugin for QML. - - \ingroup qtlocation-examples - - Key Qt Location classes used in this example: - - \list - \li \l{QGeoPositionInfo} - \li \l{QGeoPositionInfoSource} - \endlist - - \image ../images/example-weatherinfo.png - - The key part of this example is the application's data model, contained - in the WeatherData and AppModel classes. WeatherData represents the weather - information taken from the HTTP service. It is a simple data class, but we - give it Q_PROPERTies to expose it nicely to QML, later. - - \snippet weatherinfo/appmodel.h 0 - \snippet weatherinfo/appmodel.h 1 - - AppModel models the state of the entire application. At startup, the - application first begins by waiting for network connectivity. We do - this using the QNetworkConfigurationManager and QNetworkSession family - of C++ APIs. - - \snippet weatherinfo/appmodel.cpp 0 - \snippet weatherinfo/appmodel.cpp 1 - - Once the network session is open, we proceed to get the platform's - default position source using QGeoPositionInfo::createDefaultSource() - - \snippet weatherinfo/appmodel.cpp 2 - - If no default source is available, we take a static location and fetch - weather for that. If, however, we do have a position source, we connect - its positionUpdated() signal to a slot on the AppModel and call - startUpdates(), which begins regular updates of device position. - - When a position update is received, we use the longitude and latitude - of the returned coordinate to retrieve the current "city" name for use - in the weather lookup. - - \snippet weatherinfo/appmodel.cpp 3 - - To inform the UI about this process, the cityChanged() signal is emitted - when a new city is used, and the weatherChanged() signal whenever a - weather update occurs. - - \snippet weatherinfo/appmodel.h 2 - \snippet weatherinfo/appmodel.h 3 - \snippet weatherinfo/appmodel.h 4 - - We use a QQmlListProperty for the weather forecast information, - which contains the next 4 days of forecast weather. This makes it - easy to access from QML. - - To expose these to the QML UI layer, we use the qmlRegisterType() - function. We call this once for each type we wish to register, before - loading the actual QML file. - - \snippet weatherinfo/main.cpp 0 - \snippet weatherinfo/main.cpp 1 - - Finally, in the actual QML, we instantiate the AppModel. - - \snippet weatherinfo/weatherinfo.qml 0 - \snippet weatherinfo/weatherinfo.qml 1 - \snippet weatherinfo/weatherinfo.qml 2 - - Once instantiated like this, we can use its properties elsewhere in the - QML document: - - \snippet weatherinfo/weatherinfo.qml 3 - \snippet weatherinfo/weatherinfo.qml 4 - -*/ diff --git a/src/location/doc/src/maps.qdoc b/src/location/doc/src/maps.qdoc index 99cc9bca..3426d626 100644 --- a/src/location/doc/src/maps.qdoc +++ b/src/location/doc/src/maps.qdoc @@ -147,7 +147,7 @@ varying degrees of accuracy. A geocoding query in QML is performed using the \l{QtLocation5::GeocodeModel}{GeocodeModel} type. For an address-to-coordinate query, its \c{query} property may be set to either an -\l{QtLocation5::Address}{Address} object or a string containing the textual +\l{QtPositioning5::Address}{Address} object or a string containing the textual form of the address to search for. To perform the reverse, the same property can be set to a \l {coordinate} instead. Results are made available in the contents of the model. @@ -161,7 +161,7 @@ contents of the model. \li \l{QtLocation5::GeocodeModel}{GeocodeModel} \li Queries the Plugin for geocoding translations and provides access to results via indexes in the model. \row - \li \l{QtLocation5::Address}{Address} + \li \l{QtPositioning5::Address}{Address} \li Structured address for use in queries and results of geocoding. \endtable @@ -181,13 +181,13 @@ between the segments. \b{Key Types} \table \row - \li \l{QtLocation5::Route}{Routing} + \li \l{QtLocation5::Route}{Route} \li The entire path to be navigated. \row - \li \l{QtLocation5::RouteSegment}{Segments} + \li \l{QtLocation5::RouteSegment}{RouteSegment} \li The individual components of a route. \row - \li \l{QtLocation5::RouteManeuver}{Maneuvers} + \li \l{QtLocation5::RouteManeuver}{RouteManeuver} \li The navigation information that joins segments. \row \li \l{QtLocation5::RouteModel}{RouteModel} @@ -213,6 +213,10 @@ between the segments. geographic coordinate from a street address) and navigation (including driving and walking directions). +Currently it is not possible to interact with maps via C++. Mapping applications +must use the \l {Maps and Navigation (QML)} API. + + \section1 Geocoding In C++, an address-to-coordinate query is performed using the @@ -234,4 +238,28 @@ on the same class. Instances of QGeocodingManager are available via \li \l{QGeocodeReply} \li Contains the results of a geocoding query. \endtable + +\section1 Navigation + +In C++, a route query is performed using the \l{QGeoRoutingManager::calculateRoute()}{calculate()} +method of the QGeoRoutingManager class. The returned route reply can contain +multiple routes to the same destination. + +\b{Key Classes} +\table + \row + \li \l{QGeoServiceProvider} + \li Provides a QGeocodingManager instance ready for use. + \row + \li \l{QGeoRoutingManager} + \li Accepts queries and produces QGeoRouteReply objects. + \row + \li \l{QGeoRouteReply} + \li Contains the results of a routing query. + \row + \li \l{QGeoRoute} + \li Contains information about a route. +\endtable + + */ diff --git a/src/location/doc/src/place-caveats.qdocinc b/src/location/doc/src/place-caveats.qdocinc index ce766338..d3d9bd0e 100644 --- a/src/location/doc/src/place-caveats.qdocinc +++ b/src/location/doc/src/place-caveats.qdocinc @@ -14,7 +14,7 @@ \endlist It is possible that providers may only support a subset of these. - See the \l {Qt Location Module#Plugin References and Parameters}{plugin documentation} for more + See the \l {Qt Location#Plugin References and Parameters}{plugin documentation} for more details. Saving of properties such as the rating, extended attributes, diff --git a/src/location/doc/src/place-definition.qdocinc b/src/location/doc/src/place-definition.qdocinc index d9bcc6b7..23987757 100644 --- a/src/location/doc/src/place-definition.qdocinc +++ b/src/location/doc/src/place-definition.qdocinc @@ -17,7 +17,7 @@ QPlace::detailsFetched() function can be queried to see if all available details have been fetched, and if not, QPlaceManager::getPlaceDetails() can be used to retrieve them. Precisely which details are populated during a search and which need to be fetched individually may vary from provider to -provider. See \l {Qt Location Module#Plugin References and Parameters}{plugin documentation} for +provider. See \l {Qt Location#Plugin References and Parameters}{plugin documentation} for more details. The rich content of a place consists of items such as images, reviews and diff --git a/src/location/doc/src/plugins/nokia_terms.qdoc b/src/location/doc/src/plugins/nokia_terms.qdoc index c10bbbf0..2f29a60f 100644 --- a/src/location/doc/src/plugins/nokia_terms.qdoc +++ b/src/location/doc/src/plugins/nokia_terms.qdoc @@ -36,6 +36,6 @@ src/plugins/geoservices/nokia/NOKIA_TERMS_AND_CONDITIONS.txt in the Qt Location package. The terms and conditions are reproduced below for convenience. \legalese -\include plugins/geoservices/nokia/NOKIA_TERMS_AND_CONDITIONS.txt +\include NOKIA_TERMS_AND_CONDITIONS.txt.qdocinc \endlegalese */ diff --git a/src/location/doc/src/position.qdoc b/src/location/doc/src/position.qdoc deleted file mode 100644 index 75f54c31..00000000 --- a/src/location/doc/src/position.qdoc +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! -\page location-positioning-cpp.html - -\title Positioning (C++) - -\brief The Location Positioning API enables location positioning by means of -GPS or an NMEA data source. - -\section1 Positioning - -The Positioning component of the Qt Location API is about the geographical position, size -and address of some place. Positioning contains a QGeoCoordinate class, containing latitude, longitude and altitude in meters. QGeoLocation contains a QGeoCoordinate plus address -and size information (a bounding box) so that positions can be more than mathematical points. -Movement into or out of the defined bounding box areas can be monitored. The API -also allows the developer to control the source of the positional information -as well. - -Location data involves a precisely specified position on the Earth's -surface \unicode {0x2014} as provided by a latitude-longitude coordinate -\unicode {0x2014} along with associated data, such as: - - \list - \li The date and time at which the position was reported - \li The velocity of the device that reported the position - \li The altitude of the reported position (height above sea level) - \li The bearing of the device in degrees, relative to true north - \endlist - -This data can be extracted through a variety of methods. One of the most -well known methods of positioning is GPS (Global Positioning System), a -publicly available system that uses radiowave signals received from -Earth-orbiting satellites to calculate the precise position and time of -the receiver. Another popular method is 'Cell Identifier Positioning', which uses -the cell identifier of the cell site that is currently serving the receiving -device to calculate its approximate location. These and other positioning -methods can all be used with the Location API; the only requirement for a -location data source within the API is that it provides a -latitude-longitude coordinate with a date/time value, with the option of -providing the other attributes listed above. - - -Location data sources are created by subclassing QGeoPositionInfoSource and -providing QGeoPositionInfo objects through the -QGeoPositionInfoSource::positionUpdated() signal. Clients that require -location data can connect to the -\l{QGeoPositionInfoSource::positionUpdated()}{positionUpdated()} signal and -call \l{QGeoPositionInfoSource::startUpdates()}{startUpdates()} or -\l{QGeoPositionInfoSource::requestUpdate()}{requestUpdate()} to trigger the -distribution of location data. The location data distribution can be stopped by -calling the \l {QGeoPositionInfoSource::stopUpdates()}{stopUpdates()} function. - -A default position source may be available on some platforms. Call -QGeoPositionInfoSource::createDefaultSource() to create an instance of the default -position source; the method returns 0 if no default source is available for -the platform. - -If a problem occurs with access to the information source then an -\l {QGeoPositionInfoSource::error()}{error()} signal is emitted. - -The QGeoAreaMonitor class enables client applications to be notified when -the receiving device has moved in or out of a particular area, as specified -by a coordinate and radius. If the platform provides built-in support for -area monitoring, QGeoAreaMonitor::createDefaultMonitor() returns an instance of -the default area monitor. - -Satellite information can also be distributed through the -QGeoSatelliteInfoSource class. Call QGeoSatelliteInfoSource::createDefaultSource() to -create an instance of the default satellite data source for the platform, -if one is available. Alternatively, clients can subclass it to provide a -custom satellite data source. - - - -\section2 Requesting Location Data from Data Sources - -To receive data from a source, connect to its -\l{QGeoPositionInfoSource::positionUpdated()}{positionUpdated()} signal, -then call either \l{QGeoPositionInfoSource::startUpdates()}{startUpdates()} -or \l{QGeoPositionInfoSource::requestUpdate()}{requestUpdate()} to begin. - -Here is an example of a client that receives data from the default location -data source, as returned by QGeoPositionInfoSource::createDefaultSource(): - -\code -class MyClass : public QObject -{ - Q_OBJECT -public: - MyClass(QObject *parent = 0) - : QObject(parent) - { - QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this); - if (source) { - connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)), - this, SLOT(positionUpdated(QGeoPositionInfo))); - source->startUpdates(); - } - } - -private slots: - void positionUpdated(const QGeoPositionInfo &info) - { - qDebug() << "Position updated:" << info; - } -}; - -\endcode - -\section2 Controlling Aspects of Data Sources - -The QGeoPositionInfoSource::setUpdateInterval() method can be used to -control the rate at which position updates are received. For example, if -the client application only requires updates once every 30 seconds, it can -call \c setUpdateInterval(30000). (If no update interval is set, or -\l {QGeoPositionInfoSource::}{setUpdateInterval()} is called with a value of 0, the source uses a default -interval or some other internal logic to determine when updates should be -provided.) - -QGeoPositionInfoSource::setPreferredPositioningMethods() enables client -applications to request that a certain type of positioning method be used. -For example, if the application prefers to use only satellite positioning, -which offers fairly precise outdoor positioning but can be a heavy user of -power resources, it can call this method with the -QGeoPositionInfoSource::SatellitePositioningMethods value. However, this -method should only be used in specialized client applications; in most -cases, the default positioning methods should not be changed, as a source -may internally use a variety of positioning methods that can be useful to -the application. - -\section2 NMEA Data - -\l {http://en.wikipedia.org/wiki/NMEA_0183}{NMEA} is a common text-based -protocol for specifying navigational data. For convenience, the -QNmeaPositionInfoSource is provided to enable client applications to read -and distribute NMEA data in either real-time mode (for example, when -streaming from a GPS device) or simulation mode (for example, when reading -from a NMEA log file). In simulation mode, the source will emit updates -according to the time stamp of each NMEA sentence to produce a "replay" -of the recorded data. - -Generally, the capabilities provided by the default position source as -returned by QGeoPositionInfoSource::createDefaultSource(), along with the -QNmeaPositionInfoSource class, are sufficient for retrieving location -data. However, in some cases developers may wish to write their own custom -location data source. - -The \l {Log File Position Source (C++)} example demonstrates how to subclass QGeoPositionInfoSource -to create a custom positioning source. - - -\section1 Examples - -\section3 \b{Flickr Example} - -The \l{Flickr QML}{Flickr Example} uses the Location to download thumbnail -images from Flickr relevant to the current location. - - - -\section1 Location Position Classes - -\annotatedlist QtLocation-positioning - -*/ diff --git a/src/location/doc/src/qml-maps.qdoc b/src/location/doc/src/qml-maps.qdoc index 45cf82f4..f63cc5a4 100644 --- a/src/location/doc/src/qml-maps.qdoc +++ b/src/location/doc/src/qml-maps.qdoc @@ -53,15 +53,41 @@ Interaction with the added items, and the \l Map itself, is handled by \l MapMou are added as children of the \l {Maps and Navigation (QML)#Putting Objects on a Map (Map Overlay Objects)}{MapItems} or \l Map. -\section2 Position +\section2 Position on map +All position APIs are part of the \l {QtPositioning} module. The basic piece of position information is the \l {coordinate}. A coordinate encapsulates data for the latitude, longitude and altitude of the location. Altitude is in meters. It also has a method to determine distance to another \l {coordinate}. The \l {coordinate} type may -also be held within a \l {QtLocation5::Location}{Location} element, this will also have information +also be held within a \l {QtPositioning5::Location}{Location} element, this will also have information on a bounding box size to determine sufficient proximity to the location and a location address. + +Here is an example of a client that uses a \l{PositionSource}{position source} +to center a \l{Map}{map} on the current position: + +\code + Rectangle { + + import QtPositioning 5.0 + import QtLocation 5.0 + ... + + map : Map { + // initialize map + ... + } + + PositionSource { + onPositionChanged: { + // center the map on the current position + map.center = position.coordinate + } + } + } +\endcode + \section2 Geocoding \l {http://en.wikipedia.org/wiki/Geocoding}{Geocoding} is the derivation of @@ -194,9 +220,6 @@ example, by implementing the \c onValueChanged handler to update the Map \section1 Types -\section3 Positioning -\annotatedlist qml-QtLocation5-positioning - \section3 Maps \annotatedlist qml-QtLocation5-maps diff --git a/src/location/doc/src/qml-position.qdoc b/src/location/doc/src/qml-position.qdoc deleted file mode 100644 index 9553f6d2..00000000 --- a/src/location/doc/src/qml-position.qdoc +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! -\page location-positioning-qml.html - -\title Positioning (QML) - -\brief The Location Positioning API enables location positioning by means of -GPS or an NMEA data source. - -\section1 Location Positioning - -Location data involves a precisely specified position on the Earth's -surface \unicode {0x2014} as provided by a latitude-longitude coordinate -\unicode {0x2014} along with associated data, such as: - - \list - \li The date and time at which the position was reported - \li The velocity of the device that reported the position - \li The altitude of the reported position (height above sea level) - \li The bearing of the device in degrees, relative to true north - \endlist - -For more information see -\l {http://en.wikipedia.org/wiki/Geographic_coordinate}{Geographic Coordinate}. - -This data can be extracted through a variety of methods. One of the most -well known methods of positioning is GPS (Global Positioning System), a -publicly available system that uses radiowave signals received from -Earth-orbiting satellites to calculate the precise position and time of -the receiver. Another popular method is 'Cell Identifier Positioning', which uses -the cell identifier of the cell site that is currently serving the receiving -device to calculate its approximate location. These and other positioning -methods can all be used with the Location API; the only requirement for a -location data source within the API is that it provides a -latitude-longitude coordinate with a date/time value, with the option of -providing the other attributes listed above. - -\section2 Coordinate - -The \l {coordinate} is a basic unit of geographical information. The -\l {coordinate} type has attributes to hold the \c {latitude}, -\c longitude and \c altitude. - -\section2 Position - -The three dimensional position of an object such as a mobile device can be specified by giving -the latitude, longitude and altitude. That is the values held in the -l\ {coordinate} type. Additionally for computation of future -positions we would like to know if the object is moving, what \l {Position::speed}{speed} it is -doing and what is the \l {Position::timestamp}{timestamp} of the last position data. Position -therefore includes values for the \l {Position::coordinate}{coordinate}, -\l {Position::speed}{speed} and a \l {Position::timestamp}{timestamp}. \l Position also takes -responsibility for validation of sensible values for these properties. These are exposed as -the \l {Position::latitudeValid}{latitudeValid}, \l {Position::longitudeValid}{longitudeValid}, -\l {Position::altitudeValid}{altitudeValid}, \l {Position::speedValid}{speedValid}, -\l {Position::horizontalAccuracyValid}{horizontalAccuracyValid}, and -\l {Position::verticalAccuracyValid}{verticalAccuracyValid} properties. - - -\section2 PositionSource - -We have a Position type, a \l {coordinate} type but where does the data come from? -Also it is a good idea to be able to indicate alternative sources. -Perhaps instead of directly picking up GPS satellites it might be desirable to do -some testing using a datafile. - -The \l PositionSource type provides the developer with control, -within the limits allowed by the platform, of the source of the -geographical data. Apart from tradtional sources such as GPS and cell data the positional data can be -sourced from a logfile which is in NMEA format. - -\l {http://en.wikipedia.org/wiki/NMEA}{NMEA} is a common text-based protocol for specifying navigational data. For convenience, the \l {PositionSource::nmeaSource}{nmeaSource} property is provided to enable QML applications to read NMEA data from a log file, the source will emit updates according to the time stamp of each NMEA sentence to produce a "replay" of the recorded data. - - -\section2 Example: Centering the Map on the Current Position - -Here is an example of a client that uses a \l{PositionSource}{position source} -to center a \l{Map}{map} on the current position: - -\code -Rectangle { - - import QtLocation 5.0 - ... - - map : Map { - // initialize map - ... - } - - PositionSource { - onPositionChanged: { - // center the map on the current position - map.center = position.coordinate - } - } -} -\endcode - - -\section2 \b{Flickr Example} - -The \l{Flickr (QML)}{Flickr Example} uses the Location to download thumbnail -images from Flickr relevant to the current location. - - -\section1 Position QML Components - -\annotatedlist qml-QtLocation5-positioning -*/ diff --git a/src/location/doc/src/qtlocation-cpp.qdoc b/src/location/doc/src/qtlocation-cpp.qdoc index c13360b5..0c0f946d 100644 --- a/src/location/doc/src/qtlocation-cpp.qdoc +++ b/src/location/doc/src/qtlocation-cpp.qdoc @@ -30,17 +30,16 @@ \title Qt Location C++ API \brief Information about the Qt Location C++ API -The Location API provides a library for location positioning, mapping and navigation. +The Location API provides a library for mapping, navigation and place information. \tableofcontents -The Qt Location API provides the developer with a set of functions for determining -the current location and using that information with maps and places of interest. +The Qt Location API provides the developer with a set of functions to interact +with maps, navigational data and places of interest. This is particularly useful +when associated with current position information which can be retrieved via the +\l QtPositioning module. -Positioning information can be sourced from GPS satellites or a stream of data using -NMEA formatted text. Once a position is acquired we can monitor the updated -position to see if it moves into or out of a given region. With the Maps API -we can associate the position with a map in various formats supplied by a backend. +With the Maps API we can associate a position with a map in various formats supplied by a backend. Then the Places API could be used to populate places on the Map or even specify the current position as a place of interest and associate it with an icon, contact details and other information. @@ -49,9 +48,6 @@ The following table provides links to more detailed information on sections of t Qt Location C++ API. \table - \row - \li \l {Positioning (C++)}{Location Positioning} - \li Retrieving information about the current position. \row \li \l {Maps and Navigation (C++)}{Maps and Navigation} \li Displaying maps and finding routes. @@ -59,16 +55,11 @@ Qt Location C++ API. \li \l {Places (C++)} {Places} \li Searching for and managing points of interest. \row - \li \l {Qt Location GeoServices}{Geoservices and Positioning Plugin Implementation} + \li \l {Qt Location GeoServices}{Geoservices Plugin Implementation} \li Implement new geoservices and positioning plugins. \endtable -\section1 Positioning Classes - - \annotatedlist QtLocation-positioning - - \section1 Geoservice Provider Classes \annotatedlist QtLocation-common @@ -76,6 +67,8 @@ Qt Location C++ API. \section1 Maps and Navigation Classes +Currently it is not possible to interact with maps data via C++. The only available interface is the \l {Maps and Navigation (QML)} API. + \annotatedlist QtLocation-maps \annotatedlist QtLocation-routing diff --git a/src/location/doc/src/qtlocation-geoservices.qdoc b/src/location/doc/src/qtlocation-geoservices.qdoc index 7adb9b18..85c96b0f 100644 --- a/src/location/doc/src/qtlocation-geoservices.qdoc +++ b/src/location/doc/src/qtlocation-geoservices.qdoc @@ -33,29 +33,59 @@ The Qt Location provides the majority of its functionality through GeoService plugins. This document outlines how to develop a new GeoService plugin. +\section1 Plugin description + +Each plugin is described by a json file. The json describes the plugins capabilities and +version. Below is an example of a json file used by the OpenStreenMap plugin: + + +\quotefile ../../../plugins/geoservices/osm/osm_plugin.json + +The entries have the following meaning: + +\table + \header + \li Key + \li Description + \row + \li Keys + \li The unique name/key of the plugin. Each GeoService plugin must have a unique name. + \row + \li Provider + \li The provider name of the services. Multiple plugins may have the same name. + In such cases the Version string will be used to further distinguish the plugins. + \row + \li Experimental + \li Marks the service plugin as experimental. API developers may choose to ignore + such plugins when instanciating \l QGeoServiceProvider::QGeoServiceProvider(). + \row + \li Version + \li The plugin version. If multiple plugins have the same provider name, the plugin + with the higest version will be used. + \row + \li Features + \li List of features provided by the plugin/service. Each feature is a string + representation of the corresponding features in \l QGeoServiceProvider. For more + details see \l QGeoServiceProvider::routingFeatures(), + \l QGeoServiceProvider::geocodingFeatures() and \l QGeoServiceProvider::placesFeatures(). + +\endtable + \section1 Implementing Plugins A plugin implementer needs to subclass QGeoServiceProviderFactory and as many of the ManagerEngine classes as they want to provide implementations for. -Subclassing QGeoServiceProviderFactory will only involve exposing a name and -a version by overriding QGeoServiceProviderFactory::providerName() and -QGeoServiceProviderFactory::providerVersion(), and overriding -QGeoServiceProviderFactory::createSearchManagerEngine(), -QGeoServiceProviderFactory::createMappingManagerEngine() and -QGeoServiceProviderFactory::createRoutingManagerEngine() as appropriate. - -\section3 Tile-Based Map Convenience Classes - -Most of the current tile based mapping APIs are very similar, and so we -provide a number of classes intended to make writing tile based mapping -plugins much simpler. +Subclassing QGeoServiceProviderFactory will only involves overriding of one of the following +methods: -If the Mercator projection and the most common tile addressing scheme is used this will mainly -involve subclassing QGeoTiledMappingManagerEngine and providing an implementation of -QGeoTiledMappingManagerEngine::getTileImage(). +\list + \li \l QGeoServiceProviderFactory::createGeocodingManagerEngine() + \li \l QGeoServiceProviderFactory::createRoutingManagerEngine() + \li \l QGeoServiceProviderFactory::createPlaceManagerEngine() +\endlist -\section1 GeoService Classes +If a plugin does not provide an engine the relevant function should return 0. \annotatedlist QtLocation-impl diff --git a/src/location/doc/src/qtlocation-qml.qdoc b/src/location/doc/src/qtlocation-qml.qdoc index 351552de..a24820bd 100644 --- a/src/location/doc/src/qtlocation-qml.qdoc +++ b/src/location/doc/src/qtlocation-qml.qdoc @@ -40,22 +40,9 @@ statement in the QML file. \section2 Location QML Concepts -Position information can come from a variety of sources including satellites, -wifi, text files and so on. The position is described by the latitude, -the longitude, and the altitude in meters. For more information see -\l {http://en.wikipedia.org/wiki/Geographic_coordinate}{Geographic Coordinate}. - -The QML position is stored in a \l {coordinate} which contains the -latitude, longitude and altitude of the device. The \l {QtLocation5::Location}{Location} contains -this \l {coordinate} and adds an address, it also has a bounding box which -defines the recommended viewing region when displaying the location. - -Now that the device has a position, with regular updates the API can determine -the speed and heading of the device. It can also define a box or a circle that can -produce a notification when the device either leaves or enters that region. - -Adding a \l {QtLocation5::Map}{Map} with positions of interest and -\l {QtLocation5::Place}{Places}, then the device can be made aware of nearby features and related +Provided that a position has been obtained this module can +add a \l {QtLocation5::Map}{Map} with positions of interest and +\l {QtLocation5::Place}{Places}. The user can be made aware of nearby features and related information, displayed graphically. Features on the \l Map may be places of business, entertainment and so on. They may include paths, roads, or forms of transport leading so that navigation optimization and assistance are possible. @@ -100,9 +87,6 @@ The following table provides links to more detailed information on sections of t API. \table - \row - \li \l {Positioning (QML)}{Location Positioning} - \li Retrieving information about the current position. \row \li \l {Maps and Navigation (QML)}{Maps and Navigation} \li Displaying maps and finding routes. @@ -111,18 +95,10 @@ API. \li Searching for and managing points of interest. \endtable -\section1 Basic Types - -\annotatedlist qml-QtLocation5-basictypes - \section1 Common QML Types \annotatedlist qml-QtLocation5-common -\section1 Positioning QML Types - -\annotatedlist qml-QtLocation5-positioning - \section1 Maps QML Types \annotatedlist qml-QtLocation5-maps diff --git a/src/location/doc/src/qtlocation.qdoc b/src/location/doc/src/qtlocation.qdoc index 06cd6d58..dc3fc14d 100644 --- a/src/location/doc/src/qtlocation.qdoc +++ b/src/location/doc/src/qtlocation.qdoc @@ -50,9 +50,7 @@ The .pro file should have the \e location keyword added - \code - QT += location - \endcode + \code QT += location \endcode See more in the \l{Qt Location}{Qt Location Overview}. @@ -98,25 +96,12 @@ for example applications using routes may use The .pro file should have the \e location keyword added -\code - QT += location -\endcode +\code QT += location \endcode \section2 API Sub-Modules -The API is split into three core sub-modules, which each have QML and C++ -APIs. - -\section3 Positioning -Positioning includes all the functionality necessary to find and work with geographic -coordinates. It can use a variety of external sources of information, including GPS. This -provides us with a coordinate and altitude for the device with additional features -such as speed and direction. This provides the fundamental location information used in the API. -\table -\row - \li Positioning introduction: - \li \l{Positioning (QML)}{for QML} - \li \l{Positioning (C++)}{for C++} -\endtable +The API is split into sub-modules, which each have QML and C++ APIs. It focuses on +Map and Place information. The required position data can be retrieved via the +\l {QtPositioning} module. \section3 Places Places is diff --git a/src/location/location.pro b/src/location/location.pro index 5a053632..2ba446b6 100644 --- a/src/location/location.pro +++ b/src/location/location.pro @@ -1,54 +1,16 @@ TARGET = QtLocation -QT = core-private +QT = core-private positioning QMAKE_DOCS = $$PWD/doc/qtlocation.qdocconf OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator PUBLIC_HEADERS += \ - qgeoaddress.h \ - qgeoareamonitor.h \ - qgeoshape.h \ - qgeorectangle.h \ - qgeocircle.h \ - qgeocoordinate.h \ - qgeolocation.h \ - qgeopositioninfo.h \ - qgeopositioninfosource.h \ - qgeosatelliteinfo.h \ - qgeosatelliteinfosource.h \ - qnmeapositioninfosource.h \ - qgeopositioninfosourcefactory.h \ qlocation.h \ qlocationglobal.h -PRIVATE_HEADERS += \ - qgeoaddress_p.h \ - qgeoshape_p.h \ - qgeorectangle_p.h \ - qgeocircle_p.h \ - qgeolocation_p.h \ - qlocationutils_p.h \ - qnmeapositioninfosource_p.h \ - qgeocoordinate_p.h \ - qgeopositioninfosource_p.h - SOURCES += \ - qgeoaddress.cpp \ - qgeoareamonitor.cpp \ - qgeoshape.cpp \ - qgeorectangle.cpp \ - qgeocircle.cpp \ - qgeocoordinate.cpp \ - qgeolocation.cpp \ - qgeopositioninfo.cpp \ - qgeopositioninfosource.cpp \ - qgeosatelliteinfo.cpp \ - qgeosatelliteinfosource.cpp \ - qlocationutils.cpp \ - qnmeapositioninfosource.cpp \ - qgeopositioninfosourcefactory.cpp \ - qlocation.cpp + qlocation.cpp qtHaveModule(3d): include(maps/maps.pri) include(places/places.pri) diff --git a/src/location/maps/qgeocodereply.h b/src/location/maps/qgeocodereply.h index 9d492a0e..1f36633f 100644 --- a/src/location/maps/qgeocodereply.h +++ b/src/location/maps/qgeocodereply.h @@ -44,7 +44,9 @@ #include #include -#include +#include + +#include QT_BEGIN_NAMESPACE diff --git a/src/location/maps/qgeocodingmanager.h b/src/location/maps/qgeocodingmanager.h index 94b2d50a..6604c25d 100644 --- a/src/location/maps/qgeocodingmanager.h +++ b/src/location/maps/qgeocodingmanager.h @@ -43,7 +43,7 @@ #define QGEOCODINGMANAGER_H #include -#include +#include #include #include diff --git a/src/location/maps/qgeocodingmanagerengine.cpp b/src/location/maps/qgeocodingmanagerengine.cpp index 96508e0b..3ba59f68 100644 --- a/src/location/maps/qgeocodingmanagerengine.cpp +++ b/src/location/maps/qgeocodingmanagerengine.cpp @@ -45,7 +45,7 @@ #include "qgeoaddress.h" #include "qgeocoordinate.h" -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/location/maps/qgeocoordinateinterpolator_p.h b/src/location/maps/qgeocoordinateinterpolator_p.h index 6a6e3a21..1b75bfb4 100644 --- a/src/location/maps/qgeocoordinateinterpolator_p.h +++ b/src/location/maps/qgeocoordinateinterpolator_p.h @@ -52,7 +52,8 @@ // We mean it. // -#include "qgeocoordinate.h" +#include +#include QT_BEGIN_NAMESPACE diff --git a/src/location/maps/qgeoprojection_p.h b/src/location/maps/qgeoprojection_p.h index f8b5b32d..4dcf8b4c 100644 --- a/src/location/maps/qgeoprojection_p.h +++ b/src/location/maps/qgeoprojection_p.h @@ -56,7 +56,7 @@ #define M_PI (3.14159265358979323846) #endif -#include "qglobal.h" +#include #include QT_BEGIN_NAMESPACE diff --git a/src/location/maps/qgeoroute.h b/src/location/maps/qgeoroute.h index 0eb163f9..67287649 100644 --- a/src/location/maps/qgeoroute.h +++ b/src/location/maps/qgeoroute.h @@ -42,7 +42,7 @@ #ifndef QGEOROUTE_H #define QGEOROUTE_H -#include +#include #include #include diff --git a/src/location/maps/qgeorouterequest.h b/src/location/maps/qgeorouterequest.h index 7eb3fcba..bcc7d6ea 100644 --- a/src/location/maps/qgeorouterequest.h +++ b/src/location/maps/qgeorouterequest.h @@ -47,7 +47,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/location/maps/qgeoserviceprovider.cpp b/src/location/maps/qgeoserviceprovider.cpp index 25784421..dcfe326c 100644 --- a/src/location/maps/qgeoserviceprovider.cpp +++ b/src/location/maps/qgeoserviceprovider.cpp @@ -103,8 +103,13 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, Subclasses of QGeoServiceProvider guarantee that the different services that they provide are interoperable. - At this point only the Nokia Services plugin is packaged with Qt, - which is accessible using the provider name "nokia". + At this point there are two GeoServices plugins packaged with Qt. They are + accessible using their provider names: + + \list + \li "osm" -> \l {Qt Location Open Street Map Plugin}{OpenStreetMap} + \li "nokia" -> \l {Qt Location Nokia Plugin}{Nokia Services} + \endlist */ /*! diff --git a/src/location/maps/qgeoserviceproviderfactory.cpp b/src/location/maps/qgeoserviceproviderfactory.cpp index 2f282a67..e12e3515 100644 --- a/src/location/maps/qgeoserviceproviderfactory.cpp +++ b/src/location/maps/qgeoserviceproviderfactory.cpp @@ -101,6 +101,8 @@ QGeocodingManagerEngine *QGeoServiceProviderFactory::createGeocodingManagerEngin The default implementation returns 0, which causes a QGeoServiceProvider::NotSupportedError in QGeoServiceProvider. + + \internal */ QGeoMappingManagerEngine *QGeoServiceProviderFactory::createMappingManagerEngine(const QMap ¶meters, QGeoServiceProvider::Error *error, diff --git a/src/location/places/qplace.h b/src/location/places/qplace.h index b6eee885..5f5f0597 100644 --- a/src/location/places/qplace.h +++ b/src/location/places/qplace.h @@ -43,10 +43,10 @@ #define QPLACE_H #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/src/location/qgeoaddress.cpp b/src/location/qgeoaddress.cpp deleted file mode 100644 index 31cec9ab..00000000 --- a/src/location/qgeoaddress.cpp +++ /dev/null @@ -1,637 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgeoaddress.h" -#include "qgeoaddress_p.h" - -#include - -#ifdef QGEOADDRESS_DEBUG -#include -#endif - -QT_BEGIN_NAMESPACE - -/* - Combines a list of address parts into a single line. - - The parts parameter contains both address elements such as city, state and so on - as well as separators such as spaces and commas. - - It is expected that an element is always followed by a separator and the last - sepator is usually a new line delimeter. - - For example: Springfield, 8900 - would have four parts - ["Springfield", ", ", "8900", "
"] - - The addressLine takes care of putting in separators appropriately or leaving - them out depending on whether the adjacent elements are present or not. - For example if city were empty in the above scenario the returned string is "8900
" - If the postal code was empty, returned string is "Springfield
" - If both city and postal code were empty, the returned string is "". -*/ -static QString addressLine(const QStringList &parts) -{ - QString line; - Q_ASSERT(parts.count() % 2 == 0); - - //iterate until just before the last pair - QString penultimateSeparator; - for (int i = 0; i < parts.count() - 2; i += 2) { - if (!parts.at(i).isEmpty()) { - line.append(parts.at(i) + parts.at(i + 1)); - penultimateSeparator = parts.at(i + 1); - } - } - - if (parts.at(parts.count() - 2).isEmpty()) { - line.chop(penultimateSeparator.length()); - - if (!line.isEmpty()) - line.append(parts.at(parts.count() - 1)); - } else { - line.append(parts.at(parts.count() - 2)); - line.append(parts.at(parts.count() - 1)); - } - - return line; -} - -/* - Returns a single formatted string representing the \a address. Lines of the address - are delimited by \a newLine. By default lines are delimited by
. The \l - {QGeoAddress::countryCode} {countryCode} of the \a address determines the format of - the resultant string. -*/ -static QString formattedAddress(const QGeoAddress &address, - const QString &newLine = QLatin1String("
")) -{ - const QString Comma(QLatin1String(", ")); - const QString Dash(QLatin1String("-")); - const QString Space(QLatin1String(" ")); - - QString text; - - if (address.countryCode() == QLatin1String("ALB") - || address.countryCode() == QLatin1String("MTQ")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.postalCode() << Comma - << address.city() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("AND") - || address.countryCode() == QLatin1String("AUT") - || address.countryCode() == QLatin1String("FRA") - || address.countryCode() == QLatin1String("GLP") - || address.countryCode() == QLatin1String("GUF") - || address.countryCode() == QLatin1String("ITA") - || address.countryCode() == QLatin1String("LUX") - || address.countryCode() == QLatin1String("MCO") - || address.countryCode() == QLatin1String("REU") - || address.countryCode() == QLatin1String("RUS") - || address.countryCode() == QLatin1String("SMR") - || address.countryCode() == QLatin1String("VAT")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.postalCode() << Space - << address.city() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("ARE") - || address.countryCode() == QLatin1String("BHS")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Space - << address.city() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("AUS")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << (address.district().isEmpty() ? address.city() : address.district()) - << Space << address.state() << Space << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("BHR")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Comma - << address.city() << Comma << address.state() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("BRA")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Space - << address.city() << Dash << address.state() << Space << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("BRN") - || address.countryCode() == QLatin1String("JOR") - || address.countryCode() == QLatin1String("LBN") - || address.countryCode() == QLatin1String("NZL")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Space - << address.city() << Space << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("CAN") - || address.countryCode() == QLatin1String("USA") - || address.countryCode() == QLatin1String("VIR")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.city() << Comma << address.state() << Space - << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("CHN")) { - text += addressLine(QStringList() << address.street() << Comma << address.city() << newLine); - text += addressLine(QStringList() << address.postalCode() << Space << address.state() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("CHL")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.postalCode() << Space - << address.district() << Comma << address.city() << Comma - << address.state() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("CYM")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.state() << Space - << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("GBR")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Comma - << address.city() << Comma << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("GIB")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.city() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("HKG")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << newLine); - text += addressLine(QStringList() << address.city() << newLine); - } else if (address.countryCode() == QLatin1String("IND")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.city() << Space << address.postalCode() << Space - << address.state() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("IDN") - || address.countryCode() == QLatin1String("JEY") - || address.countryCode() == QLatin1String("LVA")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.city() << Comma << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("IRL")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Comma << address.state() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("KWT")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.postalCode() << Comma - << address.district() << Comma << address.city() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("MLT") - || address.countryCode() == QLatin1String("SGP") - || address.countryCode() == QLatin1String("UKR")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("MEX")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << newLine); - text += addressLine(QStringList() << address.postalCode() << Space << address.city() << Comma - << address.state() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("MYS")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine); - text += addressLine(QStringList() << address.state() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("OMN")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Comma - << address.postalCode() << Comma - << address.city() << Comma - << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("PRI")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Comma << address.city() << Comma - << address.state() << Comma << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("QAT")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Space << address.city() << Comma - << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("SAU")) { - text += addressLine(QStringList() << address.street() << Space << address.district() << newLine); - text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("TWN")) { - text += addressLine(QStringList() << address.street() << Comma - << address.district() << Comma << address.city() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("THA")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Comma << address.city() << Space - << address.postalCode() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("TUR")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.postalCode() << Space << address.district() << Comma - << address.city() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("VEN")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.city() << Space << address.postalCode() << Comma - << address.state() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else if (address.countryCode() == QLatin1String("ZAF")) { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.district() << Comma << address.city() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } else { - text += addressLine(QStringList() << address.street() << newLine); - text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine); - text += addressLine(QStringList() << address.country() << newLine); - } - - text.chop(newLine.length()); - return text; -} - -QGeoAddressPrivate::QGeoAddressPrivate() - : QSharedData(), - m_autoGeneratedText(false) -{ -} - -QGeoAddressPrivate::QGeoAddressPrivate(const QGeoAddressPrivate &other) - : QSharedData(other), - sCountry(other.sCountry), - sCountryCode(other.sCountryCode), - sState(other.sState), - sCounty(other.sCounty), - sCity(other.sCity), - sDistrict(other.sDistrict), - sStreet(other.sStreet), - sPostalCode(other.sPostalCode), - sText(other.sText), - m_autoGeneratedText(false) -{ -} - -QGeoAddressPrivate::~QGeoAddressPrivate() -{ -} - -/*! - \class QGeoAddress - \inmodule QtLocation - \ingroup QtLocation-positioning - \ingroup QtLocation-places-data - \ingroup QtLocation-places - \since Qt Location 5.0 - - \brief The QGeoAddress class represents an address of a \l QGeoLocation. - - The address' attributes are normalized to US feature names and can be mapped - to the local feature levels (for example State matches "Bundesland" in Germany). - - The address contains a \l text() for displaying purposes and additional - properties to access the components of an address: - - \list - \li QGeoAddress::country() - \li QGeoAddress::countryCode() - \li QGeoAddress::state() - \li QGeoAddress::city() - \li QGeoAddress::district() - \li QGeoAddress::street() - \li QGeoAddress::postalCode() - \endlist -*/ - -/*! - Default constructor. -*/ -QGeoAddress::QGeoAddress() - : d(new QGeoAddressPrivate) -{ -} - -/*! - Constructs a copy of \a other. -*/ -QGeoAddress::QGeoAddress(const QGeoAddress &other) - : d(other.d) -{ -} - -/*! - Destroys this address. -*/ -QGeoAddress::~QGeoAddress() -{ -} - -/*! - Assigns the given \a address to this address and - returns a reference to this address. -*/ -QGeoAddress &QGeoAddress::operator=(const QGeoAddress & address) -{ - if (this == &address) - return *this; - - d = address.d; - return *this; -} - -/*! - Returns true if this address is equal to \a other, - otherwise returns false. -*/ -bool QGeoAddress::operator==(const QGeoAddress &other) const -{ -#ifdef QGEOADDRESS_DEBUG - qDebug() << "country" << (d->sCountry == other.country()); - qDebug() << "countryCode" << (d->sCountryCode == other.countryCode()); - qDebug() << "state:" << (d->sState == other.state()); - qDebug() << "county:" << (d->sCounty == other.county()); - qDebug() << "city:" << (d->sCity == other.city()); - qDebug() << "district:" << (d->sDistrict == other.district()); - qDebug() << "street:" << (d->sStreet == other.street()); - qDebug() << "postalCode:" << (d->sPostalCode == other.postalCode()); - qDebug() << "text:" << (text() == other.text()); -#endif - - return d->sCountry == other.country() && - d->sCountryCode == other.countryCode() && - d->sState == other.state() && - d->sCounty == other.county() && - d->sCity == other.city() && - d->sDistrict == other.district() && - d->sStreet == other.street() && - d->sPostalCode == other.postalCode() && - this->text() == other.text(); -} - -/*! - \fn bool QGeoAddress::operator!=(const QGeoAddress &other) const - - Returns true if this address is not equal to \a other, - otherwise returns false. -*/ - -/*! - Returns the address as a single formatted string. It is the recommended string - to use to display the address to the user. It typically takes the format of - an address as found on an envelope, but this is not always necessarily the case. - - The adddress text is either automatically generated or explicitly assigned. - This can be determined by checking \l {QGeoAddress::isTextGenerated()} {isTextGenerated}. - - If an empty string is provided to setText(), then isTextGenerated() will be set - to true and text() will return a string which is locally formatted according to - countryCode() and based on the elements of the address such as street, city and so on. - Because the text string is generated from the address elements, a sequence - of calls such as text(), setStreet(), text() may return different strings for each - invocation of text(). - - If a non-empty string is provided to setText(), then isTextGenerated() will be - set to false and text() will always return the explicitly assigned string. - Calls to modify other elements such as setStreet(), setCity() and so on will not - affect the resultant string from text(). -*/ -QString QGeoAddress::text() const -{ - if (d->sText.isEmpty()) - return formattedAddress(*this); - else - return d->sText; -} - -/*! - If \a text is not empty, explicitly assigns \a text as the string to be returned by - text(). isTextGenerated() will return false. - - If \a text is empty, indicates that text() should be automatically generated - from the address elements. isTextGenerated() will return true. -*/ -void QGeoAddress::setText(const QString &text) -{ - d->sText = text; -} - -/*! - Returns the country name. -*/ -QString QGeoAddress::country() const -{ - return d->sCountry; -} - -/*! - Sets the \a country name. -*/ -void QGeoAddress::setCountry(const QString &country) -{ - d->sCountry = country; -} - -/*! - Returns the country code according to ISO 3166-1 alpha-3 -*/ -QString QGeoAddress::countryCode() const -{ - return d->sCountryCode; -} - -/*! - Sets the \a countryCode according to ISO 3166-1 alpha-3 -*/ -void QGeoAddress::setCountryCode(const QString &countryCode) -{ - d->sCountryCode = countryCode; -} - -/*! - Returns the state. The state is considered the first subdivision below country. -*/ -QString QGeoAddress::state() const -{ - return d->sState; -} - -/*! - Sets the \a state. -*/ -void QGeoAddress::setState(const QString &state) -{ - d->sState = state; -} - -/*! - Returns the county. The county is considered the second subdivision below country. -*/ -QString QGeoAddress::county() const -{ - return d->sCounty; -} - -/*! - Sets the \a county. -*/ -void QGeoAddress::setCounty(const QString &county) -{ - d->sCounty = county; -} - -/*! - Returns the city. -*/ -QString QGeoAddress::city() const -{ - return d->sCity; -} - -/*! - Sets the \a city. -*/ -void QGeoAddress::setCity(const QString &city) -{ - d->sCity = city; -} - -/*! - Returns the district. The district is considered the subdivison below city. -*/ -QString QGeoAddress::district() const -{ - return d->sDistrict; -} - -/*! - Sets the \a district. -*/ -void QGeoAddress::setDistrict(const QString &district) -{ - d->sDistrict = district; -} - -/*! - Returns the street-level component of the address. - - This typically includes a street number and street name - but may also contain things like a unit number, a building - name, or anything else that might be used to - distinguish one address from another. -*/ -QString QGeoAddress::street() const -{ - return d->sStreet; -} - -/*! - Sets the street-level component of the address to \a street. - - This typically includes a street number and street name - but may also contain things like a unit number, a building - name, or anything else that might be used to - distinguish one address from another. -*/ -void QGeoAddress::setStreet(const QString &street) -{ - d->sStreet = street; -} - -/*! - Returns the postal code. -*/ -QString QGeoAddress::postalCode() const -{ - return d->sPostalCode; -} - -/*! - Sets the \a postalCode. -*/ -void QGeoAddress::setPostalCode(const QString &postalCode) -{ - d->sPostalCode = postalCode; -} - -/*! - Returns whether this address is empty. An address is considered empty - if \e all of its fields are empty. -*/ -bool QGeoAddress::isEmpty() const -{ - return d->sCountry.isEmpty() && - d->sCountryCode.isEmpty() && - d->sState.isEmpty() && - d->sCounty.isEmpty() && - d->sCity.isEmpty() && - d->sDistrict.isEmpty() && - d->sStreet.isEmpty() && - d->sPostalCode.isEmpty() && - d->sText.isEmpty(); - -} - -/*! - Clears all of the address' data fields. -*/ -void QGeoAddress::clear() -{ - d->sCountry.clear(); - d->sCountryCode.clear(); - d->sState.clear(); - d->sCounty.clear(); - d->sCity.clear(); - d->sDistrict.clear(); - d->sStreet.clear(); - d->sPostalCode.clear(); - d->sText.clear(); -} - -/*! - Returns true if QGeoAddress::text() is automatically generated from address elements, - otherwise returns false if text() has been explicitly assigned. - - \sa text(), setText() -*/ -bool QGeoAddress::isTextGenerated() const -{ - return d->sText.isEmpty(); -} - -QT_END_NAMESPACE - diff --git a/src/location/qgeoaddress.h b/src/location/qgeoaddress.h deleted file mode 100644 index c82f824b..00000000 --- a/src/location/qgeoaddress.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOADDRESS_H -#define QGEOADDRESS_H - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QString; -class QGeoAddressPrivate; -class Q_LOCATION_EXPORT QGeoAddress -{ -public: - QGeoAddress(); - QGeoAddress(const QGeoAddress &other); - ~QGeoAddress(); - - QGeoAddress &operator=(const QGeoAddress &other); - bool operator==(const QGeoAddress &other) const; - bool operator!=(const QGeoAddress &other) const { - return !(other == *this); - } - - QString text() const; - void setText(const QString &text); - - QString country() const; - void setCountry(const QString &country); - - QString countryCode() const; - void setCountryCode(const QString &countryCode); - - QString state() const; - void setState(const QString &state); - - QString county() const; - void setCounty(const QString &county); - - QString city() const; - void setCity(const QString &city); - - QString district() const; - void setDistrict(const QString &district); - - QString postalCode() const; - void setPostalCode(const QString &postalCode); - - QString street() const; - void setStreet(const QString &street); - - bool isEmpty() const; - void clear(); - - bool isTextGenerated() const; - -private: - QSharedDataPointer d; -}; - -Q_DECLARE_TYPEINFO(QGeoAddress, Q_MOVABLE_TYPE); - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QGeoAddress) - -#endif diff --git a/src/location/qgeoaddress_p.h b/src/location/qgeoaddress_p.h deleted file mode 100644 index 5135e8c2..00000000 --- a/src/location/qgeoaddress_p.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QLOCATION_GEOADDRESS_P_H -#define QLOCATION_GEOADDRESS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QGeoAddressPrivate : public QSharedData -{ -public: - QGeoAddressPrivate(); - QGeoAddressPrivate(const QGeoAddressPrivate &other); - ~QGeoAddressPrivate(); - - QString sCountry; //!< country field - QString sCountryCode; //!< country code field - QString sState; //!< state field - QString sCounty; //!< county field - QString sCity; //!< city field - QString sDistrict; //!< district field - QString sStreet; //!< street name field - QString sPostalCode; //!< postal code field - QString sText; - bool m_autoGeneratedText; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qgeoareamonitor.cpp b/src/location/qgeoareamonitor.cpp deleted file mode 100644 index 7462e1df..00000000 --- a/src/location/qgeoareamonitor.cpp +++ /dev/null @@ -1,256 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include "qgeopositioninfosourcefactory.h" -#include "qgeopositioninfosource_p.h" - -/*! - \class QGeoAreaMonitor - \inmodule QtLocation - \ingroup QtLocation-positioning - \since Qt Location 5.0 - - \brief The QGeoAreaMonitor class enables the detection of proximity - changes for a specified set of coordinates. - - A QGeoAreaMonitor emits signals when the current position is in - range, or has moved out of range, of a specified circular area. - The area is specified by a coordinate (the center point) and a - radius (in meters). - - For example: - - \code - public: - MyClass::MyClass() - { - QGeoAreaMonitor *monitor = QGeoAreaMonitor::createDefaultMonitor(); - if (monitor) { - connect(monitor, SIGNAL(areaEntered(QGeoPositionInfo)), - this, SLOT(areaEntered(QGeoPositionInfo))); - connect(monitor, SIGNAL(areaExited(QGeoPositionInfo)), - this, SLOT(areaExited(QGeoPositionInfo))); - - QGeoCoordinate bigBenLocation(51.50104, -0.124632); - monitor->setCenter(bigBenLocation); - monitor->setRadius(100); - } else { - qDebug() << "Could not create default area monitor"; - } - } - - public Q_SLOTS: - void areaEntered(const QGeoPositionInfo &update) - { - qDebug() << "Now within 100 meters, current position is" << update.coordinate(); - } - - void areaExited(const QGeoPositionInfo &update) - { - qDebug() << "No longer within 100 meters, current position is" << update.coordinate(); - } - \endcode -*/ - -QT_BEGIN_NAMESPACE - -class QGeoAreaMonitorPrivate -{ -public: - QGeoCoordinate coord; - qreal radius; -}; - - -/*! - Creates a monitor with the given \a parent. -*/ -QGeoAreaMonitor::QGeoAreaMonitor(QObject *parent) - : QObject(parent), - d(new QGeoAreaMonitorPrivate) -{ - d->radius = qreal(0.0); -} - -/*! - Destroys the monitor. -*/ -QGeoAreaMonitor::~QGeoAreaMonitor() -{ - delete d; -} - -/*! - \property QGeoAreaMonitor::center - \brief holds the center of the area to be monitored. - - When the center is set, if the radius has already been set and - the current position is within the monitored area, areaEntered() - is emitted immediately. - - By default, contains an invalid coordinate. - - Note: Subclass implementations must call the base implementation of - setCenter() so that center() returns the correct value. -*/ -void QGeoAreaMonitor::setCenter(const QGeoCoordinate &coordinate) -{ - d->coord = coordinate; -} - -QGeoCoordinate QGeoAreaMonitor::center() const -{ - return d->coord; -} - -/*! - \property QGeoAreaMonitor::radius - \brief holds the radius of the area to be monitored, in meters. - - If the specified radius is less than the minimum supported radius, the - radius is set to the minimum radius. - - When this property is set, if the center coordinate has already been set and - the current position is within the monitored area, areaEntered() - is emitted immediately. - - By default, this property is 0. - - Note: Subclass implementations must call the base implementation of - setRadius() so that radius() returns the correct value. -*/ -void QGeoAreaMonitor::setRadius(qreal radius) -{ - d->radius = radius; -} - -qreal QGeoAreaMonitor::radius() const -{ - return d->radius; -} - -/*! - Creates and returns a monitor with the given \a parent that - monitors areas using resources on the underlying system. - - Returns 0 if the system has no support for position monitoring. -*/ -QGeoAreaMonitor *QGeoAreaMonitor::createDefaultMonitor(QObject *parent) -{ - QList plugins = QGeoPositionInfoSourcePrivate::pluginsSorted(); - foreach (const QJsonObject &obj, plugins) { - if (obj.value(QStringLiteral("Monitor")).isBool() - && obj.value(QStringLiteral("Monitor")).toBool()) - { - QGeoPositionInfoSourcePrivate d; - d.metaData = obj; - d.loadPlugin(); - QGeoAreaMonitor *s = 0; - if (d.factory) - s = d.factory->areaMonitor(parent); - return s; - } - } - - return 0; -} - -/*! - Creates and returns a monitor with the given \a parent, - by loading the plugin named \a sourceName. - - Returns 0 if the plugin cannot be found. -*/ -QGeoAreaMonitor *QGeoAreaMonitor::createMonitor(const QString &sourceName, QObject *parent) -{ - QHash plugins = QGeoPositionInfoSourcePrivate::plugins(); - if (plugins.contains(sourceName)) { - QGeoPositionInfoSourcePrivate d; - d.metaData = plugins.value(sourceName); - d.loadPlugin(); - QGeoAreaMonitor *s = 0; - if (d.factory) - s = d.factory->areaMonitor(parent); - return s; - } - - return 0; -} - -/*! - Returns a list of available monitor plugins, including the default system - backend if one is available. -*/ -QStringList QGeoAreaMonitor::availableMonitors() -{ - QStringList plugins; - QHash meta = QGeoPositionInfoSourcePrivate::plugins(); - foreach (const QString &name, meta.keys()) { - if (meta.value(name).value(QStringLiteral("Monitor")).isBool() - && meta.value(name).value(QStringLiteral("Monitor")).toBool()) { - plugins << name; - } - } - - return plugins; -} - - - -/*! - \fn void QGeoAreaMonitor::areaEntered(const QGeoPositionInfo &update); - - Emitted when the current position has moved from a position outside the - monitored area to a position within the monitored area. - - The \a update holds the new position. -*/ - -/*! - \fn void QGeoAreaMonitor::areaExited(const QGeoPositionInfo &update); - - Emitted when the current position has moved from a position within the - monitored area to a position outside the monitored area. - - The \a update holds the new position. -*/ - -QT_END_NAMESPACE diff --git a/src/location/qgeoareamonitor.h b/src/location/qgeoareamonitor.h deleted file mode 100644 index 62438d0b..00000000 --- a/src/location/qgeoareamonitor.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QGEOAREAMONITOR_H -#define QGEOAREAMONITOR_H - -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -class QGeoPositionInfo; -class QGeoAreaMonitorPrivate; -class Q_LOCATION_EXPORT QGeoAreaMonitor : public QObject -{ - Q_OBJECT - Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter) - Q_PROPERTY(qreal radius READ radius WRITE setRadius) - -public: - explicit QGeoAreaMonitor(QObject *parent); - virtual ~QGeoAreaMonitor() = 0; - - virtual void setCenter(const QGeoCoordinate &coordinate); - QGeoCoordinate center() const; - - virtual void setRadius(qreal radius); - qreal radius() const; - - static QGeoAreaMonitor *createDefaultMonitor(QObject *parent); - static QGeoAreaMonitor *createMonitor(const QString& sourceName, QObject *parent); - static QStringList availableMonitors(); - -Q_SIGNALS: - void areaEntered(const QGeoPositionInfo &update); - void areaExited(const QGeoPositionInfo &update); - -private: - Q_DISABLE_COPY(QGeoAreaMonitor) - QGeoAreaMonitorPrivate *d; -}; - - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qgeocircle.cpp b/src/location/qgeocircle.cpp deleted file mode 100644 index 6c77d934..00000000 --- a/src/location/qgeocircle.cpp +++ /dev/null @@ -1,311 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgeocircle.h" -#include "qgeocircle_p.h" - -#include "qgeocoordinate.h" -#include "qnumeric.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QGeoCircle - \inmodule QtLocation - \ingroup QtLocation-positioning - \since Qt Location 5.0 - - \brief The QGeoCircle class defines a circular geographic area. - - The circle is defined in terms of a QGeoCoordinate which specifies the - center of the circle and a qreal which specifies the radius of the circle - in meters. - - The circle is considered invalid if the center coordinate is invalid - or if the radius is less than zero. -*/ - -#ifdef Q_NO_USING_KEYWORD -/*! - \fn bool QGeoCircle::operator==(const QGeoShape &other) const - - Returns true if \a other is equal to this geo circle; otherwise returns false. -*/ - -/*! - \fn bool QGeoCircle::operator!=(const QGeoShape &other) const - - Returns true if \a other is not equal to this geo circle; otherwise returns false. -*/ -#endif - -inline QGeoCirclePrivate *QGeoCircle::d_func() -{ - return static_cast(d_ptr.data()); -} - -inline const QGeoCirclePrivate *QGeoCircle::d_func() const -{ - return static_cast(d_ptr.constData()); -} - -/*! - Constructs a new, invalid geo circle. -*/ -QGeoCircle::QGeoCircle() -: QGeoShape(new QGeoCirclePrivate) -{ -} - -/*! - Constructs a new geo circle centered at \a center and with a radius of \a radius meters. -*/ -QGeoCircle::QGeoCircle(const QGeoCoordinate ¢er, qreal radius) -{ - d_ptr = new QGeoCirclePrivate(center, radius); -} - -/*! - Constructs a new geo circle from the contents of \a other. -*/ -QGeoCircle::QGeoCircle(const QGeoCircle &other) -: QGeoShape(other) -{ -} - -/*! - Constructs a new geo circle from the contents of \a other. -*/ -QGeoCircle::QGeoCircle(const QGeoShape &other) -: QGeoShape(other) -{ - if (type() != QGeoShape::CircleType) - d_ptr = new QGeoCirclePrivate; -} - -/*! - Destroys this geo circle. -*/ -QGeoCircle::~QGeoCircle() {} - -/*! - Assigns \a other to this geo circle and returns a reference to this geo circle. -*/ -QGeoCircle &QGeoCircle::operator=(const QGeoCircle &other) -{ - QGeoShape::operator=(other); - return *this; -} - -/*! - Returns whether this geo circle is equal to \a other. -*/ -bool QGeoCircle::operator==(const QGeoCircle &other) const -{ - Q_D(const QGeoCircle); - - return *d == *other.d_func(); -} - -/*! - Returns whether this geo circle is not equal to \a other. -*/ -bool QGeoCircle::operator!=(const QGeoCircle &other) const -{ - Q_D(const QGeoCircle); - - return !(*d == *other.d_func()); -} - -bool QGeoCirclePrivate::isValid() const -{ - return center.isValid() && !qIsNaN(radius) && radius >= -1e-7; -} - -bool QGeoCirclePrivate::isEmpty() const -{ - return !isValid() || radius <= 1e-7; -} - -/*! - Sets the center coordinate of this geo circle to \a center. -*/ -void QGeoCircle::setCenter(const QGeoCoordinate ¢er) -{ - Q_D(QGeoCircle); - - d->center = center; -} - -/*! - Returns the center coordinate of this geo circle. -*/ -QGeoCoordinate QGeoCircle::center() const -{ - Q_D(const QGeoCircle); - - return d->center; -} - -/*! - Sets the radius in meters of this geo circle to \a radius. -*/ -void QGeoCircle::setRadius(qreal radius) -{ - Q_D(QGeoCircle); - - d->radius = radius; -} - -/*! - Returns the radius in meters of this geo circle. -*/ -qreal QGeoCircle::radius() const -{ - Q_D(const QGeoCircle); - - return d->radius; -} - -bool QGeoCirclePrivate::contains(const QGeoCoordinate &coordinate) const -{ - if (!isValid() || !coordinate.isValid()) - return false; - - return center.distanceTo(coordinate) <= radius; -} - -/*! - Translates this geo circle by \a degreesLatitude northwards and \a degreesLongitude eastwards. - - Negative values of \a degreesLatitude and \a degreesLongitude correspond to - southward and westward translation respectively. -*/ -void QGeoCircle::translate(double degreesLatitude, double degreesLongitude) -{ - // TODO handle dlat, dlon larger than 360 degrees - - Q_D(QGeoCircle); - - double lat = d->center.latitude(); - double lon = d->center.longitude(); - - lat += degreesLatitude; - lon += degreesLongitude; - - if (lon < -180.0) - lon += 360.0; - if (lon > 180.0) - lon -= 360.0; - - if (lat > 90.0) { - lat = 180.0 - lat; - if (lon < 0.0) - lon = 180.0; - else - lon -= 180; - } - - if (lat < -90.0) { - lat = 180.0 + lat; - if (lon < 0.0) - lon = 180.0; - else - lon -= 180; - } - - d->center = QGeoCoordinate(lat, lon); -} - -/*! - Returns a copy of this geo circle translated by \a degreesLatitude northwards and - \a degreesLongitude eastwards. - - Negative values of \a degreesLatitude and \a degreesLongitude correspond to - southward and westward translation respectively. - - \sa translate() -*/ -QGeoCircle QGeoCircle::translated(double degreesLatitude, double degreesLongitude) const -{ - QGeoCircle result(*this); - result.translate(degreesLatitude, degreesLongitude); - return result; -} - -/******************************************************************************* -*******************************************************************************/ - -QGeoCirclePrivate::QGeoCirclePrivate() -: QGeoShapePrivate(QGeoShape::CircleType), radius(-1.0) -{ -} - -QGeoCirclePrivate::QGeoCirclePrivate(const QGeoCoordinate ¢er, qreal radius) -: QGeoShapePrivate(QGeoShape::CircleType), center(center), radius(radius) -{ -} - -QGeoCirclePrivate::QGeoCirclePrivate(const QGeoCirclePrivate &other) -: QGeoShapePrivate(QGeoShape::CircleType), center(other.center), - radius(other.radius) -{ -} - -QGeoCirclePrivate::~QGeoCirclePrivate() {} - -QGeoShapePrivate *QGeoCirclePrivate::clone() const -{ - return new QGeoCirclePrivate(*this); -} - -bool QGeoCirclePrivate::operator==(const QGeoShapePrivate &other) const -{ - if (!QGeoShapePrivate::operator==(other)) - return false; - - const QGeoCirclePrivate &otherCircle = static_cast(other); - - return radius == otherCircle.radius && center == otherCircle.center; -} - -QT_END_NAMESPACE - diff --git a/src/location/qgeocircle.h b/src/location/qgeocircle.h deleted file mode 100644 index 158a48a6..00000000 --- a/src/location/qgeocircle.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOCIRCLE_H -#define QGEOCIRCLE_H - -#include - -QT_BEGIN_NAMESPACE - -class QGeoCoordinate; -class QGeoCirclePrivate; - -class Q_LOCATION_EXPORT QGeoCircle : public QGeoShape -{ -public: - QGeoCircle(); - QGeoCircle(const QGeoCoordinate ¢er, qreal radius = -1.0); - QGeoCircle(const QGeoCircle &other); - QGeoCircle(const QGeoShape &other); - - ~QGeoCircle(); - - QGeoCircle &operator=(const QGeoCircle &other); - -#ifdef Q_NO_USING_KEYWORD - bool operator==(const QGeoShape &other) const - { - return QGeoShape::operator==(other); - } -#else - using QGeoShape::operator==; -#endif - bool operator==(const QGeoCircle &other) const; - -#ifdef Q_NO_USING_KEYWORD - bool operator!=(const QGeoShape &other) const - { - return QGeoShape::operator!=(other); - } -#else - using QGeoShape::operator!=; -#endif - bool operator!=(const QGeoCircle &other) const; - - void setCenter(const QGeoCoordinate ¢er); - QGeoCoordinate center() const; - - void setRadius(qreal radius); - qreal radius() const; - - void translate(double degreesLatitude, double degreesLongitude); - QGeoCircle translated(double degreesLatitude, double degreesLongitude) const; - -private: - inline QGeoCirclePrivate *d_func(); - inline const QGeoCirclePrivate *d_func() const; -}; - -Q_DECLARE_TYPEINFO(QGeoCircle, Q_MOVABLE_TYPE); - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QGeoCircle) - -#endif - diff --git a/src/location/qgeocircle_p.h b/src/location/qgeocircle_p.h deleted file mode 100644 index 065a1276..00000000 --- a/src/location/qgeocircle_p.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOCIRCLE_P_H -#define QGEOCIRCLE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qgeoshape_p.h" -#include "qgeocoordinate.h" - -QT_BEGIN_NAMESPACE - -class QGeoCirclePrivate : public QGeoShapePrivate -{ -public: - QGeoCirclePrivate(); - QGeoCirclePrivate(const QGeoCoordinate ¢er, qreal radius); - QGeoCirclePrivate(const QGeoCirclePrivate &other); - ~QGeoCirclePrivate(); - - bool isValid() const; - bool isEmpty() const; - bool contains(const QGeoCoordinate &coordinate) const; - - QGeoShapePrivate *clone() const; - - bool operator==(const QGeoShapePrivate &other) const; - - QGeoCoordinate center; - qreal radius; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qgeocoordinate.cpp b/src/location/qgeocoordinate.cpp deleted file mode 100644 index c2b2bb50..00000000 --- a/src/location/qgeocoordinate.cpp +++ /dev/null @@ -1,644 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qgeocoordinate.h" -#include "qgeocoordinate_p.h" -#include "qlocationutils_p.h" - -#include -#include -#include -#include -#include - -#include - -#include - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -QT_BEGIN_NAMESPACE - -static const double qgeocoordinate_EARTH_MEAN_RADIUS = 6371.0072; - -inline static double qgeocoordinate_degToRad(double deg) -{ - return deg * M_PI / 180; -} -inline static double qgeocoordinate_radToDeg(double rad) -{ - return rad * 180 / M_PI; -} - - -QGeoCoordinatePrivate::QGeoCoordinatePrivate() { - lat = qQNaN(); - lng = qQNaN(); - alt = qQNaN(); -} - -QGeoCoordinatePrivate::QGeoCoordinatePrivate(const QGeoCoordinatePrivate &other) - : QSharedData(other), - lat(other.lat), - lng(other.lng), - alt(other.alt) -{} - -QGeoCoordinatePrivate::~QGeoCoordinatePrivate() -{} - - -/*! - \class QGeoCoordinate - \inmodule QtLocation - \ingroup QtLocation-positioning - \since Qt Location 5.0 - - \brief The QGeoCoordinate class defines a geographical position on the surface of the Earth. - - A QGeoCoordinate is defined by latitude, longitude, and optionally, altitude. - - Use type() to determine whether a coordinate is a 2D coordinate (has - latitude and longitude only) or 3D coordinate (has latitude, longitude - and altitude). Use distanceTo() and azimuthTo() to calculate the distance - and bearing between coordinates. - - The coordinate values should be specified using the WGS84 datum. For more information - on geographical terms see this article on \l {http://en.wikipedia.org/wiki/Geographic_coordinate_system}{coordinates} and - another on \l {http://en.wikipedia.org/wiki/Geodetic_system}{geodetic systems} - including WGS84. - - Azimuth in this context is equivalent to a compass bearing based on true north. -*/ - -/*! - \enum QGeoCoordinate::CoordinateType - Defines the types of a coordinate. - - \value InvalidCoordinate An invalid coordinate. A coordinate is invalid if its latitude or longitude values are invalid. - \value Coordinate2D A coordinate with valid latitude and longitude values. - \value Coordinate3D A coordinate with valid latitude and longitude values, and also an altitude value. -*/ - -/*! - \enum QGeoCoordinate::CoordinateFormat - Defines the possible formatting options for toString(). - - \value Degrees Returns a string representation of the coordinates in decimal degrees format. - \value DegreesWithHemisphere Returns a string representation of the coordinates in decimal degrees format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates. - \value DegreesMinutes Returns a string representation of the coordinates in degrees-minutes format. - \value DegreesMinutesWithHemisphere Returns a string representation of the coordinates in degrees-minutes format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates. - \value DegreesMinutesSeconds Returns a string representation of the coordinates in degrees-minutes-seconds format. - \value DegreesMinutesSecondsWithHemisphere Returns a string representation of the coordinates in degrees-minutes-seconds format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates. - - \sa toString() -*/ - - -/*! - Constructs a coordinate. The coordinate will be invalid until - setLatitude() and setLongitude() have been called. -*/ -QGeoCoordinate::QGeoCoordinate() - : d(new QGeoCoordinatePrivate) -{ -} - -/*! - Constructs a coordinate with the given \a latitude and \a longitude. - - If the latitude is not between -90 to 90 inclusive, or the longitude - is not between -180 to 180 inclusive, none of the values are set and - the type() will be QGeoCoordinate::InvalidCoordinate. - - \sa isValid() -*/ -QGeoCoordinate::QGeoCoordinate(double latitude, double longitude) - : d(new QGeoCoordinatePrivate) -{ - if (QLocationUtils::isValidLat(latitude) && QLocationUtils::isValidLong(longitude)) { - d->lat = latitude; - d->lng = longitude; - } -} - -/*! - Constructs a coordinate with the given \a latitude, \a longitude - and \a altitude. - - If the latitude is not between -90 to 90 inclusive, or the longitude - is not between -180 to 180 inclusive, none of the values are set and - the type() will be QGeoCoordinate::InvalidCoordinate. - - Note that \a altitude specifies the meters above sea level. - - \sa isValid() -*/ -QGeoCoordinate::QGeoCoordinate(double latitude, double longitude, double altitude) - : d(new QGeoCoordinatePrivate) -{ - if (QLocationUtils::isValidLat(latitude) && QLocationUtils::isValidLong(longitude)) { - d->lat = latitude; - d->lng = longitude; - d->alt = altitude; - } -} - -/*! - Constructs a coordinate from the contents of \a other. -*/ -QGeoCoordinate::QGeoCoordinate(const QGeoCoordinate &other) - : d(other.d) -{} - -/*! - Assigns \a other to this coordinate and returns a reference to this coordinate. -*/ -QGeoCoordinate &QGeoCoordinate::operator=(const QGeoCoordinate &other) -{ - if (this == &other) - return *this; - - d = other.d; - return (*this); -} - -/*! - Destroys the coordinate object. -*/ -QGeoCoordinate::~QGeoCoordinate() -{ -} - -/*! - Returns true if the latitude, longitude and altitude of this - coordinate are the same as those of \a other. - - The longitude will be ignored if the latitude is +/- 90 degrees. -*/ -bool QGeoCoordinate::operator==(const QGeoCoordinate &other) const -{ - bool latEqual = (qIsNaN(d->lat) && qIsNaN(other.d->lat)) - || qFuzzyCompare(d->lat, other.d->lat); - bool lngEqual = (qIsNaN(d->lng) && qIsNaN(other.d->lng)) - || qFuzzyCompare(d->lng, other.d->lng); - bool altEqual = (qIsNaN(d->alt) && qIsNaN(other.d->alt)) - || qFuzzyCompare(d->alt, other.d->alt); - - if (!qIsNaN(d->lat) && ((d->lat == 90.0) || (d->lat == -90.0))) - lngEqual = true; - - return (latEqual && lngEqual && altEqual); -} - -/*! - \fn bool QGeoCoordinate::operator!=(const QGeoCoordinate &other) const; - - Returns true if the latitude, longitude or altitude of this - coordinate are not the same as those of \a other. -*/ - -/*! - Returns true if the type() is Coordinate2D or Coordinate3D. -*/ -bool QGeoCoordinate::isValid() const -{ - CoordinateType t = type(); - return t == Coordinate2D || t == Coordinate3D; -} - -/*! - Returns the type of this coordinate. -*/ -QGeoCoordinate::CoordinateType QGeoCoordinate::type() const -{ - if (QLocationUtils::isValidLat(d->lat) - && QLocationUtils::isValidLong(d->lng)) { - if (qIsNaN(d->alt)) - return Coordinate2D; - return Coordinate3D; - } - return InvalidCoordinate; -} - - -/*! - Returns the latitude, in decimal degrees. The return value is undefined - if the latitude has not been set. - - A positive latitude indicates the Northern Hemisphere, and a negative - latitude indicates the Southern Hemisphere. - - \sa setLatitude(), type() -*/ -double QGeoCoordinate::latitude() const -{ - return d->lat; -} - -/*! - Sets the latitude (in decimal degrees) to \a latitude. The value should - be in the WGS84 datum. - - To be valid, the latitude must be between -90 to 90 inclusive. - - \sa latitude() -*/ -void QGeoCoordinate::setLatitude(double latitude) -{ - d->lat = latitude; -} - -/*! - Returns the longitude, in decimal degrees. The return value is undefined - if the longitude has not been set. - - A positive longitude indicates the Eastern Hemisphere, and a negative - longitude indicates the Western Hemisphere. - - \sa setLongitude(), type() -*/ -double QGeoCoordinate::longitude() const -{ - return d->lng; -} - -/*! - Sets the longitude (in decimal degrees) to \a longitude. The value should - be in the WGS84 datum. - - To be valid, the longitude must be between -180 to 180 inclusive. - - \sa longitude() -*/ -void QGeoCoordinate::setLongitude(double longitude) -{ - d->lng = longitude; -} - -/*! - Returns the altitude (meters above sea level). - - The return value is undefined if the altitude has not been set. - - \sa setAltitude(), type() -*/ -double QGeoCoordinate::altitude() const -{ - return d->alt; -} - -/*! - Sets the altitude (meters above sea level) to \a altitude. - - \sa altitude() -*/ -void QGeoCoordinate::setAltitude(double altitude) -{ - d->alt = altitude; -} - -/*! - Returns the distance (in meters) from this coordinate to the coordinate - specified by \a other. Altitude is not used in the calculation. - - This calculation returns the great-circle distance between the two - coordinates, with an assumption that the Earth is spherical for the - purpose of this calculation. - - Returns 0 if the type of this coordinate or the type of \a other is - QGeoCoordinate::InvalidCoordinate. -*/ -qreal QGeoCoordinate::distanceTo(const QGeoCoordinate &other) const -{ - if (type() == QGeoCoordinate::InvalidCoordinate - || other.type() == QGeoCoordinate::InvalidCoordinate) { - return 0; - } - - // Haversine formula - double dlat = qgeocoordinate_degToRad(other.d->lat - d->lat); - double dlon = qgeocoordinate_degToRad(other.d->lng - d->lng); - double haversine_dlat = sin(dlat / 2.0); - haversine_dlat *= haversine_dlat; - double haversine_dlon = sin(dlon / 2.0); - haversine_dlon *= haversine_dlon; - double y = haversine_dlat - + cos(qgeocoordinate_degToRad(d->lat)) - * cos(qgeocoordinate_degToRad(other.d->lat)) - * haversine_dlon; - double x = 2 * asin(sqrt(y)); - return qreal(x * qgeocoordinate_EARTH_MEAN_RADIUS * 1000); -} - -/*! - Returns the azimuth (or bearing) in degrees from this coordinate to the - coordinate specified by \a other. Altitude is not used in the calculation. - - The bearing returned is the bearing from the origin to \a other along the - great-circle between the two coordinates. There is an assumption that the - Earth is spherical for the purpose of this calculation. - - Returns 0 if the type of this coordinate or the type of \a other is - QGeoCoordinate::InvalidCoordinate. -*/ -qreal QGeoCoordinate::azimuthTo(const QGeoCoordinate &other) const -{ - if (type() == QGeoCoordinate::InvalidCoordinate - || other.type() == QGeoCoordinate::InvalidCoordinate) { - return 0; - } - - double dlon = qgeocoordinate_degToRad(other.d->lng - d->lng); - double lat1Rad = qgeocoordinate_degToRad(d->lat); - double lat2Rad = qgeocoordinate_degToRad(other.d->lat); - - double y = sin(dlon) * cos(lat2Rad); - double x = cos(lat1Rad) * sin(lat2Rad) - sin(lat1Rad) * cos(lat2Rad) * cos(dlon); - - double whole; - double fraction = modf(qgeocoordinate_radToDeg(atan2(y, x)), &whole); - return qreal((int(whole + 360) % 360) + fraction); -} - -void QGeoCoordinatePrivate::atDistanceAndAzimuth(const QGeoCoordinate &coord, - qreal distance, qreal azimuth, - double *lon, double *lat) -{ - double latRad = qgeocoordinate_degToRad(coord.d->lat); - double lonRad = qgeocoordinate_degToRad(coord.d->lng); - double cosLatRad = cos(latRad); - double sinLatRad = sin(latRad); - - double azimuthRad = qgeocoordinate_degToRad(azimuth); - - double ratio = (distance / (qgeocoordinate_EARTH_MEAN_RADIUS * 1000.0)); - double cosRatio = cos(ratio); - double sinRatio = sin(ratio); - - double resultLatRad = asin(sinLatRad * cosRatio - + cosLatRad * sinRatio * cos(azimuthRad)); - double resultLonRad = lonRad + atan2(sin(azimuthRad) * sinRatio * cosLatRad, - cosRatio - sinLatRad * sin(resultLatRad)); - - *lat = qgeocoordinate_radToDeg(resultLatRad); - *lon = qgeocoordinate_radToDeg(resultLonRad); -} - -/*! - Returns the coordinate that is reached by traveling \a distance meters - from the current coordinate at \a azimuth (or bearing) along a great-circle. - There is an assumption that the Earth is spherical for the purpose of this - calculation. - - The altitude will have \a distanceUp added to it. - - Returns an invalid coordinate if this coordinate is invalid. -*/ -QGeoCoordinate QGeoCoordinate::atDistanceAndAzimuth(qreal distance, qreal azimuth, qreal distanceUp) const -{ - if (!isValid()) - return QGeoCoordinate(); - - double resultLon, resultLat; - QGeoCoordinatePrivate::atDistanceAndAzimuth(*this, distance, azimuth, - &resultLon, &resultLat); - - if (resultLon > 180.0) - resultLon -= 360.0; - else if (resultLon < -180.0) - resultLon += 360.0; - - double resultAlt = d->alt + distanceUp; - return QGeoCoordinate(resultLat, resultLon, resultAlt); -} - -/*! - Returns this coordinate as a string in the specified \a format. - - For example, if this coordinate has a latitude of -27.46758, a longitude - of 153.027892 and an altitude of 28.1, these are the strings - returned depending on \a format: - - \table - \header - \li \a format value - \li Returned string - \row - \li \l Degrees - \li -27.46758\unicode{0xB0}, 153.02789\unicode{0xB0}, 28.1m - \row - \li \l DegreesWithHemisphere - \li 27.46758\unicode{0xB0} S, 153.02789\unicode{0xB0} E, 28.1m - \row - \li \l DegreesMinutes - \li -27\unicode{0xB0} 28.054', 153\unicode{0xB0} 1.673', 28.1m - \row - \li \l DegreesMinutesWithHemisphere - \li 27\unicode{0xB0} 28.054 S', 153\unicode{0xB0} 1.673' E, 28.1m - \row - \li \l DegreesMinutesSeconds - \li -27\unicode{0xB0} 28' 3.2", 153\unicode{0xB0} 1' 40.4", 28.1m - \row - \li \l DegreesMinutesSecondsWithHemisphere - \li 27\unicode{0xB0} 28' 3.2" S, 153\unicode{0xB0} 1' 40.4" E, 28.1m - \endtable - - The altitude field is omitted if no altitude is set. - - If the coordinate is invalid, an empty string is returned. -*/ -QString QGeoCoordinate::toString(CoordinateFormat format) const -{ - if (type() == QGeoCoordinate::InvalidCoordinate) - return QString(); - - QString latStr; - QString longStr; - - double absLat = qAbs(d->lat); - double absLng = qAbs(d->lng); - QChar symbol(0x00B0); // degrees symbol - - switch (format) { - case Degrees: - case DegreesWithHemisphere: { - latStr = QString::number(absLat, 'f', 5) + symbol; - longStr = QString::number(absLng, 'f', 5) + symbol; - break; - } - case DegreesMinutes: - case DegreesMinutesWithHemisphere: { - double latMin = (absLat - int(absLat)) * 60; - double lngMin = (absLng - int(absLng)) * 60; - latStr = QString::fromLatin1("%1%2 %3'") - .arg(QString::number(int(absLat))) - .arg(symbol) - .arg(QString::number(latMin, 'f', 3)); - longStr = QString::fromLatin1("%1%2 %3'") - .arg(QString::number(int(absLng))) - .arg(symbol) - .arg(QString::number(lngMin, 'f', 3)); - break; - } - case DegreesMinutesSeconds: - case DegreesMinutesSecondsWithHemisphere: { - double latMin = (absLat - int(absLat)) * 60; - double lngMin = (absLng - int(absLng)) * 60; - double latSec = (latMin - int(latMin)) * 60; - double lngSec = (lngMin - int(lngMin)) * 60; - - latStr = QString::fromLatin1("%1%2 %3' %4\"") - .arg(QString::number(int(absLat))) - .arg(symbol) - .arg(QString::number(int(latMin))) - .arg(QString::number(latSec, 'f', 1)); - longStr = QString::fromLatin1("%1%2 %3' %4\"") - .arg(QString::number(int(absLng))) - .arg(symbol) - .arg(QString::number(int(lngMin))) - .arg(QString::number(lngSec, 'f', 1)); - break; - } - } - - // now add the "-" to the start, or append the hemisphere char - switch (format) { - case Degrees: - case DegreesMinutes: - case DegreesMinutesSeconds: { - if (d->lat < 0) - latStr.insert(0, QLatin1String("-")); - if (d->lng < 0) - longStr.insert(0, QLatin1String("-")); - break; - } - case DegreesWithHemisphere: - case DegreesMinutesWithHemisphere: - case DegreesMinutesSecondsWithHemisphere: { - if (d->lat < 0) - latStr.append(QString::fromLatin1(" S")); - else if (d->lat > 0) - latStr.append(QString::fromLatin1(" N")); - if (d->lng < 0) - longStr.append(QString::fromLatin1(" W")); - else if (d->lng > 0) - longStr.append(QString::fromLatin1(" E")); - break; - } - } - - if (qIsNaN(d->alt)) - return QString::fromLatin1("%1, %2").arg(latStr, longStr); - return QString::fromLatin1("%1, %2, %3m").arg(latStr, longStr, QString::number(d->alt)); -} - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QGeoCoordinate &coord) -{ - double lat = coord.latitude(); - double lng = coord.longitude(); - - dbg.nospace() << "QGeoCoordinate("; - if (qIsNaN(lat)) - dbg.nospace() << '?'; - else - dbg.nospace() << lat; - dbg.nospace() << ", "; - if (qIsNaN(lng)) - dbg.nospace() << '?'; - else - dbg.nospace() << lng; - if (coord.type() == QGeoCoordinate::Coordinate3D) { - dbg.nospace() << ", "; - dbg.nospace() << coord.altitude(); - } - dbg.nospace() << ')'; - return dbg; -} -#endif - -#ifndef QT_NO_DATASTREAM -/*! - \fn QDataStream &operator<<(QDataStream &stream, const QGeoCoordinate &coordinate) - - \relates QGeoCoordinate - - Writes the given \a coordinate to the specified \a stream. - - \sa {Serializing Qt Data Types} -*/ - -QDataStream &operator<<(QDataStream &stream, const QGeoCoordinate &coordinate) -{ - stream << coordinate.latitude(); - stream << coordinate.longitude(); - stream << coordinate.altitude(); - return stream; -} -#endif - -#ifndef QT_NO_DATASTREAM -/*! - \fn QDataStream &operator>>(QDataStream &stream, QGeoCoordinate &coordinate) - \relates QGeoCoordinate - - Reads a coordinate from the specified \a stream into the given - \a coordinate. - - \sa {Serializing Qt Data Types} -*/ - -QDataStream &operator>>(QDataStream &stream, QGeoCoordinate &coordinate) -{ - double value; - stream >> value; - coordinate.setLatitude(value); - stream >> value; - coordinate.setLongitude(value); - stream >> value; - coordinate.setAltitude(value); - return stream; -} -#endif - -QT_END_NAMESPACE diff --git a/src/location/qgeocoordinate.h b/src/location/qgeocoordinate.h deleted file mode 100644 index 4948ad97..00000000 --- a/src/location/qgeocoordinate.h +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOCOORDINATE_H -#define QGEOCOORDINATE_H - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QDebug; -class QDataStream; - -class QGeoCoordinatePrivate; -class Q_LOCATION_EXPORT QGeoCoordinate -{ -public: - enum CoordinateType { - InvalidCoordinate, - Coordinate2D, - Coordinate3D - }; - - enum CoordinateFormat { - Degrees, - DegreesWithHemisphere, - DegreesMinutes, - DegreesMinutesWithHemisphere, - DegreesMinutesSeconds, - DegreesMinutesSecondsWithHemisphere - }; - - QGeoCoordinate(); - QGeoCoordinate(double latitude, double longitude); - QGeoCoordinate(double latitude, double longitude, double altitude); - QGeoCoordinate(const QGeoCoordinate &other); - ~QGeoCoordinate(); - - QGeoCoordinate &operator=(const QGeoCoordinate &other); - - bool operator==(const QGeoCoordinate &other) const; - inline bool operator!=(const QGeoCoordinate &other) const { - return !operator==(other); - } - - bool isValid() const; - CoordinateType type() const; - - void setLatitude(double latitude); - double latitude() const; - - void setLongitude(double longitude); - double longitude() const; - - void setAltitude(double altitude); - double altitude() const; - - qreal distanceTo(const QGeoCoordinate &other) const; - qreal azimuthTo(const QGeoCoordinate &other) const; - - QGeoCoordinate atDistanceAndAzimuth(qreal distance, qreal azimuth, qreal distanceUp = 0.0) const; - - QString toString(CoordinateFormat format = DegreesMinutesSecondsWithHemisphere) const; - -private: - QSharedDataPointer d; - - friend class QGeoCoordinatePrivate; -}; - -Q_DECLARE_TYPEINFO(QGeoCoordinate, Q_MOVABLE_TYPE); - -#ifndef QT_NO_DEBUG_STREAM -Q_LOCATION_EXPORT QDebug operator<<(QDebug, const QGeoCoordinate &); -#endif - -#ifndef QT_NO_DATASTREAM -Q_LOCATION_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoCoordinate &coordinate); -Q_LOCATION_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoCoordinate &coordinate); -#endif - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QGeoCoordinate) - -#endif diff --git a/src/location/qgeocoordinate_p.h b/src/location/qgeocoordinate_p.h deleted file mode 100644 index 86bb4820..00000000 --- a/src/location/qgeocoordinate_p.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOCOORDINATE_P_H -#define QGEOCOORDINATE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include "qgeocoordinate.h" - -QT_BEGIN_NAMESPACE - -class QGeoCoordinatePrivate : public QSharedData -{ -public: - QGeoCoordinatePrivate(); - QGeoCoordinatePrivate(const QGeoCoordinatePrivate &other); - ~QGeoCoordinatePrivate(); - - double lat; - double lng; - double alt; - - static void atDistanceAndAzimuth(const QGeoCoordinate &coord, - qreal distance, qreal azimuth, - double *lon, double *lat); -}; - -QT_END_NAMESPACE - -#endif // QGEOCOORDINATE_P_H diff --git a/src/location/qgeolocation.cpp b/src/location/qgeolocation.cpp deleted file mode 100644 index 1b43881e..00000000 --- a/src/location/qgeolocation.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgeolocation.h" -#include "qgeolocation_p.h" - -QT_USE_NAMESPACE - -QGeoLocationPrivate::QGeoLocationPrivate() - : QSharedData() -{ -} - -QGeoLocationPrivate::QGeoLocationPrivate(const QGeoLocationPrivate &other) - : QSharedData() -{ - this->address = other.address; - this->coordinate = other.coordinate; - this->viewport = other.viewport; -} - -QGeoLocationPrivate::~QGeoLocationPrivate() -{ -} - -bool QGeoLocationPrivate::operator==(const QGeoLocationPrivate &other) const -{ - return (this->address == other.address - && this->coordinate == other.coordinate - && this->viewport == other.viewport); - -} - -bool QGeoLocationPrivate::isEmpty() const -{ - return (address.isEmpty() - && !coordinate.isValid() - && viewport.isEmpty() - ); -} - -/*! - \class QGeoLocation - \inmodule QtLocation - \ingroup QtLocation-positioning - \ingroup QtLocation-places - \ingroup QtLocation-places-data - \since Qt Location 5.0 - - \brief The QGeoLocation class represents basic information about a location. - - A QGeoLocation consists of a coordinate and corresponding address, along with an optional - bounding box which is the recommended region to be displayed when viewing the location. -*/ - -/*! - \fn bool QGeoLocation::operator!=(const QGeoLocation &other) const - - Returns true if this location is not equal to \a other, otherwise returns false. -*/ - -/*! - Constructs an new location object. -*/ -QGeoLocation::QGeoLocation() - : d(new QGeoLocationPrivate) -{ -} - -/*! - Constructs a copy of \a other -*/ -QGeoLocation::QGeoLocation(const QGeoLocation &other) - :d(other.d) -{ -} - -/*! - Destroys the location object. -*/ -QGeoLocation::~QGeoLocation() -{ -} - -/*! - Assigns \a other to this location and returns a reference to this location. -*/ -QGeoLocation &QGeoLocation::operator =(const QGeoLocation &other) -{ - if (this == &other) - return *this; - - d = other.d; - return *this; -} - -/*! - Returns true if this location is equal to \a other, - otherwise returns false. -*/ -bool QGeoLocation::operator==(const QGeoLocation &other) const -{ - return (*(d.constData()) == *(other.d.constData())); -} - -/*! - Returns the address of the location. -*/ -QGeoAddress QGeoLocation::address() const -{ - return d->address; -} - -/*! - Sets the \a address of the location. -*/ -void QGeoLocation::setAddress(const QGeoAddress &address) -{ - d->address = address; -} - -/*! - Returns the coordinate of the location. -*/ -QGeoCoordinate QGeoLocation::coordinate() const -{ - return d->coordinate; -} - -/*! - Sets the \a coordinate of the location. -*/ -void QGeoLocation::setCoordinate(const QGeoCoordinate &coordinate) -{ - d->coordinate = coordinate; -} - -/*! - Returns a bounding box which represents the recommended region - to display when viewing this location. - - For example, a building's location may have a region centered around the building, - but the region is large enough to show it's immediate surrounding geographical - context. -*/ -QGeoRectangle QGeoLocation::boundingBox() const -{ - return d->viewport; -} - -/*! - Sets the \a boundingBox of the location. -*/ -void QGeoLocation::setBoundingBox(const QGeoRectangle &boundingBox) -{ - d->viewport = boundingBox; -} - -/*! - Returns true if all fields of the location are 0; otherwise returns false. -*/ -bool QGeoLocation::isEmpty() const -{ - return d->isEmpty(); -} diff --git a/src/location/qgeolocation.h b/src/location/qgeolocation.h deleted file mode 100644 index d3f1718a..00000000 --- a/src/location/qgeolocation.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOLOCATION_H -#define QGEOLOCATION_H - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QGeoAddress; -class QGeoCoordinate; -class QGeoRectangle; -class QGeoLocationPrivate; - -class Q_LOCATION_EXPORT QGeoLocation -{ -public: - QGeoLocation(); - QGeoLocation(const QGeoLocation &other); - - ~QGeoLocation(); - - QGeoLocation &operator=(const QGeoLocation &other); - - bool operator==(const QGeoLocation &other) const; - bool operator!=(const QGeoLocation &other) const { - return !(other == *this); - } - - QGeoAddress address() const; - void setAddress(const QGeoAddress &address); - QGeoCoordinate coordinate() const; - void setCoordinate(const QGeoCoordinate &position); - QGeoRectangle boundingBox() const; - void setBoundingBox(const QGeoRectangle &box); - - bool isEmpty() const; - -private: - QSharedDataPointer d; -}; - -Q_DECLARE_TYPEINFO(QGeoLocation, Q_MOVABLE_TYPE); - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QGeoLocation) - -#endif diff --git a/src/location/qgeolocation_p.h b/src/location/qgeolocation_p.h deleted file mode 100644 index 8fc814cb..00000000 --- a/src/location/qgeolocation_p.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOLOCATION_P_H -#define QGEOLOCATION_P_H - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QGeoLocationPrivate : public QSharedData -{ -public: - QGeoLocationPrivate(); - QGeoLocationPrivate(const QGeoLocationPrivate &other); - - ~QGeoLocationPrivate(); - - bool operator==(const QGeoLocationPrivate &other) const; - - bool isEmpty() const; - - QGeoAddress address; - QGeoCoordinate coordinate; - QGeoRectangle viewport; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qgeopositioninfo.cpp b/src/location/qgeopositioninfo.cpp deleted file mode 100644 index 7cd5be32..00000000 --- a/src/location/qgeopositioninfo.cpp +++ /dev/null @@ -1,332 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qgeopositioninfo.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QGeoPositionInfoPrivate -{ -public: - QDateTime timestamp; - QGeoCoordinate coord; - QHash doubleAttribs; -}; - -/*! - \class QGeoPositionInfo - \inmodule QtLocation - \ingroup QtLocation-positioning - \since Qt Location 5.0 - - \brief The QGeoPositionInfo class contains information gathered on a global position, direction and velocity at a particular point in time. - - A QGeoPositionInfo contains, at a minimum, a geographical coordinate and - a timestamp. It may also have heading and speed measurements as well as - estimates of the accuracy of the provided data. - - \sa QGeoPositionInfoSource -*/ - -/*! - \enum QGeoPositionInfo::Attribute - Defines the attributes for positional information. - - \value Direction The bearing measured in degrees clockwise from true north to the direction of travel. - \value GroundSpeed The ground speed, in meters/sec. - \value VerticalSpeed The vertical speed, in meters/sec. - \value MagneticVariation The angle between the horizontal component of the magnetic field and true north, in degrees. Also known as magnetic declination. A positive value indicates a clockwise direction from true north and a negative value indicates a counter-clockwise direction. - \value HorizontalAccuracy The accuracy of the provided latitude-longitude value, in meters. - \value VerticalAccuracy The accuracy of the provided altitude value, in meters. -*/ - -/*! - Creates an invalid QGeoPositionInfo object. - - \sa isValid() -*/ -QGeoPositionInfo::QGeoPositionInfo() - : d(new QGeoPositionInfoPrivate) -{ -} - -/*! - Creates a QGeoPositionInfo for the given \a coordinate and \a timestamp. -*/ -QGeoPositionInfo::QGeoPositionInfo(const QGeoCoordinate &coordinate, const QDateTime ×tamp) - : d(new QGeoPositionInfoPrivate) -{ - d->timestamp = timestamp; - d->coord = coordinate; -} - -/*! - Creates a QGeoPositionInfo with the values of \a other. -*/ -QGeoPositionInfo::QGeoPositionInfo(const QGeoPositionInfo &other) - : d(new QGeoPositionInfoPrivate) -{ - operator=(other); -} - -/*! - Destroys a QGeoPositionInfo object. -*/ -QGeoPositionInfo::~QGeoPositionInfo() -{ - delete d; -} - -/*! - Assigns the values from \a other to this QGeoPositionInfo. -*/ -QGeoPositionInfo &QGeoPositionInfo::operator=(const QGeoPositionInfo & other) -{ - if (this == &other) - return *this; - - d->timestamp = other.d->timestamp; - d->coord = other.d->coord; - d->doubleAttribs = other.d->doubleAttribs; - - return *this; -} - -/*! - Returns true if all of this object's values are the same as those of - \a other. -*/ -bool QGeoPositionInfo::operator==(const QGeoPositionInfo &other) const -{ - return d->timestamp == other.d->timestamp - && d->coord == other.d->coord - && d->doubleAttribs == other.d->doubleAttribs; -} - -/*! - \fn bool QGeoPositionInfo::operator!=(const QGeoPositionInfo &other) const - - Returns true if any of this object's values are not the same as those of - \a other. -*/ - -/*! - Returns true if the timestamp() and coordinate() values are both valid. - - \sa QGeoCoordinate::isValid(), QDateTime::isValid() -*/ -bool QGeoPositionInfo::isValid() const -{ - return d->timestamp.isValid() && d->coord.isValid(); -} - -/*! - Sets the date and time at which this position was reported to \a timestamp. - - The \a timestamp must be in UTC time. - - \sa timestamp() -*/ -void QGeoPositionInfo::setTimestamp(const QDateTime ×tamp) -{ - d->timestamp = timestamp; -} - -/*! - Returns the date and time at which this position was reported, in UTC time. - - Returns an invalid QDateTime if no date/time value has been set. - - \sa setTimestamp() -*/ -QDateTime QGeoPositionInfo::timestamp() const -{ - return d->timestamp; -} - -/*! - Sets the coordinate for this position to \a coordinate. - - \sa coordinate() -*/ -void QGeoPositionInfo::setCoordinate(const QGeoCoordinate &coordinate) -{ - d->coord = coordinate; -} - -/*! - Returns the coordinate for this position. - - Returns an invalid coordinate if no coordinate has been set. - - \sa setCoordinate() -*/ -QGeoCoordinate QGeoPositionInfo::coordinate() const -{ - return d->coord; -} - -/*! - Sets the value for \a attribute to \a value. - - \sa attribute() -*/ -void QGeoPositionInfo::setAttribute(Attribute attribute, qreal value) -{ - d->doubleAttribs[int(attribute)] = value; -} - -/*! - Returns the value of the specified \a attribute as a qreal value. - - Returns -1 if the value has not been set, although this may also - be a legitimate value for some attributes. - - The function hasAttribute() should be used to determine whether or - not a value has been set for an attribute. - - \sa hasAttribute(), setAttribute() -*/ -qreal QGeoPositionInfo::attribute(Attribute attribute) const -{ - if (d->doubleAttribs.contains(int(attribute))) - return d->doubleAttribs[int(attribute)]; - return -1; -} - -/*! - Removes the specified \a attribute and its value. -*/ -void QGeoPositionInfo::removeAttribute(Attribute attribute) -{ - d->doubleAttribs.remove(int(attribute)); -} - -/*! - Returns true if the specified \a attribute is present for this - QGeoPositionInfo object. -*/ -bool QGeoPositionInfo::hasAttribute(Attribute attribute) const -{ - return d->doubleAttribs.contains(int(attribute)); -} - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QGeoPositionInfo &info) -{ - dbg.nospace() << "QGeoPositionInfo(" << info.d->timestamp; - dbg.nospace() << ", "; - dbg.nospace() << info.d->coord; - - QList attribs = info.d->doubleAttribs.keys(); - qStableSort(attribs.begin(), attribs.end()); // Output a sorted list from an unsorted hash. - for (int i = 0; i < attribs.count(); ++i) { - dbg.nospace() << ", "; - switch (attribs[i]) { - case QGeoPositionInfo::Direction: - dbg.nospace() << "Direction="; - break; - case QGeoPositionInfo::GroundSpeed: - dbg.nospace() << "GroundSpeed="; - break; - case QGeoPositionInfo::VerticalSpeed: - dbg.nospace() << "VerticalSpeed="; - break; - case QGeoPositionInfo::MagneticVariation: - dbg.nospace() << "MagneticVariation="; - break; - case QGeoPositionInfo::HorizontalAccuracy: - dbg.nospace() << "HorizontalAccuracy="; - break; - case QGeoPositionInfo::VerticalAccuracy: - dbg.nospace() << "VerticalAccuracy="; - break; - } - dbg.nospace() << info.d->doubleAttribs[attribs[i]]; - } - dbg.nospace() << ')'; - return dbg; -} -#endif - -#ifndef QT_NO_DATASTREAM -/*! - \fn QDataStream &operator<<(QDataStream &stream, const QGeoPositionInfo &info) - \relates QGeoPositionInfo - - Writes the given \a info to the specified \a stream. - - \sa {Serializing Qt Data Types} -*/ - -QDataStream &operator<<(QDataStream &stream, const QGeoPositionInfo &info) -{ - stream << info.d->timestamp; - stream << info.d->coord; - stream << info.d->doubleAttribs; - return stream; -} -#endif - -#ifndef QT_NO_DATASTREAM -/*! - \fn QDataStream &operator>>(QDataStream &stream, QGeoPositionInfo &info) - \relates QGeoPositionInfo - - Reads a coordinate from the specified \a stream into the given - \a info. - - \sa {Serializing Qt Data Types} -*/ - -QDataStream &operator>>(QDataStream &stream, QGeoPositionInfo &info) -{ - stream >> info.d->timestamp; - stream >> info.d->coord; - stream >> info.d->doubleAttribs; - return stream; -} -#endif - -QT_END_NAMESPACE diff --git a/src/location/qgeopositioninfo.h b/src/location/qgeopositioninfo.h deleted file mode 100644 index ac2f51ba..00000000 --- a/src/location/qgeopositioninfo.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QGEOPOSITIONINFO_H -#define QGEOPOSITIONINFO_H - -#include - -#include - -QT_BEGIN_NAMESPACE - -class QDebug; -class QDataStream; - -class QGeoPositionInfoPrivate; -class Q_LOCATION_EXPORT QGeoPositionInfo -{ -public: - enum Attribute { - Direction, - GroundSpeed, - VerticalSpeed, - MagneticVariation, - HorizontalAccuracy, - VerticalAccuracy - }; - - QGeoPositionInfo(); - QGeoPositionInfo(const QGeoCoordinate &coordinate, const QDateTime &updateTime); - QGeoPositionInfo(const QGeoPositionInfo &other); - ~QGeoPositionInfo(); - - QGeoPositionInfo &operator=(const QGeoPositionInfo &other); - - bool operator==(const QGeoPositionInfo &other) const; - inline bool operator!=(const QGeoPositionInfo &other) const { - return !operator==(other); - } - - bool isValid() const; - - void setTimestamp(const QDateTime ×tamp); - QDateTime timestamp() const; - - void setCoordinate(const QGeoCoordinate &coordinate); - QGeoCoordinate coordinate() const; - - void setAttribute(Attribute attribute, qreal value); - qreal attribute(Attribute attribute) const; - void removeAttribute(Attribute attribute); - bool hasAttribute(Attribute attribute) const; - -private: -#ifndef QT_NO_DEBUG_STREAM - friend Q_LOCATION_EXPORT QDebug operator<<(QDebug dbg, const QGeoPositionInfo &info); -#endif -#ifndef QT_NO_DATASTREAM - friend Q_LOCATION_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoPositionInfo &info); - friend Q_LOCATION_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoPositionInfo &info); -#endif - QGeoPositionInfoPrivate *d; -}; - -#ifndef QT_NO_DEBUG_STREAM -Q_LOCATION_EXPORT QDebug operator<<(QDebug dbg, const QGeoPositionInfo &info); -#endif - -#ifndef QT_NO_DATASTREAM -Q_LOCATION_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoPositionInfo &info); -Q_LOCATION_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoPositionInfo &info); -#endif - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qgeopositioninfosource.cpp b/src/location/qgeopositioninfosource.cpp deleted file mode 100644 index 15f65f46..00000000 --- a/src/location/qgeopositioninfosource.cpp +++ /dev/null @@ -1,462 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include "qgeopositioninfosource_p.h" -#include "qgeopositioninfosourcefactory.h" - -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_LIBRARY -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - ("org.qt-project.qt.position.sourcefactory/5.0", - QLatin1String("/position"))) -#endif - -/*! - \class QGeoPositionInfoSource - \inmodule QtLocation - \ingroup QtLocation-positioning - \since Qt Location 5.0 - - \brief The QGeoPositionInfoSource class is an abstract base class for the distribution of positional updates. - - The static function QGeoPositionInfoSource::createDefaultSource() creates a default - position source that is appropriate for the platform, if one is available. - Otherwise, QGeoPositionInfoSource will check for available plugins that - implement the QGeoPositionInfoSourceFactory interface. - - Users of a QGeoPositionInfoSource subclass can request the current position using - requestUpdate(), or start and stop regular position updates using - startUpdates() and stopUpdates(). When an update is available, - positionUpdated() is emitted. The last known position can be accessed with - lastKnownPosition(). - - If regular position updates are required, setUpdateInterval() can be used - to specify how often these updates should be emitted. If no interval is - specified, updates are simply provided whenever they are available. - For example: - - \code - // Emit updates every 10 seconds if available - QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(0); - if (source) - source->setUpdateInterval(10000); - \endcode - - To remove an update interval that was previously set, call - setUpdateInterval() with a value of 0. - - Note that the position source may have a minimum value requirement for - update intervals, as returned by minimumUpdateInterval(). - - \warning On Windows CE it is not possible to detect if a device is GPS enabled. - The default position source on a Windows CE device without GPS support will never provide any position data. -*/ - -/*! - \enum QGeoPositionInfoSource::PositioningMethod - Defines the types of positioning methods. - - \value SatellitePositioningMethods Satellite-based positioning methods such as GPS or GLONASS. - \value NonSatellitePositioningMethods Other positioning methods such as 3GPP cell identifier or WiFi based positioning. - \value AllPositioningMethods Satellite-based positioning methods as soon as available. Otherwise non-satellite based methods. -*/ - -void QGeoPositionInfoSourcePrivate::loadMeta() -{ - metaData = plugins().value(providerName); -} - -void QGeoPositionInfoSourcePrivate::loadPlugin() -{ - int idx = int(metaData.value(QStringLiteral("index")).toDouble()); - if (idx < 0) - return; - factory = qobject_cast(loader()->instance(idx)); -} - -QHash QGeoPositionInfoSourcePrivate::plugins(bool reload) -{ - static QHash plugins; - static bool alreadyDiscovered = false; - - if (reload == true) - alreadyDiscovered = false; - - if (!alreadyDiscovered) { - loadPluginMetadata(plugins); - alreadyDiscovered = true; - } - return plugins; -} - -static bool pluginComparator(const QJsonObject &p1, const QJsonObject &p2) -{ - const QString prio = QStringLiteral("Priority"); - if (p1.contains(prio) && !p2.contains(prio)) - return true; - if (!p1.contains(prio) && p2.contains(prio)) - return false; - if (p1.value(prio).isDouble() && !p2.value(prio).isDouble()) - return true; - if (!p1.value(prio).isDouble() && p2.value(prio).isDouble()) - return false; - return (p1.value(prio).toDouble() > p2.value(prio).toDouble()); -} - -QList QGeoPositionInfoSourcePrivate::pluginsSorted() -{ - QList list = plugins().values(); - qStableSort(list.begin(), list.end(), pluginComparator); - return list; -} - -void QGeoPositionInfoSourcePrivate::loadPluginMetadata(QHash &plugins) -{ - QFactoryLoader *l = loader(); - QList meta = l->metaData(); - for (int i = 0; i < meta.size(); ++i) { - QJsonObject obj = meta.at(i).value(QStringLiteral("MetaData")).toObject(); - obj.insert(QStringLiteral("index"), i); - plugins.insertMulti(obj.value(QStringLiteral("Provider")).toString(), obj); - } -} - -/*! - Creates a position source with the specified \a parent. -*/ - -QGeoPositionInfoSource::QGeoPositionInfoSource(QObject *parent) - : QObject(parent), - d(new QGeoPositionInfoSourcePrivate) -{ - d->interval = 0; - d->methods = 0; -} - -/*! - Destroys the position source. -*/ -QGeoPositionInfoSource::~QGeoPositionInfoSource() -{ - delete d; -} - -/*! - \property QGeoPositionInfoSource::sourceName - \brief This property holds the unique name of the position source - implementation in use. - - This is the same name that can be passed to createSource() in order to - create a new instance of a particular position source implementation. -*/ -QString QGeoPositionInfoSource::sourceName() const -{ - return d->metaData.value(QStringLiteral("Provider")).toString(); -} - -/*! - \property QGeoPositionInfoSource::updateInterval - \brief This property holds the requested interval in milliseconds between each update. - - If the update interval is not set (or is set to 0) the - source will provide updates as often as necessary. - - If the update interval is set, the source will provide updates at an - interval as close to the requested interval as possible. If the requested - interval is less than the minimumUpdateInterval(), - the minimum interval is used instead. - - Changes to the update interval will happen as soon as is practical, however the - time the change takes may vary between implementations. Whether or not the elapsed - time from the previous interval is counted as part of the new interval is also - implementation dependent. - - The default value for this property is 0. - - Note: Subclass implementations must call the base implementation of - setUpdateInterval() so that updateInterval() returns the correct value. -*/ -void QGeoPositionInfoSource::setUpdateInterval(int msec) -{ - d->interval = msec; -} - -int QGeoPositionInfoSource::updateInterval() const -{ - return d->interval; -} - -/*! - Sets the preferred positioning methods for this source to \a methods. - - If \a methods includes a method that is not supported by the source, the - unsupported method will be ignored. - - If \a methods does not include any methods supported by the source, the - preferred methods will be set to the set of methods which the source supports. - - \b {Note:} When reimplementing this method, subclasses must call the - base method implementation to ensure preferredPositioningMethods() returns the correct value. - - \sa supportedPositioningMethods() -*/ -void QGeoPositionInfoSource::setPreferredPositioningMethods(PositioningMethods methods) -{ - d->methods = methods & supportedPositioningMethods(); - if (d->methods == 0) { - d->methods = supportedPositioningMethods(); - } -} - -/*! - Returns the positioning methods set by setPreferredPositioningMethods(). -*/ -QGeoPositionInfoSource::PositioningMethods QGeoPositionInfoSource::preferredPositioningMethods() const -{ - return d->methods; -} - -/*! - Creates and returns a position source with the given \a parent that - reads from the system's default sources of location data, or the plugin - with the highest available priority. - - Returns 0 if the system has no default position source, no valid plugins - could be found or the user does not have the permission to access the current position. -*/ -QGeoPositionInfoSource *QGeoPositionInfoSource::createDefaultSource(QObject *parent) -{ - QList plugins = QGeoPositionInfoSourcePrivate::pluginsSorted(); - foreach (const QJsonObject &obj, plugins) { - if (obj.value(QStringLiteral("Position")).isBool() - && obj.value(QStringLiteral("Position")).toBool()) - { - QGeoPositionInfoSourcePrivate d; - d.metaData = obj; - d.loadPlugin(); - QGeoPositionInfoSource *s = 0; - if (d.factory) - s = d.factory->positionInfoSource(parent); - if (s) { - s->d->metaData = d.metaData; - return s; - } - } - } - return 0; -} - - -/*! - Creates and returns a position source with the given \a parent, - by loading the plugin named \a sourceName. - - Returns 0 if the plugin cannot be found. -*/ -QGeoPositionInfoSource *QGeoPositionInfoSource::createSource(const QString &sourceName, QObject *parent) -{ - QHash plugins = QGeoPositionInfoSourcePrivate::plugins(); - if (plugins.contains(sourceName)) - { - QGeoPositionInfoSourcePrivate d; - d.metaData = plugins.value(sourceName); - d.loadPlugin(); - QGeoPositionInfoSource *src = 0; - if (d.factory) - src = d.factory->positionInfoSource(parent); - if (src) - { - src->d->metaData = d.metaData; - return src; - } - } - return 0; -} - - -/*! - Returns a list of available source plugins. This includes any default backend - plugin for the current platform. -*/ -QStringList QGeoPositionInfoSource::availableSources() -{ - QStringList plugins; - QHash meta = QGeoPositionInfoSourcePrivate::plugins(); - foreach (const QString &name, meta.keys()) { - if (meta.value(name).value(QStringLiteral("Position")).isBool() - && meta.value(name).value(QStringLiteral("Position")).toBool()) { - plugins << name; - } - } - - return plugins; -} - -/*! - \fn QGeoPositionInfo QGeoPositionInfoSource::lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const = 0; - - Returns an update containing the last known position, or a null update - if none is available. - - If \a fromSatellitePositioningMethodsOnly is true, this returns the last - known position received from a satellite positioning method; if none - is available, a null update is returned. -*/ - -/*! - \fn virtual PositioningMethods QGeoPositionInfoSource::supportedPositioningMethods() const = 0; - - Returns the positioning methods available to this source. - - \sa setPreferredPositioningMethods() -*/ - - -/*! - \property QGeoPositionInfoSource::minimumUpdateInterval - \brief This property holds the minimum time (in milliseconds) required to retrieve a position update. - - This is the minimum value accepted by setUpdateInterval() and - requestUpdate(). -*/ - - -/*! - \fn virtual void QGeoPositionInfoSource::startUpdates() = 0; - - Starts emitting updates at regular intervals as specified by setUpdateInterval(). - - If setUpdateInterval() has not been called, the source will emit updates - as soon as they become available. - - An updateTimout() signal will be emitted if this QGeoPositionInfoSource subclass determines - that it will not be able to provide regular updates. This could happen if a satellite fix is - lost or if a hardware error is detected. Position updates will recommence if the data becomes - available later on. The updateTimout() signal will not be emitted again until after the - periodic updates resume. -*/ - -/*! - \fn virtual void QGeoPositionInfoSource::stopUpdates() = 0; - - Stops emitting updates at regular intervals. -*/ - -/*! - \fn virtual void QGeoPositionInfoSource::requestUpdate(int timeout = 0); - - Attempts to get the current position and emit positionUpdated() with - this information. If the current position cannot be found within the given \a timeout - (in milliseconds) or if \a timeout is less than the value returned by - minimumUpdateInterval(), updateTimeout() is emitted. - - If the timeout is zero, the timeout defaults to a reasonable timeout - period as appropriate for the source. - - This does nothing if another update request is in progress. However - it can be called even if startUpdates() has already been called and - regular updates are in progress. - - If the source uses multiple positioning methods, it tries to get the - current position from the most accurate positioning method within the - given timeout. -*/ - -/*! - \fn virtual QGeoPositionInfoSource::Error QGeoPositionInfoSource::error() const; - - Returns the type of error that last occurred. - -*/ - -/*! - \fn void QGeoPositionInfoSource::positionUpdated(const QGeoPositionInfo &update); - - If startUpdates() or requestUpdate() is called, this signal is emitted - when an update becomes available. - - The \a update value holds the value of the new update. -*/ - -/*! - \fn void QGeoPositionInfoSource::updateTimeout(); - - If requestUpdate() was called, this signal will be emitted if the current position could not - be retrieved within the specified timeout. - - If startUpdates() has been called, this signal will be emitted if this QGeoPositionInfoSource - subclass determines that it will not be able to provide further regular updates. This signal - will not be emitted again until after the regular updates resume. -*/ - -/*! - \fn void QGeoPositionInfoSource::error(QGeoPositionInfoSource::Error positioningError) - - This signal is emitted after an error occurred. The \a positioningError - parameter describes the type of error that occurred. - -*/ - -/*! - \enum QGeoPositionInfoSource::Error - - The Error enumeration represents the errors which can occur. - - \value AccessError The connection setup to the remote positioning backend failed because the - application lacked the required privileges. - \value ClosedError The remote positioning backend closed the connection, which happens for example in case - the user is switching location services to off. This object becomes invalid and should be deleted. - A call to createDefaultSource() can be used to create a new source later on. - \value UnknownSourceError An unidentified error occurred. - */ - -#include "moc_qgeopositioninfosource.cpp" - -QT_END_NAMESPACE diff --git a/src/location/qgeopositioninfosource.h b/src/location/qgeopositioninfosource.h deleted file mode 100644 index 931316ce..00000000 --- a/src/location/qgeopositioninfosource.h +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QGEOPOSITIONINFOSOURCE_H -#define QGEOPOSITIONINFOSOURCE_H - -#include - -#include - -QT_BEGIN_NAMESPACE - -class QGeoPositionInfoSourcePrivate; -class Q_LOCATION_EXPORT QGeoPositionInfoSource : public QObject -{ - Q_OBJECT - Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval) - Q_PROPERTY(int minimumUpdateInterval READ minimumUpdateInterval) - Q_PROPERTY(QString sourceName READ sourceName) - -public: - enum Error { - AccessError, - ClosedError, /* 1 */ - UnknownSourceError = -1 - }; - Q_ENUMS(Error) - - enum PositioningMethod { - SatellitePositioningMethods = 0x000000ff, - NonSatellitePositioningMethods = 0xffffff00, - AllPositioningMethods = 0xffffffff - }; - Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod) - - explicit QGeoPositionInfoSource(QObject *parent); - virtual ~QGeoPositionInfoSource(); - - virtual void setUpdateInterval(int msec); - int updateInterval() const; - - virtual void setPreferredPositioningMethods(PositioningMethods methods); - PositioningMethods preferredPositioningMethods() const; - - virtual QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const = 0; - - virtual PositioningMethods supportedPositioningMethods() const = 0; - virtual int minimumUpdateInterval() const = 0; - - QString sourceName() const; - - static QGeoPositionInfoSource *createDefaultSource(QObject *parent); - static QGeoPositionInfoSource *createSource(const QString &sourceName, QObject *parent); - static QStringList availableSources(); - virtual Error error() const = 0; - -public Q_SLOTS: - virtual void startUpdates() = 0; - virtual void stopUpdates() = 0; - - virtual void requestUpdate(int timeout = 0) = 0; - -Q_SIGNALS: - void positionUpdated(const QGeoPositionInfo &update); - void updateTimeout(); - void error(QGeoPositionInfoSource::Error); - -private: - Q_DISABLE_COPY(QGeoPositionInfoSource) - QGeoPositionInfoSourcePrivate *d; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QGeoPositionInfoSource::PositioningMethods) - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qgeopositioninfosource_p.h b/src/location/qgeopositioninfosource_p.h deleted file mode 100644 index 97baadbf..00000000 --- a/src/location/qgeopositioninfosource_p.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOPOSITIONINFOSOURCE_P_H -#define QGEOPOSITIONINFOSOURCE_P_H - -#include "qgeopositioninfosource.h" -#include "qgeopositioninfosourcefactory.h" -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QGeoPositionInfoSourcePrivate -{ -public: - int interval; - QGeoPositionInfoSource::PositioningMethods methods; - QJsonObject metaData; - QGeoPositionInfoSourceFactory *factory; - QString providerName; - - void loadMeta(); - void loadPlugin(); - - static QHash plugins(bool reload = false); - static void loadPluginMetadata(QHash &list); - static QList pluginsSorted(); -}; - -QT_END_NAMESPACE - -#endif // QGEOPOSITIONINFOSOURCE_P_H diff --git a/src/location/qgeopositioninfosourcefactory.cpp b/src/location/qgeopositioninfosourcefactory.cpp deleted file mode 100644 index 0c0a0404..00000000 --- a/src/location/qgeopositioninfosourcefactory.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgeopositioninfosourcefactory.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QGeoPositionInfoSourceFactory - \inmodule QtLocation - \ingroup QtLocation-impl - \since Qt Location 5.0 - - \brief The QGeoPositionInfoSourceFactory class is a factory class used - as the plugin interface for external providers of positioning data. - - The other functions must be overridden by all plugins, other than - sourcePriority() which defaults to returning 0. Higher values of - priority will be preferred to lower ones. -*/ - -/*! - \fn QGeoPositionInfoSource *QGeoPositionInfoSourceFactory::positionInfoSource(QObject *parent) - - Returns a new QGeoPositionInfoSource associated with this plugin - with parent \a parent. Can also return 0, in which case the plugin - loader will use the factory with the next highest priority. - */ - -/*! - \fn QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactory::satelliteInfoSource(QObject *parent) - - Returns a new QGeoSatelliteInfoSource associated with this plugin - with parent \a parent. Can also return 0, in which case the plugin - loader will use the factory with the next highest priority. - */ - -/*! - \fn QGeoAreaMonitor *QGeoPositionInfoSourceFactory::areaMonitor(QObject *parent); - - Returns a new QGeoAreaMonitor associated with this plugin with parent \a parent. - Can also return 0, in which case the plugin loader will use the factory with the - next highest priority. - */ - -/*! - Destroys the position info source factory. -*/ -QGeoPositionInfoSourceFactory::~QGeoPositionInfoSourceFactory() -{} - -QT_END_NAMESPACE diff --git a/src/location/qgeopositioninfosourcefactory.h b/src/location/qgeopositioninfosourcefactory.h deleted file mode 100644 index 7ddb801d..00000000 --- a/src/location/qgeopositioninfosourcefactory.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOPOSITIONINFOSOURCEFACTORY_H -#define QGEOPOSITIONINFOSOURCEFACTORY_H - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_LOCATION_EXPORT QGeoPositionInfoSourceFactory -{ -public: - virtual ~QGeoPositionInfoSourceFactory(); - - virtual QGeoPositionInfoSource *positionInfoSource(QObject *parent) = 0; - virtual QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent) = 0; - virtual QGeoAreaMonitor *areaMonitor(QObject *parent) = 0; -}; - -#define QT_POSITION_SOURCE_INTERFACE -Q_DECLARE_INTERFACE(QGeoPositionInfoSourceFactory, - "org.qt-project.qt.position.sourcefactory/5.0") - -QT_END_NAMESPACE - -#endif // QGEOPOSITIONINFOSOURCEFACTORY_H diff --git a/src/location/qgeorectangle.cpp b/src/location/qgeorectangle.cpp deleted file mode 100644 index 4ee4f16f..00000000 --- a/src/location/qgeorectangle.cpp +++ /dev/null @@ -1,899 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgeorectangle.h" -#include "qgeorectangle_p.h" - -#include "qgeocoordinate.h" -#include "qnumeric.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QGeoRectangle - \inmodule QtLocation - \ingroup QtLocation-positioning - \since Qt Location 5.0 - - \brief The QGeoRectangle class defines a rectangular geographic area. - - The rectangle is defined in terms of a QGeoCoordinate which specifies the - top left coordinate of the rectangle and a QGeoCoordinate which specifies - the bottom right coordinate of the rectangle. - - A geo rectangle is considered invalid if the top left or bottom right - coordinates are invalid or if the top left coordinate is south of the - bottom right coordinate. - - Geo rectangles can never cross the poles. - - Several methods behave as though the geo rectangle is defined in terms of a - center coordinate, the width of the geo rectangle in degrees and the height - of the geo rectangle in degrees. - - If the height or center of a geo rectangle is adjusted such that it would - cross one of the poles the height is modified such that the geo rectangle - touches but does not cross the pole and that the center coordinate is still - in the center of the geo rectangle. -*/ - -#ifdef Q_NO_USING_KEYWORD -/*! - \fn bool QGeoRectangle::operator==(const QGeoShape &other) const - - Returns true if \a other is equivalent to this geo rectangle; otherwise returns false. -*/ - -/*! - \fn bool QGeoRectangle::operator!=(const QGeoShape &other) const - - Returns true if \a other is not equivalent to this geo rectangle; otherwise returns false. -*/ - -/*! - \fn bool QGeoRectangle::contains(const QGeoCoordinate &coordinate) const - - Returns true if \a coordinate is within this geo rectangle; otherwise returns false. -*/ -#endif - -inline QGeoRectanglePrivate *QGeoRectangle::d_func() -{ - return static_cast(d_ptr.data()); -} - -inline const QGeoRectanglePrivate *QGeoRectangle::d_func() const -{ - return static_cast(d_ptr.constData()); -} - -/*! - Constructs a new, invalid geo rectangle. -*/ -QGeoRectangle::QGeoRectangle() -: QGeoShape(new QGeoRectanglePrivate) -{ -} - -/*! - Constructs a new geo rectangle centered at \a center with a - width in degrees of \a degreesWidth and a height in degrees of \a degreesHeight. - - If \a degreesHeight would take the geo rectangle beyond one of the poles, - the height of the geo rectangle will be truncated such that the geo rectangle - only extends up to the pole. The center of the geo rectangle will be - unchanged, and the height will be adjusted such that the center point is at - the center of the truncated geo rectangle. -*/ -QGeoRectangle::QGeoRectangle(const QGeoCoordinate ¢er, double degreesWidth, double degreesHeight) -{ - d_ptr = new QGeoRectanglePrivate(center, center); - setWidth(degreesWidth); - setHeight(degreesHeight); -} - -/*! - Constructs a new geo rectangle with a top left coordinate \a topLeft and a bottom right - coordinate \a bottomRight. -*/ -QGeoRectangle::QGeoRectangle(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight) -{ - d_ptr = new QGeoRectanglePrivate(topLeft, bottomRight); -} - -/*! - Constructs a geo rectangle from the contents of \a other. -*/ -QGeoRectangle::QGeoRectangle(const QGeoRectangle &other) -: QGeoShape(other) -{ -} - -/*! - Constructs a geo rectangle from the contents of \a other. -*/ -QGeoRectangle::QGeoRectangle(const QGeoShape &other) -: QGeoShape(other) -{ - if (type() != QGeoShape::RectangleType) - d_ptr = new QGeoRectanglePrivate; -} - -/*! - Destroys this geo rectangle. -*/ -QGeoRectangle::~QGeoRectangle() -{ -} - -/*! - Assigns \a other to this geo rectangle and returns a reference to this geo rectangle. -*/ -QGeoRectangle &QGeoRectangle::operator=(const QGeoRectangle &other) -{ - QGeoShape::operator=(other); - return *this; -} - -/*! - Returns whether this geo rectangle is equal to \a other. -*/ -bool QGeoRectangle::operator==(const QGeoRectangle &other) const -{ - Q_D(const QGeoRectangle); - - return *d == *other.d_func(); -} - -/*! - Returns whether this geo rectangle is not equal to \a other. -*/ -bool QGeoRectangle::operator!=(const QGeoRectangle &other) const -{ - Q_D(const QGeoRectangle); - - return !(*d == *other.d_func()); -} - -bool QGeoRectanglePrivate::isValid() const -{ - return topLeft.isValid() && bottomRight.isValid() && - topLeft.latitude() >= bottomRight.latitude(); -} - -bool QGeoRectanglePrivate::isEmpty() const -{ - if (!isValid()) - return true; - - return topLeft.latitude() == bottomRight.latitude() || - topLeft.longitude() == bottomRight.longitude(); -} - -/*! - Sets the top left coordinate of this geo rectangle to \a topLeft. -*/ -void QGeoRectangle::setTopLeft(const QGeoCoordinate &topLeft) -{ - Q_D(QGeoRectangle); - - d->topLeft = topLeft; -} - -/*! - Returns the top left coordinate of this geo rectangle. -*/ -QGeoCoordinate QGeoRectangle::topLeft() const -{ - Q_D(const QGeoRectangle); - - return d->topLeft; -} - -/*! - Sets the top right coordinate of this geo rectangle to \a topRight. -*/ -void QGeoRectangle::setTopRight(const QGeoCoordinate &topRight) -{ - Q_D(QGeoRectangle); - - d->topLeft.setLatitude(topRight.latitude()); - d->bottomRight.setLongitude(topRight.longitude()); -} - -/*! - Returns the top right coordinate of this geo rectangle. -*/ -QGeoCoordinate QGeoRectangle::topRight() const -{ - // TODO remove? - if (!isValid()) - return QGeoCoordinate(); - - Q_D(const QGeoRectangle); - - return QGeoCoordinate(d->topLeft.latitude(), d->bottomRight.longitude()); -} - -/*! - Sets the bottom left coordinate of this geo rectangle to \a bottomLeft. -*/ -void QGeoRectangle::setBottomLeft(const QGeoCoordinate &bottomLeft) -{ - Q_D(QGeoRectangle); - - d->bottomRight.setLatitude(bottomLeft.latitude()); - d->topLeft.setLongitude(bottomLeft.longitude()); -} - -/*! - Returns the bottom left coordinate of this geo rectangle. -*/ -QGeoCoordinate QGeoRectangle::bottomLeft() const -{ - // TODO remove? - if (!isValid()) - return QGeoCoordinate(); - - Q_D(const QGeoRectangle); - - return QGeoCoordinate(d->bottomRight.latitude(), d->topLeft.longitude()); -} - -/*! - Sets the bottom right coordinate of this geo rectangle to \a bottomRight. -*/ -void QGeoRectangle::setBottomRight(const QGeoCoordinate &bottomRight) -{ - Q_D(QGeoRectangle); - - d->bottomRight = bottomRight; -} - -/*! - Returns the bottom right coordinate of this geo rectangle. -*/ -QGeoCoordinate QGeoRectangle::bottomRight() const -{ - Q_D(const QGeoRectangle); - - return d->bottomRight; -} - -/*! - Sets the center of this geo rectangle to \a center. - - If this causes the geo rectangle to cross on of the poles the height of the - geo rectangle will be truncated such that the geo rectangle only extends up - to the pole. The center of the geo rectangle will be unchanged, and the - height will be adjusted such that the center point is at the center of the - truncated geo rectangle. - -*/ -void QGeoRectangle::setCenter(const QGeoCoordinate ¢er) -{ - Q_D(QGeoRectangle); - - if (!isValid()) { - d->topLeft = center; - d->bottomRight = center; - return; - } - double width = this->width(); - double height = this->height(); - - double tlLat = center.latitude() + height / 2.0; - double tlLon = center.longitude() - width / 2.0; - double brLat = center.latitude() - height / 2.0; - double brLon = center.longitude() + width / 2.0; - - if (tlLon < -180.0) - tlLon += 360.0; - if (tlLon > 180.0) - tlLon -= 360.0; - - if (brLon < -180.0) - brLon += 360.0; - if (brLon > 180.0) - brLon -= 360.0; - - if (tlLat > 90.0) { - brLat = 2 * center.latitude() - 90.0; - tlLat = 90.0; - } - - if (tlLat < -90.0) { - brLat = -90.0; - tlLat = -90.0; - } - - if (brLat > 90.0) { - tlLat = 90.0; - brLat = 90.0; - } - - if (brLat < -90.0) { - tlLat = 2 * center.latitude() + 90.0; - brLat = -90.0; - } - - if (width == 360.0) { - tlLon = -180.0; - brLon = 180.0; - } - - d->topLeft = QGeoCoordinate(tlLat, tlLon); - d->bottomRight = QGeoCoordinate(brLat, brLon); -} - -/*! - Returns the center of this geo rectangle. -*/ -QGeoCoordinate QGeoRectangle::center() const -{ - if (!isValid()) - return QGeoCoordinate(); - - Q_D(const QGeoRectangle); - - double cLat = (d->topLeft.latitude() + d->bottomRight.latitude()) / 2.0; - - double cLon = (d->bottomRight.longitude() + d->topLeft.longitude()) / 2.0; - if (d->topLeft.longitude() > d->bottomRight.longitude()) { - cLon = cLon - 180.0; - } - - if (cLon < -180.0) - cLon += 360.0; - if (cLon > 180.0) - cLon -= 360.0; - - return QGeoCoordinate(cLat, cLon); -} - -/*! - Sets the width of this geo rectangle in degrees to \a degreesWidth. - - If \a degreesWidth is less than 0.0 or if this geo rectangle is invalid this - function does nothing. To set up the values of an invalid - geo rectangle based on the center, width and height you should use - setCenter() first in order to make the geo rectangle valid. - - If \a degreesWidth is greater than 360.0 then 360.0 is used as the width, - the leftmost longitude of the geo rectangle is set to -180.0 degrees and the - rightmost longitude of the geo rectangle is set to 180.0 degrees. -*/ -void QGeoRectangle::setWidth(double degreesWidth) -{ - if (!isValid()) - return; - - if (degreesWidth < 0.0) - return; - - Q_D(QGeoRectangle); - - if (degreesWidth >= 360.0) { - d->topLeft.setLongitude(-180.0); - d->bottomRight.setLongitude(180.0); - return; - } - - double tlLat = d->topLeft.latitude(); - double brLat = d->bottomRight.latitude(); - - QGeoCoordinate c = center(); - - double tlLon = c.longitude() - degreesWidth / 2.0; - - if (tlLon < -180.0) - tlLon += 360.0; - if (tlLon > 180.0) - tlLon -= 360.0; - - double brLon = c.longitude() + degreesWidth / 2.0; - - if (brLon < -180.0) - brLon += 360.0; - if (brLon > 180.0) - brLon -= 360.0; - - d->topLeft = QGeoCoordinate(tlLat, tlLon); - d->bottomRight = QGeoCoordinate(brLat, brLon); -} - -/*! - Returns the width of this geo rectangle in degrees. - - The return value is undefined if this geo rectangle is invalid. -*/ -double QGeoRectangle::width() const -{ - if (!isValid()) - return qQNaN(); - - Q_D(const QGeoRectangle); - - double result = d->bottomRight.longitude() - d->topLeft.longitude(); - if (result < 0.0) - result += 360.0; - if (result > 360.0) - result -= 360.0; - - return result; -} - -/*! - Sets the height of this geo rectangle in degrees to \a degreesHeight. - - If \a degreesHeight is less than 0.0 or if this geo rectangle is invalid - this function does nothing. To set up the values of an invalid - geo rectangle based on the center, width and height you should use - setCenter() first in order to make the geo rectangle valid. - - If the change in height would cause the geo rectangle to cross a pole - the height is adjusted such that the geo rectangle only touches the pole. - - This change is done such that the center coordinate is still at the - center of the geo rectangle, which may result in a geo rectangle with - a smaller height than might otherwise be expected. - - If \a degreesHeight is greater than 180.0 then 180.0 is used as the height. -*/ -void QGeoRectangle::setHeight(double degreesHeight) -{ - if (!isValid()) - return; - - if (degreesHeight < 0.0) - return; - - if (degreesHeight >= 180.0) { - degreesHeight = 180.0; - } - - Q_D(QGeoRectangle); - - double tlLon = d->topLeft.longitude(); - double brLon = d->bottomRight.longitude(); - - QGeoCoordinate c = center(); - - double tlLat = c.latitude() + degreesHeight / 2.0; - double brLat = c.latitude() - degreesHeight / 2.0; - - if (tlLat > 90.0) { - brLat = 2* c.latitude() - 90.0; - tlLat = 90.0; - } - - if (tlLat < -90.0) { - brLat = -90.0; - tlLat = -90.0; - } - - if (brLat > 90.0) { - tlLat = 90.0; - brLat = 90.0; - } - - if (brLat < -90.0) { - tlLat = 2 * c.latitude() + 90.0; - brLat = -90.0; - } - - d->topLeft = QGeoCoordinate(tlLat, tlLon); - d->bottomRight = QGeoCoordinate(brLat, brLon); -} - -/*! - Returns the height of this geo rectangle in degrees. - - The return value is undefined if this geo rectangle is invalid. -*/ -double QGeoRectangle::height() const -{ - if (!isValid()) - return qQNaN(); - - Q_D(const QGeoRectangle); - - double result = d->topLeft.latitude() - d->bottomRight.latitude(); - if (result < 0.0) - result = qQNaN(); - return result; -} - -bool QGeoRectanglePrivate::contains(const QGeoCoordinate &coordinate) const -{ - if (!isValid() || !coordinate.isValid()) - return false; - - double left = topLeft.longitude(); - double right = bottomRight.longitude(); - double top = topLeft.latitude(); - double bottom = bottomRight.latitude(); - - double lon = coordinate.longitude(); - double lat = coordinate.latitude(); - - if (lat > top) - return false; - if (lat < bottom) - return false; - - if ((lat == 90.0) && (top == 90.0)) - return true; - - if ((lat == -90.0) && (bottom == -90.0)) - return true; - - if (left <= right) { - if ((lon < left) || (lon > right)) - return false; - } else { - if ((lon < left) && (lon > right)) - return false; - } - - return true; -} - -/*! - Returns whether the geo rectangle \a rectangle is contained within this - geo rectangle. -*/ -bool QGeoRectangle::contains(const QGeoRectangle &rectangle) const -{ - Q_D(const QGeoRectangle); - - return (d->contains(rectangle.topLeft()) - && d->contains(rectangle.topRight()) - && d->contains(rectangle.bottomLeft()) - && d->contains(rectangle.bottomRight())); -} - -/*! - Returns whether the geo rectangle \a rectangle intersects this geo rectangle. - - If the top or bottom edges of both geo rectangles are at one of the poles - the geo rectangles are considered to be intersecting, since the longitude - is irrelevant when the edges are at the pole. -*/ -bool QGeoRectangle::intersects(const QGeoRectangle &rectangle) const -{ - Q_D(const QGeoRectangle); - - double left1 = d->topLeft.longitude(); - double right1 = d->bottomRight.longitude(); - double top1 = d->topLeft.latitude(); - double bottom1 = d->bottomRight.latitude(); - - double left2 = rectangle.d_func()->topLeft.longitude(); - double right2 = rectangle.d_func()->bottomRight.longitude(); - double top2 = rectangle.d_func()->topLeft.latitude(); - double bottom2 = rectangle.d_func()->bottomRight.latitude(); - - if (top1 < bottom2) - return false; - - if (bottom1 > top2) - return false; - - if ((top1 == 90.0) && (top1 == top2)) - return true; - - if ((bottom1 == -90.0) && (bottom1 == bottom2)) - return true; - - if (left1 < right1) { - if (left2 < right2) { - if ((left1 > right2) || (right1 < left2)) - return false; - } else { - if ((left1 > right2) && (right1 < left2)) - return false; - } - } else { - if (left2 < right2) { - if ((left2 > right1) && (right2 < left1)) - return false; - } else { - // if both wrap then they have to intersect - } - } - - return true; -} - -/*! - Translates this geo rectangle by \a degreesLatitude northwards and \a - degreesLongitude eastwards. - - Negative values of \a degreesLatitude and \a degreesLongitude correspond to - southward and westward translation respectively. - - If the translation would have caused the geo rectangle to cross a pole the - geo rectangle will be translated until the top or bottom edge of the geo rectangle - touches the pole but not further. -*/ -void QGeoRectangle::translate(double degreesLatitude, double degreesLongitude) -{ - // TODO handle dlat, dlon larger than 360 degrees - - Q_D(QGeoRectangle); - - double tlLat = d->topLeft.latitude(); - double tlLon = d->topLeft.longitude(); - double brLat = d->bottomRight.latitude(); - double brLon = d->bottomRight.longitude(); - - if ((tlLat != 90.0) || (brLat != -90.0)) { - tlLat += degreesLatitude; - brLat += degreesLatitude; - } - - if ( (tlLon != -180.0) || (brLon != 180.0) ) { - tlLon += degreesLongitude; - brLon += degreesLongitude; - } - - if (tlLon < -180.0) - tlLon += 360.0; - if (tlLon > 180.0) - tlLon -= 360.0; - - if (brLon < -180.0) - brLon += 360.0; - if (brLon > 180.0) - brLon -= 360.0; - - if (tlLat > 90.0) - tlLat = 90.0; - - if (tlLat < -90.0) - tlLat = -90.0; - - if (brLat > 90.0) - brLat = 90.0; - - if (brLat < -90.0) - brLat = -90.0; - - d->topLeft = QGeoCoordinate(tlLat, tlLon); - d->bottomRight = QGeoCoordinate(brLat, brLon); -} - -/*! - Returns a copy of this geo rectangle translated by \a degreesLatitude northwards and \a - degreesLongitude eastwards. - - Negative values of \a degreesLatitude and \a degreesLongitude correspond to - southward and westward translation respectively. - - \sa translate() -*/ -QGeoRectangle QGeoRectangle::translated(double degreesLatitude, double degreesLongitude) const -{ - QGeoRectangle result(*this); - result.translate(degreesLatitude, degreesLongitude); - return result; -} - -/*! - Returns the smallest geo rectangle which contains both this geo rectangle and \a rectangle. - - If the centers of the two geo rectangles are separated by exactly 180.0 degrees then the - width is set to 360.0 degrees with the leftmost longitude set to -180.0 degrees and the - rightmost longitude set to 180.0 degrees. This is done to ensure that the result is - independent of the order of the operands. - -*/ -QGeoRectangle QGeoRectangle::united(const QGeoRectangle &rectangle) const -{ - QGeoRectangle result(*this); - result |= rectangle; - return result; -} - -/*! - \fn QGeoRectangle QGeoRectangle::operator|(const QGeoRectangle &rectangle) const - - Returns the smallest geo rectangle which contains both this geo rectangle and \a rectangle. - - If the centers of the two geo rectangles are separated by exactly 180.0 degrees then the - width is set to 360.0 degrees with the leftmost longitude set to -180.0 degrees and the - rightmost longitude set to 180.0 degrees. This is done to ensure that the result is - independent of the order of the operands. - -*/ - -/*! - Returns the smallest geo rectangle which contains both this geo rectangle and \a rectangle. - - If the centers of the two geo rectangles are separated by exactly 180.0 degrees then the - width is set to 360.0 degrees with the leftmost longitude set to -180.0 degrees and the - rightmost longitude set to 180.0 degrees. This is done to ensure that the result is - independent of the order of the operands. - -*/ -QGeoRectangle &QGeoRectangle::operator|=(const QGeoRectangle &rectangle) -{ - // If non-intersecting goes for most narrow box - - Q_D(QGeoRectangle); - - double left1 = d->topLeft.longitude(); - double right1 = d->bottomRight.longitude(); - double top1 = d->topLeft.latitude(); - double bottom1 = d->bottomRight.latitude(); - - double left2 = rectangle.d_func()->topLeft.longitude(); - double right2 = rectangle.d_func()->bottomRight.longitude(); - double top2 = rectangle.d_func()->topLeft.latitude(); - double bottom2 = rectangle.d_func()->bottomRight.latitude(); - - double top = qMax(top1, top2); - double bottom = qMin(bottom1, bottom2); - - double left = 0.0; - double right = 0.0; - - bool wrap1 = (left1 > right1); - bool wrap2 = (left2 > right2); - - if ((wrap1 && wrap2) || (!wrap1 && !wrap2)) { - - double w = qAbs((left1 + right1 - left2 - right2) / 2.0); - - if (w < 180.0) { - left = qMin(left1, left2); - right = qMax(right1, right2); - } else if (w > 180.0) { - left = qMax(left1, left2); - right = qMin(right1, right2); - } else { - left = -180.0; - right = 180.0; - } - - } else { - double wrapLeft = 0.0; - double wrapRight = 0.0; - double nonWrapLeft = 0.0; - double nonWrapRight = 0.0; - - if (wrap1) { - wrapLeft = left1; - wrapRight = right1; - nonWrapLeft = left2; - nonWrapRight = right2; - } else { - wrapLeft = left2; - wrapRight = right2; - nonWrapLeft = left1; - nonWrapRight = right1; - } - - bool joinWrapLeft = (nonWrapRight >= wrapLeft); - bool joinWrapRight = (nonWrapLeft <= wrapRight); - - if (joinWrapLeft) { - if (joinWrapRight) { - left = -180.0; - right = 180.0; - } else { - left = nonWrapLeft; - right = wrapRight; - } - } else { - if (joinWrapRight) { - left = wrapLeft; - right = nonWrapRight; - } else { - double wrapRightDistance = nonWrapLeft - wrapRight; - double wrapLeftDistance = wrapLeft - nonWrapRight; - - if (wrapLeftDistance == wrapRightDistance) { - left = -180.0; - right = 180.0; - } else if (wrapLeftDistance < wrapRightDistance) { - left = nonWrapLeft; - right = wrapRight; - } else { - left = wrapLeft; - right = nonWrapRight; - } - } - } - } - - if (((left1 == -180) && (right1 == 180.0)) - || ((left2 == -180) && (right2 == 180.0))) { - left = -180; - right = 180; - } - - d->topLeft = QGeoCoordinate(top, left); - d->bottomRight = QGeoCoordinate(bottom, right); - - return *this; -} - -/******************************************************************************* -*******************************************************************************/ - -QGeoRectanglePrivate::QGeoRectanglePrivate() -: QGeoShapePrivate(QGeoShape::RectangleType) -{ -} - -QGeoRectanglePrivate::QGeoRectanglePrivate(const QGeoCoordinate &topLeft, - const QGeoCoordinate &bottomRight) -: QGeoShapePrivate(QGeoShape::RectangleType), topLeft(topLeft), bottomRight(bottomRight) -{ -} - -QGeoRectanglePrivate::QGeoRectanglePrivate(const QGeoRectanglePrivate &other) -: QGeoShapePrivate(QGeoShape::RectangleType), topLeft(other.topLeft), - bottomRight(other.bottomRight) -{ -} - -QGeoRectanglePrivate::~QGeoRectanglePrivate() {} - -QGeoShapePrivate *QGeoRectanglePrivate::clone() const -{ - return new QGeoRectanglePrivate(*this); -} - -bool QGeoRectanglePrivate::operator==(const QGeoShapePrivate &other) const -{ - if (!QGeoShapePrivate::operator==(other)) - return false; - - const QGeoRectanglePrivate &otherBox = static_cast(other); - - return topLeft == otherBox.topLeft && bottomRight == otherBox.bottomRight; -} - -QT_END_NAMESPACE - diff --git a/src/location/qgeorectangle.h b/src/location/qgeorectangle.h deleted file mode 100644 index 5d0ab579..00000000 --- a/src/location/qgeorectangle.h +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEORECTANGLE_H -#define QGEORECTANGLE_H - -#include - -QT_BEGIN_NAMESPACE - -class QGeoCoordinate; -class QGeoRectanglePrivate; - -class Q_LOCATION_EXPORT QGeoRectangle : public QGeoShape -{ -public: - QGeoRectangle(); - QGeoRectangle(const QGeoCoordinate ¢er, double degreesWidth, double degreesHeight); - QGeoRectangle(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight); - QGeoRectangle(const QGeoRectangle &other); - QGeoRectangle(const QGeoShape &other); - - ~QGeoRectangle(); - - QGeoRectangle &operator=(const QGeoRectangle &other); - -#ifdef Q_NO_USING_KEYWORD - bool operator==(const QGeoShape &other) const - { - return QGeoShape::operator==(other); - } -#else - using QGeoShape::operator==; -#endif - bool operator==(const QGeoRectangle &other) const; - -#ifdef Q_NO_USING_KEYWORD - bool operator!=(const QGeoShape &other) const - { - return QGeoShape::operator!=(other); - } -#else - using QGeoShape::operator!=; -#endif - bool operator!=(const QGeoRectangle &other) const; - - void setTopLeft(const QGeoCoordinate &topLeft); - QGeoCoordinate topLeft() const; - - void setTopRight(const QGeoCoordinate &topRight); - QGeoCoordinate topRight() const; - - void setBottomLeft(const QGeoCoordinate &bottomLeft); - QGeoCoordinate bottomLeft() const; - - void setBottomRight(const QGeoCoordinate &bottomRight); - QGeoCoordinate bottomRight() const; - - void setCenter(const QGeoCoordinate ¢er); - QGeoCoordinate center() const; - - void setWidth(double degreesWidth); - double width() const; - - void setHeight(double degreesHeight); - double height() const; - -#ifdef Q_NO_USING_KEYWORD - bool contains(const QGeoCoordinate &coordinate) const - { - return QGeoShape::contains(coordinate); - } -#else - using QGeoShape::contains; -#endif - bool contains(const QGeoRectangle &rectangle) const; - bool intersects(const QGeoRectangle &rectangle) const; - - void translate(double degreesLatitude, double degreesLongitude); - QGeoRectangle translated(double degreesLatitude, double degreesLongitude) const; - - QGeoRectangle united(const QGeoRectangle &rectangle) const; - QGeoRectangle operator|(const QGeoRectangle &rectangle) const; - QGeoRectangle &operator|=(const QGeoRectangle &rectangle); - -private: - inline QGeoRectanglePrivate *d_func(); - inline const QGeoRectanglePrivate *d_func() const; -}; - -Q_DECLARE_TYPEINFO(QGeoRectangle, Q_MOVABLE_TYPE); - -inline QGeoRectangle QGeoRectangle::operator|(const QGeoRectangle &rectangle) const -{ - return united(rectangle); -} - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QGeoRectangle) - -#endif - diff --git a/src/location/qgeorectangle_p.h b/src/location/qgeorectangle_p.h deleted file mode 100644 index f61a2a91..00000000 --- a/src/location/qgeorectangle_p.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEORECTANGLE_P_H -#define QGEORECTANGLE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qgeoshape_p.h" -#include "qgeocoordinate.h" - -QT_BEGIN_NAMESPACE - -class QGeoRectanglePrivate : public QGeoShapePrivate -{ -public: - QGeoRectanglePrivate(); - QGeoRectanglePrivate(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight); - QGeoRectanglePrivate(const QGeoRectanglePrivate &other); - ~QGeoRectanglePrivate(); - - bool isValid() const; - bool isEmpty() const; - bool contains(const QGeoCoordinate &coordinate) const; - - QGeoShapePrivate *clone() const; - - bool operator==(const QGeoShapePrivate &other) const; - - QGeoCoordinate topLeft; - QGeoCoordinate bottomRight; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qgeosatelliteinfo.cpp b/src/location/qgeosatelliteinfo.cpp deleted file mode 100644 index acb2ce75..00000000 --- a/src/location/qgeosatelliteinfo.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qgeosatelliteinfo.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QGeoSatelliteInfoPrivate -{ -public: - int signal; - int satId; - QGeoSatelliteInfo::SatelliteSystem system; - QHash doubleAttribs; -}; - - -/*! - \class QGeoSatelliteInfo - \inmodule QtLocation - \ingroup QtLocation-positioning - \since Qt Location 5.0 - - \brief The QGeoSatelliteInfo class contains basic information about a satellite. - - \sa QGeoSatelliteInfoSource -*/ - -/*! - \enum QGeoSatelliteInfo::Attribute - Defines the attributes for the satellite information. - \value Elevation The elevation of the satellite, in degrees. - \value Azimuth The azimuth to true north, in degrees. -*/ - -/*! - \enum QGeoSatelliteInfo::SatelliteSystem - Defines the GNSS system of the satellite. - \value Undefined Not defined. - \value GPS Global Positioning System (USA). - \value GLONASS Global Positioning System (Russia). - -*/ - - -/*! - Creates a satellite information object. -*/ -QGeoSatelliteInfo::QGeoSatelliteInfo() - : d(new QGeoSatelliteInfoPrivate) -{ - d->signal = -1; - d->satId = -1; - d->system = QGeoSatelliteInfo::Undefined; -} - -/*! - Creates a satellite information object with the values of \a other. -*/ - -QGeoSatelliteInfo::QGeoSatelliteInfo(const QGeoSatelliteInfo &other) - : d(new QGeoSatelliteInfoPrivate) -{ - operator=(other); -} - -/*! - Destroys a satellite information object. -*/ -QGeoSatelliteInfo::~QGeoSatelliteInfo() -{ - delete d; -} - -/*! - Assigns the values from \a other to this object. -*/ -QGeoSatelliteInfo &QGeoSatelliteInfo::operator=(const QGeoSatelliteInfo & other) -{ - if (this == &other) - return *this; - - d->signal = other.d->signal; - d->satId = other.d->satId; - d->system = other.d->system; - d->doubleAttribs = other.d->doubleAttribs; - return *this; -} - -/*! - Returns true if all the information for this satellite - are the same as those of \a other. -*/ -bool QGeoSatelliteInfo::operator==(const QGeoSatelliteInfo &other) const -{ - return d->signal == other.d->signal - && d->satId == other.d->satId - && d->system == other.d->system - && d->doubleAttribs == other.d->doubleAttribs; -} - -/*! - \fn bool QGeoSatelliteInfo::operator!=(const QGeoSatelliteInfo &other) const; - - Returns true if any of the information for this satellite - are not the same as those of \a other. -*/ - - -/*! - Sets the Satellite System (GPS, GLONASS, ...) to \a system. -*/ -void QGeoSatelliteInfo::setSatelliteSystem(SatelliteSystem system) -{ - d->system = system; -} - -/*! - Returns the Satellite System (GPS, GLONASS, ...) -*/ -QGeoSatelliteInfo::SatelliteSystem QGeoSatelliteInfo::satelliteSystem() const -{ - return d->system; -} - -/*! - Sets the satellite identifier number to \a satId. - - The satellite identifier number can be used to identify a satellite inside the satellite system. - For satellite system GPS the satellite identifier number represents the PRN (Pseudo-random noise) number. - For satellite system GLONASS the satellite identifier number represents the slot number. -*/ -void QGeoSatelliteInfo::setSatelliteIdentifier(int satId) -{ - d->satId = satId; -} - -/*! - Returns the satellite identifier number. - - The satellite identifier number can be used to identify a satellite inside the satellite system. - For satellite system GPS the satellite identifier number represents the PRN (Pseudo-random noise) number. - For satellite system GLONASS the satellite identifier number represents the slot number. -*/ -int QGeoSatelliteInfo::satelliteIdentifier() const -{ - return d->satId; -} - -/*! - Sets the signal strength to \a signalStrength, in decibels. -*/ -void QGeoSatelliteInfo::setSignalStrength(int signalStrength) -{ - d->signal = signalStrength; -} - -/*! - Returns the signal strength, or -1 if the value has not been set. -*/ -int QGeoSatelliteInfo::signalStrength() const -{ - return d->signal; -} - -/*! - Sets the value for \a attribute to \a value. -*/ -void QGeoSatelliteInfo::setAttribute(Attribute attribute, qreal value) -{ - d->doubleAttribs[int(attribute)] = value; -} - -/*! - Returns the value of the specified \a attribute as a qreal value. - - Returns -1 if the value has not been set. - - \sa hasAttribute(), setAttribute() -*/ -qreal QGeoSatelliteInfo::attribute(Attribute attribute) const -{ - if (d->doubleAttribs.contains(int(attribute))) - return d->doubleAttribs[int(attribute)]; - return -1; -} - -/*! - Removes the specified \a attribute and its value. -*/ -void QGeoSatelliteInfo::removeAttribute(Attribute attribute) -{ - d->doubleAttribs.remove(int(attribute)); -} - -/*! - Returns true if the specified \a attribute is present in this update. -*/ -bool QGeoSatelliteInfo::hasAttribute(Attribute attribute) const -{ - return d->doubleAttribs.contains(int(attribute)); -} - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QGeoSatelliteInfo &info) -{ - dbg.nospace() << "QGeoSatelliteInfo(system=" << info.d->system; - dbg.nospace() << ", satId=" << info.d->satId; - dbg.nospace() << ", signal-strength=" << info.d->signal; - - - QList attribs = info.d->doubleAttribs.keys(); - for (int i = 0; i < attribs.count(); ++i) { - dbg.nospace() << ", "; - switch (attribs[i]) { - case QGeoSatelliteInfo::Elevation: - dbg.nospace() << "Elevation="; - break; - case QGeoSatelliteInfo::Azimuth: - dbg.nospace() << "Azimuth="; - break; - } - dbg.nospace() << info.d->doubleAttribs[attribs[i]]; - } - dbg.nospace() << ')'; - return dbg; -} -#endif - -#ifndef QT_NO_DATASTREAM -/*! - \fn QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info) - \relates QGeoSatelliteInfo - - Writes the given \a info to the specified \a stream. - - \sa \link datastreamformat.html Format of the QDataStream operators \endlink - -*/ - -QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info) -{ - stream << info.d->signal; - stream << info.d->doubleAttribs; - stream << info.d->satId; - stream << info.d->system; - return stream; -} -#endif - -#ifndef QT_NO_DATASTREAM -/*! - \fn QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info) - \relates QGeoSatelliteInfo - - Reads satellite information from the specified \a stream into the given - \a info. - - \sa \link datastreamformat.html Format of the QDataStream operators \endlink -*/ - -QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info) -{ - int system; - stream >> info.d->signal; - stream >> info.d->doubleAttribs; - stream >> info.d->satId; - stream >> system; - info.d->system = (QGeoSatelliteInfo::SatelliteSystem)system; - return stream; -} -#endif - -QT_END_NAMESPACE diff --git a/src/location/qgeosatelliteinfo.h b/src/location/qgeosatelliteinfo.h deleted file mode 100644 index e2afb4ff..00000000 --- a/src/location/qgeosatelliteinfo.h +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QGEOSATELLITEINFO_H -#define QGEOSATELLITEINFO_H - -#include - -QT_BEGIN_NAMESPACE - -class QDebug; -class QDataStream; - -class QGeoSatelliteInfoPrivate; -class Q_LOCATION_EXPORT QGeoSatelliteInfo -{ -public: - enum Attribute { - Elevation, - Azimuth - }; - - enum SatelliteSystem { - Undefined = 0x00, - GPS = 0x01, - GLONASS = 0x02 - }; - - QGeoSatelliteInfo(); - QGeoSatelliteInfo(const QGeoSatelliteInfo &other); - ~QGeoSatelliteInfo(); - - QGeoSatelliteInfo &operator=(const QGeoSatelliteInfo &other); - - bool operator==(const QGeoSatelliteInfo &other) const; - inline bool operator!=(const QGeoSatelliteInfo &other) const { - return !operator==(other); - } - - void setSatelliteSystem(SatelliteSystem system); - SatelliteSystem satelliteSystem() const; - - void setSatelliteIdentifier(int satId); - int satelliteIdentifier() const; - - void setSignalStrength(int signalStrength); - int signalStrength() const; - - void setAttribute(Attribute attribute, qreal value); - qreal attribute(Attribute attribute) const; - void removeAttribute(Attribute attribute); - - bool hasAttribute(Attribute attribute) const; - -private: -#ifndef QT_NO_DEBUG_STREAM - friend Q_LOCATION_EXPORT QDebug operator<<(QDebug dbg, const QGeoSatelliteInfo &info); -#endif -#ifndef QT_NO_DATASTREAM - friend Q_LOCATION_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info); - friend Q_LOCATION_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info); -#endif - QGeoSatelliteInfoPrivate *d; -}; - -#ifndef QT_NO_DEBUG_STREAM -Q_LOCATION_EXPORT QDebug operator<<(QDebug dbg, const QGeoSatelliteInfo &info); -#endif - -#ifndef QT_NO_DATASTREAM -Q_LOCATION_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info); -Q_LOCATION_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info); -#endif - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qgeosatelliteinfosource.cpp b/src/location/qgeosatelliteinfosource.cpp deleted file mode 100644 index 509d4781..00000000 --- a/src/location/qgeosatelliteinfosource.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include "qgeopositioninfosourcefactory.h" -#include "qgeopositioninfosource_p.h" -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QGeoSatelliteInfoSource - \inmodule QtLocation - \ingroup QtLocation-positioning - \since Qt Location 5.0 - - \brief The QGeoSatelliteInfoSource class is an abstract base class for the distribution of satellite information updates. - - The static function QGeoSatelliteInfoSource::createDefaultSource() creates a default - satellite data source that is appropriate for the platform, if one is - available. Otherwise, available QGeoPositionInfoSourceFactory plugins will - be checked for one that has a satellite data source available. - - Call startUpdates() and stopUpdates() to start and stop regular updates, - or requestUpdate() to request a single update. - When an update is available, satellitesInViewUpdated() and/or - satellitesInUseUpdated() will be emitted. - - If regular satellite updates are required, setUpdateInterval() can be used - to specify how often these updates should be emitted. If no interval is - specified, updates are simply provided whenever they are available. - For example: - - \code - // Emit updates every 10 seconds if available - QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(0); - if (source) - source->setUpdateInterval(10000); - \endcode - - To remove an update interval that was previously set, call - setUpdateInterval() with a value of 0. - - Note that the satellite source may have a minimum value requirement for - update intervals, as returned by minimumUpdateInterval(). - - \warning On Windows CE it is not possible to detect if a device is GPS enabled. - The default satellite source on a Windows CE device without GPS support will never provide any satellite data. -*/ - -class QGeoSatelliteInfoSourcePrivate -{ -public: - int interval; -}; - -/*! - Creates a satellite source with the specified \a parent. -*/ -QGeoSatelliteInfoSource::QGeoSatelliteInfoSource(QObject *parent) - : QObject(parent), - d(new QGeoSatelliteInfoSourcePrivate) -{ - d->interval = 0; -} - -/*! - Destroys the satellite source. -*/ -QGeoSatelliteInfoSource::~QGeoSatelliteInfoSource() -{ - delete d; -} - -/*! - \property QGeoSatelliteInfoSource::updateInterval - \brief This property holds the requested interval in milliseconds between each update. - - If the update interval is not set (or is set to 0) the - source will provide updates as often as necessary. - - If the update interval is set, the source will provide updates at an - interval as close to the requested interval as possible. If the requested - interval is less than the minimumUpdateInterval(), - the minimum interval is used instead. - - Changes to the update interval will happen as soon as is practical, however the - time the change takes may vary between implementations. Whether or not the elapsed - time from the previous interval is counted as part of the new interval is also - implementation dependent. - - The default value for this property is 0. - - Note: Subclass implementations must call the base implementation of - setUpdateInterval() so that updateInterval() returns the correct value. -*/ -void QGeoSatelliteInfoSource::setUpdateInterval(int msec) -{ - d->interval = msec; -} - -int QGeoSatelliteInfoSource::updateInterval() const -{ - return d->interval; -} - - - -/*! - Creates and returns a source with the specified \a parent that reads - from the system's default source of satellite update information, or the - highest priority available plugin. - - Returns 0 if the system has no default position source, no valid plugins - could be found or the user does not have the permission to access the satellite data. -*/ -QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createDefaultSource(QObject *parent) -{ - QList plugins = QGeoPositionInfoSourcePrivate::pluginsSorted(); - foreach (const QJsonObject &obj, plugins) { - if (obj.value(QStringLiteral("Satellite")).isBool() - && obj.value(QStringLiteral("Satellite")).toBool()) - { - QGeoPositionInfoSourcePrivate d; - d.metaData = obj; - d.loadPlugin(); - QGeoSatelliteInfoSource *s = 0; - if (d.factory) - s = d.factory->satelliteInfoSource(parent); - return s; - } - } - - return 0; -} - -/*! - Creates and returns a source with the given \a parent, - by loading the plugin named \a sourceName. - - Returns 0 if the plugin cannot be found. -*/ -QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createSource(const QString &sourceName, QObject *parent) -{ - QHash plugins = QGeoPositionInfoSourcePrivate::plugins(); - if (plugins.contains(sourceName)) { - QGeoPositionInfoSourcePrivate d; - d.metaData = plugins.value(sourceName); - d.loadPlugin(); - QGeoSatelliteInfoSource *src = 0; - if (d.factory) - src = d.factory->satelliteInfoSource(parent); - return src; - } - - return 0; -} - -/*! - Returns a list of available source plugins, including the default system - backend if one is available. -*/ -QStringList QGeoSatelliteInfoSource::availableSources() -{ - QStringList plugins; - QHash meta = QGeoPositionInfoSourcePrivate::plugins(); - foreach (const QString &name, meta.keys()) { - if (meta.value(name).value(QStringLiteral("Satellite")).isBool() - && meta.value(name).value(QStringLiteral("Satellite")).toBool()) { - plugins << name; - } - } - - return plugins; -} - -/*! - \fn void QGeoSatelliteInfoSource::satellitesInViewUpdated(const QList &satellites); - - If startUpdates() or requestUpdate() is called, this signal is emitted - when an update is available on the satellites that are - currently in view. - - The \a satellites parameter holds the satellites currently in view. -*/ - -/*! - \fn void QGeoSatelliteInfoSource::satellitesInUseUpdated(const QList &satellites); - - If startUpdates() or requestUpdate() is called, this signal is emitted - when an update is available on the number of satellites that are - currently in use. - - These are the satellites that are used to get a "fix" - that - is, those used to determine the current position. - - The \a satellites parameter holds the satellites currently in use. -*/ - -/*! - \property QGeoSatelliteInfoSource::minimumUpdateInterval - \brief This property holds the minimum time (in milliseconds) required to retrieve a satellite update. - - This is the minimum value accepted by setUpdateInterval() and - requestUpdate(). -*/ - - -/*! - \fn virtual void QGeoSatelliteInfoSource::startUpdates() = 0; - - Starts emitting updates at regular intervals. The updates will be - provided whenever new satellite information becomes available. - - \sa satellitesInViewUpdated(), satellitesInUseUpdated() -*/ - -/*! - \fn virtual void QGeoSatelliteInfoSource::stopUpdates() = 0; - - Stops emitting updates at regular intervals. -*/ - -/*! - \fn virtual void QGeoSatelliteInfoSource::requestUpdate(int timeout = 0); - - Attempts to get the current satellite information and emit - satellitesInViewUpdated() and satellitesInUseUpdated() with this - information. If the current position cannot be found - within the given \a timeout (in milliseconds) or if \a timeout is less than the value returned by - minimumUpdateInterval(), requestTimeout() is - emitted. - - If the timeout is zero, the timeout defaults to a reasonable timeout - period as appropriate for the source. - - This does nothing if another update request is in progress. However - it can be called even if startUpdates() has already been called and - regular updates are in progress. -*/ - -/*! - \fn void QGeoSatelliteInfoSource::requestTimeout(); - - Emitted if requestUpdate() was called and the current satellite - information could not be retrieved within the specified timeout. -*/ - -/*! - \fn QGeoSatelliteInfoSource::Error QGeoSatelliteInfoSource::error() const = 0 - - Returns the last error that occurred. -*/ - -/*! - \fn void QGeoSatelliteInfoSource::error(QGeoSatelliteInfoSource::Error satelliteError) - - This signal is emitted after an error occurred. The \a satelliteError - parameter describes the type of error that occurred. - -*/ - -/*! - \enum QGeoSatelliteInfoSource::Error - - The Error enumeration represents the errors which can occur. - - \value AccessError The connection setup to the remote positioning backend failed because the - application lacked the required privileges. - \value ClosedError The remote satellite backend closed the connection, which happens for example in case - the user is switching location services to off. This object becomes invalid and should be deleted. - A new satellite source can be created by calling createDefaultSource() later on. - \value UnknownSourceError An unidentified error occurred. - */ - - -#include "moc_qgeosatelliteinfosource.cpp" - -QT_END_NAMESPACE diff --git a/src/location/qgeosatelliteinfosource.h b/src/location/qgeosatelliteinfosource.h deleted file mode 100644 index c7f734b6..00000000 --- a/src/location/qgeosatelliteinfosource.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QGEOSATELLITEINFOSOURCE_H -#define QGEOSATELLITEINFOSOURCE_H - -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -class QGeoSatelliteInfoSourcePrivate; -class Q_LOCATION_EXPORT QGeoSatelliteInfoSource : public QObject -{ - Q_OBJECT - Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval) - Q_PROPERTY(int minimumUpdateInterval READ minimumUpdateInterval) - -public: - enum Error { - AccessError, - ClosedError, /* 1 */ - UnknownSourceError = -1 - }; - Q_ENUMS(Error) - - explicit QGeoSatelliteInfoSource(QObject *parent); - virtual ~QGeoSatelliteInfoSource(); - - static QGeoSatelliteInfoSource *createDefaultSource(QObject *parent); - static QGeoSatelliteInfoSource *createSource(const QString &sourceName, QObject *parent); - static QStringList availableSources(); - - virtual void setUpdateInterval(int msec); - int updateInterval() const; - virtual int minimumUpdateInterval() const = 0; - virtual Error error() const = 0; - -public Q_SLOTS: - virtual void startUpdates() = 0; - virtual void stopUpdates() = 0; - - virtual void requestUpdate(int timeout = 0) = 0; - -Q_SIGNALS: - void satellitesInViewUpdated(const QList &satellites); - void satellitesInUseUpdated(const QList &satellites); - void requestTimeout(); - void error(QGeoSatelliteInfoSource::Error); - -private: - Q_DISABLE_COPY(QGeoSatelliteInfoSource) - QGeoSatelliteInfoSourcePrivate *d; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qgeoshape.cpp b/src/location/qgeoshape.cpp deleted file mode 100644 index 5481b1cf..00000000 --- a/src/location/qgeoshape.cpp +++ /dev/null @@ -1,307 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgeoshape.h" -#include "qgeoshape_p.h" -#include "qgeorectangle.h" -#include "qgeocircle.h" - -#ifndef QT_NO_DEBUG_STREAM -#include -#endif - -#ifndef QT_NO_DATASTREAM -#include -#endif - -QT_BEGIN_NAMESPACE - -QGeoShapePrivate::QGeoShapePrivate(QGeoShape::ShapeType type) -: type(type) -{ -} - -QGeoShapePrivate::~QGeoShapePrivate() -{ -} - -bool QGeoShapePrivate::operator==(const QGeoShapePrivate &other) const -{ - return type == other.type; -} - -/*! - \class QGeoShape - \inmodule QtLocation - \ingroup QtLocation-positioning - \since Qt Location 5.0 - - \brief The QGeoShape class defines a geographic area. - - This class is the base class for classes which specify a geographic - area. - - For the sake of consistency, subclasses should describe the specific - details of the associated areas in terms of QGeoCoordinate instances - and distances in meters. -*/ - -/*! - \enum QGeoShape::ShapeType - - Describes the type of the shape. - - \value UnknownType A shape of unknown type. - \value RectangleType A rectangular shape. - \value CircleType A circular shape. -*/ - -inline QGeoShapePrivate *QGeoShape::d_func() -{ - return static_cast(d_ptr.data()); -} - -inline const QGeoShapePrivate *QGeoShape::d_func() const -{ - return static_cast(d_ptr.constData()); -} - -/*! - Constructs a new invalid geo shape of \l UnknownType. -*/ -QGeoShape::QGeoShape() -{ -} - -/*! - Constructs a new geo shape which is a copy of \a other. -*/ -QGeoShape::QGeoShape(const QGeoShape &other) -: d_ptr(other.d_ptr) -{ -} - -/*! - \internal -*/ -QGeoShape::QGeoShape(QGeoShapePrivate *d) -: d_ptr(d) -{ -} - -/*! - Destroys this geo shape. -*/ -QGeoShape::~QGeoShape() -{ -} - -/*! - Returns the type of this geo shape. -*/ -QGeoShape::ShapeType QGeoShape::type() const -{ - Q_D(const QGeoShape); - - if (d) - return d->type; - else - return UnknownType; -} - -/*! - Returns whether this geo shape is valid. - - An geo shape is considered to be invalid if some of the data that is required to - unambiguously describe the geo shape has not been set or has been set to an - unsuitable value. -*/ -bool QGeoShape::isValid() const -{ - Q_D(const QGeoShape); - - if (d) - return d->isValid(); - else - return false; -} - -/*! - Returns whether this geo shape is empty. - - An empty geo shape is a region which has a geometrical area of 0. -*/ -bool QGeoShape::isEmpty() const -{ - Q_D(const QGeoShape); - - if (d) - return d->isEmpty(); - else - return true; -} - -/*! - Returns whether the coordinate \a coordinate is contained within this geo shape. -*/ -bool QGeoShape::contains(const QGeoCoordinate &coordinate) const -{ - Q_D(const QGeoShape); - - if (d) - return d->contains(coordinate); - else - return false; -} - - -/*! - Returns true if the \a other geo shape is equivalent to this geo shape, otherwise returns - false. -*/ -bool QGeoShape::operator==(const QGeoShape &other) const -{ - Q_D(const QGeoShape); - - if (d == other.d_func()) - return true; - - if (!d || !(other.d_func())) - return false; - - return *d == *other.d_func(); -} - -/*! - Returns true if the \a other geo shape is not equivalent to this geo shape, otherwise returns - false. -*/ -bool QGeoShape::operator!=(const QGeoShape &other) const -{ - return !(*this == other); -} - -/*! - Assigns \a other to this geo shape and returns a reference to this geo shape. -*/ -QGeoShape &QGeoShape::operator=(const QGeoShape &other) -{ - if (this == &other) - return *this; - - d_ptr = other.d_ptr; - return *this; -} - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QGeoShape &shape) -{ - //dbg << *shape.d_func(); - dbg.nospace() << "QGeoShape("; - switch (shape.type()) { - case QGeoShape::UnknownType: - dbg.nospace() << "Unknown"; - break; - case QGeoShape::RectangleType: - dbg.nospace() << "Rectangle"; - break; - case QGeoShape::CircleType: - dbg.nospace() << "Circle"; - } - - dbg.nospace() << ')'; - - return dbg; -} -#endif - -#ifndef QT_NO_DATASTREAM -QDataStream &operator<<(QDataStream &stream, const QGeoShape &shape) -{ - stream << quint32(shape.type()); - switch (shape.type()) { - case QGeoShape::UnknownType: - break; - case QGeoShape::RectangleType: { - QGeoRectangle r = shape; - stream << r.topLeft() << r.bottomRight(); - break; - } - case QGeoShape::CircleType: { - QGeoCircle c = shape; - stream << c.center() << c.radius(); - break; - } - } - - return stream; -} - -QDataStream &operator>>(QDataStream &stream, QGeoShape &shape) -{ - quint32 type; - stream >> type; - - switch (type) { - case QGeoShape::UnknownType: - shape = QGeoShape(); - break; - case QGeoShape::RectangleType: { - QGeoCoordinate tl; - QGeoCoordinate br; - stream >> tl >> br; - shape = QGeoRectangle(tl, br); - break; - } - case QGeoShape::CircleType: { - QGeoCoordinate c; - qreal r; - stream >> c >> r; - shape = QGeoCircle(c, r); - break; - } - } - - return stream; -} -#endif - -QT_END_NAMESPACE diff --git a/src/location/qgeoshape.h b/src/location/qgeoshape.h deleted file mode 100644 index 8be73aeb..00000000 --- a/src/location/qgeoshape.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOSHAPE_H -#define QGEOSHAPE_H - -#include -#include - -QT_BEGIN_NAMESPACE - -class QDebug; -class QGeoShapePrivate; - -class Q_LOCATION_EXPORT QGeoShape -{ -public: - QGeoShape(); - QGeoShape(const QGeoShape &other); - ~QGeoShape(); - - enum ShapeType { - UnknownType, - RectangleType, - CircleType - }; - - ShapeType type() const; - - bool isValid() const; - bool isEmpty() const; - bool contains(const QGeoCoordinate &coordinate) const; - - bool operator==(const QGeoShape &other) const; - bool operator!=(const QGeoShape &other) const; - - QGeoShape &operator=(const QGeoShape &other); - -protected: - QGeoShape(QGeoShapePrivate *d); - - QSharedDataPointer d_ptr; - -private: - inline QGeoShapePrivate *d_func(); - inline const QGeoShapePrivate *d_func() const; -}; - -Q_DECLARE_TYPEINFO(QGeoShape, Q_MOVABLE_TYPE); - -#ifndef QT_NO_DEBUG_STREAM -Q_LOCATION_EXPORT QDebug operator<<(QDebug, const QGeoShape &); -#endif - -#ifndef QT_NO_DATASTREAM -Q_LOCATION_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoShape &shape); -Q_LOCATION_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoShape &shape); -#endif - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QGeoShape) - -#endif - diff --git a/src/location/qgeoshape_p.h b/src/location/qgeoshape_p.h deleted file mode 100644 index 497df8d2..00000000 --- a/src/location/qgeoshape_p.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGEOSHAPE_P_H -#define QGEOSHAPE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -#include "qgeoshape.h" - -QT_BEGIN_NAMESPACE - -class QGeoShapePrivate : public QSharedData -{ -public: - explicit QGeoShapePrivate(QGeoShape::ShapeType type); - virtual ~QGeoShapePrivate(); - - virtual bool isValid() const = 0; - virtual bool isEmpty() const = 0; - virtual bool contains(const QGeoCoordinate &coordinate) const = 0; - - virtual QGeoShapePrivate *clone() const = 0; - - virtual bool operator==(const QGeoShapePrivate &other) const; - - QGeoShape::ShapeType type; -}; - -// don't use the copy constructor when detaching from a QSharedDataPointer, use virtual clone() -// call instead. -template <> -Q_INLINE_TEMPLATE QGeoShapePrivate *QSharedDataPointer::clone() -{ - return d->clone(); -} - -QT_END_NAMESPACE - -#endif - diff --git a/src/location/qlocationutils.cpp b/src/location/qlocationutils.cpp deleted file mode 100644 index accb8373..00000000 --- a/src/location/qlocationutils.cpp +++ /dev/null @@ -1,357 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qlocationutils_p.h" -#include "qgeopositioninfo.h" - -#include -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -// converts e.g. 15306.0235 from NMEA sentence to 153.100392 -static double qlocationutils_nmeaDegreesToDecimal(double nmeaDegrees) -{ - double deg; - double min = 100.0 * modf(nmeaDegrees / 100.0, °); - return deg + (min / 60.0); -} - -static void qlocationutils_readGga(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) -{ - QByteArray sentence(data, size); - QList parts = sentence.split(','); - QGeoCoordinate coord; - - if (hasFix && parts.count() > 6 && parts[6].count() > 0) - *hasFix = parts[6].toInt() > 0; - - if (parts.count() > 1 && parts[1].count() > 0) { - QTime time; - if (QLocationUtils::getNmeaTime(parts[1], &time)) - info->setTimestamp(QDateTime(QDate(), time, Qt::UTC)); - } - - if (parts.count() > 5 && parts[3].count() == 1 && parts[5].count() == 1) { - double lat; - double lng; - if (QLocationUtils::getNmeaLatLong(parts[2], parts[3][0], parts[4], parts[5][0], &lat, &lng)) { - coord.setLatitude(lat); - coord.setLongitude(lng); - } - } - - if (parts.count() > 9 && parts[9].count() > 0) { - bool hasAlt = false; - double alt = parts[9].toDouble(&hasAlt); - if (hasAlt) - coord.setAltitude(alt); - } - - if (coord.type() != QGeoCoordinate::InvalidCoordinate) - info->setCoordinate(coord); -} - -static void qlocationutils_readGll(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) -{ - QByteArray sentence(data, size); - QList parts = sentence.split(','); - QGeoCoordinate coord; - - if (hasFix && parts.count() > 6 && parts[6].count() > 0) - *hasFix = (parts[6][0] == 'A'); - - if (parts.count() > 5 && parts[5].count() > 0) { - QTime time; - if (QLocationUtils::getNmeaTime(parts[5], &time)) - info->setTimestamp(QDateTime(QDate(), time, Qt::UTC)); - } - - if (parts.count() > 4 && parts[2].count() == 1 && parts[4].count() == 1) { - double lat; - double lng; - if (QLocationUtils::getNmeaLatLong(parts[1], parts[2][0], parts[3], parts[4][0], &lat, &lng)) { - coord.setLatitude(lat); - coord.setLongitude(lng); - } - } - - if (coord.type() != QGeoCoordinate::InvalidCoordinate) - info->setCoordinate(coord); -} - -static void qlocationutils_readRmc(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) -{ - QByteArray sentence(data, size); - QList parts = sentence.split(','); - QGeoCoordinate coord; - QDate date; - QTime time; - - if (hasFix && parts.count() > 2 && parts[2].count() > 0) - *hasFix = (parts[2][0] == 'A'); - - if (parts.count() > 9 && parts[9].count() == 6) { - date = QDate::fromString(QString::fromLatin1(parts[9]), QLatin1String("ddMMyy")); - if (date.isValid()) - date = date.addYears(100); // otherwise starts from 1900 - else - date = QDate(); - } - - if (parts.count() > 1 && parts[1].count() > 0) - QLocationUtils::getNmeaTime(parts[1], &time); - - if (parts.count() > 6 && parts[4].count() == 1 && parts[6].count() == 1) { - double lat; - double lng; - if (QLocationUtils::getNmeaLatLong(parts[3], parts[4][0], parts[5], parts[6][0], &lat, &lng)) { - coord.setLatitude(lat); - coord.setLongitude(lng); - } - } - - bool parsed = false; - double value = 0.0; - if (parts.count() > 7 && parts[7].count() > 0) { - value = parts[7].toDouble(&parsed); - if (parsed) - info->setAttribute(QGeoPositionInfo::GroundSpeed, qreal(value * 1.852 / 3.6)); // knots -> m/s - } - if (parts.count() > 8 && parts[8].count() > 0) { - value = parts[8].toDouble(&parsed); - if (parsed) - info->setAttribute(QGeoPositionInfo::Direction, qreal(value)); - } - if (parts.count() > 11 && parts[11].count() == 1 - && (parts[11][0] == 'E' || parts[11][0] == 'W')) { - value = parts[10].toDouble(&parsed); - if (parsed) { - if (parts[11][0] == 'W') - value *= -1; - info->setAttribute(QGeoPositionInfo::MagneticVariation, qreal(value)); - } - } - - if (coord.type() != QGeoCoordinate::InvalidCoordinate) - info->setCoordinate(coord); - - info->setTimestamp(QDateTime(date, time, Qt::UTC)); -} - -static void qlocationutils_readVtg(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) -{ - if (hasFix) - *hasFix = false; - - QByteArray sentence(data, size); - QList parts = sentence.split(','); - - bool parsed = false; - double value = 0.0; - if (parts.count() > 1 && parts[1].count() > 0) { - value = parts[1].toDouble(&parsed); - if (parsed) - info->setAttribute(QGeoPositionInfo::Direction, qreal(value)); - } - if (parts.count() > 7 && parts[7].count() > 0) { - value = parts[7].toDouble(&parsed); - if (parsed) - info->setAttribute(QGeoPositionInfo::GroundSpeed, qreal(value / 3.6)); // km/h -> m/s - } -} - -static void qlocationutils_readZda(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) -{ - if (hasFix) - *hasFix = false; - - QByteArray sentence(data, size); - QList parts = sentence.split(','); - QDate date; - QTime time; - - if (parts.count() > 1 && parts[1].count() > 0) - QLocationUtils::getNmeaTime(parts[1], &time); - - if (parts.count() > 4 && parts[2].count() > 0 && parts[3].count() > 0 - && parts[4].count() == 4) { // must be full 4-digit year - int day = parts[2].toUInt(); - int month = parts[3].toUInt(); - int year = parts[4].toUInt(); - if (day > 0 && month > 0 && year > 0) - date.setDate(year, month, day); - } - - info->setTimestamp(QDateTime(date, time, Qt::UTC)); -} - -bool QLocationUtils::getPosInfoFromNmea(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) -{ - if (!info) - return false; - - if (hasFix) - *hasFix = false; - if (size < 6 || data[0] != '$' || !hasValidNmeaChecksum(data, size)) - return false; - - if (data[3] == 'G' && data[4] == 'G' && data[5] == 'A') { - // "$--GGA" sentence. - qlocationutils_readGga(data, size, info, hasFix); - return true; - } - - if (data[3] == 'G' && data[4] == 'L' && data[5] == 'L') { - // "$--GLL" sentence. - qlocationutils_readGll(data, size, info, hasFix); - return true; - } - - if (data[3] == 'R' && data[4] == 'M' && data[5] == 'C') { - // "$--RMC" sentence. - qlocationutils_readRmc(data, size, info, hasFix); - return true; - } - - if (data[3] == 'V' && data[4] == 'T' && data[5] == 'G') { - // "$--VTG" sentence. - qlocationutils_readVtg(data, size, info, hasFix); - return true; - } - - if (data[3] == 'Z' && data[4] == 'D' && data[5] == 'A') { - // "$--ZDA" sentence. - qlocationutils_readZda(data, size, info, hasFix); - return true; - } - - return false; -} - -bool QLocationUtils::hasValidNmeaChecksum(const char *data, int size) -{ - int asteriskIndex = -1; - for (int i = 0; i < size; ++i) { - if (data[i] == '*') { - asteriskIndex = i; - break; - } - } - - const int CSUM_LEN = 2; - if (asteriskIndex < 0 || asteriskIndex + CSUM_LEN >= size) - return false; - - // XOR byte value of all characters between '$' and '*' - int result = 0; - for (int i = 1; i < asteriskIndex; ++i) - result ^= data[i]; - /* - char calc[CSUM_LEN + 1]; - ::snprintf(calc, CSUM_LEN + 1, "%02x", result); - return ::strncmp(calc, &data[asteriskIndex+1], 2) == 0; - */ - - QByteArray checkSumBytes(&data[asteriskIndex + 1], 2); - bool ok = false; - int checksum = checkSumBytes.toInt(&ok,16); - return ok && checksum == result; -} - -bool QLocationUtils::getNmeaTime(const QByteArray &bytes, QTime *time) -{ - int dotIndex = bytes.indexOf('.'); - QTime tempTime; - - if (dotIndex < 0) { - tempTime = QTime::fromString(QString::fromLatin1(bytes.constData()), - QLatin1String("hhmmss")); - } else { - tempTime = QTime::fromString(QString::fromLatin1(bytes.mid(0, dotIndex)), - QLatin1String("hhmmss")); - bool hasMsecs = false; - int midLen = qMin(3, bytes.size() - dotIndex - 1); - int msecs = bytes.mid(dotIndex + 1, midLen).toUInt(&hasMsecs); - if (hasMsecs) - tempTime = tempTime.addMSecs(msecs); - } - - if (tempTime.isValid()) { - *time = tempTime; - return true; - } - return false; -} - -bool QLocationUtils::getNmeaLatLong(const QByteArray &latString, char latDirection, const QByteArray &lngString, char lngDirection, double *lat, double *lng) -{ - if ((latDirection != 'N' && latDirection != 'S') - || (lngDirection != 'E' && lngDirection != 'W')) { - return false; - } - - bool hasLat = false; - bool hasLong = false; - double tempLat = latString.toDouble(&hasLat); - double tempLng = lngString.toDouble(&hasLong); - if (hasLat && hasLong) { - tempLat = qlocationutils_nmeaDegreesToDecimal(tempLat); - if (latDirection == 'S') - tempLat *= -1; - tempLng = qlocationutils_nmeaDegreesToDecimal(tempLng); - if (lngDirection == 'W') - tempLng *= -1; - - if (isValidLat(tempLat) && isValidLong(tempLng)) { - *lat = tempLat; - *lng = tempLng; - return true; - } - } - return false; -} - -QT_END_NAMESPACE - diff --git a/src/location/qlocationutils_p.h b/src/location/qlocationutils_p.h deleted file mode 100644 index 700bfa64..00000000 --- a/src/location/qlocationutils_p.h +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QLOCATIONUTILS_P_H -#define QLOCATIONUTILS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -QT_BEGIN_NAMESPACE -class QTime; -class QByteArray; - -class QGeoPositionInfo; -class QLocationUtils -{ -public: - inline static bool isValidLat(double lat) { - return lat >= -90 && lat <= 90; - } - inline static bool isValidLong(double lng) { - return lng >= -180 && lng <= 180; - } - - inline static double clipLat(double lat) { - if (lat > 90) - lat = 90; - else if (lat < -90) - lat = -90; - return lat; - } - - inline static double wrapLong(double lng) { - if (lng > 180) - lng -= 360; - else if (lng < -180) - lng += 360; - return lng; - } - - /* - Creates a QGeoPositionInfo from a GGA, GLL, RMC, VTG or ZDA sentence. - - Note: - - GGA and GLL sentences have time but not date so the update's - QDateTime object will have an invalid date. - - RMC reports date with a two-digit year so in this case the year - is assumed to be after the year 2000. - */ - Q_AUTOTEST_EXPORT static bool getPosInfoFromNmea(const char *data, int size, QGeoPositionInfo *info, bool *hasFix = 0); - - /* - Returns true if the given NMEA sentence has a valid checksum. - */ - Q_AUTOTEST_EXPORT static bool hasValidNmeaChecksum(const char *data, int size); - - /* - Returns time from a string in hhmmss or hhmmss.z+ format. - */ - Q_AUTOTEST_EXPORT static bool getNmeaTime(const QByteArray &bytes, QTime *time); - - /* - Accepts for example ("2734.7964", 'S', "15306.0124", 'E') and returns the - lat-long values. Fails if lat or long fail isValidLat() or isValidLong(). - */ - Q_AUTOTEST_EXPORT static bool getNmeaLatLong(const QByteArray &latString, char latDirection, const QByteArray &lngString, char lngDirection, double *lat, double *lon); -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qnmeapositioninfosource.cpp b/src/location/qnmeapositioninfosource.cpp deleted file mode 100644 index 6232a8bb..00000000 --- a/src/location/qnmeapositioninfosource.cpp +++ /dev/null @@ -1,623 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qnmeapositioninfosource_p.h" -#include "qlocationutils_p.h" - -#include -#include -#include -#include - - -QT_BEGIN_NAMESPACE - -QNmeaRealTimeReader::QNmeaRealTimeReader(QNmeaPositionInfoSourcePrivate *sourcePrivate) - : QNmeaReader(sourcePrivate) -{ -} - -void QNmeaRealTimeReader::readAvailableData() -{ - while (m_proxy->m_device->canReadLine()){ - QGeoPositionInfo update; - bool hasFix = false; - - char buf[1024]; - qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf)); - if (m_proxy->parsePosInfoFromNmeaData(buf, size, &update, &hasFix)) - m_proxy->notifyNewUpdate(&update, hasFix); - } -} - - -//============================================================ - -QNmeaSimulatedReader::QNmeaSimulatedReader(QNmeaPositionInfoSourcePrivate *sourcePrivate) - : QNmeaReader(sourcePrivate), - m_currTimerId(-1), - m_hasValidDateTime(false) -{ -} - -QNmeaSimulatedReader::~QNmeaSimulatedReader() -{ - if (m_currTimerId > 0) - killTimer(m_currTimerId); -} - -void QNmeaSimulatedReader::readAvailableData() -{ - if (m_currTimerId > 0) // we are already reading - return; - - if (!m_hasValidDateTime) { // first update - Q_ASSERT(m_proxy->m_device && (m_proxy->m_device->openMode() & QIODevice::ReadOnly)); - - if (!setFirstDateTime()) { - //m_proxy->notifyReachedEndOfFile(); - qWarning("QNmeaPositionInfoSource: cannot find NMEA sentence with valid date & time"); - return; - } - - m_hasValidDateTime = true; - simulatePendingUpdate(); - - } else { - // previously read to EOF, but now new data has arrived - processNextSentence(); - } -} - -bool QNmeaSimulatedReader::setFirstDateTime() -{ - // find the first update with valid date and time - QGeoPositionInfo update; - bool hasFix = false; - while (m_proxy->m_device->bytesAvailable() > 0) { - char buf[1024]; - qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf)); - if (size <= 0) - continue; - bool ok = m_proxy->parsePosInfoFromNmeaData(buf, size, &update, &hasFix); - if (ok && update.timestamp().isValid()) { - QPendingGeoPositionInfo pending; - pending.info = update; - pending.hasFix = hasFix; - m_pendingUpdates.enqueue(pending); - return true; - } - } - return false; -} - -void QNmeaSimulatedReader::simulatePendingUpdate() -{ - if (m_pendingUpdates.size() > 0) { - // will be dequeued in processNextSentence() - QPendingGeoPositionInfo &pending = m_pendingUpdates.head(); - if (pending.info.coordinate().type() != QGeoCoordinate::InvalidCoordinate) - m_proxy->notifyNewUpdate(&pending.info, pending.hasFix); - } - - processNextSentence(); -} - -void QNmeaSimulatedReader::timerEvent(QTimerEvent *event) -{ - killTimer(event->timerId()); - m_currTimerId = -1; - simulatePendingUpdate(); -} - -void QNmeaSimulatedReader::processNextSentence() -{ - QGeoPositionInfo info; - bool hasFix = false; - int timeToNextUpdate = -1; - QTime prevTime; - if (m_pendingUpdates.size() > 0) - prevTime = m_pendingUpdates.head().info.timestamp().time(); - - // find the next update with a valid time (as long as the time is valid, - // we can calculate when the update should be emitted) - while (m_proxy->m_device && m_proxy->m_device->bytesAvailable() > 0) { - char buf[1024]; - qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf)); - if (size <= 0) - continue; - if (m_proxy->parsePosInfoFromNmeaData(buf, size, &info, &hasFix)) { - QTime time = info.timestamp().time(); - if (time.isValid()) { - if (!prevTime.isValid()) { - timeToNextUpdate = 0; - break; - } - timeToNextUpdate = prevTime.msecsTo(time); - if (timeToNextUpdate >= 0) - break; - } - } - } - - if (timeToNextUpdate < 0) - return; - - m_pendingUpdates.dequeue(); - - QPendingGeoPositionInfo pending; - pending.info = info; - pending.hasFix = hasFix; - m_pendingUpdates.enqueue(pending); - m_currTimerId = startTimer(timeToNextUpdate); -} - - -//============================================================ - - -QNmeaPositionInfoSourcePrivate::QNmeaPositionInfoSourcePrivate(QNmeaPositionInfoSource *parent, QNmeaPositionInfoSource::UpdateMode updateMode) - : QObject(parent), - m_updateMode(updateMode), - m_device(0), - m_invokedStart(false), - m_positionError(QGeoPositionInfoSource::UnknownSourceError), - m_source(parent), - m_nmeaReader(0), - m_updateTimer(0), - m_requestTimer(0), - m_noUpdateLastInterval(false), - m_updateTimeoutSent(false), - m_connectedReadyRead(false) -{ -} - -QNmeaPositionInfoSourcePrivate::~QNmeaPositionInfoSourcePrivate() -{ - delete m_nmeaReader; - delete m_updateTimer; -} - -bool QNmeaPositionInfoSourcePrivate::openSourceDevice() -{ - if (!m_device) { - qWarning("QNmeaPositionInfoSource: no QIODevice data source, call setDevice() first"); - return false; - } - - if (!m_device->isOpen() && !m_device->open(QIODevice::ReadOnly)) { - qWarning("QNmeaPositionInfoSource: cannot open QIODevice data source"); - return false; - } - - connect(m_device, SIGNAL(aboutToClose()), SLOT(sourceDataClosed())); - connect(m_device, SIGNAL(readChannelFinished()), SLOT(sourceDataClosed())); - connect(m_device, SIGNAL(destroyed()), SLOT(sourceDataClosed())); - - return true; -} - -void QNmeaPositionInfoSourcePrivate::sourceDataClosed() -{ - if (m_nmeaReader && m_device && m_device->bytesAvailable()) - m_nmeaReader->readAvailableData(); -} - -void QNmeaPositionInfoSourcePrivate::readyRead() -{ - if (m_nmeaReader) - m_nmeaReader->readAvailableData(); -} - -bool QNmeaPositionInfoSourcePrivate::initialize() -{ - if (m_nmeaReader) - return true; - - if (!openSourceDevice()) - return false; - - if (m_updateMode == QNmeaPositionInfoSource::RealTimeMode) - m_nmeaReader = new QNmeaRealTimeReader(this); - else - m_nmeaReader = new QNmeaSimulatedReader(this); - - return true; -} - -void QNmeaPositionInfoSourcePrivate::prepareSourceDevice() -{ - // some data may already be available - if (m_updateMode == QNmeaPositionInfoSource::SimulationMode) { - if (m_nmeaReader && m_device->bytesAvailable()) - m_nmeaReader->readAvailableData(); - } - - if (!m_connectedReadyRead) { - connect(m_device, SIGNAL(readyRead()), SLOT(readyRead())); - m_connectedReadyRead = true; - } -} - -bool QNmeaPositionInfoSourcePrivate::parsePosInfoFromNmeaData(const char *data, int size, - QGeoPositionInfo *posInfo, bool *hasFix) -{ - return m_source->parsePosInfoFromNmeaData(data, size, posInfo, hasFix); -} - -void QNmeaPositionInfoSourcePrivate::startUpdates() -{ - if (m_invokedStart) - return; - - m_invokedStart = true; - m_pendingUpdate = QGeoPositionInfo(); - m_noUpdateLastInterval = false; - - bool initialized = initialize(); - if (!initialized) - return; - - if (m_updateMode == QNmeaPositionInfoSource::RealTimeMode) { - // skip over any buffered data - we only want the newest data - if (m_device->bytesAvailable()) { - if (m_device->isSequential()) - m_device->readAll(); - else - m_device->seek(m_device->bytesAvailable()); - } - } - - if (m_updateTimer) - m_updateTimer->stop(); - - if (m_source->updateInterval() > 0) { - if (!m_updateTimer) - m_updateTimer = new QBasicTimer; - m_updateTimer->start(m_source->updateInterval(), this); - } - - if (initialized) - prepareSourceDevice(); -} - -void QNmeaPositionInfoSourcePrivate::stopUpdates() -{ - m_invokedStart = false; - if (m_updateTimer) - m_updateTimer->stop(); - m_pendingUpdate = QGeoPositionInfo(); - m_noUpdateLastInterval = false; -} - -void QNmeaPositionInfoSourcePrivate::requestUpdate(int msec) -{ - if (m_requestTimer && m_requestTimer->isActive()) - return; - - if (msec <= 0 || msec < m_source->minimumUpdateInterval()) { - emit m_source->updateTimeout(); - return; - } - - if (!m_requestTimer) { - m_requestTimer = new QTimer(this); - connect(m_requestTimer, SIGNAL(timeout()), SLOT(updateRequestTimeout())); - } - - bool initialized = initialize(); - if (!initialized) { - emit m_source->updateTimeout(); - return; - } - - m_requestTimer->start(msec); - - if (initialized) - prepareSourceDevice(); -} - -void QNmeaPositionInfoSourcePrivate::updateRequestTimeout() -{ - m_requestTimer->stop(); - emit m_source->updateTimeout(); -} - -void QNmeaPositionInfoSourcePrivate::notifyNewUpdate(QGeoPositionInfo *update, bool hasFix) -{ - // include before uncommenting - //qDebug() << "QNmeaPositionInfoSourcePrivate::notifyNewUpdate()" << update->timestamp() << hasFix << m_invokedStart << (m_requestTimer && m_requestTimer->isActive()); - - QDate date = update->timestamp().date(); - if (date.isValid()) { - m_currentDate = date; - } else { - // some sentence have time but no date - QTime time = update->timestamp().time(); - if (time.isValid() && m_currentDate.isValid()) - update->setTimestamp(QDateTime(m_currentDate, time, Qt::UTC)); - } - - if (hasFix && update->isValid()) { - if (m_requestTimer && m_requestTimer->isActive()) { - m_requestTimer->stop(); - emitUpdated(*update); - } else if (m_invokedStart) { - if (m_updateTimer && m_updateTimer->isActive()) { - // for periodic updates, only want the most recent update - m_pendingUpdate = *update; - if (m_noUpdateLastInterval) { - emitPendingUpdate(); - m_noUpdateLastInterval = false; - } - } else { - emitUpdated(*update); - } - } - m_lastUpdate = *update; - } -} - -void QNmeaPositionInfoSourcePrivate::timerEvent(QTimerEvent *) -{ - emitPendingUpdate(); -} - -void QNmeaPositionInfoSourcePrivate::emitPendingUpdate() -{ - if (m_pendingUpdate.isValid()) { - m_updateTimeoutSent = false; - m_noUpdateLastInterval = false; - emitUpdated(m_pendingUpdate); - m_pendingUpdate = QGeoPositionInfo(); - } else { - if (m_noUpdateLastInterval && !m_updateTimeoutSent) { - m_updateTimeoutSent = true; - m_pendingUpdate = QGeoPositionInfo(); - emit m_source->updateTimeout(); - } - m_noUpdateLastInterval = true; - } -} - -void QNmeaPositionInfoSourcePrivate::emitUpdated(const QGeoPositionInfo &update) -{ - m_lastUpdate = update; - emit m_source->positionUpdated(update); -} - -//========================================================= - -/*! - \class QNmeaPositionInfoSource - \inmodule QtLocation - \ingroup QtLocation-positioning - \since Qt Location 5.0 - - \brief The QNmeaPositionInfoSource class provides positional information using a NMEA data source. - - NMEA is a commonly used protocol for the specification of one's global - position at a certain point in time. The QNmeaPositionInfoSource class reads NMEA - data and uses it to provide positional data in the form of - QGeoPositionInfo objects. - - A QNmeaPositionInfoSource instance operates in either \l {RealTimeMode} or - \l {SimulationMode}. These modes allow NMEA data to be read from either a - live source of positional data, or replayed for simulation purposes from - previously recorded NMEA data. - - The source of NMEA data is set with setDevice(). - - Use startUpdates() to start receiving regular position updates and stopUpdates() to stop these - updates. If you only require updates occasionally, you can call requestUpdate() to request a - single update. - - In both cases the position information is received via the positionUpdated() signal and the - last known position can be accessed with lastKnownPosition(). -*/ - - -/*! - \enum QNmeaPositionInfoSource::UpdateMode - Defines the available update modes. - - \value RealTimeMode Positional data is read and distributed from the data source as it becomes available. Use this mode if you are using a live source of positional data (for example, a GPS hardware device). - \value SimulationMode The data and time information in the NMEA source data is used to provide positional updates at the rate at which the data was originally recorded. Use this mode if the data source contains previously recorded NMEA data and you want to replay the data for simulation purposes. -*/ - - -/*! - Constructs a QNmeaPositionInfoSource instance with the given \a parent - and \a updateMode. -*/ -QNmeaPositionInfoSource::QNmeaPositionInfoSource(UpdateMode updateMode, QObject *parent) - : QGeoPositionInfoSource(parent), - d(new QNmeaPositionInfoSourcePrivate(this, updateMode)) -{ -} - -/*! - Destroys the position source. -*/ -QNmeaPositionInfoSource::~QNmeaPositionInfoSource() -{ - delete d; -} - -/*! - Parses an NMEA sentence string into a QGeoPositionInfo. - - The default implementation will parse standard NMEA sentences. - This method should be reimplemented in a subclass whenever the need to deal with non-standard - NMEA sentences arises. - - The parser reads \a size bytes from \a data and uses that information to setup \a posInfo and - \a hasFix. If \a hasFix is set to false then \a posInfo may contain only the time or the date - and the time. - - Returns true if the sentence was succsesfully parsed, otherwise returns false and should not - modifiy \a posInfo or \a hasFix. -*/ -bool QNmeaPositionInfoSource::parsePosInfoFromNmeaData(const char *data, int size, - QGeoPositionInfo *posInfo, bool *hasFix) -{ - return QLocationUtils::getPosInfoFromNmea(data, size, posInfo, hasFix); -} - -/*! - Returns the update mode. -*/ -QNmeaPositionInfoSource::UpdateMode QNmeaPositionInfoSource::updateMode() const -{ - return d->m_updateMode; -} - -/*! - Sets the NMEA data source to \a device. If the device is not open, it - will be opened in QIODevice::ReadOnly mode. - - The source device can only be set once and must be set before calling - startUpdates() or requestUpdate(). - - \b {Note:} The \a device must emit QIODevice::readyRead() for the - source to be notified when data is available for reading. - QNmeaPositionInfoSource does not assume the ownership of the device, - and hence does not deallocate it upon destruction. -*/ -void QNmeaPositionInfoSource::setDevice(QIODevice *device) -{ - if (device != d->m_device) { - if (!d->m_device) - d->m_device = device; - else - qWarning("QNmeaPositionInfoSource: source device has already been set"); - } -} - -/*! - Returns the NMEA data source. -*/ -QIODevice *QNmeaPositionInfoSource::device() const -{ - return d->m_device; -} - -/*! - \reimp -*/ -void QNmeaPositionInfoSource::setUpdateInterval(int msec) -{ - int interval = msec; - if (interval != 0) - interval = qMax(msec, minimumUpdateInterval()); - QGeoPositionInfoSource::setUpdateInterval(interval); - if (d->m_invokedStart) { - d->stopUpdates(); - d->startUpdates(); - } -} - -/*! - \reimp -*/ -void QNmeaPositionInfoSource::startUpdates() -{ - d->startUpdates(); -} - -/*! - \reimp -*/ -void QNmeaPositionInfoSource::stopUpdates() -{ - d->stopUpdates(); -} - -/*! - \reimp -*/ -void QNmeaPositionInfoSource::requestUpdate(int msec) -{ - d->requestUpdate(msec == 0 ? 60000 * 5 : msec); -} - -/*! - \reimp -*/ -QGeoPositionInfo QNmeaPositionInfoSource::lastKnownPosition(bool) const -{ - // the bool value does not matter since we only use satellite positioning - return d->m_lastUpdate; -} - -/*! - \reimp -*/ -QGeoPositionInfoSource::PositioningMethods QNmeaPositionInfoSource::supportedPositioningMethods() const -{ - return SatellitePositioningMethods; -} - -/*! - \reimp -*/ -int QNmeaPositionInfoSource::minimumUpdateInterval() const -{ - return 100; -} - -/*! - \reimp -*/ -QGeoPositionInfoSource::Error QNmeaPositionInfoSource::error() const -{ - return d->m_positionError; -} - -void QNmeaPositionInfoSource::setError(QGeoPositionInfoSource::Error positionError) -{ - d->m_positionError = positionError; - emit QGeoPositionInfoSource::error(positionError); -} - -#include "moc_qnmeapositioninfosource.cpp" -#include "moc_qnmeapositioninfosource_p.cpp" - -QT_END_NAMESPACE diff --git a/src/location/qnmeapositioninfosource.h b/src/location/qnmeapositioninfosource.h deleted file mode 100644 index fd1abd57..00000000 --- a/src/location/qnmeapositioninfosource.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QNMEAPOSITIONINFOSOURCE_H -#define QNMEAPOSITIONINFOSOURCE_H - -#include - -QT_BEGIN_NAMESPACE - -class QIODevice; - -class QNmeaPositionInfoSourcePrivate; -class Q_LOCATION_EXPORT QNmeaPositionInfoSource : public QGeoPositionInfoSource -{ - Q_OBJECT -public: - enum UpdateMode { - RealTimeMode = 1, - SimulationMode - }; - - explicit QNmeaPositionInfoSource(UpdateMode updateMode, QObject *parent = 0); - ~QNmeaPositionInfoSource(); - - UpdateMode updateMode() const; - - void setDevice(QIODevice *source); - QIODevice *device() const; - - void setUpdateInterval(int msec); - - QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const; - PositioningMethods supportedPositioningMethods() const; - int minimumUpdateInterval() const; - Error error() const; - - -public Q_SLOTS: - void startUpdates(); - void stopUpdates(); - void requestUpdate(int timeout = 0); - -protected: - virtual bool parsePosInfoFromNmeaData(const char *data, - int size, - QGeoPositionInfo *posInfo, - bool *hasFix); - -private: - Q_DISABLE_COPY(QNmeaPositionInfoSource) - friend class QNmeaPositionInfoSourcePrivate; - QNmeaPositionInfoSourcePrivate *d; - void setError(QGeoPositionInfoSource::Error positionError); -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/location/qnmeapositioninfosource_p.h b/src/location/qnmeapositioninfosource_p.h deleted file mode 100644 index b231d72f..00000000 --- a/src/location/qnmeapositioninfosource_p.h +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QNMEAPOSITIONINFOSOURCE_P_H -#define QNMEAPOSITIONINFOSOURCE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qnmeapositioninfosource.h" -#include "qgeopositioninfo.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QBasicTimer; -class QTimerEvent; -class QTimer; - -class QNmeaReader; -struct QPendingGeoPositionInfo -{ - QGeoPositionInfo info; - bool hasFix; -}; - - -class QNmeaPositionInfoSourcePrivate : public QObject -{ - Q_OBJECT -public: - QNmeaPositionInfoSourcePrivate(QNmeaPositionInfoSource *parent, QNmeaPositionInfoSource::UpdateMode updateMode); - ~QNmeaPositionInfoSourcePrivate(); - - void startUpdates(); - void stopUpdates(); - void requestUpdate(int msec); - - bool parsePosInfoFromNmeaData(const char *data, - int size, - QGeoPositionInfo *posInfo, - bool *hasFix); - - void notifyNewUpdate(QGeoPositionInfo *update, bool fixStatus); - - QNmeaPositionInfoSource::UpdateMode m_updateMode; - QPointer m_device; - QGeoPositionInfo m_lastUpdate; - bool m_invokedStart; - QGeoPositionInfoSource::Error m_positionError; - -public Q_SLOTS: - void readyRead(); - -protected: - void timerEvent(QTimerEvent *event); - -private Q_SLOTS: - void emitPendingUpdate(); - void sourceDataClosed(); - void updateRequestTimeout(); - -private: - bool openSourceDevice(); - bool initialize(); - void prepareSourceDevice(); - void emitUpdated(const QGeoPositionInfo &update); - - QNmeaPositionInfoSource *m_source; - QNmeaReader *m_nmeaReader; - QBasicTimer *m_updateTimer; - QGeoPositionInfo m_pendingUpdate; - QDate m_currentDate; - QTimer *m_requestTimer; - bool m_noUpdateLastInterval; - bool m_updateTimeoutSent; - bool m_connectedReadyRead; -}; - - -class QNmeaReader -{ -public: - explicit QNmeaReader(QNmeaPositionInfoSourcePrivate *sourcePrivate) - : m_proxy(sourcePrivate) {} - virtual ~QNmeaReader() {} - - virtual void readAvailableData() = 0; - -protected: - QNmeaPositionInfoSourcePrivate *m_proxy; -}; - - -class QNmeaRealTimeReader : public QNmeaReader -{ -public: - explicit QNmeaRealTimeReader(QNmeaPositionInfoSourcePrivate *sourcePrivate); - virtual void readAvailableData(); -}; - - -class QNmeaSimulatedReader : public QObject, public QNmeaReader -{ - Q_OBJECT -public: - explicit QNmeaSimulatedReader(QNmeaPositionInfoSourcePrivate *sourcePrivate); - ~QNmeaSimulatedReader(); - virtual void readAvailableData(); - -protected: - virtual void timerEvent(QTimerEvent *event); - -private Q_SLOTS: - void simulatePendingUpdate(); - -private: - bool setFirstDateTime(); - void processNextSentence(); - - QQueue m_pendingUpdates; - int m_currTimerId; - bool m_hasValidDateTime; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/geoservices/nokia/NOKIA_TERMS_AND_CONDITIONS.txt.qdocinc b/src/plugins/geoservices/nokia/NOKIA_TERMS_AND_CONDITIONS.txt.qdocinc new file mode 100644 index 00000000..d73042b6 --- /dev/null +++ b/src/plugins/geoservices/nokia/NOKIA_TERMS_AND_CONDITIONS.txt.qdocinc @@ -0,0 +1,315 @@ +NOKIA DEVELOPER SOFTWARE AGREEMENT 2.1 + +FOR THE NOKIA MAPS PLUG-IN TO Qt LOCATION + + +Please read this Nokia Developer Software Agreement carefully before accessing, downloading or using any part ofthe Nokia Maps Plug-In to Qt Mobility. By accessing, downloading, installing, using or clicking on the "Accept" button while downloading, installing and/or using the Software, You agree to the terms and conditions of this Agreement. + +Please note that this Agreement is structured in two sections: (i) general terms that apply to most Nokia developer software distributions; and (ii) additional terms and conditions applicable to certain parts of the Software or related content, services, additions and extensions that are specific to the particular Software provided. Please ensure to review the entirety of the terms provided as important restrictions relevant to your use of the Software are often included as additional terms. + +GENERAL TERMS + +1. Acceptance + +This Nokia Developer Software Agreement (the “Agreement”) governs Your use of the Software (ase defined below) and these terms and conditions constitute an agreement between You (either an individual or an entity) and Nokia Corporation including its affiliates and suppliers (collectively “Nokia”) defining the rights and responsibilities of You and Nokia with respect to the Software. + +There may be additional terms and conditions specific to the particular Software provided or applicable to certain parts of the Software or related content, services, additions and extensions. + +You are not allowed to use the Software if You do not agree to these terms and conditions. + +2. Definitions + +“Application” means one or more software programs developed by You in compliance with the requirements set forth in this Agreement and documentation provided by Nokia, under Your own trademark or brand, including bug fixes, updates, upgrades and new versions of such software programs. + +“Authorized Users” means You and Your employees and contractors or, if You are an educational institution, Your faculty and staff, as applicable, who (a) each have a valid Forum Nokia account with Nokia, (b) have a demonstrable need to know or use the Software in order to develop and test Applications, and (c) to the extent such individuals will have access to Confidential Information, each have written and binding agreements with You to protect the unauthorized use and disclosure of such Confidential Information. + +“Software” means (i) the Nokia Maps Plug-In to the Qt Mobility software product (source code and/or object code as applicable), with the exception of Open Source Software (as defined below), documentation, sample code, simulators, tools, libraries, application programming interfaces (APIs), data, files, and materials hereby provided or made available by Nokia for use by You in connection with Your Application development, and includes any updates that may be provided or made available by Nokia. + +"Open Source Software" means any software, which is, as included in the Software, subject to a license terms and conditions currently listed at http://opensource.org/licenses/ or meeting the criteria listed at http://www.opensource.org/docs/definition.php or which is subject to any similar free or open source license terms. Open Source Software contained in the Software is licensed under the license terms accompanying such Open Source Software and not the terms of this Agreement. + + “You” or “Your” means the person(s) or entity using the Software or otherwise exercising rights under these Terms. If you are accepting these Terms on behalf of your company. organization or other entity, “You” or “Your” refers to your company, organization or other entity as well. + +3. Eligibility + +You must be legally competent to execute this Agreement. Thereby You must be of the legal age of majority in the jurisdiction in which You reside (at least 18 years of age in most countries) and have the right and authority to enter into this Agreement on Your own behalf, or if You are entering into this Agreement on behalf of Your company, organization or other entity, that You have the right and authority to legally bind Your company, organization or other entity to the terms and obligations of this Agreement. + +4. Registration and termination + +If registration is required, You agree to provide truthful and complete information when registering for the Software and to keep that information updated. Providing misleading information about Your identity is forbidden. + +You may terminate Your registration(s) if You no longer wish to use the Software. After termination, You may not access the Software. Nokia may terminate Your registration(s) or restrict Your access to certain parts of the Software or related services if there is an indication that You have breached this Agreement. + +You may terminate this Agreement at any time by permanently uninstalling and/or deleting, at Your own costs, the Software and any backup copies, and all related materials provided by Nokia and by ceasing to use the Software. All Your rights automatically and immediately terminate without notice from Nokia if You fail to comply with any provision of these Terms. In such an event, You must immediately uninstall and/or delete, at Your own cost, the Software, all backup copies, and all other related material provided by Nokia as well as stop using the Software. + +Nokia may, in its sole discretion, provide with updates to the Software from time to time. Nokia may also provide with updates that are considered as important or critical by Nokia, and in such case You may not continue using the previous version of the Software and the use of the previous version of the Software may be prevented without installation of the update. Any related services or features of the Software may not be available during maintenance breaks and other times. Nokia may also decide to discontinue the Software, related service or any part thereof in its sole discretion. In such case You will be provided a prior notification and Nokia may terminate the Agreement accordingly. + +5. Updates to the Terms + +Nokia reserves the right to modify or amend the terms and conditions of this Agreement at any time without prior notice. If the terms are changed in a material, adverse way, Nokia will provide a separate notice advising of such change. In order to continue using the Software, You must accept and agree to the new terms of this Agreement. If You do not agree to new terms, Your use of the Software will be suspended or terminated by Nokia. + +6. Use of the Software + +You hereby certify and agree that You will comply with the terms of this Agreement and You agree to monitor and be responsible for Your Authorized Users’ use of the Software and their compliance with the terms of this Agreement. You may not grant access to the Software for any other than Authorized Users. + +The Software is made accessible to You for the sole purpose of developing and testing Your Application(s). You may install, as applicable, a reasonable number of copies of the Software on computers owned or controlled by You to be used by You or Your Authorized Users during the term of this Agreement. + +As a condition to using the Software, You hereby agree that: + +(i) You will not use the Software in any manner or for any purpose that violates these Terms or any applicable law or regulation, including without limitation, any intellectual property or other proprietary rights, any right of any person, rights of privacy, or rights of personality; + +(ii) You will not distribute or post spam, unreasonably large files, chain letters, pyramid schemes, any malicious code, viruses or any other technologies or content that may harm the Software, other users, servers or network; + +(iii) You will not use the Software in connection with any unlawful, offensive, abusive, obscene, pornographic, harassing, libelous or otherwise inappropriate content or material; + +(iv) You will be solely responsible for all costs, expenses, losses and liabilities incurred, and activities undertaken by You and Authorized Users in connection with the Software, Your Applications and Your related development efforts; and + +(v) You will not remove or obscure any copyright or trademark notices or other similar notices or markings or legends from the Software; + +Notwithstanding anything to the contrary contained herein, You may not (a) reverse engineer, decompile, disassemble or otherwise attempt to discover the source code of the Software, except and only to the extent permitted by applicable mandatory law; (b) modify or create derivative works of the Software, except and only to the extent permitted by Nokia; or (c) distribute, communicate to the public, export, re-export, sublicense, rent, loan, lease, disclose, sell, market, commercialise, re-license, host, or otherwise transfer or make available to any third party (including without limitation any affiliates and subcontractors) the Software (or any portions thereof). + +Nothing in this Agreement or otherwise prevents Nokia from developing, distributing and/or making use of any application that is directly or indirectly competing with Your Application. + +7. Requirements for Your Applications + +Your Application developed using the Software, or any part thereof, must comply with the following criteria and requirements, as may be modified by Nokia from time to time: + +(i) Your Application will be developed and used in compliance with the these Terms or any applicable law or regulation, including without limitation, any intellectual property or other proprietary rights, any right of any person, rights of privacy, or rights of personality; + +(ii) Your Application will be developed in compliance with the documentation, technical guidelines and other requirements as Nokia may provide from time to time; + +(iii) Your Application does not and will not, to the best of Your knowledge, violate, misappropriate, or infringe any copyright, patent, trademark, trade secret, rights of privacy or other proprietary or legal right of any third party or of Nokia; + +(iv) Your Application must not contain nor transfer any viruses, files, code malware or any other malicious software programs that may harm or disrupt the normal operation of the device or network; + +(v) Your Application must identify the nature and provider (including contact details) of the application, function as promoted and not contain any false, fraudulent or misleading information or representations; + +(vi) You will clearly communicate to the users of Your Application(s) (e.g. in the Application UI) that the use of the Application(s) creates data traffic; + +(vii) You will provide users of the Application(s) with easy settings to disable notifications; + +(viii) You will not design or market the Application, or any part thereof, in connection with any internal business application the purpose of which is directly related to the operation of Your core business and where the users of such application are Your employees or contractors (e.g. fleet or asset management and tracking); + +(ix) You will not design or market the Application, or any part thereof, for use in or with systems, devices or products that are critical to health and/or security of other people and property (e.g. intended for surgical implant into the body or other applications intended to support or sustain life or for any aviation or nuclear reactor application) or any other application in which the software or its failure, malfunction or inadequacy could directly or indirectly cause or contribute to personal injury or death or significant property damage; + +(x) Your Application must not enable push notifications routed from other notification systems and servers provided by third parties; + +(xi) Your Application shall not send any push notifications without first obtaining user consent, (e.g. unsolicited messages, advertising, promotions, or direct marketing of any kind or for the purposes of phishing and spamming); and + +(xii) Your Application shall not send any messages for the purpose of phishing or spamming, or enable anonymous or prank phone calls or SMS/MMS messaging. + +8. Ownership and Intellectual Property Rights + +The Software and all rights, without limitation including title and intellectual property rights therein, are owned by Nokia and/or its licensors and affiliates and are protected by international treaty provisions and all other applicable national laws of the country in which it is being used. The structure, organization, and code of the Software are the valuable trade secrets and confidential information of Nokia and/or its licensors and affiliates. + +No right or license, express or implied, is granted to any part of the Software except as expressly set forth above. In addition, no licenses or immunities are granted to the combination of the Software with any other software or hardware not delivered by Nokia under this Agreement. Also, any and all licenses with respect to Nokia or third party patents (including essential patents) are specifically excluded from the scope of this Agreement, and those licenses need to be acquired separately from Nokia or the respective right holders, as the case may be. + +You and Your affiliates, as the case may be, covenant and agree not to bring suit before any court or administrative agency or otherwise assert any claim against Nokia or any of its affiliates, suppliers, licensees or customers based on any of Your patent or Your affiliate’s due to reproduction, development, use, manufacturing, marketing, selling, distribution, licensing, importing, sub-licensing or other disposal of the Software or implementations thereof. + +You and Your affiliates shall impose the obligation stated in clause above on any third party to whom You or Your affiliates may assign or transfer Your patents. This obligation is restricted to suits or other assertions based on such assigned or transferred patents. + +You shall be released from Your covenant and agreement not to sue under this section in relation to a particular beneficiary (but not in relation to any other beneficiary) in the following event: (i) You are first sued for patent infringement related to the Software by such other beneficiary who benefits from Your covenant and agreement as set forth herein; and (ii) the suit is based on Your infringement of such other beneficiary’s patent rights which if held by You would be subject to the covenant and agreement not to sue provided for above in this section. + +For the purposes of this section, patent means any patent, utility model and any divisional, re-exam, re-issue, continuation and continuation-in-part thereof as well as any corresponding application globally. + +9. Fees + +Your use of the Software may be or may become subject to charges. Nokia reserves the right to charge for the Software and to change its fees from time to time, at its discretion. + +10. Availability + +The Software may not be available in all countries and may be provided only in selected languages. The Software or some features may be network dependent, contact Your network service provider for more information. + +11. Support and maintenance + +Nokia has no obligation to furnish You with technical or other support unless separately agreed in writing between You and Nokia. In case of such support given by Nokia, You understand and agree that the support has been given on “as is” and “as available” basis and Nokia will have no obligations or liabilities related to such support. + +12. Feedback + +By submitting feedback (“Feedback”) to Nokia related to the Software, You acknowledge and agree that (1) Nokia may have similar development ideas to the Feedback; (2) Your Feedback does not contain confidential or proprietary information related to Your own activities or those of any third party; (3) Nokia is not under any obligation of confidentiality with respect to the Feedback; and (4) You are not entitled to any compensation of any kind from Nokia. You hereby grant Nokia a worldwide non-exclusive, sublicensable, assignable, fully paid up, royalty-free, perpetual and irrevocable license to use, reproduce, adapt, translate, exploit, copy, publicly perform, display, distribute, further develop and modify for any purpose such Feedback, and to prepare derivative works thereof, or incorporate such Feedback into other works as well as sublicense products and Software resulting from such works. + +13. Links to Third Party Sites and Services + +For Your easy accessibility Nokia may include links to sites and services on the Internet that are owned or operated by third parties and that are not part of the Software. Upon following a link to such a third-party site, You shall review and agree to that site's rules of use before using such site or service. + +You agree that Nokia has no control over the content of third-party sites and cannot assume any responsibility for services provided or material created or published by such sites. A link to a third-party site does not imply that Nokia endorses the site or the products or services referenced in the site. + +You agree that Nokia is neither responsible nor liable for any such links or any third party Internet site. + +14. Confidentiality + +You agree that all material and information in any form received from Nokia, including, but not limited to Software and its copies, as well as all translations of computer programs contained in the Software, Nokia's products, designs, business plans, business opportunities, finances, research, development, know-how, personnel, or third-party confidential information, will be considered and referred to collectively as "Confidential Information". Confidential Information, however, does not include: (a) information that Nokia makes generally available to the public; (b) information that You can demonstrate to have had rightfully in Your possession prior to disclosure to You by Nokia; (c) information that is independently developed by You without the use of any Confidential Information; or (d) information that You rightfully obtain from a third party who has been given the right to transfer or disclose it by Nokia. You agree to keep confidential and not to disclose, publish, or disseminate any Confidential Information to any third party. You further agree to take reasonable precautions to prevent any unauthorized use, disclosure, publication, or dissemination of Confidential Information. You agree not to use Confidential Information otherwise for Your own or any third party's benefit without the prior written approval of an authorized representative of Nokia in each instance. + +You further agree that despite of any other confidentiality agreements You may have between You and Nokia, Nokia will not be responsible for keeping confidential any information You provide to Nokia through the use of the Software or any related services. Neither Nokia nor any of its employees accept or consider unsolicited ideas, including but not limited to ideas for new advertising campaigns, new promotions, new products or technologies, processes, materials, marketing plans or new product names. If, despite the request that You not send us Your ideas and materials, You still send them, please understand that Nokia makes no assurances that Your ideas and materials will be treated as confidential or proprietary. + +The rights and obligations of this section 14 shall remain in force for five (5) years from the date of the disclosure of Confidential Information. + +15. No warranties + +YOU ACKNOWLEDGE THAT THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, AND TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW NEITHER NOKIA, ITS LICENSORS OR AFFILIATES, NOR THE COPYRIGHT HOLDERS MAKE ANY REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ACCURACY OF DOCUMENTATION AND SUPPORT MATERIAL, OR FITNESS FOR A PARTICULAR PURPOSE OR THAT SOFTWARE WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER RIGHTS. THERE IS NO WARRANTY BY NOKIA OR BY ANY OTHER PARTY THAT THE FUNCTIONS CONTAINED IN THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE. YOU ASSUME ALL RESPONSIBILITY AND RISK FOR THE SELECTION OF THE SOFTWARE TO ACHIEVE YOUR INTENDED RESULTS AND FOR THE INSTALLATION, USE, AND RESULTS OBTAINED FROM IT. + +16. Indemnity + +You agree to defend and indemnify Nokia from and against all third party claims and all liabilities, assessments, losses, costs or damages resulting from or arising out of (i) Your breach of this Agreement, (ii) Your infringement or violation of any intellectual property, other rights or privacy of a third party, and (iii) misuse of the Software by a third party where such misuse was made available by Your failure to take reasonable measures to protect Your username and password against misuse. + +17. Limitation of liability + +TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL NOKIA, ITS EMPLOYEES,LICENSORS OR AFFILIATES BE LIABLE FOR ANY LOST PROFITS, REVENUE, SALES, DATA, OR COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SOFTWARE, PROPERTY DAMAGE, PERSONAL INJURY, INTERRUPTION OF BUSINESS, LOSS OF BUSINESS INFORMATION, OR FOR ANY SPECIAL, DIRECT, INDIRECT, INCIDENTAL, ECONOMIC, COVER, PUNITIVE, SPECIAL, OR CONSEQUENTIAL DAMAGES, HOWEVER CAUSED AND WHETHER ARISING UNDER CONTRACT, TORT, NEGLIGENCE, OR OTHER THEORY OF LIABILITY ARISING OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE OR THE SOFTWARE, EVEN IF NOKIA OR ITS LICENSORS OR AFFILIATES ARE ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME COUNTRIES/STATES/JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF LIABILITY, BUT MAY ALLOW LIABILITY TO BE LIMITED, IN SUCH CASES, NOKIA, ITS EMPLOYEES OR LICENSORS OR AFFILIATES' LIABILITY SHALL BE LIMITED TO U.S. $50. Nothing contained in this Agreement shall prejudice the statutory rights of any party dealing as a consumer. Nothing contained in this Agreement limits Nokia's liability to you in the event of death or personal injury resulting from Nokia's negligence. Nokia is acting on behalf of its employees and licensors or affiliates for the purpose of disclaiming, excluding, and/or restricting obligations, warranties, and liability as provided in this Agreement, but in no other respects and for no other purpose. + +18. Export control + +You acknowledge that the Software may be subject to export control restrictions of various countries. You shall fully comply with all applicable export license restrictions and requirements as well as with all laws and regulations relating to the importation of the Software and/or Applications and shall procure all necessary governmental authorizations, including without limitation, all necessary licenses, approvals, permissions or consents, where necessary for the re-exportation of the Software or Applications. + +19. Government End Users + +A "U.S. Government End User" shall mean any agency or entity of the government of the United States. The following shall apply if You are a U.S. Government End User. The Software is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" and "commercial computer software documentation," as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire the Software with only those rights set forth herein. The Software (including related documentation) is provided to U.S. Government End Users: (a) only as a commercial end item; and (b) only pursuant to this Agreement. + +20. Miscellaneous + +20.1 Notices + +All notices of the Software should be delivered to: + +Nokia Corporation +P.O. Box 100 +FIN-00045 Nokia Group +Finland + +20.2 Assignment + +You shall not be entitled to assign or transfer all or any of Your rights, benefits and obligations under this Agreement without the prior written consent of Nokia, which shall not be unreasonably withheld. Nokia shall be entitled to assign or transfer any of its rights, benefits or obligations under this Agreement on an unrestricted basis. + +20.3 Severability + +If any part of this Agreement is found void and unenforceable, it will not affect the validity of the balance of the Agreement, which shall remain valid and enforceable according to its terms. + +20.4 Privacy + +The Nokia Privacy Policy and any additional privacy supplements govern the use of Your personal data. + +20.5 Governing law and dispute resolution + +This Agreement is governed by the laws of Finland. All disputes arising from or relating to these Terms shall be settled by a single arbitrator appointed by the Central Chamber of Commerce of Finland. The arbitration procedure shall take place in Helsinki, Finland in the English language. + +20.6 Entire Agreement + +This is the entire agreement between Nokia and You relating to the Software, and it supersedes any prior representations, discussions, undertakings, end-user agreements, communications, or advertising relating to the Software. + +ADDITIONAL TERMS + +Location API Additional Terms + +In addition to the terms set forth in Nokia Software Development Agreement version 2.1, the Nokia Privacy Policy and following additional terms shall apply to Your use of the Nokia Maps Plug-In (“Plug-In”) that is delivered in conjunction with the Qt Mobility software package and Nokia’s related location-based services (“Service”). Please note that these terms and conditions do no apply to Your use of the location APIs included in Qt Mobility as such and only apply to the use of the Plug-In and Service + + +1. Definitions + +“Nokia Maps Content” means the maps content available from Nokia from time to time for the purpose of being rendered on the Nokia Maps, including data provided by Nokia that originates from third parties. + +“Location API Service” means the service offered by Nokia that enables You to incorporate the Location API s For Developers, the Nokia Maps Content and the Places Content, as made available by Nokia from time to time, into Your Applications and to have end-users access and use it on such Applications. + +“Location API For Developers” means the software, as made available by Nokia from time to time that allows the rendering of Nokia Maps Content and Places Content within Applications. For clarity, the Location API For Developers may include software components that are downloaded and installed on the users’ mobile device(s) and/or JavaScript libraries that are invoked and downloaded by the Location API(s) and/or data retrieved from server based APIs, including but not limited to the Ovi Maps Rendering API. “Location API Developer Package” means the Location API(s), documentation and any and all other material made accessible to You by Nokia from time to time that enables You to incorporate the Location API For Developers into Your Applications and is designated by Nokia as being a part of the Location API Developer Package. + +“Location API(s)” means the interface information made accessible to You by Nokia from time to time that enables You to incorporate the Location API For Developers into Your Applications. + +Places Content” means the geo-location content, including rich content (e.g. descriptions, opening hours, reviews) available from Nokia, including data provided by Nokia that originates from third parties + +2. Service Offering, Registration and Termination + +The Service is made available under a variety of business models to suit Your needs which will form an integral part of your agreement with Nokia for the use of the Software. For information about the Service, please visit www.forumnokia.com/Maps/. + +If you do not register for the Service Your use of the Location API For Developers is limited to internal testing of your Application(s) that use the Location API(s) and the Service will automatically disable itself once the access quota for the Service has been exceeded. + +If you elect to register for the Service (https://api.forum.nokia.com/ovi-api), You will be provided with a token and/or developer key that will enable You to create Application(s) that use the Location API(s) and distribute such Application(s) under the terms of this Agreement. The number of requests submitted by your Application(s) to the Service may be subject to certain quota limitations as updated from time to time by Nokia. + +If You elect to register for the Service, You agree to provide truthful and complete information when registering for the Service and to keep that information updated. Providing misleading information about Your identity is forbidden. You are personally responsible for any use of the Location API Service. You agree to take due care in protecting Your Application using Location API, Your token and/or developer key against misuse by others and promptly notify Nokia about any misuse. Where requested by Nokia, You agree to include and use the token and/or developer key, as applicable, in each request You make to access to the Location API(s). + +You may terminate Your registration if You no longer wish to use the Service. After termination, You may not access the Service. Nokia may terminate Your registration or restrict Your access to certain parts of the Service if there is an indication that You have breached these terms or with a prior notice if You have not signed into the Service with Your identifier code in the past three (3) months. + +3. Changes + +Nokia may, in its sole discretion, change, improve and correct the Service from time to time. Nokia may also provide with updates to the Service that are considered as important or critical by Nokia, and in such case You may not continue using the previous version of the Service and the use of the previous version of the Service may be prevented without installation of the update. The Service may not be available during maintenance breaks and other times. Nokia may also decide to discontinue the Service or any part thereof in its sole discretion. In such case You will be provided a prior notification and Nokia may terminate the Agreement accordingly. + +Except as set forth in Privacy Policy, Nokia shall not be responsible for any removal or loss of the information or content You have submitted (“Material”) to the Service when Your registration is terminated. After the Material is removed from the Service by either You or Nokia, traces and copies of the Material may still remain. + +Nokia reserves the right to modify or amend these terms and conditions at any time without prior notice. If the terms are changed in a material, adverse way, Nokia will provide a separate notice advising of such change. In order to continue using the Service, You must accept and agree to the new terms and conditions. If You do not agree to new terms, Your use of the Service will be suspended or terminated by Nokia. + +4. Use of Location API Developer Package + +The Location API Developer Package is made accessible to You for the purposes of incorporating the Service into Your Application and for the limited purposes of evaluating, testing, and controlling the Location API For Developers during the term of this Agreement, subject to the limitations set forth in Section 2 of these additional terms set forth above. If you have not registered for the Service, You may not distribute your Applications incorporating the Service. + +When using the Location API Developer Package and/or the Service, unless otherwise agreed in writing with Nokia, You hereby agree that You will not: + +(i) use or incorporate, without Nokia’s prior written permission, the Service, Location API Developer Package or any part thereof, in connection with any Application or other service (a) which has the primary functionality of providing turn-by-turn navigation services, real time navigation or route guidance; or (b) where such Application’s functionality is substantially similar to the Nokia Maps or navigation/location-based products distributed by Nokia or its affiliates; or (c) which has the primary purpose of capturing or collecting end user data; + +(ii) use, without Nokia’s prior written permission, the Service or Location API For Developers, or any part thereof, in connection with any internal business Application the purpose of which is directly related to the operation of Your core business and where the users of such Application are Your employees or contractors (e.g. fleet or asset management and tracking); + +(iii) remove, obscure, modify or omit, any copyright or trademark notices or other similar notices or markings or legends or branding requirements from the Location API Developer Package, Location API For Developers, Nokia Maps Content, or the Places Content whether such notices, markings or legends or other branding requirements originate from Nokia or a third party; + +(iv) alter or manipulate the order of search, geo-coding and/or reverse geo-coding results delivered by or through any Location API to or as part of the Application (where applicable); + +(v) alter, delete or otherwise change any Nokia Maps Content or Places Content, including third party content contained in the Nokia Maps Content or Places Content, branding or sponsorship information, that is displayed through the use of the Service or Location API For Developers; + +(vi) create an Application which obsures or alters the visibility of Places Content and/or Nokia Maps Content or any other content; or + +(v) use the Location API(s) or Service to exceed any transaction volume limits (if any) set by Nokia for Applications, Location APIs and/or Services. The amount of the possible transaction volume limit is as set forth in the documentation included in the Location API. Nokia may change the limit from time to time in its sole discretion, but will provide You with sixty (60) days’ advance notice of a change in the volume limit. Any programmatic methods or other actions intended to circumvent the transaction volume limits shall be considered a material breach of this Agreement; + +(vii) access, or use the Service any Nokia Maps Content or Places Content through any technology or means other than those provided by the Service or Location API(s), or through other explicitly authorized means Nokia may designate; + +(viii) use the Service, Location API or Location API For Developers in a manner that gives You or any other person access to mass downloads or bulk feeds of any Nokia Maps Content or Places Content, including but not limited to numerical latitude or longitude coordinates; + +(ix) pre-fetch, cache, or store any Nokia Maps Content or Places Content except that You may store (i) references and IDs; and (ii) limited amounts of Nokia Maps Content or Places Conent solely for the purpose of testing your Application, if You do so temporarily, securely, and in a manner that does not permit use of the Nokia Maps Content or Places Content outside of the Service; or + +(x) use the Location API Developer Package, including the Location API For Developers, or the Service in any manner or for any purpose that violates this Agreement or any law or regulation, including without limitation, any intellectual property or other proprietary rights, any right of any person, rights of privacy, or rights of personality; or + +(xi) use the Location API(s) to issue queries that are not in response to end user actions; or + +(xii) create Application(s) which do not display the results of every such search made by such Application(s) using the Location API(s) to the end user; or + +(xiii) distribute in any manner, such as through the Location API(s), Nokia Maps Content or Places Content collected using the Location API(s), or data derived from the Nokia Maps Content or Places Content, including, but not limited to location corrections. + +If screen size constraints prevent Nokia Maps Content or Places Content from being displayed with search or detail results, You shall display a notice informing the end user that the Nokia Maps Content or Places Content cannot be displayed. + +You also agree (i) to comply with these terms, applicable laws and good manners; (ii) not to distribute or post spam, unreasonably large files, chain letters, pyramid schemes, viruses or any other technologies that may harm the Service, or the interest or property of the Service users; (iii) not to use the Service in connection with any unlawful, offensive, abusive, pornographic, harassing, libelous or otherwise inappropriate Material and comply with Nokia Content Guidelines as may be provided by Nokia from time to time; and (iv) to respect the privacy of others. You agree to comply with Nokia Technical Guidelines and other guidelines as Nokia may provide from time to time. + +5. Nokia Maps Content and Publication + +Nokia Maps Content and Places Content are provided to You and Your end users for planning purposes only and Nokia does not guarantee the accuracy or availability of any Nokia Maps Content or Places Content. You may find that weather conditions, construction projects, closures or other events may cause road conditions, directions, positioning coordinates or other location information to differ from the results depicted in the Nokia Maps Content or Places Content. All use of Nokia Maps Content and/or Places Content is at Your own risk. + +6. Privacy and Ovi store publication + +You agree that Your use of the Services and Location API will comply with the Nokia Privacy Policy (http://www.nokia.com/privacy-policy). + +If your Application enables You or any party to gain access to information about users, including but not limited to personally identifiable information, non-personally identifiable usage information or location information (“Information”), You must provide users with notice about what Information is accessible and how such Information will be used or disclosed so that users may make informed decisions about whether or not to use Your Application. Furthermore, you must make Your privacy policy regarding the use of Information publicly available. + +If You intend to publish your Application on Nokia’s Ovi Store, please note that Your Application must comply with the Ovi Store Publication Requirements (https://publish.ovi.com/info/). + +7. Fees + +Your use of the Service may be or may become subject to charges. Nokia reserves the right to charge for the Service and to change its fees from time to time, at its discretion, but Nokia will provide You with sixty (60) days’ advance notice if charges will be implemented for use of the Service. + +8. Availability + +The Service may not be available in all countries and may be provided only in selected languages. The Service may be network dependent, contact Your network service provider for more information. + +9. Your Services + +You may interact with users, including consumers, on or through the Service. You agree that any such interactions by You do not involve Nokia and are solely between You and the other user(s). + +10. Links to Third Party Sites, Content and Advertising + +Nokia may include links to sites on the Internet that are owned or operated by third parties and that are not part of the Service. Upon following a link to such a third-party site, You shall review and agree to that site's rules of use before using such site. + +You agree that Nokia has no control over the content of third-party sites and cannot assume any responsibility for services provided or material created or published by such sites. A link to a third-party site does not imply that Nokia endorses the site or the products or services referenced in the site. + +In addition, users may create links within the Service to content that has not otherwise been submitted to the Service. You agree that Nokia is neither responsible nor liable for any such links. Moreover, Nokia Maps Content and Places Content made available to You by Nokia, may include content and data that originates from third parties. + +Nokia reserves the right, in its sole discretion, to implement advertising in the Location API For Developers. Unless otherwise agreed in writing between You and Nokia, and if Nokia implements advertising, You agree not to remove, otherwise alter, tamper with; or obsure such advertising. Nokia will provide You with sixty (60) days’ advance written notice prior to implementing advertising in the Location API For Developers. + +11. Reporting + +You agree to implement those reporting mechanisms specified by Nokia (if any). For example, if specified by Nokia, You agree to provide Nokia with reports if your Application which utilizes the Location API(s) detects its own location through the use of a sensor (including, but not limited to GPS, cell triangulation, WiFi or similar functionality) to display the location of the device on a map or to calculate a route. + +12. Additional Export Control Restrictions + +The Service and Location API Developer Package, including technical data, includes cryptographic software subject to export controls under the U.S. Export Administration Regulations ("EAR") and may be subject to import or export controls in other countries. The EAR prohibits the use of the Service and the Location API Developer Package and technical data by a Government End User, as defined hereafter, without a license from the U.S. government. A Government End User is defined in Part 772 of the EAR as "any foreign central, regional, or local government department, agency, or other entity performing governmental functions; including governmental research institutions, governmental corporations, or their separate business units (as defined in part 772 of the EAR) which are engaged in the manufacture or distribution of items or services controlled on the Wassenaar Munitions List, and international governmental organizations. This term does not include: utilities, telecommunications companies and Internet service providers; banks and financial institutions; transportation; broadcast or entertainment; educational organizations; civil health and medical organizations; retail or wholesale firms; and manufacturing or industrial entities not engaged in the manufacture or distribution of items or services controlled on the Wassenaar Munitions List. You agree to strictly comply with all applicable import and export regulations and acknowledge that You have the responsibility to obtain licenses to export, re-export, transfer, or import the Service and the Location API Developer Package. You further represent that You are not a Government End User as defined above, and You will not transfer the Service and the Location API Developer Package to any Government End User without a license. + diff --git a/src/plugins/geoservices/nokia/placesv2/jsonparserhelpers.cpp b/src/plugins/geoservices/nokia/placesv2/jsonparserhelpers.cpp index ed0c55af..1a18d15d 100644 --- a/src/plugins/geoservices/nokia/placesv2/jsonparserhelpers.cpp +++ b/src/plugins/geoservices/nokia/placesv2/jsonparserhelpers.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp b/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp index f96122db..4995358b 100644 --- a/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp @@ -49,7 +49,7 @@ #include "qgeocodereply_nokia.h" #include "qgeocodexmlparser.h" -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeocodexmlparser.cpp b/src/plugins/geoservices/nokia/qgeocodexmlparser.cpp index affd6e69..b9dbd934 100644 --- a/src/plugins/geoservices/nokia/qgeocodexmlparser.cpp +++ b/src/plugins/geoservices/nokia/qgeocodexmlparser.cpp @@ -52,9 +52,9 @@ #include #include -#include -#include -#include +#include +#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp b/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp index c5135436..cd8a4bad 100644 --- a/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp +++ b/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp @@ -54,7 +54,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp index 044359a2..5ea99027 100644 --- a/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp @@ -55,7 +55,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h index 175e829a..3ba30d90 100644 --- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h +++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h @@ -50,7 +50,7 @@ #define QGEOTILEDMAPPINGMANAGERENGINE_NOKIA_H #include "qgeotiledmappingmanagerengine_p.h" -#include +#include #include "qgeomaptype_p.h" #include diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp index a31d88c4..9c2a9b85 100644 --- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp +++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp @@ -70,7 +70,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp index dfb656dd..39b5339b 100644 --- a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp +++ b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp @@ -44,10 +44,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp b/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp index a97913d5..05bc97dd 100644 --- a/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp +++ b/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp @@ -48,10 +48,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 5d629f4d..457e8051 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -1,3 +1,3 @@ TEMPLATE = subdirs -SUBDIRS += position -qtHaveModule(3d): SUBDIRS += geoservices +qtHaveModule(positioning): SUBDIRS += position +qtHaveModule(3d):qtHaveModule(location) SUBDIRS += geoservices diff --git a/src/plugins/position/geoclue/geoclue.pro b/src/plugins/position/geoclue/geoclue.pro index b6a80c69..81e39d8a 100644 --- a/src/plugins/position/geoclue/geoclue.pro +++ b/src/plugins/position/geoclue/geoclue.pro @@ -1,5 +1,5 @@ TARGET = qtposition_geoclue -QT += location gui +QT = core positioning PLUGIN_TYPE = position load(qt_plugin) diff --git a/src/plugins/position/geoclue/qgeocluemaster.cpp b/src/plugins/position/geoclue/qgeocluemaster.cpp index e8444cef..a3eb9b14 100644 --- a/src/plugins/position/geoclue/qgeocluemaster.cpp +++ b/src/plugins/position/geoclue/qgeocluemaster.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Jolla Ltd, author: Aaron McCarthy ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/geoclue/qgeocluemaster.h b/src/plugins/position/geoclue/qgeocluemaster.h index 0ebedb33..f48ecb7e 100644 --- a/src/plugins/position/geoclue/qgeocluemaster.h +++ b/src/plugins/position/geoclue/qgeocluemaster.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Jolla Ltd, author: Aaron McCarthy ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp index 04f23c21..2279d832 100644 --- a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp +++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp @@ -5,7 +5,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h index 0adf004b..ff351b6a 100644 --- a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h +++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster_p.h @@ -5,7 +5,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.cpp b/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.cpp index 0395e5b6..e6219105 100644 --- a/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.cpp +++ b/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.cpp @@ -5,7 +5,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage @@ -43,7 +43,9 @@ #include "qgeopositioninfosourcefactory_geoclue.h" #include "qgeopositioninfosource_geocluemaster_p.h" +#ifdef HAS_SATELLITE #include "qgeosatelliteinfosource_geocluemaster.h" +#endif QGeoPositionInfoSource *QGeoPositionInfoSourceFactoryGeoclue::positionInfoSource(QObject *parent) { diff --git a/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.h b/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.h index 4eedaf81..0fa95d72 100644 --- a/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.h +++ b/src/plugins/position/geoclue/qgeopositioninfosourcefactory_geoclue.h @@ -5,7 +5,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp b/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp index 276b0278..3a78b174 100644 --- a/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp +++ b/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Jolla Ltd, author: Aaron McCarthy ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.h b/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.h index 60f4fe48..1448f827 100644 --- a/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.h +++ b/src/plugins/position/geoclue/qgeosatelliteinfosource_geocluemaster.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Jolla Ltd, author: Aaron McCarthy ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage @@ -48,7 +48,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/position/gypsy/gypsy.pro b/src/plugins/position/gypsy/gypsy.pro index 2255746e..f67d41e7 100644 --- a/src/plugins/position/gypsy/gypsy.pro +++ b/src/plugins/position/gypsy/gypsy.pro @@ -1,5 +1,5 @@ TARGET = qtposition_gypsy -QT += location gui +QT = core positioning PLUGIN_TYPE = position load(qt_plugin) diff --git a/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.cpp b/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.cpp index 77c8d1d7..dee265de 100644 --- a/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.cpp +++ b/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.h b/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.h index f44d47f7..6cd145ca 100644 --- a/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.h +++ b/src/plugins/position/gypsy/qgeopositioninfosourcefactory_gypsy.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy.cpp b/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy.cpp index 0a3d8c26..3a41047a 100644 --- a/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy.cpp +++ b/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy_p.h b/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy_p.h index 9d274cc0..edf6ec94 100644 --- a/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy_p.h +++ b/src/plugins/position/gypsy/qgeosatelliteinfosource_gypsy_p.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/positionpoll/positionpoll.pro b/src/plugins/position/positionpoll/positionpoll.pro index 8c871947..dd26f522 100644 --- a/src/plugins/position/positionpoll/positionpoll.pro +++ b/src/plugins/position/positionpoll/positionpoll.pro @@ -1,5 +1,5 @@ TARGET = qtposition_positionpoll -QT += location gui +QT += positioning PLUGIN_TYPE = position load(qt_plugin) diff --git a/src/plugins/position/positionpoll/positionpollfactory.cpp b/src/plugins/position/positionpoll/positionpollfactory.cpp index a35b6c1e..a3ec6527 100644 --- a/src/plugins/position/positionpoll/positionpollfactory.cpp +++ b/src/plugins/position/positionpoll/positionpollfactory.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/positionpoll/positionpollfactory.h b/src/plugins/position/positionpoll/positionpollfactory.h index 50658eb7..73a4d60a 100644 --- a/src/plugins/position/positionpoll/positionpollfactory.h +++ b/src/plugins/position/positionpoll/positionpollfactory.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/positionpoll/qgeoareamonitor_polling.cpp b/src/plugins/position/positionpoll/qgeoareamonitor_polling.cpp index 5fc4794b..784c9fad 100644 --- a/src/plugins/position/positionpoll/qgeoareamonitor_polling.cpp +++ b/src/plugins/position/positionpoll/qgeoareamonitor_polling.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/positionpoll/qgeoareamonitor_polling.h b/src/plugins/position/positionpoll/qgeoareamonitor_polling.h index d798c2bf..a94e4e40 100644 --- a/src/plugins/position/positionpoll/qgeoareamonitor_polling.h +++ b/src/plugins/position/positionpoll/qgeoareamonitor_polling.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp b/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp index 053a1fb0..359a9b16 100644 --- a/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp +++ b/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/qgeopositioninfosource_simulator_p.h b/src/plugins/position/simulator/qgeopositioninfosource_simulator_p.h index 7818176b..ffc91a7a 100644 --- a/src/plugins/position/simulator/qgeopositioninfosource_simulator_p.h +++ b/src/plugins/position/simulator/qgeopositioninfosource_simulator_p.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.cpp b/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.cpp index c8f11aae..efdb65b4 100644 --- a/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.cpp +++ b/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.h b/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.h index 262f9098..42dadf77 100644 --- a/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.h +++ b/src/plugins/position/simulator/qgeopositioninfosourcefactory_simulator.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/qgeosatelliteinfosource_simulator.cpp b/src/plugins/position/simulator/qgeosatelliteinfosource_simulator.cpp index 6a86bea7..1612e255 100644 --- a/src/plugins/position/simulator/qgeosatelliteinfosource_simulator.cpp +++ b/src/plugins/position/simulator/qgeosatelliteinfosource_simulator.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/qgeosatelliteinfosource_simulator_p.h b/src/plugins/position/simulator/qgeosatelliteinfosource_simulator_p.h index 58e414e9..5d97c7eb 100644 --- a/src/plugins/position/simulator/qgeosatelliteinfosource_simulator_p.h +++ b/src/plugins/position/simulator/qgeosatelliteinfosource_simulator_p.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/qlocationconnection_simulator.cpp b/src/plugins/position/simulator/qlocationconnection_simulator.cpp index 7906dd7c..b78eb1cf 100644 --- a/src/plugins/position/simulator/qlocationconnection_simulator.cpp +++ b/src/plugins/position/simulator/qlocationconnection_simulator.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/qlocationconnection_simulator_p.h b/src/plugins/position/simulator/qlocationconnection_simulator_p.h index 6cbc18dd..402d7113 100644 --- a/src/plugins/position/simulator/qlocationconnection_simulator_p.h +++ b/src/plugins/position/simulator/qlocationconnection_simulator_p.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/qlocationdata_simulator.cpp b/src/plugins/position/simulator/qlocationdata_simulator.cpp index cf9c65eb..24fe0446 100644 --- a/src/plugins/position/simulator/qlocationdata_simulator.cpp +++ b/src/plugins/position/simulator/qlocationdata_simulator.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/qlocationdata_simulator_p.h b/src/plugins/position/simulator/qlocationdata_simulator_p.h index 8ac7dcd7..d148e2b4 100644 --- a/src/plugins/position/simulator/qlocationdata_simulator_p.h +++ b/src/plugins/position/simulator/qlocationdata_simulator_p.h @@ -3,7 +3,7 @@ ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** -** This file is part of the QtLocation module of the Qt Toolkit. +** This file is part of the QtPositioning module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage diff --git a/src/plugins/position/simulator/simulator.pro b/src/plugins/position/simulator/simulator.pro index 944907f7..e1105f17 100644 --- a/src/plugins/position/simulator/simulator.pro +++ b/src/plugins/position/simulator/simulator.pro @@ -1,5 +1,5 @@ TARGET = qtposition_simulator -QT += location gui +QT += positioning gui PLUGIN_TYPE = position load(qt_plugin) diff --git a/src/positioning/doc/images/example-weatherinfo.png b/src/positioning/doc/images/example-weatherinfo.png new file mode 100644 index 00000000..6557b57b Binary files /dev/null and b/src/positioning/doc/images/example-weatherinfo.png differ diff --git a/src/positioning/doc/images/qml-flickr-1.jpg b/src/positioning/doc/images/qml-flickr-1.jpg new file mode 100644 index 00000000..14fc5c92 Binary files /dev/null and b/src/positioning/doc/images/qml-flickr-1.jpg differ diff --git a/src/positioning/doc/qtpositioning.qdocconf b/src/positioning/doc/qtpositioning.qdocconf new file mode 100644 index 00000000..182cb7a8 --- /dev/null +++ b/src/positioning/doc/qtpositioning.qdocconf @@ -0,0 +1,56 @@ +include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) + +project = QtPositioning +description = Qt Positioning Reference Documentation +url = http://qt-project.org/doc/qt-$QT_VER/qtpositioning +version = $QT_VERSION + + + +qhp.projects = QtPositioning + +qhp.QtPositioning.file = qtpositioning.qhp +qhp.QtPositioning.namespace = org.qt-project.qtpositioning.$QT_VERSION_TAG +qhp.QtPositioning.virtualFolder = qtpositioning +qhp.QtPositioning.indexTitle = Qt Positioning +qhp.QtPositioning.indexRoot = + +qhp.QtPositioning.filterAttributes = qtpositioning $QT_VERSION qtrefdoc +qhp.QtPositioning.customFilters.Qt.name = QtPositioning $QT_VERSION +qhp.QtPositioning.customFilters.Qt.filterAttributes = qtpositioning $QT_VERSION +qhp.QtPositioning.subprojects = overviews classes qml examples +qhp.QtPositioning.subprojects.classes.title = C++ Classes +qhp.QtPositioning.subprojects.classes.indexTitle = Qt Positioning C++ Classes +qhp.QtPositioning.subprojects.classes.selectors = class fake:headerfile +qhp.QtPositioning.subprojects.classes.sortPages = true +qhp.QtPositioning.subprojects.qml.title = QML Types +qhp.QtPositioning.subprojects.qml.indexTitle = Qt Positioning QML Types +qhp.QtPositioning.subprojects.qml.selectors = fake:headerfile +qhp.QtPositioning.subprojects.qml.sortPages = true +qhp.QtPositioning.subprojects.overviews.title = Overviews +qhp.QtPositioning.subprojects.overviews.indexTitle = Qt Positioning Overview +qhp.QtPositioning.subprojects.overviews.selectors = fake:page,group,module +qhp.QtPositioning.subprojects.examples.title = Qt Positioning Examples +qhp.QtPositioning.subprojects.examples.indexTitle = Qt Positioning Examples +qhp.QtPositioning.subprojects.examples.selectors = fake:example + +tagfile = ../../../doc/qtpositioning/qtpositioning.tags + +depends += qtcore qtdoc qtquick qtqml qtnetwork + +headerdirs += .. \ + ../../imports/positioning + +sourcedirs += .. \ + ../../imports/positioning + +exampledirs += ../../../examples \ + ../../../examples/declarative \ + snippets/ + + +imagedirs += images + +navigation.landingpage = "Qt Positioning" +navigation.cppclassespage = "Qt Positioning C++ Classes" +navigation.qmltypespage = "Qt Positioning QML Types" diff --git a/src/positioning/doc/snippets/cpp/cpp.pro b/src/positioning/doc/snippets/cpp/cpp.pro new file mode 100644 index 00000000..47401e90 --- /dev/null +++ b/src/positioning/doc/snippets/cpp/cpp.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +TARGET = positioning_cppsnippet +QT = core positioning + +SOURCES += \ + main.cpp \ + cppqml.cpp + diff --git a/src/positioning/doc/snippets/cpp/cppqml.cpp b/src/positioning/doc/snippets/cpp/cppqml.cpp new file mode 100644 index 00000000..5ab23513 --- /dev/null +++ b/src/positioning/doc/snippets/cpp/cppqml.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +void cppQmlInterface(QObject *qmlObject) +{ + //! [Address get] + QGeoAddress geoAddress = qmlObject->property("address").value(); + //! [Address get] + + //! [Address set] + qmlObject->setProperty("address", QVariant::fromValue(geoAddress)); + //! [Address set] + + //! [Location get] + QGeoLocation geoLocation = qmlObject->property("location").value(); + //! [Location get] + + //! [Location set] + qmlObject->setProperty("location", QVariant::fromValue(geoLocation)); + //! [Location set] +} + diff --git a/src/positioning/doc/snippets/cpp/main.cpp b/src/positioning/doc/snippets/cpp/main.cpp new file mode 100644 index 00000000..bc78207f --- /dev/null +++ b/src/positioning/doc/snippets/cpp/main.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +int main(int /*argc*/, char ** /*argv*/) +{ + return 0; +} + diff --git a/src/positioning/doc/snippets/doc_src_qtpositioning.qml b/src/positioning/doc/snippets/doc_src_qtpositioning.qml new file mode 100644 index 00000000..cc9547b7 --- /dev/null +++ b/src/positioning/doc/snippets/doc_src_qtpositioning.qml @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [import] +import QtPositioning 5.0 +//! [import] + +Item { +} + diff --git a/src/positioning/doc/src/cpp-position.qdoc b/src/positioning/doc/src/cpp-position.qdoc new file mode 100644 index 00000000..75c2e30e --- /dev/null +++ b/src/positioning/doc/src/cpp-position.qdoc @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\page location-positioning-cpp.html + +\title Positioning (C++) + +\brief The Location Positioning API enables location positioning by means of +GPS or an NMEA data source. + +\section1 Positioning + +The Positioning component of the Qt Location API is about the geographical position, size +and address of some place. Positioning contains a QGeoCoordinate class, containing latitude, longitude and altitude in meters. QGeoLocation contains a QGeoCoordinate plus address +and size information (a bounding box) so that positions can be more than mathematical points. +Movement into or out of the defined bounding box areas can be monitored. The API +also allows the developer to control the source of the positional information +as well. + +Location data involves a precisely specified position on the Earth's +surface \unicode {0x2014} as provided by a latitude-longitude coordinate +\unicode {0x2014} along with associated data, such as: + + \list + \li The date and time at which the position was reported + \li The velocity of the device that reported the position + \li The altitude of the reported position (height above sea level) + \li The bearing of the device in degrees, relative to true north + \endlist + +This data can be extracted through a variety of methods. One of the most +well known methods of positioning is GPS (Global Positioning System), a +publicly available system that uses radiowave signals received from +Earth-orbiting satellites to calculate the precise position and time of +the receiver. Another popular method is 'Cell Identifier Positioning', which uses +the cell identifier of the cell site that is currently serving the receiving +device to calculate its approximate location. These and other positioning +methods can all be used with the Location API; the only requirement for a +location data source within the API is that it provides a +latitude-longitude coordinate with a date/time value, with the option of +providing the other attributes listed above. + + +Location data sources are created by subclassing QGeoPositionInfoSource and +providing QGeoPositionInfo objects through the +QGeoPositionInfoSource::positionUpdated() signal. Clients that require +location data can connect to the +\l{QGeoPositionInfoSource::positionUpdated()}{positionUpdated()} signal and +call \l{QGeoPositionInfoSource::startUpdates()}{startUpdates()} or +\l{QGeoPositionInfoSource::requestUpdate()}{requestUpdate()} to trigger the +distribution of location data. The location data distribution can be stopped by +calling the \l {QGeoPositionInfoSource::stopUpdates()}{stopUpdates()} function. + +A default position source may be available on some platforms. Call +QGeoPositionInfoSource::createDefaultSource() to create an instance of the default +position source; the method returns 0 if no default source is available for +the platform. + +If a problem occurs with access to the information source then an +\l {QGeoPositionInfoSource::error()}{error()} signal is emitted. + +The QGeoAreaMonitor class enables client applications to be notified when +the receiving device has moved in or out of a particular area, as specified +by a coordinate and radius. If the platform provides built-in support for +area monitoring, QGeoAreaMonitor::createDefaultMonitor() returns an instance of +the default area monitor. + +Satellite information can also be distributed through the +QGeoSatelliteInfoSource class. Call QGeoSatelliteInfoSource::createDefaultSource() to +create an instance of the default satellite data source for the platform, +if one is available. Alternatively, clients can subclass it to provide a +custom satellite data source. + + + +\section2 Requesting Location Data from Data Sources + +To receive data from a source, connect to its +\l{QGeoPositionInfoSource::positionUpdated()}{positionUpdated()} signal, +then call either \l{QGeoPositionInfoSource::startUpdates()}{startUpdates()} +or \l{QGeoPositionInfoSource::requestUpdate()}{requestUpdate()} to begin. + +Here is an example of a client that receives data from the default location +data source, as returned by QGeoPositionInfoSource::createDefaultSource(): + +\code +class MyClass : public QObject +{ + Q_OBJECT +public: + MyClass(QObject *parent = 0) + : QObject(parent) + { + QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this); + if (source) { + connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)), + this, SLOT(positionUpdated(QGeoPositionInfo))); + source->startUpdates(); + } + } + +private slots: + void positionUpdated(const QGeoPositionInfo &info) + { + qDebug() << "Position updated:" << info; + } +}; + +\endcode + +\section2 Controlling Aspects of Data Sources + +The QGeoPositionInfoSource::setUpdateInterval() method can be used to +control the rate at which position updates are received. For example, if +the client application only requires updates once every 30 seconds, it can +call \c setUpdateInterval(30000). (If no update interval is set, or +\l {QGeoPositionInfoSource::}{setUpdateInterval()} is called with a value of 0, the source uses a default +interval or some other internal logic to determine when updates should be +provided.) + +QGeoPositionInfoSource::setPreferredPositioningMethods() enables client +applications to request that a certain type of positioning method be used. +For example, if the application prefers to use only satellite positioning, +which offers fairly precise outdoor positioning but can be a heavy user of +power resources, it can call this method with the +QGeoPositionInfoSource::SatellitePositioningMethods value. However, this +method should only be used in specialized client applications; in most +cases, the default positioning methods should not be changed, as a source +may internally use a variety of positioning methods that can be useful to +the application. + +\section2 NMEA Data + +\l {http://en.wikipedia.org/wiki/NMEA_0183}{NMEA} is a common text-based +protocol for specifying navigational data. For convenience, the +QNmeaPositionInfoSource is provided to enable client applications to read +and distribute NMEA data in either real-time mode (for example, when +streaming from a GPS device) or simulation mode (for example, when reading +from a NMEA log file). In simulation mode, the source will emit updates +according to the time stamp of each NMEA sentence to produce a "replay" +of the recorded data. + +Generally, the capabilities provided by the default position source as +returned by QGeoPositionInfoSource::createDefaultSource(), along with the +QNmeaPositionInfoSource class, are sufficient for retrieving location +data. However, in some cases developers may wish to write their own custom +location data source. + +The \l {Log File Position Source (C++)} example demonstrates how to subclass QGeoPositionInfoSource +to create a custom positioning source. + + +\section1 Examples + +\section3 \b{Flickr Example} + +The \l{Flickr QML}{Flickr Example} uses the Location to download thumbnail +images from Flickr relevant to the current location. + + + +\section1 Positioning Classes + +\annotatedlist QtPositioning-positioning + +*/ diff --git a/src/positioning/doc/src/cpp-qml-positioning.qdoc b/src/positioning/doc/src/cpp-qml-positioning.qdoc new file mode 100644 index 00000000..4ccd8510 --- /dev/null +++ b/src/positioning/doc/src/cpp-qml-positioning.qdoc @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\page positioning-cpp-qml.html +\title Interfaces between C++ and QML Code in Qt Positioning + +\brief Some of the providing QtPositioning QML types providing interfaces to access and modify properties in C++. + +\section2 Address - QGeoAddress +\target geoaddress +The \l {QtPositioning5::Address::address} {Address.address} property is used to provide an interface between C++ and QML code. First a pointer to a +Address object must be obtained from C++, then use the \l {QObject::property()}{property()} and +\l {QObject::setProperty()}{setProperty()} functions to get and set the \c address property. +The following gets the QGeoAddress representing this object from C++: +\snippet cpp/cppqml.cpp Address get +The following sets the properties of this object based on a QGeoAddress object from C++: +\snippet cpp/cppqml.cpp Address set + + +\section2 Location - QGeoLocation +\target location +The \l {Location::location} {Location.location} property is used to provide an interface between C++ and QML code. First a pointer to a +Location object must be obtained from C++, then use the \l {QObject::property()}{property()} and +\l {QObject::setProperty()}{setProperty()} functions to get and set the \c location property. +The following gets the QGeoLocation representing this object from C++: +\snippet cpp/cppqml.cpp Location get +The following sets the properties of this object based on a QGeoLocation object from C++: +\snippet cpp/cppqml.cpp Location set + +*/ diff --git a/src/positioning/doc/src/examples/declarative-flickr.qdoc b/src/positioning/doc/src/examples/declarative-flickr.qdoc new file mode 100644 index 00000000..c68797b0 --- /dev/null +++ b/src/positioning/doc/src/examples/declarative-flickr.qdoc @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example declarative/flickr + \title Flickr (QML) + \ingroup qtpositioning-examples + + \brief The Flickr example shows how to use the user's current position to + fetch local content from a web service. + + This is a small example, illustrating one of the very core parts of the + Qt Positioning API: the ability to retrieve and use the user's current + geographic position. + + Key QML types shown in this example: + \list + \li \l{QtPositioning5::PositionSource}{PositionSource} + \li \l{XmlListModel}{XmlListModel} + \endlist + + \image qml-flickr-1.jpg + + \section2 Retrieving the Current Position + + Retrieving the user's current position is achieved using the PositionSource + type. In this example, we instantiate the PositionSource as part of the + GeoTab component (the floating "window" describing current position and + status). + + \snippet flickr/flickrmobile/GeoTab.qml possrc + + When the "Locate and update" button is pressed, we first interrogate the + PositionSource to check if it has an available backend for positioning + data. If it does not, we fall back to using a pre-recorded NMEA log + for demonstration. We then instruct the PositionSource to update. + + \snippet flickr/flickrmobile/GeoTab.qml locatebutton-top + \snippet flickr/flickrmobile/GeoTab.qml locatebutton-clicked + + To share the new position data with the rest of the application, we use + properties that we have created on the GeoTab component: + + \snippet flickr/flickrmobile/GeoTab.qml props + + \section2 Using the Current Position + + The longitude and latitude values retrieved here are eventually set on + in properties on the RestModel component. The RestModel is an XmlListModel, + which retrieves XML data from a URL and creates a data model by performing + XPath queries on it. + + In this case, it retrieves data from the Flickr REST API online, based on + our current position + + \snippet flickr/flickrcommon/RestModel.qml restmodel + + This model data is then shown in a variety of Qt Quick views to produce + the example application. + +*/ diff --git a/src/positioning/doc/src/examples/logfilepositionsource.qdoc b/src/positioning/doc/src/examples/logfilepositionsource.qdoc new file mode 100644 index 00000000..f69c1dd1 --- /dev/null +++ b/src/positioning/doc/src/examples/logfilepositionsource.qdoc @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\example logfilepositionsource +\title Log File Position Source (C++) +\ingroup qtpositioning-examples + +\brief The Logfile Position Source shows how to create and work with a custom NMEA position source, + for platforms without GPS. + +The data is read from a file which has positional data in NMEA format. The resulting time and +position information is then displayed to the screen as simple text in date/time and +latitude/longitude format. + +This example class reads position data from a text file, \e log.txt. The file specifies position +data using a simple text format: it contains one position update per line, where each line contains +a date/time, a latitude and a longitude, separated by spaces. The date/time is in ISO 8601 format +and the latitude and longitude are in degrees decimal format. Here is an excerpt from \e log.txt: + +\code +2009-08-24T22:25:01 -27.576082 153.092415 +2009-08-24T22:25:02 -27.576223 153.092530 +2009-08-24T22:25:03 -27.576364 153.092648 +\endcode + +The class reads this data and distributes it via the +\l{QGeoPositionInfoSource::positionUpdated()}{positionUpdated()} signal. + +Here is the definition of the \c LogFilePositionSource class: + +\quotefromfile logfilepositionsource/logfilepositionsource.h +\skipto class LogFilePositionSource +\printuntil }; + +The main methods overrided by the subclass are: + +\list + \li \l{QGeoPositionInfoSource::startUpdates()}{startUpdates()}: called by client applications + to start regular position updates. + \li \l{QGeoPositionInfoSource::stopUpdates()}{stopUpdates()}: called by client applications to + stop regular position updates. + \li \l{QGeoPositionInfoSource::requestUpdate()}{requestUpdate()}: called by client applications + to request a single update, with a specified timeout. +\endlist + +When a position update is available, the subclass emits the +\l{QGeoPositionInfoSource::positionUpdated()}{positionUpdated()} signal. + +Here are the key methods in the class implementation: + +\quotefromfile logfilepositionsource/logfilepositionsource.cpp +\skipto LogFilePositionSource::LogFilePositionSource +\printuntil /^\}/ +\skipto LogFilePositionSource::startUpdates +\printuntil /^\}/ +\skipto LogFilePositionSource::stopUpdates +\printuntil /^\}/ +\skipto LogFilePositionSource::requestUpdate +\printuntil /^\}/ +\printuntil LogFilePositionSource::readNextPosition +\printuntil /^\}/ +*/ diff --git a/src/positioning/doc/src/examples/qtpositioning-examples.qdoc b/src/positioning/doc/src/examples/qtpositioning-examples.qdoc new file mode 100644 index 00000000..ac1d79ec --- /dev/null +++ b/src/positioning/doc/src/examples/qtpositioning-examples.qdoc @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \group qtpositioning-examples + \title Qt Positioning Examples + \brief Examples for the Qt Positioning module + \ingroup all-examples + \ingroup qtpositioning + + These are the Qt Positioning examples. + +*/ + diff --git a/src/positioning/doc/src/examples/weatherinfo.qdoc b/src/positioning/doc/src/examples/weatherinfo.qdoc new file mode 100644 index 00000000..0c98cc04 --- /dev/null +++ b/src/positioning/doc/src/examples/weatherinfo.qdoc @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example weatherinfo + \title Weather Info (C++/QML) + + \brief The Weather Info example shows how to use the user's current position + to retrieve local content from a web service in a C++ plugin for QML. + + \ingroup qtpositioning-examples + + Key Qt Positioning classes used in this example: + + \list + \li \l{QGeoPositionInfo} + \li \l{QGeoPositionInfoSource} + \endlist + + \image ../images/example-weatherinfo.png + + The key part of this example is the application's data model, contained + in the WeatherData and AppModel classes. WeatherData represents the weather + information taken from the HTTP service. It is a simple data class, but we + give it Q_PROPERTies to expose it nicely to QML, later. + + \snippet weatherinfo/appmodel.h 0 + \snippet weatherinfo/appmodel.h 1 + + AppModel models the state of the entire application. At startup, the + application first begins by waiting for network connectivity. We do + this using the QNetworkConfigurationManager and QNetworkSession family + of C++ APIs. + + \snippet weatherinfo/appmodel.cpp 0 + \snippet weatherinfo/appmodel.cpp 1 + + Once the network session is open, we proceed to get the platform's + default position source using QGeoPositionInfo::createDefaultSource() + + \snippet weatherinfo/appmodel.cpp 2 + + If no default source is available, we take a static position and fetch + weather for that. If, however, we do have a position source, we connect + its positionUpdated() signal to a slot on the AppModel and call + startUpdates(), which begins regular updates of device position. + + When a position update is received, we use the longitude and latitude + of the returned coordinate to retrieve the current "city" name for use + in the weather lookup. + + \snippet weatherinfo/appmodel.cpp 3 + + To inform the UI about this process, the cityChanged() signal is emitted + when a new city is used, and the weatherChanged() signal whenever a + weather update occurs. + + \snippet weatherinfo/appmodel.h 2 + \snippet weatherinfo/appmodel.h 3 + \snippet weatherinfo/appmodel.h 4 + + We use a QQmlListProperty for the weather forecast information, + which contains the next 4 days of forecast weather. This makes it + easy to access from QML. + + To expose these to the QML UI layer, we use the qmlRegisterType() + function. We call this once for each type we wish to register, before + loading the actual QML file. + + \snippet weatherinfo/main.cpp 0 + \snippet weatherinfo/main.cpp 1 + + Finally, in the actual QML, we instantiate the AppModel. + + \snippet weatherinfo/weatherinfo.qml 0 + \snippet weatherinfo/weatherinfo.qml 1 + \snippet weatherinfo/weatherinfo.qml 2 + + Once instantiated like this, we can use its properties elsewhere in the + QML document: + + \snippet weatherinfo/weatherinfo.qml 3 + \snippet weatherinfo/weatherinfo.qml 4 + +*/ diff --git a/src/positioning/doc/src/qml-position.qdoc b/src/positioning/doc/src/qml-position.qdoc new file mode 100644 index 00000000..850bdd35 --- /dev/null +++ b/src/positioning/doc/src/qml-position.qdoc @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\page location-positioning-qml.html + +\title Positioning (QML) + +\brief The Location Positioning API enables location positioning by means of +GPS or an NMEA data source. + +\section1 Location Positioning + +Location data involves a precisely specified position on the Earth's +surface \unicode {0x2014} as provided by a latitude-longitude coordinate +\unicode {0x2014} along with associated data, such as: + + \list + \li The date and time at which the position was reported + \li The velocity of the device that reported the position + \li The altitude of the reported position (height above sea level) + \li The bearing of the device in degrees, relative to true north + \endlist + +For more information see +\l {http://en.wikipedia.org/wiki/Geographic_coordinate}{Geographic Coordinate}. + +This data can be extracted through a variety of methods. One of the most +well known methods of positioning is GPS (Global Positioning System), a +publicly available system that uses radiowave signals received from +Earth-orbiting satellites to calculate the precise position and time of +the receiver. Another popular method is 'Cell Identifier Positioning', which uses +the cell identifier of the cell site that is currently serving the receiving +device to calculate its approximate location. These and other positioning +methods can all be used with the Location API; the only requirement for a +location data source within the API is that it provides a +latitude-longitude coordinate with a date/time value, with the option of +providing the other attributes listed above. + +\section2 Coordinate + +The \l {coordinate} is a basic unit of geographical information. The +\l {coordinate} type has attributes to hold the \c {latitude}, +\c longitude and \c altitude. + +\section2 Position + +The three dimensional position of an object such as a mobile device can be specified by giving +the latitude, longitude and altitude. That is the values held in the +l\ {coordinate} type. Additionally for computation of future +positions we would like to know if the object is moving, what \l {Position::speed}{speed} it is +doing and what is the \l {Position::timestamp}{timestamp} of the last position data. Position +therefore includes values for the \l {Position::coordinate}{coordinate}, +\l {Position::speed}{speed} and a \l {Position::timestamp}{timestamp}. \l Position also takes +responsibility for validation of sensible values for these properties. These are exposed as +the \l {Position::latitudeValid}{latitudeValid}, \l {Position::longitudeValid}{longitudeValid}, +\l {Position::altitudeValid}{altitudeValid}, \l {Position::speedValid}{speedValid}, +\l {Position::horizontalAccuracyValid}{horizontalAccuracyValid}, and +\l {Position::verticalAccuracyValid}{verticalAccuracyValid} properties. + + +\section2 PositionSource + +We have a Position type, a \l {coordinate} type but where does the data come from? +Also it is a good idea to be able to indicate alternative sources. +Perhaps instead of directly picking up GPS satellites it might be desirable to do +some testing using a datafile. + +The \l PositionSource type provides the developer with control, +within the limits allowed by the platform, of the source of the +geographical data. Apart from tradtional sources such as GPS and cell data the positional data can be +sourced from a logfile which is in NMEA format. + +\l {http://en.wikipedia.org/wiki/NMEA}{NMEA} is a common text-based protocol for specifying navigational data. For convenience, the \l {PositionSource::nmeaSource}{nmeaSource} property is provided to enable QML applications to read NMEA data from a log file, the source will emit updates according to the time stamp of each NMEA sentence to produce a "replay" of the recorded data. + + + +\section2 \b{Flickr Example} + +The \l{Flickr (QML)}{Flickr Example} uses the Location to download thumbnail +images from Flickr relevant to the current location. + +*/ diff --git a/src/positioning/doc/src/qtpositioning-plugins.qdoc b/src/positioning/doc/src/qtpositioning-plugins.qdoc new file mode 100644 index 00000000..1ed1be1a --- /dev/null +++ b/src/positioning/doc/src/qtpositioning-plugins.qdoc @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\page qtpositioning-plugins.html +\title Qt Positioning service plugins +\brief Implementing Qt Positioning plugins + +Qt Positioning provides the majority of its functionality through plugins. This +document outlines how to develop a new position plugin. + +\section1 Plugin description + +Each plugin is described by a json file. The json describes the plugins capabilities and +version. Below is an example of a json file used by the postionpoll plugin: + +\quotefile ../../../plugins/position/positionpoll/plugin.json + +The entries have the following meaning: + +\table + \header + \li Key + \li Description + \row + \li Keys + \li The unique name/key of the plugin. Each position plugin must have a unique name. + \row + \li Provider + \li The provider name of the services. Multiple plugins may have the same name. + In such cases the Version string will be used to further distinguish the plugins. + \row + \li Position + \li Set to \c true if the plugin implements a \l QGeoPositionInfoSource. + \row + \li Satellite + \li Set to \c true if the plugin implements a \l QGeoSatelliteInfoSource. + \row + \li Monitor + \li Set to \c true if the plugin implements a \l QGeoAreaMonitor. + \row + \li Priority + \li The plugin priority. If multiple plugins have the same provider name, the plugin + with the higest priority will be used. +\endtable + +\section1 Implementing Plugins + +A plugin implementer needs to subclass \l QGeoPositionInfoSourceFactory and override one or more of +its functions. If a plugin does not support a specific feature the function should return 0 or +utilize the default implementation. + +\list + \li \l QGeoPositionInfoSourceFactory::areaMonitor() + \li \l QGeoPositionInfoSourceFactory::positionInfoSource() + \li \l QGeoPositionInfoSourceFactory::satelliteInfoSource() +\endlist +*/ diff --git a/src/positioning/doc/src/qtpositioning-qml.qdoc b/src/positioning/doc/src/qtpositioning-qml.qdoc new file mode 100644 index 00000000..ba35cb89 --- /dev/null +++ b/src/positioning/doc/src/qtpositioning-qml.qdoc @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmlmodule QtPositioning 5.0 + \title Qt Positioning QML Types + \ingroup qmlmodules + \brief Provides QML types for position information + +\section1 Overview + +The identifying string for this module is \e QtPositioning. To use include the following import +statement in the QML file. + +\snippet doc_src_qtpositioning.qml import + +\section2 Positioning QML Concepts + +Position information can come from a variety of sources including satellites, +wifi, text files and so on. The position is described by the latitude, +the longitude, and the altitude in meters. For more information see +\l {http://en.wikipedia.org/wiki/Geographic_coordinate}{Geographic Coordinate}. + +The QML position is stored in a \l {coordinate} which contains the +latitude, longitude and altitude of the device. The \l {QtPositioning5::Location}{Location} contains +this \l {coordinate} and adds an address, it also has a bounding box which +defines the recommended viewing region when displaying the location. + +Now that the device has a position, with regular updates the API can determine +the speed and heading of the device. It can also define a box or a circle that can +produce a notification when the device either leaves or enters that region. + +More detailed information retrieving the current position can be found under +{Positioning (QML)}{Location Positioning via QML} + +\section1 Basic Types + +\annotatedlist qml-QtPositioning5-basictypes + +\section1 Alphabetical Listing of all QML Types +*/ diff --git a/src/positioning/doc/src/qtpositioning.qdoc b/src/positioning/doc/src/qtpositioning.qdoc new file mode 100644 index 00000000..95b3fecc --- /dev/null +++ b/src/positioning/doc/src/qtpositioning.qdoc @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + + + + +/*! + \module QtPositioning + \title Qt Positioning C++ Classes + \ingroup modules + \qtvariable location + + \brief The Positioning module provides positioning information via QML and C++ interfaces. + + To load the Qt Positioning module, add the following statement to your .qml files + + \code + import QtPositioning 5.0 + \endcode + + For C++ projects include the header appropriate for the current use case, + for example applications using routes may use + + \code #include \endcode + + The .pro file should have the \e positioning keyword added + + \code QT += positioning \endcode + + + See more in the \l{Qt Positioning}{Qt Positioning Overview}. + +*/ + + + +/*! +\page qtpositioning-index.html +\title Qt Positioning +\brief The Qt Positioning API provides positioning information via QML and C++ interfaces. +\ingroup technology-apis + +The Qt Positioning API provides positioning information via QML and C++ interfaces. + +\section1 Overview + +The Qt Positioning API gives developers the ability to determine a position by +using a variety of possible sources, including satellite, or wifi, or text file, +and so on. That information can then be used to for example determine a position +on a map. In addition satellite information can be retrieved and area based monitoring +can be performed. + +\section1 Getting Started + +To load the Qt Positioning module, add the following statement to your .qml files + +\code + import QtPositioning 5.0 +\endcode + +For C++ projects include the header appropriate for the current use case, +for example applications using routes may use + +\code #include \endcode + +The .pro file should have the \e positioning keyword added + +\code QT += positioning \endcode + +\section1 Related information +\section2 Overview + +Positioning includes all the functionality necessary to find and work with geographic +coordinates. It can use a variety of external sources of information, including GPS. This +provides us with a coordinate and altitude for the device with additional features +such as speed and direction. This provides the fundamental location information used in the API. + +\section2 References +\table +\row + \li Positioning introduction: + \li \l{Positioning (QML)}{for QML} + \li \l{Positioning (C++)}{for C++} +\row + \li API references: + \li \l {Qt Positioning QML Types}{for QML} + \li \l {Qt Positioning C++ Classes}{for C++} +\row + \li Position plugins: + \li \l {Qt Positioning service plugins} +\endtable + +\section2 Examples + +\list + \li \l {Flickr (QML)} + \li \l {Log File Position Source (C++)} + \li \l {Weather Info (C++/QML)} +\endlist +*/ diff --git a/src/positioning/positioning.pro b/src/positioning/positioning.pro new file mode 100644 index 00000000..da1186bf --- /dev/null +++ b/src/positioning/positioning.pro @@ -0,0 +1,58 @@ +TARGET = QtPositioning +QT = core-private +QT += qml # the dependecy should be removed, see QTBUG-22330 + + +QMAKE_DOCS = $$PWD/doc/qtpositioning.qdocconf +OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator + +PUBLIC_HEADERS += \ + qgeoaddress.h \ + qgeoareamonitor.h \ + qgeoshape.h \ + qgeorectangle.h \ + qgeocircle.h \ + qgeocoordinate.h \ + qgeolocation.h \ + qgeopositioninfo.h \ + qgeopositioninfosource.h \ + qgeosatelliteinfo.h \ + qgeosatelliteinfosource.h \ + qnmeapositioninfosource.h \ + qgeopositioninfosourcefactory.h \ + qpositioningglobal.h + +PRIVATE_HEADERS += \ + qgeoaddress_p.h \ + qgeoshape_p.h \ + qgeorectangle_p.h \ + qgeocircle_p.h \ + qgeolocation_p.h \ + qlocationutils_p.h \ + qnmeapositioninfosource_p.h \ + qgeocoordinate_p.h \ + qgeopositioninfosource_p.h \ + qdeclarativegeoaddress_p.h \ + qdeclarativegeolocation_p.h + +SOURCES += \ + qgeoaddress.cpp \ + qgeoareamonitor.cpp \ + qgeoshape.cpp \ + qgeorectangle.cpp \ + qgeocircle.cpp \ + qgeocoordinate.cpp \ + qgeolocation.cpp \ + qgeopositioninfo.cpp \ + qgeopositioninfosource.cpp \ + qgeosatelliteinfo.cpp \ + qgeosatelliteinfosource.cpp \ + qlocationutils.cpp \ + qnmeapositioninfosource.cpp \ + qgeopositioninfosourcefactory.cpp \ + qdeclarativegeoaddress.cpp \ + qdeclarativegeolocation.cpp + +HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS + +load(qt_module) diff --git a/src/positioning/qdeclarativegeoaddress.cpp b/src/positioning/qdeclarativegeoaddress.cpp new file mode 100644 index 00000000..d061db10 --- /dev/null +++ b/src/positioning/qdeclarativegeoaddress.cpp @@ -0,0 +1,358 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativegeoaddress_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Address + \instantiates QDeclarativeGeoAddress + \inqmlmodule QtPositioning 5.0 + \since Qt Positioning 5.0 + + \brief The Address QML type represents a specific location as a street address. + + An Address is used as a unit of data for queries such as (Reverse) Geocoding + or Places searches -- many of these operations either accept an Address + or return one. + + Not all properties of an Address are necessarily available or relevant + in all parts of the world and all locales. The \l district, \l state and + \l county properties are particularly area-specific for many data sources + (including the provided Nokia plugin), and often only one or two of these + is available or useful. + + The Address has a \l text property which holds a formatted string. It + is the recommended way to display an address to the user and typically + takes the format of an address as found on an envelope, but this is not always + the case. The \l text may be automatically generated from constituent + address properties such as \l street, \l city and and so on, but can also + be explicitly assigned. See \l text for details. + + \section2 Example Usage + + The following code snippet shows the declaration of an Address object. + + \code + Address { + id: address + street: "53 Brandl St" + city: "Eight Mile Plains" + country: "Australia" + countryCode: "AUS" + } + \endcode + + This could then be used, for example, as the value of a geocoding query, + to get an exact longitude and latitude for the address. + + \sa {QGeoAddress} +*/ + +QDeclarativeGeoAddress::QDeclarativeGeoAddress(QObject *parent) : + QObject(parent) +{ +} + +QDeclarativeGeoAddress::QDeclarativeGeoAddress(const QGeoAddress &address, QObject *parent) : + QObject(parent), m_address(address) +{ +} + +/*! + \qmlproperty QGeoAddress QtPositioning5::Address::address + + For details on how to use this property to interface between C++ and QML see + "\l {positioning-cpp-qml.html#geoaddress} {Interfaces between C++ and QML Code}". +*/ +QGeoAddress QDeclarativeGeoAddress::address() const +{ + return m_address; +} + +void QDeclarativeGeoAddress::setAddress(const QGeoAddress &address) +{ + // Elaborate but takes care of emiting needed signals + setText(address.text()); + setCountry(address.country()); + setCountryCode(address.countryCode()); + setState(address.state()); + setCounty(address.county()); + setCity(address.city()); + setDistrict(address.district()); + setStreet(address.street()); + setPostalCode(address.postalCode()); + m_address = address; +} + +/*! + \qmlproperty string QtPositioning5::Address::text + + This property holds the address as a single formatted string. It is the recommended + string to use to display the address to the user. It typically takes the format of + an address as found on an envelope, but this is not always necessarily the case. + + The adddress \c text is either automatically generated or explicitly assigned, + this can be determined by checking \l isTextGenerated. + + If an empty string is assigned to \c text, then \l isTextGenerated will be set + to true and \c text will return a string which is locally formatted according to + \l countryCode and based on the properties of the address. Modifying the address + properties such as \l street, \l city and so on may cause the contents of \c text to + change. + + If a non-empty string is assigned to \c text, then \l isTextGenerated will be + set to false and \c text will always return the explicitly assigned string. + Modifying address properties will not affect the \c text property. +*/ +QString QDeclarativeGeoAddress::text() const +{ + return m_address.text(); +} + +void QDeclarativeGeoAddress::setText(const QString &address) +{ + QString oldText = m_address.text(); + bool oldIsTextGenerated = m_address.isTextGenerated(); + m_address.setText(address); + + if (oldText != m_address.text()) + emit textChanged(); + if (oldIsTextGenerated != m_address.isTextGenerated()) + emit isTextGeneratedChanged(); +} + +/*! + \qmlproperty string QtPositioning::Address::country + + This property holds the country of the address as a single formatted string. +*/ +QString QDeclarativeGeoAddress::country() const +{ + return m_address.country(); +} + +void QDeclarativeGeoAddress::setCountry(const QString &country) +{ + if (m_address.country() == country) + return; + QString oldText = m_address.text(); + m_address.setCountry(country); + emit countryChanged(); + + if (m_address.isTextGenerated() && oldText != m_address.text()) + emit textChanged(); +} + +/*! + \qmlproperty string QtPositioning::Address::countryCode + + This property holds the country code of the address as a single formatted string. +*/ +QString QDeclarativeGeoAddress::countryCode() const +{ + return m_address.countryCode(); +} + +void QDeclarativeGeoAddress::setCountryCode(const QString &countryCode) +{ + if (m_address.countryCode() == countryCode) + return; + QString oldText = m_address.text(); + m_address.setCountryCode(countryCode); + emit countryCodeChanged(); + + if (m_address.isTextGenerated() && oldText != m_address.text()) + emit textChanged(); +} + +/*! + \qmlproperty string QtPositioning::Address::state + + This property holds the state of the address as a single formatted string. +*/ +QString QDeclarativeGeoAddress::state() const +{ + return m_address.state(); +} + +void QDeclarativeGeoAddress::setState(const QString &state) +{ + if (m_address.state() == state) + return; + QString oldText = m_address.text(); + m_address.setState(state); + emit stateChanged(); + + if (m_address.isTextGenerated() && oldText != m_address.text()) + emit textChanged(); +} + +/*! + \qmlproperty string QtPositioning::Address::county + + This property holds the county of the address as a single formatted string. +*/ +QString QDeclarativeGeoAddress::county() const +{ + return m_address.county(); +} + +void QDeclarativeGeoAddress::setCounty(const QString &county) +{ + if (m_address.county() == county) + return; + QString oldText = m_address.text(); + m_address.setCounty(county); + emit countyChanged(); + + if (m_address.isTextGenerated() && oldText != m_address.text()) + emit textChanged(); +} + +/*! + \qmlproperty string QtPositioning::Address::city + + This property holds the city of the address as a single formatted string. +*/ +QString QDeclarativeGeoAddress::city() const +{ + return m_address.city(); +} + +void QDeclarativeGeoAddress::setCity(const QString &city) +{ + if (m_address.city() == city) + return; + QString oldText = m_address.text(); + m_address.setCity(city); + emit cityChanged(); + + if (m_address.isTextGenerated() && oldText != m_address.text()) + emit textChanged(); +} + +/*! + \qmlproperty string QtPositioning::Address::district + + This property holds the district of the address as a single formatted string. +*/ +QString QDeclarativeGeoAddress::district() const +{ + return m_address.district(); +} + +void QDeclarativeGeoAddress::setDistrict(const QString &district) +{ + if (m_address.district() == district) + return; + QString oldText = m_address.text(); + m_address.setDistrict(district); + emit districtChanged(); + + if (m_address.isTextGenerated() && oldText != m_address.text()) + emit textChanged(); +} + +/*! + \qmlproperty string QtPositioning::Address::street + + This property holds the street of the address but + may also contain things like a unit number, a building + name, or anything else that might be used to + distinguish one address from another. +*/ +QString QDeclarativeGeoAddress::street() const +{ + return m_address.street(); +} + +void QDeclarativeGeoAddress::setStreet(const QString &street) +{ + if (m_address.street() == street) + return; + QString oldText = m_address.text(); + m_address.setStreet(street); + emit streetChanged(); + + if (m_address.isTextGenerated() && oldText != m_address.text()) + emit textChanged(); +} + +/*! + \qmlproperty string QtPositioning::Address::postalCode + + This property holds the postal code of the address as a single formatted string. +*/ +QString QDeclarativeGeoAddress::postalCode() const +{ + return m_address.postalCode(); +} + +void QDeclarativeGeoAddress::setPostalCode(const QString &postalCode) +{ + if (m_address.postalCode() == postalCode) + return; + QString oldText = m_address.text(); + m_address.setPostalCode(postalCode); + emit postalCodeChanged(); + + if (m_address.isTextGenerated() && oldText != m_address.text()) + emit textChanged(); +} + +/*! + \qmlproperty bool QtPositioning::Address::isTextGenerated + + This property holds a boolean that if true, indicates that \l text is automatically + generated from address properties. If false, it indicates that the \l text has been + explicitly assigned. + +*/ +bool QDeclarativeGeoAddress::isTextGenerated() const +{ + return m_address.isTextGenerated(); +} + +#include "moc_qdeclarativegeoaddress_p.cpp" + +QT_END_NAMESPACE diff --git a/src/positioning/qdeclarativegeoaddress_p.h b/src/positioning/qdeclarativegeoaddress_p.h new file mode 100644 index 00000000..c3904a4f --- /dev/null +++ b/src/positioning/qdeclarativegeoaddress_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEGEOADDRESS_P_H +#define QDECLARATIVEGEOADDRESS_P_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Q_POSITIONING_EXPORT QDeclarativeGeoAddress : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QGeoAddress address READ address WRITE setAddress) + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged) + Q_PROPERTY(QString countryCode READ countryCode WRITE setCountryCode NOTIFY countryCodeChanged) + Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) + Q_PROPERTY(QString county READ county WRITE setCounty NOTIFY countyChanged) + Q_PROPERTY(QString city READ city WRITE setCity NOTIFY cityChanged) + Q_PROPERTY(QString district READ district WRITE setDistrict NOTIFY districtChanged) + Q_PROPERTY(QString street READ street WRITE setStreet NOTIFY streetChanged) + Q_PROPERTY(QString postalCode READ postalCode WRITE setPostalCode NOTIFY postalCodeChanged) + Q_PROPERTY(bool isTextGenerated READ isTextGenerated NOTIFY isTextGeneratedChanged) + +public: + explicit QDeclarativeGeoAddress(QObject *parent = 0); + QDeclarativeGeoAddress(const QGeoAddress &address, QObject *parent = 0); + QGeoAddress address() const; + void setAddress(const QGeoAddress &address); + + QString text() const; + void setText(const QString &address); + + QString country() const; + void setCountry(const QString &country); + QString countryCode() const; + void setCountryCode(const QString &countryCode); + QString state() const; + void setState(const QString &state); + QString county() const; + void setCounty(const QString &county); + QString city() const; + void setCity(const QString &city); + QString district() const; + void setDistrict(const QString &district); + QString street() const; + void setStreet(const QString &street); + QString postalCode() const; + void setPostalCode(const QString &postalCode); + bool isTextGenerated() const; + +Q_SIGNALS: + void textChanged(); + void countryChanged(); + void countryCodeChanged(); + void stateChanged(); + void countyChanged(); + void cityChanged(); + void districtChanged(); + void streetChanged(); + void postalCodeChanged(); + void isTextGeneratedChanged(); + +private: + QGeoAddress m_address; +}; + +QT_END_NAMESPACE +QML_DECLARE_TYPE(QDeclarativeGeoAddress) + +#endif // QDECLARATIVEGEOADDRESS_P_H diff --git a/src/positioning/qdeclarativegeolocation.cpp b/src/positioning/qdeclarativegeolocation.cpp new file mode 100644 index 00000000..95ba3113 --- /dev/null +++ b/src/positioning/qdeclarativegeolocation.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeolocation_p.h" + +QT_USE_NAMESPACE + +/*! + \qmltype Location + \instantiates QDeclarativeGeoLocation + \inqmlmodule QtPositioning 5.0 + \since Qt Positioning 5.0 + + \brief The Location type holds location data. + + Location types represent a geographic "location", in a human sense. This + consists of a specific \l {coordinate}, an \l {address} and a \l {boundingBox}{bounding box}. + The \l {boundingBox}{bounding box} represents the recommended region + to display when viewing this location. + + The Location type is most commonly seen as the contents of a search + model such as the GeocodeModel. When a GeocodeModel returns the list of + locations found for a given query, it represents these as Location objects. + + \section2 Example Usage + + The following example shows a simple Location object being declared: + + \code + Location { + coordinate { + latitude: -27.3 + longitude: 153.1 + } + address: Address { + ... + } + } + \endcode +*/ + +QDeclarativeGeoLocation::QDeclarativeGeoLocation(QObject *parent) +: QObject(parent), m_address(0) + +{ + setLocation(QGeoLocation()); +} + +QDeclarativeGeoLocation::QDeclarativeGeoLocation(const QGeoLocation &src, QObject *parent) +: QObject(parent), m_address(0) +{ + setLocation(src); +} + +QDeclarativeGeoLocation::~QDeclarativeGeoLocation() +{ +} + +/*! + \qmlproperty QGeoLocation QtPositioning::Location::location + + For details on how to use this property to interface between C++ and QML see + "\l {positioning-cpp-qml.html#location} {Interfaces between C++ and QML Code}". +*/ +void QDeclarativeGeoLocation::setLocation(const QGeoLocation &src) +{ + if (m_address && m_address->parent() == this) { + m_address->setAddress(src.address()); + } else if (!m_address || m_address->parent() != this) { + m_address = new QDeclarativeGeoAddress(src.address(), this); + emit addressChanged(); + } + + setCoordinate(src.coordinate()); + setBoundingBox(src.boundingBox()); +} + +QGeoLocation QDeclarativeGeoLocation::location() const +{ + QGeoLocation retValue; + retValue.setAddress(m_address ? m_address->address() : QGeoAddress()); + retValue.setCoordinate(m_coordinate); + retValue.setBoundingBox(m_boundingBox); + return retValue; +} + +/*! + \qmlproperty Address QtPositioning::Location::address + + This property holds the address of the location which can be use to retrieve address details of the location. +*/ +void QDeclarativeGeoLocation::setAddress(QDeclarativeGeoAddress *address) +{ + if (m_address == address) + return; + + if (m_address && m_address->parent() == this) + delete m_address; + + m_address = address; + emit addressChanged(); +} + +QDeclarativeGeoAddress *QDeclarativeGeoLocation::address() const +{ + return m_address; +} + +/*! + \qmlproperty coordinate QtPositioning::Location::coordinate + + This property holds the exact geographical coordinate of the location which can be used to retrieve the latitude, longitude and altitude of the location. + + \note this property's changed() signal is currently emitted only if the + whole object changes, not if only the contents of the object change. +*/ +void QDeclarativeGeoLocation::setCoordinate(const QGeoCoordinate coordinate) +{ + if (m_coordinate == coordinate) + return; + + m_coordinate = coordinate; + emit coordinateChanged(); +} + +QGeoCoordinate QDeclarativeGeoLocation::coordinate() const +{ + return m_coordinate; +} + +/*! + \qmlproperty georectangle QtPositioning::Location::boundingBox + + This property holds the recommended region to use when displaying the location. + For example, a building's location may have a region centered around the building, + but the region is large enough to show it's immediate surrounding geographical + context. + + Note: this property's changed() signal is currently emitted only if the + whole object changes, not if only the contents of the object change. +*/ +void QDeclarativeGeoLocation::setBoundingBox(const QGeoRectangle &boundingBox) +{ + if (m_boundingBox == boundingBox) + return; + + m_boundingBox = boundingBox; + emit boundingBoxChanged(); +} + +QGeoRectangle QDeclarativeGeoLocation::boundingBox() const +{ + return m_boundingBox; +} diff --git a/src/positioning/qdeclarativegeolocation_p.h b/src/positioning/qdeclarativegeolocation_p.h new file mode 100644 index 00000000..1352d827 --- /dev/null +++ b/src/positioning/qdeclarativegeolocation_p.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOLOCATION_P_H +#define QDECLARATIVEGEOLOCATION_P_H + + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Q_POSITIONING_EXPORT QDeclarativeGeoLocation : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QGeoLocation location READ location WRITE setLocation) + Q_PROPERTY(QDeclarativeGeoAddress *address READ address WRITE setAddress NOTIFY addressChanged) + Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) + Q_PROPERTY(QGeoRectangle boundingBox READ boundingBox WRITE setBoundingBox NOTIFY boundingBoxChanged) + +public: + explicit QDeclarativeGeoLocation(QObject *parent = 0); + explicit QDeclarativeGeoLocation(const QGeoLocation &src, QObject *parent = 0); + ~QDeclarativeGeoLocation(); + + QGeoLocation location() const; + void setLocation(const QGeoLocation &src); + + QDeclarativeGeoAddress *address() const; + void setAddress(QDeclarativeGeoAddress *address); + QGeoCoordinate coordinate() const; + void setCoordinate(const QGeoCoordinate coordinate); + + QGeoRectangle boundingBox() const; + void setBoundingBox(const QGeoRectangle &boundingBox); + +Q_SIGNALS: + void addressChanged(); + void coordinateChanged(); + void boundingBoxChanged(); + +private: + QDeclarativeGeoAddress *m_address; + QGeoRectangle m_boundingBox; + QGeoCoordinate m_coordinate; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativeGeoLocation) + +#endif // QDECLARATIVELOCATION_P_H diff --git a/src/positioning/qgeoaddress.cpp b/src/positioning/qgeoaddress.cpp new file mode 100644 index 00000000..b62e3431 --- /dev/null +++ b/src/positioning/qgeoaddress.cpp @@ -0,0 +1,637 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeoaddress.h" +#include "qgeoaddress_p.h" + +#include + +#ifdef QGEOADDRESS_DEBUG +#include +#endif + +QT_BEGIN_NAMESPACE + +/* + Combines a list of address parts into a single line. + + The parts parameter contains both address elements such as city, state and so on + as well as separators such as spaces and commas. + + It is expected that an element is always followed by a separator and the last + sepator is usually a new line delimeter. + + For example: Springfield, 8900 + would have four parts + ["Springfield", ", ", "8900", "
"] + + The addressLine takes care of putting in separators appropriately or leaving + them out depending on whether the adjacent elements are present or not. + For example if city were empty in the above scenario the returned string is "8900
" + If the postal code was empty, returned string is "Springfield
" + If both city and postal code were empty, the returned string is "". +*/ +static QString addressLine(const QStringList &parts) +{ + QString line; + Q_ASSERT(parts.count() % 2 == 0); + + //iterate until just before the last pair + QString penultimateSeparator; + for (int i = 0; i < parts.count() - 2; i += 2) { + if (!parts.at(i).isEmpty()) { + line.append(parts.at(i) + parts.at(i + 1)); + penultimateSeparator = parts.at(i + 1); + } + } + + if (parts.at(parts.count() - 2).isEmpty()) { + line.chop(penultimateSeparator.length()); + + if (!line.isEmpty()) + line.append(parts.at(parts.count() - 1)); + } else { + line.append(parts.at(parts.count() - 2)); + line.append(parts.at(parts.count() - 1)); + } + + return line; +} + +/* + Returns a single formatted string representing the \a address. Lines of the address + are delimited by \a newLine. By default lines are delimited by
. The \l + {QGeoAddress::countryCode} {countryCode} of the \a address determines the format of + the resultant string. +*/ +static QString formattedAddress(const QGeoAddress &address, + const QString &newLine = QLatin1String("
")) +{ + const QString Comma(QLatin1String(", ")); + const QString Dash(QLatin1String("-")); + const QString Space(QLatin1String(" ")); + + QString text; + + if (address.countryCode() == QLatin1String("ALB") + || address.countryCode() == QLatin1String("MTQ")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.postalCode() << Comma + << address.city() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("AND") + || address.countryCode() == QLatin1String("AUT") + || address.countryCode() == QLatin1String("FRA") + || address.countryCode() == QLatin1String("GLP") + || address.countryCode() == QLatin1String("GUF") + || address.countryCode() == QLatin1String("ITA") + || address.countryCode() == QLatin1String("LUX") + || address.countryCode() == QLatin1String("MCO") + || address.countryCode() == QLatin1String("REU") + || address.countryCode() == QLatin1String("RUS") + || address.countryCode() == QLatin1String("SMR") + || address.countryCode() == QLatin1String("VAT")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.postalCode() << Space + << address.city() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("ARE") + || address.countryCode() == QLatin1String("BHS")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Space + << address.city() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("AUS")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << (address.district().isEmpty() ? address.city() : address.district()) + << Space << address.state() << Space << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("BHR")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Comma + << address.city() << Comma << address.state() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("BRA")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Space + << address.city() << Dash << address.state() << Space << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("BRN") + || address.countryCode() == QLatin1String("JOR") + || address.countryCode() == QLatin1String("LBN") + || address.countryCode() == QLatin1String("NZL")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Space + << address.city() << Space << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("CAN") + || address.countryCode() == QLatin1String("USA") + || address.countryCode() == QLatin1String("VIR")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.city() << Comma << address.state() << Space + << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("CHN")) { + text += addressLine(QStringList() << address.street() << Comma << address.city() << newLine); + text += addressLine(QStringList() << address.postalCode() << Space << address.state() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("CHL")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.postalCode() << Space + << address.district() << Comma << address.city() << Comma + << address.state() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("CYM")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.state() << Space + << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("GBR")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Comma + << address.city() << Comma << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("GIB")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.city() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("HKG")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << newLine); + text += addressLine(QStringList() << address.city() << newLine); + } else if (address.countryCode() == QLatin1String("IND")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.city() << Space << address.postalCode() << Space + << address.state() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("IDN") + || address.countryCode() == QLatin1String("JEY") + || address.countryCode() == QLatin1String("LVA")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.city() << Comma << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("IRL")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Comma << address.state() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("KWT")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.postalCode() << Comma + << address.district() << Comma << address.city() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("MLT") + || address.countryCode() == QLatin1String("SGP") + || address.countryCode() == QLatin1String("UKR")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("MEX")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << newLine); + text += addressLine(QStringList() << address.postalCode() << Space << address.city() << Comma + << address.state() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("MYS")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine); + text += addressLine(QStringList() << address.state() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("OMN")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Comma + << address.postalCode() << Comma + << address.city() << Comma + << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("PRI")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Comma << address.city() << Comma + << address.state() << Comma << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("QAT")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Space << address.city() << Comma + << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("SAU")) { + text += addressLine(QStringList() << address.street() << Space << address.district() << newLine); + text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("TWN")) { + text += addressLine(QStringList() << address.street() << Comma + << address.district() << Comma << address.city() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("THA")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Comma << address.city() << Space + << address.postalCode() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("TUR")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.postalCode() << Space << address.district() << Comma + << address.city() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("VEN")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.city() << Space << address.postalCode() << Comma + << address.state() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else if (address.countryCode() == QLatin1String("ZAF")) { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.district() << Comma << address.city() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } else { + text += addressLine(QStringList() << address.street() << newLine); + text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine); + text += addressLine(QStringList() << address.country() << newLine); + } + + text.chop(newLine.length()); + return text; +} + +QGeoAddressPrivate::QGeoAddressPrivate() + : QSharedData(), + m_autoGeneratedText(false) +{ +} + +QGeoAddressPrivate::QGeoAddressPrivate(const QGeoAddressPrivate &other) + : QSharedData(other), + sCountry(other.sCountry), + sCountryCode(other.sCountryCode), + sState(other.sState), + sCounty(other.sCounty), + sCity(other.sCity), + sDistrict(other.sDistrict), + sStreet(other.sStreet), + sPostalCode(other.sPostalCode), + sText(other.sText), + m_autoGeneratedText(false) +{ +} + +QGeoAddressPrivate::~QGeoAddressPrivate() +{ +} + +/*! + \class QGeoAddress + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \ingroup QtLocation-places-data + \ingroup QtLocation-places + \since Qt Positioning 5.0 + + \brief The QGeoAddress class represents an address of a \l QGeoLocation. + + The address' attributes are normalized to US feature names and can be mapped + to the local feature levels (for example State matches "Bundesland" in Germany). + + The address contains a \l text() for displaying purposes and additional + properties to access the components of an address: + + \list + \li QGeoAddress::country() + \li QGeoAddress::countryCode() + \li QGeoAddress::state() + \li QGeoAddress::city() + \li QGeoAddress::district() + \li QGeoAddress::street() + \li QGeoAddress::postalCode() + \endlist +*/ + +/*! + Default constructor. +*/ +QGeoAddress::QGeoAddress() + : d(new QGeoAddressPrivate) +{ +} + +/*! + Constructs a copy of \a other. +*/ +QGeoAddress::QGeoAddress(const QGeoAddress &other) + : d(other.d) +{ +} + +/*! + Destroys this address. +*/ +QGeoAddress::~QGeoAddress() +{ +} + +/*! + Assigns the given \a address to this address and + returns a reference to this address. +*/ +QGeoAddress &QGeoAddress::operator=(const QGeoAddress & address) +{ + if (this == &address) + return *this; + + d = address.d; + return *this; +} + +/*! + Returns true if this address is equal to \a other, + otherwise returns false. +*/ +bool QGeoAddress::operator==(const QGeoAddress &other) const +{ +#ifdef QGEOADDRESS_DEBUG + qDebug() << "country" << (d->sCountry == other.country()); + qDebug() << "countryCode" << (d->sCountryCode == other.countryCode()); + qDebug() << "state:" << (d->sState == other.state()); + qDebug() << "county:" << (d->sCounty == other.county()); + qDebug() << "city:" << (d->sCity == other.city()); + qDebug() << "district:" << (d->sDistrict == other.district()); + qDebug() << "street:" << (d->sStreet == other.street()); + qDebug() << "postalCode:" << (d->sPostalCode == other.postalCode()); + qDebug() << "text:" << (text() == other.text()); +#endif + + return d->sCountry == other.country() && + d->sCountryCode == other.countryCode() && + d->sState == other.state() && + d->sCounty == other.county() && + d->sCity == other.city() && + d->sDistrict == other.district() && + d->sStreet == other.street() && + d->sPostalCode == other.postalCode() && + this->text() == other.text(); +} + +/*! + \fn bool QGeoAddress::operator!=(const QGeoAddress &other) const + + Returns true if this address is not equal to \a other, + otherwise returns false. +*/ + +/*! + Returns the address as a single formatted string. It is the recommended string + to use to display the address to the user. It typically takes the format of + an address as found on an envelope, but this is not always necessarily the case. + + The adddress text is either automatically generated or explicitly assigned. + This can be determined by checking \l {QGeoAddress::isTextGenerated()} {isTextGenerated}. + + If an empty string is provided to setText(), then isTextGenerated() will be set + to true and text() will return a string which is locally formatted according to + countryCode() and based on the elements of the address such as street, city and so on. + Because the text string is generated from the address elements, a sequence + of calls such as text(), setStreet(), text() may return different strings for each + invocation of text(). + + If a non-empty string is provided to setText(), then isTextGenerated() will be + set to false and text() will always return the explicitly assigned string. + Calls to modify other elements such as setStreet(), setCity() and so on will not + affect the resultant string from text(). +*/ +QString QGeoAddress::text() const +{ + if (d->sText.isEmpty()) + return formattedAddress(*this); + else + return d->sText; +} + +/*! + If \a text is not empty, explicitly assigns \a text as the string to be returned by + text(). isTextGenerated() will return false. + + If \a text is empty, indicates that text() should be automatically generated + from the address elements. isTextGenerated() will return true. +*/ +void QGeoAddress::setText(const QString &text) +{ + d->sText = text; +} + +/*! + Returns the country name. +*/ +QString QGeoAddress::country() const +{ + return d->sCountry; +} + +/*! + Sets the \a country name. +*/ +void QGeoAddress::setCountry(const QString &country) +{ + d->sCountry = country; +} + +/*! + Returns the country code according to ISO 3166-1 alpha-3 +*/ +QString QGeoAddress::countryCode() const +{ + return d->sCountryCode; +} + +/*! + Sets the \a countryCode according to ISO 3166-1 alpha-3 +*/ +void QGeoAddress::setCountryCode(const QString &countryCode) +{ + d->sCountryCode = countryCode; +} + +/*! + Returns the state. The state is considered the first subdivision below country. +*/ +QString QGeoAddress::state() const +{ + return d->sState; +} + +/*! + Sets the \a state. +*/ +void QGeoAddress::setState(const QString &state) +{ + d->sState = state; +} + +/*! + Returns the county. The county is considered the second subdivision below country. +*/ +QString QGeoAddress::county() const +{ + return d->sCounty; +} + +/*! + Sets the \a county. +*/ +void QGeoAddress::setCounty(const QString &county) +{ + d->sCounty = county; +} + +/*! + Returns the city. +*/ +QString QGeoAddress::city() const +{ + return d->sCity; +} + +/*! + Sets the \a city. +*/ +void QGeoAddress::setCity(const QString &city) +{ + d->sCity = city; +} + +/*! + Returns the district. The district is considered the subdivison below city. +*/ +QString QGeoAddress::district() const +{ + return d->sDistrict; +} + +/*! + Sets the \a district. +*/ +void QGeoAddress::setDistrict(const QString &district) +{ + d->sDistrict = district; +} + +/*! + Returns the street-level component of the address. + + This typically includes a street number and street name + but may also contain things like a unit number, a building + name, or anything else that might be used to + distinguish one address from another. +*/ +QString QGeoAddress::street() const +{ + return d->sStreet; +} + +/*! + Sets the street-level component of the address to \a street. + + This typically includes a street number and street name + but may also contain things like a unit number, a building + name, or anything else that might be used to + distinguish one address from another. +*/ +void QGeoAddress::setStreet(const QString &street) +{ + d->sStreet = street; +} + +/*! + Returns the postal code. +*/ +QString QGeoAddress::postalCode() const +{ + return d->sPostalCode; +} + +/*! + Sets the \a postalCode. +*/ +void QGeoAddress::setPostalCode(const QString &postalCode) +{ + d->sPostalCode = postalCode; +} + +/*! + Returns whether this address is empty. An address is considered empty + if \e all of its fields are empty. +*/ +bool QGeoAddress::isEmpty() const +{ + return d->sCountry.isEmpty() && + d->sCountryCode.isEmpty() && + d->sState.isEmpty() && + d->sCounty.isEmpty() && + d->sCity.isEmpty() && + d->sDistrict.isEmpty() && + d->sStreet.isEmpty() && + d->sPostalCode.isEmpty() && + d->sText.isEmpty(); + +} + +/*! + Clears all of the address' data fields. +*/ +void QGeoAddress::clear() +{ + d->sCountry.clear(); + d->sCountryCode.clear(); + d->sState.clear(); + d->sCounty.clear(); + d->sCity.clear(); + d->sDistrict.clear(); + d->sStreet.clear(); + d->sPostalCode.clear(); + d->sText.clear(); +} + +/*! + Returns true if QGeoAddress::text() is automatically generated from address elements, + otherwise returns false if text() has been explicitly assigned. + + \sa text(), setText() +*/ +bool QGeoAddress::isTextGenerated() const +{ + return d->sText.isEmpty(); +} + +QT_END_NAMESPACE + diff --git a/src/positioning/qgeoaddress.h b/src/positioning/qgeoaddress.h new file mode 100644 index 00000000..1aedd1a5 --- /dev/null +++ b/src/positioning/qgeoaddress.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOADDRESS_H +#define QGEOADDRESS_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QString; +class QGeoAddressPrivate; +class Q_POSITIONING_EXPORT QGeoAddress +{ +public: + QGeoAddress(); + QGeoAddress(const QGeoAddress &other); + ~QGeoAddress(); + + QGeoAddress &operator=(const QGeoAddress &other); + bool operator==(const QGeoAddress &other) const; + bool operator!=(const QGeoAddress &other) const { + return !(other == *this); + } + + QString text() const; + void setText(const QString &text); + + QString country() const; + void setCountry(const QString &country); + + QString countryCode() const; + void setCountryCode(const QString &countryCode); + + QString state() const; + void setState(const QString &state); + + QString county() const; + void setCounty(const QString &county); + + QString city() const; + void setCity(const QString &city); + + QString district() const; + void setDistrict(const QString &district); + + QString postalCode() const; + void setPostalCode(const QString &postalCode); + + QString street() const; + void setStreet(const QString &street); + + bool isEmpty() const; + void clear(); + + bool isTextGenerated() const; + +private: + QSharedDataPointer d; +}; + +Q_DECLARE_TYPEINFO(QGeoAddress, Q_MOVABLE_TYPE); + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QGeoAddress) + +#endif diff --git a/src/positioning/qgeoaddress_p.h b/src/positioning/qgeoaddress_p.h new file mode 100644 index 00000000..fa499d8b --- /dev/null +++ b/src/positioning/qgeoaddress_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QLOCATION_GEOADDRESS_P_H +#define QLOCATION_GEOADDRESS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QGeoAddressPrivate : public QSharedData +{ +public: + QGeoAddressPrivate(); + QGeoAddressPrivate(const QGeoAddressPrivate &other); + ~QGeoAddressPrivate(); + + QString sCountry; //!< country field + QString sCountryCode; //!< country code field + QString sState; //!< state field + QString sCounty; //!< county field + QString sCity; //!< city field + QString sDistrict; //!< district field + QString sStreet; //!< street name field + QString sPostalCode; //!< postal code field + QString sText; + bool m_autoGeneratedText; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qgeoareamonitor.cpp b/src/positioning/qgeoareamonitor.cpp new file mode 100644 index 00000000..5ad69e9a --- /dev/null +++ b/src/positioning/qgeoareamonitor.cpp @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include "qgeopositioninfosourcefactory.h" +#include "qgeopositioninfosource_p.h" + +/*! + \class QGeoAreaMonitor + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \since Qt Positioning 5.0 + + \brief The QGeoAreaMonitor class enables the detection of proximity + changes for a specified set of coordinates. + + A QGeoAreaMonitor emits signals when the current position is in + range, or has moved out of range, of a specified circular area. + The area is specified by a coordinate (the center point) and a + radius (in meters). + + For example: + + \code + public: + MyClass::MyClass() + { + QGeoAreaMonitor *monitor = QGeoAreaMonitor::createDefaultMonitor(); + if (monitor) { + connect(monitor, SIGNAL(areaEntered(QGeoPositionInfo)), + this, SLOT(areaEntered(QGeoPositionInfo))); + connect(monitor, SIGNAL(areaExited(QGeoPositionInfo)), + this, SLOT(areaExited(QGeoPositionInfo))); + + QGeoCoordinate bigBenLocation(51.50104, -0.124632); + monitor->setCenter(bigBenLocation); + monitor->setRadius(100); + } else { + qDebug() << "Could not create default area monitor"; + } + } + + public Q_SLOTS: + void areaEntered(const QGeoPositionInfo &update) + { + qDebug() << "Now within 100 meters, current position is" << update.coordinate(); + } + + void areaExited(const QGeoPositionInfo &update) + { + qDebug() << "No longer within 100 meters, current position is" << update.coordinate(); + } + \endcode +*/ + +QT_BEGIN_NAMESPACE + +class QGeoAreaMonitorPrivate +{ +public: + QGeoCoordinate coord; + qreal radius; +}; + + +/*! + Creates a monitor with the given \a parent. +*/ +QGeoAreaMonitor::QGeoAreaMonitor(QObject *parent) + : QObject(parent), + d(new QGeoAreaMonitorPrivate) +{ + d->radius = qreal(0.0); +} + +/*! + Destroys the monitor. +*/ +QGeoAreaMonitor::~QGeoAreaMonitor() +{ + delete d; +} + +/*! + \property QGeoAreaMonitor::center + \brief holds the center of the area to be monitored. + + When the center is set, if the radius has already been set and + the current position is within the monitored area, areaEntered() + is emitted immediately. + + By default, contains an invalid coordinate. + + Note: Subclass implementations must call the base implementation of + setCenter() so that center() returns the correct value. +*/ +void QGeoAreaMonitor::setCenter(const QGeoCoordinate &coordinate) +{ + d->coord = coordinate; +} + +QGeoCoordinate QGeoAreaMonitor::center() const +{ + return d->coord; +} + +/*! + \property QGeoAreaMonitor::radius + \brief holds the radius of the area to be monitored, in meters. + + If the specified radius is less than the minimum supported radius, the + radius is set to the minimum radius. + + When this property is set, if the center coordinate has already been set and + the current position is within the monitored area, areaEntered() + is emitted immediately. + + By default, this property is 0. + + Note: Subclass implementations must call the base implementation of + setRadius() so that radius() returns the correct value. +*/ +void QGeoAreaMonitor::setRadius(qreal radius) +{ + d->radius = radius; +} + +qreal QGeoAreaMonitor::radius() const +{ + return d->radius; +} + +/*! + Creates and returns a monitor with the given \a parent that + monitors areas using resources on the underlying system. + + Returns 0 if the system has no support for position monitoring. +*/ +QGeoAreaMonitor *QGeoAreaMonitor::createDefaultMonitor(QObject *parent) +{ + QList plugins = QGeoPositionInfoSourcePrivate::pluginsSorted(); + foreach (const QJsonObject &obj, plugins) { + if (obj.value(QStringLiteral("Monitor")).isBool() + && obj.value(QStringLiteral("Monitor")).toBool()) + { + QGeoPositionInfoSourcePrivate d; + d.metaData = obj; + d.loadPlugin(); + QGeoAreaMonitor *s = 0; + if (d.factory) + s = d.factory->areaMonitor(parent); + return s; + } + } + + return 0; +} + +/*! + Creates and returns a monitor with the given \a parent, + by loading the plugin named \a sourceName. + + Returns 0 if the plugin cannot be found. +*/ +QGeoAreaMonitor *QGeoAreaMonitor::createMonitor(const QString &sourceName, QObject *parent) +{ + QHash plugins = QGeoPositionInfoSourcePrivate::plugins(); + if (plugins.contains(sourceName)) { + QGeoPositionInfoSourcePrivate d; + d.metaData = plugins.value(sourceName); + d.loadPlugin(); + QGeoAreaMonitor *s = 0; + if (d.factory) + s = d.factory->areaMonitor(parent); + return s; + } + + return 0; +} + +/*! + Returns a list of available monitor plugins, including the default system + backend if one is available. +*/ +QStringList QGeoAreaMonitor::availableMonitors() +{ + QStringList plugins; + QHash meta = QGeoPositionInfoSourcePrivate::plugins(); + foreach (const QString &name, meta.keys()) { + if (meta.value(name).value(QStringLiteral("Monitor")).isBool() + && meta.value(name).value(QStringLiteral("Monitor")).toBool()) { + plugins << name; + } + } + + return plugins; +} + + + +/*! + \fn void QGeoAreaMonitor::areaEntered(const QGeoPositionInfo &update); + + Emitted when the current position has moved from a position outside the + monitored area to a position within the monitored area. + + The \a update holds the new position. +*/ + +/*! + \fn void QGeoAreaMonitor::areaExited(const QGeoPositionInfo &update); + + Emitted when the current position has moved from a position within the + monitored area to a position outside the monitored area. + + The \a update holds the new position. +*/ + +QT_END_NAMESPACE diff --git a/src/positioning/qgeoareamonitor.h b/src/positioning/qgeoareamonitor.h new file mode 100644 index 00000000..1aed8b6b --- /dev/null +++ b/src/positioning/qgeoareamonitor.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QGEOAREAMONITOR_H +#define QGEOAREAMONITOR_H + +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +class QGeoPositionInfo; +class QGeoAreaMonitorPrivate; +class Q_POSITIONING_EXPORT QGeoAreaMonitor : public QObject +{ + Q_OBJECT + Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter) + Q_PROPERTY(qreal radius READ radius WRITE setRadius) + +public: + explicit QGeoAreaMonitor(QObject *parent); + virtual ~QGeoAreaMonitor() = 0; + + virtual void setCenter(const QGeoCoordinate &coordinate); + QGeoCoordinate center() const; + + virtual void setRadius(qreal radius); + qreal radius() const; + + static QGeoAreaMonitor *createDefaultMonitor(QObject *parent); + static QGeoAreaMonitor *createMonitor(const QString& sourceName, QObject *parent); + static QStringList availableMonitors(); + +Q_SIGNALS: + void areaEntered(const QGeoPositionInfo &update); + void areaExited(const QGeoPositionInfo &update); + +private: + Q_DISABLE_COPY(QGeoAreaMonitor) + QGeoAreaMonitorPrivate *d; +}; + + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qgeocircle.cpp b/src/positioning/qgeocircle.cpp new file mode 100644 index 00000000..f9c43c1c --- /dev/null +++ b/src/positioning/qgeocircle.cpp @@ -0,0 +1,311 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeocircle.h" +#include "qgeocircle_p.h" + +#include "qgeocoordinate.h" +#include "qnumeric.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QGeoCircle + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \since Qt Positioning 5.0 + + \brief The QGeoCircle class defines a circular geographic area. + + The circle is defined in terms of a QGeoCoordinate which specifies the + center of the circle and a qreal which specifies the radius of the circle + in meters. + + The circle is considered invalid if the center coordinate is invalid + or if the radius is less than zero. +*/ + +#ifdef Q_NO_USING_KEYWORD +/*! + \fn bool QGeoCircle::operator==(const QGeoShape &other) const + + Returns true if \a other is equal to this geo circle; otherwise returns false. +*/ + +/*! + \fn bool QGeoCircle::operator!=(const QGeoShape &other) const + + Returns true if \a other is not equal to this geo circle; otherwise returns false. +*/ +#endif + +inline QGeoCirclePrivate *QGeoCircle::d_func() +{ + return static_cast(d_ptr.data()); +} + +inline const QGeoCirclePrivate *QGeoCircle::d_func() const +{ + return static_cast(d_ptr.constData()); +} + +/*! + Constructs a new, invalid geo circle. +*/ +QGeoCircle::QGeoCircle() +: QGeoShape(new QGeoCirclePrivate) +{ +} + +/*! + Constructs a new geo circle centered at \a center and with a radius of \a radius meters. +*/ +QGeoCircle::QGeoCircle(const QGeoCoordinate ¢er, qreal radius) +{ + d_ptr = new QGeoCirclePrivate(center, radius); +} + +/*! + Constructs a new geo circle from the contents of \a other. +*/ +QGeoCircle::QGeoCircle(const QGeoCircle &other) +: QGeoShape(other) +{ +} + +/*! + Constructs a new geo circle from the contents of \a other. +*/ +QGeoCircle::QGeoCircle(const QGeoShape &other) +: QGeoShape(other) +{ + if (type() != QGeoShape::CircleType) + d_ptr = new QGeoCirclePrivate; +} + +/*! + Destroys this geo circle. +*/ +QGeoCircle::~QGeoCircle() {} + +/*! + Assigns \a other to this geo circle and returns a reference to this geo circle. +*/ +QGeoCircle &QGeoCircle::operator=(const QGeoCircle &other) +{ + QGeoShape::operator=(other); + return *this; +} + +/*! + Returns whether this geo circle is equal to \a other. +*/ +bool QGeoCircle::operator==(const QGeoCircle &other) const +{ + Q_D(const QGeoCircle); + + return *d == *other.d_func(); +} + +/*! + Returns whether this geo circle is not equal to \a other. +*/ +bool QGeoCircle::operator!=(const QGeoCircle &other) const +{ + Q_D(const QGeoCircle); + + return !(*d == *other.d_func()); +} + +bool QGeoCirclePrivate::isValid() const +{ + return center.isValid() && !qIsNaN(radius) && radius >= -1e-7; +} + +bool QGeoCirclePrivate::isEmpty() const +{ + return !isValid() || radius <= 1e-7; +} + +/*! + Sets the center coordinate of this geo circle to \a center. +*/ +void QGeoCircle::setCenter(const QGeoCoordinate ¢er) +{ + Q_D(QGeoCircle); + + d->center = center; +} + +/*! + Returns the center coordinate of this geo circle. +*/ +QGeoCoordinate QGeoCircle::center() const +{ + Q_D(const QGeoCircle); + + return d->center; +} + +/*! + Sets the radius in meters of this geo circle to \a radius. +*/ +void QGeoCircle::setRadius(qreal radius) +{ + Q_D(QGeoCircle); + + d->radius = radius; +} + +/*! + Returns the radius in meters of this geo circle. +*/ +qreal QGeoCircle::radius() const +{ + Q_D(const QGeoCircle); + + return d->radius; +} + +bool QGeoCirclePrivate::contains(const QGeoCoordinate &coordinate) const +{ + if (!isValid() || !coordinate.isValid()) + return false; + + return center.distanceTo(coordinate) <= radius; +} + +/*! + Translates this geo circle by \a degreesLatitude northwards and \a degreesLongitude eastwards. + + Negative values of \a degreesLatitude and \a degreesLongitude correspond to + southward and westward translation respectively. +*/ +void QGeoCircle::translate(double degreesLatitude, double degreesLongitude) +{ + // TODO handle dlat, dlon larger than 360 degrees + + Q_D(QGeoCircle); + + double lat = d->center.latitude(); + double lon = d->center.longitude(); + + lat += degreesLatitude; + lon += degreesLongitude; + + if (lon < -180.0) + lon += 360.0; + if (lon > 180.0) + lon -= 360.0; + + if (lat > 90.0) { + lat = 180.0 - lat; + if (lon < 0.0) + lon = 180.0; + else + lon -= 180; + } + + if (lat < -90.0) { + lat = 180.0 + lat; + if (lon < 0.0) + lon = 180.0; + else + lon -= 180; + } + + d->center = QGeoCoordinate(lat, lon); +} + +/*! + Returns a copy of this geo circle translated by \a degreesLatitude northwards and + \a degreesLongitude eastwards. + + Negative values of \a degreesLatitude and \a degreesLongitude correspond to + southward and westward translation respectively. + + \sa translate() +*/ +QGeoCircle QGeoCircle::translated(double degreesLatitude, double degreesLongitude) const +{ + QGeoCircle result(*this); + result.translate(degreesLatitude, degreesLongitude); + return result; +} + +/******************************************************************************* +*******************************************************************************/ + +QGeoCirclePrivate::QGeoCirclePrivate() +: QGeoShapePrivate(QGeoShape::CircleType), radius(-1.0) +{ +} + +QGeoCirclePrivate::QGeoCirclePrivate(const QGeoCoordinate ¢er, qreal radius) +: QGeoShapePrivate(QGeoShape::CircleType), center(center), radius(radius) +{ +} + +QGeoCirclePrivate::QGeoCirclePrivate(const QGeoCirclePrivate &other) +: QGeoShapePrivate(QGeoShape::CircleType), center(other.center), + radius(other.radius) +{ +} + +QGeoCirclePrivate::~QGeoCirclePrivate() {} + +QGeoShapePrivate *QGeoCirclePrivate::clone() const +{ + return new QGeoCirclePrivate(*this); +} + +bool QGeoCirclePrivate::operator==(const QGeoShapePrivate &other) const +{ + if (!QGeoShapePrivate::operator==(other)) + return false; + + const QGeoCirclePrivate &otherCircle = static_cast(other); + + return radius == otherCircle.radius && center == otherCircle.center; +} + +QT_END_NAMESPACE + diff --git a/src/positioning/qgeocircle.h b/src/positioning/qgeocircle.h new file mode 100644 index 00000000..0a265460 --- /dev/null +++ b/src/positioning/qgeocircle.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOCIRCLE_H +#define QGEOCIRCLE_H + +#include + +QT_BEGIN_NAMESPACE + +class QGeoCoordinate; +class QGeoCirclePrivate; + +class Q_POSITIONING_EXPORT QGeoCircle : public QGeoShape +{ +public: + QGeoCircle(); + QGeoCircle(const QGeoCoordinate ¢er, qreal radius = -1.0); + QGeoCircle(const QGeoCircle &other); + QGeoCircle(const QGeoShape &other); + + ~QGeoCircle(); + + QGeoCircle &operator=(const QGeoCircle &other); + +#ifdef Q_NO_USING_KEYWORD + bool operator==(const QGeoShape &other) const + { + return QGeoShape::operator==(other); + } +#else + using QGeoShape::operator==; +#endif + bool operator==(const QGeoCircle &other) const; + +#ifdef Q_NO_USING_KEYWORD + bool operator!=(const QGeoShape &other) const + { + return QGeoShape::operator!=(other); + } +#else + using QGeoShape::operator!=; +#endif + bool operator!=(const QGeoCircle &other) const; + + void setCenter(const QGeoCoordinate ¢er); + QGeoCoordinate center() const; + + void setRadius(qreal radius); + qreal radius() const; + + void translate(double degreesLatitude, double degreesLongitude); + QGeoCircle translated(double degreesLatitude, double degreesLongitude) const; + +private: + inline QGeoCirclePrivate *d_func(); + inline const QGeoCirclePrivate *d_func() const; +}; + +Q_DECLARE_TYPEINFO(QGeoCircle, Q_MOVABLE_TYPE); + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QGeoCircle) + +#endif + diff --git a/src/positioning/qgeocircle_p.h b/src/positioning/qgeocircle_p.h new file mode 100644 index 00000000..e8e4a2c0 --- /dev/null +++ b/src/positioning/qgeocircle_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOCIRCLE_P_H +#define QGEOCIRCLE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qgeoshape_p.h" +#include "qgeocoordinate.h" + +QT_BEGIN_NAMESPACE + +class QGeoCirclePrivate : public QGeoShapePrivate +{ +public: + QGeoCirclePrivate(); + QGeoCirclePrivate(const QGeoCoordinate ¢er, qreal radius); + QGeoCirclePrivate(const QGeoCirclePrivate &other); + ~QGeoCirclePrivate(); + + bool isValid() const; + bool isEmpty() const; + bool contains(const QGeoCoordinate &coordinate) const; + + QGeoShapePrivate *clone() const; + + bool operator==(const QGeoShapePrivate &other) const; + + QGeoCoordinate center; + qreal radius; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qgeocoordinate.cpp b/src/positioning/qgeocoordinate.cpp new file mode 100644 index 00000000..e3392487 --- /dev/null +++ b/src/positioning/qgeocoordinate.cpp @@ -0,0 +1,644 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qgeocoordinate.h" +#include "qgeocoordinate_p.h" +#include "qlocationutils_p.h" + +#include +#include +#include +#include +#include + +#include + +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +QT_BEGIN_NAMESPACE + +static const double qgeocoordinate_EARTH_MEAN_RADIUS = 6371.0072; + +inline static double qgeocoordinate_degToRad(double deg) +{ + return deg * M_PI / 180; +} +inline static double qgeocoordinate_radToDeg(double rad) +{ + return rad * 180 / M_PI; +} + + +QGeoCoordinatePrivate::QGeoCoordinatePrivate() { + lat = qQNaN(); + lng = qQNaN(); + alt = qQNaN(); +} + +QGeoCoordinatePrivate::QGeoCoordinatePrivate(const QGeoCoordinatePrivate &other) + : QSharedData(other), + lat(other.lat), + lng(other.lng), + alt(other.alt) +{} + +QGeoCoordinatePrivate::~QGeoCoordinatePrivate() +{} + + +/*! + \class QGeoCoordinate + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \since Qt Positioning 5.0 + + \brief The QGeoCoordinate class defines a geographical position on the surface of the Earth. + + A QGeoCoordinate is defined by latitude, longitude, and optionally, altitude. + + Use type() to determine whether a coordinate is a 2D coordinate (has + latitude and longitude only) or 3D coordinate (has latitude, longitude + and altitude). Use distanceTo() and azimuthTo() to calculate the distance + and bearing between coordinates. + + The coordinate values should be specified using the WGS84 datum. For more information + on geographical terms see this article on \l {http://en.wikipedia.org/wiki/Geographic_coordinate_system}{coordinates} and + another on \l {http://en.wikipedia.org/wiki/Geodetic_system}{geodetic systems} + including WGS84. + + Azimuth in this context is equivalent to a compass bearing based on true north. +*/ + +/*! + \enum QGeoCoordinate::CoordinateType + Defines the types of a coordinate. + + \value InvalidCoordinate An invalid coordinate. A coordinate is invalid if its latitude or longitude values are invalid. + \value Coordinate2D A coordinate with valid latitude and longitude values. + \value Coordinate3D A coordinate with valid latitude and longitude values, and also an altitude value. +*/ + +/*! + \enum QGeoCoordinate::CoordinateFormat + Defines the possible formatting options for toString(). + + \value Degrees Returns a string representation of the coordinates in decimal degrees format. + \value DegreesWithHemisphere Returns a string representation of the coordinates in decimal degrees format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates. + \value DegreesMinutes Returns a string representation of the coordinates in degrees-minutes format. + \value DegreesMinutesWithHemisphere Returns a string representation of the coordinates in degrees-minutes format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates. + \value DegreesMinutesSeconds Returns a string representation of the coordinates in degrees-minutes-seconds format. + \value DegreesMinutesSecondsWithHemisphere Returns a string representation of the coordinates in degrees-minutes-seconds format, using 'N', 'S', 'E' or 'W' to indicate the hemispheres of the coordinates. + + \sa toString() +*/ + + +/*! + Constructs a coordinate. The coordinate will be invalid until + setLatitude() and setLongitude() have been called. +*/ +QGeoCoordinate::QGeoCoordinate() + : d(new QGeoCoordinatePrivate) +{ +} + +/*! + Constructs a coordinate with the given \a latitude and \a longitude. + + If the latitude is not between -90 to 90 inclusive, or the longitude + is not between -180 to 180 inclusive, none of the values are set and + the type() will be QGeoCoordinate::InvalidCoordinate. + + \sa isValid() +*/ +QGeoCoordinate::QGeoCoordinate(double latitude, double longitude) + : d(new QGeoCoordinatePrivate) +{ + if (QLocationUtils::isValidLat(latitude) && QLocationUtils::isValidLong(longitude)) { + d->lat = latitude; + d->lng = longitude; + } +} + +/*! + Constructs a coordinate with the given \a latitude, \a longitude + and \a altitude. + + If the latitude is not between -90 to 90 inclusive, or the longitude + is not between -180 to 180 inclusive, none of the values are set and + the type() will be QGeoCoordinate::InvalidCoordinate. + + Note that \a altitude specifies the meters above sea level. + + \sa isValid() +*/ +QGeoCoordinate::QGeoCoordinate(double latitude, double longitude, double altitude) + : d(new QGeoCoordinatePrivate) +{ + if (QLocationUtils::isValidLat(latitude) && QLocationUtils::isValidLong(longitude)) { + d->lat = latitude; + d->lng = longitude; + d->alt = altitude; + } +} + +/*! + Constructs a coordinate from the contents of \a other. +*/ +QGeoCoordinate::QGeoCoordinate(const QGeoCoordinate &other) + : d(other.d) +{} + +/*! + Assigns \a other to this coordinate and returns a reference to this coordinate. +*/ +QGeoCoordinate &QGeoCoordinate::operator=(const QGeoCoordinate &other) +{ + if (this == &other) + return *this; + + d = other.d; + return (*this); +} + +/*! + Destroys the coordinate object. +*/ +QGeoCoordinate::~QGeoCoordinate() +{ +} + +/*! + Returns true if the latitude, longitude and altitude of this + coordinate are the same as those of \a other. + + The longitude will be ignored if the latitude is +/- 90 degrees. +*/ +bool QGeoCoordinate::operator==(const QGeoCoordinate &other) const +{ + bool latEqual = (qIsNaN(d->lat) && qIsNaN(other.d->lat)) + || qFuzzyCompare(d->lat, other.d->lat); + bool lngEqual = (qIsNaN(d->lng) && qIsNaN(other.d->lng)) + || qFuzzyCompare(d->lng, other.d->lng); + bool altEqual = (qIsNaN(d->alt) && qIsNaN(other.d->alt)) + || qFuzzyCompare(d->alt, other.d->alt); + + if (!qIsNaN(d->lat) && ((d->lat == 90.0) || (d->lat == -90.0))) + lngEqual = true; + + return (latEqual && lngEqual && altEqual); +} + +/*! + \fn bool QGeoCoordinate::operator!=(const QGeoCoordinate &other) const; + + Returns true if the latitude, longitude or altitude of this + coordinate are not the same as those of \a other. +*/ + +/*! + Returns true if the type() is Coordinate2D or Coordinate3D. +*/ +bool QGeoCoordinate::isValid() const +{ + CoordinateType t = type(); + return t == Coordinate2D || t == Coordinate3D; +} + +/*! + Returns the type of this coordinate. +*/ +QGeoCoordinate::CoordinateType QGeoCoordinate::type() const +{ + if (QLocationUtils::isValidLat(d->lat) + && QLocationUtils::isValidLong(d->lng)) { + if (qIsNaN(d->alt)) + return Coordinate2D; + return Coordinate3D; + } + return InvalidCoordinate; +} + + +/*! + Returns the latitude, in decimal degrees. The return value is undefined + if the latitude has not been set. + + A positive latitude indicates the Northern Hemisphere, and a negative + latitude indicates the Southern Hemisphere. + + \sa setLatitude(), type() +*/ +double QGeoCoordinate::latitude() const +{ + return d->lat; +} + +/*! + Sets the latitude (in decimal degrees) to \a latitude. The value should + be in the WGS84 datum. + + To be valid, the latitude must be between -90 to 90 inclusive. + + \sa latitude() +*/ +void QGeoCoordinate::setLatitude(double latitude) +{ + d->lat = latitude; +} + +/*! + Returns the longitude, in decimal degrees. The return value is undefined + if the longitude has not been set. + + A positive longitude indicates the Eastern Hemisphere, and a negative + longitude indicates the Western Hemisphere. + + \sa setLongitude(), type() +*/ +double QGeoCoordinate::longitude() const +{ + return d->lng; +} + +/*! + Sets the longitude (in decimal degrees) to \a longitude. The value should + be in the WGS84 datum. + + To be valid, the longitude must be between -180 to 180 inclusive. + + \sa longitude() +*/ +void QGeoCoordinate::setLongitude(double longitude) +{ + d->lng = longitude; +} + +/*! + Returns the altitude (meters above sea level). + + The return value is undefined if the altitude has not been set. + + \sa setAltitude(), type() +*/ +double QGeoCoordinate::altitude() const +{ + return d->alt; +} + +/*! + Sets the altitude (meters above sea level) to \a altitude. + + \sa altitude() +*/ +void QGeoCoordinate::setAltitude(double altitude) +{ + d->alt = altitude; +} + +/*! + Returns the distance (in meters) from this coordinate to the coordinate + specified by \a other. Altitude is not used in the calculation. + + This calculation returns the great-circle distance between the two + coordinates, with an assumption that the Earth is spherical for the + purpose of this calculation. + + Returns 0 if the type of this coordinate or the type of \a other is + QGeoCoordinate::InvalidCoordinate. +*/ +qreal QGeoCoordinate::distanceTo(const QGeoCoordinate &other) const +{ + if (type() == QGeoCoordinate::InvalidCoordinate + || other.type() == QGeoCoordinate::InvalidCoordinate) { + return 0; + } + + // Haversine formula + double dlat = qgeocoordinate_degToRad(other.d->lat - d->lat); + double dlon = qgeocoordinate_degToRad(other.d->lng - d->lng); + double haversine_dlat = sin(dlat / 2.0); + haversine_dlat *= haversine_dlat; + double haversine_dlon = sin(dlon / 2.0); + haversine_dlon *= haversine_dlon; + double y = haversine_dlat + + cos(qgeocoordinate_degToRad(d->lat)) + * cos(qgeocoordinate_degToRad(other.d->lat)) + * haversine_dlon; + double x = 2 * asin(sqrt(y)); + return qreal(x * qgeocoordinate_EARTH_MEAN_RADIUS * 1000); +} + +/*! + Returns the azimuth (or bearing) in degrees from this coordinate to the + coordinate specified by \a other. Altitude is not used in the calculation. + + The bearing returned is the bearing from the origin to \a other along the + great-circle between the two coordinates. There is an assumption that the + Earth is spherical for the purpose of this calculation. + + Returns 0 if the type of this coordinate or the type of \a other is + QGeoCoordinate::InvalidCoordinate. +*/ +qreal QGeoCoordinate::azimuthTo(const QGeoCoordinate &other) const +{ + if (type() == QGeoCoordinate::InvalidCoordinate + || other.type() == QGeoCoordinate::InvalidCoordinate) { + return 0; + } + + double dlon = qgeocoordinate_degToRad(other.d->lng - d->lng); + double lat1Rad = qgeocoordinate_degToRad(d->lat); + double lat2Rad = qgeocoordinate_degToRad(other.d->lat); + + double y = sin(dlon) * cos(lat2Rad); + double x = cos(lat1Rad) * sin(lat2Rad) - sin(lat1Rad) * cos(lat2Rad) * cos(dlon); + + double whole; + double fraction = modf(qgeocoordinate_radToDeg(atan2(y, x)), &whole); + return qreal((int(whole + 360) % 360) + fraction); +} + +void QGeoCoordinatePrivate::atDistanceAndAzimuth(const QGeoCoordinate &coord, + qreal distance, qreal azimuth, + double *lon, double *lat) +{ + double latRad = qgeocoordinate_degToRad(coord.d->lat); + double lonRad = qgeocoordinate_degToRad(coord.d->lng); + double cosLatRad = cos(latRad); + double sinLatRad = sin(latRad); + + double azimuthRad = qgeocoordinate_degToRad(azimuth); + + double ratio = (distance / (qgeocoordinate_EARTH_MEAN_RADIUS * 1000.0)); + double cosRatio = cos(ratio); + double sinRatio = sin(ratio); + + double resultLatRad = asin(sinLatRad * cosRatio + + cosLatRad * sinRatio * cos(azimuthRad)); + double resultLonRad = lonRad + atan2(sin(azimuthRad) * sinRatio * cosLatRad, + cosRatio - sinLatRad * sin(resultLatRad)); + + *lat = qgeocoordinate_radToDeg(resultLatRad); + *lon = qgeocoordinate_radToDeg(resultLonRad); +} + +/*! + Returns the coordinate that is reached by traveling \a distance meters + from the current coordinate at \a azimuth (or bearing) along a great-circle. + There is an assumption that the Earth is spherical for the purpose of this + calculation. + + The altitude will have \a distanceUp added to it. + + Returns an invalid coordinate if this coordinate is invalid. +*/ +QGeoCoordinate QGeoCoordinate::atDistanceAndAzimuth(qreal distance, qreal azimuth, qreal distanceUp) const +{ + if (!isValid()) + return QGeoCoordinate(); + + double resultLon, resultLat; + QGeoCoordinatePrivate::atDistanceAndAzimuth(*this, distance, azimuth, + &resultLon, &resultLat); + + if (resultLon > 180.0) + resultLon -= 360.0; + else if (resultLon < -180.0) + resultLon += 360.0; + + double resultAlt = d->alt + distanceUp; + return QGeoCoordinate(resultLat, resultLon, resultAlt); +} + +/*! + Returns this coordinate as a string in the specified \a format. + + For example, if this coordinate has a latitude of -27.46758, a longitude + of 153.027892 and an altitude of 28.1, these are the strings + returned depending on \a format: + + \table + \header + \li \a format value + \li Returned string + \row + \li \l Degrees + \li -27.46758\unicode{0xB0}, 153.02789\unicode{0xB0}, 28.1m + \row + \li \l DegreesWithHemisphere + \li 27.46758\unicode{0xB0} S, 153.02789\unicode{0xB0} E, 28.1m + \row + \li \l DegreesMinutes + \li -27\unicode{0xB0} 28.054', 153\unicode{0xB0} 1.673', 28.1m + \row + \li \l DegreesMinutesWithHemisphere + \li 27\unicode{0xB0} 28.054 S', 153\unicode{0xB0} 1.673' E, 28.1m + \row + \li \l DegreesMinutesSeconds + \li -27\unicode{0xB0} 28' 3.2", 153\unicode{0xB0} 1' 40.4", 28.1m + \row + \li \l DegreesMinutesSecondsWithHemisphere + \li 27\unicode{0xB0} 28' 3.2" S, 153\unicode{0xB0} 1' 40.4" E, 28.1m + \endtable + + The altitude field is omitted if no altitude is set. + + If the coordinate is invalid, an empty string is returned. +*/ +QString QGeoCoordinate::toString(CoordinateFormat format) const +{ + if (type() == QGeoCoordinate::InvalidCoordinate) + return QString(); + + QString latStr; + QString longStr; + + double absLat = qAbs(d->lat); + double absLng = qAbs(d->lng); + QChar symbol(0x00B0); // degrees symbol + + switch (format) { + case Degrees: + case DegreesWithHemisphere: { + latStr = QString::number(absLat, 'f', 5) + symbol; + longStr = QString::number(absLng, 'f', 5) + symbol; + break; + } + case DegreesMinutes: + case DegreesMinutesWithHemisphere: { + double latMin = (absLat - int(absLat)) * 60; + double lngMin = (absLng - int(absLng)) * 60; + latStr = QString::fromLatin1("%1%2 %3'") + .arg(QString::number(int(absLat))) + .arg(symbol) + .arg(QString::number(latMin, 'f', 3)); + longStr = QString::fromLatin1("%1%2 %3'") + .arg(QString::number(int(absLng))) + .arg(symbol) + .arg(QString::number(lngMin, 'f', 3)); + break; + } + case DegreesMinutesSeconds: + case DegreesMinutesSecondsWithHemisphere: { + double latMin = (absLat - int(absLat)) * 60; + double lngMin = (absLng - int(absLng)) * 60; + double latSec = (latMin - int(latMin)) * 60; + double lngSec = (lngMin - int(lngMin)) * 60; + + latStr = QString::fromLatin1("%1%2 %3' %4\"") + .arg(QString::number(int(absLat))) + .arg(symbol) + .arg(QString::number(int(latMin))) + .arg(QString::number(latSec, 'f', 1)); + longStr = QString::fromLatin1("%1%2 %3' %4\"") + .arg(QString::number(int(absLng))) + .arg(symbol) + .arg(QString::number(int(lngMin))) + .arg(QString::number(lngSec, 'f', 1)); + break; + } + } + + // now add the "-" to the start, or append the hemisphere char + switch (format) { + case Degrees: + case DegreesMinutes: + case DegreesMinutesSeconds: { + if (d->lat < 0) + latStr.insert(0, QLatin1String("-")); + if (d->lng < 0) + longStr.insert(0, QLatin1String("-")); + break; + } + case DegreesWithHemisphere: + case DegreesMinutesWithHemisphere: + case DegreesMinutesSecondsWithHemisphere: { + if (d->lat < 0) + latStr.append(QString::fromLatin1(" S")); + else if (d->lat > 0) + latStr.append(QString::fromLatin1(" N")); + if (d->lng < 0) + longStr.append(QString::fromLatin1(" W")); + else if (d->lng > 0) + longStr.append(QString::fromLatin1(" E")); + break; + } + } + + if (qIsNaN(d->alt)) + return QString::fromLatin1("%1, %2").arg(latStr, longStr); + return QString::fromLatin1("%1, %2, %3m").arg(latStr, longStr, QString::number(d->alt)); +} + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QGeoCoordinate &coord) +{ + double lat = coord.latitude(); + double lng = coord.longitude(); + + dbg.nospace() << "QGeoCoordinate("; + if (qIsNaN(lat)) + dbg.nospace() << '?'; + else + dbg.nospace() << lat; + dbg.nospace() << ", "; + if (qIsNaN(lng)) + dbg.nospace() << '?'; + else + dbg.nospace() << lng; + if (coord.type() == QGeoCoordinate::Coordinate3D) { + dbg.nospace() << ", "; + dbg.nospace() << coord.altitude(); + } + dbg.nospace() << ')'; + return dbg; +} +#endif + +#ifndef QT_NO_DATASTREAM +/*! + \fn QDataStream &operator<<(QDataStream &stream, const QGeoCoordinate &coordinate) + + \relates QGeoCoordinate + + Writes the given \a coordinate to the specified \a stream. + + \sa {Serializing Qt Data Types} +*/ + +QDataStream &operator<<(QDataStream &stream, const QGeoCoordinate &coordinate) +{ + stream << coordinate.latitude(); + stream << coordinate.longitude(); + stream << coordinate.altitude(); + return stream; +} +#endif + +#ifndef QT_NO_DATASTREAM +/*! + \fn QDataStream &operator>>(QDataStream &stream, QGeoCoordinate &coordinate) + \relates QGeoCoordinate + + Reads a coordinate from the specified \a stream into the given + \a coordinate. + + \sa {Serializing Qt Data Types} +*/ + +QDataStream &operator>>(QDataStream &stream, QGeoCoordinate &coordinate) +{ + double value; + stream >> value; + coordinate.setLatitude(value); + stream >> value; + coordinate.setLongitude(value); + stream >> value; + coordinate.setAltitude(value); + return stream; +} +#endif + +QT_END_NAMESPACE diff --git a/src/positioning/qgeocoordinate.h b/src/positioning/qgeocoordinate.h new file mode 100644 index 00000000..23001ad1 --- /dev/null +++ b/src/positioning/qgeocoordinate.h @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOCOORDINATE_H +#define QGEOCOORDINATE_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QDebug; +class QDataStream; + +class QGeoCoordinatePrivate; +class Q_POSITIONING_EXPORT QGeoCoordinate +{ +public: + enum CoordinateType { + InvalidCoordinate, + Coordinate2D, + Coordinate3D + }; + + enum CoordinateFormat { + Degrees, + DegreesWithHemisphere, + DegreesMinutes, + DegreesMinutesWithHemisphere, + DegreesMinutesSeconds, + DegreesMinutesSecondsWithHemisphere + }; + + QGeoCoordinate(); + QGeoCoordinate(double latitude, double longitude); + QGeoCoordinate(double latitude, double longitude, double altitude); + QGeoCoordinate(const QGeoCoordinate &other); + ~QGeoCoordinate(); + + QGeoCoordinate &operator=(const QGeoCoordinate &other); + + bool operator==(const QGeoCoordinate &other) const; + inline bool operator!=(const QGeoCoordinate &other) const { + return !operator==(other); + } + + bool isValid() const; + CoordinateType type() const; + + void setLatitude(double latitude); + double latitude() const; + + void setLongitude(double longitude); + double longitude() const; + + void setAltitude(double altitude); + double altitude() const; + + qreal distanceTo(const QGeoCoordinate &other) const; + qreal azimuthTo(const QGeoCoordinate &other) const; + + QGeoCoordinate atDistanceAndAzimuth(qreal distance, qreal azimuth, qreal distanceUp = 0.0) const; + + QString toString(CoordinateFormat format = DegreesMinutesSecondsWithHemisphere) const; + +private: + QSharedDataPointer d; + + friend class QGeoCoordinatePrivate; +}; + +Q_DECLARE_TYPEINFO(QGeoCoordinate, Q_MOVABLE_TYPE); + +#ifndef QT_NO_DEBUG_STREAM +Q_POSITIONING_EXPORT QDebug operator<<(QDebug, const QGeoCoordinate &); +#endif + +#ifndef QT_NO_DATASTREAM +Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoCoordinate &coordinate); +Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoCoordinate &coordinate); +#endif + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QGeoCoordinate) + +#endif diff --git a/src/positioning/qgeocoordinate_p.h b/src/positioning/qgeocoordinate_p.h new file mode 100644 index 00000000..6685d464 --- /dev/null +++ b/src/positioning/qgeocoordinate_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOCOORDINATE_P_H +#define QGEOCOORDINATE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include "qgeocoordinate.h" + +QT_BEGIN_NAMESPACE + +class QGeoCoordinatePrivate : public QSharedData +{ +public: + QGeoCoordinatePrivate(); + QGeoCoordinatePrivate(const QGeoCoordinatePrivate &other); + ~QGeoCoordinatePrivate(); + + double lat; + double lng; + double alt; + + static void atDistanceAndAzimuth(const QGeoCoordinate &coord, + qreal distance, qreal azimuth, + double *lon, double *lat); +}; + +QT_END_NAMESPACE + +#endif // QGEOCOORDINATE_P_H diff --git a/src/positioning/qgeolocation.cpp b/src/positioning/qgeolocation.cpp new file mode 100644 index 00000000..2dc5a8b2 --- /dev/null +++ b/src/positioning/qgeolocation.cpp @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeolocation.h" +#include "qgeolocation_p.h" + +QT_USE_NAMESPACE + +QGeoLocationPrivate::QGeoLocationPrivate() + : QSharedData() +{ +} + +QGeoLocationPrivate::QGeoLocationPrivate(const QGeoLocationPrivate &other) + : QSharedData() +{ + this->address = other.address; + this->coordinate = other.coordinate; + this->viewport = other.viewport; +} + +QGeoLocationPrivate::~QGeoLocationPrivate() +{ +} + +bool QGeoLocationPrivate::operator==(const QGeoLocationPrivate &other) const +{ + return (this->address == other.address + && this->coordinate == other.coordinate + && this->viewport == other.viewport); + +} + +bool QGeoLocationPrivate::isEmpty() const +{ + return (address.isEmpty() + && !coordinate.isValid() + && viewport.isEmpty() + ); +} + +/*! + \class QGeoLocation + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \ingroup QtLocation-places + \ingroup QtLocation-places-data + \since Qt Positioning 5.0 + + \brief The QGeoLocation class represents basic information about a location. + + A QGeoLocation consists of a coordinate and corresponding address, along with an optional + bounding box which is the recommended region to be displayed when viewing the location. +*/ + +/*! + \fn bool QGeoLocation::operator!=(const QGeoLocation &other) const + + Returns true if this location is not equal to \a other, otherwise returns false. +*/ + +/*! + Constructs an new location object. +*/ +QGeoLocation::QGeoLocation() + : d(new QGeoLocationPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QGeoLocation::QGeoLocation(const QGeoLocation &other) + :d(other.d) +{ +} + +/*! + Destroys the location object. +*/ +QGeoLocation::~QGeoLocation() +{ +} + +/*! + Assigns \a other to this location and returns a reference to this location. +*/ +QGeoLocation &QGeoLocation::operator =(const QGeoLocation &other) +{ + if (this == &other) + return *this; + + d = other.d; + return *this; +} + +/*! + Returns true if this location is equal to \a other, + otherwise returns false. +*/ +bool QGeoLocation::operator==(const QGeoLocation &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns the address of the location. +*/ +QGeoAddress QGeoLocation::address() const +{ + return d->address; +} + +/*! + Sets the \a address of the location. +*/ +void QGeoLocation::setAddress(const QGeoAddress &address) +{ + d->address = address; +} + +/*! + Returns the coordinate of the location. +*/ +QGeoCoordinate QGeoLocation::coordinate() const +{ + return d->coordinate; +} + +/*! + Sets the \a coordinate of the location. +*/ +void QGeoLocation::setCoordinate(const QGeoCoordinate &coordinate) +{ + d->coordinate = coordinate; +} + +/*! + Returns a bounding box which represents the recommended region + to display when viewing this location. + + For example, a building's location may have a region centered around the building, + but the region is large enough to show it's immediate surrounding geographical + context. +*/ +QGeoRectangle QGeoLocation::boundingBox() const +{ + return d->viewport; +} + +/*! + Sets the \a boundingBox of the location. +*/ +void QGeoLocation::setBoundingBox(const QGeoRectangle &boundingBox) +{ + d->viewport = boundingBox; +} + +/*! + Returns true if all fields of the location are 0; otherwise returns false. +*/ +bool QGeoLocation::isEmpty() const +{ + return d->isEmpty(); +} diff --git a/src/positioning/qgeolocation.h b/src/positioning/qgeolocation.h new file mode 100644 index 00000000..395f83f1 --- /dev/null +++ b/src/positioning/qgeolocation.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOLOCATION_H +#define QGEOLOCATION_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QGeoAddress; +class QGeoCoordinate; +class QGeoRectangle; +class QGeoLocationPrivate; + +class Q_POSITIONING_EXPORT QGeoLocation +{ +public: + QGeoLocation(); + QGeoLocation(const QGeoLocation &other); + + ~QGeoLocation(); + + QGeoLocation &operator=(const QGeoLocation &other); + + bool operator==(const QGeoLocation &other) const; + bool operator!=(const QGeoLocation &other) const { + return !(other == *this); + } + + QGeoAddress address() const; + void setAddress(const QGeoAddress &address); + QGeoCoordinate coordinate() const; + void setCoordinate(const QGeoCoordinate &position); + QGeoRectangle boundingBox() const; + void setBoundingBox(const QGeoRectangle &box); + + bool isEmpty() const; + +private: + QSharedDataPointer d; +}; + +Q_DECLARE_TYPEINFO(QGeoLocation, Q_MOVABLE_TYPE); + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QGeoLocation) + +#endif diff --git a/src/positioning/qgeolocation_p.h b/src/positioning/qgeolocation_p.h new file mode 100644 index 00000000..86befce3 --- /dev/null +++ b/src/positioning/qgeolocation_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOLOCATION_P_H +#define QGEOLOCATION_P_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QGeoLocationPrivate : public QSharedData +{ +public: + QGeoLocationPrivate(); + QGeoLocationPrivate(const QGeoLocationPrivate &other); + + ~QGeoLocationPrivate(); + + bool operator==(const QGeoLocationPrivate &other) const; + + bool isEmpty() const; + + QGeoAddress address; + QGeoCoordinate coordinate; + QGeoRectangle viewport; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qgeopositioninfo.cpp b/src/positioning/qgeopositioninfo.cpp new file mode 100644 index 00000000..75a676a2 --- /dev/null +++ b/src/positioning/qgeopositioninfo.cpp @@ -0,0 +1,332 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qgeopositioninfo.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QGeoPositionInfoPrivate +{ +public: + QDateTime timestamp; + QGeoCoordinate coord; + QHash doubleAttribs; +}; + +/*! + \class QGeoPositionInfo + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \since Qt Positioning 5.0 + + \brief The QGeoPositionInfo class contains information gathered on a global position, direction and velocity at a particular point in time. + + A QGeoPositionInfo contains, at a minimum, a geographical coordinate and + a timestamp. It may also have heading and speed measurements as well as + estimates of the accuracy of the provided data. + + \sa QGeoPositionInfoSource +*/ + +/*! + \enum QGeoPositionInfo::Attribute + Defines the attributes for positional information. + + \value Direction The bearing measured in degrees clockwise from true north to the direction of travel. + \value GroundSpeed The ground speed, in meters/sec. + \value VerticalSpeed The vertical speed, in meters/sec. + \value MagneticVariation The angle between the horizontal component of the magnetic field and true north, in degrees. Also known as magnetic declination. A positive value indicates a clockwise direction from true north and a negative value indicates a counter-clockwise direction. + \value HorizontalAccuracy The accuracy of the provided latitude-longitude value, in meters. + \value VerticalAccuracy The accuracy of the provided altitude value, in meters. +*/ + +/*! + Creates an invalid QGeoPositionInfo object. + + \sa isValid() +*/ +QGeoPositionInfo::QGeoPositionInfo() + : d(new QGeoPositionInfoPrivate) +{ +} + +/*! + Creates a QGeoPositionInfo for the given \a coordinate and \a timestamp. +*/ +QGeoPositionInfo::QGeoPositionInfo(const QGeoCoordinate &coordinate, const QDateTime ×tamp) + : d(new QGeoPositionInfoPrivate) +{ + d->timestamp = timestamp; + d->coord = coordinate; +} + +/*! + Creates a QGeoPositionInfo with the values of \a other. +*/ +QGeoPositionInfo::QGeoPositionInfo(const QGeoPositionInfo &other) + : d(new QGeoPositionInfoPrivate) +{ + operator=(other); +} + +/*! + Destroys a QGeoPositionInfo object. +*/ +QGeoPositionInfo::~QGeoPositionInfo() +{ + delete d; +} + +/*! + Assigns the values from \a other to this QGeoPositionInfo. +*/ +QGeoPositionInfo &QGeoPositionInfo::operator=(const QGeoPositionInfo & other) +{ + if (this == &other) + return *this; + + d->timestamp = other.d->timestamp; + d->coord = other.d->coord; + d->doubleAttribs = other.d->doubleAttribs; + + return *this; +} + +/*! + Returns true if all of this object's values are the same as those of + \a other. +*/ +bool QGeoPositionInfo::operator==(const QGeoPositionInfo &other) const +{ + return d->timestamp == other.d->timestamp + && d->coord == other.d->coord + && d->doubleAttribs == other.d->doubleAttribs; +} + +/*! + \fn bool QGeoPositionInfo::operator!=(const QGeoPositionInfo &other) const + + Returns true if any of this object's values are not the same as those of + \a other. +*/ + +/*! + Returns true if the timestamp() and coordinate() values are both valid. + + \sa QGeoCoordinate::isValid(), QDateTime::isValid() +*/ +bool QGeoPositionInfo::isValid() const +{ + return d->timestamp.isValid() && d->coord.isValid(); +} + +/*! + Sets the date and time at which this position was reported to \a timestamp. + + The \a timestamp must be in UTC time. + + \sa timestamp() +*/ +void QGeoPositionInfo::setTimestamp(const QDateTime ×tamp) +{ + d->timestamp = timestamp; +} + +/*! + Returns the date and time at which this position was reported, in UTC time. + + Returns an invalid QDateTime if no date/time value has been set. + + \sa setTimestamp() +*/ +QDateTime QGeoPositionInfo::timestamp() const +{ + return d->timestamp; +} + +/*! + Sets the coordinate for this position to \a coordinate. + + \sa coordinate() +*/ +void QGeoPositionInfo::setCoordinate(const QGeoCoordinate &coordinate) +{ + d->coord = coordinate; +} + +/*! + Returns the coordinate for this position. + + Returns an invalid coordinate if no coordinate has been set. + + \sa setCoordinate() +*/ +QGeoCoordinate QGeoPositionInfo::coordinate() const +{ + return d->coord; +} + +/*! + Sets the value for \a attribute to \a value. + + \sa attribute() +*/ +void QGeoPositionInfo::setAttribute(Attribute attribute, qreal value) +{ + d->doubleAttribs[int(attribute)] = value; +} + +/*! + Returns the value of the specified \a attribute as a qreal value. + + Returns -1 if the value has not been set, although this may also + be a legitimate value for some attributes. + + The function hasAttribute() should be used to determine whether or + not a value has been set for an attribute. + + \sa hasAttribute(), setAttribute() +*/ +qreal QGeoPositionInfo::attribute(Attribute attribute) const +{ + if (d->doubleAttribs.contains(int(attribute))) + return d->doubleAttribs[int(attribute)]; + return -1; +} + +/*! + Removes the specified \a attribute and its value. +*/ +void QGeoPositionInfo::removeAttribute(Attribute attribute) +{ + d->doubleAttribs.remove(int(attribute)); +} + +/*! + Returns true if the specified \a attribute is present for this + QGeoPositionInfo object. +*/ +bool QGeoPositionInfo::hasAttribute(Attribute attribute) const +{ + return d->doubleAttribs.contains(int(attribute)); +} + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QGeoPositionInfo &info) +{ + dbg.nospace() << "QGeoPositionInfo(" << info.d->timestamp; + dbg.nospace() << ", "; + dbg.nospace() << info.d->coord; + + QList attribs = info.d->doubleAttribs.keys(); + qStableSort(attribs.begin(), attribs.end()); // Output a sorted list from an unsorted hash. + for (int i = 0; i < attribs.count(); ++i) { + dbg.nospace() << ", "; + switch (attribs[i]) { + case QGeoPositionInfo::Direction: + dbg.nospace() << "Direction="; + break; + case QGeoPositionInfo::GroundSpeed: + dbg.nospace() << "GroundSpeed="; + break; + case QGeoPositionInfo::VerticalSpeed: + dbg.nospace() << "VerticalSpeed="; + break; + case QGeoPositionInfo::MagneticVariation: + dbg.nospace() << "MagneticVariation="; + break; + case QGeoPositionInfo::HorizontalAccuracy: + dbg.nospace() << "HorizontalAccuracy="; + break; + case QGeoPositionInfo::VerticalAccuracy: + dbg.nospace() << "VerticalAccuracy="; + break; + } + dbg.nospace() << info.d->doubleAttribs[attribs[i]]; + } + dbg.nospace() << ')'; + return dbg; +} +#endif + +#ifndef QT_NO_DATASTREAM +/*! + \fn QDataStream &operator<<(QDataStream &stream, const QGeoPositionInfo &info) + \relates QGeoPositionInfo + + Writes the given \a info to the specified \a stream. + + \sa {Serializing Qt Data Types} +*/ + +QDataStream &operator<<(QDataStream &stream, const QGeoPositionInfo &info) +{ + stream << info.d->timestamp; + stream << info.d->coord; + stream << info.d->doubleAttribs; + return stream; +} +#endif + +#ifndef QT_NO_DATASTREAM +/*! + \fn QDataStream &operator>>(QDataStream &stream, QGeoPositionInfo &info) + \relates QGeoPositionInfo + + Reads a coordinate from the specified \a stream into the given + \a info. + + \sa {Serializing Qt Data Types} +*/ + +QDataStream &operator>>(QDataStream &stream, QGeoPositionInfo &info) +{ + stream >> info.d->timestamp; + stream >> info.d->coord; + stream >> info.d->doubleAttribs; + return stream; +} +#endif + +QT_END_NAMESPACE diff --git a/src/positioning/qgeopositioninfo.h b/src/positioning/qgeopositioninfo.h new file mode 100644 index 00000000..d56c2cbb --- /dev/null +++ b/src/positioning/qgeopositioninfo.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QGEOPOSITIONINFO_H +#define QGEOPOSITIONINFO_H + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QDebug; +class QDataStream; + +class QGeoPositionInfoPrivate; +class Q_POSITIONING_EXPORT QGeoPositionInfo +{ +public: + enum Attribute { + Direction, + GroundSpeed, + VerticalSpeed, + MagneticVariation, + HorizontalAccuracy, + VerticalAccuracy + }; + + QGeoPositionInfo(); + QGeoPositionInfo(const QGeoCoordinate &coordinate, const QDateTime &updateTime); + QGeoPositionInfo(const QGeoPositionInfo &other); + ~QGeoPositionInfo(); + + QGeoPositionInfo &operator=(const QGeoPositionInfo &other); + + bool operator==(const QGeoPositionInfo &other) const; + inline bool operator!=(const QGeoPositionInfo &other) const { + return !operator==(other); + } + + bool isValid() const; + + void setTimestamp(const QDateTime ×tamp); + QDateTime timestamp() const; + + void setCoordinate(const QGeoCoordinate &coordinate); + QGeoCoordinate coordinate() const; + + void setAttribute(Attribute attribute, qreal value); + qreal attribute(Attribute attribute) const; + void removeAttribute(Attribute attribute); + bool hasAttribute(Attribute attribute) const; + +private: +#ifndef QT_NO_DEBUG_STREAM + friend Q_POSITIONING_EXPORT QDebug operator<<(QDebug dbg, const QGeoPositionInfo &info); +#endif +#ifndef QT_NO_DATASTREAM + friend Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoPositionInfo &info); + friend Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoPositionInfo &info); +#endif + QGeoPositionInfoPrivate *d; +}; + +#ifndef QT_NO_DEBUG_STREAM +Q_POSITIONING_EXPORT QDebug operator<<(QDebug dbg, const QGeoPositionInfo &info); +#endif + +#ifndef QT_NO_DATASTREAM +Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoPositionInfo &info); +Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoPositionInfo &info); +#endif + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qgeopositioninfosource.cpp b/src/positioning/qgeopositioninfosource.cpp new file mode 100644 index 00000000..4fa7a4ca --- /dev/null +++ b/src/positioning/qgeopositioninfosource.cpp @@ -0,0 +1,462 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include "qgeopositioninfosource_p.h" +#include "qgeopositioninfosourcefactory.h" + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +#ifndef QT_NO_LIBRARY +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, + ("org.qt-project.qt.position.sourcefactory/5.0", + QLatin1String("/position"))) +#endif + +/*! + \class QGeoPositionInfoSource + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \since Qt Positioning 5.0 + + \brief The QGeoPositionInfoSource class is an abstract base class for the distribution of positional updates. + + The static function QGeoPositionInfoSource::createDefaultSource() creates a default + position source that is appropriate for the platform, if one is available. + Otherwise, QGeoPositionInfoSource will check for available plugins that + implement the QGeoPositionInfoSourceFactory interface. + + Users of a QGeoPositionInfoSource subclass can request the current position using + requestUpdate(), or start and stop regular position updates using + startUpdates() and stopUpdates(). When an update is available, + positionUpdated() is emitted. The last known position can be accessed with + lastKnownPosition(). + + If regular position updates are required, setUpdateInterval() can be used + to specify how often these updates should be emitted. If no interval is + specified, updates are simply provided whenever they are available. + For example: + + \code + // Emit updates every 10 seconds if available + QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(0); + if (source) + source->setUpdateInterval(10000); + \endcode + + To remove an update interval that was previously set, call + setUpdateInterval() with a value of 0. + + Note that the position source may have a minimum value requirement for + update intervals, as returned by minimumUpdateInterval(). + + \warning On Windows CE it is not possible to detect if a device is GPS enabled. + The default position source on a Windows CE device without GPS support will never provide any position data. +*/ + +/*! + \enum QGeoPositionInfoSource::PositioningMethod + Defines the types of positioning methods. + + \value SatellitePositioningMethods Satellite-based positioning methods such as GPS or GLONASS. + \value NonSatellitePositioningMethods Other positioning methods such as 3GPP cell identifier or WiFi based positioning. + \value AllPositioningMethods Satellite-based positioning methods as soon as available. Otherwise non-satellite based methods. +*/ + +void QGeoPositionInfoSourcePrivate::loadMeta() +{ + metaData = plugins().value(providerName); +} + +void QGeoPositionInfoSourcePrivate::loadPlugin() +{ + int idx = int(metaData.value(QStringLiteral("index")).toDouble()); + if (idx < 0) + return; + factory = qobject_cast(loader()->instance(idx)); +} + +QHash QGeoPositionInfoSourcePrivate::plugins(bool reload) +{ + static QHash plugins; + static bool alreadyDiscovered = false; + + if (reload == true) + alreadyDiscovered = false; + + if (!alreadyDiscovered) { + loadPluginMetadata(plugins); + alreadyDiscovered = true; + } + return plugins; +} + +static bool pluginComparator(const QJsonObject &p1, const QJsonObject &p2) +{ + const QString prio = QStringLiteral("Priority"); + if (p1.contains(prio) && !p2.contains(prio)) + return true; + if (!p1.contains(prio) && p2.contains(prio)) + return false; + if (p1.value(prio).isDouble() && !p2.value(prio).isDouble()) + return true; + if (!p1.value(prio).isDouble() && p2.value(prio).isDouble()) + return false; + return (p1.value(prio).toDouble() > p2.value(prio).toDouble()); +} + +QList QGeoPositionInfoSourcePrivate::pluginsSorted() +{ + QList list = plugins().values(); + qStableSort(list.begin(), list.end(), pluginComparator); + return list; +} + +void QGeoPositionInfoSourcePrivate::loadPluginMetadata(QHash &plugins) +{ + QFactoryLoader *l = loader(); + QList meta = l->metaData(); + for (int i = 0; i < meta.size(); ++i) { + QJsonObject obj = meta.at(i).value(QStringLiteral("MetaData")).toObject(); + obj.insert(QStringLiteral("index"), i); + plugins.insertMulti(obj.value(QStringLiteral("Provider")).toString(), obj); + } +} + +/*! + Creates a position source with the specified \a parent. +*/ + +QGeoPositionInfoSource::QGeoPositionInfoSource(QObject *parent) + : QObject(parent), + d(new QGeoPositionInfoSourcePrivate) +{ + d->interval = 0; + d->methods = 0; +} + +/*! + Destroys the position source. +*/ +QGeoPositionInfoSource::~QGeoPositionInfoSource() +{ + delete d; +} + +/*! + \property QGeoPositionInfoSource::sourceName + \brief This property holds the unique name of the position source + implementation in use. + + This is the same name that can be passed to createSource() in order to + create a new instance of a particular position source implementation. +*/ +QString QGeoPositionInfoSource::sourceName() const +{ + return d->metaData.value(QStringLiteral("Provider")).toString(); +} + +/*! + \property QGeoPositionInfoSource::updateInterval + \brief This property holds the requested interval in milliseconds between each update. + + If the update interval is not set (or is set to 0) the + source will provide updates as often as necessary. + + If the update interval is set, the source will provide updates at an + interval as close to the requested interval as possible. If the requested + interval is less than the minimumUpdateInterval(), + the minimum interval is used instead. + + Changes to the update interval will happen as soon as is practical, however the + time the change takes may vary between implementations. Whether or not the elapsed + time from the previous interval is counted as part of the new interval is also + implementation dependent. + + The default value for this property is 0. + + Note: Subclass implementations must call the base implementation of + setUpdateInterval() so that updateInterval() returns the correct value. +*/ +void QGeoPositionInfoSource::setUpdateInterval(int msec) +{ + d->interval = msec; +} + +int QGeoPositionInfoSource::updateInterval() const +{ + return d->interval; +} + +/*! + Sets the preferred positioning methods for this source to \a methods. + + If \a methods includes a method that is not supported by the source, the + unsupported method will be ignored. + + If \a methods does not include any methods supported by the source, the + preferred methods will be set to the set of methods which the source supports. + + \b {Note:} When reimplementing this method, subclasses must call the + base method implementation to ensure preferredPositioningMethods() returns the correct value. + + \sa supportedPositioningMethods() +*/ +void QGeoPositionInfoSource::setPreferredPositioningMethods(PositioningMethods methods) +{ + d->methods = methods & supportedPositioningMethods(); + if (d->methods == 0) { + d->methods = supportedPositioningMethods(); + } +} + +/*! + Returns the positioning methods set by setPreferredPositioningMethods(). +*/ +QGeoPositionInfoSource::PositioningMethods QGeoPositionInfoSource::preferredPositioningMethods() const +{ + return d->methods; +} + +/*! + Creates and returns a position source with the given \a parent that + reads from the system's default sources of location data, or the plugin + with the highest available priority. + + Returns 0 if the system has no default position source, no valid plugins + could be found or the user does not have the permission to access the current position. +*/ +QGeoPositionInfoSource *QGeoPositionInfoSource::createDefaultSource(QObject *parent) +{ + QList plugins = QGeoPositionInfoSourcePrivate::pluginsSorted(); + foreach (const QJsonObject &obj, plugins) { + if (obj.value(QStringLiteral("Position")).isBool() + && obj.value(QStringLiteral("Position")).toBool()) + { + QGeoPositionInfoSourcePrivate d; + d.metaData = obj; + d.loadPlugin(); + QGeoPositionInfoSource *s = 0; + if (d.factory) + s = d.factory->positionInfoSource(parent); + if (s) { + s->d->metaData = d.metaData; + return s; + } + } + } + return 0; +} + + +/*! + Creates and returns a position source with the given \a parent, + by loading the plugin named \a sourceName. + + Returns 0 if the plugin cannot be found. +*/ +QGeoPositionInfoSource *QGeoPositionInfoSource::createSource(const QString &sourceName, QObject *parent) +{ + QHash plugins = QGeoPositionInfoSourcePrivate::plugins(); + if (plugins.contains(sourceName)) + { + QGeoPositionInfoSourcePrivate d; + d.metaData = plugins.value(sourceName); + d.loadPlugin(); + QGeoPositionInfoSource *src = 0; + if (d.factory) + src = d.factory->positionInfoSource(parent); + if (src) + { + src->d->metaData = d.metaData; + return src; + } + } + return 0; +} + + +/*! + Returns a list of available source plugins. This includes any default backend + plugin for the current platform. +*/ +QStringList QGeoPositionInfoSource::availableSources() +{ + QStringList plugins; + QHash meta = QGeoPositionInfoSourcePrivate::plugins(); + foreach (const QString &name, meta.keys()) { + if (meta.value(name).value(QStringLiteral("Position")).isBool() + && meta.value(name).value(QStringLiteral("Position")).toBool()) { + plugins << name; + } + } + + return plugins; +} + +/*! + \fn QGeoPositionInfo QGeoPositionInfoSource::lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const = 0; + + Returns an update containing the last known position, or a null update + if none is available. + + If \a fromSatellitePositioningMethodsOnly is true, this returns the last + known position received from a satellite positioning method; if none + is available, a null update is returned. +*/ + +/*! + \fn virtual PositioningMethods QGeoPositionInfoSource::supportedPositioningMethods() const = 0; + + Returns the positioning methods available to this source. + + \sa setPreferredPositioningMethods() +*/ + + +/*! + \property QGeoPositionInfoSource::minimumUpdateInterval + \brief This property holds the minimum time (in milliseconds) required to retrieve a position update. + + This is the minimum value accepted by setUpdateInterval() and + requestUpdate(). +*/ + + +/*! + \fn virtual void QGeoPositionInfoSource::startUpdates() = 0; + + Starts emitting updates at regular intervals as specified by setUpdateInterval(). + + If setUpdateInterval() has not been called, the source will emit updates + as soon as they become available. + + An updateTimout() signal will be emitted if this QGeoPositionInfoSource subclass determines + that it will not be able to provide regular updates. This could happen if a satellite fix is + lost or if a hardware error is detected. Position updates will recommence if the data becomes + available later on. The updateTimout() signal will not be emitted again until after the + periodic updates resume. +*/ + +/*! + \fn virtual void QGeoPositionInfoSource::stopUpdates() = 0; + + Stops emitting updates at regular intervals. +*/ + +/*! + \fn virtual void QGeoPositionInfoSource::requestUpdate(int timeout = 0); + + Attempts to get the current position and emit positionUpdated() with + this information. If the current position cannot be found within the given \a timeout + (in milliseconds) or if \a timeout is less than the value returned by + minimumUpdateInterval(), updateTimeout() is emitted. + + If the timeout is zero, the timeout defaults to a reasonable timeout + period as appropriate for the source. + + This does nothing if another update request is in progress. However + it can be called even if startUpdates() has already been called and + regular updates are in progress. + + If the source uses multiple positioning methods, it tries to get the + current position from the most accurate positioning method within the + given timeout. +*/ + +/*! + \fn virtual QGeoPositionInfoSource::Error QGeoPositionInfoSource::error() const; + + Returns the type of error that last occurred. + +*/ + +/*! + \fn void QGeoPositionInfoSource::positionUpdated(const QGeoPositionInfo &update); + + If startUpdates() or requestUpdate() is called, this signal is emitted + when an update becomes available. + + The \a update value holds the value of the new update. +*/ + +/*! + \fn void QGeoPositionInfoSource::updateTimeout(); + + If requestUpdate() was called, this signal will be emitted if the current position could not + be retrieved within the specified timeout. + + If startUpdates() has been called, this signal will be emitted if this QGeoPositionInfoSource + subclass determines that it will not be able to provide further regular updates. This signal + will not be emitted again until after the regular updates resume. +*/ + +/*! + \fn void QGeoPositionInfoSource::error(QGeoPositionInfoSource::Error positioningError) + + This signal is emitted after an error occurred. The \a positioningError + parameter describes the type of error that occurred. + +*/ + +/*! + \enum QGeoPositionInfoSource::Error + + The Error enumeration represents the errors which can occur. + + \value AccessError The connection setup to the remote positioning backend failed because the + application lacked the required privileges. + \value ClosedError The remote positioning backend closed the connection, which happens for example in case + the user is switching location services to off. This object becomes invalid and should be deleted. + A call to createDefaultSource() can be used to create a new source later on. + \value UnknownSourceError An unidentified error occurred. + */ + +#include "moc_qgeopositioninfosource.cpp" + +QT_END_NAMESPACE diff --git a/src/positioning/qgeopositioninfosource.h b/src/positioning/qgeopositioninfosource.h new file mode 100644 index 00000000..3e1d54c8 --- /dev/null +++ b/src/positioning/qgeopositioninfosource.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QGEOPOSITIONINFOSOURCE_H +#define QGEOPOSITIONINFOSOURCE_H + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QGeoPositionInfoSourcePrivate; +class Q_POSITIONING_EXPORT QGeoPositionInfoSource : public QObject +{ + Q_OBJECT + Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval) + Q_PROPERTY(int minimumUpdateInterval READ minimumUpdateInterval) + Q_PROPERTY(QString sourceName READ sourceName) + +public: + enum Error { + AccessError, + ClosedError, /* 1 */ + UnknownSourceError = -1 + }; + Q_ENUMS(Error) + + enum PositioningMethod { + SatellitePositioningMethods = 0x000000ff, + NonSatellitePositioningMethods = 0xffffff00, + AllPositioningMethods = 0xffffffff + }; + Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod) + + explicit QGeoPositionInfoSource(QObject *parent); + virtual ~QGeoPositionInfoSource(); + + virtual void setUpdateInterval(int msec); + int updateInterval() const; + + virtual void setPreferredPositioningMethods(PositioningMethods methods); + PositioningMethods preferredPositioningMethods() const; + + virtual QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const = 0; + + virtual PositioningMethods supportedPositioningMethods() const = 0; + virtual int minimumUpdateInterval() const = 0; + + QString sourceName() const; + + static QGeoPositionInfoSource *createDefaultSource(QObject *parent); + static QGeoPositionInfoSource *createSource(const QString &sourceName, QObject *parent); + static QStringList availableSources(); + virtual Error error() const = 0; + +public Q_SLOTS: + virtual void startUpdates() = 0; + virtual void stopUpdates() = 0; + + virtual void requestUpdate(int timeout = 0) = 0; + +Q_SIGNALS: + void positionUpdated(const QGeoPositionInfo &update); + void updateTimeout(); + void error(QGeoPositionInfoSource::Error); + +private: + Q_DISABLE_COPY(QGeoPositionInfoSource) + QGeoPositionInfoSourcePrivate *d; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QGeoPositionInfoSource::PositioningMethods) + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qgeopositioninfosource_p.h b/src/positioning/qgeopositioninfosource_p.h new file mode 100644 index 00000000..3d844ae5 --- /dev/null +++ b/src/positioning/qgeopositioninfosource_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCE_P_H +#define QGEOPOSITIONINFOSOURCE_P_H + +#include "qgeopositioninfosource.h" +#include "qgeopositioninfosourcefactory.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QGeoPositionInfoSourcePrivate +{ +public: + int interval; + QGeoPositionInfoSource::PositioningMethods methods; + QJsonObject metaData; + QGeoPositionInfoSourceFactory *factory; + QString providerName; + + void loadMeta(); + void loadPlugin(); + + static QHash plugins(bool reload = false); + static void loadPluginMetadata(QHash &list); + static QList pluginsSorted(); +}; + +QT_END_NAMESPACE + +#endif // QGEOPOSITIONINFOSOURCE_P_H diff --git a/src/positioning/qgeopositioninfosourcefactory.cpp b/src/positioning/qgeopositioninfosourcefactory.cpp new file mode 100644 index 00000000..a113a4aa --- /dev/null +++ b/src/positioning/qgeopositioninfosourcefactory.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeopositioninfosourcefactory.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QGeoPositionInfoSourceFactory + \inmodule QtPositioning + \since Qt Positioning 5.0 + + \brief The QGeoPositionInfoSourceFactory class is a factory class used + as the plugin interface for external providers of positioning data. + + The other functions must be overridden by all plugins, other than + sourcePriority() which defaults to returning 0. Higher values of + priority will be preferred to lower ones. +*/ + +/*! + \fn QGeoPositionInfoSource *QGeoPositionInfoSourceFactory::positionInfoSource(QObject *parent) + + Returns a new QGeoPositionInfoSource associated with this plugin + with parent \a parent. Can also return 0, in which case the plugin + loader will use the factory with the next highest priority. + */ + +/*! + \fn QGeoSatelliteInfoSource *QGeoPositionInfoSourceFactory::satelliteInfoSource(QObject *parent) + + Returns a new QGeoSatelliteInfoSource associated with this plugin + with parent \a parent. Can also return 0, in which case the plugin + loader will use the factory with the next highest priority. + */ + +/*! + \fn QGeoAreaMonitor *QGeoPositionInfoSourceFactory::areaMonitor(QObject *parent); + + Returns a new QGeoAreaMonitor associated with this plugin with parent \a parent. + Can also return 0, in which case the plugin loader will use the factory with the + next highest priority. + */ + +/*! + Destroys the position info source factory. +*/ +QGeoPositionInfoSourceFactory::~QGeoPositionInfoSourceFactory() +{} + +QT_END_NAMESPACE diff --git a/src/positioning/qgeopositioninfosourcefactory.h b/src/positioning/qgeopositioninfosourcefactory.h new file mode 100644 index 00000000..32e0bc00 --- /dev/null +++ b/src/positioning/qgeopositioninfosourcefactory.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCEFACTORY_H +#define QGEOPOSITIONINFOSOURCEFACTORY_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Q_POSITIONING_EXPORT QGeoPositionInfoSourceFactory +{ +public: + virtual ~QGeoPositionInfoSourceFactory(); + + virtual QGeoPositionInfoSource *positionInfoSource(QObject *parent) = 0; + virtual QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent) = 0; + virtual QGeoAreaMonitor *areaMonitor(QObject *parent) = 0; +}; + +#define QT_POSITION_SOURCE_INTERFACE +Q_DECLARE_INTERFACE(QGeoPositionInfoSourceFactory, + "org.qt-project.qt.position.sourcefactory/5.0") + +QT_END_NAMESPACE + +#endif // QGEOPOSITIONINFOSOURCEFACTORY_H diff --git a/src/positioning/qgeorectangle.cpp b/src/positioning/qgeorectangle.cpp new file mode 100644 index 00000000..354bdb1c --- /dev/null +++ b/src/positioning/qgeorectangle.cpp @@ -0,0 +1,899 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeorectangle.h" +#include "qgeorectangle_p.h" + +#include "qgeocoordinate.h" +#include "qnumeric.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QGeoRectangle + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \since Qt Positioning 5.0 + + \brief The QGeoRectangle class defines a rectangular geographic area. + + The rectangle is defined in terms of a QGeoCoordinate which specifies the + top left coordinate of the rectangle and a QGeoCoordinate which specifies + the bottom right coordinate of the rectangle. + + A geo rectangle is considered invalid if the top left or bottom right + coordinates are invalid or if the top left coordinate is south of the + bottom right coordinate. + + Geo rectangles can never cross the poles. + + Several methods behave as though the geo rectangle is defined in terms of a + center coordinate, the width of the geo rectangle in degrees and the height + of the geo rectangle in degrees. + + If the height or center of a geo rectangle is adjusted such that it would + cross one of the poles the height is modified such that the geo rectangle + touches but does not cross the pole and that the center coordinate is still + in the center of the geo rectangle. +*/ + +#ifdef Q_NO_USING_KEYWORD +/*! + \fn bool QGeoRectangle::operator==(const QGeoShape &other) const + + Returns true if \a other is equivalent to this geo rectangle; otherwise returns false. +*/ + +/*! + \fn bool QGeoRectangle::operator!=(const QGeoShape &other) const + + Returns true if \a other is not equivalent to this geo rectangle; otherwise returns false. +*/ + +/*! + \fn bool QGeoRectangle::contains(const QGeoCoordinate &coordinate) const + + Returns true if \a coordinate is within this geo rectangle; otherwise returns false. +*/ +#endif + +inline QGeoRectanglePrivate *QGeoRectangle::d_func() +{ + return static_cast(d_ptr.data()); +} + +inline const QGeoRectanglePrivate *QGeoRectangle::d_func() const +{ + return static_cast(d_ptr.constData()); +} + +/*! + Constructs a new, invalid geo rectangle. +*/ +QGeoRectangle::QGeoRectangle() +: QGeoShape(new QGeoRectanglePrivate) +{ +} + +/*! + Constructs a new geo rectangle centered at \a center with a + width in degrees of \a degreesWidth and a height in degrees of \a degreesHeight. + + If \a degreesHeight would take the geo rectangle beyond one of the poles, + the height of the geo rectangle will be truncated such that the geo rectangle + only extends up to the pole. The center of the geo rectangle will be + unchanged, and the height will be adjusted such that the center point is at + the center of the truncated geo rectangle. +*/ +QGeoRectangle::QGeoRectangle(const QGeoCoordinate ¢er, double degreesWidth, double degreesHeight) +{ + d_ptr = new QGeoRectanglePrivate(center, center); + setWidth(degreesWidth); + setHeight(degreesHeight); +} + +/*! + Constructs a new geo rectangle with a top left coordinate \a topLeft and a bottom right + coordinate \a bottomRight. +*/ +QGeoRectangle::QGeoRectangle(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight) +{ + d_ptr = new QGeoRectanglePrivate(topLeft, bottomRight); +} + +/*! + Constructs a geo rectangle from the contents of \a other. +*/ +QGeoRectangle::QGeoRectangle(const QGeoRectangle &other) +: QGeoShape(other) +{ +} + +/*! + Constructs a geo rectangle from the contents of \a other. +*/ +QGeoRectangle::QGeoRectangle(const QGeoShape &other) +: QGeoShape(other) +{ + if (type() != QGeoShape::RectangleType) + d_ptr = new QGeoRectanglePrivate; +} + +/*! + Destroys this geo rectangle. +*/ +QGeoRectangle::~QGeoRectangle() +{ +} + +/*! + Assigns \a other to this geo rectangle and returns a reference to this geo rectangle. +*/ +QGeoRectangle &QGeoRectangle::operator=(const QGeoRectangle &other) +{ + QGeoShape::operator=(other); + return *this; +} + +/*! + Returns whether this geo rectangle is equal to \a other. +*/ +bool QGeoRectangle::operator==(const QGeoRectangle &other) const +{ + Q_D(const QGeoRectangle); + + return *d == *other.d_func(); +} + +/*! + Returns whether this geo rectangle is not equal to \a other. +*/ +bool QGeoRectangle::operator!=(const QGeoRectangle &other) const +{ + Q_D(const QGeoRectangle); + + return !(*d == *other.d_func()); +} + +bool QGeoRectanglePrivate::isValid() const +{ + return topLeft.isValid() && bottomRight.isValid() && + topLeft.latitude() >= bottomRight.latitude(); +} + +bool QGeoRectanglePrivate::isEmpty() const +{ + if (!isValid()) + return true; + + return topLeft.latitude() == bottomRight.latitude() || + topLeft.longitude() == bottomRight.longitude(); +} + +/*! + Sets the top left coordinate of this geo rectangle to \a topLeft. +*/ +void QGeoRectangle::setTopLeft(const QGeoCoordinate &topLeft) +{ + Q_D(QGeoRectangle); + + d->topLeft = topLeft; +} + +/*! + Returns the top left coordinate of this geo rectangle. +*/ +QGeoCoordinate QGeoRectangle::topLeft() const +{ + Q_D(const QGeoRectangle); + + return d->topLeft; +} + +/*! + Sets the top right coordinate of this geo rectangle to \a topRight. +*/ +void QGeoRectangle::setTopRight(const QGeoCoordinate &topRight) +{ + Q_D(QGeoRectangle); + + d->topLeft.setLatitude(topRight.latitude()); + d->bottomRight.setLongitude(topRight.longitude()); +} + +/*! + Returns the top right coordinate of this geo rectangle. +*/ +QGeoCoordinate QGeoRectangle::topRight() const +{ + // TODO remove? + if (!isValid()) + return QGeoCoordinate(); + + Q_D(const QGeoRectangle); + + return QGeoCoordinate(d->topLeft.latitude(), d->bottomRight.longitude()); +} + +/*! + Sets the bottom left coordinate of this geo rectangle to \a bottomLeft. +*/ +void QGeoRectangle::setBottomLeft(const QGeoCoordinate &bottomLeft) +{ + Q_D(QGeoRectangle); + + d->bottomRight.setLatitude(bottomLeft.latitude()); + d->topLeft.setLongitude(bottomLeft.longitude()); +} + +/*! + Returns the bottom left coordinate of this geo rectangle. +*/ +QGeoCoordinate QGeoRectangle::bottomLeft() const +{ + // TODO remove? + if (!isValid()) + return QGeoCoordinate(); + + Q_D(const QGeoRectangle); + + return QGeoCoordinate(d->bottomRight.latitude(), d->topLeft.longitude()); +} + +/*! + Sets the bottom right coordinate of this geo rectangle to \a bottomRight. +*/ +void QGeoRectangle::setBottomRight(const QGeoCoordinate &bottomRight) +{ + Q_D(QGeoRectangle); + + d->bottomRight = bottomRight; +} + +/*! + Returns the bottom right coordinate of this geo rectangle. +*/ +QGeoCoordinate QGeoRectangle::bottomRight() const +{ + Q_D(const QGeoRectangle); + + return d->bottomRight; +} + +/*! + Sets the center of this geo rectangle to \a center. + + If this causes the geo rectangle to cross on of the poles the height of the + geo rectangle will be truncated such that the geo rectangle only extends up + to the pole. The center of the geo rectangle will be unchanged, and the + height will be adjusted such that the center point is at the center of the + truncated geo rectangle. + +*/ +void QGeoRectangle::setCenter(const QGeoCoordinate ¢er) +{ + Q_D(QGeoRectangle); + + if (!isValid()) { + d->topLeft = center; + d->bottomRight = center; + return; + } + double width = this->width(); + double height = this->height(); + + double tlLat = center.latitude() + height / 2.0; + double tlLon = center.longitude() - width / 2.0; + double brLat = center.latitude() - height / 2.0; + double brLon = center.longitude() + width / 2.0; + + if (tlLon < -180.0) + tlLon += 360.0; + if (tlLon > 180.0) + tlLon -= 360.0; + + if (brLon < -180.0) + brLon += 360.0; + if (brLon > 180.0) + brLon -= 360.0; + + if (tlLat > 90.0) { + brLat = 2 * center.latitude() - 90.0; + tlLat = 90.0; + } + + if (tlLat < -90.0) { + brLat = -90.0; + tlLat = -90.0; + } + + if (brLat > 90.0) { + tlLat = 90.0; + brLat = 90.0; + } + + if (brLat < -90.0) { + tlLat = 2 * center.latitude() + 90.0; + brLat = -90.0; + } + + if (width == 360.0) { + tlLon = -180.0; + brLon = 180.0; + } + + d->topLeft = QGeoCoordinate(tlLat, tlLon); + d->bottomRight = QGeoCoordinate(brLat, brLon); +} + +/*! + Returns the center of this geo rectangle. +*/ +QGeoCoordinate QGeoRectangle::center() const +{ + if (!isValid()) + return QGeoCoordinate(); + + Q_D(const QGeoRectangle); + + double cLat = (d->topLeft.latitude() + d->bottomRight.latitude()) / 2.0; + + double cLon = (d->bottomRight.longitude() + d->topLeft.longitude()) / 2.0; + if (d->topLeft.longitude() > d->bottomRight.longitude()) { + cLon = cLon - 180.0; + } + + if (cLon < -180.0) + cLon += 360.0; + if (cLon > 180.0) + cLon -= 360.0; + + return QGeoCoordinate(cLat, cLon); +} + +/*! + Sets the width of this geo rectangle in degrees to \a degreesWidth. + + If \a degreesWidth is less than 0.0 or if this geo rectangle is invalid this + function does nothing. To set up the values of an invalid + geo rectangle based on the center, width and height you should use + setCenter() first in order to make the geo rectangle valid. + + If \a degreesWidth is greater than 360.0 then 360.0 is used as the width, + the leftmost longitude of the geo rectangle is set to -180.0 degrees and the + rightmost longitude of the geo rectangle is set to 180.0 degrees. +*/ +void QGeoRectangle::setWidth(double degreesWidth) +{ + if (!isValid()) + return; + + if (degreesWidth < 0.0) + return; + + Q_D(QGeoRectangle); + + if (degreesWidth >= 360.0) { + d->topLeft.setLongitude(-180.0); + d->bottomRight.setLongitude(180.0); + return; + } + + double tlLat = d->topLeft.latitude(); + double brLat = d->bottomRight.latitude(); + + QGeoCoordinate c = center(); + + double tlLon = c.longitude() - degreesWidth / 2.0; + + if (tlLon < -180.0) + tlLon += 360.0; + if (tlLon > 180.0) + tlLon -= 360.0; + + double brLon = c.longitude() + degreesWidth / 2.0; + + if (brLon < -180.0) + brLon += 360.0; + if (brLon > 180.0) + brLon -= 360.0; + + d->topLeft = QGeoCoordinate(tlLat, tlLon); + d->bottomRight = QGeoCoordinate(brLat, brLon); +} + +/*! + Returns the width of this geo rectangle in degrees. + + The return value is undefined if this geo rectangle is invalid. +*/ +double QGeoRectangle::width() const +{ + if (!isValid()) + return qQNaN(); + + Q_D(const QGeoRectangle); + + double result = d->bottomRight.longitude() - d->topLeft.longitude(); + if (result < 0.0) + result += 360.0; + if (result > 360.0) + result -= 360.0; + + return result; +} + +/*! + Sets the height of this geo rectangle in degrees to \a degreesHeight. + + If \a degreesHeight is less than 0.0 or if this geo rectangle is invalid + this function does nothing. To set up the values of an invalid + geo rectangle based on the center, width and height you should use + setCenter() first in order to make the geo rectangle valid. + + If the change in height would cause the geo rectangle to cross a pole + the height is adjusted such that the geo rectangle only touches the pole. + + This change is done such that the center coordinate is still at the + center of the geo rectangle, which may result in a geo rectangle with + a smaller height than might otherwise be expected. + + If \a degreesHeight is greater than 180.0 then 180.0 is used as the height. +*/ +void QGeoRectangle::setHeight(double degreesHeight) +{ + if (!isValid()) + return; + + if (degreesHeight < 0.0) + return; + + if (degreesHeight >= 180.0) { + degreesHeight = 180.0; + } + + Q_D(QGeoRectangle); + + double tlLon = d->topLeft.longitude(); + double brLon = d->bottomRight.longitude(); + + QGeoCoordinate c = center(); + + double tlLat = c.latitude() + degreesHeight / 2.0; + double brLat = c.latitude() - degreesHeight / 2.0; + + if (tlLat > 90.0) { + brLat = 2* c.latitude() - 90.0; + tlLat = 90.0; + } + + if (tlLat < -90.0) { + brLat = -90.0; + tlLat = -90.0; + } + + if (brLat > 90.0) { + tlLat = 90.0; + brLat = 90.0; + } + + if (brLat < -90.0) { + tlLat = 2 * c.latitude() + 90.0; + brLat = -90.0; + } + + d->topLeft = QGeoCoordinate(tlLat, tlLon); + d->bottomRight = QGeoCoordinate(brLat, brLon); +} + +/*! + Returns the height of this geo rectangle in degrees. + + The return value is undefined if this geo rectangle is invalid. +*/ +double QGeoRectangle::height() const +{ + if (!isValid()) + return qQNaN(); + + Q_D(const QGeoRectangle); + + double result = d->topLeft.latitude() - d->bottomRight.latitude(); + if (result < 0.0) + result = qQNaN(); + return result; +} + +bool QGeoRectanglePrivate::contains(const QGeoCoordinate &coordinate) const +{ + if (!isValid() || !coordinate.isValid()) + return false; + + double left = topLeft.longitude(); + double right = bottomRight.longitude(); + double top = topLeft.latitude(); + double bottom = bottomRight.latitude(); + + double lon = coordinate.longitude(); + double lat = coordinate.latitude(); + + if (lat > top) + return false; + if (lat < bottom) + return false; + + if ((lat == 90.0) && (top == 90.0)) + return true; + + if ((lat == -90.0) && (bottom == -90.0)) + return true; + + if (left <= right) { + if ((lon < left) || (lon > right)) + return false; + } else { + if ((lon < left) && (lon > right)) + return false; + } + + return true; +} + +/*! + Returns whether the geo rectangle \a rectangle is contained within this + geo rectangle. +*/ +bool QGeoRectangle::contains(const QGeoRectangle &rectangle) const +{ + Q_D(const QGeoRectangle); + + return (d->contains(rectangle.topLeft()) + && d->contains(rectangle.topRight()) + && d->contains(rectangle.bottomLeft()) + && d->contains(rectangle.bottomRight())); +} + +/*! + Returns whether the geo rectangle \a rectangle intersects this geo rectangle. + + If the top or bottom edges of both geo rectangles are at one of the poles + the geo rectangles are considered to be intersecting, since the longitude + is irrelevant when the edges are at the pole. +*/ +bool QGeoRectangle::intersects(const QGeoRectangle &rectangle) const +{ + Q_D(const QGeoRectangle); + + double left1 = d->topLeft.longitude(); + double right1 = d->bottomRight.longitude(); + double top1 = d->topLeft.latitude(); + double bottom1 = d->bottomRight.latitude(); + + double left2 = rectangle.d_func()->topLeft.longitude(); + double right2 = rectangle.d_func()->bottomRight.longitude(); + double top2 = rectangle.d_func()->topLeft.latitude(); + double bottom2 = rectangle.d_func()->bottomRight.latitude(); + + if (top1 < bottom2) + return false; + + if (bottom1 > top2) + return false; + + if ((top1 == 90.0) && (top1 == top2)) + return true; + + if ((bottom1 == -90.0) && (bottom1 == bottom2)) + return true; + + if (left1 < right1) { + if (left2 < right2) { + if ((left1 > right2) || (right1 < left2)) + return false; + } else { + if ((left1 > right2) && (right1 < left2)) + return false; + } + } else { + if (left2 < right2) { + if ((left2 > right1) && (right2 < left1)) + return false; + } else { + // if both wrap then they have to intersect + } + } + + return true; +} + +/*! + Translates this geo rectangle by \a degreesLatitude northwards and \a + degreesLongitude eastwards. + + Negative values of \a degreesLatitude and \a degreesLongitude correspond to + southward and westward translation respectively. + + If the translation would have caused the geo rectangle to cross a pole the + geo rectangle will be translated until the top or bottom edge of the geo rectangle + touches the pole but not further. +*/ +void QGeoRectangle::translate(double degreesLatitude, double degreesLongitude) +{ + // TODO handle dlat, dlon larger than 360 degrees + + Q_D(QGeoRectangle); + + double tlLat = d->topLeft.latitude(); + double tlLon = d->topLeft.longitude(); + double brLat = d->bottomRight.latitude(); + double brLon = d->bottomRight.longitude(); + + if ((tlLat != 90.0) || (brLat != -90.0)) { + tlLat += degreesLatitude; + brLat += degreesLatitude; + } + + if ( (tlLon != -180.0) || (brLon != 180.0) ) { + tlLon += degreesLongitude; + brLon += degreesLongitude; + } + + if (tlLon < -180.0) + tlLon += 360.0; + if (tlLon > 180.0) + tlLon -= 360.0; + + if (brLon < -180.0) + brLon += 360.0; + if (brLon > 180.0) + brLon -= 360.0; + + if (tlLat > 90.0) + tlLat = 90.0; + + if (tlLat < -90.0) + tlLat = -90.0; + + if (brLat > 90.0) + brLat = 90.0; + + if (brLat < -90.0) + brLat = -90.0; + + d->topLeft = QGeoCoordinate(tlLat, tlLon); + d->bottomRight = QGeoCoordinate(brLat, brLon); +} + +/*! + Returns a copy of this geo rectangle translated by \a degreesLatitude northwards and \a + degreesLongitude eastwards. + + Negative values of \a degreesLatitude and \a degreesLongitude correspond to + southward and westward translation respectively. + + \sa translate() +*/ +QGeoRectangle QGeoRectangle::translated(double degreesLatitude, double degreesLongitude) const +{ + QGeoRectangle result(*this); + result.translate(degreesLatitude, degreesLongitude); + return result; +} + +/*! + Returns the smallest geo rectangle which contains both this geo rectangle and \a rectangle. + + If the centers of the two geo rectangles are separated by exactly 180.0 degrees then the + width is set to 360.0 degrees with the leftmost longitude set to -180.0 degrees and the + rightmost longitude set to 180.0 degrees. This is done to ensure that the result is + independent of the order of the operands. + +*/ +QGeoRectangle QGeoRectangle::united(const QGeoRectangle &rectangle) const +{ + QGeoRectangle result(*this); + result |= rectangle; + return result; +} + +/*! + \fn QGeoRectangle QGeoRectangle::operator|(const QGeoRectangle &rectangle) const + + Returns the smallest geo rectangle which contains both this geo rectangle and \a rectangle. + + If the centers of the two geo rectangles are separated by exactly 180.0 degrees then the + width is set to 360.0 degrees with the leftmost longitude set to -180.0 degrees and the + rightmost longitude set to 180.0 degrees. This is done to ensure that the result is + independent of the order of the operands. + +*/ + +/*! + Returns the smallest geo rectangle which contains both this geo rectangle and \a rectangle. + + If the centers of the two geo rectangles are separated by exactly 180.0 degrees then the + width is set to 360.0 degrees with the leftmost longitude set to -180.0 degrees and the + rightmost longitude set to 180.0 degrees. This is done to ensure that the result is + independent of the order of the operands. + +*/ +QGeoRectangle &QGeoRectangle::operator|=(const QGeoRectangle &rectangle) +{ + // If non-intersecting goes for most narrow box + + Q_D(QGeoRectangle); + + double left1 = d->topLeft.longitude(); + double right1 = d->bottomRight.longitude(); + double top1 = d->topLeft.latitude(); + double bottom1 = d->bottomRight.latitude(); + + double left2 = rectangle.d_func()->topLeft.longitude(); + double right2 = rectangle.d_func()->bottomRight.longitude(); + double top2 = rectangle.d_func()->topLeft.latitude(); + double bottom2 = rectangle.d_func()->bottomRight.latitude(); + + double top = qMax(top1, top2); + double bottom = qMin(bottom1, bottom2); + + double left = 0.0; + double right = 0.0; + + bool wrap1 = (left1 > right1); + bool wrap2 = (left2 > right2); + + if ((wrap1 && wrap2) || (!wrap1 && !wrap2)) { + + double w = qAbs((left1 + right1 - left2 - right2) / 2.0); + + if (w < 180.0) { + left = qMin(left1, left2); + right = qMax(right1, right2); + } else if (w > 180.0) { + left = qMax(left1, left2); + right = qMin(right1, right2); + } else { + left = -180.0; + right = 180.0; + } + + } else { + double wrapLeft = 0.0; + double wrapRight = 0.0; + double nonWrapLeft = 0.0; + double nonWrapRight = 0.0; + + if (wrap1) { + wrapLeft = left1; + wrapRight = right1; + nonWrapLeft = left2; + nonWrapRight = right2; + } else { + wrapLeft = left2; + wrapRight = right2; + nonWrapLeft = left1; + nonWrapRight = right1; + } + + bool joinWrapLeft = (nonWrapRight >= wrapLeft); + bool joinWrapRight = (nonWrapLeft <= wrapRight); + + if (joinWrapLeft) { + if (joinWrapRight) { + left = -180.0; + right = 180.0; + } else { + left = nonWrapLeft; + right = wrapRight; + } + } else { + if (joinWrapRight) { + left = wrapLeft; + right = nonWrapRight; + } else { + double wrapRightDistance = nonWrapLeft - wrapRight; + double wrapLeftDistance = wrapLeft - nonWrapRight; + + if (wrapLeftDistance == wrapRightDistance) { + left = -180.0; + right = 180.0; + } else if (wrapLeftDistance < wrapRightDistance) { + left = nonWrapLeft; + right = wrapRight; + } else { + left = wrapLeft; + right = nonWrapRight; + } + } + } + } + + if (((left1 == -180) && (right1 == 180.0)) + || ((left2 == -180) && (right2 == 180.0))) { + left = -180; + right = 180; + } + + d->topLeft = QGeoCoordinate(top, left); + d->bottomRight = QGeoCoordinate(bottom, right); + + return *this; +} + +/******************************************************************************* +*******************************************************************************/ + +QGeoRectanglePrivate::QGeoRectanglePrivate() +: QGeoShapePrivate(QGeoShape::RectangleType) +{ +} + +QGeoRectanglePrivate::QGeoRectanglePrivate(const QGeoCoordinate &topLeft, + const QGeoCoordinate &bottomRight) +: QGeoShapePrivate(QGeoShape::RectangleType), topLeft(topLeft), bottomRight(bottomRight) +{ +} + +QGeoRectanglePrivate::QGeoRectanglePrivate(const QGeoRectanglePrivate &other) +: QGeoShapePrivate(QGeoShape::RectangleType), topLeft(other.topLeft), + bottomRight(other.bottomRight) +{ +} + +QGeoRectanglePrivate::~QGeoRectanglePrivate() {} + +QGeoShapePrivate *QGeoRectanglePrivate::clone() const +{ + return new QGeoRectanglePrivate(*this); +} + +bool QGeoRectanglePrivate::operator==(const QGeoShapePrivate &other) const +{ + if (!QGeoShapePrivate::operator==(other)) + return false; + + const QGeoRectanglePrivate &otherBox = static_cast(other); + + return topLeft == otherBox.topLeft && bottomRight == otherBox.bottomRight; +} + +QT_END_NAMESPACE + diff --git a/src/positioning/qgeorectangle.h b/src/positioning/qgeorectangle.h new file mode 100644 index 00000000..cd91c1d7 --- /dev/null +++ b/src/positioning/qgeorectangle.h @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEORECTANGLE_H +#define QGEORECTANGLE_H + +#include + +QT_BEGIN_NAMESPACE + +class QGeoCoordinate; +class QGeoRectanglePrivate; + +class Q_POSITIONING_EXPORT QGeoRectangle : public QGeoShape +{ +public: + QGeoRectangle(); + QGeoRectangle(const QGeoCoordinate ¢er, double degreesWidth, double degreesHeight); + QGeoRectangle(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight); + QGeoRectangle(const QGeoRectangle &other); + QGeoRectangle(const QGeoShape &other); + + ~QGeoRectangle(); + + QGeoRectangle &operator=(const QGeoRectangle &other); + +#ifdef Q_NO_USING_KEYWORD + bool operator==(const QGeoShape &other) const + { + return QGeoShape::operator==(other); + } +#else + using QGeoShape::operator==; +#endif + bool operator==(const QGeoRectangle &other) const; + +#ifdef Q_NO_USING_KEYWORD + bool operator!=(const QGeoShape &other) const + { + return QGeoShape::operator!=(other); + } +#else + using QGeoShape::operator!=; +#endif + bool operator!=(const QGeoRectangle &other) const; + + void setTopLeft(const QGeoCoordinate &topLeft); + QGeoCoordinate topLeft() const; + + void setTopRight(const QGeoCoordinate &topRight); + QGeoCoordinate topRight() const; + + void setBottomLeft(const QGeoCoordinate &bottomLeft); + QGeoCoordinate bottomLeft() const; + + void setBottomRight(const QGeoCoordinate &bottomRight); + QGeoCoordinate bottomRight() const; + + void setCenter(const QGeoCoordinate ¢er); + QGeoCoordinate center() const; + + void setWidth(double degreesWidth); + double width() const; + + void setHeight(double degreesHeight); + double height() const; + +#ifdef Q_NO_USING_KEYWORD + bool contains(const QGeoCoordinate &coordinate) const + { + return QGeoShape::contains(coordinate); + } +#else + using QGeoShape::contains; +#endif + bool contains(const QGeoRectangle &rectangle) const; + bool intersects(const QGeoRectangle &rectangle) const; + + void translate(double degreesLatitude, double degreesLongitude); + QGeoRectangle translated(double degreesLatitude, double degreesLongitude) const; + + QGeoRectangle united(const QGeoRectangle &rectangle) const; + QGeoRectangle operator|(const QGeoRectangle &rectangle) const; + QGeoRectangle &operator|=(const QGeoRectangle &rectangle); + +private: + inline QGeoRectanglePrivate *d_func(); + inline const QGeoRectanglePrivate *d_func() const; +}; + +Q_DECLARE_TYPEINFO(QGeoRectangle, Q_MOVABLE_TYPE); + +inline QGeoRectangle QGeoRectangle::operator|(const QGeoRectangle &rectangle) const +{ + return united(rectangle); +} + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QGeoRectangle) + +#endif + diff --git a/src/positioning/qgeorectangle_p.h b/src/positioning/qgeorectangle_p.h new file mode 100644 index 00000000..136d4be4 --- /dev/null +++ b/src/positioning/qgeorectangle_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEORECTANGLE_P_H +#define QGEORECTANGLE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qgeoshape_p.h" +#include "qgeocoordinate.h" + +QT_BEGIN_NAMESPACE + +class QGeoRectanglePrivate : public QGeoShapePrivate +{ +public: + QGeoRectanglePrivate(); + QGeoRectanglePrivate(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight); + QGeoRectanglePrivate(const QGeoRectanglePrivate &other); + ~QGeoRectanglePrivate(); + + bool isValid() const; + bool isEmpty() const; + bool contains(const QGeoCoordinate &coordinate) const; + + QGeoShapePrivate *clone() const; + + bool operator==(const QGeoShapePrivate &other) const; + + QGeoCoordinate topLeft; + QGeoCoordinate bottomRight; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qgeosatelliteinfo.cpp b/src/positioning/qgeosatelliteinfo.cpp new file mode 100644 index 00000000..1c19f295 --- /dev/null +++ b/src/positioning/qgeosatelliteinfo.cpp @@ -0,0 +1,315 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qgeosatelliteinfo.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QGeoSatelliteInfoPrivate +{ +public: + int signal; + int satId; + QGeoSatelliteInfo::SatelliteSystem system; + QHash doubleAttribs; +}; + + +/*! + \class QGeoSatelliteInfo + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \since Qt Positioning 5.0 + + \brief The QGeoSatelliteInfo class contains basic information about a satellite. + + \sa QGeoSatelliteInfoSource +*/ + +/*! + \enum QGeoSatelliteInfo::Attribute + Defines the attributes for the satellite information. + \value Elevation The elevation of the satellite, in degrees. + \value Azimuth The azimuth to true north, in degrees. +*/ + +/*! + \enum QGeoSatelliteInfo::SatelliteSystem + Defines the GNSS system of the satellite. + \value Undefined Not defined. + \value GPS Global Positioning System (USA). + \value GLONASS Global Positioning System (Russia). + +*/ + + +/*! + Creates a satellite information object. +*/ +QGeoSatelliteInfo::QGeoSatelliteInfo() + : d(new QGeoSatelliteInfoPrivate) +{ + d->signal = -1; + d->satId = -1; + d->system = QGeoSatelliteInfo::Undefined; +} + +/*! + Creates a satellite information object with the values of \a other. +*/ + +QGeoSatelliteInfo::QGeoSatelliteInfo(const QGeoSatelliteInfo &other) + : d(new QGeoSatelliteInfoPrivate) +{ + operator=(other); +} + +/*! + Destroys a satellite information object. +*/ +QGeoSatelliteInfo::~QGeoSatelliteInfo() +{ + delete d; +} + +/*! + Assigns the values from \a other to this object. +*/ +QGeoSatelliteInfo &QGeoSatelliteInfo::operator=(const QGeoSatelliteInfo & other) +{ + if (this == &other) + return *this; + + d->signal = other.d->signal; + d->satId = other.d->satId; + d->system = other.d->system; + d->doubleAttribs = other.d->doubleAttribs; + return *this; +} + +/*! + Returns true if all the information for this satellite + are the same as those of \a other. +*/ +bool QGeoSatelliteInfo::operator==(const QGeoSatelliteInfo &other) const +{ + return d->signal == other.d->signal + && d->satId == other.d->satId + && d->system == other.d->system + && d->doubleAttribs == other.d->doubleAttribs; +} + +/*! + \fn bool QGeoSatelliteInfo::operator!=(const QGeoSatelliteInfo &other) const; + + Returns true if any of the information for this satellite + are not the same as those of \a other. +*/ + + +/*! + Sets the Satellite System (GPS, GLONASS, ...) to \a system. +*/ +void QGeoSatelliteInfo::setSatelliteSystem(SatelliteSystem system) +{ + d->system = system; +} + +/*! + Returns the Satellite System (GPS, GLONASS, ...) +*/ +QGeoSatelliteInfo::SatelliteSystem QGeoSatelliteInfo::satelliteSystem() const +{ + return d->system; +} + +/*! + Sets the satellite identifier number to \a satId. + + The satellite identifier number can be used to identify a satellite inside the satellite system. + For satellite system GPS the satellite identifier number represents the PRN (Pseudo-random noise) number. + For satellite system GLONASS the satellite identifier number represents the slot number. +*/ +void QGeoSatelliteInfo::setSatelliteIdentifier(int satId) +{ + d->satId = satId; +} + +/*! + Returns the satellite identifier number. + + The satellite identifier number can be used to identify a satellite inside the satellite system. + For satellite system GPS the satellite identifier number represents the PRN (Pseudo-random noise) number. + For satellite system GLONASS the satellite identifier number represents the slot number. +*/ +int QGeoSatelliteInfo::satelliteIdentifier() const +{ + return d->satId; +} + +/*! + Sets the signal strength to \a signalStrength, in decibels. +*/ +void QGeoSatelliteInfo::setSignalStrength(int signalStrength) +{ + d->signal = signalStrength; +} + +/*! + Returns the signal strength, or -1 if the value has not been set. +*/ +int QGeoSatelliteInfo::signalStrength() const +{ + return d->signal; +} + +/*! + Sets the value for \a attribute to \a value. +*/ +void QGeoSatelliteInfo::setAttribute(Attribute attribute, qreal value) +{ + d->doubleAttribs[int(attribute)] = value; +} + +/*! + Returns the value of the specified \a attribute as a qreal value. + + Returns -1 if the value has not been set. + + \sa hasAttribute(), setAttribute() +*/ +qreal QGeoSatelliteInfo::attribute(Attribute attribute) const +{ + if (d->doubleAttribs.contains(int(attribute))) + return d->doubleAttribs[int(attribute)]; + return -1; +} + +/*! + Removes the specified \a attribute and its value. +*/ +void QGeoSatelliteInfo::removeAttribute(Attribute attribute) +{ + d->doubleAttribs.remove(int(attribute)); +} + +/*! + Returns true if the specified \a attribute is present in this update. +*/ +bool QGeoSatelliteInfo::hasAttribute(Attribute attribute) const +{ + return d->doubleAttribs.contains(int(attribute)); +} + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QGeoSatelliteInfo &info) +{ + dbg.nospace() << "QGeoSatelliteInfo(system=" << info.d->system; + dbg.nospace() << ", satId=" << info.d->satId; + dbg.nospace() << ", signal-strength=" << info.d->signal; + + + QList attribs = info.d->doubleAttribs.keys(); + for (int i = 0; i < attribs.count(); ++i) { + dbg.nospace() << ", "; + switch (attribs[i]) { + case QGeoSatelliteInfo::Elevation: + dbg.nospace() << "Elevation="; + break; + case QGeoSatelliteInfo::Azimuth: + dbg.nospace() << "Azimuth="; + break; + } + dbg.nospace() << info.d->doubleAttribs[attribs[i]]; + } + dbg.nospace() << ')'; + return dbg; +} +#endif + +#ifndef QT_NO_DATASTREAM +/*! + \fn QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info) + \relates QGeoSatelliteInfo + + Writes the given \a info to the specified \a stream. + + \sa \link datastreamformat.html Format of the QDataStream operators \endlink + +*/ + +QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info) +{ + stream << info.d->signal; + stream << info.d->doubleAttribs; + stream << info.d->satId; + stream << info.d->system; + return stream; +} +#endif + +#ifndef QT_NO_DATASTREAM +/*! + \fn QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info) + \relates QGeoSatelliteInfo + + Reads satellite information from the specified \a stream into the given + \a info. + + \sa \link datastreamformat.html Format of the QDataStream operators \endlink +*/ + +QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info) +{ + int system; + stream >> info.d->signal; + stream >> info.d->doubleAttribs; + stream >> info.d->satId; + stream >> system; + info.d->system = (QGeoSatelliteInfo::SatelliteSystem)system; + return stream; +} +#endif + +QT_END_NAMESPACE diff --git a/src/positioning/qgeosatelliteinfo.h b/src/positioning/qgeosatelliteinfo.h new file mode 100644 index 00000000..fb13157d --- /dev/null +++ b/src/positioning/qgeosatelliteinfo.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QGEOSATELLITEINFO_H +#define QGEOSATELLITEINFO_H + +#include + +QT_BEGIN_NAMESPACE + +class QDebug; +class QDataStream; + +class QGeoSatelliteInfoPrivate; +class Q_POSITIONING_EXPORT QGeoSatelliteInfo +{ +public: + enum Attribute { + Elevation, + Azimuth + }; + + enum SatelliteSystem { + Undefined = 0x00, + GPS = 0x01, + GLONASS = 0x02 + }; + + QGeoSatelliteInfo(); + QGeoSatelliteInfo(const QGeoSatelliteInfo &other); + ~QGeoSatelliteInfo(); + + QGeoSatelliteInfo &operator=(const QGeoSatelliteInfo &other); + + bool operator==(const QGeoSatelliteInfo &other) const; + inline bool operator!=(const QGeoSatelliteInfo &other) const { + return !operator==(other); + } + + void setSatelliteSystem(SatelliteSystem system); + SatelliteSystem satelliteSystem() const; + + void setSatelliteIdentifier(int satId); + int satelliteIdentifier() const; + + void setSignalStrength(int signalStrength); + int signalStrength() const; + + void setAttribute(Attribute attribute, qreal value); + qreal attribute(Attribute attribute) const; + void removeAttribute(Attribute attribute); + + bool hasAttribute(Attribute attribute) const; + +private: +#ifndef QT_NO_DEBUG_STREAM + friend Q_POSITIONING_EXPORT QDebug operator<<(QDebug dbg, const QGeoSatelliteInfo &info); +#endif +#ifndef QT_NO_DATASTREAM + friend Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info); + friend Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info); +#endif + QGeoSatelliteInfoPrivate *d; +}; + +#ifndef QT_NO_DEBUG_STREAM +Q_POSITIONING_EXPORT QDebug operator<<(QDebug dbg, const QGeoSatelliteInfo &info); +#endif + +#ifndef QT_NO_DATASTREAM +Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info); +Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info); +#endif + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qgeosatelliteinfosource.cpp b/src/positioning/qgeosatelliteinfosource.cpp new file mode 100644 index 00000000..faf8dad8 --- /dev/null +++ b/src/positioning/qgeosatelliteinfosource.cpp @@ -0,0 +1,320 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include "qgeopositioninfosourcefactory.h" +#include "qgeopositioninfosource_p.h" +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \class QGeoSatelliteInfoSource + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \since Qt Positioning 5.0 + + \brief The QGeoSatelliteInfoSource class is an abstract base class for the distribution of satellite information updates. + + The static function QGeoSatelliteInfoSource::createDefaultSource() creates a default + satellite data source that is appropriate for the platform, if one is + available. Otherwise, available QGeoPositionInfoSourceFactory plugins will + be checked for one that has a satellite data source available. + + Call startUpdates() and stopUpdates() to start and stop regular updates, + or requestUpdate() to request a single update. + When an update is available, satellitesInViewUpdated() and/or + satellitesInUseUpdated() will be emitted. + + If regular satellite updates are required, setUpdateInterval() can be used + to specify how often these updates should be emitted. If no interval is + specified, updates are simply provided whenever they are available. + For example: + + \code + // Emit updates every 10 seconds if available + QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(0); + if (source) + source->setUpdateInterval(10000); + \endcode + + To remove an update interval that was previously set, call + setUpdateInterval() with a value of 0. + + Note that the satellite source may have a minimum value requirement for + update intervals, as returned by minimumUpdateInterval(). + + \warning On Windows CE it is not possible to detect if a device is GPS enabled. + The default satellite source on a Windows CE device without GPS support will never provide any satellite data. +*/ + +class QGeoSatelliteInfoSourcePrivate +{ +public: + int interval; +}; + +/*! + Creates a satellite source with the specified \a parent. +*/ +QGeoSatelliteInfoSource::QGeoSatelliteInfoSource(QObject *parent) + : QObject(parent), + d(new QGeoSatelliteInfoSourcePrivate) +{ + d->interval = 0; +} + +/*! + Destroys the satellite source. +*/ +QGeoSatelliteInfoSource::~QGeoSatelliteInfoSource() +{ + delete d; +} + +/*! + \property QGeoSatelliteInfoSource::updateInterval + \brief This property holds the requested interval in milliseconds between each update. + + If the update interval is not set (or is set to 0) the + source will provide updates as often as necessary. + + If the update interval is set, the source will provide updates at an + interval as close to the requested interval as possible. If the requested + interval is less than the minimumUpdateInterval(), + the minimum interval is used instead. + + Changes to the update interval will happen as soon as is practical, however the + time the change takes may vary between implementations. Whether or not the elapsed + time from the previous interval is counted as part of the new interval is also + implementation dependent. + + The default value for this property is 0. + + Note: Subclass implementations must call the base implementation of + setUpdateInterval() so that updateInterval() returns the correct value. +*/ +void QGeoSatelliteInfoSource::setUpdateInterval(int msec) +{ + d->interval = msec; +} + +int QGeoSatelliteInfoSource::updateInterval() const +{ + return d->interval; +} + + + +/*! + Creates and returns a source with the specified \a parent that reads + from the system's default source of satellite update information, or the + highest priority available plugin. + + Returns 0 if the system has no default position source, no valid plugins + could be found or the user does not have the permission to access the satellite data. +*/ +QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createDefaultSource(QObject *parent) +{ + QList plugins = QGeoPositionInfoSourcePrivate::pluginsSorted(); + foreach (const QJsonObject &obj, plugins) { + if (obj.value(QStringLiteral("Satellite")).isBool() + && obj.value(QStringLiteral("Satellite")).toBool()) + { + QGeoPositionInfoSourcePrivate d; + d.metaData = obj; + d.loadPlugin(); + QGeoSatelliteInfoSource *s = 0; + if (d.factory) + s = d.factory->satelliteInfoSource(parent); + return s; + } + } + + return 0; +} + +/*! + Creates and returns a source with the given \a parent, + by loading the plugin named \a sourceName. + + Returns 0 if the plugin cannot be found. +*/ +QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createSource(const QString &sourceName, QObject *parent) +{ + QHash plugins = QGeoPositionInfoSourcePrivate::plugins(); + if (plugins.contains(sourceName)) { + QGeoPositionInfoSourcePrivate d; + d.metaData = plugins.value(sourceName); + d.loadPlugin(); + QGeoSatelliteInfoSource *src = 0; + if (d.factory) + src = d.factory->satelliteInfoSource(parent); + return src; + } + + return 0; +} + +/*! + Returns a list of available source plugins, including the default system + backend if one is available. +*/ +QStringList QGeoSatelliteInfoSource::availableSources() +{ + QStringList plugins; + QHash meta = QGeoPositionInfoSourcePrivate::plugins(); + foreach (const QString &name, meta.keys()) { + if (meta.value(name).value(QStringLiteral("Satellite")).isBool() + && meta.value(name).value(QStringLiteral("Satellite")).toBool()) { + plugins << name; + } + } + + return plugins; +} + +/*! + \fn void QGeoSatelliteInfoSource::satellitesInViewUpdated(const QList &satellites); + + If startUpdates() or requestUpdate() is called, this signal is emitted + when an update is available on the satellites that are + currently in view. + + The \a satellites parameter holds the satellites currently in view. +*/ + +/*! + \fn void QGeoSatelliteInfoSource::satellitesInUseUpdated(const QList &satellites); + + If startUpdates() or requestUpdate() is called, this signal is emitted + when an update is available on the number of satellites that are + currently in use. + + These are the satellites that are used to get a "fix" - that + is, those used to determine the current position. + + The \a satellites parameter holds the satellites currently in use. +*/ + +/*! + \property QGeoSatelliteInfoSource::minimumUpdateInterval + \brief This property holds the minimum time (in milliseconds) required to retrieve a satellite update. + + This is the minimum value accepted by setUpdateInterval() and + requestUpdate(). +*/ + + +/*! + \fn virtual void QGeoSatelliteInfoSource::startUpdates() = 0; + + Starts emitting updates at regular intervals. The updates will be + provided whenever new satellite information becomes available. + + \sa satellitesInViewUpdated(), satellitesInUseUpdated() +*/ + +/*! + \fn virtual void QGeoSatelliteInfoSource::stopUpdates() = 0; + + Stops emitting updates at regular intervals. +*/ + +/*! + \fn virtual void QGeoSatelliteInfoSource::requestUpdate(int timeout = 0); + + Attempts to get the current satellite information and emit + satellitesInViewUpdated() and satellitesInUseUpdated() with this + information. If the current position cannot be found + within the given \a timeout (in milliseconds) or if \a timeout is less than the value returned by + minimumUpdateInterval(), requestTimeout() is + emitted. + + If the timeout is zero, the timeout defaults to a reasonable timeout + period as appropriate for the source. + + This does nothing if another update request is in progress. However + it can be called even if startUpdates() has already been called and + regular updates are in progress. +*/ + +/*! + \fn void QGeoSatelliteInfoSource::requestTimeout(); + + Emitted if requestUpdate() was called and the current satellite + information could not be retrieved within the specified timeout. +*/ + +/*! + \fn QGeoSatelliteInfoSource::Error QGeoSatelliteInfoSource::error() const = 0 + + Returns the last error that occurred. +*/ + +/*! + \fn void QGeoSatelliteInfoSource::error(QGeoSatelliteInfoSource::Error satelliteError) + + This signal is emitted after an error occurred. The \a satelliteError + parameter describes the type of error that occurred. + +*/ + +/*! + \enum QGeoSatelliteInfoSource::Error + + The Error enumeration represents the errors which can occur. + + \value AccessError The connection setup to the remote positioning backend failed because the + application lacked the required privileges. + \value ClosedError The remote satellite backend closed the connection, which happens for example in case + the user is switching location services to off. This object becomes invalid and should be deleted. + A new satellite source can be created by calling createDefaultSource() later on. + \value UnknownSourceError An unidentified error occurred. + */ + + +#include "moc_qgeosatelliteinfosource.cpp" + +QT_END_NAMESPACE diff --git a/src/positioning/qgeosatelliteinfosource.h b/src/positioning/qgeosatelliteinfosource.h new file mode 100644 index 00000000..35aa2b33 --- /dev/null +++ b/src/positioning/qgeosatelliteinfosource.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QGEOSATELLITEINFOSOURCE_H +#define QGEOSATELLITEINFOSOURCE_H + +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +class QGeoSatelliteInfoSourcePrivate; +class Q_POSITIONING_EXPORT QGeoSatelliteInfoSource : public QObject +{ + Q_OBJECT + Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval) + Q_PROPERTY(int minimumUpdateInterval READ minimumUpdateInterval) + +public: + enum Error { + AccessError, + ClosedError, /* 1 */ + UnknownSourceError = -1 + }; + Q_ENUMS(Error) + + explicit QGeoSatelliteInfoSource(QObject *parent); + virtual ~QGeoSatelliteInfoSource(); + + static QGeoSatelliteInfoSource *createDefaultSource(QObject *parent); + static QGeoSatelliteInfoSource *createSource(const QString &sourceName, QObject *parent); + static QStringList availableSources(); + + virtual void setUpdateInterval(int msec); + int updateInterval() const; + virtual int minimumUpdateInterval() const = 0; + virtual Error error() const = 0; + +public Q_SLOTS: + virtual void startUpdates() = 0; + virtual void stopUpdates() = 0; + + virtual void requestUpdate(int timeout = 0) = 0; + +Q_SIGNALS: + void satellitesInViewUpdated(const QList &satellites); + void satellitesInUseUpdated(const QList &satellites); + void requestTimeout(); + void error(QGeoSatelliteInfoSource::Error); + +private: + Q_DISABLE_COPY(QGeoSatelliteInfoSource) + QGeoSatelliteInfoSourcePrivate *d; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qgeoshape.cpp b/src/positioning/qgeoshape.cpp new file mode 100644 index 00000000..53799738 --- /dev/null +++ b/src/positioning/qgeoshape.cpp @@ -0,0 +1,307 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeoshape.h" +#include "qgeoshape_p.h" +#include "qgeorectangle.h" +#include "qgeocircle.h" + +#ifndef QT_NO_DEBUG_STREAM +#include +#endif + +#ifndef QT_NO_DATASTREAM +#include +#endif + +QT_BEGIN_NAMESPACE + +QGeoShapePrivate::QGeoShapePrivate(QGeoShape::ShapeType type) +: type(type) +{ +} + +QGeoShapePrivate::~QGeoShapePrivate() +{ +} + +bool QGeoShapePrivate::operator==(const QGeoShapePrivate &other) const +{ + return type == other.type; +} + +/*! + \class QGeoShape + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \since Qt Positioning 5.0 + + \brief The QGeoShape class defines a geographic area. + + This class is the base class for classes which specify a geographic + area. + + For the sake of consistency, subclasses should describe the specific + details of the associated areas in terms of QGeoCoordinate instances + and distances in meters. +*/ + +/*! + \enum QGeoShape::ShapeType + + Describes the type of the shape. + + \value UnknownType A shape of unknown type. + \value RectangleType A rectangular shape. + \value CircleType A circular shape. +*/ + +inline QGeoShapePrivate *QGeoShape::d_func() +{ + return static_cast(d_ptr.data()); +} + +inline const QGeoShapePrivate *QGeoShape::d_func() const +{ + return static_cast(d_ptr.constData()); +} + +/*! + Constructs a new invalid geo shape of \l UnknownType. +*/ +QGeoShape::QGeoShape() +{ +} + +/*! + Constructs a new geo shape which is a copy of \a other. +*/ +QGeoShape::QGeoShape(const QGeoShape &other) +: d_ptr(other.d_ptr) +{ +} + +/*! + \internal +*/ +QGeoShape::QGeoShape(QGeoShapePrivate *d) +: d_ptr(d) +{ +} + +/*! + Destroys this geo shape. +*/ +QGeoShape::~QGeoShape() +{ +} + +/*! + Returns the type of this geo shape. +*/ +QGeoShape::ShapeType QGeoShape::type() const +{ + Q_D(const QGeoShape); + + if (d) + return d->type; + else + return UnknownType; +} + +/*! + Returns whether this geo shape is valid. + + An geo shape is considered to be invalid if some of the data that is required to + unambiguously describe the geo shape has not been set or has been set to an + unsuitable value. +*/ +bool QGeoShape::isValid() const +{ + Q_D(const QGeoShape); + + if (d) + return d->isValid(); + else + return false; +} + +/*! + Returns whether this geo shape is empty. + + An empty geo shape is a region which has a geometrical area of 0. +*/ +bool QGeoShape::isEmpty() const +{ + Q_D(const QGeoShape); + + if (d) + return d->isEmpty(); + else + return true; +} + +/*! + Returns whether the coordinate \a coordinate is contained within this geo shape. +*/ +bool QGeoShape::contains(const QGeoCoordinate &coordinate) const +{ + Q_D(const QGeoShape); + + if (d) + return d->contains(coordinate); + else + return false; +} + + +/*! + Returns true if the \a other geo shape is equivalent to this geo shape, otherwise returns + false. +*/ +bool QGeoShape::operator==(const QGeoShape &other) const +{ + Q_D(const QGeoShape); + + if (d == other.d_func()) + return true; + + if (!d || !(other.d_func())) + return false; + + return *d == *other.d_func(); +} + +/*! + Returns true if the \a other geo shape is not equivalent to this geo shape, otherwise returns + false. +*/ +bool QGeoShape::operator!=(const QGeoShape &other) const +{ + return !(*this == other); +} + +/*! + Assigns \a other to this geo shape and returns a reference to this geo shape. +*/ +QGeoShape &QGeoShape::operator=(const QGeoShape &other) +{ + if (this == &other) + return *this; + + d_ptr = other.d_ptr; + return *this; +} + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QGeoShape &shape) +{ + //dbg << *shape.d_func(); + dbg.nospace() << "QGeoShape("; + switch (shape.type()) { + case QGeoShape::UnknownType: + dbg.nospace() << "Unknown"; + break; + case QGeoShape::RectangleType: + dbg.nospace() << "Rectangle"; + break; + case QGeoShape::CircleType: + dbg.nospace() << "Circle"; + } + + dbg.nospace() << ')'; + + return dbg; +} +#endif + +#ifndef QT_NO_DATASTREAM +QDataStream &operator<<(QDataStream &stream, const QGeoShape &shape) +{ + stream << quint32(shape.type()); + switch (shape.type()) { + case QGeoShape::UnknownType: + break; + case QGeoShape::RectangleType: { + QGeoRectangle r = shape; + stream << r.topLeft() << r.bottomRight(); + break; + } + case QGeoShape::CircleType: { + QGeoCircle c = shape; + stream << c.center() << c.radius(); + break; + } + } + + return stream; +} + +QDataStream &operator>>(QDataStream &stream, QGeoShape &shape) +{ + quint32 type; + stream >> type; + + switch (type) { + case QGeoShape::UnknownType: + shape = QGeoShape(); + break; + case QGeoShape::RectangleType: { + QGeoCoordinate tl; + QGeoCoordinate br; + stream >> tl >> br; + shape = QGeoRectangle(tl, br); + break; + } + case QGeoShape::CircleType: { + QGeoCoordinate c; + qreal r; + stream >> c >> r; + shape = QGeoCircle(c, r); + break; + } + } + + return stream; +} +#endif + +QT_END_NAMESPACE diff --git a/src/positioning/qgeoshape.h b/src/positioning/qgeoshape.h new file mode 100644 index 00000000..f1cb4cf2 --- /dev/null +++ b/src/positioning/qgeoshape.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOSHAPE_H +#define QGEOSHAPE_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QDebug; +class QGeoShapePrivate; + +class Q_POSITIONING_EXPORT QGeoShape +{ +public: + QGeoShape(); + QGeoShape(const QGeoShape &other); + ~QGeoShape(); + + enum ShapeType { + UnknownType, + RectangleType, + CircleType + }; + + ShapeType type() const; + + bool isValid() const; + bool isEmpty() const; + bool contains(const QGeoCoordinate &coordinate) const; + + bool operator==(const QGeoShape &other) const; + bool operator!=(const QGeoShape &other) const; + + QGeoShape &operator=(const QGeoShape &other); + +protected: + QGeoShape(QGeoShapePrivate *d); + + QSharedDataPointer d_ptr; + +private: + inline QGeoShapePrivate *d_func(); + inline const QGeoShapePrivate *d_func() const; +}; + +Q_DECLARE_TYPEINFO(QGeoShape, Q_MOVABLE_TYPE); + +#ifndef QT_NO_DEBUG_STREAM +Q_POSITIONING_EXPORT QDebug operator<<(QDebug, const QGeoShape &); +#endif + +#ifndef QT_NO_DATASTREAM +Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoShape &shape); +Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoShape &shape); +#endif + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QGeoShape) + +#endif + diff --git a/src/positioning/qgeoshape_p.h b/src/positioning/qgeoshape_p.h new file mode 100644 index 00000000..ec0b8283 --- /dev/null +++ b/src/positioning/qgeoshape_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOSHAPE_P_H +#define QGEOSHAPE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include "qgeoshape.h" + +QT_BEGIN_NAMESPACE + +class QGeoShapePrivate : public QSharedData +{ +public: + explicit QGeoShapePrivate(QGeoShape::ShapeType type); + virtual ~QGeoShapePrivate(); + + virtual bool isValid() const = 0; + virtual bool isEmpty() const = 0; + virtual bool contains(const QGeoCoordinate &coordinate) const = 0; + + virtual QGeoShapePrivate *clone() const = 0; + + virtual bool operator==(const QGeoShapePrivate &other) const; + + QGeoShape::ShapeType type; +}; + +// don't use the copy constructor when detaching from a QSharedDataPointer, use virtual clone() +// call instead. +template <> +Q_INLINE_TEMPLATE QGeoShapePrivate *QSharedDataPointer::clone() +{ + return d->clone(); +} + +QT_END_NAMESPACE + +#endif + diff --git a/src/positioning/qlocationutils.cpp b/src/positioning/qlocationutils.cpp new file mode 100644 index 00000000..5d6cfbb2 --- /dev/null +++ b/src/positioning/qlocationutils.cpp @@ -0,0 +1,357 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qlocationutils_p.h" +#include "qgeopositioninfo.h" + +#include +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +// converts e.g. 15306.0235 from NMEA sentence to 153.100392 +static double qlocationutils_nmeaDegreesToDecimal(double nmeaDegrees) +{ + double deg; + double min = 100.0 * modf(nmeaDegrees / 100.0, °); + return deg + (min / 60.0); +} + +static void qlocationutils_readGga(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) +{ + QByteArray sentence(data, size); + QList parts = sentence.split(','); + QGeoCoordinate coord; + + if (hasFix && parts.count() > 6 && parts[6].count() > 0) + *hasFix = parts[6].toInt() > 0; + + if (parts.count() > 1 && parts[1].count() > 0) { + QTime time; + if (QLocationUtils::getNmeaTime(parts[1], &time)) + info->setTimestamp(QDateTime(QDate(), time, Qt::UTC)); + } + + if (parts.count() > 5 && parts[3].count() == 1 && parts[5].count() == 1) { + double lat; + double lng; + if (QLocationUtils::getNmeaLatLong(parts[2], parts[3][0], parts[4], parts[5][0], &lat, &lng)) { + coord.setLatitude(lat); + coord.setLongitude(lng); + } + } + + if (parts.count() > 9 && parts[9].count() > 0) { + bool hasAlt = false; + double alt = parts[9].toDouble(&hasAlt); + if (hasAlt) + coord.setAltitude(alt); + } + + if (coord.type() != QGeoCoordinate::InvalidCoordinate) + info->setCoordinate(coord); +} + +static void qlocationutils_readGll(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) +{ + QByteArray sentence(data, size); + QList parts = sentence.split(','); + QGeoCoordinate coord; + + if (hasFix && parts.count() > 6 && parts[6].count() > 0) + *hasFix = (parts[6][0] == 'A'); + + if (parts.count() > 5 && parts[5].count() > 0) { + QTime time; + if (QLocationUtils::getNmeaTime(parts[5], &time)) + info->setTimestamp(QDateTime(QDate(), time, Qt::UTC)); + } + + if (parts.count() > 4 && parts[2].count() == 1 && parts[4].count() == 1) { + double lat; + double lng; + if (QLocationUtils::getNmeaLatLong(parts[1], parts[2][0], parts[3], parts[4][0], &lat, &lng)) { + coord.setLatitude(lat); + coord.setLongitude(lng); + } + } + + if (coord.type() != QGeoCoordinate::InvalidCoordinate) + info->setCoordinate(coord); +} + +static void qlocationutils_readRmc(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) +{ + QByteArray sentence(data, size); + QList parts = sentence.split(','); + QGeoCoordinate coord; + QDate date; + QTime time; + + if (hasFix && parts.count() > 2 && parts[2].count() > 0) + *hasFix = (parts[2][0] == 'A'); + + if (parts.count() > 9 && parts[9].count() == 6) { + date = QDate::fromString(QString::fromLatin1(parts[9]), QLatin1String("ddMMyy")); + if (date.isValid()) + date = date.addYears(100); // otherwise starts from 1900 + else + date = QDate(); + } + + if (parts.count() > 1 && parts[1].count() > 0) + QLocationUtils::getNmeaTime(parts[1], &time); + + if (parts.count() > 6 && parts[4].count() == 1 && parts[6].count() == 1) { + double lat; + double lng; + if (QLocationUtils::getNmeaLatLong(parts[3], parts[4][0], parts[5], parts[6][0], &lat, &lng)) { + coord.setLatitude(lat); + coord.setLongitude(lng); + } + } + + bool parsed = false; + double value = 0.0; + if (parts.count() > 7 && parts[7].count() > 0) { + value = parts[7].toDouble(&parsed); + if (parsed) + info->setAttribute(QGeoPositionInfo::GroundSpeed, qreal(value * 1.852 / 3.6)); // knots -> m/s + } + if (parts.count() > 8 && parts[8].count() > 0) { + value = parts[8].toDouble(&parsed); + if (parsed) + info->setAttribute(QGeoPositionInfo::Direction, qreal(value)); + } + if (parts.count() > 11 && parts[11].count() == 1 + && (parts[11][0] == 'E' || parts[11][0] == 'W')) { + value = parts[10].toDouble(&parsed); + if (parsed) { + if (parts[11][0] == 'W') + value *= -1; + info->setAttribute(QGeoPositionInfo::MagneticVariation, qreal(value)); + } + } + + if (coord.type() != QGeoCoordinate::InvalidCoordinate) + info->setCoordinate(coord); + + info->setTimestamp(QDateTime(date, time, Qt::UTC)); +} + +static void qlocationutils_readVtg(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) +{ + if (hasFix) + *hasFix = false; + + QByteArray sentence(data, size); + QList parts = sentence.split(','); + + bool parsed = false; + double value = 0.0; + if (parts.count() > 1 && parts[1].count() > 0) { + value = parts[1].toDouble(&parsed); + if (parsed) + info->setAttribute(QGeoPositionInfo::Direction, qreal(value)); + } + if (parts.count() > 7 && parts[7].count() > 0) { + value = parts[7].toDouble(&parsed); + if (parsed) + info->setAttribute(QGeoPositionInfo::GroundSpeed, qreal(value / 3.6)); // km/h -> m/s + } +} + +static void qlocationutils_readZda(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) +{ + if (hasFix) + *hasFix = false; + + QByteArray sentence(data, size); + QList parts = sentence.split(','); + QDate date; + QTime time; + + if (parts.count() > 1 && parts[1].count() > 0) + QLocationUtils::getNmeaTime(parts[1], &time); + + if (parts.count() > 4 && parts[2].count() > 0 && parts[3].count() > 0 + && parts[4].count() == 4) { // must be full 4-digit year + int day = parts[2].toUInt(); + int month = parts[3].toUInt(); + int year = parts[4].toUInt(); + if (day > 0 && month > 0 && year > 0) + date.setDate(year, month, day); + } + + info->setTimestamp(QDateTime(date, time, Qt::UTC)); +} + +bool QLocationUtils::getPosInfoFromNmea(const char *data, int size, QGeoPositionInfo *info, bool *hasFix) +{ + if (!info) + return false; + + if (hasFix) + *hasFix = false; + if (size < 6 || data[0] != '$' || !hasValidNmeaChecksum(data, size)) + return false; + + if (data[3] == 'G' && data[4] == 'G' && data[5] == 'A') { + // "$--GGA" sentence. + qlocationutils_readGga(data, size, info, hasFix); + return true; + } + + if (data[3] == 'G' && data[4] == 'L' && data[5] == 'L') { + // "$--GLL" sentence. + qlocationutils_readGll(data, size, info, hasFix); + return true; + } + + if (data[3] == 'R' && data[4] == 'M' && data[5] == 'C') { + // "$--RMC" sentence. + qlocationutils_readRmc(data, size, info, hasFix); + return true; + } + + if (data[3] == 'V' && data[4] == 'T' && data[5] == 'G') { + // "$--VTG" sentence. + qlocationutils_readVtg(data, size, info, hasFix); + return true; + } + + if (data[3] == 'Z' && data[4] == 'D' && data[5] == 'A') { + // "$--ZDA" sentence. + qlocationutils_readZda(data, size, info, hasFix); + return true; + } + + return false; +} + +bool QLocationUtils::hasValidNmeaChecksum(const char *data, int size) +{ + int asteriskIndex = -1; + for (int i = 0; i < size; ++i) { + if (data[i] == '*') { + asteriskIndex = i; + break; + } + } + + const int CSUM_LEN = 2; + if (asteriskIndex < 0 || asteriskIndex + CSUM_LEN >= size) + return false; + + // XOR byte value of all characters between '$' and '*' + int result = 0; + for (int i = 1; i < asteriskIndex; ++i) + result ^= data[i]; + /* + char calc[CSUM_LEN + 1]; + ::snprintf(calc, CSUM_LEN + 1, "%02x", result); + return ::strncmp(calc, &data[asteriskIndex+1], 2) == 0; + */ + + QByteArray checkSumBytes(&data[asteriskIndex + 1], 2); + bool ok = false; + int checksum = checkSumBytes.toInt(&ok,16); + return ok && checksum == result; +} + +bool QLocationUtils::getNmeaTime(const QByteArray &bytes, QTime *time) +{ + int dotIndex = bytes.indexOf('.'); + QTime tempTime; + + if (dotIndex < 0) { + tempTime = QTime::fromString(QString::fromLatin1(bytes.constData()), + QLatin1String("hhmmss")); + } else { + tempTime = QTime::fromString(QString::fromLatin1(bytes.mid(0, dotIndex)), + QLatin1String("hhmmss")); + bool hasMsecs = false; + int midLen = qMin(3, bytes.size() - dotIndex - 1); + int msecs = bytes.mid(dotIndex + 1, midLen).toUInt(&hasMsecs); + if (hasMsecs) + tempTime = tempTime.addMSecs(msecs); + } + + if (tempTime.isValid()) { + *time = tempTime; + return true; + } + return false; +} + +bool QLocationUtils::getNmeaLatLong(const QByteArray &latString, char latDirection, const QByteArray &lngString, char lngDirection, double *lat, double *lng) +{ + if ((latDirection != 'N' && latDirection != 'S') + || (lngDirection != 'E' && lngDirection != 'W')) { + return false; + } + + bool hasLat = false; + bool hasLong = false; + double tempLat = latString.toDouble(&hasLat); + double tempLng = lngString.toDouble(&hasLong); + if (hasLat && hasLong) { + tempLat = qlocationutils_nmeaDegreesToDecimal(tempLat); + if (latDirection == 'S') + tempLat *= -1; + tempLng = qlocationutils_nmeaDegreesToDecimal(tempLng); + if (lngDirection == 'W') + tempLng *= -1; + + if (isValidLat(tempLat) && isValidLong(tempLng)) { + *lat = tempLat; + *lng = tempLng; + return true; + } + } + return false; +} + +QT_END_NAMESPACE + diff --git a/src/positioning/qlocationutils_p.h b/src/positioning/qlocationutils_p.h new file mode 100644 index 00000000..4b42695c --- /dev/null +++ b/src/positioning/qlocationutils_p.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QLOCATIONUTILS_P_H +#define QLOCATIONUTILS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_NAMESPACE +class QTime; +class QByteArray; + +class QGeoPositionInfo; +class QLocationUtils +{ +public: + inline static bool isValidLat(double lat) { + return lat >= -90 && lat <= 90; + } + inline static bool isValidLong(double lng) { + return lng >= -180 && lng <= 180; + } + + inline static double clipLat(double lat) { + if (lat > 90) + lat = 90; + else if (lat < -90) + lat = -90; + return lat; + } + + inline static double wrapLong(double lng) { + if (lng > 180) + lng -= 360; + else if (lng < -180) + lng += 360; + return lng; + } + + /* + Creates a QGeoPositionInfo from a GGA, GLL, RMC, VTG or ZDA sentence. + + Note: + - GGA and GLL sentences have time but not date so the update's + QDateTime object will have an invalid date. + - RMC reports date with a two-digit year so in this case the year + is assumed to be after the year 2000. + */ + Q_AUTOTEST_EXPORT static bool getPosInfoFromNmea(const char *data, int size, QGeoPositionInfo *info, bool *hasFix = 0); + + /* + Returns true if the given NMEA sentence has a valid checksum. + */ + Q_AUTOTEST_EXPORT static bool hasValidNmeaChecksum(const char *data, int size); + + /* + Returns time from a string in hhmmss or hhmmss.z+ format. + */ + Q_AUTOTEST_EXPORT static bool getNmeaTime(const QByteArray &bytes, QTime *time); + + /* + Accepts for example ("2734.7964", 'S', "15306.0124", 'E') and returns the + lat-long values. Fails if lat or long fail isValidLat() or isValidLong(). + */ + Q_AUTOTEST_EXPORT static bool getNmeaLatLong(const QByteArray &latString, char latDirection, const QByteArray &lngString, char lngDirection, double *lat, double *lon); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qnmeapositioninfosource.cpp b/src/positioning/qnmeapositioninfosource.cpp new file mode 100644 index 00000000..14b0f257 --- /dev/null +++ b/src/positioning/qnmeapositioninfosource.cpp @@ -0,0 +1,623 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnmeapositioninfosource_p.h" +#include "qlocationutils_p.h" + +#include +#include +#include +#include + + +QT_BEGIN_NAMESPACE + +QNmeaRealTimeReader::QNmeaRealTimeReader(QNmeaPositionInfoSourcePrivate *sourcePrivate) + : QNmeaReader(sourcePrivate) +{ +} + +void QNmeaRealTimeReader::readAvailableData() +{ + while (m_proxy->m_device->canReadLine()){ + QGeoPositionInfo update; + bool hasFix = false; + + char buf[1024]; + qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf)); + if (m_proxy->parsePosInfoFromNmeaData(buf, size, &update, &hasFix)) + m_proxy->notifyNewUpdate(&update, hasFix); + } +} + + +//============================================================ + +QNmeaSimulatedReader::QNmeaSimulatedReader(QNmeaPositionInfoSourcePrivate *sourcePrivate) + : QNmeaReader(sourcePrivate), + m_currTimerId(-1), + m_hasValidDateTime(false) +{ +} + +QNmeaSimulatedReader::~QNmeaSimulatedReader() +{ + if (m_currTimerId > 0) + killTimer(m_currTimerId); +} + +void QNmeaSimulatedReader::readAvailableData() +{ + if (m_currTimerId > 0) // we are already reading + return; + + if (!m_hasValidDateTime) { // first update + Q_ASSERT(m_proxy->m_device && (m_proxy->m_device->openMode() & QIODevice::ReadOnly)); + + if (!setFirstDateTime()) { + //m_proxy->notifyReachedEndOfFile(); + qWarning("QNmeaPositionInfoSource: cannot find NMEA sentence with valid date & time"); + return; + } + + m_hasValidDateTime = true; + simulatePendingUpdate(); + + } else { + // previously read to EOF, but now new data has arrived + processNextSentence(); + } +} + +bool QNmeaSimulatedReader::setFirstDateTime() +{ + // find the first update with valid date and time + QGeoPositionInfo update; + bool hasFix = false; + while (m_proxy->m_device->bytesAvailable() > 0) { + char buf[1024]; + qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf)); + if (size <= 0) + continue; + bool ok = m_proxy->parsePosInfoFromNmeaData(buf, size, &update, &hasFix); + if (ok && update.timestamp().isValid()) { + QPendingGeoPositionInfo pending; + pending.info = update; + pending.hasFix = hasFix; + m_pendingUpdates.enqueue(pending); + return true; + } + } + return false; +} + +void QNmeaSimulatedReader::simulatePendingUpdate() +{ + if (m_pendingUpdates.size() > 0) { + // will be dequeued in processNextSentence() + QPendingGeoPositionInfo &pending = m_pendingUpdates.head(); + if (pending.info.coordinate().type() != QGeoCoordinate::InvalidCoordinate) + m_proxy->notifyNewUpdate(&pending.info, pending.hasFix); + } + + processNextSentence(); +} + +void QNmeaSimulatedReader::timerEvent(QTimerEvent *event) +{ + killTimer(event->timerId()); + m_currTimerId = -1; + simulatePendingUpdate(); +} + +void QNmeaSimulatedReader::processNextSentence() +{ + QGeoPositionInfo info; + bool hasFix = false; + int timeToNextUpdate = -1; + QTime prevTime; + if (m_pendingUpdates.size() > 0) + prevTime = m_pendingUpdates.head().info.timestamp().time(); + + // find the next update with a valid time (as long as the time is valid, + // we can calculate when the update should be emitted) + while (m_proxy->m_device && m_proxy->m_device->bytesAvailable() > 0) { + char buf[1024]; + qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf)); + if (size <= 0) + continue; + if (m_proxy->parsePosInfoFromNmeaData(buf, size, &info, &hasFix)) { + QTime time = info.timestamp().time(); + if (time.isValid()) { + if (!prevTime.isValid()) { + timeToNextUpdate = 0; + break; + } + timeToNextUpdate = prevTime.msecsTo(time); + if (timeToNextUpdate >= 0) + break; + } + } + } + + if (timeToNextUpdate < 0) + return; + + m_pendingUpdates.dequeue(); + + QPendingGeoPositionInfo pending; + pending.info = info; + pending.hasFix = hasFix; + m_pendingUpdates.enqueue(pending); + m_currTimerId = startTimer(timeToNextUpdate); +} + + +//============================================================ + + +QNmeaPositionInfoSourcePrivate::QNmeaPositionInfoSourcePrivate(QNmeaPositionInfoSource *parent, QNmeaPositionInfoSource::UpdateMode updateMode) + : QObject(parent), + m_updateMode(updateMode), + m_device(0), + m_invokedStart(false), + m_positionError(QGeoPositionInfoSource::UnknownSourceError), + m_source(parent), + m_nmeaReader(0), + m_updateTimer(0), + m_requestTimer(0), + m_noUpdateLastInterval(false), + m_updateTimeoutSent(false), + m_connectedReadyRead(false) +{ +} + +QNmeaPositionInfoSourcePrivate::~QNmeaPositionInfoSourcePrivate() +{ + delete m_nmeaReader; + delete m_updateTimer; +} + +bool QNmeaPositionInfoSourcePrivate::openSourceDevice() +{ + if (!m_device) { + qWarning("QNmeaPositionInfoSource: no QIODevice data source, call setDevice() first"); + return false; + } + + if (!m_device->isOpen() && !m_device->open(QIODevice::ReadOnly)) { + qWarning("QNmeaPositionInfoSource: cannot open QIODevice data source"); + return false; + } + + connect(m_device, SIGNAL(aboutToClose()), SLOT(sourceDataClosed())); + connect(m_device, SIGNAL(readChannelFinished()), SLOT(sourceDataClosed())); + connect(m_device, SIGNAL(destroyed()), SLOT(sourceDataClosed())); + + return true; +} + +void QNmeaPositionInfoSourcePrivate::sourceDataClosed() +{ + if (m_nmeaReader && m_device && m_device->bytesAvailable()) + m_nmeaReader->readAvailableData(); +} + +void QNmeaPositionInfoSourcePrivate::readyRead() +{ + if (m_nmeaReader) + m_nmeaReader->readAvailableData(); +} + +bool QNmeaPositionInfoSourcePrivate::initialize() +{ + if (m_nmeaReader) + return true; + + if (!openSourceDevice()) + return false; + + if (m_updateMode == QNmeaPositionInfoSource::RealTimeMode) + m_nmeaReader = new QNmeaRealTimeReader(this); + else + m_nmeaReader = new QNmeaSimulatedReader(this); + + return true; +} + +void QNmeaPositionInfoSourcePrivate::prepareSourceDevice() +{ + // some data may already be available + if (m_updateMode == QNmeaPositionInfoSource::SimulationMode) { + if (m_nmeaReader && m_device->bytesAvailable()) + m_nmeaReader->readAvailableData(); + } + + if (!m_connectedReadyRead) { + connect(m_device, SIGNAL(readyRead()), SLOT(readyRead())); + m_connectedReadyRead = true; + } +} + +bool QNmeaPositionInfoSourcePrivate::parsePosInfoFromNmeaData(const char *data, int size, + QGeoPositionInfo *posInfo, bool *hasFix) +{ + return m_source->parsePosInfoFromNmeaData(data, size, posInfo, hasFix); +} + +void QNmeaPositionInfoSourcePrivate::startUpdates() +{ + if (m_invokedStart) + return; + + m_invokedStart = true; + m_pendingUpdate = QGeoPositionInfo(); + m_noUpdateLastInterval = false; + + bool initialized = initialize(); + if (!initialized) + return; + + if (m_updateMode == QNmeaPositionInfoSource::RealTimeMode) { + // skip over any buffered data - we only want the newest data + if (m_device->bytesAvailable()) { + if (m_device->isSequential()) + m_device->readAll(); + else + m_device->seek(m_device->bytesAvailable()); + } + } + + if (m_updateTimer) + m_updateTimer->stop(); + + if (m_source->updateInterval() > 0) { + if (!m_updateTimer) + m_updateTimer = new QBasicTimer; + m_updateTimer->start(m_source->updateInterval(), this); + } + + if (initialized) + prepareSourceDevice(); +} + +void QNmeaPositionInfoSourcePrivate::stopUpdates() +{ + m_invokedStart = false; + if (m_updateTimer) + m_updateTimer->stop(); + m_pendingUpdate = QGeoPositionInfo(); + m_noUpdateLastInterval = false; +} + +void QNmeaPositionInfoSourcePrivate::requestUpdate(int msec) +{ + if (m_requestTimer && m_requestTimer->isActive()) + return; + + if (msec <= 0 || msec < m_source->minimumUpdateInterval()) { + emit m_source->updateTimeout(); + return; + } + + if (!m_requestTimer) { + m_requestTimer = new QTimer(this); + connect(m_requestTimer, SIGNAL(timeout()), SLOT(updateRequestTimeout())); + } + + bool initialized = initialize(); + if (!initialized) { + emit m_source->updateTimeout(); + return; + } + + m_requestTimer->start(msec); + + if (initialized) + prepareSourceDevice(); +} + +void QNmeaPositionInfoSourcePrivate::updateRequestTimeout() +{ + m_requestTimer->stop(); + emit m_source->updateTimeout(); +} + +void QNmeaPositionInfoSourcePrivate::notifyNewUpdate(QGeoPositionInfo *update, bool hasFix) +{ + // include before uncommenting + //qDebug() << "QNmeaPositionInfoSourcePrivate::notifyNewUpdate()" << update->timestamp() << hasFix << m_invokedStart << (m_requestTimer && m_requestTimer->isActive()); + + QDate date = update->timestamp().date(); + if (date.isValid()) { + m_currentDate = date; + } else { + // some sentence have time but no date + QTime time = update->timestamp().time(); + if (time.isValid() && m_currentDate.isValid()) + update->setTimestamp(QDateTime(m_currentDate, time, Qt::UTC)); + } + + if (hasFix && update->isValid()) { + if (m_requestTimer && m_requestTimer->isActive()) { + m_requestTimer->stop(); + emitUpdated(*update); + } else if (m_invokedStart) { + if (m_updateTimer && m_updateTimer->isActive()) { + // for periodic updates, only want the most recent update + m_pendingUpdate = *update; + if (m_noUpdateLastInterval) { + emitPendingUpdate(); + m_noUpdateLastInterval = false; + } + } else { + emitUpdated(*update); + } + } + m_lastUpdate = *update; + } +} + +void QNmeaPositionInfoSourcePrivate::timerEvent(QTimerEvent *) +{ + emitPendingUpdate(); +} + +void QNmeaPositionInfoSourcePrivate::emitPendingUpdate() +{ + if (m_pendingUpdate.isValid()) { + m_updateTimeoutSent = false; + m_noUpdateLastInterval = false; + emitUpdated(m_pendingUpdate); + m_pendingUpdate = QGeoPositionInfo(); + } else { + if (m_noUpdateLastInterval && !m_updateTimeoutSent) { + m_updateTimeoutSent = true; + m_pendingUpdate = QGeoPositionInfo(); + emit m_source->updateTimeout(); + } + m_noUpdateLastInterval = true; + } +} + +void QNmeaPositionInfoSourcePrivate::emitUpdated(const QGeoPositionInfo &update) +{ + m_lastUpdate = update; + emit m_source->positionUpdated(update); +} + +//========================================================= + +/*! + \class QNmeaPositionInfoSource + \inmodule QtPositioning + \ingroup QtPositioning-positioning + \since Qt Positioning 5.0 + + \brief The QNmeaPositionInfoSource class provides positional information using a NMEA data source. + + NMEA is a commonly used protocol for the specification of one's global + position at a certain point in time. The QNmeaPositionInfoSource class reads NMEA + data and uses it to provide positional data in the form of + QGeoPositionInfo objects. + + A QNmeaPositionInfoSource instance operates in either \l {RealTimeMode} or + \l {SimulationMode}. These modes allow NMEA data to be read from either a + live source of positional data, or replayed for simulation purposes from + previously recorded NMEA data. + + The source of NMEA data is set with setDevice(). + + Use startUpdates() to start receiving regular position updates and stopUpdates() to stop these + updates. If you only require updates occasionally, you can call requestUpdate() to request a + single update. + + In both cases the position information is received via the positionUpdated() signal and the + last known position can be accessed with lastKnownPosition(). +*/ + + +/*! + \enum QNmeaPositionInfoSource::UpdateMode + Defines the available update modes. + + \value RealTimeMode Positional data is read and distributed from the data source as it becomes available. Use this mode if you are using a live source of positional data (for example, a GPS hardware device). + \value SimulationMode The data and time information in the NMEA source data is used to provide positional updates at the rate at which the data was originally recorded. Use this mode if the data source contains previously recorded NMEA data and you want to replay the data for simulation purposes. +*/ + + +/*! + Constructs a QNmeaPositionInfoSource instance with the given \a parent + and \a updateMode. +*/ +QNmeaPositionInfoSource::QNmeaPositionInfoSource(UpdateMode updateMode, QObject *parent) + : QGeoPositionInfoSource(parent), + d(new QNmeaPositionInfoSourcePrivate(this, updateMode)) +{ +} + +/*! + Destroys the position source. +*/ +QNmeaPositionInfoSource::~QNmeaPositionInfoSource() +{ + delete d; +} + +/*! + Parses an NMEA sentence string into a QGeoPositionInfo. + + The default implementation will parse standard NMEA sentences. + This method should be reimplemented in a subclass whenever the need to deal with non-standard + NMEA sentences arises. + + The parser reads \a size bytes from \a data and uses that information to setup \a posInfo and + \a hasFix. If \a hasFix is set to false then \a posInfo may contain only the time or the date + and the time. + + Returns true if the sentence was succsesfully parsed, otherwise returns false and should not + modifiy \a posInfo or \a hasFix. +*/ +bool QNmeaPositionInfoSource::parsePosInfoFromNmeaData(const char *data, int size, + QGeoPositionInfo *posInfo, bool *hasFix) +{ + return QLocationUtils::getPosInfoFromNmea(data, size, posInfo, hasFix); +} + +/*! + Returns the update mode. +*/ +QNmeaPositionInfoSource::UpdateMode QNmeaPositionInfoSource::updateMode() const +{ + return d->m_updateMode; +} + +/*! + Sets the NMEA data source to \a device. If the device is not open, it + will be opened in QIODevice::ReadOnly mode. + + The source device can only be set once and must be set before calling + startUpdates() or requestUpdate(). + + \b {Note:} The \a device must emit QIODevice::readyRead() for the + source to be notified when data is available for reading. + QNmeaPositionInfoSource does not assume the ownership of the device, + and hence does not deallocate it upon destruction. +*/ +void QNmeaPositionInfoSource::setDevice(QIODevice *device) +{ + if (device != d->m_device) { + if (!d->m_device) + d->m_device = device; + else + qWarning("QNmeaPositionInfoSource: source device has already been set"); + } +} + +/*! + Returns the NMEA data source. +*/ +QIODevice *QNmeaPositionInfoSource::device() const +{ + return d->m_device; +} + +/*! + \reimp +*/ +void QNmeaPositionInfoSource::setUpdateInterval(int msec) +{ + int interval = msec; + if (interval != 0) + interval = qMax(msec, minimumUpdateInterval()); + QGeoPositionInfoSource::setUpdateInterval(interval); + if (d->m_invokedStart) { + d->stopUpdates(); + d->startUpdates(); + } +} + +/*! + \reimp +*/ +void QNmeaPositionInfoSource::startUpdates() +{ + d->startUpdates(); +} + +/*! + \reimp +*/ +void QNmeaPositionInfoSource::stopUpdates() +{ + d->stopUpdates(); +} + +/*! + \reimp +*/ +void QNmeaPositionInfoSource::requestUpdate(int msec) +{ + d->requestUpdate(msec == 0 ? 60000 * 5 : msec); +} + +/*! + \reimp +*/ +QGeoPositionInfo QNmeaPositionInfoSource::lastKnownPosition(bool) const +{ + // the bool value does not matter since we only use satellite positioning + return d->m_lastUpdate; +} + +/*! + \reimp +*/ +QGeoPositionInfoSource::PositioningMethods QNmeaPositionInfoSource::supportedPositioningMethods() const +{ + return SatellitePositioningMethods; +} + +/*! + \reimp +*/ +int QNmeaPositionInfoSource::minimumUpdateInterval() const +{ + return 100; +} + +/*! + \reimp +*/ +QGeoPositionInfoSource::Error QNmeaPositionInfoSource::error() const +{ + return d->m_positionError; +} + +void QNmeaPositionInfoSource::setError(QGeoPositionInfoSource::Error positionError) +{ + d->m_positionError = positionError; + emit QGeoPositionInfoSource::error(positionError); +} + +#include "moc_qnmeapositioninfosource.cpp" +#include "moc_qnmeapositioninfosource_p.cpp" + +QT_END_NAMESPACE diff --git a/src/positioning/qnmeapositioninfosource.h b/src/positioning/qnmeapositioninfosource.h new file mode 100644 index 00000000..605a5696 --- /dev/null +++ b/src/positioning/qnmeapositioninfosource.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNMEAPOSITIONINFOSOURCE_H +#define QNMEAPOSITIONINFOSOURCE_H + +#include + +QT_BEGIN_NAMESPACE + +class QIODevice; + +class QNmeaPositionInfoSourcePrivate; +class Q_POSITIONING_EXPORT QNmeaPositionInfoSource : public QGeoPositionInfoSource +{ + Q_OBJECT +public: + enum UpdateMode { + RealTimeMode = 1, + SimulationMode + }; + + explicit QNmeaPositionInfoSource(UpdateMode updateMode, QObject *parent = 0); + ~QNmeaPositionInfoSource(); + + UpdateMode updateMode() const; + + void setDevice(QIODevice *source); + QIODevice *device() const; + + void setUpdateInterval(int msec); + + QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const; + PositioningMethods supportedPositioningMethods() const; + int minimumUpdateInterval() const; + Error error() const; + + +public Q_SLOTS: + void startUpdates(); + void stopUpdates(); + void requestUpdate(int timeout = 0); + +protected: + virtual bool parsePosInfoFromNmeaData(const char *data, + int size, + QGeoPositionInfo *posInfo, + bool *hasFix); + +private: + Q_DISABLE_COPY(QNmeaPositionInfoSource) + friend class QNmeaPositionInfoSourcePrivate; + QNmeaPositionInfoSourcePrivate *d; + void setError(QGeoPositionInfoSource::Error positionError); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qnmeapositioninfosource_p.h b/src/positioning/qnmeapositioninfosource_p.h new file mode 100644 index 00000000..ec9ebeaf --- /dev/null +++ b/src/positioning/qnmeapositioninfosource_p.h @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNMEAPOSITIONINFOSOURCE_P_H +#define QNMEAPOSITIONINFOSOURCE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qnmeapositioninfosource.h" +#include "qgeopositioninfo.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QBasicTimer; +class QTimerEvent; +class QTimer; + +class QNmeaReader; +struct QPendingGeoPositionInfo +{ + QGeoPositionInfo info; + bool hasFix; +}; + + +class QNmeaPositionInfoSourcePrivate : public QObject +{ + Q_OBJECT +public: + QNmeaPositionInfoSourcePrivate(QNmeaPositionInfoSource *parent, QNmeaPositionInfoSource::UpdateMode updateMode); + ~QNmeaPositionInfoSourcePrivate(); + + void startUpdates(); + void stopUpdates(); + void requestUpdate(int msec); + + bool parsePosInfoFromNmeaData(const char *data, + int size, + QGeoPositionInfo *posInfo, + bool *hasFix); + + void notifyNewUpdate(QGeoPositionInfo *update, bool fixStatus); + + QNmeaPositionInfoSource::UpdateMode m_updateMode; + QPointer m_device; + QGeoPositionInfo m_lastUpdate; + bool m_invokedStart; + QGeoPositionInfoSource::Error m_positionError; + +public Q_SLOTS: + void readyRead(); + +protected: + void timerEvent(QTimerEvent *event); + +private Q_SLOTS: + void emitPendingUpdate(); + void sourceDataClosed(); + void updateRequestTimeout(); + +private: + bool openSourceDevice(); + bool initialize(); + void prepareSourceDevice(); + void emitUpdated(const QGeoPositionInfo &update); + + QNmeaPositionInfoSource *m_source; + QNmeaReader *m_nmeaReader; + QBasicTimer *m_updateTimer; + QGeoPositionInfo m_pendingUpdate; + QDate m_currentDate; + QTimer *m_requestTimer; + bool m_noUpdateLastInterval; + bool m_updateTimeoutSent; + bool m_connectedReadyRead; +}; + + +class QNmeaReader +{ +public: + explicit QNmeaReader(QNmeaPositionInfoSourcePrivate *sourcePrivate) + : m_proxy(sourcePrivate) {} + virtual ~QNmeaReader() {} + + virtual void readAvailableData() = 0; + +protected: + QNmeaPositionInfoSourcePrivate *m_proxy; +}; + + +class QNmeaRealTimeReader : public QNmeaReader +{ +public: + explicit QNmeaRealTimeReader(QNmeaPositionInfoSourcePrivate *sourcePrivate); + virtual void readAvailableData(); +}; + + +class QNmeaSimulatedReader : public QObject, public QNmeaReader +{ + Q_OBJECT +public: + explicit QNmeaSimulatedReader(QNmeaPositionInfoSourcePrivate *sourcePrivate); + ~QNmeaSimulatedReader(); + virtual void readAvailableData(); + +protected: + virtual void timerEvent(QTimerEvent *event); + +private Q_SLOTS: + void simulatePendingUpdate(); + +private: + bool setFirstDateTime(); + void processNextSentence(); + + QQueue m_pendingUpdates; + int m_currTimerId; + bool m_hasValidDateTime; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/positioning/qpositioningglobal.h b/src/positioning/qpositioningglobal.h new file mode 100644 index 00000000..e0de618b --- /dev/null +++ b/src/positioning/qpositioningglobal.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtPositioning module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QPOSITIONINGGLOBAL_H +#define QPOSITIONINGGLOBAL_H + +#include + +QT_BEGIN_NAMESPACE + +#ifndef QT_STATIC +# if defined(QT_BUILD_POSITIONING_LIB) +# define Q_POSITIONING_EXPORT Q_DECL_EXPORT +# else +# define Q_POSITIONING_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_POSITIONING_EXPORT +#endif + +QT_END_NAMESPACE + +#endif // QPOSITIONINGGLOBAL_H + diff --git a/src/src.pro b/src/src.pro index 8895e83a..bb05e39f 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += 3rdparty location plugins +SUBDIRS += 3rdparty positioning location plugins qtHaveModule(quick): SUBDIRS += imports -- cgit v1.2.1