diff options
Diffstat (limited to 'src/location/mapsgl')
28 files changed, 0 insertions, 5383 deletions
diff --git a/src/location/mapsgl/cameradata.cpp b/src/location/mapsgl/cameradata.cpp deleted file mode 100644 index 619c8250..00000000 --- a/src/location/mapsgl/cameradata.cpp +++ /dev/null @@ -1,293 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "cameradata.h" - -#include "projection_p.h" - -#include <QVariant> -#include <QVariantAnimation> - -#include <QMetaType> - -#include <QWeakPointer> - -#include <cmath> - -QT_BEGIN_NAMESPACE - -class CameraDataPrivate : public QSharedData -{ -public: - CameraDataPrivate(); - CameraDataPrivate(const CameraDataPrivate &rhs); - - CameraDataPrivate& operator = (const CameraDataPrivate &rhs); - - bool operator == (const CameraDataPrivate &rhs) const; - - QGeoCoordinate center_; - double distance_; - double bearing_; - double tilt_; - double roll_; - double aspectRatio_; - int zoomLevel_; - double zoomFactor_; - - QWeakPointer<Projection> projection_; -}; - -CameraDataPrivate::CameraDataPrivate() - : QSharedData(), - center_(-27.5, 153), - distance_(0.02), - bearing_(0.0), - tilt_(0.0), - roll_(0.0), - aspectRatio_(1.0), - zoomLevel_(9) {} - -CameraDataPrivate::CameraDataPrivate(const CameraDataPrivate &rhs) - : QSharedData(rhs), - center_(rhs.center_), - distance_(rhs.distance_), - bearing_(rhs.bearing_), - tilt_(rhs.tilt_), - roll_(rhs.roll_), - aspectRatio_(rhs.aspectRatio_), - zoomLevel_(rhs.zoomLevel_), - zoomFactor_(rhs.zoomFactor_), - projection_(rhs.projection_) {} - -CameraDataPrivate& CameraDataPrivate::operator = (const CameraDataPrivate &rhs) -{ - center_ = rhs.center_; - distance_ = rhs.distance_; - bearing_ = rhs.bearing_; - tilt_ = rhs.tilt_; - roll_ = rhs.roll_; - aspectRatio_ = rhs.aspectRatio_; - zoomLevel_ = rhs.zoomLevel_; - zoomFactor_ = rhs.zoomFactor_; - QSharedPointer<Projection> p = rhs.projection_.toStrongRef(); - if (p) - projection_ = p.toWeakRef(); - else - projection_.clear(); - - return *this; -} - -bool CameraDataPrivate::operator == (const CameraDataPrivate &rhs) const -{ - return ((center_ == rhs.center_) - && (distance_ == rhs.distance_) - && (bearing_ == rhs.bearing_) - && (tilt_ == rhs.tilt_) - && (roll_ == rhs.roll_) - && (aspectRatio_ == rhs.aspectRatio_) - && (zoomLevel_ == rhs.zoomLevel_) - && (zoomFactor_ == rhs.zoomFactor_)); -} - -QVariant cameraInterpolator(const CameraData &start, - const CameraData &end, - qreal progress) -{ - CameraData result = start; - - - QSharedPointer<Projection> p = start.projection(); - if (!p) - p = end.projection(); - - if (!p) - result.setCenter(start.center()); - else - result.setCenter(p->interpolate(start.center(), end.center(), progress)); - - double sf = 1.0 - progress; - double ef = progress; - - result.setBearing(sf * start.bearing() + ef * end.bearing()); - result.setTilt(sf * start.tilt() + ef * end.tilt()); - result.setRoll(sf * start.roll() + ef * end.roll()); - result.setZoomFactor(sf * start.zoomFactor() + ef * end.zoomFactor()); - - return QVariant::fromValue(result); -} - -CameraData::CameraData() - : d(new CameraDataPrivate()) -{ - qRegisterMetaType<CameraData>(); - qRegisterAnimationInterpolator<CameraData>(cameraInterpolator); - setZoomFactor(4.0); -} - -CameraData::CameraData(const CameraData &other) - : d(other.d) {} - -CameraData::~CameraData() -{ -} - -CameraData& CameraData::operator = (const CameraData &other) -{ - d = other.d; - return *this; -} - -bool CameraData::operator == (const CameraData &rhs) const -{ - return (*(d.constData()) == *(rhs.d.constData())); -} - -bool CameraData::operator != (const CameraData &other) const -{ - return !(operator==(other)); -} - -void CameraData::setCenter(const QGeoCoordinate ¢er) -{ - d->center_ = center; -} - -QGeoCoordinate CameraData::center() const -{ - return d->center_; -} - -void CameraData::setBearing(double bearing) -{ - d->bearing_ = bearing; -} - -double CameraData::bearing() const -{ - return d->bearing_; -} - -void CameraData::setTilt(double tilt) -{ - d->tilt_ = tilt; -} - -double CameraData::tilt() const -{ - return d->tilt_; -} - -void CameraData::setRoll(double roll) -{ - d->roll_ = roll; -} - -double CameraData::roll() const -{ - return d->roll_; -} - -void CameraData::setAspectRatio(double aspectRatio) -{ - d->aspectRatio_ = aspectRatio; -} - -double CameraData::aspectRatio() const -{ - return d->aspectRatio_; -} - -/* - Distance and zoomLevel are only writeable for debugging purposes. - The setters will eventually go away and then zoomFactor will be - the way to set these. -*/ - -void CameraData::setDistance(double distance) -{ - d->zoomFactor_ = -1.0 * log(distance) / log(2.0); - d->distance_ = distance; -} - -double CameraData::distance() const -{ - return d->distance_; -} - -void CameraData::setZoomLevel(int zoomLevel) -{ - d->zoomLevel_ = zoomLevel; -} - -int CameraData::zoomLevel() const -{ - return d->zoomLevel_; -} - -void CameraData::setZoomFactor(double zoomFactor) -{ - d->zoomLevel_ = floor(zoomFactor); -// qDebug() << __FUNCTION__ << zoomFactor << d->zoomLevel_; - - // FIXME this will need some tuning - - d->distance_ = 1.0 / pow(2.0, zoomFactor); - - d->zoomFactor_ = zoomFactor; -} - -double CameraData::zoomFactor() const -{ - return d->zoomFactor_; -} - -void CameraData::setProjection(QSharedPointer<Projection> projection) -{ - d->projection_ = projection.toWeakRef(); -} - -QSharedPointer<Projection> CameraData::projection() const -{ - return d->projection_.toStrongRef(); -} - -QT_END_NAMESPACE diff --git a/src/location/mapsgl/cameradata.h b/src/location/mapsgl/cameradata.h deleted file mode 100644 index a735a24f..00000000 --- a/src/location/mapsgl/cameradata.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef CAMERADATA_H -#define CAMERADATA_H - -#include "qgeocoordinate.h" -#include "projection_p.h" - -#include <QMetaType> - -#include <QSharedPointer> -#include <QSharedDataPointer> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class CameraDataPrivate; - -class Q_LOCATION_EXPORT CameraData -{ -public: - CameraData(); - CameraData(const CameraData &other); - ~CameraData(); - - CameraData& operator = (const CameraData &other); - - bool operator == (const CameraData &other) const; - bool operator != (const CameraData &other) const; - - void setCenter(const QGeoCoordinate &coordinate); - QGeoCoordinate center() const; - - void setBearing(double bearing); - double bearing() const; - - void setTilt(double tilt); - double tilt() const; - - void setRoll(double roll); - double roll() const; - - void setAspectRatio(double aspectRatio); - double aspectRatio() const; - - void setDistance(double distance); - double distance() const; - - void setZoomLevel(int zoomLevel); - int zoomLevel() const; - - void setZoomFactor(double zoomFactor); - double zoomFactor() const; - - void setProjection(QSharedPointer<Projection> projection); - QSharedPointer<Projection> projection() const; - -private: - QSharedDataPointer<CameraDataPrivate> d; -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(CameraData) - -QT_END_HEADER - -#endif // CAMERADATA_H diff --git a/src/location/mapsgl/frustum.cpp b/src/location/mapsgl/frustum.cpp deleted file mode 100644 index 99ff0fa8..00000000 --- a/src/location/mapsgl/frustum.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "frustum_p.h" - -#include <Qt3D/qglcamera.h> - -#include <cmath> - -Frustum::Frustum() {} - -void Frustum::update(const QGLCamera *camera, double aspectRatio, bool updatePlanes) -{ - if (aspectRatio > 1.0) { - double fov = atan2(camera->viewSize().height() , (2 * camera->nearPlane())); - - hn_ = 2 * tan(fov) * camera->nearPlane(); - wn_ = hn_ * aspectRatio; - - hf_ = 2 * tan(fov) * camera->farPlane(); - wf_ = hf_ * aspectRatio; - } else { - double fov = atan2(camera->viewSize().width() , (2 * camera->nearPlane())); - - wn_ = 2 * tan(fov) * camera->nearPlane(); - hn_ = wn_ / aspectRatio; - - wf_ = 2 * tan(fov) * camera->farPlane(); - hf_ = wf_ / aspectRatio; - } - - QVector3D p = camera->eye(); - QVector3D d = camera->center() - camera->eye(); - d.normalize(); - - QVector3D up = camera->upVector(); - up.normalize(); - - QVector3D right = QVector3D::normal(d, up); - - cf_ = p + d * camera->farPlane(); - tlf_ = cf_ + (up * hf_ / 2) - (right * wf_ / 2); - trf_ = cf_ + (up * hf_ / 2) + (right * wf_ / 2); - blf_ = cf_ - (up * hf_ / 2) - (right * wf_ / 2); - brf_ = cf_ - (up * hf_ / 2) + (right * wf_ / 2); - - cn_ = p + d * camera->nearPlane(); - tln_ = cn_ + (up * hn_ / 2) - (right * wn_ / 2); - trn_ = cn_ + (up * hn_ / 2) + (right * wn_ / 2); - bln_ = cn_ - (up * hn_ / 2) - (right * wn_ / 2); - brn_ = cn_ - (up * hn_ / 2) + (right * wn_ / 2); - - if (!updatePlanes) - return; - - QPlane3D pn = QPlane3D(bln_, tln_, brn_); - pn.setNormal(pn.normal().normalized()); - planeHash_.insert(Frustum::Planes(Frustum::Near), pn); - - QPlane3D pf = QPlane3D(blf_, brf_, tlf_); - pf.setNormal(pf.normal().normalized()); - planeHash_.insert(Frustum::Planes(Frustum::Far), pf); - - QPlane3D pl = QPlane3D(blf_, tlf_, bln_); - pl.setNormal(pl.normal().normalized()); - planeHash_.insert(Frustum::Planes(Frustum::Left), pl); - - QPlane3D pr = QPlane3D(brf_, brn_, trf_); - pr.setNormal(pr.normal().normalized()); - planeHash_.insert(Frustum::Planes(Frustum::Right), pr); - - QPlane3D pt = QPlane3D(tlf_, trf_, tln_); - pt.setNormal(pt.normal().normalized()); - planeHash_.insert(Frustum::Planes(Frustum::Top), pt); - - QPlane3D pb = QPlane3D(blf_, bln_, brf_); - pb.setNormal(pb.normal().normalized()); - planeHash_.insert(Frustum::Planes(Frustum::Bottom), pb); -} - -bool Frustum::contains(const QVector3D ¢er, double radius) const -{ - if (planeHash_.isEmpty()) - return false; - - QHash<Frustum::Planes, QPlane3D>::const_iterator i = planeHash_.constBegin(); - QHash<Frustum::Planes, QPlane3D>::const_iterator end = planeHash_.constEnd(); - - while (i != end) { - if (i.value().distanceTo(center) < -1.0 * radius) - return false; - ++i; - } - - return true; -} - -QPlane3D Frustum::plane(Planes planes) const -{ - return planeHash_.value(planes); -} diff --git a/src/location/mapsgl/frustum_p.h b/src/location/mapsgl/frustum_p.h deleted file mode 100644 index e558b99f..00000000 --- a/src/location/mapsgl/frustum_p.h +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef TILEFRUSTUM_H -#define TILEFRUSTUM_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QVector3D> -#include <QHash> - -#include <Qt3D/qplane3d.h> - -QT_BEGIN_NAMESPACE - -class QGLCamera; - -class Q_AUTOTEST_EXPORT Frustum -{ -public: - enum Plane { - Near = 0x001, - Far = 0x002, - Right = 0x004, - Left = 0x008, - Top = 0x010, - Bottom = 0x020, - TopLeftNear = Top | Left | Near, - TopLeftFar = Top | Left | Far, - TopRightNear = Top | Right | Near, - TopRightFar = Top | Right | Far, - BottomLeftNear = Bottom | Left | Near, - BottomLeftFar = Bottom | Left | Far, - BottomRightNear = Bottom | Right | Near, - BottomRightFar = Bottom | Right | Far - }; - - Q_DECLARE_FLAGS(Planes, Plane) - - Frustum(); - - void update(const QGLCamera *camera, double aspectRatio, bool updatePlanes = false); - - bool contains(const QVector3D ¢er, double radius) const; - - QVector3D topLeftNear() const { - return tln_; - } - QVector3D topLeftFar() const { - return tlf_; - } - QVector3D bottomLeftNear() const { - return bln_; - } - QVector3D bottomLeftFar() const { - return blf_; - } - QVector3D topRightNear() const { - return trn_; - } - QVector3D topRightFar() const { - return trf_; - } - QVector3D bottomRightNear() const { - return brn_; - } - QVector3D bottomRightFar() const { - return brf_; - } - - QPlane3D plane(Planes planes) const; - -private: - double hf_; - double wf_; - QVector3D cf_; - QVector3D tlf_; - QVector3D trf_; - QVector3D blf_; - QVector3D brf_; - - double hn_; - double wn_; - QVector3D cn_; - QVector3D tln_; - QVector3D trn_; - QVector3D bln_; - QVector3D brn_; - - QHash<Planes, QPlane3D> planeHash_; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(Frustum::Planes) - -QT_END_NAMESPACE - -#endif // TILEFRUSTUM_H diff --git a/src/location/mapsgl/map.cpp b/src/location/mapsgl/map.cpp deleted file mode 100644 index 9b168d19..00000000 --- a/src/location/mapsgl/map.cpp +++ /dev/null @@ -1,1357 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "map.h" -#include "map_p.h" - -#include "tilecache.h" -#include "mapsphere_p.h" -#include "projection_p.h" -#include "projection2d_p.h" -#include "tile.h" -#include "mapcontroller.h" - -#include "qgeomappingmanager.h" - -#include <QMutex> -#include <QMap> - -#include <qglscenenode.h> -#include <qgeometrydata.h> -#include <qglbuilder.h> -#include <Qt3D/qglpainter.h> -#include <Qt3D/qgeometrydata.h> -#include <Qt3D/qglbuilder.h> -#include <Qt3D/qglcamera.h> -#include <Qt3D/qglsubsurface.h> - -#include <cmath> - -Map::Map(TileCache *cache, QObject *parent) - : QObject(parent) -{ -// d_ptr = new Map3DPrivate(this, cache, 20000.0); - - // edge is 2^max zoom * 4 - d_ptr = new MapPrivate(this, cache, 20, 256); -} - -Map::~Map() -{ - delete d_ptr; -} - -TileCache* Map::tileCache() -{ - Q_D(Map); - return d->tileCache(); -} - -MapController* Map::mapController() -{ - Q_D(Map); - return d->mapController(); -} - -void Map::setMappingManager(QGeoMappingManager *manager) -{ - Q_D(Map); - d->setMappingManager(manager); -} - -void Map::paintGL(QGLPainter *painter) -{ - Q_D(Map); - d->paintGL(painter); -} - -QGLCamera* Map::glCamera() const -{ - Q_D(const Map); - return d->glCamera(); -} - -void Map::resize(int width, int height) -{ - Q_D(Map); - d->resize(width, height); - - // always emit this signal to trigger items to redraw - emit cameraDataChanged(d->cameraData()); -} - -int Map::width() const -{ - Q_D(const Map); - return d->width(); -} - -int Map::height() const -{ - Q_D(const Map); - return d->height(); -} - -void Map::setCameraData(const CameraData &cameraData) -{ - Q_D(Map); - - if (cameraData == d->cameraData()) - return; - - d->setCameraData(cameraData); - update(); - - emit cameraDataChanged(d->cameraData()); -} - -CameraData Map::cameraData() const -{ - Q_D(const Map); - return d->cameraData(); -} - -void Map::update() -{ - Q_D(Map); - d->update(); - emit updateRequired(); -} - -QGeoCoordinate Map::screenPositionToCoordinate(const QPointF &pos, bool clipToViewport) const -{ - Q_D(const Map); - if (clipToViewport) { - int w = d->width(); - int h = d->height(); - - if ((pos.x() < 0) || (w < pos.x()) || (pos.y() < 0) || (h < pos.y())) - return QGeoCoordinate(); - } - - return d->screenPositionToCoordinate(pos); -} - -QPointF Map::coordinateToScreenPosition(const QGeoCoordinate &coordinate, bool clipToViewport) const -{ - Q_D(const Map); - QPointF pos = d->coordinateToScreenPosition(coordinate); - - if (clipToViewport) { - int w = d->width(); - int h = d->height(); - - if ((pos.x() < 0) || (w < pos.x()) || (pos.y() < 0) || (h < pos.y())) - return QPointF(qQNaN(), qQNaN()); - } - - return pos; -} - -void Map::setActiveMapType(const MapType type) -{ - Q_D(Map); - d->setActiveMapType(type); -} - -const MapType Map::activeMapType() const -{ - Q_D(const Map); - return d->activeMapType(); -} - -//------------------------------------------------------------// - -TileMap::TileMap(int minY, int maxY) - : size(0), - minY(minY), - maxY(maxY), - minX(maxY - minY + 1, -1), - maxX(maxY - minY + 1, -1) -{} - -void TileMap::adjust(int tileX, int tileY) -{ - int index = tileY - minY; - int min = minX.at(index); - int max = maxX.at(index); - - if (min == -1) { - min = tileX; - max = tileX; - minX[index] = min; - maxX[index] = max; - size += 1; - } else { - int oldSize = (max - min); - int min2 = qMin(min, tileX); - if (min2 != min) - minX[index] = min2; - int max2 = qMax(max, tileX); - if (max2 != max) - maxX[index] = max2; - int newSize = (max2 - min2); - size += (newSize - oldSize); - } -} - -IntersectGenerator::IntersectGenerator(const MapPrivate *mp, - double p1, - double p2, - int t1, - int t2, - IntersectGenerator::Axis axis, - int zoomLevel) - : mp_(mp), - axis_(axis), - zoomLevel_(zoomLevel) -{ - if (t1 == t2) { - hasNext_ = false; - return; - } - - bool inc = true; - if (axis_ == IntersectGenerator::XAxis) { - inc = (0 < (p2 - p1)); - } else { - inc = (0 < (p1 - p2)); - } - - step_ = 1; - adjust_ = 0; - if (!inc) { - step_ = -1; - adjust_ = -1; - } - - first_ = p1; - denom_ = p2 - p1; - - current_ = t1; - end_ = t2 + step_; - - hasNext_ = true; - - generateValue(); -} - -bool IntersectGenerator::hasNext() const -{ - return hasNext_; -} - -QPair<double, int> IntersectGenerator::value() const -{ - return value_; -} - -void IntersectGenerator::next() -{ - generateValue(); -} - -void IntersectGenerator::generateValue() -{ - while (current_ != end_) { - double alpha = 0.0; - - if (axis_ == IntersectGenerator::XAxis) { - double x = mp_->tileXIntersectToPoint(zoomLevel_, current_).x(); - alpha = (x - first_) / denom_; - } else { - double y = mp_->tileYIntersectToPoint(zoomLevel_, current_).y(); - alpha = (y - first_) / denom_; - } - - if ((0.0 < alpha) && (alpha < 1.0)) { - value_ = QPair<double,int>(alpha, current_ + adjust_); - current_ += step_; - if (current_ == end_) - hasNext_ = false; - return; - } - current_ += step_; - } - hasNext_ = false; -} - -//------------------------------------------------------------// - -MapPrivate::MapPrivate(Map *parent, TileCache *cache, int maxZoom, int tileSize) - : map_(parent), - cache_(cache), - manager_(0), - controller_(0), - activeMapType_(MapType()), - maxZoom_(maxZoom), - tileSize_(tileSize), - baseHeight_(100.0) -{ - sphere_ = new MapSphere(parent, this, cache); - glCamera_ = new QGLCamera(); - - sideLength_ = pow(2.0, 1.0 * maxZoom_) * tileSize; - - projection_ = QSharedPointer<Projection>(new Projection2D(baseHeight_, sideLength_)); - screenPoly_.resize(4); - screenPoly_[0] = QPointF(0.0, 0.0); - screenPoly_[1] = QPointF(0.0, sideLength_); - screenPoly_[2] = QPointF(sideLength_, sideLength_); - screenPoly_[3] = QPointF(sideLength_, 0.0); - - screenPolyLeft_.resize(4); - screenPolyLeft_[0] = QPointF(0.0, 0.0); - screenPolyLeft_[1] = QPointF(0.0, sideLength_); - screenPolyLeft_[2] = QPointF(sideLength_ / 2.0, sideLength_); - screenPolyLeft_[3] = QPointF(sideLength_ / 2.0, 0.0); - - screenPolyRight_.resize(4); - screenPolyRight_[0] = QPointF(sideLength_ / 2.0, 0.0); - screenPolyRight_[1] = QPointF(sideLength_ / 2.0, sideLength_); - screenPolyRight_[2] = QPointF(sideLength_, sideLength_); - screenPolyRight_[3] = QPointF(sideLength_, 0.0); -} - -MapPrivate::~MapPrivate() -{ - // controller_ is a child of map_, don't need to delete it here - manager_->deregisterMap(map_); - delete sphere_; - delete glCamera_; - // TODO map items are not deallocated! - // However: how to ensure this is done in rendering thread? -} - -TileCache* MapPrivate::tileCache() -{ - return cache_; -} - -QGLSceneNode* MapPrivate::createTileNode(const Tile &tile) -{ - QGLSceneNode* node = createTileSpecNode(tile.tileSpec()); - - QGLMaterial *mat = new QGLMaterial(node); - mat->setTexture(tile.texture()); - node->setEffect(QGL::LitDecalTexture2D); - node->setMaterial(mat); - - return node; -} - -void MapPrivate::setMappingManager(QGeoMappingManager *manager) -{ - if (manager) { - manager->registerMap(map_); - pluginString_ = manager->managerName() + QLatin1String("_") + QString::number(manager->managerVersion()); - sphere_->setMappingManager(manager); - } else { - manager->deregisterMap(map_); - } - manager_ = manager; -} - -MapController* MapPrivate::mapController() -{ - if (!controller_) - controller_ = new MapController(map_, projection_); - return controller_; -} - -QGLCamera* MapPrivate::glCamera() const -{ - return glCamera_; -} - -void MapPrivate::setCameraData(const CameraData &cameraData) -{ - cameraData_ = cameraData; - cameraData_.setAspectRatio(aspectRatio_); - cameraData_.setProjection(projection_.toWeakRef()); - updateGlCamera(glCamera_); - updateFrustum(frustum_); - visibleTiles_ = updateVisibleTiles(); - sphere_->update(visibleTiles_); -} - -CameraData MapPrivate::cameraData() const -{ - return cameraData_; -} - -void MapPrivate::update() -{ - sphere_->update(visibleTiles_); -} - -void MapPrivate::resize(int width, int height) -{ - width_ = width; - height_ = height; - aspectRatio_ = 1.0 * width_ / height_; - setCameraData(cameraData_); -} - -QVector2D MapPrivate::pointToTile(const QVector3D &point, int zoom, bool roundUp) const -{ - QVector2D p = projection_->pointToMercator(point); - - int z = 1 << zoom; - int x = 0; - int y = 0; - - if (p.y() == 1.0) - y = z - 1; - else - y = static_cast<int>(z * p.y()) % z; - - if ((qAbs(p.x()) < 1e-6) || (qAbs(p.x() - 1) < 1e-6)) - if (roundUp) - x = z - 1; - else - x = 0; - else - x = static_cast<int>(z * p.x()) % z; - - return QVector2D(x, y); -} - -QVector3D MapPrivate::tileXIntersectToPoint(int zoomLevel, int x) const -{ - int zpow2 = 1 << zoomLevel; - return projection_->mercatorToPoint(QVector2D(x * 1.0 / zpow2, zpow2 / 2.0)); -} - -QVector3D MapPrivate::tileYIntersectToPoint(int zoomLevel, int y) const -{ - int zpow2 = 1 << zoomLevel; - return projection_->mercatorToPoint(QVector2D(zpow2 / 2.0, y * 1.0 / zpow2)); -} - -int MapPrivate::width() const -{ - return width_; -} - -int MapPrivate::height() const -{ - return height_; -} - -double MapPrivate::aspectRatio() const -{ - return aspectRatio_; -} - -void MapPrivate::setActiveMapType(const MapType type) -{ - activeMapType_ = type; - //TODO: check if this shared - //make it more optimal - //rewrite current specs - QList<TileSpec> temp = visibleTiles_; - visibleTiles_.clear(); - foreach (TileSpec spec,temp) { - spec.setMapId(type.mapId()); - visibleTiles_ << spec; - } - - map_->update(); -} - -const MapType MapPrivate::activeMapType() const -{ - return activeMapType_; -} - -void MapPrivate::tileFetched(const TileSpec &spec) -{ - sphere_->tileFetched(spec); -} - -QRect MapPrivate::specToRect(const TileSpec &tileSpec) const -{ - int geomZoom = tileSpec.zoom(); - int x = tileSpec.x(); - int y = tileSpec.y(); - - int z = 1 << geomZoom; - - bool rightEdge = false; - - double x1 = x * 1.0 / z; - double x2 = ((x + 1) % z) * 1.0 / z; - if (x2 == 0.0) { - x2 = 1.0; - rightEdge = true; - } - double y1 = y * 1.0 / z; - double y2 = (y + 1) * 1.0 / z; - - QVector3D tl = projection_->mercatorToPoint(QVector2D(x1, y1)); - QVector3D tr = projection_->mercatorToPoint(QVector2D(x2, y1)); - QVector3D bl = projection_->mercatorToPoint(QVector2D(x1, y2)); - QVector3D br = projection_->mercatorToPoint(QVector2D(x2, y2)); - - if (rightEdge) { - tr.setX(sideLength_); - br.setX(sideLength_); - } - - return QRect(bl.x(), bl.y(), br.x() - tl.x() - 1, tl.y() - br.y() - 1); -} - -QGLSceneNode* MapPrivate::createTileSpecNode(const TileSpec &tileSpec) -{ - int geomZoom = tileSpec.zoom(); - int tileZoom = geomZoom; - int x = tileSpec.x(); - int y = tileSpec.y(); - - QGLBuilder builder; - - int z = 1 << geomZoom; - - bool rightEdge = false; - - double x1 = x * 1.0 / z; - double x2 = ((x + 1) % z) * 1.0 / z; - if (x2 == 0.0) { - x2 = 1.0; - rightEdge = true; - } - double y1 = y * 1.0 / z; - double y2 = (y + 1) * 1.0 / z; - - QVector3D tl = projection_->mercatorToPoint(QVector2D(x1, y1)); - QVector3D tr = projection_->mercatorToPoint(QVector2D(x2, y1)); - QVector3D bl = projection_->mercatorToPoint(QVector2D(x1, y2)); - QVector3D br = projection_->mercatorToPoint(QVector2D(x2, y2)); - - if (rightEdge) { - tr.setX(sideLength_); - br.setX(sideLength_); - } - - int dz = 1 << (geomZoom - tileZoom); - - int tx1 = x % dz; - int ty1 = y % dz; - - ty1 = dz - ty1; - - int tx2 = (x + 1) % dz; - if (tx2 == 0) - tx2 = dz; - - int ty2 = (y + 1) % dz; - if (ty2 == 0) - ty2 = dz; - - ty2 = dz - ty2; - - QGeometryData g; - - QVector3D n = QVector3D(0, 0, 1); - - g.appendVertex(tl); - g.appendNormal(n); - g.appendTexCoord(QVector2D(tx1 * 1.0 / dz, ty1 * 1.0 / dz)); - - g.appendVertex(bl); - g.appendNormal(n); - g.appendTexCoord(QVector2D(tx1 * 1.0 / dz, ty2 * 1.0 / dz)); - - g.appendVertex(br); - g.appendNormal(n); - g.appendTexCoord(QVector2D(tx2 * 1.0 / dz, ty2 * 1.0 / dz)); - - g.appendVertex(tr); - g.appendNormal(n); - g.appendTexCoord(QVector2D(tx2 * 1.0 / dz, ty1 * 1.0 / dz)); - - builder.addQuads(g); - - return builder.finalizedSceneNode(); -} - -void MapPrivate::paintGL(QGLPainter *painter) -{ - double side = pow(2.0, cameraData_.zoomFactor()) * tileSize_; - double mapWidth = width_ * 1.0; - double mapHeight = height_ * 1.0; - double offsetX = 0.0; - double offsetY = 0.0; - - if (side < mapWidth) { - offsetX = (mapWidth - side) / 2.0; - mapWidth = side; - } - - if (side < mapHeight) { - offsetY = (mapHeight - side) / 2.0; - mapHeight = side; - } - - glEnable(GL_SCISSOR_TEST); - - painter->setScissor(QRect(offsetX, offsetY, mapWidth, mapHeight)); - - QGLCamera *camera = glCamera(); - - bool old = camera->blockSignals(true); - - glDisable(GL_DEPTH_TEST); - - QVector3D c = camera->center(); - c.setX(c.x() + sideLength_); - camera->setCenter(c); - - QVector3D e = camera->eye(); - e.setX(e.x() + sideLength_); - camera->setEye(e); - - painter->setCamera(camera); - painter->projectionMatrix().scale(1, -1, 1); - sphere_->paintGL(painter); - - c.setX(c.x() - 2 * sideLength_); - camera->setCenter(c); - e.setX(e.x() - 2 * sideLength_); - camera->setEye(e); - - painter->setCamera(camera); - painter->projectionMatrix().scale(1, -1, 1); - sphere_->paintGL(painter); - - c.setX(c.x() + sideLength_); - camera->setCenter(c); - e.setX(e.x() + sideLength_); - camera->setEye(e); - - painter->setCamera(camera); - painter->projectionMatrix().scale(1, -1, 1); - sphere_->paintGL(painter); - - glEnable(GL_DEPTH_TEST); - - camera->blockSignals(old); -} - -void MapPrivate::updateGlCamera(QGLCamera* glCamera) -{ - bool old = glCamera->blockSignals(true); - - CameraData camera = cameraData(); - - double f = 1.0 * qMin(width(), height()) / tileSize_; - - double altitude = sideLength_ * camera.distance() * f / 2.0; - - QGeoCoordinate coord = camera.center(); - coord.setAltitude(0.0); - QVector3D center = projection_->coordToPoint(coord); - coord.setAltitude(altitude); - QVector3D eye = projection_->coordToPoint(coord); - -// if (pow(2.0, cameraData_.zoomFactor()) * tileSize_ < height_) { -// center.setY(sideLength_ / 2.0); -// eye.setY(sideLength_ / 2.0); -// } - - QVector3D view = eye - center; - QVector3D side = QVector3D::normal(view, QVector3D(0.0, 1.0, 0.0)); - QVector3D up = QVector3D::normal(side, view); - - QMatrix4x4 mBearing; - mBearing.rotate(-1.0 * camera.bearing(), view); - up = mBearing * up; - - QVector3D side2 = QVector3D::normal(up, view); - QMatrix4x4 mTilt; - mTilt.rotate(camera.tilt(), side2); - eye = (mTilt * view) + center; - - view = eye - center; - side = QVector3D::normal(view, QVector3D(0.0, 1.0, 0.0)); - up = QVector3D::normal(view, side2); - - QMatrix4x4 mRoll; - mRoll.rotate(camera.roll(), view); - up = mRoll * up; - - double nearPlane = 1.0; - double farPlane = 2.0 * altitude; - - glCamera->setCenter(center); - glCamera->setEye(eye); - glCamera->setUpVector(up); - glCamera->setNearPlane(nearPlane); - glCamera->setFarPlane(farPlane); - - glCamera->blockSignals(old); - - // TODO fold into above code if this works for screen <-> coordinate conversions - viewSize_ = glCamera->viewSize(); - eye_ = eye; - projectionMatrix_ = glCamera->projectionMatrix(aspectRatio()) * glCamera->modelViewMatrix(); -} - -QGeoCoordinate MapPrivate::screenPositionToCoordinate(const QPointF &pos) const -{ - double side = pow(2.0, cameraData_.zoomFactor()) * tileSize_; - double mapWidth = width_ * 1.0; - double mapHeight = height_ * 1.0; - double offsetX = 0.0; - double offsetY = 0.0; - - if (side < mapWidth) { - offsetX = (mapWidth - side) / 2.0; - mapWidth = side; - } - - if (side < mapHeight) { - offsetY = (mapHeight - side) / 2.0; - mapHeight = side; - } - - double posX = pos.x() - offsetX; - double posY = pos.y() - offsetY; - - if (posX < 0.0) - return QGeoCoordinate(); - if (mapWidth < posX) - return QGeoCoordinate(); - - if (posY < 0.0) - return QGeoCoordinate(); - if (mapHeight < posY) - return QGeoCoordinate(); - - double w = mapWidth / viewSize_.width(); - double h = mapHeight / viewSize_.height(); - double x = (posX - w) / w; - double y = (posY - h) / h; - - x = (x + 1.0) / 2.0; - y = (y + 1.0) / 2.0; - - QVector3D tl = frustum_.topLeftFar(); - QVector3D tr = frustum_.topRightFar(); - QVector3D bl = frustum_.bottomLeftFar(); - - QVector3D n = (1 - x - y) * tl + x * tr + y * bl; - - if (eye_.z() == n.z()) - return QGeoCoordinate(); - - double alpha = eye_.z() / (eye_.z() - n.z()); - QVector3D c = (1 - alpha) * eye_ + alpha * n; - - return projection_->pointToCoord(c); -} - -QPointF MapPrivate::coordinateToScreenPosition(const QGeoCoordinate &coordinate) const -{ - QVector3D c = projection_->coordToPoint(coordinate); - QVector3D d = projectionMatrix_.map(c); - QPointF point = QPointF((d.x() + 1.0) * width() / 2.0, (-d.y() + 1.0) * height() / 2.0); - - double side = pow(2.0, cameraData_.zoomFactor()) * tileSize_; - double mapWidth = width_ * 1.0; - double offsetX = 0.0; - - if (side < mapWidth) { - offsetX = (mapWidth - side) / 2.0; - mapWidth = side; - - if (point.x() < offsetX) - point.setX(point.x() + mapWidth); - - if (offsetX + mapWidth < point.x()) - point.setX(point.x() - mapWidth); - } - - QPointF altPointRight(point.x() + side, point.y()); - QPointF altPointLeft(point.x() - side, point.y()); - - QPointF ret = point; - qreal minDist = qAbs(point.x() - width_ / 2.0); - qreal dist; - - if ((dist = qAbs(altPointRight.x() - width_ / 2.0)) < minDist) { - ret = altPointRight; - minDist = dist; - } - if ((dist = qAbs(altPointLeft.x() - width_ / 2.0)) < minDist) { - ret = altPointLeft; - minDist = dist; - } - - return ret; -} - -void MapPrivate::updateFrustum(Frustum &frustum) -{ - frustum.update(glCamera(), cameraData().aspectRatio()); -} - -QList<TileSpec> MapPrivate::updateVisibleTiles() -{ - QList<QVector3D> points; - - points.append(pointsOnLineWithZ(frustum_.topLeftNear(), frustum_.topLeftFar(), baseHeight_)); - points.append(pointsOnLineWithZ(frustum_.topRightNear(), frustum_.topRightFar(), baseHeight_)); - points.append(pointsOnLineWithZ(frustum_.bottomLeftNear(), frustum_.bottomLeftFar(), baseHeight_)); - points.append(pointsOnLineWithZ(frustum_.bottomRightNear(), frustum_.bottomRightFar(), baseHeight_)); - - points.append(pointsOnLineWithZ(frustum_.topLeftNear(), frustum_.bottomLeftNear(), baseHeight_)); - points.append(pointsOnLineWithZ(frustum_.bottomLeftNear(), frustum_.bottomRightNear(), baseHeight_)); - points.append(pointsOnLineWithZ(frustum_.bottomRightNear(), frustum_.topRightNear(), baseHeight_)); - points.append(pointsOnLineWithZ(frustum_.topRightNear(), frustum_.topLeftNear(), baseHeight_)); - - points.append(pointsOnLineWithZ(frustum_.topLeftFar(), frustum_.bottomLeftFar(), baseHeight_)); - points.append(pointsOnLineWithZ(frustum_.bottomLeftFar(), frustum_.bottomRightFar(), baseHeight_)); - points.append(pointsOnLineWithZ(frustum_.bottomRightFar(), frustum_.topRightFar(), baseHeight_)); - points.append(pointsOnLineWithZ(frustum_.topRightFar(), frustum_.topLeftFar(), baseHeight_)); - - QList<TileSpec> tiles; - - if (points.isEmpty()) - return tiles; - - // sort points into a right handed polygon - - LengthSorter sorter; - - // - initial sort to remove duplicates - sorter.base = points.first(); - qSort(points.begin(), points.end(), sorter); - for (int i = points.size() - 1; i > 0; --i) { - if (points.at(i) == points.at(i - 1)) - points.removeAt(i); - } - - // - proper sort - // - start with the first point, put it in the sorted part of the list - // - add the nearest unsorted point to the last sorted point to the end - // of the sorted points - QList<QVector3D>::iterator i; - for (i = points.begin(); i != points.end(); ++i) { - sorter.base = *i; - if (i + 1 != points.end()) - qSort(i + 1, points.end(), sorter); - } - - // - determine if what we have is right handed - if (points.size() >= 3) { - QVector3D normal = QVector3D::normal(points.at(1) - points.at(0), - points.at(2) - points.at(1)); - // - if not, reverse the list - if (normal.z() < 0.0) { - int s = points.size(); - int s2 = s / 2; - for (int i = 0; i < s2; ++i) { - points.swap(i, s - 1 - i); - } - } - } - - // work out if the polygon needs clipping - // - if we go off the far right edge we need to clip into - // two regions - one which rounds down now and one which rounds up - // - otherwise if we cross an edge of the map we just need to clip - // to the map square - - bool round = false; - bool clip = false; - for (int i = 0; i < points.size(); ++i) { - QVector3D p = points.at(i); - if (p.x() >= sideLength_) { - round = true; - break; - } - if ((p.x() < 0) - || (sideLength_ < p.x()) - || (p.y() < 0) - || (sideLength_ < p.y())) { - clip = true; - } - } - - if (!round) { - if (!clip) { - tiles.append(tilesFromPoints(points.toVector(), false)); - } else { - QPair<QList<QVector3D>,QList<QVector3D> > pair = clipPolygonToMap(points); - if (!pair.first.isEmpty()) - tiles.append(tilesFromPoints(pair.first.toVector(), true)); - if (!pair.second.isEmpty()) - tiles.append(tilesFromPoints(pair.second.toVector(), false)); - } - } else { - QPair<QList<QVector3D>,QList<QVector3D> > pair = clipPolygonToMap(points); - if (!pair.first.isEmpty()) { - QPair<QList<QVector3D>, QList<QVector3D> > split = splitPolygonX(pair.first, sideLength_ / 2.0); - if (!split.first.isEmpty()) { - tiles.append(tilesFromPoints(split.first.toVector(), false)); - } - if (!split.second.isEmpty()) { - tiles.append(tilesFromPoints(split.second.toVector(), true)); - } - } - if (!pair.second.isEmpty()) { - QPair<QList<QVector3D>, QList<QVector3D> > split = splitPolygonX(pair.second, sideLength_ / 2.0); - if (!split.first.isEmpty()) { - tiles.append(tilesFromPoints(split.first.toVector(), false)); - } - if (!split.second.isEmpty()) { - tiles.append(tilesFromPoints(split.second.toVector(), true)); - } - } - } - - return tiles; -} - -QList<TileSpec> MapPrivate::tilesFromPoints(const QVector<QVector3D> &points, bool roundUp) const -{ - int numPoints = points.size(); - - if (numPoints == 0) - return QList<TileSpec>(); - - int zoomLevel = cameraData().zoomLevel(); - - int minY = -1; - int maxY = -1; - - QVector<QVector2D> tiles(points.size()); - for (int i = 0; i < numPoints; ++i) { - QVector2D t = pointToTile(points.at(i), zoomLevel, roundUp); - if (minY == -1) { - minY = t.y(); - maxY = t.y(); - } else { - minY = qMin(minY, static_cast<int>(t.y())); - maxY = qMax(maxY, static_cast<int>(t.y())); - } - tiles[i] = t; - } - - TileMap map(minY, maxY); - - for (int i1 = 0; i1 < numPoints; ++i1) { - int i2 = (i1 + 1) % numPoints; - tilesFromLine(points.at(i1), points.at(i2), tiles.at(i1), tiles.at(i2), zoomLevel, map); - } - - QList<TileSpec> results; - - results.reserve(map.size); - - int size = map.minX.size(); - for (int i = 0; i < size; ++i) { - int y = map.minY + i; - int minX = map.minX[i]; - int maxX = map.maxX[i]; - for (int x = minX; x <= maxX; ++x) - results << TileSpec(pluginString_, activeMapType().mapId(), zoomLevel, x, y); - } - - return results; -} - -void MapPrivate::tilesFromLine(const QVector3D &p1, - const QVector3D &p2, - const QVector2D &t1, - const QVector2D &t2, - int zoomLevel, - TileMap &map) const -{ - IntersectGenerator xGen = IntersectGenerator(this, p1.x(), p2.x(), t1.x(), t2.x(), - IntersectGenerator::XAxis, zoomLevel); - IntersectGenerator yGen = IntersectGenerator(this, p1.y(), p2.y(), t1.y(), t2.y(), - IntersectGenerator::YAxis, zoomLevel); - - int tileX = t1.x(); - int tileY = t1.y(); - - map.adjust(tileX, tileY); - - while (xGen.hasNext() && yGen.hasNext()) { - QPair<double, int> x = xGen.value(); - QPair<double, int> y = yGen.value(); - if (x.first < y.first) { - tileX = x.second; - map.adjust(tileX, tileY); - xGen.next(); - } else if (x.first > y.first) { - tileY = y.second; - map.adjust(tileX, tileY); - yGen.next(); - } else { - map.adjust(tileX, y.second); - map.adjust(x.second, tileY); - tileX = x.second; - tileY = y.second; - map.adjust(tileX, tileY); - xGen.next(); - yGen.next(); - } - } - - while (xGen.hasNext()) { - tileX = xGen.value().second; - map.adjust(tileX, tileY); - xGen.next(); - } - - while (yGen.hasNext()) { - tileY = yGen.value().second; - map.adjust(tileX, tileY); - yGen.next(); - } -} - -QPair<QList<QVector3D>,QList<QVector3D> > MapPrivate::clipPolygonToMap(const QList<QVector3D> &points) const -{ - bool clipX0 = false; - bool clipX1 = false; - bool clipY0 = false; - bool clipY1 = false; - int size = points.size(); - for (int i = 0; i < size; ++i) { - QVector3D p = points.at(i); - if (p.x() < 0.0) - clipX0 = true; - if (sideLength_ < p.x()) - clipX1 = true; - if (p.y() < 0.0) - clipY0 = true; - if (sideLength_ < p.y()) - clipY1 = true; - - } - - QList<QVector3D> results = points; - - if (clipY0) { - results = splitPolygonY(results, 0.0).second; - } - - if (clipY1) { - results = splitPolygonY(results, sideLength_).first; - } - - if (clipX0) { - if (clipX1) { - results = splitPolygonX(results, 0.0).second; - results = splitPolygonX(results, sideLength_).first; - return QPair<QList<QVector3D>,QList<QVector3D> >(results, QList<QVector3D>()); - } else { - QPair<QList<QVector3D>,QList<QVector3D> > pair = splitPolygonX(results, 0.0); - for (int i = 0; i < pair.first.size(); ++i) { - pair.first[i].setX(pair.first.at(i).x() + sideLength_); - } - return pair; - } - } else { - if (clipX1) { - QPair<QList<QVector3D>,QList<QVector3D> > pair = splitPolygonX(results, sideLength_); - for (int i = 0; i < pair.second.size(); ++i) { - pair.second[i].setX(pair.second.at(i).x() - sideLength_); - } - return pair; - } else { - return QPair<QList<QVector3D>,QList<QVector3D> >(results, QList<QVector3D>()); - } - } -} - -QPair<QList<QVector3D>,QList<QVector3D> > MapPrivate::splitPolygonY(const QList<QVector3D> &points, double y) const -{ - QList<QVector3D> pointsBelow; - QList<QVector3D> pointsAbove; - - int size = points.size(); - - if (size == 0) { - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsBelow, pointsAbove); - } - - bool allAbove = true; - bool allBelow = true; - - for (int i = 0; i < size; ++i) { - double py = points.at(i).y(); - if (py < y) - allAbove = false; - if (y < py) - allBelow = false; - } - - if (allAbove) { - if (allBelow) { - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsBelow, pointsAbove); - } else { - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsBelow, points); - } - } else { - if (allBelow) { - return QPair<QList<QVector3D>,QList<QVector3D> >(points, pointsAbove); - } - } - - - int intersect1 = -1; - int intersect2 = -1; - - // add intersects - - QList<QVector3D> tmpPoints = points; - - for (int i1 = 0; i1 < size; ++i1) { - int i2 = (i1 + 1) % size; - - QVector3D p1 = tmpPoints.at(i1); - QVector3D p2 = tmpPoints.at(i2); - - if (p1.y() == y) { - if (intersect1 == -1) - intersect1 = i1; - else if (intersect2 == -1) - intersect2 = i1; - else - qDebug() << __FUNCTION__ << " more than 2 intersections"; - } - - if (((p1.y() < y) && (y < p2.y())) - || ((p2.y() < y) && (y < p1.y()))) { - QList<QVector3D> newPoints = pointsOnLineWithY(p1, p2, y); - if (newPoints.size() == 1) { - tmpPoints.insert(i1 + 1, newPoints.at(0)); - ++size; - // will get added to intersect1 or intersect 2 in next iteration - } - } - } - - // split at intersects - if ((intersect1 != -1) && (intersect2 != -1)) { - - size = tmpPoints.size(); - - bool firstBelow = true; - - for (int i = intersect1; i <= intersect2; ++i) { - QVector3D p = tmpPoints.at(i); - if (y < p.y()) - firstBelow = false; - pointsBelow.append(p); - } - - for (int i = intersect2; i <= intersect1 + size; ++i) { - pointsAbove.append(tmpPoints.at(i % size)); - } - - if (firstBelow) - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsBelow, pointsAbove); - else - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsAbove, pointsBelow); - - } else { - qDebug() << __FUNCTION__ << " less than 2 intersections"; - } - - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsBelow, pointsAbove); -} - -QPair<QList<QVector3D>,QList<QVector3D> > MapPrivate::splitPolygonX(const QList<QVector3D> &points, double x) const -{ - QList<QVector3D> pointsBelow; - QList<QVector3D> pointsAbove; - - int size = points.size(); - - if (size == 0) { - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsBelow, pointsAbove); - } - - bool allAbove = true; - bool allBelow = true; - - for (int i = 0; i < size; ++i) { - double px = points.at(i).x(); - if (px < x) - allAbove = false; - if (x < px) - allBelow = false; - } - - if (allAbove) { - if (allBelow) { - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsBelow, pointsAbove); - } else { - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsBelow, points); - } - } else { - if (allBelow) { - return QPair<QList<QVector3D>,QList<QVector3D> >(points, pointsAbove); - } - } - - int intersect1 = -1; - int intersect2 = -1; - - // add intersects - - QList<QVector3D> tmpPoints = points; - - for (int i1 = 0; i1 < size; ++i1) { - int i2 = (i1 + 1) % size; - - QVector3D p1 = tmpPoints.at(i1); - QVector3D p2 = tmpPoints.at(i2); - - if (p1.x() == x) { - if (intersect1 == -1) - intersect1 = i1; - else if (intersect2 == -1) - intersect2 = i1; - else - qDebug() << __FUNCTION__ << " more than 2 intersections"; - } - - if (((p1.x() < x) && (x < p2.x())) - || ((p2.x() < x) && (x < p1.x()))) { - QList<QVector3D> newPoints = pointsOnLineWithX(p1, p2, x); - if (newPoints.size() == 1) { - tmpPoints.insert(i1 + 1, newPoints.at(0)); - ++size; - // will get added to intersect1 or intersect 2 in next iteration - } - } - } - - // split at intersects - if ((intersect1 != -1) && (intersect2 != -1)) { - - size = tmpPoints.size(); - - bool firstBelow = true; - - for (int i = intersect1; i <= intersect2; ++i) { - QVector3D p = tmpPoints.at(i); - if (x < p.x()) - firstBelow = false; - pointsBelow.append(p); - } - - for (int i = intersect2; i <= intersect1 + size; ++i) { - pointsAbove.append(tmpPoints.at(i % size)); - } - - if (firstBelow) - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsBelow, pointsAbove); - else - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsAbove, pointsBelow); - - } else { - qDebug() << __FUNCTION__ << " less than 2 intersections"; - } - - return QPair<QList<QVector3D>,QList<QVector3D> >(pointsBelow, pointsAbove); -} - -QList<QVector3D> MapPrivate::pointsOnLineWithX(const QVector3D &p1, const QVector3D &p2, double x) const -{ - QList<QVector3D> results; - - if (p1.x() == p2.x()) { - if (p1.x() == x) { - results.append(p1); - results.append(p2); - } - } else { - double f = (p1.x() - x) / (p1.x() - p2.x()); - if ((0 <= f) && (f <= 1.0)) - results.append((1 - f) * p1 + f * p2); - } - - return results; -} - -QList<QVector3D> MapPrivate::pointsOnLineWithY(const QVector3D &p1, const QVector3D &p2, double y) const -{ - QList<QVector3D> results; - - if (p1.y() == p2.y()) { - if (p1.y() == y) { - results.append(p1); - results.append(p2); - } - } else { - double f = (p1.y() - y) / (p1.y() - p2.y()); - if ((0 <= f) && (f <= 1.0)) - results.append((1 - f) * p1 + f * p2); - } - - return results; -} - -QList<QVector3D> MapPrivate::pointsOnLineWithZ(const QVector3D &p1, const QVector3D &p2, double z) const -{ - QList<QVector3D> results; - - if (p1.z() == p2.z()) { - if (p1.z() == z) { - results.append(p1); - results.append(p2); - } - } else { - double f = (p1.z() - z) / (p1.z() - p2.z()); - if ((0 <= f) && (f <= 1.0)) - results.append((1 - f) * p1 + f * p2); - } - - return results; -} diff --git a/src/location/mapsgl/map.h b/src/location/mapsgl/map.h deleted file mode 100644 index 8b3644e9..00000000 --- a/src/location/mapsgl/map.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef MAP_H -#define MAP_H - -#include <QObject> - -#include "cameradata.h" -#include "maptype.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QGeoCoordinate; - -class QGeoMappingManager; - -class TileCache; -class MapPrivate; -class MapItem; -class MapController; - -class QGLCamera; -class QGLPainter; - -class QPointF; - -class Q_LOCATION_EXPORT Map : public QObject -{ - Q_OBJECT - - Q_PROPERTY(CameraData camera READ cameraData WRITE setCameraData NOTIFY cameraDataChanged) - Q_PROPERTY(MapType activeMapType READ activeMapType WRITE setActiveMapType NOTIFY activeMapTypeChanged) - -public: - Map(TileCache *cache, QObject *parent = 0); - virtual ~Map(); - - TileCache* tileCache(); - - void setMappingManager(QGeoMappingManager *manager); - - MapController* mapController(); - - QGLCamera* glCamera() const; - void paintGL(QGLPainter *painter); - - void resize(int width, int height); - int width() const; - int height() const; - - void setCameraData(const CameraData &cameraData); - CameraData cameraData() const; - - QGeoCoordinate screenPositionToCoordinate(const QPointF &pos, bool clipToViewport = true) const; - QPointF coordinateToScreenPosition(const QGeoCoordinate &coordinate, bool clipToViewport = true) const; - - void setActiveMapType(const MapType mapType); - const MapType activeMapType() const; - -public Q_SLOTS: - void update(); - -Q_SIGNALS: - void updateRequired(); - void cameraDataChanged(const CameraData &cameraData); - void activeMapTypeChanged(); - -private: - MapPrivate *d_ptr; - Q_DECLARE_PRIVATE(Map) - - friend class QGeoMappingManager; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // MAP_H diff --git a/src/location/mapsgl/map_p.h b/src/location/mapsgl/map_p.h deleted file mode 100644 index 989c15ef..00000000 --- a/src/location/mapsgl/map_p.h +++ /dev/null @@ -1,254 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef MAP_P_H -#define MAP_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QList> -#include <QSet> -#include <QVector> -#include <QPair> -#include <QPolygonF> -#include <QSizeF> -#include <QVector3D> -#include <QMatrix4x4> -#include <QString> - -#include "cameradata.h" -#include "frustum_p.h" - -#include "maptype.h" - -#include <QSharedPointer> - -QT_BEGIN_NAMESPACE - -class QGeoMappingManager; - -class Tile; -class TileCache; -class TileSpec; -class Map; -class MapController; -class MapSphere; -class Projection; - -class QGLCamera; -class QGLSceneNode; -class QGLPainter; - -class MapPrivate; - -struct TileMap -{ - TileMap(int minY, int maxY); - - int size; - int minY; - int maxY; - QVector<int> minX; - QVector<int> maxX; - - void adjust(int tileX, int tileY); -}; - -class IntersectGenerator -{ -public: - enum Axis { - XAxis, - YAxis - }; - IntersectGenerator(const MapPrivate *mp, - double p1, - double p2, - int t1, - int t2, - Axis axis, - int zoomLevel); - - bool hasNext() const; - QPair<double, int> value() const; - void next(); - -private: - void generateValue(); - -protected: - const MapPrivate *mp_; - Axis axis_; - int zoomLevel_; - - bool hasNext_; - QPair<double, int> value_; - - int current_; - int step_; - int end_; - - int adjust_; - double first_; - double denom_; -}; - -class MapPrivate -{ -public: - MapPrivate(Map *parent, TileCache *cache, int maxZoom, int tileSize); - virtual ~MapPrivate(); - - TileCache* tileCache(); - - void setMappingManager(QGeoMappingManager *manager); - - MapController* mapController(); - - QGLCamera* glCamera() const; - void paintGL(QGLPainter *painter); - - void setCameraData(const CameraData &cameraData); - CameraData cameraData() const; - - void resize(int width, int height); - int width() const; - int height() const; - double aspectRatio() const; - - QGLSceneNode* createTileSpecNode(const TileSpec &tileSpec); - QGLSceneNode* createTileNode(const Tile &tile); - - QRect specToRect(const TileSpec &tileSpec) const; - - void update(); - - const MapType activeMapType() const; - void setActiveMapType(const MapType mapType); - - QGeoCoordinate screenPositionToCoordinate(const QPointF &pos) const; - QPointF coordinateToScreenPosition(const QGeoCoordinate &coordinate) const; - - QVector2D pointToTile(const QVector3D &point, int zoom, bool roundUp = false) const; - QVector3D tileXIntersectToPoint(int zoomLevel, int x) const; - QVector3D tileYIntersectToPoint(int zoomLevel, int y) const; - - void tileFetched(const TileSpec &spec); - -private: - void updateGlCamera(QGLCamera* glCamera); - void updateFrustum(Frustum &frustum); - QList<TileSpec> updateVisibleTiles(); - - int width_; - int height_; - double aspectRatio_; - - Map *map_; - TileCache* cache_; - QGeoMappingManager *manager_; - QString pluginString_; - MapController *controller_; - - QSharedPointer<Projection> projection_; - - QGLCamera *glCamera_; - - CameraData cameraData_; - Frustum frustum_; - QList<TileSpec> visibleTiles_; - - MapSphere *sphere_; - MapType activeMapType_; - - // from map2d_p.h - - void tilesFromLine(const QVector3D &p1, - const QVector3D &p2, - const QVector2D &t1, - const QVector2D &t2, - int zoomLevel, - TileMap &map) const; - - QList<TileSpec> tilesFromPoints(const QVector<QVector3D> &points, bool roundUp) const; - - QPair<QList<QVector3D>,QList<QVector3D> > clipPolygonToMap(const QList<QVector3D> &points) const; - - class LengthSorter { - public: - QVector3D base; - bool operator()(const QVector3D &lhs, const QVector3D &rhs) { - return (lhs - base).lengthSquared() < (rhs - base).lengthSquared(); - } - }; - - QList<QVector3D> pointsOnLineWithX(const QVector3D &p1, const QVector3D &p2, double x) const; - QList<QVector3D> pointsOnLineWithY(const QVector3D &p1, const QVector3D &p2, double y) const; - QList<QVector3D> pointsOnLineWithZ(const QVector3D &p1, const QVector3D &p2, double z) const; - - QPair<QList<QVector3D>,QList<QVector3D> > splitPolygonX(const QList<QVector3D> &points, double x) const; - QPair<QList<QVector3D>,QList<QVector3D> > splitPolygonY(const QList<QVector3D> &points, double y) const; - - int maxZoom_; - int tileSize_; - - double baseHeight_; - double sideLength_; - QPolygonF screenPoly_; - QPolygonF screenPolyLeft_; - QPolygonF screenPolyRight_; - - QSizeF viewSize_; - QVector3D eye_; - QMatrix4x4 projectionMatrix_; -}; - -QT_END_NAMESPACE - -#endif // MAP_P_H diff --git a/src/location/mapsgl/mapcontroller.cpp b/src/location/mapsgl/mapcontroller.cpp deleted file mode 100644 index df263f69..00000000 --- a/src/location/mapsgl/mapcontroller.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "mapcontroller.h" - -#include "map.h" -#include "projection_p.h" - -#include <QPointF> - -#include <QVariant> -#include <QVariantAnimation> - -QVariant coordinateInterpolator(const AnimatableCoordinate &start, - const AnimatableCoordinate &end, - qreal progress) -{ - AnimatableCoordinate result; - - QSharedPointer<Projection> p = start.projection(); - if (!p) - p = end.projection(); - - if (!p) - result.setCoordinate(start.coordinate()); - else - result.setCoordinate(p->interpolate(start.coordinate(), - end.coordinate(), - progress)); - - result.setProjection(p); - - return QVariant::fromValue(result); -} - -AnimatableCoordinate::AnimatableCoordinate() {} - -AnimatableCoordinate::AnimatableCoordinate(const QGeoCoordinate &coordinate, - QSharedPointer<Projection> projection) - : coordinate_(coordinate), - projection_(projection) -{ -} - -QGeoCoordinate AnimatableCoordinate::coordinate() const -{ - return coordinate_; -} - -void AnimatableCoordinate::setCoordinate(const QGeoCoordinate &coordinate) -{ - coordinate_ = coordinate; -} - -QSharedPointer<Projection> AnimatableCoordinate::projection() const -{ - return projection_; -} - -void AnimatableCoordinate::setProjection(QSharedPointer<Projection> projection) -{ - projection_ = projection; -} - -MapController::MapController(Map *map, QSharedPointer<Projection> projection) - : QObject(map), - map_(map), - projection_(projection) -{ - qRegisterMetaType<AnimatableCoordinate>(); - qRegisterAnimationInterpolator<AnimatableCoordinate>(coordinateInterpolator); - - oldCameraData_ = map_->cameraData(); - - connect(map, - SIGNAL(cameraDataChanged(CameraData)), - this, - SLOT(cameraDataChanged(CameraData))); -} - -MapController::~MapController() {} - -void MapController::cameraDataChanged(const CameraData &cameraData) -{ - if (oldCameraData_.center() != cameraData.center()) - emit centerChanged(AnimatableCoordinate(cameraData.center(), projection_)); - - if (oldCameraData_.bearing() != cameraData.bearing()) - emit bearingChanged(cameraData.bearing()); - - if (oldCameraData_.tilt() != cameraData.tilt()) - emit tiltChanged(cameraData.tilt()); - - if (oldCameraData_.roll() != cameraData.roll()) - emit rollChanged(cameraData.roll()); - - if (oldCameraData_.zoomFactor() != cameraData.zoomFactor()) - emit zoomChanged(cameraData.zoomFactor()); - - oldCameraData_ = cameraData; -} - -AnimatableCoordinate MapController::center() const -{ - return AnimatableCoordinate(map_->cameraData().center(), projection_); -} - -void MapController::setCenter(const AnimatableCoordinate ¢er) -{ - CameraData cd = map_->cameraData(); - - if (center.coordinate() == cd.center()) - return; - - cd.setCenter(center.coordinate()); - map_->setCameraData(cd); -} - -qreal MapController::bearing() const -{ - return map_->cameraData().bearing(); -} - -void MapController::setBearing(qreal bearing) -{ - CameraData cd = map_->cameraData(); - - if (bearing == cd.bearing()) - return; - - cd.setBearing(bearing); - map_->setCameraData(cd); -} - -qreal MapController::tilt() const -{ - return map_->cameraData().tilt(); -} - -void MapController::setTilt(qreal tilt) -{ - CameraData cd = map_->cameraData(); - - if (tilt == cd.tilt()) - return; - - cd.setTilt(tilt); - map_->setCameraData(cd); -} - -qreal MapController::roll() const -{ - return map_->cameraData().roll(); -} - -void MapController::setRoll(qreal roll) -{ - CameraData cd = map_->cameraData(); - - if (roll == cd.roll()) - return; - - cd.setRoll(roll); - map_->setCameraData(cd); -} - -qreal MapController::zoom() const -{ - return map_->cameraData().zoomFactor(); -} - -void MapController::setZoom(qreal zoom) -{ - CameraData cd = map_->cameraData(); - - if (zoom == cd.zoomFactor()) - return; - - cd.setZoomFactor(zoom); - map_->setCameraData(cd); -} - -void MapController::pan(qreal dx, qreal dy) -{ - if (dx == 0 && dy == 0) - return; - CameraData cd = map_->cameraData(); - QGeoCoordinate coord = map_->screenPositionToCoordinate( - QPointF(map_->width() / 2 + dx, - map_->height() / 2 - dy)); - - if (coord.isValid()) { - cd.setCenter(coord); - map_->setCameraData(cd); - } -} diff --git a/src/location/mapsgl/mapcontroller.h b/src/location/mapsgl/mapcontroller.h deleted file mode 100644 index 6873488e..00000000 --- a/src/location/mapsgl/mapcontroller.h +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MAPCONTROLLER_H -#define MAPCONTROLLER_H - -#include <QObject> - -#include "qgeocoordinate.h" -#include "cameradata.h" - -QT_BEGIN_NAMESPACE - -class Map; - -class Q_LOCATION_EXPORT AnimatableCoordinate { -public: - AnimatableCoordinate(); - AnimatableCoordinate(const QGeoCoordinate &coordinate, - QSharedPointer<Projection> projection); - - QGeoCoordinate coordinate() const; - void setCoordinate(const QGeoCoordinate &coordinate); - - QSharedPointer<Projection> projection() const; - void setProjection(QSharedPointer<Projection> projection); - -private: - QGeoCoordinate coordinate_; - QSharedPointer<Projection> projection_; -}; - -class Q_LOCATION_EXPORT MapController : public QObject -{ - Q_OBJECT - - Q_PROPERTY(AnimatableCoordinate center READ center WRITE setCenter NOTIFY centerChanged) - Q_PROPERTY(qreal bearing READ bearing WRITE setBearing NOTIFY bearingChanged) - Q_PROPERTY(qreal tilt READ tilt WRITE setTilt NOTIFY tiltChanged) - Q_PROPERTY(qreal roll READ roll WRITE setRoll NOTIFY rollChanged) - Q_PROPERTY(qreal zoom READ zoom WRITE setZoom NOTIFY zoomChanged) - -public: - MapController(Map *map, QSharedPointer<Projection> projection); - ~MapController(); - - AnimatableCoordinate center() const; - void setCenter(const AnimatableCoordinate ¢er); - - qreal bearing() const; - void setBearing(qreal bearing); - - qreal tilt() const; - void setTilt(qreal tilt); - - qreal roll() const; - void setRoll(qreal roll); - - qreal zoom() const; - void setZoom(qreal zoom); - - void pan(qreal dx, qreal dy); - -private slots: - void cameraDataChanged(const CameraData &cameraData); - -signals: - void centerChanged(const AnimatableCoordinate ¢er); - void bearingChanged(qreal bearing); - void tiltChanged(qreal tilt); - void rollChanged(qreal roll); - void zoomChanged(qreal zoom); - -private: - Map *map_; - QSharedPointer<Projection> projection_; - CameraData oldCameraData_; -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(AnimatableCoordinate) - -#endif // MAPCONTROLLER_H diff --git a/src/location/mapsgl/mapsgl.pri b/src/location/mapsgl/mapsgl.pri deleted file mode 100644 index 27c68661..00000000 --- a/src/location/mapsgl/mapsgl.pri +++ /dev/null @@ -1,35 +0,0 @@ - -INCLUDEPATH += mapsgl - -QT += network qt3d - -SOURCES += \ - mapsgl/cameradata.cpp \ - mapsgl/frustum.cpp \ - mapsgl/map.cpp \ - mapsgl/mapcontroller.cpp \ - mapsgl/mapsphere.cpp \ - mapsgl/projection.cpp \ - mapsgl/projection2d_p.cpp \ - mapsgl/tilecache.cpp \ - mapsgl/tile.cpp \ - mapsgl/tilespec.cpp \ - mapsgl/maptype.cpp - -PUBLIC_HEADERS += \ - mapsgl/cameradata.h \ - mapsgl/map.h \ - mapsgl/mapcontroller.h \ - mapsgl/tilecache.h \ - mapsgl/tile.h \ - mapsgl/tilespec.h \ - mapsgl/maptype.h - -PRIVATE_HEADERS += \ - mapsgl/frustum_p.h \ - mapsgl/map_p.h \ - mapsgl/mapsphere_p.h \ - mapsgl/maptype_p.h \ - mapsgl/projection_p.h \ - mapsgl/projection2d_p.h \ - mapsgl/tilespec_p.h diff --git a/src/location/mapsgl/mapsphere.cpp b/src/location/mapsgl/mapsphere.cpp deleted file mode 100644 index 0a56f9b4..00000000 --- a/src/location/mapsgl/mapsphere.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "mapsphere_p.h" - -#include "tilecache.h" -#include "tilespec.h" -#include "tile.h" -#include "map.h" -#include "map_p.h" - -#include "qgeomappingmanager.h" - -#include <QOpenGLFramebufferObject> - -#include <Qt3D/qglscenenode.h> -#include <Qt3D/qglframebufferobjectsurface.h> -#include <Qt3D/qglcamera.h> -#include <Qt3D/qglpainter.h> - -#include <QVector> -#include <QTimer> - -MapSphere::MapSphere(Map* map, MapPrivate *mapPrivate, TileCache *tileCache) - : QObject(0), - tileCache_(tileCache), - map_(map), - mapPrivate_(mapPrivate), - manager_(0) -{ - - sphereNode_ = new QGLSceneNode(this); - - connect(this, - SIGNAL(tileUpdated()), - map, - SIGNAL(updateRequired())); -} - -MapSphere::~MapSphere() -{ - QList<QGLSceneNode*> nodes = built_.values(); - for (int i = 0; i < nodes.size(); ++i) { - QGLSceneNode *node = nodes.at(i); - //node->material()->texture()->release(); - node->geometry().clear(); - sphereNode_->removeNode(node); - delete node; - } -} - -void MapSphere::setMappingManager(QGeoMappingManager *manager) -{ - manager_ = manager; -} - -QGLSceneNode* MapSphere::sphereSceneNode() const -{ - return sphereNode_; -} - -// Function to perform housekeeping that require access to GL context -// (access to GL context varies depending on if we are running as -// c++ app or QML app). -// -// Function is guaranteed to be only called when executing in -// rendering thread with valid GL context. Furthermore it is -// safe to update any geometry/structures - mutex is locked. -void MapSphere::GLContextAvailable() -{ - // need something like this in the cache for - // releasing textures and freeing nodes that - // have been evicted from the GPU - tileCache_->GLContextAvailable(sphereNode_); -// qDeleteAll(obsoleteNodes_); -// obsoleteNodes_.clear(); -} - -void MapSphere::update(const QList<TileSpec> &tiles) -{ - QHash<TileSpec, QGLSceneNode*> stillBuilt; - - QVector<TileSpec> req(tiles.size()); - QVector<TileSpec> draw(tiles.size()); - - QSet<TileSpec> cancelTiles = requested_ - tiles.toSet(); - - int reqSize = 0; - int drawSize = 0; - QList<TileSpec>::const_iterator i = tiles.constBegin(); - QList<TileSpec>::const_iterator tilesEnd = tiles.constEnd(); - while (i != tilesEnd) { - /* - If the tile is already built or has been requested then we - shouldn't use it (where "use" means drawing a cached tile or - requested an uncached tile). - */ - if (built_.contains(*i)) { - stillBuilt.insert(*i, built_.value(*i)); - } else if (!requested_.contains(*i)){ - /* - Otherwise we add it to the correct list - */ - if (tileCache_->contains(*i)) { - draw[drawSize] = *i; - ++drawSize; - } else { - req[reqSize] = *i; - ++reqSize; - requested_.insert(*i); - } - } - - ++i; - } - - req.resize(reqSize); - - updateMutex.lock(); - - QHash<TileSpec, QGLSceneNode*>::const_iterator j = built_.constBegin(); - QHash<TileSpec, QGLSceneNode*>::const_iterator end = built_.constEnd(); - while (j != end) { - TileSpec spec = j.key(); - if (!stillBuilt.contains(spec)) { - sphereNode_->removeNode(j.value()); - } - ++j; - } - built_.swap(stillBuilt); - - updateMutex.unlock(); - - for (int i = 0; i < drawSize; ++i) - displayTile(draw.at(i)); - - if (req.isEmpty()) { - emit tileUpdated(); - } else { - if (manager_) { - manager_->updateTileRequests(map_, req.toList().toSet(), cancelTiles); - } - } -} - -void MapSphere::tileFetched(const TileSpec &spec) -{ - if (!requested_.contains(spec)) - return; - - displayTile(spec); - - requested_.remove(spec); - - emit tileUpdated(); -} - -void MapSphere::displayTile(const TileSpec &spec) -{ - if (built_.contains(spec)) - return; - - updateMutex.lock(); - Tile tile = tileCache_->get(spec); - QGLSceneNode *node = tile.sceneNode(); - if (!node) { - node = mapPrivate_->createTileNode(tile); - tile.setSceneNode(node); - tile.bind(); - tileCache_->update(spec, tile); - } - if (node) { - sphereNode_->addNode(node); - built_.insert(spec, node); - } - updateMutex.unlock(); -} - -void MapSphere::paintGL(QGLPainter *painter) -{ - if (!updateMutex.tryLock()) { - qWarning() << "----- map will miss a frame, no mutex acquired!------"; - return; - } - - GLContextAvailable(); - - sphereNode_->draw(painter); - - updateMutex.unlock(); -} diff --git a/src/location/mapsgl/mapsphere_p.h b/src/location/mapsgl/mapsphere_p.h deleted file mode 100644 index c66d683f..00000000 --- a/src/location/mapsgl/mapsphere_p.h +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef MAPSPHERE_H -#define MAPSPHERE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtLocation/qlocationglobal.h> -#include "tilespec.h" - -#include <QObject> -#include <QSet> -#include <QHash> -#include <QList> -#include <QCache> -#include <QSharedPointer> - -#include <QMutex> - -QT_BEGIN_NAMESPACE - -class QGLSceneNode; -class QGLPainter; - -class QOpenGLFramebufferObject; - -class TileSpec; -class TileCache; - -class Map; -class MapPrivate; - -class QGeoMappingManager; - -class Q_LOCATION_EXPORT MapSphere : public QObject -{ - Q_OBJECT -public: - MapSphere(Map* map, MapPrivate *mapPrivate, TileCache *tileCache); - ~MapSphere(); - - void setMappingManager(QGeoMappingManager *manager); - - QGLSceneNode* sphereSceneNode() const; - - QMutex updateMutex; - // when running as QML app we can't access GL context anywhere - // but QSG rendering thread. - void GLContextAvailable(); - - void paintGL(QGLPainter *painter); - - void tileFetched(const TileSpec &spec); - -public Q_SLOTS: - void update(const QList<TileSpec> &tiles); - -Q_SIGNALS: - void tileUpdated(); - -private: - void displayTile(const TileSpec &spec); - - QList<TileSpec> visibleTiles_; - - TileCache *tileCache_; - int minZoom_; - - QSet<TileSpec> requested_; - QHash<TileSpec, QGLSceneNode*> built_; - - QGLSceneNode* sphereNode_; - - Map *map_; - MapPrivate* mapPrivate_; - QGeoMappingManager *manager_; -}; - -QT_END_NAMESPACE - -#endif // MAPSPHERE_H diff --git a/src/location/mapsgl/maptype.cpp b/src/location/mapsgl/maptype.cpp deleted file mode 100644 index e3d63f11..00000000 --- a/src/location/mapsgl/maptype.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "maptype.h" -#include "maptype_p.h" - -QT_BEGIN_NAMESPACE - -MapType::MapType() - : d_ptr(new MapTypePrivate()) {} - -MapType::MapType(const MapType &other) - : d_ptr(other.d_ptr) {} - -MapType::MapType(MapType::MapStyle style, const QString &name, const QString &description, bool mobile, int mapId) - : d_ptr(new MapTypePrivate(style, name, description, mobile, mapId)) {} - -MapType::~MapType() {} - -MapType& MapType::operator = (const MapType &other) -{ - d_ptr = other.d_ptr; - return *this; -} - -bool MapType::operator == (const MapType &other) const -{ - return (*d_ptr.constData() == *other.d_ptr.constData()); -} - -bool MapType::operator != (const MapType &other) const -{ - return !(operator ==(other)); -} - -MapType::MapStyle MapType::style() const -{ - return d_ptr->style_; -} - -QString MapType::name() const -{ - return d_ptr->name_; -} - -QString MapType::description() const -{ - return d_ptr->description_; -} - -bool MapType::mobile() const -{ - return d_ptr->mobile_; -} - -int MapType::mapId() const -{ - return d_ptr->mapId_; -} - -MapTypePrivate::MapTypePrivate() - : style_(MapType::NoMap), - name_(QLatin1String("")), - description_(QLatin1String("")), - mobile_(false), - mapId_(0) {} - -MapTypePrivate::MapTypePrivate(const MapTypePrivate &other) - : QSharedData(other), - style_(other.style_), - name_(other.name_), - description_(other.description_), - mobile_(other.mobile_), - mapId_(other.mapId_) {} - -MapTypePrivate::MapTypePrivate(MapType::MapStyle style, const QString &name, const QString &description, bool mobile, int mapId) - : style_(style), - name_(name), - description_(description), - mobile_(mobile), - mapId_(mapId) {} - -MapTypePrivate::~MapTypePrivate() {} - -bool MapTypePrivate::operator == (const MapTypePrivate &other) const -{ - return ((style_ == other.style_) - && (name_ == other.name_) - && (description_ == other.description_) - && (mobile_ == other.mobile_) - && (mapId_ == other.mapId_)); -} - -QT_END_NAMESPACE diff --git a/src/location/mapsgl/maptype.h b/src/location/mapsgl/maptype.h deleted file mode 100644 index 874b2f60..00000000 --- a/src/location/mapsgl/maptype.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MAPTYPE_H -#define MAPTYPE_H - -#include <QtLocation/qlocationglobal.h> -#include <QString> -#include <QSharedDataPointer> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class MapTypePrivate; - -class Q_LOCATION_EXPORT MapType -{ - -public: - enum MapStyle { - NoMap = 0, - StreetMap, - SatelliteMapDay, - SatelliteMapNight, - TerrainMap, - HybridMap, - TransitMap, - GrayStreetMap, - CustomMap = 100 - }; - - MapType(); - MapType(const MapType &other); - MapType(MapStyle style, const QString &name, const QString &description, bool mobile, int mapId); - ~MapType(); - - MapType& operator = (const MapType &other); - - bool operator == (const MapType &other) const; - bool operator != (const MapType &other) const; - - MapStyle style() const; - QString name() const; - QString description() const; - bool mobile() const; - int mapId() const; - -private: - QSharedDataPointer<MapTypePrivate> d_ptr; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/location/mapsgl/maptype_p.h b/src/location/mapsgl/maptype_p.h deleted file mode 100644 index e3e05255..00000000 --- a/src/location/mapsgl/maptype_p.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MAPTYPE_P_H -#define MAPTYPE_P_H - -#include <QMetaType> -#include <QString> -#include <QSharedData> - -#include "maptype.h" - -QT_BEGIN_NAMESPACE - -class MapTypePrivate : public QSharedData -{ - -public: - MapTypePrivate(); - MapTypePrivate(MapType::MapStyle style, const QString &name, const QString &description, bool mobile, int mapId); - MapTypePrivate(const MapTypePrivate &other); - ~MapTypePrivate(); - - MapTypePrivate& operator = (const MapTypePrivate &other); - - bool operator == (const MapTypePrivate &other) const; - - MapType::MapStyle style_; - QString name_; - QString description_; - bool mobile_; - int mapId_; -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(MapTypePrivate) - -#endif // MAPTYPE_P_H diff --git a/src/location/mapsgl/projection.cpp b/src/location/mapsgl/projection.cpp deleted file mode 100644 index 84927351..00000000 --- a/src/location/mapsgl/projection.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "projection_p.h" - -#include "qgeocoordinate.h" - -#include <qvector2d.h> -#include <qvector3d.h> -#include <QMatrix4x4> -#include <qnumeric.h> - -#include <cmath> - -Projection::Projection() {} - -Projection::~Projection() {} - -QVector3D Projection::mercatorToPoint(const QVector2D &mercator) const -{ - return this->coordToPoint(mercatorToCoord(mercator)); -} - -QVector2D Projection::pointToMercator(const QVector3D &point) const -{ - return coordToMercator(this->pointToCoord(point)); -} - -QVector2D Projection::coordToMercator(const QGeoCoordinate &coord) const -{ - const double pi = M_PI; - - double lon = coord.longitude() / 360.0 + 0.5; - - double lat = coord.latitude(); - lat = 0.5 - (log(tan((pi / 4.0) + (pi / 2.0) * lat / 180.0)) / pi) / 2.0; - lat = qMax(0.0, lat); - lat = qMin(1.0, lat); - - return QVector2D(lon, lat); -} - -double Projection::realmod(const double a, const double b) -{ - quint64 div = static_cast<quint64>(a / b); - return a - static_cast<double>(div) * b; -} - -QGeoCoordinate Projection::mercatorToCoord(const QVector2D &mercator) const -{ - const double pi = M_PI; - - double fx = mercator.x(); - double fy = mercator.y(); - - if (fy < 0.0) - fy = 0.0; - else if (fy > 1.0) - fy = 1.0; - - double lat; - - if (fy == 0.0) - lat = 90.0; - else if (fy == 1.0) - lat = -90.0; - else - lat = (180.0 / pi) * (2.0 * atan(exp(pi * (1.0 - 2.0 * fy))) - (pi / 2.0)); - - double lng; - if (fx >= 0) { - lng = realmod(fx, 1.0); - } else { - lng = realmod(1.0 - realmod(-1.0 * fx, 1.0), 1.0); - } - - lng = lng * 360.0 - 180.0; - - return QGeoCoordinate(lat, lng, 0.0); -} diff --git a/src/location/mapsgl/projection2d_p.cpp b/src/location/mapsgl/projection2d_p.cpp deleted file mode 100644 index d8adddce..00000000 --- a/src/location/mapsgl/projection2d_p.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "projection2d_p.h" - -#include "qgeocoordinate.h" - -#include <QVector2D> -#include <QVector3D> - -#include <qnumeric.h> - -Projection2D::Projection2D(double baseHeight, double sideLength) - : baseHeight_(baseHeight), sideLength_(sideLength) {} - -Projection2D::~Projection2D() {} - -QVector3D Projection2D::coordToPoint(const QGeoCoordinate &coord) const -{ - QVector2D m = coordToMercator(coord); - double z = baseHeight_; - if (!qIsNaN(coord.altitude())) - z += coord.altitude(); - return QVector3D(m.x() * sideLength_, (1.0 - m.y()) * sideLength_, z); -} - -QGeoCoordinate Projection2D::pointToCoord(const QVector3D &point) const -{ - QVector2D m = QVector2D(point.x() / sideLength_, 1.0 - point.y() / sideLength_); - QGeoCoordinate coord = mercatorToCoord(m); - coord.setAltitude(point.z() - baseHeight_); - return coord; -} - -QVector3D Projection2D::mercatorToPoint(const QVector2D &mercator) const -{ - return QVector3D(mercator.x() * sideLength_, (1.0 - mercator.y()) * sideLength_, baseHeight_); -} - -QVector2D Projection2D::pointToMercator(const QVector3D &point) const -{ - return QVector2D(point.x() / sideLength_, 1.0 - (point.y() / sideLength_)); -} - -QGeoCoordinate Projection2D::interpolate(const QGeoCoordinate &start, const QGeoCoordinate &end, qreal progress) -{ - if (start == end) { - if (progress < 0.5) { - return start; - } else { - return end; - } - } - - QGeoCoordinate s2 = start; - s2.setAltitude(0.0); - QGeoCoordinate e2 = end; - e2.setAltitude(0.0); - QVector3D s = coordToPoint(s2); - QVector3D e = coordToPoint(e2); - - double x = s.x(); - - if (sideLength_ / 2.0 < qAbs(e.x() - s.x())) { - // handle dateline crossing - } else { - x = (1.0 - progress) * s.x() + progress * e.x(); - } - - double y = (1.0 - progress) * s.y() + progress * e.y(); - - QGeoCoordinate result = pointToCoord(QVector3D(x, y, 0.0)); - result.setAltitude((1.0 - progress) * start.altitude() + progress * end.altitude()); - return result; -} diff --git a/src/location/mapsgl/projection2d_p.h b/src/location/mapsgl/projection2d_p.h deleted file mode 100644 index 2ca83703..00000000 --- a/src/location/mapsgl/projection2d_p.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef PROJECTION2D_P_H -#define PROJECTION2D_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "projection_p.h" - -QT_BEGIN_NAMESPACE - -class Q_AUTOTEST_EXPORT Projection2D : public Projection -{ -public: - Projection2D(double baseHeight, double sideLength); - virtual ~Projection2D(); - - virtual QVector3D coordToPoint(const QGeoCoordinate &coord) const; - virtual QGeoCoordinate pointToCoord(const QVector3D &point) const; - - virtual QVector3D mercatorToPoint(const QVector2D &mercator) const; - virtual QVector2D pointToMercator(const QVector3D &point) const; - - virtual QGeoCoordinate interpolate(const QGeoCoordinate &start, const QGeoCoordinate &end, qreal progress); - -private: - double baseHeight_; - double sideLength_; -}; - -QT_END_NAMESPACE - -#endif // PROJECTION2D_P_H diff --git a/src/location/mapsgl/projection_p.h b/src/location/mapsgl/projection_p.h deleted file mode 100644 index 20f86f63..00000000 --- a/src/location/mapsgl/projection_p.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef PROJECTION_H -#define PROJECTION_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qglobal.h" - -QT_BEGIN_NAMESPACE - -class QGeoCoordinate; -class QVector2D; -class QVector3D; - -class Q_AUTOTEST_EXPORT Projection -{ -public: - Projection(); - virtual ~Projection(); - - virtual QVector3D coordToPoint(const QGeoCoordinate &coord) const = 0; - virtual QGeoCoordinate pointToCoord(const QVector3D &point) const = 0; - - QVector2D coordToMercator(const QGeoCoordinate &coord) const; - QGeoCoordinate mercatorToCoord(const QVector2D &mercator) const; - - virtual QVector3D mercatorToPoint(const QVector2D &mercator) const; - virtual QVector2D pointToMercator(const QVector3D &point) const; - - virtual QGeoCoordinate interpolate(const QGeoCoordinate &start, const QGeoCoordinate &end, qreal progress) = 0; -private: - static double realmod(const double a, const double b); -}; - -QT_END_NAMESPACE - -#endif // PROJECTION_H diff --git a/src/location/mapsgl/tile.cpp b/src/location/mapsgl/tile.cpp deleted file mode 100644 index 4cd51f14..00000000 --- a/src/location/mapsgl/tile.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "tile.h" - -#include <Qt3D/qgltexture2d.h> -#include <Qt3D/qglscenenode.h> - -QT_BEGIN_NAMESPACE - -Tile::Tile() {} - -Tile::Tile(const TileSpec &spec) - : spec_(spec), - texture_(0), - sceneNode_(0), - bound_(false) {} - -bool Tile::operator == (const Tile &rhs) const -{ - return (spec_ == rhs.spec_); -} - -void Tile::setTileSpec(const TileSpec &spec) -{ - spec_ = spec; -} - -TileSpec Tile::tileSpec() const -{ - return spec_; -} - -void Tile::setTexture(QGLTexture2D *texture) -{ - texture_ = texture; -} - -QGLTexture2D* Tile::texture() const -{ - return texture_; -} - -void Tile::setSceneNode(QGLSceneNode *sceneNode) -{ - sceneNode_ = sceneNode; -} - -QGLSceneNode* Tile::sceneNode() const -{ - return sceneNode_; -} - -void Tile::bind() -{ - if (bound_) - return; - - texture_->bind(); -// texture_->clearImage(); - - bound_ = true; -} - -void Tile::setBound(bool bound) -{ - bound_ = bound; -} - -bool Tile::isBound() const -{ - return bound_; -} - -QT_END_NAMESPACE diff --git a/src/location/mapsgl/tile.h b/src/location/mapsgl/tile.h deleted file mode 100644 index 96879e23..00000000 --- a/src/location/mapsgl/tile.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef TILE_H -#define TILE_H - -#include "qglobal.h" - -#include "tilespec.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - - - -class QGLTexture2D; -class QGLSceneNode; - -class Q_LOCATION_EXPORT Tile -{ -public: - Tile(); - Tile(const TileSpec &spec); - - bool operator == (const Tile &rhs) const; - - void setTileSpec(const TileSpec &spec); - TileSpec tileSpec() const; - - void setTexture(QGLTexture2D *texture); - QGLTexture2D* texture() const; - - void setSceneNode(QGLSceneNode *sceneNode); - QGLSceneNode *sceneNode() const; - - void bind(); - void setBound(bool bound); - bool isBound() const; - -private: - TileSpec spec_; - QGLTexture2D *texture_; - QGLSceneNode *sceneNode_; - bool bound_; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // TILE_H diff --git a/src/location/mapsgl/tilecache.cpp b/src/location/mapsgl/tilecache.cpp deleted file mode 100644 index ebc1f7ec..00000000 --- a/src/location/mapsgl/tilecache.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "tilecache.h" - -#include "tile.h" -#include "tilespec.h" - -#include "qgeomappingmanager.h" - -#include <QDir> -#include <QMetaType> -#include <QDebug> - -#include <Qt3D/qgltexture2d.h> -#include <Qt3D/qglscenenode.h> - -Q_DECLARE_METATYPE(QList<TileSpec>) -Q_DECLARE_METATYPE(QSet<TileSpec>) - -QT_BEGIN_NAMESPACE - -class TileDisk -{ -public: - ~TileDisk() - { -// qWarning() << "evicting (disk) " << spec; -// cache->evictFromDiskCache(this); - } - - TileSpec spec; - QString filename; - TileCache *cache; -}; - -class TileMemory -{ -public: - ~TileMemory() - { -// qWarning() << "evicting (memory) " << spec; - cache->evictFromMemoryCache(this); - } - - TileSpec spec; - QPixmap pixmap; - TileCache *cache; -}; - -class TileTexture { -public: - ~TileTexture() - { -// qWarning() << "evicting (texture) " << spec; - cache->evictFromTextureCache(this); - } - - TileSpec spec; - bool bound; - QGLTexture2D *texture; - QGLSceneNode *node; - TileCache *cache; -}; - -TileCache::TileCache(const QString &directory, QObject *parent) -: QObject(parent), directory_(directory) -{ - qRegisterMetaType<TileSpec>(); - qRegisterMetaType<QList<TileSpec> >(); - qRegisterMetaType<QSet<TileSpec> >(); - - - if (directory_.isEmpty()) { - QString dirname = QLatin1String(".tilecache"); - QDir home = QDir::home(); - if (!home.exists(dirname)) - home.mkdir(dirname); - directory_ = home.filePath(dirname); - } - qDebug() << __FUNCTION__ << directory_; - - diskCache_.setMaxCost(100 * 1024 * 1024); - memoryCache_.setMaxCost(50 * 1024 * 1024); - textureCache_.setMaxCost(100 * 1024 * 1024); - - loadTiles(); -} - -TileCache::~TileCache() {} - -void TileCache::setMaxDiskUsage(int diskUsage) -{ - diskCache_.setMaxCost(diskUsage); -} - -int TileCache::maxDiskUsage() const -{ - return diskCache_.maxCost(); -} - -int TileCache::diskUsage() const -{ - return diskCache_.totalCost(); -} - -void TileCache::setMaxMemoryUsage(int memoryUsage) -{ - memoryCache_.setMaxCost(memoryUsage); -} - -int TileCache::maxMemoryUsage() const -{ - return memoryCache_.maxCost(); -} - -int TileCache::memoryUsage() const -{ - return memoryCache_.totalCost(); -} - -void TileCache::setMaxTextureUsage(int textureUsage) -{ - textureCache_.setMaxCost(textureUsage); -} - -int TileCache::maxTextureUsage() const -{ - return textureCache_.maxCost(); -} - -int TileCache::textureUsage() const -{ - return textureCache_.totalCost(); -} - -void TileCache::GLContextAvailable(QGLSceneNode *parentNode) -{ - int size = cleanupList_.size(); - for (int i = 0; i < size; ++i) { - Tile t = cleanupList_.at(i); - QGLSceneNode *node = t.sceneNode(); - if (node) { - parentNode->removeNode(node); - delete node; - } - QGLTexture2D *texture = t.texture(); - if (texture) { - texture->release(); - delete texture; - } - } - cleanupList_.clear(); -} - -bool TileCache::contains(const TileSpec &spec) const -{ - return keys_.contains(spec); -} - -Tile TileCache::get(const TileSpec &spec) -{ - if (textureCache_.contains(spec)) { - TileTexture *tt = textureCache_.object(spec); - - Tile t = Tile(tt->spec); - t.setTexture(tt->texture); - t.setSceneNode(tt->node); - t.setBound(tt->bound); - return t; - } -// if (memoryCache_.contains(spec)) { -// TileMemory *tm = memoryCache_.object(spec); -// TileTexture *tt = addToTextureCache(tm->spec, tm->pixmap); - -// Tile t = Tile(tt->spec); -// t.setTexture(tt->texture); -// t.setSceneNode(tt->node); -// t.setBound(tt->bound); -// return t; -// } - if (diskCache_.contains(spec)) { - TileDisk *td = diskCache_.object(spec); -// TileMemory *tm = addToMemoryCache(td->spec, QPixmap(td->filename)); -// TileTexture *tt = addToTextureCache(tm->spec, tm->pixmap); - TileTexture *tt = addToTextureCache(td->spec, QPixmap(td->filename)); - - Tile t = Tile(tt->spec); - t.setTexture(tt->texture); - t.setSceneNode(tt->node); - t.setBound(tt->bound); - return t; - } - - return Tile(); -} - -// TODO rename so this is less strange -// OR do node creation in here somehow -void TileCache::update(const TileSpec &spec, const Tile &tile) -{ - TileTexture *tt = textureCache_.object(spec); - if (tt) { - tt->node = tile.sceneNode(); - tt->texture = tile.texture(); - tt->bound = tile.isBound(); - } -} - -void TileCache::insert(const TileSpec &spec, const QByteArray &bytes, TileCache::CacheAreas areas) -{ - keys_.insert(spec); - - QPixmap pixmap; - if (!pixmap.loadFromData(bytes)) { - handleError(spec, QLatin1String("Problem with tile image")); - return; - } - - if (areas & TileCache::DiskCache) { - QString filename = tileSpecToFilename(spec, directory_); - - QFile file(filename); - file.open(QIODevice::WriteOnly); - file.write(bytes); - file.close(); - - addToDiskCache(spec, filename); - } - - if (areas & TileCache::MemoryCache) { -// addToMemoryCache(spec, pixmap); - } - - if (areas & TileCache::TextureCache) { - addToTextureCache(spec, pixmap); - } -} - -void TileCache::evictFromDiskCache(TileDisk *td) -{ - keys_.remove(td->spec); - QFile::remove(td->filename); -} - -void TileCache::evictFromMemoryCache(TileMemory * /* tm */) -{ -} - -void TileCache::evictFromTextureCache(TileTexture *tt) -{ - Tile t(tt->spec); - t.setTexture(tt->texture); - t.setSceneNode(tt->node); - cleanupList_ << t; -} - -TileDisk* TileCache::addToDiskCache(const TileSpec &spec, const QString &filename) -{ - keys_.insert(spec); - -// qWarning() << "adding (disk) " << spec; - - TileDisk *td = new TileDisk; - td->spec = spec; - td->filename = filename; - td->cache = this; - - QFileInfo fi(filename); - int diskCost = fi.size(); - - diskCache_.insert(spec, - td, - diskCost); - - return td; -} - -TileMemory* TileCache::addToMemoryCache(const TileSpec &spec, const QPixmap &pixmap) -{ - keys_.insert(spec); - -// qWarning() << "adding (memory) " << spec; - - TileMemory *tm = new TileMemory; - tm->spec = spec; - tm->pixmap = pixmap; - tm->cache = this; - - int memoryCost = pixmap.width() * pixmap.height() * pixmap.depth() / 8; - - memoryCache_.insert(spec, - tm, - memoryCost); - - return tm; -} - -TileTexture* TileCache::addToTextureCache(const TileSpec &spec, const QPixmap &pixmap) -{ - keys_.insert(spec); - -// qWarning() << "adding (texture) " << spec; - - TileTexture *tt = new TileTexture; - tt->spec = spec; - tt->texture = new QGLTexture2D(); - tt->texture->setPixmap(pixmap); - tt->texture->setHorizontalWrap(QGL::ClampToEdge); - tt->texture->setVerticalWrap(QGL::ClampToEdge); - -// tt->texture->bind(); -// tt->texture->clearImage(); - - tt->node = 0; - tt->cache = this; - - int textureCost = pixmap.width() * pixmap.height() * pixmap.depth() / 8;; - - textureCache_.insert(spec, - tt, - textureCost); - - return tt; -} - -void TileCache::handleError(const TileSpec &, const QString &error) -{ - qWarning() << "tile request error " << error; -} - -void TileCache::loadTiles() -{ - QStringList formats; - formats << QLatin1String("*.png"); - - QDir dir(directory_); - //QStringList files = dir.entryList(formats, QDir::Files, QDir::Time | QDir::Reversed); - QStringList files = dir.entryList(formats, QDir::Files); - int tiles = 0; - for (int i = 0; i < files.size(); ++i) { - TileSpec spec = filenameToTileSpec(files.at(i)); - if (spec.zoom() == -1) - continue; - QString filename = dir.filePath(files.at(i)); - addToDiskCache(spec, filename); - tiles++; - } - qDebug() << __FUNCTION__ << " loaded this many map tiles to cache: " << tiles; - -} - -QString TileCache::tileSpecToFilename(const TileSpec &spec, const QString &directory) -{ - QString filename = spec.plugin(); - filename += QLatin1String("-"); - filename += QString::number(spec.mapId()); - filename += QLatin1String("-"); - filename += QString::number(spec.zoom()); - filename += QLatin1String("-"); - filename += QString::number(spec.x()); - filename += QLatin1String("-"); - filename += QString::number(spec.y()); - filename += QLatin1String(".png"); - - QDir dir = QDir(directory); - - return dir.filePath(filename); -} - -TileSpec TileCache::filenameToTileSpec(const QString &filename) -{ - TileSpec emptySpec; - QString extension = QLatin1String(".png"); - - if (!filename.endsWith(extension)) - return emptySpec; - - QString name = filename; - name.chop(extension.length()); - QStringList fields = name.split('-'); - - if (fields.length() != 5) - return emptySpec; - - QList<int> numbers; - - bool ok = false; - for (int i = 1; i < 5; ++i) { - ok = false; - int value = fields.at(i).toInt(&ok); - if (!ok) - return emptySpec; - numbers.append(value); - } - - return TileSpec(fields.at(0), - numbers.at(0), - numbers.at(1), - numbers.at(2), - numbers.at(3)); -} - -QT_END_NAMESPACE diff --git a/src/location/mapsgl/tilecache.h b/src/location/mapsgl/tilecache.h deleted file mode 100644 index 06432d9f..00000000 --- a/src/location/mapsgl/tilecache.h +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef TILECACHE_H -#define TILECACHE_H - -#include <QtLocation/qlocationglobal.h> - -#include <QObject> -#include <QCache> -#include <QSet> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - - - -class QGeoMappingManager; - -class TileSpec; -class Tile; - -class TileDisk; -class TileMemory; -class TileTexture; - -class QGLSceneNode; - -class QPixmap; -class QThread; - -class Q_LOCATION_EXPORT TileCache : public QObject -{ - Q_OBJECT -public: - enum CacheArea { - DiskCache = 0x01, - MemoryCache = 0x02, - TextureCache = 0x04, - AllCaches = 0xFF - }; - Q_DECLARE_FLAGS(CacheAreas, CacheArea) - - TileCache(const QString &directory = QString(), QObject *parent = 0); - ~TileCache(); - - void setMaxDiskUsage(int diskUsage); - int maxDiskUsage() const; - int diskUsage() const; - - void setMaxMemoryUsage(int memoryUsage); - int maxMemoryUsage() const; - int memoryUsage() const; - - void setMaxTextureUsage(int textureUsage); - int maxTextureUsage() const; - int textureUsage() const; - - void GLContextAvailable(QGLSceneNode *parentNode); - - bool contains(const TileSpec &spec) const; - Tile get(const TileSpec &spec); - - void update(const TileSpec &spec, const Tile &tile); - - void evictFromDiskCache(TileDisk *td); - void evictFromMemoryCache(TileMemory *tm); - void evictFromTextureCache(TileTexture *tt); - - void insert(const TileSpec &spec, const QByteArray &bytes, CacheAreas areas = AllCaches); - void handleError(const TileSpec &spec, const QString &errorString); - -private: - void loadTiles(); - - TileDisk* addToDiskCache(const TileSpec &spec, const QString &filename); - TileMemory* addToMemoryCache(const TileSpec &spec, const QPixmap &pixmap); - TileTexture* addToTextureCache(const TileSpec &spec, const QPixmap &pixmap); - - static QString tileSpecToFilename(const TileSpec &spec, const QString &directory); - static TileSpec filenameToTileSpec(const QString &filename); - - QString directory_; - - QSet<TileSpec> keys_; - QCache<TileSpec, TileDisk > diskCache_; - QCache<TileSpec, TileMemory > memoryCache_; - QCache<TileSpec, TileTexture > textureCache_; - - QList<Tile> cleanupList_; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(TileCache::CacheAreas) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // TILECACHE_H diff --git a/src/location/mapsgl/tilecamera.cpp b/src/location/mapsgl/tilecamera.cpp deleted file mode 100644 index 32a28a9a..00000000 --- a/src/location/mapsgl/tilecamera.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "tilecamera.h" - -#include "spheregeometry.h" - -#include <QVector3D> -#include <qnumeric.h> -#include <qglcamera.h> - -#include <cmath> - -TileCamera::TileCamera() - : latitude_(-27.5), - longitude_(153), - distance_(0.1), - bearing_(0.0), - tilt_(0.0), - aspectRatio_(1.0), - camera_(new QGLCamera()) -{ -} - -TileCamera::~TileCamera() -{ - delete camera_; -} - -// Up and right units are bit obscure still, fixme -void TileCamera::rotateCamera(const SphereGeometry & sphere, double up, double right) -{ - QVector3D view = camera_->eye() - camera_->center(); - QVector3D side = QVector3D::normal(view, camera_->upVector()); - QMatrix4x4 rotationMatrix; - // First determine how big angle and about which axis' to rotate - // and express them with a rotation matrix (spherical rotation around origin) - rotationMatrix.rotate(right / sphere.zoomLevel(), camera_->upVector()); - rotationMatrix.rotate(up / sphere.zoomLevel(), side); - // Then rotate the eye and center of the camera - camera_->setCenter(camera_->center() * rotationMatrix); - camera_->setEye(camera_->eye() * rotationMatrix); -} - -void TileCamera::setCamera(const SphereGeometry &sphere, - double latitude, - double longitude, - double distance, - double bearing, - double tilt, - double aspectRatio) -{ - QVector3D c = sphere.coordToPoint(latitude, longitude); - QVector3D e = sphere.coordToPoint(latitude, longitude, sphere.radius() * distance); - - camera_->setCenter(c); - camera_->setEye(e); - - QVector3D view = camera_->eye() - camera_->center(); - QVector3D side = QVector3D::normal(view, QVector3D(0.0, 1.0, 0.0)); - QVector3D up = QVector3D::normal(side, view); - - // define rotation around view vector and apply it to up vector - QMatrix4x4 mBearing; - mBearing.rotate(-1.0 * bearing, view); - camera_->setUpVector(mBearing * up); - - // define rotation around new side vector and apply it to eye - QVector3D side2 = QVector3D::normal(mBearing * up, view); - QMatrix4x4 mTilt; - mTilt.rotate(tilt, side2); - camera_->setEye((mTilt * view) + c); - - // reset the up vector after tilting - view = camera_->eye() - camera_->center(); - up = QVector3D::normal(view, side2); - camera_->setUpVector(up); - - // set near and far planes - camera_->setNearPlane(1); - camera_->setFarPlane(2.0 * sphere.radius() * distance); - zoom_ = sphere.zoomLevel(); -} - -/* TODO improve zoomCamera a lot. Current implementation is very hacky. - - @factor: fractions of a zoom level to zoom in. Doubling a zoom level - roughly doubles the distance from the earth. - - @detailPreference: whether the distance from the earth should be that of the eye from - closest point on earth, or from eye to center (center is where we are looking at). - - */ -void TileCamera::zoomCamera(SphereGeometry& sphere, double factor, DetailPreference detailPreference) -{ - if (!(-1.0 < factor && factor < 1.0)) { - qWarning() << "Zoom factor must be between -1.0 and 1.0, you gave: " << factor; - return; - } - - QVector3D view = camera_->eye() - camera_->center(); - Q_ASSERT(view.length() > 0.0); - double viewVectorLength = view.length(); - double eyeVectorLength = camera_->eye().length(); - double sphereRadius = sphere.radius(); - double zoomDistance; - if (detailPreference == DetailPreferenceNear) { - qDebug() << "Zooming, preferring details/tiles near, factor: " << factor; - double viewEyeDotProduct = QVector3D::dotProduct(view, camera_->eye()); - // Dodgy, fixme - bool zoomOut = false; - if (factor < 0.0) { - factor = -factor; - zoomOut = true; - } - factor += 1.0; - // Look for the multiplication factor so that multiplying the view with the factor - // will result in eye height changing according to given factor. - double sqrtResult = sqrt(pow(viewEyeDotProduct, 2) - 4 * pow(viewVectorLength, 2) * (pow(eyeVectorLength, 2) - pow(sphereRadius + factor * eyeVectorLength - factor * sphereRadius , 2))); - double viewVectorFactor = (-viewEyeDotProduct + sqrtResult) / (2 * pow(viewVectorLength, 2)); - // Dodgy, fixme - if (!zoomOut) - camera_->setEye(camera_->eye() - view * viewVectorFactor); - else - camera_->setEye(view * viewVectorFactor + camera_->eye()); - // Fixme, far too big farplane (no pun intended) - view = camera_->eye() - camera_->center(); - camera_->setFarPlane(sphere.radius() + view.length()); - zoomDistance = camera_->eye().length() - sphere.radius(); - } else if (detailPreference == DetailPreferenceCenter) { - qDebug() << "Zooming, preferring details/tiles at center, factor: " << factor; - factor = -factor; - factor += 1; - camera_->setEye(camera_->center() + view * factor); - view = camera_->eye() - camera_->center(); - camera_->setFarPlane(sphere.radius() + view.length()); - zoomDistance = view.length(); - } else { - qWarning("Unsupported detail preference for zoom."); - return; - } - // Adjust sphere zoom level if necessary - double maxZoomLevel = 18; // TODO this needs to come from the current plugin - double zoomCoefficient = 0.5; // TODO just initial guess - int zoomLevel = int(maxZoomLevel - log(zoomDistance / zoomCoefficient) / log(2.0)); - qDebug() << "Zoom, tilesphere zoom was : " << sphere.zoomLevel(); - qDebug() << "Zoom level (fractional) would be : " << maxZoomLevel - log2(zoomDistance / zoomCoefficient); - if ((int)zoomLevel != sphere.zoomLevel() && zoomLevel < maxZoomLevel && zoomLevel >= 0) { - sphere.setZoomLevel(int(zoomLevel)); -// sphere.update(*this); - } -} - -// Can be done like this if quaternions ease the animation -//void TileCamera::tiltCamera(double tilt, QQuaternion = QQuaternion()) { -// { -// if (!quaternion.isIdentity()) // use quaternion. However, keeping track of 'tilt_' needs to be done -// ... -// else // use tilt angle - -void TileCamera::tiltCamera(const SphereGeometry& sphere, double tilt) -{ - Q_ASSERT(!qIsNaN(tilt)); - camera_->rotateCenter(camera_->tilt(tilt)); - // Don't fall through the sphere surface - if (camera_->eye().length() - sphere.radius() < 0.0) { - qDebug() << "Camera tilt safestop, would go through earth."; - camera_->rotateCenter(camera_->tilt(-tilt)); - } -} - -void TileCamera::rollCamera(const SphereGeometry& sphere, double roll) -{ - Q_UNUSED(sphere); - Q_ASSERT(!qIsNaN(roll)); - camera_->rotateCenter(camera_->roll(roll)); -} - -void TileCamera::panCamera(const SphereGeometry& sphere, double pan) -{ - Q_ASSERT(!qIsNaN(pan)); - camera_->rotateCenter(camera_->pan(pan)); - if (camera_->eye().length() - sphere.radius() < 0.0) { - qDebug() << "Camera pan safety stop, would go through earth."; - camera_->rotateCenter(camera_->pan(-pan)); - } -} - -QGLCamera* TileCamera::camera() const -{ - return camera_; -} - -QVector3D TileCamera::eye() const -{ - return camera_->eye(); -} - -QVector3D TileCamera::view(double x, double y) const -{ - double fov = atan(camera_->viewSize().height() / (2 * camera_->nearPlane())); - - double hf = 2 * tan(fov) * camera_->farPlane(); - double wf = hf * aspectRatio_; - - QVector3D p = camera_->eye(); - QVector3D d = camera_->center() - camera_->eye(); - d.normalize(); - - QVector3D up = camera_->upVector(); - up.normalize(); - - QVector3D right = QVector3D::normal(d, up); - - double x1 = qMin(qMax(x, 0.0), 1.0) - 0.5; - double y1 = qMin(qMax(y, 0.0), 1.0) - 0.5; - - QVector3D c = d * camera_->farPlane(); - c += up * hf * y1; - c += right * wf * x1; - - return c.normalized(); -} - diff --git a/src/location/mapsgl/tilecamera.h b/src/location/mapsgl/tilecamera.h deleted file mode 100644 index 4c40743f..00000000 --- a/src/location/mapsgl/tilecamera.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef TILECAMERA_H -#define TILECAMERA_H - -#include "qglobal.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - - - -class SphereGeometry; -class QGLCamera; -class QGLSceneNode; -class QVector3D; - -class Q_LOCATION_EXPORT TileCamera -{ -public: - TileCamera(); - ~TileCamera(); - - enum DetailPreference { - DetailPreferenceNear, - DetailPreferenceCenter - }; - - // Reset the camera (to look at lon,lat, with given distance, tilt etc.) - void setCamera(const SphereGeometry &sphere, - double latitude, - double longitude, - double distance, - double bearing, - double tilt, - double aspectRatio); - void tiltCamera(const SphereGeometry& sphere, double tilt); - void rollCamera(const SphereGeometry& sphere, double roll); - void panCamera(const SphereGeometry& sphere, double pan); - void rotateCamera(const SphereGeometry& sphere, double up, double right); - void zoomCamera(SphereGeometry& sphere, double factor, DetailPreference detailPreference = DetailPreferenceNear); - - QGLCamera* camera() const; - - QVector3D eye() const; - QVector3D view(double x, double y) const; - -private: - double latitude_; - double longitude_; - double distance_; - double bearing_; - double tilt_; - double zoom_; - double aspectRatio_; - QGLCamera* camera_; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // TILECAMERA_H diff --git a/src/location/mapsgl/tilespec.cpp b/src/location/mapsgl/tilespec.cpp deleted file mode 100644 index 951a2266..00000000 --- a/src/location/mapsgl/tilespec.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "tilespec.h" -#include "tilespec_p.h" -#include <QDebug> - -QT_BEGIN_NAMESPACE - -TileSpec::TileSpec() - : d_ptr(new TileSpecPrivate()) {} - -TileSpec::TileSpec(const QString &plugin, int mapId, int zoom, int x, int y) - : d_ptr(new TileSpecPrivate(plugin, mapId, zoom, x, y)) {} - -TileSpec::TileSpec(const TileSpec &other) - : d_ptr(new TileSpecPrivate(*(other.d_ptr))) {} - -TileSpec::~TileSpec() { - delete d_ptr; -} - -TileSpec& TileSpec::operator = (const TileSpec &other) -{ - d_ptr->operator=(*(other.d_ptr)); - return *this; -} - -QString TileSpec::plugin() const -{ - Q_D(const TileSpec); - return d->plugin_; -} - -void TileSpec::setZoom(int zoom) -{ - Q_D(TileSpec); - d->zoom_ = zoom; -} - -int TileSpec::zoom() const -{ - Q_D(const TileSpec); - return d->zoom_; -} - -void TileSpec::setX(int x) -{ - Q_D(TileSpec); - d->x_ = x; -} - -int TileSpec::x() const -{ - Q_D(const TileSpec); - return d->x_; -} - -void TileSpec::setY(int y) -{ - Q_D(TileSpec); - d->y_ = y; -} - -int TileSpec::y() const -{ - Q_D(const TileSpec); - return d->y_; -} - -void TileSpec::setMapId(int mapId) -{ - Q_D(TileSpec); - d->mapId_ = mapId; -} - -int TileSpec::mapId() const -{ - Q_D(const TileSpec); - return d->mapId_; -} - -bool TileSpec::operator == (const TileSpec &rhs) const -{ - return (d_ptr->operator == (*(rhs.d_ptr))); -} - -bool TileSpec::operator < (const TileSpec &rhs) const -{ - return (d_ptr->operator < (*(rhs.d_ptr))); -} - -unsigned int qHash(const TileSpec &spec) -{ - unsigned int result = (qHash(spec.plugin()) * 13) % 31; - result += ((spec.mapId() * 17) % 31) << 5; - result += ((spec.zoom() * 19) % 31) << 10; - result += ((spec.x() * 23) % 31) << 15; - result += ((spec.y() * 29) % 31) << 20; - return result; -} - -QDebug operator<< (QDebug dbg, const TileSpec &spec) -{ - dbg << spec.plugin() << spec.mapId() << spec.zoom() << spec.x() << spec.y(); - return dbg; -} - -TileSpecPrivate::TileSpecPrivate() - : mapId_(0), - zoom_(-1), - x_(-1), - y_(-1) {} - -TileSpecPrivate::TileSpecPrivate(const TileSpecPrivate &other) - : plugin_(other.plugin_), - mapId_(other.mapId_), - zoom_(other.zoom_), - x_(other.x_), - y_(other.y_) {} - -TileSpecPrivate::TileSpecPrivate(const QString &plugin, int mapId, int zoom, int x, int y) - : plugin_(plugin), - mapId_(mapId), - zoom_(zoom), - x_(x), - y_(y) {} - -TileSpecPrivate::~TileSpecPrivate() {} - -TileSpecPrivate& TileSpecPrivate::operator = (const TileSpecPrivate &other) -{ - plugin_ = other.plugin_; - mapId_ = other.mapId_; - zoom_ = other.zoom_; - x_ = other.x_; - y_ = other.y_; - return *this; -} - -bool TileSpecPrivate::operator == (const TileSpecPrivate &rhs) const -{ - if (plugin_ != rhs.plugin_) - return false; - - if (mapId_ != rhs.mapId_) - return false; - - if (zoom_ != rhs.zoom_) - return false; - - if (x_ != rhs.x_) - return false; - - if (y_ != rhs.y_) - return false; - - return true; -} - -bool TileSpecPrivate::operator < (const TileSpecPrivate &rhs) const -{ - if (plugin_ < rhs.plugin_) - return true; - if (plugin_ > rhs.plugin_) - return false; - - if (zoom_ < rhs.zoom_) - return true; - if (zoom_ > rhs.zoom_) - return false; - - if (x_ < rhs.x_) - return true; - if (x_ > rhs.x_) - return false; - - return (y_ < rhs.y_); -} - -QT_END_NAMESPACE diff --git a/src/location/mapsgl/tilespec.h b/src/location/mapsgl/tilespec.h deleted file mode 100644 index 9b14a50b..00000000 --- a/src/location/mapsgl/tilespec.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef TILESPEC_H -#define TILESPEC_H - -#include <QtLocation/qlocationglobal.h> -#include <QtCore/QMetaType> -#include <QString> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class TileSpecPrivate; - -class Q_LOCATION_EXPORT TileSpec -{ -public: - TileSpec(); - TileSpec(const TileSpec &other); - TileSpec(const QString &plugin, int mapId, int zoom, int x, int y); - ~TileSpec(); - - TileSpec& operator = (const TileSpec &other); - - QString plugin() const; - - void setZoom(int zoom); - int zoom() const; - - void setX(int x); - int x() const; - - void setY(int y); - int y() const; - - void setMapId(int mapId); - int mapId() const; - - bool operator == (const TileSpec &rhs) const; - bool operator < (const TileSpec &rhs) const; - -private: - TileSpecPrivate *d_ptr; - Q_DECLARE_PRIVATE(TileSpec) -}; - -unsigned int qHash(const TileSpec &spec); - -QDebug operator<<(QDebug, const TileSpec &); - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(TileSpec) - -QT_END_HEADER - -#endif // TILESPEC_H diff --git a/src/location/mapsgl/tilespec_p.h b/src/location/mapsgl/tilespec_p.h deleted file mode 100644 index 828a8adb..00000000 --- a/src/location/mapsgl/tilespec_p.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef TILESPEC_P_H -#define TILESPEC_P_H - -#include <QString> - -QT_BEGIN_NAMESPACE - -class TileSpecPrivate -{ -public: - TileSpecPrivate(); - TileSpecPrivate(const TileSpecPrivate &other); - TileSpecPrivate(const QString &plugin, int mapId, int zoom, int x, int y); - ~TileSpecPrivate(); - - TileSpecPrivate& operator = (const TileSpecPrivate &other); - - bool operator == (const TileSpecPrivate &rhs) const; - bool operator < (const TileSpecPrivate &rhs) const; - - QString plugin_; - int mapId_; - int zoom_; - int x_; - int y_; -}; - -QT_END_NAMESPACE - -#endif // TILESPEC_P_H |