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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-05-01 12:35:18 +02:00 committed by Dirk Hohndel
parent d33e3b22fc
commit c71a5d7413
3 changed files with 25 additions and 7 deletions

View file

@ -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));
}
}