Dirk,
Here comes the rest of the series. I'v tested with:
 - No Dives
-  Dives
- Creating Dives
- Cancelling

everything seemed to work - I need a bit of help testing it. after all it's
a major rewrite.

points:

- new code is *much* more easy to read and follow.
- Lots of dead code removed.
- you *cant* edit the dive site and the dive at the same time. edit the
dive, then edit the dive site, or only edit the dive site.

sorry for that but it just closed a can of worms and it's not that bad. I
promess to make this work on 5.0 flawlessly, no time for 4.5

On Tue, Sep 22, 2015 at 10:55 PM, Dirk Hohndel <d...@hohndel.org> wrote:

> On Tue, Sep 22, 2015 at 05:50:45PM -0300, Tomaz Canabrava wrote:
> > Uffs, so:
> >
> > This patch series completely rewrites the LocationManagement *lineedit +
> > combobox* that we used to have.
>
> Wow.
>
> > It is stetically identical to the old one, everything beneath the UI has
> > changed.
>
> There are a few minute differences... one that I noticed is that if you
> have focus in the location field (let's say you clicked on it), simply
> pressing shift or control already gets the completer shown - before you
> ever entered (or removed) a character. That's not terrible, but it seemed
> noteworthy
>

Fixed.


>
> > it currently *doesn't* works ( the line edit + selection *works* , but it
> > doesn't *sets* the dive site ) - I need a bit of help on that as my time
> > just runned out.
>
> That makes it a bit harder to test. So I focused on testing simply what's
> shown to the user and how you can navigate with mouse and keyboard.
>
> If I hit enter on a selection it's chosen. But clicking on a selection
> only highlights it but it doesn't get chosen.
>

Fixed. ( it was actually getting choosed but the dpopup didn't disappeared)

>
> > but basically:
> > after a dive site is choosed on the new location line edit, you have:
> > currentDiveSiteUuid and text()
> > if location.currentDiveSiteUuid() == 1, this means that we need to
> create a
> > new dive site and set the text() as dive_site.name
> >
> > if location.currentDiveSiteUuid() > 1, it's an existing dive site. just
> set
> > it on the dive.
> >
> > Please test: I'm doing this in berseker mode for two days trying to
> remove
> > the old system that's completely broken ( because we where abusing
> > QCompleter, it works very well in all other cases that we use it. )
>
> As I said in IRC - I'm quite nervous about such a dramatic rewrite this
> late in the cycle. I understand why we need it as this addresses a user
> visible bug in the current code... still. Urgs.
>
> Since right now it stops us from actually selecting dive sites I didn't
> pull this into master, yet.
>

I really tried to fix it using QCompleter, didn't worked. you remember m y
5 rewrites trying to hack around it.


>
> Thanks for your hard work, Tomaz.
>
> /D
>
From 0e24074f4e2c3159f5f32bd81c2ff9f26f751e21 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 13:56:49 -0300
Subject: [PATCH 15/28] Fix keyboard inconsistencies.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/locationinformation.cpp | 12 ++++--------
 qt-ui/locationinformation.h   |  1 -
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index 7e640f1..d95acfc 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -433,15 +433,9 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) : QLineEdit(parent),
 	view->setFocusProxy(this);
 
 	connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName);
-	connect(this, &QLineEdit::editingFinished, this, &DiveLocationLineEdit::setDiveSiteName);
 	connect(view, &QAbstractItemView::activated, this, &DiveLocationLineEdit::itemActivated);
 }
 
-void DiveLocationLineEdit::setDiveSiteName()
-{
-
-}
-
 bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e)
 {
 	if(e->type() == QEvent::KeyPress) {
@@ -458,8 +452,7 @@ bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e)
 			return false;
 		}
 
-		if (keyEv->key() == Qt::Key_Space ||
-			keyEv->key() == Qt::Key_Tab){
+		if (keyEv->key() == Qt::Key_Tab){
 				itemActivated(view->currentIndex());
 				view->hide();
 				return false;
@@ -493,6 +486,8 @@ void DiveLocationLineEdit::itemActivated(const QModelIndex& index)
 		qDebug() << "Setting a New dive site";
 	else
 		qDebug() << "Setting a Existing dive site";
+	if(view->isVisible())
+		view->hide();
 }
 
 void DiveLocationLineEdit::refreshDiveSiteCache()
@@ -585,6 +580,7 @@ void DiveLocationLineEdit::showPopup()
 	if (!view->isVisible()) {
 		setTemporaryDiveSiteName(text());
 		proxy->invalidate();
+		view->setCurrentIndex( view->model()->index(0,1));
 		view->show();
 	}
 }
diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index 2b41f52..5085f83 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -96,7 +96,6 @@ public:
 	void setTemporaryDiveSiteName(const QString& s);
 	bool eventFilter(QObject*, QEvent*);
 	void itemActivated(const QModelIndex& index);
-	void setDiveSiteName();
 
 	DiveSiteType currDiveSiteType() const;
 	uint32_t currDiveSiteUuid() const;
-- 
2.5.3

From d8e001a4ebb67c9eb889dac59f73d0071574c622 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 14:46:29 -0300
Subject: [PATCH 16/28] Handle palette change for dive site selection

If you select a Dive Site with a different uuid than your
current dive.dive_site_uuid, you should get a different
pallete to state clearly that something changed.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/locationinformation.cpp | 13 ++++++++++++-
 qt-ui/locationinformation.h   |  3 +++
 qt-ui/maintab.cpp             |  9 ++++++++-
 qt-ui/maintab.h               |  2 +-
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index d95acfc..2ca1112 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -488,6 +488,7 @@ void DiveLocationLineEdit::itemActivated(const QModelIndex& index)
 		qDebug() << "Setting a Existing dive site";
 	if(view->isVisible())
 		view->hide();
+	emit diveSiteSelected(currUuid);
 }
 
 void DiveLocationLineEdit::refreshDiveSiteCache()
@@ -580,11 +581,21 @@ void DiveLocationLineEdit::showPopup()
 	if (!view->isVisible()) {
 		setTemporaryDiveSiteName(text());
 		proxy->invalidate();
-		view->setCurrentIndex( view->model()->index(0,1));
+		view->setCurrentIndex(view->model()->index(0,1));
 		view->show();
 	}
 }
 
+DiveLocationLineEdit::DiveSiteType DiveLocationLineEdit::currDiveSiteType() const
+{
+	return currType;
+}
+
+uint32_t DiveLocationLineEdit::currDiveSiteUuid() const
+{
+	return currUuid;
+}
+
 DiveLocationListView::DiveLocationListView(QWidget *parent)
 {
 
diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index 5085f83..db0d286 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -100,6 +100,9 @@ public:
 	DiveSiteType currDiveSiteType() const;
 	uint32_t currDiveSiteUuid() const;
 
+signals:
+	void diveSiteSelected(uint32_t uuid);
+
 protected:
 	void keyPressEvent(QKeyEvent *ev);
 	void focusOutEvent(QFocusEvent *ev);
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 51df81d..a68adb5 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -1509,7 +1509,7 @@ void MainTab::on_location_textChanged()
 		markChangedWidget(ui.location);
 }
 
-void MainTab::on_location_editingFinished()
+void MainTab::on_location_diveSiteSelected()
 {
 	if (editMode == IGNORE || acceptingEdit == true)
 		return;
@@ -1519,6 +1519,13 @@ void MainTab::on_location_editingFinished()
 		markChangedWidget(ui.location);
 		emit diveSiteChanged(0);
 		return;
+	} else {
+		if (ui.location->currDiveSiteUuid() != displayed_dive.dive_site_uuid) {
+			markChangedWidget(ui.location);
+		} else {
+			QPalette p;
+			ui.location->setPalette(p);
+		}
 	}
 
 	if (currentTrip) {
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 26dd385..a071e6c 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -69,7 +69,7 @@ slots:
 	void updateDiveInfo(bool clear = false);
 	void acceptChanges();
 	void rejectChanges();
-	void on_location_editingFinished();
+	void on_location_diveSiteSelected();
 	void on_location_textChanged();
 	void on_divemaster_textChanged();
 	void on_buddy_textChanged();
-- 
2.5.3

From 1e090586fa120181ed9c0940e56e1aed97011851 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 14:57:55 -0300
Subject: [PATCH 17/28] Removed a ton of dead code

Unused dead code / hack for the old QCompleter

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/locationinformation.cpp | 55 -------------------------------------------
 qt-ui/locationinformation.h   | 13 ----------
 qt-ui/maintab.cpp             |  4 +---
 qt-ui/maintab.h               |  2 --
 4 files changed, 1 insertion(+), 73 deletions(-)

diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index 2ca1112..b183491 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -259,61 +259,6 @@ void LocationInformationWidget::resetPallete()
 	ui.diveSiteNotes->setPalette(p);
 }
 
-bool LocationManagementEditHelper::eventFilter(QObject *obj, QEvent *ev)
-{
-	QListView *view = qobject_cast<QListView*>(obj);
-	if(!view)
-		return false;
-
-	if(ev->type() == QEvent::Show) {
-		last_uuid = 0;
-		qDebug() << "EventFilter: " << last_uuid;
-	}
-
-	if(ev->type() == QEvent::KeyPress) {
-		QKeyEvent *keyEv = (QKeyEvent*) ev;
-		if(keyEv->key() == Qt::Key_Return) {
-			handleActivation(view->currentIndex());
-			view->hide();
-			return true;
-		}
-	}
-	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();
-
-	/* if we are in 'recently added divesite mode, create a new divesite,
-	 * and go to dive site edit edit mode. */
-	if (last_uuid == RECENTLY_ADDED_DIVESITE) {
-		uint32_t ds_uuid = create_dive_site_from_current_dive(qPrintable(activated.data().toString()));
-		qDebug() << "ds_uuid" << ds_uuid;
-		struct dive_site *ds = get_dive_site_by_uuid(ds_uuid);
-		copy_dive_site(ds, &displayed_dive_site);
-		displayed_dive.dive_site_uuid = ds->uuid;
-		last_uuid = ds->uuid;
-		// Move this out of here later.
-		MainWindow::instance()->startDiveSiteEdit();
-	}
-
-	qDebug() << "Selected dive_site: " << last_uuid;
-}
-
-void LocationManagementEditHelper::resetDiveSiteUuid() {
-	last_uuid = 0;
-	qDebug() << "Reset: " << last_uuid;
-}
-
-uint32_t LocationManagementEditHelper::diveSiteUuid() const {
-	return last_uuid;
-}
-
 void LocationInformationWidget::reverseGeocode()
 {
 	ReverseGeoLookupThread *geoLookup = ReverseGeoLookupThread::instance();
diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index db0d286..7e55aeb 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -46,19 +46,6 @@ private:
 	QAction *closeAction, *acceptAction, *rejectAction;
 };
 
-class LocationManagementEditHelper : public QObject {
-Q_OBJECT
-public:
-	bool eventFilter(QObject *obj, QEvent *ev);
-	void handleActivation(const QModelIndex& activated);
-	void resetDiveSiteUuid();
-	uint32_t diveSiteUuid() const;
-signals:
-	void setLineEditText(const QString& text);
-private:
-	uint32_t last_uuid;
-};
-
 class DiveLocationFilterProxyModel : public QSortFilterProxyModel {
 	Q_OBJECT
 public:
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index a68adb5..8a6ea7f 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -377,7 +377,6 @@ 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;
 	}
@@ -844,7 +843,6 @@ void MainTab::updateDisplayedDiveSite()
 	const uint32_t orig_uuid = displayed_dive_site.uuid;
 	//TODO: FIX THIS
 	const uint32_t new_uuid = orig_uuid;
