mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: move picture removal from DivePictureItem to ProfileWidget2
On clicking the DivePictureItem "trash" icon, the item would delete the picture it represents in the currently displayed dive. This needed an access to the global "displayed_dive" variable, which we want to get rid of to make the profile more flexible. For example, we want to render the profile for printing without messing with global state. One solution would be to save the dive with every DivePictureItem. This commit follows a more Qt-ish strategy by handling this via signals: The close button emits a signal that is recast by the DivePictureItem and ultimately handled by the ProfileWidget2, which knows which dive it represents. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
636c932dfe
commit
fceb3691d9
4 changed files with 23 additions and 22 deletions
|
@ -2091,17 +2091,19 @@ void ProfileWidget2::updateThumbnail(QString filename, QImage thumbnail, duratio
|
|||
}
|
||||
|
||||
// Create a PictureEntry object and add its thumbnail to the scene if profile pictures are shown.
|
||||
ProfileWidget2::PictureEntry::PictureEntry(offset_t offsetIn, const QString &filenameIn, QGraphicsScene *scene, bool synchronous) : offset(offsetIn),
|
||||
ProfileWidget2::PictureEntry::PictureEntry(offset_t offsetIn, const QString &filenameIn, ProfileWidget2 *profile, bool synchronous) : offset(offsetIn),
|
||||
duration(duration_t {0}),
|
||||
filename(filenameIn),
|
||||
thumbnail(new DivePictureItem)
|
||||
{
|
||||
QGraphicsScene *scene = profile->scene();
|
||||
int size = Thumbnailer::defaultThumbnailSize();
|
||||
scene->addItem(thumbnail.get());
|
||||
thumbnail->setVisible(prefs.show_pictures_in_profile);
|
||||
QImage img = Thumbnailer::instance()->fetchThumbnail(filename, synchronous).scaled(size, size, Qt::KeepAspectRatio);
|
||||
thumbnail->setPixmap(QPixmap::fromImage(img));
|
||||
thumbnail->setFileUrl(filename);
|
||||
connect(thumbnail.get(), &DivePictureItem::removePicture, profile, &ProfileWidget2::removePicture);
|
||||
}
|
||||
|
||||
// Define a default sort order for picture-entries: sort lexicographically by timestamp and filename.
|
||||
|
@ -2181,7 +2183,7 @@ void ProfileWidget2::plotPicturesInternal(const struct dive *d, bool synchronous
|
|||
// Note that FOR_EACH_PICTURE handles d being null gracefully.
|
||||
FOR_EACH_PICTURE(d) {
|
||||
if (picture->offset.seconds > 0 && picture->offset.seconds <= d->duration.seconds)
|
||||
pictures.emplace_back(picture->offset, QString(picture->filename), scene(), synchronous);
|
||||
pictures.emplace_back(picture->offset, QString(picture->filename), this, synchronous);
|
||||
}
|
||||
if (pictures.empty())
|
||||
return;
|
||||
|
@ -2220,7 +2222,7 @@ void ProfileWidget2::picturesAdded(dive *d, QVector<PictureObj> pics)
|
|||
|
||||
for (const PictureObj &pic: pics) {
|
||||
if (pic.offset.seconds > 0 && pic.offset.seconds <= d->duration.seconds) {
|
||||
pictures.emplace_back(pic.offset, QString::fromStdString(pic.filename), scene(), false);
|
||||
pictures.emplace_back(pic.offset, QString::fromStdString(pic.filename), this, false);
|
||||
updateThumbnailXPos(pictures.back());
|
||||
}
|
||||
}
|
||||
|
@ -2232,6 +2234,13 @@ void ProfileWidget2::picturesAdded(dive *d, QVector<PictureObj> pics)
|
|||
calculatePictureYPositions();
|
||||
}
|
||||
|
||||
void ProfileWidget2::removePicture(const QString &fileUrl)
|
||||
{
|
||||
struct dive *d = get_dive_by_uniq_id(displayed_dive.id);
|
||||
if (d)
|
||||
Command::removePictures({ { d, { fileUrl.toStdString() } } });
|
||||
}
|
||||
|
||||
void ProfileWidget2::profileChanged(dive *d)
|
||||
{
|
||||
if (!d || d->id != displayed_dive.id)
|
||||
|
@ -2323,7 +2332,7 @@ void ProfileWidget2::pictureOffsetChanged(dive *d, QString filename, offset_t of
|
|||
// The parameters are passed directly to the contructor.
|
||||
// The call returns an iterator to the new element (which might differ from
|
||||
// the old iterator, since the buffer might have been reallocated).
|
||||
newPos = pictures.emplace(newPos, offset, filename, scene(), false);
|
||||
newPos = pictures.emplace(newPos, offset, filename, this, false);
|
||||
updateThumbnailXPos(*newPos);
|
||||
calculatePictureYPositions();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue