Commit 47b00f2f authored by dogmaphobic's avatar dogmaphobic

Google Maps Qt Geoservices plugin.

parent a2e9481b
load(qt_build_config)
MODULE_VERSION = 5.4.1
TARGET = qtgeoservices_google
CONFIG += static
QT += location-private positioning-private network
PLUGIN_TYPE = geoservices
PLUGIN_CLASS_NAME = QGeoServiceProviderFactoryGoogle
load(qt_plugin)
INCLUDEPATH += $$QT.location.includes
HEADERS += \
$$PWD/src/qgeoserviceproviderplugingoogle.h \
$$PWD/src/qgeotiledmappingmanagerenginegoogle.h \
$$PWD/src/qgeotilefetchergoogle.h \
$$PWD/src/qgeomapreplygoogle.h \
$$PWD/src/qgeocodingmanagerenginegoogle.h \
$$PWD/src/qgeocodereplygoogle.h
SOURCES += \
$$PWD/src/qgeoserviceproviderplugingoogle.cpp \
$$PWD/src/qgeotiledmappingmanagerenginegoogle.cpp \
$$PWD/src/qgeotilefetchergoogle.cpp \
$$PWD/src/qgeomapreplygoogle.cpp \
$$PWD/src/qgeocodingmanagerenginegoogle.cpp \
$$PWD/src/qgeocodereplygoogle.cpp
OTHER_FILES += \
$$PWD/google_maps_plugin.json
{
"Keys": ["google-maps"],
"Provider": "google",
"Version": 100,
"Experimental": false,
"Features": [
"OnlineMappingFeature",
"OnlineGeocodingFeature",
"ReverseGeocodingFeature"
]
}
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
#include <QtPositioning/QGeoCoordinate>
#include <QtPositioning/QGeoAddress>
#include <QtPositioning/QGeoLocation>
#include <QtPositioning/QGeoRectangle>
#include <unordered_map>
#include "qgeocodereplygoogle.h"
QT_BEGIN_NAMESPACE
enum QGeoCodeTypeGoogle {
GeoCodeTypeUnknown,
StreetAddress, // indicates a precise street address.
Route, // indicates a named route (such as "US 101").
Intersection, // indicates a major intersection, usually of two major roads.
Political, // indicates a political entity. Usually, this type indicates a polygon of some civil administration.
Country, // indicates the national political entity, and is typically the highest order type returned by the Geocoder.
AdministrativeAreaLevel1, // indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states.
AdministrativeAreaLevel2, // indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties.
AdministrativeAreaLevel3, // indicates a third-order civil entity below the country level. This type indicates a minor civil division.
ColloquialArea, // indicates a commonly-used alternative name for the entity.
Locality, // indicates an incorporated city or town political entity.
Sublocality, // indicates a first-order civil entity below a locality. For some locations may receive one of the additional types: sublocality_level_1 through to sublocality_level_5. Each sublocality level is a civil entity. Larger numbers indicate a smaller geographic area.
SublocalityLevel1,
SublocalityLevel2,
SublocalityLevel3,
SublocalityLevel4,
SublocalityLevel5,
Neighborhood, // indicates a named neighborhood
Premise, // indicates a named location, usually a building or collection of buildings with a common name
Subpremise, // indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name
PostalCode, // indicates a postal code as used to address postal mail within the country.
NaturalFeature, // indicates a prominent natural feature.
Airport, // indicates an airport.
Park, // indicates a named park.
PointOfInterest, // indicates a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category such as "Empire State Building" or "Statue of Liberty."
Floor, // indicates the floor of a building address.
Establishment, // typically indicates a place that has not yet been categorized.
Parking, // indicates a parking lot or parking structure.
PostBox, // indicates a specific postal box.
PostalTown, // indicates a grouping of geographic areas, such as locality and sublocality, used for mailing addresses in some countries.
RoomIndicates, // the room of a building address.
StreetNumber, // indicates the precise street number.
BusStation, // indicate the location of a bus stop.
TrainStation, // indicate the location of a train stop.
TransitStation, // indicate the location of a public transit stop.
};
class JasonMonger {
public:
JasonMonger();
QSet<int> json2QGeoCodeTypeGoogle(const QJsonArray &types);
private:
int _getCode(const QString &key);
QMap<QString, int> _m;
};
JasonMonger::JasonMonger()
{
_m[QStringLiteral("street_address")] = StreetAddress;
_m[QStringLiteral("route")] = Route;
_m[QStringLiteral("intersection")] = Intersection;
_m[QStringLiteral("political")] = Political;
_m[QStringLiteral("country")] = Country;
_m[QStringLiteral("administrative_area_level_1")] = AdministrativeAreaLevel1;
_m[QStringLiteral("administrative_area_level_2")] = AdministrativeAreaLevel2;
_m[QStringLiteral("administrative_area_level_3")] = AdministrativeAreaLevel3;
_m[QStringLiteral("colloquial_area")] = ColloquialArea;
_m[QStringLiteral("locality")] = Locality;
_m[QStringLiteral("sublocality")] = Sublocality;
_m[QStringLiteral("sublocality_level_1")] = SublocalityLevel1;
_m[QStringLiteral("sublocality_level_2")] = SublocalityLevel2;
_m[QStringLiteral("sublocality_level_3")] = SublocalityLevel3;
_m[QStringLiteral("sublocality_level_4")] = SublocalityLevel4;
_m[QStringLiteral("sublocality_level_5")] = SublocalityLevel5;
_m[QStringLiteral("neighborhood")] = Neighborhood;
_m[QStringLiteral("premise")] = Premise;
_m[QStringLiteral("subpremise")] = Subpremise;
_m[QStringLiteral("postal_code")] = PostalCode;
_m[QStringLiteral("natural_feature")] = NaturalFeature;
_m[QStringLiteral("airport")] = Airport;
_m[QStringLiteral("park")] = Park;
_m[QStringLiteral("point_of_interest")] = PointOfInterest;
_m[QStringLiteral("floor")] = Floor;
_m[QStringLiteral("establishment")] = Establishment;
_m[QStringLiteral("parking")] = Parking;
_m[QStringLiteral("post_box")] = PostBox;
_m[QStringLiteral("postal_town")] = PostalTown;
_m[QStringLiteral("room indicates")] = RoomIndicates;
_m[QStringLiteral("street_number")] = StreetNumber;
_m[QStringLiteral("bus_station")] = BusStation;
_m[QStringLiteral("train_station")] = TrainStation;
_m[QStringLiteral("transit_station")] = TransitStation;
}
int JasonMonger::_getCode(const QString &key) {
return _m.value(key, GeoCodeTypeUnknown);
}
QSet<int> JasonMonger::json2QGeoCodeTypeGoogle(const QJsonArray &types) {
QSet<int> result;
for (int i=0; i<types.size(); ++i) {
result |= _getCode(types[i].toString());
}
return result;
}
JasonMonger kMonger;
QGeoCodeReplyGoogle::QGeoCodeReplyGoogle(QNetworkReply *reply, QObject *parent)
: QGeoCodeReply(parent), m_reply(reply)
{
connect(m_reply, SIGNAL(finished()), this, SLOT(networkReplyFinished()));
connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(networkReplyError(QNetworkReply::NetworkError)));
setLimit(1);
setOffset(0);
}
QGeoCodeReplyGoogle::~QGeoCodeReplyGoogle()
{
if (m_reply)
m_reply->deleteLater();
}
void QGeoCodeReplyGoogle::abort()
{
if (!m_reply)
return;
m_reply->abort();
m_reply->deleteLater();
m_reply = 0;
}
void QGeoCodeReplyGoogle::networkReplyFinished()
{
if (!m_reply)
return;
if (m_reply->error() != QNetworkReply::NoError)
return;
QJsonDocument document = QJsonDocument::fromJson(m_reply->readAll());
QJsonObject object = document.object();
if (object.value(QStringLiteral("status")) != QStringLiteral("OK")) {
QString error = object.value(QStringLiteral("status")).toString();
qWarning() << m_reply->url() << "returned" << error;
setError(QGeoCodeReply::CommunicationError, error);
m_reply->deleteLater();
m_reply = 0;
return;
}
QList<QGeoLocation> locations;
QJsonArray results = object.value(QStringLiteral("results")).toArray();
for (int i=0; i<results.size(); ++i) {
if (!results[i].isObject())
continue;
QJsonObject geocode = results[i].toObject();
QGeoAddress address;
if (geocode.contains(QStringLiteral("formatted_address"))) {
address.setText(geocode.value(QStringLiteral("formatted_address")).toString());
}
if (geocode.contains(QStringLiteral("address_components"))) {
QJsonArray ac = geocode.value(QStringLiteral("address_components")).toArray();
for (int j=0; j<ac.size(); ++j) {
if (!ac[j].isObject())
continue;
QJsonObject c = ac[j].toObject();
if (!c.contains(QStringLiteral("types")))
continue;
QSet<int> types = kMonger.json2QGeoCodeTypeGoogle(c[QStringLiteral("types")].toArray());
QString long_name = c[QStringLiteral("long_name")].toString();
QString short_name = c[QStringLiteral("short_name")].toString();
if (types.contains(Country)) {
address.setCountry(long_name);
address.setCountryCode(short_name);
} else if (types.contains(AdministrativeAreaLevel1)) {
address.setState(long_name);
} else if (types.contains(AdministrativeAreaLevel2)) {
address.setCounty(long_name);
} else if (types.contains(Locality)) {
address.setCity(long_name);
} else if (types.contains(Sublocality)) {
address.setDistrict(long_name);
} else if (types.contains(PostalCode)) {
address.setPostalCode(long_name);
} else if (types.contains(StreetAddress) || types.contains(Route) || types.contains(Intersection)) {
address.setStreet(long_name);
}
}
}
QGeoCoordinate coordinate;
QGeoRectangle boundingBox;
if (geocode.contains(QStringLiteral("geometry"))) {
QJsonObject geom = geocode.value(QStringLiteral("geometry")).toObject();
if (geom.contains(QStringLiteral("location"))) {
QJsonObject location = geom.value(QStringLiteral("location")).toObject();
coordinate.setLatitude(location.value(QStringLiteral("lat")).toDouble());
coordinate.setLongitude(location.value(QStringLiteral("lng")).toDouble());
}
if (geom.contains(QStringLiteral("bounds"))) {
QJsonObject bounds = geom.value(QStringLiteral("bounds")).toObject();
QJsonObject northeast = bounds.value(QStringLiteral("northeast")).toObject();
QJsonObject southwest = bounds.value(QStringLiteral("southwest")).toObject();
QGeoCoordinate topRight(northeast.value(QStringLiteral("lat")).toDouble(),
northeast.value(QStringLiteral("lng")).toDouble());
QGeoCoordinate bottomLeft(southwest.value(QStringLiteral("lat")).toDouble(),
southwest.value(QStringLiteral("lng")).toDouble());
boundingBox.setTopRight(topRight);
boundingBox.setBottomLeft(bottomLeft);
}
}
QGeoLocation location;
location.setAddress(address);
location.setCoordinate(coordinate);
location.setBoundingBox(boundingBox);
locations << location;
}
setLocations(locations);
setFinished(true);
m_reply->deleteLater();
m_reply = 0;
}
void QGeoCodeReplyGoogle::networkReplyError(QNetworkReply::NetworkError error)
{
Q_UNUSED(error)
if (!m_reply)
return;
setError(QGeoCodeReply::CommunicationError, m_reply->errorString());
m_reply->deleteLater();
m_reply = 0;
}
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#ifndef QGEOCODEREPLYGOOGLE_H
#define QGEOCODEREPLYGOOGLE_H
#include <QtNetwork/QNetworkReply>
#include <QtLocation/QGeoCodeReply>
QT_BEGIN_NAMESPACE
class QGeoCodeReplyGoogle : public QGeoCodeReply
{
Q_OBJECT
public:
explicit QGeoCodeReplyGoogle(QNetworkReply *reply, QObject *parent = 0);
~QGeoCodeReplyGoogle();
void abort();
private Q_SLOTS:
void networkReplyFinished();
void networkReplyError(QNetworkReply::NetworkError error);
private:
QNetworkReply *m_reply;
};
QT_END_NAMESPACE
#endif // QGEOCODEREPLYGOOGLE_H
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#include <QtCore/QVariantMap>
#include <QtCore/QUrl>
#include <QtCore/QUrlQuery>
#include <QtCore/QLocale>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtPositioning/QGeoCoordinate>
#include <QtPositioning/QGeoAddress>
#include <QtPositioning/QGeoShape>
#include <QtPositioning/QGeoRectangle>
#include "qgeocodingmanagerenginegoogle.h"
#include "qgeocodereplygoogle.h"
QT_BEGIN_NAMESPACE
static QString addressToQuery(const QGeoAddress &address)
{
return address.street() + QStringLiteral(", ") +
address.district() + QStringLiteral(", ") +
address.city() + QStringLiteral(", ") +
address.state() + QStringLiteral(", ") +
address.country();
}
static QString boundingBoxToLtrb(const QGeoRectangle &rect)
{
return QString::number(rect.topLeft().longitude()) + QLatin1Char(',') +
QString::number(rect.topLeft().latitude()) + QLatin1Char(',') +
QString::number(rect.bottomRight().longitude()) + QLatin1Char(',') +
QString::number(rect.bottomRight().latitude());
}
QGeoCodingManagerEngineGoogle::QGeoCodingManagerEngineGoogle(
const QVariantMap &parameters,
QGeoServiceProvider::Error *error,
QString *errorString)
: QGeoCodingManagerEngine(parameters), m_networkManager(new QNetworkAccessManager(this))
{
if (parameters.contains(QStringLiteral("useragent")))
m_userAgent = parameters.value(QStringLiteral("useragent")).toString().toLatin1();
else
m_userAgent = "Qt Location based application";
*error = QGeoServiceProvider::NoError;
errorString->clear();
}
QGeoCodingManagerEngineGoogle::~QGeoCodingManagerEngineGoogle()
{
}
QGeoCodeReply *QGeoCodingManagerEngineGoogle::geocode(const QGeoAddress &address, const QGeoShape &bounds)
{
return geocode(addressToQuery(address), -1, -1, bounds);
}
QGeoCodeReply *QGeoCodingManagerEngineGoogle::geocode(const QString &address, int limit, int offset, const QGeoShape &bounds)
{
Q_UNUSED(limit);
Q_UNUSED(offset);
QNetworkRequest request;
request.setRawHeader("User-Agent", m_userAgent);
QUrl url(QStringLiteral("http://maps.googleapis.com/maps/api/geocode/json"));
QUrlQuery query;
query.addQueryItem(QStringLiteral("sensor"), QStringLiteral("false"));
query.addQueryItem(QStringLiteral("language"), locale().name().left(2));
query.addQueryItem(QStringLiteral("address"), address);
if (bounds.type() == QGeoShape::RectangleType) {
query.addQueryItem(QStringLiteral("bounds"), boundingBoxToLtrb(bounds));
}
url.setQuery(query);
request.setUrl(url);
qDebug() << url;
QNetworkReply *reply = m_networkManager->get(request);
reply->setParent(0);
QGeoCodeReplyGoogle *geocodeReply = new QGeoCodeReplyGoogle(reply);
connect(geocodeReply, SIGNAL(finished()), this, SLOT(replyFinished()));
connect(geocodeReply, SIGNAL(error(QGeoCodeReply::Error,QString)),
this, SLOT(replyError(QGeoCodeReply::Error,QString)));
return geocodeReply;
}
QGeoCodeReply *QGeoCodingManagerEngineGoogle::reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds)
{
Q_UNUSED(bounds)
QNetworkRequest request;
request.setRawHeader("User-Agent", m_userAgent);
QUrl url(QStringLiteral("http://maps.googleapis.com/maps/api/geocode/json"));
QUrlQuery query;
query.addQueryItem(QStringLiteral("sensor"), QStringLiteral("false"));
query.addQueryItem(QStringLiteral("language"), locale().name().left(2));
query.addQueryItem(QStringLiteral("latlng"), QStringLiteral("%1,%2")
.arg(coordinate.latitude())
.arg(coordinate.longitude()));
url.setQuery(query);
request.setUrl(url);
qDebug() << url;
QNetworkReply *reply = m_networkManager->get(request);
reply->setParent(0);
QGeoCodeReplyGoogle *geocodeReply = new QGeoCodeReplyGoogle(reply);
connect(geocodeReply, SIGNAL(finished()), this, SLOT(replyFinished()));
connect(geocodeReply, SIGNAL(error(QGeoCodeReply::Error,QString)),
this, SLOT(replyError(QGeoCodeReply::Error,QString)));
return geocodeReply;
}
void QGeoCodingManagerEngineGoogle::replyFinished()
{
QGeoCodeReply *reply = qobject_cast<QGeoCodeReply *>(sender());
if (reply)
emit finished(reply);
}
void QGeoCodingManagerEngineGoogle::replyError(QGeoCodeReply::Error errorCode, const QString &errorString)
{
QGeoCodeReply *reply = qobject_cast<QGeoCodeReply *>(sender());
if (reply)
emit error(reply, errorCode, errorString);
}
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#ifndef QGEOCODINGMANAGERENGINEGOOGLE_H
#define QGEOCODINGMANAGERENGINEGOOGLE_H
#include <QtLocation/QGeoServiceProvider>
#include <QtLocation/QGeoCodingManagerEngine>
#include <QtLocation/QGeoCodeReply>
QT_BEGIN_NAMESPACE
class QNetworkAccessManager;
class QGeoCodingManagerEngineGoogle : public QGeoCodingManagerEngine
{
Q_OBJECT
public:
QGeoCodingManagerEngineGoogle(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString);
~QGeoCodingManagerEngineGoogle();
QGeoCodeReply* geocode (const QGeoAddress &address, const QGeoShape &bounds) Q_DECL_OVERRIDE;
QGeoCodeReply* geocode (const QString &address, int limit, int offset, const QGeoShape &bounds) Q_DECL_OVERRIDE;
QGeoCodeReply* reverseGeocode (const QGeoCoordinate &coordinate, const QGeoShape &bounds) Q_DECL_OVERRIDE;
private Q_SLOTS:
void replyFinished ();
void replyError (QGeoCodeReply::Error errorCode, const QString &errorString);
private:
QNetworkAccessManager *m_networkManager;
QByteArray m_userAgent;
};
QT_END_NAMESPACE
#endif // QGEOCODINGMANAGERENGINEGOOGLE_H
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#include <QtLocation/private/qgeotilespec_p.h>
#include "qgeomapreplygoogle.h"
QGeoMapReplyGoogle::QGeoMapReplyGoogle(QNetworkReply *reply, const QGeoTileSpec &spec, QObject *parent)
: QGeoTiledMapReply(spec, parent)
, m_reply(reply)
{
connect(m_reply, SIGNAL(finished()), this, SLOT(networkReplyFinished()));
connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(networkReplyError(QNetworkReply::NetworkError)));
connect(m_reply, SIGNAL(destroyed()), this, SLOT(replyDestroyed()));
}
QGeoMapReplyGoogle::~QGeoMapReplyGoogle()
{
if (m_reply) {
m_reply->deleteLater();
m_reply = 0;
}
}
void QGeoMapReplyGoogle::abort()
{
if (!m_reply)
return;
m_reply->abort();
}
QNetworkReply *QGeoMapReplyGoogle::networkReply() const
{
return m_reply;
}
void QGeoMapReplyGoogle::replyDestroyed()
{
m_reply = 0;
}
void QGeoMapReplyGoogle::networkReplyFinished()
{
if (!m_reply)
return;
if (m_reply->error() != QNetworkReply::NoError)
return;
QByteArray a = m_reply->readAll();
setMapImageData(a);
if(tileSpec().mapId() > 0 && tileSpec().mapId() < 5)
setMapImageFormat("png");
else
qWarning("Unknown map id %d", tileSpec().mapId());
setFinished(true);
m_reply->deleteLater();
m_reply = 0;
}
void QGeoMapReplyGoogle::networkReplyError(QNetworkReply::NetworkError error)
{
if (!m_reply)
return;
if (error != QNetworkReply::OperationCanceledError)
setError(QGeoTiledMapReply::CommunicationError, m_reply->errorString());
setFinished(true);
m_reply->deleteLater();
m_reply = 0;
}
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#ifndef QGEOMAPREPLYGOOGLE_H
#define QGEOMAPREPLYGOOGLE_H
#include <QtNetwork/QNetworkReply>
#include <QtLocation/private/qgeotiledmapreply_p.h>
QT_BEGIN_NAMESPACE
class QGeoMapReplyGoogle : public QGeoTiledMapReply
{
Q_OBJECT
public:
explicit QGeoMapReplyGoogle(QNetworkReply *reply, const QGeoTileSpec &spec, QObject *parent = 0);
~QGeoMapReplyGoogle();
void abort();
QNetworkReply *networkReply() const;
private Q_SLOTS:
void replyDestroyed ();
void networkReplyFinished ();
void networkReplyError (QNetworkReply::NetworkError error);
private:
QNetworkReply* m_reply;
};
QT_END_NAMESPACE
#endif // QGEOMAPREPLYGOOGLE_H
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#include <QtLocation/private/qgeotiledmappingmanagerengine_p.h>
#include "qdebug.h"
#include "qgeoserviceproviderplugingoogle.h"
#include "qgeotiledmappingmanagerenginegoogle.h"
#include "qgeocodingmanagerenginegoogle.h"
QT_BEGIN_NAMESPACE
QGeoCodingManagerEngine *QGeoServiceProviderFactoryGoogle::createGeocodingManagerEngine(
const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const
{
return new QGeoCodingManagerEngineGoogle(parameters, error, errorString);
}
QGeoMappingManagerEngine *QGeoServiceProviderFactoryGoogle::createMappingManagerEngine(
const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const
{
return new QGeoTiledMappingManagerEngineGoogle(parameters, error, errorString);
}
QGeoRoutingManagerEngine *QGeoServiceProviderFactoryGoogle::createRoutingManagerEngine(
const QVariantMap &, QGeoServiceProvider::Error *, QString *) const
{
// Not implemented for QGC
return NULL;
}
QPlaceManagerEngine *QGeoServiceProviderFactoryGoogle::createPlaceManagerEngine(
const QVariantMap &, QGeoServiceProvider::Error *, QString *) const
{
// Not implemented for QGC
return NULL;
}
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#ifndef QGEOSERVICEPROVIDER_GOOGLE_H
#define QGEOSERVICEPROVIDER_GOOGLE_H
#include <QtCore/QObject>
#include <QtLocation/QGeoServiceProviderFactory>
QT_BEGIN_NAMESPACE
class QGeoServiceProviderFactoryGoogle: public QObject, public QGeoServiceProviderFactory
{
Q_OBJECT
Q_INTERFACES(QGeoServiceProviderFactory)
Q_PLUGIN_METADATA(IID "org.qt-project.qt.geoservice.serviceproviderfactory/5.0" FILE "google_maps_plugin.json")
public:
QGeoCodingManagerEngine* createGeocodingManagerEngine(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const;
QGeoMappingManagerEngine* createMappingManagerEngine(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const;
QGeoRoutingManagerEngine* createRoutingManagerEngine(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const;
QPlaceManagerEngine* createPlaceManagerEngine(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const;
};
QT_END_NAMESPACE
#endif // QGEOSERVICEPROVIDER_GOOGLE_H
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#include <QtLocation/private/qgeocameracapabilities_p.h>
#include <QtLocation/private/qgeomaptype_p.h>
#include <QtLocation/private/qgeotiledmapdata_p.h>
#include <QDir>
#include <QStandardPaths>
#include "qgeotiledmappingmanagerenginegoogle.h"
#include "qgeotilefetchergoogle.h"
QT_BEGIN_NAMESPACE
QGeoTiledMappingManagerEngineGoogle::QGeoTiledMappingManagerEngineGoogle(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)
: QGeoTiledMappingManagerEngine()
{
QGeoCameraCapabilities cameraCaps;
cameraCaps.setMinimumZoomLevel(0.0);
cameraCaps.setMaximumZoomLevel(22.0);
setCameraCapabilities(cameraCaps);
setTileSize(QSize(256, 256));
QList<QGeoMapType> mapTypes;
mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("Street Map"), tr("Google street map"), false, false, 1);
mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, tr("Satellite Map"),tr("Google satellite map"), false, false, 2);
mapTypes << QGeoMapType(QGeoMapType::TerrainMap, tr("Terrain Map"), tr("Google terrain map"), false, false, 3);
mapTypes << QGeoMapType(QGeoMapType::HybridMap, tr("Hybrid Map"), tr("Google hybrid map"), false, false, 4);
setSupportedMapTypes(mapTypes);
QGeoTileFetcherGoogle *tileFetcher = new QGeoTileFetcherGoogle(this);
if (parameters.contains(QStringLiteral("useragent"))) {
const QByteArray ua = parameters.value(QStringLiteral("useragent")).toString().toLatin1();
tileFetcher->setUserAgent(ua);
} else
// QGC Default
tileFetcher->setUserAgent("qgroundcontrol.org");
setTileFetcher(tileFetcher);
QString cacheDir;
if (parameters.contains(QStringLiteral("mapping.cache.directory")))
cacheDir = parameters.value(QStringLiteral("mapping.cache.directory")).toString();
else {
cacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/QGCMapCache");
if(!QDir::root().mkpath(cacheDir)) {
qWarning() << "Could not create mapping disk cache directory: " << cacheDir;
cacheDir = QDir::homePath() + QLatin1String("/.qgcmapscache/");
}
}
if(!QDir::root().mkpath(cacheDir))
{
qWarning() << "Could not create mapping disk cache directory: " << cacheDir;
cacheDir.clear();
} else {
qDebug() << "Mapping cache directory:" << cacheDir;
}
QGeoTileCache *tileCache = createTileCacheWithDir(cacheDir);
int cacheLimit = 0;
if (parameters.contains(QStringLiteral("mapping.cache.disk.size"))) {
bool ok = false;
cacheLimit = parameters.value(QStringLiteral("mapping.cache.disk.size")).toString().toInt(&ok);
if (!ok)
cacheLimit = 0;
}
if(!cacheLimit)
// QGC Default
cacheLimit = 1024 * 1024 * 1024;
tileCache->setMaxDiskUsage(cacheLimit);
qDebug() << "Disk caching limit:" << cacheLimit;
cacheLimit = 0;
if (parameters.contains(QStringLiteral("mapping.cache.memory.size"))) {
bool ok = false;
cacheLimit = parameters.value(QStringLiteral("mapping.cache.memory.size")).toString().toInt(&ok);
if (!ok)
cacheLimit = 0;
}
if(!cacheLimit)
// QGC Default
cacheLimit = 10 * 1024 * 1024;
tileCache->setMaxMemoryUsage(cacheLimit);
qDebug() << "Memory caching limit:" << cacheLimit;
cacheLimit = 0;
if (parameters.contains(QStringLiteral("mapping.cache.texture.size"))) {
bool ok = false;
cacheLimit = parameters.value(QStringLiteral("mapping.cache.texture.size")).toString().toInt(&ok);
if (!ok)
cacheLimit = 0;
}
if(!cacheLimit)
// QGC Default
cacheLimit = 10 * 1024 * 1024;
tileCache->setExtraTextureUsage(cacheLimit);
*error = QGeoServiceProvider::NoError;
errorString->clear();
}
QGeoTiledMappingManagerEngineGoogle::~QGeoTiledMappingManagerEngineGoogle()
{
}
QGeoMapData *QGeoTiledMappingManagerEngineGoogle::createMapData()
{
return new QGeoTiledMapData(this, 0);
}
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#ifndef QGEOTILEDMAPPINGMANAGERENGINEGOOGLE_H
#define QGEOTILEDMAPPINGMANAGERENGINEGOOGLE_H
#include <QtLocation/QGeoServiceProvider>
#include <QtLocation/private/qgeotiledmappingmanagerengine_p.h>
QT_BEGIN_NAMESPACE
class QGeoTiledMappingManagerEngineGoogle : public QGeoTiledMappingManagerEngine
{
Q_OBJECT
public:
QGeoTiledMappingManagerEngineGoogle(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString);
~QGeoTiledMappingManagerEngineGoogle();
QGeoMapData *createMapData();
};
QT_END_NAMESPACE
#endif // QGEOTILEDMAPPINGMANAGERENGINEGOOGLE_H
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#include "qgeotilefetchergoogle.h"
#include "qgeomapreplygoogle.h"
#include <QtCore/QLocale>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtLocation/private/qgeotilespec_p.h>
QT_BEGIN_NAMESPACE
QGeoTileFetcherGoogle::QGeoTileFetcherGoogle(QGeoTiledMappingManagerEngine *parent)
: QGeoTileFetcher(parent)
, m_networkManager(new QNetworkAccessManager(this))
, m_userAgent("Qt Application")
{
}
void QGeoTileFetcherGoogle::setUserAgent(const QByteArray &userAgent)
{
m_userAgent = userAgent;
}
QGeoTiledMapReply *QGeoTileFetcherGoogle::getTileImage(const QGeoTileSpec &spec)
{
QNetworkRequest request;
request.setRawHeader("User-Agent", m_userAgent);
QString url;
if (spec.mapId() == 1) {
url = QStringLiteral("http://mt1.google.com/vt/lyrs=m");
} else if (spec.mapId() == 2) {
url = QStringLiteral("http://mt1.google.com/vt/lyrs=s");
} else if (spec.mapId() == 3) {
url = QStringLiteral("http://mt1.google.com/vt/lyrs=p");
} else if (spec.mapId() == 4) {
url = QStringLiteral(" http://mt1.google.com/vt/lyrs=h");
} else {
qWarning("Unknown map id %d\n", spec.mapId());
url = QStringLiteral("http://mt1.google.com/vt/lyrs=m");
}
url += QStringLiteral("&x=%1&y=%2&z=%3")
.arg(spec.x())
.arg(spec.y())
.arg(spec.zoom());
QStringList langs = QLocale::system().uiLanguages();
if (langs.length() > 0) {
url += QStringLiteral("&hl=%1").arg(langs[0]);
}
url += QStringLiteral("&scale=2");
QUrl qurl(url);
request.setUrl(qurl);
QNetworkReply *reply = m_networkManager->get(request);
reply->setParent(0);
return new QGeoMapReplyGoogle(reply, spec);
}
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia 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.
**
**
** $QT_END_LICENSE$
**
** 2015.4.4
** Adapted for google maps with the intent of use for QGroundControl
**
** Gus Grubba <mavlink@grubba.com>
**
****************************************************************************/
#ifndef QGEOTILEFETCHERGOOGLE_H
#define QGEOTILEFETCHERGOOGLE_H
#include <QtLocation/private/qgeotilefetcher_p.h>
#include <QtLocation/private/qgeotilecache_p.h>
QT_BEGIN_NAMESPACE
class QGeoTiledMappingManagerEngine;
class QNetworkAccessManager;
class QGeoTileFetcherGoogle : public QGeoTileFetcher
{
Q_OBJECT
public:
explicit QGeoTileFetcherGoogle(QGeoTiledMappingManagerEngine *parent = 0);
void setUserAgent(const QByteArray &userAgent);
private:
QGeoTiledMapReply* getTileImage(const QGeoTileSpec &spec);
QNetworkAccessManager *m_networkManager;
QByteArray m_userAgent;
};
QT_END_NAMESPACE
#endif // QGEOTILEFETCHERGOOGLE_H
......@@ -51,6 +51,7 @@ linux {
macx-clang | macx-llvm {
message("Mac build")
CONFIG += MacBuild
QMAKE_CXXFLAGS += -fvisibility=hidden
} else {
error("Unsupported Mac toolchain, only 64-bit LLVM+clang is supported")
}
......@@ -86,23 +87,57 @@ win32:debug_and_release {
# Setup our build directories
BASEDIR = $${IN_PWD}
BASEDIR = $${IN_PWD}
DebugBuild {
DESTDIR = $${OUT_PWD}/debug
DESTDIR = $${OUT_PWD}/debug
BUILDDIR = $${OUT_PWD}/build-debug
}
ReleaseBuild {
DESTDIR = $${OUT_PWD}/release
DESTDIR = $${OUT_PWD}/release
BUILDDIR = $${OUT_PWD}/build-release
}
OBJECTS_DIR = $${BUILDDIR}/obj
MOC_DIR = $${BUILDDIR}/moc
UI_DIR = $${BUILDDIR}/ui
RCC_DIR = $${BUILDDIR}/rcc
LANGUAGE = C++
MOC_DIR = $${BUILDDIR}/moc
UI_DIR = $${BUILDDIR}/ui
RCC_DIR = $${BUILDDIR}/rcc
LANGUAGE = C++
message(BASEDIR $$BASEDIR DESTDIR $$DESTDIR TARGET $$TARGET)
# Google Maps QtLocation
GOOGLEDIR = $${OUT_PWD}/libs/QtLocationGoogle/plugins/geoservices
LinuxBuild {
LIBS += -L$$GOOGLEDIR -lqtgeoservices_google
PRE_TARGETDEPS += $$GOOGLEDIR/libqtgeoservices_google.a
}
WindowsBuild {
DebugBuild {
LIBS += -L$$GOOGLEDIR -lqtgeoservices_googled
PRE_TARGETDEPS += $$GOOGLEDIR/qtgeoservices_googled.lib
}
ReleaseBuild {
LIBS += -L$$GOOGLEDIR -lqtgeoservices_google
PRE_TARGETDEPS += $$GOOGLEDIR/qtgeoservices_google.lib
}
}
MacBuild {
DebugBuild {
LIBS += -L$$GOOGLEDIR -lqtgeoservices_google_debug
PRE_TARGETDEPS += $$GOOGLEDIR/libqtgeoservices_google_debug.a
}
ReleaseBuild {
LIBS += -L$$GOOGLEDIR -lqtgeoservices_google
PRE_TARGETDEPS += $$GOOGLEDIR/libqtgeoservices_google.a
}
}
# Qt configuration
CONFIG += qt \
thread
......
# -------------------------------------------------
# QGroundControl - Micro Air Vehicle Groundstation
# Please see our website at <http://qgroundcontrol.org>
# Maintainer:
# Lorenz Meier <lm@inf.ethz.ch>
# (c) 2009-2015 QGroundControl Developers
# This file is part of the open groundstation project
# QGroundControl is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# QGroundControl is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with QGroundControl. If not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------------
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = libs/QtLocationGoogle
SUBDIRS += ./qgcsystem.pro
qgcsystem.depends = QtLocationGoogle
......@@ -101,6 +101,14 @@ int main(int argc, char *argv[])
// anyway to silence the debug output.
qRegisterMetaType<QSerialPort::SerialPortError>();
qRegisterMetaType<QAbstractSocket::SocketError>();
// We statically link to the google QtLocation plugin
#ifdef Q_OS_WIN
// In Windows, the compiler doesn't see the use of the class created by Q_IMPORT_PLUGIN
#pragma warning( disable : 4930 4101 )
#endif
Q_IMPORT_PLUGIN(QGeoServiceProviderFactoryGoogle)
bool runUnitTests = false; // Run unit tests
......
......@@ -40,24 +40,31 @@ Rectangle {
property real roll: isNaN(flightDisplay.roll) ? 0 : flightDisplay.roll
property real pitch: isNaN(flightDisplay.pitch) ? 0 : flightDisplay.pitch
function getBool(value) {
return value === '0' ? false : true;
}
function setBool(value) {
return value ? "1" : "0";
}
Component.onCompleted:
{
//mapBackground.visible = flightDisplay.loadSetting("enableMapBackground", false);
//mapBackground.alwaysNorth = flightDisplay.loadSetting("mapAlwaysNorth", false);
attitudeWidget.visible = flightDisplay.loadSetting("enableattitudeWidget", true);
//attitudeWidget.displayBackground = flightDisplay.loadSetting("displayRollPitchBackground", true);
pitchWidget.visible = flightDisplay.loadSetting("enablepitchWidget", true);
altitudeWidget.visible = flightDisplay.loadSetting("enablealtitudeWidget", true);
speedWidget.visible = flightDisplay.loadSetting("enablespeedWidget", true);
compassIndicator.visible = flightDisplay.loadSetting("enableCompassIndicator", true);
currentSpeed.showAirSpeed = flightDisplay.loadSetting("showAirSpeed", true);
currentSpeed.showGroundSpeed = flightDisplay.loadSetting("showGroundSpeed", true);
currentAltitude.showClimbRate = flightDisplay.loadSetting("showCurrentClimbRate", true);
currentAltitude.showAltitude = flightDisplay.loadSetting("showCurrentAltitude", true);
//mapTypeMenu.update();
mapBackground.visible = getBool(flightDisplay.loadSetting("showMapBackground", "0"));
mapBackground.alwaysNorth = getBool(flightDisplay.loadSetting("mapAlwaysPointsNorth", "0"));
attitudeWidget.visible = getBool(flightDisplay.loadSetting("showAttitudeWidget", "1"));
attitudeWidget.displayBackground = getBool(flightDisplay.loadSetting("showAttitudeBackground", "1"));
pitchWidget.visible = getBool(flightDisplay.loadSetting("showPitchWidget", "1"));
altitudeWidget.visible = getBool(flightDisplay.loadSetting("showAltitudeWidget", "1"));
speedWidget.visible = getBool(flightDisplay.loadSetting("showSpeedWidget", "1"));
compassIndicator.visible = getBool(flightDisplay.loadSetting("showCompassIndicator", "1"));
currentSpeed.showAirSpeed = getBool(flightDisplay.loadSetting("showCurrentAirSpeed", "1"));
currentSpeed.showGroundSpeed = getBool(flightDisplay.loadSetting("showCurrentGroundSpeed", "1"));
currentAltitude.showClimbRate = getBool(flightDisplay.loadSetting("showCurrentClimbRate", "1"));
currentAltitude.showAltitude = getBool(flightDisplay.loadSetting("showCurrentAltitude", "1"));
mapTypeMenu.update();
}
/*
Rectangle {
id: windowBackground
anchors.fill: parent
......@@ -66,34 +73,6 @@ Rectangle {
color: Qt.hsla(0.25, 0.5, 0.45)
z: 0
}
*/
/*
Menu {
id: mapTypeMenu
function setCurrentMap(map) {
for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
if (map === mapBackground.mapItem.supportedMapTypes[i].name) {
mapBackground.mapItem.activeMapType = mapBackground.mapItem.supportedMapTypes[i]
return;
}
}
}
function addMap(map) {
var mItem = mapTypeMenu.addItem(map);
var menuSlot = function() {setCurrentMap(map);};
mItem.triggered.connect(menuSlot);
}
function update() {
clear()
for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
addMap(mapBackground.mapItem.supportedMapTypes[i].name);
}
if (mapBackground.mapItem.supportedMapTypes.length > 0)
setCurrentMap(mapBackground.mapItem.activeMapType.name);
}
}
*/
Menu {
id: contextMenu
......@@ -105,11 +84,10 @@ Rectangle {
onTriggered:
{
attitudeWidget.visible = !attitudeWidget.visible;
flightDisplay.saveSetting("enableattitudeWidget", attitudeWidget.visible);
flightDisplay.saveSetting("showAttitudeWidget", setBool(attitudeWidget.visible));
}
}
/*
MenuItem {
text: "Display Attitude Background"
checkable: true
......@@ -117,10 +95,9 @@ Rectangle {
onTriggered:
{
attitudeWidget.displayBackground = !attitudeWidget.displayBackground;
flightDisplay.saveSetting("displayRollPitchBackground", attitudeWidget.displayBackground);
flightDisplay.saveSetting("showAttitudeBackground", setBool(attitudeWidget.displayBackground));
}
}
*/
MenuItem {
text: "Pitch Indicator"
......@@ -129,7 +106,7 @@ Rectangle {
onTriggered:
{
pitchWidget.visible = !pitchWidget.visible;
flightDisplay.saveSetting("enablepitchWidget", pitchWidget.visible);
flightDisplay.saveSetting("showPitchWidget", setBool(pitchWidget.visible));
}
}
......@@ -140,7 +117,7 @@ Rectangle {
onTriggered:
{
altitudeWidget.visible = !altitudeWidget.visible;
flightDisplay.saveSetting("enablealtitudeWidget", altitudeWidget.visible);
flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
}
}
......@@ -151,7 +128,7 @@ Rectangle {
onTriggered:
{
currentAltitude.showAltitude = !currentAltitude.showAltitude;
flightDisplay.saveSetting("showCurrentAltitude", currentAltitude.showAltitude);
flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
}
}
......@@ -162,7 +139,7 @@ Rectangle {
onTriggered:
{
currentAltitude.showClimbRate = !currentAltitude.showClimbRate;
flightDisplay.saveSetting("showCurrentClimbRate", currentAltitude.showClimbRate);
flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
}
}
......@@ -173,7 +150,7 @@ Rectangle {
onTriggered:
{
speedWidget.visible = !speedWidget.visible;
flightDisplay.saveSetting("enablespeedWidget", speedWidget.visible);
flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
}
}
......@@ -184,7 +161,7 @@ Rectangle {
onTriggered:
{
currentSpeed.showAirSpeed = !currentSpeed.showAirSpeed;
flightDisplay.saveSetting("showAirSpeed", currentSpeed.showAirSpeed);
flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
}
}
......@@ -195,7 +172,7 @@ Rectangle {
onTriggered:
{
currentSpeed.showGroundSpeed = !currentSpeed.showGroundSpeed;
flightDisplay.saveSetting("showGroundSpeed", currentSpeed.showGroundSpeed);
flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
}
}
......@@ -206,11 +183,10 @@ Rectangle {
onTriggered:
{
compassIndicator.visible = !compassIndicator.visible;
flightDisplay.saveSetting("enableCompassIndicator", compassIndicator.visible);
flightDisplay.saveSetting("showCompassIndicator", setBool(compassIndicator.visible));
}
}
/*
MenuSeparator {}
MenuItem {
......@@ -220,7 +196,7 @@ Rectangle {
onTriggered:
{
mapBackground.visible = !mapBackground.visible;
flightDisplay.saveSetting("enableMapBackground", mapBackground.visible);
flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
}
}
......@@ -231,19 +207,41 @@ Rectangle {
onTriggered:
{
mapBackground.alwaysNorth = !mapBackground.alwaysNorth;
flightDisplay.saveSetting("mapAlwaysNorth", mapBackground.alwaysNorth);
flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
}
}
MenuItem {
text: "Map Type..."
checkable: false
onTriggered:
{
mapTypeMenu.popup();
Menu {
id: mapTypeMenu
title: "Map Type..."
function setCurrentMap(map) {
for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
if (map === mapBackground.mapItem.supportedMapTypes[i].name) {
mapBackground.mapItem.activeMapType = mapBackground.mapItem.supportedMapTypes[i]
flightDisplay.saveSetting("currentMapType", map);
return;
}
}
}
function addMap(map) {
var mItem = mapTypeMenu.addItem(map);
var menuSlot = function() {setCurrentMap(map);};
mItem.triggered.connect(menuSlot);
}
function update() {
clear()
for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
addMap(mapBackground.mapItem.supportedMapTypes[i].name);
}
var map = ''
if (mapBackground.mapItem.supportedMapTypes.length > 0)
map = mapBackground.mapItem.activeMapType.name;
map = flightDisplay.loadSetting("currentMapType", map);
console.log('Set map type: ', map)
if(map != '')
setCurrentMap(map);
}
}
*/
MenuSeparator {}
......@@ -252,35 +250,34 @@ Rectangle {
onTriggered:
{
attitudeWidget.visible = true;
flightDisplay.saveSetting("enableattitudeWidget", attitudeWidget.visible);
flightDisplay.saveSetting("showAttitudeWidget", setBool(attitudeWidget.visible));
attitudeWidget.displayBackground = true;
flightDisplay.saveSetting("displayRollPitchBackground", attitudeWidget.displayBackground);
flightDisplay.saveSetting("showAttitudeBackground", setBool(attitudeWidget.displayBackground));
pitchWidget.visible = true;
flightDisplay.saveSetting("enablepitchWidget", pitchWidget.visible);
flightDisplay.saveSetting("showPitchWidget", setBool(pitchWidget.visible));
altitudeWidget.visible = true;
flightDisplay.saveSetting("enablealtitudeWidget", altitudeWidget.visible);
flightDisplay.saveSetting("showAltitudeWidget", setBool(altitudeWidget.visible));
currentAltitude.showAltitude = true;
flightDisplay.saveSetting("showCurrentAltitude", currentAltitude.showAltitude);
flightDisplay.saveSetting("showCurrentAltitude", setBool(currentAltitude.showAltitude));
currentAltitude.showClimbRate = true;
flightDisplay.saveSetting("showCurrentClimbRate", currentAltitude.showClimbRate);
flightDisplay.saveSetting("showCurrentClimbRate", setBool(currentAltitude.showClimbRate));
speedWidget.visible = true;
flightDisplay.saveSetting("enablespeedWidget", speedWidget.visible);
flightDisplay.saveSetting("showSpeedWidget", setBool(speedWidget.visible));
currentSpeed.showAirSpeed = true;
flightDisplay.saveSetting("showAirSpeed", currentSpeed.showAirSpeed);
flightDisplay.saveSetting("showCurrentAirSpeed", setBool(currentSpeed.showAirSpeed));
currentSpeed.showGroundSpeed = true;
flightDisplay.saveSetting("showGroundSpeed", currentSpeed.showGroundSpeed);
flightDisplay.saveSetting("showCurrentGroundSpeed", setBool(currentSpeed.showGroundSpeed));
compassIndicator.visible = true;
flightDisplay.saveSetting("enableCompassIndicator", compassIndicator.visible);
//mapBackground.visible = false;
//flightDisplay.saveSetting("enableMapBackground", mapBackground.visible);
//mapBackground.alwaysNorth = false;
//flightDisplay.saveSetting("mapAlwaysNorth", mapBackground.alwaysNorth);
flightDisplay.saveSetting("showCompassIndicator", setBool(compassIndicator.visible));
mapBackground.visible = false;
flightDisplay.saveSetting("showMapBackground", setBool(mapBackground.visible));
mapBackground.alwaysNorth = false;
flightDisplay.saveSetting("mapAlwaysPointsNorth", setBool(mapBackground.alwaysNorth));
}
}
}
/*
QGCMapBackground {
id: mapBackground
anchors.centerIn: parent
......@@ -290,15 +287,14 @@ Rectangle {
longitude: flightDisplay.longitude
z: 5
}
*/
QGCAttitudeWidget {
id: attitudeWidget
anchors.centerIn: parent
rollAngle: roll
pitchAngle: pitch
useWhite: true // !mapBackground.visible
backgroundOpacity: 1.0 // mapBackground.visible ? 0.25 : 1.0
useWhite: !mapBackground.visible
backgroundOpacity: mapBackground.visible ? 0.25 : 1.0
z: 10
}
......@@ -307,9 +303,9 @@ Rectangle {
anchors.verticalCenter: parent.verticalCenter
pitchAngle: pitch
rollAngle: roll
color: Qt.rgba(0,0,0,0) // mapBackground.visible ? Qt.rgba(0,0,0,0.5) : Qt.rgba(0,0,0,0)
opacity: 0.75 // mapBackground.visible ? 1 : 0.75
z: 25 // mapBackground.visible ? 20 : 25
color: mapBackground.visible ? Qt.rgba(0,0,0,0.5) : Qt.rgba(0,0,0,0)
opacity: mapBackground.visible ? 1 : 0.75
z: mapBackground.visible ? 20 : 25
}
Image {
......@@ -318,7 +314,7 @@ Rectangle {
mipmap: true
width: 260
fillMode: Image.PreserveAspectFit
z: 20 // mapBackground.visible ? 25 : 20
z: mapBackground.visible ? 25 : 20
}
QGCAltitudeWidget {
......@@ -380,6 +376,4 @@ Rectangle {
}
z: 100
}
}
......@@ -86,7 +86,7 @@ QGCFlightDisplay::~QGCFlightDisplay()
_refreshTimer->stop();
}
void QGCFlightDisplay::saveSetting(const QString& name, bool value)
void QGCFlightDisplay::saveSetting(const QString &name, const QString& value)
{
QSettings settings;
QString key(kMainFlightDisplayGroup);
......@@ -94,12 +94,12 @@ void QGCFlightDisplay::saveSetting(const QString& name, bool value)
settings.setValue(key, value);
}
bool QGCFlightDisplay::loadSetting(const QString& name, bool defaultValue)
QString QGCFlightDisplay::loadSetting(const QString &name, const QString& defaultValue)
{
QSettings settings;
QString key(kMainFlightDisplayGroup);
key += "/" + name;
return settings.value(key, defaultValue).toBool();
return settings.value(key, defaultValue).toString();
}
void QGCFlightDisplay::_forgetUAS(UASInterface* uas)
......
......@@ -54,8 +54,8 @@ public:
Q_PROPERTY(float latitude READ latitude NOTIFY latitudeChanged)
Q_PROPERTY(float longitude READ longitude NOTIFY longitudeChanged)
Q_INVOKABLE void saveSetting (const QString &key, bool value);
Q_INVOKABLE bool loadSetting (const QString &key, bool defaultValue);
Q_INVOKABLE void saveSetting (const QString &key, const QString& value);
Q_INVOKABLE QString loadSetting (const QString &key, const QString& defaultValue);
float roll () { return _roll; }
float pitch () { return _pitch; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment