[QGIS Commit] r9598 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Nov 8 14:05:49 EST 2008


Author: jef
Date: 2008-11-08 14:05:49 -0500 (Sat, 08 Nov 2008)
New Revision: 9598

Modified:
   trunk/qgis/src/app/qgsattributetable.cpp
   trunk/qgis/src/app/qgsattributetable.h
   trunk/qgis/src/app/qgsattributetabledisplay.cpp
Log:
partly fix #1377, #1382 and #1306

Modified: trunk/qgis/src/app/qgsattributetable.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributetable.cpp	2008-11-08 18:55:36 UTC (rev 9597)
+++ trunk/qgis/src/app/qgsattributetable.cpp	2008-11-08 19:05:49 UTC (rev 9598)
@@ -171,7 +171,7 @@
   QList < int >::iterator it;
   for ( it = idsOfSelected.begin(); it != idsOfSelected.end(); ++it )
   {
-    selectRowWithId(( *it ) );
+    selectRowWithId( *it );
   }
   connect( this, SIGNAL( itemSelectionChanged() ), this, SLOT( handleChangedSelections() ) );
 
@@ -226,7 +226,7 @@
 
 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 );
 }
 
@@ -437,6 +437,19 @@
   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 );
@@ -457,7 +470,7 @@
     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 );
@@ -596,28 +609,27 @@
   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
 
@@ -627,6 +639,12 @@
   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 );
   }
 
@@ -754,7 +772,7 @@
   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 );

Modified: trunk/qgis/src/app/qgsattributetable.h
===================================================================
--- trunk/qgis/src/app/qgsattributetable.h	2008-11-08 18:55:36 UTC (rev 9597)
+++ trunk/qgis/src/app/qgsattributetable.h	2008-11-08 19:05:49 UTC (rev 9598)
@@ -87,7 +87,7 @@
     /**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 */
@@ -95,6 +95,10 @@
 
     /**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 );
 

Modified: trunk/qgis/src/app/qgsattributetabledisplay.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributetabledisplay.cpp	2008-11-08 18:55:36 UTC (rev 9597)
+++ trunk/qgis/src/app/qgsattributetabledisplay.cpp	2008-11-08 19:05:49 UTC (rev 9598)
@@ -244,7 +244,7 @@
 
 void QgsAttributeTableDisplay::selectRowsWithId( const QgsFeatureIds &ids )
 {
-  tblAttributes->selectRowsWithId( ids );
+  tblAttributes->selectRowsWithId( ids, mLayer );
 }
 
 void QgsAttributeTableDisplay::setTheme()



More information about the QGIS-commit mailing list