From d24f813f3f2a05c112e803e4256b53535895fc98 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 14 Jul 2021 11:49:10 +1200 Subject: Initial mirror commit --- src/dic-options/FieldsView.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/dic-options/FieldsView.cpp (limited to 'src/dic-options/FieldsView.cpp') diff --git a/src/dic-options/FieldsView.cpp b/src/dic-options/FieldsView.cpp new file mode 100644 index 0000000..65801c7 --- /dev/null +++ b/src/dic-options/FieldsView.cpp @@ -0,0 +1,41 @@ +#include "FieldsView.h" +#include "FieldStyleDelegate.h" + +#include + +FieldsView::FieldsView(QWidget *parent): + QTableView( parent ) + { + setDragEnabled(true); + setAcceptDrops(true); + setDropIndicatorShown(true); + setDragDropOverwriteMode( false ); + FieldStyleDelegate* delegate = new FieldStyleDelegate(this); + setItemDelegateForColumn( 1, delegate ); + + setShowGrid(false); + verticalHeader()->hide(); + setSelectionBehavior( QAbstractItemView::SelectRows ); + } + +void FieldsView::startDrag(Qt::DropActions supportedActions) + { + selectionModel()->select( selectionModel()->selection(), + QItemSelectionModel::Select | QItemSelectionModel::Rows ); + QAbstractItemView::startDrag( supportedActions ); + } + +void FieldsView::setModel( FieldsListModel* aModel ) + { + QTableView::setModel( aModel ); + qRegisterMetaType< QList >(); + connect( aModel, SIGNAL(indexesDropped(QList)), + this, SLOT(selectIndexes(QList)), Qt::QueuedConnection ); + } + +void FieldsView::selectIndexes( QList aIndexes ) + { + selectionModel()->clearSelection(); + foreach( QPersistentModelIndex pIndex, aIndexes ) + selectionModel()->select( pIndex, QItemSelectionModel::Select | QItemSelectionModel::Rows ); + } -- cgit