×
Namespaces

Variants
Actions
(Difference between revisions)

QML Geohelper Plugin

From Nokia Developer Wiki
Jump to: navigation, search
jahartik (Talk | contribs)
(Created page with 'Category:Qt MobilityCategory:Qt Quick __NOTOC__ __NOEDITSECTION__ {{CodeSnippet |id=... |platform=... |devices=... |category=... |subcategory=... |creationdate=... |keywo…')
 
kpakarin (Talk | contribs)
Line 19: Line 19:
 
==Overview==
 
==Overview==
  
{{Abstract|An abstract (line or paragraph) describing very briefly what the article delivers - for example "This article defines the standard boilerplate text for a new code example"}}
+
Geohelper plugin to expose Qt mobility location geoservice apis to Qml environment
 
+
''Delete the texts that do not apply.''
+
  
 
This snippet can be self-signed.
 
This snippet can be self-signed.
  
[or]
+
==Preconditions==
  
This snippet requires XXX capabilities. Self-signing is not possible because a Developer Certificate is needed.
+
Qt 4.7.1 or newer and Qt mobility 1.1.0 or newer installed
  
[or]
+
==Pro file (optional)==
  
This snippets requires XXX capabilities. Self-signing is not possible because a Developer Certificate, Publisher ID, and device manufacturer approval are required.
+
The following capabilities and libraries are required:
  
 +
CAPABILITY:
 +
symbian:TARGET.CAPABILITY = NetworkServices Location ReadUserData WriteUserData
  
==Preconditions==
+
==Header file==
  
''In complex cases you may need to provide information on the framework needed in order to implement and use the code snippet. For example, a Bluetooth connection must be established in order to use the code snippet "send a file via Bluetooth OBEX". You can refer to an already existing code example.''
+
geohelper.h applying this macro to definitions of member functions to allow them to be invoked via the meta-object system
  
 +
<code>
  
==MMP file (optional)==
+
#ifndef GEOHELPER_H
 +
#define GEOHELPER_H
  
The following capabilities and libraries are required:
+
#include <QObject>
 +
#include <QMap>
  
CAPABILITY     
+
#include <QGeoServiceProvider>
 +
#include <QGeoMappingManager>
 +
#include <QGeoSearchManager>
 +
#include <QGeoRoutingManager>
  
 +
#include <QDeclarativeEngine>
 +
#include <QGeoRouteReply>
 +
#include <QGeoRouteRequest>
  
LIBRARY         
+
#include <QGeoCoordinate>
  
LIBRARY        
+
#include <QDeclarativeItem>
 +
#include <QGeoMapPolylineObject>
 +
#include <QGeoMapPixmapObject>
 +
#include <QGeoMapTextObject>
  
<code> code </code>
 
  
==Header file==
+
QTM_USE_NAMESPACE
 +
 
 +
 
 +
class GeoHelper : public QObject
 +
{
 +
    Q_OBJECT
 +
    Q_PROPERTY(QDeclarativeItem* map READ map WRITE setMap)
 +
public:
 +
    explicit GeoHelper(QObject *parent = 0);
 +
    ~GeoHelper();
 +
 
 +
    QDeclarativeItem *map() const {return mapitem; }
 +
    void setMap(QDeclarativeItem *map) { mapitem = map; listRef = QDeclarativeListReference(mapitem, "objects");};
 +
 
 +
    Q_INVOKABLE void findRoute(double fromLatitude, double fromLongitude, double toLatitude, double toLongitude);
 +
    Q_INVOKABLE void findAddress(double latitude, double longitude);
 +
    Q_INVOKABLE void findCoordinates(QString street, QString city, QString country = QString("FINLAND"));
 +
    Q_INVOKABLE void clearMap();
 +
    Q_INVOKABLE void removeFromMap(QString id);
 +
    Q_INVOKABLE void drawPolyline(QString id, QString coordinateArr);
 +
    Q_INVOKABLE void drawImage(QString id, double latitude, double longitude, QString imagepath, int xOffset, int yOffset);
 +
    Q_INVOKABLE void drawText(QString id, double latitude, double longitude, QString text);
 +
    Q_INVOKABLE void findObjectsInCoordinates(double latitude, double longitude);
 +
 
 +
 
 +
signals:
 +
    void searchError(const QString &error);
 +
    void routingError(const QString &error);
 +
 
 +
    void searchReply(const QString &reply);
 +
    void routingReply(const QString &reply);
 +
 
 +
    void geomapobjectSelected(QString id, bool selected);
 +
 
 +
    void debugMsg(const QString &reply);
 +
 
 +
 
 +
private slots:
 +
    void searchErrorSlot(QGeoSearchReply *reply, QGeoSearchReply::Error error, QString errorString = QString());
 +
    void searchFinishedSlot(QGeoSearchReply *reply);
 +
 
 +
    void routingErrorSlot(QGeoRouteReply *reply, QGeoRouteReply::Error error, QString errorString);
 +
    void routingFinishedSlot(QGeoRouteReply * reply);
 +
 
 +
 
 +
 
 +
private:
 +
 
 +
    QGeoServiceProvider* provider;
 +
    QGeoMappingManager* mappingManager;
 +
    QGeoSearchManager* searchManager;
 +
    QGeoRoutingManager* routingManager;
 +
    QDeclarativeContext* context;
 +
    QDeclarativeItem* mapitem;
 +
 
 +
 
 +
    QMap<QString, QGeoMapObject *> mapobjects;
 +
    QDeclarativeListReference listRef;
 +
 
 +
};
  
