Select right divesite on click

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-07-13 15:14:46 -03:00 committed by Dirk Hohndel
parent ca5606d3e9
commit c658f2878b
4 changed files with 49 additions and 11 deletions

View file

@ -332,7 +332,8 @@ bool LocationManagementEditHelper::eventFilter(QObject *obj, QEvent *ev)
return false; return false;
if(ev->type() == QEvent::Show) { if(ev->type() == QEvent::Show) {
last_uuid = displayed_dive_site.uuid; last_uuid = 0;
qDebug() << "EventFilter: " << last_uuid;
} }
if(ev->type() == QEvent::KeyPress) { if(ev->type() == QEvent::KeyPress) {
@ -356,5 +357,10 @@ void LocationManagementEditHelper::handleActivation(const QModelIndex& activated
} }
void LocationManagementEditHelper::resetDiveSiteUuid() { void LocationManagementEditHelper::resetDiveSiteUuid() {
last_uuid = displayed_dive_site.uuid; last_uuid = 0;
qDebug() << "Reset: " << last_uuid;
}
uint32_t LocationManagementEditHelper::diveSiteUuid() const {
return last_uuid;
} }

View file

@ -71,6 +71,7 @@ public:
bool eventFilter(QObject *obj, QEvent *ev); bool eventFilter(QObject *obj, QEvent *ev);
void handleActivation(const QModelIndex& activated); void handleActivation(const QModelIndex& activated);
void resetDiveSiteUuid(); void resetDiveSiteUuid();
uint32_t diveSiteUuid() const;
private: private:
uint32_t last_uuid; uint32_t last_uuid;

View file

@ -23,6 +23,7 @@
#include "divelocationmodel.h" #include "divelocationmodel.h"
#include "divesite.h" #include "divesite.h"
#include "locationinformation.h" #include "locationinformation.h"
#include "divesite.h"
#if defined(FBSUPPORT) #if defined(FBSUPPORT)
#include "socialnetworks.h" #include "socialnetworks.h"
@ -760,6 +761,7 @@ void MainTab::updateDiveInfo(bool clear)
else else
ui.cylinders->view()->hideColumn(CylindersModel::USE); ui.cylinders->view()->hideColumn(CylindersModel::USE);
qDebug() << "Set the current dive site:" << displayed_dive.dive_site_uuid;
emit diveSiteChanged(displayed_dive.dive_site_uuid); emit diveSiteChanged(displayed_dive.dive_site_uuid);
} }
@ -816,6 +818,36 @@ void MainTab::reload()
mydive->what = displayed_dive.what; \ mydive->what = displayed_dive.what; \
} }
void MainTab::updateDisplayedDiveDiveSite()
{
const QString new_name = ui.location->text();
const QString orig_name = displayed_dive_site.name;
const uint32_t orig_uuid = displayed_dive_site.uuid;
const uint32_t new_uuid = locationManagementEditHelper->diveSiteUuid();
if(orig_uuid) {
if (new_uuid && orig_uuid != new_uuid) {
displayed_dive.dive_site_uuid = new_uuid;
copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
} else if (new_name.count() && orig_name != new_name) {
displayed_dive.dive_site_uuid = find_or_create_dive_site_with_name(qPrintable(new_name));
copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
} else {
qDebug() << "Current divesite is the same as informed";
}
} else {
if (new_uuid) {
displayed_dive.dive_site_uuid = new_uuid;
copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
} else if (new_name.count()) {
displayed_dive.dive_site_uuid = find_or_create_dive_site_with_name(qPrintable(new_name));
copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
} else {
qDebug() << "No divesite will be set";
}
}
}
void MainTab::acceptChanges() void MainTab::acceptChanges()
{ {
int i, addedId = -1; int i, addedId = -1;
@ -834,12 +866,9 @@ void MainTab::acceptChanges()
struct dive *added_dive = clone_dive(&displayed_dive); struct dive *added_dive = clone_dive(&displayed_dive);
record_dive(added_dive); record_dive(added_dive);
addedId = added_dive->id; addedId = added_dive->id;
if (displayed_dive_site.uuid) updateDisplayedDiveDiveSite();
copy_dive_site(&displayed_dive_site, get_dive_site_by_uuid(displayed_dive_site.uuid)); get_dive_by_uniq_id(added_dive->id)->dive_site_uuid = displayed_dive_site.uuid;
else if (ui.location->text().count()) {
uint32_t uuid = create_dive_site(qPrintable(ui.location->text()));
added_dive->dive_site_uuid = uuid;
}
// unselect everything as far as the UI is concerned and select the new // unselect everything as far as the UI is concerned and select the new
// dive - we'll have to undo/redo this later after we resort the dive_table // dive - we'll have to undo/redo this later after we resort the dive_table
// but we need the dive selected for the middle part of this function - this // but we need the dive selected for the middle part of this function - this
@ -895,6 +924,8 @@ void MainTab::acceptChanges()
time_t offset = cd->when - displayed_dive.when; time_t offset = cd->when - displayed_dive.when;
MODIFY_SELECTED_DIVES(mydive->when -= offset;); MODIFY_SELECTED_DIVES(mydive->when -= offset;);
} }
updateDisplayedDiveDiveSite();
if (displayed_dive.dive_site_uuid != cd->dive_site_uuid) if (displayed_dive.dive_site_uuid != cd->dive_site_uuid)
MODIFY_SELECTED_DIVES(EDIT_VALUE(dive_site_uuid)); MODIFY_SELECTED_DIVES(EDIT_VALUE(dive_site_uuid));
@ -903,9 +934,6 @@ void MainTab::acceptChanges()
saveTaggedStrings(); saveTaggedStrings();
saveTags(); saveTags();
if (displayed_dive_site.uuid)
copy_dive_site(&displayed_dive_site, get_dive_site_by_uuid(displayed_dive_site.uuid));
if (editMode != ADD && cylindersModel->changed) { if (editMode != ADD && cylindersModel->changed) {
mark_divelist_changed(true); mark_divelist_changed(true);
MODIFY_SELECTED_DIVES( MODIFY_SELECTED_DIVES(
@ -962,6 +990,8 @@ void MainTab::acceptChanges()
cd->weightsystem[i].description = copy_string(displayed_dive.weightsystem[i].description); cd->weightsystem[i].description = copy_string(displayed_dive.weightsystem[i].description);
} }
} }
// each dive that was selected might have had the temperatures in its active divecomputer changed // each dive that was selected might have had the temperatures in its active divecomputer changed
// so re-populate the temperatures - easiest way to do this is by calling fixup_dive // so re-populate the temperatures - easiest way to do this is by calling fixup_dive
for_each_dive (i, d) { for_each_dive (i, d) {

View file

@ -123,6 +123,7 @@ private:
dive_trip_t displayedTrip; dive_trip_t displayedTrip;
bool acceptingEdit; bool acceptingEdit;
LocationManagementEditHelper *locationManagementEditHelper; LocationManagementEditHelper *locationManagementEditHelper;
void updateDisplayedDiveDiveSite();
}; };
#endif // MAINTAB_H #endif // MAINTAB_H