@@ -248,7 +248,7 @@ void QgsAttributeTableModel::loadLayer()
248
248
249
249
if ( behaviour == 1 )
250
250
{
251
- beginInsertRows ( QModelIndex (), 0 , mLayer ->selectedFeatureCount () );
251
+ beginInsertRows ( QModelIndex (), 0 , mLayer ->selectedFeatureCount () - 1 );
252
252
foreach ( QgsFeatureId fid, mLayer ->selectedFeaturesIds () )
253
253
{
254
254
featureAdded ( fid, false );
@@ -371,21 +371,31 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient
371
371
372
372
void QgsAttributeTableModel::sort ( int column, Qt::SortOrder order )
373
373
{
374
- QgsAttributeMap row;
375
- QgsAttributeList attrs;
376
- QgsFeature f;
377
-
378
- attrs.append ( mAttributes [column] );
379
-
380
374
emit layoutAboutToBeChanged ();
381
375
// QgsDebugMsg("SORTing");
382
376
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
+
383
387
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;
385
393
while ( mLayer ->nextFeature ( f ) )
386
394
{
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] );
389
399
}
390
400
391
401
if ( order == Qt::AscendingOrder )
@@ -506,7 +516,7 @@ Qt::ItemFlags QgsAttributeTableModel::flags( const QModelIndex &index ) const
506
516
507
517
void QgsAttributeTableModel::reload ( const QModelIndex &index1, const QModelIndex &index2 )
508
518
{
509
- for ( int row = index1.row (); row <= index2.row (); row++ )
519
+ for ( int row = index1.row (); row <= index2.row (); row++ )
510
520
{
511
521
QgsFeatureId fid = rowToId ( row );
512
522
mFeatureMap .remove ( fid );
0 commit comments