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>
This commit is contained in:
Tomaz Canabrava 2015-01-06 22:12:05 -02:00 committed by Dirk Hohndel
parent fd41ff4ab9
commit 59fc5cecb7
2 changed files with 19 additions and 3 deletions

View file

@ -135,8 +135,16 @@ void ColumnDropCSVView::dropEvent(QDropEvent *event)
event->acceptProposedAction();
const QMimeData *mimeData = event->mimeData();
if (mimeData->data(subsurface_mimedata).count()) {
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.
}
}

View file

@ -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;