Implement the functionality of remove_picture.

Added the remove_picture functionality, with code
shamelessy stolen from remove_event, and hoock it
up with the interface.

Fixes #650

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-07-29 23:03:32 -03:00 committed by Dirk Hohndel
parent 1e6986d870
commit 3b9bceacb6
6 changed files with 32 additions and 8 deletions

View file

@ -89,11 +89,21 @@ QVariant DivePictureModel::data(const QModelIndex &index, int role) const
switch (role) {
case Qt::UserRole:
ret = QVariant::fromValue((void *)stringPixmapCache[key].picture);
break;
case Qt::DisplayRole:
ret = key;
}
}
return ret;
}
void DivePictureModel::removePicture(const QString &fileUrl)
{
dive_remove_picture(stringPixmapCache[fileUrl].picture);
copy_dive(current_dive, &displayed_dive);
updateDivePictures();
}
int DivePictureModel::rowCount(const QModelIndex &parent) const
{
return numberOfPictures;

View file

@ -19,6 +19,7 @@ public:
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
void updateDivePictures();
void removePicture(const QString& fileUrl);
private:
DivePictureModel();

View file

@ -119,9 +119,7 @@ void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
void DivePictureItem::removePicture()
{
/* this is a WIP, it doesn't really *removes* anything, merely hides it.
* good workaround, I still need to figure out how to activelly remove
* it from the model. */
button->hide();
hide();
DivePictureModel::instance()->removePicture(fileUrl);
}

View file

@ -1352,7 +1352,9 @@ void ProfileWidget2::keyEscAction()
void ProfileWidget2::plotPictures()
{
qDeleteAll(pictures);
Q_FOREACH(DivePictureItem *item, pictures){
item->deleteLater();
}
pictures.clear();
if (printMode)
@ -1368,7 +1370,7 @@ void ProfileWidget2::plotPictures()
continue;
DivePictureItem *item = new DivePictureItem();
item->setPixmap(m->index(i,0).data(Qt::DecorationRole).value<QPixmap>());
item->setFileUrl(m->index(i,0).data(Qt::DisplayPropertyRole).toString());
item->setFileUrl(m->index(i,1).data().toString());
// let's put the picture at the correct time, but at a fixed "depth" on the profile
// not sure this is ideal, but it seems to look right.
x = timeAxis->posAtValue(pic->offset.seconds);