Skip to content

Commit

Permalink
Delete equality operator of QgsMapLayerRef and make its bool operator…
Browse files Browse the repository at this point in the history
… explicit

This will avoid implicit conversion to bool when comparing QList<QgsMapLayerRef>s in the future.
  • Loading branch information
uclaros authored and nyalldawson committed Oct 25, 2024
1 parent 45751f4 commit 66a909d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/3d/qgs3dmapsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "qgsrasterlayer.h"
#include "qgspointlightsettings.h"
#include "qgsdirectionallightsettings.h"
#include "qgsmaplayerlistutils_p.h"

#include <QDomDocument>
#include <QDomElement>
Expand Down Expand Up @@ -546,17 +547,12 @@ double Qgs3DMapSettings::terrainVerticalScale() const

void Qgs3DMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
{
QList<QgsMapLayerRef> lst;
lst.reserve( layers.count() );
for ( QgsMapLayer *layer : layers )
{
lst.append( layer );
}
const QList<QgsMapLayer *> raw = _qgis_listRefToRaw( mLayers );

if ( mLayers == lst )
if ( layers == raw )
return;

mLayers = lst;
mLayers = _qgis_listRawToRef( layers );
emit layersChanged();
}

Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsmaplayerref.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ struct _LayerRef
provider = l && l->dataProvider() ? l->dataProvider()->name() : QString();
}

/**
* Equality operator is deleted to avoid confusion as there are multiple ways two _LayerRef objects can be considered equal.
*/
bool operator==( const _LayerRef &other ) = delete;

/**
* Returns TRUE if the layer reference is resolved and contains a reference to an existing
* map layer.
*/
operator bool() const
explicit operator bool() const
{
return static_cast< bool >( layer.data() );
}
Expand Down

0 comments on commit 66a909d

Please sign in to comment.