summaryrefslogtreecommitdiff
path: root/src/dic-options/FieldsView.cpp
blob: 65801c7b64dbf70e3259b04bfd9f6a507356320f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 );
    }