/usr/include/qgis/qgspallabeling.h is in libqgis-dev 1.7.4+1.7.5~20120320-1.1+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | /***************************************************************************
qgspallabeling.h
Smart labeling for vector layers
-------------------
begin : June 2009
copyright : (C) Martin Dobias
email : wonder.sk at gmail.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
//Note: although this file is in the core library, it is not part of the stable API
//and might change at any time!
#ifndef QGSPALLABELING_H
#define QGSPALLABELING_H
class QFontMetricsF;
class QPainter;
class QgsGeometry;
class QgsMapRenderer;
class QgsRectangle;
class QgsCoordinateTransform;
class QgsLabelSearchTree;
struct QgsDiagramLayerSettings;
#include <QString>
#include <QFont>
#include <QColor>
#include <QHash>
#include <QList>
#include <QRectF>
namespace pal
{
class Pal;
class Layer;
class LabelPosition;
}
class QgsMapToPixel;
class QgsFeature;
#include "qgspoint.h"
#include "qgsmaprenderer.h" // definition of QgsLabelingEngineInterface
class QgsPalGeometry;
class QgsVectorLayer;
class CORE_EXPORT QgsPalLayerSettings
{
public:
QgsPalLayerSettings();
QgsPalLayerSettings( const QgsPalLayerSettings& s );
~QgsPalLayerSettings();
enum Placement
{
AroundPoint, // Point / Polygon
OverPoint, // Point / Polygon
Line, // Line / Polygon
Curved, // Line
Horizontal, // Polygon
Free // Polygon
};
enum LinePlacementFlags
{
OnLine = 1,
AboveLine = 2,
BelowLine = 4,
MapOrientation = 8
};
enum DataDefinedProperties
{
Size = 0,
Bold,
Italic,
Underline,
Color,
Strikeout,
Family,
BufferSize,
BufferColor,
PositionX, //x-coordinate data defined label position
PositionY, //y-coordinate data defined label position
Hali, //horizontal alignment for data defined label position (Left, Center, Right)
Vali, //vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top)
LabelDistance,
Rotation //data defined rotation (only useful in connection with data defined position)
};
QString fieldName;
Placement placement;
unsigned int placementFlags;
QFont textFont;
QColor textColor;
bool enabled;
int priority; // 0 = low, 10 = high
bool obstacle; // whether it's an obstacle
double dist; // distance from the feature (in mm)
double vectorScaleFactor; //scale factor painter units->pixels
double rasterCompressFactor; //pixel resolution scale factor
int scaleMin, scaleMax; // disabled if both are zero
double bufferSize; //buffer size (in mm)
QColor bufferColor;
bool labelPerPart; // whether to label every feature's part or only the biggest one
bool mergeLines;
bool multiLineLabels; //draw labels on multiple lines if they contain '\n'
double minFeatureSize; // minimum feature size to be labelled (in mm)
// Adds '<' or '>' to the label string pointing to the direction of the line / polygon ring
// Works only if Placement == Line
bool addDirectionSymbol;
bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
bool distInMapUnits; //true if distance is in map units (otherwise in mm)
// called from register feature hook
void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY );
// implementation of register feature hook
void registerFeature( QgsFeature& f, const QgsRenderContext& context );
void readFromLayer( QgsVectorLayer* layer );
void writeToLayer( QgsVectorLayer* layer );
/**Set a property as data defined*/
void setDataDefinedProperty( DataDefinedProperties p, int attributeIndex );
/**Set a property to static instead data defined*/
void removeDataDefinedProperty( DataDefinedProperties p );
// temporary stuff: set when layer gets prepared
pal::Layer* palLayer;
int fieldIndex;
QFontMetricsF* fontMetrics;
const QgsMapToPixel* xform;
const QgsCoordinateTransform* ct;
QgsPoint ptZero, ptOne;
QList<QgsPalGeometry*> geometries;
/**Stores field indices for data defined layer properties*/
QMap< DataDefinedProperties, int > dataDefinedProperties;
/**Calculates pixel size (considering output size should be in pixel or map units, scale factors and oversampling)
@param size size to convert
@param c rendercontext
@return font pixel size*/
int sizeToPixel( double size, const QgsRenderContext& c ) const;
private:
/**Checks if a feature is larger than a minimum size (in mm)
@return true if above size, false if below*/
bool checkMinimumSizeMM( const QgsRenderContext& ct, QgsGeometry* geom, double minSize ) const;
};
class CORE_EXPORT QgsLabelCandidate
{
public:
QgsLabelCandidate( QRectF r, double c ): rect( r ), cost( c ) {}
QRectF rect;
double cost;
};
class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
{
public:
QgsPalLabeling();
~QgsPalLabeling();
QgsPalLayerSettings& layer( const QString& layerName );
void numCandidatePositions( int& candPoint, int& candLine, int& candPolygon );
void setNumCandidatePositions( int candPoint, int candLine, int candPolygon );
enum Search { Chain, Popmusic_Tabu, Popmusic_Chain, Popmusic_Tabu_Chain, Falp };
void setSearchMethod( Search s );
Search searchMethod() const;
bool isShowingCandidates() const { return mShowingCandidates; }
void setShowingCandidates( bool showing ) { mShowingCandidates = showing; }
const QList<QgsLabelCandidate>& candidates() { return mCandidates; }
bool isShowingAllLabels() const { return mShowingAllLabels; }
void setShowingAllLabels( bool showing ) { mShowingAllLabels = showing; }
// implemented methods from labeling engine interface
//! called when we're going to start with rendering
virtual void init( QgsMapRenderer* mr );
//! called to find out whether the layer is used for labeling
virtual bool willUseLayer( QgsVectorLayer* layer );
//! hook called when drawing layer before issuing select()
virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx );
//! adds a diagram layer to the labeling engine
virtual int addDiagramLayer( QgsVectorLayer* layer, QgsDiagramLayerSettings *s );
//! hook called when drawing for every feature in a layer
virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() );
virtual void registerDiagramFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() );
//! called when the map is drawn and labels should be placed
virtual void drawLabeling( QgsRenderContext& context );
//! called when we're done with rendering
virtual void exit();
//! return infos about labels at a given (map) position
virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p );
//! called when passing engine among map renderers
virtual QgsLabelingEngineInterface* clone();
void drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* painter, const QgsMapToPixel* xform );
//!drawLabel
void drawLabel( pal::LabelPosition* label, QPainter* painter, const QFont& f, const QColor& c, const QgsMapToPixel* xform, double bufferSize = -1, \
const QColor& bufferColor = QColor( 255, 255, 255 ), bool drawBuffer = false );
static void drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color );
protected:
void initPal();
protected:
// hashtable of layer settings, being filled during labeling
QHash<QgsVectorLayer*, QgsPalLayerSettings> mActiveLayers;
// hashtable of active diagram layers
QHash<QgsVectorLayer*, QgsDiagramLayerSettings> mActiveDiagramLayers;
QgsPalLayerSettings mInvalidLayerSettings;
QgsMapRenderer* mMapRenderer;
int mCandPoint, mCandLine, mCandPolygon;
Search mSearch;
pal::Pal* mPal;
// list of candidates from last labeling
QList<QgsLabelCandidate> mCandidates;
bool mShowingCandidates;
bool mShowingAllLabels; // whether to avoid collisions or not
QgsLabelSearchTree* mLabelSearchTree;
};
#endif // QGSPALLABELING_H
|