18 #include <QHeaderView>
33 : QTableView( parent )
34 , mMasterModel( NULL )
35 , mFilterModel( NULL )
36 , mFeatureSelectionModel( NULL )
37 , mActionPopup( NULL )
40 restoreGeometry( settings.value(
"/BetterAttributeTable/geometry" ).toByteArray() );
42 verticalHeader()->setDefaultSectionSize( 20 );
43 horizontalHeader()->setHighlightSections(
false );
48 setSelectionBehavior( QAbstractItemView::SelectRows );
49 setSelectionMode( QAbstractItemView::ExtendedSelection );
50 setSortingEnabled(
true );
52 verticalHeader()->viewport()->installEventFilter(
this );
54 connect( verticalHeader(), SIGNAL( sectionPressed(
int ) ),
this, SLOT(
selectRow(
int ) ) );
55 connect( verticalHeader(), SIGNAL( sectionEntered(
int ) ),
this, SLOT(
_q_selectRow(
int ) ) );
91 if (
object == verticalHeader()->viewport() )
93 switch ( event->type() )
95 case QEvent::MouseButtonPress:
99 case QEvent::MouseButtonRelease:
115 disconnect(
mFilterModel, SIGNAL( filterAboutToBeInvalidated() ),
this, SLOT( onFilterAboutToBeInvalidated() ) );
116 disconnect(
mFilterModel, SIGNAL( filterInvalidated() ),
this, SLOT( onFilterInvalidated() ) );
139 settings.setValue(
"/BetterAttributeTable/geometry", QVariant( saveGeometry() ) );
144 setSelectionMode( QAbstractItemView::NoSelection );
146 setSelectionMode( QAbstractItemView::ExtendedSelection );
151 setSelectionMode( QAbstractItemView::NoSelection );
153 setSelectionMode( QAbstractItemView::ExtendedSelection );
158 setSelectionMode( QAbstractItemView::NoSelection );
160 setSelectionMode( QAbstractItemView::ExtendedSelection );
165 switch ( event->key() )
174 setSelectionMode( QAbstractItemView::NoSelection );
176 setSelectionMode( QAbstractItemView::ExtendedSelection );
187 foreach (
const QModelIndex index, indexes )
195 setDirtyRegion( viewport()->rect() );
200 QItemSelection selection;
213 QModelIndex idx = indexAt( event->pos() );
214 if ( !idx.isValid() )
248 if ( selectionBehavior() == QTableView::SelectColumns
249 || ( selectionMode() == QTableView::SingleSelection
250 && selectionBehavior() == QTableView::SelectItems ) )
253 if ( row >= 0 && row < model()->rowCount() )
255 int column = horizontalHeader()->logicalIndexAt( isRightToLeft() ? viewport()->width() : 0 );
256 QModelIndex index = model()->index( row, column );
257 QItemSelectionModel::SelectionFlags command = selectionCommand( index );
258 selectionModel()->setCurrentIndex( index, QItemSelectionModel::NoUpdate );
259 if (( anchor && !( command & QItemSelectionModel::Current ) )
260 || ( selectionMode() == QTableView::SingleSelection ) )
263 if ( selectionMode() != QTableView::SingleSelection
264 && command.testFlag( QItemSelectionModel::Toggle ) )
268 ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
269 command &= ~QItemSelectionModel::Toggle;
272 command |= QItemSelectionModel::Current;
276 QModelIndex br = model()->index( qMax(
mRowSectionAnchor, row ), model()->columnCount() - 1 );
277 if ( verticalHeader()->sectionsMoved() && tl.row() != br.row() )
278 setSelection( visualRect( tl ) | visualRect( br ), command );