14 changes: 14 additions & 0 deletions src/core/pal/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ namespace pal
*/
bool obstacle() const { return mObstacle; }

/** Returns the obstacle type, which controls how features within the layer
* act as obstacles for labels.
* @see setObstacleType
*/
ObstacleType obstacleType() const { return mObstacleType; }

/** Sets the obstacle type, which controls how features within the layer
* act as obstacles for labels.
* @param obstacleType new obstacle type
* @see obstacleType
*/
void setObstacleType( ObstacleType obstacleType ) { mObstacleType = obstacleType; }

/** Sets the layer's priority.
* @param priority layer priority, between 0 and 1. 0 corresponds to highest priority,
* 1 to lowest priority.
Expand Down Expand Up @@ -260,6 +273,7 @@ namespace pal
double mDefaultPriority;

bool mObstacle;
ObstacleType mObstacleType;
bool mActive;
bool mLabelLayer;
bool mDisplayAll;
Expand Down
10 changes: 5 additions & 5 deletions src/core/pal/pal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ namespace pal
{
Layer *layer;
QLinkedList<Feats*>* fFeats;
RTree<PointSet*, double, 2, double> *obstacles;
RTree<FeaturePart*, double, 2, double> *obstacles;
RTree<LabelPosition*, double, 2, double> *candidates;
double bbox_min[2];
double bbox_max[2];
Expand Down Expand Up @@ -287,7 +287,7 @@ namespace pal
Pal* pal;
} FilterContext;

bool filteringCallback( PointSet *pset, void *ctx )
bool filteringCallback( FeaturePart *featurePart, void *ctx )
{

RTree<LabelPosition*, double, 2, double> *cdtsIndex = (( FilterContext* ) ctx )->cdtsIndex;
Expand All @@ -297,10 +297,10 @@ namespace pal
return false; // do not continue searching

double amin[2], amax[2];
pset->getBoundingBox( amin, amax );
featurePart->getBoundingBox( amin, amax );

LabelPosition::PruneCtx pruneContext;
pruneContext.obstacle = pset;
pruneContext.obstacle = featurePart;
pruneContext.pal = pal;
cdtsIndex->Search( amin, amax, LabelPosition::pruneCallback, ( void* ) &pruneContext );

Expand All @@ -310,7 +310,7 @@ namespace pal
Problem* Pal::extract( int nbLayers, const QStringList& layersName, double lambda_min, double phi_min, double lambda_max, double phi_max )
{
// to store obstacles
RTree<PointSet*, double, 2, double> *obstacles = new RTree<PointSet*, double, 2, double>();
RTree<FeaturePart*, double, 2, double> *obstacles = new RTree<FeaturePart*, double, 2, double>();

Problem *prob = new Problem();

Expand Down
6 changes: 6 additions & 0 deletions src/core/pal/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ namespace pal
};
Q_DECLARE_FLAGS( LineArrangementFlags, LineArrangementFlag )

enum ObstacleType
{
PolygonInterior,
PolygonBoundary
};

/**
* \brief Pal main class.
*
Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2626,7 +2626,7 @@ namespace pal
solList->push_back( labelpositions[sol->s[i]] ); // active labels
}
else if ( returnInactive
|| labelpositions[featStartId[i]]->getFeaturePart()->getLayer()->displayAll()
|| labelpositions[featStartId[i]]->getFeaturePart()->layer()->displayAll()
|| labelpositions[featStartId[i]]->getFeaturePart()->getAlwaysShow() )
{
solList->push_back( labelpositions[featStartId[i]] ); // unplaced label
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
limitNumLabels = false;
maxNumLabels = 2000;
obstacle = true;
obstacleType = PolygonInterior;

// scale factors
vectorScaleFactor = 1.0;
Expand Down Expand Up @@ -413,6 +414,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
limitNumLabels = s.limitNumLabels;
maxNumLabels = s.maxNumLabels;
obstacle = s.obstacle;
obstacleType = s.obstacleType;

// shape background
shapeDraw = s.shapeDraw;
Expand Down Expand Up @@ -920,6 +922,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
limitNumLabels = layer->customProperty( "labeling/limitNumLabels", QVariant( false ) ).toBool();
maxNumLabels = layer->customProperty( "labeling/maxNumLabels", QVariant( 2000 ) ).toInt();
obstacle = layer->customProperty( "labeling/obstacle", QVariant( true ) ).toBool();
obstacleType = ( ObstacleType )layer->customProperty( "labeling/obstacleType", QVariant( PolygonInterior ) ).toUInt();

readDataDefinedPropertyMap( layer, dataDefinedProperties );
}
Expand Down Expand Up @@ -1071,6 +1074,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
layer->setCustomProperty( "labeling/limitNumLabels", limitNumLabels );
layer->setCustomProperty( "labeling/maxNumLabels", maxNumLabels );
layer->setCustomProperty( "labeling/obstacle", obstacle );
layer->setCustomProperty( "labeling/obstacleType", ( unsigned int )obstacleType );

writeDataDefinedPropertyMap( layer, dataDefinedProperties );
}
Expand Down Expand Up @@ -3316,6 +3320,16 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QStringList& attrNames,
// set whether adjacent lines should be merged
l->setMergeConnectedLines( lyr.mergeLines );

// set obstacle type
switch ( lyr.obstacleType )
{
case PolygonInterior:
l->setObstacleType( pal::PolygonInterior );
break;
case PolygonBoundary:
l->setObstacleType( pal::PolygonBoundary );
break;
}

// set whether location of centroid must be inside of polygons
l->setCentroidInside( lyr.centroidInside );
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgspallabeling.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ class CORE_EXPORT QgsPalLayerSettings
will be drawn with right alignment*/
};

/** Valid obstacle types, which affect how features within the layer will act as obstacles
* for labels.
*/
enum ObstacleType
{
PolygonInterior, /*!< avoid placing labels over interior of polygon (prefer placing labels totally
outside or just slightly inside polygon) */
PolygonBoundary /*!< avoid placing labels over boundary of polygon (prefer placing outside or
completely inside polygon) */
};

enum ShapeType
{
ShapeRectangle = 0,
Expand Down Expand Up @@ -428,6 +439,10 @@ class CORE_EXPORT QgsPalLayerSettings
double minFeatureSize; // minimum feature size to be labelled (in mm)
bool obstacle; // whether features for layer are obstacles to labels of other layers

/** Controls how features act as obstacles for labels
*/
ObstacleType obstacleType;

//-- scale factors
double vectorScaleFactor; //scale factor painter units->pixels
double rasterCompressFactor; //pixel resolution scale factor
Expand Down
62 changes: 50 additions & 12 deletions src/ui/qgslabelingguibase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
<item>
<widget class="QStackedWidget" name="mLabelStackedWidget">
<property name="currentIndex">
<number>0</number>
<number>6</number>
</property>
<widget class="QWidget" name="mLabelPage_Text">
<layout class="QVBoxLayout" name="verticalLayout_6">
Expand Down Expand Up @@ -1244,7 +1244,7 @@ font-style: italic;</string>
<rect>
<x>0</x>
<y>0</y>
<width>566</width>
<width>383</width>
<height>389</height>
</rect>
</property>
Expand Down Expand Up @@ -1844,8 +1844,8 @@ font-style: italic;</string>
<rect>
<x>0</x>
<y>0</y>
<width>582</width>
<height>379</height>
<width>298</width>
<height>257</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down Expand Up @@ -2205,7 +2205,7 @@ font-style: italic;</string>
<rect>
<x>0</x>
<y>0</y>
<width>566</width>
<width>362</width>
<height>697</height>
</rect>
</property>
Expand Down Expand Up @@ -3008,7 +3008,7 @@ font-style: italic;</string>
<rect>
<x>0</x>
<y>0</y>
<width>566</width>
<width>325</width>
<height>424</height>
</rect>
</property>
Expand Down Expand Up @@ -3489,7 +3489,7 @@ font-style: italic;</string>
<rect>
<x>0</x>
<y>0</y>
<width>566</width>
<width>427</width>
<height>829</height>
</rect>
</property>
Expand Down Expand Up @@ -4818,9 +4818,9 @@ font-style: italic;</string>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>566</width>
<height>622</height>
<y>-292</y>
<width>578</width>
<height>655</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
Expand Down Expand Up @@ -5440,7 +5440,7 @@ font-style: italic;</string>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkNoObstacle">
<widget class="QCheckBox" name="mChkNoObstacle">
<property name="enabled">
<bool>true</bool>
</property>
Expand All @@ -5449,6 +5449,44 @@ font-style: italic;</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="mPolygonObstacleTypeFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>Minimise placing labels</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mObstacleTypeComboBox"/>
</item>
<item>
<spacer name="horizontalSpacer_15">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -5875,7 +5913,7 @@ font-style: italic;</string>
<tabstop>mLimitLabelChkBox</tabstop>
<tabstop>mLimitLabelSpinBox</tabstop>
<tabstop>mMinSizeSpinBox</tabstop>
<tabstop>chkNoObstacle</tabstop>
<tabstop>mChkNoObstacle</tabstop>
<tabstop>mRenderingLabelGrpBx</tabstop>
</tabstops>
<resources>
Expand Down