Skip to content

Commit

Permalink
Added over point / over centroid placement. Instead of creating candi…
Browse files Browse the repository at this point in the history
…dates around the point it creates candidates "on top" of the point.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11043 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jul 11, 2009
1 parent 2f56ea6 commit 97ac08c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 9 deletions.
33 changes: 31 additions & 2 deletions src/core/pal/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ namespace pal
return uid;
}

int Feature::setPositionOverPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width )
{
int nbp = 3;
*lPos = new LabelPosition *[nbp];

double lx = x - label_x / 2;
double ly = y - label_y / 2;
double cost = 0.0001;
int id = 0;
double alpha = 0;

double offset = label_x / 4;

// at the center
( *lPos )[0] = new LabelPosition( id, lx, ly, label_x, label_y, alpha, cost, this );
// shifted to the sides - with higher cost
cost = 0.0021;
( *lPos )[1] = new LabelPosition( id, lx+offset, ly, label_x, label_y, alpha, cost, this );
( *lPos )[2] = new LabelPosition( id, lx-offset, ly, label_x, label_y, alpha, cost, this );
return nbp;
}

int Feature::setPositionForPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width )
{

Expand Down Expand Up @@ -793,7 +815,10 @@ namespace pal
{
case GEOS_POINT:
fetchCoordinates();
nbp = setPositionForPoint( x[0], y[0], scale, lPos, delta );
if ( layer->getArrangement() == P_POINT_OVER )
nbp = setPositionOverPoint( x[0], y[0], scale, lPos, delta );
else
nbp = setPositionForPoint( x[0], y[0], scale, lPos, delta );
#ifdef _EXPORT_MAP_
toSVGPath( nbPoints, type, x, y, dpi , scale,
convert2pt( bbox_min[0], scale, dpi ),
Expand All @@ -810,9 +835,13 @@ namespace pal
switch ( layer->getArrangement() )
{
case P_POINT:
case P_POINT_OVER:
double cx, cy;
mapShape->getCentroid( cx, cy );
nbp = setPositionForPoint( cx, cy, scale, lPos, delta );
if (P_POINT_OVER)
nbp = setPositionOverPoint( cx, cy, scale, lPos, delta );
else
nbp = setPositionForPoint( cx, cy, scale, lPos, delta );
break;
case P_LINE:
case P_LINE_AROUND:
Expand Down
5 changes: 5 additions & 0 deletions src/core/pal/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ namespace pal
*/
int setPositionForPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width );

/**
* generate one candidate over specified point
*/
int setPositionOverPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width );

/**
* \brief generate candidates for line feature
* Generate candidates for line features
Expand Down
1 change: 1 addition & 0 deletions src/core/pal/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ namespace pal
enum _arrangement
{
P_POINT = 0, /**< arranges candidates around a point (centroid for polygon)*/
P_POINT_OVER, /** arranges candidates over a point (centroid for polygon)*/
P_LINE, /**< Only for lines and polygons, arranges candidates over the line or the polygon perimeter */
P_HORIZ, /**< Only for polygon, arranges candidates horizontaly */
P_FREE, /**< Only for polygon, arranges candidates with respect of polygon orientation */
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/labeling/labelinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ LabelingGui::LabelingGui( PalLabeling* lbl, QString layerId, QWidget* parent )
spinDistPoint->setValue(lyr.dist);
//spinAngle->setValue(lyr.angle);
break;
case LayerSettings::OverPoint:
radOverPoint->setChecked(true);
radOverCentroid->setChecked(true);
break;
case LayerSettings::AroundLine:
case LayerSettings::OnLine:
radLineParallel->setChecked(true);
Expand Down Expand Up @@ -170,6 +174,11 @@ LayerSettings LabelingGui::layerSettings()
lyr.dist = spinDistPoint->value();
//lyr.angle = spinAngle->value();
}
else if ( (stackedPlacement->currentWidget() == pagePoint && radOverPoint->isChecked())
|| (stackedPlacement->currentWidget() == pagePolygon && radOverCentroid->isChecked()) )
{
lyr.placement = LayerSettings::OverPoint;
}
else if ( (stackedPlacement->currentWidget() == pageLine && radLineParallel->isChecked())
|| (stackedPlacement->currentWidget() == pagePolygon && radPolygonPerimeter->isChecked()) )
{
Expand Down
18 changes: 11 additions & 7 deletions 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>454</width>
<height>474</height>
<height>514</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -77,7 +77,7 @@
<item>
<widget class="QStackedWidget" name="stackedPlacement">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="pagePoint">
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand All @@ -93,9 +93,6 @@
</item>
<item>
<widget class="QRadioButton" name="radOverPoint">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>over point</string>
</property>
Expand Down Expand Up @@ -130,15 +127,22 @@
<widget class="QWidget" name="pagePolygon">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QRadioButton" name="radAroundCentroid">
<widget class="QRadioButton" name="radOverCentroid">
<property name="text">
<string>around centroid</string>
<string>over centroid</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radAroundCentroid">
<property name="text">
<string>around centroid</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radPolygonHorizontal">
<property name="text">
Expand Down
1 change: 1 addition & 0 deletions src/plugins/labeling/pallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ int PalLabeling::prepareLayerHook(void* context, void* layerContext, int& attrIn
switch (lyr->placement)
{
case LayerSettings::AroundPoint: arrangement = P_POINT; break;
case LayerSettings::OverPoint: arrangement = P_POINT_OVER; break;
case LayerSettings::OnLine: arrangement = P_LINE; break;
case LayerSettings::AroundLine: arrangement = P_LINE_AROUND; break;
case LayerSettings::Horizontal: arrangement = P_HORIZ; break;
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 @@ -34,6 +34,7 @@ class LayerSettings
enum Placement
{
AroundPoint, // Point / Polygon
OverPoint, // Point / Polygon
OnLine, // Line / Polygon
AroundLine, // Line / Polygon
Horizontal, // Polygon
Expand Down

0 comments on commit 97ac08c

Please sign in to comment.