Fixes Setting the dive-location via the map.

This patch adds a context menu to set the dive location
via the globe, being the dive with a coordinate or not.

It also fixes setting the dive location on edit mode.

Fixes: #315

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2013-12-02 15:06:19 -02:00 committed by Dirk Hohndel
parent bbc022ba18
commit d26f109fba
3 changed files with 31 additions and 36 deletions

View file

@ -24,7 +24,7 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QMessageBox> #include <QMessageBox>
GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0) GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0), editingDiveLocation(false)
{ {
// check if Google Sat Maps are installed // check if Google Sat Maps are installed
// if not, check if they are in a known location // if not, check if they are in a known location
@ -72,7 +72,6 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
setMinimumHeight(0); setMinimumHeight(0);
setMinimumWidth(0); setMinimumWidth(0);
editingDiveCoords = 0;
fixZoomTimer = new QTimer(); fixZoomTimer = new QTimer();
connect(fixZoomTimer, SIGNAL(timeout()), this, SLOT(fixZoom())); connect(fixZoomTimer, SIGNAL(timeout()), this, SLOT(fixZoom()));
fixZoomTimer->setSingleShot(true); fixZoomTimer->setSingleShot(true);
@ -82,19 +81,29 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
bool GlobeGPS::eventFilter(QObject *obj, QEvent *ev) bool GlobeGPS::eventFilter(QObject *obj, QEvent *ev)
{ {
// This disables Zooming when a double click occours on the scene. // This disables Zooming when a double click occours on the scene.
if (ev->type() == QEvent::MouseButtonDblClick && !editingDiveCoords) if (ev->type() == QEvent::MouseButtonDblClick && !editingDiveLocation)
return true; return true;
// This disables the Marble's Context Menu // This disables the Marble's Context Menu
// we need to move this to our 'contextMenuEvent' // we need to move this to our 'contextMenuEvent'
// if we plan to do a different one in the future. // if we plan to do a different one in the future.
if (ev->type() == QEvent::ContextMenu) if (ev->type() == QEvent::ContextMenu){
contextMenuEvent(static_cast<QContextMenuEvent*>(ev));
return true; return true;
}
if (ev->type() == QEvent::MouseButtonPress){ if (ev->type() == QEvent::MouseButtonPress){
QMouseEvent *e = static_cast<QMouseEvent*>(ev); QMouseEvent *e = static_cast<QMouseEvent*>(ev);
if(e->button() == Qt::RightButton) if(e->button() == Qt::RightButton)
return true; return true;
} }
return QObject::eventFilter(obj,ev ); return QObject::eventFilter(obj,ev );
}
void GlobeGPS::contextMenuEvent(QContextMenuEvent* ev)
{
QMenu m;
QAction *a = m.addAction(tr("Edit Selected Dive Locations"), this, SLOT(prepareForGetDiveCoordinates()));
a->setData(QVariant::fromValue<void*>(&m));
m.exec(ev->globalPos());
} }
void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
@ -185,11 +194,9 @@ void GlobeGPS::repopulateLabels()
void GlobeGPS::reload() void GlobeGPS::reload()
{ {
editingDiveCoords = 0; editingDiveLocation = false;
if (messageWidget->isVisible()) if (messageWidget->isVisible())
messageWidget->animatedHide(); messageWidget->animatedHide();
repopulateLabels(); repopulateLabels();
} }
@ -202,13 +209,11 @@ void GlobeGPS::centerOn(dive* dive)
if (!dive) if (!dive)
return; return;
editingDiveCoords = 0;
qreal longitude = dive->longitude.udeg / 1000000.0; qreal longitude = dive->longitude.udeg / 1000000.0;
qreal latitude = dive->latitude.udeg / 1000000.0; qreal latitude = dive->latitude.udeg / 1000000.0;
if (!longitude || !latitude) { if (!longitude || !latitude) {
prepareForGetDiveCoordinates(dive); prepareForGetDiveCoordinates();
return; return;
} }
@ -231,37 +236,27 @@ void GlobeGPS::fixZoom()
zoomView(currentZoomLevel, Marble::Linear); zoomView(currentZoomLevel, Marble::Linear);
} }
void GlobeGPS::prepareForGetDiveCoordinates()
void GlobeGPS::prepareForGetDiveCoordinates(dive* dive)
{ {
if (!messageWidget->isVisible()) { if (!messageWidget->isVisible()) {
messageWidget->setMessageType(KMessageWidget::Warning); messageWidget->setMessageType(KMessageWidget::Warning);
messageWidget->setText(QObject::tr("No location data - move the map and double-click to set the dive location")); messageWidget->setText(QObject::tr("No location data - move the map and double-click to set the dive location"));
messageWidget->setWordWrap(true); messageWidget->setWordWrap(true);
messageWidget->animatedShow(); messageWidget->animatedShow();
editingDiveLocation = true;
} }
editingDiveCoords = dive;
}
void GlobeGPS::diveEditMode()
{
if (messageWidget->isVisible())
messageWidget->animatedHide();
messageWidget->setMessageType(KMessageWidget::Warning);
messageWidget->setText(QObject::tr("Editing dive - move the map and double-click to set the dive location"));
messageWidget->setWordWrap(true);
messageWidget->animatedShow();
} }
void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
{ {
if (mainWindow()->dive_list()->selectionModel()->selection().isEmpty())
return;
// convert to degrees if in radian. // convert to degrees if in radian.
if (unit == GeoDataCoordinates::Radian) { if (unit == GeoDataCoordinates::Radian) {
lon = lon * 180 / M_PI; lon = lon * 180 / M_PI;
lat = lat * 180 / M_PI; lat = lat * 180 / M_PI;
} }
if (!editingDiveCoords)
return;
/* change everything on the selection. */ /* change everything on the selection. */
int i; int i;
@ -273,7 +268,7 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U
dive->longitude.udeg = lrint(lon * 1000000.0); dive->longitude.udeg = lrint(lon * 1000000.0);
} }
centerOn(lon, lat, true); centerOn(lon, lat, true);
editingDiveCoords = 0; editingDiveLocation = false;
mark_divelist_changed(TRUE); mark_divelist_changed(TRUE);
messageWidget->animatedHide(); messageWidget->animatedHide();
mainWindow()->refreshDisplay(); mainWindow()->refreshDisplay();
@ -282,13 +277,13 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U
void GlobeGPS::mousePressEvent(QMouseEvent* event) void GlobeGPS::mousePressEvent(QMouseEvent* event)
{ {
qreal lat, lon; qreal lat, lon;
bool clickOnGlobe = geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree);
// there could be two scenarios that got us here; let's check if we are editing a dive // there could be two scenarios that got us here; let's check if we are editing a dive
if (mainWindow()->information()->isEditing() && if (mainWindow()->information()->isEditing() && clickOnGlobe) {
geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree)) {
mainWindow()->information()->updateCoordinatesText(lat, lon); mainWindow()->information()->updateCoordinatesText(lat, lon);
repopulateLabels(); repopulateLabels();
} else if (editingDiveCoords && } else if (clickOnGlobe) {
geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree)) {
changeDiveGeoPosition(lon, lat, GeoDataCoordinates::Degree); changeDiveGeoPosition(lon, lat, GeoDataCoordinates::Degree);
} }
} }

