Skip to content

Commit

Permalink
Fix clazy qmap-with-pointer-key warnings
Browse files Browse the repository at this point in the history
From the clazy docs:

Finds cases where you're using QMap<K,T> and K is a pointer.

QMap has the particularity of sorting it's keys, but sorting
by memory address makes no sense. Use QHash instead, which
provides faster lookups.
  • Loading branch information
nyalldawson committed Oct 22, 2016
1 parent bd20fe4 commit a3968a2
Show file tree
Hide file tree
Showing 24 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion python/gui/editorwidgets/core/qgseditorwidgetfactory.sip
Expand Up @@ -108,7 +108,7 @@ class QgsEditorWidgetFactory
* @return A map of widget type names and weight values
* @note not available in Python bindings
*/
//virtual QMap<const char*, int> supportedWidgetTypes() { return QMap<const char*, int>(); }
//virtual QHash<const char*, int> supportedWidgetTypes();

/**
* Create a pretty String representation of the value.
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsfeatureaction.cpp
Expand Up @@ -257,4 +257,4 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature& feature )
}
}

QMap<QgsVectorLayer *, QgsAttributeMap> QgsFeatureAction::sLastUsedValues;
QHash<QgsVectorLayer *, QgsAttributeMap> QgsFeatureAction::sLastUsedValues;
2 changes: 1 addition & 1 deletion src/app/qgsfeatureaction.h
Expand Up @@ -64,7 +64,7 @@ class APP_EXPORT QgsFeatureAction : public QAction

bool mFeatureSaved;

static QMap<QgsVectorLayer *, QgsAttributeMap> sLastUsedValues;
static QHash<QgsVectorLayer *, QgsAttributeMap> sLastUsedValues;
};

#endif
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolreshape.cpp
Expand Up @@ -105,7 +105,7 @@ void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
if ( vlayer->geometryType() == QgsWkbTypes::PolygonGeometry )
{
//ignore all current layer features as they should be reshaped too
QMap<QgsVectorLayer*, QSet<QgsFeatureId> > ignoreFeatures;
QHash<QgsVectorLayer*, QSet<QgsFeatureId> > ignoreFeatures;
ignoreFeatures.insert( vlayer, vlayer->allFeatureIds() );

if ( geom.avoidIntersections( ignoreFeatures ) != 0 )
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.cpp
Expand Up @@ -1790,7 +1790,7 @@ bool QgsGeometry::deletePart( int partNum )
return ok;
}

int QgsGeometry::avoidIntersections( const QMap<QgsVectorLayer*, QSet< QgsFeatureId > >& ignoreFeatures )
int QgsGeometry::avoidIntersections( const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures )
{
if ( !d->geometry )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.h
Expand Up @@ -737,7 +737,7 @@ class CORE_EXPORT QgsGeometry
* @param ignoreFeatures possibility to give a list of features where intersections should be ignored (not available in python bindings)
* @note added in 1.5
*/
int avoidIntersections( const QMap<QgsVectorLayer*, QSet<QgsFeatureId> >& ignoreFeatures = ( QMap<QgsVectorLayer*, QSet<QgsFeatureId> >() ) );
int avoidIntersections( const QHash<QgsVectorLayer*, QSet<QgsFeatureId> >& ignoreFeatures = ( QHash<QgsVectorLayer*, QSet<QgsFeatureId> >() ) );

/** \ingroup core
*/
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsgeometryeditutils.cpp
Expand Up @@ -225,7 +225,7 @@ bool QgsGeometryEditUtils::deletePart( QgsAbstractGeometry* geom, int partNum )
return c->removeGeometry( partNum );
}

