~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/gui/qgslabel.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                         qgslabel.h - render vector labels
3
 
                             -------------------
4
 
    begin                : August 2004
5
 
    copyright            : (C) 2004 by Radim Blazek
6
 
    email                : blazek@itc.it
7
 
 ***************************************************************************/
8
 
/***************************************************************************
9
 
 *                                                                         *
10
 
 *   This program is free software; you can redistribute it and/or modify  *
11
 
 *   it under the terms of the GNU General Public License as published by  *
12
 
 *   the Free Software Foundation; either version 2 of the License, or     *
13
 
 *   (at your option) any later version.                                   *
14
 
 *                                                                         *
15
 
 ***************************************************************************/
16
 
/* $Id: qgslabel.h 5686 2006-08-10 16:19:19Z rblazek $ */
17
 
#ifndef QGSLABEL_H
18
 
#define QGSLABEL_H
19
 
 
20
 
#include <vector>
21
 
#include <list>
22
 
#include <qdom.h>
23
 
 
24
 
class QString;
25
 
class QWidget;
26
 
class QPainter;
27
 
class QPaintDevice;
28
 
 
29
 
class QgsPoint;
30
 
class QgsFeature;
31
 
class QgsField;
32
 
class QgsMapCanvas;
33
 
class QgsLabelAttributes;
34
 
class QgsRect;
35
 
class QgsMapToPixel;
36
 
class QgsCoordinateTransform;
37
 
 
38
 
/** Render class to display labels */
39
 
class QgsLabel
40
 
{
41
 
public:
42
 
    QgsLabel ( std::vector<QgsField> const & fields  );
43
 
 
44
 
    ~QgsLabel();
45
 
 
46
 
    /* Fields */
47
 
    enum LabelField {
48
 
        Text = 0,
49
 
        Family,
50
 
        Size,
51
 
        Bold,
52
 
        Italic,
53
 
        Underline,
54
 
        Color,
55
 
        XCoordinate,
56
 
        YCoordinate,
57
 
        XOffset,
58
 
        YOffset,
59
 
        Angle,
60
 
        Alignment,
61
 
        BufferEnabled,
62
 
        BufferSize,
63
 
        BufferColor,
64
 
        BufferBrush,
65
 
        BorderWidth,
66
 
        BorderColor,
67
 
        BorderStyle,
68
 
        LabelFieldCount
69
 
    };
70
 
 
71
 
    void dialog( QWidget * parent = 0 );
72
 
 
73
 
    /** \brief render label
74
 
     *  \param sizeScale global scale factor for size in pixels, labels in map units are not scaled
75
 
     */
76
 
    void renderLabel ( QPainter* painter, QgsRect* viewExtent, 
77
 
                       const QgsCoordinateTransform& coordTransform,
78
 
                       bool doCoordTransform, QgsMapToPixel *transform,
79
 
                       QgsFeature *feature, bool selected, QgsLabelAttributes *classAttributes=0, double sizeScale = 1.);
80
 
 
81
 
    /** Reads the renderer configuration from an XML file
82
 
     @param rnode the DOM node to read 
83
 
    */
84
 
    void readXML(const QDomNode& node);
85
 
 
86
 
    /** Writes the contents of the renderer to a configuration file */
87
 
    void writeXML(std::ostream& xml);
88
 
 
89
 
    //! add vector of required fields to existing list of fields
90
 
    void addRequiredFields ( std::list<int> *fields );
91
 
 
92
 
    //! Set available fields
93
 
    void setFields( std::vector<QgsField> const & fields  );
94
 
 
95
 
    //! Available vector fields
96
 
    std::vector<QgsField> & fields ( void );
97
 
 
98
 
    //! Pointer to default attributes
99
 
    QgsLabelAttributes *layerAttributes ( void );
100
 
 
101
 
    //! Set label field
102
 
    void setLabelField ( int attr, const QString str );
103
 
 
104
 
    //! label field
105
 
    QString labelField ( int attr );
106
 
 
107
 
    /** Get field value if : 1) field name is not empty
108
 
     *                       2) field exists
109
 
     *                       3) value is defined
110
 
     *  otherwise returns empty string
111
 
    */
112
 
    QString fieldValue ( int attr, QgsFeature *feature );
113
 
 
114
 
private:
115
 
    /** Does the actual rendering of a label at the given point
116
 
     * 
117
 
     */
118
 
    void renderLabel(QPainter* painter, QgsPoint point, 
119
 
                     bool doCoordTransform,
120
 
                     const QgsCoordinateTransform& coordTransform,
121
 
                     QgsMapToPixel* transform,
122
 
                     QString text, QFont font, QPen pen,
123
 
                     int dx, int dy,
124
 
                     double xoffset, double yoffset,
125
 
                     double ang);
126
 
 
127
 
    /** Get label point for simple feature in map units */
128
 
    void labelPoint ( std::vector<QgsPoint>&, QgsFeature *feature );
129
 
 
130
 
    /** Get label point for the given feature in wkb format. */
131
 
    unsigned char* labelPoint( QgsPoint& point, unsigned char* wkb);
132
 
 
133
 
    /** Color to draw selected features */
134
 
    QColor mSelectionColor;
135
 
    
136
 
    //! Default layer attributes
137
 
    QgsLabelAttributes *mLabelAttributes;
138
 
    
139
 
    //! Available layer fields
140
 
    std::vector<QgsField> mField;
141
 
 
142
 
    //! Label fields
143
 
    std::vector<QString> mLabelField;
144
 
 
145
 
    //! Label field indexes
146
 
    std::vector<int> mLabelFieldIdx;
147
 
};
148
 
 
149
 
#endif