diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2015-01-06 22:12:05 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-01-06 19:38:38 -0800 |
commit | 59fc5cecb71ebf2edcca2cc7818b92bc621c2620 (patch) | |
tree | b4ea608c299fcfd6bb0cdccf1a8a9623266658c1 | |
parent | fd41ff4ab91d95c1ad505ca5b53697963fdf14b2 (diff) | |
download | subsurface-59fc5cecb71ebf2edcca2cc7818b92bc621c2620.tar.gz |
Add the code to actually make it possible to move columns
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/divelogimportdialog.cpp | 21 | ||||
-rw-r--r-- | qt-ui/divelogimportdialog.h | 1 |
2 files changed, 19 insertions, 3 deletions
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<ColumnNameResult*>(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<QStringList> columns); QStringList result() const; + void swapValues(const QString& one, const QString& other); private: QList<QStringList> columnValues; QStringList columnNames; |