[QGIS Commit] r11209 - in branches/symbology-ng-branch/src:
core/pal plugins/labeling
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed Jul 29 21:51:15 EDT 2009
Author: wonder
Date: 2009-07-29 21:51:14 -0400 (Wed, 29 Jul 2009)
New Revision: 11209
Modified:
branches/symbology-ng-branch/src/core/pal/layer.cpp
branches/symbology-ng-branch/src/core/pal/layer.h
branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp
branches/symbology-ng-branch/src/plugins/labeling/labelingguibase.ui
branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h
Log:
Added possibility to choose mode when labeling a layer: label per feature (default) or label per feature part.
Label per feature uses longest line resp. largest polygon, for multipoint features fallback to label per feature part.
Modified: branches/symbology-ng-branch/src/core/pal/layer.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/layer.cpp 2009-07-30 00:48:23 UTC (rev 11208)
+++ branches/symbology-ng-branch/src/core/pal/layer.cpp 2009-07-30 01:51:14 UTC (rev 11209)
@@ -62,7 +62,7 @@
: pal( pal ), obstacle( obstacle ), active( active ),
toLabel( toLabel ), label_unit( label_unit ),
min_scale( min_scale ), max_scale( max_scale ),
- arrangement( arrangement ), arrangementFlags( 0 )
+ arrangement( arrangement ), arrangementFlags( 0 ), mode(LabelPerFeature)
{
this->name = new char[strlen( lyrName ) +1];
@@ -240,6 +240,9 @@
bool first_feat = true;
+ double geom_size, biggest_size = -1;
+ FeaturePart* biggest_part = NULL;
+
// break the (possibly multi-part) geometry into simple geometries
LinkedList <const GEOSGeometry*> *simpleGeometries = unmulti( the_geom );
@@ -276,18 +279,26 @@
continue;
}
- // feature part is ready!
+ if (mode == LabelPerFeature && (type == GEOS_POLYGON || type == GEOS_LINESTRING))
+ {
+ if (type == GEOS_LINESTRING)
+ GEOSLength(geom, &geom_size);
+ else if (type == GEOS_POLYGON)
+ GEOSArea(geom, &geom_size);
- double bmin[2];
- double bmax[2];
- fpart->getBoundingBox(bmin, bmax);
+ if (geom_size > biggest_size)
+ {
+ biggest_size = geom_size;
+ delete biggest_part; // safe with NULL part
+ biggest_part = fpart;
+ }
+ continue; // don't add the feature part now, do it later
+ // TODO: we should probably add also other parts to act just as obstacles
+ }
- // add to list of layer's feature parts
- featureParts->push_back( fpart );
+ // feature part is ready!
+ addFeaturePart(fpart);
- // add to r-tree for fast spatial access
- rtree->Insert( bmin, bmax, fpart );
-
first_feat = false;
}
delete simpleGeometries;
@@ -296,17 +307,41 @@
modMutex->unlock();
+ // if using only biggest parts...
+ if (mode == LabelPerFeature && biggest_part != NULL)
+ {
+ addFeaturePart(biggest_part);
+ first_feat = false;
+ }
+
// add feature to layer if we have added something
if (!first_feat)
{
features->push_back( f );
hashtable->insertItem( geom_id, f );
}
+ else
+ {
+ delete f;
+ }
return !first_feat; // true if we've added something
}
+void Layer::addFeaturePart( FeaturePart* fpart )
+{
+ double bmin[2];
+ double bmax[2];
+ fpart->getBoundingBox(bmin, bmax);
+ // add to list of layer's feature parts
+ featureParts->push_back( fpart );
+
+ // add to r-tree for fast spatial access
+ rtree->Insert( bmin, bmax, fpart );
+}
+
+
void Layer::setLabelUnit( Units label_unit )
{
if ( label_unit == PIXEL || label_unit == METER )
Modified: branches/symbology-ng-branch/src/core/pal/layer.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/layer.h 2009-07-30 00:48:23 UTC (rev 11208)
+++ branches/symbology-ng-branch/src/core/pal/layer.h 2009-07-30 01:51:14 UTC (rev 11209)
@@ -73,6 +73,9 @@
friend bool extractFeatCallback( FeaturePart *ft_ptr, void *ctx );
friend void toSVGPath( int nbPoints, double *x, double *y, int dpi, Layer *layer, int type, char *uid, std::ostream &out, double scale, int xmin, int ymax, bool exportInfo, char *color );
+ public:
+ enum LabelMode { LabelPerFeature, LabelPerFeaturePart };
+
protected:
char *name; /* unique */
@@ -97,6 +100,8 @@
Arrangement arrangement;
+ LabelMode mode;
+
/** optional flags used for some placement methods */
unsigned long arrangementFlags;
@@ -134,6 +139,9 @@
*/
bool isScaleValid( double scale );
+ /** add newly creted feature part into r tree and to the list */
+ void addFeaturePart( FeaturePart* fpart );
+
public:
/**
* \brief get the number of features into layer
@@ -260,6 +268,9 @@
*/
double getPriority();
+ void setLabelMode( LabelMode m ) { mode = m; }
+ LabelMode getLabelMode() const { return mode; }
+
/**
* \brief register a feature in the layer
*
Modified: branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp 2009-07-30 00:48:23 UTC (rev 11208)
+++ branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp 2009-07-30 01:51:14 UTC (rev 11209)
@@ -111,6 +111,7 @@
chkEnableLabeling->setChecked( lyr.enabled );
sliderPriority->setValue( lyr.priority );
chkNoObstacle->setChecked( !lyr.obstacle );
+ chkLabelPerFeaturePart->setChecked( lyr.labelPerPart );
bool scaleBased = (lyr.scaleMin != 0 && lyr.scaleMax != 0);
chkScaleBasedVisibility->setChecked(scaleBased);
@@ -222,6 +223,7 @@
lyr.enabled = chkEnableLabeling->isChecked();
lyr.priority = sliderPriority->value();
lyr.obstacle = !chkNoObstacle->isChecked();
+ lyr.labelPerPart = chkLabelPerFeaturePart->isChecked();
if (chkScaleBasedVisibility->isChecked())
{
lyr.scaleMin = spinScaleMin->value();
Modified: branches/symbology-ng-branch/src/plugins/labeling/labelingguibase.ui
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/labelingguibase.ui 2009-07-30 00:48:23 UTC (rev 11208)
+++ branches/symbology-ng-branch/src/plugins/labeling/labelingguibase.ui 2009-07-30 01:51:14 UTC (rev 11209)
@@ -649,6 +649,13 @@
</layout>
</item>
<item>
+ <widget class="QCheckBox" name="chkLabelPerFeaturePart">
+ <property name="text">
+ <string>label every part of multi-part features</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="chkNoObstacle">
Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp 2009-07-30 00:48:23 UTC (rev 11208)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp 2009-07-30 01:51:14 UTC (rev 11209)
@@ -109,6 +109,7 @@
scaleMax = s.scaleMax;
bufferSize = s.bufferSize;
bufferColor = s.bufferColor;
+ labelPerPart = s.labelPerPart;
fontMetrics = NULL;
ct = NULL;
@@ -287,6 +288,9 @@
if ( lyr->placementFlags )
l->setArrangementFlags( lyr->placementFlags );
+ // set label mode (label per feature is the default)
+ l->setLabelMode( lyr->labelPerPart ? Layer::LabelPerFeaturePart : Layer::LabelPerFeature );
+
// save the pal layer to our layer context (with some additional info)
lyr->palLayer = l;
lyr->fieldIndex = fldIndex;
Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h 2009-07-30 00:48:23 UTC (rev 11208)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h 2009-07-30 01:51:14 UTC (rev 11209)
@@ -63,6 +63,7 @@
int scaleMin, scaleMax; // disabled if both are zero
int bufferSize;
QColor bufferColor;
+ bool labelPerPart; // whether to label every feature's part or only the biggest one
// called from register feature hook
void calculateLabelSize(QString text, double& labelX, double& labelY);
More information about the QGIS-commit
mailing list