summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-07-29 23:03:32 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-30 12:52:31 -0700
commit3b9bceacb6efcd3e97c95077a2295c931c834514 (patch)
treec40ae2d7529f5fd6aab9d9041c785202fe0c61a0
parent1e6986d87010a636d151f77b3da2a40d52a95178 (diff)
downloadsubsurface-3b9bceacb6efcd3e97c95077a2295c931c834514.tar.gz
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>
-rw-r--r--dive.c17
-rw-r--r--dive.h2
-rw-r--r--qt-ui/divepicturewidget.cpp10
-rw-r--r--qt-ui/divepicturewidget.h1
-rw-r--r--qt-ui/profile/divepixmapitem.cpp4
-rw-r--r--qt-ui/profile/profilewidget2.cpp6
6 files changed, 32 insertions, 8 deletions
diff --git a/dive.c b/dive.c
index 139afe23e..dd847c261 100644
--- a/dive.c
+++ b/dive.c
@@ -2489,9 +2489,22 @@ void dive_set_geodata_from_picture(struct dive *d, struct picture *pic)
}
}
-void dive_remove_picture(struct dive *d, struct picture *p)
+static void picture_free( struct picture *p){
+ if (!p)
+ return;
+ free( p->filename );
+ free( p );
+}
+void dive_remove_picture(struct picture *p)
{
-
+ struct picture **ep = &current_dive->picture_list;
+ while (ep && !same_string((*ep)->filename, p->filename))
+ ep = &(*ep)->next;
+ if (ep) {
+ struct picture *temp = (*ep)->next;
+ picture_free(*ep);
+ *ep = temp;
+ }
}
/* this always acts on the current divecomputer of the current dive */
diff --git a/dive.h b/dive.h
index 204cb2fee..0bffeb69e 100644
--- a/dive.h
+++ b/dive.h
@@ -311,7 +311,7 @@ struct picture {
extern struct picture *alloc_picture();
extern void dive_create_picture(struct dive *d, char *filename, int shift_time);
extern void dive_add_picture(struct dive *d, struct picture *newpic);
-extern void dive_remove_picture(struct dive *d, struct picture *pic);
+extern void dive_remove_picture(struct picture *pic);
extern unsigned int dive_get_picture_count(struct dive *d);
extern void picture_load_exif_data(struct picture *p, timestamp_t *timestamp);
extern void dive_set_geodata_from_picture(struct dive *d, struct picture *pic);
diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp
index fd64f613a..76d3e7c65 100644
--- a/qt-ui/divepicturewidget.cpp
+++ b/qt-ui/divepicturewidget.cpp
@@ -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;
diff --git a/qt-ui/divepicturewidget.h b/qt-ui/divepicturewidget.h
index a0fd2693a..6f53bee09 100644
--- a/qt-ui/divepicturewidget.h
+++ b/qt-ui/divepicturewidget.h
@@ -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();
diff --git a/qt-ui/profile/divepixmapitem.cpp b/qt-ui/profile/divepixmapitem.cpp
index 3fb06adb9..41541c21e 100644
--- a/qt-ui/profile/divepixmapitem.cpp
+++ b/qt-ui/profile/divepixmapitem.cpp
@@ -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);
}
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 21f0cb4e4..8f0d1584f 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -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);