mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dive pictures: don't repopulate DivePictureModel on deletion
On deletion of a single or multiple pictures, the whole DivePictureModel was repopulated, which was clearly visible in the UI, owing to the reconstructing of all images in the profile plot. To avoid this vexing behavior, implement proper deletion routines in DivePictureModel and ProfileWidget2. Since this needs sensible erase() semantics the QList<PictureEntry> member of DivePictureModel was replaced by a QVector. A QVector should be the default anyway, unless there are very specific reasons to use a QList (which actually is a deque, not a classical linked list). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
3c0c1801cd
commit
f47f2773fd
4 changed files with 32 additions and 3 deletions
|
@ -1118,7 +1118,7 @@ void ProfileWidget2::setProfileState()
|
||||||
#ifndef SUBSURFACE_MOBILE
|
#ifndef SUBSURFACE_MOBILE
|
||||||
connect(DivePictureModel::instance(), &DivePictureModel::dataChanged, this, &ProfileWidget2::updatePictures);
|
connect(DivePictureModel::instance(), &DivePictureModel::dataChanged, this, &ProfileWidget2::updatePictures);
|
||||||
connect(DivePictureModel::instance(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(plotPictures()));
|
connect(DivePictureModel::instance(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(plotPictures()));
|
||||||
connect(DivePictureModel::instance(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(plotPictures()));
|
connect(DivePictureModel::instance(), &DivePictureModel::rowsRemoved, this, &ProfileWidget2::removePictures);
|
||||||
connect(DivePictureModel::instance(), &DivePictureModel::modelReset, this, &ProfileWidget2::plotPictures);
|
connect(DivePictureModel::instance(), &DivePictureModel::modelReset, this, &ProfileWidget2::plotPictures);
|
||||||
#endif
|
#endif
|
||||||
/* show the same stuff that the profile shows. */
|
/* show the same stuff that the profile shows. */
|
||||||
|
@ -2089,6 +2089,19 @@ void ProfileWidget2::plotPictures()
|
||||||
item->setPos(x, y);
|
item->setPos(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProfileWidget2::removePictures(const QModelIndex &, int first, int last)
|
||||||
|
{
|
||||||
|
DivePictureModel *m = DivePictureModel::instance();
|
||||||
|
first = std::max(0, first - m->rowDDStart);
|
||||||
|
// Note that last points *to* the last item and not *past* the last item,
|
||||||
|
// therefore we add 1 to achieve conventional C++ semantics.
|
||||||
|
last = std::min((int)pictures.size(), last + 1 - m->rowDDStart);
|
||||||
|
if (first >= (int)pictures.size() || last <= first)
|
||||||
|
return;
|
||||||
|
pictures.erase(pictures.begin() + first, pictures.begin() + last);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ProfileWidget2::dropEvent(QDropEvent *event)
|
void ProfileWidget2::dropEvent(QDropEvent *event)
|
||||||
|
|
|
@ -110,6 +110,7 @@ slots: // Necessary to call from QAction's signals.
|
||||||
void replot(dive *d = 0);
|
void replot(dive *d = 0);
|
||||||
#ifndef SUBSURFACE_MOBILE
|
#ifndef SUBSURFACE_MOBILE
|
||||||
void plotPictures();
|
void plotPictures();
|
||||||
|
void removePictures(const QModelIndex &, int first, int last);
|
||||||
void setPlanState();
|
void setPlanState();
|
||||||
void setAddState();
|
void setAddState();
|
||||||
void changeGas();
|
void changeGas();
|
||||||
|
|
|
@ -149,7 +149,22 @@ void DivePictureModel::removePictures(const QVector<QString> &fileUrls)
|
||||||
copy_dive(current_dive, &displayed_dive);
|
copy_dive(current_dive, &displayed_dive);
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
|
|
||||||
updateDivePictures();
|
for (int i = 0; i < pictures.size(); ++i) {
|
||||||
|
// Find range [i j) of pictures to remove
|
||||||
|
if (std::find(fileUrls.begin(), fileUrls.end(), pictures[i].filename) == fileUrls.end())
|
||||||
|
continue;
|
||||||
|
int j;
|
||||||
|
for (j = i + 1; j < pictures.size(); ++j) {
|
||||||
|
if (std::find(fileUrls.begin(), fileUrls.end(), pictures[j].filename) == fileUrls.end())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Qt's model-interface is surprisingly idiosyncratic: you don't pass [first last), but [first last] ranges.
|
||||||
|
// For example, an empty list would be [0 -1].
|
||||||
|
beginRemoveRows(QModelIndex(), i, j - 1);
|
||||||
|
pictures.erase(pictures.begin() + i, pictures.begin() + j);
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int DivePictureModel::rowCount(const QModelIndex &parent) const
|
int DivePictureModel::rowCount(const QModelIndex &parent) const
|
||||||
|
|
|
@ -30,7 +30,7 @@ public slots:
|
||||||
void updateThumbnail(QString filename, QImage thumbnail);
|
void updateThumbnail(QString filename, QImage thumbnail);
|
||||||
private:
|
private:
|
||||||
DivePictureModel();
|
DivePictureModel();
|
||||||
QList<PictureEntry> pictures;
|
QVector<PictureEntry> pictures;
|
||||||
int findPictureId(const QString &filename); // Return -1 if not found
|
int findPictureId(const QString &filename); // Return -1 if not found
|
||||||
double zoomLevel; // -1.0: minimum, 0.0: standard, 1.0: maximum
|
double zoomLevel; // -1.0: minimum, 0.0: standard, 1.0: maximum
|
||||||
int size;
|
int size;
|
||||||
|
|
Loading…
Add table
Reference in a new issue