@@ -171,7 +171,7 @@ void QgsAttributeTable::columnClicked( int col )
171
171
QList < int >::iterator it;
172
172
for ( it = idsOfSelected.begin (); it != idsOfSelected.end (); ++it )
173
173
{
174
- selectRowWithId (( *it ) );
174
+ selectRowWithId ( *it );
175
175
}
176
176
connect ( this , SIGNAL ( itemSelectionChanged () ), this , SLOT ( handleChangedSelections () ) );
177
177
@@ -226,7 +226,7 @@ void QgsAttributeTable::selectRowWithId( int id )
226
226
227
227
void QgsAttributeTable::sortColumn ( int col, bool ascending )
228
228
{
229
- int type = horizontalHeaderItem ( col )->data ( QgsAttributeTable:: AttributeType ).toInt ();
229
+ int type = horizontalHeaderItem ( col )->data ( AttributeType ).toInt ();
230
230
qsort ( 0 , rowCount () - 1 , col, ascending, type != QVariant::Int && type != QVariant::Double );
231
231
}
232
232
@@ -437,6 +437,19 @@ void QgsAttributeTable::copySelectedRows()
437
437
clipboard->setText ( toClipboard, QClipboard::Clipboard );
438
438
}
439
439
440
+ void QgsAttributeTable::addFeatureToTable ( QgsVectorLayer *layer, int id )
441
+ {
442
+ blockSignals ( true );
443
+
444
+ QgsFeature f;
445
+ if ( layer->featureAtId ( id, f, false , true ) == 0 )
446
+ {
447
+ putFeatureInTable ( rowCount (), f );
448
+ }
449
+
450
+ blockSignals ( false );
451
+ }
452
+
440
453
void QgsAttributeTable::fillTable ( QgsVectorLayer *layer )
441
454
{
442
455
blockSignals ( true );
@@ -457,7 +470,7 @@ void QgsAttributeTable::fillTable( QgsVectorLayer *layer )
457
470
QTableWidgetItem *twi = new QTableWidgetItem ( fldIt->name () );
458
471
twi->setData ( AttributeIndex, fldIt.key () );
459
472
twi->setData ( AttributeName, fldIt->name () );
460
- twi->setData ( QgsAttributeTable:: AttributeType, (int )( fldIt->type ()) );
473
+ twi->setData ( AttributeType, ( int ) fldIt->type () );
461
474
setHorizontalHeaderItem ( h, twi );
462
475
463
476
mAttrIdxMap .insert ( fldIt.key (), h );
@@ -596,27 +609,26 @@ void QgsAttributeTable::bringSelectedToTop()
596
609
blockSignals ( false );
597
610
}
598
611
599
- void QgsAttributeTable::selectRowsWithId ( const QgsFeatureIds& ids )
612
+ void QgsAttributeTable::selectRowsWithId ( const QgsFeatureIds & ids, QgsVectorLayer *layer )
600
613
{
601
- /*
614
+ # if 0
602
615
// if selecting rows takes too much time we can use progress dialog
603
- QProgressDialog progress( tr("Updating selection..."), tr("Abort"), 0, mSelected.size(), tabledisplay);
604
- int i= 0;
605
- for( std::set<int>::iterator iter= mSelected.begin();iter!= mSelected.end();++iter)
616
+ QProgressDialog progress( tr( "Updating selection..." ), tr( "Abort" ), 0, mSelected.size(), tabledisplay );
617
+ int i = 0;
618
+ for ( std::set<int>::iterator iter = mSelected.begin();iter != mSelected.end();++iter )
606
619
{
607
620
++i;
608
- progress.setValue(i );
621
+ progress.setValue( i );
609
622
qApp->processEvents();
610
- if( progress.wasCanceled())
623
+ if ( progress.wasCanceled() )
611
624
{
612
625
//deselect the remaining features if action was canceled
613
- mSelected.erase(iter,--mSelected.end());
626
+ mSelected.erase( iter, --mSelected.end() );
614
627
break;
615
- }
616
- selectRowWithId(*iter);//todo: avoid that the table gets repainted during each selection
628
+ }
629
+ selectRowWithId( *iter );//todo: avoid that the table gets repainted during each selection
617
630
}
618
- */
619
-
631
+ #endif
620
632
621
633
// to select more rows at once effectively, we stop sending signals to handleChangedSelections()
622
634
// otherwise it will repaint map everytime row is selected
@@ -627,6 +639,12 @@ void QgsAttributeTable::selectRowsWithId( const QgsFeatureIds& ids )
627
639
QgsFeatureIds::const_iterator it;
628
640
for ( it = ids.begin (); it != ids.end (); it++ )
629
641
{
642
+ if ( layer && !rowIdMap.contains ( *it ) )
643
+ {
644
+ // add feature if we do not already have it
645
+ addFeatureToTable ( layer, *it );
646
+ }
647
+
630
648
selectRowWithId ( *it );
631
649
}
632
650
@@ -754,7 +772,7 @@ void QgsAttributeTable::addAttribute( int attr, const QgsField &fld )
754
772
QTableWidgetItem *twi = new QTableWidgetItem ( fld.name () );
755
773
twi->setData ( AttributeIndex, attr );
756
774
twi->setData ( AttributeName, fld.name () );
757
- twi->setData ( AttributeType, fld.type () );
775
+ twi->setData ( AttributeType, ( int ) fld.type () );
758
776
759
777
insertColumn ( columnCount () );
760
778
setHorizontalHeaderItem ( columnCount () - 1 , twi );
0 commit comments