Skip to content

Commit a2111b0

Browse files
committed
Use std::unique_ptr for LayerFeature
1 parent 8c85b73 commit a2111b0

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp

+38-5
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,38 @@ QgsGeometryCheckerUtils::LayerFeatures::iterator::iterator( const QStringList::c
9797
nextLayerFeature( true );
9898
}
9999

100+
QgsGeometryCheckerUtils::LayerFeatures::iterator::iterator( const QgsGeometryCheckerUtils::LayerFeatures::iterator &rh )
101+
{
102+
mLayerIt = rh.mLayerIt;
103+
mFeatureIt = rh.mFeatureIt;
104+
mParent = rh.mParent;
105+
mCurrentFeature = qgis::make_unique<LayerFeature>( *rh.mCurrentFeature.get() );
106+
}
107+
100108
bool QgsGeometryCheckerUtils::LayerFeature::useMapCrs() const
101109
{
102110
return mMapCrs;
103111
}
104112
QgsGeometryCheckerUtils::LayerFeatures::iterator::~iterator()
105113
{
106-
delete mCurrentFeature;
114+
}
115+
116+
QgsGeometryCheckerUtils::LayerFeatures::iterator QgsGeometryCheckerUtils::LayerFeatures::iterator::operator++( int )
117+
{
118+
iterator tmp( *this );
119+
++*this;
120+
return tmp;
121+
}
122+
123+
const QgsGeometryCheckerUtils::LayerFeature &QgsGeometryCheckerUtils::LayerFeatures::iterator::operator*() const
124+
{
125+
Q_ASSERT( mCurrentFeature );
126+
return *mCurrentFeature;
127+
}
128+
129+
bool QgsGeometryCheckerUtils::LayerFeatures::iterator::operator!=( const QgsGeometryCheckerUtils::LayerFeatures::iterator &other )
130+
{
131+
return mLayerIt != other.mLayerIt || mFeatureIt != other.mFeatureIt;
107132
}
108133

109134
const QgsGeometryCheckerUtils::LayerFeatures::iterator &QgsGeometryCheckerUtils::LayerFeatures::iterator::operator++()
@@ -127,8 +152,7 @@ bool QgsGeometryCheckerUtils::LayerFeatures::iterator::nextLayerFeature( bool be
127152
}
128153
// End
129154
mFeatureIt = QgsFeatureIds::const_iterator();
130-
delete mCurrentFeature;
131-
mCurrentFeature = nullptr;
155+
mCurrentFeature.reset();
132156
return false;
133157
}
134158

@@ -173,8 +197,7 @@ bool QgsGeometryCheckerUtils::LayerFeatures::iterator::nextFeature( bool begin )
173197
QgsFeature feature;
174198
if ( featurePool->getFeature( *mFeatureIt, feature ) && feature.geometry() && feature.geometry().constGet() )
175199
{
176-
delete mCurrentFeature;
177-
mCurrentFeature = new LayerFeature( mParent->mFeaturePools[*mLayerIt], feature, mParent->mContext, mParent->mUseMapCrs );
200+
mCurrentFeature.reset( new LayerFeature( mParent->mFeaturePools[*mLayerIt], feature, mParent->mContext, mParent->mUseMapCrs ) );
178201
return true;
179202
}
180203
++mFeatureIt;
@@ -225,6 +248,16 @@ QgsGeometryCheckerUtils::LayerFeatures::LayerFeatures( const QMap<QString, QgsFe
225248
}
226249
}
227250

251+
QgsGeometryCheckerUtils::LayerFeatures::iterator QgsGeometryCheckerUtils::LayerFeatures::begin() const
252+
{
253+
return iterator( mLayerIds.constBegin(), this );
254+
}
255+
256+
QgsGeometryCheckerUtils::LayerFeatures::iterator QgsGeometryCheckerUtils::LayerFeatures::end() const
257+
{
258+
return iterator( mLayerIds.end(), this );
259+
}
260+
228261
/////////////////////////////////////////////////////////////////////////////
229262

230263
std::unique_ptr<QgsGeometryEngine> QgsGeometryCheckerUtils::createGeomEngine( const QgsAbstractGeometry *geometry, double tolerance )

src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,25 @@ class ANALYSIS_EXPORT QgsGeometryCheckerUtils
101101
{
102102
public:
103103
iterator( const QList<QString>::const_iterator &layerIt, const LayerFeatures *parent );
104+
iterator( const iterator &rh );
104105
~iterator();
105106
const iterator &operator++();
106-
iterator operator++( int ) { iterator tmp( *this ); ++*this; return tmp; }
107-
const LayerFeature &operator*() const { Q_ASSERT( mCurrentFeature ); return *mCurrentFeature; }
108-
bool operator!=( const iterator &other ) { return mLayerIt != other.mLayerIt || mFeatureIt != other.mFeatureIt; }
107+
iterator operator++( int );
108+
const LayerFeature &operator*() const;
109+
bool operator!=( const iterator &other );
109110

110111
private:
111112
bool nextLayerFeature( bool begin );
112113
bool nextLayer( bool begin );
113114
bool nextFeature( bool begin );
114115
QList<QString>::const_iterator mLayerIt;
115116
QgsFeatureIds::const_iterator mFeatureIt;
116-
const LayerFeatures *mParent;
117-
const LayerFeature *mCurrentFeature = nullptr;
117+
const LayerFeatures *mParent = nullptr;
118+
std::unique_ptr<LayerFeature> mCurrentFeature;
118119
};
119120

120-
iterator begin() const { return iterator( mLayerIds.constBegin(), this ); }
121-
iterator end() const { return iterator( mLayerIds.end(), this ); }
121+
iterator begin() const;
122+
iterator end() const;
122123

123124
#endif
124125

0 commit comments

Comments
 (0)