Skip to content

Commit

Permalink
Don't return const references to implicitly shared Qt classes
Browse files Browse the repository at this point in the history
Instead return the inexpensive copies. Should provide extra safety
against issues like #14822

(refs #14822)
  • Loading branch information
nyalldawson committed Jan 14, 2017
1 parent ef8a135 commit 231f6af
Show file tree
Hide file tree
Showing 97 changed files with 172 additions and 222 deletions.
2 changes: 1 addition & 1 deletion python/analysis/raster/qgsrelief.sip
Expand Up @@ -26,7 +26,7 @@ class QgsRelief

void clearReliefColors();
void addReliefColorClass( const QgsRelief::ReliefColor& color );
const QList< QgsRelief::ReliefColor >& reliefColors() const;
QList< QgsRelief::ReliefColor > reliefColors() const;
void setReliefColors( const QList< QgsRelief::ReliefColor >& c );

/** Calculates class breaks according with the method of Buenzli (2011) using an iterative algorithm for segmented regression
Expand Down
2 changes: 1 addition & 1 deletion python/core/composer/qgsatlascomposition.sip
Expand Up @@ -145,7 +145,7 @@ public:
* @see setPredefinedScales
* @see QgsComposerMap::atlasScalingMode
*/
const QVector<qreal>& predefinedScales() const;
QVector<qreal> predefinedScales() const;

/** Sets the list of predefined scales for the atlas. This is used
* for maps which are set to the predefined atlas scaling mode.
Expand Down
2 changes: 1 addition & 1 deletion python/core/composer/qgscomposerhtml.sip
Expand Up @@ -51,7 +51,7 @@ class QgsComposerHtml: QgsComposerMultiFrame
* @see setUrl
* @see contentMode
*/
const QUrl& url() const;
QUrl url() const;

/** Sets the HTML to display in the item when the item is using
* the QgsComposerHtml::ManualHtml mode. Setting the HTML using this function
Expand Down
2 changes: 1 addition & 1 deletion python/core/composer/qgscomposition.sip
Expand Up @@ -235,7 +235,7 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
double snapGridOffsetY() const;

void setGridPen( const QPen& p );
const QPen& gridPen() const;
QPen gridPen() const;

void setGridStyle( const GridStyle s );
GridStyle gridStyle() const;
Expand Down
2 changes: 1 addition & 1 deletion python/core/layertree/qgslayertreemodel.sip
Expand Up @@ -228,7 +228,7 @@ class QgsLayerTreeModel : QAbstractItemModel
*/
void refreshScaleBasedLayers( const QModelIndex& index = QModelIndex() );

static const QIcon& iconGroup();
static QIcon iconGroup();

//! Filter nodes from QgsMapLayerLegend according to the current filtering rules
QList<QgsLayerTreeModelLegendNode*> filterLegendNodes( const QList<QgsLayerTreeModelLegendNode*>& nodes );
Expand Down
22 changes: 11 additions & 11 deletions python/core/qgsdataitem.sip
Expand Up @@ -308,12 +308,12 @@ class QgsLayerItem : QgsDataItem
virtual QString comments() const;

public:
static const QIcon &iconPoint();
static const QIcon &iconLine();
static const QIcon &iconPolygon();
static const QIcon &iconTable();
static const QIcon &iconRaster();
static const QIcon &iconDefault();
static QIcon iconPoint();
static QIcon iconLine();
static QIcon iconPolygon();
static QIcon iconTable();
static QIcon iconRaster();
static QIcon iconDefault();

virtual QString layerName() const;
};
Expand All @@ -331,8 +331,8 @@ class QgsDataCollectionItem : QgsDataItem

void addChild( QgsDataItem *item /Transfer/ );

static const QIcon &iconDir(); // shared icon: open/closed directory
static const QIcon &iconDataCollection(); // default icon for data collection
static QIcon iconDir(); // shared icon: open/closed directory
static QIcon iconDataCollection(); // default icon for data collection
};

/** A directory: contains subdirectories and layers */
Expand Down Expand Up @@ -477,7 +477,7 @@ class QgsFavoritesItem : QgsDataCollectionItem
void removeDirectory( QgsDirectoryItem *item );

//! Icon for favorites group
static const QIcon &iconFavorites();
static QIcon iconFavorites();
};

/** A zip file: contains layers, using GDAL/OGR VSIFILE mechanism */
Expand All @@ -492,7 +492,7 @@ class QgsZipItem : QgsDataCollectionItem
~QgsZipItem();

QVector<QgsDataItem*> createChildren();
const QStringList & getZipFileList();
QStringList getZipFileList();

//! @note not available via python bindings
// static QVector<dataItem_t *> mDataItemPtr;
Expand All @@ -504,6 +504,6 @@ class QgsZipItem : QgsDataCollectionItem
//! @note available in python as itemFromFilePath
static QgsDataItem* itemFromPath( QgsDataItem* parent, const QString& filePath, const QString& name, const QString& path ) /Factory,PyName=itemFromFilePath/;

static const QIcon &iconZip();
static QIcon iconZip();

};
2 changes: 1 addition & 1 deletion python/core/qgsexpressionfieldbuffer.sip
Expand Up @@ -64,5 +64,5 @@ class QgsExpressionFieldBuffer
*/
void updateFields( QgsFields& flds );

const QList<QgsExpressionFieldBuffer::ExpressionField>& expressions() const;
QList<QgsExpressionFieldBuffer::ExpressionField> expressions() const;
};
2 changes: 1 addition & 1 deletion python/core/qgsnetworkaccessmanager.sip
Expand Up @@ -46,7 +46,7 @@ class QgsNetworkAccessManager : QNetworkAccessManager
const QNetworkProxy &fallbackProxy() const;

//! retrieve exclude list (urls shouldn't use the fallback proxy)
const QStringList &excludeList() const;
QStringList excludeList() const;

//! set fallback proxy and URL that shouldn't use it.
void setFallbackProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes );
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsproviderregistry.sip
Expand Up @@ -29,7 +29,7 @@ class QgsProviderRegistry
QString pluginList( bool asHtml = false ) const;

/** Return library directory where plugins are found */
const QDir & libraryDirectory() const;
QDir libraryDirectory() const;

/** Set library directory where to search for plugins */
void setLibraryDirectory( const QDir & path );
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsrelationmanager.sip
Expand Up @@ -25,7 +25,7 @@ class QgsRelationManager : QObject
*
* @return A QMap where the key is the relation id, the value the relation object.
*/
const QMap<QString, QgsRelation>& relations() const;
QMap<QString, QgsRelation> relations() const;

/**
* Add a relation.
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectordataprovider.sip
Expand Up @@ -375,7 +375,7 @@ class QgsVectorDataProvider : QgsDataProvider
/**
* Returns the names of the supported types
*/
const QList< QgsVectorDataProvider::NativeType > &nativeTypes() const;
QList< QgsVectorDataProvider::NativeType > nativeTypes() const;

/**
* Returns true if the provider is strict about the type of inserted features
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -1111,10 +1111,10 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator

const QMap< QString, QString >& attributeAliases() const;

const QSet<QString>& excludeAttributesWms() const;
QSet<QString> excludeAttributesWms() const;
void setExcludeAttributesWms( const QSet<QString>& att );

const QSet<QString>& excludeAttributesWfs() const;
QSet<QString> excludeAttributesWfs() const;
void setExcludeAttributesWfs( const QSet<QString>& att );

/** Delete an attribute field (but does not commit it) */
Expand Down
6 changes: 3 additions & 3 deletions python/core/symbology-ng/qgssvgcache.sip
Expand Up @@ -79,7 +79,7 @@ class QgsSvgCache : QObject
* @param rasterScaleFactor raster scale factor
* @param fitsInCache
*/
const QImage& svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
QImage svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache );
/** Get SVG as QPicture&.
* @param file Absolute or relative path to SVG file.
Expand All @@ -91,7 +91,7 @@ class QgsSvgCache : QObject
* @param rasterScaleFactor raster scale factor
* @param forceVectorOutput
*/
const QPicture& svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
QPicture svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput = false );

