3434
3535QgsFeatureListView::QgsFeatureListView ( QWidget *parent )
3636 : QListView( parent )
37- , mCurrentEditSelectionModel( NULL )
38- , mFeatureSelectionModel( NULL )
39- , mItemDelegate( NULL )
37+ , mModel( 0 )
38+ , mCurrentEditSelectionModel( 0 )
39+ , mFeatureSelectionModel( 0 )
40+ , mItemDelegate( 0 )
4041 , mEditSelectionDrag( false )
4142{
4243 setSelectionMode ( QAbstractItemView::ExtendedSelection );
@@ -100,7 +101,7 @@ QString QgsFeatureListView::parserErrorString()
100101QgsFeatureIds QgsFeatureListView::currentEditSelection ()
101102{
102103 QgsFeatureIds selection;
103- Q_FOREACH ( QModelIndex idx, mCurrentEditSelectionModel ->selectedIndexes () )
104+ Q_FOREACH ( QModelIndex idx, mCurrentEditSelectionModel ->selectedIndexes () )
104105 {
105106 selection << idx.data ( QgsAttributeTableModel::FeatureIdRole ).value <QgsFeatureId>();
106107 }
@@ -115,20 +116,27 @@ void QgsFeatureListView::setCurrentFeatureEdited( bool state )
115116
116117void QgsFeatureListView::mousePressEvent ( QMouseEvent *event )
117118{
118- QPoint pos = event->pos ();
119+ if ( mModel )
120+ {
121+ QPoint pos = event->pos ();
119122
120- QModelIndex index = indexAt ( pos );
123+ QModelIndex index = indexAt ( pos );
121124
122- if ( QgsFeatureListViewDelegate::EditElement == mItemDelegate ->positionToElement ( event->pos () ) )
123- {
124- mEditSelectionDrag = true ;
125- setEditSelection ( mModel ->mapToMaster ( index ), QItemSelectionModel::ClearAndSelect );
125+ if ( QgsFeatureListViewDelegate::EditElement == mItemDelegate ->positionToElement ( event->pos () ) )
126+ {
127+ mEditSelectionDrag = true ;
128+ setEditSelection ( mModel ->mapToMaster ( index ), QItemSelectionModel::ClearAndSelect );
129+ }
130+ else
131+ {
132+ mFeatureSelectionModel ->enableSync ( false );
133+ selectRow ( index, true );
134+ repaintRequested ();
135+ }
126136 }
127137 else
128138 {
129- mFeatureSelectionModel ->enableSync ( false );
130- selectRow ( index, true );
131- repaintRequested ();
139+ QgsDebugMsg ( " No model assigned to this view" );
132140 }
133141}
134142
0 commit comments