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:
Tomaz Canabrava 2013-05-17 16:12:55 -03:00
parent b89265c7f0
commit 56dbb7c2ff
2 changed files with 68 additions and 11 deletions

View file

@ -9,7 +9,8 @@
#include <marble/MarbleModel.h>
#include <marble/GeoDataTreeModel.h>
using namespace Marble;
#include <QMouseEvent>
#include <QMessageBox>
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 ) );
}
}
}
void GlobeGPS::reload()
@ -40,7 +40,9 @@ void GlobeGPS::reload()
model()->treeModel()->removeDocument(loadedDives);
delete loadedDives;
}
if (editingDiveCoords){
editingDiveCoords = 0;
}
loadedDives = new GeoDataDocument;
@ -62,5 +64,50 @@ void GlobeGPS::reload()
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);
}
}

View file

@ -2,22 +2,32 @@
#define GLOBE_H
#include <marble/MarbleWidget.h>
#include <marble/GeoDataCoordinates.h>
#include <QHash>
namespace Marble{
class GeoDataDocument;
}
class GlobeGPS : public Marble::MarbleWidget{
using namespace Marble;
struct dive;
class GlobeGPS : public MarbleWidget{
Q_OBJECT
void prepareForGetDiveCoordinates(struct dive* dive);
public:
using Marble::MarbleWidget::centerOn;
using MarbleWidget::centerOn;
GlobeGPS(QWidget *parent);
void reload();
void centerOn(struct dive* dive);
protected:
virtual void mousePressEvent(QMouseEvent* event);
private:
Marble::GeoDataDocument *loadedDives;
GeoDataDocument *loadedDives;
QStringList diveLocations;
struct dive* editingDiveCoords;
public Q_SLOTS:
void changeDiveGeoPosition(qreal lon,qreal lat,GeoDataCoordinates::Unit);
};