View file

@ -19,23 +19,24 @@ public:
void reload(); void reload();
void repopulateLabels(); void repopulateLabels();
void centerOn(struct dive* dive); void centerOn(struct dive* dive);
void diveEditMode();
bool eventFilter(QObject*, QEvent*); bool eventFilter(QObject*, QEvent*);
protected: protected:
/* reimp */ void resizeEvent(QResizeEvent *event); /* reimp */ void resizeEvent(QResizeEvent *event);
/* reimp */ void mousePressEvent(QMouseEvent* event); /* reimp */ void mousePressEvent(QMouseEvent* event);
/* reimp */ void contextMenuEvent(QContextMenuEvent*);
private: private:
void prepareForGetDiveCoordinates(struct dive* dive);
GeoDataDocument *loadedDives; GeoDataDocument *loadedDives;
struct dive* editingDiveCoords;
KMessageWidget* messageWidget; KMessageWidget* messageWidget;
QTimer *fixZoomTimer; QTimer *fixZoomTimer;
int currentZoomLevel; int currentZoomLevel;
bool editingDiveLocation;
public slots: public slots:
void changeDiveGeoPosition(qreal lon,qreal lat,GeoDataCoordinates::Unit); void changeDiveGeoPosition(qreal lon,qreal lat,GeoDataCoordinates::Unit);
void mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit); void mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit);
void fixZoom(); void fixZoom();
void prepareForGetDiveCoordinates();
}; };
#endif #endif

View file

@ -166,12 +166,11 @@ void MainTab::enableEdition(EditMode newEditMode)
return; return;
mainWindow()->dive_list()->setEnabled(false); mainWindow()->dive_list()->setEnabled(false);
mainWindow()->globe()->diveEditMode(); mainWindow()->globe()->prepareForGetDiveCoordinates();
// We may be editing one or more dives here. backup everything. // We may be editing one or more dives here. backup everything.
notesBackup.clear(); notesBackup.clear();
ui.notesButtonBox->show(); ui.notesButtonBox->show();
ui.equipmentButtonBox->show(); ui.equipmentButtonBox->show();
if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) { if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
// we are editing trip location and notes // we are editing trip location and notes
ui.diveNotesMessage->setText(tr("This trip is being edited. Select Save or Cancel when done.")); ui.diveNotesMessage->setText(tr("This trip is being edited. Select Save or Cancel when done."));