Skip to content

Commit 227f381

Browse files
author
jef
committedNov 8, 2008
partly fix #1377, #1382 and #1306
git-svn-id: http://svn.osgeo.org/qgis/trunk@9598 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 933cfb9 commit 227f381

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed
 

‎src/app/qgsattributetable.cpp

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

227227
void 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+
440453
void 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 );

‎src/app/qgsattributetable.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,18 @@ class QgsAttributeTable : public QTableWidget
8787
/**Swaps the selected rows such that the selected ones are on the top of the table*/
8888
void bringSelectedToTop();
8989
/** Selects rows with chosen feature IDs */
90-
void selectRowsWithId( const QgsFeatureIds& ids );
90+
void selectRowsWithId( const QgsFeatureIds& ids, QgsVectorLayer *layer = 0 );
9191
/** Shows only rows with chosen feature IDs, others get hidden */
9292
void showRowsWithId( const QgsFeatureIds& ids );
9393
/** Shows all rows */
9494
void showAllRows();
9595

9696
/**Fills the contents of a provider into this table*/
9797
void fillTable( QgsVectorLayer *layer );
98+
99+
/** adds a feature to the current table */
100+
void addFeatureToTable( QgsVectorLayer *layer, int id );
101+
98102
void addAttribute( int idx, const QgsField &fld );
99103
void deleteAttribute( int idx );
100104

‎src/app/qgsattributetabledisplay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void QgsAttributeTableDisplay::setAttributeActions( const QgsAttributeAction &ac
244244

245245
void QgsAttributeTableDisplay::selectRowsWithId( const QgsFeatureIds &ids )
246246
{
247-
tblAttributes->selectRowsWithId( ids );
247+
tblAttributes->selectRowsWithId( ids, mLayer );
248248
}
249249

250250
void QgsAttributeTableDisplay::setTheme()

0 commit comments

Comments
 (0)
Please sign in to comment.