From c71a5d74135d8ebf9dce6de6633499c1c41c07ff Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 1 May 2018 12:35:18 +0200 Subject: Dive pictures: Don't update all pictures on drag & drop to profile In the old code, we used to reload the whole picture list on drag & drop to the profile. Instead, only update the drag&dropped picture and repaint the profile-pictures. Signed-off-by: Berthold Stoeger --- qt-models/divepicturemodel.cpp | 22 +++++++++++++++++++--- qt-models/divepicturemodel.h | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'qt-models') diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp index 89917761c..2fc7b8311 100644 --- a/qt-models/divepicturemodel.cpp +++ b/qt-models/divepicturemodel.cpp @@ -153,12 +153,28 @@ int DivePictureModel::rowCount(const QModelIndex &parent) const return pictures.count(); } +int DivePictureModel::findPictureId(const QString &filename) +{ + for (int i = 0; i < pictures.size(); ++i) + if (pictures[i].filename == filename) + return i; + return -1; +} + void DivePictureModel::updateThumbnail(QString filename, QImage thumbnail) { - for (int i = 0; i < pictures.size(); ++i) { - if (pictures[i].filename != filename) - continue; + int i = findPictureId(filename); + if (i >= 0) { pictures[i].image = thumbnail; emit dataChanged(createIndex(i, 0), createIndex(i, 1)); } } + +void DivePictureModel::updateDivePictureOffset(const QString &filename, int offsetSeconds) +{ + int i = findPictureId(filename); + if (i >= 0) { + pictures[i].offsetSeconds = offsetSeconds; + emit dataChanged(createIndex(i, 0), createIndex(i, 1)); + } +} diff --git a/qt-models/divepicturemodel.h b/qt-models/divepicturemodel.h index e68c00570..7f2cde6d0 100644 --- a/qt-models/divepicturemodel.h +++ b/qt-models/divepicturemodel.h @@ -24,12 +24,14 @@ public: void updateDivePicturesWhenDone(QList>); void removePicture(const QString& fileUrl, bool last); int rowDDStart, rowDDEnd; + void updateDivePictureOffset(const QString &filename, int offsetSeconds); public slots: void setZoomLevel(int level); void updateThumbnail(QString filename, QImage thumbnail); private: DivePictureModel(); QList pictures; + int findPictureId(const QString &filename); // Return -1 if not found double zoomLevel; // -1.0: minimum, 0.0: standard, 1.0: maximum int size; int defaultSize; -- cgit v1.2.3-70-g09d2