this doesn't selects the correct dive site yet if you have more than one
dive site with the same name, it's just a proof of concept about the visual
of it.

I'm working on make it select the right dive_site.
From 37014aec52e7e0970022d7cf1fa732a966cddf95 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 8 Jul 2015 11:13:06 -0300
Subject: [PATCH 4/4] Paint correctly the states

The State handling is a pain to do manually, but I can't really
use the style painter because if I do that it would paint the
string of the model ( and that's something I don't wanna do )
so I clear the text, draw the control, then I paint the stuff
that I really need.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/modeldelegates.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 423eea3..2c03a80 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -520,12 +520,12 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
 	fontBigger.setPointSize(fontBigger.pointSize() + 1);
 	fontBigger.setBold(true);
 
+	initStyleOption(&opt, index);
+	opt.text = QString();
+	qApp->style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, NULL);
+
 	painter->save();
 	painter->setRenderHint(QPainter::Antialiasing);
-	if( ( option.state & QStyle::State_Selected ) || ( option.state & QStyle::State_MouseOver ) )
-	    bg = option.palette.highlight();
-	else
-	    bg = option.palette.window();
 	painter->setPen(QPen(Qt::NoPen));
 	painter->setBrush(bg);
 	painter->drawRect(option.rect);
-- 
2.4.5

From e264534821f0f6727c6e6c41c05e3135fc5125fb Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 8 Jul 2015 11:09:51 -0300
Subject: [PATCH 3/4] Use Taxonomy or Coords on the Delegate

The Taxonomy text should be used if there's a taxonomy
in the dive site. if there isn't, then use coords. if
there's none, then nothing will appear on the bottom
of the dive site name.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/modeldelegates.cpp | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 0399722..423eea3 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -502,9 +502,20 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
 	if (!ds)
 		return;
 
-	const char *gpsCoords = printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg);
-	QString diveSiteCoords(gpsCoords);
-	free( (void*) gpsCoords);
+	QString bottomText;
+	for (int i = 0; i < ds->taxonomy.nr; i++) {
+		if(ds->taxonomy.category[i].category == TC_NONE)
+			continue;
+		if(!bottomText.isEmpty())
+			bottomText += " ";
+		bottomText += QString(ds->taxonomy.category[i].value) + " ";
+	}
+
+	if (bottomText.isEmpty()) {
+		const char *gpsCoords = printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg);
+		bottomText = QString(gpsCoords);
+		free( (void*) gpsCoords);
+	}
 
 	fontBigger.setPointSize(fontBigger.pointSize() + 1);
 	fontBigger.setBold(true);
@@ -526,7 +537,7 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
 	painter->drawText(option.rect.x(),option.rect.y() + fmBigger.boundingRect("YH").height(), diveSiteName);
 	painter->setFont(fontSmaller);
 	painter->setBrush(option.palette.brightText());
-	painter->drawText(option.rect.x(),option.rect.y() + fmBigger.boundingRect("YH").height() * 2, diveSiteCoords);
+	painter->drawText(option.rect.x(),option.rect.y() + fmBigger.boundingRect("YH").height() * 2, bottomText);
 	painter->restore();
 }
 
-- 
2.4.5

From c4fb701df4d70a16001806bdaea023198a36ee8e Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 8 Jul 2015 10:11:13 -0300
Subject: [PATCH 2/4] Better spacing on the Delegate

Makes the Location Delegate pleasant to the eye.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/modeldelegates.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 68e62a5..0399722 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -506,7 +506,7 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
 	QString diveSiteCoords(gpsCoords);
 	free( (void*) gpsCoords);
 
-	fontBigger.setPointSize(fontBigger.pointSize() + 2);
+	fontBigger.setPointSize(fontBigger.pointSize() + 1);
 	fontBigger.setBold(true);
 
 	painter->save();
@@ -533,7 +533,7 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
 QSize LocationFilterDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
 {
 	QFont fontBigger = qApp->font();
-	fontBigger.setPointSize(fontBigger.pointSize() + 2);
+	fontBigger.setPointSize(fontBigger.pointSize());
 	fontBigger.setBold(true);
 
 	QFontMetrics fmBigger(fontBigger);
@@ -542,6 +542,9 @@ QSize LocationFilterDelegate::sizeHint(const QStyleOptionViewItem &option, const
 	QFontMetrics fmSmaller(fontSmaller);
 
 	QSize retSize = QStyledItemDelegate::sizeHint(option, index);
-	retSize.setHeight(fmBigger.boundingRect("Yellow House").height() + 5 /*spacing*/ + fmSmaller.boundingRect("Yellow House").height());
+	retSize.setHeight(
+		fmBigger.boundingRect("Yellow House").height() + 5 /*spacing*/ +
+		fmSmaller.boundingRect("Yellow House").height());
+
 	return retSize;
 }
-- 
2.4.5

From ed79913e535c552ab460d96a6061d26b5715a9cb Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 8 Jul 2015 09:59:25 -0300
Subject: [PATCH 1/4] Fix show the correct delegate on the Completer

For some reason the completer wouldn't show the delegate
if the line order of the code was different.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/maintab.cpp | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index f698dbb..0ff44ae 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -59,21 +59,13 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
 	closeMessage();
 
 	QCompleter *completer = new QCompleter();
+	QListView *completerListview = new QListView();
+	completer->setPopup(completerListview);
 	completer->setModel(LocationInformationModel::instance());
 	completer->setCompletionColumn(LocationInformationModel::NAME);
 	completer->setCompletionRole(Qt::DisplayRole);
-	completer->setCompletionMode(QCompleter::PopupCompletion);
 	completer->setCaseSensitivity(Qt::CaseInsensitive);
-
-	QListView *completerListview = new QListView();
 	completerListview->setItemDelegate(new LocationFilterDelegate());
-	completer->setPopup(completerListview);
-
-	QListView *completerListView2 = new QListView();
-	completerListView2->setItemDelegate(new LocationFilterDelegate());
-	completerListView2->setModel(LocationInformationModel::instance());
-	completerListView2->setModelColumn(1);
-	completerListView2->show();
 
 	ui.location->setCompleter(completer);
 	connect(ui.addDiveSite, SIGNAL(clicked()), this, SLOT(showDiveSiteSimpleEdit()));
-- 
2.4.5

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to