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 <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-07-08 18:45:20 -03:00 committed by Dirk Hohndel
parent 0054304cc8
commit dbc33cb81a
2 changed files with 4 additions and 28 deletions

View file

@ -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)

View file

@ -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);
};