[FEATURE][labeling] Data defined control over whether a feature

acts as an obstacle for labels
This commit is contained in:
Nyall Dawson 2015-07-23 15:00:45 +10:00
parent 1325b98db6
commit c97733ea27
9 changed files with 92 additions and 26 deletions

View File

@ -298,6 +298,8 @@ class QgsPalLayerSettings
FontLimitPixel,
FontMinPixel,
FontMaxPixel,
IsObstacle,
// (data defined only)
Show,
AlwaysShow

View File

@ -656,7 +656,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.previewBkgrdColor = mPreviewBackgroundBtn->color();
lyr.priority = mPrioritySlider->value();
lyr.obstacle = mChkNoObstacle->isChecked();
lyr.obstacle = mChkNoObstacle->isChecked() || mLabelModeComboBox->currentIndex() == 2;
lyr.obstacleType = ( QgsPalLayerSettings::ObstacleType )mObstacleTypeComboBox->itemData( mObstacleTypeComboBox->currentIndex() ).toInt();
lyr.labelPerPart = chkLabelPerFeaturePart->isChecked();
lyr.displayAll = mPalShowAllLabelsForLayerChkBx->isChecked();
@ -856,6 +856,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
setDataDefinedProperty( mFontMaxPixelDDBtn, QgsPalLayerSettings::FontMaxPixel, lyr );
setDataDefinedProperty( mShowLabelDDBtn, QgsPalLayerSettings::Show, lyr );
setDataDefinedProperty( mAlwaysShowDDBtn, QgsPalLayerSettings::AlwaysShow, lyr );
setDataDefinedProperty( mIsObstacleDDBtn, QgsPalLayerSettings::IsObstacle, lyr );
return lyr;
}
@ -1121,6 +1122,9 @@ void QgsLabelingGui::populateDataDefinedButtons( QgsPalLayerSettings& s )
mAlwaysShowDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::AlwaysShow ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::boolDesc() );
mIsObstacleDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::IsObstacle ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::boolDesc() );
}
void QgsLabelingGui::changeTextColor( const QColor &color )

View File

@ -75,6 +75,7 @@ namespace pal
, repeatDist( 0.0 )
, alwaysShow( false )
, mFixedQuadrant( false )
, mIsObstacle( true )
, mPriority( -1.0 )
{
assert( finite( lx ) && finite( ly ) );

View File

@ -108,6 +108,18 @@ namespace pal
double repeatDistance() const { return repeatDist; }
void setAlwaysShow( bool bl ) { alwaysShow = bl; }
/** Sets whether the feature will act as an obstacle for labels.
* @param obstacle whether feature will act as an obstacle
* @see isObstacle
*/
void setIsObstacle( bool obstacle ) { mIsObstacle = obstacle; }
/** Returns whether the feature will act as an obstacle for labels.
* @returns true if feature is an obstacle
* @see setIsObstacle
*/
double isObstacle() const { return mIsObstacle; }
/** Sets the priority for labeling the feature.
* @param priority feature's priority, as a value between 0 (highest priority)
* and 1 (lowest priority). Set to -1.0 to use the layer's default priority
@ -161,9 +173,12 @@ namespace pal
private:
bool mFixedQuadrant;
bool mIsObstacle;
//-1 if layer priority should be used
double mPriority;
};
/**

View File

@ -168,6 +168,9 @@ namespace pal
f->setAlwaysShow( alwaysShow );
// feature inherits layer setting for acting as an obstacle
f->setIsObstacle( mObstacle );
bool first_feat = true;
double geom_size = -1, biggest_size = -1;

View File

@ -203,7 +203,7 @@ namespace pal
#endif
// all feature which are obstacle will be inserted into obstacles
if ( context->layer->obstacle() )
if ( ft_ptr->getFeature()->isObstacle() )
{
ft_ptr->getBoundingBox( amin, amax );
context->obstacles->Insert( amin, amax, ft_ptr );

View File

@ -294,6 +294,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
mDataDefinedNames.insert( RepeatDistance, QPair<QString, int>( "RepeatDistance", -1 ) );
mDataDefinedNames.insert( RepeatDistanceUnit, QPair<QString, int>( "RepeatDistanceUnit", -1 ) );
mDataDefinedNames.insert( Priority, QPair<QString, int>( "Priority", -1 ) );
mDataDefinedNames.insert( IsObstacle, QPair<QString, int>( "IsObstacle", -1 ) );
// (data defined only)
mDataDefinedNames.insert( PositionX, QPair<QString, int>( "PositionX", 9 ) );
@ -2207,6 +2208,12 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
}
}
// data defined is obstacle?
if ( dataDefinedEvaluate( QgsPalLayerSettings::IsObstacle, exprVal ) )
{
feat->setIsObstacle( exprVal.toBool() );
}
//add parameters for data defined labeling to QgsPalGeometry
QMap< DataDefinedProperties, QVariant >::const_iterator dIt = dataDefinedValues.constBegin();
for ( ; dIt != dataDefinedValues.constEnd(); ++dIt )

View File

@ -273,6 +273,8 @@ class CORE_EXPORT QgsPalLayerSettings
FontLimitPixel = 24,
FontMinPixel = 25,
FontMaxPixel = 26,
IsObstacle = 88,
// (data defined only)
Show = 15,
AlwaysShow = 20

View File

@ -4818,9 +4818,9 @@ font-style: italic;</string>
<property name="geometry">
<rect>
<x>0</x>
<y>-298</y>
<y>-361</y>
<width>578</width>
<height>683</height>
<height>724</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
@ -5461,15 +5461,61 @@ font-style: italic;</string>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mObstaclesGroupBox">
<property name="title">
<string>Obstacles</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
<item>
<widget class="QCheckBox" name="mChkNoObstacle">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Discourage labels from covering features</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QCheckBox" name="mChkNoObstacle">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Discourage labels from covering features</string>
</property>
</widget>
</item>
<item>
<widget class="QgsDataDefinedButton" name="mIsObstacleDDBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_24">
<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>
</item>
<item>
<widget class="QFrame" name="mPolygonObstacleTypeFrame">
@ -5512,19 +5558,6 @@ font-style: italic;</string>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
@ -5935,7 +5968,6 @@ font-style: italic;</string>
<tabstop>mLimitLabelChkBox</tabstop>
<tabstop>mLimitLabelSpinBox</tabstop>
<tabstop>mMinSizeSpinBox</tabstop>
<tabstop>mChkNoObstacle</tabstop>
<tabstop>mRenderingLabelGrpBx</tabstop>
</tabstops>
<resources>