diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-06-30 11:36:37 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-08 11:00:44 -0700 |
commit | 3d7865cf269d8b2f9e06084586ee76e8a44faff1 (patch) | |
tree | 0473244d27775664edf717cd45cf2f62613c77b6 /qt-models/divepicturemodel.cpp | |
parent | b28dba6087f0433af8ece176b64fcac54ca370a4 (diff) | |
download | subsurface-3d7865cf269d8b2f9e06084586ee76e8a44faff1.tar.gz |
Dive pictures: detach ProfileWidget2 from DivePictureModel
As long as ProfileWidget2 and DivePictureModel showed the same set of
pictures and any change would lead to a full recalculation of the set,
it made sense to let ProfileWidget2 use DivePictureModel's data.
Recently, keeping the two lists in sync become more and more of a
burden. Therefore, disconnect ProfileWidget2 and DivePictureModel. This
will lead to some code-duplication and perhaps a temporary drop in
UI-performance, but in the end the code is distinctly simpler and also
more flexible.
Thus, for example the DivePhotoTab could be changed to support headings
without having to touch ProfileWidget2 at all.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divepicturemodel.cpp')
-rw-r--r-- | qt-models/divepicturemodel.cpp | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/qt-models/divepicturemodel.cpp b/qt-models/divepicturemodel.cpp index 5948f426c..f080138cf 100644 --- a/qt-models/divepicturemodel.cpp +++ b/qt-models/divepicturemodel.cpp @@ -14,10 +14,7 @@ DivePictureModel *DivePictureModel::instance() return self; } -DivePictureModel::DivePictureModel() : rowDDStart(0), - rowDDEnd(0), - zoomLevel(0.0), - defaultSize(Thumbnailer::defaultThumbnailSize()) +DivePictureModel::DivePictureModel() : zoomLevel(0.0) { connect(Thumbnailer::instance(), &Thumbnailer::thumbnailChanged, this, &DivePictureModel::updateThumbnail, Qt::QueuedConnection); @@ -44,7 +41,7 @@ void DivePictureModel::updateThumbnails() { updateZoom(); for (PictureEntry &entry: pictures) - entry.image = Thumbnailer::instance()->fetchThumbnail(entry); + entry.image = Thumbnailer::instance()->fetchThumbnail(entry.filename); } void DivePictureModel::updateDivePictures() @@ -52,7 +49,6 @@ void DivePictureModel::updateDivePictures() beginResetModel(); if (!pictures.isEmpty()) { pictures.clear(); - rowDDStart = rowDDEnd = 0; Thumbnailer::instance()->clearWorkQueue(); } @@ -60,12 +56,8 @@ void DivePictureModel::updateDivePictures() struct dive *dive; for_each_dive (i, dive) { if (dive->selected) { - if (dive->id == displayed_dive.id) - rowDDStart = pictures.count(); FOR_EACH_PICTURE(dive) pictures.push_back({picture, picture->filename, {}, picture->offset.seconds}); - if (dive->id == displayed_dive.id) - rowDDEnd = pictures.count(); } } @@ -93,9 +85,6 @@ QVariant DivePictureModel::data(const QModelIndex &index, int role) const case Qt::DecorationRole: ret = entry.image.scaled(size, size, Qt::KeepAspectRatio); break; - case Qt::UserRole: // Used by profile widget to access bigger thumbnails - ret = entry.image.scaled(defaultSize, defaultSize, Qt::KeepAspectRatio); - break; case Qt::DisplayRole: ret = QFileInfo(entry.filename).fileName(); break; @@ -126,14 +115,6 @@ static bool removePictureFromSelectedDive(const char *fileUrl) return false; } -// Calculate how many items of a range are before the given index -static int rangeBefore(int rangeFrom, int rangeTo, int index) -{ - if (rangeTo <= rangeFrom) - return 0; - return std::min(rangeTo, index) - std::min(rangeFrom, index); -} - void DivePictureModel::removePictures(const QVector<QString> &fileUrls) { bool removed = false; @@ -159,13 +140,8 @@ void DivePictureModel::removePictures(const QVector<QString> &fileUrls) beginRemoveRows(QModelIndex(), i, j - 1); pictures.erase(pictures.begin() + i, pictures.begin() + j); endRemoveRows(); - - // After removing pictures, we have to adjust rowDDStart and rowDDEnd. - // Calculate the part of the range that is before rowDDStart and rowDDEnd, - // respectively and subtract accordingly. - rowDDStart -= rangeBefore(i, j, rowDDStart); - rowDDEnd -= rangeBefore(i, j, rowDDEnd); } + emit picturesRemoved(fileUrls); } int DivePictureModel::rowCount(const QModelIndex&) const |