[QGIS Commit] r11138 - trunk/qgis/src/app/attributetable

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Jul 21 11:28:02 EDT 2009


Author: wonder
Date: 2009-07-21 11:28:02 -0400 (Tue, 21 Jul 2009)
New Revision: 11138

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
Log:
Moved from QMap to QHash for the row-id maps and feature map in models.
There might be a tiny speed up in attribute table loading...


Modified: trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp	2009-07-21 14:29:38 UTC (rev 11137)
+++ trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.cpp	2009-07-21 15:28:02 UTC (rev 11138)
@@ -32,6 +32,8 @@
   QgsAttributeTableModel::loadLayer();
   mLayer->select( mLayer->pendingAllAttributesList(), QgsRectangle(), false );
 
+  mFeatureMap.reserve( mLayer->pendingFeatureCount() + 50 );
+
   QgsFeature f;
   while ( mLayer->nextFeature( f ) )
     mFeatureMap.insert( f.id(), f );

Modified: trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h	2009-07-21 14:29:38 UTC (rev 11137)
+++ trunk/qgis/src/app/attributetable/qgsattributetablememorymodel.h	2009-07-21 15:28:02 UTC (rev 11138)
@@ -20,6 +20,7 @@
 #include <QAbstractTableModel>
 #include <QModelIndex>
 #include <QObject>
+#include <QHash>
 
 //QGIS Includes
 #include "qgsfeature.h" //QgsAttributeMap
@@ -98,7 +99,7 @@
      */
     virtual void loadLayer();
 
-    QMap<int, QgsFeature> mFeatureMap;
+    QHash<int, QgsFeature> mFeatureMap;
 };
 
 #endif //QGSATTRIBUTETABLEMEMORYMODEL_H

Modified: trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2009-07-21 14:29:38 UTC (rev 11137)
+++ trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2009-07-21 15:28:02 UTC (rev 11138)
@@ -82,7 +82,7 @@
 #endif
 
   QgsDebugMsg( "id->row" );
-  QMap<int, int>::iterator it;
+  QHash<int, int>::iterator it;
   for ( it = mIdRowMap.begin(); it != mIdRowMap.end(); ++it )
     QgsDebugMsg( QString( "%1->%2" ).arg( it.key() ).arg( *it ) );
 
@@ -175,6 +175,10 @@
 
   mLayer->select( QgsAttributeList(), 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() );
@@ -198,7 +202,7 @@
 
 #if 0
   QgsDebugMsg( "id->row" );
-  QMap<int, int>::iterator it;
+  QHash<int, int>::iterator it;
   for ( it = mIdRowMap.begin(); it != mIdRowMap.end(); ++it )
     QgsDebugMsg( QString( "%1->%2" ).arg( it.key() ).arg( *it ) );
 
@@ -248,7 +252,8 @@
   if ( !mRowIdMap.contains( id ) )
   {
     QgsDebugMsg( QString( "rowToId: row %1 not in the map" ).arg( id ) );
-    return -1;
+    // return negative infinite (to avoid collision with newly added features)
+    return -999999;
   }
 
   return mRowIdMap[id];

Modified: trunk/qgis/src/app/attributetable/qgsattributetablemodel.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablemodel.h	2009-07-21 14:29:38 UTC (rev 11137)
+++ trunk/qgis/src/app/attributetable/qgsattributetablemodel.h	2009-07-21 15:28:02 UTC (rev 11138)
@@ -20,6 +20,7 @@
 #include <QAbstractTableModel>
 #include <QModelIndex>
 #include <QObject>
+#include <QHash>
 
 //QGIS Includes
 #include "qgsfeature.h" //QgsAttributeMap
@@ -185,8 +186,8 @@
     QgsAttributeList mAttributes;
 
     QList<QgsAttributeTableIdColumnPair> mSortList;
-    QMap<int, int> mIdRowMap;
-    QMap<int, int> mRowIdMap;
+    QHash<int, int> mIdRowMap;
+    QHash<int, int> mRowIdMap;
 
     /**
      * Initializes id <-> row maps



More information about the QGIS-commit mailing list