Fix moving columns

Qt has a very bad habit of getting the inner widget instead of the outer
one.

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 23:20:54 -02:00 committed by Dirk Hohndel
parent 6746b73d85
commit a96e0e1ec1

View file

@ -175,7 +175,6 @@ void ColumnDropCSVView::dropEvent(QDropEvent *event)
ColumnNameResult *m = qobject_cast<ColumnNameResult*>(model()); ColumnNameResult *m = qobject_cast<ColumnNameResult*>(model());
m->swapValues(value_old, value_new); m->swapValues(value_old, value_new);
} }
} }
} }
@ -187,15 +186,15 @@ ColumnNameResult::ColumnNameResult(QObject *parent) : QAbstractTableModel(parent
void ColumnNameResult::swapValues(const QString &one, const QString &other) { void ColumnNameResult::swapValues(const QString &one, const QString &other) {
int firstIndex = columnNames.indexOf(one); int firstIndex = columnNames.indexOf(one);
int secondIndex = columnNames.indexOf(other); int secondIndex = columnNames.indexOf(other);
columnNames[firstIndex] = other; setData(index(0, firstIndex), QVariant(other), Qt::EditRole);
columnNames[secondIndex] = one; setData(index(0, secondIndex), QVariant(one), Qt::EditRole);
dataChanged(index(0,0), index(0, columnCount()-1));
} }
bool ColumnNameResult::setData(const QModelIndex &index, const QVariant &value, int role) bool ColumnNameResult::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
if (!index.isValid() || index.row() != 0) if (!index.isValid() || index.row() != 0) {
return false; return false;
}
if (role == Qt::EditRole) { if (role == Qt::EditRole) {
columnNames[index.column()] = value.toString(); columnNames[index.column()] = value.toString();
dataChanged(index, index); dataChanged(index, index);
@ -275,7 +274,12 @@ void ColumnDropCSVView::mousePressEvent(QMouseEvent *press)
drag->setPixmap(pix); drag->setPixmap(pix);
drag->setMimeData(mimeData); drag->setMimeData(mimeData);
if (drag->exec() != Qt::IgnoreAction){ if (drag->exec() != Qt::IgnoreAction){
if (drag->target() != drag->source()) { QObject *target = drag->target();
if (target->objectName() == "qt_scrollarea_viewport")
target = target->parent();
if (target != drag->source()) {
model()->setData(atClick, QString()); model()->setData(atClick, QString());
} }
} }