/** Calculates the viewbox size of a (possibly cached) SVG file.
Expand Down Expand Up @@ -144,7 +144,7 @@ class QgsSvgCache : QObject
QByteArray getImageData( const QString &path ) const;

/** Get SVG content*/
const QByteArray& svgContent( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
QByteArray svgContent( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor );

signals:
Expand Down
2 changes: 1 addition & 1 deletion python/gui/editorwidgets/core/qgseditorwidgetregistry.sip
Expand Up @@ -110,7 +110,7 @@ class QgsEditorWidgetRegistry : QObject
*
* @return All ids and factories
*/
const QMap<QString, QgsEditorWidgetFactory*>& factories();
QMap<QString, QgsEditorWidgetFactory*> factories();

/**
* Get a factory for the given widget type id.
Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgsadvanceddigitizingdockwidget.sip
Expand Up @@ -269,7 +269,7 @@ class QgsAdvancedDigitizingDockWidget : QDockWidget
/**
* Snapped to a segment
*/
const QList<QgsPoint>& snappedSegment() const;
QList<QgsPoint> snappedSegment() const;

//! return the action used to enable/disable the tools
QAction* enableAction();
Expand Down
8 changes: 4 additions & 4 deletions python/server/qgsserverprojectparser.sip
Expand Up @@ -60,9 +60,9 @@ class QgsServerProjectParser

QStringList supportedOutputCrsList() const;

const QList<QDomElement>& projectLayerElements() const;
QList<QDomElement> projectLayerElements() const;

const QList<QDomElement>& legendGroupElements() const;
QList<QDomElement> legendGroupElements() const;

QString projectTitle() const;

Expand All @@ -73,8 +73,8 @@ class QgsServerProjectParser
const QSet<QString>& restrictedLayers() const;
bool useLayerIds() const;

const QHash< QString, QDomElement >& projectLayerElementsByName() const;
const QHash< QString, QDomElement >& projectLayerElementsById() const;
QHash< QString, QDomElement > projectLayerElementsByName() const;
QHash< QString, QDomElement > projectLayerElementsById() const;

// SIP doesn't like QMap:
// void layerFromLegendLayer( const QDomElement& legendLayerElem, QMap< int, QgsMapLayer*>& layers, bool useCache = true ) const;
Expand Down
4 changes: 2 additions & 2 deletions python/server/qgswmsconfigparser.sip
Expand Up @@ -88,8 +88,8 @@ class QgsWmsConfigParser
virtual double legendIconLabelSpace() const = 0;
virtual double legendSymbolWidth() const = 0;
virtual double legendSymbolHeight() const = 0;
virtual const QFont& legendLayerFont() const = 0;
virtual const QFont& legendItemFont() const = 0;
virtual QFont legendLayerFont() const = 0;
virtual QFont legendItemFont() const = 0;

virtual double maxWidth() const = 0;
virtual double maxHeight() const = 0;
Expand Down
4 changes: 2 additions & 2 deletions python/server/qgswmsprojectparser.sip
Expand Up @@ -46,8 +46,8 @@ class QgsWmsProjectParser : public QgsWmsConfigParser
double legendIconLabelSpace() const /*override*/ ;
double legendSymbolWidth() const /*override*/ ;
double legendSymbolHeight() const /*override*/ ;
const QFont& legendLayerFont() const /*override*/ ;
const QFont& legendItemFont() const /*override*/ ;
QFont legendLayerFont() const /*override*/ ;
QFont legendItemFont() const /*override*/ ;

double maxWidth() const /*override*/ ;
double maxHeight() const /*override*/ ;
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/interpolation/qgsinterpolator.h
Expand Up @@ -67,7 +67,7 @@ class ANALYSIS_EXPORT QgsInterpolator
virtual int interpolatePoint( double x, double y, double& result ) = 0;

//! @note not available in Python bindings
const QList<LayerData>& layerData() const { return mLayerData; }
QList<LayerData> layerData() const { return mLayerData; }

protected:

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsrelief.h
Expand Up @@ -61,7 +61,7 @@ class ANALYSIS_EXPORT QgsRelief

void clearReliefColors();
void addReliefColorClass( const ReliefColor& color );
const QList< ReliefColor >& reliefColors() const { return mReliefColors; }
QList< ReliefColor > reliefColors() const { return mReliefColors; }
void setReliefColors( const QList< ReliefColor >& c ) { mReliefColors = c; }

/** Calculates class breaks according with the method of Buenzli (2011) using an iterative algorithm for segmented regression
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposer.h
Expand Up @@ -104,7 +104,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

QAction* windowAction() {return mWindowAction;}

const QString& title() const {return mTitle;}
QString title() const {return mTitle;}
void setTitle( const QString& title );

/** Loads the contents of a template document into the composer's composition.
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmeasuretool.cpp
Expand Up @@ -65,7 +65,7 @@ QgsMeasureTool::~QgsMeasureTool()
}


const QList<QgsPoint>& QgsMeasureTool::points()
QList<QgsPoint> QgsMeasureTool::points()
{
return mPoints;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmeasuretool.h
Expand Up @@ -52,7 +52,7 @@ class APP_EXPORT QgsMeasureTool : public QgsMapTool
void addPoint( const QgsPoint &point );

//! Returns reference to array of the points
const QList<QgsPoint>& points();
QList<QgsPoint> points();

// Inherited from QgsMapTool

Expand Down
2 changes: 1 addition & 1 deletion src/core/auth/qgsauthmethodregistry.cpp
Expand Up @@ -246,7 +246,7 @@ QString QgsAuthMethodRegistry::pluginList( bool asHtml ) const
return list;
}

const QDir &QgsAuthMethodRegistry::libraryDirectory() const
QDir QgsAuthMethodRegistry::libraryDirectory() const
{
return mLibraryDirectory;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/auth/qgsauthmethodregistry.h
Expand Up @@ -56,7 +56,7 @@ class CORE_EXPORT QgsAuthMethodRegistry
QString pluginList( bool asHtml = false ) const;

//! Return library directory where plugins are found
const QDir & libraryDirectory() const;
QDir libraryDirectory() const;

//! Set library directory where to search for plugins
void setLibraryDirectory( const QDir & path );
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgsatlascomposition.h
Expand Up @@ -176,7 +176,7 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
* @see setPredefinedScales
* @see QgsComposerMap::atlasScalingMode
*/
const QVector<qreal>& predefinedScales() const { return mPredefinedScales; }
QVector<qreal> predefinedScales() const { return mPredefinedScales; }

/** Sets the list of predefined scales for the atlas. This is used
* for maps which are set to the predefined atlas scaling mode.
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerhtml.h
Expand Up @@ -80,7 +80,7 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
* @see setUrl
* @see contentMode
*/
const QUrl& url() const { return mUrl; }
QUrl url() const { return mUrl; }

/** Sets the HTML to display in the item when the item is using
* the QgsComposerHtml::ManualHtml mode. Setting the HTML using this function
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposition.h
Expand Up @@ -301,7 +301,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene, public QgsExpressionCo
double snapGridOffsetY() const {return mSnapGridOffsetY;}

void setGridPen( const QPen& p );
const QPen& gridPen() const {return mGridPen;}
QPen gridPen() const {return mGridPen;}

void setGridStyle( const GridStyle s );
GridStyle gridStyle() const {return mGridStyle;}
Expand Down
9 changes: 2 additions & 7 deletions src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -1109,14 +1109,9 @@ bool QgsLayerTreeModel::testFlag( QgsLayerTreeModel::Flag f ) const
return mFlags.testFlag( f );
}

const QIcon& QgsLayerTreeModel::iconGroup()
QIcon QgsLayerTreeModel::iconGroup()
{
static QIcon icon;

if ( icon.isNull() )
icon = QgsApplication::getThemeIcon( QStringLiteral( "/mActionFolder.svg" ) );

return icon;
return QgsApplication::getThemeIcon( QStringLiteral( "/mActionFolder.svg" ) );
}

QList<QgsLayerTreeModelLegendNode*> QgsLayerTreeModel::filterLegendNodes( const QList<QgsLayerTreeModelLegendNode*>& nodes )
Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodel.h
Expand Up @@ -255,7 +255,7 @@ class CORE_EXPORT QgsLayerTreeModel : public QAbstractItemModel
*/
void refreshScaleBasedLayers( const QModelIndex& index = QModelIndex() );

static const QIcon& iconGroup();
static QIcon iconGroup();

//! Filter nodes from QgsMapLayerLegend according to the current filtering rules
QList<QgsLayerTreeModelLegendNode*> filterLegendNodes( const QList<QgsLayerTreeModelLegendNode*>& nodes );
Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -585,7 +585,7 @@ QgsWmsLegendNode::QgsWmsLegendNode( QgsLayerTreeLayer* nodeLayer, QObject* paren
{
}

const QImage& QgsWmsLegendNode::getLegendGraphic() const
QImage QgsWmsLegendNode::getLegendGraphic() const
{
if ( ! mValid && ! mFetcher )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodellegendnode.h
Expand Up @@ -334,7 +334,7 @@ class CORE_EXPORT QgsWmsLegendNode : public QgsLayerTreeModelLegendNode
private:

// Lazily initializes mImage
const QImage& getLegendGraphic() const;
QImage getLegendGraphic() const;

QImage renderMessage( const QString& msg ) const;

Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreenode.h
Expand Up @@ -84,7 +84,7 @@ class CORE_EXPORT QgsLayerTreeNode : public QObject
//! Get list of children of the node. Children are owned by the parent
QList<QgsLayerTreeNode*> children() { return mChildren; }
//! Get list of children of the node. Children are owned by the parent
const QList<QgsLayerTreeNode*>& children() const { return mChildren; }
QList<QgsLayerTreeNode*> children() const { return mChildren; }

//! Return name of the node
//! @note added in 3.0
Expand Down

0 comments on commit 231f6af

Please sign in to comment.