Skip to content
Permalink
Browse files

Added over point / over centroid placement. Instead of creating candi…

…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
wonder committed Jul 11, 2009
1 parent 2f56ea6 commit 97ac08cf7a95a3a864ae91500b93d5b6b5456a6c
@@ -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 )
{

@@ -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 ),
@@ -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:
@@ -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
@@ -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 */
@@ -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);
@@ -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()) )
{
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>454</width>
<height>474</height>
<height>514</height>
</rect>
</property>
<property name="windowTitle">
@@ -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">
@@ -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>
@@ -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">
@@ -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;
@@ -34,6 +34,7 @@ class LayerSettings
enum Placement
{
AroundPoint, // Point / Polygon
OverPoint, // Point / Polygon
OnLine, // Line / Polygon
AroundLine, // Line / Polygon
Horizontal, // Polygon

0 comments on commit 97ac08c

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