this was needed to remove the pictures that are not on the trip.
From 3096f7d76c5abd81d0429ba372e1386e9a41f231 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <tomaz.canabr...@intel.com> Date: Wed, 6 Aug 2014 18:05:54 -0300 Subject: [PATCH] Delete pictures from the Widget by pressing delete
Select the picture, press delete, profit. Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com> --- qt-ui/maintab.cpp | 17 +++++++++++++++++ qt-ui/maintab.h | 2 +- qt-ui/modeldelegates.cpp | 3 ++- qt-ui/profile/divepixmapitem.cpp | 7 +++++-- qt-ui/profile/divepixmapitem.h | 1 + 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index ed65a19..d49c884 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -167,6 +167,13 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui.cylinders->view()->setColumnHidden(i, checked); ui.cylinders->view()->horizontalHeader()->addAction(action); } + + QAction *deletePhoto = new QAction(this); + deletePhoto->setShortcut(Qt::Key_Delete); + deletePhoto->setShortcutContext(Qt::WidgetShortcut); + ui.photosView->addAction(deletePhoto); + ui.photosView->setSelectionMode(QAbstractItemView::SingleSelection); + connect(deletePhoto, SIGNAL(triggered(bool)), this, SLOT(removeSelectedPhotos())); } MainTab::~MainTab() @@ -1153,3 +1160,13 @@ void MainTab::photoDoubleClicked(const QString filePath) { QDesktopServices::openUrl(QUrl::fromLocalFile(filePath)); } + +void MainTab::removeSelectedPhotos() +{ + if (!ui.photosView->selectionModel()->hasSelection()) + return; + + QModelIndex photoIndex = ui.photosView->selectionModel()->selectedIndexes().first(); + QString fileUrl = photoIndex.data(Qt::DisplayPropertyRole).toString(); + DivePictureModel::instance()->removePicture(fileUrl); +} diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 20a72d0..f3aec54 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -86,7 +86,7 @@ slots: void updateTextLabels(bool showUnits = true); void escDetected(void); void photoDoubleClicked(const QString filePath); - + void removeSelectedPhotos(); private: Ui::MainTab ui; WeightModel *weightModel; diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 87846d2..019f19b 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -63,8 +63,9 @@ QSize StarWidgetsDelegate::sizeHint(const QStyleOptionViewItem &option, const QM return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS - 1), IMG_SIZE); } -ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject *parent) : QStyledItemDelegate(parent), model(model) +ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject *parent) : QStyledItemDelegate(parent) { + model = new QSortFilterProxyModel(); connect(this, SIGNAL(closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint)), this, SLOT(revertModelData(QWidget *, QAbstractItemDelegate::EndEditHint))); connect(this, SIGNAL(closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint)), diff --git a/qt-ui/profile/divepixmapitem.cpp b/qt-ui/profile/divepixmapitem.cpp index 853b950..a73473a 100644 --- a/qt-ui/profile/divepixmapitem.cpp +++ b/qt-ui/profile/divepixmapitem.cpp @@ -114,6 +114,11 @@ void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) button->hide(); } +DivePictureItem::~DivePictureItem(){ + if(button) + Animations::hide(button); +} + void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { QDesktopServices::openUrl(QUrl::fromLocalFile(fileUrl)); @@ -121,7 +126,5 @@ void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void DivePictureItem::removePicture() { - Animations::hide(button); - hide(); DivePictureModel::instance()->removePicture(fileUrl); } diff --git a/qt-ui/profile/divepixmapitem.h b/qt-ui/profile/divepixmapitem.h index d39f26d..963e641 100644 --- a/qt-ui/profile/divepixmapitem.h +++ b/qt-ui/profile/divepixmapitem.h @@ -19,6 +19,7 @@ class DivePictureItem : public DivePixmapItem { Q_PROPERTY(qreal scale WRITE setScale READ scale) public: DivePictureItem(QObject *parent = 0); + virtual ~DivePictureItem(); void setPixmap(const QPixmap& pix); public slots: void settingsChanged(); -- 2.0.4
_______________________________________________ subsurface mailing list subsurface@hohndel.org http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface