Skip to content

Commit b532151

Browse files
committed
GRASS feature id fix, tables selection id fix, fixes #6451
1 parent 8024df7 commit b532151

5 files changed

+29
-11
lines changed

src/gui/attributetable/qgsattributetabledelegate.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemMode
8484
return;
8585

8686
int fieldIdx = model->data( index, QgsAttributeTableModel::FieldIndexRole ).toInt();
87-
QgsFeatureId fid = model->data( index, QgsAttributeTableModel::FeatureIdRole ).toInt();
87+
QgsFeatureId fid = model->data( index, QgsAttributeTableModel::FeatureIdRole ).toLongLong();
8888

8989
QVariant value;
9090
if ( !QgsAttributeEditor::retrieveValue( editor, vl, fieldIdx, value ) )
@@ -114,7 +114,7 @@ void QgsAttributeTableDelegate::paint( QPainter * painter,
114114
const QStyleOptionViewItem & option,
115115
const QModelIndex & index ) const
116116
{
117-
QgsFeatureId fid = index.model()->data( index, QgsAttributeTableModel::FeatureIdRole ).toInt();
117+
QgsFeatureId fid = index.model()->data( index, QgsAttributeTableModel::FeatureIdRole ).toLongLong();
118118

119119
QStyleOptionViewItem myOpt = option;
120120

src/gui/attributetable/qgsfeatureselectionmodel.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool QgsFeatureSelectionModel::isSelected( QgsFeatureId fid )
5252

5353
bool QgsFeatureSelectionModel::isSelected( const QModelIndex &index )
5454
{
55-
return isSelected( index.model()->data( index, QgsAttributeTableModel::FeatureIdRole ).toInt() );
55+
return isSelected( index.model()->data( index, QgsAttributeTableModel::FeatureIdRole ).toLongLong() );
5656
}
5757

5858
void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection, QItemSelectionModel::SelectionFlags command )
@@ -61,7 +61,7 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,
6161

6262
foreach ( const QModelIndex index, selection.indexes() )
6363
{
64-
QgsFeatureId id = index.model()->data( index, QgsAttributeTableModel::FeatureIdRole ).toInt();
64+
QgsFeatureId id = index.model()->data( index, QgsAttributeTableModel::FeatureIdRole ).toLongLong();
6565

6666
ids << id;
6767
}

src/providers/grass/qgsgrassfeatureiterator.cpp

+19-7
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ bool QgsGrassFeatureIterator::nextFeature( QgsFeature& feature )
149149

150150
feature.setValid( false );
151151
int cat = -1, type = -1, id = -1;
152+
QgsFeatureId featureId = -1;
152153

153154
QgsDebugMsgLevel( "entered.", 3 );
154155

@@ -172,13 +173,19 @@ bool QgsGrassFeatureIterator::nextFeature( QgsFeature& feature )
172173
{
173174
Vect_cidx_get_cat_by_index( P->mMap, P->mCidxFieldIndex, mNextCidx++, &cat, &type, &id );
174175
// Warning: selection array is only of type line/area of current layer -> check type first
175-
176-
if ( filterById && id != mRequest.filterFid() )
176+
if ( !( type & P->mGrassType ) )
177177
continue;
178178

179-
if ( !( type & P->mGrassType ) )
179+
// The 'id' is a unique id of a GRASS geometry object (point, line, area)
180+
// but it cannot be used as QgsFeatureId because one geometry object may
181+
// represent more features because it may have more categories.
182+
featureId = makeFeatureId( id, cat );
183+
184+
if ( filterById && featureId != mRequest.filterFid() )
180185
continue;
181186

187+
// it is correct to use id with mSelection because mSelection is only used
188+
// for geometry selection
182189
if ( !mSelection[id] )
183190
continue;
184191

@@ -190,11 +197,9 @@ bool QgsGrassFeatureIterator::nextFeature( QgsFeature& feature )
190197
close();
191198
return false; // No more features
192199
}
193-
#if QGISDEBUG > 3
194-
QgsDebugMsg( QString( "cat = %1 type = %2 id = %3" ).arg( cat ).arg( type ).arg( id ) );
195-
#endif
200+
QgsDebugMsgLevel( QString( "cat = %1 type = %2 id = %3 fatureId = %4" ).arg( cat ).arg( type ).arg( id ).arg( featureId ), 3 );
196201

197-
feature.setFeatureId( id );
202+
feature.setFeatureId( featureId );
198203
feature.initAttributes( P->fields().count() );
199204
feature.setFields( &P->fields() ); // allow name-based attribute lookups
200205

@@ -395,3 +400,10 @@ void QgsGrassFeatureIterator::setFeatureGeometry( QgsFeature& feature, int id, i
395400

396401
feature.setGeometryAndOwnership( wkb, wkbsize );
397402
}
403+
404+
QgsFeatureId QgsGrassFeatureIterator::makeFeatureId( int grassId, int cat )
405+
{
406+
// Because GRASS object id and category are both int and QgsFeatureId is qint64
407+
// we can create unique QgsFeatureId from GRASS id and cat
408+
return ( QgsFeatureId )grassId * 1000000000 + cat;
409+
}

src/providers/grass/qgsgrassfeatureiterator.h

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class QgsGrassFeatureIterator : public QgsAbstractFeatureIterator
3939
protected:
4040
QgsGrassProvider* P;
4141

42+
// create QgsFeatureId from GRASS geometry object id and cat
43+
static QgsFeatureId makeFeatureId( int grassId, int cat );
44+
4245
void setSelectionRect( const QgsRectangle& rect, bool useIntersect );
4346

4447
void setFeatureGeometry( QgsFeature& feature, int id, int type );

src/providers/grass/qgsgrassprovider.h

+3
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
520520
bool mValid; // !UPDATE!
521521
long mNumberFeatures; // !UPDATE!
522522

523+
// create QgsFeatureId from GRASS geometry object id and cat
524+
static QgsFeatureId makeFeatureId( int grassId, int cat );
525+
523526
// Reopen map after edit or freeze
524527
bool reopenMap();
525528

0 commit comments

Comments
 (0)