Skip to content
Permalink
Browse files

Fix clazy qmap-with-pointer-key warnings

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 a3968a29bd82275f636c5b4d120a3f3fb4893210
@@ -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.
@@ -257,4 +257,4 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature& feature )
}
}

QMap<QgsVectorLayer *, QgsAttributeMap> QgsFeatureAction::sLastUsedValues;
QHash<QgsVectorLayer *, QgsAttributeMap> QgsFeatureAction::sLastUsedValues;
@@ -64,7 +64,7 @@ class APP_EXPORT QgsFeatureAction : public QAction

bool mFeatureSaved;

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

#endif
@@ -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 )
@@ -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 )
{
@@ -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
*/
@@ -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() )
@@ -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();

@@ -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
@@ -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.
@@ -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 )
@@ -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;
@@ -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;
};

@@ -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;
@@ -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;
};

@@ -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 );
@@ -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;
@@ -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;
}
@@ -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;
@@ -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;
}
@@ -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
@@ -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
@@ -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() );
@@ -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;
};


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

0 comments on commit a3968a2

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