QgsAbstractGeometry* QgsGeometryEditUtils::avoidIntersections( const QgsAbstractGeometry& geom, QMap<QgsVectorLayer*, QSet<QgsFeatureId> > ignoreFeatures )
QgsAbstractGeometry* QgsGeometryEditUtils::avoidIntersections( const QgsAbstractGeometry& geom, QHash<QgsVectorLayer *, QSet<QgsFeatureId> > ignoreFeatures )
{
QScopedPointer<QgsGeometryEngine> geomEngine( QgsGeometry::createGeometryEngine( &geom ) );
if ( geomEngine.isNull() )
Expand Down Expand Up @@ -256,7 +256,7 @@ QgsAbstractGeometry* QgsGeometryEditUtils::avoidIntersections( const QgsAbstract
if ( currentLayer )
{
QgsFeatureIds ignoreIds;
QMap<QgsVectorLayer*, QSet<qint64> >::const_iterator ignoreIt = ignoreFeatures.find( currentLayer );
QHash<QgsVectorLayer*, QSet<qint64> >::const_iterator ignoreIt = ignoreFeatures.find( currentLayer );
if ( ignoreIt != ignoreFeatures.constEnd() )
ignoreIds = ignoreIt.value();

Expand Down
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometryeditutils.h
Expand Up @@ -60,7 +60,7 @@ class QgsGeometryEditUtils
* @param geom geometry to alter
* @param ignoreFeatures map of layer to feature id of features to ignore
*/
static QgsAbstractGeometry* avoidIntersections( const QgsAbstractGeometry& geom, QMap<QgsVectorLayer*, QSet<QgsFeatureId> > ignoreFeatures = ( QMap<QgsVectorLayer*, QSet<QgsFeatureId> >() ) );
static QgsAbstractGeometry* avoidIntersections( const QgsAbstractGeometry& geom, QHash<QgsVectorLayer*, QSet<QgsFeatureId> > ignoreFeatures = ( QHash<QgsVectorLayer*, QSet<QgsFeatureId> >() ) );
};

#endif // QGSGEOMETRYEDITUTILS_H
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetfactory.h
Expand Up @@ -125,7 +125,7 @@ class GUI_EXPORT QgsEditorWidgetFactory
* @return A map of widget type names and weight values
* @note not available in Python bindings
*/
virtual QMap<const char*, int> supportedWidgetTypes() { return QMap<const char*, int>(); }
virtual QHash<const char*, int> supportedWidgetTypes() { return QHash<const char*, int>(); }

/**
* Create a pretty String representation of the value.
Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
Expand Up @@ -207,8 +207,8 @@ bool QgsEditorWidgetRegistry::registerWidget( const QString& widgetId, QgsEditor
mWidgetFactories.insert( widgetId, widgetFactory );

// Use this factory as default where it provides the heighest priority
QMap<const char*, int> types = widgetFactory->supportedWidgetTypes();
QMap<const char*, int>::ConstIterator it;
QHash<const char*, int> types = widgetFactory->supportedWidgetTypes();
QHash<const char*, int>::ConstIterator it;
it = types.constBegin();

for ( ; it != types.constEnd(); ++it )
Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgscheckboxwidgetfactory.cpp
Expand Up @@ -61,9 +61,9 @@ void QgsCheckboxWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config,
configElement.setAttribute( "UncheckedState", config.value( "UncheckedState", "0" ).toString() );
}

QMap<const char*, int> QgsCheckboxWidgetFactory::supportedWidgetTypes()
QHash<const char*, int> QgsCheckboxWidgetFactory::supportedWidgetTypes()
{
QMap<const char*, int> map = QMap<const char*, int>();
QHash<const char*, int> map = QHash<const char*, int>();
map.insert( QCheckBox::staticMetaObject.className(), 10 );
map.insert( QGroupBox::staticMetaObject.className(), 10 );
return map;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgscheckboxwidgetfactory.h
Expand Up @@ -35,7 +35,7 @@ class GUI_EXPORT QgsCheckboxWidgetFactory : public QgsEditorWidgetFactory
QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;
QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx ) override;
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QMap<const char*, int> supportedWidgetTypes() override;
QHash<const char *, int> supportedWidgetTypes() override;
unsigned int fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const override;
};

Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsdatetimeeditfactory.cpp
Expand Up @@ -108,9 +108,9 @@ Qt::AlignmentFlag QgsDateTimeEditFactory::alignmentFlag( QgsVectorLayer* vl, int
return Qt::AlignLeft;
}

QMap<const char*, int> QgsDateTimeEditFactory::supportedWidgetTypes()
QHash<const char*, int> QgsDateTimeEditFactory::supportedWidgetTypes()
{
QMap<const char*, int> map = QMap<const char*, int>();
QHash<const char*, int> map = QHash<const char*, int>();
map.insert( QDateTimeEdit::staticMetaObject.className(), 10 );
map.insert( QgsDateTimeEdit::staticMetaObject.className(), 10 );
return map;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsdatetimeeditfactory.h
Expand Up @@ -41,7 +41,7 @@ class GUI_EXPORT QgsDateTimeEditFactory : public QgsEditorWidgetFactory
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const override;
virtual QMap<const char*, int> supportedWidgetTypes() override;
virtual QHash<const char*, int> supportedWidgetTypes() override;
unsigned int fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const override;
};

Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsrangewidgetfactory.cpp
Expand Up @@ -79,9 +79,9 @@ unsigned int QgsRangeWidgetFactory::fieldScore( const QgsVectorLayer* vl, int fi
return 0;
}

QMap<const char*, int> QgsRangeWidgetFactory::supportedWidgetTypes()
QHash<const char*, int> QgsRangeWidgetFactory::supportedWidgetTypes()
{
QMap<const char*, int> map = QMap<const char*, int>();
QHash<const char*, int> map = QHash<const char*, int>();
map.insert( QSlider::staticMetaObject.className(), 10 );
map.insert( QDial::staticMetaObject.className(), 10 );
map.insert( QSpinBox::staticMetaObject.className(), 10 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsrangewidgetfactory.h
Expand Up @@ -34,7 +34,7 @@ class GUI_EXPORT QgsRangeWidgetFactory : public QgsEditorWidgetFactory
virtual QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;
virtual QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx ) override;
virtual void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
virtual QMap<const char*, int> supportedWidgetTypes() override;
virtual QHash<const char *, int> supportedWidgetTypes() override;

private:
virtual unsigned int fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const override;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsrelationreferencefactory.cpp
Expand Up @@ -109,9 +109,9 @@ void QgsRelationReferenceFactory::writeConfig( const QgsEditorWidgetConfig& conf
}
}

QMap<const char*, int> QgsRelationReferenceFactory::supportedWidgetTypes()
QHash<const char*, int> QgsRelationReferenceFactory::supportedWidgetTypes()
{
QMap<const char*, int> map = QMap<const char*, int>();
QHash<const char*, int> map = QHash<const char*, int>();
map.insert( QgsRelationReferenceWidget::staticMetaObject.className(), 10 );
return map;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsrelationreferencefactory.h
Expand Up @@ -86,7 +86,7 @@ class GUI_EXPORT QgsRelationReferenceFactory : public QgsEditorWidgetFactory

virtual QVariant sortValue( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config, const QVariant &cache, const QVariant &value ) const override;

virtual QMap<const char*, int> supportedWidgetTypes() override;
virtual QHash<const char *, int> supportedWidgetTypes() override;

private:
QgsAttributeEditorContext mEditorContext;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsvaluemapwidgetfactory.cpp
Expand Up @@ -109,9 +109,9 @@ Qt::AlignmentFlag QgsValueMapWidgetFactory::alignmentFlag( QgsVectorLayer* vl, i
return Qt::AlignLeft;
}

QMap<const char*, int> QgsValueMapWidgetFactory::supportedWidgetTypes()
QHash<const char*, int> QgsValueMapWidgetFactory::supportedWidgetTypes()
{
QMap<const char*, int> map = QMap<const char*, int>();
QHash<const char*, int> map = QHash<const char*, int>();
map.insert( QComboBox::staticMetaObject.className(), 10 );
return map;
}
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsvaluemapwidgetfactory.h
Expand Up @@ -38,7 +38,7 @@ class GUI_EXPORT QgsValueMapWidgetFactory : public QgsEditorWidgetFactory
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
QVariant sortValue( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config, const QVariant &cache, const QVariant &value ) const override;
Qt::AlignmentFlag alignmentFlag( QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config ) const override;
virtual QMap<const char*, int> supportedWidgetTypes() override;
virtual QHash<const char *, int> supportedWidgetTypes() override;
};

#endif // QGSVALUEMAPWIDGETFACTORY_H
4 changes: 2 additions & 2 deletions src/gui/symbology-ng/qgsrulebasedrendererwidget.cpp
Expand Up @@ -507,7 +507,7 @@ void QgsRuleBasedRendererWidget::countFeatures()
{
return;
}
QMap<QgsRuleBasedRenderer::Rule*, QgsRuleBasedRendererCount> countMap;
QHash<QgsRuleBasedRenderer::Rule*, QgsRuleBasedRendererCount> countMap;

QgsRuleBasedRenderer::RuleList ruleList = mRenderer->rootRule()->descendants();
// insert all so that we have counts 0
Expand Down Expand Up @@ -1285,7 +1285,7 @@ void QgsRuleBasedRendererModel::finishedAddingRules()
emit endInsertRows();
}

void QgsRuleBasedRendererModel::setFeatureCounts( const QMap<QgsRuleBasedRenderer::Rule*, QgsRuleBasedRendererCount>& theCountMap )
void QgsRuleBasedRendererModel::setFeatureCounts( const QHash<QgsRuleBasedRenderer::Rule*, QgsRuleBasedRendererCount>& theCountMap )
{
mFeatureCountMap = theCountMap;
updateRule( QModelIndex() );
Expand Down
4 changes: 2 additions & 2 deletions src/gui/symbology-ng/qgsrulebasedrendererwidget.h
Expand Up @@ -85,12 +85,12 @@ class GUI_EXPORT QgsRuleBasedRendererModel : public QAbstractItemModel
void finishedAddingRules(); // call endInsertRows

//! @note not available in python bindungs
void setFeatureCounts( const QMap<QgsRuleBasedRenderer::Rule*, QgsRuleBasedRendererCount>& theCountMap );
void setFeatureCounts( const QHash<QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount> &theCountMap );
void clearFeatureCounts();

protected:
QgsRuleBasedRenderer* mR;
QMap<QgsRuleBasedRenderer::Rule*, QgsRuleBasedRendererCount> mFeatureCountMap;
QHash<QgsRuleBasedRenderer::Rule*, QgsRuleBasedRendererCount> mFeatureCountMap;
};


Expand Down
2 changes: 1 addition & 1 deletion src/providers/ows/qgsowsdataitems.cpp
Expand Up @@ -38,7 +38,7 @@ QgsOWSConnectionItem::~QgsOWSConnectionItem()
QVector<QgsDataItem*> QgsOWSConnectionItem::createChildren()
{
QVector<QgsDataItem*> children;
QMap<QgsDataItem*, QString> serviceItems; // service/provider key
QHash<QgsDataItem*, QString> serviceItems; // service/provider key

int layerCount = 0;
// Try to open with WMS,WFS,WCS
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgswmsserver.h
Expand Up @@ -89,7 +89,7 @@ class QgsWmsServer: public QgsOWSServer
QImage* getLegendGraphics();

typedef QSet<QgsSymbol*> SymbolSet;
typedef QMap<QgsVectorLayer*, SymbolSet> HitTest;
typedef QHash<QgsVectorLayer*, SymbolSet> HitTest;

/** Returns the map as an image (or a null pointer in case of error). The caller takes ownership
of the image object). If an instance to existing hit test structure is passed, instead of rendering
Expand Down

0 comments on commit a3968a2

Please sign in to comment.