mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
mapwidgethelper: use dynamic creation of the Plugin object
The googlemaps plugin is about to support tile language via the PluginParameter 'googlemaps.maps.language'. To be able to pass the subsurface UI language (obtained from the uiLanguage() helper) the Plugin has to be created dynamically, only *after* the MapWidgetHelper is created. MapWidgetHelper::pluginObject() now provides a QString which contains the Plugin object and also include the uiLanguage ISO value. This string is used in mapwidget.qml as: map.plugin = Qt.createQmlObject(pluginObject, rootItem) This creates the Plugin object dynamically with the proper UI language string, but also requires a couple of small changes: - move the declaration of map.mapType after the Qt.createQmlObject() call - assign map.activeMapType after map.mapType has a value Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
fb151df883
commit
1da4f91cc8
3 changed files with 31 additions and 12 deletions
|
@ -5,17 +5,9 @@ import QtPositioning 5.3
|
|||
import org.subsurfacedivelog.mobile 1.0
|
||||
|
||||
Item {
|
||||
id: rootItem
|
||||
property int nSelectedDives: 0
|
||||
|
||||
Plugin {
|
||||
id: mapPlugin
|
||||
name: "googlemaps"
|
||||
Component.onCompleted: {
|
||||
if (availableServiceProviders.indexOf(name) === -1)
|
||||
console.warn("MapWidget.qml: cannot find a plugin with the name '" + name + "'")
|
||||
}
|
||||
}
|
||||
|
||||
MapWidgetHelper {
|
||||
id: mapHelper
|
||||
map: map
|
||||
|
@ -23,15 +15,19 @@ Item {
|
|||
onSelectedDivesChanged: nSelectedDives = list.length
|
||||
onEditModeChanged: editMessage.isVisible = editMode === true ? 1 : 0
|
||||
onCoordinatesChanged: {}
|
||||
Component.onCompleted: {
|
||||
map.plugin = Qt.createQmlObject(pluginObject, rootItem)
|
||||
map.mapType = { "STREET": map.supportedMapTypes[0], "SATELLITE": map.supportedMapTypes[1] }
|
||||
map.activeMapType = map.mapType.SATELLITE
|
||||
}
|
||||
}
|
||||
|
||||
Map {
|
||||
id: map
|
||||
anchors.fill: parent
|
||||
plugin: mapPlugin
|
||||
zoomLevel: 1
|
||||
|
||||
readonly property var mapType: { "STREET": supportedMapTypes[0], "SATELLITE": supportedMapTypes[1] }
|
||||
property var mapType
|
||||
readonly property var defaultCenter: QtPositioning.coordinate(0, 0)
|
||||
readonly property real defaultZoomIn: 12.0
|
||||
readonly property real defaultZoomOut: 1.0
|
||||
|
@ -42,7 +38,6 @@ Item {
|
|||
property real newZoomOut: 1.0
|
||||
property var clickCoord: QtPositioning.coordinate(0, 0)
|
||||
|
||||
Component.onCompleted: activeMapType = mapType.SATELLITE
|
||||
onZoomLevelChanged: mapHelper.calculateSmallCircleRadius(map.center)
|
||||
|
||||
MapItemView {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "qmlmapwidgethelper.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/helpers.h"
|
||||
#include "qt-models/maplocationmodel.h"
|
||||
|
||||
#define MIN_DISTANCE_BETWEEN_DIVE_SITES_M 50.0
|
||||
|
@ -238,3 +239,23 @@ void MapWidgetHelper::setEditMode(bool editMode)
|
|||
}
|
||||
emit editModeChanged();
|
||||
}
|
||||
|
||||
QString MapWidgetHelper::pluginObject()
|
||||
{
|
||||
QString str;
|
||||
str += "import QtQuick 2.0;";
|
||||
str += "import QtLocation 5.3;";
|
||||
str += "Plugin {";
|
||||
str += " id: mapPlugin;";
|
||||
str += " name: 'googlemaps';";
|
||||
str += " PluginParameter { name: 'googlemaps.maps.language'; value: '%lang%' }";
|
||||
str += " Component.onCompleted: {";
|
||||
str += " if (availableServiceProviders.indexOf(name) === -1) {";
|
||||
str += " console.warn('MapWidget.qml: cannot find a plugin named: ' + name);";
|
||||
str += " }";
|
||||
str += " }";
|
||||
str += "}";
|
||||
QString lang = uiLanguage(NULL).replace('_', '-');
|
||||
str.replace("%lang%", lang);
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ class MapWidgetHelper : public QObject {
|
|||
Q_PROPERTY(QObject *map MEMBER m_map)
|
||||
Q_PROPERTY(MapLocationModel *model MEMBER m_mapLocationModel NOTIFY modelChanged)
|
||||
Q_PROPERTY(bool editMode READ editMode WRITE setEditMode NOTIFY editModeChanged)
|
||||
Q_PROPERTY(QString pluginObject READ pluginObject NOTIFY pluginObjectChanged)
|
||||
|
||||
public:
|
||||
explicit MapWidgetHelper(QObject *parent = NULL);
|
||||
|
@ -27,6 +28,7 @@ public:
|
|||
Q_INVOKABLE void selectVisibleLocations();
|
||||
bool editMode();
|
||||
void setEditMode(bool editMode);
|
||||
QString pluginObject();
|
||||
|
||||
private:
|
||||
QObject *m_map;
|
||||
|
@ -43,6 +45,7 @@ signals:
|
|||
void editModeChanged();
|
||||
void selectedDivesChanged(QList<int> list);
|
||||
void coordinatesChanged();
|
||||
void pluginObjectChanged();
|
||||
};
|
||||
|
||||
extern "C" const char *printGPSCoords(int lat, int lon);
|
||||
|
|
Loading…
Reference in a new issue