Skip to content

Commit 6c928ef

Browse files
committed
Add typedefs for QPointer QgsMapLayers
1 parent f720106 commit 6c928ef

14 files changed

+45
-30
lines changed

src/core/annotations/qgsannotation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class CORE_EXPORT QgsAnnotation : public QObject
348348
QPointF mBalloonSegmentPoint2;
349349

350350
//! Associated layer (or nullptr if not attached to a layer)
351-
QPointer<QgsMapLayer> mMapLayer;
351+
QgsWeakMapLayerPointer mMapLayer;
352352

353353
//! Associated feature, or invalid feature if no feature associated
354354
QgsFeature mFeature;

src/core/composer/qgscomposermap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ bool QgsComposerMap::writeXml( QDomElement& elem, QDomDocument & doc ) const
12311231

12321232
//layer set
12331233
QDomElement layerSetElem = doc.createElement( QStringLiteral( "LayerSet" ) );
1234-
Q_FOREACH ( const QPointer<QgsMapLayer>& layerPtr, mLayers )
1234+
Q_FOREACH ( const QgsWeakMapLayerPointer& layerPtr, mLayers )
12351235
{
12361236
QgsMapLayer* layer = layerPtr.data();
12371237
if ( !layer )
@@ -1557,7 +1557,7 @@ void QgsComposerMap::setLayerStyleOverrides( const QMap<QString, QString>& overr
15571557
void QgsComposerMap::storeCurrentLayerStyles()
15581558
{
15591559
mLayerStyleOverrides.clear();
1560-
Q_FOREACH ( const QPointer<QgsMapLayer>& layerPtr, mLayers )
1560+
Q_FOREACH ( const QgsWeakMapLayerPointer& layerPtr, mLayers )
15611561
{
15621562
if ( QgsMapLayer* layer = layerPtr.data() )
15631563
{

src/core/composer/qgscomposermap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgsrectangle.h"
2424
#include "qgscoordinatereferencesystem.h"
2525
#include "qgsrendercontext.h"
26+
#include "qgsmaplayer.h"
2627
#include <QFont>
2728
#include <QGraphicsRectItem>
2829

@@ -542,7 +543,7 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
542543
bool mKeepLayerSet;
543544

544545
//! Stored layer list (used if layer live-link mKeepLayerSet is disabled)
545-
QList< QPointer<QgsMapLayer> > mLayers;
546+
QgsWeakMapLayerPointerList mLayers;
546547

547548
bool mKeepLayerStyles;
548549
//! Stored style names (value) to be used with particular layer IDs (key) instead of default style

src/core/qgsexpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ static QgsExpression::Node* getNode( const QVariant& value, QgsExpression* paren
332332

333333
QgsVectorLayer* getVectorLayer( const QVariant& value, QgsExpression* )
334334
{
335-
QgsMapLayer* ml = value.value< QPointer<QgsMapLayer> >().data();
335+
QgsMapLayer* ml = value.value< QgsWeakMapLayerPointer >().data();
336336
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( ml );
337337
if ( !vl )
338338
{

src/core/qgsexpressioncontext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ QgsExpressionContextScope* QgsExpressionContextUtils::layerScope( const QgsMapLa
760760

761761
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer_name" ), layer->name(), true ) );
762762
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer_id" ), layer->id(), true ) );
763-
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer" ), QVariant::fromValue<QPointer<QgsMapLayer> >( QPointer<QgsMapLayer>( const_cast<QgsMapLayer*>( layer ) ) ), true ) );
763+
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer" ), QVariant::fromValue<QgsWeakMapLayerPointer >( QgsWeakMapLayerPointer( const_cast<QgsMapLayer*>( layer ) ) ), true ) );
764764

765765
const QgsVectorLayer* vLayer = dynamic_cast< const QgsVectorLayer* >( layer );
766766
if ( vLayer )

src/core/qgsmaplayer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,4 +920,18 @@ class CORE_EXPORT QgsMapLayer : public QObject
920920

921921
Q_DECLARE_METATYPE( QgsMapLayer* )
922922

923+
/**
924+
* Weak pointer for QgsMapLayer
925+
* @note added in QGIS 3.0
926+
* @note not available in Python bindings
927+
*/
928+
typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
929+
930+
/**
931+
* A list of weak pointers to QgsMapLayers.
932+
* @note added in QGIS 3.0
933+
* @note not available in Python bindings
934+
*/
935+
typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
936+
923937
#endif

src/core/qgsmaplayerlistutils.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616

1717
/// @cond PRIVATE
1818

19-
inline QList<QgsMapLayer*> _qgis_listQPointerToRaw( const QList< QPointer<QgsMapLayer> >& layers )
19+
inline QList<QgsMapLayer*> _qgis_listQPointerToRaw( const QgsWeakMapLayerPointerList& layers )
2020
{
2121
QList<QgsMapLayer*> lst;
2222
lst.reserve( layers.count() );
23-
Q_FOREACH ( const QPointer<QgsMapLayer>& layerPtr, layers )
23+
Q_FOREACH ( const QgsWeakMapLayerPointer& layerPtr, layers )
2424
{
2525
if ( layerPtr )
2626
lst.append( layerPtr.data() );
2727
}
2828
return lst;
2929
}
3030

31-
inline QList< QPointer<QgsMapLayer> > _qgis_listRawToQPointer( const QList<QgsMapLayer*>& layers )
31+
inline QgsWeakMapLayerPointerList _qgis_listRawToQPointer( const QList<QgsMapLayer*>& layers )
3232
{
33-
QList< QPointer<QgsMapLayer> > lst;
33+
QgsWeakMapLayerPointerList lst;
3434
lst.reserve( layers.count() );
3535
Q_FOREACH ( QgsMapLayer* layer, layers )
3636
{
@@ -39,11 +39,11 @@ inline QList< QPointer<QgsMapLayer> > _qgis_listRawToQPointer( const QList<QgsMa
3939
return lst;
4040
}
4141

42-
inline QStringList _qgis_listQPointerToIDs( const QList< QPointer<QgsMapLayer> >& layers )
42+
inline QStringList _qgis_listQPointerToIDs( const QgsWeakMapLayerPointerList& layers )
4343
{
4444
QStringList lst;
4545
lst.reserve( layers.count() );
46-
Q_FOREACH ( const QPointer<QgsMapLayer>& layerPtr, layers )
46+
Q_FOREACH ( const QgsWeakMapLayerPointer& layerPtr, layers )
4747
{
4848
if ( layerPtr )
4949
lst << layerPtr->id();
@@ -93,7 +93,7 @@ inline static QgsMapLayer* _qgis_findLayer( const QList< QgsMapLayer*> layers, c
9393
}
9494
}
9595

96-
inline uint qHash( const QPointer< QgsMapLayer >& key )
96+
inline uint qHash( const QgsWeakMapLayerPointer& key )
9797
{
9898
return qHash( key ? key->id() : QString() );
9999
}

src/core/qgsmaprenderercache.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void QgsMapRendererCache::clearInternal()
3535
mScale = 0;
3636

3737
// make sure we are disconnected from all layers
38-
Q_FOREACH ( const QPointer< QgsMapLayer >& layer, mConnectedLayers )
38+
Q_FOREACH ( const QgsWeakMapLayerPointer& layer, mConnectedLayers )
3939
{
4040
if ( layer.data() )
4141
{
@@ -48,9 +48,9 @@ void QgsMapRendererCache::clearInternal()
4848

4949
void QgsMapRendererCache::dropUnusedConnections()
5050
{
51-
QSet< QPointer< QgsMapLayer > > stillDepends = dependentLayers();
52-
QSet< QPointer< QgsMapLayer > > disconnects = mConnectedLayers.subtract( stillDepends );
53-
Q_FOREACH ( const QPointer< QgsMapLayer >& layer, disconnects )
51+
QSet< QgsWeakMapLayerPointer > stillDepends = dependentLayers();
52+
QSet< QgsWeakMapLayerPointer > disconnects = mConnectedLayers.subtract( stillDepends );
53+
Q_FOREACH ( const QgsWeakMapLayerPointer& layer, disconnects )
5454
{
5555
if ( layer.data() )
5656
{
@@ -61,13 +61,13 @@ void QgsMapRendererCache::dropUnusedConnections()
6161
mConnectedLayers = stillDepends;
6262
}
6363

64-
QSet<QPointer<QgsMapLayer> > QgsMapRendererCache::dependentLayers() const
64+
QSet<QgsWeakMapLayerPointer > QgsMapRendererCache::dependentLayers() const
6565
{
66-
QSet< QPointer< QgsMapLayer > > result;
66+
QSet< QgsWeakMapLayerPointer > result;
6767
QMap<QString, CacheParameters>::const_iterator it = mCachedImages.constBegin();
6868
for ( ; it != mCachedImages.constEnd(); ++it )
6969
{
70-
Q_FOREACH ( const QPointer< QgsMapLayer >& l, it.value().dependentLayers )
70+
Q_FOREACH ( const QgsWeakMapLayerPointer& l, it.value().dependentLayers )
7171
{
7272
if ( l.data() )
7373
result << l;
@@ -107,7 +107,7 @@ void QgsMapRendererCache::setCacheImage( const QString& cacheKey, const QImage&
107107
if ( layer )
108108
{
109109
params.dependentLayers << layer;
110-
if ( !mConnectedLayers.contains( QPointer< QgsMapLayer >( layer ) ) )
110+
if ( !mConnectedLayers.contains( QgsWeakMapLayerPointer( layer ) ) )
111111
{
112112
connect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapRendererCache::layerRequestedRepaint );
113113
mConnectedLayers << layer;

src/core/qgsmaprenderercache.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class CORE_EXPORT QgsMapRendererCache : public QObject
9999
struct CacheParameters
100100
{
101101
QImage cachedImage;
102-
QList< QPointer< QgsMapLayer > > dependentLayers;
102+
QgsWeakMapLayerPointerList dependentLayers;
103103
};
104104

105105
//! Invalidate cache contents (without locking)
@@ -108,7 +108,7 @@ class CORE_EXPORT QgsMapRendererCache : public QObject
108108
//! Disconnects from layers we no longer care about
109109
void dropUnusedConnections();
110110

111-
QSet< QPointer< QgsMapLayer > > dependentLayers() const;
111+
QSet< QgsWeakMapLayerPointer > dependentLayers() const;
112112

113113
mutable QMutex mMutex;
114114
QgsRectangle mExtent;
@@ -117,7 +117,7 @@ class CORE_EXPORT QgsMapRendererCache : public QObject
117117
//! Map of cache key to cache parameters
118118
QMap<QString, CacheParameters> mCachedImages;
119119
//! List of all layers on which this cache is currently connected
120-
QSet< QPointer< QgsMapLayer > > mConnectedLayers;
120+
QSet< QgsWeakMapLayerPointer > mConnectedLayers;
121121
};
122122

123123

src/core/qgsmaprendererjob.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct LayerRenderJob
5050
QPainter::CompositionMode blendMode;
5151
double opacity;
5252
bool cached; // if true, img already contains cached image from previous rendering
53-
QPointer< QgsMapLayer > layer;
53+
QgsWeakMapLayerPointer layer;
5454
int renderingTime; //!< Time it took to render the layer in ms (it is -1 if not rendered or still rendering)
5555
};
5656

0 commit comments

Comments
 (0)