@@ -171,7 +171,7 @@ void QgsAttributeTable::columnClicked( int col )
171171 QList < int >::iterator it;
172172 for ( it = idsOfSelected.begin (); it != idsOfSelected.end (); ++it )
173173 {
174- selectRowWithId (( *it ) );
174+ selectRowWithId ( *it );
175175 }
176176 connect ( this , SIGNAL ( itemSelectionChanged () ), this , SLOT ( handleChangedSelections () ) );
177177
@@ -226,7 +226,7 @@ void QgsAttributeTable::selectRowWithId( int id )
226226
227227void QgsAttributeTable::sortColumn ( int col, bool ascending )
228228{
229- int type = horizontalHeaderItem ( col )->data ( QgsAttributeTable:: AttributeType ).toInt ();
229+ int type = horizontalHeaderItem ( col )->data ( AttributeType ).toInt ();
230230 qsort ( 0 , rowCount () - 1 , col, ascending, type != QVariant::Int && type != QVariant::Double );
231231}
232232
@@ -437,6 +437,19 @@ void QgsAttributeTable::copySelectedRows()
437437 clipboard->setText ( toClipboard, QClipboard::Clipboard );
438438}
439439
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+
440453void QgsAttributeTable::fillTable ( QgsVectorLayer *layer )
441454{
442455 blockSignals ( true );
@@ -457,7 +470,7 @@ void QgsAttributeTable::fillTable( QgsVectorLayer *layer )
457470 QTableWidgetItem *twi = new QTableWidgetItem ( fldIt->name () );
458471 twi->setData ( AttributeIndex, fldIt.key () );
459472 twi->setData ( AttributeName, fldIt->name () );
460- twi->setData ( QgsAttributeTable:: AttributeType, (int )( fldIt->type ()) );
473+ twi->setData ( AttributeType, ( int ) fldIt->type () );
461474 setHorizontalHeaderItem ( h, twi );
462475
463476 mAttrIdxMap .insert ( fldIt.key (), h );
@@ -596,27 +609,26 @@ void QgsAttributeTable::bringSelectedToTop()
596609 blockSignals ( false );
597610}
598611
599- void QgsAttributeTable::selectRowsWithId ( const QgsFeatureIds& ids )
612+ void QgsAttributeTable::selectRowsWithId ( const QgsFeatureIds & ids, QgsVectorLayer *layer )
600613{
601- /*
614+ # if 0
602615 // 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 )
606619 {
607620 ++i;
608- progress.setValue(i );
621+ progress.setValue( i );
609622 qApp->processEvents();
610- if( progress.wasCanceled())
623+ if ( progress.wasCanceled() )
611624 {
612625 //deselect the remaining features if action was canceled
613- mSelected.erase(iter,--mSelected.end());
626+ mSelected.erase( iter, --mSelected.end() );
614627 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
617630 }
618- */
619-
631+ #endif
620632
621633 // to select more rows at once effectively, we stop sending signals to handleChangedSelections()
622634 // otherwise it will repaint map everytime row is selected
@@ -627,6 +639,12 @@ void QgsAttributeTable::selectRowsWithId( const QgsFeatureIds& ids )
627639 QgsFeatureIds::const_iterator it;
628640 for ( it = ids.begin (); it != ids.end (); it++ )
629641 {
642+ if ( layer && !rowIdMap.contains ( *it ) )
643+ {
644+ // add feature if we do not already have it
645+ addFeatureToTable ( layer, *it );
646+ }
647+
630648 selectRowWithId ( *it );
631649 }
632650
@@ -754,7 +772,7 @@ void QgsAttributeTable::addAttribute( int attr, const QgsField &fld )
754772 QTableWidgetItem *twi = new QTableWidgetItem ( fld.name () );
755773 twi->setData ( AttributeIndex, attr );
756774 twi->setData ( AttributeName, fld.name () );
757- twi->setData ( AttributeType, fld.type () );
775+ twi->setData ( AttributeType, ( int ) fld.type () );
758776
759777 insertColumn ( columnCount () );
760778 setHorizontalHeaderItem ( columnCount () - 1 , twi );
0 commit comments