Skip to content

Commit 231f6af

Browse files
committed
Don't return const references to implicitly shared Qt classes
Instead return the inexpensive copies. Should provide extra safety against issues like #14822 (refs #14822)
1 parent ef8a135 commit 231f6af

File tree

97 files changed

+172
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+172
-222
lines changed

python/analysis/raster/qgsrelief.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class QgsRelief
2626

2727
void clearReliefColors();
2828
void addReliefColorClass( const QgsRelief::ReliefColor& color );
29-
const QList< QgsRelief::ReliefColor >& reliefColors() const;
29+
QList< QgsRelief::ReliefColor > reliefColors() const;
3030
void setReliefColors( const QList< QgsRelief::ReliefColor >& c );
3131

3232
/** Calculates class breaks according with the method of Buenzli (2011) using an iterative algorithm for segmented regression

python/core/composer/qgsatlascomposition.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public:
145145
* @see setPredefinedScales
146146
* @see QgsComposerMap::atlasScalingMode
147147
*/
148-
const QVector<qreal>& predefinedScales() const;
148+
QVector<qreal> predefinedScales() const;
149149

150150
/** Sets the list of predefined scales for the atlas. This is used
151151
* for maps which are set to the predefined atlas scaling mode.

python/core/composer/qgscomposerhtml.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class QgsComposerHtml: QgsComposerMultiFrame
5151
* @see setUrl
5252
* @see contentMode
5353
*/
54-
const QUrl& url() const;
54+
QUrl url() const;
5555

5656
/** Sets the HTML to display in the item when the item is using
5757
* the QgsComposerHtml::ManualHtml mode. Setting the HTML using this function

python/core/composer/qgscomposition.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
235235
double snapGridOffsetY() const;
236236

237237
void setGridPen( const QPen& p );
238-
const QPen& gridPen() const;
238+
QPen gridPen() const;
239239

240240
void setGridStyle( const GridStyle s );
241241
GridStyle gridStyle() const;

python/core/layertree/qgslayertreemodel.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class QgsLayerTreeModel : QAbstractItemModel
228228
*/
229229
void refreshScaleBasedLayers( const QModelIndex& index = QModelIndex() );
230230

231-
static const QIcon& iconGroup();
231+
static QIcon iconGroup();
232232

233233
//! Filter nodes from QgsMapLayerLegend according to the current filtering rules
234234
QList<QgsLayerTreeModelLegendNode*> filterLegendNodes( const QList<QgsLayerTreeModelLegendNode*>& nodes );

python/core/qgsdataitem.sip

+11-11
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,12 @@ class QgsLayerItem : QgsDataItem
308308
virtual QString comments() const;
309309

310310
public:
311-
static const QIcon &iconPoint();
312-
static const QIcon &iconLine();
313-
static const QIcon &iconPolygon();
314-
static const QIcon &iconTable();
315-
static const QIcon &iconRaster();
316-
static const QIcon &iconDefault();
311+
static QIcon iconPoint();
312+
static QIcon iconLine();
313+
static QIcon iconPolygon();
314+
static QIcon iconTable();
315+
static QIcon iconRaster();
316+
static QIcon iconDefault();
317317

318318
virtual QString layerName() const;
319319
};
@@ -331,8 +331,8 @@ class QgsDataCollectionItem : QgsDataItem
331331

332332
void addChild( QgsDataItem *item /Transfer/ );
333333

334-
static const QIcon &iconDir(); // shared icon: open/closed directory
335-
static const QIcon &iconDataCollection(); // default icon for data collection
334+
static QIcon iconDir(); // shared icon: open/closed directory
335+
static QIcon iconDataCollection(); // default icon for data collection
336336
};
337337

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

479479
//! Icon for favorites group
480-
static const QIcon &iconFavorites();
480+
static QIcon iconFavorites();
481481
};
482482

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

494494
QVector<QgsDataItem*> createChildren();
495-
const QStringList & getZipFileList();
495+
QStringList getZipFileList();
496496

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

507-
static const QIcon &iconZip();
507+
static QIcon iconZip();
508508

509509
};

python/core/qgsexpressionfieldbuffer.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ class QgsExpressionFieldBuffer
6464
*/
6565
void updateFields( QgsFields& flds );
6666

