Skip to content

Commit

Permalink
Add 'show all labels' setting to individual PAL layers
Browse files Browse the repository at this point in the history
- 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 a584a9a
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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() )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/pal/layer.cpp
Expand Up @@ -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 )
{
Expand Down
5 changes: 4 additions & 1 deletion src/core/pal/layer.h
Expand Up @@ -75,6 +75,7 @@ namespace pal

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

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

Units label_unit;

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/pal/pal.cpp
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/core/pal/pal.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/problem.cpp
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgspallabeling.cpp
Expand Up @@ -167,6 +167,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
decimals = 3;
plusSign = false;
labelPerPart = false;
displayAll = false;
mergeLines = false;
minFeatureSize = 0.0;
vectorScaleFactor = 1.0;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgspallabeling.h
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/ui/qgsengineconfigdialog.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down
21 changes: 14 additions & 7 deletions src/ui/qgslabelingguibase.ui
Expand Up @@ -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">
Expand All @@ -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">
Expand All @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit a584a9a

Please sign in to comment.