Those are correct patches and should be used, there's a problem that I
was unable to solve, tougth ( and I'm not feeling very cody today )
After a edit is done, the tags will be deleted and repopulated, this
is done in 'saveTag()', the code seems correct and works.
The tags are correctly saved on the dive, but the tags are not
appearing on the information tab unless you have more than one dive on
the list, then desselect and resellect it.

I tried to walk around the code, and for me it seems like the code
that copies the selected dive to the displayed_dive is not being
called, and I didn't found out why.
From 6c015c813ced581f40d506ac77c2f8dd4ee58972 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Tue, 8 Jul 2014 18:18:33 -0300
Subject: [PATCH 1/2] Remove if to save or not save the tags.

The way that we work with tags is a bit weird, we have a global
tag_list pointer and every dive copy the tags from there. the problem
is that the tags_changed() function looks at those two places ( the
global and the dive-local lists ) to see if something was changed,
but we shouldn't add anything at the global taglist untill a tag
is really added, so that function is bogus.

The correct way to check if something changed is to check all the
strings in tags against the strings in the QLineEdit and see if they
are the same, then we can add things to the tag_list.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 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 477cd22..ad672ce 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -719,8 +719,7 @@ void MainTab::acceptChanges()
 				}
 			}
 		}
-		if (tagsChanged(&displayed_dive, cd))
-			saveTags();
+		saveTags();
 
 #if 0 // with the new architecture this shouldn't be needed anymore
 		if (editMode == MANUALLY_ADDED_DIVE) {
-- 
2.0.1

From bb0e4165958dc276d5b41269e51c2678a24ac1ca Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Tue, 8 Jul 2014 18:45:20 -0300
Subject: [PATCH 2/2] Correctly save the tags on the dive.

Very good patch, lots of removed lines. :)
Only try to add the tags when user accepts, discards the
test to see if the tags were changed or not, delete the
old list and copy the new one always.

only bug that's appearing now: taglist is still empty after save
we need to reselect the dive to make it appear, fixing that
on the next patch.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/maintab.cpp | 31 ++++---------------------------
 qt-ui/maintab.h   |  1 -
 2 files changed, 4 insertions(+), 28 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index ad672ce..5249660 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -970,24 +970,6 @@ void MainTab::on_timeEdit_timeChanged(const QTime &time)
 	markChangedWidget(ui.timeEdit);
 }
 
-bool MainTab::tagsChanged(dive *a, dive *b)
-{
-	char bufA[1024], bufB[1024];
-	taglist_get_tagstring(a->tag_list, bufA, sizeof(bufA));
-	taglist_get_tagstring(b->tag_list, bufB, sizeof(bufB));
-	QString tagStringA(bufA);
-	QString tagStringB(bufB);
-	QStringList text_list = tagStringA.split(",", QString::SkipEmptyParts);
-	for (int i = 0; i < text_list.size(); i++)
-		text_list[i] = text_list[i].trimmed();
-	QString textA = text_list.join(", ");
-	text_list = tagStringB.split(",", QString::SkipEmptyParts);
-	for (int i = 0; i < text_list.size(); i++)
-		text_list[i] = text_list[i].trimmed();
-	QString textB = text_list.join(", ");
-	return textA != textB;
-}
-
 // changing the tags on multiple dives is semantically strange - what's the right thing to do?
 void MainTab::saveTags()
 {
@@ -997,21 +979,16 @@ void MainTab::saveTags()
 		taglist_free(mydive->tag_list);
 		mydive->tag_list = NULL;
 		Q_FOREACH (tag, ui.tagWidget->getBlockStringList())
-			taglist_add_tag(&mydive->tag_list, tag.toUtf8().data()););
+			taglist_add_tag(&mydive->tag_list, tag.toUtf8().data());
+	);
+	qDebug() << "Save tags called";
 }
 
 void MainTab::on_tagWidget_textChanged()
 {
 	if (editMode == IGNORE)
 		return;
-	QString tag;
-	if (displayed_dive.tag_list != current_dive->tag_list)
-		taglist_free(displayed_dive.tag_list);
-	displayed_dive.tag_list = NULL;
-	Q_FOREACH (tag, ui.tagWidget->getBlockStringList())
-		taglist_add_tag(&displayed_dive.tag_list, tag.toUtf8().data());
-	if (tagsChanged(&displayed_dive, current_dive))
-		markChangedWidget(ui.tagWidget);
+	markChangedWidget(ui.tagWidget);
 }
 
 void MainTab::on_location_textChanged(const QString &text)
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 3eb5596..1493d6d 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -102,7 +102,6 @@ private:
 	bool modified;
 	void resetPallete();
 	void saveTags();
-	bool tagsChanged(struct dive *a, struct dive *b);
 	void updateGpsCoordinates(const struct dive *dive);
 	void markChangedWidget(QWidget *w);
 };
-- 
2.0.1

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

Reply via email to