From 1ba08e2fec619b105cb0d3d0718758bdcc9c7d87 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 6 Jan 2015 22:24:46 -0200 Subject: [PATCH] Make it possible to move from top to bottom Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/divelogimportdialog.cpp | 31 +++++++++++++++++++++++++++++++ qt-ui/divelogimportdialog.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index 632659cd2..7d165b892 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -103,6 +103,37 @@ void ColumnNameView::mousePressEvent(QMouseEvent *press) } } +void ColumnNameView::dragLeaveEvent(QDragLeaveEvent *leave) +{ + Q_UNUSED(leave); +} + +void ColumnNameView::dragEnterEvent(QDragEnterEvent *event) +{ + event->acceptProposedAction(); +} + +void ColumnNameView::dragMoveEvent(QDragMoveEvent *event) +{ + QModelIndex curr = indexAt(event->pos()); + if (!curr.isValid() || curr.row() != 0) + return; + event->acceptProposedAction(); +} + +void ColumnNameView::dropEvent(QDropEvent *event) +{ + const QMimeData *mimeData = event->mimeData(); + if (mimeData->data(subsurface_mimedata).count()) { + if (event->source() != this) { + event->acceptProposedAction(); + QVariant value = QString(mimeData->data(subsurface_mimedata)); + model()->insertRow(model()->rowCount()); + model()->setData(model()->index(model()->rowCount()-1, 0), value); + } + } +} + ColumnDropCSVView::ColumnDropCSVView(QWidget *parent) { setAcceptDrops(true); diff --git a/qt-ui/divelogimportdialog.h b/qt-ui/divelogimportdialog.h index 29ceedf7d..7e43434cd 100644 --- a/qt-ui/divelogimportdialog.h +++ b/qt-ui/divelogimportdialog.h @@ -50,6 +50,10 @@ public: ColumnNameView(QWidget *parent); protected: void mousePressEvent(QMouseEvent *press); + void dragLeaveEvent(QDragLeaveEvent *leave); + void dragEnterEvent(QDragEnterEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); private: int currentDraggedIndex; };