mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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>
This commit is contained in:
parent
3b654438b6
commit
11fc888cdc
2 changed files with 10 additions and 7 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
static QString subsurface_mimedata = "subsurface/csvcolumns";
|
static QString subsurface_mimedata = "subsurface/csvcolumns";
|
||||||
|
static QString subsurface_index = "subsurface/csvindex";
|
||||||
|
|
||||||
const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = {
|
const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = {
|
||||||
// time, depth, temperature, po2, cns, ndl, tts, stopdepth, pressure
|
// time, depth, temperature, po2, cns, ndl, tts, stopdepth, pressure
|
||||||
|
@ -182,8 +183,8 @@ void ColumnDropCSVView::dropEvent(QDropEvent *event)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event->source() == this ) {
|
if (event->source() == this ) {
|
||||||
QString value_old = QString(mimeData->data(subsurface_mimedata));
|
int value_old = mimeData->data(subsurface_index).toInt();
|
||||||
QString value_new = curr.data().toString();
|
int value_new = curr.column();
|
||||||
ColumnNameResult *m = qobject_cast<ColumnNameResult*>(model());
|
ColumnNameResult *m = qobject_cast<ColumnNameResult*>(model());
|
||||||
m->swapValues(value_old, value_new);
|
m->swapValues(value_old, value_new);
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
|
@ -202,10 +203,11 @@ ColumnNameResult::ColumnNameResult(QObject *parent) : QAbstractTableModel(parent
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColumnNameResult::swapValues(const QString &one, const QString &other) {
|
void ColumnNameResult::swapValues(int firstIndex, int secondIndex) {
|
||||||
int firstIndex = columnNames.indexOf(one);
|
qDebug() << firstIndex << secondIndex;
|
||||||
int secondIndex = columnNames.indexOf(other);
|
QString one = columnNames[firstIndex];
|
||||||
setData(index(0, firstIndex), QVariant(other), Qt::EditRole);
|
QString two = columnNames[secondIndex];
|
||||||
|
setData(index(0, firstIndex), QVariant(two), Qt::EditRole);
|
||||||
setData(index(0, secondIndex), QVariant(one), Qt::EditRole);
|
setData(index(0, secondIndex), QVariant(one), Qt::EditRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,6 +297,7 @@ void ColumnDropCSVView::mousePressEvent(QMouseEvent *press)
|
||||||
QDrag *drag = new QDrag(this);
|
QDrag *drag = new QDrag(this);
|
||||||
QMimeData *mimeData = new QMimeData;
|
QMimeData *mimeData = new QMimeData;
|
||||||
mimeData->setData(subsurface_mimedata, atClick.data().toByteArray());
|
mimeData->setData(subsurface_mimedata, atClick.data().toByteArray());
|
||||||
|
mimeData->setData(subsurface_index, QString::number(atClick.column()).toLocal8Bit());
|
||||||
drag->setPixmap(pix);
|
drag->setPixmap(pix);
|
||||||
drag->setMimeData(mimeData);
|
drag->setMimeData(mimeData);
|
||||||
if (drag->exec() != Qt::IgnoreAction){
|
if (drag->exec() != Qt::IgnoreAction){
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
void setColumnValues(QList<QStringList> columns);
|
void setColumnValues(QList<QStringList> columns);
|
||||||
QStringList result() const;
|
QStringList result() const;
|
||||||
void swapValues(const QString& one, const QString& other);
|
void swapValues(int firstIndex, int secondIndex);
|
||||||
private:
|
private:
|
||||||
QList<QStringList> columnValues;
|
QList<QStringList> columnValues;
|
||||||
QStringList columnNames;
|
QStringList columnNames;
|
||||||
|
|
Loading…
Reference in a new issue