Navigation Menu

Skip to content

Commit

Permalink
fix #4690
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 4, 2012
1 parent 21f9dcd commit 26778bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
5 changes: 1 addition & 4 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -778,10 +778,7 @@ void QgsAttributeTableDialog::on_mOpenFieldCalculator_clicked()

if ( col >= 0 )
{
QModelIndex idx0 = mModel->index( 0, col );
QModelIndex idx1 = mModel->index( mModel->rowCount() - 1, col );

mModel->reload( idx0, idx1 );
mModel->reload( mModel->index( 0, col ), mModel->index( mModel->rowCount() - 1, col ) );
}
}
}
Expand Down
32 changes: 21 additions & 11 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -248,7 +248,7 @@ void QgsAttributeTableModel::loadLayer()

if ( behaviour == 1 )
{
beginInsertRows( QModelIndex(), 0, mLayer->selectedFeatureCount() );
beginInsertRows( QModelIndex(), 0, mLayer->selectedFeatureCount() - 1 );
foreach( QgsFeatureId fid, mLayer->selectedFeaturesIds() )
{
featureAdded( fid, false );
Expand Down Expand Up @@ -371,21 +371,31 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient

void QgsAttributeTableModel::sort( int column, Qt::SortOrder order )
{
QgsAttributeMap row;
QgsAttributeList attrs;
QgsFeature f;

attrs.append( mAttributes[column] );

emit layoutAboutToBeChanged();
// QgsDebugMsg("SORTing");

QSettings settings;
int behaviour = settings.value( "/qgis/attributeTableBehaviour", 0 ).toInt();

QgsRectangle rect;
if ( behaviour == 2 )
{
// current canvas only
rect = mCurrentExtent;
}

mSortList.clear();
mLayer->select( attrs, QgsRectangle(), false );

int idx = fieldIdx( column );
mLayer->select( QgsAttributeList() << idx, rect, false );

QgsFeature f;
while ( mLayer->nextFeature( f ) )
{
row = f.attributeMap();
mSortList.append( QgsAttributeTableIdColumnPair( f.id(), row[ mAttributes[column] ] ) );
if ( behaviour == 1 && !mIdRowMap.contains( f.id() ) )
continue;

mSortList << QgsAttributeTableIdColumnPair( f.id(), f.attributeMap()[idx] );
}

if ( order == Qt::AscendingOrder )
Expand Down Expand Up @@ -506,7 +516,7 @@ Qt::ItemFlags QgsAttributeTableModel::flags( const QModelIndex &index ) const

void QgsAttributeTableModel::reload( const QModelIndex &index1, const QModelIndex &index2 )
{
for( int row = index1.row(); row <= index2.row(); row++ )
for ( int row = index1.row(); row <= index2.row(); row++ )
{
QgsFeatureId fid = rowToId( row );
mFeatureMap.remove( fid );
Expand Down

0 comments on commit 26778bf

Please sign in to comment.