-	// locationManagementEditHelper->diveSiteUuid();
 
 	qDebug() << "Updating Displayed Dive Site";
 
@@ -891,7 +889,7 @@ void MainTab::updateDiveSite(int divenr)
 		return;
 
 	const uint32_t newUuid = displayed_dive_site.uuid;
-	const uint32_t pickedUuid = locationManagementEditHelper->diveSiteUuid();
+	const uint32_t pickedUuid = ui.location->currDiveSiteUuid();
 	const QString newName = displayed_dive_site.name;
 	const uint32_t origUuid = cd->dive_site_uuid;
 	struct dive_site *origDs = get_dive_site_by_uuid(origUuid);
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index a071e6c..aea774b 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -22,7 +22,6 @@ class CylindersModel;
 class ExtraDataModel;
 class DivePictureModel;
 class QCompleter;
-class LocationManagementEditHelper;
 
 struct Completers {
 	QCompleter *divemaster;
@@ -124,7 +123,6 @@ private:
 	dive_trip_t *currentTrip;
 	dive_trip_t displayedTrip;
 	bool acceptingEdit;
-	LocationManagementEditHelper *locationManagementEditHelper;
 	void updateDisplayedDiveSite();
 	void updateDiveSite(int divenr);
 };
-- 
2.5.3

From 4d18ad0d843c32d433c445396ff540b1b3e46f3b Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 15:16:49 -0300
Subject: [PATCH 18/28] Remove dead code

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/locationinformation.h |  2 +-
 qt-ui/maintab.cpp           | 28 ----------------------------
 qt-ui/maintab.h             |  1 -
 3 files changed, 1 insertion(+), 30 deletions(-)

diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index 7e55aeb..db68090 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -83,7 +83,6 @@ public:
 	void setTemporaryDiveSiteName(const QString& s);
 	bool eventFilter(QObject*, QEvent*);
 	void itemActivated(const QModelIndex& index);
-
 	DiveSiteType currDiveSiteType() const;
 	uint32_t currDiveSiteUuid() const;
 
@@ -94,6 +93,7 @@ protected:
 	void keyPressEvent(QKeyEvent *ev);
 	void focusOutEvent(QFocusEvent *ev);
 	void showPopup();
+
 private:
 	DiveLocationFilterProxyModel *proxy;
 	DiveLocationModel *model;
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 8a6ea7f..4e3e9ba 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -195,7 +195,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
 	connect(ReverseGeoLookupThread::instance(), &QThread::finished,
 			this, &MainTab::setCurrentLocationIndex);
 
-	ui.location->installEventFilter(this);
 	acceptingEdit = false;
 }
 
@@ -210,33 +209,6 @@ MainTab::~MainTab()
 	}
 }
 
-bool MainTab::eventFilter(QObject *obj, QEvent *ev)
-{
-	QMoveEvent *mEv;
-	QResizeEvent *rEv;
-	QLineEdit *line = qobject_cast<QLineEdit*>(obj);
-
-	if (ev->type() == QEvent::MouseMove || ev->type() == QEvent::HoverMove || ev->type() == QEvent::Paint)
-		return false;
-
-	if (line) {
-		if (ev->type() == QEvent::Resize) {
-			/*if (line->completer()->popup()->isVisible()) {
-				QListView *choices = qobject_cast<QListView*>(line->completer()->popup());
-				QPoint p = ui.location->mapToGlobal(ui.location->pos());
-				choices->setGeometry(
-				choices->geometry().x(),
-				p.y() + 3,
-				choices->geometry().width(),
-				choices->geometry().height());
-
-			}
-			*/
-		}
-	}
-	return false;
-}
-
 void MainTab::setCurrentLocationIndex()
 {
 	if (current_dive) {
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index aea774b..502ea69 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -54,7 +54,6 @@ public:
 	void refreshDisplayedDiveSite();
 	void nextInputField(QKeyEvent *event);
 	void showAndTriggerEditSelective(struct dive_components what);
-	virtual bool eventFilter(QObject*, QEvent*);
 
 signals:
 	void addDiveFinished();
-- 
2.5.3

From 2d8f008ac319ab0a32cd93ee8dfd7705d144f723 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 16:03:28 -0300
Subject: [PATCH 19/28] Correctly Fix the popup position

When the message to 'This dive site is being edited' was
being show while the popup to choose the dive site, the
line edit was being covered. now it correctly moves to
the correct place.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/locationinformation.cpp | 6 +++++-
 qt-ui/locationinformation.h   | 2 +-
 qt-ui/maintab.cpp             | 3 +++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index b183491..bbb5906 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -489,7 +489,7 @@ void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev)
 	}
 }
 
