summaryrefslogtreecommitdiffstats
path: root/qt-ui/globe.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-17 16:12:55 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-17 16:12:55 -0300
commit56dbb7c2ff697a393f5051e2b5363bd4c0f2bb6e (patch)
treec3135142e4285c68b8b8a1f9b7fe93c51b4e91e9 /qt-ui/globe.cpp
parentb89265c7f0de93c663435541167518188bcd4b2d (diff)
downloadsubsurface-56dbb7c2ff697a393f5051e2b5363bd4c0f2bb6e.tar.gz
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>
Diffstat (limited to 'qt-ui/globe.cpp')
-rw-r--r--qt-ui/globe.cpp55
1 files changed, 51 insertions, 4 deletions
diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp
index a8fb886d8..93d1ab7c4 100644
--- a/qt-ui/globe.cpp
+++ b/qt-ui/globe.cpp
@@ -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);
+ }
+}
+