Skip to content

Commit

Permalink
GRASS feature id fix, tables selection id fix, fixes #6451
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jun 12, 2013
1 parent 8024df7 commit b532151
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/gui/attributetable/qgsattributetabledelegate.cpp
Expand Up @@ -84,7 +84,7 @@ void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemMode
return;

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

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

QStyleOptionViewItem myOpt = option;

Expand Down
4 changes: 2 additions & 2 deletions src/gui/attributetable/qgsfeatureselectionmodel.cpp
Expand Up @@ -52,7 +52,7 @@ bool QgsFeatureSelectionModel::isSelected( QgsFeatureId fid )

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

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

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

ids << id;
}
Expand Down
26 changes: 19 additions & 7 deletions src/providers/grass/qgsgrassfeatureiterator.cpp
Expand Up @@ -149,6 +149,7 @@ bool QgsGrassFeatureIterator::nextFeature( QgsFeature& feature )

feature.setValid( false );
int cat = -1, type = -1, id = -1;
QgsFeatureId featureId = -1;

QgsDebugMsgLevel( "entered.", 3 );

Expand All @@ -172,13 +173,19 @@ bool QgsGrassFeatureIterator::nextFeature( QgsFeature& feature )
{
Vect_cidx_get_cat_by_index( P->mMap, P->mCidxFieldIndex, mNextCidx++, &cat, &type, &id );
// Warning: selection array is only of type line/area of current layer -> check type first

if ( filterById && id != mRequest.filterFid() )
if ( !( type & P->mGrassType ) )
continue;

if ( !( type & P->mGrassType ) )
// The 'id' is a unique id of a GRASS geometry object (point, line, area)
// but it cannot be used as QgsFeatureId because one geometry object may
// represent more features because it may have more categories.
featureId = makeFeatureId( id, cat );

if ( filterById && featureId != mRequest.filterFid() )
continue;

// it is correct to use id with mSelection because mSelection is only used
// for geometry selection
if ( !mSelection[id] )
continue;

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

feature.setFeatureId( id );
feature.setFeatureId( featureId );
feature.initAttributes( P->fields().count() );
feature.setFields( &P->fields() ); // allow name-based attribute lookups

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

feature.setGeometryAndOwnership( wkb, wkbsize );
}

QgsFeatureId QgsGrassFeatureIterator::makeFeatureId( int grassId, int cat )
{
// Because GRASS object id and category are both int and QgsFeatureId is qint64
// we can create unique QgsFeatureId from GRASS id and cat
return ( QgsFeatureId )grassId * 1000000000 + cat;
}
3 changes: 3 additions & 0 deletions src/providers/grass/qgsgrassfeatureiterator.h
Expand Up @@ -39,6 +39,9 @@ class QgsGrassFeatureIterator : public QgsAbstractFeatureIterator
protected:
QgsGrassProvider* P;

// create QgsFeatureId from GRASS geometry object id and cat
static QgsFeatureId makeFeatureId( int grassId, int cat );

void setSelectionRect( const QgsRectangle& rect, bool useIntersect );

void setFeatureGeometry( QgsFeature& feature, int id, int type );
Expand Down
3 changes: 3 additions & 0 deletions src/providers/grass/qgsgrassprovider.h
Expand Up @@ -520,6 +520,9 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider
bool mValid; // !UPDATE!
long mNumberFeatures; // !UPDATE!

// create QgsFeatureId from GRASS geometry object id and cat
static QgsFeatureId makeFeatureId( int grassId, int cat );

// Reopen map after edit or freeze
bool reopenMap();

Expand Down

0 comments on commit b532151

Please sign in to comment.