Okay - those are the patches I did yesterday + today. Dirk asked me to focus on something else, so those are the patches that I did.
I'll try to implement davide's mockup for the full dive site management later.
From 39401bb643ef5bd959d0553341f203f828f2f0bc Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <tomaz.canabr...@intel.com> Date: Tue, 14 Jul 2015 14:29:48 -0300 Subject: [PATCH 6/6] Remove Quick Edit Dive Site Widget Voted down by common consent. Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com> --- qt-ui/locationinformation.cpp | 98 ------------------------------------------- qt-ui/locationinformation.h | 21 ---------- qt-ui/maintab.cpp | 14 ------- qt-ui/maintab.h | 1 - qt-ui/maintab.ui | 27 ++++-------- qt-ui/simpledivesiteedit.ui | 68 ------------------------------ 6 files changed, 8 insertions(+), 221 deletions(-) delete mode 100644 qt-ui/simpledivesiteedit.ui diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index b9d985b..47ceb65 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -227,104 +227,6 @@ void LocationInformationWidget::resetPallete() ui.diveSiteNotes->setPalette(p); } -SimpleDiveSiteEditDialog::SimpleDiveSiteEditDialog(QWidget *parent) : - QDialog(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::Popup), - ui(new Ui::SimpleDiveSiteEditDialog()), changed_dive_site(false) -{ - ui->setupUi(this); - ui->diveSiteDescription->installEventFilter(this); - ui->diveSiteNotes->installEventFilter(this); -} - -SimpleDiveSiteEditDialog::~SimpleDiveSiteEditDialog() -{ - delete ui; -} - -bool SimpleDiveSiteEditDialog::eventFilter(QObject *obj, QEvent *ev) -{ - if (ev->type() != QEvent::FocusOut) - return false; - - if (obj == ui->diveSiteDescription) { - diveSiteDescription_editingFinished(); - } else if (obj == ui->diveSiteNotes) { - diveSiteNotes_editingFinished(); - } - return false; -} - -void SimpleDiveSiteEditDialog::showEvent(QShowEvent *ev) -{ - const int heigth = 275; - const int width = 450; - - // Position. - QDialog::showEvent(ev); - QRect currGeometry = geometry(); - currGeometry.setX(QCursor::pos().x() + 15); - currGeometry.setY(QCursor::pos().y() - heigth / 2); - currGeometry.setWidth(width); - currGeometry.setHeight(heigth); - setGeometry(currGeometry); - ev->accept(); - - //Da - ui->diveSiteName->setText(displayed_dive_site.name); - ui->diveSiteNotes->setPlainText(displayed_dive_site.notes); - ui->diveSiteDescription->setPlainText(displayed_dive_site.description); - - const char *gps_text = printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg); - ui->diveSiteCoordinates->setText(QString(gps_text)); - free( (void*) gps_text); - - changed_dive_site = false; -} - -void SimpleDiveSiteEditDialog::on_diveSiteName_editingFinished() -{ - if (ui->diveSiteName->text() == displayed_dive_site.name) - return; - free(displayed_dive_site.name); - displayed_dive_site.name = copy_string(qPrintable(ui->diveSiteName->text())); - changed_dive_site = true; -} - -void SimpleDiveSiteEditDialog::on_diveSiteCoordinates_editingFinished() -{ - double lat, lon; - uint32_t uLat, uLon; - - parseGpsText(ui->diveSiteCoordinates->text(), &lat, &lon); - uLat = lat * 1000000; - uLon = lon * 1000000; - - if (uLat == displayed_dive_site.latitude.udeg && uLon == displayed_dive_site.longitude.udeg) - return; - - displayed_dive_site.latitude.udeg = uLat; - displayed_dive_site.longitude.udeg = uLon; - changed_dive_site = true; -} - -void SimpleDiveSiteEditDialog::diveSiteDescription_editingFinished() -{ - if (ui->diveSiteDescription->toPlainText() == displayed_dive_site.description) - return; - free(displayed_dive_site.description); - displayed_dive_site.description = copy_string(qPrintable(ui->diveSiteDescription->toPlainText())); - changed_dive_site = true; -} - -void SimpleDiveSiteEditDialog::diveSiteNotes_editingFinished() -{ - if (ui->diveSiteNotes->toPlainText() == displayed_dive_site.notes) - return; - free(displayed_dive_site.notes); - displayed_dive_site.notes = copy_string(qPrintable(ui->diveSiteNotes->toPlainText())); - changed_dive_site = true; -} - bool LocationManagementEditHelper::eventFilter(QObject *obj, QEvent *ev) { QListView *view = qobject_cast<QListView*>(obj); diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index b1746f7..b377319 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -44,27 +44,6 @@ private: mode current_mode; }; - -#include "ui_simpledivesiteedit.h" -class SimpleDiveSiteEditDialog : public QDialog { -Q_OBJECT -public: - SimpleDiveSiteEditDialog(QWidget *parent); - virtual ~SimpleDiveSiteEditDialog(); - bool changed_dive_site; - bool eventFilter(QObject *obj, QEvent *ev); -public slots: - void on_diveSiteName_editingFinished(); - void on_diveSiteCoordinates_editingFinished(); - void diveSiteDescription_editingFinished(); - void diveSiteNotes_editingFinished(); -protected: - void showEvent(QShowEvent *ev); -private: - Ui::SimpleDiveSiteEditDialog *ui; - -}; - class LocationManagementEditHelper : public QObject { Q_OBJECT public: diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 2efaa52..abb6af9 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -74,7 +74,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), locationManagementEditHelper, &LocationManagementEditHelper::handleActivation); ui.location->setCompleter(completer); - connect(ui.addDiveSite, SIGNAL(clicked()), this, SLOT(showDiveSiteSimpleEdit())); connect(ui.geocodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode())); QAction *action = new QAction(tr("Apply changes"), this); @@ -250,27 +249,14 @@ void MainTab::setCurrentLocationIndex() } } -void MainTab::showDiveSiteSimpleEdit() -{ - if (ui.location->text().isEmpty()) - return; - SimpleDiveSiteEditDialog dlg(this); - dlg.exec(); - if (dlg.changed_dive_site) { - markChangedWidget(ui.location); - } -} - void MainTab::enableGeoLookupEdition() { ui.waitingSpinner->stop(); - ui.addDiveSite->show(); } void MainTab::disableGeoLookupEdition() { ui.waitingSpinner->start(); - ui.addDiveSite->hide(); } void MainTab::toggleTriggeredColumn() diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 1e3f950..bcfb334 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -98,7 +98,6 @@ slots: void enableGeoLookupEdition(); void disableGeoLookupEdition(); void setCurrentLocationIndex(); - void showDiveSiteSimpleEdit(); void reverseGeocode(); private: Ui::MainTab ui; diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 3318bf7..c83d12e 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -56,7 +56,7 @@ <x>0</x> <y>0</y> <width>449</width> - <height>751</height> + <height>758</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_3"> @@ -167,15 +167,15 @@ </item> <item> <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>0</number> + </property> <property name="leftMargin"> <number>5</number> </property> <property name="rightMargin"> <number>5</number> </property> - <property name="spacing"> - <number>0</number> - </property> <item> <layout class="QHBoxLayout" name="LocationLayout" stretch="0,1"> <item> @@ -209,17 +209,6 @@ <widget class="QLineEdit" name="location"/> </item> <item> - <widget class="QToolButton" name="addDiveSite"> - <property name="text"> - <string>...</string> - </property> - <property name="icon"> - <iconset resource="../subsurface.qrc"> - <normaloff>:/edit</normaloff>:/edit</iconset> - </property> - </widget> - </item> - <item> <widget class="QToolButton" name="geocodeButton"> <property name="text"> <string>...</string> @@ -658,8 +647,8 @@ <rect> <x>0</x> <y>0</y> - <width>286</width> - <height>300</height> + <width>317</width> + <height>365</height> </rect> </property> <layout class="QGridLayout" name="diveInfoScrollAreaLayout"> @@ -999,8 +988,8 @@ <rect> <x>0</x> <y>0</y> - <width>297</width> - <height>177</height> + <width>331</width> + <height>220</height> </rect> </property> <layout class="QHBoxLayout" name="horizontalLayout"> diff --git a/qt-ui/simpledivesiteedit.ui b/qt-ui/simpledivesiteedit.ui deleted file mode 100644 index 7153023..0000000 --- a/qt-ui/simpledivesiteedit.ui +++ /dev/null @@ -1,68 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>SimpleDiveSiteEditDialog</class> - <widget class="QDialog" name="SimpleDiveSiteEditDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>449</width> - <height>338</height> - </rect> - </property> - <property name="windowTitle"> - <string>Dialog</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Name</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="diveSiteName"/> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Coordinates</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="diveSiteCoordinates"/> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Description</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="QPlainTextEdit" name="diveSiteNotes"/> - </item> - <item row="3" column="1"> - <widget class="QPlainTextEdit" name="diveSiteDescription"/> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>Notes</string> - </property> - </widget> - </item> - <item row="0" column="0" colspan="2"> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>Dive site quick edit. Hit ESC or click outside to close</string> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections/> -</ui> -- 2.4.5
From 5355997dddc94f49c720db47240a1b20dc48e236 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <tomaz.canabr...@intel.com> Date: Mon, 13 Jul 2015 17:11:03 -0300 Subject: [PATCH 5/6] Change Location Management to make Linus Happy Do not overwrite a dive site if the name is the same as any other dive site, create a new one and duplicate the information. Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com> --- qt-ui/maintab.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 66e42e3..2efaa52 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -841,8 +841,15 @@ void MainTab::updateDisplayedDiveSite() 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); + // As per linus request.: If I enter the name of a dive site, + // do not select a new one, but "clone" the old one and copy + // the information of it, just changing it's name. + uint32_t new_ds_uuid = create_dive_site(NULL); + struct dive_site *new_ds = get_dive_site_by_uuid(new_ds_uuid); + copy_dive_site(&displayed_dive_site, new_ds); + new_ds->name = copy_string(qPrintable(new_name)); + displayed_dive.dive_site_uuid = new_ds->uuid; + copy_dive_site(new_ds, &displayed_dive_site); } else { qDebug() << "Current divesite is the same as informed"; } -- 2.4.5
From 4c116874cef7496492f9205fe2919c885a5b1bc7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <tomaz.canabr...@intel.com> Date: Mon, 13 Jul 2015 15:38:46 -0300 Subject: [PATCH 4/6] Move code that handles Location to a sane place Dark times are ahead upon us. So, This fixes a few thigns related to Location Management, it is working :) Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com> --- qt-ui/maintab.cpp | 70 ++++++++++++++----------------------------------------- qt-ui/maintab.h | 2 +- 2 files changed, 19 insertions(+), 53 deletions(-) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index c68138f..66e42e3 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -818,13 +818,24 @@ void MainTab::reload() mydive->what = displayed_dive.what; \ } -void MainTab::updateDisplayedDiveDiveSite() +void MainTab::updateDisplayedDiveSite() { 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(); + qDebug() << "Updating Displayed Dive Site"; + if(current_dive) { + struct dive_site *ds_from_dive = get_dive_site_by_uuid(current_dive->dive_site_uuid); + if (!dive_site_has_gps_location(ds_from_dive) && + same_string(displayed_dive_site.notes, "SubsurfaceWebservice")) { + ds_from_dive->latitude = displayed_dive_site.latitude; + ds_from_dive->longitude = displayed_dive_site.longitude; + delete_dive_site(displayed_dive_site.uuid); + } + } + if(orig_uuid) { if (new_uuid && orig_uuid != new_uuid) { displayed_dive.dive_site_uuid = new_uuid; @@ -835,7 +846,7 @@ void MainTab::updateDisplayedDiveDiveSite() } else { qDebug() << "Current divesite is the same as informed"; } - } else { + } else if (!orig_uuid) { 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); @@ -854,6 +865,10 @@ void MainTab::acceptChanges() struct dive *d; bool do_replot = false; + if(ui.location->hasFocus()) { + this->setFocus(); + } + acceptingEdit = true; tabBar()->setTabIcon(0, QIcon()); // Notes tabBar()->setTabIcon(1, QIcon()); // Equipment @@ -866,7 +881,6 @@ void MainTab::acceptChanges() struct dive *added_dive = clone_dive(&displayed_dive); record_dive(added_dive); addedId = added_dive->id; - 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 @@ -925,7 +939,6 @@ void MainTab::acceptChanges() 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)); @@ -1406,54 +1419,7 @@ void MainTab::on_location_editingFinished() return; } - QString currText = ui.location->text(); - - struct dive_site *ds; - int idx; - bool found = false; - for_each_dive_site (idx,ds) { - if (same_string(ds->name, qPrintable(currText))) { - found = true; - break; - } - } - - if (!found) { - uint32_t uuid = create_dive_site(qPrintable(ui.location->text())); - ds = get_dive_site_by_uuid(uuid); - if (same_string(displayed_dive_site.notes, "SubsurfaceWebservice")) { - ds->latitude = displayed_dive_site.latitude; - ds->longitude = displayed_dive_site.longitude; - delete_dive_site(displayed_dive_site.uuid); - } - displayed_dive.dive_site_uuid = uuid; - copy_dive_site(get_dive_site_by_uuid(uuid), &displayed_dive_site); - markChangedWidget(ui.location); - - LocationInformationModel::instance()->update(); - emit diveSiteChanged(uuid); - return; - } - - if (!get_dive_site(idx)) - return; - - if (current_dive) { - struct dive_site *ds_from_dive = get_dive_site_by_uuid(displayed_dive.dive_site_uuid); - if(ds_from_dive && ui.location->text() == ds_from_dive->name) - return; - ds_from_dive = get_dive_site(idx); - if (!dive_site_has_gps_location(ds_from_dive) && - same_string(displayed_dive_site.notes, "SubsurfaceWebservice")) { - ds_from_dive->latitude = displayed_dive_site.latitude; - ds_from_dive->longitude = displayed_dive_site.longitude; - delete_dive_site(displayed_dive_site.uuid); - } - displayed_dive.dive_site_uuid = ds_from_dive->uuid; - copy_dive_site(get_dive_site_by_uuid(ds_from_dive->uuid), &displayed_dive_site); - markChangedWidget(ui.location); - emit diveSiteChanged(ds_from_dive->uuid); - } + updateDisplayedDiveSite(); } void MainTab::on_suit_textChanged(const QString &text) diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 6a6b9d1..1e3f950 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -123,7 +123,7 @@ private: dive_trip_t displayedTrip; bool acceptingEdit; LocationManagementEditHelper *locationManagementEditHelper; - void updateDisplayedDiveDiveSite(); + void updateDisplayedDiveSite(); }; #endif // MAINTAB_H -- 2.4.5
From 0fbfbbb7b79f3f5743c4313fae81a4da7b774369 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <tomaz.canabr...@intel.com> Date: Mon, 13 Jul 2015 15:14:46 -0300 Subject: [PATCH 3/6] Select right divesite on click. Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com> --- qt-ui/locationinformation.cpp | 10 +++++++-- qt-ui/locationinformation.h | 1 + qt-ui/maintab.cpp | 48 +++++++++++++++++++++++++++++++++++-------- qt-ui/maintab.h | 1 + 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 0be4b1e..b9d985b 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 7027cd8..b1746f7 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 88b607d..c68138f 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 7f0ba1c..6a6b9d1 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 -- 2.4.5
From f1e36004fdae1953dcaded9800eb925c6a5e4a72 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <tomaz.canabr...@intel.com> Date: Mon, 13 Jul 2015 15:13:48 -0300 Subject: [PATCH 2/6] Create/Retrieve dive_site by name. When we are working on the location management, we wanna get a new dive_site if the dive_site name changed unless there's no dive_site by that name, then we create it. Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com> --- divesite.c | 16 ++++++++++++++++ divesite.h | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/divesite.c b/divesite.c index 998fe23..800ccc9 100644 --- a/divesite.c +++ b/divesite.c @@ -200,3 +200,19 @@ void clear_dive_site(struct dive_site *ds) ds->taxonomy.nr = 0; free_taxonomy(&ds->taxonomy); } + +uint32_t find_or_create_dive_site_with_name(const char *name) +{ + int i; + struct dive_site *ds; + bool found = false; + for_each_dive_site(i,ds) { + if (same_string(name, ds->name)) { + found = true; + break; + } + } + if (ds) + return ds->uuid; + return create_dive_site(name); +} diff --git a/divesite.h b/divesite.h index 306272e..8801ddc 100644 --- a/divesite.h +++ b/divesite.h @@ -59,7 +59,7 @@ uint32_t get_dive_site_uuid_by_gps_proximity(degrees_t latitude, degrees_t longi bool dive_site_is_empty(struct dive_site *ds); void copy_dive_site(struct dive_site *orig, struct dive_site *copy); void clear_dive_site(struct dive_site *ds); - +uint32_t find_or_create_dive_site_with_name(const char *name); #ifdef __cplusplus } #endif -- 2.4.5
From a434d68a22cf3439f54f52e3eab4fd215ea8f81d Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <tomaz.canabr...@intel.com> Date: Wed, 8 Jul 2015 14:27:17 -0300 Subject: [PATCH 1/6] Get the selected dive site from the list Hooked a eventFilter on the QListView that displays our dive sites so it would filter the keys enter and space, storing the current dive_site uuid when that happens. Also it stores the uuid on clicks. Now we need to get that information on the acceptedChanges and check if the uuid stored there == displayed_dive_site.uuid and also if text != displayed_dive_site.name, because if the user didn't clicked on anythign but only wrote stuff on the LineEdit no dive site would be selected and so uuid == displayed_dive_site.uuid ( wich would mean 'no changes') Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com> --- qt-ui/locationinformation.cpp | 34 ++++++++++++++++++++++++++++++++++ qt-ui/locationinformation.h | 11 +++++++++++ qt-ui/maintab.cpp | 6 ++++++ qt-ui/maintab.h | 2 ++ 4 files changed, 53 insertions(+) diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index b3907a8..0be4b1e 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -324,3 +324,37 @@ void SimpleDiveSiteEditDialog::diveSiteNotes_editingFinished() displayed_dive_site.notes = copy_string(qPrintable(ui->diveSiteNotes->toPlainText())); changed_dive_site = true; } + +bool LocationManagementEditHelper::eventFilter(QObject *obj, QEvent *ev) +{ + QListView *view = qobject_cast<QListView*>(obj); + if(!view) + return false; + + if(ev->type() == QEvent::Show) { + last_uuid = displayed_dive_site.uuid; + } + + if(ev->type() == QEvent::KeyPress) { + QKeyEvent *keyEv = (QKeyEvent*) ev; + if(keyEv->key() == Qt::Key_Space || keyEv->key() == Qt::Key_Return) { + handleActivation(view->currentIndex()); + } + + } + return false; +} + +void LocationManagementEditHelper::handleActivation(const QModelIndex& activated) +{ + if (!activated.isValid()) + return; + QModelIndex uuidIdx = activated.model()->index( + activated.row(), LocationInformationModel::UUID); + last_uuid = uuidIdx.data().toInt(); + qDebug() << "Selected dive_site: " << last_uuid; +} + +void LocationManagementEditHelper::resetDiveSiteUuid() { + last_uuid = displayed_dive_site.uuid; +} diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h index 42e4d5a..7027cd8 100644 --- a/qt-ui/locationinformation.h +++ b/qt-ui/locationinformation.h @@ -64,4 +64,15 @@ private: Ui::SimpleDiveSiteEditDialog *ui; }; + +class LocationManagementEditHelper : public QObject { +Q_OBJECT +public: + bool eventFilter(QObject *obj, QEvent *ev); + void handleActivation(const QModelIndex& activated); + void resetDiveSiteUuid(); +private: + uint32_t last_uuid; + +}; #endif diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 043fe0a..88b607d 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -67,6 +67,11 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), completer->setCaseSensitivity(Qt::CaseInsensitive); completerListview->setItemDelegate(new LocationFilterDelegate()); + locationManagementEditHelper = new LocationManagementEditHelper(); + completerListview->installEventFilter(locationManagementEditHelper); + connect(completerListview, &QAbstractItemView::activated, + locationManagementEditHelper, &LocationManagementEditHelper::handleActivation); + ui.location->setCompleter(completer); connect(ui.addDiveSite, SIGNAL(clicked()), this, SLOT(showDiveSiteSimpleEdit())); connect(ui.geocodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode())); @@ -386,6 +391,7 @@ void MainTab::enableEdition(EditMode newEditMode) displayMessage(tr("Multiple dives are being edited.")); } else { displayMessage(tr("This dive is being edited.")); + locationManagementEditHelper->resetDiveSiteUuid(); } editMode = newEditMode != NONE ? newEditMode : DIVE; } diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 306aee6..7f0ba1c 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -22,6 +22,7 @@ class CylindersModel; class ExtraDataModel; class DivePictureModel; class QCompleter; +class LocationManagementEditHelper; struct Completers { QCompleter *divemaster; @@ -121,6 +122,7 @@ private: dive_trip_t *currentTrip; dive_trip_t displayedTrip; bool acceptingEdit; + LocationManagementEditHelper *locationManagementEditHelper; }; #endif // MAINTAB_H -- 2.4.5
_______________________________________________ subsurface mailing list subsurface@subsurface-divelog.org http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface