Browse Source

Change map settings to string

QGC4.4
Pierre TILAK 6 years ago
parent
commit
5683020f93
  1. 2
      src/Airmap/AirmapSettings.qml
  2. 5
      src/FlightMap/FlightMap.qml
  3. 6
      src/QtLocationPlugin/GoogleMapProvider.h
  4. 12
      src/QtLocationPlugin/MapProvider.h
  5. 97
      src/QtLocationPlugin/QGCMapUrlEngine.cpp
  6. 6
      src/QtLocationPlugin/QMLControl/OfflineMap.qml
  7. 11
      src/Settings/FlightMap.SettingsGroup.json
  8. 101
      src/Settings/FlightMapSettings.cc
  9. 30
      src/Settings/FlightMapSettings.h
  10. 35
      src/ui/preferences/GeneralSettings.qml

2
src/Airmap/AirmapSettings.qml

@ -681,7 +681,7 @@ Item {
visible: !QGroundControl.airspaceManager.flightPlan.loadingFlightList && _flightList.count > 0 && tableView.currentRow >= 0 visible: !QGroundControl.airspaceManager.flightPlan.loadingFlightList && _flightList.count > 0 && tableView.currentRow >= 0
function updateActiveMapType() { function updateActiveMapType() {
var settings = QGroundControl.settingsManager.flightMapSettings var settings = QGroundControl.settingsManager.flightMapSettings
var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue var fullMapName = settings.mapProvider.value + " " + settings.mapType.value
for (var i = 0; i < map.supportedMapTypes.length; i++) { for (var i = 0; i < map.supportedMapTypes.length; i++) {
if (fullMapName === map.supportedMapTypes[i].name) { if (fullMapName === map.supportedMapTypes[i].name) {
map.activeMapType = map.supportedMapTypes[i] map.activeMapType = map.supportedMapTypes[i]

5
src/FlightMap/FlightMap.qml

@ -95,7 +95,10 @@ Map {
function updateActiveMapType() { function updateActiveMapType() {
var settings = QGroundControl.settingsManager.flightMapSettings var settings = QGroundControl.settingsManager.flightMapSettings
var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue //var fullMapName = settings.mapProvider.value + " " + settings.mapType.value
var fullMapName = settings.mapProvider.value
console.log("updateActiveMapType",fullMapName)
for (var i = 0; i < _map.supportedMapTypes.length; i++) { for (var i = 0; i < _map.supportedMapTypes.length; i++) {
if (fullMapName === _map.supportedMapTypes[i].name) { if (fullMapName === _map.supportedMapTypes[i].name) {
_map.activeMapType = _map.supportedMapTypes[i] _map.activeMapType = _map.supportedMapTypes[i]

6
src/QtLocationPlugin/GoogleMapProvider.h

@ -56,9 +56,9 @@ class GoogleMapProvider : public MapProvider {
// CycleMap, // CycleMap,
// CustomMap = 100 // CustomMap = 100
const unsigned int AVERAGE_GOOGLE_STREET_MAP = 4913; const quint32 AVERAGE_GOOGLE_STREET_MAP = 4913;
const unsigned int AVERAGE_GOOGLE_SAT_MAP = 56887; const quint32 AVERAGE_GOOGLE_SAT_MAP = 56887;
const unsigned int AVERAGE_GOOGLE_TERRAIN_MAP = 19391; const quint32 AVERAGE_GOOGLE_TERRAIN_MAP = 19391;
// ----------------------------------------------------------- // -----------------------------------------------------------
// Google Street Map // Google Street Map

12
src/QtLocationPlugin/MapProvider.h

@ -11,12 +11,12 @@ static const unsigned char pngSignature[] = {0x89, 0x50, 0x4E, 0x47, 0x0D,
static const unsigned char jpegSignature[] = {0xFF, 0xD8, 0xFF, 0x00}; static const unsigned char jpegSignature[] = {0xFF, 0xD8, 0xFF, 0x00};
static const unsigned char gifSignature[] = {0x47, 0x49, 0x46, 0x38, 0x00}; static const unsigned char gifSignature[] = {0x47, 0x49, 0x46, 0x38, 0x00};
const unsigned int AVERAGE_BING_STREET_MAP = 1297; const quint32 AVERAGE_BING_STREET_MAP = 1297;
const unsigned int AVERAGE_BING_SAT_MAP = 19597; const quint32 AVERAGE_BING_SAT_MAP = 19597;
const unsigned int AVERAGE_MAPBOX_SAT_MAP = 15739; const quint32 AVERAGE_MAPBOX_SAT_MAP = 15739;
const unsigned int AVERAGE_MAPBOX_STREET_MAP = 5648; const quint32 AVERAGE_MAPBOX_STREET_MAP = 5648;
const unsigned int AVERAGE_TILE_SIZE = 13652; const quint32 AVERAGE_TILE_SIZE = 13652;
const unsigned int AVERAGE_AIRMAP_ELEV_SIZE = 2786; const quint32 AVERAGE_AIRMAP_ELEV_SIZE = 2786;
class MapProvider : public QObject { class MapProvider : public QObject {
Q_OBJECT Q_OBJECT

97
src/QtLocationPlugin/QGCMapUrlEngine.cpp

@ -7,39 +7,36 @@
* *
****************************************************************************/ ****************************************************************************/
/** /**
* @file * @file
* @author Gus Grubba <mavlink@grubba.com> * @author Gus Grubba <mavlink@grubba.com>
* Original work: The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * Original work: The OpenPilot Team, http://www.openpilot.org Copyright (C)
* 2012.
*/ */
//#define DEBUG_GOOGLE_MAPS //#define DEBUG_GOOGLE_MAPS
#include "AppSettings.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "QGCMapEngine.h" #include "QGCMapEngine.h"
#include "AppSettings.h"
#include "SettingsManager.h" #include "SettingsManager.h"
#include <QRegExp> #include <QByteArray>
#include <QNetworkReply>
#include <QEventLoop> #include <QEventLoop>
#include <QTimer> #include <QNetworkReply>
#include <QRegExp>
#include <QString> #include <QString>
#include <QByteArray> #include <QTimer>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
UrlFactory::UrlFactory() UrlFactory::UrlFactory() : _timeout(5 * 1000) {
: _timeout(5 * 1000)
{
// BingMaps // BingMaps
//_versionBingMaps = "563"; //_versionBingMaps = "563";
#ifndef QGC_NO_GOOGLE_MAPS #ifndef QGC_NO_GOOGLE_MAPS
_providersTable["GoogleStreet"] = new GoogleStreetMapProvider(this); _providersTable["Google Street Map"] = new GoogleStreetMapProvider(this);
_providersTable["Google Satellite"] = new GoogleSatelliteMapProvider(this); _providersTable["Google Satellite"] = new GoogleSatelliteMapProvider(this);
_providersTable["Google Terrain"] = new GoogleTerrainMapProvider(this);
#endif #endif
} }
@ -48,29 +45,34 @@ void UrlFactory::registerProvider(QString name, MapProvider* provider){
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
UrlFactory::~UrlFactory() UrlFactory::~UrlFactory() {}
{
}
QString QString UrlFactory::getImageFormat(int id, const QByteArray& image) {
UrlFactory::getImageFormat(int id, const QByteArray& image) QString type = getTypeFromId(id);
{ if (_providersTable.find(type) != _providersTable.end()) {
return _providersTable[getTypeFromId(id)]->getImageFormat(image); return _providersTable[getTypeFromId(id)]->getImageFormat(image);
} else {
return "";
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QString QString UrlFactory::getImageFormat(QString type, const QByteArray& image) {
UrlFactory::getImageFormat(QString type, const QByteArray& image) if (_providersTable.find(type) != _providersTable.end()) {
{
return _providersTable[type]->getImageFormat(image); return _providersTable[type]->getImageFormat(image);
} else {
return "";
}
// QString format; // QString format;
// if(image.size() > 2) // if(image.size() > 2)
//{ //{
// if (image.startsWith(reinterpret_cast<const char*>(pngSignature))) // if (image.startsWith(reinterpret_cast<const char*>(pngSignature)))
// format = "png"; // format = "png";
// else if (image.startsWith(reinterpret_cast<const char*>(jpegSignature))) // else if (image.startsWith(reinterpret_cast<const
// char*>(jpegSignature)))
// format = "jpg"; // format = "jpg";
// else if (image.startsWith(reinterpret_cast<const char*>(gifSignature))) // else if (image.startsWith(reinterpret_cast<const
// char*>(gifSignature)))
// format = "gif"; // format = "gif";
// else { // else {
// switch (type) { // switch (type) {
@ -119,23 +121,26 @@ UrlFactory::getImageFormat(QString type, const QByteArray& image)
// format = "jpg"; // format = "jpg";
// break; // break;
// default: // default:
// qWarning("UrlFactory::getImageFormat() Unknown map id %d", type); // qWarning("UrlFactory::getImageFormat() Unknown map id %d",
// break; // type); break;
// } // }
// } // }
//} //}
// return format; // return format;
} }
QNetworkRequest QNetworkRequest UrlFactory::getTileURL(int id, int x, int y, int zoom,
UrlFactory::getTileURL(int id, int x, int y, int zoom, QNetworkAccessManager* networkManager){ QNetworkAccessManager* networkManager) {
return _providersTable[getTypeFromId(id)]->getTileURL(x,y,zoom,networkManager); QString type = getTypeFromId(id);
if (_providersTable.find(type) != _providersTable.end()) {
return _providersTable[type]->getTileURL(x, y, zoom, networkManager);
}
return QNetworkRequest(QUrl());
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QNetworkRequest QNetworkRequest UrlFactory::getTileURL(QString type, int x, int y, int zoom,
UrlFactory::getTileURL(QString type, int x, int y, int zoom, QNetworkAccessManager* networkManager) QNetworkAccessManager* networkManager) {
{
return _providersTable[type]->getTileURL(x, y, zoom, networkManager); return _providersTable[type]->getTileURL(x, y, zoom, networkManager);
////-- Build URL ////-- Build URL
// QNetworkRequest request; // QNetworkRequest request;
@ -151,7 +156,8 @@ UrlFactory::getTileURL(QString type, int x, int y, int zoom, QNetworkAccessManag
// // case GoogleLabels: // // case GoogleLabels:
// // case GoogleTerrain: // // case GoogleTerrain:
// // case GoogleHybrid: // // case GoogleHybrid:
// // request.setRawHeader("Referrer", "https://www.google.com/maps/preview"); // // request.setRawHeader("Referrer",
// "https://www.google.com/maps/preview");
// // break; // // break;
// case BingHybrid: // case BingHybrid:
// case BingMap: // case BingMap:
@ -171,15 +177,17 @@ UrlFactory::getTileURL(QString type, int x, int y, int zoom, QNetworkAccessManag
// break; // break;
// case OpenStreetMap: // case OpenStreetMap:
// case OpenStreetOsm: // case OpenStreetOsm:
// request.setRawHeader("Referrer", "https://www.openstreetmap.org/"); // request.setRawHeader("Referrer",
// break; // "https://www.openstreetmap.org/"); break;
// */ // */
// case EsriWorldStreet: // case EsriWorldStreet:
// case EsriWorldSatellite: // case EsriWorldSatellite:
// case EsriTerrain: { // case EsriTerrain: {
// QByteArray token = qgcApp()->toolbox()->settingsManager()->appSettings()->esriToken()->rawValue().toString().toLatin1(); // QByteArray token =
// request.setRawHeader("User-Agent", QByteArrayLiteral("Qt Location based application")); // qgcApp()->toolbox()->settingsManager()->appSettings()->esriToken()->rawValue().toString().toLatin1();
// request.setRawHeader("User-Agent", QByteArrayLiteral("Qt
// Location based application"));
// request.setRawHeader("User-Token", token); // request.setRawHeader("User-Token", token);
// } // }
// return request; // return request;
@ -455,12 +463,15 @@ UrlFactory::_getURL(QString type, int x, int y, int zoom, QNetworkAccessManager*
#endif #endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
quint32 quint32 UrlFactory::averageSizeForType(QString type) {
UrlFactory::averageSizeForType(QString type) qDebug() << "UrlFactory::averageSizeForType for" << type;
{ if (_providersTable.find(type) != _providersTable.end()) {
return _providersTable[type]->getAverageSize(); return _providersTable[type]->getAverageSize();
} else {
qDebug() << "UrlFactory::averageSizeForType " << type
<< " Not registered";
}
// switch (type) { // switch (type) {
// case GoogleMap: // case GoogleMap:
@ -517,6 +528,4 @@ QString UrlFactory::getTypeFromId(int id){
// Todo : qHash produce a uint bigger than max(int) // Todo : qHash produce a uint bigger than max(int)
// There is still a low probability for abs to // There is still a low probability for abs to
// generate similar hash for different types // generate similar hash for different types
int UrlFactory::getIdFromType(QString type){ int UrlFactory::getIdFromType(QString type) { return abs(qHash(type)); }
return abs(qHash(type));
}

6
src/QtLocationPlugin/QMLControl/OfflineMap.qml

@ -38,7 +38,7 @@ Item {
property Fact _mapboxFact: _settingsManager ? _settingsManager.appSettings.mapboxToken : null property Fact _mapboxFact: _settingsManager ? _settingsManager.appSettings.mapboxToken : null
property Fact _esriFact: _settingsManager ? _settingsManager.appSettings.esriToken : null property Fact _esriFact: _settingsManager ? _settingsManager.appSettings.esriToken : null
property string mapType: _fmSettings ? (_fmSettings.mapProvider.enumStringValue + " " + _fmSettings.mapType.enumStringValue) : "" property string mapType: _fmSettings ? (_fmSettings.mapProvider.value + " " + _fmSettings.mapType.value) : ""
property bool isMapInteractive: false property bool isMapInteractive: false
property var savedCenter: undefined property var savedCenter: undefined
property real savedZoom: 3 property real savedZoom: 3
@ -93,10 +93,10 @@ Item {
function updateMap() { function updateMap() {
for (var i = 0; i < _map.supportedMapTypes.length; i++) { for (var i = 0; i < _map.supportedMapTypes.length; i++) {
//console.log(_map.supportedMapTypes[i].name) console.log(_map.supportedMapTypes[i].name, i)
if (mapType === _map.supportedMapTypes[i].name) { if (mapType === _map.supportedMapTypes[i].name) {
_map.activeMapType = _map.supportedMapTypes[i] _map.activeMapType = _map.supportedMapTypes[i]
//console.log("Update Map:" + " " + _map.activeMapType) console.log("Update Map:" + " " + _map.activeMapType)
handleChanges() handleChanges()
return return
} }

11
src/Settings/FlightMap.SettingsGroup.json

@ -2,17 +2,12 @@
{ {
"name": "mapProvider", "name": "mapProvider",
"shortDescription": "Currently selected map provider for flight maps", "shortDescription": "Currently selected map provider for flight maps",
"type": "uint32", "type": "string"
"enumStrings": "Bing,Google,Statkart,Mapbox,Esri,Eniro,VWorld",
"enumValues": "0,1,2,3,4,5,6",
"defaultValue": 0
}, },
{ {
"name": "mapType", "name": "mapType",
"shortDescription": "Currently selected map type for flight maps", "shortDescription": "Currently selected map type for flight maps",
"type": "uint32", "type": "string",
"enumStrings": "Street Map,Satellite Map,Hybrid Map,Terrain Map", "default": ""
"enumValues": "0,1,2,3",
"defaultValue": 2
} }
] ]

101
src/Settings/FlightMapSettings.cc

@ -19,106 +19,7 @@
DECLARE_SETTINGGROUP(FlightMap, "FlightMap") DECLARE_SETTINGGROUP(FlightMap, "FlightMap")
{ {
qmlRegisterUncreatableType<FlightMapSettings>("QGroundControl.SettingsManager", 1, 0, "FlightMapSettings", "Reference only"); qmlRegisterUncreatableType<FlightMapSettings>("QGroundControl.SettingsManager", 1, 0, "FlightMapSettings", "Reference only");
// Save the original version since we modify based on map provider
_savedMapTypeStrings = _nameToMetaDataMap[mapTypeName]->enumStrings();
_savedMapTypeValues = _nameToMetaDataMap[mapTypeName]->enumValues();
#ifdef QGC_NO_GOOGLE_MAPS
//-- Remove Google
_excludeProvider(mapProviderGoogle);
#endif
if(qgcApp()->toolbox()->settingsManager()->appSettings()->mapboxToken()->rawValue().toString().isEmpty()) {
_excludeProvider(mapProviderMapbox);
}
if(qgcApp()->toolbox()->settingsManager()->appSettings()->esriToken()->rawValue().toString().isEmpty()) {
_excludeProvider(mapProviderEsri);
}
_newMapProvider(mapProvider()->rawValue());
} }
DECLARE_SETTINGSFACT(FlightMapSettings, mapProvider)
DECLARE_SETTINGSFACT(FlightMapSettings, mapType) DECLARE_SETTINGSFACT(FlightMapSettings, mapType)
DECLARE_SETTINGSFACT_NO_FUNC(FlightMapSettings, mapProvider)
{
if (!_mapProviderFact) {
_mapProviderFact = _createSettingsFact(mapProviderName);
connect(_mapProviderFact, &Fact::rawValueChanged, this, &FlightMapSettings::_newMapProvider);
}
return _mapProviderFact;
}
void FlightMapSettings::_excludeProvider(MapProvider_t provider)
{
FactMetaData* metaData = _nameToMetaDataMap[mapProviderName];
QVariantList enumValues = metaData->enumValues();
QStringList enumStrings = metaData->enumStrings();
_removeEnumValue(provider, enumStrings, enumValues);
metaData->setEnumInfo(enumStrings, enumValues);
}
void FlightMapSettings::_removeEnumValue(int value, QStringList& enumStrings, QVariantList& enumValues)
{
bool found = false;
int removeIndex;
for (removeIndex=0; removeIndex<enumValues.count(); removeIndex++) {
if (enumValues[removeIndex].toInt() == value) {
found = true;
break;
}
}
if (found) {
enumValues.removeAt(removeIndex);
enumStrings.removeAt(removeIndex);
}
}
void FlightMapSettings::_newMapProvider(QVariant value)
{
FactMetaData* metaData = _nameToMetaDataMap[mapTypeName];
QStringList enumStrings = _savedMapTypeStrings;
QVariantList enumValues = _savedMapTypeValues;
switch (value.toInt()) {
case mapProviderBing:
_removeEnumValue(mapTypeTerrain, enumStrings, enumValues);
break;
case mapProviderGoogle:
_removeEnumValue(mapTypeHybrid, enumStrings, enumValues);
break;
case mapProviderStarkart:
_removeEnumValue(mapTypeStreet, enumStrings, enumValues);
_removeEnumValue(mapTypeSatellite, enumStrings, enumValues);
_removeEnumValue(mapTypeHybrid, enumStrings, enumValues);
break;
case mapProviderEniro:
_removeEnumValue(mapTypeStreet, enumStrings, enumValues);
_removeEnumValue(mapTypeSatellite, enumStrings, enumValues);
_removeEnumValue(mapTypeHybrid, enumStrings, enumValues);
break;
case mapProviderEsri:
_removeEnumValue(mapTypeHybrid, enumStrings, enumValues);
break;
case mapProviderVWorld:
_removeEnumValue(mapTypeHybrid, enumStrings, enumValues);
_removeEnumValue(mapTypeTerrain, enumStrings, enumValues);
}
metaData->setEnumInfo(enumStrings, enumValues);
emit mapTypeChanged();
// Check that map type is still valid for this new map provider
bool found = false;
int currentMapType = mapType()->rawValue().toInt();
for (int i=0; i<enumValues.count(); i++) {
if (currentMapType == enumValues[i].toInt()) {
found = true;
break;
}
}
if (!found) {
mapType()->setRawValue(0);
}
}

30
src/Settings/FlightMapSettings.h

@ -18,39 +18,9 @@ class FlightMapSettings : public SettingsGroup
public: public:
FlightMapSettings(QObject* parent = nullptr); FlightMapSettings(QObject* parent = nullptr);
// This enum must match the json meta data
typedef enum {
mapProviderBing,
mapProviderGoogle,
mapProviderStarkart,
mapProviderMapbox,
mapProviderEsri,
mapProviderEniro,
mapProviderVWorld
} MapProvider_t;
// This enum must match the json meta data
typedef enum {
mapTypeStreet,
mapTypeSatellite,
mapTypeHybrid,
mapTypeTerrain
} MapType_t;
DEFINE_SETTING_NAME_GROUP() DEFINE_SETTING_NAME_GROUP()
DEFINE_SETTINGFACT(mapProvider) DEFINE_SETTINGFACT(mapProvider)
DEFINE_SETTINGFACT(mapType) DEFINE_SETTINGFACT(mapType)
signals:
void mapTypeChanged(void);
private slots:
void _newMapProvider(QVariant value);
private:
void _removeEnumValue(int value, QStringList& enumStrings, QVariantList& enumValues);
void _excludeProvider(MapProvider_t provider);
QStringList _savedMapTypeStrings;
QVariantList _savedMapTypeValues;
}; };

35
src/ui/preferences/GeneralSettings.qml

@ -38,8 +38,8 @@ Rectangle {
property real _labelWidth: ScreenTools.defaultFontPixelWidth * 20 property real _labelWidth: ScreenTools.defaultFontPixelWidth * 20
property real _comboFieldWidth: ScreenTools.defaultFontPixelWidth * 28 property real _comboFieldWidth: ScreenTools.defaultFontPixelWidth * 28
property real _valueFieldWidth: ScreenTools.defaultFontPixelWidth * 10 property real _valueFieldWidth: ScreenTools.defaultFontPixelWidth * 10
property Fact _mapProvider: QGroundControl.settingsManager.flightMapSettings.mapProvider property string _mapProvider: QGroundControl.settingsManager.flightMapSettings.mapProvider.value
property Fact _mapType: QGroundControl.settingsManager.flightMapSettings.mapType property string _mapType: QGroundControl.settingsManager.flightMapSettings.mapType.value
property Fact _followTarget: QGroundControl.settingsManager.appSettings.followTarget property Fact _followTarget: QGroundControl.settingsManager.appSettings.followTarget
property real _panelWidth: _root.width * _internalWidthRatio property real _panelWidth: _root.width * _internalWidthRatio
property real _margins: ScreenTools.defaultFontPixelWidth property real _margins: ScreenTools.defaultFontPixelWidth
@ -160,30 +160,19 @@ Rectangle {
QGCLabel { QGCLabel {
text: qsTr("Map Provider") text: qsTr("Map Provider")
width: _labelWidth width: _labelWidth
visible: _mapProvider.visible //visible: _mapProvider.visible
} }
FactComboBox { QGCComboBox {
Layout.preferredWidth: _comboFieldWidth id: mapCombo
fact: _mapProvider model: QGroundControl.mapEngineManager.mapList
indexModel: false
visible: _mapProvider.visible
}
QGCLabel {
text: qsTr("Map Type")
visible: _mapType && _mapType.visible
}
FactComboBox {
id: mapTypes
Layout.preferredWidth: _comboFieldWidth Layout.preferredWidth: _comboFieldWidth
fact: _mapType onActivated: {
indexModel: false _mapProvider = textAt(index)
visible: _mapType && _mapType.visible QGroundControl.settingsManager.flightMapSettings.mapProvider.value=textAt(index)
Connections {
target: QGroundControl.settingsManager.flightMapSettings
onMapTypeChanged: {
mapTypes.model = _mapType.enumStrings
} }
Component.onCompleted: {
var index = mapCombo.find(_mapProvider)
mapCombo.currentIndex = index
} }
} }

Loading…
Cancel
Save