summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-14 22:07:00 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-05-06 13:58:09 -0700
commite61641c79cd57bfa55d2371615a7eef7c73b4eb7 (patch)
tree85333dfed1630b1d968498495d1d1c151570e015 /qt-models
parentebdb3e3c3029d3762207e8dcadfa3a61bf0a9293 (diff)
downloadsubsurface-e61641c79cd57bfa55d2371615a7eef7c73b4eb7.tar.gz
undo: implement undo of setting a picture time by drag&drop
Even though the functionality is seemingly trivial, this is a bit invasive, as the code has to be split into two distinct parts: 1) Post undo command 2) React to changes to the divelist Don't compile that code on mobile. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/divepicturemodel.cpp24
-rw-r--r--qt-models/divepicturemodel.h3
2 files changed, 11 insertions, 16 deletions
diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp
index 306030c4e..e50c51744 100644
--- a/qt-models/divepicturemodel.cpp
+++ b/qt-models/divepicturemodel.cpp
@@ -6,6 +6,7 @@
#include "core/imagedownloader.h"
#include "core/picture.h"
#include "core/qthelper.h"
+#include "core/subsurface-qt/divelistnotifier.h"
#include <QFileInfo>
#include <QPainter>
@@ -20,6 +21,8 @@ DivePictureModel::DivePictureModel() : zoomLevel(0.0)
{
connect(Thumbnailer::instance(), &Thumbnailer::thumbnailChanged,
this, &DivePictureModel::updateThumbnail, Qt::QueuedConnection);
+ connect(&diveListNotifier, &DiveListNotifier::pictureOffsetChanged,
+ this, &DivePictureModel::pictureOffsetChanged);
}
void DivePictureModel::setZoomLevel(int level)
@@ -212,13 +215,13 @@ void DivePictureModel::updateThumbnail(QString filename, QImage thumbnail, durat
}
}
-void DivePictureModel::updateDivePictureOffset(int diveId, const QString &filenameIn, int offsetSeconds)
+void DivePictureModel::pictureOffsetChanged(dive *d, const QString filenameIn, offset_t offset)
{
std::string filename = filenameIn.toStdString();
// Find the pictures of the given dive.
- auto from = std::find_if(pictures.begin(), pictures.end(), [diveId](const PictureEntry &e) { return e.diveId == diveId; });
- auto to = std::find_if(from, pictures.end(), [diveId](const PictureEntry &e) { return e.diveId != diveId; });
+ auto from = std::find_if(pictures.begin(), pictures.end(), [d](const PictureEntry &e) { return e.diveId == d->id; });
+ auto to = std::find_if(from, pictures.end(), [d](const PictureEntry &e) { return e.diveId != d->id; });
// Find picture with the given filename
auto oldPos = std::find_if(from, to, [filename](const PictureEntry &e) { return e.filename == filename; });
@@ -226,20 +229,11 @@ void DivePictureModel::updateDivePictureOffset(int diveId, const QString &filena
return;
// Find new position
- auto newPos = std::find_if(from, to, [offsetSeconds](const PictureEntry &e) { return e.offsetSeconds > offsetSeconds; });
+ auto newPos = std::find_if(from, to, [offset](const PictureEntry &e) { return e.offsetSeconds > offset.seconds; });
// Update the offset here and in the backend
- oldPos->offsetSeconds = offsetSeconds;
- if (struct dive *dive = get_dive_by_uniq_id(diveId)) {
- FOR_EACH_PICTURE(dive) {
- if (picture->filename == filename) {
- picture->offset.seconds = offsetSeconds;
- mark_divelist_changed(true);
- break;
- }
- }
- copy_dive(current_dive, &displayed_dive);
- }
+ oldPos->offsetSeconds = offset.seconds;
+ copy_dive(current_dive, &displayed_dive); // TODO: remove once profile can display arbitrary dives
// Henceforth we will work with indices instead of iterators
int oldIndex = oldPos - pictures.begin();
diff --git a/qt-models/divepicturemodel.h b/qt-models/divepicturemodel.h
index 1ed5e8095..2d628f429 100644
--- a/qt-models/divepicturemodel.h
+++ b/qt-models/divepicturemodel.h
@@ -18,6 +18,7 @@ struct PictureEntry {
duration_t length;
};
+struct dive;
class DivePictureModel : public QAbstractTableModel {
Q_OBJECT
public:
@@ -27,12 +28,12 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
void updateDivePictures();
void removePictures(const QVector<QString> &fileUrls);
- void updateDivePictureOffset(int diveId, const QString &filename, int offsetSeconds);
signals:
void picturesRemoved(const QVector<QString> &fileUrls);
public slots:
void setZoomLevel(int level);
void updateThumbnail(QString filename, QImage thumbnail, duration_t duration);
+ void pictureOffsetChanged(dive *d, const QString filename, offset_t offset);
private:
DivePictureModel();
QVector<PictureEntry> pictures;