Skip to content
Permalink
Browse files

GRASS feature id fix, tables selection id fix, fixes #6451

  • Loading branch information
blazek committed Jun 12, 2013
1 parent 8024df7 commit b532151c97121bf263e6055a36d99c646d391cae
@@ -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 ) )
@@ -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;

@@ -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 )
@@ -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;
}
@@ -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 );

@@ -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;

@@ -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

@@ -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;
}
@@ -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 );
@@ -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();

0 comments on commit b532151

Please sign in to comment.
You can’t perform that action at this time.