mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-05 00:09:32 -04:00
[wip] Make sure Form Layout view can accept both external copies and internal moves
This commit is contained in:
parent
c96c989add
commit
b3f8e32f1b
@ -493,13 +493,7 @@ Qt::ItemFlags QgsAttributesAvailableWidgetsModel::flags( const QModelIndex &inde
|
||||
if ( !index.isValid() )
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
|
||||
|
||||
AttributesFormTreeNode *node = getItem( index );
|
||||
if ( node->type() == QgsAttributeFormTreeData::WidgetType )
|
||||
flags |= Qt::ItemIsDropEnabled;
|
||||
|
||||
return flags;
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
|
||||
}
|
||||
|
||||
QVariant QgsAttributesAvailableWidgetsModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
||||
@ -691,6 +685,11 @@ bool QgsAttributesAvailableWidgetsModel::setData( const QModelIndex &index, cons
|
||||
return result;
|
||||
}
|
||||
|
||||
Qt::DropActions QgsAttributesAvailableWidgetsModel::supportedDragActions() const
|
||||
{
|
||||
return Qt::CopyAction;
|
||||
}
|
||||
|
||||
QModelIndex QgsAttributesAvailableWidgetsModel::getFieldContainer() const
|
||||
{
|
||||
if ( mRootItem->childCount() > 0 )
|
||||
@ -747,7 +746,7 @@ QVariant QgsAttributesFormLayoutModel::headerData( int section, Qt::Orientation
|
||||
Qt::ItemFlags QgsAttributesFormLayoutModel::flags( const QModelIndex &index ) const
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
return Qt::NoItemFlags;
|
||||
return Qt::ItemIsDropEnabled;
|
||||
|
||||
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
|
||||
|
||||
@ -1021,16 +1020,11 @@ bool QgsAttributesFormLayoutModel::removeRows( int row, int count, const QModelI
|
||||
|
||||
AttributesFormTreeNode *node = getItem( parent );
|
||||
|
||||
if ( row >= node->childCount() )
|
||||
if ( row > node->childCount() - count )
|
||||
return false;
|
||||
|
||||
beginRemoveRows( parent, row, row + count - 1 );
|
||||
|
||||
// for (int i=row+count-1; i==row; i-- )
|
||||
// {
|
||||
// node->deleteChildAtIndex( i );
|
||||
// }
|
||||
while ( count-- )
|
||||
for ( int r = 0; r < count; ++r )
|
||||
node->deleteChildAtIndex( row );
|
||||
endRemoveRows();
|
||||
return true;
|
||||
@ -1045,6 +1039,11 @@ bool QgsAttributesFormLayoutModel::removeRow( int row, const QModelIndex &parent
|
||||
return true;
|
||||
}
|
||||
|
||||
Qt::DropActions QgsAttributesFormLayoutModel::supportedDragActions() const
|
||||
{
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
Qt::DropActions QgsAttributesFormLayoutModel::supportedDropActions() const
|
||||
{
|
||||
return Qt::DropAction::CopyAction | Qt::DropAction::MoveAction;
|
||||
|
@ -16,6 +16,8 @@
|
||||
#ifndef QGSATTRIBUTESFORMMODEL_H
|
||||
#define QGSATTRIBUTESFORMMODEL_H
|
||||
|
||||
#define SIP_NO_FILE
|
||||
|
||||
#include "qgsaddtaborgroup.h"
|
||||
#include "qgsattributeeditorelement.h"
|
||||
#include "qgsoptionalexpression.h"
|
||||
@ -472,6 +474,7 @@ class QgsAttributesAvailableWidgetsModel : public QgsAttributesFormModel
|
||||
bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
|
||||
|
||||
// Drag and drop support
|
||||
Qt::DropActions supportedDragActions() const override;
|
||||
//Qt::DropActions supportedDropActions() const override;
|
||||
//QStringList mimeTypes() const override;
|
||||
//QMimeData *mimeData( const QModelIndexList &indexes ) const override;
|
||||
@ -521,14 +524,15 @@ class QgsAttributesFormLayoutModel : public QgsAttributesFormModel
|
||||
|
||||
// Add/remove data:
|
||||
//bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
|
||||
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
|
||||
bool removeRow( int row, const QModelIndex &parent = QModelIndex() );
|
||||
|
||||
// Drag and drop support
|
||||
Qt::DropActions supportedDragActions() const override;
|
||||
Qt::DropActions supportedDropActions() const override;
|
||||
//QStringList mimeTypes() const override;
|
||||
//QMimeData *mimeData( const QModelIndexList &indexes ) const override;
|
||||
bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
|
||||
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
|
||||
|
||||
// Other methods
|
||||
QList< QgsAddAttributeFormContainerDialog::ContainerPair > getListOfContainers() const;
|
||||
|
@ -65,7 +65,6 @@ QgsAttributesFormProperties::QgsAttributesFormProperties( QgsVectorLayer *layer,
|
||||
availableWidgetsWidgetLayout->addWidget( mAvailableWidgetsTreeView );
|
||||
availableWidgetsWidgetLayout->setContentsMargins( 0, 0, 0, 0 );
|
||||
mAvailableWidgetsWidget->setLayout( availableWidgetsWidgetLayout );
|
||||
mAvailableWidgetsTreeView->setSelectionMode( QAbstractItemView::SelectionMode::ExtendedSelection );
|
||||
mAvailableWidgetsTreeView->setContextMenuPolicy( Qt::CustomContextMenu );
|
||||
|
||||
mAvailableWidgetsModel = new QgsAttributesAvailableWidgetsModel( mLayer, QgsProject().instance(), this );
|
||||
@ -128,8 +127,10 @@ void QgsAttributesFormProperties::initAvailableWidgetsTree()
|
||||
{
|
||||
mAvailableWidgetsTreeView->setSortingEnabled( false );
|
||||
mAvailableWidgetsTreeView->setSelectionBehavior( QAbstractItemView::SelectRows );
|
||||
mAvailableWidgetsTreeView->setSelectionMode( QAbstractItemView::SelectionMode::ExtendedSelection );
|
||||
mAvailableWidgetsTreeView->setAcceptDrops( false );
|
||||
mAvailableWidgetsTreeView->setDragDropMode( QAbstractItemView::DragDropMode::DragOnly );
|
||||
//mAvailableWidgetsTreeView->setDefaultDropAction( Qt::CopyAction ); // probably not needed for AW
|
||||
|
||||
mAvailableWidgetsModel->populate();
|
||||
mAvailableWidgetsTreeView->expandAll();
|
||||
@ -142,7 +143,8 @@ void QgsAttributesFormProperties::initFormLayoutTree()
|
||||
mFormLayoutTreeView->setSelectionBehavior( QAbstractItemView::SelectRows );
|
||||
mFormLayoutTreeView->setSelectionMode( QAbstractItemView::SelectionMode::ExtendedSelection );
|
||||
mFormLayoutTreeView->setAcceptDrops( true );
|
||||
mFormLayoutTreeView->setDragDropMode( QAbstractItemView::DragDropMode::InternalMove );
|
||||
mFormLayoutTreeView->setDragDropMode( QAbstractItemView::DragDropMode::DragDrop );
|
||||
mFormLayoutTreeView->setDefaultDropAction( Qt::MoveAction );
|
||||
|
||||
mFormLayoutTreeView->selectionModel()->clear();
|
||||
mFormLayoutModel->populate();
|
||||
|
Loading…
x
Reference in New Issue
Block a user