2017-07-16 23:04:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-07-14 21:54:13 +00:00
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QQuickItem>
|
2017-07-15 20:34:44 +00:00
|
|
|
#include <QModelIndex>
|
2017-07-14 21:54:13 +00:00
|
|
|
|
|
|
|
#include "mapwidget.h"
|
2017-07-14 22:26:13 +00:00
|
|
|
#include "core/dive.h"
|
|
|
|
#include "core/divesite.h"
|
2017-07-15 23:59:56 +00:00
|
|
|
#include "mobile-widgets/qmlmapwidgethelper.h"
|
2017-07-17 15:05:28 +00:00
|
|
|
#include "qt-models/maplocationmodel.h"
|
2017-07-14 21:54:13 +00:00
|
|
|
|
|
|
|
MapWidget *MapWidget::m_instance = NULL;
|
|
|
|
|
|
|
|
MapWidget::MapWidget(QWidget *parent) : QQuickWidget(parent)
|
|
|
|
{
|
2017-07-15 23:59:56 +00:00
|
|
|
qmlRegisterType<MapWidgetHelper>("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper");
|
2017-07-17 15:05:28 +00:00
|
|
|
qmlRegisterType<MapLocationModel>("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel");
|
|
|
|
qmlRegisterType<MapLocation>("org.subsurfacedivelog.mobile", 1, 0, "MapLocation");
|
2017-07-15 23:59:56 +00:00
|
|
|
|
2017-07-14 21:54:13 +00:00
|
|
|
setSource(QUrl(QStringLiteral("qrc:/mapwidget-qml")));
|
|
|
|
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
|
|
|
|
|
|
|
m_rootItem = qobject_cast<QQuickItem *>(rootObject());
|
2017-07-16 00:16:13 +00:00
|
|
|
m_mapHelper = rootObject()->findChild<MapWidgetHelper *>();
|
2017-07-14 21:54:13 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 22:26:13 +00:00
|
|
|
void MapWidget::centerOnDiveSite(struct dive_site *ds)
|
|
|
|
{
|
2017-07-16 21:06:05 +00:00
|
|
|
m_mapHelper->centerOnDiveSite(ds);
|
2017-07-14 22:26:13 +00:00
|
|
|
}
|
|
|
|
|
2017-07-15 20:34:44 +00:00
|
|
|
void MapWidget::centerOnIndex(const QModelIndex& idx)
|
|
|
|
{
|
|
|
|
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))
|
|
|
|
centerOnDiveSite(&displayed_dive_site);
|
|
|
|
else
|
|
|
|
centerOnDiveSite(ds);
|
|
|
|
}
|
|
|
|
|
2017-07-15 20:41:31 +00:00
|
|
|
void MapWidget::repopulateLabels()
|
|
|
|
{
|
|
|
|
// TODO;
|
|
|
|
}
|
|
|
|
|
2017-07-15 19:58:16 +00:00
|
|
|
void MapWidget::reload()
|
|
|
|
{
|
|
|
|
// TODO;
|
|
|
|
}
|
|
|
|
|
2017-07-15 20:13:54 +00:00
|
|
|
void MapWidget::endGetDiveCoordinates()
|
|
|
|
{
|
|
|
|
// TODO;
|
|
|
|
}
|
|
|
|
|
2017-07-15 20:51:51 +00:00
|
|
|
void MapWidget::prepareForGetDiveCoordinates()
|
|
|
|
{
|
|
|
|
// TODO;
|
|
|
|
}
|
|
|
|
|
2017-07-14 21:54:13 +00:00
|
|
|
MapWidget::~MapWidget()
|
|
|
|
{
|
|
|
|
m_instance = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MapWidget *MapWidget::instance()
|
|
|
|
{
|
|
|
|
if (m_instance == NULL)
|
|
|
|
m_instance = new MapWidget();
|
|
|
|
return m_instance;
|
|
|
|
}
|