Commit 5683020f authored by Pierre TILAK's avatar Pierre TILAK

Change map settings to string

parent 1f6c8d1a
......@@ -681,7 +681,7 @@ Item {
visible: !QGroundControl.airspaceManager.flightPlan.loadingFlightList && _flightList.count > 0 && tableView.currentRow >= 0
function updateActiveMapType() {
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++) {
if (fullMapName === map.supportedMapTypes[i].name) {
map.activeMapType = map.supportedMapTypes[i]
......
......@@ -95,7 +95,10 @@ Map {
function updateActiveMapType() {
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++) {
if (fullMapName === _map.supportedMapTypes[i].name) {
_map.activeMapType = _map.supportedMapTypes[i]
......
......@@ -56,9 +56,9 @@ class GoogleMapProvider : public MapProvider {
// CycleMap,
// CustomMap = 100
const unsigned int AVERAGE_GOOGLE_STREET_MAP = 4913;
const unsigned int AVERAGE_GOOGLE_SAT_MAP = 56887;
const unsigned int AVERAGE_GOOGLE_TERRAIN_MAP = 19391;
const quint32 AVERAGE_GOOGLE_STREET_MAP = 4913;
const quint32 AVERAGE_GOOGLE_SAT_MAP = 56887;
const quint32 AVERAGE_GOOGLE_TERRAIN_MAP = 19391;
// -----------------------------------------------------------
// Google Street Map
......
......@@ -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 gifSignature[] = {0x47, 0x49, 0x46, 0x38, 0x00};
const unsigned int AVERAGE_BING_STREET_MAP = 1297;
const unsigned int AVERAGE_BING_SAT_MAP = 19597;
const unsigned int AVERAGE_MAPBOX_SAT_MAP = 15739;
const unsigned int AVERAGE_MAPBOX_STREET_MAP = 5648;
const unsigned int AVERAGE_TILE_SIZE = 13652;
const unsigned int AVERAGE_AIRMAP_ELEV_SIZE = 2786;
const quint32 AVERAGE_BING_STREET_MAP = 1297;
const quint32 AVERAGE_BING_SAT_MAP = 19597;
const quint32 AVERAGE_MAPBOX_SAT_MAP = 15739;
const quint32 AVERAGE_MAPBOX_STREET_MAP = 5648;
const quint32 AVERAGE_TILE_SIZE = 13652;
const quint32 AVERAGE_AIRMAP_ELEV_SIZE = 2786;
class MapProvider : public QObject {
Q_OBJECT
......
This diff is collapsed.
......@@ -38,7 +38,7 @@ Item {
property Fact _mapboxFact: _settingsManager ? _settingsManager.appSettings.mapboxToken : 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 var savedCenter: undefined
property real savedZoom: 3
......@@ -93,10 +93,10 @@ Item {
function updateMap() {
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) {
_map.activeMapType = _map.supportedMapTypes[i]
//console.log("Update Map:" + " " + _map.activeMapType)
console.log("Update Map:" + " " + _map.activeMapType)
handleChanges()
return
}
......
......@@ -2,17 +2,12 @@
{
"name": "mapProvider",
"shortDescription": "Currently selected map provider for flight maps",
"type": "uint32",
"enumStrings": "Bing,Google,Statkart,Mapbox,Esri,Eniro,VWorld",
"enumValues": "0,1,2,3,4,5,6",
"defaultValue": 0
"type": "string"
},
{
"name": "mapType",
"shortDescription": "Currently selected map type for flight maps",
"type": "uint32",
"enumStrings": "Street Map,Satellite Map,Hybrid Map,Terrain Map",
"enumValues": "0,1,2,3",
"defaultValue": 2
"type": "string",
"default": ""
}
]
......@@ -19,106 +19,7 @@
DECLARE_SETTINGGROUP(FlightMap, "FlightMap")
{
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_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);
}
}
......@@ -18,39 +18,9 @@ class FlightMapSettings : public SettingsGroup
public:
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_SETTINGFACT(mapProvider)
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;
};
......@@ -38,8 +38,8 @@ Rectangle {
property real _labelWidth: ScreenTools.defaultFontPixelWidth * 20
property real _comboFieldWidth: ScreenTools.defaultFontPixelWidth * 28
property real _valueFieldWidth: ScreenTools.defaultFontPixelWidth * 10
property Fact _mapProvider: QGroundControl.settingsManager.flightMapSettings.mapProvider
property Fact _mapType: QGroundControl.settingsManager.flightMapSettings.mapType
property string _mapProvider: QGroundControl.settingsManager.flightMapSettings.mapProvider.value
property string _mapType: QGroundControl.settingsManager.flightMapSettings.mapType.value
property Fact _followTarget: QGroundControl.settingsManager.appSettings.followTarget
property real _panelWidth: _root.width * _internalWidthRatio
property real _margins: ScreenTools.defaultFontPixelWidth
......@@ -160,30 +160,19 @@ Rectangle {
QGCLabel {
text: qsTr("Map Provider")
width: _labelWidth
visible: _mapProvider.visible
//visible: _mapProvider.visible
}
FactComboBox {
QGCComboBox {
id: mapCombo
model: QGroundControl.mapEngineManager.mapList
Layout.preferredWidth: _comboFieldWidth
fact: _mapProvider
indexModel: false
visible: _mapProvider.visible
}
QGCLabel {
text: qsTr("Map Type")
visible: _mapType && _mapType.visible
onActivated: {
_mapProvider = textAt(index)
QGroundControl.settingsManager.flightMapSettings.mapProvider.value=textAt(index)
}
FactComboBox {
id: mapTypes
Layout.preferredWidth: _comboFieldWidth
fact: _mapType
indexModel: false
visible: _mapType && _mapType.visible
Connections {
target: QGroundControl.settingsManager.flightMapSettings
onMapTypeChanged: {
mapTypes.model = _mapType.enumStrings
}
Component.onCompleted: {
var index = mapCombo.find(_mapProvider)
mapCombo.currentIndex = index
}
}
......
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