Skip to content
Permalink
Browse files

Attribute editor (drag and drop layouter): Proper handling when multi…

…ple fields are dropped
  • Loading branch information
m-kuhn committed Mar 28, 2013
1 parent 0005467 commit a3634e24b21188488b116563c8fd4763e1a2b134
Showing with 23 additions and 43 deletions.
  1. +21 −41 src/app/qgsfieldsproperties.cpp
  2. +2 −2 src/app/qgsfieldsproperties.h
@@ -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;
@@ -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 )
@@ -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

0 comments on commit a3634e2

Please sign in to comment.
You can’t perform that action at this time.