geohelper.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /********************************************************************************************
  2. ** Copyright © 2011 Nokia Corporation. All rights reserved.
  3. ** Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
  4. ** Java and all Java-based marks are trademarks or registered trademarks of
  5. ** Sun Microsystems, Inc. Other product and company names mentioned herein may be
  6. ** trademarks or trade names of their respective owners.
  7. **
  8. ** Subject to the conditions below, you may, without charge:
  9. **
  10. ** · Use, copy, modify and/or merge copies of this software and
  11. ** associated content and documentation files (the “Software”)
  12. **
  13. ** · Publish, distribute, sub-licence and/or sell new software
  14. ** derived from or incorporating the Software.
  15. **
  16. ** Some of the documentation, content and/or software maybe licensed under open source
  17. ** software or other licenses. To the extent such documentation, content and/or
  18. ** software are included, licenses and/or other terms and conditions shall apply
  19. ** in addition and/or instead of this notice. The exact terms of the licenses, disclaimers,
  20. ** acknowledgements and notices are reproduced in the materials provided.
  21. **
  22. ** This file, unmodified, shall be included with all copies or substantial portions
  23. ** of the Software that are distributed in source code form.
  24. **
  25. ** The Software cannot constitute the primary value of any new software derived
  26. ** from or incorporating the Software.
  27. **
  28. ** Any person dealing with the Software shall not misrepresent the source of the Software.
  29. **
  30. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  31. ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  32. ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  33. ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  34. ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  35. ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  36. ********************************************************************************************/
  37. #ifndef GEOHELPER_H
  38. #define GEOHELPER_H
  39. #include <QObject>
  40. #include <QMap>
  41. #include <QGeoServiceProvider>
  42. #include <QGeoMappingManager>
  43. #include <QGeoSearchManager>
  44. #include <QGeoRoutingManager>
  45. #include <QDeclarativeEngine>
  46. #include <QGeoRouteReply>
  47. #include <QGeoRouteRequest>
  48. #include <QGeoCoordinate>
  49. #include <QDeclarativeItem>
  50. #include <QGeoMapPolylineObject>
  51. #include <QGeoMapPixmapObject>
  52. #include <QGeoMapTextObject>
  53. QTM_USE_NAMESPACE
  54. class GeoHelper : public QObject
  55. {
  56. Q_OBJECT
  57. Q_PROPERTY(QDeclarativeItem* map READ map WRITE setMap)
  58. public:
  59. explicit GeoHelper(QObject *parent = 0);
  60. ~GeoHelper();
  61. QDeclarativeItem *map() const {return mapitem; }
  62. void setMap(QDeclarativeItem *map) { mapitem = map; listRef = QDeclarativeListReference(mapitem, "objects");};
  63. Q_INVOKABLE void findRoute(double fromLatitude, double fromLongitude, double toLatitude, double toLongitude);
  64. Q_INVOKABLE void findAddress(double latitude, double longitude);
  65. Q_INVOKABLE void findCoordinates(QString street, QString city, QString country = QString("FINLAND"));
  66. Q_INVOKABLE void clearMap();
  67. Q_INVOKABLE void removeFromMap(QString id);
  68. Q_INVOKABLE void drawPolyline(QString id, QString coordinateArr);
  69. Q_INVOKABLE void drawImage(QString id, double latitude, double longitude, QString imagepath, int xOffset, int yOffset);
  70. Q_INVOKABLE void drawText(QString id, double latitude, double longitude, QString text);
  71. Q_INVOKABLE void findObjectsInCoordinates(double latitude, double longitude);
  72. signals:
  73. void searchError(const QString &error);
  74. void routingError(const QString &error);
  75. void searchReply(const QString &reply);
  76. void routingReply(const QString &reply);
  77. void geomapobjectSelected(QString id, bool selected);
  78. void debugMsg(const QString &reply);
  79. private slots:
  80. void searchErrorSlot(QGeoSearchReply *reply, QGeoSearchReply::Error error, QString errorString = QString());
  81. void searchFinishedSlot(QGeoSearchReply *reply);
  82. void routingErrorSlot(QGeoRouteReply *reply, QGeoRouteReply::Error error, QString errorString);
  83. void routingFinishedSlot(QGeoRouteReply * reply);
  84. private:
  85. QGeoServiceProvider* provider;
  86. QGeoMappingManager* mappingManager;
  87. QGeoSearchManager* searchManager;
  88. QGeoRoutingManager* routingManager;
  89. QDeclarativeContext* context;
  90. QDeclarativeItem* mapitem;
  91. QMap<QString, QGeoMapObject *> mapobjects;
  92. QDeclarativeListReference listRef;
  93. };
  94. #endif // GEOHELPER_H