Skip to content
Permalink
Browse files

QgsFeature: use a vector of attributes instead of a map (for faster a…

…ccess)
  • Loading branch information
wonder-sk committed Oct 18, 2012
1 parent 4bc60ff commit 8bf959093f1a0ec2e00f55d334fc2a555d7b1bab
Showing with 685 additions and 809 deletions.
  1. +3 −3 python/core/diagram/qgsdiagram.sip
  2. +3 −3 python/core/diagram/qgshistogramdiagram.sip
  3. +3 −3 python/core/diagram/qgspiediagram.sip
  4. +3 −3 python/core/diagram/qgstextdiagram.sip
  5. +8 −8 python/core/qgsdiagramrendererv2.sip
  6. +15 −39 python/core/qgsfeature.sip
  7. 0 scripts/astyle.sh
  8. +2 −1 src/analysis/interpolation/DualEdgeTriangulation.cc
  9. +3 −4 src/analysis/interpolation/qgsinterpolator.cpp
  10. +3 −4 src/analysis/interpolation/qgstininterpolator.cpp
  11. +12 −20 src/analysis/network/qgslinevectorlayerdirector.cpp
  12. +37 −37 src/analysis/vector/qgsgeometryanalyzer.cpp
  13. +6 −15 src/analysis/vector/qgsoverlayanalyzer.cpp
  14. +1 −1 src/analysis/vector/qgsoverlayanalyzer.h
  15. +10 −9 src/app/qgisapp.cpp
  16. +3 −3 src/app/qgsattributedialog.cpp
  17. +2 −2 src/app/qgsattributetypedialog.cpp
  18. +4 −4 src/app/qgsattributetypeloaddialog.cpp
  19. +3 −3 src/app/qgsclipboard.cpp
  20. +11 −13 src/app/qgsfeatureaction.cpp
  21. +1 −2 src/app/qgsgraduatedsymboldialog.cpp
  22. +10 −9 src/app/qgsidentifyresults.cpp
  23. +1 −1 src/app/qgslabelpropertydialog.cpp
  24. +7 −12 src/app/qgsmaptoollabel.cpp
  25. +3 −3 src/app/qgsmaptooloffsetcurve.cpp
  26. +3 −4 src/app/qgsmaptoolrotatepointsymbols.cpp
  27. +8 −6 src/app/qgsmergeattributesdialog.cpp
  28. +1 −1 src/app/qgsmergeattributesdialog.h
  29. +3 −3 src/core/composer/qgscomposerattributetable.cpp
  30. +2 −2 src/core/composer/qgscomposerattributetable.h
  31. +3 −3 src/core/diagram/qgsdiagram.h
  32. +11 −13 src/core/diagram/qgshistogramdiagram.cpp
  33. +3 −3 src/core/diagram/qgshistogramdiagram.h
  34. +6 −6 src/core/diagram/qgspiediagram.cpp
  35. +3 −3 src/core/diagram/qgspiediagram.h
  36. +6 −6 src/core/diagram/qgstextdiagram.cpp
  37. +3 −3 src/core/diagram/qgstextdiagram.h
  38. +3 −2 src/core/qgsattributeaction.cpp
  39. +6 −6 src/core/qgsdiagramrendererv2.cpp
  40. +8 −8 src/core/qgsdiagramrendererv2.h
  41. +6 −6 src/core/qgsexpression.cpp
  42. +13 −44 src/core/qgsfeature.cpp
  43. +16 −32 src/core/qgsfeature.h
  44. +1 −11 src/core/qgslabel.cpp
  45. +22 −27 src/core/qgspallabeling.cpp
  46. +5 −5 src/core/qgsvectordataprovider.cpp
  47. +3 −9 src/core/qgsvectorfilewriter.cpp
  48. +55 −52 src/core/qgsvectorlayer.cpp
  49. +4 −4 src/core/qgsvectorlayer.h
  50. +7 −6 src/core/qgsvectorlayerimport.cpp
  51. +15 −16 src/core/qgsvectorlayerjoinbuffer.cpp
  52. +1 −1 src/core/renderer/qgscontinuouscolorrenderer.cpp
  53. +4 −8 src/core/renderer/qgsgraduatedsymbolrenderer.cpp
  54. +3 −6 src/core/renderer/qgssinglesymbolrenderer.cpp
  55. +4 −8 src/core/renderer/qgsuniquevaluerenderer.cpp
  56. +6 −7 src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
  57. +7 −7 src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
  58. +6 −7 src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
  59. +3 −7 src/core/symbology-ng/qgspointdisplacementrenderer.cpp
  60. +2 −2 src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
  61. +2 −2 src/core/symbology-ng/qgsvectorfieldsymbollayer.cpp
  62. +1 −1 src/gui/attributetable/qgsattributetablememorymodel.cpp
  63. +5 −5 src/gui/attributetable/qgsattributetablemodel.cpp
  64. +2 −2 src/gui/qgsattributeeditor.cpp
  65. +4 −5 src/gui/qgsformannotationitem.cpp
  66. +1 −1 src/gui/qgsmaptip.cpp
  67. +1 −2 src/gui/qgssearchquerybuilder.cpp
  68. +1 −1 src/mapserver/qgsfilter.cpp
  69. +11 −10 src/mapserver/qgswfsserver.cpp
  70. +6 −6 src/mapserver/qgswmsserver.cpp
  71. +13 −13 src/plugins/diagram_overlay/qgsbardiagramfactory.cpp
  72. +2 −2 src/plugins/diagram_overlay/qgsbardiagramfactory.h
  73. +7 −9 src/plugins/diagram_overlay/qgsdiagramrenderer.cpp
  74. +5 −6 src/plugins/diagram_overlay/qgspiediagramfactory.cpp
  75. +23 −24 src/plugins/evis/eventbrowser/evisgenericeventbrowsergui.cpp
  76. +1 −1 src/plugins/grass/qgsgrassmodule.cpp
  77. +2 −4 src/plugins/heatmap/heatmap.cpp
  78. +11 −10 src/plugins/offline_editing/offline_editing.cpp
  79. +3 −4 src/plugins/roadgraph/speedproperter.cpp
  80. +2 −1 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  81. +50 −47 src/providers/gpx/qgsgpxprovider.cpp
  82. +1 −1 src/providers/grass/qgsgrassfeatureiterator.cpp
  83. +12 −6 src/providers/grass/qgsgrassprovider.cpp
  84. +1 −1 src/providers/memory/qgsmemoryprovider.cpp
  85. +2 −2 src/providers/ogr/qgsogrfeatureiterator.cpp
  86. +8 −9 src/providers/ogr/qgsogrprovider.cpp
  87. +1 −2 src/providers/osm/osmrenderer.cpp
  88. +9 −9 src/providers/postgres/qgspostgresfeatureiterator.cpp
  89. +28 −24 src/providers/postgres/qgspostgresprovider.cpp
  90. +3 −3 src/providers/spatialite/qgsspatialitefeatureiterator.cpp
  91. +17 −10 src/providers/spatialite/qgsspatialiteprovider.cpp
  92. +0 −14 src/providers/wfs/qgswfsdata.cpp
  93. +2 −2 src/providers/wfs/qgswfsprovider.cpp
  94. +2 −1 tests/src/core/regression1141.cpp
  95. +22 −21 tests/src/core/testqgsexpression.cpp
  96. +2 −1 tests/src/core/testqgsmaprenderer.cpp
  97. +3 −3 tests/src/core/testqgsrulebasedrenderer.cpp
  98. +3 −3 tests/src/core/testqgsvectordataprovider.cpp
  99. +10 −5 tests/src/core/testqgsvectorfilewriter.cpp
@@ -6,12 +6,12 @@ class QgsDiagram
public:
virtual ~QgsDiagram();
/**Draws the diagram at the given position (in pixel coordinates)*/
virtual void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position ) = 0;
virtual void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position ) = 0;
virtual QString diagramName() const = 0;
/**Returns the size in map units the diagram will use to render.*/
virtual QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s ) = 0;
virtual QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s ) = 0;
/**Returns the size in map units the diagram will use to render. Interpolate size*/
virtual QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) = 0;
virtual QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) = 0;

protected:
/** Changes the pen width to match the current settings and rendering context
@@ -7,8 +7,8 @@ class QgsHistogramDiagram: QgsDiagram
QgsHistogramDiagram();
~QgsHistogramDiagram();

void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position );
QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
QString diagramName() const;
};
@@ -7,8 +7,8 @@ class QgsPieDiagram: QgsDiagram
QgsPieDiagram();
~QgsPieDiagram();

void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position );
QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
QString diagramName() const;
};
@@ -20,9 +20,9 @@ class QgsTextDiagram: QgsDiagram

QgsTextDiagram();
~QgsTextDiagram();
void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position );
QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );

QString diagramName() const;
};
@@ -119,14 +119,14 @@ class QgsDiagramRendererV2
virtual ~QgsDiagramRendererV2();

/**Returns size of the diagram for feature f in map units. Returns an invalid QSizeF in case of error*/
virtual QSizeF sizeMapUnits( const QgsAttributeMap& attributes, const QgsRenderContext& c );
virtual QSizeF sizeMapUnits( const QgsAttributes& attributes, const QgsRenderContext& c );

virtual QString rendererName() const = 0;

/**Returns attribute indices needed for diagram rendering*/
virtual QList<int> diagramAttributes() const = 0;

void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QPointF& pos );
void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QPointF& pos );

void setDiagram( QgsDiagram* d );
const QgsDiagram* diagram() const;
@@ -144,10 +144,10 @@ class QgsDiagramRendererV2
* @param c render context
* @param s out: diagram settings for the feature
*/
virtual bool diagramSettings( const QgsAttributeMap& att, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
virtual bool diagramSettings( const QgsAttributes& att, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;

/**Returns size of the diagram (in painter units) or an invalid size in case of error*/
virtual QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c ) = 0;
virtual QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c ) = 0;

/**Converts size from mm to map units*/
void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
@@ -183,9 +183,9 @@ class QgsSingleCategoryDiagramRenderer : QgsDiagramRendererV2
void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;

protected:
bool diagramSettings( const QgsAttributeMap&, const QgsRenderContext& c, QgsDiagramSettings& s );
bool diagramSettings( const QgsAttributes&, const QgsRenderContext& c, QgsDiagramSettings& s );

QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c );
};

class QgsLinearlyInterpolatedDiagramRenderer : QgsDiagramRendererV2
@@ -226,7 +226,7 @@ class QgsLinearlyInterpolatedDiagramRenderer : QgsDiagramRendererV2
void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;

protected:
bool diagramSettings( const QgsAttributeMap&, const QgsRenderContext& c, QgsDiagramSettings& s );
bool diagramSettings( const QgsAttributes&, const QgsRenderContext& c, QgsDiagramSettings& s );

QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c );
};
@@ -3,6 +3,8 @@
// key = field index, value = field value
typedef QMap<int, QVariant> QgsAttributeMap;

typedef QVector<QVariant> QgsAttributes;

// key = feature id, value = changed attributes
typedef QMap<qint64, QMap<int, QVariant> > QgsChangedAttributesMap;

@@ -30,13 +32,12 @@ class QgsFeature

SIP_PYOBJECT __getitem__(int key);
%MethodCode
const QgsAttributeMap& attrMap = sipCpp->attributeMap();
QgsAttributeMap::const_iterator it = attrMap.find(a0);
if (it == attrMap.end())
const QgsAttributes& attrs = sipCpp->attributes();
if (a0 < 0 || a0 >= attrs.count())
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
else
{
QVariant* v = new QVariant(it.value());
QVariant* v = new QVariant(attrs[a0]);
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
}
%End
@@ -48,14 +49,14 @@ class QgsFeature
PyErr_SetString(PyExc_KeyError, a0->toAscii());
else
{
QVariant* v = new QVariant( sipCpp->attributeMap().value(fieldIdx) );
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
}
%End

void __setitem__(int key, QVariant value);
%MethodCode
sipCpp->addAttribute(a0, *a1);
sipCpp->setAttribute(a0, *a1);
%End

void __setitem__(const QString& key, QVariant value);
@@ -65,13 +66,13 @@ class QgsFeature
PyErr_SetString(PyExc_KeyError, a0->toAscii());
else
{
sipCpp->addAttribute(fieldIdx, *a1);
sipCpp->setAttribute(fieldIdx, *a1);
}
%End

void __delitem__(int key);
%MethodCode
if (sipCpp->attributeMap().contains(a0))
if (a0 >= 0 && a0 < sipCpp->attributes().count())
sipCpp->deleteAttribute(a0);
else
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
@@ -107,34 +108,15 @@ class QgsFeature
*/
void setFeatureId( qint64 id );

/**
* Get the attributes for this feature.
* @return A std::map containing the field name/value mapping
*/
const QMap<int, QVariant> & attributeMap() const;


/**Sets all the attributes in one go*/
void setAttributeMap( const QMap<int, QVariant> & attributeMap );

/** Clear attribute map
* added in 1.5
*/
void clearAttributeMap();

/**
* Add an attribute to the map
*/
void addAttribute( int field, QVariant attr );
const QgsAttributes& attributes() const;
//QgsAttributes& attributes();
void setAttributes(const QgsAttributes& attrs);
void setAttribute( int field, const QVariant& attr );
void initAttributes( int fieldCount );

/**Deletes an attribute and its value*/
void deleteAttribute( int field );

/**Changes an existing attribute value
@param field index of the field
@param attr attribute name and value to be set */
void changeAttribute( int field, QVariant attr );

/**
* Return the validity of this feature. This is normally set by
* the provider to indicate some problem that makes the feature
@@ -188,13 +170,7 @@ class QgsFeature
* Field map must be associated to make this work.
* @note added in 2.0
*/
bool addAttribute( const QString& name, QVariant value );

/** Change a value of an attribute. Returns false if attribute name could not be converted to index.
* Field map must be associated to make this work.
* @note added in 2.0
*/
bool changeAttribute( const QString& name, QVariant value );
bool setAttribute( const QString& name, QVariant value );

/** Remove an attribute value. Returns false if attribute name could not be converted to index.
* Field map must be associated to make this work.
0 scripts/astyle.sh 100644 → 100755
No changes.
@@ -3134,6 +3134,7 @@ bool DualEdgeTriangulation::saveAsShapefile( const QString& fileName ) const
lineGeom.push_back( QgsPoint( p2->getX(), p2->getY() ) );
QgsGeometry* geom = QgsGeometry::fromPolyline( lineGeom );
edgeLineFeature.setGeometry( geom );
edgeLineFeature.initAttributes( 1 );

//attributes
QString attributeString;
@@ -3148,7 +3149,7 @@ bool DualEdgeTriangulation::saveAsShapefile( const QString& fileName ) const
attributeString = "structure line";
}
}
edgeLineFeature.addAttribute( 0, attributeString );
edgeLineFeature.setAttribute( 0, attributeString );

writer.addFeature( edgeLineFeature );
}
@@ -77,13 +77,12 @@ int QgsInterpolator::cacheBaseData()
{
if ( !v_it->zCoordInterpolation )
{
QgsAttributeMap attMap = theFeature.attributeMap();
QgsAttributeMap::const_iterator att_it = attMap.find( v_it->interpolationAttribute );
if ( att_it == attMap.end() ) //attribute not found, something must be wrong (e.g. NULL value)
QVariant attributeVariant = theFeature.attribute( v_it->interpolationAttribute );
if ( !attributeVariant.isValid() ) //attribute not found, something must be wrong (e.g. NULL value)
{
continue;
}
attributeValue = att_it.value().toDouble( &attributeConversionOk );
attributeValue = attributeVariant.toDouble( &attributeConversionOk );
if ( !attributeConversionOk || qIsNaN( attributeValue ) ) //don't consider vertices with attributes like 'nan' for the interpolation
{
continue;
@@ -184,13 +184,12 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
bool attributeConversionOk = false;
if ( !zCoord )
{
QgsAttributeMap attMap = f->attributeMap();
QgsAttributeMap::const_iterator att_it = attMap.find( attr );
if ( att_it == attMap.end() ) //attribute not found, something must be wrong (e.g. NULL value)
QVariant attributeVariant = f->attribute( attr );
if ( !attributeVariant.isValid() ) //attribute not found, something must be wrong (e.g. NULL value)
{
return 3;
}
attributeValue = att_it.value().toDouble( &attributeConversionOk );
attributeValue = attributeVariant.toDouble( &attributeConversionOk );
if ( !attributeConversionOk || qIsNaN( attributeValue ) ) //don't consider vertices with attributes like 'nan' for the interpolation
{
return 4;
@@ -280,29 +280,21 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
vl->select( la );
while ( vl->nextFeature( feature ) )
{
QgsAttributeMap attr = feature.attributeMap();
int directionType = mDefaultDirection;
QgsAttributeMap::const_iterator it;

// What direction have feature?
for ( it = attr.constBegin(); it != attr.constEnd(); ++it )
QString str = feature.attribute( mDirectionFieldId ).toString();
if ( str == mBothDirectionValue )
{
if ( it.key() != mDirectionFieldId )
{
continue;
}
QString str = it.value().toString();
if ( str == mBothDirectionValue )
{
directionType = 3;
}
else if ( str == mDirectDirectionValue )
{
directionType = 1;
}
else if ( str == mReverseDirectionValue )
{
directionType = 2;
}
directionType = 3;
}
else if ( str == mDirectDirectionValue )
{
directionType = 1;
}
else if ( str == mReverseDirectionValue )
{
directionType = 2;
}

// begin features segments and add arc to the Graph;

0 comments on commit 8bf9590

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