67-
const QList<QgsExpressionFieldBuffer::ExpressionField>& expressions() const;
67+
QList<QgsExpressionFieldBuffer::ExpressionField> expressions() const;
6868
};

python/core/qgsnetworkaccessmanager.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class QgsNetworkAccessManager : QNetworkAccessManager
4646
const QNetworkProxy &fallbackProxy() const;
4747

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

5151
//! set fallback proxy and URL that shouldn't use it.
5252
void setFallbackProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes );

python/core/qgsproviderregistry.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class QgsProviderRegistry
2929
QString pluginList( bool asHtml = false ) const;
3030

3131
/** Return library directory where plugins are found */
32-
const QDir & libraryDirectory() const;
32+
QDir libraryDirectory() const;
3333

3434
/** Set library directory where to search for plugins */
3535
void setLibraryDirectory( const QDir & path );

python/core/qgsrelationmanager.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class QgsRelationManager : QObject
2525
*
2626
* @return A QMap where the key is the relation id, the value the relation object.
2727
*/
28-
const QMap<QString, QgsRelation>& relations() const;
28+
QMap<QString, QgsRelation> relations() const;
2929

3030
/**
3131
* Add a relation.

python/core/qgsvectordataprovider.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class QgsVectorDataProvider : QgsDataProvider
375375
/**
376376
* Returns the names of the supported types
377377
*/
378-
const QList< QgsVectorDataProvider::NativeType > &nativeTypes() const;
378+
QList< QgsVectorDataProvider::NativeType > nativeTypes() const;
379379

380380
/**
381381
* Returns true if the provider is strict about the type of inserted features

python/core/qgsvectorlayer.sip

+2-2
Original file line numberDiff line numberDiff line change
@@ -1111,10 +1111,10 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator
11111111

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

1114-
const QSet<QString>& excludeAttributesWms() const;
1114+
QSet<QString> excludeAttributesWms() const;
11151115
void setExcludeAttributesWms( const QSet<QString>& att );
11161116

1117-
const QSet<QString>& excludeAttributesWfs() const;
1117+
QSet<QString> excludeAttributesWfs() const;
11181118
void setExcludeAttributesWfs( const QSet<QString>& att );
11191119

11201120
/** Delete an attribute field (but does not commit it) */

python/core/symbology-ng/qgssvgcache.sip

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class QgsSvgCache : QObject
7979
* @param rasterScaleFactor raster scale factor
8080
* @param fitsInCache
8181
*/
82-
const QImage& svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
82+
QImage svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
8383
double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache );
8484
/** Get SVG as QPicture&.
8585
* @param file Absolute or relative path to SVG file.
@@ -91,7 +91,7 @@ class QgsSvgCache : QObject
9191
* @param rasterScaleFactor raster scale factor
9292
* @param forceVectorOutput
9393
*/
94-
const QPicture& svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
94+
QPicture svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
9595
double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput = false );
9696

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

