18 #include <QHeaderView>
34 : QTableView( parent )
35 , mMasterModel( NULL )
36 , mFilterModel( NULL )
37 , mFeatureSelectionModel( NULL )
38 , mFeatureSelectionManager( NULL )
39 , mActionPopup( NULL )
42 restoreGeometry( settings.value(
"/BetterAttributeTable/geometry" ).toByteArray() );
44 verticalHeader()->setDefaultSectionSize( 20 );
45 horizontalHeader()->setHighlightSections(
false );
50 setSelectionBehavior( QAbstractItemView::SelectRows );
51 setSelectionMode( QAbstractItemView::ExtendedSelection );
52 setSortingEnabled(
true );
54 verticalHeader()->viewport()->installEventFilter(
this );
56 connect( verticalHeader(), SIGNAL( sectionPressed(
int ) ),
this, SLOT(
selectRow(
int ) ) );
57 connect( verticalHeader(), SIGNAL( sectionEntered(
int ) ),
this, SLOT(
_q_selectRow(
int ) ) );
93 if (
object == verticalHeader()->viewport() )
95 switch ( event->type() )
97 case QEvent::MouseButtonPress:
101 case QEvent::MouseButtonRelease:
117 disconnect(
mFilterModel, SIGNAL( filterAboutToBeInvalidated() ),
this, SLOT( onFilterAboutToBeInvalidated() ) );
118 disconnect(
mFilterModel, SIGNAL( filterInvalidated() ),
this, SLOT( onFilterInvalidated() ) );
157 settings.setValue(
"/BetterAttributeTable/geometry", QVariant( saveGeometry() ) );
162 setSelectionMode( QAbstractItemView::NoSelection );
164 setSelectionMode( QAbstractItemView::ExtendedSelection );
169 setSelectionMode( QAbstractItemView::NoSelection );
171 setSelectionMode( QAbstractItemView::ExtendedSelection );
176 setSelectionMode( QAbstractItemView::NoSelection );
178 setSelectionMode( QAbstractItemView::ExtendedSelection );
183 switch ( event->key() )
192 setSelectionMode( QAbstractItemView::NoSelection );
194 setSelectionMode( QAbstractItemView::ExtendedSelection );
205 foreach (
const QModelIndex
index, indexes )
213 setDirtyRegion( viewport()->rect() );
218 QItemSelection selection;
231 QModelIndex idx = indexAt( event->pos() );
232 if ( !idx.isValid() )
266 if ( selectionBehavior() == QTableView::SelectColumns
267 || ( selectionMode() == QTableView::SingleSelection
268 && selectionBehavior() == QTableView::SelectItems ) )
271 if ( row >= 0 && row < model()->rowCount() )
273 int column = horizontalHeader()->logicalIndexAt( isRightToLeft() ? viewport()->width() : 0 );
274 QModelIndex
index = model()->index( row, column );
275 QItemSelectionModel::SelectionFlags command = selectionCommand( index );
276 selectionModel()->setCurrentIndex( index, QItemSelectionModel::NoUpdate );
277 if (( anchor && !( command & QItemSelectionModel::Current ) )
278 || ( selectionMode() == QTableView::SingleSelection ) )
281 if ( selectionMode() != QTableView::SingleSelection
282 && command.testFlag( QItemSelectionModel::Toggle ) )
286 ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
287 command &= ~QItemSelectionModel::Toggle;
290 command |= QItemSelectionModel::Current;
294 QModelIndex br = model()->index( qMax(
mRowSectionAnchor, row ), model()->columnCount() - 1 );
295 if ( verticalHeader()->sectionsMoved() && tl.row() != br.row() )
296 setSelection( visualRect( tl ) | visualRect( br ), command );