Skip to content
Permalink
Browse files
[FEATURE] add row cache for attribute table
  • Loading branch information
jef-n committed Nov 24, 2011
1 parent 1717d3c commit 90481072533765c2d1eca58dfa3c36d00d30c8d6
@@ -203,6 +203,7 @@
<file>themes/default/propertyicons/rendering.png</file>
<file>themes/default/propertyicons/symbology.png</file>
<file>themes/default/propertyicons/transparency.png</file>
<file>themes/default/propertyicons/gdal.png</file>
<file>themes/default/qgis.xpm</file>
<file>themes/default/rendererCategorizedSymbol.png</file>
<file>themes/default/rendererGraduatedSymbol.png</file>
5 src/app/qgsoptions.cpp 100644 → 100755
@@ -67,7 +67,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
cmbSize->addItem( "32" );

QStringList styles = QStyleFactory::keys();
foreach(QString style, styles )
foreach( QString style, styles )
{
cmbStyle->addItem( style );
}
@@ -182,6 +182,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
cmbAttrTableBehaviour->addItem( tr( "Show features in current canvas" ) );
cmbAttrTableBehaviour->setCurrentIndex( settings.value( "/qgis/attributeTableBehaviour", 0 ).toInt() );

spinBoxAttrTableRowCache->setValue( settings.value( "/qgis/attributeTableRowCache", 10000 ).toInt() );

// set the display update threshold
spinBoxUpdateThreshold->setValue( settings.value( "/Map/updateThreshold" ).toInt() );
//set the default projection behaviour radio buttongs
@@ -584,6 +586,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/showTips", cbxShowTips->isChecked() );
settings.setValue( "/qgis/dockAttributeTable", cbxAttributeTableDocked->isChecked() );
settings.setValue( "/qgis/attributeTableBehaviour", cmbAttrTableBehaviour->currentIndex() );
settings.setValue( "/qgis/attributeTableRowCache", spinBoxAttrTableRowCache->value() );
settings.setValue( "/qgis/dockIdentifyResults", cbxIdentifyResultsDocked->isChecked() );
settings.setValue( "/qgis/dockSnapping", cbxSnappingOptionsDocked->isChecked() );
settings.setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() );
@@ -81,8 +81,6 @@ class QgsAttributeTableMemoryModel : public QgsAttributeTableModel
* Loads the layer into the model
*/
virtual void loadLayer();

QHash<QgsFeatureId, QgsFeature> mFeatureMap;
};

#endif //QGSATTRIBUTETABLEMEMORYMODEL_H
@@ -33,6 +33,9 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayer *theLayer, QObjec
: QAbstractTableModel( parent )
{
mFeat.setFeatureId( std::numeric_limits<int>::min() );
mFeatureMap.clear();
mFeatureQueue.clear();

mLayer = theLayer;
loadAttributes();

@@ -50,9 +53,33 @@ bool QgsAttributeTableModel::featureAtId( QgsFeatureId fid ) const
QgsDebugMsgLevel( QString( "loading feature %1" ).arg( fid ), 3 );

if ( fid == std::numeric_limits<int>::min() )
{
return false;
}
else if ( mFeatureMap.contains( fid ) )
{
mFeat = mFeatureMap[ fid ];
return true;
}
else if ( mLayer->featureAtId( fid, mFeat, false, true ) )
{
QSettings settings;
int cacheSize = settings.value( "/qgis/attributeTableRowCache", "10000" ).toInt();

if ( mFeatureQueue.size() == cacheSize )
{
mFeatureMap.remove( mFeatureQueue.dequeue() );
}

mFeatureQueue.enqueue( fid );
mFeatureMap.insert( fid, mFeat );

return true;
}
else
return mLayer->featureAtId( fid, mFeat, false, true );
{
return false;
}
}

void QgsAttributeTableModel::featureDeleted( QgsFeatureId fid )
@@ -152,6 +179,10 @@ void QgsAttributeTableModel::layerDeleted()

void QgsAttributeTableModel::attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value )
{
if ( mFeatureMap.contains( fid ) )
{
mFeatureMap[ fid ].changeAttribute( fieldCol( idx ), value );
}
setData( index( idToRow( fid ), fieldCol( idx ) ), value, Qt::EditRole );
}

@@ -21,6 +21,7 @@
#include <QModelIndex>
#include <QObject>
#include <QHash>
#include <QQueue>

#include "qgsfeature.h" // QgsAttributeMap
#include "qgsvectorlayer.h" // QgsAttributeList
@@ -196,6 +197,7 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
int mFieldCount;

mutable QgsFeature mFeat;
mutable QHash<QgsFeatureId, QgsFeature> mFeatureMap;

QgsAttributeList mAttributes;
QMap< int, const QMap<QString, QVariant> * > mValueMaps;
@@ -228,6 +230,10 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
* @return feature exists
*/
virtual bool featureAtId( QgsFeatureId fid ) const;

private:
mutable QQueue<QgsFeatureId> mFeatureQueue;

};


0 comments on commit 9048107

Please sign in to comment.