Skip to content
Permalink
Browse files

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...


git-svn-id: http://svn.osgeo.org/qgis/trunk@11138 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jul 21, 2009
1 parent 8b1fb78 commit 8a803aa522b0e10d20a10aae3c3e5dcefc1c8f64
@@ -32,6 +32,8 @@ void QgsAttributeTableMemoryModel::loadLayer()
QgsAttributeTableModel::loadLayer();
mLayer->select( mLayer->pendingAllAttributesList(), QgsRectangle(), false );

mFeatureMap.reserve( mLayer->pendingFeatureCount() + 50 );

QgsFeature f;
while ( mLayer->nextFeature( f ) )
mFeatureMap.insert( f.id(), f );
@@ -20,6 +20,7 @@
#include <QAbstractTableModel>
#include <QModelIndex>
#include <QObject>
#include <QHash>

//QGIS Includes
#include "qgsfeature.h" //QgsAttributeMap
@@ -98,7 +99,7 @@ class QgsAttributeTableMemoryModel: public QgsAttributeTableModel
*/
virtual void loadLayer();

QMap<int, QgsFeature> mFeatureMap;
QHash<int, QgsFeature> mFeatureMap;
};

#endif //QGSATTRIBUTETABLEMEMORYMODEL_H
@@ -82,7 +82,7 @@ void QgsAttributeTableModel::featureDeleted( int fid )
#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 @@ void QgsAttributeTableModel::loadLayer()

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 @@ void QgsAttributeTableModel::loadLayer()

#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 @@ int QgsAttributeTableModel::rowToId( const int id ) const
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];
@@ -20,6 +20,7 @@
#include <QAbstractTableModel>
#include <QModelIndex>
#include <QObject>
#include <QHash>

//QGIS Includes
#include "qgsfeature.h" //QgsAttributeMap
@@ -185,8 +186,8 @@ class QgsAttributeTableModel: public QAbstractTableModel
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

0 comments on commit 8a803aa

Please sign in to comment.
You can’t perform that action at this time.