Skip to content

Commit

Permalink
Attribute editor (drag and drop layouter): Proper handling when multi…
Browse files Browse the repository at this point in the history
…ple fields are dropped
  • Loading branch information
m-kuhn committed Mar 28, 2013
1 parent 0005467 commit a3634e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 43 deletions.
62 changes: 21 additions & 41 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -113,30 +113,31 @@ bool QgsAttributesTree::dropMimeData( QTreeWidgetItem * parent, int index, const
{
QByteArray itemData = data->data( "application/x-qabstractitemmodeldatalist" );
QDataStream stream( &itemData, QIODevice::ReadOnly );
int r, c;
QMap<int, QVariant> roleDataMap;
stream >> r >> c >> roleDataMap;
int row, col;

QString itemType = roleDataMap.value( Qt::UserRole ).toString();
QString itemName = roleDataMap.value( Qt::DisplayRole ).toString();

if ( itemType == "field" ) //
while ( !stream.atEnd() )
{
if ( parent )
{
addItem( parent, itemName );
bDropSuccessful = true;
}
else // Should never happen as we ignore drops of fields onto the root element in dragMoveEvent, but actually does happen. Qt?
QMap<int, QVariant> roleDataMap;
stream >> row >> col >> roleDataMap;

if ( col == 1 )
{
// addItem( invisibleRootItem(), itemName );
// bDropSuccessful = true;
/* do something with the data */

QString itemName = roleDataMap.value( Qt::DisplayRole ).toString();

if ( parent )
{
addItem( parent, itemName );
bDropSuccessful = true;
}
else // Should never happen as we ignore drops of fields onto the root element in dragMoveEvent, but actually does happen. Qt?
{
// addItem( invisibleRootItem(), itemName );
// bDropSuccessful = true;
}
}
}
else
{
bDropSuccessful = QTreeWidget::dropMimeData( parent, index, data, Qt::MoveAction );
}
}

return bDropSuccessful;
Expand All @@ -150,30 +151,9 @@ void QgsAttributesTree::dropEvent( QDropEvent *event )
if ( event->source() == this )
{
event->setDropAction( Qt::MoveAction );
QTreeWidget::dropEvent( event );
}
else
{
// Qt::DropAction dropAction;
QByteArray itemData = event->mimeData()->data( "application/x-qabstractitemmodeldatalist" );
QDataStream stream( &itemData, QIODevice::ReadOnly );
int r, c, rDummy, cDummy;
QMap<int, QVariant> roleDataMap, newRoleDataMap, roleDataMapDummy;
stream >> rDummy >> cDummy >> roleDataMapDummy >> r >> c >> roleDataMap; // fieldName is in second column

QString fieldName = roleDataMap.value( Qt::DisplayRole ).toString();
newRoleDataMap.insert( Qt::UserRole , "field" );
newRoleDataMap.insert( Qt::DisplayRole , fieldName );

QMimeData * mimeData = new QMimeData();
QByteArray mdata;
QDataStream newStream( &mdata, QIODevice::WriteOnly );
newStream << r << c << newRoleDataMap;
mimeData->setData( QString( "application/x-qabstractitemmodeldatalist" ), mdata );
QDropEvent newEvent = QDropEvent( event->pos(), Qt::CopyAction , mimeData, event->mouseButtons(), event->keyboardModifiers() );

QTreeWidget::dropEvent( &newEvent );
}
QTreeWidget::dropEvent( event );
}

QgsFieldsProperties::QgsFieldsProperties( QgsVectorLayer *layer, QWidget* parent )
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsfieldsproperties.h
Expand Up @@ -34,8 +34,8 @@ class QgsAttributesList : public QTableWidget

protected:
// virtual void dragMoveEvent( QDragMoveEvent *event );
//QMimeData *mimeData( const QList<QTableWidgetItem *> items ) const;
//Qt::DropActions supportedDropActions() const;
// QMimeData *mimeData( const QList<QTableWidgetItem *> items ) const;
// Qt::DropActions supportedDropActions() const;
};

class QgsAttributesTree : public QTreeWidget
Expand Down

0 comments on commit a3634e2

Please sign in to comment.