aboutsummaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlmapwidgethelper.cpp
AgeCommit message (Collapse)Author
2017-10-09Use lrint() for all degrees_t related roundingGravatar Lubomir I. Ivanov
In certain places the '(int)' cast is used, while in other the llrint() or lrint() functions. Make the conversation from degrees in the 'double' form to the 'int' degrees_t consistent using lrint(). lrint() is the function which should give the best results, because it accepts a 'double' and results in a 'long' even if degrees_t is 'int'. If the truncation from 'long' to 'int' is discarding some of the precision then the next step would be to turn degrees_t into a 64bit signed integer type. Possible fix for #625. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-09-20mapwidgethelper: support Qt 5.5.xGravatar Lubomir I. Ivanov
MapWidgetHelper::calculateSmallCircleRadius() uses the second argument (boolean) of QDeclarativeGeoMap::toCoordinate() and QDeclarativeGeoMap::fromCoordinate(), which isn't supported in Qt 5.5.x and errors will be thrown on runtime. This argument usage is redundant for the calculateSmallCircleRadius() use case. If the argument is set to "false" it tells the map to avoid clipping the viewport and always return a valid QPointF/QGeoCoordinate. Given that calculateSmallCircleRadius() only works with the map center - i.e it's called like so in MapWidget.qml: onZoomLevelChanged: mapHelper.calculateSmallCircleRadius(map.center) The only way for the radius estimation to fail is if the map widget width is smaller than SMALL_CIRCLE_RADIUS_PX * 2 = 52px, which is not possible as the MainWindow splitter prevents it. If the map widget becomes that small it would be hardly usable, yet no errors should be thrown related to this change. Tested-by: Stefan Fuchs <sfuchs@gmx.de> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-08-24mapwidgethelper: use system_default_directory() for cacheGravatar Lubomir I. Ivanov
The default location which is used when the PluginParemeter "googlemaps.cachefolder" is not specified should be ~/.cache/googlemaps on Linux or /user/<name>/appdata/local/cache/googlemaps on Windows. This patch moves the cache to the default system location where we store the printing templates, cloudstorage and the default user XML file. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-08-24mapwidgethelper: use dynamic creation of the Plugin objectGravatar Lubomir I. Ivanov
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>
2017-08-10mapwidgethelper: fix wrong logic in selectVisibleLocations()Gravatar Lubomir I. Ivanov
Looking for already existing locations with m_mapLocationModel->getMapLocationForUuid() will not cover dive sites which are too close to each other and are skipped when creating MapLocations. See reloadMapLocations() and the usage of MIN_DISTANCE_BETWEEN_DIVE_SITES_M. Constructing a new QGeoCoordinate for the already retrieved dive site (ds) coordinates ensures that we are traversing *all* dive sites at the backend and not only those visible on the map. Fixes the issue where not all dives in the DiveList are selected, even if a dive clearly happened on a location currently visible in the map viewport (map -> context menu -> select visible dive locations). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-08-07mapwidgethelper: add the selectVisibleLocations() methodGravatar Lubomir I. Ivanov
The new method selectVisibleLocations() contains a routine to find all visible MapLocation objects in the Map viewport and select the dives associated to said MapLocation objects. This method is to be invoked from the QML context menu. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-08-07mapwidgethelper: support tracking of all selected dive sitesGravatar Lubomir I. Ivanov
MapWidgetHelper::centerOnDiveSite() now checks if more than one dive sites are selected and finds the most top-left and bottom-right ones in the coordinate system to form a rectangle. It also supports the special cases where a selected dive site does not have coordinates or the case where only a single dive site with GPS coordinates are selected. TODO: implement mapwidget.qml::centerOnRectangle() This QML function will receive a QGeoCoordinate based rectangle which has to be centered in the viewport with animation. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28Switch new files to unix line endingsGravatar Dirk Hohndel
I thought we had this automated, but Lubomirs commits introduced a few files with dos line endings. This is purely a change of line endings, no other changes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-28mapwidgethelper: add methods for editing MapLocationsGravatar Lubomir I. Ivanov
updateCurrentDiveSiteCoordinates() should be called from QML when a marker changed it's location. it emits the coordinatesChanged() signal, which should be tracked in the MapWidget class. The MapWidget class should emit the same signal to the MainWindow (Marble does that). editMode is now a boolean property, which should put the QML map into editing mode. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: add the same logic for markers as in globe.cppGravatar Lubomir I. Ivanov
The marble globe tracks dive sites with the same name and discards such that are less than 50 meters apart. We already store names in MapLocation objects, but using a QMap<QString, MapLocation *> to check the names is probably faster with the expense of using more memory. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: change centerOnDiveSite()Gravatar Lubomir I. Ivanov
Call setSelectedUuid() from C++ also center on coodinates instead on a MapLocation, as there is no point to pass the MapLocation object back to QML. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28maplocationmodel: add the "namer" propertyGravatar Lubomir I. Ivanov
The MapLocation QObject now has a QString property "name", which is translating the dive_site->name member. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: emit a selectedDivesChanged() signalGravatar Lubomir I. Ivanov
The signal emits a QList<int> filled with dive idexes from the main backend dive table. The MapWidgetHelper QML instance handles that in onSelectedDivesChanged(). This will only be needed for the mobile version, as the desktop version should connect it's own slot in MapWidget.cpp. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: obtain a list of nearby divesGravatar Lubomir I. Ivanov
Based on a current location (MapLocation), iterate the dive list and add nearby dives (distance smaller than m_smallCircleRadius) to a local QList property (m_selectedDiveIds). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: add means to obtain a small circle radiusGravatar Lubomir I. Ivanov
Based on a QGeoCoordinate, calculateSmallCircleRadius() calls some QML Map methods to obtain how big a circle is in meters if a circle is drawn over the Map widget with radius SMALL_CIRCLE_RADIUS_PX pixels. This is called a "small circle" of a sphere: https://en.wikipedia.org/wiki/Circle_of_a_sphere This "small circle" radius becomes huge if the map is zoomed out, while quite small if the map is really zoomed in. The idea behind this circle is to be able to select multiple nearby dives, when clicking on the map (TODO). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: skip dive sites which are near each otherGravatar Lubomir I. Ivanov
Use QGeoCoordinate::distanceTo() to skip dive sites which are too close (50m) to dives sites which are already added as MapLocations. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: add the method copyToClipboardCoordinates()Gravatar Lubomir I. Ivanov
This method uses the helper printGPSCoords() to format the coordinates of a location into either decimal or sexagesimal. The selection is handled by the boolean flag "formatTraditional" and the user preferences flag - prefs.coordinates_traditional. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper.cpp: call deselectMapLocation() in QMLGravatar Lubomir I. Ivanov
If a divesite doesn't have a GPS location we want to deselect the currently selected markers and zoom out the map. In the Map QML object the function deselectMapLocation will handle that. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: pass a MapLocation object to QML in centerOnDiveSite()Gravatar Lubomir I. Ivanov
The function in QML centerOnCoordinate() is now renamed centerOnMapLocation() and accepts a MapLocation object, so that a marker is selected (based on UUID). In MapWidgetHelper::centerOnDiveSite(), the pointer to a MapLocation is retrieved via MapLocationModel::getMapLocationForUuid(). Added in the previous commit. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: add a slot to handle marker selection from the modelGravatar Lubomir I. Ivanov
When MapLocationModel updates the selected marker, MapWidgetHelper now receives a signal. The slot is named selectedLocationChanged(). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28maplocationmodel: add a "uuid" property to MapLocationGravatar Lubomir I. Ivanov
The "uuid" property will be the one from the dive_site. At first it will also be used to track the active marker/flag selection. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: pass a QGeoCoordinate to the QML mapGravatar Lubomir I. Ivanov
Rename the QML function "centerOnCoordinates" to "centerOnCoordinate" and pass a QGeoCoordinate to it in ::centerOnDiveSite(). This will prevent the creation of a QGeoCoordinate object on the QML side and instead it will be created in C++. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28maplocationmodel: use QVector for the MapLocation storageGravatar Lubomir I. Ivanov
QVector is faster, use it for "m_mapLocations" instead of QList. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28maplocationmodel: add the addList() methodGravatar Lubomir I. Ivanov
This method should be used if many markers are added at once. It's main purpose is to reduces the number of beingInsertRows() calls. Make MapWidgetHelper::reloadMapLocations() use it. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidgethelper: add the reloadMapLocations() methodGravatar Lubomir I. Ivanov
reloadMapLocations() is the method which is called when the list of markers (model) should be cleared and re-populated with new MapLocation objects. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28qmlmapwidgethelper: maintain an instance of MapLocationModelGravatar Lubomir I. Ivanov
The idea here is that the QML code should be able to fetch a model from the MapWidgetHelper instance which is instantiated inside the QML code; fetch it in the lines of "mapHelper.model". This way, updates at the backend would be reflected on the Map QML widget. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28add the SPDX-License-Identifier to new source filesGravatar Lubomir I. Ivanov
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mapwidget.qml: add the function centerOnCoordinates()Gravatar Lubomir I. Ivanov
This function can be called to center the map on a specific coordinates. For the C++ version call it via QMetaObject::invokeMethod() in centerOnDiveSite(). TODO: add QML property animations. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28qmlmapwidgethelper: add the centerOnDiveSite() methodGravatar Lubomir I. Ivanov
MapWidget sould not handle any of the map backend. Instead it should just pass calls to MapWidgetHelper. Do that for centerOnDiveSite(). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28qmlmapwidgethelper: remove stray test() methodGravatar Lubomir I. Ivanov
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-07-28mobile-widgets: add the helper class MapWidgetHelperGravatar Lubomir I. Ivanov
The idea with this class is that it should be used by both the mobile and desktop version. TODO STEPS: 1) the class should be registered in both the mobile and desktop version with qmlRegisterType<MapWidgetHelper>... 2) the MapWidget.qml should create an instance of this class. 3) this way the helper will be part of the QML and both the desktop and mobile version can have access to it. 4) the desktop version as a first implementation can just use findChild() in desktop-widgets/mapwidget.cpp. 5) desktop-widgets/mapwidget.cpp on the desktop should just translate calls from the rest of the desktop-widgets to this helper class. 6) the mobile version access to this object would be easy but is off the scope for now. 7) the idea, when implementing the desktop support is to make it so that when implementing the mobile version later, no or only minimal changes would be required to the MapWidgetHelper class. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>