-void DiveLocationLineEdit::showPopup()
+void DiveLocationLineEdit::fixPopupPosition()
 {
 	const QRect screen = QApplication::desktop()->availableGeometry(this);
 	const int maxVisibleItems = 5;
@@ -522,7 +522,11 @@ void DiveLocationLineEdit::showPopup()
 	}
 
 	view->setGeometry(pos.x(), pos.y(), w, h);
+}
 
+void DiveLocationLineEdit::showPopup()
+{
+	fixPopupPosition();
 	if (!view->isVisible()) {
 		setTemporaryDiveSiteName(text());
 		proxy->invalidate();
diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index db68090..3e8adea 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -85,7 +85,7 @@ public:
 	void itemActivated(const QModelIndex& index);
 	DiveSiteType currDiveSiteType() const;
 	uint32_t currDiveSiteUuid() const;
-
+	void fixPopupPosition();
 signals:
 	void diveSiteSelected(uint32_t uuid);
 
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 4e3e9ba..6320c2e 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -195,6 +195,9 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
 	connect(ReverseGeoLookupThread::instance(), &QThread::finished,
 			this, &MainTab::setCurrentLocationIndex);
 
+	connect(ui.diveNotesMessage, &KMessageWidget::showAnimationFinished,
+					ui.location, &DiveLocationLineEdit::fixPopupPosition);
+
 	acceptingEdit = false;
 }
 
-- 
2.5.3

From 449a53c33b16aa9d813a8f3966b5ff6f321f8e9c Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 16:11:35 -0300
Subject: [PATCH 20/28] Set the correct dive site uuid

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/maintab.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 6320c2e..de2f936 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -816,8 +816,7 @@ 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;
-	//TODO: FIX THIS
-	const uint32_t new_uuid = orig_uuid;
+	const uint32_t new_uuid = ui.location->currDiveSiteUuid();
 
 	qDebug() << "Updating Displayed Dive Site";
 
-- 
2.5.3

From 9dbd19a88d9284738ac15a18fa4b73ede84b26e1 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 16:13:46 -0300
Subject: [PATCH 21/28] Removed unused code

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/maintab.cpp | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index de2f936..7bbcf3f 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -293,12 +293,6 @@ void MainTab::displayMessage(QString str)
 	ui.diveStatisticsMessage->setText(str);
 	ui.diveStatisticsMessage->animatedShow();
 	updateTextLabels();
-
-// TODO: this doesn't exists anymore. Find out why it was removed from
-// the KMessageWidget and try to see if this is still needed.
-//	ui.tagWidget->fixPopupPosition(ui.diveNotesMessage->bestContentHeight());
-//	ui.buddy->fixPopupPosition(ui.diveNotesMessage->bestContentHeight());
-//	ui.divemaster->fixPopupPosition(ui.diveNotesMessage->bestContentHeight());
 }
 
 void MainTab::updateTextLabels(bool showUnits)
-- 
2.5.3

From c46736619458c93d6ed711dce8a53dec4bbf3ac2 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 16:19:58 -0300
Subject: [PATCH 22/28] Select an index if no index is selected.

