Skip to content

Commit

Permalink
partly fix #1377, #1382 and #1306
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9598 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 8, 2008
1 parent b2cce3c commit a947a79
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
50 changes: 34 additions & 16 deletions src/app/qgsattributetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void QgsAttributeTable::columnClicked( int col )
QList < int >::iterator it;
for ( it = idsOfSelected.begin(); it != idsOfSelected.end(); ++it )
{
selectRowWithId(( *it ) );
selectRowWithId( *it );
}
connect( this, SIGNAL( itemSelectionChanged() ), this, SLOT( handleChangedSelections() ) );

Expand Down Expand Up @@ -226,7 +226,7 @@ void QgsAttributeTable::selectRowWithId( int id )

void QgsAttributeTable::sortColumn( int col, bool ascending )
{
int type = horizontalHeaderItem( col )->data( QgsAttributeTable::AttributeType ).toInt();
int type = horizontalHeaderItem( col )->data( AttributeType ).toInt();
qsort( 0, rowCount() - 1, col, ascending, type != QVariant::Int && type != QVariant::Double );
}

Expand Down Expand Up @@ -437,6 +437,19 @@ void QgsAttributeTable::copySelectedRows()
clipboard->setText( toClipboard, QClipboard::Clipboard );
}

void QgsAttributeTable::addFeatureToTable( QgsVectorLayer *layer, int id )
{
blockSignals( true );

QgsFeature f;
if ( layer->featureAtId( id, f, false, true ) == 0 )
{
putFeatureInTable( rowCount(), f );
}

blockSignals( false );
}

void QgsAttributeTable::fillTable( QgsVectorLayer *layer )
{
blockSignals( true );
Expand All @@ -457,7 +470,7 @@ void QgsAttributeTable::fillTable( QgsVectorLayer *layer )
QTableWidgetItem *twi = new QTableWidgetItem( fldIt->name() );
twi->setData( AttributeIndex, fldIt.key() );
twi->setData( AttributeName, fldIt->name() );
twi->setData( QgsAttributeTable::AttributeType, (int)(fldIt->type()));
twi->setData( AttributeType, ( int ) fldIt->type() );
setHorizontalHeaderItem( h, twi );

mAttrIdxMap.insert( fldIt.key(), h );
Expand Down Expand Up @@ -596,27 +609,26 @@ void QgsAttributeTable::bringSelectedToTop()
blockSignals( false );
}

void QgsAttributeTable::selectRowsWithId( const QgsFeatureIds& ids )
void QgsAttributeTable::selectRowsWithId( const QgsFeatureIds &ids, QgsVectorLayer *layer )
{
/*
#if 0
// if selecting rows takes too much time we can use progress dialog
QProgressDialog progress( tr("Updating selection..."), tr("Abort"), 0, mSelected.size(), tabledisplay);
int i=0;
for(std::set<int>::iterator iter=mSelected.begin();iter!=mSelected.end();++iter)
QProgressDialog progress( tr( "Updating selection..." ), tr( "Abort" ), 0, mSelected.size(), tabledisplay );
int i = 0;
for ( std::set<int>::iterator iter = mSelected.begin();iter != mSelected.end();++iter )
{
++i;
progress.setValue(i);
progress.setValue( i );
qApp->processEvents();
if(progress.wasCanceled())
if ( progress.wasCanceled() )
{
//deselect the remaining features if action was canceled
mSelected.erase(iter,--mSelected.end());
mSelected.erase( iter, --mSelected.end() );
break;
}
selectRowWithId(*iter);//todo: avoid that the table gets repainted during each selection
}
selectRowWithId( *iter );//todo: avoid that the table gets repainted during each selection
}
*/

#endif

// to select more rows at once effectively, we stop sending signals to handleChangedSelections()
// otherwise it will repaint map everytime row is selected
Expand All @@ -627,6 +639,12 @@ void QgsAttributeTable::selectRowsWithId( const QgsFeatureIds& ids )
QgsFeatureIds::const_iterator it;
for ( it = ids.begin(); it != ids.end(); it++ )
{
if ( layer && !rowIdMap.contains( *it ) )
{
// add feature if we do not already have it
addFeatureToTable( layer, *it );
}

selectRowWithId( *it );
}

Expand Down Expand Up @@ -754,7 +772,7 @@ void QgsAttributeTable::addAttribute( int attr, const QgsField &fld )
QTableWidgetItem *twi = new QTableWidgetItem( fld.name() );
twi->setData( AttributeIndex, attr );
twi->setData( AttributeName, fld.name() );
twi->setData( AttributeType, fld.type() );
twi->setData( AttributeType, ( int ) fld.type() );

insertColumn( columnCount() );
setHorizontalHeaderItem( columnCount() - 1, twi );
Expand Down
6 changes: 5 additions & 1 deletion src/app/qgsattributetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,18 @@ class QgsAttributeTable : public QTableWidget
/**Swaps the selected rows such that the selected ones are on the top of the table*/
void bringSelectedToTop();
/** Selects rows with chosen feature IDs */
void selectRowsWithId( const QgsFeatureIds& ids );
void selectRowsWithId( const QgsFeatureIds& ids, QgsVectorLayer *layer = 0 );
/** Shows only rows with chosen feature IDs, others get hidden */
void showRowsWithId( const QgsFeatureIds& ids );
/** Shows all rows */
void showAllRows();

/**Fills the contents of a provider into this table*/
void fillTable( QgsVectorLayer *layer );

/** adds a feature to the current table */
void addFeatureToTable( QgsVectorLayer *layer, int id );

void addAttribute( int idx, const QgsField &fld );
void deleteAttribute( int idx );

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributetabledisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void QgsAttributeTableDisplay::setAttributeActions( const QgsAttributeAction &ac

void QgsAttributeTableDisplay::selectRowsWithId( const QgsFeatureIds &ids )
{
tblAttributes->selectRowsWithId( ids );
tblAttributes->selectRowsWithId( ids, mLayer );
}

void QgsAttributeTableDisplay::setTheme()
Expand Down

0 comments on commit a947a79

Please sign in to comment.