Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More RAII in PAL #9450

Merged
merged 2 commits into from
Mar 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 10 additions & 26 deletions src/core/pal/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ bool Layer::registerFeature( QgsLabelFeature *lf )
if ( lf->size().width() < 0 || lf->size().height() < 0 )
return false;

mMutex.lock();
QMutexLocker locker( &mMutex );

if ( mHashtable.contains( lf->id() ) )
{
mMutex.unlock();
//A feature with this id already exists. Don't throw an exception as sometimes,
//the same feature is added twice (dateline split with otf-reprojection)
return false;
Expand All @@ -116,13 +115,12 @@ bool Layer::registerFeature( QgsLabelFeature *lf )
bool addedFeature = false;

double geom_size = -1, biggest_size = -1;
FeaturePart *biggest_part = nullptr;
std::unique_ptr<FeaturePart> biggest_part;

// break the (possibly multi-part) geometry into simple geometries
QLinkedList<const GEOSGeometry *> *simpleGeometries = Util::unmulti( lf->geometry() );
if ( !simpleGeometries ) // unmulti() failed?
{
mMutex.unlock();
throw InternalException::UnknownGeometry();
}

Expand All @@ -144,24 +142,21 @@ bool Layer::registerFeature( QgsLabelFeature *lf )

if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
{
mMutex.unlock();
throw InternalException::UnknownGeometry();
}

FeaturePart *fpart = new FeaturePart( lf, geom );
std::unique_ptr<FeaturePart> fpart = qgis::make_unique<FeaturePart>( lf, geom );

// ignore invalid geometries
if ( ( type == GEOS_LINESTRING && fpart->nbPoints < 2 ) ||
( type == GEOS_POLYGON && fpart->nbPoints < 3 ) )
{
delete fpart;
continue;
}

// polygons: reorder coordinates
if ( type == GEOS_POLYGON && GeomFunction::reorderPolygon( fpart->nbPoints, fpart->x, fpart->y ) != 0 )
{
delete fpart;
continue;
}

Expand All @@ -178,16 +173,14 @@ bool Layer::registerFeature( QgsLabelFeature *lf )
}
else
{
addObstaclePart( fpart );
fpart = nullptr;
addObstaclePart( fpart.release() );
}
}

// feature has to be labeled?
if ( !mLabelLayer || !labelWellDefined )
{
//nothing more to do for this part
delete fpart;
continue;
}

Expand All @@ -201,18 +194,13 @@ bool Layer::registerFeature( QgsLabelFeature *lf )
if ( geom_size > biggest_size )
{
biggest_size = geom_size;
delete biggest_part; // safe with NULL part
biggest_part = fpart;
}
else
{
delete fpart;
biggest_part.reset( fpart.release() );
}
continue; // don't add the feature part now, do it later
}

// feature part is ready!
addFeaturePart( fpart, lf->labelText() );
addFeaturePart( fpart.release(), lf->labelText() );
addedFeature = true;
}
delete simpleGeometries;
Expand All @@ -223,7 +211,6 @@ bool Layer::registerFeature( QgsLabelFeature *lf )
simpleGeometries = Util::unmulti( lf->obstacleGeometry() );
if ( !simpleGeometries ) // unmulti() failed?
{
mMutex.unlock();
throw InternalException::UnknownGeometry();
}

Expand All @@ -241,39 +228,36 @@ bool Layer::registerFeature( QgsLabelFeature *lf )

if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
{
mMutex.unlock();
throw InternalException::UnknownGeometry();
}

FeaturePart *fpart = new FeaturePart( lf, geom );
std::unique_ptr<FeaturePart> fpart = qgis::make_unique<FeaturePart>( lf, geom );

// ignore invalid geometries
if ( ( type == GEOS_LINESTRING && fpart->nbPoints < 2 ) ||
( type == GEOS_POLYGON && fpart->nbPoints < 3 ) )
{
delete fpart;
continue;
}

// polygons: reorder coordinates
if ( type == GEOS_POLYGON && GeomFunction::reorderPolygon( fpart->nbPoints, fpart->x, fpart->y ) != 0 )
{
delete fpart;
continue;
}

// feature part is ready!
addObstaclePart( fpart );
addObstaclePart( fpart.release() );
}
delete simpleGeometries;
}

mMutex.unlock();
locker.unlock();

// if using only biggest parts...
if ( ( mMode == LabelPerFeature || lf->hasFixedPosition() ) && biggest_part )
{
addFeaturePart( biggest_part, lf->labelText() );
addFeaturePart( biggest_part.release(), lf->labelText() );
addedFeature = true;
}

Expand Down