mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Switch new files to unix line endings
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>
This commit is contained in:
parent
5be6fd2f8e
commit
c59cdd6efd
5 changed files with 495 additions and 495 deletions
|
@ -1,102 +1,102 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
|
||||||
#include "mapwidget.h"
|
#include "mapwidget.h"
|
||||||
#include "core/dive.h"
|
#include "core/dive.h"
|
||||||
#include "core/divesite.h"
|
#include "core/divesite.h"
|
||||||
#include "mobile-widgets/qmlmapwidgethelper.h"
|
#include "mobile-widgets/qmlmapwidgethelper.h"
|
||||||
#include "qt-models/maplocationmodel.h"
|
#include "qt-models/maplocationmodel.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "divelistview.h"
|
#include "divelistview.h"
|
||||||
|
|
||||||
static bool skipReload = false;
|
static bool skipReload = false;
|
||||||
|
|
||||||
MapWidget *MapWidget::m_instance = NULL;
|
MapWidget *MapWidget::m_instance = NULL;
|
||||||
|
|
||||||
MapWidget::MapWidget(QWidget *parent) : QQuickWidget(parent)
|
MapWidget::MapWidget(QWidget *parent) : QQuickWidget(parent)
|
||||||
{
|
{
|
||||||
qmlRegisterType<MapWidgetHelper>("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper");
|
qmlRegisterType<MapWidgetHelper>("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper");
|
||||||
qmlRegisterType<MapLocationModel>("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel");
|
qmlRegisterType<MapLocationModel>("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel");
|
||||||
qmlRegisterType<MapLocation>("org.subsurfacedivelog.mobile", 1, 0, "MapLocation");
|
qmlRegisterType<MapLocation>("org.subsurfacedivelog.mobile", 1, 0, "MapLocation");
|
||||||
|
|
||||||
setSource(QUrl(QStringLiteral("qrc:/MapWidget.qml")));
|
setSource(QUrl(QStringLiteral("qrc:/MapWidget.qml")));
|
||||||
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||||
|
|
||||||
m_rootItem = qobject_cast<QQuickItem *>(rootObject());
|
m_rootItem = qobject_cast<QQuickItem *>(rootObject());
|
||||||
m_mapHelper = rootObject()->findChild<MapWidgetHelper *>();
|
m_mapHelper = rootObject()->findChild<MapWidgetHelper *>();
|
||||||
connect(m_mapHelper, SIGNAL(selectedDivesChanged(QList<int>)),
|
connect(m_mapHelper, SIGNAL(selectedDivesChanged(QList<int>)),
|
||||||
this, SLOT(selectedDivesChanged(QList<int>)));
|
this, SLOT(selectedDivesChanged(QList<int>)));
|
||||||
connect(m_mapHelper, SIGNAL(coordinatesChanged()),
|
connect(m_mapHelper, SIGNAL(coordinatesChanged()),
|
||||||
this, SLOT(coordinatesChangedLocal()));
|
this, SLOT(coordinatesChangedLocal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::centerOnDiveSite(struct dive_site *ds)
|
void MapWidget::centerOnDiveSite(struct dive_site *ds)
|
||||||
{
|
{
|
||||||
if (!skipReload)
|
if (!skipReload)
|
||||||
m_mapHelper->centerOnDiveSite(ds);
|
m_mapHelper->centerOnDiveSite(ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::centerOnIndex(const QModelIndex& idx)
|
void MapWidget::centerOnIndex(const QModelIndex& idx)
|
||||||
{
|
{
|
||||||
struct dive_site *ds = get_dive_site_by_uuid(idx.model()->index(idx.row(), 0).data().toInt());
|
struct dive_site *ds = get_dive_site_by_uuid(idx.model()->index(idx.row(), 0).data().toInt());
|
||||||
if (!ds || !dive_site_has_gps_location(ds))
|
if (!ds || !dive_site_has_gps_location(ds))
|
||||||
centerOnDiveSite(&displayed_dive_site);
|
centerOnDiveSite(&displayed_dive_site);
|
||||||
else
|
else
|
||||||
centerOnDiveSite(ds);
|
centerOnDiveSite(ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::repopulateLabels()
|
void MapWidget::repopulateLabels()
|
||||||
{
|
{
|
||||||
m_mapHelper->reloadMapLocations();
|
m_mapHelper->reloadMapLocations();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::reload()
|
void MapWidget::reload()
|
||||||
{
|
{
|
||||||
setEditMode(false);
|
setEditMode(false);
|
||||||
if (!skipReload)
|
if (!skipReload)
|
||||||
m_mapHelper->reloadMapLocations();
|
m_mapHelper->reloadMapLocations();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::setEditMode(bool editMode)
|
void MapWidget::setEditMode(bool editMode)
|
||||||
{
|
{
|
||||||
m_mapHelper->setEditMode(editMode);
|
m_mapHelper->setEditMode(editMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::endGetDiveCoordinates()
|
void MapWidget::endGetDiveCoordinates()
|
||||||
{
|
{
|
||||||
setEditMode(false);
|
setEditMode(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::prepareForGetDiveCoordinates()
|
void MapWidget::prepareForGetDiveCoordinates()
|
||||||
{
|
{
|
||||||
setEditMode(true);
|
setEditMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::selectedDivesChanged(QList<int> list)
|
void MapWidget::selectedDivesChanged(QList<int> list)
|
||||||
{
|
{
|
||||||
skipReload = true;
|
skipReload = true;
|
||||||
MainWindow::instance()->dive_list()->unselectDives();
|
MainWindow::instance()->dive_list()->unselectDives();
|
||||||
if (!list.empty())
|
if (!list.empty())
|
||||||
MainWindow::instance()->dive_list()->selectDives(list);
|
MainWindow::instance()->dive_list()->selectDives(list);
|
||||||
skipReload = false;
|
skipReload = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::coordinatesChangedLocal()
|
void MapWidget::coordinatesChangedLocal()
|
||||||
{
|
{
|
||||||
emit coordinatesChanged();
|
emit coordinatesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
MapWidget::~MapWidget()
|
MapWidget::~MapWidget()
|
||||||
{
|
{
|
||||||
m_instance = NULL;
|
m_instance = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
MapWidget *MapWidget::instance()
|
MapWidget *MapWidget::instance()
|
||||||
{
|
{
|
||||||
if (m_instance == NULL)
|
if (m_instance == NULL)
|
||||||
m_instance = new MapWidget();
|
m_instance = new MapWidget();
|
||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +1,45 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#ifndef MAPWIDGET_H
|
#ifndef MAPWIDGET_H
|
||||||
#define MAPWIDGET_H
|
#define MAPWIDGET_H
|
||||||
|
|
||||||
#include <QQuickWidget>
|
#include <QQuickWidget>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
#undef IGNORE
|
#undef IGNORE
|
||||||
|
|
||||||
class QResizeEvent;
|
class QResizeEvent;
|
||||||
class QQuickItem;
|
class QQuickItem;
|
||||||
class MapWidgetHelper;
|
class MapWidgetHelper;
|
||||||
struct dive_site;
|
struct dive_site;
|
||||||
|
|
||||||
class MapWidget : public QQuickWidget {
|
class MapWidget : public QQuickWidget {
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MapWidget(QWidget *parent = NULL);
|
MapWidget(QWidget *parent = NULL);
|
||||||
~MapWidget();
|
~MapWidget();
|
||||||
|
|
||||||
static MapWidget *instance();
|
static MapWidget *instance();
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void coordinatesChanged();
|
void coordinatesChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void centerOnDiveSite(struct dive_site *);
|
void centerOnDiveSite(struct dive_site *);
|
||||||
void centerOnIndex(const QModelIndex& idx);
|
void centerOnIndex(const QModelIndex& idx);
|
||||||
void endGetDiveCoordinates();
|
void endGetDiveCoordinates();
|
||||||
void repopulateLabels();
|
void repopulateLabels();
|
||||||
void prepareForGetDiveCoordinates();
|
void prepareForGetDiveCoordinates();
|
||||||
void selectedDivesChanged(QList<int>);
|
void selectedDivesChanged(QList<int>);
|
||||||
void coordinatesChangedLocal();
|
void coordinatesChangedLocal();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setEditMode(bool editMode);
|
void setEditMode(bool editMode);
|
||||||
static MapWidget *m_instance;
|
static MapWidget *m_instance;
|
||||||
QQuickItem *m_rootItem;
|
QQuickItem *m_rootItem;
|
||||||
MapWidgetHelper *m_mapHelper;
|
MapWidgetHelper *m_mapHelper;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAPWIDGET_H
|
#endif // MAPWIDGET_H
|
||||||
|
|
|
@ -1,161 +1,161 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QGeoCoordinate>
|
#include <QGeoCoordinate>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "qmlmapwidgethelper.h"
|
#include "qmlmapwidgethelper.h"
|
||||||
#include "core/dive.h"
|
#include "core/dive.h"
|
||||||
#include "core/divesite.h"
|
#include "core/divesite.h"
|
||||||
#include "qt-models/maplocationmodel.h"
|
#include "qt-models/maplocationmodel.h"
|
||||||
|
|
||||||
#define MIN_DISTANCE_BETWEEN_DIVE_SITES_M 50.0
|
#define MIN_DISTANCE_BETWEEN_DIVE_SITES_M 50.0
|
||||||
#define SMALL_CIRCLE_RADIUS_PX 26.0
|
#define SMALL_CIRCLE_RADIUS_PX 26.0
|
||||||
|
|
||||||
MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
|
MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
m_mapLocationModel = new MapLocationModel(this);
|
m_mapLocationModel = new MapLocationModel(this);
|
||||||
connect(m_mapLocationModel, SIGNAL(selectedLocationChanged(MapLocation *)),
|
connect(m_mapLocationModel, SIGNAL(selectedLocationChanged(MapLocation *)),
|
||||||
this, SLOT(selectedLocationChanged(MapLocation *)));
|
this, SLOT(selectedLocationChanged(MapLocation *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds)
|
void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds)
|
||||||
{
|
{
|
||||||
if (!dive_site_has_gps_location(ds)) {
|
if (!dive_site_has_gps_location(ds)) {
|
||||||
m_mapLocationModel->setSelectedUuid(ds ? ds->uuid : 0, false);
|
m_mapLocationModel->setSelectedUuid(ds ? ds->uuid : 0, false);
|
||||||
QMetaObject::invokeMethod(m_map, "deselectMapLocation");
|
QMetaObject::invokeMethod(m_map, "deselectMapLocation");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_mapLocationModel->setSelectedUuid(ds->uuid, false);
|
m_mapLocationModel->setSelectedUuid(ds->uuid, false);
|
||||||
const qreal latitude = ds->latitude.udeg * 0.000001;
|
const qreal latitude = ds->latitude.udeg * 0.000001;
|
||||||
const qreal longitude = ds->longitude.udeg * 0.000001;
|
const qreal longitude = ds->longitude.udeg * 0.000001;
|
||||||
QGeoCoordinate dsCoord(latitude, longitude);
|
QGeoCoordinate dsCoord(latitude, longitude);
|
||||||
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord)));
|
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidgetHelper::reloadMapLocations()
|
void MapWidgetHelper::reloadMapLocations()
|
||||||
{
|
{
|
||||||
struct dive_site *ds;
|
struct dive_site *ds;
|
||||||
int idx;
|
int idx;
|
||||||
QMap<QString, MapLocation *> locationNameMap;
|
QMap<QString, MapLocation *> locationNameMap;
|
||||||
m_mapLocationModel->clear();
|
m_mapLocationModel->clear();
|
||||||
MapLocation *location;
|
MapLocation *location;
|
||||||
QVector<MapLocation *> locationList;
|
QVector<MapLocation *> locationList;
|
||||||
qreal latitude, longitude;
|
qreal latitude, longitude;
|
||||||
|
|
||||||
if (displayed_dive_site.uuid && dive_site_has_gps_location(&displayed_dive_site)) {
|
if (displayed_dive_site.uuid && dive_site_has_gps_location(&displayed_dive_site)) {
|
||||||
latitude = displayed_dive_site.latitude.udeg * 0.000001;
|
latitude = displayed_dive_site.latitude.udeg * 0.000001;
|
||||||
longitude = displayed_dive_site.longitude.udeg * 0.000001;
|
longitude = displayed_dive_site.longitude.udeg * 0.000001;
|
||||||
location = new MapLocation(displayed_dive_site.uuid, QGeoCoordinate(latitude, longitude),
|
location = new MapLocation(displayed_dive_site.uuid, QGeoCoordinate(latitude, longitude),
|
||||||
QString(displayed_dive_site.name));
|
QString(displayed_dive_site.name));
|
||||||
locationList.append(location);
|
locationList.append(location);
|
||||||
locationNameMap[QString(displayed_dive_site.name)] = location;
|
locationNameMap[QString(displayed_dive_site.name)] = location;
|
||||||
}
|
}
|
||||||
for_each_dive_site(idx, ds) {
|
for_each_dive_site(idx, ds) {
|
||||||
if (!dive_site_has_gps_location(ds) || ds->uuid == displayed_dive_site.uuid)
|
if (!dive_site_has_gps_location(ds) || ds->uuid == displayed_dive_site.uuid)
|
||||||
continue;
|
continue;
|
||||||
latitude = ds->latitude.udeg * 0.000001;
|
latitude = ds->latitude.udeg * 0.000001;
|
||||||
longitude = ds->longitude.udeg * 0.000001;
|
longitude = ds->longitude.udeg * 0.000001;
|
||||||
QGeoCoordinate dsCoord(latitude, longitude);
|
QGeoCoordinate dsCoord(latitude, longitude);
|
||||||
QString name(ds->name);
|
QString name(ds->name);
|
||||||
// don't add dive locations with the same name, unless they are
|
// don't add dive locations with the same name, unless they are
|
||||||
// at least MIN_DISTANCE_BETWEEN_DIVE_SITES_M apart
|
// at least MIN_DISTANCE_BETWEEN_DIVE_SITES_M apart
|
||||||
if (locationNameMap[name]) {
|
if (locationNameMap[name]) {
|
||||||
MapLocation *existingLocation = locationNameMap[name];
|
MapLocation *existingLocation = locationNameMap[name];
|
||||||
QGeoCoordinate coord = qvariant_cast<QGeoCoordinate>(existingLocation->getRole(MapLocation::Roles::RoleCoordinate));
|
QGeoCoordinate coord = qvariant_cast<QGeoCoordinate>(existingLocation->getRole(MapLocation::Roles::RoleCoordinate));
|
||||||
if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M)
|
if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
location = new MapLocation(ds->uuid, dsCoord, name);
|
location = new MapLocation(ds->uuid, dsCoord, name);
|
||||||
locationList.append(location);
|
locationList.append(location);
|
||||||
locationNameMap[name] = location;
|
locationNameMap[name] = location;
|
||||||
}
|
}
|
||||||
m_mapLocationModel->addList(locationList);
|
m_mapLocationModel->addList(locationList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidgetHelper::selectedLocationChanged(MapLocation *location)
|
void MapWidgetHelper::selectedLocationChanged(MapLocation *location)
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
struct dive *dive;
|
struct dive *dive;
|
||||||
m_selectedDiveIds.clear();
|
m_selectedDiveIds.clear();
|
||||||
QGeoCoordinate locationCoord = location->coordinate();
|
QGeoCoordinate locationCoord = location->coordinate();
|
||||||
for_each_dive (idx, dive) {
|
for_each_dive (idx, dive) {
|
||||||
struct dive_site *ds = get_dive_site_for_dive(dive);
|
struct dive_site *ds = get_dive_site_for_dive(dive);
|
||||||
if (!dive_site_has_gps_location(ds))
|
if (!dive_site_has_gps_location(ds))
|
||||||
continue;
|
continue;
|
||||||
const qreal latitude = ds->latitude.udeg * 0.000001;
|
const qreal latitude = ds->latitude.udeg * 0.000001;
|
||||||
const qreal longitude = ds->longitude.udeg * 0.000001;
|
const qreal longitude = ds->longitude.udeg * 0.000001;
|
||||||
QGeoCoordinate dsCoord(latitude, longitude);
|
QGeoCoordinate dsCoord(latitude, longitude);
|
||||||
if (locationCoord.distanceTo(dsCoord) < m_smallCircleRadius)
|
if (locationCoord.distanceTo(dsCoord) < m_smallCircleRadius)
|
||||||
m_selectedDiveIds.append(idx);
|
m_selectedDiveIds.append(idx);
|
||||||
}
|
}
|
||||||
emit selectedDivesChanged(m_selectedDiveIds);
|
emit selectedDivesChanged(m_selectedDiveIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Based on a 2D Map widget circle with center "coord" and radius SMALL_CIRCLE_RADIUS_PX,
|
* Based on a 2D Map widget circle with center "coord" and radius SMALL_CIRCLE_RADIUS_PX,
|
||||||
* obtain a "small circle" with radius m_smallCircleRadius in meters:
|
* obtain a "small circle" with radius m_smallCircleRadius in meters:
|
||||||
* https://en.wikipedia.org/wiki/Circle_of_a_sphere
|
* https://en.wikipedia.org/wiki/Circle_of_a_sphere
|
||||||
*
|
*
|
||||||
* The idea behind this circle is to be able to select multiple nearby dives, when clicking on
|
* The idea behind this circle is to be able to select multiple nearby dives, when clicking on
|
||||||
* the map. This code can be in QML, but it is in C++ instead for performance reasons.
|
* the map. This code can be in QML, but it is in C++ instead for performance reasons.
|
||||||
*
|
*
|
||||||
* This can be made faster with an exponential regression [a * exp(b * x)], with a pretty
|
* This can be made faster with an exponential regression [a * exp(b * x)], with a pretty
|
||||||
* decent R-squared, but it becomes bound to map provider zoom level mappings and the
|
* decent R-squared, but it becomes bound to map provider zoom level mappings and the
|
||||||
* SMALL_CIRCLE_RADIUS_PX value, which makes the code hard to maintain.
|
* SMALL_CIRCLE_RADIUS_PX value, which makes the code hard to maintain.
|
||||||
*/
|
*/
|
||||||
void MapWidgetHelper::calculateSmallCircleRadius(QGeoCoordinate coord)
|
void MapWidgetHelper::calculateSmallCircleRadius(QGeoCoordinate coord)
|
||||||
{
|
{
|
||||||
QPointF point;
|
QPointF point;
|
||||||
QMetaObject::invokeMethod(m_map, "fromCoordinate", Q_RETURN_ARG(QPointF, point),
|
QMetaObject::invokeMethod(m_map, "fromCoordinate", Q_RETURN_ARG(QPointF, point),
|
||||||
Q_ARG(QGeoCoordinate, coord), Q_ARG(bool, false));
|
Q_ARG(QGeoCoordinate, coord), Q_ARG(bool, false));
|
||||||
QPointF point2(point.x() + SMALL_CIRCLE_RADIUS_PX, point.y());
|
QPointF point2(point.x() + SMALL_CIRCLE_RADIUS_PX, point.y());
|
||||||
QGeoCoordinate coord2;
|
QGeoCoordinate coord2;
|
||||||
QMetaObject::invokeMethod(m_map, "toCoordinate", Q_RETURN_ARG(QGeoCoordinate, coord2),
|
QMetaObject::invokeMethod(m_map, "toCoordinate", Q_RETURN_ARG(QGeoCoordinate, coord2),
|
||||||
Q_ARG(QPointF, point2), Q_ARG(bool, false));
|
Q_ARG(QPointF, point2), Q_ARG(bool, false));
|
||||||
m_smallCircleRadius = coord2.distanceTo(coord);
|
m_smallCircleRadius = coord2.distanceTo(coord);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidgetHelper::copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional)
|
void MapWidgetHelper::copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional)
|
||||||
{
|
{
|
||||||
bool savep = prefs.coordinates_traditional;
|
bool savep = prefs.coordinates_traditional;
|
||||||
prefs.coordinates_traditional = formatTraditional;
|
prefs.coordinates_traditional = formatTraditional;
|
||||||
|
|
||||||
const int lat = llrint(1000000.0 * coord.latitude());
|
const int lat = llrint(1000000.0 * coord.latitude());
|
||||||
const int lon = llrint(1000000.0 * coord.longitude());
|
const int lon = llrint(1000000.0 * coord.longitude());
|
||||||
const char *coordinates = printGPSCoords(lat, lon);
|
const char *coordinates = printGPSCoords(lat, lon);
|
||||||
QApplication::clipboard()->setText(QString(coordinates), QClipboard::Clipboard);
|
QApplication::clipboard()->setText(QString(coordinates), QClipboard::Clipboard);
|
||||||
|
|
||||||
free((void *)coordinates);
|
free((void *)coordinates);
|
||||||
prefs.coordinates_traditional = savep;
|
prefs.coordinates_traditional = savep;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidgetHelper::updateCurrentDiveSiteCoordinates(quint32 uuid, QGeoCoordinate coord)
|
void MapWidgetHelper::updateCurrentDiveSiteCoordinates(quint32 uuid, QGeoCoordinate coord)
|
||||||
{
|
{
|
||||||
MapLocation *loc = m_mapLocationModel->getMapLocationForUuid(uuid);
|
MapLocation *loc = m_mapLocationModel->getMapLocationForUuid(uuid);
|
||||||
if (loc)
|
if (loc)
|
||||||
loc->setCoordinate(coord);
|
loc->setCoordinate(coord);
|
||||||
displayed_dive_site.latitude.udeg = llrint(coord.latitude() * 1000000.0);
|
displayed_dive_site.latitude.udeg = llrint(coord.latitude() * 1000000.0);
|
||||||
displayed_dive_site.longitude.udeg = llrint(coord.longitude() * 1000000.0);
|
displayed_dive_site.longitude.udeg = llrint(coord.longitude() * 1000000.0);
|
||||||
emit coordinatesChanged();
|
emit coordinatesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapWidgetHelper::editMode()
|
bool MapWidgetHelper::editMode()
|
||||||
{
|
{
|
||||||
return m_editMode;
|
return m_editMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidgetHelper::setEditMode(bool editMode)
|
void MapWidgetHelper::setEditMode(bool editMode)
|
||||||
{
|
{
|
||||||
m_editMode = editMode;
|
m_editMode = editMode;
|
||||||
MapLocation *exists = m_mapLocationModel->getMapLocationForUuid(displayed_dive_site.uuid);
|
MapLocation *exists = m_mapLocationModel->getMapLocationForUuid(displayed_dive_site.uuid);
|
||||||
// if divesite uuid doesn't exist in the model, add a new MapLocation.
|
// if divesite uuid doesn't exist in the model, add a new MapLocation.
|
||||||
if (editMode && !exists) {
|
if (editMode && !exists) {
|
||||||
QGeoCoordinate coord(0.0, 0.0);
|
QGeoCoordinate coord(0.0, 0.0);
|
||||||
m_mapLocationModel->add(new MapLocation(displayed_dive_site.uuid, coord,
|
m_mapLocationModel->add(new MapLocation(displayed_dive_site.uuid, coord,
|
||||||
QString(displayed_dive_site.name)));
|
QString(displayed_dive_site.name)));
|
||||||
QMetaObject::invokeMethod(m_map, "centerOnCoordinate",
|
QMetaObject::invokeMethod(m_map, "centerOnCoordinate",
|
||||||
Q_ARG(QVariant, QVariant::fromValue(coord)));
|
Q_ARG(QVariant, QVariant::fromValue(coord)));
|
||||||
}
|
}
|
||||||
emit editModeChanged();
|
emit editModeChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,49 +1,49 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#ifndef QMLMAPWIDGETHELPER_H
|
#ifndef QMLMAPWIDGETHELPER_H
|
||||||
#define QMLMAPWIDGETHELPER_H
|
#define QMLMAPWIDGETHELPER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class QGeoCoordinate;
|
class QGeoCoordinate;
|
||||||
class MapLocationModel;
|
class MapLocationModel;
|
||||||
class MapLocation;
|
class MapLocation;
|
||||||
struct dive_site;
|
struct dive_site;
|
||||||
|
|
||||||
class MapWidgetHelper : public QObject {
|
class MapWidgetHelper : public QObject {
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QObject *map MEMBER m_map)
|
Q_PROPERTY(QObject *map MEMBER m_map)
|
||||||
Q_PROPERTY(MapLocationModel *model MEMBER m_mapLocationModel NOTIFY modelChanged)
|
Q_PROPERTY(MapLocationModel *model MEMBER m_mapLocationModel NOTIFY modelChanged)
|
||||||
Q_PROPERTY(bool editMode READ editMode WRITE setEditMode NOTIFY editModeChanged)
|
Q_PROPERTY(bool editMode READ editMode WRITE setEditMode NOTIFY editModeChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MapWidgetHelper(QObject *parent = NULL);
|
explicit MapWidgetHelper(QObject *parent = NULL);
|
||||||
|
|
||||||
void centerOnDiveSite(struct dive_site *);
|
void centerOnDiveSite(struct dive_site *);
|
||||||
void reloadMapLocations();
|
void reloadMapLocations();
|
||||||
Q_INVOKABLE void copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional);
|
Q_INVOKABLE void copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional);
|
||||||
Q_INVOKABLE void calculateSmallCircleRadius(QGeoCoordinate coord);
|
Q_INVOKABLE void calculateSmallCircleRadius(QGeoCoordinate coord);
|
||||||
Q_INVOKABLE void updateCurrentDiveSiteCoordinates(quint32 uuid, QGeoCoordinate coord);
|
Q_INVOKABLE void updateCurrentDiveSiteCoordinates(quint32 uuid, QGeoCoordinate coord);
|
||||||
bool editMode();
|
bool editMode();
|
||||||
void setEditMode(bool editMode);
|
void setEditMode(bool editMode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QObject *m_map;
|
QObject *m_map;
|
||||||
MapLocationModel *m_mapLocationModel;
|
MapLocationModel *m_mapLocationModel;
|
||||||
qreal m_smallCircleRadius;
|
qreal m_smallCircleRadius;
|
||||||
QList<int> m_selectedDiveIds;
|
QList<int> m_selectedDiveIds;
|
||||||
bool m_editMode;
|
bool m_editMode;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void selectedLocationChanged(MapLocation *);
|
void selectedLocationChanged(MapLocation *);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void modelChanged();
|
void modelChanged();
|
||||||
void editModeChanged();
|
void editModeChanged();
|
||||||
void selectedDivesChanged(QList<int> list);
|
void selectedDivesChanged(QList<int> list);
|
||||||
void coordinatesChanged();
|
void coordinatesChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" const char *printGPSCoords(int lat, int lon);
|
extern "C" const char *printGPSCoords(int lat, int lon);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,138 +1,138 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include "maplocationmodel.h"
|
#include "maplocationmodel.h"
|
||||||
|
|
||||||
const char *MapLocation::PROPERTY_NAME_COORDINATE = "coordinate";
|
const char *MapLocation::PROPERTY_NAME_COORDINATE = "coordinate";
|
||||||
const char *MapLocation::PROPERTY_NAME_UUID = "uuid";
|
const char *MapLocation::PROPERTY_NAME_UUID = "uuid";
|
||||||
const char *MapLocation::PROPERTY_NAME_NAME = "name";
|
const char *MapLocation::PROPERTY_NAME_NAME = "name";
|
||||||
|
|
||||||
MapLocation::MapLocation()
|
MapLocation::MapLocation()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MapLocation::MapLocation(quint32 uuid, QGeoCoordinate coord, QString name) :
|
MapLocation::MapLocation(quint32 uuid, QGeoCoordinate coord, QString name) :
|
||||||
m_uuid(uuid), m_coordinate(coord), m_name(name)
|
m_uuid(uuid), m_coordinate(coord), m_name(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MapLocation::getRole(int role) const
|
QVariant MapLocation::getRole(int role) const
|
||||||
{
|
{
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::RoleUuid:
|
case Roles::RoleUuid:
|
||||||
return QVariant::fromValue(m_uuid);
|
return QVariant::fromValue(m_uuid);
|
||||||
case Roles::RoleCoordinate:
|
case Roles::RoleCoordinate:
|
||||||
return QVariant::fromValue(m_coordinate);
|
return QVariant::fromValue(m_coordinate);
|
||||||
case Roles::RoleName:
|
case Roles::RoleName:
|
||||||
return QVariant::fromValue(m_name);
|
return QVariant::fromValue(m_name);
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QGeoCoordinate MapLocation::coordinate()
|
QGeoCoordinate MapLocation::coordinate()
|
||||||
{
|
{
|
||||||
return m_coordinate;
|
return m_coordinate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLocation::setCoordinate(QGeoCoordinate coord)
|
void MapLocation::setCoordinate(QGeoCoordinate coord)
|
||||||
{
|
{
|
||||||
m_coordinate = coord;
|
m_coordinate = coord;
|
||||||
emit coordinateChanged();
|
emit coordinateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 MapLocation::uuid()
|
quint32 MapLocation::uuid()
|
||||||
{
|
{
|
||||||
return m_uuid;
|
return m_uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent)
|
MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
m_roles[MapLocation::Roles::RoleUuid] = MapLocation::PROPERTY_NAME_UUID;
|
m_roles[MapLocation::Roles::RoleUuid] = MapLocation::PROPERTY_NAME_UUID;
|
||||||
m_roles[MapLocation::Roles::RoleCoordinate] = MapLocation::PROPERTY_NAME_COORDINATE;
|
m_roles[MapLocation::Roles::RoleCoordinate] = MapLocation::PROPERTY_NAME_COORDINATE;
|
||||||
m_roles[MapLocation::Roles::RoleName] = MapLocation::PROPERTY_NAME_NAME;
|
m_roles[MapLocation::Roles::RoleName] = MapLocation::PROPERTY_NAME_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
MapLocationModel::~MapLocationModel()
|
MapLocationModel::~MapLocationModel()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MapLocationModel::data(const QModelIndex & index, int role) const
|
QVariant MapLocationModel::data(const QModelIndex & index, int role) const
|
||||||
{
|
{
|
||||||
if (index.row() < 0 || index.row() >= m_mapLocations.size())
|
if (index.row() < 0 || index.row() >= m_mapLocations.size())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
return m_mapLocations.at(index.row())->getRole(role);
|
return m_mapLocations.at(index.row())->getRole(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> MapLocationModel::roleNames() const
|
QHash<int, QByteArray> MapLocationModel::roleNames() const
|
||||||
{
|
{
|
||||||
return m_roles;
|
return m_roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MapLocationModel::rowCount(const QModelIndex &parent) const
|
int MapLocationModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return m_mapLocations.size();
|
return m_mapLocations.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int MapLocationModel::count()
|
int MapLocationModel::count()
|
||||||
{
|
{
|
||||||
return m_mapLocations.size();
|
return m_mapLocations.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
MapLocation *MapLocationModel::get(int row)
|
MapLocation *MapLocationModel::get(int row)
|
||||||
{
|
{
|
||||||
if (row < 0 || row >= m_mapLocations.size())
|
if (row < 0 || row >= m_mapLocations.size())
|
||||||
return NULL;
|
return NULL;
|
||||||
return m_mapLocations.at(row);
|
return m_mapLocations.at(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLocationModel::add(MapLocation *location)
|
void MapLocationModel::add(MapLocation *location)
|
||||||
{
|
{
|
||||||
beginInsertRows(QModelIndex(), m_mapLocations.size(), m_mapLocations.size());
|
beginInsertRows(QModelIndex(), m_mapLocations.size(), m_mapLocations.size());
|
||||||
m_mapLocations.append(location);
|
m_mapLocations.append(location);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLocationModel::addList(QVector<MapLocation *> list)
|
void MapLocationModel::addList(QVector<MapLocation *> list)
|
||||||
{
|
{
|
||||||
if (!list.size())
|
if (!list.size())
|
||||||
return;
|
return;
|
||||||
beginInsertRows(QModelIndex(), m_mapLocations.size(), m_mapLocations.size() + list.size() - 1);
|
beginInsertRows(QModelIndex(), m_mapLocations.size(), m_mapLocations.size() + list.size() - 1);
|
||||||
m_mapLocations.append(list);
|
m_mapLocations.append(list);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLocationModel::clear()
|
void MapLocationModel::clear()
|
||||||
{
|
{
|
||||||
if (!m_mapLocations.size())
|
if (!m_mapLocations.size())
|
||||||
return;
|
return;
|
||||||
beginRemoveRows(QModelIndex(), 0, m_mapLocations.size() - 1);
|
beginRemoveRows(QModelIndex(), 0, m_mapLocations.size() - 1);
|
||||||
qDeleteAll(m_mapLocations);
|
qDeleteAll(m_mapLocations);
|
||||||
m_mapLocations.clear();
|
m_mapLocations.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLocationModel::setSelectedUuid(QVariant uuid, QVariant fromClick)
|
void MapLocationModel::setSelectedUuid(QVariant uuid, QVariant fromClick)
|
||||||
{
|
{
|
||||||
m_selectedUuid = qvariant_cast<quint32>(uuid);
|
m_selectedUuid = qvariant_cast<quint32>(uuid);
|
||||||
const bool fromClickBool = qvariant_cast<bool>(fromClick);
|
const bool fromClickBool = qvariant_cast<bool>(fromClick);
|
||||||
emit selectedUuidChanged();
|
emit selectedUuidChanged();
|
||||||
if (fromClickBool)
|
if (fromClickBool)
|
||||||
emit selectedLocationChanged(getMapLocationForUuid(m_selectedUuid));
|
emit selectedLocationChanged(getMapLocationForUuid(m_selectedUuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 MapLocationModel::selectedUuid()
|
quint32 MapLocationModel::selectedUuid()
|
||||||
{
|
{
|
||||||
return m_selectedUuid;
|
return m_selectedUuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
MapLocation *MapLocationModel::getMapLocationForUuid(quint32 uuid)
|
MapLocation *MapLocationModel::getMapLocationForUuid(quint32 uuid)
|
||||||
{
|
{
|
||||||
MapLocation *location;
|
MapLocation *location;
|
||||||
foreach(location, m_mapLocations) {
|
foreach(location, m_mapLocations) {
|
||||||
if (uuid == location->uuid())
|
if (uuid == location->uuid())
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue