Skip to content
Permalink
Browse files

Add 'show all labels' setting to individual PAL layers

- Implements a version of #5874
- Show-all labels are not obstacles for other PAL layer labels during collisions
(i.e. they will overlap or underlie other labels depending upon render order)
  • Loading branch information
dakcarto committed Sep 4, 2012
1 parent 141c38d commit a584a9a7e4989d61cb06c10662525f0a225f5894
@@ -162,6 +162,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
sliderPriority->setValue( lyr.priority );
chkNoObstacle->setChecked( !lyr.obstacle );
chkLabelPerFeaturePart->setChecked( lyr.labelPerPart );
mPalShowAllLabelsForLayerChkBx->setChecked( lyr.displayAll );
chkMergeLines->setChecked( lyr.mergeLines );
mMinSizeSpinBox->setValue( lyr.minFeatureSize );
chkAddDirectionSymbol->setChecked( lyr.addDirectionSymbol );
@@ -348,6 +349,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.priority = sliderPriority->value();
lyr.obstacle = !chkNoObstacle->isChecked();
lyr.labelPerPart = chkLabelPerFeaturePart->isChecked();
lyr.displayAll = mPalShowAllLabelsForLayerChkBx->isChecked();
lyr.mergeLines = chkMergeLines->isChecked();
if ( chkScaleBasedVisibility->isChecked() )
{
@@ -58,9 +58,9 @@
namespace pal
{

Layer::Layer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal )
Layer::Layer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal, bool displayAll )
: pal( pal ), obstacle( obstacle ), active( active ),
toLabel( toLabel ), label_unit( label_unit ),
toLabel( toLabel ), displayAll( displayAll ), label_unit( label_unit ),
min_scale( min_scale ), max_scale( max_scale ),
arrangement( arrangement ), arrangementFlags( 0 ), mode( LabelPerFeature ), mergeLines( false )
{
@@ -75,6 +75,7 @@ namespace pal

public:
enum LabelMode { LabelPerFeature, LabelPerFeaturePart };
bool getDisplayAll() const { return displayAll; }

protected:
char *name; /* unique */
@@ -92,6 +93,7 @@ namespace pal
bool obstacle;
bool active;
bool toLabel;
bool displayAll;

Units label_unit;

@@ -126,9 +128,10 @@ namespace pal
* @param active is the layer is active (currently displayed)
* @param toLabel the layer will be labeled whether toLablel is true
* @param pal pointer to the pal object
* @param displayAll if true, all features will be labelled even though overlaps occur
*
*/
Layer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal );
Layer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal, bool displayAll = false );

/**
* \brief Delete the layer
@@ -165,7 +165,7 @@ namespace pal
}


Layer * Pal::addLayer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel )
Layer * Pal::addLayer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, bool displayAll )
{
Layer *lyr;
lyrsMutex->lock();
@@ -187,7 +187,7 @@ namespace pal
}
}

lyr = new Layer( lyrName, min_scale, max_scale, arrangement, label_unit, defaultPriority, obstacle, active, toLabel, this );
lyr = new Layer( lyrName, min_scale, max_scale, arrangement, label_unit, defaultPriority, obstacle, active, toLabel, this, displayAll );
layers->push_back( lyr );

lyrsMutex->unlock();
@@ -263,12 +263,13 @@ namespace pal
* @param obstacle 'true' will discourage other label to be placed above features of this layer
* @param active is the layer is active (currently displayed)
* @param toLabel the layer will be labeled only if toLablel is true
* @param displayAll if true, all features will be labelled even though overlaps occur
*
* @throws PalException::LayerExists
*
* @todo add symbolUnit
*/
Layer * addLayer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel );
Layer * addLayer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, bool displayAll = false );

/**
* \brief Look for a layer
@@ -2951,7 +2951,7 @@ namespace pal
for ( i = 0; i < nbft; i++ )
if ( sol->s[i] != -1 )
solList->push_back( labelpositions[sol->s[i]] ); // active labels
else if ( returnInactive )
else if ( returnInactive || labelpositions[featStartId[i]]->getFeaturePart()->getLayer()->getDisplayAll() )
solList->push_back( labelpositions[featStartId[i]] ); // unplaced label

return solList;
@@ -167,6 +167,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
decimals = 3;
plusSign = false;
labelPerPart = false;
displayAll = false;
mergeLines = false;
minFeatureSize = 0.0;
vectorScaleFactor = 1.0;
@@ -212,6 +213,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
decimals = s.decimals;
plusSign = s.plusSign;
labelPerPart = s.labelPerPart;
displayAll = s.displayAll;
mergeLines = s.mergeLines;
minFeatureSize = s.minFeatureSize;
vectorScaleFactor = s.vectorScaleFactor;
@@ -392,6 +394,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
decimals = layer->customProperty( "labeling/decimals" ).toInt();
plusSign = layer->customProperty( "labeling/plussign" ).toInt();
labelPerPart = layer->customProperty( "labeling/labelPerPart" ).toBool();
displayAll = layer->customProperty( "labeling/displayAll", QVariant( false ) ).toBool();
mergeLines = layer->customProperty( "labeling/mergeLines" ).toBool();
addDirectionSymbol = layer->customProperty( "labeling/addDirectionSymbol" ).toBool();
minFeatureSize = layer->customProperty( "labeling/minFeatureSize" ).toDouble();
@@ -448,6 +451,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
layer->setCustomProperty( "labeling/decimals", decimals );
layer->setCustomProperty( "labeling/plussign", plusSign );
layer->setCustomProperty( "labeling/labelPerPart", labelPerPart );
layer->setCustomProperty( "labeling/displayAll", displayAll );
layer->setCustomProperty( "labeling/mergeLines", mergeLines );
layer->setCustomProperty( "labeling/addDirectionSymbol", addDirectionSymbol );
layer->setCustomProperty( "labeling/minFeatureSize", minFeatureSize );
@@ -1114,7 +1118,8 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,

Layer* l = mPal->addLayer( layer->id().toUtf8().data(),
min_scale, max_scale, arrangement,
METER, priority, lyr.obstacle, true, true );
METER, priority, lyr.obstacle, true, true,
lyr.displayAll );

if ( lyr.placementFlags )
l->setArrangementFlags( lyr.placementFlags );
@@ -144,6 +144,7 @@ class CORE_EXPORT QgsPalLayerSettings
int decimals;
bool plusSign;
bool labelPerPart; // whether to label every feature's part or only the biggest one
bool displayAll; // if true, all features will be labelled even though overlaps occur
bool mergeLines;
double minFeatureSize; // minimum feature size to be labelled (in mm)
// Adds '<' or '>' to the label string pointing to the direction of the line / polygon ring
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>316</width>
<height>271</height>
<width>406</width>
<height>298</height>
</rect>
</property>
<property name="windowTitle">
@@ -175,7 +175,7 @@
<item>
<widget class="QCheckBox" name="chkShowAllLabels">
<property name="text">
<string>Show all labels (i.e. including colliding labels)</string>
<string>Show all labels for all layers (i.e. including colliding labels)</string>
</property>
</widget>
</item>
@@ -1469,8 +1469,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>701</width>
<height>483</height>
<width>686</width>
<height>485</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
@@ -1489,28 +1489,28 @@
<string>Options</string>
</property>
<layout class="QGridLayout" name="gridLayout_12">
<item row="1" column="0">
<item row="2" column="0">
<widget class="QCheckBox" name="chkMergeLines">
<property name="text">
<string>Merge connected lines to avoid duplicate labels</string>
</property>
</widget>
</item>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QCheckBox" name="chkLabelPerFeaturePart">
<property name="text">
<string>Label every part of multi-part features</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QCheckBox" name="chkAddDirectionSymbol">
<property name="text">
<string>Add direction symbol</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_19">
@@ -1531,7 +1531,7 @@
</item>
</layout>
</item>
<item row="4" column="0">
<item row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<widget class="QCheckBox" name="chkNoObstacle">
@@ -1568,6 +1568,13 @@
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="mPalShowAllLabelsForLayerChkBx">
<property name="text">
<string>Show all labels for this layer (i.e. including colliding labels)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit a584a9a

Please sign in to comment.
You can’t perform that action at this time.