Skip to content

Commit a3634e2

Browse files
committed
Attribute editor (drag and drop layouter): Proper handling when multiple fields are dropped
1 parent 0005467 commit a3634e2

File tree

2 files changed

+23
-43
lines changed

2 files changed

+23
-43
lines changed

src/app/qgsfieldsproperties.cpp

+21-41
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,31 @@ bool QgsAttributesTree::dropMimeData( QTreeWidgetItem * parent, int index, const
113113
{
114114
QByteArray itemData = data->data( "application/x-qabstractitemmodeldatalist" );
115115
QDataStream stream( &itemData, QIODevice::ReadOnly );
116-
int r, c;
117-
QMap<int, QVariant> roleDataMap;
118-
stream >> r >> c >> roleDataMap;
116+
int row, col;
119117

120-
QString itemType = roleDataMap.value( Qt::UserRole ).toString();
121-
QString itemName = roleDataMap.value( Qt::DisplayRole ).toString();
122-
123-
if ( itemType == "field" ) //
118+
while ( !stream.atEnd() )
124119
{
125-
if ( parent )
126-
{
127-
addItem( parent, itemName );
128-
bDropSuccessful = true;
129-
}
130-
else // Should never happen as we ignore drops of fields onto the root element in dragMoveEvent, but actually does happen. Qt?
120+
QMap<int, QVariant> roleDataMap;
121+
stream >> row >> col >> roleDataMap;
122+
123+
if ( col == 1 )
131124
{
132-
// addItem( invisibleRootItem(), itemName );
133-
// bDropSuccessful = true;
125+
/* do something with the data */
126+
127+
QString itemName = roleDataMap.value( Qt::DisplayRole ).toString();
128+
129+
if ( parent )
130+
{
131+
addItem( parent, itemName );
132+
bDropSuccessful = true;
133+
}
134+
else // Should never happen as we ignore drops of fields onto the root element in dragMoveEvent, but actually does happen. Qt?
135+
{
136+
// addItem( invisibleRootItem(), itemName );
137+
// bDropSuccessful = true;
138+
}
134139
}
135140
}
136-
else
137-
{
138-
bDropSuccessful = QTreeWidget::dropMimeData( parent, index, data, Qt::MoveAction );
139-
}
140141
}
141142

142143
return bDropSuccessful;
@@ -150,30 +151,9 @@ void QgsAttributesTree::dropEvent( QDropEvent *event )
150151
if ( event->source() == this )
151152
{
152153
event->setDropAction( Qt::MoveAction );
153-
QTreeWidget::dropEvent( event );
154154
}
155-
else
156-
{
157-
// Qt::DropAction dropAction;
158-
QByteArray itemData = event->mimeData()->data( "application/x-qabstractitemmodeldatalist" );
159-
QDataStream stream( &itemData, QIODevice::ReadOnly );
160-
int r, c, rDummy, cDummy;
161-
QMap<int, QVariant> roleDataMap, newRoleDataMap, roleDataMapDummy;
162-
stream >> rDummy >> cDummy >> roleDataMapDummy >> r >> c >> roleDataMap; // fieldName is in second column
163-
164-
QString fieldName = roleDataMap.value( Qt::DisplayRole ).toString();
165-
newRoleDataMap.insert( Qt::UserRole , "field" );
166-
newRoleDataMap.insert( Qt::DisplayRole , fieldName );
167155

168-
QMimeData * mimeData = new QMimeData();
169-
QByteArray mdata;
170-
QDataStream newStream( &mdata, QIODevice::WriteOnly );
171-
newStream << r << c << newRoleDataMap;
172-
mimeData->setData( QString( "application/x-qabstractitemmodeldatalist" ), mdata );
173-
QDropEvent newEvent = QDropEvent( event->pos(), Qt::CopyAction , mimeData, event->mouseButtons(), event->keyboardModifiers() );
174-
175-
QTreeWidget::dropEvent( &newEvent );
176-
}
156+
QTreeWidget::dropEvent( event );
177157
}
178158

179159
QgsFieldsProperties::QgsFieldsProperties( QgsVectorLayer *layer, QWidget* parent )

src/app/qgsfieldsproperties.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class QgsAttributesList : public QTableWidget
3434

3535
protected:
3636
// virtual void dragMoveEvent( QDragMoveEvent *event );
37-
//QMimeData *mimeData( const QList<QTableWidgetItem *> items ) const;
38-
//Qt::DropActions supportedDropActions() const;
37+
// QMimeData *mimeData( const QList<QTableWidgetItem *> items ) const;
38+
// Qt::DropActions supportedDropActions() const;
3939
};
4040

4141
class QgsAttributesTree : public QTreeWidget

0 commit comments

Comments
 (0)