Dive media: transport dive-id in drag'n'drop events

9efb56e2d4 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>
This commit is contained in:
Berthold Stoeger 2018-07-14 17:40:24 +02:00 committed by Dirk Hohndel
parent 8ff7314b21
commit c5f66c5538
3 changed files with 29 additions and 34 deletions

View file

@ -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)