QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
96  QColor layerFontColor() const {return mLayerFontColor.isValid() ? mLayerFontColor : fontColor() ;}
97 
105  void setLayerFontColor( const QColor &fontColor ) {mLayerFontColor = fontColor;}
106 
107 
108  QSizeF symbolSize() const {return mSymbolSize;}
109  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
110 
118  bool drawRasterStroke() const { return mRasterSymbolStroke; }
119 
128  void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
129 
138  QColor rasterStrokeColor() const { return mRasterStrokeColor; }
139 
149  void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
150 
159  double rasterStrokeWidth() const { return mRasterStrokeWidth; }
160 
170  void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
171 
172  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
173  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
174 
175  double lineSpacing() const { return mLineSpacing; }
176  void setLineSpacing( double s ) { mLineSpacing = s; }
177 
178  double mmPerMapUnit() const { return mMmPerMapUnit; }
179  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
180 
181  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
182  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
183 
189  double mapScale() const { return mMapScale; }
190 
196  void setMapScale( double scale ) { mMapScale = scale; }
197 
203  double mapUnitsPerPixel() const;
204 
210  void setMapUnitsPerPixel( double mapUnitsPerPixel );
211 
212  int dpi() const { return mDpi; }
213  void setDpi( int dpi ) { mDpi = dpi; }
214 
215  // utility functions
216 
221  QStringList splitStringForWrapping( const QString &stringToSplt ) const;
222 
227  void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
228 
239  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;
240 
242  QFont scaledFontPixelSize( const QFont &font ) const;
243 
245  double pixelFontSize( double pointSize ) const;
246 
248  double textWidthMillimeters( const QFont &font, const QString &text ) const;
249 
251  double fontHeightCharacterMM( const QFont &font, QChar c ) const;
252 
254  double fontAscentMillimeters( const QFont &font ) const;
255 
257  double fontDescentMillimeters( const QFont &font ) const;
258 
259  private:
260 
261  QString mTitle;
262 
264  Qt::AlignmentFlag mTitleAlignment = Qt::AlignLeft;
265 
266  QString mWrapChar;
267 
268  QColor mFontColor;
269 
271  qreal mBoxSpace = 2;
272 
274  QSizeF mSymbolSize;
275 
277  QSizeF mWmsLegendSize;
278 
280  double mLineSpacing = 1;
281 
283  double mColumnSpace = 2;
284 
286  int mColumnCount = 1;
287 
289  bool mSplitLayer = false;
290 
292  bool mEqualColumnWidth = false;
293 
294  bool mRasterSymbolStroke = true;
295  QColor mRasterStrokeColor;
296  double mRasterStrokeWidth = 0.0;
297 
298  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
299 
301  double mMmPerMapUnit = 1;
302 
304  bool mUseAdvancedEffects = true;
305 
307  double mMapScale = 1;
308 
310  int mDpi = 96;
311 
313  QColor mLayerFontColor;
314 };
315 
316 
317 
318 #endif // QGSLEGENDSETTINGS_H
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
QString wrapChar() const
void setWrapChar(const QString &t)
double boxSpace() const
void setEqualColumnWidth(bool s)
void setBoxSpace(double s)
void setMmPerMapUnit(double mmPerMapUnit)
double lineSpacing() const
int columnCount() const
void setSymbolSize(QSizeF s)
double columnSpace() const
Composer legend components style.
double mmPerMapUnit() const
bool equalColumnWidth() const
QColor fontColor() const
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define SIP_SKIP
Definition: qgis_sip.h:119
void setMapScale(double scale)
Sets the legend map scale.
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.
void setDpi(int dpi)
void setFontColor(const QColor &c)
void setColumnSpace(double s)
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns style.
void setLineSpacing(double s)
void setLayerFontColor(const QColor &fontColor)
Sets layer font color to fontColor Overrides fontColor()
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
double mapScale() const
Returns the legend map scale.
QColor layerFontColor() const
Returns layer font color, defaults to fontColor()
void setWmsLegendSize(QSizeF s)
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns reference to modifiable style.
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items...
void setUseAdvancedEffects(bool use)
bool useAdvancedEffects() const
bool splitLayer() const
void setStyle(QgsLegendStyle::Style s, const QgsLegendStyle &style)
void setColumnCount(int c)
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
QString title() const
QSizeF symbolSize() const
QSizeF wmsLegendSize() const
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
void setSplitLayer(bool s)
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.