Defaults to first row.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/locationinformation.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index bbb5906..c108c74 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -522,6 +522,9 @@ void DiveLocationLineEdit::fixPopupPosition()
 	}
 
 	view->setGeometry(pos.x(), pos.y(), w, h);
+	if(!view->currentIndex().isValid()) {
+		view->setCurrentIndex(view->model()->index(0,1));
+	}
 }
 
 void DiveLocationLineEdit::showPopup()
@@ -530,7 +533,6 @@ void DiveLocationLineEdit::showPopup()
 	if (!view->isVisible()) {
 		setTemporaryDiveSiteName(text());
 		proxy->invalidate();
-		view->setCurrentIndex(view->model()->index(0,1));
 		view->show();
 	}
 }
-- 
2.5.3

From 6289994af5baee69d91d17f278ad04cb113d6b42 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 16:27:44 -0300
Subject: [PATCH 23/28] Do not display popup with modifiers.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/locationinformation.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index c108c74..b9d489e 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -469,6 +469,9 @@ void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s)
 
 	model->setData(i1, i1_name );
 	proxy->invalidate();
+	fixPopupPosition();
+	if (!view->isVisible())
+		view->show();
 }
 
 void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev)
@@ -482,8 +485,9 @@ void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev)
 		if(ev->key() != Qt::Key_Up && ev->key() != Qt::Key_Down) {
 			currType = NEW_DIVE_SITE;
 			currUuid = RECENTLY_ADDED_DIVESITE;
+		} else {
+			showPopup();
 		}
-		showPopup();
 	} else if (ev->key() == Qt::Key_Escape) {
 		view->hide();
 	}
-- 
2.5.3

From 46f343b9860efddf7ccdd685feb65dd0664e273f Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 16:34:52 -0300
Subject: [PATCH 24/28] Dont crash on new dive site.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/maintab.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 7bbcf3f..884f76c 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -813,6 +813,10 @@ void MainTab::updateDisplayedDiveSite()
 	const uint32_t new_uuid = ui.location->currDiveSiteUuid();
 
 	qDebug() << "Updating Displayed Dive Site";
