diff options
author | Alex <qt-info@nokia.com> | 2011-05-11 15:51:00 +1000 |
---|---|---|
committer | Alex <qt-info@nokia.com> | 2011-05-11 15:51:00 +1000 |
commit | 9b0d684b569e32dc9b8e13ebeeb3544d86871fff (patch) | |
tree | 71b85bcefd03bb1a79324b0ac8bb024a6f1b68aa | |
parent | 312dd340f91c1007379ddae47825ec0d4ddf5437 (diff) | |
download | qtlocation-9b0d684b569e32dc9b8e13ebeeb3544d86871fff.tar.gz |
Add declarative API fo QtLocation
68 files changed, 13388 insertions, 1 deletions
diff --git a/src/imports/imports.pro b/src/imports/imports.pro new file mode 100644 index 00000000..9fd19bdb --- /dev/null +++ b/src/imports/imports.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += location + diff --git a/src/imports/location/location.cpp b/src/imports/location/location.cpp new file mode 100644 index 00000000..a932ec6b --- /dev/null +++ b/src/imports/location/location.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativepositionsource_p.h" +#include "qdeclarativeposition_p.h" +#include "qdeclarativelandmark_p.h" +#include "qdeclarativelandmarkcategory_p.h" +#include "qdeclarativelandmarkmodel_p.h" +#include "qdeclarativelandmarkcategorymodel_p.h" + +#include "qgeomapobject.h" +#include "qdeclarativegeoboundingbox_p.h" +#include "qdeclarativegeoaddress_p.h" +#include "qdeclarativegeoplace_p.h" +#include "qdeclarativecoordinate_p.h" + +#include "qdeclarativegeoserviceprovider_p.h" +#include "qdeclarativegraphicsgeomap_p.h" +#include "qdeclarativegeomapgroupobject_p.h" +#include "qdeclarativegeomapobjectborder_p.h" +#include "qdeclarativegeomapcircleobject_p.h" +#include "qdeclarativegeomappixmapobject_p.h" +#include "qdeclarativegeomappolygonobject_p.h" +#include "qdeclarativegeomappolylineobject_p.h" +#include "qdeclarativegeomaprectangleobject_p.h" +#include "qdeclarativegeomaptextobject_p.h" + +#include "qdeclarativegeomapmousearea_p.h" +#include "qdeclarativegeomapmouseevent_p.h" + +//#include "qdeclarativegeocodemodel_p.h" +//#include "qdeclarativereversegeocodemodel_p.h" + +#include <QtDeclarative/qdeclarativeextensionplugin.h> +#include <QtDeclarative/qdeclarative.h> + +QT_BEGIN_NAMESPACE +QTM_USE_NAMESPACE + +class QLocationDeclarativeModule: public QDeclarativeExtensionPlugin +{ + Q_OBJECT + +public: + virtual void registerTypes(const char* uri) { + Q_ASSERT(QLatin1String(uri) == QLatin1String("QtMobility.location")); + // Elements available since Qt mobility 1.1: + qmlRegisterType<QDeclarativePosition>(uri, 1, 1, "Position"); + qmlRegisterType<QDeclarativePositionSource>(uri, 1, 1, "PositionSource"); + qmlRegisterType<QDeclarativeLandmark>(uri, 1, 1, "Landmark"); + qmlRegisterType<QDeclarativeLandmarkModel>(uri, 1, 1, "LandmarkModel"); + qmlRegisterType<QDeclarativeLandmarkNameFilter>(uri, 1, 1, "LandmarkNameFilter"); + qmlRegisterType<QDeclarativeLandmarkCategoryFilter>(uri, 1, 1, "LandmarkCategoryFilter"); + qmlRegisterType<QDeclarativeLandmarkBoxFilter>(uri, 1, 1, "LandmarkBoxFilter"); + qmlRegisterType<QDeclarativeLandmarkProximityFilter>(uri, 1, 1, "LandmarkProximityFilter"); + qmlRegisterType<QDeclarativeLandmarkUnionFilter>(uri, 1, 1, "LandmarkUnionFilter"); + qmlRegisterType<QDeclarativeLandmarkIntersectionFilter>(uri, 1, 1, "LandmarkIntersectionFilter"); + qmlRegisterType<QDeclarativeLandmarkCategory>(uri, 1, 1, "LandmarkCategory"); + qmlRegisterType<QDeclarativeLandmarkCategoryModel>(uri, 1, 1, "LandmarkCategoryModel"); + qmlRegisterUncreatableType<QDeclarativeLandmarkFilterBase>(uri, 1, 1, "LandmarkFilterBase", QDeclarativeLandmarkFilterBase::tr("LandmarkFilterBase is an abstract class")); + qmlRegisterUncreatableType<QDeclarativeLandmarkAbstractModel>(uri, 1, 1, "LandmarkAbstractModel", QDeclarativeLandmarkAbstractModel::tr("LandmarkAbstractModel is an abstract class")); + qmlRegisterType<QDeclarativeCoordinate>(uri, 1, 1, "Coordinate"); + qmlRegisterType<QDeclarativeGeoBoundingBox>(uri, 1, 1, "BoundingBox"); + qmlRegisterType<QDeclarativeGeoPlace>(uri, 1, 1, "Place"); + qmlRegisterType<QDeclarativeGeoAddress>(uri, 1, 1, "Address"); + + qmlRegisterType<QDeclarativeGeoServiceProvider>(uri, 1, 2, "Plugin"); + qmlRegisterType<QDeclarativeGeoServiceProviderParameter>(uri, 1, 2, "PluginParameter"); + qmlRegisterType<QDeclarativeGraphicsGeoMap>(uri, 1, 2, "Map"); + qmlRegisterType<QDeclarativeGeoMapObjectBorder>(); // used as grouped property + qmlRegisterType<QGeoMapObject>(uri, 1, 2, "QGeoMapObject"); + qmlRegisterType<QDeclarativeGeoMapObject>(uri, 1, 2, "MapObject"); + qmlRegisterType<QDeclarativeGeoMapObjectView>(uri, 1, 2, "MapObjectView"); + qmlRegisterType<QDeclarativeGeoMapGroupObject>(uri, 1, 2, "MapGroup"); + qmlRegisterType<QDeclarativeGeoMapCircleObject>(uri, 1, 2, "MapCircle"); + qmlRegisterType<QDeclarativeGeoMapPolygonObject>(uri, 1, 2, "MapPolygon"); + qmlRegisterType<QDeclarativeGeoMapPolylineObject>(uri, 1, 2, "MapPolyline"); + qmlRegisterType<QDeclarativeGeoMapRectangleObject>(uri, 1, 2, "MapRectangle"); + qmlRegisterType<QDeclarativeGeoMapTextObject>(uri, 1, 2, "MapText"); + qmlRegisterType<QDeclarativeGeoMapPixmapObject>(uri, 1, 2, "MapImage"); + + qmlRegisterType<QDeclarativeGeoMapMouseArea>(uri, 1, 2, "MapMouseArea"); + qmlRegisterType<QDeclarativeGeoMapMouseEvent>(uri, 1, 2, "MapMouseEvent"); + + //qmlRegisterType<QDeclarativeGeocodeModel>(uri, 1, 3, "GeocodeModel"); + //qmlRegisterType<QDeclarativeReverseGeocodeModel>(uri, 1, 3, "ReverseGeocodeModel"); + } +}; + +QT_END_NAMESPACE +#include "location.moc" + +Q_EXPORT_PLUGIN2(declarative_location, QT_PREPEND_NAMESPACE(QLocationDeclarativeModule)); + + + diff --git a/src/imports/location/location.pro b/src/imports/location/location.pro new file mode 100644 index 00000000..cbbf10d6 --- /dev/null +++ b/src/imports/location/location.pro @@ -0,0 +1,116 @@ +TARGET = declarative_location +TARGETPATH = Qt/location + +# Compatibility demands old path too. +#TARGETPATH = QtMobility/location + +include(../qimportbase.pri) + +QT += declarative network location + +DESTDIR = $$QT.location.imports/$$TARGETPATH +target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + + +# On some platforms, build both versions because debug and release +# versions are incompatible +#win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release + +# Where to search for the #include'd files +#INCLUDEPATH += ../../../src/global +#INCLUDEPATH += ../../../src/location +#INCLUDEPATH += ../../../src/location/landmarks +#INCLUDEPATH += ../../../src/location/maps +#INCLUDEPATH += . + +# The header and source files of this project. Note that qmake generates dependency information +# and automatically adds necessary 'moc' files as it sees Q_OBJECT macros' in header files +HEADERS += qdeclarativeposition_p.h \ + qdeclarativepositionsource_p.h \ + qdeclarativelandmark_p.h \ + qdeclarativelandmarkmodel_p.h \ + qdeclarativelandmarkcategorymodel_p.h \ + qdeclarativelandmarkcategory_p.h \ + qdeclarativelandmarkfilters_p.h \ + qdeclarativecoordinate_p.h \ + qdeclarativegeomapobjectborder_p.h \ + qdeclarativegeomapcircleobject_p.h \ + qdeclarativegeomapgroupobject_p.h \ + qdeclarativegeomapobject_p.h \ + qdeclarativegeomappixmapobject_p.h \ + qdeclarativegeomappolygonobject_p.h \ + qdeclarativegeomappolylineobject_p.h \ + qdeclarativegeomaprectangleobject_p.h \ + qdeclarativegeomaptextobject_p.h \ + qdeclarativegeomapmouseevent_p.h \ + qdeclarativegeomapmousearea_p.h \ + qdeclarativegeoserviceprovider_p.h \ + qdeclarativegraphicsgeomap_p.h \ + qdeclarativegeoplace_p.h \ + qdeclarativegeoaddress_p.h \ + qdeclarativegeoboundingbox_p.h +# qdeclarativegeosearchmodel_p.h \ +# qdeclarativegeocodemodel_p.h \ +# qdeclarativereversegeocodemodel_p.h \ +# qdeclarativegeoroutingmodel_p.h \ +# qdeclarativegeoroute_p.h \ +# qdeclarativegeoroutesegment_p.h \ +# qdeclarativegeomaneuver_p.h + +SOURCES += qdeclarativeposition.cpp \ + location.cpp \ + qdeclarativepositionsource.cpp \ + qdeclarativelandmark.cpp \ + qdeclarativelandmarkmodel.cpp \ + qdeclarativelandmarkcategorymodel.cpp \ + qdeclarativelandmarkcategory.cpp \ + qdeclarativelandmarkfilters.cpp \ + qdeclarativecoordinate.cpp \ + qdeclarativegeomapobjectborder.cpp \ + qdeclarativegeomapcircleobject.cpp \ + qdeclarativegeomapgroupobject.cpp \ + qdeclarativegeomapobject.cpp \ + qdeclarativegeomappixmapobject.cpp \ + qdeclarativegeomappolygonobject.cpp \ + qdeclarativegeomappolylineobject.cpp \ + qdeclarativegeomaprectangleobject.cpp \ + qdeclarativegeomaptextobject.cpp \ + qdeclarativegeomapmouseevent.cpp \ + qdeclarativegeomapmousearea.cpp \ + qdeclarativegeoserviceprovider.cpp \ + qdeclarativegraphicsgeomap.cpp \ + qdeclarativegeoplace.cpp \ + qdeclarativegeoaddress.cpp \ + qdeclarativegeoboundingbox.cpp +# qdeclarativegeosearchmodel.cpp \ +# qdeclarativegeocodemodel.cpp \ +# qdeclarativereversegeocodemodel.cpp \ +# qdeclarativegeoroutingmodel.cpp \ +# qdeclarativegeoroute.cpp \ +# qdeclarativegeoroutesegment.cpp \ +# qdeclarativegeomaneuver.cpp + +# Tell qmake to create such makefile that qmldir and target (i.e. declarative_location) +# are both copied to qt/imports/QtMobility/location -directory, +# as the "/imports" is the default place where qmlviewer looks for plugins +# (otherwise qmlviewer -I <path> -option is needed) + +qmldir.files += $$PWD/qmldir +qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +INSTALLS += target qmldir + +symbian { + # In Symbian, a library should enjoy _largest_ possible capability set. + # However, really needs only Location capability so feel free to reduce + # depending on your signing capabilities. + TARGET.CAPABILITY = ALL -TCB + # Allow writable DLL data + TARGET.EPOCALLOWDLLDATA = 1 + # Target UID, makes every Symbian app unique + TARGET.UID3 = 0x20033007 + # Specifies what files shall be deployed: the plugin itself and the qmldir file. + importFiles.sources = $$DESTDIR/declarative_location$${QT_LIBINFIX}.dll qmldir + importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH + DEPLOYMENT = importFiles + } diff --git a/src/imports/location/qdeclarativecoordinate.cpp b/src/imports/location/qdeclarativecoordinate.cpp new file mode 100644 index 00000000..31aec957 --- /dev/null +++ b/src/imports/location/qdeclarativecoordinate.cpp @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativecoordinate_p.h" +#include <qnumeric.h> +#include "qdeclarative.h" + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass Coordinate + + \brief The Coordinate element holds various positional data, such as \l + latitude, \l longitude and \l altitude. + \inherits QObject + + \ingroup qml-location + + The Coordinate element is part of the \bold{QtMobility.location 1.1} module. +*/ + +QDeclarativeCoordinate::QDeclarativeCoordinate(QObject* parent) + : QObject(parent) {} + +QDeclarativeCoordinate::QDeclarativeCoordinate(const QGeoCoordinate &coordinate, + QObject *parent) + : QObject(parent), + m_coordinate(coordinate) {} + +QDeclarativeCoordinate::~QDeclarativeCoordinate() {} + +void QDeclarativeCoordinate::setCoordinate(const QGeoCoordinate &coordinate) +{ + QGeoCoordinate previousCoordinate = m_coordinate; + m_coordinate = coordinate; + + // Comparing two NotANumbers is false which is not wanted here + if (coordinate.altitude() != previousCoordinate.altitude() && + !(qIsNaN(coordinate.altitude()) && qIsNaN(previousCoordinate.altitude()))) { + emit altitudeChanged(m_coordinate.altitude()); + } + if (coordinate.latitude() != previousCoordinate.latitude() && + !(qIsNaN(coordinate.latitude()) && qIsNaN(previousCoordinate.latitude()))) { + emit latitudeChanged(m_coordinate.latitude()); + } + if (coordinate.longitude() != previousCoordinate.longitude() && + !(qIsNaN(coordinate.longitude()) && qIsNaN(previousCoordinate.longitude()))) { + emit longitudeChanged(m_coordinate.longitude()); + } +} + +QGeoCoordinate QDeclarativeCoordinate::coordinate() const +{ + return m_coordinate; +} + +/*! + \qmlproperty double Coordinate::altitude + + This property holds the value of altitude (metres above sea level). + If the property has not been set, its default value is zero. + +*/ + +void QDeclarativeCoordinate::setAltitude(double altitude) +{ + if (m_coordinate.altitude() != altitude) { + m_coordinate.setAltitude(altitude); + emit altitudeChanged(m_coordinate.altitude()); + } +} + +double QDeclarativeCoordinate::altitude() const +{ + return m_coordinate.altitude(); +} + +/*! + \qmlproperty double Coordinate::longitude + + 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 zero. +*/ + +void QDeclarativeCoordinate::setLongitude(double longitude) +{ + if (m_coordinate.longitude() != longitude) { + m_coordinate.setLongitude(longitude); + emit longitudeChanged(m_coordinate.longitude()); + } +} + +double QDeclarativeCoordinate::longitude() const +{ + return m_coordinate.longitude(); +} + +/*! + \qmlproperty double Coordinate::latitude + + 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 zero. +*/ + +void QDeclarativeCoordinate::setLatitude(double latitude) +{ + if (m_coordinate.latitude() != latitude) { + m_coordinate.setLatitude(latitude); + emit latitudeChanged(latitude); + } +} + +double QDeclarativeCoordinate::latitude() const +{ + return m_coordinate.latitude(); +} + +/*! + \qmlmethod Coordinate::distanceTo(Coordinate) + + 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 QDeclarativeCoordinate::distanceTo(QObject* coordinate) +{ + QDeclarativeCoordinate* coord = static_cast<QDeclarativeCoordinate*>(coordinate); + return m_coordinate.distanceTo(coord->coordinate()); +} + +#include "moc_qdeclarativecoordinate_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/imports/location/qdeclarativecoordinate_p.h b/src/imports/location/qdeclarativecoordinate_p.h new file mode 100644 index 00000000..c1bf61d9 --- /dev/null +++ b/src/imports/location/qdeclarativecoordinate_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVECOORDINATE_H +#define QDECLARATIVECOORDINATE_H + +#include <qgeocoordinate.h> +#include <QtDeclarative/qdeclarative.h> + +#include <QObject> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeCoordinate : public QObject +{ + Q_OBJECT + + Q_PROPERTY(double latitude READ latitude WRITE setLatitude NOTIFY latitudeChanged) + Q_PROPERTY(double longitude READ longitude WRITE setLongitude NOTIFY longitudeChanged) + Q_PROPERTY(double altitude READ altitude WRITE setAltitude NOTIFY altitudeChanged) + +public: + QDeclarativeCoordinate(QObject* parent = 0); + QDeclarativeCoordinate(const QGeoCoordinate &coordinate, QObject* parent = 0); + ~QDeclarativeCoordinate(); + + Q_INVOKABLE qreal distanceTo(QObject* coordinate); + + QGeoCoordinate coordinate() const; + void setCoordinate(const QGeoCoordinate &coordinate); + + double latitude() const; + void setLatitude(double latitude); + + double longitude() const; + void setLongitude(double longitude); + + double altitude() const; + void setAltitude(double altitude); + +Q_SIGNALS: + void latitudeChanged(double latitude); + void longitudeChanged(double longitude); + void altitudeChanged(double altitude); + +private: + QGeoCoordinate m_coordinate; +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeCoordinate)); + +#endif diff --git a/src/imports/location/qdeclarativegeoaddress.cpp b/src/imports/location/qdeclarativegeoaddress.cpp new file mode 100644 index 00000000..621a101c --- /dev/null +++ b/src/imports/location/qdeclarativegeoaddress.cpp @@ -0,0 +1,248 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativegeoaddress_p.h" + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass Address QDeclarativeGeoAddress + \brief The Address element presents an address. + \ingroup qml-location + + The Address element presents an address of a location. + This element is part of the \bold{QtMobility.location 1.1} module. + + \sa Landmark, Place, {QGeoAddress} +*/ + +QDeclarativeGeoAddress::QDeclarativeGeoAddress(QObject* parent) : + QObject(parent) +{ +} + +QDeclarativeGeoAddress::QDeclarativeGeoAddress(const QGeoAddress& address, QObject* parent) : + QObject(parent), m_address(address) +{ +} + +QGeoAddress QDeclarativeGeoAddress::address() const +{ + return m_address; +} + +void QDeclarativeGeoAddress::setAddress(const QGeoAddress& address) +{ + // Elaborate but takes care of emiting needed signals + setCountry(address.country()); + setCountryCode(address.countryCode()); + setState(address.state()); + setCounty(address.county()); + setCity(address.city()); + setDistrict(address.district()); + setStreet(address.street()); + setPostcode(address.postcode()); + m_address = address; +} + +QString QDeclarativeGeoAddress::country() const +{ + return m_address.country(); +} + +/*! + \qmlproperty string Address::country + + This property holds the country of the address. + + */ + +void QDeclarativeGeoAddress::setCountry(const QString& country) +{ + if (m_address.country() == country) + return; + m_address.setCountry(country); + emit countryChanged(); +} + +QString QDeclarativeGeoAddress::countryCode() const +{ + return m_address.countryCode(); +} + +/*! + \qmlproperty string Address::countryCode + + This property holds the country code of the address. + + */ + +void QDeclarativeGeoAddress::setCountryCode(const QString& countryCode) +{ + if (m_address.countryCode() == countryCode) + return; + m_address.setCountryCode(countryCode); + emit countryCodeChanged(); +} + +QString QDeclarativeGeoAddress::state() const +{ + return m_address.state(); +} + +/*! + \qmlproperty string Address::state + + This property holds the state of the address. + + */ + +void QDeclarativeGeoAddress::setState(const QString& state) +{ + if (m_address.state() == state) + return; + m_address.setState(state); + emit stateChanged(); +} + +QString QDeclarativeGeoAddress::county() const +{ + return m_address.county(); +} + +/*! + \qmlproperty string Address::county + + This property holds the county of the address. + + */ + +void QDeclarativeGeoAddress::setCounty(const QString& county) +{ + if (m_address.county() == county) + return; + m_address.setCounty(county); + emit countyChanged(); +} + +QString QDeclarativeGeoAddress::city() const +{ + return m_address.city(); +} + +/*! + \qmlproperty string Address::city + + This property holds the city of the address. + + */ + +void QDeclarativeGeoAddress::setCity(const QString& city) +{ + if (m_address.city() == city) + return; + m_address.setCity(city); + emit cityChanged(); +} + +QString QDeclarativeGeoAddress::district() const +{ + return m_address.district(); +} + +/*! + \qmlproperty string Address::district + + This property holds the district of the address. + + */ + +void QDeclarativeGeoAddress::setDistrict(const QString& district) +{ + if (m_address.district() == district) + return; + m_address.setDistrict(district); + emit districtChanged(); +} + +QString QDeclarativeGeoAddress::street() const +{ + return m_address.street(); +} + +/*! + \qmlproperty string Address::street + + This property holds the street of the address. + + */ + +void QDeclarativeGeoAddress::setStreet(const QString& street) +{ + if (m_address.street() == street) + return; + m_address.setStreet(street); + emit streetChanged(); +} + +QString QDeclarativeGeoAddress::postcode() const +{ + return m_address.postcode(); +} + +/*! + \qmlproperty string Address::postcode + + This property holds the post code of the address. + + */ + +void QDeclarativeGeoAddress::setPostcode(const QString& postcode) +{ + if (m_address.postcode() == postcode) + return; + m_address.setPostcode(postcode); + emit postcodeChanged(); +} + +#include "moc_qdeclarativegeoaddress_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeoaddress_p.h b/src/imports/location/qdeclarativegeoaddress_p.h new file mode 100644 index 00000000..b750fb3c --- /dev/null +++ b/src/imports/location/qdeclarativegeoaddress_p.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEGEOADDRESS_P_H +#define QDECLARATIVEGEOADDRESS_P_H + +#include <qgeoaddress.h> +#include <QtCore> +#include <QtDeclarative/qdeclarative.h> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoAddress : public QObject +{ + Q_OBJECT + 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 postcode READ postcode WRITE setPostcode NOTIFY postcodeChanged) + +public: + explicit QDeclarativeGeoAddress(QObject* parent = 0); + QDeclarativeGeoAddress(const QGeoAddress& address, QObject* parent = 0); + QGeoAddress address() const; + void setAddress(const QGeoAddress& 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 postcode() const; + void setPostcode(const QString& postcode); + +signals: + void countryChanged(); + void countryCodeChanged(); + void stateChanged(); + void countyChanged(); + void cityChanged(); + void districtChanged(); + void streetChanged(); + void postcodeChanged(); + +private: + QGeoAddress m_address; +}; + +QTM_END_NAMESPACE +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoAddress)); + +#endif // QDECLARATIVEGEOADDRESS_P_H diff --git a/src/imports/location/qdeclarativegeoboundingbox.cpp b/src/imports/location/qdeclarativegeoboundingbox.cpp new file mode 100644 index 00000000..472e4d88 --- /dev/null +++ b/src/imports/location/qdeclarativegeoboundingbox.cpp @@ -0,0 +1,274 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include <qnumeric.h> +#include "qdeclarativegeoboundingbox_p.h" + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass BoundingBox QDeclarativeGeoBoundingBox + \brief The QGeoBoundingBox class defines a rectangular geographic area. + \ingroup qml-location + + The BoundingBox class defines a rectangular geographic area. + This element is part of the \bold{QtMobility.location 1.1} module. + For behavioral details, please see \l QGeoBoundingBox. + + \sa Landmark, Place, Address, {QGeoBoundingBox} +*/ + +QDeclarativeGeoBoundingBox::QDeclarativeGeoBoundingBox(QObject* parent) : + QObject(parent), m_height(qQNaN()), m_width(qQNaN()) +{ +} + +QDeclarativeGeoBoundingBox::QDeclarativeGeoBoundingBox(const QGeoBoundingBox& box, QObject* parent) : + QObject(parent), + m_declarativeBottomLeft(box.bottomLeft()), + m_declarativeBottomRight(box.bottomRight()), + m_declarativeTopLeft(box.topLeft()), + m_declarativeTopRight(box.topRight()), + m_declarativeCenter(box.center()), + m_box(box), + m_height(box.height()), + m_width(box.width()) +{ +} + +void QDeclarativeGeoBoundingBox::setBox(const QGeoBoundingBox& box) +{ + m_box = box; + synchronizeDeclarative(); +} + +QGeoBoundingBox QDeclarativeGeoBoundingBox::box() +{ + return m_box; +} + + +QDeclarativeCoordinate* QDeclarativeGeoBoundingBox::bottomLeft() +{ + return &m_declarativeBottomLeft; +} + +/*! + \qmlproperty Coordinate BoundingBox::bottomLeft + + This property holds the bottom left coordinate of this bounding box. + + Note: this property's changed() signal is currently emitted only if the + whole element changes, not if only the contents of the element change. + + \sa {QGeoBoundingBox} + */ + +void QDeclarativeGeoBoundingBox::setBottomLeft(QDeclarativeCoordinate *coordinate) +{ + if (m_box.bottomLeft() == coordinate->coordinate()) + return; + m_box.setBottomLeft(coordinate->coordinate()); + synchronizeDeclarative(); + emit bottomLeftChanged(); +} + +QDeclarativeCoordinate* QDeclarativeGeoBoundingBox::bottomRight() +{ + return &m_declarativeBottomRight; +} + +/*! + \qmlproperty Coordinate BoundingBox::bottomRight + + This property holds the bottom right coordinate of this bounding box. + + Note: this property's changed() signal is currently emitted only if the + whole element changes, not if only the contents of the element change. + + \sa {QGeoBoundingBox} + */ + +void QDeclarativeGeoBoundingBox::setBottomRight(QDeclarativeCoordinate *coordinate) +{ + if (m_box.bottomRight() == coordinate->coordinate()) + return; + m_box.setBottomRight(coordinate->coordinate()); + synchronizeDeclarative(); + emit bottomRightChanged(); +} + +QDeclarativeCoordinate* QDeclarativeGeoBoundingBox::topLeft() +{ + return &m_declarativeTopLeft; +} + +/*! + \qmlproperty Coordinate BoundingBox::topLeft + + This property holds the top left coordinate of this bounding box. + + Note: this property's changed() signal is currently emitted only if the + whole element changes, not if only the contents of the element change. + + \sa {QGeoBoundingBox} + */ + +void QDeclarativeGeoBoundingBox::setTopLeft(QDeclarativeCoordinate *coordinate) +{ + if (m_box.topLeft() == coordinate->coordinate()) + return; + m_box.setTopLeft(coordinate->coordinate()); + synchronizeDeclarative(); + emit topLeftChanged(); +} + +QDeclarativeCoordinate* QDeclarativeGeoBoundingBox::topRight() +{ + return &m_declarativeTopRight; +} + +/*! + \qmlproperty Coordinate BoundingBox::topRight + + This property holds the top right coordinate of this bounding box. + + Note: this property's changed() signal is currently emitted only if the + whole element changes, not if only the contents of the element change. + + \sa {QGeoBoundingBox} + */ + +void QDeclarativeGeoBoundingBox::setTopRight(QDeclarativeCoordinate *coordinate) +{ + if (m_box.topRight() == coordinate->coordinate()) + return; + m_box.setTopRight(coordinate->coordinate()); + synchronizeDeclarative(); + emit topRightChanged(); +} + +QDeclarativeCoordinate* QDeclarativeGeoBoundingBox::center() +{ + return &m_declarativeCenter; +} + +/*! + \qmlproperty Coordinate BoundingBox::center + + This property holds the center coordinate of this bounding box. + + Note: this property's changed() signal is currently emitted only if the + whole element changes, not if only the contents of the element change. + + \sa {QGeoBoundingBox} + + */ + +void QDeclarativeGeoBoundingBox::setCenter(QDeclarativeCoordinate *coordinate) +{ + if (m_box.center() == coordinate->coordinate()) + return; + m_box.setCenter(coordinate->coordinate()); + synchronizeDeclarative(); + emit centerChanged(); +} + +double QDeclarativeGeoBoundingBox::height() +{ + return m_height; +} + +/*! + \qmlproperty double BoundingBox::height + + This property holds the height of this bounding box (in degrees). + + \sa {QGeoBoundingBox} + */ + +void QDeclarativeGeoBoundingBox::setHeight(const double height) +{ + m_box.setHeight(height); + synchronizeDeclarative(); +} + +double QDeclarativeGeoBoundingBox::width() +{ + return m_width; +} + +/*! + \qmlproperty double BoundingBox::width + + This property holds the width of this bounding box (in degrees). + + \sa {QGeoBoundingBox} + + */ + +void QDeclarativeGeoBoundingBox::setWidth(const double width) +{ + m_box.setWidth(width); + synchronizeDeclarative(); +} + +void QDeclarativeGeoBoundingBox::synchronizeDeclarative() +{ + m_declarativeBottomLeft.setCoordinate(m_box.bottomLeft()); + m_declarativeBottomRight.setCoordinate(m_box.bottomRight()); + m_declarativeTopLeft.setCoordinate(m_box.topLeft()); + m_declarativeTopRight.setCoordinate(m_box.topRight()); + m_declarativeCenter.setCoordinate(m_box.center()); + // Check not to compare two Not a Numbers, which by definition is 'false'. + if ((!qIsNaN(m_width) || !qIsNaN(m_box.width())) && m_width != m_box.width()) { + m_width = m_box.width(); + emit widthChanged(); + } + if ((!qIsNaN(m_height) || !qIsNaN(m_box.height())) && m_height != m_box.height()) { + m_height = m_box.height(); + emit heightChanged(); + } +} + +#include "moc_qdeclarativegeoboundingbox_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeoboundingbox_p.h b/src/imports/location/qdeclarativegeoboundingbox_p.h new file mode 100644 index 00000000..6f7b1e80 --- /dev/null +++ b/src/imports/location/qdeclarativegeoboundingbox_p.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEGEOBOUNDINGBOX_P_H +#define QDECLARATIVEGEOBOUNDINGBOX_P_H + +#include "qdeclarativecoordinate_p.h" +#include <qgeoboundingbox.h> + +#include <QtCore> +#include <QtDeclarative/qdeclarative.h> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoBoundingBox : public QObject +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeCoordinate* bottomLeft READ bottomLeft WRITE setBottomLeft NOTIFY bottomLeftChanged) + Q_PROPERTY(QDeclarativeCoordinate* bottomRight READ bottomRight WRITE setBottomRight NOTIFY bottomRightChanged) + Q_PROPERTY(QDeclarativeCoordinate* topLeft READ topLeft WRITE setTopLeft NOTIFY topLeftChanged) + Q_PROPERTY(QDeclarativeCoordinate* topRight READ topRight WRITE setTopRight NOTIFY topRightChanged) + Q_PROPERTY(QDeclarativeCoordinate* center READ center WRITE setCenter NOTIFY centerChanged) + Q_PROPERTY(double height READ height WRITE setHeight NOTIFY heightChanged) + Q_PROPERTY(double width READ width WRITE setWidth NOTIFY widthChanged) + +public: + explicit QDeclarativeGeoBoundingBox(QObject* parent = 0); + QDeclarativeGeoBoundingBox(const QGeoBoundingBox& box, QObject* parent = 0); + void setBox(const QGeoBoundingBox& box); + QGeoBoundingBox box(); + + QDeclarativeCoordinate* bottomLeft(); + void setBottomLeft(QDeclarativeCoordinate* coordinate); + QDeclarativeCoordinate* bottomRight(); + void setBottomRight(QDeclarativeCoordinate* coordinate); + QDeclarativeCoordinate* topLeft(); + void setTopLeft(QDeclarativeCoordinate* coordinate); + QDeclarativeCoordinate* topRight(); + void setTopRight(QDeclarativeCoordinate* coordinate); + QDeclarativeCoordinate* center(); + void setCenter(QDeclarativeCoordinate* coordinate); + double height(); + void setHeight(const double height); + double width(); + void setWidth(const double width); + +signals: + void bottomLeftChanged(); + void bottomRightChanged(); + void topLeftChanged(); + void topRightChanged(); + void centerChanged(); + void heightChanged(); + void widthChanged(); + +private: + void synchronizeDeclarative(); + +private: + QDeclarativeCoordinate m_declarativeBottomLeft; + QDeclarativeCoordinate m_declarativeBottomRight; + QDeclarativeCoordinate m_declarativeTopLeft; + QDeclarativeCoordinate m_declarativeTopRight; + QDeclarativeCoordinate m_declarativeCenter; + QGeoBoundingBox m_box; + double m_height; + double m_width; +}; + +QTM_END_NAMESPACE +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoBoundingBox)); + +#endif // QDECLARATIVEGEOBOUNDINGBOX_P_H diff --git a/src/imports/location/qdeclarativegeocodemodel.cpp b/src/imports/location/qdeclarativegeocodemodel.cpp new file mode 100644 index 00000000..c9c6eaeb --- /dev/null +++ b/src/imports/location/qdeclarativegeocodemodel.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeocodemodel_p.h" + +#include <qgeosearchmanager.h> + +QTM_BEGIN_NAMESPACE + +QDeclarativeGeocodeModel::QDeclarativeGeocodeModel(QObject *parent) + : QDeclarativeGeoSearchModel(parent), + complete_(false) {} + +QDeclarativeGeocodeModel::~QDeclarativeGeocodeModel() {} + +void QDeclarativeGeocodeModel::setAddress(QDeclarativeGeoAddress *address) +{ + if (address_.address() == address->address()) + return; + + address_.setAddress(address->address()); + + emit addressChanged(&address_); + + if (complete_) + update(); +} + +QDeclarativeGeoAddress* QDeclarativeGeocodeModel::address() +{ + return &address_; +} + +void QDeclarativeGeocodeModel::componentComplete() +{ + if (!searchManager()) + return; + + complete_ = true; + update(); +} + +void QDeclarativeGeocodeModel::update() +{ + if (searchManager() && !address_.address().isEmpty()) { + + setStatus(QDeclarativeGeoSearchModel::Loading); + + searchManager()->geocode(address_.address()); + + // TODO check for finished + } +} + +QVariant QDeclarativeGeocodeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() > places().count()) + return QVariant(); + + QGeoPlace place = places().at(index.row()); + + if (role == Qt::DisplayRole) + return place.coordinate().toString(); + + return QDeclarativeGeoSearchModel::data(index, role); +} + +QVariant QDeclarativeGeocodeModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (section != 0) + return QVariant(); + + if (role == Qt::DisplayRole) + return QString("Coordinate"); + + return QDeclarativeGeoSearchModel::headerData(section, orientation, role); +} + + +#include "moc_qdeclarativegeocodemodel_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeocodemodel_p.h b/src/imports/location/qdeclarativegeocodemodel_p.h new file mode 100644 index 00000000..7d6732b0 --- /dev/null +++ b/src/imports/location/qdeclarativegeocodemodel_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOCODEMODEL_H +#define QDECLARATIVEGEOCODEMODEL_H + +#include "qdeclarativegeosearchmodel_p.h" + +#include "qdeclarativegeoaddress_p.h" + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeocodeModel : public QDeclarativeGeoSearchModel +{ + + Q_OBJECT + + Q_PROPERTY(QDeclarativeGeoAddress* address READ address WRITE setAddress NOTIFY addressChanged) + +public: + explicit QDeclarativeGeocodeModel(QObject *parent = 0); + ~QDeclarativeGeocodeModel(); + + void setAddress(QDeclarativeGeoAddress *address); + QDeclarativeGeoAddress* address(); + + // From QDeclarativeParserStatus + virtual void componentComplete(); + + // From QAbstractListModel + virtual QVariant data(const QModelIndex &index, int role) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + +Q_SIGNALS: + void addressChanged(QDeclarativeGeoAddress *address); + +private: + void update(); + + bool complete_; + QDeclarativeGeoAddress address_; +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/imports/location/qdeclarativegeomaneuver.cpp b/src/imports/location/qdeclarativegeomaneuver.cpp new file mode 100644 index 00000000..63d08ae8 --- /dev/null +++ b/src/imports/location/qdeclarativegeomaneuver.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomaneuver_p.h" + +QTM_BEGIN_NAMESPACE + +QDeclarativeGeoManeuver::QDeclarativeGeoManeuver(QObject *parent) + : QObject(parent) +{ + position_ = new QDeclarativeCoordinate(this); + waypoint_ = new QDeclarativeCoordinate(this); +} + +QDeclarativeGeoManeuver::QDeclarativeGeoManeuver(const QGeoManeuver &maneuver, QObject *parent) + : QObject(parent), + maneuver_(maneuver) +{ + position_ = new QDeclarativeCoordinate(maneuver_.position(), this); + waypoint_ = new QDeclarativeCoordinate(maneuver_.waypoint(), this); +} + +QDeclarativeGeoManeuver::~QDeclarativeGeoManeuver() {} + +bool QDeclarativeGeoManeuver::valid() const +{ + return maneuver_.isValid(); +} + +QDeclarativeCoordinate* QDeclarativeGeoManeuver::position() const +{ + return position_; +} + +QString QDeclarativeGeoManeuver::instructionText() const +{ + return maneuver_.instructionText(); +} + +QDeclarativeGeoManeuver::Direction QDeclarativeGeoManeuver::direction() const +{ + return QDeclarativeGeoManeuver::Direction(maneuver_.direction()); +} + +int QDeclarativeGeoManeuver::timeToNextInstruction() const +{ + return maneuver_.timeToNextInstruction(); +} + +qreal QDeclarativeGeoManeuver::distanceToNextInstruction() const +{ + return maneuver_.distanceToNextInstruction(); +} + +QDeclarativeCoordinate* QDeclarativeGeoManeuver::waypoint() const +{ + return waypoint_; +} + +#include "moc_qdeclarativegeomaneuver_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomaneuver_p.h b/src/imports/location/qdeclarativegeomaneuver_p.h new file mode 100644 index 00000000..b97016c0 --- /dev/null +++ b/src/imports/location/qdeclarativegeomaneuver_p.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMANEUVER_H +#define QDECLARATIVEGEOMANEUVER_H + +#include <qgeomaneuver.h> + +#include "qdeclarativecoordinate_p.h" + +#include <QObject> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoManeuver : public QObject +{ + Q_OBJECT + Q_ENUMS(Direction) + + Q_PROPERTY(bool valid READ valid) + Q_PROPERTY(QDeclarativeCoordinate* position READ position CONSTANT) + Q_PROPERTY(QString instructionText READ instructionText CONSTANT) + Q_PROPERTY(Direction direction READ direction CONSTANT) + Q_PROPERTY(int timeToNextInstruction READ timeToNextInstruction CONSTANT) + Q_PROPERTY(qreal distanceToNextInstruction READ distanceToNextInstruction CONSTANT) + Q_PROPERTY(QDeclarativeCoordinate* waypoint READ waypoint CONSTANT) + +public: + enum Direction { + NoDirection = QGeoManeuver::NoDirection, + DirectionForward = QGeoManeuver::DirectionForward, + DirectionBearRight = QGeoManeuver::DirectionBearRight, + DirectionLightRight = QGeoManeuver::DirectionLightRight, + DirectionRight = QGeoManeuver::DirectionRight, + DirectionHardRight = QGeoManeuver::DirectionHardRight, + DirectionUTurnRight = QGeoManeuver::DirectionUTurnRight, + DirectionUTurnLeft = QGeoManeuver::DirectionUTurnLeft, + DirectionHardLeft = QGeoManeuver::DirectionHardLeft, + DirectionLeft = QGeoManeuver::DirectionLeft, + DirectionLightLeft = QGeoManeuver::DirectionLightLeft, + DirectionBearLeft = QGeoManeuver::DirectionBearLeft + }; + + QDeclarativeGeoManeuver(QObject *parent = 0); + QDeclarativeGeoManeuver(const QGeoManeuver &maneuver, QObject *parent = 0); + ~QDeclarativeGeoManeuver(); + + bool valid() const; + + QDeclarativeCoordinate* position() const; + QString instructionText() const; + Direction direction() const; + int timeToNextInstruction() const; + qreal distanceToNextInstruction() const; + QDeclarativeCoordinate* waypoint() const; + +private: + QGeoManeuver maneuver_; + QDeclarativeCoordinate* position_; + QDeclarativeCoordinate* waypoint_; +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/imports/location/qdeclarativegeomapcircleobject.cpp b/src/imports/location/qdeclarativegeomapcircleobject.cpp new file mode 100644 index 00000000..59b64e06 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapcircleobject.cpp @@ -0,0 +1,243 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomapcircleobject_p.h" + +#include <QColor> +#include <QBrush> + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass MapCircle + + \brief The MapCircle element displays a circle on a map. + \inherits QGeoMapCircleObject + + \ingroup qml-location-maps + + The circle is specified in terms of a central coordinate and + a radius in metres. + + If \l center and \l radius are not specified and valid the + circle will not be displayed. + + An example, a MapCircle positioned at your current position (assuming there + is a PositionSource): + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Basic map position marker definition + The element is used with a Map element. + + The MapCircle element is part of the \bold{QtMobility.location 1.2} module. +*/ + +QDeclarativeGeoMapCircleObject::QDeclarativeGeoMapCircleObject(QDeclarativeItem *parent) + : QDeclarativeGeoMapObject(parent), circle_(0), center_(0) +{ + circle_ = new QGeoMapCircleObject(); + setMapObject(circle_); + + connect(circle_, + SIGNAL(radiusChanged(qreal)), + this, + SIGNAL(radiusChanged(qreal))); + connect(&border_, + SIGNAL(colorChanged(QColor)), + this, + SLOT(borderColorChanged(QColor))); + connect(&border_, + SIGNAL(widthChanged(int)), + this, + SLOT(borderWidthChanged(int))); +} + +QDeclarativeGeoMapCircleObject::~QDeclarativeGeoMapCircleObject() +{ + delete circle_; +} + +/*! + \qmlproperty Coordinate MapCircle::center + + This property holds the coordinate at the center of the circle. + + The default value is an invalid coordinate. +*/ + +void QDeclarativeGeoMapCircleObject::setCenter(QDeclarativeCoordinate *center) +{ + if (!center || center == center_) + return; + center_ = center; + connect(center_, + SIGNAL(latitudeChanged(double)), + this, + SLOT(centerLatitudeChanged(double))); + connect(center_, + SIGNAL(longitudeChanged(double)), + this, + SLOT(centerLongitudeChanged(double))); + connect(center_, + SIGNAL(altitudeChanged(double)), + this, + SLOT(centerAltitudeChanged(double))); + + circle_->setCenter(center->coordinate()); + emit centerChanged(center_); +} + +QDeclarativeCoordinate* QDeclarativeGeoMapCircleObject::center() +{ + return center_; +} + +void QDeclarativeGeoMapCircleObject::centerLatitudeChanged(double /*latitude*/) +{ + circle_->setCenter(center_->coordinate()); +} + +void QDeclarativeGeoMapCircleObject::centerLongitudeChanged(double /*longitude*/) +{ + circle_->setCenter(center_->coordinate()); +} + +void QDeclarativeGeoMapCircleObject::centerAltitudeChanged(double /*altitude*/) +{ + circle_->setCenter(center_->coordinate()); +} + +void QDeclarativeGeoMapCircleObject::setRadius(qreal radius) +{ + circle_->setRadius(radius); +} + +qreal QDeclarativeGeoMapCircleObject::radius() const +{ + return circle_->radius(); +} + +/*! + \qmlproperty qreal MapCircle::radius + + This property holds the radius of the circle in metres. + + A negative value is used to indicate that the radius is invalid and + the default value is a radius of -1.0. +*/ + +/*! + \qmlproperty color MapCircle::color + + This property holds the color used to fill the circle. + + The default value corresponds to a transparent color. +*/ + +void QDeclarativeGeoMapCircleObject::setColor(const QColor &color) +{ + if (color_ == color) + return; + + color_ = color; + QBrush m_brush(color); + circle_->setBrush(m_brush); + emit colorChanged(color_); +} + +QColor QDeclarativeGeoMapCircleObject::color() const +{ + return color_; +} + +/*! + \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. + + 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. + + For no line, use a width of 0 or a transparent color. +*/ +QDeclarativeGeoMapObjectBorder* QDeclarativeGeoMapCircleObject::border() +{ + return &border_; +} + +void QDeclarativeGeoMapCircleObject::borderColorChanged(const QColor &color) +{ + QPen p = circle_->pen(); + p.setColor(color); + circle_->setPen(p); +} + +void QDeclarativeGeoMapCircleObject::borderWidthChanged(int width) +{ + QPen p = circle_->pen(); + p.setWidth(width); + if (width == 0) + p.setStyle(Qt::NoPen); + else + p.setStyle(Qt::SolidLine); + circle_->setPen(p); +} + +/*! + \qmlproperty int MapCircle::z + + This property holds the z-value of the circle. + + Map objects are drawn in z-value order, and objects with the + same z-value will be drawn in insertion order. +*/ + +/*! + \qmlproperty bool MapCircle::visible + + This property holds a boolean corresponding to whether or not the + circle is visible. +*/ + +#include "moc_qdeclarativegeomapcircleobject_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/imports/location/qdeclarativegeomapcircleobject_p.h b/src/imports/location/qdeclarativegeomapcircleobject_p.h new file mode 100644 index 00000000..57027232 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapcircleobject_p.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPCIRCLEOBJECT_H +#define QDECLARATIVEGEOMAPCIRCLEOBJECT_H + +#include "qdeclarativegeomapobject_p.h" +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeomapobjectborder_p.h" +#include "qgeomapcircleobject.h" + +class QColor; +class QBrush; + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoMapCircleObject : public QDeclarativeGeoMapObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeCoordinate* center READ center WRITE setCenter NOTIFY centerChanged) + Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QDeclarativeGeoMapObjectBorder* border READ border) + +public: + QDeclarativeGeoMapCircleObject(QDeclarativeItem *parent = 0); + ~QDeclarativeGeoMapCircleObject(); + + QDeclarativeCoordinate* center(); + void setCenter(QDeclarativeCoordinate *center); + + qreal radius() const; + void setRadius(qreal radius); + + QColor color() const; + void setColor(const QColor &color); + + QDeclarativeGeoMapObjectBorder* border(); + +Q_SIGNALS: + void centerChanged(const QDeclarativeCoordinate *center); + void radiusChanged(qreal radius); + void colorChanged(const QColor &color); + +private Q_SLOTS: + void borderColorChanged(const QColor &color); + void borderWidthChanged(int width); + void centerLatitudeChanged(double latitude); + void centerLongitudeChanged(double longitude); + void centerAltitudeChanged(double altitude); + +private: + QGeoMapCircleObject* circle_; + QDeclarativeCoordinate *center_; + QColor color_; + QDeclarativeGeoMapObjectBorder border_; +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapCircleObject)); + +#endif diff --git a/src/imports/location/qdeclarativegeomapgroupobject.cpp b/src/imports/location/qdeclarativegeomapgroupobject.cpp new file mode 100644 index 00000000..29cbb0c8 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapgroupobject.cpp @@ -0,0 +1,245 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomapgroupobject_p.h" + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass MapGroup + + \brief The MapGroup element aggregates a set of map objects. + \inherits QGeoMapGroupObject + + \ingroup qml-location-maps + + Grouping is provided to make it easier to quickly add, remove, show + and hide groups of objects. + + It also allows users to specify an ordering of objects local to the + group via the z-values and insertion order of the objects in the group. + + An example of group having a small red circle on top of bigger green circle: + \snippet examples/declarative-location/landmarkmap/landmarkmap.qml MapGroup + + The MapGroup element is part of the \bold{QtMobility.location 1.2} module. +*/ + +QDeclarativeGeoMapGroupObject::QDeclarativeGeoMapGroupObject(QDeclarativeItem *parent) + : QDeclarativeGeoMapObject(parent) +{ + group_ = new QGeoMapGroupObject(); + setMapObject(group_); +} + +QDeclarativeGeoMapGroupObject::~QDeclarativeGeoMapGroupObject() +{ + // Remove all objects from the group before deleting it. + // These objects are owned by their declarative counterparts + // and they'll delete them. + QList<QGeoMapObject*> objects = group_->childObjects(); + for (int i = 0; i < objects.size(); ++i) { + group_->removeChildObject(objects.at(i)); + } + delete group_; +} + +void QDeclarativeGeoMapGroupObject::componentComplete() +{ + QList<QGraphicsItem*> children = childItems(); + for (int i = 0; i < children.size(); ++i) { + QDeclarativeGeoMapObject *mapObject + = qobject_cast<QDeclarativeGeoMapObject*>(children.at(i)); + if (mapObject) { + group_->addChildObject(mapObject->mapObject()); + objects_.append(mapObject); + mapObject->setMap(map()); + } + } + + QDeclarativeGeoMapObject::componentComplete(); +} + +void QDeclarativeGeoMapGroupObject::setMap(QDeclarativeGraphicsGeoMap *map) +{ + QDeclarativeGeoMapObject::setMap(map); + for (int i = 0; i < objects_.size(); ++i) + objects_[i]->setMap(map); +} + +/*! + \qmlproperty list<QGeoMapObject> MapGroup::objects + \default + + This property holds the list of objects which make up the group. +*/ + +QDeclarativeListProperty<QDeclarativeGeoMapObject> QDeclarativeGeoMapGroupObject::objects() +{ + return QDeclarativeListProperty<QDeclarativeGeoMapObject>(this, + 0, + child_append, + child_count, + child_at, + child_clear); +} + +void QDeclarativeGeoMapGroupObject::child_append(QDeclarativeListProperty<QDeclarativeGeoMapObject> *prop, QDeclarativeGeoMapObject *mapObject) +{ + QDeclarativeGeoMapGroupObject* group = static_cast<QDeclarativeGeoMapGroupObject*>(prop->object); + group->group_->addChildObject(mapObject->mapObject()); + group->objects_.append(mapObject); +} + +int QDeclarativeGeoMapGroupObject::child_count(QDeclarativeListProperty<QDeclarativeGeoMapObject> *prop) +{ + return static_cast<QDeclarativeGeoMapGroupObject*>(prop->object)->objects_.size(); +} + +QDeclarativeGeoMapObject* QDeclarativeGeoMapGroupObject::child_at(QDeclarativeListProperty<QDeclarativeGeoMapObject> *prop, int index) +{ + return static_cast<QDeclarativeGeoMapGroupObject*>(prop->object)->objects_.at(index); +} + +void QDeclarativeGeoMapGroupObject::child_clear(QDeclarativeListProperty<QDeclarativeGeoMapObject> *prop) +{ + QDeclarativeGeoMapGroupObject* group = static_cast<QDeclarativeGeoMapGroupObject*>(prop->object); + group->group_->clearChildObjects(); + group->objects_.clear(); +} + +void QDeclarativeGeoMapGroupObject::doubleClickEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (event->accepted()) + return; + + for (int i = objects_.size() - 1; i >= 0; --i) { + objects_.at(i)->doubleClickEvent(event); + if (event->accepted()) + return; + } + + QDeclarativeGeoMapObject::doubleClickEvent(event); +} + +void QDeclarativeGeoMapGroupObject::pressEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (event->accepted()) + return; + + for (int i = objects_.size() - 1; i >= 0; --i) { + objects_.at(i)->pressEvent(event); + if (event->accepted()) + return; + } + + QDeclarativeGeoMapObject::pressEvent(event); +} + +void QDeclarativeGeoMapGroupObject::releaseEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (event->accepted()) + return; + + for (int i = objects_.size() - 1; i >= 0; --i) { + objects_.at(i)->releaseEvent(event); + if (event->accepted()) + return; + } + + QDeclarativeGeoMapObject::releaseEvent(event); +} + +void QDeclarativeGeoMapGroupObject::enterEvent() +{ + for (int i = objects_.size() - 1; i >= 0; --i) + objects_.at(i)->enterEvent(); + + QDeclarativeGeoMapObject::enterEvent(); +} + +void QDeclarativeGeoMapGroupObject::exitEvent() +{ + for (int i = objects_.size() - 1; i >= 0; --i) + objects_.at(i)->exitEvent(); + + QDeclarativeGeoMapObject::exitEvent(); +} + +void QDeclarativeGeoMapGroupObject::moveEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (event->accepted()) + return; + + for (int i = objects_.size() - 1; i >= 0; --i) { + objects_.at(i)->moveEvent(event); + if (event->accepted()) + return; + } + + QDeclarativeGeoMapObject::moveEvent(event); +} + +/*! + \qmlproperty int MapGroup::zValue + + This property holds the z-value of the group. + + Map objects are drawn in z-value order, and objects with the + same z-value will be drawn in insertion order. + + The objects inside the group are drawn according to the z-values + and insertion order of the other elements of the group. This + is indpendent of the z-value and insertion order of the group + element itself. +*/ + +/*! + \qmlproperty bool MapGroup::visible + + This property holds a boolean corresponding to whether or not the + group is visible. +*/ + +#include "moc_qdeclarativegeomapgroupobject_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/imports/location/qdeclarativegeomapgroupobject_p.h b/src/imports/location/qdeclarativegeomapgroupobject_p.h new file mode 100644 index 00000000..3ccf4db8 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapgroupobject_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPGROUPOBJECT_H +#define QDECLARATIVEGEOMAPGROUPOBJECT_H + +#include "qgeomapgroupobject.h" + +#include "qdeclarativegeomapobject_p.h" +#include <QtDeclarative/qdeclarative.h> +#include <QDeclarativeListProperty> + +QTM_BEGIN_NAMESPACE + +class QGeoCoordinate; + +class QDeclarativeGeoMapGroupObject : public QDeclarativeGeoMapObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeGeoMapObject> objects READ objects) + +public: + QDeclarativeGeoMapGroupObject(QDeclarativeItem *parent = 0); + ~QDeclarativeGeoMapGroupObject(); + + virtual void componentComplete(); + + virtual void setMap(QDeclarativeGraphicsGeoMap *map); + + QDeclarativeListProperty<QDeclarativeGeoMapObject> objects(); + + virtual void doubleClickEvent(QDeclarativeGeoMapMouseEvent *event); + virtual void pressEvent(QDeclarativeGeoMapMouseEvent *event); + virtual void releaseEvent(QDeclarativeGeoMapMouseEvent *event); + virtual void enterEvent(); + virtual void exitEvent(); + virtual void moveEvent(QDeclarativeGeoMapMouseEvent *event); + +private: + static void child_append(QDeclarativeListProperty<QDeclarativeGeoMapObject> *prop, QDeclarativeGeoMapObject *mapObject); + static int child_count(QDeclarativeListProperty<QDeclarativeGeoMapObject> *prop); + static QDeclarativeGeoMapObject* child_at(QDeclarativeListProperty<QDeclarativeGeoMapObject> *prop, int index); + static void child_clear(QDeclarativeListProperty<QDeclarativeGeoMapObject> *prop); + + QGeoMapGroupObject* group_; + QList<QDeclarativeGeoMapObject*> objects_; +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapGroupObject)); + +#endif diff --git a/src/imports/location/qdeclarativegeomapmousearea.cpp b/src/imports/location/qdeclarativegeomapmousearea.cpp new file mode 100644 index 00000000..eb3c4d21 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapmousearea.cpp @@ -0,0 +1,428 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomapmousearea_p.h" + +#include <QDebug> + +#include "qdeclarativegeomapobject_p.h" + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass MapMouseArea QDeclarativeGeoMapMouseArea + + \brief The MapMouseArea item enables simple mouse handling. + + \ingroup qml-location-maps + + A MapMouseArea is an invisible item that is typically used in conjunction + with a visible map object or map item in order to provide mouse handling. + By effectively acting as a proxy, the logic for mouse handling can be + contained within a MapMouseArea item. + + The \l enabled property is used to enable and disable mouse handling for + the proxied item. When disabled, the mouse area becomes transparent to + mouse events. + + The \l pressed read-only property indicates whether or not the user is + holding down a mouse button over the mouse area. This property is often + used in bindings between properties in a user interface. + + Information about the mouse position and button clicks are provided via + signals for which event handler properties are defined. The most commonly + used involved handling mouse presses and clicks: onClicked, onDoubleClicked, + onPressed and onReleased. + + MapMouseArea items only report mouse clicks and not changes to the + position of the mouse cursor. + + \sa MapMouseEvent +*/ + +QDeclarativeGeoMapMouseArea::QDeclarativeGeoMapMouseArea(QDeclarativeItem *parent) + : QDeclarativeItem(parent), + enabled_(true), + hoverEnabled_(false) {} + +QDeclarativeGeoMapMouseArea::~QDeclarativeGeoMapMouseArea() +{ +} + +void QDeclarativeGeoMapMouseArea::setMap(QDeclarativeGraphicsGeoMap *map) +{ + map_ = map; +} + +QDeclarativeGraphicsGeoMap* QDeclarativeGeoMapMouseArea::map() const +{ + return map_; +} + +/*! + \qmlproperty qreal MapMouseArea::mouseX + \qmlproperty qreal MapMouseArea::mouseY + + These properties hold the screen coordinates of the mouse cursor. + + These properties will only be valid while a button is pressed, and will + remain valid as long as the button is held down even if the mouse is moved + outside the area. + + The screen coordinates are relative to the MouseArea. +*/ + +qreal QDeclarativeGeoMapMouseArea::mouseX() const +{ + return mouseX_; +} + +qreal QDeclarativeGeoMapMouseArea::mouseY() const +{ + return mouseY_; +} + +bool QDeclarativeGeoMapMouseArea::hovered() const +{ + return hovered_; +} + +void QDeclarativeGeoMapMouseArea::setHovered(bool hovered) +{ + if (hovered_ == hovered) + return; + + hovered_ = hovered; + + emit hoveredChanged(hovered_); + + if (hovered_) + emit entered(); + else + emit exited(); +} + +/*! + \qmlproperty bool MapMouseArea::pressed + This property holds whether the mouse area is currently pressed. +*/ + +bool QDeclarativeGeoMapMouseArea::pressed() const +{ + return pressed_; +} + +bool QDeclarativeGeoMapMouseArea::setPressed(bool pressed, QDeclarativeGeoMapMouseEvent *event) +{ + if (pressed_ == pressed) + return false; + + bool isClick = pressed_ && !pressed;// && hovered_; + + pressed_ = pressed; + + if (pressed_) { + if (!doubleClick_) + emit QDeclarativeGeoMapMouseArea::pressed(event); + } else { + emit released(event); + // TODO set saved position in event? + if (isClick && !longPress_ && !doubleClick_) { + emit clicked(event); + + } + } + + emit pressedChanged(pressed_); + + return event->accepted(); +} + +/*! + \qmlproperty bool MapMouseArea::enabled + This property holds whether the item accepts mouse events. + + By default, this property is true. +*/ + +bool QDeclarativeGeoMapMouseArea::isEnabled() const +{ + return enabled_; +} + +void QDeclarativeGeoMapMouseArea::setEnabled(bool enabled) +{ + if (enabled_ == enabled) + return; + + enabled_ = enabled; + + emit enabledChanged(enabled_); +} + +/*! + \qmlproperty MouseButton MapMouseArea::pressedButton + This property holds the mouse button currently pressed. + + It is one of: + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MiddleButton + \endlist + + \sa acceptedButtons +*/ + +Qt::MouseButton QDeclarativeGeoMapMouseArea::pressedButton() const +{ + return pressedButton_; +} + + +/*! + \qmlproperty Qt::MouseButtons MapMouseArea::acceptedButtons + This property holds the mouse buttons that the mouse area reacts to. + + The available buttons are: + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MiddleButton + \endlist + + To accept more than one button the flags can be combined with the + "|" (or) operator: + + \code + MapMouseArea { acceptedButtons: Qt.LeftButton | Qt.RightButton } + \endcode + + The default value is \c Qt.LeftButton. +*/ + +void QDeclarativeGeoMapMouseArea::setAcceptedButtons(Qt::MouseButtons acceptedButtons) +{ + if (acceptedButtons_ == acceptedButtons) + return; + + acceptedButtons_ = acceptedButtons; + + emit acceptedButtonsChanged(acceptedButtons_); +} + +Qt::MouseButtons QDeclarativeGeoMapMouseArea::acceptedButtons() const +{ + return acceptedButtons_; +} + +bool QDeclarativeGeoMapMouseArea::hoverEnabled() const +{ + return hoverEnabled_; +} + +void QDeclarativeGeoMapMouseArea::setHoverEnabled(bool hoverEnabled) +{ + if (hoverEnabled == hoverEnabled_) + return; + + hoverEnabled_ = hoverEnabled; + setAcceptsHoverEvents(hoverEnabled_); + setAcceptHoverEvents(hoverEnabled_); + setAcceptedMouseButtons(Qt::LeftButton); + emit hoverEnabledChanged(hoverEnabled_); + // TODO update hovered property +} + + + + + + + +void QDeclarativeGeoMapMouseArea::doubleClickEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (!enabled_) { + //TODO QDeclarativeItem::mouseDoubleClickEvent(convert event to regular event here) + return; + } + // TODO check this properly + bool doubleClickConnected = true; + + if (doubleClickConnected) + doubleClick_ = true; + // TODO save event + event->setAccepted(doubleClickConnected); + emit doubleClicked(event); + // TODO QDeclarativeItem::mouseDoubleClickEvent(convert event to regular event here) + + map_->setActiveMouseArea(0); +} + +void QDeclarativeGeoMapMouseArea::pressEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (!enabled_) { + //TODO QDeclarativeItem::mousePressEvent(convert event to regular event here) + return; + } + + event->setAccepted(true); + + longPress_ = false; + // TODO save event + mouseX_ = event->x(); + mouseY_ = event->y(); + pressedButton_ = Qt::MouseButton(event->button()); + modifiers_ = Qt::KeyboardModifiers(event->modifiers()); + + //setHovered(true); + // TODO setup long press timer + event->setAccepted(setPressed(true, event)); + + if (event->accepted()) + map_->setActiveMouseArea(this); +} + +void QDeclarativeGeoMapMouseArea::releaseEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (!enabled_) { + //TODO QDeclarativeItem::mouseReleaseEvent(convert event to regular event here) + return; + } + + // save event + setPressed(false, event); + pressedButton_ = Qt::NoButton; + modifiers_ = Qt::NoModifier; + doubleClick_ = false; +} + +void QDeclarativeGeoMapMouseArea::enterEvent() +{ + if (!enabled_ || !hoverEnabled()) + return; + + setHovered(true); + + emit entered(); +} + +void QDeclarativeGeoMapMouseArea::exitEvent() +{ + if (!enabled_ || !hoverEnabled()) + return; + + setHovered(false); + + emit exited(); +} + +void QDeclarativeGeoMapMouseArea::moveEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (!enabled_) + return; + + event->setButton(pressedButton_); + event->setModifiers(modifiers_); + + emit positionChanged(event); +} + +/*! + \qmlsignal MapMouseArea::onPressed(MapMouseEvent mouse) + + This handler is called when there is a press. + + The \l {MapMouseEvent}{mouse} parameter provides information about the + press, including the x and y position and which button was pressed. + + The \l {MapMouseEvent}{accepted} property of the MapMouseEvent parameter determines whether + this MapMouseArea will handle the press and all future mouse events until + release. The default is to accept the event and not allow other + MapMouseArea beneath this one to handle the event. If \l {MapMouseEvent}{accepted} + is set to false, no further events will be sent to this MapMouseArea until + the button is next pressed. +*/ + +/*! + \qmlsignal MapMouseArea::onReleased(MapMouseEvent mouse) + + This handler is called when there is a release. + The \l {MapMouseEvent}{mouse} parameter provides information about the + click, including the x and y position of the release of the click. + + The \l {MapMouseEvent}{accepted} property of the MapMouseEvent parameter is ignored + in this handler. +*/ + +/*! + \qmlsignal MapMouseArea::onClicked(MapMouseEvent mouse) + + This handler is called when there is a click. A click is defined as a + press followed by a release, both inside the MapMouseArea (pressing, + moving outside the MapMouseArea, and then moving back inside and + releasing is also considered a click). + + The \l {MapMouseEvent}{mouse} parameter provides information about the + click, including the x and y position of the release of the click. + + The \l {MapMouseEvent}{accepted} property of the MapMouseEvent parameter is ignored in + this handler. +*/ + +/*! + \qmlsignal MapMouseArea::onDoubleClicked(MapMouseEvent mouse) + + This handler is called when there is a double-click (a press followed + by a release followed by a press). + + The \l {MapMouseEvent}{mouse} parameter provides information about the + click, including the x and y position of the release of the click. + + If the \l {MapMouseEvent}{accepted} property of the \l {MapMouseEvent}{mouse} parameter is + set to false in the handler, the onPressed/onReleased/onClicked handlers + will be called for the second click; otherwise they are suppressed. + The accepted property defaults to true. +*/ + +#include "moc_qdeclarativegeomapmousearea_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomapmousearea_p.h b/src/imports/location/qdeclarativegeomapmousearea_p.h new file mode 100644 index 00000000..d7c386c8 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapmousearea_p.h @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPMOUSEAREA_H +#define QDECLARATIVEGEOMAPMOUSEAREA_H + +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegraphicsgeomap_p.h" +#include "qdeclarativegeomapmouseevent_p.h" + +#include <QtDeclarative/qdeclarativeitem.h> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoMapMouseArea : public QDeclarativeItem +{ + Q_OBJECT + + Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mousePositionChanged) + Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mousePositionChanged) + Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) + Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(Qt::MouseButton pressedButton READ pressedButton NOTIFY pressedButtonChanged) + Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) + Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged) + +public: + QDeclarativeGeoMapMouseArea(QDeclarativeItem *parent = 0); + ~QDeclarativeGeoMapMouseArea(); + + void setMap(QDeclarativeGraphicsGeoMap *map); + QDeclarativeGraphicsGeoMap* map() const; + + qreal mouseX() const; + qreal mouseY() const; + bool hovered() const; + bool pressed() const; + + bool isEnabled() const; + void setEnabled(bool enabled); + + Qt::MouseButton pressedButton() const; + + bool hoverEnabled() const; + void setHoverEnabled(bool hoverEnabled); + + void setAcceptedButtons(Qt::MouseButtons acceptedButtons); + Qt::MouseButtons acceptedButtons() const; + + void doubleClickEvent(QDeclarativeGeoMapMouseEvent *event); + void pressEvent(QDeclarativeGeoMapMouseEvent *event); + void releaseEvent(QDeclarativeGeoMapMouseEvent *event); + void enterEvent(); + void exitEvent(); + void moveEvent(QDeclarativeGeoMapMouseEvent *event); + +Q_SIGNALS: + void mousePositionChanged(); + void hoveredChanged(bool hovered); + void pressedChanged(bool pressed); + void enabledChanged(bool enabled); + void pressedButtonChanged(Qt::MouseButtons pressedButton); + void acceptedButtonsChanged(Qt::MouseButtons acceptedButtons); + void hoverEnabledChanged(bool hoverEnabled); + + void positionChanged(QDeclarativeGeoMapMouseEvent *mouse); + void pressed(QDeclarativeGeoMapMouseEvent *mouse); +// void pressAndHold(QDeclarativeGeoMapMouseEvent *mouse); + void released(QDeclarativeGeoMapMouseEvent *mouse); + void clicked(QDeclarativeGeoMapMouseEvent *mouse); + void doubleClicked(QDeclarativeGeoMapMouseEvent *mouse); + void entered(); + void exited(); +// void cancelled(); + +private: + bool setPressed(bool pressed, QDeclarativeGeoMapMouseEvent *event); + void setHovered(bool hovered); + + bool hovered_; + bool enabled_; + bool hoverEnabled_; + qreal mouseX_; + qreal mouseY_; + bool pressed_; + bool longPress_; + bool doubleClick_; + Qt::MouseButtons acceptedButtons_; + Qt::MouseButton pressedButton_; + Qt::KeyboardModifiers modifiers_; + +// qreal startX_; +// qreal startY_; +// QPointF lastPos_; +// QPointF lastScenePos_; +// Qt::MouseButton lastButton_; +// Qt::MouseButtons lastButtons_; +// Qt::KeyboardModifiers lastModifiers_; + + QDeclarativeGraphicsGeoMap* map_; +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapMouseArea)); + +#endif diff --git a/src/imports/location/qdeclarativegeomapmouseevent.cpp b/src/imports/location/qdeclarativegeomapmouseevent.cpp new file mode 100644 index 00000000..51d717f7 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapmouseevent.cpp @@ -0,0 +1,202 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomapmouseevent_p.h" + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass MapMouseEvent QDeclarativeGeoMapMouseEvent + + \brief The MapMouseEvent object provides information about a mouse event. + + \ingroup qml-location-maps + + The position of the mouse can be found via the \l x and \l y properties + or the \l coordinate property. + The button that caused the event is available via the \l button property. + + \sa MapMouseArea +*/ + +QDeclarativeGeoMapMouseEvent::QDeclarativeGeoMapMouseEvent(QObject *parent) + : QObject(parent), + accepted_(false), + button_(Qt::NoButton), + coordinate_(0) +{ +} + +QDeclarativeGeoMapMouseEvent::~QDeclarativeGeoMapMouseEvent() +{ +} + +/*! + \qmlproperty bool MapMouseEvent::accepted + + Setting \a accepted to true prevents the mouse event from being + propagated to items below this item. + + Generally, if the item acts on the mouse event then it should be accepted + so that items lower in the stacking order do not also respond to the same ev +ent. +*/ + +void QDeclarativeGeoMapMouseEvent::setAccepted(bool accepted) +{ + accepted_ = accepted; +} + +bool QDeclarativeGeoMapMouseEvent::accepted() const +{ + return accepted_; +} + +/*! + \qmlproperty enumeration MapMouseEvent::button + + This property holds the button that caused the event. It can be one of: + \list + \o Qt.LeftButton + \o Qt.RightButton + \o Qt.MiddleButton + \endlist +*/ + +void QDeclarativeGeoMapMouseEvent::setButton(int button) +{ + button_ = button; +} + +int QDeclarativeGeoMapMouseEvent::button() const +{ + return button_; +} + +/*! + \qmlproperty int MapMouseEvent::modifiers + + This property holds the keyboard modifier flags that existed immediately + before the event occurred. + + It contains a bitwise combination of: + \list + \o Qt.NoModifier - No modifier key is pressed. + \o Qt.ShiftModifier - A Shift key on the keyboard is pressed. + \o Qt.ControlModifier - A Ctrl key on the keyboard is pressed. + \o Qt.AltModifier - An Alt key on the keyboard is pressed. + \o Qt.MetaModifier - A Meta key on the keyboard is pressed. + \o Qt.KeypadModifier - A keypad button is pressed. + \endlist +*/ + +void QDeclarativeGeoMapMouseEvent::setModifiers(int modifiers) +{ + modifiers_ = modifiers; +} + +int QDeclarativeGeoMapMouseEvent::modifiers() const +{ + return modifiers_; +} + +//void QDeclarativeGeoMapMouseEvent::setWasHeld(bool wasHeld) +//{ +// wasHeld_ = wasHeld; +//} + +//bool QDeclarativeGeoMapMouseEvent::wasHeld() const +//{ +// return wasHeld_; +//} + +/*! + \qmlproperty int MapMouseEvent::x + \qmlproperty int MapMouseEvent::y + + These properties hold the screen coordinates of the position supplied + by the mouse event. +*/ + +void QDeclarativeGeoMapMouseEvent::setX(int x) +{ + x_ = x; +} + +int QDeclarativeGeoMapMouseEvent::x() const +{ + return x_; +} + +void QDeclarativeGeoMapMouseEvent::setY(int y) +{ + y_ = y; +} + +int QDeclarativeGeoMapMouseEvent::y() const +{ + return y_; +} + +/*! + \qmlproperty Coordinate MapMouseEvent::coordinate + + This property holds the coordinate corresponding to the latitude + and longitude of the position on the map at which the mouse event + occurred. +*/ + +void QDeclarativeGeoMapMouseEvent::setCoordinate(QDeclarativeCoordinate *coordinate) +{ + if (!coordinate || (coordinate == coordinate_)) + return; + + coordinate_ = coordinate; +} + +QDeclarativeCoordinate* QDeclarativeGeoMapMouseEvent::coordinate() +{ + return coordinate_; +} + +#include "moc_qdeclarativegeomapmouseevent_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomapmouseevent_p.h b/src/imports/location/qdeclarativegeomapmouseevent_p.h new file mode 100644 index 00000000..5949e280 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapmouseevent_p.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPMOUSEEVENT_H +#define QDECLARATIVEGEOMAPMOUSEEVENT_H + +#include "qdeclarativecoordinate_p.h" + +#include <QtDeclarative/qdeclarative.h> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoMapMouseEvent : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool accepted READ accepted WRITE setAccepted) + Q_PROPERTY(int button READ button) + Q_PROPERTY(int modifiers READ modifiers) +// Q_PROPERTY(bool wasHeld READ wasHeld) + Q_PROPERTY(int x READ x) + Q_PROPERTY(int y READ y) + Q_PROPERTY(QDeclarativeCoordinate* coordinate READ coordinate) + +public: + QDeclarativeGeoMapMouseEvent(QObject *parent = 0); + ~QDeclarativeGeoMapMouseEvent(); + + void setAccepted(bool accepted); + bool accepted() const; + + void setButton(int button); + int button() const; + + void setModifiers(int modifiers); + int modifiers() const; + +// void setWasHeld(bool wasHeld); +// bool wasHeld() const; + + void setX(int x); + int x() const; + + void setY(int y); + int y() const; + + void setCoordinate(QDeclarativeCoordinate *coordinate); + QDeclarativeCoordinate* coordinate(); + +private: + bool accepted_; + int button_; + int modifiers_; +// bool wasHeld_; + int x_; + int y_; + QDeclarativeCoordinate *coordinate_; +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapMouseEvent)); + +#endif diff --git a/src/imports/location/qdeclarativegeomapobject.cpp b/src/imports/location/qdeclarativegeomapobject.cpp new file mode 100644 index 00000000..ab223fd2 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapobject.cpp @@ -0,0 +1,485 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomapobject_p.h" +#include "qdeclarativegeomapmousearea_p.h" +#include "qdeclarativelandmark_p.h" +#include "qgeomapdata.h" + +#include <QDeclarativeParserStatus> +#include <QAbstractItemModel> +#include <QDeclarativeContext> + +#include <QDebug> + +QTM_BEGIN_NAMESPACE + +QDeclarativeGeoMapObject::QDeclarativeGeoMapObject(QDeclarativeItem *parent) + : QDeclarativeItem(parent), + object_(0), + visible_(true) +{ +} + +QDeclarativeGeoMapObject::~QDeclarativeGeoMapObject() {} + +void QDeclarativeGeoMapObject::componentComplete() +{ + QDeclarativeItem::componentComplete(); + + QList<QGraphicsItem*> children = childItems(); + for (int i = 0; i < children.size(); ++i) { + QDeclarativeGeoMapMouseArea *mouseArea + = qobject_cast<QDeclarativeGeoMapMouseArea*>(children.at(i)); + if (mouseArea) { + mouseArea->setMap(map_); + mouseAreas_.append(mouseArea); + } + } +} + +void QDeclarativeGeoMapObject::setMap(QDeclarativeGraphicsGeoMap *map) +{ + map_ = map; + for (int i = 0; i < mouseAreas_.size(); ++i) + mouseAreas_[i]->setMap(map_); +} + +QDeclarativeGraphicsGeoMap* QDeclarativeGeoMapObject::map() const +{ + return map_; +} + +void QDeclarativeGeoMapObject::doubleClickEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (event->accepted()) + return; + + for (int i = 0; i < mouseAreas_.size(); ++i) { + mouseAreas_.at(i)->doubleClickEvent(event); + if (event->accepted()) + return; + } +} + +void QDeclarativeGeoMapObject::pressEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (event->accepted()) + return; + + for (int i = 0; i < mouseAreas_.size(); ++i) { + mouseAreas_.at(i)->pressEvent(event); + if (event->accepted()) + return; + } +} + +void QDeclarativeGeoMapObject::releaseEvent(QDeclarativeGeoMapMouseEvent *event) +{ + if (event->accepted()) + return; + + for (int i = 0; i < mouseAreas_.size(); ++i) { + mouseAreas_.at(i)->releaseEvent(event); + if (event->accepted()) + return; + } +} + +void QDeclarativeGeoMapObject::enterEvent() +{ + for (int i = 0; i < mouseAreas_.size(); ++i) + mouseAreas_.at(i)->enterEvent(); +} + +void QDeclarativeGeoMapObject::exitEvent() +{ + for (int i = 0; i < mouseAreas_.size(); ++i) + mouseAreas_.at(i)->exitEvent(); +} + +void QDeclarativeGeoMapObject::moveEvent(QDeclarativeGeoMapMouseEvent *event) +{ + for (int i = 0; i < mouseAreas_.size(); ++i) + mouseAreas_.at(i)->moveEvent(event); +} + +void QDeclarativeGeoMapObject::setMapObject(QGeoMapObject *object) +{ + if (!object) + return; + + object_ = object; + object_->setVisible(visible_); + + connect(this, + SIGNAL(zChanged()), + this, + SLOT(parentZChanged())); + + object_->setZValue(zValue()); +} + +QGeoMapObject* QDeclarativeGeoMapObject::mapObject() +{ + return object_; +} + +void QDeclarativeGeoMapObject::parentZChanged() +{ + object_->setZValue(zValue()); +} + +void QDeclarativeGeoMapObject::setVisible(bool visible) +{ + if (visible_ == visible) + return; + + visible_ = visible; + + if (object_) + object_->setVisible(visible); + + emit visibleChanged(visible_); +} + +bool QDeclarativeGeoMapObject::isVisible() const +{ + return visible_; +} + +/*! + \qmlclass MapObjectView + + \brief The MapObjectView is used to populate Map from a model. + \inherits QDeclarativeItem + + \ingroup qml-location-maps + + The MapObjectView is used to populate Map with MapObjects from a model. + The MapObjectView element only makes sense when contained in a Map object, + meaning that it has no standalone presentation. + + Note: For model data, currently only LandmarkModel is supported. Using other types + of models results in undefined behavior. + + Assuming you have a LandmarkModel identified by landmarkModel, an example usage: + \snippet doc/src/snippets/declarative/testpolymapobjects.qml MapObjectView + + The MapObjectView element is part of the \bold{QtMobility.location 1.2} module. +*/ + +QDeclarativeGeoMapObjectView::QDeclarativeGeoMapObjectView(QDeclarativeItem *parent) + : QObject(parent), visible_(true), componentCompleted_(false), delegate_(0), + model_(0), map_(0) +{ +} + +QDeclarativeGeoMapObjectView::~QDeclarativeGeoMapObjectView() +{ + // Remove group from map, and items from the group. This is to + // prevent their deletion. The objects are owned by the + // declarative objects and are to be deleted by them. + if (map_ && map_->mapData_) { + map_->mapData_->removeMapObject(&group_); + removeInstantiatedItems(); + } +} + +void QDeclarativeGeoMapObjectView::componentComplete() +{ + componentCompleted_ = true; +} + +QVariant QDeclarativeGeoMapObjectView::model() const +{ + return modelVariant_; +} + +/*! + \qmlproperty model MapObjectView::model + + This property holds the model that provides data for + populating data with delegates. + + Note: Currently only LandmarkModel is supported. Using other + models results in undefined behavior. + +*/ + +void QDeclarativeGeoMapObjectView::setModel(const QVariant &model) +{ + if (!model.isValid() || model == modelVariant_) + return; + QObject *object = qvariant_cast<QObject*>(model); + QAbstractItemModel* itemModel; + if (!object || !(itemModel = qobject_cast<QAbstractItemModel*>(object))) { + return; + } + modelVariant_ = model; + model_ = itemModel; + // At the moment maps only works with landmark model. Because of this tight + // restriction, we are not listening to all change signals. + QObject::connect(model_, SIGNAL(modelReset()), this, SLOT(modelReset())); + QObject::connect(model_, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelRowsRemoved(QModelIndex, int, int))); + QObject::connect(model_, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelRowsInserted(QModelIndex, int, int))); + repopulate(); + emit modelChanged(); +} + +void QDeclarativeGeoMapObjectView::modelReset() +{ + repopulate(); +} + +void QDeclarativeGeoMapObjectView::modelRowsInserted(QModelIndex, int start, int end) +{ + if (!componentCompleted_ || !map_ || !map_->mapData_ || !delegate_ || !model_) + return; + Q_ASSERT(declarativeObjectList_.count() == group_.childObjects().count()); + QDeclarativeGeoMapObject* mapObject; + for (int i = start; i <= end; ++i) { + mapObject = createItem(i); + if (!mapObject) { + break; + } + declarativeObjectList_.append(mapObject); + mapObject->setVisible(visible_); + mapObject->setMap(map_); + group_.addChildObject(mapObject->mapObject()); + // Needed in order for mouse areas to work. + map_->objectMap_.insert(mapObject->mapObject(), mapObject); + } + Q_ASSERT(declarativeObjectList_.count() == group_.childObjects().count()); +} + +void QDeclarativeGeoMapObjectView::modelRowsRemoved(QModelIndex, int start, int end) +{ + if (!componentCompleted_ || !map_ || !map_->mapData_ || !delegate_ || !model_) + return; + Q_ASSERT(declarativeObjectList_.count() == group_.childObjects().count()); + for (int i = end; i >= start; --i) { + QDeclarativeGeoMapObject *object = declarativeObjectList_.takeAt(i); + if (!object) // bad + break; + group_.removeChildObject(object->mapObject()); + map_->objectMap_.remove(object->mapObject()); + delete object; + } + Q_ASSERT(declarativeObjectList_.count() == group_.childObjects().count()); +} + +QDeclarativeComponent* QDeclarativeGeoMapObjectView::delegate() const +{ + return delegate_; +} + +/*! + \qmlproperty Component MapObjectView::delegate + + This property holds the delegate which defines how each item in the + model should be displayed. The Component must contain exactly one + MapObject -derived element as the root element. + +*/ + +void QDeclarativeGeoMapObjectView::setDelegate(QDeclarativeComponent *delegate) +{ + if (!delegate) + return; + delegate_ = delegate; + + repopulate(); + emit delegateChanged(); +} + +void QDeclarativeGeoMapObjectView::setMapData(QDeclarativeGraphicsGeoMap* map) +{ + if (!map || !map->mapData_ || map_) // changing map on the fly not supported + return; + map_ = map; + map_->mapData_->addMapObject(&group_); +} + +void QDeclarativeGeoMapObjectView::removeInstantiatedItems() +{ + // Delete the declarative components we have instantiated. + // They will also delete the actual qgeomapobjects + QList<QGeoMapObject*> mapObjects = group_.childObjects(); + if (!mapObjects.isEmpty()) { + for (int i = 0; i < mapObjects.size(); i++) { + group_.removeChildObject(mapObjects.at(i)); + delete map_->objectMap_.take(mapObjects.at(i)); + } + } + declarativeObjectList_.clear(); +} + +// Removes and repopulates all items. +void QDeclarativeGeoMapObjectView::repopulate() +{ + if (!componentCompleted_ || !map_ || !map_->mapData_ || !delegate_ || !model_) + return; + // Free any earlier instances + removeInstantiatedItems(); + + // Iterate model data and instantiate delegates. + // We could use more specialized landmark model calls here too, + // but hopefully the support will be leveraged to a general model + // level. + QDeclarativeGeoMapObject* mapObject; + for (int i = 0; i < model_->rowCount(); ++i) { + mapObject = createItem(i); + if (!mapObject) + break; + declarativeObjectList_.append(mapObject); + mapObject->setVisible(visible_); + mapObject->setMap(map_); + group_.addChildObject(mapObject->mapObject()); + // Needed in order for mouse areas to work. + map_->objectMap_.insert(mapObject->mapObject(), mapObject); + } +} + +// Currently item creation is tightly bound to landmark model. Some day +// this may be leveraged to any user defined model or e.g. XML model. +QDeclarativeGeoMapObject* QDeclarativeGeoMapObjectView::createItem(int modelRow) +{ + if (!delegate_ || !model_) + return NULL; + QModelIndex index = model_->index(modelRow, 0); // column 0 + if (!index.isValid()) { + qWarning() << "QDeclarativeGeoMapObject Index is not valid: " << modelRow; + return NULL; + } + QHashIterator<int, QByteArray> iterator(model_->roleNames()); + QDeclarativeContext *itemContext = new QDeclarativeContext(qmlContext(this)); + while (iterator.hasNext()) { + iterator.next(); + QVariant modelData = model_->data(index, iterator.key()); + if (!modelData.isValid()) + continue; + // This call would fail for <QObject*> Need to be figured out why + // if the model support is leveraged. + QObject *data_ptr = modelData.value<QDeclarativeLandmark*>(); + if (!data_ptr) + continue; + itemContext->setContextProperty(QLatin1String(iterator.value().data()), data_ptr); + // To avoid name collisions (delegate has same named attribute as model's role) + // one can add here that the data is accessible also e.g. via 'model'. + // In case of landmarks, two of the following are then equivalent: + // latitude : landmark.coordinate.latitude + // latitude : model.landmark.coordinate.latitude + // itemContext->setContextProperty(QLatin1String("model."), data_ptr); + // At the time being, it is however uncertain how to make it from a + // QtMobility project (QDeclarativeVisualDataModel not available). + // This however needs to be figured out if model support is generalized. + } + QObject* obj = delegate_->create(itemContext); + + if (!obj) { + qWarning() << "QDeclarativeGeoMapObject map object creation failed."; + delete itemContext; + return NULL; + } + QDeclarativeGeoMapObject *declMapObj = qobject_cast<QDeclarativeGeoMapObject*>(obj); + if (!declMapObj) { + qWarning() << "QDeclarativeGeoMapObject map object delegate is of unsupported type."; + delete itemContext; + return NULL; + } + itemContext->setParent(declMapObj); + return declMapObj; +} + +/*! + \qmlproperty bool MapObjectView::visible + + This property holds whether the delegate objects created from the + model are visible or not. Default value is true. + +*/ + +void QDeclarativeGeoMapObjectView::setVisible(bool visible) +{ + if (visible_ == visible) + return; + visible_ = visible; + + QList<QGeoMapObject*> mapObjects = group_.childObjects(); + if (!mapObjects.isEmpty()) { + for (int i = 0; i < mapObjects.count(); ++i) { + mapObjects.at(i)->setVisible(visible_); + } + } + emit visibleChanged(); +} + +bool QDeclarativeGeoMapObjectView::isVisible() const +{ + return visible_; +} + +/*! + \qmlproperty int MapObjectView::z + + This property holds the z-value of the MapObjectView. + It determines the z-value of the instantiated delegates. + + As with other Map objects, objects with same z-value are + drawn in insertion order. + +*/ + +void QDeclarativeGeoMapObjectView::setZValue(qreal zValue) +{ + group_.setZValue(zValue); + emit zChanged(); +} + +qreal QDeclarativeGeoMapObjectView::zValue() +{ + return group_.zValue(); +} + +#include "moc_qdeclarativegeomapobject_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomapobject_p.h b/src/imports/location/qdeclarativegeomapobject_p.h new file mode 100644 index 00000000..e17619ca --- /dev/null +++ b/src/imports/location/qdeclarativegeomapobject_p.h @@ -0,0 +1,159 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPOBJECT_H +#define QDECLARATIVEGEOMAPOBJECT_H + +#include "qgeomapobject.h" +#include "qdeclarativegeomapmouseevent_p.h" +#include "qgeomapgroupobject.h" +#include "QModelIndex" + +#include <QtDeclarative/qdeclarativeitem.h> +class QAbstractItemModel; + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGraphicsGeoMap; +class QDeclarativeGeoMapMouseArea; + +class QDeclarativeGeoMapObject : public QDeclarativeItem +{ + Q_OBJECT + + Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) + +public: + QDeclarativeGeoMapObject(QDeclarativeItem *parent = 0); + ~QDeclarativeGeoMapObject(); + + virtual void componentComplete(); + + virtual void setMap(QDeclarativeGraphicsGeoMap *map); + QDeclarativeGraphicsGeoMap* map() const; + + void setMapObject(QGeoMapObject *object); + QGeoMapObject* mapObject(); + + void setVisible(bool visible); + bool isVisible() const; + + virtual void doubleClickEvent(QDeclarativeGeoMapMouseEvent *event); + virtual void pressEvent(QDeclarativeGeoMapMouseEvent *event); + virtual void releaseEvent(QDeclarativeGeoMapMouseEvent *event); + virtual void enterEvent(); + virtual void exitEvent(); + virtual void moveEvent(QDeclarativeGeoMapMouseEvent *event); + +Q_SIGNALS: + void visibleChanged(bool visible); + +private Q_SLOTS: + void parentZChanged(); + +private: + QGeoMapObject *object_; + bool visible_; + QDeclarativeGraphicsGeoMap* map_; + QList<QDeclarativeGeoMapMouseArea*> mouseAreas_; +}; + + +class QDeclarativeGeoMapObjectView : public QObject, public QDeclarativeParserStatus +{ + Q_OBJECT + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QDeclarativeComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) + Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) + Q_PROPERTY(qreal z READ zValue WRITE setZValue NOTIFY zChanged) + +public: + QDeclarativeGeoMapObjectView(QDeclarativeItem *parent = 0); + ~QDeclarativeGeoMapObjectView(); + + QVariant model() const; + void setModel(const QVariant &); + + QDeclarativeComponent *delegate() const; + void setDelegate(QDeclarativeComponent*); + + void setMapData(QDeclarativeGraphicsGeoMap*); + void repopulate(); + void removeInstantiatedItems(); + + qreal zValue(); + void setZValue(qreal zValue); + + void setVisible(bool visible); + bool isVisible() const; + + QDeclarativeGeoMapObject* createItem(int modelRow); + // From QDeclarativeParserStatus + virtual void componentComplete(); + void classBegin() {} + +Q_SIGNALS: + void modelChanged(); + void delegateChanged(); + void visibleChanged(); + void zChanged(); + +private Q_SLOTS: + void modelReset(); + void modelRowsInserted(QModelIndex, int start, int end); + void modelRowsRemoved(QModelIndex, int start, int end); + +private: + bool visible_; + bool componentCompleted_; + QDeclarativeComponent *delegate_; + QVariant modelVariant_; + QAbstractItemModel* model_; + QDeclarativeGraphicsGeoMap *map_; + QGeoMapGroupObject group_; + QList<QDeclarativeGeoMapObject*> declarativeObjectList_; +}; + +QTM_END_NAMESPACE +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapObject)); +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapObjectView)); + +#endif diff --git a/src/imports/location/qdeclarativegeomapobjectborder.cpp b/src/imports/location/qdeclarativegeomapobjectborder.cpp new file mode 100644 index 00000000..aadb51ec --- /dev/null +++ b/src/imports/location/qdeclarativegeomapobjectborder.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomapobjectborder_p.h" + +#include <QColor> +#include <QBrush> + +QTM_BEGIN_NAMESPACE + +QDeclarativeGeoMapObjectBorder::QDeclarativeGeoMapObjectBorder(QObject *parent) + : QObject(parent), + m_width(1) {} + +QDeclarativeGeoMapObjectBorder::~QDeclarativeGeoMapObjectBorder() {} + +void QDeclarativeGeoMapObjectBorder::setColor(const QColor &color) +{ + if (m_color == color) + return; + + m_color = color; + emit colorChanged(m_color); +} + +QColor QDeclarativeGeoMapObjectBorder::color() const +{ + return m_color; +} + +void QDeclarativeGeoMapObjectBorder::setWidth(int width) +{ + if (m_width == width) + return; + + m_width = width; + emit widthChanged(width); +} + +int QDeclarativeGeoMapObjectBorder::width() const +{ + return m_width; +} + +#include "moc_qdeclarativegeomapobjectborder_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/imports/location/qdeclarativegeomapobjectborder_p.h b/src/imports/location/qdeclarativegeomapobjectborder_p.h new file mode 100644 index 00000000..75f34a08 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapobjectborder_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPOBJECTBORDER_H +#define QDECLARATIVEGEOMAPOBJECTBORDER_H + +#include "qmobilityglobal.h" +#include <QtDeclarative/qdeclarative.h> + +#include <QObject> +#include <QColor> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoMapObjectBorder : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) + +public: + QDeclarativeGeoMapObjectBorder(QObject *parent = 0); + ~QDeclarativeGeoMapObjectBorder(); + + QColor color() const; + void setColor(const QColor &color); + + int width() const; + void setWidth(int width); + +Q_SIGNALS: + void colorChanged(const QColor &color); + void widthChanged(int width); + +private: + QColor m_color; + int m_width; + Q_DISABLE_COPY(QDeclarativeGeoMapObjectBorder) +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapObjectBorder)); + +#endif diff --git a/src/imports/location/qdeclarativegeomappixmapobject.cpp b/src/imports/location/qdeclarativegeomappixmapobject.cpp new file mode 100644 index 00000000..4533fe8f --- /dev/null +++ b/src/imports/location/qdeclarativegeomappixmapobject.cpp @@ -0,0 +1,353 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomappixmapobject_p.h" + +#include <QBrush> +#include <QUrl> +#include <QFile> +#include <QIODevice> +#include <QImage> +#include <QImageReader> + +#include <QtDeclarative/qdeclarativeengine.h> +#include <QtDeclarative/qdeclarativecontext.h> + +#include <QDebug> + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass MapImage + + \brief The MapImage element displays an image on a map. + \inherits QGeoMapPixmapObject + + \ingroup qml-location-maps + + The image loaded from \l source will be drawn \l offset.x and + \l offset.y pixels away from the on-screen position of \l coordinate. + + If \l source does not point to an image or \l coordinate is + invalid nothing will be displayed. + + The status of the image loading can be monitored via \l status. + + An example of map image: + \snippet examples/declarative-location/landmarkmap/landmarkmap.qml MapImage + + The MapImage element is part of the \bold{QtMobility.location 1.2} module. +*/ + +QDeclarativeGeoMapPixmapObject::QDeclarativeGeoMapPixmapObject(QDeclarativeItem *parent) + : QDeclarativeGeoMapObject(parent), + pixmap_(0), + reply_(0), + status_(QDeclarativeGeoMapPixmapObject::Null) +{ + pixmap_ = new QGeoMapPixmapObject(); + setMapObject(pixmap_); + + connect(pixmap_, + SIGNAL(offsetChanged(QPoint)), + this, + SIGNAL(offsetChanged(QPoint))); +} + +QDeclarativeGeoMapPixmapObject::~QDeclarativeGeoMapPixmapObject() +{ + delete pixmap_; +} + +/*! + \qmlproperty Coordinate MapImage::coordinate + + This property holds the coordinate at which to anchor the image. +*/ + +void QDeclarativeGeoMapPixmapObject::setCoordinate(QDeclarativeCoordinate *coordinate) +{ + if (!coordinate || coordinate == coordinate_) + return; + coordinate_ = coordinate; + + connect(coordinate_, + SIGNAL(latitudeChanged(double)), + this, + SLOT(coordinateLatitudeChanged(double))); + connect(coordinate_, + SIGNAL(longitudeChanged(double)), + this, + SLOT(coordinateLongitudeChanged(double))); + connect(coordinate_, + SIGNAL(altitudeChanged(double)), + this, + SLOT(coordinateAltitudeChanged(double))); + + pixmap_->setCoordinate(coordinate->coordinate()); + emit coordinateChanged(coordinate_); +} + +QDeclarativeCoordinate* QDeclarativeGeoMapPixmapObject::coordinate() +{ + return coordinate_; +} + +void QDeclarativeGeoMapPixmapObject::coordinateLatitudeChanged(double /*latitude*/) +{ + pixmap_->setCoordinate(coordinate_->coordinate()); +} + +void QDeclarativeGeoMapPixmapObject::coordinateLongitudeChanged(double /*longitude*/) +{ + pixmap_->setCoordinate(coordinate_->coordinate()); +} + +void QDeclarativeGeoMapPixmapObject::coordinateAltitudeChanged(double /*altitude*/) +{ + pixmap_->setCoordinate(coordinate_->coordinate()); +} + +/*! + \qmlproperty int MapImage::offset.x + \qmlproperty int MapImage::offset.y + + These properties hold the offset from the on-screen position of + \l coordinate at which the image should be displayed. + + They both default to 0. +*/ + +QPoint QDeclarativeGeoMapPixmapObject::offset() const +{ + return pixmap_->offset(); +} + +void QDeclarativeGeoMapPixmapObject::setOffset(const QPoint &offset) +{ + pixmap_->setOffset(offset); +} + +/*! + \qmlproperty url MapImage::source + + This property holds the URL describing the location of the image to + display. + + The URL can be absolute or relative to where the QML file + was loaded from, and can be a local file, a file embedded within + a Qt Resource bundle, or a file retrieved from the network. +*/ + +void QDeclarativeGeoMapPixmapObject::setSource(const QUrl &source) +{ + if (source_ == source) + return; + + source_ = source; + + load(); + + emit sourceChanged(source); +} + +QUrl QDeclarativeGeoMapPixmapObject::source() const +{ + return source_; +} + +/*! + \qmlproperty enumeration MapImage::status + + This property holds the status of image loading. It can be one of: + \list + \o MapImage.Null - no image has been set + \o MapImage.Ready - the image has been loaded + \o MapImage.Loading - the image is currently being loaded + \o MapImage.Error - an error occurred while loading the image + \endlist +*/ + +QDeclarativeGeoMapPixmapObject::Status QDeclarativeGeoMapPixmapObject::status() const +{ + return status_; +} + + +void QDeclarativeGeoMapPixmapObject::setStatus(const QDeclarativeGeoMapPixmapObject::Status status) +{ + if (status_ == status) + return; + + status_ = status; + + emit statusChanged(status_); +} + +void QDeclarativeGeoMapPixmapObject::load() +{ + // need to deal with absolute / relative local / remote files + + QUrl url = QDeclarativeEngine::contextForObject(this)->resolvedUrl(source_); + + QString path; + + if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0) { + if (url.authority().isEmpty()) + path = QLatin1Char(':') + url.path(); + } else if (url.scheme().compare(QLatin1String("file"), Qt::CaseInsensitive) == 0) { + path = url.toLocalFile(); + } + + if (!path.isEmpty()) { + QFile f(path); + if (f.open(QIODevice::ReadOnly)) { + QImage image; + QImageReader imageReader(&f); + if (imageReader.read(&image)) { + pixmap_->setPixmap(QPixmap::fromImage(image)); + setStatus(QDeclarativeGeoMapPixmapObject::Ready); + } else { + pixmap_->setPixmap(QPixmap()); + setStatus(QDeclarativeGeoMapPixmapObject::Error); + //qWarning() << "image read fail"; + } + } else { + pixmap_->setPixmap(QPixmap()); + setStatus(QDeclarativeGeoMapPixmapObject::Error); + //qWarning() << "file open fail"; + } + } else { + if (reply_) { + reply_->abort(); + reply_->deleteLater(); + reply_ = 0; + } + + QDeclarativeEngine *engine = QDeclarativeEngine::contextForObject(this)->engine(); + if (engine) { + QNetworkAccessManager *nam = engine->networkAccessManager(); + reply_ = nam->get(QNetworkRequest(url)); + + if (reply_->isFinished()) { + if (reply_->error() == QNetworkReply::NoError) { + finished(); + } else { + error(reply_->error()); + } + delete reply_; + reply_ = 0; + return; + } + + setStatus(QDeclarativeGeoMapPixmapObject::Loading); + + connect(reply_, + SIGNAL(finished()), + this, + SLOT(finished())); + connect(reply_, + SIGNAL(error(QNetworkReply::NetworkError)), + this, + SLOT(error(QNetworkReply::NetworkError))); + + } else { + pixmap_->setPixmap(QPixmap()); + setStatus(QDeclarativeGeoMapPixmapObject::Error); + //qWarning() << "null engine fail"; + } + } +} + +void QDeclarativeGeoMapPixmapObject::finished() +{ + if (reply_->error() != QNetworkReply::NoError) { + reply_->deleteLater(); + reply_ = 0; + return; + } + + QImage image; + QImageReader imageReader(reply_); + if (imageReader.read(&image)) { + pixmap_->setPixmap(QPixmap::fromImage(image)); + setStatus(QDeclarativeGeoMapPixmapObject::Ready); + } else { + pixmap_->setPixmap(QPixmap()); + setStatus(QDeclarativeGeoMapPixmapObject::Error); + //qWarning() << "image read fail"; + } + + reply_->deleteLater(); + reply_ = 0; +} + +void QDeclarativeGeoMapPixmapObject::error(QNetworkReply::NetworkError error) +{ + Q_UNUSED(error) + reply_->deleteLater(); + reply_ = 0; + + pixmap_->setPixmap(QPixmap()); + setStatus(QDeclarativeGeoMapPixmapObject::Error); + //qWarning() << "network error fail"; +} + +/*! + \qmlproperty int MapImage::z + + This property holds the z-value of the image. + + Map objects are drawn in z-value order, and objects with the + same z-value will be drawn in insertion order. +*/ + +/*! + \qmlproperty bool MapImage::visible + + This property holds a boolean corresponding to whether or not the + image is visible. +*/ + +#include "moc_qdeclarativegeomappixmapobject_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/imports/location/qdeclarativegeomappixmapobject_p.h b/src/imports/location/qdeclarativegeomappixmapobject_p.h new file mode 100644 index 00000000..bf869efb --- /dev/null +++ b/src/imports/location/qdeclarativegeomappixmapobject_p.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPPIXMAPOBJECT_H +#define QDECLARATIVEGEOMAPPIXMAPOBJECT_H + +#include "qdeclarativegeomapobject_p.h" +#include "qdeclarativecoordinate_p.h" +#include "qgeomappixmapobject.h" + +#include <QColor> +#include <QUrl> +#include <QNetworkReply> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoMapPixmapObject : public QDeclarativeGeoMapObject +{ + Q_OBJECT + Q_ENUMS(Status) + + Q_PROPERTY(QDeclarativeCoordinate* coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QPoint offset READ offset WRITE setOffset NOTIFY offsetChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + +public: + enum Status { + Null, + Ready, + Loading, + Error + }; + + QDeclarativeGeoMapPixmapObject(QDeclarativeItem *parent = 0); + ~QDeclarativeGeoMapPixmapObject(); + + QDeclarativeCoordinate* coordinate(); + void setCoordinate(QDeclarativeCoordinate *coordinate); + + QUrl source() const; + void setSource(const QUrl &source); + + QPoint offset() const; + void setOffset(const QPoint &offset); + + Status status() const; + +Q_SIGNALS: + void coordinateChanged(const QDeclarativeCoordinate *coordinate); + void sourceChanged(const QUrl &source); + void offsetChanged(const QPoint &offset); + void statusChanged(QDeclarativeGeoMapPixmapObject::Status status); + +private Q_SLOTS: + void coordinateLatitudeChanged(double latitude); + void coordinateLongitudeChanged(double longitude); + void coordinateAltitudeChanged(double altitude); + void finished(); + void error(QNetworkReply::NetworkError error); + +private: + void setStatus(const QDeclarativeGeoMapPixmapObject::Status status); + void load(); + + QGeoMapPixmapObject* pixmap_; + QDeclarativeCoordinate *coordinate_; + QUrl source_; + QNetworkReply *reply_; + Status status_; + + Q_DISABLE_COPY(QDeclarativeGeoMapPixmapObject) +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapPixmapObject)); + +#endif diff --git a/src/imports/location/qdeclarativegeomappolygonobject.cpp b/src/imports/location/qdeclarativegeomappolygonobject.cpp new file mode 100644 index 00000000..38dbcb19 --- /dev/null +++ b/src/imports/location/qdeclarativegeomappolygonobject.cpp @@ -0,0 +1,305 @@ + +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomappolygonobject_p.h" + +#include <QColor> +#include <QBrush> + +#include <QtDeclarative/qdeclarativeinfo.h> + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass MapPolygon + + \brief The MapPolygon element displays a polygon on a map. + \inherits QGeoMapPolygonObject + + \ingroup qml-location-maps + + The polygon is specified in terms of an ordered list of + coordinates. Any invalid coordinates in the list will be ignored. + + If the list contains less than 3 valid coordinates the polygon + will not be displayed. + + Simplistic example to illustrate, this element could be defined in Map body: + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Basic MapPolygon + + The MapPolygon element is part of the \bold{QtMobility.location 1.2} module. +*/ + +QDeclarativeGeoMapPolygonObject::QDeclarativeGeoMapPolygonObject(QDeclarativeItem *parent) + : QDeclarativeGeoMapObject(parent), polygon_(0), componentCompleted_(false) +{ + polygon_ = new QGeoMapPolygonObject(); + setMapObject(polygon_); + + connect(&border_, + SIGNAL(colorChanged(QColor)), + this, + SLOT(borderColorChanged(QColor))); + connect(&border_, + SIGNAL(widthChanged(int)), + this, + SLOT(borderWidthChanged(int))); +} + +QDeclarativeGeoMapPolygonObject::~QDeclarativeGeoMapPolygonObject() +{ + // QML engine deletes coordinates, no need to delete them here. + path_.clear(); + delete polygon_; +} + +/*! + \qmlproperty list<Coordinate> MapPolygon::path + \default + + This property holds the ordered list of coordinates which + define the polygon. +*/ + +QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativeGeoMapPolygonObject::declarativePath() +{ + return QDeclarativeListProperty<QDeclarativeCoordinate>(this, + 0, + path_append, + path_count, + path_at, + path_clear); +} + +void QDeclarativeGeoMapPolygonObject::path_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *coordinate) +{ + QDeclarativeGeoMapPolygonObject* poly = static_cast<QDeclarativeGeoMapPolygonObject*>(prop->object); + poly->path_.append(coordinate); + QList<QGeoCoordinate> p = poly->polygon_->path(); + p.append(coordinate->coordinate()); + poly->polygon_->setPath(p); + poly->pathPropertyChanged(); +} + +int QDeclarativeGeoMapPolygonObject::path_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) +{ + return static_cast<QDeclarativeGeoMapPolygonObject*>(prop->object)->path_.count(); +} + +QDeclarativeCoordinate* QDeclarativeGeoMapPolygonObject::path_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, int index) +{ + return static_cast<QDeclarativeGeoMapPolygonObject*>(prop->object)->path_.at(index); +} + +void QDeclarativeGeoMapPolygonObject::path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) +{ + QDeclarativeGeoMapPolygonObject* poly = static_cast<QDeclarativeGeoMapPolygonObject*>(prop->object); + QList<QDeclarativeCoordinate*> p = poly->path_; + qDeleteAll(p); + p.clear(); + poly->polygon_->setPath(QList<QGeoCoordinate>()); + poly->pathPropertyChanged(); +} + +void QDeclarativeGeoMapPolygonObject::pathPropertyChanged() +{ + if (componentCompleted_) + emit pathChanged(); +} + +void QDeclarativeGeoMapPolygonObject::componentComplete() +{ + // Setup member coordinates + QObjectList kids = children(); + QList<QGeoCoordinate> path = polygon_->path(); + for (int i = 0; i < kids.size(); ++i) { + QDeclarativeCoordinate *coordinate = qobject_cast<QDeclarativeCoordinate*>(kids.at(i)); + if (coordinate) { + path_.append(coordinate); + path.append(coordinate->coordinate()); + } else { + qmlInfo(this) << tr("Member is not a Coordinate"); + } + } + polygon_->setPath(path); + componentCompleted_ = true; + QDeclarativeGeoMapObject::componentComplete(); +} + +/*! + \qmlproperty color MapPolygon::color + + This property holds the color used to fill the circle. + + The default value corresponds to a transparent color. +*/ + +void QDeclarativeGeoMapPolygonObject::setColor(const QColor &color) +{ + if (color_ == color) + return; + + color_ = color; + QBrush m_brush(color); + polygon_->setBrush(m_brush); + emit colorChanged(color_); +} + +QColor QDeclarativeGeoMapPolygonObject::color() const +{ + return color_; +} + +/*! + \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. + + 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. + + For no line, use a width of 0 or a transparent color. +*/ + +QDeclarativeGeoMapObjectBorder* QDeclarativeGeoMapPolygonObject::border() +{ + return &border_; +} + +void QDeclarativeGeoMapPolygonObject::borderColorChanged(const QColor &color) +{ + QPen p = polygon_->pen(); + p.setColor(color); + polygon_->setPen(p); +} + +void QDeclarativeGeoMapPolygonObject::borderWidthChanged(int width) +{ + QPen p = polygon_->pen(); + p.setWidth(width); + if (width == 0) + p.setStyle(Qt::NoPen); + else + p.setStyle(Qt::SolidLine); + polygon_->setPen(p); +} + +/*! + \qmlmethod MapPolygon::addCoordinate(Coordinate) + + Adds coordinate to the path. The resulting path is derived + from values at the time of assignment, meaning that later changes + in values are not reflected in the path. + + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Adding to polygon + + \sa removeCoordinate + +*/ + +void QDeclarativeGeoMapPolygonObject::addCoordinate(QDeclarativeCoordinate* coordinate) +{ + path_.append(coordinate); + QList<QGeoCoordinate> p = polygon_->path(); + p.append(coordinate->coordinate()); + polygon_->setPath(p); + emit pathChanged(); +} + +/*! + \qmlmethod MapPolygon::removeCoordinate(Coordinate) + + Remove coordinate from the path. Removed Coordinate is not deleted. + If there are multiple instances of the same coordinate, the one added + last is removed. + + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Removing from polygon + + If more finetuned control is needed, one can also + iterate and/or use the inherent index property of the path list. + + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Iterating and removing polyline + + \sa addCoordinate + +*/ + +void QDeclarativeGeoMapPolygonObject::removeCoordinate(QDeclarativeCoordinate* coordinate) +{ + int index = path_.lastIndexOf(coordinate); + if (index == -1) { + qmlInfo(this) << tr("Cannot remove nonexistent coordinate."); + return; + } + QList<QGeoCoordinate> path = polygon_->path(); + if (path.count() < index + 1) { + qmlInfo(this) << tr("Cannot remove the coordinate, it does not exist."); + return; + } + path.removeAt(index); + path_.removeAt(index); + polygon_->setPath(path); + emit pathChanged(); +} + +/*! + \qmlproperty int MapPolygon::z + + This property holds the z-value of the polygon. + + Map objects are drawn in z-value order, and objects with the + same z-value will be drawn in insertion order. +*/ + +/*! + \qmlproperty bool MapPolygon::visible + + This property holds a boolean corresponding to whether or not the + polygon is visible. +*/ + +#include "moc_qdeclarativegeomappolygonobject_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/imports/location/qdeclarativegeomappolygonobject_p.h b/src/imports/location/qdeclarativegeomappolygonobject_p.h new file mode 100644 index 00000000..1c409df3 --- /dev/null +++ b/src/imports/location/qdeclarativegeomappolygonobject_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPPOLYGONOBJECT_H +#define QDECLARATIVEGEOMAPPOLYGONOBJECT_H + +#include "qdeclarativegeomapobject_p.h" +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeomapobjectborder_p.h" +#include "qgeomappolygonobject.h" + +#include <QDeclarativeListProperty> + +class QColor; +class QBrush; + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoMapPolygonObject : public QDeclarativeGeoMapObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeCoordinate> path READ declarativePath NOTIFY pathChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QDeclarativeGeoMapObjectBorder* border READ border) + +public: + QDeclarativeGeoMapPolygonObject(QDeclarativeItem *parent = 0); + ~QDeclarativeGeoMapPolygonObject(); + + QDeclarativeListProperty<QDeclarativeCoordinate> declarativePath(); + + Q_INVOKABLE void addCoordinate(QDeclarativeCoordinate* coordinate); + Q_INVOKABLE void removeCoordinate(QDeclarativeCoordinate* coordinate); + + QColor color() const; + void setColor(const QColor &color); + + // From QDeclarativeParserStatus + virtual void classBegin() {} + virtual void componentComplete(); + + QDeclarativeGeoMapObjectBorder* border(); + +Q_SIGNALS: + void colorChanged(const QColor &color); + void pathChanged(); + +private Q_SLOTS: + void borderColorChanged(const QColor &color); + void borderWidthChanged(int width); + +private: + static void path_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *coordinate); + static int path_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop); + static QDeclarativeCoordinate* path_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, int index); + static void path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop); + void pathPropertyChanged(); + + QGeoMapPolygonObject* polygon_; + QList<QDeclarativeCoordinate*> path_; + QColor color_; + QDeclarativeGeoMapObjectBorder border_; + bool componentCompleted_; +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapPolygonObject)); + +#endif diff --git a/src/imports/location/qdeclarativegeomappolylineobject.cpp b/src/imports/location/qdeclarativegeomappolylineobject.cpp new file mode 100644 index 00000000..13c8b7a6 --- /dev/null +++ b/src/imports/location/qdeclarativegeomappolylineobject.cpp @@ -0,0 +1,280 @@ + +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomappolylineobject_p.h" + +#include <QColor> +#include <QBrush> + +#include <QtDeclarative/qdeclarativeinfo.h> + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass MapPolyline + + \brief The MapPolyline element displays a polyline on a map. + \inherits QGeoMapPolylineObject + + \ingroup qml-location-maps + + The polyline is specified in terms of an ordered list of + coordinates. Any invalid coordinates in the list will be ignored. + + If the list contains less than 2 valid coordinates the polyline + will not be displayed. + + Simplistic example to illustrate, this element could be defined in Map body: + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Basic MapPolyline + + The MapPolyline element is part of the \bold{QtMobility.location 1.2} module. +*/ + +QDeclarativeGeoMapPolylineObject::QDeclarativeGeoMapPolylineObject(QDeclarativeItem *parent) + : QDeclarativeGeoMapObject(parent), polyline_(0), componentCompleted_(false) +{ + polyline_ = new QGeoMapPolylineObject(); + setMapObject(polyline_); + + connect(&border_, + SIGNAL(colorChanged(QColor)), + this, + SLOT(borderColorChanged(QColor))); + connect(&border_, + SIGNAL(widthChanged(int)), + this, + SLOT(borderWidthChanged(int))); +} + +QDeclarativeGeoMapPolylineObject::~QDeclarativeGeoMapPolylineObject() +{ + // QML engine will delete the actual declarative coordinates. + path_.clear(); + delete polyline_; +} + +/*! + \qmlproperty list<Coordinate> MapPolyline::path + \default + + This property holds the ordered list of coordinates which + define the polyline. +*/ + +QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativeGeoMapPolylineObject::declarativePath() +{ + return QDeclarativeListProperty<QDeclarativeCoordinate>(this, + 0, + path_append, + path_count, + path_at, + path_clear); +} + +void QDeclarativeGeoMapPolylineObject::path_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *coordinate) +{ + QDeclarativeGeoMapPolylineObject* poly = static_cast<QDeclarativeGeoMapPolylineObject*>(prop->object); + poly->path_.append(coordinate); + QList<QGeoCoordinate> p = poly->polyline_->path(); + p.append(coordinate->coordinate()); + poly->polyline_->setPath(p); + poly->pathPropertyChanged(); +} + +int QDeclarativeGeoMapPolylineObject::path_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) +{ + return static_cast<QDeclarativeGeoMapPolylineObject*>(prop->object)->path_.count(); +} + +QDeclarativeCoordinate* QDeclarativeGeoMapPolylineObject::path_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, int index) +{ + return static_cast<QDeclarativeGeoMapPolylineObject*>(prop->object)->path_.at(index); +} + +void QDeclarativeGeoMapPolylineObject::path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) +{ + QDeclarativeGeoMapPolylineObject* poly = static_cast<QDeclarativeGeoMapPolylineObject*>(prop->object); + QList<QDeclarativeCoordinate*> p = poly->path_; + qDeleteAll(p); + p.clear(); + poly->polyline_->setPath(QList<QGeoCoordinate>()); + poly->pathPropertyChanged(); +} + +void QDeclarativeGeoMapPolylineObject::componentComplete() +{ + // Setup member coordinates + QObjectList kids = children(); + QList<QGeoCoordinate> path = polyline_->path(); + for (int i = 0; i < kids.size(); ++i) { + QDeclarativeCoordinate *coordinate = qobject_cast<QDeclarativeCoordinate*>(kids.at(i)); + if (coordinate) { + path_.append(coordinate); + path.append(coordinate->coordinate()); + } + } + polyline_->setPath(path); + componentCompleted_ = true; + QDeclarativeGeoMapObject::componentComplete(); +} + +void QDeclarativeGeoMapPolylineObject::pathPropertyChanged() +{ + if (componentCompleted_) + emit pathChanged(); +} + +/*! + \qmlproperty int MapPolyline::border.width + \qmlproperty color MapPolyline::border.color + + These properties hold 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. + + For no line, use a width of 0 or a transparent color. +*/ + +QDeclarativeGeoMapObjectBorder* QDeclarativeGeoMapPolylineObject::border() +{ + return &border_; +} + +void QDeclarativeGeoMapPolylineObject::borderColorChanged(const QColor &color) +{ + QPen p = polyline_->pen(); + p.setColor(color); + polyline_->setPen(p); +} + +void QDeclarativeGeoMapPolylineObject::borderWidthChanged(int width) +{ + QPen p = polyline_->pen(); + p.setWidth(width); + if (width == 0) + p.setStyle(Qt::NoPen); + else + p.setStyle(Qt::SolidLine); + polyline_->setPen(p); +} + +/*! + \qmlmethod MapPolyline::addCoordinate(Coordinate) + + Adds coordinate to the path. The resulting path is derived + from values at the time of assignment, meaning that later changes + in values are not reflected in the path. + + A basic example is to draw the path where one has been: + + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Wherever I may roam + + \sa removeCoordinate + +*/ + +void QDeclarativeGeoMapPolylineObject::addCoordinate(QDeclarativeCoordinate* coordinate) +{ + path_.append(coordinate); + QList<QGeoCoordinate> p = polyline_->path(); + p.append(coordinate->coordinate()); + polyline_->setPath(p); + emit pathChanged(); +} + +/*! + \qmlmethod MapPolyline::removeCoordinate(Coordinate) + + Remove coordinate from the path. If there are multiple instances + of the same coordinate, the one added last is removed. Removed Coordinate is not deleted. + + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Removing from polyline + + If more finetuned control is needed, one can also + iterate and/or use the inherent index property of the path list. + + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Iterating and removing polyline + + \sa addCoordinate + +*/ + +void QDeclarativeGeoMapPolylineObject::removeCoordinate(QDeclarativeCoordinate* coordinate) +{ + int index = path_.lastIndexOf(coordinate); + if (index == -1) { + qmlInfo(this) << tr("Cannot remove nonexistent coordinate."); + return; + } + QList<QGeoCoordinate> path = polyline_->path(); + if (path.count() < index + 1) { + qmlInfo(this) << tr("Cannot remove the coordinate, it does not exist."); + return; + } + path.removeAt(index); + path_.removeAt(index); + polyline_->setPath(path); + emit pathChanged(); +} + +/*! + \qmlproperty int MapPolyline::z + + This property holds the z-value of the polyline. + + Map objects are drawn in z-value order, and objects with the + same z-value will be drawn in insertion order. +*/ + +/*! + \qmlproperty bool MapPolyline::visible + + This property holds a boolean corresponding to whether or not the + polyline is visible. +*/ + +#include "moc_qdeclarativegeomappolylineobject_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/imports/location/qdeclarativegeomappolylineobject_p.h b/src/imports/location/qdeclarativegeomappolylineobject_p.h new file mode 100644 index 00000000..5a300bf5 --- /dev/null +++ b/src/imports/location/qdeclarativegeomappolylineobject_p.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPPOLYLINEOBJECT_H +#define QDECLARATIVEGEOMAPPOLYLINEOBJECT_H + +#include "qdeclarativegeomapobject_p.h" +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeomapobjectborder_p.h" +#include "qgeomappolylineobject.h" + +#include <QDeclarativeListProperty> + +class QColor; +class QBrush; + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoMapPolylineObject : public QDeclarativeGeoMapObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeCoordinate> path READ declarativePath NOTIFY pathChanged) + Q_PROPERTY(QDeclarativeGeoMapObjectBorder* border READ border) + +public: + QDeclarativeGeoMapPolylineObject(QDeclarativeItem *parent = 0); + ~QDeclarativeGeoMapPolylineObject(); + + Q_INVOKABLE void addCoordinate(QDeclarativeCoordinate* coordinate); + Q_INVOKABLE void removeCoordinate(QDeclarativeCoordinate* coordinate); + + // From QDeclarativeParserStatus + virtual void classBegin() {} + virtual void componentComplete(); + + QDeclarativeListProperty<QDeclarativeCoordinate> declarativePath(); + QDeclarativeGeoMapObjectBorder* border(); + +Q_SIGNALS: + void pathChanged(); + +private Q_SLOTS: + void borderColorChanged(const QColor &color); + void borderWidthChanged(int width); + +private: + static void path_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *coordinate); + static int path_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop); + static QDeclarativeCoordinate* path_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, int index); + static void path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop); + void pathPropertyChanged(); + + QGeoMapPolylineObject* polyline_; + QList<QDeclarativeCoordinate*> path_; + QDeclarativeGeoMapObjectBorder border_; + bool componentCompleted_; +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapPolylineObject)); + +#endif diff --git a/src/imports/location/qdeclarativegeomaprectangleobject.cpp b/src/imports/location/qdeclarativegeomaprectangleobject.cpp new file mode 100644 index 00000000..c49ea49e --- /dev/null +++ b/src/imports/location/qdeclarativegeomaprectangleobject.cpp @@ -0,0 +1,278 @@ + + + +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomaprectangleobject_p.h" + +#include <QColor> +#include <QBrush> + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass MapRectangle + + \brief The MapRectangle element displays a rectangle on a map. + \inherits QGeoMapRectangleObject + + \ingroup qml-location-maps + + The rectangle is specified in terms of the top left and bottom + right coordinates. + + If \l topLeft and \l bottomRight are not specified and valid the + rectangle will not be displayed. + + An example of one big yellow rectangle: + \snippet doc/src/snippets/declarative/testpolymapobjects.qml MapRectangle + + The MapRectangle element is part of the \bold{QtMobility.location 1.2} module. +*/ + +QDeclarativeGeoMapRectangleObject::QDeclarativeGeoMapRectangleObject(QDeclarativeItem *parent) + : QDeclarativeGeoMapObject(parent), rectangle_(0), topLeft_(0), bottomRight_(0) +{ + rectangle_ = new QGeoMapRectangleObject(); + setMapObject(rectangle_); + + connect(&border_, + SIGNAL(colorChanged(QColor)), + this, + SLOT(borderColorChanged(QColor))); + connect(&border_, + SIGNAL(widthChanged(int)), + this, + SLOT(borderWidthChanged(int))); +} + +QDeclarativeGeoMapRectangleObject::~QDeclarativeGeoMapRectangleObject() +{ + delete rectangle_; +} + +/*! + \qmlproperty Coordinate MapRectangle::topLeft + + This property holds the coordinate corresponding to the top left + corner of the rectangle. + + The default value is an invalid coordinate. +*/ + +void QDeclarativeGeoMapRectangleObject::setTopLeft(QDeclarativeCoordinate *topLeft) +{ + if (!topLeft || topLeft == topLeft_) + return; + + topLeft_ = topLeft; + + connect(topLeft_, + SIGNAL(latitudeChanged(double)), + this, + SLOT(topLeftLatitudeChanged(double))); + connect(topLeft_, + SIGNAL(longitudeChanged(double)), + this, + SLOT(topLeftLongitudeChanged(double))); + connect(topLeft_, + SIGNAL(altitudeChanged(double)), + this, + SLOT(topLeftAltitudeChanged(double))); + + rectangle_->setTopLeft(topLeft->coordinate()); + emit topLeftChanged(topLeft_); +} + +QDeclarativeCoordinate* QDeclarativeGeoMapRectangleObject::topLeft() +{ + return topLeft_; +} + +void QDeclarativeGeoMapRectangleObject::topLeftLatitudeChanged(double /*latitude*/) +{ + rectangle_->setTopLeft(topLeft_->coordinate()); +} + +void QDeclarativeGeoMapRectangleObject::topLeftLongitudeChanged(double /*longitude*/) +{ + rectangle_->setTopLeft(topLeft_->coordinate()); +} + +void QDeclarativeGeoMapRectangleObject::topLeftAltitudeChanged(double /*altitude*/) +{ + rectangle_->setTopLeft(topLeft_->coordinate()); +} + +/*! + \qmlproperty Coordinate MapRectangle::bottomRight + + This property holds the coordinate corresponding to the bottom right + corner of the rectangle. + + The default value is an invalid coordinate. +*/ + +void QDeclarativeGeoMapRectangleObject::setBottomRight(QDeclarativeCoordinate *bottomRight) +{ + if (!bottomRight || bottomRight == bottomRight_) + return; + + bottomRight_ = bottomRight; + connect(bottomRight_, + SIGNAL(latitudeChanged(double)), + this, + SLOT(bottomRightLatitudeChanged(double))); + connect(bottomRight_, + SIGNAL(longitudeChanged(double)), + this, + SLOT(bottomRightLongitudeChanged(double))); + connect(bottomRight_, + SIGNAL(altitudeChanged(double)), + this, + SLOT(bottomRightAltitudeChanged(double))); + + rectangle_->setBottomRight(bottomRight->coordinate()); + + emit bottomRightChanged(bottomRight_); +} + +QDeclarativeCoordinate* QDeclarativeGeoMapRectangleObject::bottomRight() +{ + return bottomRight_; +} + +void QDeclarativeGeoMapRectangleObject::bottomRightLatitudeChanged(double /*latitude*/) +{ + rectangle_->setBottomRight(bottomRight_->coordinate()); +} + +void QDeclarativeGeoMapRectangleObject::bottomRightLongitudeChanged(double /*longitude*/) +{ + rectangle_->setBottomRight(bottomRight_->coordinate()); +} + +void QDeclarativeGeoMapRectangleObject::bottomRightAltitudeChanged(double /*altitude*/) +{ + rectangle_->setBottomRight(bottomRight_->coordinate()); +} + +/*! + \qmlproperty color MapRectangle::color + + This property holds the color used to fill the circle. + + The default value corresponds to a transparent color. +*/ + +void QDeclarativeGeoMapRectangleObject::setColor(const QColor &color) +{ + if (color_ == color) + return; + + color_ = color; + QBrush m_brush(color); + rectangle_->setBrush(m_brush); + emit colorChanged(color_); +} + +QColor QDeclarativeGeoMapRectangleObject::color() const +{ + return color_; +} + +/*! + \qmlproperty int MapRectangle::border.width + \qmlproperty color MapRectangle::border.color + + These properties hold 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. + + For no line, use a width of 0 or a transparent color. +*/ + +QDeclarativeGeoMapObjectBorder* QDeclarativeGeoMapRectangleObject::border() +{ + return &border_; +} + +void QDeclarativeGeoMapRectangleObject::borderColorChanged(const QColor &color) +{ + QPen p = rectangle_->pen(); + p.setColor(color); + rectangle_->setPen(p); +} + +void QDeclarativeGeoMapRectangleObject::borderWidthChanged(int width) +{ + QPen p = rectangle_->pen(); + p.setWidth(width); + if (width == 0) + p.setStyle(Qt::NoPen); + else + p.setStyle(Qt::SolidLine); + rectangle_->setPen(p); +} + +/*! + \qmlproperty int MapRectangle::z + + This property holds the z-value of the rectangle. + + Map objects are drawn in z-value order, and objects with the + same z-value will be drawn in insertion order. +*/ + +/*! + \qmlproperty bool MapRectangle::visible + + This property holds a boolean corresponding to whether or not the + rectangle is visible. +*/ + +#include "moc_qdeclarativegeomaprectangleobject_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/imports/location/qdeclarativegeomaprectangleobject_p.h b/src/imports/location/qdeclarativegeomaprectangleobject_p.h new file mode 100644 index 00000000..ccd5a4f3 --- /dev/null +++ b/src/imports/location/qdeclarativegeomaprectangleobject_p.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPRECTANGLEOBJECT_H +#define QDECLARATIVEGEOMAPRECTANGLEOBJECT_H + +#include "qdeclarativegeomapobject_p.h" +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeomapobjectborder_p.h" +#include "qgeomaprectangleobject.h" + +class QColor; +class QBrush; + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoMapRectangleObject : public QDeclarativeGeoMapObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeCoordinate* topLeft READ topLeft WRITE setTopLeft NOTIFY topLeftChanged) + Q_PROPERTY(QDeclarativeCoordinate* bottomRight READ bottomRight WRITE setBottomRight NOTIFY bottomRightChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QDeclarativeGeoMapObjectBorder* border READ border) + +public: + QDeclarativeGeoMapRectangleObject(QDeclarativeItem *parent = 0); + ~QDeclarativeGeoMapRectangleObject(); + + QDeclarativeCoordinate* topLeft(); + void setTopLeft(QDeclarativeCoordinate *center); + + QDeclarativeCoordinate* bottomRight(); + void setBottomRight(QDeclarativeCoordinate *center); + + QColor color() const; + void setColor(const QColor &color); + + QDeclarativeGeoMapObjectBorder* border(); + +Q_SIGNALS: + void topLeftChanged(const QDeclarativeCoordinate *center); + void bottomRightChanged(const QDeclarativeCoordinate *center); + void colorChanged(const QColor &color); + +private Q_SLOTS: + void topLeftLatitudeChanged(double latitude); + void topLeftLongitudeChanged(double longitude); + void topLeftAltitudeChanged(double altitude); + + void bottomRightLatitudeChanged(double latitude); + void bottomRightLongitudeChanged(double longitude); + void bottomRightAltitudeChanged(double altitude); + + void borderColorChanged(const QColor &color); + void borderWidthChanged(int width); + +private: + QGeoMapRectangleObject* rectangle_; + QDeclarativeCoordinate *topLeft_; + QDeclarativeCoordinate *bottomRight_; + QColor color_; + QDeclarativeGeoMapObjectBorder border_; +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapRectangleObject)); + +#endif diff --git a/src/imports/location/qdeclarativegeomaptextobject.cpp b/src/imports/location/qdeclarativegeomaptextobject.cpp new file mode 100644 index 00000000..b54943ca --- /dev/null +++ b/src/imports/location/qdeclarativegeomaptextobject.cpp @@ -0,0 +1,406 @@ + +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomaptextobject_p.h" + +#include <QPen> +#include <QBrush> + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass MapText + + \brief The MapText element displays text on a map. + \inherits QGeoMapTextObject + + \ingroup qml-location-maps + + The string \l text will be drawn \l offset.x and \l offset.y pixels away from the + on-screen position of \l coordinate. + + The text will be rendered with font \l font and color \l color, and will + be aligned according to \l horizontalAlignment and \l verticalAlignment. + + If \l text is empty or \l coordinate is invalid nothing will be displayed. + + An example of text item: + \snippet doc/src/snippets/declarative/testpolymapobjects.qml MapText + + The MapText element is part of the \bold{QtMobility.location 1.2} module. +*/ + +QDeclarativeGeoMapTextObject::QDeclarativeGeoMapTextObject(QDeclarativeItem *parent) + : QDeclarativeGeoMapObject(parent), + text_(0), coordinate_(0) +{ + text_ = new QGeoMapTextObject(); + setMapObject(text_); + + QPen p = text_->pen(); + p.setStyle(Qt::NoPen); + text_->setPen(p); + + text_->setBrush(QBrush(Qt::black)); + + connect(text_, + SIGNAL(textChanged(QString)), + this, + SIGNAL(textChanged(QString))); + connect(text_, + SIGNAL(fontChanged(QFont)), + this, + SIGNAL(fontChanged(QFont))); + connect(text_, + SIGNAL(offsetChanged(QPoint)), + this, + SIGNAL(offsetChanged(QPoint))); + + hAlignment_ = QDeclarativeGeoMapTextObject::AlignHCenter; + vAlignment_ = QDeclarativeGeoMapTextObject::AlignVCenter; +} + +QDeclarativeGeoMapTextObject::~QDeclarativeGeoMapTextObject() +{ + delete text_; +} + +/*! + \qmlproperty Coordinate MapText::coordinate + + This property holds the coordinate at which to anchor the text. +*/ + +void QDeclarativeGeoMapTextObject::setCoordinate(QDeclarativeCoordinate *coordinate) +{ + if (!coordinate || coordinate == coordinate_) + return; + + coordinate_ = coordinate; + connect(coordinate_, + SIGNAL(latitudeChanged(double)), + this, + SLOT(coordinateLatitudeChanged(double))); + connect(coordinate_, + SIGNAL(longitudeChanged(double)), + this, + SLOT(coordinateLongitudeChanged(double))); + connect(coordinate_, + SIGNAL(altitudeChanged(double)), + this, + SLOT(coordinateAltitudeChanged(double))); + + text_->setCoordinate(coordinate->coordinate()); + emit coordinateChanged(coordinate_); +} + +QDeclarativeCoordinate* QDeclarativeGeoMapTextObject::coordinate() +{ + return coordinate_; +} + +void QDeclarativeGeoMapTextObject::coordinateLatitudeChanged(double /*latitude*/) +{ + text_->setCoordinate(coordinate_->coordinate()); +} + +void QDeclarativeGeoMapTextObject::coordinateLongitudeChanged(double /*longitude*/) +{ + text_->setCoordinate(coordinate_->coordinate()); +} + +void QDeclarativeGeoMapTextObject::coordinateAltitudeChanged(double /*altitude*/) +{ + text_->setCoordinate(coordinate_->coordinate()); +} + +/*! + \qmlproperty string MapText::text + + This property holds the text to display. + + The default value is an empty string. +*/ + +QString QDeclarativeGeoMapTextObject::text() const +{ + return text_->text(); +} + +void QDeclarativeGeoMapTextObject::setText(const QString &text) +{ + text_->setText(text); +} + +/*! + \qmlproperty string MapText::font.family + + Sets the family name of the font. + + The family name is case insensitive and may optionally include a foundry name, e.g. "Helvetica [Cronyx]". + If the family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen. + If the family isn't available a family will be set using the font matching algorithm. +*/ + +/*! + \qmlproperty bool MapText::font.bold + + Sets whether the font weight is bold. +*/ + +/*! + \qmlproperty enumeration MapText::font.weight + + Sets the font's weight. + + The weight can be one of: + \list + \o Font.Light + \o Font.Normal - the default + \o Font.DemiBold + \o Font.Bold + \o Font.Black + \endlist + + \qml + MapText { text: "Hello"; font.weight: Font.DemiBold } + \endqml +*/ + +/*! + \qmlproperty bool MapText::font.italic + + Sets whether the font has an italic style. +*/ + +/*! + \qmlproperty bool MapText::font.underline + + Sets whether the text is underlined. +*/ + +/*! + \qmlproperty bool MapText::font.strikeout + + Sets whether the font has a strikeout style. +*/ + +/*! + \qmlproperty real MapText::font.pointSize + + Sets the font size in points. The point size must be greater than zero. +*/ + +/*! + \qmlproperty int MapText::font.pixelSize + + Sets the font size in pixels. + + Using this function makes the font device dependent. + Use \c pointSize to set the size of the font in a device independent manner. +*/ + +/*! + \qmlproperty real MapText::font.letterSpacing + + Sets the letter spacing for the font. + + Letter spacing changes the default spacing between individual letters in the font. + A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing. +*/ + +/*! + \qmlproperty real MapText::font.wordSpacing + + Sets the word spacing for the font. + + Word spacing changes the default spacing between individual words. + A positive value increases the word spacing by a corresponding amount of pixels, + while a negative value decreases the inter-word spacing accordingly. +*/ + +/*! + \qmlproperty enumeration MapText::font.capitalization + + Sets the capitalization for the text. + + \list + \o Font.MixedCase - This is the normal text rendering option where no capitalization change is applied. + \o Font.AllUppercase - This alters the text to be rendered in all uppercase type. + \o Font.AllLowercase - This alters the text to be rendered in all lowercase type. + \o Font.SmallCaps - This alters the text to be rendered in small-caps type. + \o Font.Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character. + \endlist + + \qml + MapText { text: "Hello"; font.capitalization: Font.AllLowercase } + \endqml +*/ + +QFont QDeclarativeGeoMapTextObject::font() const +{ + return text_->font(); +} + +void QDeclarativeGeoMapTextObject::setFont(const QFont &font) +{ + text_->setFont(font); +} + +/*! + \qmlproperty int MapText::offset.x + \qmlproperty int MapText::offset.y + + These properties hold the offset from the on-screen position of + \l coordinate at which the text should be displayed. + + They both default to 0. +*/ + +QPoint QDeclarativeGeoMapTextObject::offset() const +{ + return text_->offset(); +} + +void QDeclarativeGeoMapTextObject::setOffset(const QPoint &offset) +{ + text_->setOffset(offset); +} + +/*! + \qmlproperty color MapText::color + + This property holds the color used to draw the text. + + The default value is black. +*/ + +void QDeclarativeGeoMapTextObject::setColor(const QColor &color) +{ + if (color_ == color) + return; + + color_ = color; + QBrush m_brush(color); + text_->setBrush(m_brush); + emit colorChanged(color_); +} + +QColor QDeclarativeGeoMapTextObject::color() const +{ + return color_; +} + +/*! + \qmlproperty enumeration MapText::horizontalAlignment + \qmlproperty enumeration MapText::verticalAlignment + + Sets the horizontal and vertical alignment of the text. + + The alignment is relative to the point \l offset.x and \l offset.y pixels away from + the on-screen position of \l coordinate. + + The valid values for \c horizontalAlignment are \c MapText.AlignLeft, + \c MapText.AlignRight and \c MapText.AlignHCenter. The valid values + for \c verticalAlignment are \c MapText.AlignTop, \c MapText.AlignBottom + and \c MapText.AlignVCenter. + + The default values are \c MapText.AlignHCenter and \c MapText.AlignVCenter + respectively. +*/ + +QDeclarativeGeoMapTextObject::HorizontalAlignment QDeclarativeGeoMapTextObject::horizontalAlignment() const +{ + return hAlignment_; +} + +void QDeclarativeGeoMapTextObject::setHorizontalAlignment(QDeclarativeGeoMapTextObject::HorizontalAlignment alignment) +{ + if (hAlignment_ == alignment) + return; + + + hAlignment_ = alignment; + + text_->setAlignment(Qt::Alignment(hAlignment_ | vAlignment_)); + + emit horizontalAlignmentChanged(hAlignment_); +} + + +QDeclarativeGeoMapTextObject::VerticalAlignment QDeclarativeGeoMapTextObject::verticalAlignment() const +{ + return vAlignment_; +} + +void QDeclarativeGeoMapTextObject::setVerticalAlignment(QDeclarativeGeoMapTextObject::VerticalAlignment alignment) +{ + if (vAlignment_ == alignment) + return; + + vAlignment_ = alignment; + + text_->setAlignment(Qt::Alignment(hAlignment_ | vAlignment_)); + + emit verticalAlignmentChanged(vAlignment_); +} + +/*! + \qmlproperty int MapText::z + + This property holds the z-value of the text. + + Map objects are drawn in z-value order, and objects with the + same z-value will be drawn in insertion order. +*/ + +/*! + \qmlproperty bool MapText::visible + + This property holds a boolean corresponding to whether or not the + text is visible. +*/ + +#include "moc_qdeclarativegeomaptextobject_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/imports/location/qdeclarativegeomaptextobject_p.h b/src/imports/location/qdeclarativegeomaptextobject_p.h new file mode 100644 index 00000000..3f54b106 --- /dev/null +++ b/src/imports/location/qdeclarativegeomaptextobject_p.h @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPTEXTOBJECT_H +#define QDECLARATIVEGEOMAPTEXTOBJECT_H + +#include "qdeclarativegeomapobject_p.h" +#include "qdeclarativecoordinate_p.h" +#include "qgeomaptextobject.h" + +#include <QColor> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoMapTextObject : public QDeclarativeGeoMapObject +{ + Q_OBJECT + Q_ENUMS(HorizontalAlignment) + Q_ENUMS(VerticalAlignment) + + Q_PROPERTY(QDeclarativeCoordinate* coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QPoint offset READ offset WRITE setOffset NOTIFY offsetChanged) + Q_PROPERTY(HorizontalAlignment horizontalAlignment READ horizontalAlignment WRITE setHorizontalAlignment NOTIFY horizontalAlignmentChanged) + Q_PROPERTY(VerticalAlignment verticalAlignment READ verticalAlignment WRITE setVerticalAlignment NOTIFY verticalAlignmentChanged) + +public: + enum HorizontalAlignment { + AlignHCenter = Qt::AlignHCenter, + AlignLeft = Qt::AlignLeft, + AlignRight = Qt::AlignRight + }; + + enum VerticalAlignment { + AlignVCenter = Qt::AlignVCenter, + AlignTop = Qt::AlignTop, + AlignBottom = Qt::AlignBottom + }; + + QDeclarativeGeoMapTextObject(QDeclarativeItem *parent = 0); + ~QDeclarativeGeoMapTextObject(); + + QDeclarativeCoordinate* coordinate(); + void setCoordinate(QDeclarativeCoordinate *coordinate); + + QString text() const; + void setText(const QString &text); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &color); + + QPoint offset() const; + void setOffset(const QPoint &offset); + + HorizontalAlignment horizontalAlignment() const; + void setHorizontalAlignment(HorizontalAlignment alignment); + + VerticalAlignment verticalAlignment() const; + void setVerticalAlignment(VerticalAlignment alignment); + +Q_SIGNALS: + void coordinateChanged(const QDeclarativeCoordinate *coordinate); + void textChanged(const QString &text); + void fontChanged(const QFont &font); + void colorChanged(const QColor &color); + void offsetChanged(const QPoint &offset); + void horizontalAlignmentChanged(HorizontalAlignment alignment); + void verticalAlignmentChanged(VerticalAlignment alignment); + +private Q_SLOTS: + void coordinateLatitudeChanged(double latitude); + void coordinateLongitudeChanged(double longitude); + void coordinateAltitudeChanged(double altitude); + +private: + QGeoMapTextObject* text_; + QDeclarativeCoordinate *coordinate_; + QColor color_; + HorizontalAlignment hAlignment_; + VerticalAlignment vAlignment_; +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoMapTextObject)); + +#endif diff --git a/src/imports/location/qdeclarativegeoplace.cpp b/src/imports/location/qdeclarativegeoplace.cpp new file mode 100644 index 00000000..7e607207 --- /dev/null +++ b/src/imports/location/qdeclarativegeoplace.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativegeoplace_p.h" + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass Place QDeclarativeGeoPlace + \brief The A Place element presents basic information about a place. + \ingroup qml-location + + This element is part of the \bold{QtMobility.location 1.1} module. + + The Place element represents basic information about a place. + + A Place contains a coordinate and the corresponding address, + along with an optional bounding box describing the minimum viewport + necessary to display the entirety of the place. + + \sa Landmark, Address, {QGeoPlace} +*/ + +QDeclarativeGeoPlace::QDeclarativeGeoPlace(QObject* parent) : + QObject(parent) +{ +} + +QDeclarativeGeoPlace::QDeclarativeGeoPlace(const QGeoPlace& place, QObject* parent) : + QObject(parent), + m_declarativeBox(place.viewport(), this), + m_declarativeCoordinate(place.coordinate(), this), + m_declarativeAddress(place.address(), this) +{ +} + +QDeclarativeGeoPlace::~QDeclarativeGeoPlace() +{ +} + +void QDeclarativeGeoPlace::setPlace(const QGeoPlace& place) +{ + m_declarativeBox.setBox(place.viewport()); + m_declarativeCoordinate.setCoordinate(place.coordinate()); + m_declarativeAddress.setAddress(place.address()); +} + +QDeclarativeGeoBoundingBox* QDeclarativeGeoPlace::viewport() +{ + return &m_declarativeBox; +} + +/*! + \qmlproperty BoundingBox Place::viewport + + This property holds the viewport of the place + (minimum viewport necessary to display the entirety of the place). + + Note: viewportChanged() signal is currently emitted only if the + whole element changes, not if only the contents of the element change. + */ + +void QDeclarativeGeoPlace::setViewport(QDeclarativeGeoBoundingBox* box) +{ + if (m_declarativeBox.box() == box->box()) + return; + m_declarativeBox.setBox(box->box()); + emit viewportChanged(); +} + +QDeclarativeCoordinate* QDeclarativeGeoPlace::coordinate() +{ + return &m_declarativeCoordinate; +} + +/*! + \qmlproperty Coordinate Place::coordinate + + This property holds coordinate where this place is located at. + + Note: coordinateChanged() signal is currently emitted only if the + whole element changes, not if only the contents of the element change. + + */ + +void QDeclarativeGeoPlace::setCoordinate(QDeclarativeCoordinate* coordinate) +{ + if (m_declarativeCoordinate.coordinate() == coordinate->coordinate()) + return; + m_declarativeCoordinate.setCoordinate(coordinate->coordinate()); + emit coordinateChanged(); +} + +QDeclarativeGeoAddress* QDeclarativeGeoPlace::address() +{ + return &m_declarativeAddress; +} + +/*! + \qmlproperty Address Place::address + + This property holds address of the place. + + Note: addressChanged() signal is currently emitted only if the + whole address element changes, not if only the contents of the element + change. + + */ + +void QDeclarativeGeoPlace::setAddress(QDeclarativeGeoAddress* address) +{ + if (m_declarativeAddress.address() == address->address()) + return; + m_declarativeAddress.setAddress(address->address()); + emit addressChanged(); +} + +#include "moc_qdeclarativegeoplace_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeoplace_p.h b/src/imports/location/qdeclarativegeoplace_p.h new file mode 100644 index 00000000..fb638514 --- /dev/null +++ b/src/imports/location/qdeclarativegeoplace_p.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEGEOPLACE_P_H +#define QDECLARATIVEGEOPLACE_P_H + +#include <qgeoplace.h> +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeoboundingbox_p.h" +#include "qdeclarativegeoaddress_p.h" + +#include <QVariant> +#include <QtDeclarative/qdeclarative.h> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoPlace : public QObject +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeGeoBoundingBox* viewport READ viewport WRITE setViewport NOTIFY viewportChanged) + Q_PROPERTY(QDeclarativeCoordinate* coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) + Q_PROPERTY(QDeclarativeGeoAddress* address READ address WRITE setAddress NOTIFY addressChanged) + +public: + explicit QDeclarativeGeoPlace(QObject* parent = 0); + QDeclarativeGeoPlace(const QGeoPlace& place, QObject* parent); + virtual ~QDeclarativeGeoPlace(); + void setPlace(const QGeoPlace& place); + + QDeclarativeGeoBoundingBox* viewport(); + void setViewport(QDeclarativeGeoBoundingBox* box); + + QDeclarativeCoordinate* coordinate(); + void setCoordinate(QDeclarativeCoordinate* coordinate); + + QDeclarativeGeoAddress* address(); + void setAddress(QDeclarativeGeoAddress* address); + +signals: + void viewportChanged(); + void coordinateChanged(); + void addressChanged(); + +private: + QDeclarativeGeoBoundingBox m_declarativeBox; + QDeclarativeCoordinate m_declarativeCoordinate; + QDeclarativeGeoAddress m_declarativeAddress; +}; + +QTM_END_NAMESPACE + +Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(QGeoPlace)) + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoPlace)); + +#endif // QDECLARATIVEGEOPLACE_P_H diff --git a/src/imports/location/qdeclarativegeoroute.cpp b/src/imports/location/qdeclarativegeoroute.cpp new file mode 100644 index 00000000..45691c67 --- /dev/null +++ b/src/imports/location/qdeclarativegeoroute.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeoroute_p.h" + +QTM_BEGIN_NAMESPACE + +QDeclarativeGeoRoute::QDeclarativeGeoRoute(QObject *parent) + : QObject(parent) {} + +QDeclarativeGeoRoute::QDeclarativeGeoRoute(const QGeoRoute &route, QObject *parent) + : QObject(parent), + route_(route) +{ + bounds_ = new QDeclarativeGeoBoundingBox(route.bounds(), this); + + for (int i = 0; i < route_.path().size(); ++i) + path_.append(new QDeclarativeCoordinate(route_.path().at(i), this)); + + QGeoRouteSegment segment = route_.firstRouteSegment(); + while (segment.isValid()) { + segments_.append(new QDeclarativeGeoRouteSegment(segment, this)); + segment = segment.nextRouteSegment(); + } +} + +QDeclarativeGeoRoute::~QDeclarativeGeoRoute() {} + +QDeclarativeGeoBoundingBox* QDeclarativeGeoRoute::bounds() const +{ + return bounds_; +} + +int QDeclarativeGeoRoute::travelTime() const +{ + return route_.travelTime(); +} + +qreal QDeclarativeGeoRoute::distance() const +{ + return route_.distance(); +} + +QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativeGeoRoute::path() +{ + return QDeclarativeListProperty<QDeclarativeCoordinate>(this, + 0, + path_append, + path_count, + path_at, + path_clear); +} + +void QDeclarativeGeoRoute::path_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *coordinate) +{ + static_cast<QDeclarativeGeoRoute*>(prop->object)->path_.append(coordinate); +} + +int QDeclarativeGeoRoute::path_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) +{ + return static_cast<QDeclarativeGeoRoute*>(prop->object)->path_.count(); +} + +QDeclarativeCoordinate* QDeclarativeGeoRoute::path_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, int index) +{ + return static_cast<QDeclarativeGeoRoute*>(prop->object)->path_.at(index); +} + +void QDeclarativeGeoRoute::path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) +{ + static_cast<QDeclarativeGeoRoute*>(prop->object)->path_.clear(); +} + +QDeclarativeListProperty<QDeclarativeGeoRouteSegment> QDeclarativeGeoRoute::segments() +{ + return QDeclarativeListProperty<QDeclarativeGeoRouteSegment>(this, + 0, + segments_append, + segments_count, + segments_at, + segments_clear); +} + +void QDeclarativeGeoRoute::segments_append(QDeclarativeListProperty<QDeclarativeGeoRouteSegment> *prop, QDeclarativeGeoRouteSegment *segment) +{ + static_cast<QDeclarativeGeoRoute*>(prop->object)->segments_.append(segment); +} + +int QDeclarativeGeoRoute::segments_count(QDeclarativeListProperty<QDeclarativeGeoRouteSegment> *prop) +{ + return static_cast<QDeclarativeGeoRoute*>(prop->object)->segments_.count(); +} + +QDeclarativeGeoRouteSegment* QDeclarativeGeoRoute::segments_at(QDeclarativeListProperty<QDeclarativeGeoRouteSegment> *prop, int index) +{ + return static_cast<QDeclarativeGeoRoute*>(prop->object)->segments_.at(index); +} + +void QDeclarativeGeoRoute::segments_clear(QDeclarativeListProperty<QDeclarativeGeoRouteSegment> *prop) +{ + static_cast<QDeclarativeGeoRoute*>(prop->object)->segments_.clear(); +} + +#include "moc_qdeclarativegeoroute_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeoroute_p.h b/src/imports/location/qdeclarativegeoroute_p.h new file mode 100644 index 00000000..51ba8c9d --- /dev/null +++ b/src/imports/location/qdeclarativegeoroute_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOROUTE_H +#define QDECLARATIVEGEOROUTE_H + +#include "qdeclarativegeoboundingbox_p.h" +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeoroutesegment_p.h" + +#include <qgeoroute.h> + +#include <QObject> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoRoute : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeGeoBoundingBox *bounds READ bounds CONSTANT) + Q_PROPERTY(int travelTime READ travelTime CONSTANT) + Q_PROPERTY(qreal distance READ distance CONSTANT) + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeCoordinate> path READ path) + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeGeoRouteSegment> segments READ segments) + +public: + QDeclarativeGeoRoute(QObject *parent = 0); + QDeclarativeGeoRoute(const QGeoRoute &route, QObject *parent = 0); + ~QDeclarativeGeoRoute(); + + QDeclarativeGeoBoundingBox* bounds() const; + int travelTime() const; + qreal distance() const; + QDeclarativeListProperty<QDeclarativeCoordinate> path(); + QDeclarativeListProperty<QDeclarativeGeoRouteSegment> segments(); + +private: + static void path_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *coordinate); + static int path_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop); + static QDeclarativeCoordinate* path_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, int index); + static void path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop); + + static void segments_append(QDeclarativeListProperty<QDeclarativeGeoRouteSegment> *prop, QDeclarativeGeoRouteSegment *segment); + static int segments_count(QDeclarativeListProperty<QDeclarativeGeoRouteSegment> *prop); + static QDeclarativeGeoRouteSegment* segments_at(QDeclarativeListProperty<QDeclarativeGeoRouteSegment> *prop, int index); + static void segments_clear(QDeclarativeListProperty<QDeclarativeGeoRouteSegment> *prop); + + QGeoRoute route_; + QDeclarativeGeoBoundingBox* bounds_; + QList<QDeclarativeCoordinate*> path_; + QList<QDeclarativeGeoRouteSegment*> segments_; +}; + + +QTM_END_NAMESPACE + +#endif + diff --git a/src/imports/location/qdeclarativegeoroutesegment.cpp b/src/imports/location/qdeclarativegeoroutesegment.cpp new file mode 100644 index 00000000..a88a3239 --- /dev/null +++ b/src/imports/location/qdeclarativegeoroutesegment.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeoroutesegment_p.h" + +QTM_BEGIN_NAMESPACE + +QDeclarativeGeoRouteSegment::QDeclarativeGeoRouteSegment(QObject *parent) + : QObject(parent) +{ + maneuver_ = new QDeclarativeGeoManeuver(this); +} + +QDeclarativeGeoRouteSegment::QDeclarativeGeoRouteSegment(const QGeoRouteSegment &segment, + QObject *parent) + : QObject(parent), + segment_(segment) +{ + maneuver_ = new QDeclarativeGeoManeuver(segment_.maneuver(), this); + + for (int i = 0; i < segment_.path().size(); ++i) + path_.append(new QDeclarativeCoordinate(segment_.path().at(i), this)); +} + +QDeclarativeGeoRouteSegment::~QDeclarativeGeoRouteSegment() {} + +int QDeclarativeGeoRouteSegment::travelTime() const +{ + return segment_.travelTime(); +} + +qreal QDeclarativeGeoRouteSegment::distance() const +{ + return segment_.distance(); +} + +QDeclarativeGeoManeuver* QDeclarativeGeoRouteSegment::maneuver() const +{ + return maneuver_; +} + +QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativeGeoRouteSegment::path() +{ + return QDeclarativeListProperty<QDeclarativeCoordinate>(this, + 0, + path_append, + path_count, + path_at, + path_clear); +} + +void QDeclarativeGeoRouteSegment::path_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *coordinate) +{ + //static_cast<QDeclarativeGeoRouteSegment*>(prop->object)->segment_.path().append(coordinate->coordinate()); + static_cast<QDeclarativeGeoRouteSegment*>(prop->object)->path_.append(coordinate); +} + +int QDeclarativeGeoRouteSegment::path_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) +{ + return static_cast<QDeclarativeGeoRouteSegment*>(prop->object)->path_.count(); +} + +QDeclarativeCoordinate* QDeclarativeGeoRouteSegment::path_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, int index) +{ + return static_cast<QDeclarativeGeoRouteSegment*>(prop->object)->path_.at(index); +} + +void QDeclarativeGeoRouteSegment::path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) +{ + //static_cast<QDeclarativeGeoRouteSegment*>(prop->object)->segment_.path().clear(); + static_cast<QDeclarativeGeoRouteSegment*>(prop->object)->path_.clear(); +} + +#include "moc_qdeclarativegeoroutesegment_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeoroutesegment_p.h b/src/imports/location/qdeclarativegeoroutesegment_p.h new file mode 100644 index 00000000..bbabd654 --- /dev/null +++ b/src/imports/location/qdeclarativegeoroutesegment_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOROUTESEGMENT_H +#define QDECLARATIVEGEOROUTESEGMENT_H + +#include "qdeclarativegeomaneuver_p.h" + +#include <qgeoroutesegment.h> + +#include <QObject> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoRouteSegment : public QObject +{ + Q_OBJECT + Q_PROPERTY(int travelTime READ travelTime CONSTANT) + Q_PROPERTY(qreal distance READ distance CONSTANT) + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeCoordinate> path READ path) + Q_PROPERTY(QDeclarativeGeoManeuver* maneuver READ maneuver CONSTANT) + +public: + QDeclarativeGeoRouteSegment(QObject *parent = 0); + QDeclarativeGeoRouteSegment(const QGeoRouteSegment &segment, QObject *parent = 0); + ~QDeclarativeGeoRouteSegment(); + + int travelTime() const; + qreal distance() const; + QDeclarativeListProperty<QDeclarativeCoordinate> path(); + QDeclarativeGeoManeuver* maneuver() const; + +private: + static void path_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *coordinate); + static int path_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop); + static QDeclarativeCoordinate* path_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, int index); + static void path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop); + + QGeoRouteSegment segment_; + QDeclarativeGeoManeuver* maneuver_; + QList<QDeclarativeCoordinate*> path_; +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/imports/location/qdeclarativegeoroutingmodel.cpp b/src/imports/location/qdeclarativegeoroutingmodel.cpp new file mode 100644 index 00000000..7bc28915 --- /dev/null +++ b/src/imports/location/qdeclarativegeoroutingmodel.cpp @@ -0,0 +1,390 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeoroutingmodel_p.h" +#include "qdeclarativegeoroute_p.h" + +#include <qgeoserviceprovider.h> +#include <qgeoroutingmanager.h> + +QTM_BEGIN_NAMESPACE + +QDeclarativeGeoRoutingModel::QDeclarativeGeoRoutingModel(QObject *parent) + : QAbstractListModel(parent), + complete_(false), + plugin_(0), + serviceProvider_(0), + routingManager_(0), + autoUpdate_(false), + status_(QDeclarativeGeoRoutingModel::Null) +{ +} + +QDeclarativeGeoRoutingModel::~QDeclarativeGeoRoutingModel() +{ + if (serviceProvider_) + delete serviceProvider_; +} + +void QDeclarativeGeoRoutingModel::classBegin() +{ +} + +void QDeclarativeGeoRoutingModel::componentComplete() +{ + if (!routingManager_) + return; + + complete_ = true; +} + +int QDeclarativeGeoRoutingModel::rowCount(const QModelIndex &parent) const +{ + return routes_.count(); +} + +QVariant QDeclarativeGeoRoutingModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() > routes_.count()) + return QVariant(); + + return QVariant(); +} + +QVariant QDeclarativeGeoRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (section != 0) + return QVariant(); + + return QVariant(); +} + +void QDeclarativeGeoRoutingModel::setPlugin(QDeclarativeGeoServiceProvider *plugin) +{ + if (plugin_ || !plugin) + return; + + plugin_ = plugin; + + emit pluginChanged(plugin_); + + serviceProvider_ = new QGeoServiceProvider(plugin_->name(), + plugin_->parameterMap()); + + // check for error + + routingManager_ = serviceProvider_->routingManager(); + + connect(routingManager_, + SIGNAL(finished(QGeoRoutReply*)), + this, + SLOT(routingFinished(QGeoRouteReply*))); + + connect(routingManager_, + SIGNAL(error(QGeoRouteReply*, QGeoRouteReply::Error, QString)), + this, + SLOT(routingError(QGeoRouteReply*, QGeoRouteReply::Error, QString))); + +} + +QDeclarativeGeoServiceProvider* QDeclarativeGeoRoutingModel::plugin() const +{ + return plugin_; +} + +void QDeclarativeGeoRoutingModel::setAutoUpdate(bool autoUpdate) +{ + if (autoUpdate_ == autoUpdate) + return; + + autoUpdate_ = autoUpdate; + + emit autoUpdateChanged(autoUpdate_); +} + +bool QDeclarativeGeoRoutingModel::autoUpdate() const +{ + return autoUpdate_; +} + +void QDeclarativeGeoRoutingModel::setNumberAlternativeRoutes(int numberAlternativeRoutes) +{ + if (numberAlternativeRoutes == request_.numberAlternativeRoutes()) + return; + + request_.setNumberAlternativeRoutes(numberAlternativeRoutes); + + emit numberAlternativeRoutesChanged(numberAlternativeRoutes); + + if (autoUpdate_ && complete_) + update(); +} + +int QDeclarativeGeoRoutingModel::numberAlternativeRoutes() const +{ + return request_.numberAlternativeRoutes(); +} + +QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativeGeoRoutingModel::waypoints() +{ + return QDeclarativeListProperty<QDeclarativeCoordinate>(this, + 0, + waypoints_append, + waypoints_count, + waypoints_at, + waypoints_clear); +} + +void QDeclarativeGeoRoutingModel::waypoints_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *waypoint) +{ +// static_cast<QDeclarativeGeoRoutingModel>(prop->object) +} + +int QDeclarativeGeoRoutingModel::waypoints_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) +{ +// static_cast<QDeclarativeGeoRoutingModel>(prop->object) + return 0; +} + +QDeclarativeCoordinate* QDeclarativeGeoRoutingModel::waypoints_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, int index) +{ +// static_cast<QDeclarativeGeoRoutingModel>(prop->object) + return 0; +} + +void QDeclarativeGeoRoutingModel::waypoints_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) +{ +// static_cast<QDeclarativeGeoRoutingModel>(prop->object) +} + +QDeclarativeListProperty<QDeclarativeGeoBoundingBox> QDeclarativeGeoRoutingModel::excludeAreas() +{ + return QDeclarativeListProperty<QDeclarativeGeoBoundingBox>(this, + 0, + exclusions_append, + exclusions_count, + exclusions_at, + exclusions_clear); +} + +void QDeclarativeGeoRoutingModel::exclusions_append(QDeclarativeListProperty<QDeclarativeGeoBoundingBox> *prop, QDeclarativeGeoBoundingBox *area) +{ +// static_cast<QDeclarativeGeoRoutingModel>(prop->object) +} + +int QDeclarativeGeoRoutingModel::exclusions_count(QDeclarativeListProperty<QDeclarativeGeoBoundingBox> *prop) +{ +// static_cast<QDeclarativeGeoRoutingModel>(prop->object) + return 0; +} + +QDeclarativeGeoBoundingBox* QDeclarativeGeoRoutingModel::exclusions_at(QDeclarativeListProperty<QDeclarativeGeoBoundingBox> *prop, int index) +{ +// static_cast<QDeclarativeGeoRoutingModel>(prop->object) + return 0; +} + +void QDeclarativeGeoRoutingModel::exclusions_clear(QDeclarativeListProperty<QDeclarativeGeoBoundingBox> *prop) +{ +// static_cast<QDeclarativeGeoRoutingModel>(prop->object) +} + +void QDeclarativeGeoRoutingModel::setTravelModes(QDeclarativeGeoRoutingModel::TravelModes travelModes) +{ + QGeoRouteRequest::TravelModes reqTravelModes; + + if (travelModes & QDeclarativeGeoRoutingModel::CarTravel) + reqTravelModes |= QGeoRouteRequest::CarTravel; + if (travelModes & QDeclarativeGeoRoutingModel::PedestrianTravel) + reqTravelModes |= QGeoRouteRequest::PedestrianTravel; + if (travelModes & QDeclarativeGeoRoutingModel::BicycleTravel) + reqTravelModes |= QGeoRouteRequest::BicycleTravel; + if (travelModes & QDeclarativeGeoRoutingModel::PublicTransitTravel) + reqTravelModes |= QGeoRouteRequest::PublicTransitTravel; + if (travelModes & QDeclarativeGeoRoutingModel::TruckTravel) + reqTravelModes |= QGeoRouteRequest::TruckTravel; + + if (reqTravelModes == request_.travelModes()) + return; + + request_.setTravelModes(reqTravelModes); + + emit travelModesChanged(travelModes); + + if (autoUpdate_ && complete_) + update(); +} + +QDeclarativeGeoRoutingModel::TravelModes QDeclarativeGeoRoutingModel::travelModes() const +{ + QGeoRouteRequest::TravelModes reqTravelModes = request_.travelModes(); + QDeclarativeGeoRoutingModel::TravelModes travelModes; + + if (reqTravelModes & QGeoRouteRequest::CarTravel) + travelModes |= QDeclarativeGeoRoutingModel::CarTravel; + if (reqTravelModes & QGeoRouteRequest::PedestrianTravel) + travelModes |= QDeclarativeGeoRoutingModel::PedestrianTravel; + if (reqTravelModes & QGeoRouteRequest::BicycleTravel) + travelModes |= QDeclarativeGeoRoutingModel::BicycleTravel; + if (reqTravelModes & QGeoRouteRequest::PublicTransitTravel) + travelModes |= QDeclarativeGeoRoutingModel::PublicTransitTravel; + if (reqTravelModes & QGeoRouteRequest::TruckTravel) + travelModes |= QDeclarativeGeoRoutingModel::TruckTravel; + + return travelModes; +} + +void QDeclarativeGeoRoutingModel::setRouteOptimization(QDeclarativeGeoRoutingModel::RouteOptimizations optimization) +{ + QGeoRouteRequest::RouteOptimizations reqOptimizations; + + if (optimization & QDeclarativeGeoRoutingModel::ShortestRoute) + reqOptimizations |= QGeoRouteRequest::ShortestRoute; + if (optimization & QDeclarativeGeoRoutingModel::FastestRoute) + reqOptimizations |= QGeoRouteRequest::FastestRoute; + if (optimization & QDeclarativeGeoRoutingModel::MostEconomicRoute) + reqOptimizations |= QGeoRouteRequest::MostEconomicRoute; + if (optimization & QDeclarativeGeoRoutingModel::MostScenicRoute) + reqOptimizations |= QGeoRouteRequest::MostScenicRoute; + + if (reqOptimizations == request_.routeOptimization()) + return; + + request_.setRouteOptimization(reqOptimizations); + + emit routeOptimizationChanged(optimization); + + if (autoUpdate_ && complete_) + update(); +} + +QDeclarativeGeoRoutingModel::RouteOptimizations QDeclarativeGeoRoutingModel::routeOptimization() const +{ + QGeoRouteRequest::RouteOptimizations reqOptimizations = request_.routeOptimization(); + QDeclarativeGeoRoutingModel::RouteOptimizations optimization; + + if (reqOptimizations & QGeoRouteRequest::ShortestRoute) + optimization |= QDeclarativeGeoRoutingModel::ShortestRoute; + if (reqOptimizations & QGeoRouteRequest::FastestRoute) + optimization |= QDeclarativeGeoRoutingModel::FastestRoute; + if (reqOptimizations & QGeoRouteRequest::MostEconomicRoute) + optimization |= QDeclarativeGeoRoutingModel::MostEconomicRoute; + if (reqOptimizations & QGeoRouteRequest::MostScenicRoute) + optimization |= QDeclarativeGeoRoutingModel::MostScenicRoute; + + return optimization; +} + +void QDeclarativeGeoRoutingModel::setStatus(QDeclarativeGeoRoutingModel::Status status) +{ + if (status_ == status) + return; + + status_ = status; + + emit statusChanged(status_); +} + +QDeclarativeGeoRoutingModel::Status QDeclarativeGeoRoutingModel::status() const +{ + return status_; +} + +void QDeclarativeGeoRoutingModel::setError(const QString &error) +{ + if (error_ == error) + return; + + error_ = error; + + emit errorChanged(error_); +} + +QString QDeclarativeGeoRoutingModel::error() const +{ + return error_; +} + +void QDeclarativeGeoRoutingModel::update() +{ + if (!routingManager_) + return; + + routingManager_->calculateRoute(request_); +} + +void QDeclarativeGeoRoutingModel::routingFinished(QGeoRouteReply *reply) +{ + if (reply->error() != QGeoRouteReply::NoError) + return; + + beginResetModel(); + + qDeleteAll(routes_); + routes_.clear(); + for (int i = 0; i < reply->routes().size(); ++i) + routes_.append(new QDeclarativeGeoRoute(reply->routes().at(i), this)); + + endResetModel(); + + setError(""); + setStatus(QDeclarativeGeoRoutingModel::Ready); + + reply->deleteLater(); + + emit routesChanged(); +} + +void QDeclarativeGeoRoutingModel::routingError(QGeoRouteReply *reply, + QGeoRouteReply::Error error, + const QString &errorString) +{ + setError(errorString); + setStatus(QDeclarativeGeoRoutingModel::Error); + reply->deleteLater(); +} + +#include "moc_qdeclarativegeoroutingmodel_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeoroutingmodel_p.h b/src/imports/location/qdeclarativegeoroutingmodel_p.h new file mode 100644 index 00000000..b01a17a3 --- /dev/null +++ b/src/imports/location/qdeclarativegeoroutingmodel_p.h @@ -0,0 +1,218 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOROUTINGMODEL_H +#define QDECLARATIVEGEOROUTINGMODEL_H + +#include "qdeclarativegeoserviceprovider_p.h" + +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeoboundingbox_p.h" + +#include <qgeorouterequest.h> +#include <qgeoroutereply.h> + +#include <QtDeclarative/qdeclarative.h> +#include <QDeclarativeParserStatus> +#include <QAbstractListModel> + +#include <QObject> + +QTM_BEGIN_NAMESPACE + +class QGeoServiceProvider; +class QGeoRoutingManager; +class QDeclarativeGeoRoute; + +class QDeclarativeGeoRoutingModel : public QAbstractListModel, public QDeclarativeParserStatus +{ + Q_OBJECT + Q_ENUMS(Status) + Q_ENUMS(TravelMode) + Q_ENUMS(FeatureType) + Q_ENUMS(FeatureWeight) + Q_ENUMS(RouteOptimization) + Q_FLAGS(RouteOptimizations) + + Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) + Q_PROPERTY(bool autoUpdate READ autoUpdate WRITE setAutoUpdate NOTIFY autoUpdateChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(QString error READ error NOTIFY errorChanged) + Q_INTERFACES(QDeclarativeParserStatus) + +public: + enum Status { + Null, + Ready, + Loading, + Error + }; + + enum TravelMode { + CarTravel = QGeoRouteRequest::CarTravel, + PedestrianTravel = QGeoRouteRequest::PedestrianTravel, + BicycleTravel = QGeoRouteRequest::BicycleTravel, + PublicTransitTravel = QGeoRouteRequest::PublicTransitTravel, + TruckTravel = QGeoRouteRequest::TruckTravel + }; + Q_DECLARE_FLAGS(TravelModes, TravelMode) + + enum FeatureType { + NoFeature = QGeoRouteRequest::NoFeature, + TollFeature = QGeoRouteRequest::TollFeature, + HighwayFeature = QGeoRouteRequest::HighwayFeature, + PublicTransitFeature = QGeoRouteRequest::PublicTransitFeature, + FerryFeature = QGeoRouteRequest::FerryFeature, + TunnelFeature = QGeoRouteRequest::TunnelFeature, + DirtRoadFeature = QGeoRouteRequest::DirtRoadFeature, + ParksFeature = QGeoRouteRequest::ParksFeature, + MotorPoolLaneFeature = QGeoRouteRequest::MotorPoolLaneFeature + }; + Q_DECLARE_FLAGS(FeatureTypes, FeatureType) + + enum FeatureWeight { + NeutralFeatureWeight = QGeoRouteRequest::NeutralFeatureWeight, + PreferFeatureWeight = QGeoRouteRequest::PreferFeatureWeight, + RequireFeatureWeight = QGeoRouteRequest::RequireFeatureWeight, + AvoidFeatureWeight = QGeoRouteRequest::AvoidFeatureWeight, + DisallowFeatureWeight = QGeoRouteRequest::DisallowFeatureWeight + }; + Q_DECLARE_FLAGS(FeatureWeights, FeatureWeight) + + enum RouteOptimization { + ShortestRoute = QGeoRouteRequest::ShortestRoute, + FastestRoute = QGeoRouteRequest::FastestRoute, + MostEconomicRoute = QGeoRouteRequest::MostEconomicRoute, + MostScenicRoute = QGeoRouteRequest::MostScenicRoute + }; + Q_DECLARE_FLAGS(RouteOptimizations, RouteOptimization) + + + QDeclarativeGeoRoutingModel(QObject *parent = 0); + ~QDeclarativeGeoRoutingModel(); + + // From QDeclarativeParserStatus + void classBegin(); + void componentComplete(); + + // From QAbstractListModel + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + + void setPlugin(QDeclarativeGeoServiceProvider *plugin); + QDeclarativeGeoServiceProvider* plugin() const; + + void setAutoUpdate(bool autoUpdate); + bool autoUpdate() const; + + void setNumberAlternativeRoutes(int numberAlternativeRoutes); + int numberAlternativeRoutes() const; + + QDeclarativeListProperty<QDeclarativeCoordinate> waypoints(); + QDeclarativeListProperty<QDeclarativeGeoBoundingBox> excludeAreas(); + + /* + feature weights + */ + + void setTravelModes(TravelModes travelModes); + TravelModes travelModes() const; + + void setRouteOptimization(RouteOptimizations optimization); + RouteOptimizations routeOptimization() const; + + Status status() const; + QString error() const; + +Q_SIGNALS: + void pluginChanged(QDeclarativeGeoServiceProvider *plugin); + void autoUpdateChanged(bool autoUpdate); + + void numberAlternativeRoutesChanged(int numberAlternativeRoutes); + void travelModesChanged(QDeclarativeGeoRoutingModel::TravelModes travelModes); + void routeOptimizationChanged(QDeclarativeGeoRoutingModel::RouteOptimizations optimization); + + void statusChanged(QDeclarativeGeoRoutingModel::Status status); + void errorChanged(const QString &error); + void routesChanged(); + +public Q_SLOTS: + void update(); + +private Q_SLOTS: + void routingFinished(QGeoRouteReply *reply); + void routingError(QGeoRouteReply *reply, + QGeoRouteReply::Error error, + const QString &errorString); + +private: + static void waypoints_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *waypoint); + static int waypoints_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop); + static QDeclarativeCoordinate* waypoints_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, int index); + static void waypoints_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop); + + static void exclusions_append(QDeclarativeListProperty<QDeclarativeGeoBoundingBox> *prop, QDeclarativeGeoBoundingBox *area); + static int exclusions_count(QDeclarativeListProperty<QDeclarativeGeoBoundingBox> *prop); + static QDeclarativeGeoBoundingBox* exclusions_at(QDeclarativeListProperty<QDeclarativeGeoBoundingBox> *prop, int index); + static void exclusions_clear(QDeclarativeListProperty<QDeclarativeGeoBoundingBox> *prop); + + void setStatus(Status status); + void setError(const QString &error); + + bool complete_; + + QDeclarativeGeoServiceProvider* plugin_; + QGeoServiceProvider* serviceProvider_; + QGeoRoutingManager* routingManager_; + + QGeoRouteRequest request_; + + bool autoUpdate_; + Status status_; + QString error_; + QList<QDeclarativeGeoRoute*> routes_; +}; + + +QTM_END_NAMESPACE + +#endif diff --git a/src/imports/location/qdeclarativegeosearchmodel.cpp b/src/imports/location/qdeclarativegeosearchmodel.cpp new file mode 100644 index 00000000..26bb909e --- /dev/null +++ b/src/imports/location/qdeclarativegeosearchmodel.cpp @@ -0,0 +1,221 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeosearchmodel_p.h" + +#include "qdeclarativegeoplace_p.h" +#include "qdeclarativelandmark_p.h" + +#include <qgeoserviceprovider.h> +#include <qgeosearchmanager.h> + +QTM_BEGIN_NAMESPACE + +QDeclarativeGeoSearchModel::QDeclarativeGeoSearchModel(QObject* parent) + : QAbstractListModel(parent), + plugin_(0), + serviceProvider_(0), + searchManager_(0), + status_(QDeclarativeGeoSearchModel::Null) +{ + QHash<int, QByteArray> roleNames; + roleNames = QAbstractItemModel::roleNames(); + roleNames.insert(PlaceRole, "place"); + roleNames.insert(LandmarkRole, "landmark"); + setRoleNames(roleNames); +} + +QDeclarativeGeoSearchModel::~QDeclarativeGeoSearchModel() +{ + if (serviceProvider_) + delete serviceProvider_; +} + +// From QDeclarativeParserStatus +void QDeclarativeGeoSearchModel::classBegin() {} +void QDeclarativeGeoSearchModel::componentComplete() {} + +// From QAbstractListModel +int QDeclarativeGeoSearchModel::rowCount(const QModelIndex &parent) const +{ + return places_.count(); +} + +QVariant QDeclarativeGeoSearchModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() > places_.count()) + return QVariant(); + + QGeoPlace place = places_.at(index.row()); + + if (role == QDeclarativeGeoSearchModel::PlaceRole) { + return QVariant::fromValue(new QDeclarativeGeoPlace(place, const_cast<QDeclarativeGeoSearchModel*>(this))); + } else if (role == QDeclarativeGeoSearchModel::LandmarkRole) { + if (place.isLandmark()) + return QVariant::fromValue(QLandmark(place)); + } + + return QVariant(); +} + +QVariant QDeclarativeGeoSearchModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const +{ + if (section != 0) + return QVariant(); + + if (role == QDeclarativeGeoSearchModel::PlaceRole) { + return QString("Place"); + } else if (role == QDeclarativeGeoSearchModel::LandmarkRole) { + return QString("Landmark"); + } + + return QVariant(); +} + +void QDeclarativeGeoSearchModel::setPlugin(QDeclarativeGeoServiceProvider *plugin) +{ + if (plugin_ || !plugin) + return; + + plugin_ = plugin; + + emit pluginChanged(plugin_); + + serviceProvider_ = new QGeoServiceProvider(plugin_->name(), + plugin_->parameterMap()); + + // check for error + + searchManager_ = serviceProvider_->searchManager(); + + connect(searchManager_, + SIGNAL(finished(QGeoSearchReply*)), + this, + SLOT(searchFinished(QGeoSearchReply*))); + + connect(searchManager_, + SIGNAL(error(QGeoSearchReply*, QGeoSearchReply::Error, QString)), + this, + SLOT(searchError(QGeoSearchReply*, QGeoSearchReply::Error, QString))); +} + +QDeclarativeGeoServiceProvider* QDeclarativeGeoSearchModel::plugin() const +{ + return plugin_; +} + +void QDeclarativeGeoSearchModel::searchFinished(QGeoSearchReply *reply) +{ + if (reply->error() != QGeoSearchReply::NoError) + return; + + setPlaces(reply->places()); + + setError(""); + setStatus(QDeclarativeGeoSearchModel::Ready); + + reply->deleteLater(); + + emit placesChanged(); +} + +void QDeclarativeGeoSearchModel::searchError(QGeoSearchReply *reply, + QGeoSearchReply::Error error, + const QString &errorString) +{ + setError(errorString); + setStatus(QDeclarativeGeoSearchModel::Error); + reply->deleteLater(); +} + +QDeclarativeGeoSearchModel::Status QDeclarativeGeoSearchModel::status() const +{ + return status_; +} + +void QDeclarativeGeoSearchModel::setStatus(QDeclarativeGeoSearchModel::Status status) +{ + if (status_ == status) + return; + + status_ = status; + + emit statusChanged(status_); +} + +QString QDeclarativeGeoSearchModel::error() const +{ + return error_; +} + +void QDeclarativeGeoSearchModel::setError(const QString &error) +{ + if (error_ == error) + return; + + error_ = error; + + emit errorChanged(error_); +} + +QGeoSearchManager* QDeclarativeGeoSearchModel::searchManager() +{ + return searchManager_; +} + +QList<QGeoPlace> QDeclarativeGeoSearchModel::places() const +{ + return places_; +} + +void QDeclarativeGeoSearchModel::setPlaces(const QList<QGeoPlace> &places) +{ + beginResetModel(); + places_ = places; + endResetModel(); +} + +#include "moc_qdeclarativegeosearchmodel_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeosearchmodel_p.h b/src/imports/location/qdeclarativegeosearchmodel_p.h new file mode 100644 index 00000000..80d3dfd9 --- /dev/null +++ b/src/imports/location/qdeclarativegeosearchmodel_p.h @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOSEARCHMODEL_H +#define QDECLARATIVEGEOSEARCHMODEL_H + +#include "qdeclarativegeoserviceprovider_p.h" + +#include <qgeosearchreply.h> + +#include <QtDeclarative/qdeclarative.h> +#include <QDeclarativeParserStatus> +#include <QAbstractListModel> + +QTM_BEGIN_NAMESPACE + +class QGeoServiceProvider; +class QGeoSearchManager; +class QDeclarativeGeoPlace; + +class QDeclarativeGeoSearchModel : public QAbstractListModel, public QDeclarativeParserStatus +{ + Q_OBJECT + Q_ENUMS(Status) + + Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(QString error READ error NOTIFY errorChanged) + Q_INTERFACES(QDeclarativeParserStatus) + +public: + enum Status { + Null, + Ready, + Loading, + Error + }; + + enum Roles { + PlaceRole = Qt::UserRole + 499, + LandmarkRole = Qt::UserRole + 500 + }; + + explicit QDeclarativeGeoSearchModel(QObject* parent = 0); + virtual ~QDeclarativeGeoSearchModel(); + + // From QDeclarativeParserStatus + virtual void classBegin(); + virtual void componentComplete(); + + // From QAbstractListModel + virtual int rowCount(const QModelIndex &parent) const; + virtual QVariant data(const QModelIndex &index, int role) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + + void setPlugin(QDeclarativeGeoServiceProvider *plugin); + QDeclarativeGeoServiceProvider* plugin() const; + + Status status() const; + + QString error() const; + +Q_SIGNALS: + void pluginChanged(QDeclarativeGeoServiceProvider *plugin); + void statusChanged(QDeclarativeGeoSearchModel::Status status); + void errorChanged(const QString &error); + void placesChanged(); + +private Q_SLOTS: + void searchFinished(QGeoSearchReply *reply); + void searchError(QGeoSearchReply *reply, + QGeoSearchReply::Error error, + const QString &errorString); + +protected: + QGeoSearchManager* searchManager(); + + QList<QGeoPlace> places() const; + + void setStatus(Status status); + + void setError(const QString &error); + +private: + void setPlaces(const QList<QGeoPlace> &places); + + QDeclarativeGeoServiceProvider* plugin_; + QGeoServiceProvider* serviceProvider_; + QGeoSearchManager* searchManager_; + + Status status_; + QString error_; + QList<QGeoPlace> places_; +}; + + +QTM_END_NAMESPACE + +#endif diff --git a/src/imports/location/qdeclarativegeoserviceprovider.cpp b/src/imports/location/qdeclarativegeoserviceprovider.cpp new file mode 100644 index 00000000..3d88a638 --- /dev/null +++ b/src/imports/location/qdeclarativegeoserviceprovider.cpp @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeoserviceprovider_p.h" + +#include <QDebug> + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass Plugin + + \brief The Plugin element describes a Location based services plugin. + \inherits QObject + + \ingroup qml-location-maps + + An example of setting the Plugin in the Map element: + \snippet examples/declarative-location/landmarkmap/landmarkmap.qml Map Plugin + + The Plugin element is part of the \bold{QtMobility.location 1.2} module. +*/ + +QDeclarativeGeoServiceProvider::QDeclarativeGeoServiceProvider(QObject *parent) + : QObject(parent) {} + +QDeclarativeGeoServiceProvider::~QDeclarativeGeoServiceProvider() {} + +/*! + \qmlproperty string Plugin::name + + This property holds the name of the plugin. +*/ +void QDeclarativeGeoServiceProvider::setName(const QString &name) +{ + if (name_ == name) + return; + + name_ = name; + + emit nameChanged(name_); +} + +QString QDeclarativeGeoServiceProvider::name() const +{ + return name_; +} + +/*! + \qmlproperty list<PluginParameter> Plugin::parameters + \default + + This property holds the list of plugin parameters. +*/ +QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> QDeclarativeGeoServiceProvider::parameters() +{ + return QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter>(this, + 0, + parameter_append, + parameter_count, + parameter_at, + parameter_clear); +} + +void QDeclarativeGeoServiceProvider::parameter_append(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop, QDeclarativeGeoServiceProviderParameter *parameter) +{ + static_cast<QDeclarativeGeoServiceProvider*>(prop->object)->parameters_.append(parameter); +} + +int QDeclarativeGeoServiceProvider::parameter_count(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop) +{ + return static_cast<QDeclarativeGeoServiceProvider*>(prop->object)->parameters_.count(); +} + +QDeclarativeGeoServiceProviderParameter* QDeclarativeGeoServiceProvider::parameter_at(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop, int index) +{ + return static_cast<QDeclarativeGeoServiceProvider*>(prop->object)->parameters_[index]; +} + +void QDeclarativeGeoServiceProvider::parameter_clear(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop) +{ + static_cast<QDeclarativeGeoServiceProvider*>(prop->object)->parameters_.clear(); +} + +QMap<QString, QVariant> QDeclarativeGeoServiceProvider::parameterMap() const +{ + QMap<QString, QVariant> map; + + for(int i = 0; i < parameters_.size(); ++i) { + QDeclarativeGeoServiceProviderParameter *parameter = parameters_.at(i); + map.insert(parameter->name(), parameter->value()); + } + + return map; +} +/******************************************************************************* +*******************************************************************************/ + +/*! + \qmlclass PluginParameter + + \brief The PluginParameter element describes the parameter to a \l Plugin. + \inherits QObject + + \ingroup qml-location-maps + + The PluginParameter element is part of the \bold{QtMobility.location 1.2} module. +*/ + +QDeclarativeGeoServiceProviderParameter::QDeclarativeGeoServiceProviderParameter(QObject *parent) + : QObject(parent) {} + +QDeclarativeGeoServiceProviderParameter::~QDeclarativeGeoServiceProviderParameter() {} + +/*! + \qmlproperty string PluginParameter::name + + This property holds the name of the plugin parameter. +*/ +void QDeclarativeGeoServiceProviderParameter::setName(const QString &name) +{ + if (name_ == name) + return; + + name_ = name; + + emit nameChanged(name_); +} + +QString QDeclarativeGeoServiceProviderParameter::name() const +{ + return name_; +} + +/*! + \qmlproperty QVariant PluginParameter::value + + This property holds the value of the plugin parameter. +*/ +void QDeclarativeGeoServiceProviderParameter::setValue(const QVariant &value) +{ + if (value_ == value) + return; + + value_ = value; + + emit valueChanged(value_); +} + +QVariant QDeclarativeGeoServiceProviderParameter::value() const +{ + return value_; +} + +/******************************************************************************* +*******************************************************************************/ + +#include "moc_qdeclarativegeoserviceprovider_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/imports/location/qdeclarativegeoserviceprovider_p.h b/src/imports/location/qdeclarativegeoserviceprovider_p.h new file mode 100644 index 00000000..72859e81 --- /dev/null +++ b/src/imports/location/qdeclarativegeoserviceprovider_p.h @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEQGEOSERVICEPROVIDER_H +#define QDECLARATIVEQGEOSERVICEPROVIDER_H + +#include <qgeocoordinate.h> +#include <QtDeclarative/qdeclarativeitem.h> + +#include <QMap> +#include <QString> +#include <QVariant> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeGeoServiceProviderParameter : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) + +public: + QDeclarativeGeoServiceProviderParameter(QObject *parent = 0); + ~QDeclarativeGeoServiceProviderParameter(); + + void setName(const QString &name); + QString name() const; + + void setValue(const QVariant &value); + QVariant value() const; + +Q_SIGNALS: + void nameChanged(const QString &name); + void valueChanged(const QVariant &value); + +private: + QString name_; + QVariant value_; +}; + +class QDeclarativeGeoServiceProvider : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> parameters READ parameters) + + Q_CLASSINFO("DefaultProperty", "parameters") + +public: + QDeclarativeGeoServiceProvider(QObject *parent = 0); + ~QDeclarativeGeoServiceProvider(); + + void setName(const QString &name); + QString name() const; + + QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> parameters(); + + QMap<QString, QVariant> parameterMap() const; + +Q_SIGNALS: + void nameChanged(const QString &name); + +private: + static void parameter_append(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop, QDeclarativeGeoServiceProviderParameter *mapObject); + static int parameter_count(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop); + static QDeclarativeGeoServiceProviderParameter* parameter_at(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop, int index); + static void parameter_clear(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop); + + QString name_; + QList<QDeclarativeGeoServiceProviderParameter*> parameters_; + + Q_DISABLE_COPY(QDeclarativeGeoServiceProvider) +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoServiceProviderParameter)); +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGeoServiceProvider)); + +#endif diff --git a/src/imports/location/qdeclarativegraphicsgeomap.cpp b/src/imports/location/qdeclarativegraphicsgeomap.cpp new file mode 100644 index 00000000..7c945fad --- /dev/null +++ b/src/imports/location/qdeclarativegraphicsgeomap.cpp @@ -0,0 +1,923 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegraphicsgeomap_p.h" +#include "qdeclarativegeomapmousearea_p.h" + +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeoserviceprovider_p.h" +#include "qdeclarativelandmark_p.h" + +#include <qgeoserviceprovider.h> +#include <qgeomappingmanager.h> +#include <qgeomapdata.h> +#include <qgeomapobject.h> + +#include <QGraphicsSceneMouseEvent> +#include <QDeclarativeContext> +#include <QtDeclarative/qdeclarativeinfo.h> +#include <QModelIndex> + +#include <QDebug> + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass Map + + \brief The Map element displays a map. + \inherits QDeclarativeItem + + \ingroup qml-location-maps + + The Map element can be used be used to display a map of the world. The + bulk of the functionality is provided by a mapping plugin described + by the Plugin element associated with the Map. + + Various map objects can be added to the map. These map objects are + specified in terms of coordinates and metres. + + MapObjects can be directly added to the Map element and it will display them + automatically. The various objects that can be added include: + + \list + \o MapRectangle + \o MapCircle + \o MapText + \o MapImage + \o MapPolygon + \o MapPolyline + \o MapGroup + \o MapObjectView + \endlist + + Of the above list, MapObjectView is a special case and not a MapObject as such. + Here is a small example to illustrate this: + + \snippet doc/src/snippets/declarative/declarative-map.qml Basic MapObjects and View on Map + + Mouse handling is done by adding MapMouseArea items as children of either + MapObjects or the Map item itself. + + The Map element is part of the \bold{QtMobility.location 1.2} module. +*/ +QDeclarativeGraphicsGeoMap::QDeclarativeGraphicsGeoMap(QDeclarativeItem *parent) + : QDeclarativeItem(parent), + plugin_(0), + serviceProvider_(0), + mappingManager_(0), + mapData_(0), + center_(0), + initialCoordinate(0), + mapType_(NoMap), + connectivityMode_(NoConnectivity), + componentCompleted_(false) +{ + initialCoordinate = new QGeoCoordinate(-27.0, 153.0); + zoomLevel_ = 8; + size_ = QSizeF(100.0, 100.0); + setAcceptsHoverEvents(true); + setAcceptHoverEvents(true); + setAcceptedMouseButtons(Qt::LeftButton | Qt::MidButton | Qt::RightButton); + setFlag(QGraphicsItem::ItemHasNoContents, false); + setFlag(QGraphicsItem::ItemAcceptsInputMethod); +} + +QDeclarativeGraphicsGeoMap::~QDeclarativeGraphicsGeoMap() +{ + if (mapData_) { + qDeleteAll(mapViews_); + // Remove map objects, we can't allow mapObject + // to delete the objects because they are owned + // by the declarative elements. + //QList<QGeoMapObject*> objects = objectMap_.keys(); + QList<QDeclarativeGeoMapObject*> objects = mapObjects_; + for (int i = 0; i < objects.size(); ++i) { + mapData_->removeMapObject(objects.at(i)->mapObject()); + } + delete mapData_; + } + if (serviceProvider_) + delete serviceProvider_; + + if (initialCoordinate) { + delete initialCoordinate; + } +} + +// todo: mixture of mapviews and mapobjects does not preserve the order (z). +// to be addressed when merged with other changes +void QDeclarativeGraphicsGeoMap::componentComplete() +{ + componentCompleted_ = true; + QDeclarativeItem::componentComplete(); + populateMap(); +} + +void QDeclarativeGraphicsGeoMap::populateMap() +{ + if (!mapData_ || !componentCompleted_) + return; + QObjectList kids = children(); + for (int i = 0; i < kids.size(); ++i) { + // dispatch items appropriately + QDeclarativeGeoMapObjectView* mapView = qobject_cast<QDeclarativeGeoMapObjectView*>(kids.at(i)); + if (mapView) { + mapViews_.append(mapView); + setupMapView(mapView); + continue; + } + QDeclarativeGeoMapObject *mapObject = qobject_cast<QDeclarativeGeoMapObject*>(kids.at(i)); + if (mapObject) { + mapObjects_.append(mapObject); + objectMap_.insert(mapObject->mapObject(), mapObject); + mapData_->addMapObject(mapObject->mapObject()); + mapObject->setMap(this); + continue; + } + QDeclarativeGeoMapMouseArea *mouseArea + = qobject_cast<QDeclarativeGeoMapMouseArea*>(kids.at(i)); + if (mouseArea) { + mouseArea->setMap(this); + mouseAreas_.append(mouseArea); + } + } +} + +void QDeclarativeGraphicsGeoMap::setupMapView(QDeclarativeGeoMapObjectView *view) +{ + view->setMapData(this); + view->repopulate(); +} + +void QDeclarativeGraphicsGeoMap::paint(QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget * /*widget*/) +{ + if (mapData_) { + mapData_->paint(painter, option); + } +} + +void QDeclarativeGraphicsGeoMap::geometryChanged(const QRectF &newGeometry, + const QRectF & /*oldGeometry*/) +{ + setSize(newGeometry.size()); +} + +/*! + \qmlproperty Plugin Map::plugin + + This property holds the plugin which provides the mapping functionality. + + This is write-once property. Once the map has a plugin associated with + it any attempted modifications of the plugin will be ignored. +*/ + +void QDeclarativeGraphicsGeoMap::setPlugin(QDeclarativeGeoServiceProvider *plugin) +{ + if (plugin_) { + qmlInfo(this) << tr("Plugin is a write-once property, and cannot be set again."); + return; + } + + plugin_ = plugin; + + emit pluginChanged(plugin_); + + serviceProvider_ = new QGeoServiceProvider(plugin_->name(), + plugin_->parameterMap()); + + if (serviceProvider_->error() != QGeoServiceProvider::NoError) { + qWarning() << serviceProvider_->errorString(); + delete serviceProvider_; + serviceProvider_ = 0; + return; + } + + mappingManager_ = serviceProvider_->mappingManager(); + if (!mappingManager_ || serviceProvider_->error() != QGeoServiceProvider::NoError) { + qWarning() << serviceProvider_->errorString(); + delete serviceProvider_; + serviceProvider_ = 0; + delete mappingManager_; + mappingManager_ = 0; + return; + } + + mapData_ = mappingManager_->createMapData(); + mapData_->init(); + //mapData_->setParentItem(this); + + // setters + mapData_->setWindowSize(size_); + mapData_->setZoomLevel(zoomLevel_); + + if (center_) + mapData_->setCenter(center_->coordinate()); + else + mapData_->setCenter(*initialCoordinate); + + mapData_->setMapType(QGraphicsGeoMap::MapType(mapType_)); + mapData_->setConnectivityMode(QGraphicsGeoMap::ConnectivityMode(connectivityMode_)); + + // Populate the map objects. + populateMap(); + // setup signals + connect(mapData_, + SIGNAL(updateMapDisplay(QRectF)), + this, + SLOT(updateMapDisplay(QRectF))); + + connect(mapData_, + SIGNAL(centerChanged(QGeoCoordinate)), + this, + SLOT(internalCenterChanged(QGeoCoordinate))); + + connect(mapData_, + SIGNAL(mapTypeChanged(QGraphicsGeoMap::MapType)), + this, + SLOT(internalMapTypeChanged(QGraphicsGeoMap::MapType))); + + connect(mapData_, + SIGNAL(connectivityModeChanged(QGraphicsGeoMap::ConnectivityMode)), + this, + SLOT(internalConnectivityModeChanged(QGraphicsGeoMap::ConnectivityMode))); + + connect(mapData_, + SIGNAL(windowSizeChanged(QSizeF)), + this, + SIGNAL(sizeChanged(QSizeF))); + + connect(mapData_, + SIGNAL(zoomLevelChanged(qreal)), + this, + SIGNAL(zoomLevelChanged(qreal))); +} + +void QDeclarativeGraphicsGeoMap::updateMapDisplay(const QRectF &target) +{ + update(target); +} + +QDeclarativeGeoServiceProvider* QDeclarativeGraphicsGeoMap::plugin() const +{ + return plugin_; +} + +/*! + \qmlproperty qreal Map::minimumZoomLevel + + This property holds the minimum valid zoom level for the map. +*/ +qreal QDeclarativeGraphicsGeoMap::minimumZoomLevel() const +{ + if (mappingManager_) + return mappingManager_->minimumZoomLevel(); + else + return -1.0; +} + +/*! + \qmlproperty qreal Map::maximumZoomLevel + + This property holds the maximum valid zoom level for the map. +*/ +qreal QDeclarativeGraphicsGeoMap::maximumZoomLevel() const +{ + if (mappingManager_) + return mappingManager_->maximumZoomLevel(); + else + return -1.0; +} + +// TODO make these more QML like +//QList<MapType> QDeclarativeGraphicsGeoMap::supportedMapTypes() const; +//QList<ConnectivityMode> QDeclarativeGraphicsGeoMap::supportedConnectivityModes() const; + +/*! + \qmlproperty QSizeF Map::size + + This property holds the size of the map viewport. +*/ +void QDeclarativeGraphicsGeoMap::setSize(const QSizeF &size) +{ + if (mapData_) { + setWidth(size.width()); + setHeight(size.height()); + mapData_->setWindowSize(size); + } else { + if (size_ == size) + return; + + size_ = size; + + emit sizeChanged(size_); + } + +} + +QSizeF QDeclarativeGraphicsGeoMap::size() const +{ + if (mapData_) + return mapData_->windowSize(); + else + return size_; +} + +/*! + \qmlproperty qreal Map::zoomLevel + + This property holds the zoom level for the map. + + Larger values for the zoom level provide more detail. + + The default value is 8.0. +*/ +void QDeclarativeGraphicsGeoMap::setZoomLevel(qreal zoomLevel) +{ + if (mapData_) { + mapData_->setZoomLevel(zoomLevel); + } else { + if (zoomLevel_ == zoomLevel) + return; + + zoomLevel_ = zoomLevel; + + emit zoomLevelChanged(zoomLevel_); + } +} + +qreal QDeclarativeGraphicsGeoMap::zoomLevel() const +{ + if (mapData_) { + return mapData_->zoomLevel(); + } else { + return zoomLevel_; + } +} + +/*! + \qmlproperty Coordinate Map::center + + This property holds the coordinate which occupies the center of the + mapping viewport. + + The default value is an arbitrary valid coordinate. +*/ +void QDeclarativeGraphicsGeoMap::setCenter(QDeclarativeCoordinate *center) +{ + if (center_ == center) + return; + + if (center_) { + center_->disconnect(this); + } + center_ = center; + if (center_) { + connect(center_, + SIGNAL(latitudeChanged(double)), + this, + SLOT(centerLatitudeChanged(double))); + connect(center_, + SIGNAL(longitudeChanged(double)), + this, + SLOT(centerLongitudeChanged(double))); + connect(center_, + SIGNAL(altitudeChanged(double)), + this, + SLOT(centerAltitudeChanged(double))); + + if (mapData_) { + mapData_->setCenter(center_->coordinate()); + } + } + emit declarativeCenterChanged(center_); +} + +QDeclarativeCoordinate* QDeclarativeGraphicsGeoMap::center() +{ + if (mapData_ && center_) + center_->setCoordinate(mapData_->center()); + return center_; +} + +void QDeclarativeGraphicsGeoMap::centerLatitudeChanged(double /*latitude*/) +{ + if (mapData_ && center_) + mapData_->setCenter(center_->coordinate()); +} + +void QDeclarativeGraphicsGeoMap::centerLongitudeChanged(double /*longitude*/) +{ + if (mapData_ && center_) + mapData_->setCenter(center_->coordinate()); +} + +void QDeclarativeGraphicsGeoMap::centerAltitudeChanged(double /*altitude*/) +{ + if (mapData_ && center_) + mapData_->setCenter(center_->coordinate()); +} + +/*! + \qmlproperty enumeration Map::mapType + + This property holds the type of map to display. + + The type can be one of: + \list + \o Map.StreetMap + \o Map.SatelliteMapDay + \o Map.SatelliteMapNight + \o Map.TerrainMap + \endlist + + The default value is determined by the plugin. +*/ +void QDeclarativeGraphicsGeoMap::setMapType(QDeclarativeGraphicsGeoMap::MapType mapType) +{ + if (mapData_) { + mapData_->setMapType(QGraphicsGeoMap::MapType(mapType)); + } else { + if (mapType_ == mapType) + return; + + mapType_ = mapType; + + emit mapTypeChanged(mapType_); + } +} + +QDeclarativeGraphicsGeoMap::MapType QDeclarativeGraphicsGeoMap::mapType() const +{ + if (mapData_) { + return QDeclarativeGraphicsGeoMap::MapType(mapData_->mapType()); + } else { + return mapType_; + } +} + +/*! + \qmlproperty enumeration Map::connectivityMode + + This property holds the connectivity mode used to fetch the map data. + + The mode can be one of: + \list + \o Map.OfflineMode + \o Map.OnlineMode + \o Map.HybridMode + \endlist + + The default value is determined by the plugin. +*/ +void QDeclarativeGraphicsGeoMap::setConnectivityMode(QDeclarativeGraphicsGeoMap::ConnectivityMode connectivityMode) +{ + if (mapData_) { + mapData_->setConnectivityMode(QGraphicsGeoMap::ConnectivityMode(connectivityMode)); + } else { + if (connectivityMode_ == connectivityMode) + return; + + connectivityMode_ = connectivityMode; + + emit connectivityModeChanged(connectivityMode_); + } +} + +QDeclarativeGraphicsGeoMap::ConnectivityMode QDeclarativeGraphicsGeoMap::connectivityMode() const +{ + if (mapData_) + return QDeclarativeGraphicsGeoMap::ConnectivityMode(mapData_->connectivityMode()); + else + return connectivityMode_; +} + +/*! + \qmlproperty list<QGeoMapObject> Map::objects + \default + + This property holds the list of objects associated with this map. + + The various objects that can be added include: + \list + \o MapRectangle + \o MapCircle + \o MapText + \o MapImage + \o MapPolygon + \o MapPolyline + \o MapGroup + \endlist +*/ + +/*! + \qmlmethod Map::toCoordinate(QPointF screenPosition) + + Returns the coordinate which corresponds to the screen position + \a screenPosition. + + Returns an invalid coordinate if \a screenPosition is not within + the current viewport. + + An example to constraint landmarks of a model to just those + currently on Map: + \snippet examples/declarative-location/landmarkmap/landmarkmap.qml Map toCoordinate + +*/ + +QDeclarativeCoordinate* QDeclarativeGraphicsGeoMap::toCoordinate(QPointF screenPosition) const +{ + QGeoCoordinate coordinate; + + if (mapData_) + coordinate = mapData_->screenPositionToCoordinate(screenPosition); + + return new QDeclarativeCoordinate(coordinate, + const_cast<QDeclarativeGraphicsGeoMap *>(this)); +} + +/*! + \qmlmethod Map::toScreenPosition(Coordinate coordinate) + + Returns the screen position which corresponds to the coordinate + \a coordinate. + + Returns an invalid QPointF if \a coordinate is not within the + current viewport. +*/ +QPointF QDeclarativeGraphicsGeoMap::toScreenPosition(QDeclarativeCoordinate* coordinate) const +{ + QPointF point; + + if (mapData_) + point = mapData_->coordinateToScreenPosition(coordinate->coordinate()); + + return point; +} + +void QDeclarativeGraphicsGeoMap::pan(int dx, int dy) +{ + if (mapData_) { + mapData_->pan(dx, dy); + update(); + } else { + qmlInfo(this) << tr("Map plugin is not set, cannot pan."); + } +} + +QDeclarativeGeoMapMouseEvent* QDeclarativeGraphicsGeoMap::createMapMouseEvent(QGraphicsSceneMouseEvent *event) +{ + if (!event || !mapData_) + return 0; + + QDeclarativeGeoMapMouseEvent *mouseEvent = new QDeclarativeGeoMapMouseEvent(this); + + mouseEvent->setButton(event->button()); + mouseEvent->setModifiers(event->modifiers()); + + QGeoCoordinate coordinate = mapData_->screenPositionToCoordinate(event->pos()); + mouseEvent->setCoordinate(new QDeclarativeCoordinate(coordinate, this)); + mouseEvent->setX(event->pos().x()); + mouseEvent->setY(event->pos().y()); + + return mouseEvent; +} + +QDeclarativeGeoMapMouseEvent* QDeclarativeGraphicsGeoMap::createMapMouseEvent(QGraphicsSceneHoverEvent *event) +{ + if (!event || !mapData_) + return 0; + + QDeclarativeGeoMapMouseEvent *mouseEvent = new QDeclarativeGeoMapMouseEvent(this); + + mouseEvent->setModifiers(event->modifiers()); + + QGeoCoordinate coordinate = mapData_->screenPositionToCoordinate(event->pos()); + mouseEvent->setCoordinate(new QDeclarativeCoordinate(coordinate, this)); + mouseEvent->setX(event->pos().x()); + mouseEvent->setY(event->pos().y()); + + return mouseEvent; +} + +void QDeclarativeGraphicsGeoMap::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if (!mapData_) { + qmlInfo(this) << tr("Map plugin is not set, mouse event cannot be processed."); + return; + } + + // First deliver the mouse event to possible map objects (they will accept it if + // they have their own mouse area). If no accepting objects, check if the map + // object itself has any mouse areas. This way the map objects have higher priority + // in mouse event handling. + QList<QGeoMapObject*> objects = mapData_->mapObjectsAtScreenPosition(event->pos()); + + QDeclarativeGeoMapMouseEvent *mouseEvent = createMapMouseEvent(event); + + for (int i = objects.size() - 1; i >= 0; --i) { + QDeclarativeGeoMapObject* mapObject = objectMap_.value(objects.at(i), 0); + if (mapObject) { + mapObject->pressEvent(mouseEvent); + if (mouseEvent->accepted()) { + event->setAccepted(true); + delete mouseEvent; + return; + } + } + } + + for (int i = 0; i < mouseAreas_.size(); ++i) { + mouseAreas_.at(i)->pressEvent(mouseEvent); + if (mouseEvent->accepted()) { + event->setAccepted(true); + delete mouseEvent; + return; + } + } + + delete mouseEvent; + + QDeclarativeItem::mousePressEvent(event); +} + +void QDeclarativeGraphicsGeoMap::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + QDeclarativeGeoMapMouseEvent *mouseEvent = createMapMouseEvent(event); + + if (activeMouseArea_) + activeMouseArea_->releaseEvent(mouseEvent); + activeMouseArea_ = 0; + + bool accepted = (mouseEvent->accepted()); + + delete mouseEvent; + + if (accepted) + return; + + QDeclarativeItem::mouseReleaseEvent(event); +} + +void QDeclarativeGraphicsGeoMap::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + if (!mapData_) { + qmlInfo(this) << tr("Map plugin is not set, mouse event cannot be processed."); + return; + } + + activeMouseArea_ = 0; + + QList<QGeoMapObject*> objects = mapData_->mapObjectsAtScreenPosition(event->pos()); + + QDeclarativeGeoMapMouseEvent *mouseEvent = createMapMouseEvent(event); + + for (int i = objects.size() - 1; i >= 0; --i) { + QDeclarativeGeoMapObject* mapObject = objectMap_.value(objects.at(i), 0); + if (mapObject) { + mapObject->doubleClickEvent(mouseEvent); + if (mouseEvent->accepted()) { + event->setAccepted(true); + delete mouseEvent; + return; + } + } + } + + for (int i = 0; i < mouseAreas_.size(); ++i) { + mouseAreas_.at(i)->doubleClickEvent(mouseEvent); + if (mouseEvent->accepted()) { + event->setAccepted(true); + delete mouseEvent; + return; + } + } + + bool accepted = (mouseEvent->accepted()); + + delete mouseEvent; + + if (accepted) + return; + + QDeclarativeItem::mouseDoubleClickEvent(event); +} + +void QDeclarativeGraphicsGeoMap::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + QDeclarativeGeoMapMouseEvent *mouseEvent = createMapMouseEvent(event); + + if (activeMouseArea_) + activeMouseArea_->moveEvent(mouseEvent); + + bool accepted = (mouseEvent->accepted()); + + delete mouseEvent; + + if (accepted) + return; + + QDeclarativeItem::mouseMoveEvent(event); +} + +void QDeclarativeGraphicsGeoMap::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ +// qWarning() << "hover enter"; +} + +void QDeclarativeGraphicsGeoMap::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + if (!mapData_) + return; + + QList<QGeoMapObject*> objectsThen = mapData_->mapObjectsAtScreenPosition(event->lastPos()); + QList<QGeoMapObject*> objectsNow = mapData_->mapObjectsAtScreenPosition(event->pos()); + + QSet<QGeoMapObject*> enter = objectsNow.toSet(); + enter -= objectsThen.toSet(); + + for (int i = 0; i < objectsNow.size(); ++i) { + if (!enter.contains(objectsNow.at(i))) + continue; + + QDeclarativeGeoMapObject* mapObject = objectMap_.value(objectsNow.at(i), 0); + if (mapObject) + mapObject->enterEvent(); + } + + QSet<QGeoMapObject*> exit = objectsThen.toSet(); + exit -= objectsNow.toSet(); + + for (int i = 0; i < objectsThen.size(); ++i) { + if (!exit.contains(objectsThen.at(i))) + continue; + + QDeclarativeGeoMapObject* mapObject = objectMap_.value(objectsThen.at(i), 0); + if (mapObject) + mapObject->exitEvent(); + } + + QSet<QGeoMapObject*> move = objectsNow.toSet(); + move += objectsThen.toSet(); + + QList<QGeoMapObject*> objects = mapData_->mapObjectsInViewport(); + + QDeclarativeGeoMapMouseEvent *mouseEvent = createMapMouseEvent(event); + + for (int i = 0; i < objects.size(); ++i) { + if (!move.contains(objects.at(i))) + continue; + + QDeclarativeGeoMapObject* mapObject = objectMap_.value(objects.at(i), 0); + if (mapObject) + mapObject->moveEvent(mouseEvent); + } + + /* + QList<QGeoMapObject*> objects = mapData_->mapObjectsAtScreenPosition(event->pos()); + + for (int i = objects.size() - 1; i >= 0; --i) { + QDeclarativeGeoMapObject* mapObject = objectMap_.value(objects.at(i), 0); + if (mapObject) + mapObject->moveEvent(mouseEvent); + } + */ + + for (int i = 0; i < mouseAreas_.size(); ++i) + mouseAreas_.at(i)->moveEvent(mouseEvent); + + delete mouseEvent; +} + +void QDeclarativeGraphicsGeoMap::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ +// qWarning() << "hover leave"; +} + +void QDeclarativeGraphicsGeoMap::internalCenterChanged(const QGeoCoordinate &coordinate) +{ + emit declarativeCenterChanged(new QDeclarativeCoordinate(coordinate, this)); +} + +void QDeclarativeGraphicsGeoMap::internalMapTypeChanged(QGraphicsGeoMap::MapType mapType) +{ + emit mapTypeChanged(QDeclarativeGraphicsGeoMap::MapType(mapType)); +} + +void QDeclarativeGraphicsGeoMap::internalConnectivityModeChanged(QGraphicsGeoMap::ConnectivityMode connectivityMode) +{ + emit connectivityModeChanged(QDeclarativeGraphicsGeoMap::ConnectivityMode(connectivityMode)); +} + +/*! + \qmlmethod Map::addMapObject(MapObject) + + Adds the given MapOject to the Map. If the object already + is on the Map, it will not be added again. + + As an example, consider you have a MapCircle presenting your current position: + + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Basic map position marker definition + You can add it to Map (alterntively it can be defined as a child element of the Map): + + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Basic add MapObject + Note: MapObjectViews can not be added with this method. +*/ + +void QDeclarativeGraphicsGeoMap::addMapObject(QDeclarativeGeoMapObject *object) +{ + if (!mapData_) + qmlInfo(this) << tr("Map plugin is not set, map object cannot be added."); + if (!mapData_ || !object || objectMap_.contains(object->mapObject())) + return; + mapObjects_.append(object); + objectMap_.insert(object->mapObject(), object); + mapData_->addMapObject(object->mapObject()); + object->setMap(this); +} + +/*! + \qmlmethod Map::removeMapObject(MapObject) + + Removes the given MapObject from the Map. If the MapObject does not + exist, function does nothing. + + As an example, consider you have a MapCircle presenting your current position: + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Basic map position marker definition + + You can remove it from the Map element: + \snippet doc/src/snippets/declarative/testpolymapobjects.qml Basic remove MapObject + + +*/ + +void QDeclarativeGraphicsGeoMap::removeMapObject(QDeclarativeGeoMapObject *object) +{ + if (!mapData_) + qmlInfo(this) << tr("Map plugin is not set, map object cannot be removed."); + if (!mapData_ || !object || !objectMap_.contains(object->mapObject())) + return; + objectMap_.remove(object->mapObject()); + mapObjects_.removeOne(object); + mapData_->removeMapObject(object->mapObject()); +} + +void QDeclarativeGraphicsGeoMap::setActiveMouseArea(QDeclarativeGeoMapMouseArea *area) +{ + activeMouseArea_ = area; +} + +QDeclarativeGeoMapMouseArea* QDeclarativeGraphicsGeoMap::activeMouseArea() const +{ + return activeMouseArea_; +} + +// This function is strictly for testing purposes +int QDeclarativeGraphicsGeoMap::testGetDeclarativeMapObjectCount() +{ + return objectMap_.values().count(); +} + +#include "moc_qdeclarativegraphicsgeomap_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegraphicsgeomap_p.h b/src/imports/location/qdeclarativegraphicsgeomap_p.h new file mode 100644 index 00000000..4696cc31 --- /dev/null +++ b/src/imports/location/qdeclarativegraphicsgeomap_p.h @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGRAPHICSGEOMAP_H +#define QDECLARATIVEGRAPHICSGEOMAP_H + +#include <qgraphicsgeomap.h> +#include <QtDeclarative/qdeclarativeitem.h> + +#include "qdeclarativegeomapobject_p.h" + +QTM_BEGIN_NAMESPACE + +class QGeoCoordinate; +class QGeoMapObject; +class QGeoMapData; +class QGeoServiceProvider; +class QDeclarativeCoordinate; +class QDeclarativeGeoServiceProvider; + +class QDeclarativeGraphicsGeoMap : public QDeclarativeItem +{ + Q_OBJECT + + Q_ENUMS(MapType) + Q_ENUMS(ConnectivityMode) + + Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) + Q_PROPERTY(QSizeF size READ size WRITE setSize NOTIFY sizeChanged) + Q_PROPERTY(qreal minimumZoomLevel READ minimumZoomLevel CONSTANT) + Q_PROPERTY(qreal maximumZoomLevel READ maximumZoomLevel CONSTANT) + Q_PROPERTY(qreal zoomLevel READ zoomLevel WRITE setZoomLevel NOTIFY zoomLevelChanged) + Q_PROPERTY(MapType mapType READ mapType WRITE setMapType NOTIFY mapTypeChanged) + Q_PROPERTY(QDeclarativeCoordinate* center READ center WRITE setCenter NOTIFY declarativeCenterChanged) + Q_PROPERTY(ConnectivityMode connectivityMode READ connectivityMode WRITE setConnectivityMode NOTIFY connectivityModeChanged) + Q_INTERFACES(QDeclarativeParserStatus) + +public: + enum MapType { + NoMap = QGraphicsGeoMap::NoMap, + StreetMap = QGraphicsGeoMap::StreetMap, + SatelliteMapDay = QGraphicsGeoMap::SatelliteMapDay, + SatelliteMapNight = QGraphicsGeoMap::SatelliteMapNight, + TerrainMap = QGraphicsGeoMap::TerrainMap + }; + + enum ConnectivityMode { + NoConnectivity = QGraphicsGeoMap::NoConnectivity, + OfflineMode = QGraphicsGeoMap::OfflineMode, + OnlineMode = QGraphicsGeoMap::OnlineMode, + HybridMode = QGraphicsGeoMap::HybridMode + }; + +public: + QDeclarativeGraphicsGeoMap(QDeclarativeItem *parent = 0); + ~QDeclarativeGraphicsGeoMap(); + + // From QDeclarativeParserStatus + virtual void componentComplete(); + + // From QGraphicsItem + void paint(QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *widget); + + void setPlugin(QDeclarativeGeoServiceProvider *plugin); + QDeclarativeGeoServiceProvider* plugin() const; + + qreal minimumZoomLevel() const; + qreal maximumZoomLevel() const; + + // TODO make these more QML like + //QList<MapType> supportedMapTypes() const; + //QList<ConnectivityMode> supportedConnectivityModes() const; + + void setSize(const QSizeF &size); + QSizeF size() const; + + void setZoomLevel(qreal zoomLevel); + qreal zoomLevel() const; + + void setCenter(QDeclarativeCoordinate *center); + QDeclarativeCoordinate* center(); + + void setMapType(MapType mapType); + MapType mapType() const; + + void setConnectivityMode(ConnectivityMode connectivityMode); + ConnectivityMode connectivityMode() const; + + QDeclarativeListProperty<QDeclarativeGeoMapObject> objects(); + + Q_INVOKABLE void addMapObject(QDeclarativeGeoMapObject* object); + Q_INVOKABLE void removeMapObject(QDeclarativeGeoMapObject* object); + + Q_INVOKABLE QDeclarativeCoordinate* toCoordinate(QPointF screenPosition) const; + Q_INVOKABLE QPointF toScreenPosition(QDeclarativeCoordinate* coordinate) const; + + // This function is strictly for testing purposes and may be removed at + // any time without any notice (hence also the obscure naming to avoid + // accidental usage): + Q_INVOKABLE int testGetDeclarativeMapObjectCount(); + + void setActiveMouseArea(QDeclarativeGeoMapMouseArea *area); + QDeclarativeGeoMapMouseArea* activeMouseArea() const; + +public Q_SLOTS: + void pan(int dx, int dy); + +protected: + void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverMoveEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + +Q_SIGNALS: + void pluginChanged(QDeclarativeGeoServiceProvider *plugin); + void sizeChanged(const QSizeF &size); + void zoomLevelChanged(qreal zoomLevel); + void declarativeCenterChanged(const QDeclarativeCoordinate *coordinate); + void mapTypeChanged(QDeclarativeGraphicsGeoMap::MapType mapType); + void connectivityModeChanged(QDeclarativeGraphicsGeoMap::ConnectivityMode connectivityMode); + +private Q_SLOTS: + void updateMapDisplay(const QRectF& target); + void internalCenterChanged(const QGeoCoordinate &coordinate); + void internalMapTypeChanged(QGraphicsGeoMap::MapType mapType); + void internalConnectivityModeChanged(QGraphicsGeoMap::ConnectivityMode connectivityMode); + void centerLatitudeChanged(double latitude); + void centerLongitudeChanged(double longitude); + void centerAltitudeChanged(double altitude); + +private: + void setupMapView(QDeclarativeGeoMapObjectView *view); + void populateMap(); + + QDeclarativeGeoMapObject* createItem(int modelIndex); + QDeclarativeGeoMapMouseEvent* createMapMouseEvent(QGraphicsSceneMouseEvent *event); + QDeclarativeGeoMapMouseEvent* createMapMouseEvent(QGraphicsSceneHoverEvent *event); + + QDeclarativeGeoServiceProvider* plugin_; + QGeoServiceProvider* serviceProvider_; + QGeoMappingManager* mappingManager_; + QGeoMapData* mapData_; + + qreal zoomLevel_; + QDeclarativeCoordinate* center_; + QGeoCoordinate *initialCoordinate; + QDeclarativeGraphicsGeoMap::MapType mapType_; + QDeclarativeGraphicsGeoMap::ConnectivityMode connectivityMode_; + QSizeF size_; + + QList<QDeclarativeGeoMapObject*> mapObjects_; + QHash<QGeoMapObject*, QDeclarativeGeoMapObject*> objectMap_; + + bool componentCompleted_; + QList<QDeclarativeGeoMapObjectView*> mapViews_; + QDeclarativeGeoMapMouseArea* activeMouseArea_; + QList<QDeclarativeGeoMapMouseArea*> mouseAreas_; + + friend class QDeclarativeGeoMapObjectView; + Q_DISABLE_COPY(QDeclarativeGraphicsGeoMap) +}; + +QTM_END_NAMESPACE + +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeGraphicsGeoMap)); + +#endif diff --git a/src/imports/location/qdeclarativelandmark.cpp b/src/imports/location/qdeclarativelandmark.cpp new file mode 100644 index 00000000..1e1527ba --- /dev/null +++ b/src/imports/location/qdeclarativelandmark.cpp @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativelandmark_p.h" + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass Landmark QDeclarativeLandmark + \brief The Landmark element presents one landmark. + \ingroup qml-location-landmarks + \inherits Place + + This element is part of the \bold{QtMobility.location 1.1} module. + + The Landmark element presents one landmark. + The primary source for landmarks is the \l LandmarkModel. + To get Categories of a certain landmark, see the + LandmarkCategoryModel::landmark. Currently saving Landmarks + is not supported. + + \snippet doc/src/snippets/declarative/declarative-landmark.qml User declared landmark + + \sa Place, LandmarkCategory, LandmarkModel, LandmarkCategoryModel, {QLandmark} +*/ + +QDeclarativeLandmark::QDeclarativeLandmark(QObject* parent) : + QDeclarativeGeoPlace(parent) +{ +} + +QDeclarativeLandmark::QDeclarativeLandmark(const QLandmark& landmark, QObject* parent) : + QDeclarativeGeoPlace(landmark, parent), m_landmark(landmark) +{ +} + +QString QDeclarativeLandmark::name() +{ + return m_landmark.name(); +} + +/*! + \qmlproperty string Landmark::name + + This property holds the name of the landmark. + + */ + +void QDeclarativeLandmark::setName(const QString& name) +{ + if (name == m_landmark.name()) + return; + m_landmark.setName(name); + emit nameChanged(); +} + +QString QDeclarativeLandmark::phoneNumber() +{ + return m_landmark.phoneNumber(); +} + +/*! + \qmlproperty string Landmark::phoneNumber + + This property holds the phoneNumber of the landmark. + + */ + +void QDeclarativeLandmark::setPhoneNumber(const QString& phoneNumber) +{ + if (phoneNumber == m_landmark.phoneNumber()) + return; + m_landmark.setPhoneNumber(phoneNumber); + emit phoneNumberChanged(); +} + +QString QDeclarativeLandmark::description() +{ + return m_landmark.description(); +} + +/*! + \qmlproperty string Landmark::description + + This property holds the description of the landmark. + + */ + +void QDeclarativeLandmark::setDescription(const QString& description) +{ + if (description == m_landmark.description()) + return; + m_landmark.setDescription(description); + emit descriptionChanged(); +} + +double QDeclarativeLandmark::radius() +{ + return m_landmark.radius(); +} + +/*! + \qmlproperty double Landmark::radius + + This property holds the coverage radius of the landmark (in metres). + The coverage radius is relevant for large landmarks such as cities. + + Note that landmark searches over a given area do not factor in the coverage radius. + + */ + +void QDeclarativeLandmark::setRadius(const double& radius) +{ + if (radius == m_landmark.radius()) + return; + m_landmark.setRadius(radius); + emit radiusChanged(); +} + +QUrl QDeclarativeLandmark::iconSource() +{ + return m_landmark.iconUrl(); +} + +/*! + \qmlproperty url Landmark::iconSource + + This property holds the landmark's icon's URL. + + */ + +void QDeclarativeLandmark::setIconSource(const QUrl& iconSource) +{ + if (iconSource == m_landmark.iconUrl()) + return; + m_landmark.setIconUrl(iconSource); + emit iconSourceChanged(); +} + +QUrl QDeclarativeLandmark::url() +{ + return m_landmark.url(); +} + +/*! + \qmlproperty url Landmark::url + + This property holds the URL of the landmark. + + */ + +void QDeclarativeLandmark::setUrl(const QUrl& url) +{ + if (url == m_landmark.url()) + return; + m_landmark.setUrl(url); + emit urlChanged(); +} + +// Initializes this landmark from the given landmark +void QDeclarativeLandmark::setLandmark(const QLandmark& landmark) +{ + // Elaborate but makes sure appropriate signals are sent + // (this function is called when landmark updates). + setPlace(landmark); // viewport, address, coordinate etc. + setName(landmark.name()); + setPhoneNumber(landmark.phoneNumber()); + setDescription(landmark.description()); + setRadius(landmark.radius()); + setIconSource(landmark.iconUrl()); + setUrl(landmark.url()); + m_landmark = landmark; +} + +QList<QLandmarkCategoryId> QDeclarativeLandmark::categoryIds () const +{ + return m_landmark.categoryIds(); +} + +QLandmark QDeclarativeLandmark::landmark() +{ + return m_landmark; +} + +#include "moc_qdeclarativelandmark_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativelandmark_p.h b/src/imports/location/qdeclarativelandmark_p.h new file mode 100644 index 00000000..177a5831 --- /dev/null +++ b/src/imports/location/qdeclarativelandmark_p.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVELANDMARK_P_H +#define QDECLARATIVELANDMARK_P_H + +#include <QtCore> +#include <QAbstractListModel> +#include <qlandmark.h> +#include <QtDeclarative/qdeclarative.h> +#include "qdeclarativelandmarkcategory_p.h" +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeoplace_p.h" + +// Define this to get qDebug messages +// #define QDECLARATIVE_LANDMARK_DEBUG + +#ifdef QDECLARATIVE_LANDMARK_DEBUG +#include <QDebug> +#endif + +QTM_BEGIN_NAMESPACE + +class QDeclarativeLandmark : public QDeclarativeGeoPlace +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString phoneNumber READ phoneNumber WRITE setPhoneNumber NOTIFY phoneNumberChanged) + Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged) + Q_PROPERTY(double radius READ radius WRITE setRadius NOTIFY radiusChanged) + Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged) + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) + +public: + explicit QDeclarativeLandmark(QObject* parent = 0); + QDeclarativeLandmark(const QLandmark& landmark, QObject* parent = 0); + void setLandmark(const QLandmark& landmark); + + QString name(); + void setName(const QString& name); + QString phoneNumber(); + void setPhoneNumber(const QString& phoneNumber); + QString description(); + void setDescription(const QString& description); + double radius(); + void setRadius(const double& radius); + QUrl iconSource(); + void setIconSource(const QUrl& iconSource); + QUrl url(); + void setUrl(const QUrl& url); + QDeclarativeCoordinate* coordinate(); + void setCoordinate(QDeclarativeCoordinate* coordinate); + + QLandmark landmark(); + +signals: + void nameChanged(); + void phoneNumberChanged(); + void descriptionChanged(); + void radiusChanged(); + void iconSourceChanged(); + void urlChanged(); + void coordinateChanged(); + +private: + friend class QDeclarativeLandmarkModel; + friend class QDeclarativeLandmarkCategoryModel; + QList<QLandmarkCategoryId> categoryIds () const; + QDeclarativeCoordinate m_coordinate; + QLandmark m_landmark; +}; + +QTM_END_NAMESPACE +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeLandmark)); + +#endif // QDECLARATIVELANDMARK_P_H diff --git a/src/imports/location/qdeclarativelandmarkcategory.cpp b/src/imports/location/qdeclarativelandmarkcategory.cpp new file mode 100644 index 00000000..78d480f7 --- /dev/null +++ b/src/imports/location/qdeclarativelandmarkcategory.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativelandmarkcategory_p.h" + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass LandmarkCategory QDeclarativeLandmarkCategory + \brief The LandmarkCategory element presents one landmark category. + \ingroup qml-location-landmarks + + This element is part of the \bold{QtMobility.location 1.1} module. + + The primary source for categories is the \l LandmarkCategoryModel. + To get \l Landmarks belonging to certain category(ies), + \l LandmarkCategoryFilter may be used. Currently saving of categories + is not supported. + + \snippet doc/src/snippets/declarative/declarative-landmark.qml User declared category + + \sa Landmark, LandmarkModel, LandmarkCategoryModel, {QLandmarkCategory} +*/ + + +QDeclarativeLandmarkCategory::QDeclarativeLandmarkCategory(QObject* parent) : + QObject(parent) +{ +} + +QString QDeclarativeLandmarkCategory::name() +{ + return m_category.name(); +} + +/*! + \qmlproperty string LandmarkCategory::name + + This property holds the name of the category. + + */ + +void QDeclarativeLandmarkCategory::setName(const QString& name) +{ + if (name == m_category.name()) + return; + m_category.setName(name); + emit nameChanged(); +} + +QUrl QDeclarativeLandmarkCategory::iconSource() +{ + return m_category.iconUrl(); +} + +/*! + \qmlproperty url LandmarkCategory::iconSource + + This property holds the icon source URL of the category. + + */ + +void QDeclarativeLandmarkCategory::setIconSource(const QUrl& iconSource) +{ + if (iconSource == m_category.iconUrl()) + return; + m_category.setIconUrl(iconSource); + emit iconSourceChanged(); +} + +QLandmarkCategory QDeclarativeLandmarkCategory::category() const +{ + return m_category; +} + +// Initializes this category from the given category +void QDeclarativeLandmarkCategory::setCategory(const QLandmarkCategory& category) +{ + setName(category.name()); + setIconSource(category.iconUrl()); + m_category = category; +} + +#include "moc_qdeclarativelandmarkcategory_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativelandmarkcategory_p.h b/src/imports/location/qdeclarativelandmarkcategory_p.h new file mode 100644 index 00000000..9d890b46 --- /dev/null +++ b/src/imports/location/qdeclarativelandmarkcategory_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVELANDMARKCATEGORY_P_H +#define QDECLARATIVELANDMARKCATEGORY_P_H + +#include <qlandmark.h> +#include <qlandmarkcategory.h> +#include <QtDeclarative/qdeclarative.h> +#include <QAbstractListModel> +#include <QtCore> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeLandmarkCategory : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged) + +public: + explicit QDeclarativeLandmarkCategory(QObject* parent = 0); + + QString name(); + void setName(const QString& name); + + QUrl iconSource(); + void setIconSource(const QUrl& iconSource); + + QLandmarkCategory category() const; + +signals: + void nameChanged(); + void iconSourceChanged(); + +private: + + QLandmarkCategory m_category; + friend class QDeclarativeLandmarkCategoryModel; + void setCategory(const QLandmarkCategory& category); +}; + +QTM_END_NAMESPACE +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeLandmarkCategory)); + +#endif // QDECLARATIVELANDMARKCATEGORY_P_H diff --git a/src/imports/location/qdeclarativelandmarkcategorymodel.cpp b/src/imports/location/qdeclarativelandmarkcategorymodel.cpp new file mode 100644 index 00000000..9255cae8 --- /dev/null +++ b/src/imports/location/qdeclarativelandmarkcategorymodel.cpp @@ -0,0 +1,343 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativelandmarkcategorymodel_p.h" +#include <qlandmarkcategoryfetchrequest.h> +#include <qlandmarkcategoryfetchbyidrequest.h> +#include <QTimer> + +#ifdef QDECLARATIVE_LANDMARK_DEBUG +#include <QDebug> +#endif + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass LandmarkCategoryModel QDeclarativeLandmarkCategoryModel + \brief The LandmarkCategoryModel element provides access to categories. + \inherits LandmarkAbstractModel + \ingroup qml-location-landmarks + + This element is part of the \bold{QtMobility.location 1.1} module. + + LandmarkCategoryModel provides a model of categories from the categories store. + The contents of the model can be specified with \l landmark, and sorted + via the \l LandmarkAbstractModel::sortBy and \l LandmarkAbstractModel::sortOrder properties. + Whether the model is automatically updated when the store or \l landmark changes, can be + controlled with \l LandmarkAbstractModel::autoUpdate property. + + There are two ways of accessing the category data: via model by using views and delegates, + or alternatively via \l categories list property. Of the two, the model access is preferred. + Direct list access (i.e. non-model) is not guaranteed to be in order set by sortBy and + sortOrder. + + At the moment only data role provided by the model is \c category. + Through that one can access any data provided by the LandmarkCategory element. + + \snippet examples/declarative-location/landmarkmap/landmarkmap.qml Category model + + \sa LandmarkAbstractModel, LandmarkModel, {QLandmarkManager} +*/ + +QDeclarativeLandmarkCategoryModel::QDeclarativeLandmarkCategoryModel(QObject *parent) : + QDeclarativeLandmarkAbstractModel(parent), m_fetchRequest(0), m_landmark(0) +{ + // Establish role names so that they can be queried from this model + QHash<int, QByteArray> roleNames; + roleNames = QAbstractItemModel::roleNames(); + roleNames.insert(CategoryRole, "category"); + setRoleNames(roleNames); +} + +QDeclarativeLandmarkCategoryModel::~QDeclarativeLandmarkCategoryModel() +{ + delete m_fetchRequest; + delete m_sortingOrder; + qDeleteAll(m_categoryMap.values()); + m_categoryMap.clear(); +} + +// When the parent is valid it means that rowCount is returning the number of children of parent. +int QDeclarativeLandmarkCategoryModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return m_categories.count(); +} + +// Returns the stored under the given role for the item referred to by the index. +QVariant QDeclarativeLandmarkCategoryModel::data(const QModelIndex &index, int role) const +{ + QLandmarkCategory category = m_categories.value(index.row()); + + switch (role) { + case Qt::DisplayRole: + return category.name(); + case CategoryRole: + return QVariant::fromValue(m_categoryMap.value(category.categoryId().localId())); + } + return QVariant(); +} + +QDeclarativeLandmark* QDeclarativeLandmarkCategoryModel::landmark() const +{ + return m_landmark; +} + +/*! + \qmlproperty Landmark LandmarkCategoryModel::landmark + + Landmark whose categories the model should represent. + Note that the landmark needs to be from \l LandmarkModel + because its internal category identifiers need to be set. + + */ + +void QDeclarativeLandmarkCategoryModel::setLandmark(QDeclarativeLandmark *landmark) +{ + if (landmark == m_landmark) + return; + m_landmark = landmark; + if (m_autoUpdate) + scheduleUpdate(); + emit landmarkChanged(); +} + +int QDeclarativeLandmarkCategoryModel::count() const +{ + return m_categories.count(); +} + +void QDeclarativeLandmarkCategoryModel::startUpdate() +{ +#ifdef QDECLARATIVE_LANDMARK_DEBUG + qDebug("QDeclarativeLandmarkCategoryModel::startUpdate()"); +#endif + if (!m_manager) { + m_updatePending = false; + return; + } + // Clear any previous updates and request new + cancelUpdate(); + if (m_landmark) { + QLandmarkCategoryFetchByIdRequest* req = new QLandmarkCategoryFetchByIdRequest(m_manager, this); + req->setCategoryIds(m_landmark->categoryIds()); + m_fetchRequest = req; + } else { + m_fetchRequest = new QLandmarkCategoryFetchRequest(m_manager, this); + setFetchRange(); + setFetchOrder(); + } + QObject::connect(m_fetchRequest, SIGNAL(stateChanged(QLandmarkAbstractRequest::State)), this, SLOT(fetchRequestStateChanged(QLandmarkAbstractRequest::State))); + m_fetchRequest->start(); + m_updatePending = false; // Allow requesting updates again +} + +void QDeclarativeLandmarkCategoryModel::setFetchRange() +{ + if (!m_fetchRequest || ((m_limit <= 0) && (m_offset <= 0)) || + (m_fetchRequest->type() != QLandmarkAbstractRequest::CategoryFetchRequest)) + return; + QLandmarkCategoryFetchRequest* req = static_cast<QLandmarkCategoryFetchRequest*>(m_fetchRequest); + if (m_limit > 0) + req->setLimit(m_limit); + if ((m_offset > 0)) + req->setOffset(m_offset); +} + +void QDeclarativeLandmarkCategoryModel::setFetchOrder() +{ + if (!m_fetchRequest || + ((m_sortKey == NoSort) && (m_sortOrder == NoOrder)) || + m_fetchRequest->type() != QLandmarkAbstractRequest::CategoryFetchRequest) + return; + if (m_sortingOrder) { + delete m_sortingOrder; + m_sortingOrder = 0; + } + if (m_sortKey == NameSort) { + m_sortingOrder = new QLandmarkNameSort(); + } else { + m_sortingOrder = new QLandmarkSortOrder(); + } + if (m_sortOrder != NoOrder) + m_sortingOrder->setDirection((Qt::SortOrder)m_sortOrder); + static_cast<QLandmarkCategoryFetchRequest*>(m_fetchRequest)->setSorting(*m_sortingOrder); +} + +void QDeclarativeLandmarkCategoryModel::cancelUpdate() +{ +#ifdef QDECLARATIVE_LANDMARK_DEBUG + qDebug("QDeclarativeLandmarkCategoryModel::cancelUpdate()"); +#endif + if (m_fetchRequest) { + delete m_fetchRequest; + m_fetchRequest = 0; + } +} + +void QDeclarativeLandmarkCategoryModel::convertCategoriesToDeclarative() +{ + QList<QString> categoriesToRemove = m_categoryMap.keys(); + + foreach(const QLandmarkCategory& category, m_categories) { + if (!m_categoryMap.contains(category.categoryId().localId())) { + QDeclarativeLandmarkCategory* declarativeLandmarkCategory = new QDeclarativeLandmarkCategory(this); + declarativeLandmarkCategory->setCategory(category); + m_categoryMap.insert(category.categoryId().localId(), declarativeLandmarkCategory); + } else { + // The landmark exists already, update it + m_categoryMap.value(category.categoryId().localId())->setCategory(category); + // Item is still valid, remove it from the list of removables + categoriesToRemove.removeOne(category.categoryId().localId()); + } + } + foreach (const QString removable, categoriesToRemove) { + delete m_categoryMap.value(removable); + m_categoryMap.remove(removable); + } + emit categoriesChanged(); +} + +void QDeclarativeLandmarkCategoryModel::fetchRequestStateChanged(QLandmarkAbstractRequest::State state) +{ +#ifdef QDECLARATIVE_LANDMARK_DEBUG + qDebug() << "QDeclarativeLandmarkCategoryModel::Fetch request finished with state: " << state; + if (m_fetchRequest) + qDebug() << "and related request error code is: " << m_fetchRequest->errorString(); +#endif + if (!m_fetchRequest || state != QLandmarkAbstractRequest::FinishedState) + return; + + if (m_fetchRequest->error() == QLandmarkManager::NoError) { + // Later improvement item is to make udpate incremental by + // connecting to resultsAvailable() -function. + beginResetModel(); + int oldCount = m_categories.count(); + switch (m_fetchRequest->type()) + { + case QLandmarkAbstractRequest::CategoryFetchRequest: + { + QLandmarkCategoryFetchRequest* req = static_cast<QLandmarkCategoryFetchRequest*>(m_fetchRequest); + m_categories = req->categories(); + } + break; + case QLandmarkAbstractRequest::CategoryFetchByIdRequest: + { + QLandmarkCategoryFetchByIdRequest* req = static_cast<QLandmarkCategoryFetchByIdRequest*>(m_fetchRequest); + m_categories = req->categories(); + } + break; + + default: + // No other types supported + return; + } + // Convert into declarative classes + convertCategoriesToDeclarative(); + endResetModel(); + if (!(oldCount == 0 && m_categories.count() == 0)) + emit modelChanged(); + if (oldCount != m_categories.count()) + emit countChanged(); + } else if (m_error != m_fetchRequest->errorString()) { + m_error = m_fetchRequest->errorString(); + emit errorChanged(); + } +} + +// For testing purposes in order to access ordered data (i.e. as filters dictate) +QList<QLandmarkCategory> QDeclarativeLandmarkCategoryModel::categoryList() +{ + return m_categories; +} + +/*! + \qmlproperty QDeclarativeListProperty LandmarkCategoryModel::categories + + This element holds the list of \l LandmarkCategory elements that the model currently has. + Accessing categories by iterating over this list is not guaranteed to be in the + order set by \l LandmarkAbstractModel::sortBy or \l LandmarkAbstractModel::sortOrder + + \snippet doc/src/snippets/declarative/declarative-landmark.qml Categories list iteration + +*/ + +QDeclarativeListProperty<QDeclarativeLandmarkCategory> QDeclarativeLandmarkCategoryModel::categories() +{ + return QDeclarativeListProperty<QDeclarativeLandmarkCategory>(this, + 0, // opaque data parameter + categories_append, + categories_count, + categories_at, + categories_clear); +} + +void QDeclarativeLandmarkCategoryModel::categories_append(QDeclarativeListProperty<QDeclarativeLandmarkCategory>* prop, QDeclarativeLandmarkCategory* category) +{ + Q_UNUSED(prop); + Q_UNUSED(category); + qWarning() << "LandmarkModel: appending categories is not currently supported"; +} + +int QDeclarativeLandmarkCategoryModel::categories_count(QDeclarativeListProperty<QDeclarativeLandmarkCategory>* prop) +{ + // The 'prop' is in a sense 'this' for this static function (as given in categories() function) + return static_cast<QDeclarativeLandmarkCategoryModel*>(prop->object)->m_categoryMap.values().count(); +} + +QDeclarativeLandmarkCategory* QDeclarativeLandmarkCategoryModel::categories_at(QDeclarativeListProperty<QDeclarativeLandmarkCategory>* prop, int index) +{ + return static_cast<QDeclarativeLandmarkCategoryModel*>(prop->object)->m_categoryMap.values().at(index); +} + +void QDeclarativeLandmarkCategoryModel::categories_clear(QDeclarativeListProperty<QDeclarativeLandmarkCategory>* prop) +{ + QDeclarativeLandmarkCategoryModel* model = static_cast<QDeclarativeLandmarkCategoryModel*>(prop->object); + QMap<QString, QDeclarativeLandmarkCategory*>* categoryMap = &model->m_categoryMap; + qDeleteAll(categoryMap->values()); + categoryMap->clear(); + model->m_categories.clear(); + emit model->categoriesChanged(); +} + +#include "moc_qdeclarativelandmarkcategorymodel_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativelandmarkcategorymodel_p.h b/src/imports/location/qdeclarativelandmarkcategorymodel_p.h new file mode 100644 index 00000000..9d21e337 --- /dev/null +++ b/src/imports/location/qdeclarativelandmarkcategorymodel_p.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVELANDMARKCATEGORYMODEL_P_H +#define QDECLARATIVELANDMARKCATEGORYMODEL_P_H + +#include <qdeclarativelandmark_p.h> +#include <qdeclarativelandmarkmodel_p.h> +#include <qdeclarativelandmarkcategory_p.h> +#include <qdeclarativelandmarkfilters_p.h> + +#include <qlandmarkcategory.h> +#include <qlandmarkmanager.h> +#include <qlandmarkabstractrequest.h> + +#include <QtDeclarative/qdeclarative.h> +#include <QAbstractListModel> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeLandmarkCategoryModel: public QDeclarativeLandmarkAbstractModel +{ + Q_OBJECT + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QDeclarativeLandmark* landmark READ landmark WRITE setLandmark NOTIFY landmarkChanged) + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeLandmarkCategory> categories READ categories NOTIFY categoriesChanged) + +public: + explicit QDeclarativeLandmarkCategoryModel(QObject* parent = 0); + virtual ~QDeclarativeLandmarkCategoryModel(); + + // From QAbstractListModel + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + + // Roles for exposing data via model + enum { + CategoryRole = Qt::UserRole + 500 + }; + QDeclarativeLandmark* landmark() const; + void setLandmark(QDeclarativeLandmark* landmark); + int count() const; + + // For testing purpose to access ordered data + QList<QLandmarkCategory> categoryList(); + QDeclarativeListProperty<QDeclarativeLandmarkCategory> categories(); + static void categories_append(QDeclarativeListProperty<QDeclarativeLandmarkCategory>* prop, QDeclarativeLandmarkCategory* category); + static int categories_count(QDeclarativeListProperty<QDeclarativeLandmarkCategory>* prop); + static QDeclarativeLandmarkCategory* categories_at(QDeclarativeListProperty<QDeclarativeLandmarkCategory>* prop, int index); + static void categories_clear(QDeclarativeListProperty<QDeclarativeLandmarkCategory>* prop); + +signals: + void countChanged(); + void landmarkChanged(); + void categoriesChanged(); + +private slots: + void cancelUpdate(); + void fetchRequestStateChanged(QLandmarkAbstractRequest::State state); + +private: + Q_INVOKABLE void startUpdate(); + void convertCategoriesToDeclarative(); + void setFetchRange(); + void setFetchFilters(); + void setFetchOrder(); + +private: + QLandmarkAbstractRequest* m_fetchRequest; + // Landmark list received from platform + QList<QLandmarkCategory> m_categories; + // Same category list, but as declarative classes + QMap<QString, QDeclarativeLandmarkCategory*> m_categoryMap; + QDeclarativeLandmark* m_landmark; +}; + +QTM_END_NAMESPACE +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeLandmarkCategoryModel)); + +#endif // QDECLARATIVELANDMARKCATEGORYMODEL_P_H diff --git a/src/imports/location/qdeclarativelandmarkfilters.cpp b/src/imports/location/qdeclarativelandmarkfilters.cpp new file mode 100644 index 00000000..798698b6 --- /dev/null +++ b/src/imports/location/qdeclarativelandmarkfilters.cpp @@ -0,0 +1,445 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativelandmarkfilters_p.h" +#include "qdeclarativeposition_p.h" + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass LandmarkNameFilter QDeclarativeLandmarkNameFilter + \brief The LandmarkNameFilter element specifies a name filter for landmark model. + \ingroup qml-location-landmarks + + The LandmarkNameFilter element specifies a name filter for landmark model. + Logical combinations of this and other landmark filters can be + formed using \l LandmarkIntersectionFilter and \l LandmarkUnionFilter. + Currently wild card matching is not supported (only exact matches). + + This element is part of the \bold{QtMobility.location 1.1} module. + + \snippet doc/src/snippets/declarative/declarative-landmark.qml Landmark name filter + + \sa LandmarkModel, {QLandmarkNameFilter} + +*/ + +QDeclarativeLandmarkNameFilter::QDeclarativeLandmarkNameFilter(QObject *parent) : + QDeclarativeLandmarkFilterBase(parent) +{ +} + +QDeclarativeLandmarkNameFilter::~QDeclarativeLandmarkNameFilter() +{ +} + +QString QDeclarativeLandmarkNameFilter::name() const +{ + return m_name; +} + +/*! + \qmlproperty QString LandmarkNameFilter::name + The name string to match landmark names against. + Currently regular expression (/wildcard) matching is not supported. +*/ + +void QDeclarativeLandmarkNameFilter::setName(const QString& name) +{ + if (name == m_name) + return; + m_name = name; + m_filter.setName(m_name); + emit nameChanged(); + emit filterContentChanged(); +} + +QLandmarkFilter* QDeclarativeLandmarkNameFilter::filter() +{ + if (m_name.isEmpty()) + return 0; + return &m_filter; +} + +/*! + \qmlclass LandmarkCategoryFilter QDeclarativeLandmarkCategoryFilter + \brief The LandmarkCategoryFilter element specifies a category filter for landmark model. + \ingroup qml-location-landmarks + + This element is part of the \bold{QtMobility.location 1.1} module. + + Logical combinations of this and other landmark filters can be + formed using \l LandmarkIntersectionFilter and \l LandmarkUnionFilter. + + \sa LandmarkModel, LandmarkCategoryModel, {QLandmarkCategoryFilter} +*/ + +QDeclarativeLandmarkCategoryFilter::QDeclarativeLandmarkCategoryFilter(QObject* parent) : + QDeclarativeLandmarkFilterBase(parent), m_category(0) +{ +} + +QDeclarativeLandmarkCategoryFilter::~QDeclarativeLandmarkCategoryFilter() +{ +} + +QDeclarativeLandmarkCategory* QDeclarativeLandmarkCategoryFilter::category() const +{ + return m_category; +} + +/*! + \qmlproperty LandmarkCategory LandmarkCategoryFilter::category + Category for whose landmarks should be filtered. +*/ + +void QDeclarativeLandmarkCategoryFilter::setCategory(QDeclarativeLandmarkCategory* category) +{ + m_category = category; + m_filter.setCategoryId(m_category->category().categoryId()); + emit categoryChanged(); + emit filterContentChanged(); +} + +QLandmarkFilter* QDeclarativeLandmarkCategoryFilter::filter() +{ + if (!m_category) + return 0; + return &m_filter; +} + + +/*! + \qmlclass LandmarkBoxFilter QDeclarativeLandmarkBoxFilter + \brief The LandmarkBoxFilter element specifies a box (rectangle) filter for landmark model. + \ingroup qml-location-landmarks + + This element is part of the \bold{QtMobility.location 1.1} module. + + The LandmarkBoxFilter element specifies a box (rectangle) filter for landmark model. + Logical combinations of this and other landmark filters can be + formed using \l LandmarkIntersectionFilter and \l LandmarkUnionFilter. + + The following example creates a filter which filters for landmarks located within + the given box (rectangle between top left and bottom right coordinates). + + \snippet doc/src/snippets/declarative/declarative-landmark.qml Box filter + + \sa LandmarkModel, {QLandmarkBoxFilter} + +*/ + +QDeclarativeLandmarkBoxFilter::QDeclarativeLandmarkBoxFilter(QObject* parent) : + QDeclarativeLandmarkFilterBase(parent), m_topLeft(0), m_bottomRight(0) +{ +} + +QDeclarativeLandmarkBoxFilter::~QDeclarativeLandmarkBoxFilter() +{ +} + +QDeclarativeCoordinate* QDeclarativeLandmarkBoxFilter::topLeft() const +{ + return m_topLeft; +} + +/*! + \qmlproperty Coordinate LandmarkBoxFilter::topLeft + Top left coordinate of the box to filter (landmarks within the boundaries). +*/ + +void QDeclarativeLandmarkBoxFilter::setTopLeft(QDeclarativeCoordinate* coordinate) +{ + if (m_topLeft == coordinate) + return; + + m_topLeft = coordinate; + + if (m_topLeft && m_bottomRight) + m_filter.setBoundingBox(QGeoBoundingBox(m_topLeft->coordinate(), m_bottomRight->coordinate())); + emit topLeftChanged(); + emit filterContentChanged(); +} + +/*! + \qmlproperty Coordinate LandmarkBoxFilter::bottomRight + Bottom right coordinate of the box to filter (landmarks within the boundaries). +*/ + +QDeclarativeCoordinate* QDeclarativeLandmarkBoxFilter::bottomRight() const +{ + return m_bottomRight; +} + +void QDeclarativeLandmarkBoxFilter::setBottomRight(QDeclarativeCoordinate* coordinate) +{ + if (m_bottomRight == coordinate) + return; + + m_bottomRight = coordinate; + if (m_topLeft && m_bottomRight) + m_filter.setBoundingBox(QGeoBoundingBox(m_topLeft->coordinate(), m_bottomRight->coordinate())); + emit bottomRightChanged(); + emit filterContentChanged(); +} + +QLandmarkFilter* QDeclarativeLandmarkBoxFilter::filter() +{ + if (!m_topLeft || !m_bottomRight) + return 0; + return &m_filter; +} + +/*! + \qmlclass LandmarkProximityFilter QDeclarativeLandmarkProximityFilter + \brief The LandmarkProximityFilter element specifies a proximity filter for landmark model. + \ingroup qml-location-landmarks + + The LandmarkProximityFilter element specifies a proximity filter for landmark model. + Logical combinations of this and other landmark filters can be + formed using \l LandmarkIntersectionFilter and \l LandmarkUnionFilter. + + This element is part of the \bold{QtMobility.location 1.1} module. + + The following example creates a filter which filters for landmarks located within + 1500 metres of the current position. + + \snippet doc/src/snippets/declarative/declarative-landmark.qml Landmark proximity filter + + \sa LandmarkModel, {QLandmarkProximityFilter} +*/ + +QDeclarativeLandmarkProximityFilter::QDeclarativeLandmarkProximityFilter(QObject *parent) : + QDeclarativeLandmarkFilterBase(parent), m_radius(0), m_coordinate(0) +{ +} + +QDeclarativeLandmarkProximityFilter::~QDeclarativeLandmarkProximityFilter() +{ +} + +double QDeclarativeLandmarkProximityFilter::radius() const +{ + return m_radius; +} + +/*! + \qmlproperty double LandmarkProximityFilter::radius + Radius (in metres) from the \l center coordinate to filter + (landmarks within that area). + + \sa center +*/ + +void QDeclarativeLandmarkProximityFilter::setRadius(const double radius) +{ + if (radius == m_radius) + return; + m_radius = radius; + emit radiusChanged(); + emit filterContentChanged(); +} + +QDeclarativeCoordinate* QDeclarativeLandmarkProximityFilter::center() const +{ + return m_coordinate; +} + +/*! + \qmlproperty Coordinate LandmarkProximityFilter::center + Center coordinate in whose proximity landmarks should be filtered. + + \sa radius +*/ + +void QDeclarativeLandmarkProximityFilter::setCenter(QDeclarativeCoordinate* coordinate) +{ + if (m_coordinate == coordinate) + return; + m_coordinate = coordinate; + + if (m_coordinate) { + QObject::connect(m_coordinate, SIGNAL(latitudeChanged(double)), this, SIGNAL(filterContentChanged())); + QObject::connect(m_coordinate, SIGNAL(longitudeChanged(double)), this, SIGNAL(filterContentChanged())); + } + emit centerChanged(); + emit filterContentChanged(); +} + +QLandmarkFilter* QDeclarativeLandmarkProximityFilter::filter() +{ + if (!m_coordinate) + return 0; + // Populate filter only now in case their contents have changed. + m_filter.setRadius(m_radius); + m_filter.setCenter(m_coordinate->coordinate()); + return &m_filter; +} + + +QDeclarativeLandmarkCompoundFilter::QDeclarativeLandmarkCompoundFilter(QObject* parent) + : QDeclarativeLandmarkFilterBase(parent) +{ +} + +/*! + \qmlproperty list<Landmark*Filter> LandmarkUnionFilter::filters + \default + + The filters to OR together. +*/ + +/*! + \qmlproperty list<Landmark*Filter> LandmarkIntersectionFilter::filters + \default + + The filters to AND together. +*/ + +QDeclarativeListProperty<QDeclarativeLandmarkFilterBase> QDeclarativeLandmarkCompoundFilter::filters() +{ + return QDeclarativeListProperty<QDeclarativeLandmarkFilterBase>(this, + 0, // opaque data parameter + filters_append, + filters_count, + filters_at, + filters_clear); +} + +void QDeclarativeLandmarkCompoundFilter::filters_append(QDeclarativeListProperty<QDeclarativeLandmarkFilterBase>* prop, QDeclarativeLandmarkFilterBase* filter) +{ + QDeclarativeLandmarkCompoundFilter* compoundFilter = static_cast<QDeclarativeLandmarkCompoundFilter*>(prop->object); + compoundFilter->m_filters.append(filter); + QObject::connect(filter, SIGNAL(filterContentChanged()), compoundFilter, SIGNAL(filterContentChanged())); + emit compoundFilter->filterContentChanged(); +} + +int QDeclarativeLandmarkCompoundFilter::filters_count(QDeclarativeListProperty<QDeclarativeLandmarkFilterBase>* prop) +{ + // The 'prop' is in a sense 'this' for this static function (as given in filters() function) + return static_cast<QDeclarativeLandmarkCompoundFilter*>(prop->object)->m_filters.count(); +} + +QDeclarativeLandmarkFilterBase* QDeclarativeLandmarkCompoundFilter::filters_at(QDeclarativeListProperty<QDeclarativeLandmarkFilterBase>* prop, int index) +{ + return static_cast<QDeclarativeLandmarkCompoundFilter*>(prop->object)->m_filters.at(index); +} + +void QDeclarativeLandmarkCompoundFilter::filters_clear(QDeclarativeListProperty<QDeclarativeLandmarkFilterBase>* prop) +{ + QDeclarativeLandmarkCompoundFilter* filter = static_cast<QDeclarativeLandmarkCompoundFilter*>(prop->object); + qDeleteAll(filter->m_filters); + filter->m_filters.clear(); +} + +template <class T> + bool QDeclarativeLandmarkCompoundFilter::appendFilters(T* compoundFilter) +{ + // Creates a T type compound filter of all filters. + if (m_filters.isEmpty()) + return false; + compoundFilter->clear(); + for (int i = 0; i < m_filters.count(); i++) { + compoundFilter->append(*m_filters.at(i)->filter()); + } + return true; +} + +/*! + \qmlclass LandmarkUnionFilter QDeclarativeLandmarkUnionFilter + \brief The LandmarkUnionFilter element specifies a union of landmark filters. + \ingroup qml-location-landmarks + + This element is part of the \bold{QtMobility.location 1.1} module. + + Logical OR combinations of landmark filters can be formed using LandmarkUnionFilter. + + The following example creates a filter which filters for landmarks which are + either named \c Nimbin, or located within 1500 metres from current location + (or both). + + \snippet doc/src/snippets/declarative/declarative-landmark.qml LandmarkModel union filter + + \sa LandmarkIntersectionFilter LandmarkModel, {QLandmarkUnionFilter} + +*/ + +QLandmarkFilter* QDeclarativeLandmarkUnionFilter::filter() +{ + return appendFilters<QLandmarkUnionFilter>(&m_filter) ? &m_filter : 0; +} + +QDeclarativeLandmarkUnionFilter::QDeclarativeLandmarkUnionFilter(QObject* parent) + : QDeclarativeLandmarkCompoundFilter(parent) +{ +} + +/*! + \qmlclass LandmarkIntersectionFilter QDeclarativeLandmarkIntersectionFilter + \brief The LandmarkIntersectionFilter element specifies an insection of landmark filters. + \ingroup qml-location-landmarks + + This element is part of the \bold{QtMobility.location 1.1} module. + + The LandmarkIntersectionFilter element specifies an insection of landmark filters. + Logical AND combinations of LandmarkFilters can be formed using LandmarkIntersectionFilter. + + The following example creates a filter which filters for landmarks named \c Darwin within + 500 metres of coordinate (20,10). + + \snippet doc/src/snippets/declarative/declarative-landmark.qml LandmarkModel intersection filter + + \sa LandmarkUnionFilter, LandmarkModel, {QLandmarkIntersectionFilter} +*/ + +QDeclarativeLandmarkIntersectionFilter::QDeclarativeLandmarkIntersectionFilter(QObject* parent) + : QDeclarativeLandmarkCompoundFilter(parent) +{ +} + +QLandmarkFilter* QDeclarativeLandmarkIntersectionFilter::filter() +{ + return appendFilters<QLandmarkIntersectionFilter>(&m_filter) ? &m_filter : 0; +} + +#include "moc_qdeclarativelandmarkfilters_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativelandmarkfilters_p.h b/src/imports/location/qdeclarativelandmarkfilters_p.h new file mode 100644 index 00000000..bd000ed2 --- /dev/null +++ b/src/imports/location/qdeclarativelandmarkfilters_p.h @@ -0,0 +1,240 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVELANDMARKFILTERS_P_H +#define QDECLARATIVELANDMARKFILTERS_P_H + +#include <qlandmarkintersectionfilter.h> +#include <qlandmarkproximityfilter.h> +#include <qdeclarativecoordinate_p.h> +#include <qlandmarkunionfilter.h> +#include <qlandmarknamefilter.h> +#include <qlandmarkcategoryfilter.h> +#include <qlandmarkboxfilter.h> +#include <qlandmarkfilter.h> +#include <qdeclarativelandmarkcategory_p.h> + +#include <QtDeclarative/qdeclarative.h> +#include <QDeclarativeListProperty> +#include <QObject> + +QTM_BEGIN_NAMESPACE + +class QDeclarativeLandmarkFilterBase : public QObject +{ + Q_OBJECT + +public: + explicit QDeclarativeLandmarkFilterBase(QObject* parent = 0) : QObject(parent) {} + virtual ~QDeclarativeLandmarkFilterBase() {} + + // Returns a C++ intersection filter of all set filters + virtual QLandmarkFilter* filter() = 0; + +signals: + // This signal is more of internal importance, not part of public interface + void filterContentChanged(); + +}; + +class QDeclarativeLandmarkCompoundFilter: public QDeclarativeLandmarkFilterBase +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeLandmarkFilterBase> filters READ filters) + Q_CLASSINFO("DefaultProperty", "filters") + +public: + explicit QDeclarativeLandmarkCompoundFilter(QObject* parent = 0); + virtual ~QDeclarativeLandmarkCompoundFilter() {} + // 'READ' accessor for the filters, basically this is also a 'WRITE' accessor + // as per QDeclarativeListProperty's design. + QDeclarativeListProperty<QDeclarativeLandmarkFilterBase> filters(); + + static void filters_append(QDeclarativeListProperty<QDeclarativeLandmarkFilterBase>* prop, QDeclarativeLandmarkFilterBase* landmark); + static int filters_count(QDeclarativeListProperty<QDeclarativeLandmarkFilterBase>* prop); + static QDeclarativeLandmarkFilterBase* filters_at(QDeclarativeListProperty<QDeclarativeLandmarkFilterBase>* prop, int index); + static void filters_clear(QDeclarativeListProperty<QDeclarativeLandmarkFilterBase>* prop); + +protected: + template <class T> bool appendFilters(T* compoundFilter); + +private: + QList<QDeclarativeLandmarkFilterBase*> m_filters; +}; + + +class QDeclarativeLandmarkCategoryFilter : public QDeclarativeLandmarkFilterBase +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeLandmarkCategory* category READ category WRITE setCategory NOTIFY categoryChanged) + +public: + explicit QDeclarativeLandmarkCategoryFilter(QObject* parent = 0); + ~QDeclarativeLandmarkCategoryFilter(); + + QDeclarativeLandmarkCategory* category() const; + void setCategory(QDeclarativeLandmarkCategory* category); + // From QDeclarativeLandmarkFilterBase + virtual QLandmarkFilter* filter(); + +signals: + void categoryChanged(); + +private: + QDeclarativeLandmarkCategory* m_category; + QLandmarkCategoryFilter m_filter; +}; + + +class QDeclarativeLandmarkBoxFilter : public QDeclarativeLandmarkFilterBase +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeCoordinate* topLeft READ topLeft WRITE setTopLeft NOTIFY topLeftChanged) + Q_PROPERTY(QDeclarativeCoordinate* bottomRight READ bottomRight WRITE setBottomRight NOTIFY bottomRightChanged) + +public: + explicit QDeclarativeLandmarkBoxFilter(QObject* parent = 0); + ~QDeclarativeLandmarkBoxFilter(); + + QDeclarativeCoordinate* topLeft() const; + void setTopLeft(QDeclarativeCoordinate* coordinate); + + QDeclarativeCoordinate* bottomRight() const; + void setBottomRight(QDeclarativeCoordinate* coordinate); + + // From QDeclarativeLandmarkFilterBase + virtual QLandmarkFilter* filter(); + +signals: + void topLeftChanged(); + void bottomRightChanged(); + +private: + + QDeclarativeCoordinate* m_topLeft; + QDeclarativeCoordinate* m_bottomRight; + QLandmarkBoxFilter m_filter; +}; + +class QDeclarativeLandmarkNameFilter : public QDeclarativeLandmarkFilterBase +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + +public: + explicit QDeclarativeLandmarkNameFilter(QObject* parent = 0); + ~QDeclarativeLandmarkNameFilter(); + + QString name() const; + void setName(const QString& name); + // From QDeclarativeLandmarkFilterBase + virtual QLandmarkFilter* filter(); + +signals: + void nameChanged(); + +private: + QString m_name; + QLandmarkNameFilter m_filter; +}; + + +class QDeclarativeLandmarkProximityFilter : public QDeclarativeLandmarkFilterBase +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeCoordinate* center READ center WRITE setCenter NOTIFY centerChanged) + Q_PROPERTY(double radius READ radius WRITE setRadius NOTIFY radiusChanged) + +public: + explicit QDeclarativeLandmarkProximityFilter(QObject* parent = 0); + ~QDeclarativeLandmarkProximityFilter(); + + double radius() const; + void setRadius(const double radius); + QDeclarativeCoordinate* center() const; + void setCenter(QDeclarativeCoordinate* coordinate); + // From QDeclarativeLandmarkFilterBase + virtual QLandmarkFilter* filter(); + +signals: + void radiusChanged(); + void centerChanged(); + +private: + double m_radius; + QDeclarativeCoordinate* m_coordinate; + QLandmarkProximityFilter m_filter; +}; + + +class QDeclarativeLandmarkUnionFilter : public QDeclarativeLandmarkCompoundFilter +{ + Q_OBJECT + +public: + explicit QDeclarativeLandmarkUnionFilter(QObject* parent = 0); + QLandmarkFilter* filter(); + +private: + QLandmarkUnionFilter m_filter; +}; + +class QDeclarativeLandmarkIntersectionFilter : public QDeclarativeLandmarkCompoundFilter +{ + Q_OBJECT + +public: + explicit QDeclarativeLandmarkIntersectionFilter(QObject* parent = 0); + virtual QLandmarkFilter* filter(); + +private: + QLandmarkIntersectionFilter m_filter; +}; + +QTM_END_NAMESPACE +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeLandmarkNameFilter)); +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeLandmarkCategoryFilter)); +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeLandmarkBoxFilter)); +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeLandmarkProximityFilter)); +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeLandmarkUnionFilter)); +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeLandmarkIntersectionFilter)); + +#endif // QDECLARATIVELANDMARKFILTERS_P_H diff --git a/src/imports/location/qdeclarativelandmarkmodel.cpp b/src/imports/location/qdeclarativelandmarkmodel.cpp new file mode 100644 index 00000000..b07885c4 --- /dev/null +++ b/src/imports/location/qdeclarativelandmarkmodel.cpp @@ -0,0 +1,819 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativelandmarkmodel_p.h" +#include <QtDeclarative/qdeclarativeinfo.h> +#include <QTimer> + +#ifdef QDECLARATIVE_LANDMARK_DEBUG +#include <QDebug> +#endif + +QTM_BEGIN_NAMESPACE + + +/*! + \qmlclass LandmarkAbstractModel QDeclarativeLandmarkAbstractModel + \brief The LandmarkAbstractModel element is an uncreatable / + uninstantiable base element for LandmarkModel and LandmarkCategoryModel. + It defines many common properties for the two models. + \ingroup qml-location-landmarks + + The LandmarkAbstractModel element is an uncreatable / + uninstantiable base element for LandmarkModel and LandmarkCategoryModel. + It defines many common properties for the two models. + + This element is part of the \bold{QtMobility.location 1.1} module. + + \sa LandmarkModel, LandmarkCategoryModel +*/ + +QDeclarativeLandmarkAbstractModel::QDeclarativeLandmarkAbstractModel(QObject *parent) : + QAbstractListModel(parent), m_manager(0), + m_componentCompleted(false), m_updatePending(false), m_autoUpdate(true), + m_limit(-1), m_offset(-1), m_sortingOrder(0), m_sortOrder(NoOrder), m_sortKey(NoSort) +{ +} + +/*! + \qmlsignal LandmarkAbstractModel::modelChanged() + + This handler is called when the model data has changed. + +*/ + +/*! + \qmlsignal LandmarkAbstractModel::databaseChanged() + + This handler is called when the data in the underlying data + storage has changed. If \l autoUpdate is true, model data + will be updated shortly afterwards. +*/ + + +QDeclarativeLandmarkAbstractModel::~QDeclarativeLandmarkAbstractModel() +{ + delete m_manager; +} + +void QDeclarativeLandmarkAbstractModel::componentComplete() +{ + m_componentCompleted = true; + if (!m_manager) { + m_manager = new QLandmarkManager(); + connectManager(); + } + if (m_autoUpdate) { + scheduleUpdate(); + } +} + +void QDeclarativeLandmarkAbstractModel::connectManager() +{ + if (!m_manager) + return; + connect(m_manager, SIGNAL(categoriesAdded(QList<QLandmarkCategoryId>)), + this, SLOT(categoriesChanged(QList<QLandmarkCategoryId>))); + connect(m_manager, SIGNAL(categoriesChanged(QList<QLandmarkCategoryId>)), + this, SLOT(categoriesChanged(QList<QLandmarkCategoryId>))); + connect(m_manager, SIGNAL(categoriesRemoved(QList<QLandmarkCategoryId>)), + this, SLOT(categoriesChanged(QList<QLandmarkCategoryId>))); + connect(m_manager, SIGNAL(landmarksAdded(QList<QLandmarkId>)), + this, SLOT(landmarksChanged(QList<QLandmarkId>))); + connect(m_manager, SIGNAL(landmarksChanged(QList<QLandmarkId>)), + this, SLOT(landmarksChanged(QList<QLandmarkId>))); + connect(m_manager, SIGNAL(landmarksRemoved(QList<QLandmarkId>)), + this, SLOT(landmarksChanged(QList<QLandmarkId>))); + connect(m_manager, SIGNAL(dataChanged()), + this, SLOT(dataChanged())); +} + +void QDeclarativeLandmarkAbstractModel::categoriesChanged(const QList<QLandmarkCategoryId>& ids) +{ + Q_UNUSED(ids) + if (m_autoUpdate) + update(); + emit databaseChanged(); +} + +void QDeclarativeLandmarkAbstractModel::landmarksChanged(const QList<QLandmarkId>& ids) +{ + Q_UNUSED(ids) + if (m_autoUpdate) + update(); + emit databaseChanged(); +} + +void QDeclarativeLandmarkAbstractModel::dataChanged() +{ + if (m_autoUpdate) + update(); + emit databaseChanged(); +} + +/*! + \qmlproperty bool LandmarkAbstractModel::autoUpdate + + Controls whether the model data should be automatically updated when + appropriate events occur: limit changes, offset changes, filter changes, + filter contents change, or sorting rules change. Property also controls + whether the data is updated automatically once model instantiation is completed. + + Note: while autoUpdate adds to development comfort, each change in appropriate parameters + cause full fetch from underlying database and therefore its use should be thought through. + E.g. if your application inherently behaves such that filters, their contents, + and underlying database change very frequently, it may be wiser to bind a manual + \l update call to a less hectic trigger source. + +*/ + +void QDeclarativeLandmarkAbstractModel::setAutoUpdate(bool autoUpdate) +{ + if (autoUpdate == m_autoUpdate) + return; + m_autoUpdate = autoUpdate; + emit autoUpdateChanged(); +} + +bool QDeclarativeLandmarkAbstractModel::autoUpdate() const +{ + return m_autoUpdate; +} + +void QDeclarativeLandmarkAbstractModel::scheduleUpdate() +{ + if (!m_componentCompleted || m_updatePending) + return; + m_updatePending = true; // Disallow possible duplicate request triggering + QMetaObject::invokeMethod(this, "startUpdate", Qt::QueuedConnection); +} + +/*! + \qmlproperty string LandmarkAbstractModel::error + + Human readable string of the last error that occurred + (read-only). + +*/ + +QString QDeclarativeLandmarkAbstractModel::error() const +{ + return m_error; +} + +// This is purely for testing purposes, not part of public interface +void QDeclarativeLandmarkAbstractModel::setDbFileName(QString fileName) +{ + if (fileName == m_dbFileName) + return; + m_dbFileName = fileName; + if (m_manager) { + cancelUpdate(); + cancelImport(); + delete m_manager; + m_manager = 0; + } + QMap<QString, QString> map; + map["filename"] = m_dbFileName; +#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_6) || defined(Q_WS_MEEGO) + m_manager = new QLandmarkManager(); +#else + m_manager = new QLandmarkManager("com.nokia.qt.landmarks.engines.sqlite", map); +#endif + connectManager(); + if (m_autoUpdate) + scheduleUpdate(); +} + + +/*! + \qmlmethod LandmarkAbstractModel::update() + + Updates the items represented by the model from the + underlying store. + + \sa autoUpdate +*/ + +void QDeclarativeLandmarkAbstractModel::update() +{ + scheduleUpdate(); +} + +int QDeclarativeLandmarkAbstractModel::limit() +{ + return m_limit; +} + +/*! + \qmlproperty int LandmarkAbstractModel::limit + + Sets the maximum amount of items held by the model. +*/ + +void QDeclarativeLandmarkAbstractModel::setLimit(int limit) +{ + if (limit == m_limit) + return; + m_limit = limit; + if (m_autoUpdate) { + scheduleUpdate(); + } + emit limitChanged(); +} + +int QDeclarativeLandmarkAbstractModel::offset() +{ + return m_offset; +} + +/*! + \qmlproperty int LandmarkAbstractModel::offset + + Sets the offset for the landmarks. For example if + one creates a tabbed / paged application, the offset + could be changed dynamically by a multiple of items per page. + +*/ + +void QDeclarativeLandmarkAbstractModel::setOffset(int offset) +{ + if (offset == m_offset) + return; + m_offset = offset; + if (m_autoUpdate) { + scheduleUpdate(); + } + emit offsetChanged(); +} + +QDeclarativeLandmarkAbstractModel::SortKey QDeclarativeLandmarkAbstractModel::sortBy() const +{ + return m_sortKey; +} + +/*! + \qmlproperty enumeration LandmarkAbstractModel::sortBy + + Specifies the role to sort the items by. + + Note: both sortBy and sortOrder incur performance costs. + If the order is not important (e.g. when displaying landmarks + as Map objects) it is advisable not to set them. + + \list + \o LandmarkAbstractModel.None (default) + \o LandmarkAbstractModel.NameSort + \endlist +*/ + +void QDeclarativeLandmarkAbstractModel::setSortBy(QDeclarativeLandmarkAbstractModel::SortKey key) +{ + if (key == m_sortKey) + return; + m_sortKey = key; + if (m_autoUpdate) { + scheduleUpdate(); + } + emit sortByChanged(); +} + +QDeclarativeLandmarkAbstractModel::SortOrder QDeclarativeLandmarkAbstractModel::sortOrder() const +{ + return m_sortOrder; +} + +/*! + \qmlproperty enumeration LandmarkAbstractModel::sortOrder + + Specifies the sort order. + + Note: both sortBy and sortOrder incur performance costs. + If the order is not important (e.g. when displaying landmarks + as Map objects) it is advisable not to set them. + + \list + \o LandmarkAbstractModel.AscendingOrder + \o LandmarkAbstractModel.DescendingOrder + \endlist +*/ + +void QDeclarativeLandmarkAbstractModel::setSortOrder(QDeclarativeLandmarkAbstractModel::SortOrder order) +{ + if (order == m_sortOrder) + return; + m_sortOrder = order; + if (m_autoUpdate) { + scheduleUpdate(); + } + emit sortOrderChanged(); +} + +/*! + \qmlclass LandmarkModel QDeclarativeLandmarkModel + \brief The LandmarkModel element provides access to landmarks. + \inherits LandmarkAbstractModel + \ingroup qml-location-landmarks + + This element is part of the \bold{QtMobility.location 1.1} module. + + LandmarkModel provides a model of landmarks from the landmarks store. + The contents of the model can be specified with a \l filter, and sorted + with the \l LandmarkAbstractModel::sortBy and \l LandmarkAbstractModel::sortOrder properties. + Whether the model is automatically updated when the store or filter changes, can be controlled + with \l LandmarkAbstractModel::autoUpdate property. + + There are two ways of accessing the landmark data: through model by using views and delegates, + or alternatively via \l landmarks list property. Of the two, the model access is preferred. + Direct list access (i.e. non-model) is not guaranteed to be in order set by sortBy and + sortOrder. + + At the moment only data role provided by the model is \c landmark (\l Landmark). + Through that one can access any data provided by the Landmark element. + + The following example illustrates fetching of all landmarks in ascending name order. + Example illustrates both model access as well as direct list access. + + \snippet doc/src/snippets/declarative/declarative-landmark.qml LandmarkModel example + + \sa LandmarkAbstractModel, LandmarkCategoryModel, {QLandmarkManager} +*/ + +QDeclarativeLandmarkModel::QDeclarativeLandmarkModel(QObject *parent) : + QDeclarativeLandmarkAbstractModel(parent), + m_filter(0), m_fetchRequest(0), m_importRequest(0), m_importPending(false) +{ + // Establish role names so that they can be queried from this model + QHash<int, QByteArray> roleNames; + roleNames = QAbstractItemModel::roleNames(); + roleNames.insert(LandmarkRole, "landmark"); + setRoleNames(roleNames); +} + +QDeclarativeLandmarkModel::~QDeclarativeLandmarkModel() +{ + delete m_fetchRequest; + delete m_sortingOrder; + delete m_importRequest; + + qDeleteAll(m_declarativeLandmarks); + m_declarativeLandmarks.clear(); + m_landmarkIdSet.clear(); + m_landmarks.clear(); +} + +// When the parent is valid it means that rowCount is returning the number of children of parent. +int QDeclarativeLandmarkModel::rowCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent); + return m_landmarks.count(); +} + +// Returns the stored under the given role for the item referred to by the index. +QVariant QDeclarativeLandmarkModel::data(const QModelIndex& index, int role) const +{ + QDeclarativeLandmark *declarativeLandmark = m_declarativeLandmarks.at(index.row()); + + switch (role) { + case Qt::DisplayRole: + if (declarativeLandmark) + return declarativeLandmark->landmark().name(); + case LandmarkRole: + if (declarativeLandmark) + return QVariant::fromValue(declarativeLandmark); + } + return QVariant(); +} + +QDeclarativeListProperty<QDeclarativeLandmark> QDeclarativeLandmarkModel::landmarks() +{ + return QDeclarativeListProperty<QDeclarativeLandmark>(this, + 0, // opaque data parameter + landmarks_append, + landmarks_count, + landmarks_at, + landmarks_clear); +} + +QDeclarativeLandmarkFilterBase* QDeclarativeLandmarkModel::filter() +{ + return m_filter; +} + +/*! + \qmlproperty LandmarkFilterBase LandmarkModel::filter + + The filter for filtering landmarks. + + \sa LandmarkUnionFilter, LandmarkIntersectionFilter, LandmarkNameFilter, + LandmarkProximityFilter, LandmarkBoxFilter, LandmarkCategoryFilter + + \snippet doc/src/snippets/declarative/declarative-landmark.qml LandmarkModel filter + +*/ + +void QDeclarativeLandmarkModel::setFilter(QDeclarativeLandmarkFilterBase* filter) +{ + m_filter = filter; + // Connect to listen for filters' content changes + if (filter) + QObject::connect(filter, SIGNAL(filterContentChanged()), this, SLOT(filterContentChanged())); + if (m_autoUpdate) { + scheduleUpdate(); + } + emit filterChanged(); +} + +void QDeclarativeLandmarkModel::filterContentChanged() +{ + if (m_autoUpdate) { +#ifdef QDECLARATIVE_LANDMARK_DEBUG + qDebug() << "QDeclarativeLandmarkModel::filterContentChanged(), scheduling update."; +#endif + scheduleUpdate(); + } +} + +void QDeclarativeLandmarkModel::startUpdate() +{ + if (!m_manager) { + m_updatePending = false; + return; + } + // Clear any previous updates and request new + cancelUpdate(); + m_fetchRequest = new QLandmarkFetchRequest(m_manager, this); + QObject::connect(m_fetchRequest, SIGNAL(stateChanged(QLandmarkAbstractRequest::State)), this, SLOT(fetchRequestStateChanged(QLandmarkAbstractRequest::State))); + // Set filters, orders, and limits + if (m_filter) { + QLandmarkFilter* filter = m_filter->filter(); + if (filter) + m_fetchRequest->setFilter(*filter); + } + setFetchRange(); + setFetchOrder(); +#ifdef QDECLARATIVE_LANDMARK_DEBUG + qDebug() << "============ Calling start for the fetch request: " << m_fetchRequest << " whose manager is: " << m_manager; +#endif + m_fetchRequest->start(); + m_updatePending = false; // Allow requesting updates again +} + +void QDeclarativeLandmarkModel::cancelUpdate() +{ + if (m_fetchRequest) { +#ifdef QDECLARATIVE_LANDMARK_DEBUG + qDebug() << "QDeclarativeLandmarkModel::cancelUpdate() deleting m_fetchRequest:" << m_fetchRequest; +#endif + delete m_fetchRequest; + m_fetchRequest = 0; + } + if (m_sortingOrder) { + delete m_sortingOrder; + m_sortingOrder = 0; + } +} + +/*! + \qmlmethod LandmarkModel::importLandmarks() + + Imports landmarks (and categories) in \l importFile. +*/ + +void QDeclarativeLandmarkModel::importLandmarks() +{ + scheduleImport(); +} + +void QDeclarativeLandmarkModel::cancelImport() +{ + if (m_importRequest) { +#ifdef QDECLARATIVE_LANDMARK_DEBUG + qDebug() << "QDeclarativeLandmarkModel::cancelImport() deleting m_importRequest:" << m_importRequest; +#endif + delete m_importRequest; + m_importRequest = 0; + } +} + +/*! + \qmlproperty int LandmarkAbstractModel::count + + Indicates the number of items currently in the model + (landmarks/categories). + +*/ + +int QDeclarativeLandmarkModel::count() +{ + return m_landmarks.count(); +} + +void QDeclarativeLandmarkModel::setFetchRange() +{ + if (!m_fetchRequest || ((m_limit <= 0) && (m_offset <= 0))) + return; + if (m_limit > 0) + m_fetchRequest->setLimit(m_limit); + if ((m_offset > 0)) + m_fetchRequest->setOffset(m_offset); +} + +void QDeclarativeLandmarkModel::setFetchOrder() +{ + if (!m_fetchRequest || ((m_sortKey == NoSort) && (m_sortOrder == NoOrder))) + return; + if (m_sortingOrder) + delete m_sortingOrder; + if (m_sortKey == NameSort) { + m_sortingOrder = new QLandmarkNameSort(); // Only supported sort type + } else { + m_sortingOrder = new QLandmarkSortOrder(); + } + if (m_sortOrder != NoOrder) + m_sortingOrder->setDirection((Qt::SortOrder)m_sortOrder); + m_fetchRequest->setSorting(*m_sortingOrder); +} + +/*! + \qmlproperty QDeclarativeListProperty LandmarkModel::landmarks + + This element holds the list of \l Landmark elements that the model currently has. + Accessing landmarks by iterating over this list is not guaranteed to be in the + order set by \l LandmarkAbstractModel::sortBy or \l LandmarkAbstractModel::sortOrder + + \snippet doc/src/snippets/declarative/declarative-landmark.qml LandmarkModel landmarks iteration + +*/ + +void QDeclarativeLandmarkModel::landmarks_append(QDeclarativeListProperty<QDeclarativeLandmark>* prop, QDeclarativeLandmark* landmark) +{ + Q_UNUSED(prop); + Q_UNUSED(landmark); + qWarning() << "LandmarkModel: appending landmarks is not currently supported"; +} + +int QDeclarativeLandmarkModel::landmarks_count(QDeclarativeListProperty<QDeclarativeLandmark>* prop) +{ + // The 'prop' is in a sense 'this' for this static function (as given in landmarks() function) + return static_cast<QDeclarativeLandmarkModel*>(prop->object)->m_declarativeLandmarks.count(); +} + +QDeclarativeLandmark* QDeclarativeLandmarkModel::landmarks_at(QDeclarativeListProperty<QDeclarativeLandmark>* prop, int index) +{ + return static_cast<QDeclarativeLandmarkModel*>(prop->object)->m_declarativeLandmarks.at(index); +} + +void QDeclarativeLandmarkModel::landmarks_clear(QDeclarativeListProperty<QDeclarativeLandmark>* prop) +{ + QDeclarativeLandmarkModel* model = static_cast<QDeclarativeLandmarkModel*>(prop->object); + qDeleteAll(model->m_declarativeLandmarks); + model->m_declarativeLandmarks.clear(); + model->m_landmarks.clear(); + emit model->landmarksChanged(); +} + +bool QDeclarativeLandmarkModel::convertLandmarksToDeclarative() +{ + bool changed = false; + if (m_sortOrder == NoOrder && m_sortKey == NoSort) { + Q_ASSERT(m_declarativeLandmarks.count() == m_landmarkIdSet.count()); + // If order does not matter, we can up update without reseting the entire model + // which will enable performance improvements in the view as it does not need + // to recreate all items (which may have significant cost in rendering engine). + // Note: this optimization does not take into account changes in the landmark's + // contents (e.g name or phone number changes). Roughly ~O(2n) + O(rm) + O(new) + // -cost but we need to enable removing and adding range of items + // rather than sending signal for each removed item (typically all may change + // if user pans map). Also we need to be able first to remove obsolete items + // and only then append new ones. + QList<int> indexListOfNewItems; + QSet<QString> landmarksToRemoveIdSet = m_landmarkIdSet; + for (int i = 0; i < m_landmarks.count(); ++i) { + QString landmarkId = m_landmarks.at(i).landmarkId().localId(); + if (!m_landmarkIdSet.contains(landmarkId)) { + // After looping contains all new items + indexListOfNewItems.append(i); + changed = true; + } + else { + // After looping obsolete items will remain + landmarksToRemoveIdSet.remove(landmarkId); + changed = true; + } + } + // Find continuous areas for removals, starting from the end so we can remove on the fly. + int bookmark = m_declarativeLandmarks.count() - 1; + int landmarksToRemove = landmarksToRemoveIdSet.count(); + while (landmarksToRemove > 0) { + int removeBegin = -1; // will be index starting from the end + int removablesInBlock = 0; + while (bookmark >= 0) { + QString landmarkId = m_declarativeLandmarks.at(bookmark)->landmark().landmarkId().localId(); + if (landmarksToRemoveIdSet.contains(landmarkId)) { + // Landmark is obsolete, mark start of removable block. + if (removeBegin == -1) { + removeBegin = bookmark; + } + m_landmarkIdSet.remove(landmarkId); + removablesInBlock++; + bookmark--; + } else { + // Landmark is a keeper. Remove the block of obsolete landmarks detected so far. + bookmark--; + break; // this block of removables is ready to be removed + } + } + if (removeBegin != -1 && removablesInBlock > 0) { + beginRemoveRows(QModelIndex(), removeBegin + 1 - removablesInBlock, removeBegin); + for (int i = 0; i < removablesInBlock; ++i) + delete m_declarativeLandmarks.takeAt(removeBegin + 1 - removablesInBlock); + endRemoveRows(); + landmarksToRemove -= removablesInBlock; + } + } // while landmarks to remove + // Append the new items + if (!indexListOfNewItems.isEmpty()) { + int insertBegin = m_declarativeLandmarks.count(); + beginInsertRows(QModelIndex(), insertBegin, insertBegin + indexListOfNewItems.count() - 1); + for (int i = 0; i < indexListOfNewItems.count(); ++i) { + QDeclarativeLandmark* declarativeLandmark = new QDeclarativeLandmark(m_landmarks.at(indexListOfNewItems.at(i)), this); + m_declarativeLandmarks.append(declarativeLandmark); + m_landmarkIdSet.insert(m_landmarks.at(indexListOfNewItems.at(i)).landmarkId().localId()); + } + endInsertRows(); + } + } else { + // Order matters, reset the whole model. Brutal but otherwise we would need + // to create complex logic to detect item removals, additions and + // moves. This could be optimized to only occur when sortOrder and/or sortBy + // have changed. However e.g. user panning the map will likely cause complex and costly + // update sequences (but definately here is room for improvement if this + // turns in to a bottleneck). + changed = true; + beginResetModel(); + qDeleteAll(m_declarativeLandmarks); + m_declarativeLandmarks.clear(); + m_landmarkIdSet.clear(); + foreach(const QLandmark& landmark, m_landmarks) { + QDeclarativeLandmark* declarativeLandmark = new QDeclarativeLandmark(landmark, this); + m_declarativeLandmarks.append(declarativeLandmark); + m_landmarkIdSet.insert(landmark.landmarkId().localId()); + } + endResetModel(); + } + emit landmarksChanged(); + return changed; +} + +QString QDeclarativeLandmarkModel::importFile() const +{ + return m_importFile; +} + +/*! + \qmlproperty string LandmarkModel::importFile + + Landmarks and their related categories can be imported by setting + the import file. If \l LandmarkAbstractModel::autoUpdate is true, the import will be done + automatically and as a result model updates. Alternatively \l importLandmarks() can be invoked. + + For supported file formats, refer to \l QLandmarkManager and \l QLandmarkImportRequest. + + \snippet doc/src/snippets/declarative/declarative-landmark.qml LandmarkModel import file + + */ + +void QDeclarativeLandmarkModel::setImportFile(QString importFile) +{ + if (importFile == m_importFile) + return; + m_importFile = importFile; + if (m_importRequest) { + delete m_importRequest; + m_importRequest = 0; + } + if (m_autoUpdate) + scheduleImport(); + emit importFileChanged(); +} + +void QDeclarativeLandmarkModel::scheduleImport() +{ + if (!m_componentCompleted || m_importPending) + return; + m_importPending = true; // Disallow possible duplicate request triggering + QMetaObject::invokeMethod(this, "startImport", Qt::QueuedConnection); +} + +void QDeclarativeLandmarkModel::componentComplete() +{ + m_componentCompleted = true; + if (!m_manager) { + m_manager = new QLandmarkManager(); + connectManager(); + } + if (m_autoUpdate) { + if (!m_importFile.isEmpty()) + scheduleImport(); + scheduleUpdate(); + } +} + +void QDeclarativeLandmarkModel::startImport() +{ + if (!m_manager || m_importFile.isEmpty()) { + qmlInfo(this) << tr("Cannot import, import file is empty."); + m_importPending = false; + return; + } + if (!QFile::exists(m_importFile)) + qmlInfo(this) << tr("Import file not found."); + + if (m_importRequest) + delete m_importRequest; + m_importRequest = new QLandmarkImportRequest(m_manager); + m_importRequest->setFileName(m_importFile); +#ifdef QDECLARATIVE_LANDMARK_DEBUG + qDebug() << "============ Calling start for the import request: " << m_importRequest << " whose manager is: " << m_manager << "and file is:" << m_importFile; + +#endif + m_importRequest->start(); // If successful, will result in landmark/category added signals + m_importPending = false; +} + + +QList<QLandmark> QDeclarativeLandmarkModel::landmarkList() +{ + return m_landmarks; +} + +void QDeclarativeLandmarkModel::fetchRequestStateChanged(QLandmarkAbstractRequest::State state) +{ +#ifdef QDECLARATIVE_LANDMARK_DEBUG + qDebug() << "QDeclarativeLandmarkModel::Fetch request finished with state: " << state; + if (m_fetchRequest) { + qDebug() << "and related request error code is: " << m_fetchRequest->errorString(); + qDebug() << "and received this many landmarks:" << m_fetchRequest->landmarks().count(); + } +#endif + if (!m_fetchRequest || state != QLandmarkAbstractRequest::FinishedState) + return; + + if (m_fetchRequest->error() == QLandmarkManager::NoError) { + // Later improvement item is to make udpate incremental by connecting to resultsAvailable() -function. + int oldCount = m_landmarks.count(); + m_landmarks = m_fetchRequest->landmarks(); + // Convert into declarative classes + if (convertLandmarksToDeclarative()) { + emit modelChanged(); + } + if (oldCount != m_landmarks.count()) + emit countChanged(); + } else if (m_error != m_fetchRequest->errorString()) { + m_error = m_fetchRequest->errorString(); + emit errorChanged(); + } +} + +#include "moc_qdeclarativelandmarkmodel_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativelandmarkmodel_p.h b/src/imports/location/qdeclarativelandmarkmodel_p.h new file mode 100644 index 00000000..7d90ea79 --- /dev/null +++ b/src/imports/location/qdeclarativelandmarkmodel_p.h @@ -0,0 +1,229 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVELANDMARKMODEL_P_H +#define QDECLARATIVELANDMARKMODEL_P_H + +#include <qdeclarativelandmark_p.h> +#include <qdeclarativelandmarkfilters_p.h> + +#include <qlandmark.h> +#include <qlandmarkmanager.h> +#include <qlandmarksortorder.h> +#include <qlandmarkfetchrequest.h> +#include <qlandmarkimportrequest.h> + +#include <QtDeclarative/qdeclarative.h> +#include <QDeclarativeParserStatus> +#include <QAbstractListModel> + +QTM_BEGIN_NAMESPACE + + +class QDeclarativeLandmarkAbstractModel : public QAbstractListModel, public QDeclarativeParserStatus +{ + Q_OBJECT + Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged) + Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged) + Q_PROPERTY(bool autoUpdate READ autoUpdate WRITE setAutoUpdate NOTIFY autoUpdateChanged) + Q_PROPERTY(QString error READ error NOTIFY errorChanged) + Q_PROPERTY(SortKey sortBy READ sortBy WRITE setSortBy NOTIFY sortByChanged) + Q_PROPERTY(SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged) + Q_INTERFACES(QDeclarativeParserStatus) + Q_ENUMS(SortOrder) + Q_ENUMS(SortKey) + +public: + explicit QDeclarativeLandmarkAbstractModel(QObject* parent = 0); + virtual ~QDeclarativeLandmarkAbstractModel(); + + enum SortOrder { + AscendingOrder = Qt::AscendingOrder, + DescendingOrder = Qt::DescendingOrder, + NoOrder = Qt::DescendingOrder + 1 + }; + enum SortKey { + NoSort = QLandmarkSortOrder::NoSort, + NameSort = QLandmarkSortOrder::NameSort + }; + + SortKey sortBy() const; + void setSortBy(SortKey key); + SortOrder sortOrder() const; + void setSortOrder(SortOrder order); + + // From QDeclarativeParserStatus + virtual void classBegin() {} + virtual void componentComplete(); + + // From QAbstractListModel + virtual int rowCount(const QModelIndex &parent) const = 0; + virtual QVariant data(const QModelIndex &index, int role) const = 0; + + bool autoUpdate() const; + void setAutoUpdate(bool autoUpdate); + QString error() const; + int limit(); + void setLimit(int limit); + int offset(); + void setOffset(int offset); + + void scheduleUpdate(); + Q_INVOKABLE void setDbFileName(QString fileName); // testing purposes only + virtual void startUpdate() = 0; + +signals: + void sortByChanged(); + void sortOrderChanged(); + void errorChanged(); + void autoUpdateChanged(); + void limitChanged(); + void offsetChanged(); + void modelChanged(); + void databaseChanged(); + +public slots: + void update(); + +private slots: + void categoriesChanged(const QList<QLandmarkCategoryId> &); + void landmarksChanged(const QList<QLandmarkId> &); + void dataChanged(); + +protected: + virtual void cancelUpdate() = 0; + virtual void cancelImport() {}; + void connectManager(); + +protected: + QLandmarkManager* m_manager; + bool m_componentCompleted; + bool m_updatePending; + bool m_autoUpdate; + QString m_error; + QString m_dbFileName; + int m_limit; + int m_offset; + QLandmarkSortOrder* m_sortingOrder; + SortOrder m_sortOrder; + SortKey m_sortKey; +}; + +class QDeclarativeLandmarkModel: public QDeclarativeLandmarkAbstractModel +{ + Q_OBJECT + Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QDeclarativeLandmarkFilterBase* filter READ filter WRITE setFilter NOTIFY filterChanged) + Q_PROPERTY(QDeclarativeListProperty<QDeclarativeLandmark> landmarks READ landmarks NOTIFY landmarksChanged) + Q_PROPERTY(QString importFile READ importFile WRITE setImportFile NOTIFY importFileChanged) + +public: + explicit QDeclarativeLandmarkModel(QObject* parent = 0); + virtual ~QDeclarativeLandmarkModel(); + + // From QAbstractListModel + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + + // Roles for exposing data via model. Only one role because + // everything can be accessed via QDeclarativeLandmark + enum Roles { + LandmarkRole = Qt::UserRole + 500 + }; + + QString importFile() const; + void setImportFile(QString importFile); + void scheduleImport(); + Q_INVOKABLE void importLandmarks(); + + virtual void componentComplete(); + + int count(); + QDeclarativeLandmarkFilterBase* filter(); + void setFilter(QDeclarativeLandmarkFilterBase* filter); + + // For testing purpose to access directly ordered data + QList<QLandmark> landmarkList(); + + QDeclarativeListProperty<QDeclarativeLandmark> landmarks(); + static void landmarks_append(QDeclarativeListProperty<QDeclarativeLandmark>* prop, QDeclarativeLandmark* landmark); + static int landmarks_count(QDeclarativeListProperty<QDeclarativeLandmark>* prop); + static QDeclarativeLandmark* landmarks_at(QDeclarativeListProperty<QDeclarativeLandmark>* prop, int index); + static void landmarks_clear(QDeclarativeListProperty<QDeclarativeLandmark>* prop); + +protected: + Q_INVOKABLE void startUpdate(); + Q_INVOKABLE void startImport(); + +signals: + void countChanged(); + void filterChanged(); + void landmarksChanged(); + void importFileChanged(); + +private slots: + void filterContentChanged(); + void cancelUpdate(); + void cancelImport(); + void fetchRequestStateChanged(QLandmarkAbstractRequest::State); + +private: + bool convertLandmarksToDeclarative(); + void setFetchRange(); + void setFetchOrder(); + +private: + QDeclarativeLandmarkFilterBase* m_filter; + QLandmarkFetchRequest* m_fetchRequest; + QLandmarkImportRequest* m_importRequest; + QString m_importFile; + bool m_importPending; + // Landmark list received from platform + QList<QLandmark> m_landmarks; + // Same landmark list, but as declarative classes + QList<QDeclarativeLandmark*> m_declarativeLandmarks; // The declarative list + QSet<QString> m_landmarkIdSet; // For faster lookups when updating items +}; + +QTM_END_NAMESPACE +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativeLandmarkModel)); + +#endif // QDECLARATIVELANDMARKMODEL_P_H diff --git a/src/imports/location/qdeclarativeposition.cpp b/src/imports/location/qdeclarativeposition.cpp new file mode 100644 index 00000000..2619be69 --- /dev/null +++ b/src/imports/location/qdeclarativeposition.cpp @@ -0,0 +1,364 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativeposition_p.h" +#include "qdeclarative.h" +#include <qnmeapositioninfosource.h> +#include <QFile> +#include <QApplication> + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass Position + + \brief The Position element holds various positional data, such as coordinate + (longitude, latitude, altitude) and speed. + \inherits QObject + \ingroup qml-location + + The Position element holds various positional data, such as \l coordinate, + (longitude, latitude, and altitude) and \l speed, as well as \l timestamp. + + Not all of these are always available (e.g. latitude and longitude may be valid, + but speed update has not been received or set manually), and hence there are + corresponding validity attributes which can be used when writing applications. + + At the time being the Position element is a read-only element (meaning it does + not have exposed write accessors), primarily used by \l PositionSource. + + The Position element is part of the \bold{QtMobility.location 1.1} module. + + \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. + + Note: due to its inherent changing nature, the coordinateChanged() + - signal is emitted also when the values of the coordinate changes, + which enables easier data binding to Coordinate element instead of + directly connecting to e.g. its latitude and longitude. + + \sa longitudeValid latitudeValid altitudeValid + +*/ + +void QDeclarativePosition::setCoordinate(QGeoCoordinate coordinate) +{ + m_coordinate.setCoordinate(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(); +} + +QDeclarativeCoordinate* 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, metres / second). + Currently 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 qreal 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 qreal 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. + +*/ + +void QDeclarativePosition::setTimestamp(const QDateTime& timestamp) +{ + 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" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativeposition_p.h b/src/imports/location/qdeclarativeposition_p.h new file mode 100644 index 00000000..d851af33 --- /dev/null +++ b/src/imports/location/qdeclarativeposition_p.h @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEPOSITION_H +#define QDECLARATIVEPOSITION_H + +#include <QtCore> +#include <QDateTime> +#include <qgeopositioninfosource.h> +#include <qgeopositioninfo.h> +#include <qdeclarativecoordinate_p.h> +#include <QtDeclarative/qdeclarative.h> + +// Define this to get qDebug messages +// #define QDECLARATIVE_POSITION_DEBUG + +#ifdef QDECLARATIVE_POSITION_DEBUG +#include <QDebug> +#endif + +QTM_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(QDeclarativeCoordinate* 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: + + QDeclarativePosition(QObject* parent = 0); + ~QDeclarativePosition(); + + bool isLatitudeValid() const; + bool isLongitudeValid() const; + bool isAltitudeValid() const; + QDateTime timestamp() const; + void setTimestamp(const QDateTime& timestamp); + double speed() const; + void setSpeed(double speed); + bool isSpeedValid() const; + void setCoordinate(QDeclarativeCoordinate* coordinate); + QDeclarativeCoordinate* coordinate(); + bool isHorizontalAccuracyValid() const; + qreal horizontalAccuracy() const; + void setHorizontalAccuracy(qreal horizontalAccuracy); + bool isVerticalAccuracyValid() const; + qreal verticalAccuracy() const; + void setVerticalAccuracy(qreal verticalAccuracy); + + // C++ + void setCoordinate(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; + QDeclarativeCoordinate m_coordinate; +}; + +QTM_END_NAMESPACE +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativePosition)); + +#endif diff --git a/src/imports/location/qdeclarativepositionsource.cpp b/src/imports/location/qdeclarativepositionsource.cpp new file mode 100644 index 00000000..86a194b9 --- /dev/null +++ b/src/imports/location/qdeclarativepositionsource.cpp @@ -0,0 +1,420 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtDeclarative/qdeclarativeinfo.h> +#include "qdeclarativepositionsource_p.h" +#include "qdeclarativeposition_p.h" +#include "qdeclarative.h" +#include <qnmeapositioninfosource.h> +#include <QFile> +#include <QTimer> +#include <QApplication> +#if defined(Q_OS_SYMBIAN) +#include <e32std.h> +#endif + +QTM_BEGIN_NAMESPACE + +/*! + \qmlclass PositionSource + + \brief The PositionSource element allows you to get information about your + current position. + \inherits QObject + + \ingroup qml-location + + The PositionSource element allows you to get information about your current position. + You can receive information about things such as latitude, longitude, altitude, and + speed. This element is part of the \bold{QtMobility.location 1.1} module. + + Support for location sources are platform dependant. When declaring a PositionSource element, a + default PositionSource source shall be created. Supported positioning methods are held in + \l positioningMethod. As a development convenience, one may also set data file as a source (NMEA format). + Location updates are not necessarily started automatically upon element declaration, see \l start \l stop \l active + and \l update. + + Here is very simple example QML to illustrate the usage: + + \snippet doc/src/snippets/declarative/declarative-location.qml 0 + + \sa {QGeoPositionInfoSource}, {QGeoPositionInfo}, {QNmeaPositionInfoSource}, {QGeoCoordinate} + +*/ + +/*! + \internal + \class QDeclarativePositionSource + \brief The QDeclarativePositionSource provides positional data. +*/ + +QDeclarativePositionSource::QDeclarativePositionSource() + : m_positionSource(0), m_positioningMethod(QDeclarativePositionSource::NoPositioningMethod), + m_nmeaFile(0), m_active(false), m_singleUpdate(false), m_updateInterval(0) +{ + m_positionSource = QGeoPositionInfoSource::createDefaultSource(this); + if (m_positionSource) { + connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), + this, SLOT(positionUpdateReceived(QGeoPositionInfo))); + m_positioningMethod = positioningMethod(); +#if defined(Q_OS_SYMBIAN) + } else { + RProcess thisProcess; + if (!thisProcess.HasCapability(ECapabilityLocation)) { + qmlInfo(this) << tr("PositionSource requires the Symbian Location capability to succeed on the Symbian platform."); + } +#endif + } +#ifdef QDECLARATIVE_POSITION_DEBUG + if (m_positionSource) + qDebug("QDeclarativePositionSource QGeoPositionInfoSource::createDefaultSource SUCCESS"); + else + qDebug("QDeclarativePositionSource QGeoPositionInfoSource::createDefaultSource FAILURE"); +#endif +} + +QDeclarativePositionSource::~QDeclarativePositionSource() +{ + delete m_nmeaFile; + delete m_positionSource; +} + +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; + // The current position source needs to be deleted + // because QNmeaPositionInfoSource can be bound only to a one file. + if (m_positionSource) { + 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<QNmeaPositionInfoSource*>(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) << tr("Nmea file not found.") << 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 (m_positioningMethod != positioningMethod()) { + m_positioningMethod = positioningMethod(); + emit positioningMethodChanged(); + } + emit this->nmeaSourceChanged(); +} + +void QDeclarativePositionSource::setUpdateInterval(int updateInterval) +{ + if (m_updateInterval == updateInterval) + return; + + m_updateInterval = updateInterval; + if (m_positionSource) { + m_positionSource->setUpdateInterval(updateInterval); + } + emit updateIntervalChanged(); +} + +/*! + \qmlproperty url PositionSource::nmeaSource + + This property holds the source for NMEA 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. 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 element, there is no way to revert + back to non-file sources. +*/ + +QUrl QDeclarativePositionSource::nmeaSource() const +{ + return m_nmeaSource; +} + +/*! + \qmlproperty bool PositionSource::updateInterval + + This property holds the desired interval between updates (milliseconds). + + \sa {QGeoPositionInfoSource::updateInterval()} + +*/ + +int QDeclarativePositionSource::updateInterval() const +{ + return m_updateInterval; +} + +/*! + \qmlproperty enumeration PositionSource::positioningMethod + + This property holds the supported positioning methods of the + current source. + + \list + \o NoPositioningMethod - No positioning methods supported (no source). + \o SatellitePositioningMethod - Satellite-based positioning methods such as GPS is supported. + \o NonSatellitePositioningMethod - Non satellite methods are supported. + \o AllPositioningMethods - Combination of methods are supported. + \endlist + +*/ + +QDeclarativePositionSource::PositioningMethod QDeclarativePositionSource::positioningMethod() const +{ + if (m_positionSource) { + QGeoPositionInfoSource::PositioningMethods methods = m_positionSource->supportedPositioningMethods(); + if (methods & QGeoPositionInfoSource::SatellitePositioningMethods) { + //qDebug() << "Returning satellite: " << QDeclarativePositionSource::SatellitePositioningMethod; + return QDeclarativePositionSource::SatellitePositioningMethod; + } else if (methods & QGeoPositionInfoSource::NonSatellitePositioningMethods) { + //qDebug() << "Returning non-satellite: " << QDeclarativePositionSource::NonSatellitePositioningMethod; + return QDeclarativePositionSource::NonSatellitePositioningMethod; + } else if (methods & QGeoPositionInfoSource::AllPositioningMethods) { + //qDebug() << "Returning all: " << QDeclarativePositionSource::AllPositioningMethods; + return QDeclarativePositionSource::AllPositioningMethods; + } + } + //qDebug() << "Returning no-positioning: " << QDeclarativePositionSource::NoPositioningMethod; + return QDeclarativePositionSource::NoPositioningMethod; +} + +/*! + \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) { + // Safe to set, setting zero means using default value + m_positionSource->setUpdateInterval(m_updateInterval); + 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. + + \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(); + } + } +} + +/*! + \qmlsignal PositionSource::positionChanged() + + This signal is sent when a position update has been received + from the location source. Upon receiving this signal, at least + position::latitude, position::longitude, and position::timestamp + members of the \l position have been updated. + + \sa updateInterval + +*/ + +/*! + \qmlproperty bool PositionSource::active + + This property indicates whether the position source is (/should be) + 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. + + The Position element has different positional member variables, + whose validity can be checked with appropriate validity functions + (e.g. sometimes an update does not have speed or altitude data). + + However, whenever a \l 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(); + } +} + +#include "moc_qdeclarativepositionsource_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativepositionsource_p.h b/src/imports/location/qdeclarativepositionsource_p.h new file mode 100644 index 00000000..edfe310f --- /dev/null +++ b/src/imports/location/qdeclarativepositionsource_p.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEPOSITIONSOURCE_H +#define QDECLARATIVEPOSITIONSOURCE_H + +#include <QtCore> +#include <QDateTime> +#include <qgeopositioninfosource.h> +#include <qgeopositioninfo.h> +#include <QtDeclarative/qdeclarative.h> +#include "qdeclarativeposition_p.h" + +class QFile; + +QTM_BEGIN_NAMESPACE + +class QDeclarativePositionSource : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativePosition* position READ position NOTIFY positionChanged) + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) + Q_PROPERTY(QUrl nmeaSource READ nmeaSource WRITE setNmeaSource NOTIFY nmeaSourceChanged) + Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval NOTIFY updateIntervalChanged) + Q_PROPERTY(PositioningMethod positioningMethod READ positioningMethod NOTIFY positioningMethodChanged) + Q_ENUMS(PositioningMethod) + +public: + + enum PositioningMethod { + NoPositioningMethod = 0, + SatellitePositioningMethod = QGeoPositionInfoSource::SatellitePositioningMethods, + NonSatellitePositioningMethod = QGeoPositionInfoSource::NonSatellitePositioningMethods, + AllPositioningMethods = QGeoPositionInfoSource::AllPositioningMethods + }; + QDeclarativePositionSource(); + ~QDeclarativePositionSource(); + void setNmeaSource(const QUrl& nmeaSource); + void setUpdateInterval(int updateInterval); + void setActive(bool active); + + QUrl nmeaSource() const; + int updateInterval() const; + bool isActive() const; + QDeclarativePosition* position(); + PositioningMethod positioningMethod() const; + +public Q_SLOTS: + void update(); + void start(); + void stop(); + +Q_SIGNALS: + void positionChanged(); + void activeChanged(); + void nmeaSourceChanged(); + void updateIntervalChanged(); + void positioningMethodChanged(); + +private Q_SLOTS: + void positionUpdateReceived(const QGeoPositionInfo& update); + +private: + QGeoPositionInfoSource* m_positionSource; + PositioningMethod m_positioningMethod; + QDeclarativePosition m_position; + QFile* m_nmeaFile; + QString m_nmeaFileName; + QUrl m_nmeaSource; + bool m_active; + bool m_singleUpdate; + int m_updateInterval; +}; + +QTM_END_NAMESPACE +QML_DECLARE_TYPE(QTM_PREPEND_NAMESPACE(QDeclarativePositionSource)); + +#endif diff --git a/src/imports/location/qdeclarativereversegeocodemodel.cpp b/src/imports/location/qdeclarativereversegeocodemodel.cpp new file mode 100644 index 00000000..e6d0aa57 --- /dev/null +++ b/src/imports/location/qdeclarativereversegeocodemodel.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativereversegeocodemodel_p.h" + +#include <qgeosearchmanager.h> + +QTM_BEGIN_NAMESPACE + +QDeclarativeReverseGeocodeModel::QDeclarativeReverseGeocodeModel(QObject *parent) + : QDeclarativeGeoSearchModel(parent), + complete_(false) {} + +QDeclarativeReverseGeocodeModel::~QDeclarativeReverseGeocodeModel() {} + +void QDeclarativeReverseGeocodeModel::setCoordinate(QDeclarativeCoordinate *coordinate) +{ + if (coordinate_.coordinate() == coordinate->coordinate()) + return; + + coordinate_.setCoordinate(coordinate->coordinate()); + + emit coordinateChanged(&coordinate_); + + if (complete_) + update(); +} + +QDeclarativeCoordinate* QDeclarativeReverseGeocodeModel::coordinate() +{ + return &coordinate_; +} + +void QDeclarativeReverseGeocodeModel::componentComplete() +{ + if (!searchManager()) + return; + + complete_ = true; + update(); +} + +void QDeclarativeReverseGeocodeModel::update() +{ + if (searchManager() && coordinate_.coordinate().isValid()) { + + setStatus(QDeclarativeGeoSearchModel::Loading); + + searchManager()->reverseGeocode(coordinate_.coordinate()); + + // TODO check for finished + } +} + +QVariant QDeclarativeReverseGeocodeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() > places().count()) + return QVariant(); + + QGeoPlace place = places().at(index.row()); + + if (role == Qt::DisplayRole) { + QGeoAddress address = place.address(); + + QStringList addressStrings; + if (!address.street().isEmpty()) + addressStrings << address.street(); + if (!address.city().isEmpty()) + addressStrings << address.city(); + + QStringList stateLine; + if (!address.state().isEmpty()) + stateLine << address.state(); + if (!address.postcode().isEmpty()) + stateLine << address.postcode(); + if (!address.country().isEmpty()) + stateLine << address.country(); + + QString stateString = stateLine.join(" "); + + if (!stateString.isEmpty()) + addressStrings << stateString; + + return addressStrings.join(", "); + } + + return QDeclarativeGeoSearchModel::data(index, role); +} + +QVariant QDeclarativeReverseGeocodeModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (section != 0) + return QVariant(); + + if (role == Qt::DisplayRole) + return QString("Address"); + + return QDeclarativeGeoSearchModel::headerData(section, orientation, role); +} + +#include "moc_qdeclarativereversegeocodemodel_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/imports/location/qdeclarativereversegeocodemodel_p.h b/src/imports/location/qdeclarativereversegeocodemodel_p.h new file mode 100644 index 00000000..2ca7c871 --- /dev/null +++ b/src/imports/location/qdeclarativereversegeocodemodel_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEREVERSEGEOCODEMODEL_H +#define QDECLARATIVEREVERSEGEOCODEMODEL_H + +#include "qdeclarativegeosearchmodel_p.h" + +#include "qdeclarativecoordinate_p.h" + +QTM_BEGIN_NAMESPACE + +class QDeclarativeReverseGeocodeModel : public QDeclarativeGeoSearchModel +{ + + Q_OBJECT + + Q_PROPERTY(QDeclarativeCoordinate* coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) + +public: + explicit QDeclarativeReverseGeocodeModel(QObject *parent = 0); + ~QDeclarativeReverseGeocodeModel(); + + void setCoordinate(QDeclarativeCoordinate *coordinate); + QDeclarativeCoordinate* coordinate(); + + // From QDeclarativeParserStatus + virtual void componentComplete(); + + // From QAbstractListModel + virtual QVariant data(const QModelIndex &index, int role) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + +Q_SIGNALS: + void coordinateChanged(QDeclarativeCoordinate *coordinate); + +private: + void update(); + + bool complete_; + QDeclarativeCoordinate coordinate_; +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/imports/location/qmldir b/src/imports/location/qmldir new file mode 100644 index 00000000..077bc7f2 --- /dev/null +++ b/src/imports/location/qmldir @@ -0,0 +1 @@ +plugin declarative_location diff --git a/src/imports/qimportbase.pri b/src/imports/qimportbase.pri new file mode 100644 index 00000000..8647f05c --- /dev/null +++ b/src/imports/qimportbase.pri @@ -0,0 +1,38 @@ +load(qt_module) + +symbian:include($$QT_SOURCE_TREE/src/plugins/qpluginbase.pri) +TEMPLATE = lib +CONFIG += qt plugin + +win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release + +isEmpty(TARGETPATH) { + error("qimportbase.pri: You must provide a TARGETPATH!") +} +isEmpty(TARGET) { + error("qimportbase.pri: You must provide a TARGET!") +} + +QMLDIRFILE = $${_PRO_FILE_PWD_}/qmldir +copy2build.input = QMLDIRFILE +copy2build.output = $$QT.declarative.imports/$$TARGETPATH/qmldir +!contains(TEMPLATE_PREFIX, vc):copy2build.variable_out = PRE_TARGETDEPS +copy2build.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} +copy2build.name = COPY ${QMAKE_FILE_IN} +copy2build.CONFIG += no_link +# `clean' should leave the build in a runnable state, which means it shouldn't delete qmldir +copy2build.CONFIG += no_clean +QMAKE_EXTRA_COMPILERS += copy2build + +TARGET = $$qtLibraryTarget($$TARGET) +contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols + +include($$QT_SOURCE_TREE/src/qt_targets.pri) + +wince*:LIBS += $$QMAKE_LIBS_GUI + +symbian: { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + load(armcc_warnings) +} diff --git a/src/src.pro b/src/src.pro index 5a61a11b..b321da3d 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,3 +1,3 @@ TEMPLATE = subdirs CONFIG+=ordered -SUBDIRS += location plugins +SUBDIRS += location plugins imports |