QGIS API Documentation  3.0.2-Girona (307d082)
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 "qgis_core.h"
20 #include "qgis_sip.h"
21 #include <QColor>
22 #include <QSizeF>
23 
24 class QRectF;
25 
26 #include "qgslegendstyle.h"
27 
28 
37 class CORE_EXPORT QgsLegendSettings
38 {
39  public:
41 
42  void setTitle( const QString &t ) { mTitle = t; }
43  QString title() const { return mTitle; }
44 
50  Qt::AlignmentFlag titleAlignment() const { return mTitleAlignment; }
51 
57  void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
58 
66  QgsLegendStyle style( QgsLegendStyle::Style s ) const { return mStyleMap.value( s ); }
67  void setStyle( QgsLegendStyle::Style s, const QgsLegendStyle &style ) { mStyleMap[s] = style; }
68 
69  double boxSpace() const {return mBoxSpace;}
70  void setBoxSpace( double s ) {mBoxSpace = s;}
71 
72  void setWrapChar( const QString &t ) {mWrapChar = t;}
73  QString wrapChar() const {return mWrapChar;}
74 
75  double columnSpace() const {return mColumnSpace;}
76  void setColumnSpace( double s ) { mColumnSpace = s;}
77 
78  int columnCount() const { return mColumnCount; }
79  void setColumnCount( int c ) { mColumnCount = c;}
80 
81  bool splitLayer() const { return mSplitLayer; }
82  void setSplitLayer( bool s ) { mSplitLayer = s;}
83 
84  bool equalColumnWidth() const { return mEqualColumnWidth; }
85  void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
86 
87  QColor fontColor() const {return mFontColor;}
88  void setFontColor( const QColor &c ) {mFontColor = c;}
89 
90  QSizeF symbolSize() const {return mSymbolSize;}
91  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
92 
100  bool drawRasterStroke() const { return mRasterSymbolStroke; }
101 
110  void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
111 
120  QColor rasterStrokeColor() const { return mRasterStrokeColor; }
121 
131  void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
132 
141  double rasterStrokeWidth() const { return mRasterStrokeWidth; }
142 
152  void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
153 
154  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
155  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
156 
157  double lineSpacing() const { return mLineSpacing; }
158  void setLineSpacing( double s ) { mLineSpacing = s; }
159 
160  double mmPerMapUnit() const { return mMmPerMapUnit; }
161  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
162 
163  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
164  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
165 
171  double mapScale() const { return mMapScale; }
172 
178  void setMapScale( double scale ) { mMapScale = scale; }
179 
180  int dpi() const { return mDpi; }
181  void setDpi( int dpi ) { mDpi = dpi; }
182 
183  // utility functions
184 
189  QStringList splitStringForWrapping( const QString &stringToSplt ) const;
190 
195  void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
196 
207  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;
208 
210  QFont scaledFontPixelSize( const QFont &font ) const;
211 
213  double pixelFontSize( double pointSize ) const;
214 
216  double textWidthMillimeters( const QFont &font, const QString &text ) const;
217 
219  double fontHeightCharacterMM( const QFont &font, QChar c ) const;
220 
222  double fontAscentMillimeters( const QFont &font ) const;
223 
225  double fontDescentMillimeters( const QFont &font ) const;
226 
227  private:
228 
229  QString mTitle;
230 
232  Qt::AlignmentFlag mTitleAlignment = Qt::AlignLeft;
233 
234  QString mWrapChar;
235 
236  QColor mFontColor;
237 
239  qreal mBoxSpace = 2;
240 
242  QSizeF mSymbolSize;
243 
245  QSizeF mWmsLegendSize;
246 
248  double mLineSpacing = 1;
249 
251  double mColumnSpace = 2;
252 
254  int mColumnCount = 1;
255 
257  bool mSplitLayer = false;
258 
260  bool mEqualColumnWidth = false;
261 
262  bool mRasterSymbolStroke = true;
263  QColor mRasterStrokeColor;
264  double mRasterStrokeWidth = 0.0;
265 
266  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
267 
269  double mMmPerMapUnit = 1;
270 
272  bool mUseAdvancedEffects = true;
273 
275  double mMapScale = 1;
276 
278  int mDpi = 96;
279 };
280 
281 
282 
283 #endif // QGSLEGENDSETTINGS_H
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
void setWrapChar(const QString &t)
void setEqualColumnWidth(bool s)
double mapScale() const
Returns the legend map scale.
void setBoxSpace(double s)
void setMmPerMapUnit(double mmPerMapUnit)
int columnCount() const
bool useAdvancedEffects() const
QString wrapChar() const
void setSymbolSize(QSizeF s)
Composer legend components style.
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
QSizeF wmsLegendSize() const
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns style.
#define SIP_SKIP
Definition: qgis_sip.h:119
void setMapScale(double scale)
Sets the legend map scale.
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items...
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
void setTitle(const QString &t)
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
void setDpi(int dpi)
double boxSpace() const
void setFontColor(const QColor &c)
void setColumnSpace(double s)
QSizeF symbolSize() const
void setLineSpacing(double s)
void setWmsLegendSize(QSizeF s)
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns reference to modifiable style.
void setUseAdvancedEffects(bool use)
void setStyle(QgsLegendStyle::Style s, const QgsLegendStyle &style)
bool equalColumnWidth() const
void setColumnCount(int c)
double columnSpace() const
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
double lineSpacing() const
QColor fontColor() const
bool splitLayer() const
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
double mmPerMapUnit() const
void setSplitLayer(bool s)
QString title() const