+	if (new_uuid == RECENTLY_ADDED_DIVESITE) {
+		qDebug() << "New dive site selected, don't try to update something that doesn't exists yet.";
+		return;
+	}
 
 	if(orig_uuid) {
 		if (new_uuid && orig_uuid != new_uuid) {
-- 
2.5.3

From 64ec546ba83ffc546345e9fc880c1590a2e7806f Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 16:55:48 -0300
Subject: [PATCH 25/28] Much simpler code to set the dive site

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/maintab.cpp | 74 ++++++++++++++++---------------------------------------
 1 file changed, 21 insertions(+), 53 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 884f76c..c7a75d4 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -860,65 +860,33 @@ void MainTab::updateDiveSite(int divenr)
 	if (!cd)
 		return;
 
-	const uint32_t newUuid = displayed_dive_site.uuid;
-	const uint32_t pickedUuid = ui.location->currDiveSiteUuid();
+	if (ui.location->text().isEmpty()) {
+		qDebug() << "No location data set, not updating the dive site.";
+		return;
+	}
+
+	uint32_t pickedUuid = ui.location->currDiveSiteUuid();
 	const QString newName = displayed_dive_site.name;
 	const uint32_t origUuid = cd->dive_site_uuid;
 	struct dive_site *origDs = get_dive_site_by_uuid(origUuid);
 	const QString origName = origDs ? origDs->name : "";
-	// the user has accepted the changes made to the displayed_dive_site
-	// so let's make them permanent
-	if (!origUuid) {
-		// the dive edited didn't have a dive site
-		qDebug() << "current dive didn't have a dive site before edit";
-		if (pickedUuid) {
-			qDebug() << "assign dive_site" << pickedUuid << "to current dive";
-			cd->dive_site_uuid = pickedUuid;
-		} else if (newUuid) {
-			// user created a new divesite
-			cd->dive_site_uuid = newUuid;
-		} else if (!newName.isEmpty()) {
-			// user entered a name but didn't pick or create a dive site, so create a divesite
-			uint32_t createdUuid = create_dive_site(displayed_dive_site.name, cd->when);
-			struct dive_site *newDs = get_dive_site_by_uuid(createdUuid);
-			copy_dive_site(&displayed_dive_site, newDs);
-			newDs->uuid = createdUuid; // the copy overwrote the uuid
-			cd->dive_site_uuid = createdUuid;
-			qDebug() << "create a new dive site with name" << newName << "which is now named" << newDs->name << "and assign it as uuid" << createdUuid;
-		} else {
-			qDebug() << "neither uuid picked, uuid created nor new name found";
-		}
-	} else {
-		qDebug() << "current dive had dive site with uuid" << origUuid;
-		if (origUuid == newUuid) {
-			// looks like nothing changed
-			qDebug() << "same uuid";
-		} else if (newName != origName) {
-			if (newUuid == 0) {
-				// so we created a new site, add it to the global list
-				uint32_t createdUuid = create_dive_site(displayed_dive_site.name, cd->when);
-				struct dive_site *newDs = get_dive_site_by_uuid(createdUuid);
-				copy_dive_site(&displayed_dive_site, newDs);
-				newDs->uuid = createdUuid; // the copy overwrote the uuid
-				cd->dive_site_uuid = createdUuid;
-				qDebug() << "create a new dive site with name" << newName << "which is now named" << newDs->name << "and assign it as uuid" << createdUuid;
-				qDebug() << "original dive had site" << origUuid << "and" << (origDs ? QString("notes %1").arg(origDs->notes) : QString("no dive site"));
-				if (origDs && same_string(origDs->notes, "SubsurfaceWebservice")) {
-					// this is a special case - let's remove the original dive site if this was the only user
-					if (!is_dive_site_used(origDs->uuid, false)) {
-						qDebug() << "delete the autogenerated dive site" << origDs->name;
-						delete_dive_site(origDs->uuid);
-						free(newDs->notes);
-						newDs->notes = NULL;
-					}
-				}
-			} else {
-				qDebug() << "switched to dive site" << newName << "uuid" << newUuid << "for current dive";
-				cd->dive_site_uuid = newUuid;
-				// what to do with the old site?
-			}
+
+	if (pickedUuid == RECENTLY_ADDED_DIVESITE) {
+		pickedUuid = create_dive_site(ui.location->text().isEmpty() ? qPrintable(tr("New dive site")) : qPrintable(ui.location->text()), displayed_dive.when);
+		struct dive_site *newDs = get_dive_site_by_uuid(pickedUuid);
+		copy_dive_site(newDs, &displayed_dive_site);
+	}
+
+	if (origDs && pickedUuid != origDs->uuid && same_string(origDs->notes, "SubsurfaceWebservice")) {
+		// this is a special case - let's remove the original dive site if this was the only user
+		if (!is_dive_site_used(origDs->uuid, false)) {
+			qDebug() << "delete the autogenerated dive site" << origDs->name;
+			delete_dive_site(origDs->uuid);
 		}
 	}
+
+	cd->dive_site_uuid = pickedUuid;
+	qDebug() << "Setting the dive site id on the dive:" << pickedUuid;
 }
 
 void MainTab::acceptChanges()
-- 
2.5.3

From c03bfa1470842fe5b4b2174c3b2951c07bba6601 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 16:56:38 -0300
Subject: [PATCH 26/28] Code cleanup

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/maintab.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index c7a75d4..c74ef52 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -866,10 +866,8 @@ void MainTab::updateDiveSite(int divenr)
 	}
 
 	uint32_t pickedUuid = ui.location->currDiveSiteUuid();
-	const QString newName = displayed_dive_site.name;
 	const uint32_t origUuid = cd->dive_site_uuid;
 	struct dive_site *origDs = get_dive_site_by_uuid(origUuid);
-	const QString origName = origDs ? origDs->name : "";
 
 	if (pickedUuid == RECENTLY_ADDED_DIVESITE) {
 		pickedUuid = create_dive_site(ui.location->text().isEmpty() ? qPrintable(tr("New dive site")) : qPrintable(ui.location->text()), displayed_dive.when);
-- 
2.5.3

From 1c9a51ebdd4838243d2d545172df91dd4e701855 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 17:05:31 -0300
Subject: [PATCH 27/28] Handles Dive Selection gracefully

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/maintab.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index c74ef52..884ef54 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -868,13 +868,19 @@ void MainTab::updateDiveSite(int divenr)
 	uint32_t pickedUuid = ui.location->currDiveSiteUuid();
 	const uint32_t origUuid = cd->dive_site_uuid;
 	struct dive_site *origDs = get_dive_site_by_uuid(origUuid);
+	struct dive_site *newDs = NULL;
+
+	if (pickedUuid == origUuid) {
+		return;
+	}
 
 	if (pickedUuid == RECENTLY_ADDED_DIVESITE) {
 		pickedUuid = create_dive_site(ui.location->text().isEmpty() ? qPrintable(tr("New dive site")) : qPrintable(ui.location->text()), displayed_dive.when);
-		struct dive_site *newDs = get_dive_site_by_uuid(pickedUuid);
-		copy_dive_site(newDs, &displayed_dive_site);
 	}
 
+	newDs = get_dive_site_by_uuid(pickedUuid);
+	copy_dive_site(newDs, &displayed_dive_site);
+
 	if (origDs && pickedUuid != origDs->uuid && same_string(origDs->notes, "SubsurfaceWebservice")) {
 		// this is a special case - let's remove the original dive site if this was the only user
 		if (!is_dive_site_used(origDs->uuid, false)) {
-- 
2.5.3

From c524d9bc0d33e9012cc94421a2c46f1373a2a1bb Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 23 Sep 2015 17:11:43 -0300
Subject: [PATCH 28/28] Disable edit dive site if already in edit mode

If user selected a new dive site (a dive site that doesn't
exists yet, to be created) and clicked in edit it would edit
the *old* dive site. this is not optional, but since it
removes a severe regression it will be like this (I won't
change it till 5.0) for a while, untill I have time to
actually code something not messy for that.

The current Dive Location Management is *much* nicer than
the old one, code-wise. No more magic numbers, magic codepaths,
magic constants, qt black magic. It's straigth-forward code
simple to follow, simple to edit.

This was something I was actually postponing for 5.0 but I
managed to get a boost of subsurface time at work.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/maintab.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 884ef54..d1b6350 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -55,7 +55,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
 	ui.extraData->setModel(extraDataModel);
 	closeMessage();
 
-	ui.editDiveSiteButton->setEnabled(true);
 	connect(ui.editDiveSiteButton, SIGNAL(clicked()), MainWindow::instance(), SIGNAL(startDiveSiteEdit()));
 
 	QAction *action = new QAction(tr("Apply changes"), this);
@@ -331,6 +330,8 @@ void MainTab::enableEdition(EditMode newEditMode)
 		MainWindow::instance()->editCurrentDive();
 		return;
 	}
+
+	ui.editDiveSiteButton->setEnabled(false);
 	MainWindow::instance()->dive_list()->setEnabled(false);
 	MainWindow::instance()->setEnabledToolbar(false);
 
@@ -1105,6 +1106,7 @@ void MainTab::acceptChanges()
 	weightModel->changed = false;
 	MainWindow::instance()->setEnabledToolbar(true);
 	acceptingEdit = false;
+	ui.editDiveSiteButton->setEnabled(true);
 }
 
 void MainTab::resetPallete()
@@ -1177,6 +1179,7 @@ void MainTab::rejectChanges()
 	cylindersModel->updateDive();
 	weightModel->updateDive();
 	extraDataModel->updateDive();
+	ui.editDiveSiteButton->setEnabled(true);
 }
 #undef EDIT_TEXT2
 
-- 
2.5.3

_______________________________________________
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to