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/mapimageplugin | |
parent | 073c4e7ae33c64105f87f0362e915b480a23091a (diff) |
Diffstat (limited to 'GeoServicesExample/mapimageplugin')
12 files changed, 790 insertions, 0 deletions
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> |