#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 ); }