Skip to content
Permalink
Browse files
Change &operator to get()
  • Loading branch information
nyalldawson committed Apr 18, 2017
1 parent 2ca70dc commit f413963e2f554818e7db5d70b817c3340f29cc16
@@ -76,7 +76,7 @@ QgsComposerAttributeTableV2::QgsComposerAttributeTableV2( QgsComposition *compos
{
resetColumns();
//listen for modifications to layer and refresh table when they occur
connect( &mVectorLayer, &QgsVectorLayer::layerModified, this, &QgsComposerTableV2::refreshAttributes );
connect( mVectorLayer.get(), &QgsVectorLayer::layerModified, this, &QgsComposerTableV2::refreshAttributes );
}

if ( mComposition )
@@ -102,7 +102,7 @@ QString QgsComposerAttributeTableV2::displayName() const

void QgsComposerAttributeTableV2::setVectorLayer( QgsVectorLayer *layer )
{
if ( layer == &mVectorLayer )
if ( layer == mVectorLayer.get() )
{
//no change
return;
@@ -123,7 +123,7 @@ void QgsComposerAttributeTableV2::setVectorLayer( QgsVectorLayer *layer )
resetColumns();

//listen for modifications to layer and refresh table when they occur
connect( &mVectorLayer, &QgsVectorLayer::layerModified, this, &QgsComposerTableV2::refreshAttributes );
connect( mVectorLayer.get(), &QgsVectorLayer::layerModified, this, &QgsComposerTableV2::refreshAttributes );
}

refreshAttributes();
@@ -538,7 +538,7 @@ QgsExpressionContext QgsComposerAttributeTableV2::createExpressionContext() cons

if ( mSource == LayerAttributes )
{
context.appendScope( QgsExpressionContextUtils::layerScope( &mVectorLayer ) );
context.appendScope( QgsExpressionContextUtils::layerScope( mVectorLayer.get() ) );
}

return context;
@@ -562,7 +562,7 @@ QgsVectorLayer *QgsComposerAttributeTableV2::sourceLayer()
case QgsComposerAttributeTableV2::AtlasFeature:
return mComposition->atlasComposition().coverageLayer();
case QgsComposerAttributeTableV2::LayerAttributes:
return &mVectorLayer;
return mVectorLayer.get();
case QgsComposerAttributeTableV2::RelationChildren:
{
QgsRelation relation = mComposition->project()->relationManager()->relation( mRelationId );
@@ -120,7 +120,7 @@ class CORE_EXPORT QgsComposerAttributeTableV2: public QgsComposerTableV2
* \returns attribute table's current vector layer
* \see setVectorLayer
*/
QgsVectorLayer *vectorLayer() const { return &mVectorLayer; }
QgsVectorLayer *vectorLayer() const { return mVectorLayer.get(); }

/** Sets the relation id from which to display child features
* \param relationId id for relation to display child features from
@@ -1532,7 +1532,7 @@ void QgsComposerMap::storeCurrentLayerStyles()
mLayerStyleOverrides.clear();
Q_FOREACH ( const QgsMapLayerRef &layerRef, mLayers )
{
if ( QgsMapLayer *layer = &layerRef )
if ( QgsMapLayer *layer = layerRef.get() )
{
QgsMapLayerStyle style;
style.readFromLayer( layer );
@@ -54,7 +54,7 @@ class CORE_EXPORT QgsLayerTreeLayer : public QgsLayerTreeNode

QString layerId() const { return mRef.layerId; }

QgsMapLayer *layer() const { return &mRef; }
QgsMapLayer *layer() const { return mRef.get(); }

/**
* Returns the layer's name.
@@ -47,7 +47,7 @@ inline QList<QgsMapLayer *> _qgis_listRefToRaw( const QList< QgsMapLayerRef > &l
Q_FOREACH ( const QgsMapLayerRef &layer, layers )
{
if ( layer )
lst.append( &layer );
lst.append( layer.get() );
}
return lst;
}
@@ -69,7 +69,7 @@ inline void _qgis_removeLayers( QList< QgsMapLayerRef > &list, QList< QgsMapLaye
while ( it.hasNext() )
{
QgsMapLayerRef &ref = it.next();
if ( layersToRemove.contains( &ref ) )
if ( layersToRemove.contains( ref.get() ) )
it.remove();
}
}
@@ -88,7 +88,7 @@ struct _LayerRef
* Returns a pointer to the layer, or nullptr if the reference has not yet been matched
* to a layer.
*/
TYPE *operator &() const
TYPE *get() const
{
return layer.data();
}
@@ -27,7 +27,7 @@ class CORE_EXPORT QgsVectorLayerJoinInfo
//! Sets weak reference to the joined layer
void setJoinLayer( QgsVectorLayer *layer ) { mJoinLayerRef = QgsVectorLayerRef( layer ); }
//! Returns joined layer (may be null if the reference was set by layer ID and not resolved yet)
QgsVectorLayer *joinLayer() const { return &mJoinLayerRef; }
QgsVectorLayer *joinLayer() const { return mJoinLayerRef.get(); }

//! Sets ID of the joined layer. It will need to be overwritten by setJoinLayer() to a reference to real layer
void setJoinLayerId( const QString &layerId ) { mJoinLayerRef = QgsVectorLayerRef( layerId ); }
@@ -162,7 +162,7 @@ void TestQgsMapLayer::layerRef()
{
// construct from layer
QgsVectorLayerRef ref( mpLayer );
QCOMPARE( &ref, mpLayer );
QCOMPARE( ref.get(), mpLayer );
QCOMPARE( ref.layer.data(), mpLayer );
QCOMPARE( ref.layerId, mpLayer->id() );
QCOMPARE( ref.name, QStringLiteral( "points" ) );
@@ -180,7 +180,7 @@ void TestQgsMapLayer::layerRef()
// create a weak reference
QgsVectorLayerRef ref2( mpLayer->id(), QStringLiteral( "points" ), mpLayer->publicSource(), QStringLiteral( "ogr" ) );
QVERIFY( !ref2 );
QVERIFY( !&ref2 );
QVERIFY( !ref2.get() );
QVERIFY( !ref2.layer.data() );
QCOMPARE( ref2.layerId, mpLayer->id() );
QCOMPARE( ref2.name, QStringLiteral( "points" ) );
@@ -193,7 +193,7 @@ void TestQgsMapLayer::layerRef()
// resolve layer using project
QCOMPARE( ref2.resolve( QgsProject::instance() ), mpLayer );
QVERIFY( ref2 );
QCOMPARE( &ref2, mpLayer );
QCOMPARE( ref2.get(), mpLayer );
QCOMPARE( ref2.layer.data(), mpLayer );
QCOMPARE( ref2.layerId, mpLayer->id() );
QCOMPARE( ref2.name, QStringLiteral( "points" ) );
@@ -202,9 +202,9 @@ void TestQgsMapLayer::layerRef()

// setLayer
QgsVectorLayerRef ref3;
QVERIFY( !&ref3 );
QVERIFY( !ref3.get() );
ref3.setLayer( mpLayer );
QCOMPARE( &ref3, mpLayer );
QCOMPARE( ref3.get(), mpLayer );
QCOMPARE( ref3.layer.data(), mpLayer );
QCOMPARE( ref3.layerId, mpLayer->id() );
QCOMPARE( ref3.name, QStringLiteral( "points" ) );
@@ -213,10 +213,10 @@ void TestQgsMapLayer::layerRef()

// weak resolve
QgsVectorLayerRef ref4( QStringLiteral( "badid" ), QStringLiteral( "points" ), mpLayer->publicSource(), QStringLiteral( "ogr" ) );
QVERIFY( !&ref4 );
QVERIFY( !ref4 );
QVERIFY( !ref4.resolve( QgsProject::instance() ) );
QCOMPARE( ref4.resolveWeakly( QgsProject::instance() ), mpLayer );
QCOMPARE( &ref4, mpLayer );
QCOMPARE( ref4.get(), mpLayer );
QCOMPARE( ref4.layer.data(), mpLayer );
QCOMPARE( ref4.layerId, mpLayer->id() );
QCOMPARE( ref4.name, QStringLiteral( "points" ) );
@@ -225,7 +225,7 @@ void TestQgsMapLayer::layerRef()

// try resolving a bad reference
QgsVectorLayerRef ref5( QStringLiteral( "badid" ), QStringLiteral( "points" ), mpLayer->publicSource(), QStringLiteral( "xxx" ) );
QVERIFY( !&ref5 );
QVERIFY( !ref5.get() );
QVERIFY( !ref5.resolve( QgsProject::instance() ) );
QVERIFY( !ref5.resolveWeakly( QgsProject::instance() ) );
}
@@ -240,8 +240,8 @@ void TestQgsMapLayer::layerRefListUtils()
listRawSource << vlA << vlB;

QList< QgsMapLayerRef > refs = _qgis_listRawToRef( listRawSource );
QCOMPARE( &refs.at( 0 ), vlA );
QCOMPARE( &refs.at( 1 ), vlB );
QCOMPARE( refs.at( 0 ).get(), vlA );
QCOMPARE( refs.at( 1 ).get(), vlB );

QList<QgsMapLayer *> raw = _qgis_listRefToRaw( refs );
QCOMPARE( raw, QList< QgsMapLayer *>() << vlA << vlB );
@@ -253,8 +253,8 @@ void TestQgsMapLayer::layerRefListUtils()

_qgis_removeLayers( refs, QList< QgsMapLayer *>() << vlB << vlD );
QCOMPARE( refs.size(), 2 );
QCOMPARE( &refs.at( 0 ), vlA );
QCOMPARE( &refs.at( 1 ), vlC );
QCOMPARE( refs.at( 0 ).get(), vlA );
QCOMPARE( refs.at( 1 ).get(), vlC );


}

0 comments on commit f413963

Please sign in to comment.