Skip to content

Commit f575656

Browse files
authoredMar 11, 2019
Merge pull request #9461 from m-kuhn/pal_cleanup
Some cleanup in labeling and pal
2 parents 7757ffc + a133bca commit f575656

File tree

9 files changed

+35
-31
lines changed

9 files changed

+35
-31
lines changed
 

‎python/core/auto_generated/qgspallabeling.sip.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ class QgsLabelPosition
1919
#include "qgspallabeling.h"
2020
%End
2121
public:
22-
QgsLabelPosition( int id, double r, const QVector< QgsPointXY > &corners, const QgsRectangle &rect, double w, double h, const QString &layer, const QString &labeltext, const QFont &labelfont, bool upside_down, bool diagram = false, bool pinned = false, const QString &providerId = QString() );
22+
QgsLabelPosition( QgsFeatureId id, double r, const QVector< QgsPointXY > &corners, const QgsRectangle &rect, double w, double h, const QString &layer, const QString &labeltext, const QFont &labelfont, bool upside_down, bool diagram = false, bool pinned = false, const QString &providerId = QString() );
2323

2424
QgsLabelPosition();
2525
%Docstring
2626
Constructor for QgsLabelPosition
2727
%End
2828

29-
int featureId;
29+
QgsFeatureId featureId;
3030
double rotation;
3131
QVector< QgsPointXY > cornerPoints;
3232
QgsRectangle labelRect;

‎src/core/pal/layer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ bool Layer::registerFeature( QgsLabelFeature *lf )
118118
std::unique_ptr<FeaturePart> biggest_part;
119119

120120
// break the (possibly multi-part) geometry into simple geometries
121-
QLinkedList<const GEOSGeometry *> *simpleGeometries = Util::unmulti( lf->geometry() );
121+
std::unique_ptr<QLinkedList<const GEOSGeometry *>> simpleGeometries( Util::unmulti( lf->geometry() ) );
122122
if ( !simpleGeometries ) // unmulti() failed?
123123
{
124124
throw InternalException::UnknownGeometry();
@@ -203,12 +203,11 @@ bool Layer::registerFeature( QgsLabelFeature *lf )
203203
addFeaturePart( fpart.release(), lf->labelText() );
204204
addedFeature = true;
205205
}
206-
delete simpleGeometries;
207206

208207
if ( !featureGeomIsObstacleGeom )
209208
{
210209
//do the same for the obstacle geometry
211-
simpleGeometries = Util::unmulti( lf->obstacleGeometry() );
210+
simpleGeometries.reset( Util::unmulti( lf->obstacleGeometry() ) );
212211
if ( !simpleGeometries ) // unmulti() failed?
213212
{
214213
throw InternalException::UnknownGeometry();
@@ -249,7 +248,6 @@ bool Layer::registerFeature( QgsLabelFeature *lf )
249248
// feature part is ready!
250249
addObstaclePart( fpart.release() );
251250
}
252-
delete simpleGeometries;
253251
}
254252

255253
locker.unlock();

‎src/core/pal/problem.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,10 +2138,7 @@ void Problem::chain_search()
21382138

21392139
featWrap = nullptr;
21402140

2141-
for ( i = 0; i < nbft; i++ )
2142-
{
2143-
ok[i] = false;
2144-
}
2141+
std::fill( ok, ok + nbft, false );
21452142

21462143
//initialization();
21472144
init_sol_falp();

‎src/core/qgslabelsearchtree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void QgsLabelSearchTree::labelsInRect( const QgsRectangle &r, QList<QgsLabelPosi
7171
}
7272
}
7373