''Not the complete file but relevant code blocks.''
+
#endif // GEOHELPER_H
  
<code> code </code>  
+
</code>  
  
  

Revision as of 12:01, 29 April 2011


Article Metadata
Tested with
Devices(s): ...
Compatibility
Platform(s): ...
Symbian
Article
Keywords: ...
Created: (21 Apr 2014)
Last edited: kpakarin (29 Apr 2011)



Delete the guidance text written in italics.

Overview

Geohelper plugin to expose Qt mobility location geoservice apis to Qml environment

This snippet can be self-signed.

Preconditions

Qt 4.7.1 or newer and Qt mobility 1.1.0 or newer installed

Pro file (optional)

The following capabilities and libraries are required:

CAPABILITY: symbian:TARGET.CAPABILITY = NetworkServices Location ReadUserData WriteUserData

Header file

geohelper.h applying this macro to definitions of member functions to allow them to be invoked via the meta-object system

#ifndef GEOHELPER_H
#define GEOHELPER_H
 
#include <QObject>
#include <QMap>
 
#include <QGeoServiceProvider>
#include <QGeoMappingManager>
#include <QGeoSearchManager>
#include <QGeoRoutingManager>
 
#include <QDeclarativeEngine>
#include <QGeoRouteReply>
#include <QGeoRouteRequest>
 
#include <QGeoCoordinate>
 
#include <QDeclarativeItem>
#include <QGeoMapPolylineObject>
#include <QGeoMapPixmapObject>
#include <QGeoMapTextObject>
 
 
QTM_USE_NAMESPACE
 
 
class GeoHelper : public QObject
{
Q_OBJECT
Q_PROPERTY(QDeclarativeItem* map READ map WRITE setMap)
public:
explicit GeoHelper(QObject *parent = 0);
~GeoHelper();
 
QDeclarativeItem *map() const {return mapitem; }
void setMap(QDeclarativeItem *map) { mapitem = map; listRef = QDeclarativeListReference(mapitem, "objects");};
 
Q_INVOKABLE void findRoute(double fromLatitude, double fromLongitude, double toLatitude, double toLongitude);
Q_INVOKABLE void findAddress(double latitude, double longitude);
Q_INVOKABLE void findCoordinates(QString street, QString city, QString country = QString("FINLAND"));
Q_INVOKABLE void clearMap();
Q_INVOKABLE void removeFromMap(QString id);
Q_INVOKABLE void drawPolyline(QString id, QString coordinateArr);
Q_INVOKABLE void drawImage(QString id, double latitude, double longitude, QString imagepath, int xOffset, int yOffset);
Q_INVOKABLE void drawText(QString id, double latitude, double longitude, QString text);
Q_INVOKABLE void findObjectsInCoordinates(double latitude, double longitude);
 
 
signals:
void searchError(const QString &error);
void routingError(const QString &error);
 
void searchReply(const QString &reply);
void routingReply(const QString &reply);
 
void geomapobjectSelected(QString id, bool selected);
 
void debugMsg(const QString &reply);
 
 
private slots:
void searchErrorSlot(QGeoSearchReply *reply, QGeoSearchReply::Error error, QString errorString = QString());
void searchFinishedSlot(QGeoSearchReply *reply);
 
void routingErrorSlot(QGeoRouteReply *reply, QGeoRouteReply::Error error, QString errorString);
void routingFinishedSlot(QGeoRouteReply * reply);
 
 
 
private:
 
QGeoServiceProvider* provider;
QGeoMappingManager* mappingManager;
QGeoSearchManager* searchManager;
QGeoRoutingManager* routingManager;
QDeclarativeContext* context;
QDeclarativeItem* mapitem;
 
 
QMap<QString, QGeoMapObject *> mapobjects;
QDeclarativeListReference listRef;
 
};
 
#endif // GEOHELPER_H


Source file

Not the complete file but relevant code blocks.

You do not need to provide complete error handling but it should be commented as TODO for developers.

 code


Postconditions

Explain what the code snippet is expected to do.


Test application and other attachments (optional)

The attachments should be provided with the visible info page (Categories need to be defined, the attached file must be uploaded to Wiki, and internal Wiki links must be used). Every attachment should have its own page (however, a ZIP package can be used for multiple source code files).

80 page views in the last 30 days.