diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index 963c75710..632659cd2 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -135,8 +135,16 @@ void ColumnDropCSVView::dropEvent(QDropEvent *event) event->acceptProposedAction(); const QMimeData *mimeData = event->mimeData(); if (mimeData->data(subsurface_mimedata).count()) { - QVariant value = QString(mimeData->data(subsurface_mimedata)); - model()->setData(curr, value); + if (event->source() != this) { + QVariant value = QString(mimeData->data(subsurface_mimedata)); + model()->setData(curr, value); + } else { + QString value_old = QString(mimeData->data(subsurface_mimedata)); + QString value_new = curr.data().toString(); + ColumnNameResult *m = qobject_cast(model()); + m->swapValues(value_old, value_new); + } + } } @@ -145,6 +153,14 @@ ColumnNameResult::ColumnNameResult(QObject *parent) : QAbstractTableModel(parent } +void ColumnNameResult::swapValues(const QString &one, const QString &other) { + int firstIndex = columnNames.indexOf(one); + int secondIndex = columnNames.indexOf(other); + columnNames[firstIndex] = other; + columnNames[secondIndex] = one; + dataChanged(index(0,0), index(0, columnCount()-1)); +} + bool ColumnNameResult::setData(const QModelIndex &index, const QVariant &value, int role) { if (!index.isValid() || index.row() != 0) @@ -228,7 +244,6 @@ void ColumnDropCSVView::mousePressEvent(QMouseEvent *press) drag->setPixmap(pix); drag->setMimeData(mimeData); if (drag->exec() != Qt::IgnoreAction){ - // Do stuff here. } } diff --git a/qt-ui/divelogimportdialog.h b/qt-ui/divelogimportdialog.h index 0043f3ff2..29ceedf7d 100644 --- a/qt-ui/divelogimportdialog.h +++ b/qt-ui/divelogimportdialog.h @@ -38,6 +38,7 @@ public: int columnCount(const QModelIndex &parent = QModelIndex()) const; void setColumnValues(QList columns); QStringList result() const; + void swapValues(const QString& one, const QString& other); private: QList columnValues; QStringList columnNames;