diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2015-01-07 15:40:10 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-01-07 12:33:12 -0800 |
commit | 11fc888cdc07708394f047097a1dd6510eb4bb09 (patch) | |
tree | bf0be8f7fab5f294574bd5a68f78c07f055bb634 /qt-ui/divelogimportdialog.cpp | |
parent | 3b654438b6774f27e05d9d8f35496166c2f155dc (diff) | |
download | subsurface-11fc888cdc07708394f047097a1dd6510eb4bb09.tar.gz |
Fix moving columns around when one of the columns is empty
I used to compare strings, but since there can be more than one empty
column, this was a very sad choice, now I'm comparing indexes.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelogimportdialog.cpp')
-rw-r--r-- | qt-ui/divelogimportdialog.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index 8eadc5b32..d8b1b6e8c 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -12,6 +12,7 @@ #include <QFile> static QString subsurface_mimedata = "subsurface/csvcolumns"; +static QString subsurface_index = "subsurface/csvindex"; const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = { // time, depth, temperature, po2, cns, ndl, tts, stopdepth, pressure @@ -182,8 +183,8 @@ void ColumnDropCSVView::dropEvent(QDropEvent *event) return; if (event->source() == this ) { - QString value_old = QString(mimeData->data(subsurface_mimedata)); - QString value_new = curr.data().toString(); + int value_old = mimeData->data(subsurface_index).toInt(); + int value_new = curr.column(); ColumnNameResult *m = qobject_cast<ColumnNameResult*>(model()); m->swapValues(value_old, value_new); event->acceptProposedAction(); @@ -202,10 +203,11 @@ 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); - setData(index(0, firstIndex), QVariant(other), Qt::EditRole); +void ColumnNameResult::swapValues(int firstIndex, int secondIndex) { + qDebug() << firstIndex << secondIndex; + QString one = columnNames[firstIndex]; + QString two = columnNames[secondIndex]; + setData(index(0, firstIndex), QVariant(two), Qt::EditRole); setData(index(0, secondIndex), QVariant(one), Qt::EditRole); } @@ -295,6 +297,7 @@ void ColumnDropCSVView::mousePressEvent(QMouseEvent *press) QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData; mimeData->setData(subsurface_mimedata, atClick.data().toByteArray()); + mimeData->setData(subsurface_index, QString::number(atClick.column()).toLocal8Bit()); drag->setPixmap(pix); drag->setMimeData(mimeData); if (drag->exec() != Qt::IgnoreAction){ |