From f48065ac3c0c1f2dfdba099f6637df9c778756ab Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 6 Jan 2015 17:32:29 -0200 Subject: Do not accept drops from outside of subsurface Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/divelogimportdialog.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index 539238560..16c713989 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -11,6 +11,8 @@ #include #include +static QString subsurface_mimedata = "subsurface/csvcolumns"; + const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = { // time, depth, temperature, po2, cns, ndl, tts, stopdepth, pressure { "", }, @@ -88,14 +90,14 @@ void ColumnNameView::mousePressEvent(QMouseEvent *press) QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData; - mimeData->setText(atClick.data().toString()); + mimeData->setData(subsurface_mimedata, atClick.data().toByteArray()); model()->removeRow(atClick.row()); drag->setPixmap(pix); drag->setMimeData(mimeData); if (drag->exec() == Qt::IgnoreAction){ model()->insertRow(model()->rowCount()); QModelIndex idx = model()->index(model()->rowCount()-1, 0); - model()->setData(idx, mimeData->text()); + model()->setData(idx, mimeData->data(subsurface_mimedata)); } } @@ -105,20 +107,23 @@ void ColumnNameView::dragLeaveEvent(QDragLeaveEvent *leave) void ColumnNameView::dragEnterEvent(QDragEnterEvent *event) { - event->acceptProposedAction(); + if(event->mimeData()->data(subsurface_mimedata).count()) + event->acceptProposedAction(); } void ColumnNameView::dragMoveEvent(QDragMoveEvent *event) { - event->acceptProposedAction(); + if (event->mimeData()->data(subsurface_mimedata).count()) + event->acceptProposedAction(); } void ColumnNameView::dropEvent(QDropEvent *event) { const QMimeData *mimeData = event->mimeData(); - if (mimeData->hasText()) { + if (mimeData->data(subsurface_mimedata).count()) { + QVariant value = QString(mimeData->data(subsurface_mimedata)); model()->insertRow(model()->rowCount()); - model()->setData(model()->index(model()->rowCount()-1, 0), QVariant(mimeData->text())); + model()->setData(model()->index(model()->rowCount()-1, 0), value); } } @@ -153,8 +158,9 @@ void ColumnDropCSVView::dropEvent(QDropEvent *event) event->acceptProposedAction(); const QMimeData *mimeData = event->mimeData(); - if (mimeData->hasText()) { - model()->setData(curr, QVariant(mimeData->text())); + if (mimeData->data(subsurface_mimedata).count()) { + QVariant value = QString(mimeData->data(subsurface_mimedata)); + model()->setData(curr, value); } } -- cgit v1.2.3-70-g09d2