[QGIS Commit] r13547 - in trunk/qgis/src: app app/attributetable ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat May 22 11:45:49 EDT 2010


Author: jef
Date: 2010-05-22 11:45:49 -0400 (Sat, 22 May 2010)
New Revision: 13547

Modified:
   trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp
   trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h
   trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
   trunk/qgis/src/app/attributetable/qgsattributetablemodel.h
   trunk/qgis/src/app/qgsoptions.cpp
   trunk/qgis/src/ui/qgsoptionsbase.ui
Log:
[FEATURE] forward port r9689 to model based attribute table

Modified: trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp	2010-05-22 15:41:42 UTC (rev 13546)
+++ trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp	2010-05-22 15:45:49 UTC (rev 13547)
@@ -60,6 +60,7 @@
   }
 }
 
+#if 0
 void QgsAttributeTableMemoryModel::featureDeleted( int fid )
 {
   QgsDebugMsg( "entered." );
@@ -75,6 +76,7 @@
   mFeatureMap.insert( fid, f );
   QgsAttributeTableModel::featureAdded( fid );
 }
+#endif
 
 void QgsAttributeTableMemoryModel::layerDeleted()
 {

Modified: trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h	2010-05-22 15:41:42 UTC (rev 13546)
+++ trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h	2010-05-22 15:45:49 UTC (rev 13547)
@@ -40,6 +40,7 @@
     QgsAttributeTableMemoryModel( QgsVectorLayer *theLayer );
 
   protected slots:
+#if 0
     /**
      * Launched when a feature has been deleted
      * @param fid feature id
@@ -50,6 +51,7 @@
      * @param fid feature id
      */
     virtual void featureAdded( int fid );
+#endif
     /**
      * Launched when layer has been deleted
      */

Modified: trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2010-05-22 15:41:42 UTC (rev 13546)
+++ trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2010-05-22 15:45:49 UTC (rev 13547)
@@ -21,6 +21,7 @@
 #include "qgslogger.h"
 #include "qgisapp.h"
 #include "qgsattributeaction.h"
+#include "qgsmapcanvas.h"
 
 #include <QtGui>
 #include <QVariant>
@@ -35,10 +36,8 @@
 {
   mFeat.setFeatureId( std::numeric_limits<int>::min() );
   mLayer = theLayer;
-  mFeatureCount = mLayer->pendingFeatureCount();
   loadAttributes();
 
-
   connect( mLayer, SIGNAL( layerModified( bool ) ), this, SLOT( layerModified( bool ) ) );
   //connect(mLayer, SIGNAL(attributeValueChanged(int, int, const QVariant&)), this, SLOT( attributeValueChanged(int, int, const QVariant&)));
   //connect(mLayer, SIGNAL(featureDeleted(int)), this, SLOT( featureDeleted(int)));
@@ -52,6 +51,7 @@
   return mLayer->featureAtId( fid, mFeat, false, true );
 }
 
+#if 0
 void QgsAttributeTableModel::featureDeleted( int fid )
 {
   QgsDebugMsg( "entered." );
@@ -83,6 +83,7 @@
   QgsDebugMsg( QString( "map sizes:%1, %2" ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ) );
   reload( index( 0, 0 ), index( rowCount(), columnCount() ) );
 }
+#endif
 
 void QgsAttributeTableModel::attributeAdded( int idx )
 {
@@ -189,37 +190,56 @@
   QgsFeature f;
   bool ins = false, rm = false;
 
+  int previousSize = mRowIdMap.size();
+
   mRowIdMap.clear();
   mIdRowMap.clear();
 
-  int pendingFeatureCount = mLayer->pendingFeatureCount();
-  if ( mFeatureCount < pendingFeatureCount )
+  QSettings settings;
+  int behaviour = settings.value( "/qgis/attributeTableBehaviour", 0 ).toInt();
+
+  if ( behaviour == 1 )
   {
+    const QgsFeatureList &features = mLayer->selectedFeatures();
+
+    for ( int i = 0; i < features.size(); ++i )
+    {
+      mRowIdMap.insert( i, features[i].id() );
+      mIdRowMap.insert( features[i].id(), i );
+    }
+  }
+  else
+  {
+    QgsRectangle rect;
+    if ( behaviour == 2 )
+    {
+      // current canvas only
+      rect = QgisApp::instance()->mapCanvas()->extent();
+    }
+
+    mLayer->select( mAttributes, rect, false );
+
+    for ( int i = 0; mLayer->nextFeature( f ); ++i )
+    {
+      mRowIdMap.insert( i, f.id() );
+      mIdRowMap.insert( f.id(), i );
+    }
+  }
+
+  if ( previousSize < mRowIdMap.size() )
+  {
     QgsDebugMsg( "ins" );
     ins = true;
-    beginInsertRows( QModelIndex(), mFeatureCount, pendingFeatureCount - 1 );
+    beginInsertRows( QModelIndex(), previousSize, mRowIdMap.size() - 1 );
   }
-  else if ( mFeatureCount > pendingFeatureCount )
+  else if ( previousSize > mRowIdMap.size() )
   {
     QgsDebugMsg( "rm" );
     rm = true;
-    beginRemoveRows( QModelIndex(), pendingFeatureCount, mFeatureCount - 1 );
+    beginRemoveRows( QModelIndex(), mRowIdMap.size(), previousSize - 1 );
   }
 
-  mLayer->select( mAttributes, QgsRectangle(), false );
-
-  // preallocate data before inserting
-  mRowIdMap.reserve( pendingFeatureCount + 50 );
-  mIdRowMap.reserve( pendingFeatureCount + 50 );
-
-  for ( int i = 0; mLayer->nextFeature( f ); ++i )
-  {
-    mRowIdMap.insert( i, f.id() );
-    mIdRowMap.insert( f.id(), i );
-  }
-
   // not needed when we have featureAdded signal
-  mFeatureCount = mLayer->pendingFeatureCount();
   mFieldCount = mAttributes.size();
 
   if ( ins )
@@ -287,7 +307,7 @@
 
 int QgsAttributeTableModel::rowCount( const QModelIndex &parent ) const
 {
-  return mFeatureCount;
+  return mRowIdMap.size();
 }
 
 int QgsAttributeTableModel::columnCount( const QModelIndex &parent ) const

Modified: trunk/qgis/src/app/attributetable/qgsattributetablemodel.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablemodel.h	2010-05-22 15:41:42 UTC (rev 13546)
+++ trunk/qgis/src/app/attributetable/qgsattributetablemodel.h	2010-05-22 15:45:49 UTC (rev 13547)
@@ -166,6 +166,7 @@
     virtual void layerModified( bool onlyGeometry );
 
   protected slots:
+#if 0
     /**
      * Launched when a feature has been deleted
      * @param fid feature id
@@ -176,6 +177,7 @@
      * @param fid feature id
      */
     virtual void featureAdded( int fid );
+#endif
     /**
      * Launched when layer has been deleted
      */
@@ -183,7 +185,6 @@
 
   protected:
     QgsVectorLayer *mLayer;
-    int mFeatureCount;
     int mFieldCount;
 
     mutable QgsFeature mFeat;

Modified: trunk/qgis/src/app/qgsoptions.cpp
===================================================================
--- trunk/qgis/src/app/qgsoptions.cpp	2010-05-22 15:41:42 UTC (rev 13546)
+++ trunk/qgis/src/app/qgsoptions.cpp	2010-05-22 15:45:49 UTC (rev 13547)
@@ -142,6 +142,13 @@
   // set the current theme
   cmbTheme->setItemText( cmbTheme->currentIndex(), settings.value( "/Themes" ).toString() );
 
+  // set the attribute table behaviour
+  cmbAttrTableBehaviour->clear();
+  cmbAttrTableBehaviour->addItem( tr( "Show all features" ) );
+  cmbAttrTableBehaviour->addItem( tr( "Show selected features" ) );
+  cmbAttrTableBehaviour->addItem( tr( "Show features in current canvas" ) );
+  cmbAttrTableBehaviour->setCurrentIndex( settings.value( "/qgis/attributeTableBehaviour", 0 ).toInt() );
+
   // set the display update threshold
   spinBoxUpdateThreshold->setValue( settings.value( "/Map/updateThreshold" ).toInt() );
   //set the default projection behaviour radio buttongs
@@ -478,6 +485,7 @@
   settings.setValue( "/qgis/showLegendClassifiers", cbxLegendClassifiers->isChecked() );
   settings.setValue( "/qgis/hideSplash", cbxHideSplash->isChecked() );
   settings.setValue( "/qgis/dockAttributeTable", cbxAttributeTableDocked->isChecked() );
+  settings.setValue( "/qgis/attributeTableBehaviour", cmbAttrTableBehaviour->currentIndex() );
   settings.setValue( "/qgis/dockIdentifyResults", cbxIdentifyResultsDocked->isChecked() );
   settings.setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() );
   settings.setValue( "/qgis/addNewLayersToCurrentGroup", cbxAddNewLayersToCurrentGroup->isChecked() );

Modified: trunk/qgis/src/ui/qgsoptionsbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsoptionsbase.ui	2010-05-22 15:41:42 UTC (rev 13546)
+++ trunk/qgis/src/ui/qgsoptionsbase.ui	2010-05-22 15:45:49 UTC (rev 13547)
@@ -414,6 +414,48 @@
             </property>
            </widget>
           </item>
+          <item>
+           <layout class="QHBoxLayout" name="horizontalLayout_5">
+            <item>
+             <widget class="QLabel" name="textLabel1_7">
+              <property name="sizePolicy">
+               <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+                <horstretch>0</horstretch>
+                <verstretch>0</verstretch>
+               </sizepolicy>
+              </property>
+              <property name="text">
+               <string>Attribute table behaviour</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <spacer name="horizontalSpacer_4">
+              <property name="orientation">
+               <enum>Qt::Horizontal</enum>
+              </property>
+              <property name="sizeHint" stdset="0">
+               <size>
+                <width>40</width>
+                <height>20</height>
+               </size>
+              </property>
+             </spacer>
+            </item>
+            <item>
+             <widget class="QComboBox" name="cmbAttrTableBehaviour">
+              <property name="duplicatesEnabled">
+               <bool>false</bool>
+              </property>
+              <item>
+               <property name="text">
+                <string/>
+               </property>
+              </item>
+             </widget>
+            </item>
+           </layout>
+          </item>
          </layout>
         </widget>
        </item>



More information about the QGIS-commit mailing list