Skip to content

Commit

Permalink
#9480: Add GUI checkbox option in labeling
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed May 27, 2014
1 parent 59427e2 commit 0fdd3ac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app/qgslabelinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ void QgsLabelingGui::init()

// populate placement options
mCentroidRadioWhole->setChecked( lyr.centroidWhole );
mCentroidInsideCheckBox->setChecked( lyr.centroidInside );
switch ( lyr.placement )
{
case QgsPalLayerSettings::AroundPoint:
Expand Down Expand Up @@ -545,6 +546,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()

QWidget* curPlacementWdgt = stackedPlacement->currentWidget();
lyr.centroidWhole = mCentroidRadioWhole->isChecked();
lyr.centroidInside = mCentroidInsideCheckBox->isChecked();
if (( curPlacementWdgt == pagePoint && radAroundPoint->isChecked() )
|| ( curPlacementWdgt == pagePolygon && radAroundCentroid->isChecked() ) )
{
Expand Down
8 changes: 6 additions & 2 deletions src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
placement = AroundPoint;
placementFlags = 0;
centroidWhole = false;
centroidInside = false;
quadOffset = QuadrantOver;
xOffset = 0;
yOffset = 0;
Expand Down Expand Up @@ -502,6 +503,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
placement = s.placement;
placementFlags = s.placementFlags;
centroidWhole = s.centroidWhole;
centroidInside = s.centroidInside;
quadOffset = s.quadOffset;
xOffset = s.xOffset;
yOffset = s.yOffset;
Expand Down Expand Up @@ -997,6 +999,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
placement = ( Placement )layer->customProperty( "labeling/placement" ).toInt();
placementFlags = layer->customProperty( "labeling/placementFlags" ).toUInt();
centroidWhole = layer->customProperty( "labeling/centroidWhole", QVariant( false ) ).toBool();
centroidInside = layer->customProperty( "labeling/centroidInside", QVariant( false ) ).toBool();
dist = layer->customProperty( "labeling/dist" ).toDouble();
distInMapUnits = layer->customProperty( "labeling/distInMapUnits" ).toBool();
distMapUnitScale.minScale = layer->customProperty( "labeling/distMapUnitMinScale", 0.0 ).toDouble();
Expand Down Expand Up @@ -1167,6 +1170,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
layer->setCustomProperty( "labeling/placement", placement );
layer->setCustomProperty( "labeling/placementFlags", ( unsigned int )placementFlags );
layer->setCustomProperty( "labeling/centroidWhole", centroidWhole );
layer->setCustomProperty( "labeling/centroidInside", centroidInside );
layer->setCustomProperty( "labeling/dist", dist );
layer->setCustomProperty( "labeling/distInMapUnits", distInMapUnits );
layer->setCustomProperty( "labeling/distMapUnitMinScale", distMapUnitScale.minScale );
Expand Down Expand Up @@ -3389,8 +3393,8 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QStringList& attrNames,
// set whether adjacent lines should be merged
l->setMergeConnectedLines( lyr.mergeLines );

// force the location of the centroid inside of polygons
l->setCentroidInside( true );
// set whether location of centroid must be inside of polygons
l->setCentroidInside( lyr.centroidInside );

// set how to show upside-down labels
Layer::UpsideDownLabels upsdnlabels;
Expand Down
1 change: 1 addition & 0 deletions src/core/qgspallabeling.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ class CORE_EXPORT QgsPalLayerSettings
unsigned int placementFlags;

bool centroidWhole; // whether centroid calculated from whole or visible polygon
bool centroidInside; // whether centroid-point calculated must be inside polygon
double dist; // distance from the feature (in mm)
bool distInMapUnits; //true if distance is in map units (otherwise in mm)
QgsMapUnitScale distMapUnitScale;
Expand Down
7 changes: 7 additions & 0 deletions src/ui/qgslabelingguibase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4101,6 +4101,13 @@ font-style: italic;</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="mCentroidInsideCheckBox">
<property name="text">
<string>Force point inside polygon</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 0fdd3ac

Please sign in to comment.