74-
bool QgsLabelSearchTree::insertLabel( pal::LabelPosition *labelPos, int featureId, const QString &layerName, const QString &labeltext, const QFont &labelfont, bool diagram, bool pinned, const QString &providerId )
74+
bool QgsLabelSearchTree::insertLabel( pal::LabelPosition *labelPos, QgsFeatureId featureId, const QString &layerName, const QString &labeltext, const QFont &labelfont, bool diagram, bool pinned, const QString &providerId )
7575
{
7676
if ( !labelPos )
7777
{

‎src/core/qgslabelsearchtree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CORE_EXPORT QgsLabelSearchTree
7676
* \returns TRUE in case of success
7777
* \note not available in Python bindings
7878
*/
79-
bool insertLabel( pal::LabelPosition *labelPos, int featureId, const QString &layerName, const QString &labeltext, const QFont &labelfont, bool diagram = false, bool pinned = false, const QString &providerId = QString() ) SIP_SKIP;
79+
bool insertLabel( pal::LabelPosition *labelPos, QgsFeatureId featureId, const QString &layerName, const QString &labeltext, const QFont &labelfont, bool diagram = false, bool pinned = false, const QString &providerId = QString() ) SIP_SKIP;
8080

8181
private:
8282
// set as mutable because RTree template is not const-correct

‎src/core/qgspallabeling.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class QgsExpressionContext;
7979
class CORE_EXPORT QgsLabelPosition
8080
{
8181
public:
82-
QgsLabelPosition( int id, double r, const QVector< QgsPointXY > &corners, const QgsRectangle &rect, double w, double h, const QString &layer, const QString &labeltext, const QFont &labelfont, bool upside_down, bool diagram = false, bool pinned = false, const QString &providerId = QString() )
82+
QgsLabelPosition( QgsFeatureId id, double r, const QVector< QgsPointXY > &corners, const QgsRectangle &rect, double w, double h, const QString &layer, const QString &labeltext, const QFont &labelfont, bool upside_down, bool diagram = false, bool pinned = false, const QString &providerId = QString() )
8383
: featureId( id )
8484
, rotation( r )
8585
, cornerPoints( corners )
@@ -98,7 +98,7 @@ class CORE_EXPORT QgsLabelPosition
9898
//! Constructor for QgsLabelPosition
9999
QgsLabelPosition() = default;
100100

101-
int featureId = -1;
101+
QgsFeatureId featureId = FID_NULL;
102102
double rotation = 0;
103103
QVector< QgsPointXY > cornerPoints;
104104
QgsRectangle labelRect;

‎src/core/qgsrulebasedlabeling.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ QgsVectorLayerLabelProvider *QgsRuleBasedLabelProvider::createProvider( QgsVecto
2929

3030
bool QgsRuleBasedLabelProvider::prepare( const QgsRenderContext &context, QSet<QString> &attributeNames )
3131
{
32-
Q_FOREACH ( QgsVectorLayerLabelProvider *provider, mSubProviders )
32+
for ( QgsVectorLayerLabelProvider *provider : qgis::as_const( mSubProviders ) )
3333
provider->setEngine( mEngine );
3434

3535
// populate sub-providers
@@ -46,7 +46,7 @@ void QgsRuleBasedLabelProvider::registerFeature( const QgsFeature &feature, QgsR
4646
QList<QgsAbstractLabelProvider *> QgsRuleBasedLabelProvider::subProviders()
4747
{
4848
QList<QgsAbstractLabelProvider *> lst;
49-
Q_FOREACH ( QgsVectorLayerLabelProvider *subprovider, mSubProviders )
49+
for ( QgsVectorLayerLabelProvider *subprovider : qgis::as_const( mSubProviders ) )
5050
lst << subprovider;
5151
return lst;
5252
}
@@ -111,7 +111,7 @@ void QgsRuleBasedLabeling::Rule::initFilter()
111111
void QgsRuleBasedLabeling::Rule::updateElseRules()
112112
{
113113
mElseRules.clear();
114-
Q_FOREACH ( Rule *rule, mChildren )
114+
for ( Rule *rule : qgis::as_const( mChildren ) )
115115
{
116116
if ( rule->isElse() )
117117
mElseRules << rule;
@@ -123,7 +123,7 @@ bool QgsRuleBasedLabeling::Rule::requiresAdvancedEffects() const
123123
if ( mSettings && mSettings->format().containsAdvancedEffects() )
124124
return true;
125125

126-
Q_FOREACH ( Rule *rule, mChildren )
126+
for ( Rule *rule : qgis::as_const( mChildren ) )
127127
{
128128
if ( rule->requiresAdvancedEffects() )
129129
return true;
@@ -134,7 +134,7 @@ bool QgsRuleBasedLabeling::Rule::requiresAdvancedEffects() const
134134

135135
void QgsRuleBasedLabeling::Rule::subProviderIds( QStringList &list ) const
136136
{
137-
Q_FOREACH ( const Rule *rule, mChildren )
137+
for ( const Rule *rule : qgis::as_const( mChildren ) )
138138
{
139139
if ( rule->settings() )
140140
list << rule->ruleKey();
@@ -172,7 +172,7 @@ const QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::findRuleByKey( con
172172
if ( key == mRuleKey )
173173
return this;
174174

175-
Q_FOREACH ( Rule *rule, mChildren )
175+
for ( Rule *rule : mChildren )
176176
{
177177
const Rule *r = rule->findRuleByKey( key );
178178
if ( r )
@@ -201,7 +201,7 @@ QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::clone() const
201201
Rule *newrule = new Rule( s, mMaximumScale, mMinimumScale, mFilterExp, mDescription );
202202
newrule->setActive( mIsActive );
203203
// clone children
204-
Q_FOREACH ( Rule *rule, mChildren )
204+
for ( Rule *rule : mChildren )
205205
newrule->appendChild( rule->clone() );
206206
return newrule;
207207
}
@@ -285,7 +285,7 @@ void QgsRuleBasedLabeling::Rule::createSubProviders( QgsVectorLayer *layer, QgsR
285285
}
286286

287287
// call recursively
288-
Q_FOREACH ( Rule *rule, mChildren )
288+
for ( Rule *rule : qgis::as_const( mChildren ) )
289289
{
290290
rule->createSubProviders( layer, subProviders, provider );
291291
}
@@ -310,7 +310,7 @@ void QgsRuleBasedLabeling::Rule::prepare( const QgsRenderContext &context, QSet<
310310
}
311311

312312
// call recursively
313-
Q_FOREACH ( Rule *rule, mChildren )
313+
for ( Rule *rule : qgis::as_const( mChildren ) )
314314
{
315315
rule->prepare( context, attributeNames, subProviders );
316316
}
@@ -334,7 +334,7 @@ QgsRuleBasedLabeling::Rule::RegisterResult QgsRuleBasedLabeling::Rule::registerF
334334
bool willRegisterSomething = false;
335335

336336
// call recursively
337-
Q_FOREACH ( Rule *rule, mChildren )
337+
for ( Rule *rule : qgis::as_const( mChildren ) )
338338
{
339339
// Don't process else rules yet
340340
if ( !rule->isElse() )
@@ -349,7 +349,7 @@ QgsRuleBasedLabeling::Rule::RegisterResult QgsRuleBasedLabeling::Rule::registerF
349349
// If none of the rules passed then we jump into the else rules and process them.
350350
if ( !willRegisterSomething )
351351
{
352-
Q_FOREACH ( Rule *rule, mElseRules )
352+
for ( Rule *rule : qgis::as_const( mElseRules ) )
353353
{
354354
registered |= rule->registerFeature( feature, context, subProviders, obstacleGeometry ) != Filtered;
355355
}
@@ -370,7 +370,7 @@ bool QgsRuleBasedLabeling::Rule::isFilterOK( const QgsFeature &f, QgsRenderConte
370370

371371
context.expressionContext().setFeature( f );
372372
QVariant res = mFilter->evaluate( &context.expressionContext() );
373-
return res.toInt() != 0;
373+
return res.toBool();
374374
}
375375

376376
bool QgsRuleBasedLabeling::Rule::isScaleOK( double scale ) const
@@ -411,7 +411,16 @@ QgsRuleBasedLabeling *QgsRuleBasedLabeling::clone() const
411411

412412
QgsRuleBasedLabeling::~QgsRuleBasedLabeling()
413413
{
414-
delete mRootRule;
414+
}
415+
416+
QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::rootRule()
417+
{
418+
return mRootRule.get();
419+
}
420+
421+
const QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::rootRule() const
422+
{
423+
return mRootRule.get();
415424
}
416425

417426

‎src/core/qgsrulebasedlabeling.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
346346
explicit QgsRuleBasedLabeling( QgsRuleBasedLabeling::Rule *root SIP_TRANSFER );
347347
~QgsRuleBasedLabeling() override;
348348

349-
QgsRuleBasedLabeling::Rule *rootRule() { return mRootRule; }
350-
const Rule *rootRule() const SIP_SKIP { return mRootRule; }
349+
QgsRuleBasedLabeling::Rule *rootRule();
350+
const Rule *rootRule() const SIP_SKIP;
351351

352352
//! Create the instance from a DOM element with saved configuration
353353
static QgsRuleBasedLabeling *create( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
@@ -375,7 +375,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
375375
void toSld( QDomNode &parent, const QgsStringMap &props ) const override;
376376

377377
protected:
378-
Rule *mRootRule = nullptr;
378+
std::unique_ptr<Rule> mRootRule;
379379
};
380380

381381
#ifndef SIP_RUN

‎tests/code_layout/acceptable_missing_doc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
"QgsInterpolator": ['QgsInterpolator(const QList< QgsInterpolator::LayerData > &layerData)'],
214214
"QgsLUDialog": ['QgsLUDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)', 'lowerValue() const', 'setLowerValue(const QString &val)', 'setUpperValue(const QString &val)', 'upperValue() const'],
215215
"QgsLabelCandidate": ['QgsLabelCandidate(const QRectF &r, double c)'],
216-
"QgsLabelPosition": ['QgsLabelPosition(int id, double r, const QVector< QgsPointXY > &corners, const QgsRectangle &rect, double w, double h, const QString &layer, const QString &labeltext, const QFont &labelfont, bool upside_down, bool diagram=false, bool pinned=false, const QString &providerId=QString())'],
216+
"QgsLabelPosition": ['QgsLabelPosition(QgsFeatureId id, double r, const QVector< QgsPointXY > &corners, const QgsRectangle &rect, double w, double h, const QString &layer, const QString &labeltext, const QFont &labelfont, bool upside_down, bool diagram=false, bool pinned=false, const QString &providerId=QString())'],
217217
"QgsLabelSorter": ['QgsLabelSorter(const QgsMapSettings &mapSettings)', 'operator()(pal::LabelPosition *lp1, pal::LabelPosition *lp2) const'],
218218
"QgsLabelingEngine": ['processProvider(QgsAbstractLabelProvider *provider, QgsRenderContext &context, pal::Pal &p)'],
219219
"QgsLayerItem": ['LayerType', 'QgsLayerItem(QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, LayerType layerType, const QString &providerKey)', 'iconDefault()', 'iconLine()', 'iconPoint()', 'iconPolygon()', 'iconRaster()', 'iconTable()'],

0 commit comments

Comments
 (0)
Please sign in to comment.