|
QGIS API Documentation
master-6227475
|
00001 /*************************************************************************** 00002 qgspallabeling.h 00003 Smart labeling for vector layers 00004 ------------------- 00005 begin : June 2009 00006 copyright : (C) Martin Dobias 00007 email : wonder dot sk at gmail dot com 00008 00009 *************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 //Note: although this file is in the core library, it is not part of the stable API 00019 //and might change at any time! 00020 00021 #ifndef QGSPALLABELING_H 00022 #define QGSPALLABELING_H 00023 00024 class QFontMetricsF; 00025 class QPainter; 00026 class QPicture; 00027 class QgsGeometry; 00028 class QgsMapRenderer; 00029 class QgsRectangle; 00030 class QgsCoordinateTransform; 00031 class QgsLabelSearchTree; 00032 00033 #include <QString> 00034 #include <QFont> 00035 #include <QFontDatabase> 00036 #include <QColor> 00037 #include <QHash> 00038 #include <QList> 00039 #include <QRectF> 00040 00041 namespace pal 00042 { 00043 class Pal; 00044 class Layer; 00045 class LabelPosition; 00046 } 00047 00048 class QgsMapToPixel; 00049 class QgsFeature; 00050 00051 #include "qgspoint.h" 00052 #include "qgsrectangle.h" 00053 #include "qgsmaprenderer.h" // definition of QgsLabelingEngineInterface 00054 #include "qgsexpression.h" 00055 #include "qgsdatadefined.h" 00056 #include "qgsdiagramrendererv2.h" 00057 00058 class QgsPalGeometry; 00059 class QgsVectorLayer; 00060 00061 class CORE_EXPORT QgsPalLayerSettings 00062 { 00063 public: 00064 QgsPalLayerSettings(); 00065 QgsPalLayerSettings( const QgsPalLayerSettings& s ); 00066 ~QgsPalLayerSettings(); 00067 00068 enum Placement 00069 { 00070 AroundPoint, // Point / Polygon 00071 OverPoint, // Point / Polygon 00072 Line, // Line / Polygon 00073 Curved, // Line 00074 Horizontal, // Polygon 00075 Free // Polygon 00076 }; 00077 00078 enum LinePlacementFlags 00079 { 00080 OnLine = 1, 00081 AboveLine = 2, 00082 BelowLine = 4, 00083 MapOrientation = 8 00084 }; 00085 00086 enum QuadrantPosition 00087 { 00088 QuadrantAboveLeft, 00089 QuadrantAbove, 00090 QuadrantAboveRight, 00091 QuadrantLeft, 00092 QuadrantOver, 00093 QuadrantRight, 00094 QuadrantBelowLeft, 00095 QuadrantBelow, 00096 QuadrantBelowRight 00097 }; 00098 00099 enum UpsideDownLabels 00100 { 00101 Upright, // upside-down labels (90 <= angle < 270) are shown upright 00102 ShowDefined, // show upside down when rotation is layer- or data-defined 00103 ShowAll // show upside down for all labels, including dynamic ones 00104 }; 00105 00106 enum DirectionSymbols 00107 { 00108 SymbolLeftRight, // place direction symbols on left/right of label 00109 SymbolAbove, // place direction symbols on above label 00110 SymbolBelow // place direction symbols on below label 00111 }; 00112 00113 enum MultiLineAlign 00114 { 00115 MultiLeft = 0, 00116 MultiCenter, 00117 MultiRight 00118 }; 00119 00120 enum ShapeType 00121 { 00122 ShapeRectangle = 0, 00123 ShapeSquare, 00124 ShapeEllipse, 00125 ShapeCircle, 00126 ShapeSVG 00127 }; 00128 00129 enum SizeType 00130 { 00131 SizeBuffer = 0, 00132 SizeFixed, 00133 SizePercent 00134 }; 00135 00136 enum RotationType 00137 { 00138 RotationSync = 0, 00139 RotationOffset, 00140 RotationFixed 00141 }; 00142 00144 enum SizeUnit 00145 { 00146 Points = 0, 00147 MM, 00148 MapUnits, 00149 Percent 00150 }; 00151 00152 enum ShadowType 00153 { 00154 ShadowLowest = 0, 00155 ShadowText, 00156 ShadowBuffer, 00157 ShadowShape 00158 }; 00159 00160 // update mDataDefinedNames QMap in constructor when adding/deleting enum value 00161 enum DataDefinedProperties 00162 { 00163 // text style 00164 Size = 0, 00165 Bold = 1, 00166 Italic = 2, 00167 Underline = 3, 00168 Color = 4, 00169 Strikeout = 5, 00170 Family = 6, 00171 FontStyle = 21, 00172 FontSizeUnit = 22, 00173 FontTransp = 18, 00174 FontCase = 27, 00175 FontLetterSpacing = 28, 00176 FontWordSpacing = 29, 00177 FontBlendMode = 30, 00178 00179 // text formatting 00180 MultiLineWrapChar = 31, 00181 MultiLineHeight = 32, 00182 MultiLineAlignment = 33, 00183 DirSymbDraw = 34, 00184 DirSymbLeft = 35, 00185 DirSymbRight = 36, 00186 DirSymbPlacement = 37, 00187 DirSymbReverse = 38, 00188 NumFormat = 39, 00189 NumDecimals = 40, 00190 NumPlusSign = 41, 00191 00192 // text buffer 00193 BufferDraw = 42, 00194 BufferSize = 7, 00195 BufferUnit = 43, 00196 BufferColor = 8, 00197 BufferTransp = 19, 00198 BufferJoinStyle = 44, 00199 BufferBlendMode = 45, 00200 00201 // background 00202 ShapeDraw = 46, 00203 ShapeKind = 47, 00204 ShapeSVGFile = 48, 00205 ShapeSizeType = 49, 00206 ShapeSizeX = 50, 00207 ShapeSizeY = 85, 00208 ShapeSizeUnits = 51, 00209 ShapeRotationType = 52, 00210 ShapeRotation = 53, 00211 ShapeOffset = 54, 00212 ShapeOffsetUnits = 55, 00213 ShapeRadii = 56, 00214 ShapeRadiiUnits = 57, 00215 ShapeTransparency = 63, 00216 ShapeBlendMode = 64, 00217 ShapeFillColor = 58, 00218 ShapeBorderColor = 59, 00219 ShapeBorderWidth = 60, 00220 ShapeBorderWidthUnits = 61, 00221 ShapeJoinStyle = 62, 00222 00223 // drop shadow 00224 ShadowDraw = 65, 00225 ShadowUnder = 66, 00226 ShadowOffsetAngle = 67, 00227 ShadowOffsetDist = 68, 00228 ShadowOffsetUnits = 69, 00229 ShadowRadius = 70, 00230 ShadowRadiusUnits = 71, 00231 ShadowTransparency = 72, 00232 ShadowScale = 73, 00233 ShadowColor = 74, 00234 ShadowBlendMode = 75, 00235 00236 // placement 00237 CentroidWhole = 76, 00238 OffsetQuad = 77, 00239 OffsetXY = 78, 00240 OffsetUnits = 80, 00241 LabelDistance = 13, 00242 DistanceUnits = 81, 00243 OffsetRotation = 82, 00244 CurvedCharAngleInOut = 83, 00245 // (data defined only) 00246 PositionX = 9, //x-coordinate data defined label position 00247 PositionY = 10, //y-coordinate data defined label position 00248 Hali = 11, //horizontal alignment for data defined label position (Left, Center, Right) 00249 Vali = 12, //vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top) 00250 Rotation = 14, //data defined rotation 00251 00252 // rendering 00253 ScaleVisibility = 23, 00254 MinScale = 16, 00255 MaxScale = 17, 00256 FontLimitPixel = 24, 00257 FontMinPixel = 25, 00258 FontMaxPixel = 26, 00259 // (data defined only) 00260 Show = 15, 00261 AlwaysShow = 20 00262 }; 00263 00264 00265 // whether to label this layer 00266 bool enabled; 00267 00268 //-- text style 00269 00270 QString fieldName; 00271 00274 bool isExpression; 00275 00278 QgsExpression* getLabelExpression(); 00279 00280 QFont textFont; 00281 QString textNamedStyle; 00282 bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points) 00283 QColor textColor; 00284 int textTransp; 00285 QPainter::CompositionMode blendMode; 00286 QColor previewBkgrdColor; 00287 00288 //-- text formatting 00289 00290 QString wrapChar; 00291 double multilineHeight; //0.0 to 10.0, leading between lines as multiplyer of line height 00292 MultiLineAlign multilineAlign; // horizontal alignment of multi-line labels 00293 00294 // Adds '<' or '>', or user-defined symbol to the label string pointing to the 00295 // direction of the line / polygon ring 00296 // Works only if Placement == Line 00297 bool addDirectionSymbol; 00298 QString leftDirectionSymbol; 00299 QString rightDirectionSymbol; 00300 DirectionSymbols placeDirectionSymbol; // whether to place left/right, above or below label 00301 bool reverseDirectionSymbol; 00302 00303 bool formatNumbers; 00304 int decimals; 00305 bool plusSign; 00306 00307 //-- text buffer 00308 00309 bool bufferDraw; 00310 bool bufferDrawOld; // on when old style buffer triggered by just size is found 00311 double bufferSize; // buffer size 00312 bool bufferSizeInMapUnits; //true if buffer is in map units (otherwise in mm) 00313 QColor bufferColor; 00314 bool bufferNoFill; //set interior of buffer to 100% transparent 00315 int bufferTransp; 00316 Qt::PenJoinStyle bufferJoinStyle; 00317 QPainter::CompositionMode bufferBlendMode; 00318 00319 //-- shape background 00320 00321 bool shapeDraw; 00322 ShapeType shapeType; 00323 QString shapeSVGFile; 00324 SizeType shapeSizeType; 00325 QPointF shapeSize; 00326 SizeUnit shapeSizeUnits; 00327 RotationType shapeRotationType; 00328 double shapeRotation; 00329 QPointF shapeOffset; 00330 SizeUnit shapeOffsetUnits; 00331 QPointF shapeRadii; 00332 SizeUnit shapeRadiiUnits; 00333 int shapeTransparency; 00334 QPainter::CompositionMode shapeBlendMode; 00335 QColor shapeFillColor; 00336 QColor shapeBorderColor; 00337 double shapeBorderWidth; 00338 SizeUnit shapeBorderWidthUnits; 00339 Qt::PenJoinStyle shapeJoinStyle; 00340 00341 //-- drop shadow 00342 00343 bool shadowDraw; 00344 ShadowType shadowUnder; 00345 int shadowOffsetAngle; 00346 double shadowOffsetDist; 00347 SizeUnit shadowOffsetUnits; 00348 bool shadowOffsetGlobal; 00349 double shadowRadius; 00350 SizeUnit shadowRadiusUnits; 00351 bool shadowRadiusAlphaOnly; 00352 int shadowTransparency; 00353 int shadowScale; 00354 QColor shadowColor; 00355 QPainter::CompositionMode shadowBlendMode; 00356 00357 //-- placement 00358 00359 Placement placement; 00360 unsigned int placementFlags; 00361 00362 bool centroidWhole; // whether centroid calculated from whole or visible polygon 00363 double dist; // distance from the feature (in mm) 00364 bool distInMapUnits; //true if distance is in map units (otherwise in mm) 00365 00366 // offset labels of point/centroid features default to center 00367 // move label to quadrant: left/down, don't move, right/up (-1, 0, 1) 00368 QuadrantPosition quadOffset; 00369 00370 double xOffset; // offset from point in mm or map units 00371 double yOffset; // offset from point in mm or map units 00372 bool labelOffsetInMapUnits; //true if label offset is in map units (otherwise in mm) 00373 double angleOffset; // rotation applied to offset labels 00374 bool preserveRotation; // preserve predefined rotation data during label pin/unpin operations 00375 00376 double maxCurvedCharAngleIn; // maximum angle between inside curved label characters (defaults to 20.0, range 20.0 to 60.0) 00377 double maxCurvedCharAngleOut; // maximum angle between outside curved label characters (defaults to -20.0, range -20.0 to -95.0) 00378 00379 int priority; // 0 = low, 10 = high 00380 00381 //-- rendering 00382 00383 bool scaleVisibility; 00384 int scaleMin; 00385 int scaleMax; 00386 00387 bool fontLimitPixelSize; // true is label should be limited by fontMinPixelSize/fontMaxPixelSize 00388 int fontMinPixelSize; // minimum pixel size for showing rendered map unit labels (1 - 1000) 00389 int fontMaxPixelSize; // maximum pixel size for showing rendered map unit labels (1 - 10000) 00390 00391 bool displayAll; // if true, all features will be labelled even though overlaps occur 00392 unsigned int upsidedownLabels; // whether, or how, to show upsidedown labels 00393 00394 bool labelPerPart; // whether to label every feature's part or only the biggest one 00395 bool mergeLines; 00396 00397 bool limitNumLabels; // whether to limit the number of labels to be drawn 00398 int maxNumLabels; // maximum number of labels to be drawn 00399 00400 double minFeatureSize; // minimum feature size to be labelled (in mm) 00401 bool obstacle; // whether features for layer are obstacles to labels of other layers 00402 00403 //-- scale factors 00404 double vectorScaleFactor; //scale factor painter units->pixels 00405 double rasterCompressFactor; //pixel resolution scale factor 00406 00407 // called from register feature hook 00408 void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY, QgsFeature* f = 0 ); 00409 00410 // implementation of register feature hook 00411 void registerFeature( QgsVectorLayer* layer, QgsFeature& f, const QgsRenderContext& context ); 00412 00413 void readFromLayer( QgsVectorLayer* layer ); 00414 void writeToLayer( QgsVectorLayer* layer ); 00415 00419 QgsDataDefined* dataDefinedProperty( DataDefinedProperties p ); 00420 00424 QList<QgsPalLayerSettings::DataDefinedProperties> dataDefinedPropertyList(); 00425 00429 void setDataDefinedProperty( QgsPalLayerSettings::DataDefinedProperties p, 00430 bool active, bool useExpr, const QString& expr, const QString& field ); 00431 00433 void removeDataDefinedProperty( QgsPalLayerSettings::DataDefinedProperties p ); 00434 00438 QString updateDataDefinedString( const QString& value ); 00439 00443 QMap<QString, QString> dataDefinedMap( QgsPalLayerSettings::DataDefinedProperties p ) const; 00444 00449 QVariant dataDefinedValue( QgsPalLayerSettings::DataDefinedProperties p, QgsFeature& f, const QgsFields& fields ) const; 00450 00455 bool dataDefinedEvaluate( QgsPalLayerSettings::DataDefinedProperties p, QVariant& exprVal ) const; 00456 00459 bool dataDefinedIsActive( QgsPalLayerSettings::DataDefinedProperties p ) const; 00460 00463 bool dataDefinedUseExpression( QgsPalLayerSettings::DataDefinedProperties p ) const; 00464 00466 00467 QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* > dataDefinedProperties; 00468 00469 00477 int sizeToPixel( double size, const QgsRenderContext& c , SizeUnit unit, bool rasterfactor = false ) const; 00478 00487 double scaleToPixelContext( double size, const QgsRenderContext& c, SizeUnit unit, bool rasterfactor = false ) const; 00488 00493 QMap<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > dataDefinedNames() const { return mDataDefinedNames; } 00494 00495 // temporary stuff: set when layer gets prepared or labeled 00496 pal::Layer* palLayer; 00497 QgsFeature* mCurFeat; 00498 const QgsFields* mCurFields; 00499 int fieldIndex; 00500 const QgsMapToPixel* xform; 00501 const QgsCoordinateTransform* ct; 00502 QgsPoint ptZero, ptOne; 00503 QList<QgsPalGeometry*> geometries; 00504 QgsGeometry* extentGeom; 00505 int mFeaturesToLabel; // total features that will probably be labeled, may be less (figured before PAL) 00506 int mFeatsSendingToPal; // total features tested for sending into PAL (relative to maxNumLabels) 00507 int mFeatsRegPal; // number of features registered in PAL, when using limitNumLabels 00508 00509 bool showingShadowRects; // whether to show debug rectangles for drop shadows 00510 00511 private: 00512 void readDataDefinedPropertyMap( QgsVectorLayer* layer, 00513 QMap < QgsPalLayerSettings::DataDefinedProperties, 00514 QgsDataDefined* > & propertyMap ); 00515 void writeDataDefinedPropertyMap( QgsVectorLayer* layer, 00516 const QMap < QgsPalLayerSettings::DataDefinedProperties, 00517 QgsDataDefined* > & propertyMap ); 00518 void readDataDefinedProperty( QgsVectorLayer* layer, 00519 QgsPalLayerSettings::DataDefinedProperties p, 00520 QMap < QgsPalLayerSettings::DataDefinedProperties, 00521 QgsDataDefined* > & propertyMap ); 00522 00523 // convenience data defined evaluation function 00524 bool dataDefinedValEval( const QString& valType, 00525 QgsPalLayerSettings::DataDefinedProperties p, 00526 QVariant& exprVal ); 00527 00528 void parseTextStyle( QFont& labelFont, 00529 QgsPalLayerSettings::SizeUnit fontunits, 00530 const QgsRenderContext& context ); 00531 00532 void parseTextBuffer(); 00533 00534 void parseTextFormatting(); 00535 00536 void parseShapeBackground(); 00537 00538 void parseDropShadow(); 00539 00542 bool checkMinimumSizeMM( const QgsRenderContext& ct, QgsGeometry* geom, double minSize ) const; 00543 00544 00545 QMap<DataDefinedProperties, QVariant> dataDefinedValues; 00546 QgsExpression* expression; 00547 QMap<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > mDataDefinedNames; 00548 00549 QFontDatabase mFontDB; 00551 void updateFontViaStyle( QFont& font, const QString & fontstyle ); 00552 }; 00553 00554 class CORE_EXPORT QgsLabelCandidate 00555 { 00556 public: 00557 QgsLabelCandidate( QRectF r, double c ): rect( r ), cost( c ) {} 00558 00559 QRectF rect; 00560 double cost; 00561 }; 00562 00567 class CORE_EXPORT QgsLabelComponent 00568 { 00569 public: 00570 QgsLabelComponent(): mText( QString() ) 00571 , mOrigin( QgsPoint() ) 00572 , mUseOrigin( false ) 00573 , mRotation( 0.0 ) 00574 , mRotationOffset( 0.0 ) 00575 , mUseRotation( false ) 00576 , mCenter( QgsPoint() ) 00577 , mUseCenter( false ) 00578 , mSize( QgsPoint() ) 00579 , mOffset( QgsPoint() ) 00580 , mPicture( 0 ) 00581 , mPictureBuffer( 0.0 ) 00582 , mDpiRatio( 1.0 ) 00583 {} 00584 00585 const QString& text() { return mText; } 00586 void setText( const QString& text ) { mText = text; } 00587 00588 const QgsPoint& origin() { return mOrigin; } 00589 void setOrigin( QgsPoint point ) { mOrigin = point; } 00590 00591 bool useOrigin() const { return mUseOrigin; } 00592 void setUseOrigin( bool use ) { mUseOrigin = use; } 00593 00594 double rotation() const { return mRotation; } 00595 void setRotation( double rotation ) { mRotation = rotation; } 00596 00597 double rotationOffset() const { return mRotationOffset; } 00598 void setRotationOffset( double rotation ) { mRotationOffset = rotation; } 00599 00600 bool useRotation() const { return mUseRotation; } 00601 void setUseRotation( bool use ) { mUseRotation = use; } 00602 00603 const QgsPoint& center() { return mCenter; } 00604 void setCenter( QgsPoint point ) { mCenter = point; } 00605 00606 bool useCenter() const { return mUseCenter; } 00607 void setUseCenter( bool use ) { mUseCenter = use; } 00608 00609 const QgsPoint& size() { return mSize; } 00610 void setSize( QgsPoint point ) { mSize = point; } 00611 00612 const QgsPoint& offset() { return mOffset; } 00613 void setOffset( QgsPoint point ) { mOffset = point; } 00614 00615 const QPicture* picture() { return mPicture; } 00616 void setPicture( QPicture* picture ) { mPicture = picture; } 00617 00618 double pictureBuffer() const { return mPictureBuffer; } 00619 void setPictureBuffer( double buffer ) { mPictureBuffer = buffer; } 00620 00621 double dpiRatio() const { return mDpiRatio; } 00622 void setDpiRatio( double ratio ) { mDpiRatio = ratio; } 00623 00624 private: 00625 // current label component text, 00626 // e.g. single line in a multi-line label or charcater in curved labeling 00627 QString mText; 00628 // current origin point for painting (generally current painter rotation point) 00629 QgsPoint mOrigin; 00630 // whether to translate the painter to supplied origin 00631 bool mUseOrigin; 00632 // any rotation to be applied to painter (in radians) 00633 double mRotation; 00634 // any rotation to be applied to painter (in radians) after initial rotation 00635 double mRotationOffset; 00636 // whether to use the rotation to rotate the painter 00637 bool mUseRotation; 00638 // current center point of label compnent, after rotation 00639 QgsPoint mCenter; 00640 // whether to translate the painter to supplied origin based upon center 00641 bool mUseCenter; 00642 // width and height of label component, transformed and ready for painting 00643 QgsPoint mSize; 00644 // any translation offsets to be applied before painting, transformed and ready for painting 00645 QgsPoint mOffset; 00646 00647 // a stored QPicture of painting for the component 00648 QPicture* mPicture; 00649 // buffer for component to accommodate graphic items ignored by QPicture, 00650 // e.g. half-width of an applied QPen, which would extend beyond boundingRect() of QPicture 00651 double mPictureBuffer; 00652 00653 // a ratio of native painter dpi and that of rendering context's painter 00654 double mDpiRatio; 00655 }; 00656 00657 class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface 00658 { 00659 public: 00660 enum DrawLabelType 00661 { 00662 LabelText = 0, 00663 LabelBuffer, 00664 LabelShape, 00665 LabelSVG, 00666 LabelShadow 00667 }; 00668 00669 QgsPalLabeling(); 00670 ~QgsPalLabeling(); 00671 00672 QgsPalLayerSettings& layer( const QString& layerName ); 00673 00674 void numCandidatePositions( int& candPoint, int& candLine, int& candPolygon ); 00675 void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ); 00676 00677 enum Search { Chain, Popmusic_Tabu, Popmusic_Chain, Popmusic_Tabu_Chain, Falp }; 00678 00679 void setSearchMethod( Search s ); 00680 Search searchMethod() const; 00681 00682 bool isShowingCandidates() const { return mShowingCandidates; } 00683 void setShowingCandidates( bool showing ) { mShowingCandidates = showing; } 00684 const QList<QgsLabelCandidate>& candidates() { return mCandidates; } 00685 00686 bool isShowingShadowRectangles() const { return mShowingShadowRects; } 00687 void setShowingShadowRectangles( bool showing ) { mShowingShadowRects = showing; } 00688 00689 bool isShowingAllLabels() const { return mShowingAllLabels; } 00690 void setShowingAllLabels( bool showing ) { mShowingAllLabels = showing; } 00691 00692 // implemented methods from labeling engine interface 00693 00695 virtual void init( QgsMapRenderer* mr ); 00697 virtual bool willUseLayer( QgsVectorLayer* layer ); 00700 virtual void clearActiveLayers(); 00703 virtual void clearActiveLayer( QgsVectorLayer* layer ); 00705 virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ); 00707 virtual int addDiagramLayer( QgsVectorLayer* layer, QgsDiagramLayerSettings *s ); 00709 virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ); 00710 virtual void registerDiagramFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ); 00712 virtual void drawLabeling( QgsRenderContext& context ); 00714 virtual void exit(); 00716 virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p ); 00718 virtual QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle& r ); 00719 00721 virtual QgsLabelingEngineInterface* clone(); 00722 00724 void drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* painter, const QgsMapToPixel* xform ); 00727 void drawLabel( pal::LabelPosition* label, QgsRenderContext& context, QgsPalLayerSettings& tmpLyr, DrawLabelType drawType ); 00728 00729 static void drawLabelBuffer( QgsRenderContext& context, 00730 QgsLabelComponent component, 00731 const QgsPalLayerSettings& tmpLyr ); 00732 00733 static void drawLabelBackground( QgsRenderContext& context, 00734 QgsLabelComponent component, 00735 const QgsPalLayerSettings& tmpLyr ); 00736 00737 static void drawLabelShadow( QgsRenderContext& context, 00738 QgsLabelComponent component, 00739 const QgsPalLayerSettings& tmpLyr ); 00740 00743 void loadEngineSettings(); 00744 void saveEngineSettings(); 00745 void clearEngineSettings(); 00746 bool isStoredWithProject() const { return mSavedWithProject; } 00747 void setStoredWithProject( bool store ) { mSavedWithProject = store; } 00748 00749 protected: 00750 // update temporary QgsPalLayerSettings with any data defined text style values 00751 void dataDefinedTextStyle( QgsPalLayerSettings& tmpLyr, 00752 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues ); 00753 00754 // update temporary QgsPalLayerSettings with any data defined text formatting values 00755 void dataDefinedTextFormatting( QgsPalLayerSettings& tmpLyr, 00756 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues ); 00757 00758 // update temporary QgsPalLayerSettings with any data defined text buffer values 00759 void dataDefinedTextBuffer( QgsPalLayerSettings& tmpLyr, 00760 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues ); 00761 00762 // update temporary QgsPalLayerSettings with any data defined shape background values 00763 void dataDefinedShapeBackground( QgsPalLayerSettings& tmpLyr, 00764 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues ); 00765 00766 // update temporary QgsPalLayerSettings with any data defined drop shadow values 00767 void dataDefinedDropShadow( QgsPalLayerSettings& tmpLyr, 00768 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues ); 00769 00770 // hashtable of layer settings, being filled during labeling 00771 QHash<QgsVectorLayer*, QgsPalLayerSettings> mActiveLayers; 00772 // hashtable of active diagram layers 00773 QHash<QgsVectorLayer*, QgsDiagramLayerSettings> mActiveDiagramLayers; 00774 QgsPalLayerSettings mInvalidLayerSettings; 00775 00776 QgsMapRenderer* mMapRenderer; 00777 int mCandPoint, mCandLine, mCandPolygon; 00778 Search mSearch; 00779 00780 pal::Pal* mPal; 00781 00782 // list of candidates from last labeling 00783 QList<QgsLabelCandidate> mCandidates; 00784 bool mShowingCandidates; 00785 bool mShowingAllLabels; // whether to avoid collisions or not 00786 bool mSavedWithProject; // whether engine settings have been read from project file 00787 bool mShowingShadowRects; // whether to show debugging rectangles for drop shadows 00788 00789 QgsLabelSearchTree* mLabelSearchTree; 00790 }; 00791 00792 #endif // QGSPALLABELING_H