mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-07 19:13:23 +00:00
First cut at selecting dives from the map
We'll want to enhance this: better logic for which dives are near the selection, and it's probably best to have a "control-click" that adds the dives to the selection rather than deselecting all the old ones. But it's already useful. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
b533cf299f
commit
a737f59553
3 changed files with 61 additions and 1 deletions
|
@ -40,6 +40,25 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
|
||||||
connect(searchBox, SIGNAL(textChanged(QString)), model, SLOT(setFilterFixedString(QString)));
|
connect(searchBox, SIGNAL(textChanged(QString)), model, SLOT(setFilterFixedString(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiveListView::unselectDives()
|
||||||
|
{
|
||||||
|
selectionModel()->clearSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiveListView::selectDive(struct dive *dive, bool scrollto)
|
||||||
|
{
|
||||||
|
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
|
||||||
|
QModelIndexList match = m->match(m->index(0,0), TreeItemDT::NR, dive->number, 1, Qt::MatchRecursive);
|
||||||
|
QModelIndex idx = match.first();
|
||||||
|
|
||||||
|
QModelIndex parent = idx.parent();
|
||||||
|
if (parent.isValid())
|
||||||
|
expand(parent);
|
||||||
|
selectionModel()->select( idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||||
|
if (scrollto)
|
||||||
|
scrollTo(idx, PositionAtCenter);
|
||||||
|
}
|
||||||
|
|
||||||
void DiveListView::showSearchEdit()
|
void DiveListView::showSearchEdit()
|
||||||
{
|
{
|
||||||
searchBox->show();
|
searchBox->show();
|
||||||
|
|
|
@ -26,6 +26,8 @@ public:
|
||||||
void currentChanged(const QModelIndex& current, const QModelIndex& previous);
|
void currentChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||||
void reload(DiveTripModel::Layout layout = DiveTripModel::TREE, bool forceSort = true);
|
void reload(DiveTripModel::Layout layout = DiveTripModel::TREE, bool forceSort = true);
|
||||||
bool eventFilter(QObject* , QEvent* );
|
bool eventFilter(QObject* , QEvent* );
|
||||||
|
void unselectDives();
|
||||||
|
void selectDive(struct dive *, bool scrollto = false);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void toggleColumnVisibilityByIndex();
|
void toggleColumnVisibilityByIndex();
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "globe.h"
|
#include "globe.h"
|
||||||
#include "kmessagewidget.h"
|
#include "kmessagewidget.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
#include "ui_mainwindow.h"
|
||||||
#include "../dive.h"
|
#include "../dive.h"
|
||||||
#include "../helpers.h"
|
#include "../helpers.h"
|
||||||
|
|
||||||
|
@ -60,7 +62,44 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
|
||||||
void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
|
void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
|
||||||
{
|
{
|
||||||
GeoDataCoordinates here(lon, lat, unit);
|
GeoDataCoordinates here(lon, lat, unit);
|
||||||
qDebug("At this point Linus will make magic appear... %f/%f", here.longitude(GeoDataCoordinates::Degree), here.latitude(GeoDataCoordinates::Degree));
|
long lon_udeg = rint(1000000 * here.longitude(GeoDataCoordinates::Degree));
|
||||||
|
long lat_udeg = rint(1000000 * here.latitude(GeoDataCoordinates::Degree));
|
||||||
|
|
||||||
|
// distance() is in km above the map.
|
||||||
|
// We're going to use that to decide how
|
||||||
|
// approximate the dives have to be.
|
||||||
|
//
|
||||||
|
// Totally arbitrarily I say that 1km
|
||||||
|
// distance means that we can resolve
|
||||||
|
// to about 100m. Which in turn is about
|
||||||
|
// 1000 udeg.
|
||||||
|
//
|
||||||
|
// Trigonometry is hard, but sin x == x
|
||||||
|
// for small x, so let's just do this as
|
||||||
|
// a linear thing.
|
||||||
|
long resolve = rint(distance() * 1000);
|
||||||
|
|
||||||
|
int idx;
|
||||||
|
struct dive *dive;
|
||||||
|
bool first = true;
|
||||||
|
for_each_dive(idx, dive) {
|
||||||
|
long lat_diff, lon_diff;
|
||||||
|
if (!dive_has_gps_location(dive))
|
||||||
|
continue;
|
||||||
|
lat_diff = labs(dive->latitude.udeg - lat_udeg);
|
||||||
|
lon_diff = labs(dive->longitude.udeg - lon_udeg);
|
||||||
|
if (lat_diff > 180000000)
|
||||||
|
lat_diff = 360000000 - lat_diff;
|
||||||
|
if (lon_diff > 180000000)
|
||||||
|
lon_diff = 180000000 - lon_diff;
|
||||||
|
if (lat_diff > resolve || lon_diff > resolve)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (first)
|
||||||
|
mainWindow()->dive_list()->unselectDives();
|
||||||
|
mainWindow()->dive_list()->selectDive(dive, first);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobeGPS::reload()
|
void GlobeGPS::reload()
|
||||||
|
|
Loading…
Add table
Reference in a new issue