mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:43:24 +00:00
Added the possibility to change the coordinates of a dive.
Added the possibility to change the coordinates of a dive. it's too intrusive in the moment, but it was a proof of concept. so I'll commit as is and try to find a better way to warn the user what's going on in the future, using something less terrible than a popup exploding in his face. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
b89265c7f0
commit
56dbb7c2ff
2 changed files with 68 additions and 11 deletions
|
@ -9,7 +9,8 @@
|
||||||
#include <marble/MarbleModel.h>
|
#include <marble/MarbleModel.h>
|
||||||
#include <marble/GeoDataTreeModel.h>
|
#include <marble/GeoDataTreeModel.h>
|
||||||
|
|
||||||
using namespace Marble;
|
#include <QMouseEvent>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
|
GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
|
||||||
{
|
{
|
||||||
|
@ -31,7 +32,6 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
|
||||||
floatItem->setContentSize( QSize( 50, 50 ) );
|
floatItem->setContentSize( QSize( 50, 50 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobeGPS::reload()
|
void GlobeGPS::reload()
|
||||||
|
@ -40,7 +40,9 @@ void GlobeGPS::reload()
|
||||||
model()->treeModel()->removeDocument(loadedDives);
|
model()->treeModel()->removeDocument(loadedDives);
|
||||||
delete loadedDives;
|
delete loadedDives;
|
||||||
}
|
}
|
||||||
|
if (editingDiveCoords){
|
||||||
|
editingDiveCoords = 0;
|
||||||
|
}
|
||||||
|
|
||||||
loadedDives = new GeoDataDocument;
|
loadedDives = new GeoDataDocument;
|
||||||
|
|
||||||
|
@ -62,5 +64,50 @@ void GlobeGPS::reload()
|
||||||
|
|
||||||
void GlobeGPS::centerOn(dive* dive)
|
void GlobeGPS::centerOn(dive* dive)
|
||||||
{
|
{
|
||||||
centerOn(dive->longitude.udeg / 1000000.0,dive->latitude.udeg / 1000000.0, true);
|
qreal longitude = dive->longitude.udeg / 1000000.0;
|
||||||
|
qreal latitude = dive->latitude.udeg / 1000000.0;
|
||||||
|
|
||||||
|
if (!longitude || !latitude){
|
||||||
|
prepareForGetDiveCoordinates(dive);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
centerOn(longitude,latitude, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GlobeGPS::prepareForGetDiveCoordinates(dive* dive)
|
||||||
|
{
|
||||||
|
QMessageBox::warning(parentWidget(),
|
||||||
|
tr("This dive has no location!"),
|
||||||
|
tr("Move the planet to the desired position, then \n double-click to set the new location of this dive."));
|
||||||
|
|
||||||
|
editingDiveCoords = dive;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
|
||||||
|
{
|
||||||
|
// convert to degrees if in radian.
|
||||||
|
if (unit == GeoDataCoordinates::Radian){
|
||||||
|
lon = lon * 180 / M_PI;
|
||||||
|
lat = lat * 180 / M_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!editingDiveCoords){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
editingDiveCoords->latitude.udeg = (int) lat * 1000000.0;
|
||||||
|
editingDiveCoords->longitude.udeg = (int) lon * 1000000.0;
|
||||||
|
centerOn(lon, lat, true);
|
||||||
|
reload();
|
||||||
|
editingDiveCoords = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobeGPS::mousePressEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
qreal lat, lon;
|
||||||
|
if (editingDiveCoords && geoCoordinates(event->pos().x(), event->pos().y(), lon,lat, GeoDataCoordinates::Radian)){
|
||||||
|
changeDiveGeoPosition(lon, lat, GeoDataCoordinates::Radian);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,23 +2,33 @@
|
||||||
#define GLOBE_H
|
#define GLOBE_H
|
||||||
|
|
||||||
#include <marble/MarbleWidget.h>
|
#include <marble/MarbleWidget.h>
|
||||||
|
#include <marble/GeoDataCoordinates.h>
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
namespace Marble{
|
using namespace Marble;
|
||||||
class GeoDataDocument;
|
struct dive;
|
||||||
}
|
|
||||||
class GlobeGPS : public Marble::MarbleWidget{
|
class GlobeGPS : public MarbleWidget{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
void prepareForGetDiveCoordinates(struct dive* dive);
|
||||||
public:
|
public:
|
||||||
using Marble::MarbleWidget::centerOn;
|
using MarbleWidget::centerOn;
|
||||||
GlobeGPS(QWidget *parent);
|
GlobeGPS(QWidget *parent);
|
||||||
void reload();
|
void reload();
|
||||||
void centerOn(struct dive* dive);
|
void centerOn(struct dive* dive);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent(QMouseEvent* event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Marble::GeoDataDocument *loadedDives;
|
GeoDataDocument *loadedDives;
|
||||||
QStringList diveLocations;
|
QStringList diveLocations;
|
||||||
|
struct dive* editingDiveCoords;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void changeDiveGeoPosition(qreal lon,qreal lat,GeoDataCoordinates::Unit);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue