Skip to content
Permalink
Browse files

referencedColumns returns QSet<QString> instead of QStringList

The order of the elements is irrelevant and duplicate elements are unwanted. It
is therefore a perfect candidate for a set instead of a list. This prevents
filtering for duplicates manually be replacing some filer codes with (more
performant) builtin methods of QSet.
  • Loading branch information
m-kuhn committed Oct 5, 2016
1 parent 3767cd4 commit 722fdefe436641ff9b85eb647dbbe51a4d4f155c
Showing with 250 additions and 245 deletions.
  1. +5 −0 doc/api_break.dox
  2. +1 −1 python/core/qgsdatadefined.sip
  3. +12 −12 python/core/qgsexpression.sip
  4. +1 −1 python/core/qgsexpressioncontext.sip
  5. +6 −6 python/core/qgspallabeling.sip
  6. +1 −1 python/core/symbology-ng/qgs25drenderer.sip
  7. +1 −1 python/core/symbology-ng/qgscategorizedsymbolrenderer.sip
  8. +1 −1 python/core/symbology-ng/qgsgraduatedsymbolrenderer.sip
  9. +1 −1 python/core/symbology-ng/qgsheatmaprenderer.sip
  10. +1 −1 python/core/symbology-ng/qgsinvertedpolygonrenderer.sip
  11. +1 −1 python/core/symbology-ng/qgsnullsymbolrenderer.sip
  12. +1 −1 python/core/symbology-ng/qgspointclusterrenderer.sip
  13. +1 −1 python/core/symbology-ng/qgspointdisplacementrenderer.sip
  14. +1 −1 python/core/symbology-ng/qgspointdistancerenderer.sip
  15. +1 −3 python/core/symbology-ng/qgsrenderer.sip
  16. +1 −1 python/core/symbology-ng/qgsrulebasedrenderer.sip
  17. +1 −1 python/core/symbology-ng/qgssinglesymbolrenderer.sip
  18. +3 −4 src/core/dxf/qgsdxfexport.cpp
  19. +2 −2 src/core/qgsaggregatecalculator.cpp
  20. +1 −1 src/core/qgsdatadefined.cpp
  21. +1 −1 src/core/qgsdatadefined.h
  22. +1 −1 src/core/qgsdatadefined_p.h
  23. +65 −87 src/core/qgsexpression.cpp
  24. +15 −15 src/core/qgsexpression.h
  25. +6 −1 src/core/qgsexpressioncontext.h
  26. +22 −1 src/core/qgsfeaturerequest.cpp
  27. +3 −0 src/core/qgsfeaturerequest.h
  28. +2 −2 src/core/qgspallabeling.cpp
  29. +4 −4 src/core/qgspallabeling.h
  30. +3 −3 src/core/qgsrulebasedlabeling.cpp
  31. +2 −2 src/core/qgsrulebasedlabeling.h
  32. +4 −4 src/core/qgsvectorfilewriter.cpp
  33. +2 −2 src/core/qgsvectorlayer.cpp
  34. +3 −7 src/core/qgsvectorlayerdiagramprovider.cpp
  35. +1 −1 src/core/qgsvectorlayerdiagramprovider.h
  36. +6 −6 src/core/qgsvectorlayerlabelprovider.cpp
  37. +1 −1 src/core/qgsvectorlayerlabelprovider.h
  38. +2 −2 src/core/qgsvectorlayerrenderer.cpp
  39. +3 −3 src/core/qgsvectorlayerrenderer.h
  40. +2 −2 src/core/symbology-ng/qgs25drenderer.cpp
  41. +1 −1 src/core/symbology-ng/qgs25drenderer.h
  42. +3 −3 src/core/symbology-ng/qgscategorizedsymbolrenderer.cpp
  43. +1 −1 src/core/symbology-ng/qgscategorizedsymbolrenderer.h
  44. +1 −1 src/core/symbology-ng/qgsgeometrygeneratorsymbollayer.cpp
  45. +3 −3 src/core/symbology-ng/qgsgraduatedsymbolrenderer.cpp
  46. +1 −1 src/core/symbology-ng/qgsgraduatedsymbolrenderer.h
  47. +3 −3 src/core/symbology-ng/qgsheatmaprenderer.cpp
  48. +1 −1 src/core/symbology-ng/qgsheatmaprenderer.h
  49. +2 −2 src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
  50. +1 −1 src/core/symbology-ng/qgsinvertedpolygonrenderer.h
  51. +2 −2 src/core/symbology-ng/qgsnullsymbolrenderer.cpp
  52. +1 −1 src/core/symbology-ng/qgsnullsymbolrenderer.h
  53. +3 −3 src/core/symbology-ng/qgspointclusterrenderer.cpp
  54. +1 −1 src/core/symbology-ng/qgspointclusterrenderer.h
  55. +3 −3 src/core/symbology-ng/qgspointdisplacementrenderer.cpp
  56. +1 −1 src/core/symbology-ng/qgspointdisplacementrenderer.h
  57. +3 −3 src/core/symbology-ng/qgspointdistancerenderer.cpp
  58. +1 −1 src/core/symbology-ng/qgspointdistancerenderer.h
  59. +1 −2 src/core/symbology-ng/qgsrenderer.h
  60. +3 −4 src/core/symbology-ng/qgsrulebasedrenderer.cpp
  61. +1 −1 src/core/symbology-ng/qgsrulebasedrenderer.h
  62. +4 −3 src/core/symbology-ng/qgssinglesymbolrenderer.cpp
  63. +1 −1 src/core/symbology-ng/qgssinglesymbolrenderer.h
  64. +3 −3 src/core/symbology-ng/qgssymbollayer.cpp
  65. +2 −2 src/gui/editorwidgets/qgsrelationreferencewidget.cpp
  66. +1 −1 src/gui/symbology-ng/qgssizescalewidget.cpp
  67. +5 −5 tests/src/core/testqgsdatadefined.cpp
  68. +2 −2 tests/src/core/testqgsexpression.cpp
  69. +2 −2 tests/src/core/testqgslabelingengine.cpp
  70. +2 −1 tests/src/python/test_qgsexpression.py
@@ -710,6 +710,9 @@ version instead.</li>
<li>helptext() has been renamed to helpText()</li>
<li>isValid() has been renamed to checkExpression()</li>
<li>acceptVisitor() has been removed</li>
<li>QgsExpression::referencedColumns() returns QSet<QString> instead of QStringList</li>
<li>QgsExpression::Node::referencedColumns() returns QSet<QString> instead of QStringList</li>
<li>QgsExpression::Function::referencedColumns() returns QSet<QString> instead of QStringList</li>
</ul>

\subsection qgis_api_break_3_0_QgsFeature QgsFeature
@@ -1482,6 +1485,8 @@ optional property map passing down layer level properties to the SLD encoders. I
<code>scaleMinDenom</code> and <code>scaleMaxDenom</code> properties.</li>
<li>The RotationField capabitity was removed. This is now handled using data defined rotation at a symbol layer level</li>
<li>setScaleMethodToSymbol was removed. This is now handled using data defined scaling at a symbol layer level</li>
<li>setScaleMethodToSymbol was removed. This is now handled using data defined scaling at a symbol layer level</li>
<li>usedAttributes is now a const method and returns QSet<QString> instead of QStringList</li>
</ul>


@@ -128,7 +128,7 @@ class QgsDataDefined
* @param context expression context, used for preparing the expression if required
* @note added in QGIS 2.12
*/
QStringList referencedColumns( const QgsExpressionContext& context = QgsExpressionContext() );
QSet<QString> referencedColumns( const QgsExpressionContext& context = QgsExpressionContext() );

/**
* Get the field which this QgsDataDefined represents. Be aware that this may return
@@ -51,7 +51,7 @@ class QgsExpression
*
* TODO QGIS3: Return QSet<QString>
*/
QStringList referencedColumns() const;
QSet<QString> referencedColumns() const;

/**
* Return a list of field name indexes obtained from the provided fields.
@@ -301,7 +301,7 @@ class QgsExpression
const QString& group,
const QString& helpText = QString(),
bool usesGeometry = false,
const QStringList& referencedColumns = QStringList(),
const QSet<QString>& referencedColumns = QSet<QString>(),
bool lazyEval = false,
bool handlesNull = false,
bool isContextual = false );
@@ -314,7 +314,7 @@ class QgsExpression
const QString& group,
const QString& helpText = QString(),
bool usesGeometry = false,
const QStringList& referencedColumns = QStringList(),
const QSet<QString>& referencedColumns = QSet<QString>(),
bool lazyEval = false,
bool handlesNull = false,
bool isContextual = false );
@@ -350,7 +350,7 @@ class QgsExpression
*/
bool lazyEval() const;

virtual QStringList referencedColumns() const;
virtual QSet<QString> referencedColumns() const;

/** Returns whether the function is only available if provided by a QgsExpressionContext object.
* @note added in QGIS 2.12
@@ -517,7 +517,7 @@ class QgsExpression
*
* @return A list of columns required to evaluate this expression
*/
virtual QStringList referencedColumns() const = 0;
virtual QSet<QString> referencedColumns() const = 0;

/**
* Abstract virtual method which returns if the geometry is required to evaluate
@@ -596,7 +596,7 @@ class QgsExpression
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
virtual QString dump() const;

virtual QStringList referencedColumns() const;
virtual QSet<QString> referencedColumns() const;
virtual bool needsGeometry() const;
virtual QgsExpression::Node* clone() const;
};
@@ -616,7 +616,7 @@ class QgsExpression
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
virtual QString dump() const;

virtual QStringList referencedColumns() const;
virtual QSet<QString> referencedColumns() const;
virtual bool needsGeometry() const;
virtual QgsExpression::Node* clone() const;

@@ -650,7 +650,7 @@ class QgsExpression
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
virtual QString dump() const;

virtual QStringList referencedColumns() const;
virtual QSet<QString> referencedColumns() const;
virtual bool needsGeometry() const;
virtual QgsExpression::Node* clone() const;
};
@@ -670,7 +670,7 @@ class QgsExpression
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
virtual QString dump() const;

virtual QStringList referencedColumns() const;
virtual QSet<QString> referencedColumns() const;
virtual bool needsGeometry() const;
virtual QgsExpression::Node* clone() const;

@@ -692,7 +692,7 @@ class QgsExpression
virtual QString dump() const;
virtual QgsExpression::Node* clone() const;

virtual QStringList referencedColumns() const;
virtual QSet<QString> referencedColumns() const;
virtual bool needsGeometry() const;
};

@@ -709,7 +709,7 @@ class QgsExpression
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
virtual QString dump() const;

virtual QStringList referencedColumns() const;
virtual QSet<QString> referencedColumns() const;
virtual bool needsGeometry() const;

virtual QgsExpression::Node* clone() const;
@@ -741,7 +741,7 @@ class QgsExpression
virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
virtual QString dump() const;

virtual QStringList referencedColumns() const;
virtual QSet<QString> referencedColumns() const;
virtual bool needsGeometry() const;
virtual QgsExpression::Node* clone() const;
};
@@ -17,7 +17,7 @@ class QgsScopedExpressionFunction : QgsExpression::Function
const QString& group,
const QString& helpText = QString(),
bool usesGeometry = false,
const QStringList& referencedColumns = QStringList(),
const QSet<QString>& referencedColumns = QSet<QString>(),
bool lazyEval = false,
bool handlesNull = false,
bool isContextual = true );
@@ -122,14 +122,14 @@ class QgsLabelingEngineInterface
//! clears data defined objects from PAL layer settings for a registered layer
virtual void clearActiveLayer( const QString& layerID ) = 0;
//! called when starting rendering of a layer
virtual int prepareLayer( QgsVectorLayer* layer, QStringList& attrNames, QgsRenderContext& ctx ) = 0;
virtual int prepareLayer( QgsVectorLayer* layer, QSet<QString>& attrNames, QgsRenderContext& ctx ) = 0;
//! adds a diagram layer to the labeling engine
//! @note added in QGIS 2.12
virtual int prepareDiagramLayer( QgsVectorLayer *layer, QStringList &attrNames, QgsRenderContext &ctx );
virtual int prepareDiagramLayer( QgsVectorLayer *layer, QSet<QString>& attrNames, QgsRenderContext& ctx );
//! called for every feature
virtual void registerFeature( const QString &layerID, QgsFeature &feat, QgsRenderContext &context ) = 0;
virtual void registerFeature( const QString &layerID, QgsFeature& feat, QgsRenderContext& context ) = 0;
//! called for every diagram feature
virtual void registerDiagramFeature( const QString &layerID, QgsFeature &feat, QgsRenderContext &context );
virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, QgsRenderContext& context );
//! called when the map is drawn and labels should be placed
virtual void drawLabeling( QgsRenderContext& context ) = 0;
//! called when we're done with rendering
@@ -915,10 +915,10 @@ class QgsPalLabeling : QgsLabelingEngineInterface
//! clears data defined objects from PAL layer settings for a registered layer
virtual void clearActiveLayer( const QString& layerID );
//! hook called when drawing layer before issuing select()
virtual int prepareLayer( QgsVectorLayer* layer, QStringList &attrNames, QgsRenderContext& ctx );
virtual int prepareLayer( QgsVectorLayer* layer, QSet<QString>& attrNames, QgsRenderContext& ctx );
//! adds a diagram layer to the labeling engine
//! @note added in QGIS 2.12
virtual int prepareDiagramLayer( QgsVectorLayer* layer, QStringList& attrNames, QgsRenderContext& ctx );
virtual int prepareDiagramLayer( QgsVectorLayer* layer, QSet<QString>& attrNames, QgsRenderContext& ctx );

/** Register a feature for labelling.
* @param layerID string identifying layer associated with label
@@ -33,7 +33,7 @@ class Qgs25DRenderer : QgsFeatureRenderer
void startRender( QgsRenderContext& context, const QgsFields& fields );
void stopRender( QgsRenderContext& context );

QList<QString> usedAttributes();
QSet<QString> usedAttributes() const;
QgsFeatureRenderer* clone() const;

virtual QgsSymbol* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
@@ -59,7 +59,7 @@ class QgsCategorizedSymbolRenderer : QgsFeatureRenderer

virtual void stopRender( QgsRenderContext& context );

virtual QList<QString> usedAttributes();
virtual QSet<QString> usedAttributes() const;

virtual QString dump() const;

@@ -102,7 +102,7 @@ class QgsGraduatedSymbolRenderer : QgsFeatureRenderer

virtual void stopRender( QgsRenderContext& context );

virtual QList<QString> usedAttributes();
virtual QSet<QString> usedAttributes() const;

virtual QString dump() const;

@@ -18,7 +18,7 @@ class QgsHeatmapRenderer : QgsFeatureRenderer
//! @note symbol2 in python bindings
virtual QgsSymbolList symbols( QgsRenderContext& context );
virtual QString dump() const;
virtual QList<QString> usedAttributes();
virtual QSet<QString> usedAttributes() const;
static QgsFeatureRenderer* create( QDomElement& element ) /Factory/;
virtual QDomElement save( QDomDocument& doc );
static QgsHeatmapRenderer* convertFromRenderer( const QgsFeatureRenderer* renderer ) /Factory/;
@@ -39,7 +39,7 @@ class QgsInvertedPolygonRenderer : QgsFeatureRenderer
virtual QString dump() const;

/** Proxy that will call this method on the embedded renderer. */
virtual QList<QString> usedAttributes();
virtual QSet<QString> usedAttributes() const;
/** Proxy that will call this method on the embedded renderer. */
virtual QgsFeatureRenderer::Capabilities capabilities();
/** Proxy that will call this method on the embedded renderer.
@@ -24,7 +24,7 @@ class QgsNullSymbolRenderer : QgsFeatureRenderer
virtual void stopRender( QgsRenderContext& context );
virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );

virtual QList<QString> usedAttributes();
virtual QSet<QString> usedAttributes() const;
virtual QString dump() const;
virtual QgsFeatureRenderer* clone() const /Factory/;
virtual QgsSymbolList symbols( QgsRenderContext& context );
@@ -16,7 +16,7 @@ class QgsPointClusterRenderer : QgsPointDistanceRenderer
virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
void stopRender( QgsRenderContext& context );
QDomElement save( QDomDocument& doc );
virtual QList<QString> usedAttributes();
virtual QSet<QString> usedAttributes() const;

//! Create a renderer from XML element
static QgsFeatureRenderer* create( QDomElement& symbologyElem ) /Factory/;
@@ -26,7 +26,7 @@ class QgsPointDisplacementRenderer : QgsPointDistanceRenderer
virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
void stopRender( QgsRenderContext& context );
QDomElement save( QDomDocument& doc );
virtual QList<QString> usedAttributes();
virtual QSet<QString> usedAttributes() const;

//! Create a renderer from XML element
static QgsFeatureRenderer* create( QDomElement& symbologyElem ) /Factory/;
@@ -50,7 +50,7 @@ class QgsPointDistanceRenderer : QgsFeatureRenderer

virtual void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props = QgsStringMap() ) const;
bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
virtual QList<QString> usedAttributes();
virtual QSet<QString> usedAttributes() const;
virtual Capabilities capabilities();
virtual QgsSymbolList symbols( QgsRenderContext& context );
virtual QgsSymbol* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
@@ -119,10 +119,8 @@ class QgsFeatureRenderer

/**
* Returns a set of attributes required for this renderer.
*
* TODO QGIS3: Change QList to QSet
*/
virtual QList<QString> usedAttributes() = 0;
virtual QSet<QString> usedAttributes() const = 0;

/**
* Returns true if this renderer requires the geometry to apply the filter.
@@ -340,7 +340,7 @@ class QgsRuleBasedRenderer : QgsFeatureRenderer

virtual QString filter( const QgsFields& fields = QgsFields() );

virtual QList<QString> usedAttributes();
virtual QSet<QString> usedAttributes() const;

virtual bool filterNeedsGeometry() const;

@@ -19,7 +19,7 @@ class QgsSingleSymbolRenderer : QgsFeatureRenderer

virtual void stopRender( QgsRenderContext& context );

virtual QList<QString> usedAttributes();
virtual QSet<QString> usedAttributes() const;

QgsSymbol* symbol() const;
void setSymbol( QgsSymbol* s /Transfer/ );
@@ -965,12 +965,11 @@ void QgsDxfExport::writeEntities()
}
renderer->startRender( ctx, vl->fields() );

QStringList attributes = renderer->usedAttributes();
QSet<QString> attributes = renderer->usedAttributes();
if ( vl->fields().exists( layerIt->second ) )
{
QString layerAttr = vl->fields().at( layerIt->second ).name();
if ( !attributes.contains( layerAttr ) )
attributes << layerAttr;
attributes << layerAttr;
}

const QgsAbstractVectorLayerLabeling *labeling = vl->labeling();
@@ -1106,7 +1105,7 @@ void QgsDxfExport::writeEntitiesSymbolLevels( QgsVectorLayer* layer )
{
req.setFlags( QgsFeatureRequest::NoGeometry );
}
req.setSubsetOfAttributes( QStringList( renderer->usedAttributes() ), layer->fields() );
req.setSubsetOfAttributes( renderer->usedAttributes(), layer->fields() );
req.setFilterRect( mMapSettings.mapToLayerCoordinates( layer, mExtent ) );

QgsFeatureIterator fit = layer->getFeatures( req );
@@ -71,9 +71,9 @@ QVariant QgsAggregateCalculator::calculate( QgsAggregateCalculator::Aggregate ag
}
}

QStringList lst;
QSet<QString> lst;
if ( expression.isNull() )
lst.append( fieldOrExpression );
lst.insert( fieldOrExpression );
else
lst = expression->referencedColumns();

@@ -187,7 +187,7 @@ QgsExpression *QgsDataDefined::expression()
return d->expression;
}

QStringList QgsDataDefined::referencedColumns( const QgsExpressionContext& context )
QSet<QString> QgsDataDefined::referencedColumns( const QgsExpressionContext& context )
{
if ( !d->exprRefColumns.isEmpty() )
{
@@ -154,7 +154,7 @@ class CORE_EXPORT QgsDataDefined
* @param context expression context, used for preparing the expression if required
* @note added in QGIS 2.12
*/
QStringList referencedColumns( const QgsExpressionContext& context = QgsExpressionContext() );
QSet<QString> referencedColumns( const QgsExpressionContext& context = QgsExpressionContext() );

/**
* Get the field which this QgsDataDefined represents. Be aware that this may return
@@ -80,7 +80,7 @@ class QgsDataDefinedPrivate : public QSharedData
QString field;

bool expressionPrepared;
QStringList exprRefColumns;
QSet<QString> exprRefColumns;
};

/// @endcond

0 comments on commit 722fdef

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