Skip to content

Commit

Permalink
Option to set distance from label to the feature. Available for point…
Browse files Browse the repository at this point in the history
…s and lines.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@10907 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 12, 2009
1 parent e8a95a5 commit 7100a3b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/plugins/labeling/labelinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ LabelingGui::LabelingGui( PalLabeling* lbl, QString layerId, QWidget* parent )
chkEnableLabeling->setChecked( lyr.enabled );
sliderPriority->setValue( lyr.priority );
chkNoObstacle->setChecked( !lyr.obstacle );
spinDist->setValue( lyr.dist );
}
else
{
// set enabled by default
chkEnableLabeling->setChecked( true );
}

// feature distance available only for points and lines
if (layer()->geometryType() == QGis::Polygon)
{
spinDist->setEnabled( false );
}

btnTextColor->setColor( lyr.textColor );
updateFontPreview( lyr.textFont );
}
Expand Down Expand Up @@ -85,6 +92,7 @@ LayerSettings LabelingGui::layerSettings()
lyr.enabled = chkEnableLabeling->isChecked();
lyr.priority = sliderPriority->value();
lyr.obstacle = !chkNoObstacle->isChecked();
lyr.dist = spinDist->value();

return lyr;
}
Expand Down
30 changes: 29 additions & 1 deletion src/plugins/labeling/labelingguibase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>354</width>
<height>435</height>
<height>436</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -67,6 +67,34 @@
<item row="1" column="1">
<widget class="QComboBox" name="cboFieldName"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Label distance</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QDoubleSpinBox" name="spinDist">
<property name="decimals">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>pixels</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/labeling/pallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ void LayerSettings::registerFeature(QgsFeature& f)

// register feature to the layer
palLayer->registerFeature(lbl->strId(), lbl, labelX, labelY);

// TODO: allow layer-wide feature dist in PAL...?
if (dist != 0)
palLayer->setFeatureDistlabel(lbl->strId(), dist);
}


Expand Down Expand Up @@ -176,6 +180,9 @@ int PalLabeling::prepareLayerHook(void* context, void* layerContext, int& attrIn
PalLabeling* thisClass = (PalLabeling*) context;
LayerSettings* lyr = (LayerSettings*) layerContext;

if (!lyr->enabled)
return 0;

QgsVectorLayer* vlayer = (QgsVectorLayer*) QgsMapLayerRegistry::instance()->mapLayer(lyr->layerId);
if (vlayer == NULL)
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/labeling/pallabeling.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class LayerSettings
bool enabled;
int priority; // 0 = low, 10 = high
bool obstacle; // whether it's an obstacle
double dist; // distance from the feature

// called from register feature hook
void calculateLabelSize(QString text, double& labelX, double& labelY);
Expand Down

0 comments on commit 7100a3b

Please sign in to comment.