summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-11 10:38:50 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-11 10:40:20 -0700
commitebaa7d1fd08fec3371e6448532564ebef6df4f29 (patch)
tree3f01cda94eef46d059491a02818dcf90c39e9d0c /qt-ui
parent698b2b133fb43cfa2c28f7639662f3d787627c30 (diff)
downloadsubsurface-ebaa7d1fd08fec3371e6448532564ebef6df4f29.tar.gz
Multi dive edit: treat buddy and divemaster as tag lists
So just like tags do "differential editing". Figure out what (or in this case, who) was added / removed from the displayed dive and do the same for all other selected dives. This does seem a bit over top for divemaster, but this is more consistent and therefore should make more sense to the user - assuming we ever have one who runs into this. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/maintab.cpp75
-rw-r--r--qt-ui/maintab.h2
2 files changed, 73 insertions, 4 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 2dd33544c..ebfa0537e 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -26,6 +26,7 @@
#include <QShortcut>
#include <QMessageBox>
#include <QDesktopServices>
+#include <QStringList>
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
weightModel(new WeightModel(this)),
@@ -755,15 +756,11 @@ void MainTab::acceptChanges()
struct dive *cd = current_dive;
// now check if something has changed and if yes, edit the selected dives that
// were identical with the master dive shown (and mark the divelist as changed)
- if (!same_string(displayed_dive.buddy, cd->buddy))
- MODIFY_SELECTED_DIVES(EDIT_TEXT(buddy));
if (!same_string(displayed_dive.suit, cd->suit))
MODIFY_SELECTED_DIVES(EDIT_TEXT(suit));
if (!same_string(displayed_dive.notes, cd->notes))
MODIFY_SELECTED_DIVES(EDIT_TEXT(notes));
if (!same_string(displayed_dive.divemaster, cd->divemaster))
- MODIFY_SELECTED_DIVES(EDIT_TEXT(divemaster));
- if (displayed_dive.rating != cd->rating)
MODIFY_SELECTED_DIVES(EDIT_VALUE(rating));
if (displayed_dive.visibility != cd->visibility)
MODIFY_SELECTED_DIVES(EDIT_VALUE(visibility));
@@ -783,6 +780,9 @@ void MainTab::acceptChanges()
if (displayed_dive.dive_site_uuid != cd->dive_site_uuid)
MODIFY_SELECTED_DIVES(EDIT_VALUE(dive_site_uuid));
+ // three text fields are somewhat special and are represented as tags
+ // in the UI - they need somewhat smarter handling
+ saveTaggedStrings();
saveTags();
if (editMode != ADD && cylindersModel->changed) {
@@ -1135,6 +1135,73 @@ void MainTab::saveTags()
);
}
+// buddy and divemaster are represented in the UI just like the tags, but the internal
+// representation is just a string (with commas as delimiters). So we need to do the same
+// thing we did for tags, just differently
+void MainTab::saveTaggedStrings()
+{
+ QStringList addedList, removedList;
+ struct dive *cd = current_dive;
+
+ diffTaggedStrings(cd->buddy, displayed_dive.buddy, addedList, removedList);
+ MODIFY_SELECTED_DIVES(
+ QStringList oldList = QString(mydive->buddy).split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts);
+ QString newString;
+ QString comma;
+ Q_FOREACH (const QString tag, oldList) {
+ if (!removedList.contains(tag, Qt::CaseInsensitive)) {
+ newString += comma + tag;
+ comma = ", ";
+ }
+ }
+ Q_FOREACH (const QString tag, addedList) {
+ if (!oldList.contains(tag, Qt::CaseInsensitive)) {
+ newString += comma + tag;
+ comma = ", ";
+ }
+ }
+ free(mydive->buddy);
+ mydive->buddy = copy_string(qPrintable(newString));
+ );
+ addedList.clear();
+ removedList.clear();
+ diffTaggedStrings(cd->divemaster, displayed_dive.divemaster, addedList, removedList);
+ MODIFY_SELECTED_DIVES(
+ QStringList oldList = QString(mydive->divemaster).split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts);
+ QString newString;
+ QString comma;
+ Q_FOREACH (const QString tag, oldList) {
+ if (!removedList.contains(tag, Qt::CaseInsensitive)) {
+ newString += comma + tag;
+ comma = ", ";
+ }
+ }
+ Q_FOREACH (const QString tag, addedList) {
+ if (!oldList.contains(tag, Qt::CaseInsensitive)) {
+ newString += comma + tag;
+ comma = ", ";
+ }
+ }
+ free(mydive->divemaster);
+ mydive->divemaster = copy_string(qPrintable(newString));
+ );
+}
+
+void MainTab::diffTaggedStrings(QString currentString, QString displayedString, QStringList &addedList, QStringList &removedList)
+{
+ QStringList displayedList, currentList;
+ currentList = currentString.split(',', QString::SkipEmptyParts);
+ displayedList = displayedString.split(',', QString::SkipEmptyParts);
+ Q_FOREACH ( const QString tag, currentList) {
+ if (!displayedList.contains(tag, Qt::CaseInsensitive))
+ removedList << tag.trimmed();
+ }
+ Q_FOREACH (const QString tag, displayedList) {
+ if (!currentList.contains(tag, Qt::CaseInsensitive))
+ addedList << tag.trimmed();
+ }
+}
+
void MainTab::on_tagWidget_textChanged()
{
char buf[1024];
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 8869b068e..5cff5714f 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -112,6 +112,8 @@ private:
bool copyPaste;
void resetPallete();
void saveTags();
+ void saveTaggedStrings();
+ void diffTaggedStrings(QString currentString, QString displayedString, QStringList &addedList, QStringList &removedList);
void markChangedWidget(QWidget *w);
dive_trip_t *currentTrip;
dive_trip_t displayedTrip;