16 #include <QHeaderView>
39 , mCurrentEditSelectionModel( 0 )
40 , mFeatureSelectionModel( 0 )
42 , mEditSelectionDrag( false )
45 setSelectionMode( QAbstractItemView::ExtendedSelection );
58 delete mFeatureSelectionModel;
60 setSelectionModel( mFeatureSelectionModel );
62 mCurrentEditSelectionModel =
new QItemSelectionModel( mModel->
masterModel(), this );
64 if ( mItemDelegate && mItemDelegate->parent() == this )
71 setItemDelegate( mItemDelegate );
74 connect( mFeatureSelectionModel, SIGNAL( requestRepaint( QModelIndexList ) ),
this, SLOT(
repaintRequested( QModelIndexList ) ) );
75 connect( mFeatureSelectionModel, SIGNAL( requestRepaint() ),
this, SLOT(
repaintRequested() ) );
77 connect( mCurrentEditSelectionModel, SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), SLOT( editSelectionChanged( QItemSelection, QItemSelection ) ) );
106 Q_FOREACH ( QModelIndex idx, mCurrentEditSelectionModel->selectedIndexes() )
116 viewport()->update( visualRegionForSelection( mCurrentEditSelectionModel->selection() ) );
123 QPoint pos =
event->pos();
125 QModelIndex
index = indexAt( pos );
129 mEditSelectionDrag =
true;
135 selectRow( index,
true );
145 void QgsFeatureListView::editSelectionChanged( QItemSelection deselected, QItemSelection selected )
147 if ( isVisible() && updatesEnabled() )
151 viewport()->update( visualRegionForSelection( localDeselected ) | visualRegionForSelection( localSelected ) );
154 QItemSelection currentSelection = mCurrentEditSelectionModel->selection();
155 if ( currentSelection.size() == 1 )
157 QModelIndexList indexList = currentSelection.indexes();
158 if ( !indexList.isEmpty() )
170 QItemSelection selection;
171 selection.append( QItemSelectionRange( mModel->
index( 0, 0 ), mModel->
index( mModel->
rowCount() - 1, 0 ) ) );
173 mFeatureSelectionModel->
selectFeatures( selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
178 QItemSelection selection;
189 mCurrentEditSelectionModel->select( selection, QItemSelectionModel::ClearAndSelect );
198 mCurrentEditSelectionModel->select( index, command );
203 foreach (
const QModelIndex
index, indexes )
211 setDirtyRegion( viewport()->rect() );
222 QPoint pos =
event->pos();
224 QModelIndex
index = indexAt( pos );
226 if ( mEditSelectionDrag )
232 selectRow( index,
false );
247 if ( mEditSelectionDrag )
249 mEditSelectionDrag =
false;
259 if ( Qt::Key_Up == event->key() || Qt::Key_Down ==
event->key() )
262 if ( 0 != mCurrentEditSelectionModel->selectedIndexes().count() )
264 QModelIndex localIndex = mModel->
mapFromMaster( mCurrentEditSelectionModel->selectedIndexes().first() );
265 currentRow = localIndex.row();
268 QModelIndex newLocalIndex;
269 QModelIndex newIndex;
271 switch ( event->key() )
274 newLocalIndex = mModel->
index( currentRow - 1, 0 );
276 if ( newIndex.isValid() )
279 scrollTo( newLocalIndex );
284 newLocalIndex = mModel->
index( currentRow + 1, 0 );
286 if ( newIndex.isValid() )
289 scrollTo( newLocalIndex );
305 QModelIndex
index = indexAt( event->pos() );
307 if ( index.isValid() )
312 menu.exec( event->globalPos() );
316 void QgsFeatureListView::selectRow(
const QModelIndex&
index,
bool anchor )
318 QItemSelectionModel::SelectionFlags command = selectionCommand( index );
319 int row = index.row();
324 if ( selectionMode() != QListView::SingleSelection
325 && command.testFlag( QItemSelectionModel::Toggle ) )
328 mCtrlDragSelectionFlag = mFeatureSelectionModel->
isSelected( index )
329 ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
330 command &= ~QItemSelectionModel::Toggle;
331 command |= mCtrlDragSelectionFlag;
333 command |= QItemSelectionModel::Current;
336 QModelIndex tl = model()->index( qMin( mRowAnchor, row ), 0 );
337 QModelIndex br = model()->index( qMax( mRowAnchor, row ), model()->columnCount() - 1 );
339 mFeatureSelectionModel->
selectFeatures( QItemSelection( tl, br ), command );