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-24 18:47:19 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "divelistview.h"
|
2017-07-14 21:54:13 +00:00
|
|
|
|
2017-07-24 19:47:37 +00:00
|
|
|
static bool skipReload = false;
|
|
|
|
|
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-20 13:50:16 +00:00
|
|
|
setSource(QUrl(QStringLiteral("qrc:/MapWidget.qml")));
|
2017-07-14 21:54:13 +00:00
|
|
|
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
|
|
|
|
|
|
|
m_rootItem = qobject_cast<QQuickItem *>(rootObject());
|
2017-07-16 00:16:13 +00:00
|
|
|
m_mapHelper = rootObject()->findChild<MapWidgetHelper *>();
|
2017-07-24 18:47:19 +00:00
|
|
|
connect(m_mapHelper, SIGNAL(selectedDivesChanged(QList<int>)),
|
|
|
|
this, SLOT(selectedDivesChanged(QList<int>)));
|
2017-07-27 20:59:30 +00:00
|
|
|
connect(m_mapHelper, SIGNAL(coordinatesChanged()),
|
|
|
|
this, SLOT(coordinatesChangedLocal()));
|
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-27 20:59:30 +00:00
|
|
|
if (!skipReload)
|
|
|
|
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()
|
|
|
|
{
|
2017-07-17 19:39:38 +00:00
|
|
|
m_mapHelper->reloadMapLocations();
|
2017-07-15 20:41:31 +00:00
|
|
|
}
|
|
|
|
|
2017-07-15 19:58:16 +00:00
|
|
|
void MapWidget::reload()
|
|
|
|
{
|
2017-07-27 20:59:30 +00:00
|
|
|
setEditMode(false);
|
2017-07-24 19:47:37 +00:00
|
|
|
if (!skipReload)
|
|
|
|
m_mapHelper->reloadMapLocations();
|
2017-07-15 19:58:16 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 20:59:30 +00:00
|
|
|
void MapWidget::setEditMode(bool editMode)
|
|
|
|
{
|
|
|
|
m_mapHelper->setEditMode(editMode);
|
|
|
|
}
|
|
|
|
|
2017-07-15 20:13:54 +00:00
|
|
|
void MapWidget::endGetDiveCoordinates()
|
|
|
|
{
|
2017-07-27 20:59:30 +00:00
|
|
|
setEditMode(false);
|
2017-07-15 20:13:54 +00:00
|
|
|
}
|
|
|
|
|
2017-07-15 20:51:51 +00:00
|
|
|
void MapWidget::prepareForGetDiveCoordinates()
|
|
|
|
{
|
2017-07-27 20:59:30 +00:00
|
|
|
setEditMode(true);
|
2017-07-15 20:51:51 +00:00
|
|
|
}
|
|
|
|
|
2017-07-24 18:47:19 +00:00
|
|
|
void MapWidget::selectedDivesChanged(QList<int> list)
|
|
|
|
{
|
2017-07-24 19:47:37 +00:00
|
|
|
skipReload = true;
|
2017-07-24 18:47:19 +00:00
|
|
|
MainWindow::instance()->dive_list()->unselectDives();
|
|
|
|
if (!list.empty())
|
|
|
|
MainWindow::instance()->dive_list()->selectDives(list);
|
2017-07-24 19:47:37 +00:00
|
|
|
skipReload = false;
|
2017-07-24 18:47:19 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 20:59:30 +00:00
|
|
|
void MapWidget::coordinatesChangedLocal()
|
|
|
|
{
|
|
|
|
emit coordinatesChanged();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|