QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgslegendsettings.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslegendsettings.h
3  --------------------------------------
4  Date : July 2014
5  Copyright : (C) 2014 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSLEGENDSETTINGS_H
17 #define QGSLEGENDSETTINGS_H
18 
19 #include <QColor>
20 #include <QSizeF>
21 
22 class QRectF;
23 
24 #include "qgscomposerlegendstyle.h"
25 
27 
28 
36 class CORE_EXPORT QgsLegendSettings
37 {
38  public:
40 
41  void setTitle( const QString& t ) { mTitle = t; }
42  QString title() const { return mTitle; }
43 
48  Qt::AlignmentFlag titleAlignment() const { return mTitleAlignment; }
53  void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
54 
58  QgsComposerLegendStyle style( QgsComposerLegendStyle::Style s ) const { return mStyleMap.value( s ); }
59  void setStyle( QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style ) { mStyleMap[s] = style; }
60 
61  double boxSpace() const {return mBoxSpace;}
62  void setBoxSpace( double s ) {mBoxSpace = s;}
63 
64  void setWrapChar( const QString& t ) {mWrapChar = t;}
65  QString wrapChar() const {return mWrapChar;}
66 
67  double columnSpace() const {return mColumnSpace;}
68  void setColumnSpace( double s ) { mColumnSpace = s;}
69 
70  int columnCount() const { return mColumnCount; }
71  void setColumnCount( int c ) { mColumnCount = c;}
72 
73  int splitLayer() const { return mSplitLayer; }
74  void setSplitLayer( bool s ) { mSplitLayer = s;}
75 
76  int equalColumnWidth() const { return mEqualColumnWidth; }
77  void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
78 
79  QColor fontColor() const {return mFontColor;}
80  void setFontColor( const QColor& c ) {mFontColor = c;}
81 
82  QSizeF symbolSize() const {return mSymbolSize;}
83  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
84 
85  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
86  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
87 
88  double lineSpacing() const { return mLineSpacing; }
89  void setLineSpacing( double s ) { mLineSpacing = s; }
90 
91  double mmPerMapUnit() const { return mMmPerMapUnit; }
92  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
93 
94  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
95  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
96 
97  double mapScale() const { return mMapScale; }
98  void setMapScale( double scale ) { mMapScale = scale; }
99 
100  int dpi() const { return mDpi; }
101  void setDpi( int dpi ) { mDpi = dpi; }
102 
103  // utility functions
104 
107  QStringList splitStringForWrapping( QString stringToSplt ) const;
108 
111  void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;
112 
122  void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop, int flags = Qt::TextWordWrap ) const;
123 
125  QFont scaledFontPixelSize( const QFont& font ) const;
126 
128  double pixelFontSize( double pointSize ) const;
129 
131  double textWidthMillimeters( const QFont& font, const QString& text ) const;
132 
134  double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
135 
137  double fontAscentMillimeters( const QFont& font ) const;
138 
140  double fontDescentMillimeters( const QFont& font ) const;
141 
142  private:
143 
144  QString mTitle;
145 
147  Qt::AlignmentFlag mTitleAlignment;
148 
149  QString mWrapChar;
150 
151  QColor mFontColor;
152 
154  qreal mBoxSpace;
155 
157  QSizeF mSymbolSize;
158 
160  QSizeF mWmsLegendSize;
161 
163  double mLineSpacing;
164 
166  double mColumnSpace;
167 
169  int mColumnCount;
170 
172  bool mSplitLayer;
173 
175  bool mEqualColumnWidth;
176 
177  QMap<QgsComposerLegendStyle::Style, QgsComposerLegendStyle> mStyleMap;
178 
180  double mMmPerMapUnit;
181 
183  bool mUseAdvancedEffects;
184 
186  double mMapScale;
187 
189  int mDpi;
190 };
191 
192 
193 
194 #endif // QGSLEGENDSETTINGS_H
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
Definition: qgslegendsettings.h:53
QString wrapChar() const
Definition: qgslegendsettings.h:65
void setWrapChar(const QString &t)
Definition: qgslegendsettings.h:64
double boxSpace() const
Definition: qgslegendsettings.h:61
void setEqualColumnWidth(bool s)
Definition: qgslegendsettings.h:77
void setBoxSpace(double s)
Definition: qgslegendsettings.h:62
void setMmPerMapUnit(double mmPerMapUnit)
Definition: qgslegendsettings.h:92
double lineSpacing() const
Definition: qgslegendsettings.h:88
QgsComposerLegendStyle & rstyle(QgsComposerLegendStyle::Style s)
Returns reference to modifiable style.
Definition: qgslegendsettings.h:56
int columnCount() const
Definition: qgslegendsettings.h:70
void setSymbolSize(QSizeF s)
Definition: qgslegendsettings.h:83
double columnSpace() const
Definition: qgslegendsettings.h:67
double mmPerMapUnit() const
Definition: qgslegendsettings.h:91
QgsComposerLegendStyle style(QgsComposerLegendStyle::Style s) const
Returns style.
Definition: qgslegendsettings.h:58
QColor fontColor() const
Definition: qgslegendsettings.h:79
int splitLayer() const
Definition: qgslegendsettings.h:73
int dpi() const
Definition: qgslegendsettings.h:100
void setMapScale(double scale)
Definition: qgslegendsettings.h:98
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Definition: qgslegendsettings.h:36
void setTitle(const QString &t)
Definition: qgslegendsettings.h:41
void setDpi(int dpi)
Definition: qgslegendsettings.h:101
void setFontColor(const QColor &c)
Definition: qgslegendsettings.h:80
void setColumnSpace(double s)
Definition: qgslegendsettings.h:68
Abstract base class for the legend item types.
Definition: qgscomposerlegenditem.h:27
void setStyle(QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style)
Definition: qgslegendsettings.h:59
void setLineSpacing(double s)
Definition: qgslegendsettings.h:89
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
Definition: qgslegendsettings.h:48
double mapScale() const
Definition: qgslegendsettings.h:97
Composer legend components style.
Definition: qgscomposerlegendstyle.h:30
void setWmsLegendSize(QSizeF s)
Definition: qgslegendsettings.h:86
void setUseAdvancedEffects(bool use)
Definition: qgslegendsettings.h:95
bool useAdvancedEffects() const
Definition: qgslegendsettings.h:94
Style
Definition: qgscomposerlegendstyle.h:33
void setColumnCount(int c)
Definition: qgslegendsettings.h:71
QString title() const
Definition: qgslegendsettings.h:42
QSizeF symbolSize() const
Definition: qgslegendsettings.h:82
QSizeF wmsLegendSize() const
Definition: qgslegendsettings.h:85
int equalColumnWidth() const
Definition: qgslegendsettings.h:76
void setSplitLayer(bool s)
Definition: qgslegendsettings.h:74