summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/divepicturewidget.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-14 17:40:24 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-18 09:06:37 -0700
commitc5f66c5538d149aaab92316096070fcb01cf8f1b (patch)
treeddc208dac40450a9c7791ca8218d9772c3ea450d /desktop-widgets/divepicturewidget.cpp
parent8ff7314b219d2eab85f7777e470091a76cf25107 (diff)
downloadsubsurface-c5f66c5538d149aaab92316096070fcb01cf8f1b.tar.gz
Dive media: transport dive-id in drag'n'drop events
9efb56e2d43161d952efb444d1f13d87bfdd45b5 introduced rather complex logic for picture drag'n'drop events onto the profile. Among other things, the code had to check whether the picture actually belongs to the displayed dive. This can be simplified by transporting the dive-id in the drag'n'drop event structure. The flow goes like this: DivePictureModel--(1)-->DivePictureWidget--(2)-->ProfileWidget For (1), we can use the Qt::UserRole role. This was used to transport the picture-offset, but this is not needed anymore since ProfileWidget was decoupled from DivePictureModel. For (2), we simply replace the "position" value, which was never used. Why would the receiver care which pixel was pressed in the media-tab? This commit also contains a minor cleanup in DivePictureWidget: QListView::mousePressEvent(event) was called in both branches of an if and can therefore be removed from the if. This is so trivial, that it doesn't warrant its own commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/divepicturewidget.cpp')
-rw-r--r--desktop-widgets/divepicturewidget.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/desktop-widgets/divepicturewidget.cpp b/desktop-widgets/divepicturewidget.cpp
index 46de16d09..bc692fd9f 100644
--- a/desktop-widgets/divepicturewidget.cpp
+++ b/desktop-widgets/divepicturewidget.cpp
@@ -32,7 +32,9 @@ void DivePictureWidget::mouseDoubleClickEvent(QMouseEvent *event)
void DivePictureWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && event->modifiers() == Qt::NoModifier) {
- QString filename = model()->data(indexAt(event->pos()), Qt::DisplayPropertyRole).toString();
+ QModelIndex index = indexAt(event->pos());
+ QString filename = model()->data(index, Qt::DisplayPropertyRole).toString();
+ int diveId = model()->data(index, Qt::UserRole).toInt();
if (!filename.isEmpty()) {
int dim = lrint(defaultIconMetrics().sz_pic * 0.2);
@@ -42,7 +44,7 @@ void DivePictureWidget::mousePressEvent(QMouseEvent *event)
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
- dataStream << filename << event->pos();
+ dataStream << filename << diveId;
QMimeData *mimeData = new QMimeData;
mimeData->setData("application/x-subsurfaceimagedrop", itemData);
@@ -53,11 +55,8 @@ void DivePictureWidget::mousePressEvent(QMouseEvent *event)
drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
}
-
- QListView::mousePressEvent(event);
- } else {
- QListView::mousePressEvent(event);
}
+ QListView::mousePressEvent(event);
}
void DivePictureWidget::wheelEvent(QWheelEvent *event)