summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-07-13 15:14:46 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-13 15:43:03 -0700
commitc658f2878b540407a65af8c57b3e1bb3cc7c78c4 (patch)
tree9a1d56975d4d823d43f663679c05177eb07f633b /qt-ui
parentca5606d3e9783edbd3012684eff1a829088870b5 (diff)
downloadsubsurface-c658f2878b540407a65af8c57b3e1bb3cc7c78c4.tar.gz
Select right divesite on click
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/locationinformation.cpp10
-rw-r--r--qt-ui/locationinformation.h1
-rw-r--r--qt-ui/maintab.cpp48
-rw-r--r--qt-ui/maintab.h1
4 files changed, 49 insertions, 11 deletions
diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index 0be4b1e65..b9d985bd7 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -332,7 +332,8 @@ bool LocationManagementEditHelper::eventFilter(QObject *obj, QEvent *ev)
return false;
if(ev->type() == QEvent::Show) {
- last_uuid = displayed_dive_site.uuid;
+ last_uuid = 0;
+ qDebug() << "EventFilter: " << last_uuid;
}
if(ev->type() == QEvent::KeyPress) {
@@ -356,5 +357,10 @@ void LocationManagementEditHelper::handleActivation(const QModelIndex& activated
}
void LocationManagementEditHelper::resetDiveSiteUuid() {
- last_uuid = displayed_dive_site.uuid;
+ last_uuid = 0;
+ qDebug() << "Reset: " << last_uuid;
+}
+
+uint32_t LocationManagementEditHelper::diveSiteUuid() const {
+ return last_uuid;
}
diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index 7027cd8fa..b1746f79e 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -71,6 +71,7 @@ public:
bool eventFilter(QObject *obj, QEvent *ev);
void handleActivation(const QModelIndex& activated);
void resetDiveSiteUuid();
+ uint32_t diveSiteUuid() const;
private:
uint32_t last_uuid;
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 88b607d1b..c68138fae 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -23,6 +23,7 @@
#include "divelocationmodel.h"
#include "divesite.h"
#include "locationinformation.h"
+#include "divesite.h"
#if defined(FBSUPPORT)
#include "socialnetworks.h"
@@ -760,6 +761,7 @@ void MainTab::updateDiveInfo(bool clear)
else
ui.cylinders->view()->hideColumn(CylindersModel::USE);
+ qDebug() << "Set the current dive site:" << displayed_dive.dive_site_uuid;
emit diveSiteChanged(displayed_dive.dive_site_uuid);
}
@@ -816,6 +818,36 @@ void MainTab::reload()
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()
{
int i, addedId = -1;
@@ -834,12 +866,9 @@ void MainTab::acceptChanges()
struct dive *added_dive = clone_dive(&displayed_dive);
record_dive(added_dive);
addedId = added_dive->id;
- if (displayed_dive_site.uuid)
- copy_dive_site(&displayed_dive_site, get_dive_site_by_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;
- }
+ updateDisplayedDiveDiveSite();
+ get_dive_by_uniq_id(added_dive->id)->dive_site_uuid = displayed_dive_site.uuid;
+
// 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
// 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;
MODIFY_SELECTED_DIVES(mydive->when -= offset;);
}
+
+ updateDisplayedDiveDiveSite();
if (displayed_dive.dive_site_uuid != cd->dive_site_uuid)
MODIFY_SELECTED_DIVES(EDIT_VALUE(dive_site_uuid));
@@ -903,9 +934,6 @@ void MainTab::acceptChanges()
saveTaggedStrings();
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) {
mark_divelist_changed(true);
MODIFY_SELECTED_DIVES(
@@ -962,6 +990,8 @@ void MainTab::acceptChanges()
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
// so re-populate the temperatures - easiest way to do this is by calling fixup_dive
for_each_dive (i, d) {
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 7f0ba1ca3..6a6b9d16a 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -123,6 +123,7 @@ private:
dive_trip_t displayedTrip;
bool acceptingEdit;
LocationManagementEditHelper *locationManagementEditHelper;
+ void updateDisplayedDiveDiveSite();
};
#endif // MAINTAB_H