Skip to content

Commit 26778bf

Browse files
committed
fix #4690
1 parent 21f9dcd commit 26778bf

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/app/qgsattributetabledialog.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -778,10 +778,7 @@ void QgsAttributeTableDialog::on_mOpenFieldCalculator_clicked()
778778

779779
if ( col >= 0 )
780780
{
781-
QModelIndex idx0 = mModel->index( 0, col );
782-
QModelIndex idx1 = mModel->index( mModel->rowCount() - 1, col );
783-
784-
mModel->reload( idx0, idx1 );
781+
mModel->reload( mModel->index( 0, col ), mModel->index( mModel->rowCount() - 1, col ) );
785782
}
786783
}
787784
}

src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void QgsAttributeTableModel::loadLayer()
248248

249249
if ( behaviour == 1 )
250250
{
251-
beginInsertRows( QModelIndex(), 0, mLayer->selectedFeatureCount() );
251+
beginInsertRows( QModelIndex(), 0, mLayer->selectedFeatureCount() - 1 );
252252
foreach( QgsFeatureId fid, mLayer->selectedFeaturesIds() )
253253
{
254254
featureAdded( fid, false );
@@ -371,21 +371,31 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient
371371

372372
void QgsAttributeTableModel::sort( int column, Qt::SortOrder order )
373373
{
374-
QgsAttributeMap row;
375-
QgsAttributeList attrs;
376-
QgsFeature f;
377-
378-
attrs.append( mAttributes[column] );
379-
380374
emit layoutAboutToBeChanged();
381375
// QgsDebugMsg("SORTing");
382376

377+
QSettings settings;
378+
int behaviour = settings.value( "/qgis/attributeTableBehaviour", 0 ).toInt();
379+
380+
QgsRectangle rect;
381+
if ( behaviour == 2 )
382+
{
383+
// current canvas only
384+
rect = mCurrentExtent;
385+
}
386+
383387
mSortList.clear();
384-
mLayer->select( attrs, QgsRectangle(), false );
388+
389+
int idx = fieldIdx( column );
390+
mLayer->select( QgsAttributeList() << idx, rect, false );
391+
392+
QgsFeature f;
385393
while ( mLayer->nextFeature( f ) )
386394
{
387-
row = f.attributeMap();
388-
mSortList.append( QgsAttributeTableIdColumnPair( f.id(), row[ mAttributes[column] ] ) );
395+
if ( behaviour == 1 && !mIdRowMap.contains( f.id() ) )
396+
continue;
397+
398+
mSortList << QgsAttributeTableIdColumnPair( f.id(), f.attributeMap()[idx] );
389399
}
390400

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

507517
void QgsAttributeTableModel::reload( const QModelIndex &index1, const QModelIndex &index2 )
508518
{
509-
for( int row = index1.row(); row <= index2.row(); row++ )
519+
for ( int row = index1.row(); row <= index2.row(); row++ )
510520
{
511521
QgsFeatureId fid = rowToId( row );
512522
mFeatureMap.remove( fid );

0 commit comments

Comments
 (0)