diff options
author | Casper van Donderen <[email protected]> | 2012-06-01 12:41:13 +0200 |
---|---|---|
committer | Marius Storm-Olsen <[email protected]> | 2012-06-07 14:45:52 +0200 |
commit | 08fa70bb5fb97b07f0e85a83352fefdf10e03800 (patch) | |
tree | 382c5cc10c622ddf08dbf47c5801c23d94cf5040 /GeoServicesExample | |
parent | 073c4e7ae33c64105f87f0362e915b480a23091a (diff) |
Diffstat (limited to 'GeoServicesExample')
18 files changed, 1234 insertions, 0 deletions
diff --git a/GeoServicesExample/README.txt b/GeoServicesExample/README.txt new file mode 100644 index 0000000..142d376 --- /dev/null +++ b/GeoServicesExample/README.txt @@ -0,0 +1,68 @@ +Different Views of the World Examples +===================================== + +The C++ versions of these examples can be built using the qmake project +files supplied. The plugins built by the osmplugin and mapimageplugin +project files should be installed in the plugins/geoservices directory +in your Qt installation. The project files provide installation rules +for this that can be invoked with "make install" or similar. + +The mapimageplugin example requires a map.jpg file to be installed in +the mapimageplugin/files directory before it can be built. + +The Python version of the services example has been tested with PyQt 4.8 +and PyQtMobility 1.0. + +About Qt Quarterly +================== + +Qt Quarterly is a newsletter available to Qt developers. Every quarter we +aim to publish an issue that we hope will bring added insight and pleasure +to your Qt programming, with high-quality technical articles written by Qt +experts. + +See http://doc.qt.nokia.com/qq for more information. + +License Information +=================== + +The examples contained in this package is provided under the following +license: + + Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + All rights reserved. + Contact: Nokia Corporation ([email protected]) + + This file is part of the documentation of Qt. It was originally + published as part of Qt Quarterly. + + $QT_BEGIN_LICENSE:LGPL$ + Commercial Usage + Licensees holding valid Qt Commercial licenses may use this file in + accordance with the Qt Commercial License Agreement provided with the + Software or, alternatively, in accordance with the terms contained in + a written agreement between you and Nokia. + + 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. + + GNU General Public License Usage + Alternatively, this file may be used under the terms of the GNU + General Public License version 3.0 as published by the Free Software + Foundation and appearing in the file LICENSE.GPL included in the + packaging of this file. Please review the following information to + ensure the GNU General Public License version 3.0 requirements will be + met: http://www.gnu.org/copyleft/gpl.html. + + If you have questions regarding the use of this file, please contact + Nokia at [email protected]. + $QT_END_LICENSE$ diff --git a/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.cpp b/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.cpp new file mode 100644 index 0000000..be58236 --- /dev/null +++ b/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "imggeomappingmanagerengine.h" +#include "imggeotiledmapdata.h" + +MapImageGeoMappingManagerEngine::MapImageGeoMappingManagerEngine( + const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, QString *errorString) +: QGeoTiledMappingManagerEngine(parameters) +{ + Q_UNUSED(error) + Q_UNUSED(errorString) + Q_UNUSED(parameters) + + setTileSize(QSize(256, 256)); + setMinimumZoomLevel(0.0); + setMaximumZoomLevel(4.0); + + QList<QGraphicsGeoMap::MapType> types; + types << QGraphicsGeoMap::SatelliteMapDay; + setSupportedMapTypes(types); + + QList<QGraphicsGeoMap::ConnectivityMode> modes; + modes << QGraphicsGeoMap::OfflineMode; + setSupportedConnectivityModes(modes); + + sourceImage.load(":files/map.jpg"); +} + +MapImageGeoMappingManagerEngine::~MapImageGeoMappingManagerEngine() +{ +} + +QGeoMapData *MapImageGeoMappingManagerEngine::createMapData() +{ + QGeoMapData *data = new MapImageGeoTiledMapData(this); + if (!data) + return 0; + + data->setConnectivityMode(QGraphicsGeoMap::OnlineMode); + return data; +} + +QGeoTiledMapReply *MapImageGeoMappingManagerEngine::getTileImage(const QGeoTiledMapRequest &request) +{ + // Obtain the relevant part of the source image. + MapImageGeoMapReply *mapReply = new MapImageGeoMapReply(request, sourceImage); + + return mapReply; +} diff --git a/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.h b/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.h new file mode 100644 index 0000000..684633f --- /dev/null +++ b/GeoServicesExample/mapimageplugin/imggeomappingmanagerengine.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMGGEOMAPPINGMANAGERENGINE_H +#define IMGGEOMAPPINGMANAGERENGINE_H + +#include <QGeoServiceProvider> +#include <QGeoTiledMappingManagerEngine> +#include <QGeoTiledMapRequest> +#include <QImage> + +#include "imggeoserviceproviderfactory.h" +#include "imggeomapreply.h" + +class QNetworkAccessManager; +class MapImageGeoMapReply; + +QTM_USE_NAMESPACE + +class MapImageGeoMappingManagerEngine : public QGeoTiledMappingManagerEngine +{ + Q_OBJECT + +public: + MapImageGeoMappingManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString); + ~MapImageGeoMappingManagerEngine(); + + QGeoMapData *createMapData(); + QGeoTiledMapReply *getTileImage(const QGeoTiledMapRequest &request); + +private: + Q_DISABLE_COPY(MapImageGeoMappingManagerEngine) + + QImage sourceImage; +}; + +#endif diff --git a/GeoServicesExample/mapimageplugin/imggeomapreply.cpp b/GeoServicesExample/mapimageplugin/imggeomapreply.cpp new file mode 100644 index 0000000..40940cc --- /dev/null +++ b/GeoServicesExample/mapimageplugin/imggeomapreply.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QBuffer> +#include <QThreadPool> +#include "imggeomapreply.h" +#include "imgrunnable.h" + +MapImageGeoMapReply::MapImageGeoMapReply(const QGeoTiledMapRequest &request, + const QImage &sourceImage, QObject *parent) + : QGeoTiledMapReply(request, parent), + m_sourceImage(sourceImage) +{ + MapImageRunnable *task = new MapImageRunnable(sourceImage, + request.zoomLevel(), request.row(), request.column()); + + connect(task, SIGNAL(finished(QByteArray)), this, SLOT(supplyData(QByteArray))); + QThreadPool::globalInstance()->start(task); +} + +MapImageGeoMapReply::~MapImageGeoMapReply() +{ +} + +void MapImageGeoMapReply::supplyData(QByteArray data) +{ + setMapImageData(data); + setMapImageFormat("PNG"); + setFinished(true); + + emit finished(); +} diff --git a/GeoServicesExample/mapimageplugin/imggeomapreply.h b/GeoServicesExample/mapimageplugin/imggeomapreply.h new file mode 100644 index 0000000..9a23641 --- /dev/null +++ b/GeoServicesExample/mapimageplugin/imggeomapreply.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMGGEOMAPREPLY_H +#define IMGGEOMAPREPLY_H + +#include <QGeoTiledMapRequest> +#include <QGeoTiledMapReply> +#include <QImage> + +QTM_USE_NAMESPACE + +class MapImageGeoMapReply : public QGeoTiledMapReply +{ + Q_OBJECT + +public: + MapImageGeoMapReply(const QGeoTiledMapRequest &request, + const QImage &sourceImage, QObject *parent = 0); + ~MapImageGeoMapReply(); + +signals: + void finished(); + +private slots: + void supplyData(QByteArray); + +private: + QImage m_sourceImage; +}; + +#endif diff --git a/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.cpp b/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.cpp new file mode 100644 index 0000000..4f72577 --- /dev/null +++ b/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "imggeoserviceproviderfactory.h" +#include "imggeomappingmanagerengine.h" + +MapImageGeoServiceProviderFactory::MapImageGeoServiceProviderFactory() {} + +MapImageGeoServiceProviderFactory::~MapImageGeoServiceProviderFactory() {} + +QString MapImageGeoServiceProviderFactory::providerName() const +{ + return QLatin1String("mapimage"); +} + +int MapImageGeoServiceProviderFactory::providerVersion() const +{ + return 1; +} + +QGeoSearchManagerEngine *MapImageGeoServiceProviderFactory::createSearchManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const +{ + Q_UNUSED(error) + Q_UNUSED(errorString) + + return 0; +} + +QGeoMappingManagerEngine *MapImageGeoServiceProviderFactory::createMappingManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const +{ + return new MapImageGeoMappingManagerEngine(parameters, error, errorString); +} + +QGeoRoutingManagerEngine *MapImageGeoServiceProviderFactory::createRoutingManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const +{ + Q_UNUSED(parameters) + Q_UNUSED(error) + Q_UNUSED(errorString) + + return 0; +} + +Q_EXPORT_PLUGIN2(mapimagegeoservices, MapImageGeoServiceProviderFactory) diff --git a/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.h b/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.h new file mode 100644 index 0000000..71c76ed --- /dev/null +++ b/GeoServicesExample/mapimageplugin/imggeoserviceproviderfactory.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMGGEOSERVICEPROVIDERFACTORY_H +#define IMGGEOSERVICEPROVIDERFACTORY_H + +#include <QGeoServiceProviderFactory> +#include <QObject> + +QTM_USE_NAMESPACE + +class MapImageGeoServiceProviderFactory : public QObject, public QGeoServiceProviderFactory +{ + Q_OBJECT + Q_INTERFACES(QtMobility::QGeoServiceProviderFactory) + +public: + MapImageGeoServiceProviderFactory(); + ~MapImageGeoServiceProviderFactory(); + + QString providerName() const; + int providerVersion() const; + + QGeoMappingManagerEngine *createMappingManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; + QGeoRoutingManagerEngine *createRoutingManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; + QGeoSearchManagerEngine *createSearchManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; +}; + +#endif diff --git a/GeoServicesExample/mapimageplugin/imggeotiledmapdata.cpp b/GeoServicesExample/mapimageplugin/imggeotiledmapdata.cpp new file mode 100644 index 0000000..a2d00f5 --- /dev/null +++ b/GeoServicesExample/mapimageplugin/imggeotiledmapdata.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QGeoMappingManagerEngine> +#include <QGeoBoundingBox> +#include <QGeoCoordinate> +#include "imggeotiledmapdata.h" + +MapImageGeoTiledMapData::MapImageGeoTiledMapData(QGeoMappingManagerEngine *engine) : + QGeoTiledMapData(engine) +{ +} + +MapImageGeoTiledMapData::~MapImageGeoTiledMapData() +{ +} + +void MapImageGeoTiledMapData::paintProviderNotices(QPainter *painter, const QStyleOptionGraphicsItem *option) +{ + QRect viewport = painter->combinedTransform().inverted().mapRect(painter->viewport()); + + QLatin1String creditText = QLatin1String("www.mapaplanet.org"); + + QRect maxBoundingRect(QPoint(viewport.left()+10, viewport.top()), QPoint(viewport.right()-5, viewport.bottom()-5)); + QRect textBoundingRect = painter->boundingRect(maxBoundingRect, Qt::AlignLeft | Qt::AlignBottom | Qt::TextWordWrap, creditText); + QRect lastCreditRect = textBoundingRect.adjusted(-2, -1, 2, 1); + + QPixmap lastCredit = QPixmap(lastCreditRect.size()); + lastCredit.fill(QColor(255, 255, 255, 160)); + + QPainter painter2(&lastCredit); + + painter2.setPen(QColor(Qt::black)); + painter2.drawText(QRect(QPoint(2, 1), textBoundingRect.size()), + Qt::TextWordWrap, creditText); + + painter->drawPixmap(lastCreditRect, lastCredit); +} diff --git a/GeoServicesExample/mapimageplugin/imggeotiledmapdata.h b/GeoServicesExample/mapimageplugin/imggeotiledmapdata.h new file mode 100644 index 0000000..3e151cb --- /dev/null +++ b/GeoServicesExample/mapimageplugin/imggeotiledmapdata.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMGGEOMAPDATA_H +#define IMGGEOMAPDATA_H + +#include <QGeoTiledMapData> +#include <QPixmap> + +QTM_USE_NAMESPACE + +class MapImageGeoMappingManagerEngine; + +class MapImageGeoTiledMapData: public QGeoTiledMapData +{ +Q_OBJECT +public: + MapImageGeoTiledMapData(QGeoMappingManagerEngine *engine); + virtual ~MapImageGeoTiledMapData(); + void paintProviderNotices(QPainter *painter, const QStyleOptionGraphicsItem *option); + +private: + Q_DISABLE_COPY(MapImageGeoTiledMapData) +}; + +#endif diff --git a/GeoServicesExample/mapimageplugin/imgrunnable.cpp b/GeoServicesExample/mapimageplugin/imgrunnable.cpp new file mode 100644 index 0000000..04bffcd --- /dev/null +++ b/GeoServicesExample/mapimageplugin/imgrunnable.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QBuffer> +#include "imgrunnable.h" + +MapImageRunnable::MapImageRunnable(const QImage &sourceImage, int zoom, int row, + int column) + : m_sourceImage(sourceImage), m_zoom(zoom), m_row(row), m_column(column) +{ +} + +void MapImageRunnable::run() +{ + // The number of tiles along each axis is 2^zoom. + // zoom is a value from 0 to 4, so the number of tiles are 1 to 16. + int number = 1 << m_zoom; + + // Divide the source image into 2^zoom by 2^zoom tiles. + int tileWidth = m_sourceImage.size().width() / number; + int tileHeight = m_sourceImage.size().height() / number; + + // Calculate the coordinates for the top-left corner of the tile. + int tx = m_column * tileWidth; + int ty = m_row * tileHeight; + + QImage tileImage = m_sourceImage.copy(tx, ty, tileWidth, tileHeight); + QImage scaledImage = tileImage.scaled(256, 256); + + QByteArray data; + QBuffer buffer(&data); + buffer.open(QBuffer::WriteOnly); + scaledImage.save(&buffer, "PNG"); + buffer.close(); + + emit finished(data); +} diff --git a/GeoServicesExample/mapimageplugin/imgrunnable.h b/GeoServicesExample/mapimageplugin/imgrunnable.h new file mode 100644 index 0000000..e5c6fc5 --- /dev/null +++ b/GeoServicesExample/mapimageplugin/imgrunnable.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMGRUNNABLE_H +#define IMGRUNNABLE_H + +#include <QImage> +#include <QObject> +#include <QRunnable> + +class MapImageRunnable : public QObject, public QRunnable +{ + Q_OBJECT + +public: + MapImageRunnable(const QImage &sourceImage, int zoom, int row, int column); + void run(); + +signals: + void finished(QByteArray); + +private: + QImage m_sourceImage; + int m_zoom; + int m_row; + int m_column; +}; + +#endif diff --git a/GeoServicesExample/mapimageplugin/mapimageplugin.pro b/GeoServicesExample/mapimageplugin/mapimageplugin.pro new file mode 100644 index 0000000..13ef0ea --- /dev/null +++ b/GeoServicesExample/mapimageplugin/mapimageplugin.pro @@ -0,0 +1,27 @@ +TEMPLATE = lib +CONFIG += plugin +PLUGIN_TYPE = geoservices +TARGET = mapimagegeoservices + +QT += network + +CONFIG += mobility +MOBILITY = location + +HEADERS = imggeomappingmanagerengine.h \ + imggeomapreply.h \ + imggeoserviceproviderfactory.h \ + imggeotiledmapdata.h \ + imgrunnable.h + +SOURCES = imggeomappingmanagerengine.cpp \ + imggeomapreply.cpp \ + imggeoserviceproviderfactory.cpp \ + imggeotiledmapdata.cpp \ + imgrunnable.cpp + +RESOURCES = mapimageplugin.qrc + +target.path = $$[QT_INSTALL_PLUGINS]/$$PLUGIN_TYPE + +INSTALLS += target diff --git a/GeoServicesExample/mapimageplugin/mapimageplugin.qrc b/GeoServicesExample/mapimageplugin/mapimageplugin.qrc new file mode 100644 index 0000000..733bd55 --- /dev/null +++ b/GeoServicesExample/mapimageplugin/mapimageplugin.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>files/map.jpg</file> +</qresource> +</RCC> diff --git a/GeoServicesExample/services/main.cpp b/GeoServicesExample/services/main.cpp new file mode 100644 index 0000000..2553a4f --- /dev/null +++ b/GeoServicesExample/services/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include "mapwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MapWindow window; + window.show(); + return app.exec(); +} diff --git a/GeoServicesExample/services/mapwindow.cpp b/GeoServicesExample/services/mapwindow.cpp new file mode 100644 index 0000000..c32a5e8 --- /dev/null +++ b/GeoServicesExample/services/mapwindow.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include <QGeoCoordinate> +#include <QGeoMappingManagerEngine> +#include <QGraphicsGeoMap> +#include "mapwindow.h" + +using namespace QtMobility; + +MapWindow::MapWindow() +{ + scene = new QGraphicsScene(this); + + findServices(); + + QGraphicsView *view = new QGraphicsView(this); + view->setScene(scene); + setCentralWidget(view); +} + +void MapWindow::findServices() +{ + QMenu *serviceMenu = menuBar()->addMenu(tr("&Services")); + + actionGroup = new QActionGroup(this); + actionGroup->setExclusive(true); + connect(actionGroup, SIGNAL(triggered(QAction *)), + this, SLOT(selectService(QAction *))); + + foreach (const QString &name, QGeoServiceProvider::availableServiceProviders()) { + + QGeoServiceProvider *service = new QGeoServiceProvider(name); + services[name] = service; + QAction *action = serviceMenu->addAction(name); + action->setCheckable(true); + actionGroup->addAction(action); + } + + if (services.isEmpty()) { + + QGraphicsTextItem *item = scene->addText( + tr("Failed to find any map services. Please ensure that " + "the location services plugins for Qt Mobility have " + "been built and, if necessary, set the QT_PLUGIN_PATH " + "environment variable to the location of the Qt Mobility " + "plugins directory.")); + item->setTextWidth(300); + QAction *action = serviceMenu->addAction(tr("No services")); + action->setEnabled(false); + } else + actionGroup->actions()[0]->trigger(); +} + +void MapWindow::selectService(QAction *action) +{ + action->setChecked(true); + QString name = action->text(); + + scene->clear(); + + QGeoServiceProvider *service = services[name]; + if (service->error() != QGeoServiceProvider::NoError) { + + QGraphicsTextItem *item = scene->addText( + tr("The \"%1\" service failed with the following error:\n'" + "%2").arg(name).arg(service->errorString())); + item->setTextWidth(300); + } else { + QGeoMappingManager *manager = service->mappingManager(); + QGraphicsGeoMap *geoMap = new QGraphicsGeoMap(manager); + scene->addItem(geoMap); + + geoMap->resize(300, 300); + geoMap->setCenter(QGeoCoordinate(37.76, -25.675)); + geoMap->setMapType(QGraphicsGeoMap::TerrainMap); + geoMap->setZoomLevel(12); + } +} diff --git a/GeoServicesExample/services/mapwindow.h b/GeoServicesExample/services/mapwindow.h new file mode 100644 index 0000000..9a6ca0c --- /dev/null +++ b/GeoServicesExample/services/mapwindow.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation ([email protected]) +** +** This file is part of the documentation of Qt. It was originally +** published as part of Qt Quarterly. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you have questions regarding the use of this file, please contact +** Nokia at [email protected]. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAPWINDOW_H +#define MAPWINDOW_H + +#include <QGeoServiceProvider> +#include <QHash> +#include <QMainWindow> + +using namespace QtMobility; + +class QActionGroup; +class QGraphicsScene; + +class MapWindow : public QMainWindow +{ + Q_OBJECT + +public: + MapWindow(); + +private slots: + void selectService(QAction *action); + +private: + void findServices(); + + QActionGroup *actionGroup; + QGraphicsScene *scene; + QHash<QString, QGeoServiceProvider *> services; +}; + +#endif diff --git a/GeoServicesExample/services/services.pro b/GeoServicesExample/services/services.pro new file mode 100644 index 0000000..13288a5 --- /dev/null +++ b/GeoServicesExample/services/services.pro @@ -0,0 +1,6 @@ +HEADERS = mapwindow.h +SOURCES = main.cpp \ + mapwindow.cpp +QT += network +CONFIG += mobility +MOBILITY = location diff --git a/GeoServicesExample/services/services.py b/GeoServicesExample/services/services.py new file mode 100755 index 0000000..4812f20 --- /dev/null +++ b/GeoServicesExample/services/services.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python + +############################################################################# +## +## Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +## All rights reserved. +## Contact: Nokia Corporation ([email protected]) +## +## This file is part of the documentation of Qt. It was originally +## published as part of Qt Quarterly. +## +## $QT_BEGIN_LICENSE:LGPL$ +## Commercial Usage +## Licensees holding valid Qt Commercial licenses may use this file in +## accordance with the Qt Commercial License Agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Nokia. +## +## 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. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3.0 as published by the Free Software +## Foundation and appearing in the file LICENSE.GPL included in the +## packaging of this file. Please review the following information to +## ensure the GNU General Public License version 3.0 requirements will be +## met: http://www.gnu.org/copyleft/gpl.html. +## +## If you have questions regarding the use of this file, please contact +## Nokia at [email protected]. +## $QT_END_LICENSE$ +## +############################################################################# + +import sys + +from PyQt4.QtGui import QActionGroup, QApplication, QGraphicsScene, QGraphicsView, QMainWindow +from PyQt4.QtMobility.QtLocation import * + +class MapWindow(QMainWindow): + + def __init__(self): + + QMainWindow.__init__(self) + + self.scene = QGraphicsScene() + + self.findServices() + + view = QGraphicsView() + view.setScene(self.scene) + self.setCentralWidget(view) + + def findServices(self): + + serviceMenu = self.menuBar().addMenu(self.tr("&Services")) + + self.services = {} + self.actionGroup = QActionGroup(self) + self.actionGroup.setExclusive(True) + self.actionGroup.triggered.connect(self.selectService) + + for name in QGeoServiceProvider.availableServiceProviders(): + + service = QGeoServiceProvider(name) + self.services[name] = service + action = serviceMenu.addAction(name) + action.setCheckable(True) + self.actionGroup.addAction(action) + + if not self.services: + + item = self.scene.addText( + self.tr("Failed to find any map services. Please ensure that " + "the location services plugins for Qt Mobility have " + "been built and, if necessary, set the QT_PLUGIN_PATH " + "environment variable to the location of the Qt Mobility " + "plugins directory.")) + item.setTextWidth(300) + action = serviceMenu.addAction(self.tr("No services")) + action.setEnabled(False) + else: + self.actionGroup.actions()[0].trigger() + + def selectService(self, action): + + action.setChecked(True) + name = action.text() + + self.scene.clear() + + service = self.services[name] + if service.error() != service.NoError: + + item = self.scene.addText( + self.tr('The "%1" service failed with the following error:\n' + "%2").arg(name).arg(service.errorString())) + item.setTextWidth(300) + + else: + self.manager = service.mappingManager() + self.geoMap = QGraphicsGeoMap(self.manager) + self.scene.addItem(self.geoMap) + + self.geoMap.resize(300, 300) + self.geoMap.setCenter(QGeoCoordinate(37.76, -25.675)) + self.geoMap.setMapType(self.geoMap.TerrainMap) + self.geoMap.setZoomLevel(12) + + +if __name__ == "__main__": + + app = QApplication(sys.argv) + window = MapWindow() + window.show() + sys.exit(app.exec_()) |