aboutsummaryrefslogtreecommitdiffstats
path: root/commands/command_base.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-05 09:00:00 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-10 09:25:57 -0700
commit0212b1b9f7734c2ee4edaf7e27a2c25601b5c4bc (patch)
tree6c3120611aa8b41948b6a96cc0f67d7cfd07b23d /commands/command_base.cpp
parent8ce4e10ccb98558886ef4ead4554f44345acd603 (diff)
downloadsubsurface-0212b1b9f7734c2ee4edaf7e27a2c25601b5c4bc.tar.gz
undo infrastructure: improve undo command texts
For many of the commands it is fairly easy to add information that makes it easier to figure out what actually happened. That's especially true for commands operating on dives. Trip and dive site edits haven't been given these more elaborate undo texts (yet). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'commands/command_base.cpp')
-rw-r--r--commands/command_base.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/commands/command_base.cpp b/commands/command_base.cpp
index d13daf269..8ebbf9be5 100644
--- a/commands/command_base.cpp
+++ b/commands/command_base.cpp
@@ -3,6 +3,7 @@
#include "command_base.h"
#include "core/qthelper.h" // for updateWindowTitle()
#include "core/subsurface-qt/divelistnotifier.h"
+#include <QVector>
namespace Command {
@@ -49,6 +50,37 @@ QAction *redoAction(QObject *parent)
return undoStack.createRedoAction(parent, QCoreApplication::translate("Command", "&Redo"));
}
+QString diveNumberOrDate(struct dive *d)
+{
+ if (d->number != 0)
+ return QStringLiteral("#%1").arg(d->number);
+ else
+ return QStringLiteral("@%1").arg(get_short_dive_date_string(d->when));
+}
+
+QString getListOfDives(const std::vector<struct dive*> &dives)
+{
+ QString listOfDives;
+ if ((int)dives.size() == dive_table.nr)
+ return Base::tr("all dives");
+ int i = 0;
+ for (dive *d: dives) {
+ // we show a maximum of five dive numbers, or 4 plus ellipsis
+ if (++i == 4 && dives.size() >= 5)
+ return listOfDives + "...";
+ listOfDives += diveNumberOrDate(d) + ", ";
+ }
+ if (!listOfDives.isEmpty())
+ listOfDives.truncate(listOfDives.length() - 2);
+ return listOfDives;
+}
+
+QString getListOfDives(QVector<struct dive *> dives)
+{
+ return getListOfDives(std::vector<struct dive *>(dives.begin(), dives.end()));
+}
+
+
// return a string that can be used for the commit message and should list the changes that
// were made to the dive list
QString changesMade()