Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Attribute editor (drag and drop layouter): Proper handling when multiple... #486

Merged
merged 1 commit into from

2 participants

@m-kuhn
Collaborator

... fields are dropped

@jef-n jef-n merged commit 7d34f02 into qgis:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2013
  1. @m-kuhn
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 43 deletions.
  1. +21 −41 src/app/qgsfieldsproperties.cpp
  2. +2 −2 src/app/qgsfieldsproperties.h
View
62 src/app/qgsfieldsproperties.cpp
@@ -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 )
View
4 src/app/qgsfieldsproperties.h
@@ -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
Something went wrong with that request. Please try again.