Skip to content
Permalink
Browse files

Drop fields in correct position in drag and drop designer

Instead of always dropping fields at the end of the container,
insert them at the dropped location. Otherwise the drop indicator
line is misleading.
  • Loading branch information
nyalldawson committed Jan 16, 2018
1 parent fa120b5 commit a3a999e41651710b9531bbf426930c949542e995
Showing with 13 additions and 6 deletions.
  1. +7 −5 src/app/qgsattributesformproperties.cpp
  2. +6 −1 src/app/qgsattributesformproperties.h
@@ -786,7 +786,7 @@ DnDTree::DnDTree( QgsVectorLayer *layer, QWidget *parent )
connect( this, &QTreeWidget::itemDoubleClicked, this, &DnDTree::onItemDoubleClicked );
}

QTreeWidgetItem *DnDTree::addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data )
QTreeWidgetItem *DnDTree::addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data, int index )
{
QTreeWidgetItem *newItem = new QTreeWidgetItem( QStringList() << data.name() );
newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled );
@@ -811,7 +811,10 @@ QTreeWidgetItem *DnDTree::addItem( QTreeWidgetItem *parent, QgsAttributesFormPro
}
}
newItem->setData( 0, QgsAttributesFormProperties::DnDTreeRole, data );
parent->addChild( newItem );
if ( index < 0 )
parent->addChild( newItem );
else
parent->insertChild( index, newItem );

return newItem;
}
@@ -850,7 +853,6 @@ void DnDTree::dragMoveEvent( QDragMoveEvent *event )

bool DnDTree::dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action )
{
Q_UNUSED( index )
bool bDropSuccessful = false;

if ( action == Qt::IgnoreAction )
@@ -869,12 +871,12 @@ bool DnDTree::dropMimeData( QTreeWidgetItem *parent, int index, const QMimeData

if ( parent )
{
addItem( parent, itemElement );
addItem( parent, itemElement, index );
bDropSuccessful = true;
}
else
{
addItem( invisibleRootItem(), itemElement );
addItem( invisibleRootItem(), itemElement, index );
bDropSuccessful = true;
}
}
@@ -238,7 +238,12 @@ class DnDTree : public QTreeWidget

public:
explicit DnDTree( QgsVectorLayer *layer, QWidget *parent = nullptr );
QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data );

/**
* Adds a new item to a \a parent. If \a index is -1, the item is added to the end of the parent's existing children.
* Otherwise it is inserted at the specified \a index.
*/
QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data, int index = -1 );
QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount );

enum Type

0 comments on commit a3a999e

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