mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
media: store dive instead of dive-id in DivePictureModel
dive-pointers are stable and the dive picture model is reset if a selected dive is removed, so there is no risk in keeping pointers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0d06eb83d8
commit
bd960ea088
2 changed files with 6 additions and 6 deletions
|
@ -63,10 +63,10 @@ void DivePictureModel::updateDivePictures()
|
|||
if (dive->selected) {
|
||||
int first = pictures.count();
|
||||
FOR_EACH_PICTURE(dive)
|
||||
pictures.push_back({ dive->id, picture->filename, {}, picture->offset.seconds, {.seconds = 0}});
|
||||
pictures.push_back({ dive, picture->filename, {}, picture->offset.seconds, {.seconds = 0}});
|
||||
|
||||
// Sort pictures of this dive by offset.
|
||||
// Thus, the list will be sorted by (diveId, offset).
|
||||
// Thus, the list will be sorted by (dive, offset).
|
||||
std::sort(pictures.begin() + first, pictures.end(),
|
||||
[](const PictureEntry &a, const PictureEntry &b) { return a.offsetSeconds < b.offsetSeconds; });
|
||||
}
|
||||
|
@ -218,8 +218,8 @@ void DivePictureModel::pictureOffsetChanged(dive *d, const QString filenameIn, o
|
|||
std::string filename = filenameIn.toStdString();
|
||||
|
||||
// Find the pictures of the given dive.
|
||||
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; });
|
||||
auto from = std::find_if(pictures.begin(), pictures.end(), [d](const PictureEntry &e) { return e.d == d; });
|
||||
auto to = std::find_if(from, pictures.end(), [d](const PictureEntry &e) { return e.d != d; });
|
||||
|
||||
// Find picture with the given filename
|
||||
auto oldPos = std::find_if(from, to, [filename](const PictureEntry &e) { return e.filename == filename; });
|
||||
|
|
|
@ -10,15 +10,15 @@
|
|||
|
||||
// We use std::string instead of QString to use the same character-encoding
|
||||
// as in the C core (UTF-8). This is crucial to guarantee the same sort-order.
|
||||
struct dive;
|
||||
struct PictureEntry {
|
||||
int diveId;
|
||||
dive *d;
|
||||
std::string filename;
|
||||
QImage image;
|
||||
int offsetSeconds;
|
||||
duration_t length;
|
||||
};
|
||||
|
||||
struct dive;
|
||||
class DivePictureModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue