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

« back to all changes in this revision

Viewing changes to src/core/composer/qgscomposerlegend.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
                         qgscomposerlegend.h  -  description
 
3
                         -------------------
 
4
    begin                : June 2008
 
5
    copyright            : (C) 2008 by Marco Hugentobler
 
6
    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#ifndef QGSCOMPOSERLEGEND_H
 
19
#define QGSCOMPOSERLEGEND_H
 
20
 
 
21
#include "qgscomposeritem.h"
 
22
#include "qgslegendmodel.h"
 
23
 
 
24
class QgsSymbol;
 
25
 
 
26
/** \ingroup MapComposer
 
27
 * A legend that can be placed onto a map composition
 
28
 */
 
29
class CORE_EXPORT QgsComposerLegend: public QgsComposerItem
 
30
{
 
31
    Q_OBJECT
 
32
 
 
33
  public:
 
34
    QgsComposerLegend( QgsComposition* composition );
 
35
    ~QgsComposerLegend();
 
36
 
 
37
    /** \brief Reimplementation of QCanvasItem::paint*/
 
38
    void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
 
39
 
 
40
    /**Paints the legend and calculates its size. If painter is 0, only size is calculated*/
 
41
    QSizeF paintAndDetermineSize( QPainter* painter );
 
42
 
 
43
    /**Sets item box to the whole content*/
 
44
    void adjustBoxSize();
 
45
 
 
46
    /**Returns pointer to the legend model*/
 
47
    QgsLegendModel* model() {return &mLegendModel;}
 
48
 
 
49
    //setters and getters
 
50
    void setTitle( const QString& t ) {mTitle = t;}
 
51
    QString title() const {return mTitle;}
 
52
 
 
53
    QFont titleFont() const;
 
54
    void setTitleFont( const QFont& f );
 
55
 
 
56
    QFont layerFont() const;
 
57
    void setLayerFont( const QFont& f );
 
58
 
 
59
    QFont itemFont() const;
 
60
    void setItemFont( const QFont& f );
 
61
 
 
62
    double boxSpace() const {return mBoxSpace;}
 
63
    void setBoxSpace( double s ) {mBoxSpace = s;}
 
64
 
 
65
    double layerSpace() const {return mLayerSpace;}
 
66
    void setLayerSpace( double s ) {mLayerSpace = s;}
 
67
 
 
68
    double symbolSpace() const {return mSymbolSpace;}
 
69
    void setSymbolSpace( double s ) {mSymbolSpace = s;}
 
70
 
 
71
    double iconLabelSpace() const {return mIconLabelSpace;}
 
72
    void setIconLabelSpace( double s ) {mIconLabelSpace = s;}
 
73
 
 
74
    double symbolWidth() const {return mSymbolWidth;}
 
75
    void setSymbolWidth( double w ) {mSymbolWidth = w;}
 
76
 
 
77
    double symbolHeight() const {return mSymbolHeight;}
 
78
    void setSymbolHeight( double h ) {mSymbolHeight = h;}
 
79
 
 
80
    /**Updates the model and all legend entries*/
 
81
    void updateLegend();
 
82
 
 
83
    /** stores state in Dom node
 
84
       * @param elem is Dom element corresponding to 'Composer' tag
 
85
       * @param temp write template file
 
86
       */
 
87
    bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
 
88
 
 
89
    /** sets state from Dom document
 
90
       * @param itemElem is Dom node corresponding to item tag
 
91
       */
 
92
    bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
 
93
 
 
94
  public slots:
 
95
    /**Data changed*/
 
96
    void synchronizeWithModel();
 
97
 
 
98
  protected:
 
99
    QString mTitle;
 
100
 
 
101
    //different fonts for entries
 
102
    QFont mTitleFont;
 
103
    QFont mLayerFont;
 
104
    QFont mItemFont;
 
105
 
 
106
    /**Space between item box and contents*/
 
107
    double mBoxSpace;
 
108
    /**Vertical space between layer entries*/
 
109
    double mLayerSpace;
 
110
    /**Vertical space between symbol entries*/
 
111
    double mSymbolSpace;
 
112
    /**Horizontal space between item icon and label*/
 
113
    double mIconLabelSpace;
 
114
    /**Width of symbol icon*/
 
115
    double mSymbolWidth;
 
116
    /**Height of symbol icon*/
 
117
    double mSymbolHeight;
 
118
 
 
119
    QgsLegendModel mLegendModel;
 
120
 
 
121
 
 
122
  private:
 
123
    QgsComposerLegend(); //forbidden
 
124
 
 
125
    /**Draws child items of a layer item
 
126
       @param layerItem parent model item (layer)
 
127
       @param currentYCoord in/out: current y position of legend item
 
128
       @param maxXCoord in/out: maximum x-coordinate of the whole legend
 
129
       @param layerOpacity opacity of the corresponding map layer
 
130
    */
 
131
    void drawLayerChildItems( QPainter* p, QStandardItem* layerItem, double& currentYCoord, double& maxXCoord, int layerOpacity = 255 );
 
132
 
 
133
    /**Draws a symbol at the current y position and returns the new x position. Returns real symbol height, because for points,
 
134
     it is possible that it differs from mSymbolHeight*/
 
135
    void drawSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity = 255 ) const;
 
136
    void drawPointSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int opacity = 255 ) const;
 
137
    void drawLineSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity = 255 ) const;
 
138
    void drawPolygonSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity = 255 ) const;
 
139
 
 
140
    /**Helper function that lists ids of layers contained in map canvas*/
 
141
    QStringList layerIdList() const;
 
142
};
 
143
 
 
144
#endif