Skip to content

Commit

Permalink
[pal] Don't treat joined features as obstacles for each other
Browse files Browse the repository at this point in the history
Eg, if the "merge connected features" option for a layer is checked
then label candidates generated for the merged line should not
be marked as in conflict with any part of the merged line.
Previously they would be marked in conflict with all but one part
of the merged line, resulting in false penalties being applied
to these candidates and non-ideal final label placements.
  • Loading branch information
nyalldawson committed Nov 24, 2015
1 parent e03f554 commit 3e61891
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/pal/feature.cpp
Expand Up @@ -170,7 +170,18 @@ namespace pal
if ( !part )
return false;

return mLF->id() == part->featureId() && mLF->layer()->name() == part->layer()->name();
if ( mLF->layer()->name() != part->layer()->name() )
return false;

if ( mLF->id() == part->featureId() )
return true;

// any part of joined features are also treated as having the same label feature
int connectedFeatureId = mLF->layer()->connectedFeatureId( mLF->id() );
if ( connectedFeatureId >= 0 && connectedFeatureId == mLF->layer()->connectedFeatureId( part->featureId() ) )
return true;

return false;
}

LabelPosition::Quadrant FeaturePart::quadrantFromOffset() const
Expand Down
10 changes: 10 additions & 0 deletions src/core/pal/layer.cpp
Expand Up @@ -357,11 +357,14 @@ namespace pal
void Layer::joinConnectedFeatures()
{
// go through all label texts
int connectedFeaturesId = 0;
Q_FOREACH ( const QString& labelText, mConnectedTexts )
{
if ( !mConnectedHashtable.contains( labelText ) )
continue; // shouldn't happen

connectedFeaturesId++;

QLinkedList<FeaturePart*>* parts = mConnectedHashtable.value( labelText );

// go one-by-one part, try to merge
Expand All @@ -381,11 +384,13 @@ namespace pal
mFeatureIndex->Remove( bmin, bmax, partCheck );
mFeatureParts.removeOne( partCheck );

mConnectedFeaturesIds.insert( partCheck->featureId(), connectedFeaturesId );
otherPart->getBoundingBox( bmin, bmax );

// merge points from partCheck to p->item
if ( otherPart->mergeWithFeaturePart( partCheck ) )
{
mConnectedFeaturesIds.insert( otherPart->featureId(), connectedFeaturesId );
// reinsert p->item to r-tree (probably not needed)
mFeatureIndex->Remove( bmin, bmax, otherPart );
otherPart->getBoundingBox( bmin, bmax );
Expand All @@ -409,6 +414,11 @@ namespace pal
mConnectedTexts.clear();
}

int Layer::connectedFeatureId( QgsFeatureId featureId ) const
{
return mConnectedFeaturesIds.value( featureId, -1 );
}

void Layer::chopFeaturesAtRepeatDistance()
{
GEOSContextHandle_t geosctxt = geosContext();
Expand Down
7 changes: 7 additions & 0 deletions src/core/pal/layer.h
Expand Up @@ -239,6 +239,12 @@ namespace pal
/** Join connected features with the same label text */
void joinConnectedFeatures();

/** Returns the connected feature ID for a label feature ID, which is unique for all features
* which have been joined as a result of joinConnectedFeatures()
* @returns connected feature ID, or -1 if feature was not joined
*/
int connectedFeatureId( QgsFeatureId featureId ) const;

/** Chop layer features at the repeat distance **/
void chopFeaturesAtRepeatDistance();

Expand Down Expand Up @@ -281,6 +287,7 @@ namespace pal

QHash< QString, QLinkedList<FeaturePart*>* > mConnectedHashtable;
QStringList mConnectedTexts;
QHash< QgsFeatureId, int > mConnectedFeaturesIds;

QMutex mMutex;

Expand Down

0 comments on commit 3e61891

Please sign in to comment.