diff options
author | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
---|---|---|
committer | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
commit | d24f813f3f2a05c112e803e4256b53535895fc98 (patch) | |
tree | 601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /src/dic-options/FieldsView.cpp |
Diffstat (limited to 'src/dic-options/FieldsView.cpp')
-rw-r--r-- | src/dic-options/FieldsView.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
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 <QHeaderView> + +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<QPersistentModelIndex> >(); + connect( aModel, SIGNAL(indexesDropped(QList<QPersistentModelIndex>)), + this, SLOT(selectIndexes(QList<QPersistentModelIndex>)), Qt::QueuedConnection ); + } + +void FieldsView::selectIndexes( QList<QPersistentModelIndex> aIndexes ) + { + selectionModel()->clearSelection(); + foreach( QPersistentModelIndex pIndex, aIndexes ) + selectionModel()->select( pIndex, QItemSelectionModel::Select | QItemSelectionModel::Rows ); + } |