146146
/** Get SVG content*/
147-
const QByteArray& svgContent( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
147+
QByteArray svgContent( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
148148
double widthScaleFactor, double rasterScaleFactor );
149149

150150
signals:

python/gui/editorwidgets/core/qgseditorwidgetregistry.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class QgsEditorWidgetRegistry : QObject
110110
*
111111
* @return All ids and factories
112112
*/
113-
const QMap<QString, QgsEditorWidgetFactory*>& factories();
113+
QMap<QString, QgsEditorWidgetFactory*> factories();
114114

115115
/**
116116
* Get a factory for the given widget type id.

python/gui/qgsadvanceddigitizingdockwidget.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class QgsAdvancedDigitizingDockWidget : QDockWidget
269269
/**
270270
* Snapped to a segment
271271
*/
272-
const QList<QgsPoint>& snappedSegment() const;
272+
QList<QgsPoint> snappedSegment() const;
273273

274274
//! return the action used to enable/disable the tools
275275
QAction* enableAction();

python/server/qgsserverprojectparser.sip

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class QgsServerProjectParser
6060

6161
QStringList supportedOutputCrsList() const;
6262

63-
const QList<QDomElement>& projectLayerElements() const;
63+
QList<QDomElement> projectLayerElements() const;
6464

65-
const QList<QDomElement>& legendGroupElements() const;
65+
QList<QDomElement> legendGroupElements() const;
6666

6767
QString projectTitle() const;
6868

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

76-
const QHash< QString, QDomElement >& projectLayerElementsByName() const;
77-
const QHash< QString, QDomElement >& projectLayerElementsById() const;
76+
QHash< QString, QDomElement > projectLayerElementsByName() const;
77+
QHash< QString, QDomElement > projectLayerElementsById() const;
7878

7979
// SIP doesn't like QMap:
8080
// void layerFromLegendLayer( const QDomElement& legendLayerElem, QMap< int, QgsMapLayer*>& layers, bool useCache = true ) const;

python/server/qgswmsconfigparser.sip

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class QgsWmsConfigParser
8888
virtual double legendIconLabelSpace() const = 0;
8989
virtual double legendSymbolWidth() const = 0;
9090
virtual double legendSymbolHeight() const = 0;
91-
virtual const QFont& legendLayerFont() const = 0;
92-
virtual const QFont& legendItemFont() const = 0;
91+
virtual QFont legendLayerFont() const = 0;
92+
virtual QFont legendItemFont() const = 0;
9393

9494
virtual double maxWidth() const = 0;
9595
virtual double maxHeight() const = 0;

python/server/qgswmsprojectparser.sip

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class QgsWmsProjectParser : public QgsWmsConfigParser
4646
double legendIconLabelSpace() const /*override*/ ;
4747
double legendSymbolWidth() const /*override*/ ;
4848
double legendSymbolHeight() const /*override*/ ;
49-
const QFont& legendLayerFont() const /*override*/ ;
50-
const QFont& legendItemFont() const /*override*/ ;
49+
QFont legendLayerFont() const /*override*/ ;
50+
QFont legendItemFont() const /*override*/ ;
5151

5252
double maxWidth() const /*override*/ ;
5353
double maxHeight() const /*override*/ ;

src/analysis/interpolation/qgsinterpolator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ANALYSIS_EXPORT QgsInterpolator
6767
virtual int interpolatePoint( double x, double y, double& result ) = 0;
6868

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

7272
protected:
7373

src/analysis/raster/qgsrelief.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ANALYSIS_EXPORT QgsRelief
6161

6262
void clearReliefColors();
6363
void addReliefColorClass( const ReliefColor& color );
64-
const QList< ReliefColor >& reliefColors() const { return mReliefColors; }
64+
QList< ReliefColor > reliefColors() const { return mReliefColors; }
6565
void setReliefColors( const QList< ReliefColor >& c ) { mReliefColors = c; }
6666

6767
/** Calculates class breaks according with the method of Buenzli (2011) using an iterative algorithm for segmented regression

src/app/composer/qgscomposer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
104104

105105
QAction* windowAction() {return mWindowAction;}
106106

107-
const QString& title() const {return mTitle;}
107+
QString title() const {return mTitle;}
108108
void setTitle( const QString& title );
109109

110110
/** Loads the contents of a template document into the composer's composition.

src/app/qgsmeasuretool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ QgsMeasureTool::~QgsMeasureTool()
6565
}
6666

6767

68-
const QList<QgsPoint>& QgsMeasureTool::points()
68+
QList<QgsPoint> QgsMeasureTool::points()
6969
{
7070
return mPoints;
7171
}

src/app/qgsmeasuretool.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class APP_EXPORT QgsMeasureTool : public QgsMapTool
5252
void addPoint( const QgsPoint &point );
5353

5454
//! Returns reference to array of the points
55-
const QList<QgsPoint>& points();
55+
QList<QgsPoint> points();
5656

5757
// Inherited from QgsMapTool
5858

src/core/auth/qgsauthmethodregistry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ QString QgsAuthMethodRegistry::pluginList( bool asHtml ) const
246246
return list;
247247
}
248248

249-
const QDir &QgsAuthMethodRegistry::libraryDirectory() const
249+
QDir QgsAuthMethodRegistry::libraryDirectory() const
250250
{
251251
return mLibraryDirectory;
252252
}

src/core/auth/qgsauthmethodregistry.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class CORE_EXPORT QgsAuthMethodRegistry
5656
QString pluginList( bool asHtml = false ) const;
5757

5858
//! Return library directory where plugins are found
59-
const QDir & libraryDirectory() const;
59+
QDir libraryDirectory() const;
6060

6161
//! Set library directory where to search for plugins
6262
void setLibraryDirectory( const QDir & path );

src/core/composer/qgsatlascomposition.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
176176
* @see setPredefinedScales
177177
* @see QgsComposerMap::atlasScalingMode
178178
*/
179-
const QVector<qreal>& predefinedScales() const { return mPredefinedScales; }
179+
QVector<qreal> predefinedScales() const { return mPredefinedScales; }
180180

181181
/** Sets the list of predefined scales for the atlas. This is used
182182
* for maps which are set to the predefined atlas scaling mode.

src/core/composer/qgscomposerhtml.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
8080
* @see setUrl
8181
* @see contentMode
8282
*/
83-
const QUrl& url() const { return mUrl; }
83+
QUrl url() const { return mUrl; }
8484

8585
/** Sets the HTML to display in the item when the item is using
8686
* the QgsComposerHtml::ManualHtml mode. Setting the HTML using this function

src/core/composer/qgscomposition.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene, public QgsExpressionCo
301301
double snapGridOffsetY() const {return mSnapGridOffsetY;}
302302

303303
void setGridPen( const QPen& p );
304-
const QPen& gridPen() const {return mGridPen;}
304+
QPen gridPen() const {return mGridPen;}
305305

306306
void setGridStyle( const GridStyle s );
307307
GridStyle gridStyle() const {return mGridStyle;}

src/core/layertree/qgslayertreemodel.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -1109,14 +1109,9 @@ bool QgsLayerTreeModel::testFlag( QgsLayerTreeModel::Flag f ) const
11091109
return mFlags.testFlag( f );
11101110
}
11111111

1112-
const QIcon& QgsLayerTreeModel::iconGroup()
1112+
QIcon QgsLayerTreeModel::iconGroup()
11131113
{
1114-
static QIcon icon;
1115-
1116-
if ( icon.isNull() )
1117-
icon = QgsApplication::getThemeIcon( QStringLiteral( "/mActionFolder.svg" ) );
1118-
1119-
return icon;
1114+
return QgsApplication::getThemeIcon( QStringLiteral( "/mActionFolder.svg" ) );
11201115
}
11211116

11221117
QList<QgsLayerTreeModelLegendNode*> QgsLayerTreeModel::filterLegendNodes( const QList<QgsLayerTreeModelLegendNode*>& nodes )

src/core/layertree/qgslayertreemodel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class CORE_EXPORT QgsLayerTreeModel : public QAbstractItemModel
255255
*/
256256
void refreshScaleBasedLayers( const QModelIndex& index = QModelIndex() );
257257

258-
static const QIcon& iconGroup();
258+
static QIcon iconGroup();
259259

260260
//! Filter nodes from QgsMapLayerLegend according to the current filtering rules
261261
QList<QgsLayerTreeModelLegendNode*> filterLegendNodes( const QList<QgsLayerTreeModelLegendNode*>& nodes );

src/core/layertree/qgslayertreemodellegendnode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ QgsWmsLegendNode::QgsWmsLegendNode( QgsLayerTreeLayer* nodeLayer, QObject* paren
585585
{
586586
}
587587

588-
const QImage& QgsWmsLegendNode::getLegendGraphic() const
588+
QImage QgsWmsLegendNode::getLegendGraphic() const
589589
{
590590
if ( ! mValid && ! mFetcher )
591591
{

src/core/layertree/qgslayertreemodellegendnode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class CORE_EXPORT QgsWmsLegendNode : public QgsLayerTreeModelLegendNode
334334
private:
335335

336336
// Lazily initializes mImage
337-
const QImage& getLegendGraphic() const;
337+
QImage getLegendGraphic() const;
338338

339339
QImage renderMessage( const QString& msg ) const;
340340

src/core/layertree/qgslayertreenode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class CORE_EXPORT QgsLayerTreeNode : public QObject
8484
//! Get list of children of the node. Children are owned by the parent
8585
QList<QgsLayerTreeNode*> children() { return mChildren; }
8686
//! Get list of children of the node. Children are owned by the parent
87-
const QList<QgsLayerTreeNode*>& children() const { return mChildren; }
87+
QList<QgsLayerTreeNode*> children() const { return mChildren; }
8888

8989
//! Return name of the node
9090
//! @note added in 3.0

0 commit comments

Comments
 (0)