[QGIS Commit] r11021 -
branches/symbology-ng-branch/src/plugins/labeling
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Jul 4 16:12:23 EDT 2009
Author: wonder
Date: 2009-07-04 16:12:23 -0400 (Sat, 04 Jul 2009)
New Revision: 11021
Modified:
branches/symbology-ng-branch/src/plugins/labeling/labeling.cpp
branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp
branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h
Log:
Fixed distance from feature setting, fixed labeling with on the fly projections, fixed workaround of one segfault due copying and double release of temporary instances in LayerSettings.
Modified: branches/symbology-ng-branch/src/plugins/labeling/labeling.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/labeling.cpp 2009-07-04 20:06:42 UTC (rev 11020)
+++ branches/symbology-ng-branch/src/plugins/labeling/labeling.cpp 2009-07-04 20:12:23 UTC (rev 11021)
@@ -83,7 +83,7 @@
for (int i = 0; i < cand.count(); i++)
{
const LabelCandidate& c = cand[i];
- if (c.rect.contains(pt))
+ if (c.rect.contains(pt)) // TODO: handle rotated candidates
{
QToolTip::showText( mCanvas->mapToGlobal(e->pos()), QString::number(c.cost), mCanvas);
break;
Modified: branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp 2009-07-04 20:06:42 UTC (rev 11020)
+++ branches/symbology-ng-branch/src/plugins/labeling/labelinggui.cpp 2009-07-04 20:12:23 UTC (rev 11021)
@@ -42,7 +42,7 @@
populatePlacementMethods();
populateFieldNames();
- LayerSettings lyr = lbl->layer(layerId);
+ const LayerSettings& lyr = lbl->layer(layerId);
if (!lyr.layerId.isEmpty())
{
// load the labeling settings
Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp 2009-07-04 20:06:42 UTC (rev 11020)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp 2009-07-04 20:12:23 UTC (rev 11021)
@@ -66,14 +66,34 @@
// -------------
LayerSettings::LayerSettings()
- : palLayer(NULL), fontMetrics(NULL)
+ : palLayer(NULL), fontMetrics(NULL), ct(NULL)
{
}
+LayerSettings::LayerSettings(const LayerSettings& s)
+{
+ // copy only permanent stuff
+ layerId = s.layerId;
+ fieldName = s.fieldName;
+ placement = s.placement;
+ textFont = s.textFont;
+ textColor = s.textColor;
+ enabled = s.enabled;
+ priority = s.priority;
+ obstacle = s.obstacle;
+ dist = s.dist;
+
+ fontMetrics = NULL;
+ ct = NULL;
+}
+
+
LayerSettings::~LayerSettings()
{
// pal layer is deleted internally in PAL
+
delete fontMetrics;
+ delete ct;
}
void LayerSettings::calculateLabelSize(QString text, double& labelX, double& labelY)
@@ -93,8 +113,12 @@
double labelX, labelY; // will receive label size
calculateLabelSize(labelText, labelX, labelY);
- MyLabel* lbl = new MyLabel(f.id(), labelText, GEOSGeom_clone( f.geometry()->asGeos() ) );
+ QgsGeometry* geom = f.geometry();
+ if (ct != NULL) // reproject the geometry if necessary
+ geom->transform(*ct);
+ MyLabel* lbl = new MyLabel(f.id(), labelText, GEOSGeom_clone( geom->asGeos() ) );
+
// record the created geometry - it will be deleted at the end.
geometries.append(lbl);
@@ -103,7 +127,7 @@
// TODO: allow layer-wide feature dist in PAL...?
if (dist != 0)
- palLayer->setFeatureDistlabel(lbl->strId(), dist);
+ palLayer->setFeatureDistlabel(lbl->strId(), fabs(ptOne.x()-ptZero.x())* dist);
}
@@ -171,7 +195,7 @@
}
}
-LayerSettings PalLabeling::layer(QString layerId)
+const LayerSettings& PalLabeling::layer(QString layerId)
{
for (int i = 0; i < mLayers.count(); i++)
{
@@ -180,7 +204,7 @@
return mLayers.at(i);
}
}
- return LayerSettings();
+ return mInvalidLayer;
}
@@ -225,7 +249,12 @@
lyr->fontMetrics = new QFontMetrics(lyr->textFont);
lyr->fontBaseline = lyr->fontMetrics->boundingRect("X").bottom(); // dummy text to find out how many pixels of the text are below the baseline
lyr->xform = thisClass->mMapRenderer->coordinateTransform();
+ if (thisClass->mMapRenderer->hasCrsTransformEnabled())
+ lyr->ct = new QgsCoordinateTransform( vlayer->srs(), thisClass->mMapRenderer->destinationSrs() );
+ else
+ lyr->ct = NULL;
lyr->ptZero = lyr->xform->toMapCoordinates( 0,0 );
+ lyr->ptOne = lyr->xform->toMapCoordinates( 1,0 );
return 1; // init successful
}
@@ -255,7 +284,6 @@
case Falp: s = FALP; break;
}
mPal->setSearch(s);
- //mPal->setSearch(FALP);
// set number of candidates generated per feature
mPal->setPointP(mCandPoint);
@@ -271,15 +299,6 @@
QTime t;
t.start();
- // make sure to delete fontmetrics otherwise it crashes inside Qt when drawing... :-(
- // probably gets invalid when setting fonts in the label drawing loop
- for (int i = 0; i < mLayers.count(); i++)
- {
- LayerSettings& lyr = mLayers[i];
- delete lyr.fontMetrics;
- lyr.fontMetrics = NULL;
- }
-
// do the labeling itself
double scale = 1; // scale denominator
QgsRectangle r = extent;
@@ -289,16 +308,7 @@
pal::Problem* problem;
try
{
- //labels = mPal->labeller(scale, bbox, NULL, false);
problem = mPal->extractProblem(scale, bbox);
- if ( problem )
- {
- // TODO: other methods
- problem->chain_search();
- labels = problem->getSolution(false);
- }
- else
- labels = new std::list<Label*>();
}
catch ( std::exception& e )
{
Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h 2009-07-04 20:06:42 UTC (rev 11020)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h 2009-07-04 20:12:23 UTC (rev 11021)
@@ -4,6 +4,7 @@
class QPainter;
class QgsMapRenderer;
class QgsRectangle;
+class QgsCoordinateTransform;
#include <QString>
#include <QFont>
@@ -27,6 +28,7 @@
{
public:
LayerSettings();
+ LayerSettings(const LayerSettings& s);
~LayerSettings();
enum Placement
@@ -46,7 +48,7 @@
bool enabled;
int priority; // 0 = low, 10 = high
bool obstacle; // whether it's an obstacle
- double dist; // distance from the feature
+ double dist; // distance from the feature (in pixels)
// called from register feature hook
void calculateLabelSize(QString text, double& labelX, double& labelY);
@@ -60,7 +62,8 @@
QFontMetrics* fontMetrics;
int fontBaseline;
const QgsMapToPixel* xform;
- QgsPoint ptZero;
+ const QgsCoordinateTransform* ct;
+ QgsPoint ptZero, ptOne;
QList<MyLabel*> geometries;
};
@@ -85,7 +88,7 @@
void removeLayer(QString layerId);
- LayerSettings layer(QString layerId);
+ const LayerSettings& layer(QString layerId);
void numCandidatePositions(int& candPoint, int& candLine, int& candPolygon);
void setNumCandidatePositions(int candPoint, int candLine, int candPolygon);
@@ -110,6 +113,8 @@
protected:
QList<LayerSettings> mLayers;
+ LayerSettings mInvalidLayer;
+
QgsMapRenderer* mMapRenderer;
int mCandPoint, mCandLine, mCandPolygon;
Search mSearch;
More information about the QGIS-commit
mailing list