From 8871cc4ab7a962ce66ab06522f792eb9f1311433 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Tue, 10 Apr 2018 13:09:12 +0200 Subject: First commit Needs a 3rdParty directory with a build of omim to link against. This version only partially supports places and nothing else. Change-Id: I46771b3bbfddbcd5bb2d127f6f727eed373a8903 Reviewed-by: Paolo Angelelli --- .gitignore | 42 ++++++++++ omim.pro | 100 +++++++++++++++++++++++ qgeoserviceproviderpluginomim.cpp | 90 +++++++++++++++++++++ qgeoserviceproviderpluginomim.h | 83 ++++++++++++++++++++ qplacemanagerengineomim.cpp | 161 ++++++++++++++++++++++++++++++++++++++ qplacemanagerengineomim.h | 73 +++++++++++++++++ qplacesearchreplyomim.cpp | 109 ++++++++++++++++++++++++++ qplacesearchreplyomim.h | 65 +++++++++++++++ 8 files changed, 723 insertions(+) create mode 100644 .gitignore create mode 100644 omim.pro create mode 100644 qgeoserviceproviderpluginomim.cpp create mode 100644 qgeoserviceproviderpluginomim.h create mode 100644 qplacemanagerengineomim.cpp create mode 100644 qplacemanagerengineomim.h create mode 100644 qplacesearchreplyomim.cpp create mode 100644 qplacesearchreplyomim.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2cc2b09 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# C++ objects and libs + +*.slo +*.lo +*.o +*.a +*.la +*.lai +*.so +*.dll +*.dylib +*.qmlc +*.jsc + +# Qt-es + +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.cpp +qrc_*.cpp +ui_*.h +Makefile* +*build-* +/bin +/presentations/201704-QtDay/bin/ + +# QtCreator + +*.autosave + +# QtCtreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCtreator CMake +CMakeLists.txt.user* + diff --git a/omim.pro b/omim.pro new file mode 100644 index 0000000..530dbe2 --- /dev/null +++ b/omim.pro @@ -0,0 +1,100 @@ +TEMPLATE = lib +CONFIG += plugin relative_qt_rpath c++11 +TARGET = qtgeoservices_omim +DISTFILES += \ + omim_plugin.json + +QT += location-private positioning-private network concurrent sql core gui opengl + +#STATIC_BUILD = false +STATIC_BUILD = true +if ( $$STATIC_BUILD ) { + CONFIG += static + CONFIG += qtquickcompiler + CONFIG += create_prl + QMAKE_LFLAGS += -static + QMAKE_AR += -v + android: CONFIG += no_qtquickcompiler_depend +} + +HEADERS += $$files(*.h) +SOURCES += $$files(*.cpp) + +# Use the following, to build the plugin outside Qt +PLUGIN_TYPE = geoservices +PLUGIN_CLASS_NAME = QGeoServiceProviderFactoryOmim + +QMAKE_CXXFLAGS += -w #remove friggin warnings + + +# Place the lib into a "geoservices" subdir, otherwise addLibraryPath wont work. +DESTDIR = $$PWD/bin/geoservices/ + +DEPENDENCIES *= \ + #qt_common \ + map \ + drape_frontend \ + openlr \ + routing \ + search \ + storage \ + tracking \ + traffic \ + routing_common \ + ugc \ + indexer \ + drape \ + partners_api \ + local_ads \ + platform \ + editor \ + #bsdiff \ + mwm_diff \ + bsdiff \ + geometry \ + coding \ + base \ + freetype \ + expat \ + gflags \ + jansson \ + protobuf \ + osrm \ + stats_client \ + minizip \ + succinct \ + pugixml \ + oauthcpp \ + stb_image \ + sdf_image \ + icu \ + agg \ + opening_hours + +#LIBS += "-L/media/paolo/qdata/home/paolo/Qt/Location/playground/omim.git/3rdParty/build-omim-Dev_Debug-Debug/out/debug" +#TODO: update the path below +LIBS += "-L/media/paolo/qdata/home/paolo/Qt/Location/playground/omim.git/3rdParty/build-omim-Dev-Debug/out/debug" + +# Add libraries' dependencies. +for(project, DEPENDENCIES) { + LIBS += -l$$project +} + + +LIBS *= -lz + +INCLUDEPATH *= /media/paolo/qdata/home/paolo/Qt/Location/playground/omim.git/3rdParty/omim/ +INCLUDEPATH *= /media/paolo/qdata/home/paolo/Qt/Location/playground/omim.git/3rdParty/omim/3party/glm +INCLUDEPATH *= /media/paolo/qdata/home/paolo/Qt/Location/playground/omim.git/3rdParty/omim/3party/agg +INCLUDEPATH *= /media/paolo/qdata/home/paolo/Qt/Location/playground/omim.git/3rdParty/omim/3party/opening_hours +#INCLUDEPATH *= /media/paolo/qdata/home/paolo/Qt/Location/playground/omim.git/3rdParty/omim/search +#INCLUDEPATH *= /media/paolo/qdata/home/paolo/Qt/Location/playground/omim.git/3rdParty/omim/indexer + + +CONFIG(release, debug|release) { + DEFINES *= RELEASE _RELEASE NDEBUG + CONFIG_NAME = release +} else { + DEFINES *= DEBUG _DEBUG + CONFIG_NAME = debug +} diff --git a/qgeoserviceproviderpluginomim.cpp b/qgeoserviceproviderpluginomim.cpp new file mode 100644 index 0000000..7cdbe82 --- /dev/null +++ b/qgeoserviceproviderpluginomim.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "qgeoserviceproviderpluginomim.h" +#include "qplacemanagerengineomim.h" + +QT_BEGIN_NAMESPACE + +static QPair qtVersion() { + QString ver = qVersion(); + QStringList vers = ver.split('.'); + int maj = vers.at(0).toInt(); + int min = vers.at(1).toInt(); + return QPair(maj, min); +} + +QGeoCodingManagerEngine *QGeoServiceProviderFactoryOmim::createGeocodingManagerEngine( + const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const +{ + Q_UNUSED(parameters) + Q_UNUSED(error) + Q_UNUSED(errorString) + return 0; +} + +QGeoMappingManagerEngine *QGeoServiceProviderFactoryOmim::createMappingManagerEngine( + const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const +{ + Q_UNUSED(parameters) + Q_UNUSED(error) + Q_UNUSED(errorString) + return 0; +} + +QGeoRoutingManagerEngine *QGeoServiceProviderFactoryOmim::createRoutingManagerEngine( + const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const +{ + Q_UNUSED(parameters) + Q_UNUSED(error) + Q_UNUSED(errorString) + return 0; +} + +QPlaceManagerEngine *QGeoServiceProviderFactoryOmim::createPlaceManagerEngine( + const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const +{ + auto version = qtVersion(); + if (version.second < 8) + return 0; + + return new QPlaceManagerEngineOmim(parameters, error, errorString); + //return new QGeoTiledMappingManagerEngineOmim(parameters, error, errorString); +} + +QT_END_NAMESPACE diff --git a/qgeoserviceproviderpluginomim.h b/qgeoserviceproviderpluginomim.h new file mode 100644 index 0000000..f0f4764 --- /dev/null +++ b/qgeoserviceproviderpluginomim.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOSERVICEPROVIDER_OMIM_H +#define QGEOSERVICEPROVIDER_OMIM_H + +#include +#include + +QT_BEGIN_NAMESPACE + +#ifndef QRC_INIT +#define QRC_INIT( s ) Q_INIT_RESOURCE( s ) +#endif + +static void initResources() +{ +// QRC_INIT( PLUGIN_QRC_FILENAME ); # no qrc for the moment +} + +class QGeoServiceProviderFactoryOmim: public QObject, public QGeoServiceProviderFactory +{ + Q_OBJECT + Q_INTERFACES(QGeoServiceProviderFactory) + Q_PLUGIN_METADATA(IID "org.qt-project.qt.geoservice.serviceproviderfactory/5.0" + FILE "omim_plugin.json") + +public: + QGeoServiceProviderFactoryOmim() + { + initResources(); + } + + QGeoCodingManagerEngine *createGeocodingManagerEngine(const QVariantMap ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; + QGeoMappingManagerEngine *createMappingManagerEngine(const QVariantMap ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; + QGeoRoutingManagerEngine *createRoutingManagerEngine(const QVariantMap ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; + QPlaceManagerEngine *createPlaceManagerEngine(const QVariantMap ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; +}; + +QT_END_NAMESPACE + +#endif diff --git a/qplacemanagerengineomim.cpp b/qplacemanagerengineomim.cpp new file mode 100644 index 0000000..df81601 --- /dev/null +++ b/qplacemanagerengineomim.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qplacemanagerengineomim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "qplacesearchreplyomim.h" + + + + +QPlaceManagerEngineOmim::QPlaceManagerEngineOmim(const QVariantMap ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) + : QPlaceManagerEngine(parameters) +{ + *error = QGeoServiceProvider::NoError; + errorString->clear(); +} + +QPlaceManagerEngineOmim::~QPlaceManagerEngineOmim() +{ + +} + +// Here's the weirdness of this backend: it requires the coordinates to be in some sort of expanded mercator space: +// function coordinateToText(coord) { +// var merc = Mercator.toMercator(coord) + +// merc.y = 1.0 - merc.y +// merc.x *= 2.0 +// merc.y *= 2.0 +// merc.x -= 1.0 +// merc.y -= 1.0 +// merc.x *= 180.0 +// merc.y *= 180.0 + +// return merc.y.toFixed(5) + ", " + merc.x.toFixed(5) +// } +static QDoubleVector2D toMWMCoord(const QGeoCoordinate &coord) +{ + QDoubleVector2D merc = QWebMercator::coordToMercator(coord); + merc.setY(1.0 - merc.y()); + + merc *= 2.0; + merc -= QDoubleVector2D(1.0, 1.0); + merc *= 180.0; + + return merc; +} + +QPlaceSearchReply *QPlaceManagerEngineOmim::search(const QPlaceSearchRequest &request) +{ + m_results.clear(); + QGeoRectangle rect = request.searchArea().boundingGeoRectangle(); + + + QDoubleVector2D topLeft = toMWMCoord(rect.topLeft()); + QDoubleVector2D bottomRight = toMWMCoord(rect.bottomRight()); + + + m2::RectD viewport(/*15.9262, 51.6196, 15.9553, 51.6775*/ + topLeft.x(), bottomRight.y(), // minx miny + bottomRight.x(), topLeft.y()); // maxx maxy + + m_framework.GetSearchAPI().OnViewportChanged(viewport); + + const QString searchString = request.searchTerm(); + const QString normalized = searchString.normalized(QString::NormalizationForm_KC); + + if (normalized.isEmpty()) + return new QPlaceSearchReply(); + + + QPointer reply = new QPlaceSearchReplyOmim(request, this); + m_params.m_query = normalized.toUtf8().constData(); + auto const timestamp = ++m_timestamp; + m_params.m_onResults = [reply, timestamp, cnt = 0](search::Results const & results, + vector const & /*isLocalAdsCustomer*/) mutable { + qDebug() << "Results came back " << cnt; + if (cnt) { // This ensure only first update will be propagated + qDebug() << "Second Round <-- SKIPPED!!!!"; + return; + } + cnt = cnt + 1; + if (reply) + reply->onReplyFinished(results, timestamp); + }; + + connect(reply.data(), &QPlaceReply::finished, this, &QPlaceManagerEngineOmim::onReplyFinished); + connect(reply.data(), QOverload::of(&QPlaceReply::error), + this, &QPlaceManagerEngineOmim::onReplyError); + + if (m_framework.SearchEverywhere(m_params)) + { + qDebug() << "Search started"; + } + else + { + reply->setError(QPlaceReply::UnknownError, QStringLiteral("Error!")); + } + + return reply.data(); +} + +void QPlaceManagerEngineOmim::onReplyFinished() +{ + QPlaceReply *reply = qobject_cast(sender()); + if (reply) + emit finished(reply); +} + +void QPlaceManagerEngineOmim::onReplyError(QPlaceReply::Error errorCode, const QString &errorString) +{ + QPlaceReply *reply = qobject_cast(sender()); + if (reply) + emit error(reply, errorCode, errorString); +} + diff --git a/qplacemanagerengineomim.h b/qplacemanagerengineomim.h new file mode 100644 index 0000000..17c6a81 --- /dev/null +++ b/qplacemanagerengineomim.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPLACEMANAGERENGINEOMIM_H +#define QPLACEMANAGERENGINEOMIM_H + +#include +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QPlaceManagerEngineOmim : public QPlaceManagerEngine +{ + Q_OBJECT + +public: + QPlaceManagerEngineOmim(const QVariantMap ¶meters, QGeoServiceProvider::Error *error, + QString *errorString); + ~QPlaceManagerEngineOmim(); + + QPlaceSearchReply *search(const QPlaceSearchRequest &request) Q_DECL_OVERRIDE; + +private slots: + void onReplyFinished(); + void onReplyError(QPlaceReply::Error errorCode, const QString &errorString); + +private: + Framework m_framework; + search::EverywhereSearchParams m_params; + uint64_t m_timestamp = 0; + vector m_results; +}; + +QT_END_NAMESPACE + +#endif // QPLACEMANAGERENGINEOMIM_H diff --git a/qplacesearchreplyomim.cpp b/qplacesearchreplyomim.cpp new file mode 100644 index 0000000..54a2fb1 --- /dev/null +++ b/qplacesearchreplyomim.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qplacesearchreplyomim.h" +#include "qplacemanagerengineomim.h" +#include +#include +#include +#include + +QPlaceSearchReplyOmim::QPlaceSearchReplyOmim(const QPlaceSearchRequest &request, QPlaceManagerEngineOmim *parent) + : QPlaceSearchReply(parent) +{ + setRequest(request); +} + +QPlaceSearchReplyOmim::~QPlaceSearchReplyOmim() +{ + +} + +void QPlaceSearchReplyOmim::setError(QPlaceReply::Error errorCode, const QString &errorString) +{ + QPlaceReply::setError(errorCode, errorString); + emit error(errorCode, errorString); + + setFinished(true); + emit finished(); +} + +static QGeoCoordinate fromMWMCoord(QDoubleVector2D pos) +{ + pos /= 180.0; + pos += QDoubleVector2D(1.0, 1.0); + pos /= 2.0; + pos.setY(1.0 - pos.y()); + + QGeoCoordinate coord = QWebMercator::mercatorToCoord(pos); + + return coord; +} + +void QPlaceSearchReplyOmim::onReplyFinished(const search::Results &results, uint64_t timestamp) +{ + if (m_finished) + return; + + m_finished++; + QList qresults; + + + for (size_t i = 0; i < results.GetCount(); ++i) + { + QPlaceResult placeResult; + auto const & res = results[i]; + + QString name = QString::fromStdString(res.GetString()); + QGeoAddress address; + address.setText(QString::fromStdString(res.GetAddress())); + QGeoLocation location; + location.setAddress(address); + location.setCoordinate(fromMWMCoord(QDoubleVector2D(res.GetFeatureCenter().x, res.GetFeatureCenter().y))); + QPlace place; + place.setLocation(location); + place.setName(name); + placeResult.setPlace(place); + placeResult.setTitle(name); + qDebug() << "Res "< + +#include +#include +#include + + +class QPlaceManagerEngineOmim; +class QPlaceSearchReplyOmim : public QPlaceSearchReply +{ + Q_OBJECT + +public: + QPlaceSearchReplyOmim(const QPlaceSearchRequest &request, QPlaceManagerEngineOmim *parent); + virtual ~QPlaceSearchReplyOmim(); + +public slots: + void setError(QPlaceReply::Error errorCode, const QString &errorString); + void onReplyFinished(search::Results const & results, uint64_t timestamp); + +private: + int m_finished = 0; +}; + + +#endif // QPLACESEARCHREPLYOMIM_H -- cgit v1.2.3