QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
29 
38 class CORE_EXPORT QgsLegendSettings
39 {
40  public:
42 
43  void setTitle( const QString &t ) { mTitle = t; }
44  QString title() const { return mTitle; }
45 
51  Qt::AlignmentFlag titleAlignment() const { return mTitleAlignment; }
52 
58  void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
59 
67  QgsLegendStyle style( QgsLegendStyle::Style s ) const { return mStyleMap.value( s ); }
68  void setStyle( QgsLegendStyle::Style s, const QgsLegendStyle &style ) { mStyleMap[s] = style; }
69 
70  double boxSpace() const {return mBoxSpace;}
71  void setBoxSpace( double s ) {mBoxSpace = s;}
72 
73  void setWrapChar( const QString &t ) {mWrapChar = t;}
74  QString wrapChar() const {return mWrapChar;}
75 
76  double columnSpace() const {return mColumnSpace;}
77  void setColumnSpace( double s ) { mColumnSpace = s;}
78 
79  int columnCount() const { return mColumnCount; }
80  void setColumnCount( int c ) { mColumnCount = c;}
81 
82  bool splitLayer() const { return mSplitLayer; }
83  void setSplitLayer( bool s ) { mSplitLayer = s;}
84 
85  bool equalColumnWidth() const { return mEqualColumnWidth; }
86  void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
87 
88  QColor fontColor() const {return mFontColor;}
89  void setFontColor( const QColor &c ) {mFontColor = c;}
90 
97  QColor layerFontColor() const {return mLayerFontColor.isValid() ? mLayerFontColor : fontColor() ;}
98 
106  void setLayerFontColor( const QColor &fontColor ) {mLayerFontColor = fontColor;}
107 
108 
109  QSizeF symbolSize() const {return mSymbolSize;}
110  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
111 
119  bool drawRasterStroke() const { return mRasterSymbolStroke; }
120 
129  void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
130 
139  QColor rasterStrokeColor() const { return mRasterStrokeColor; }
140 
150  void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
151 
160  double rasterStrokeWidth() const { return mRasterStrokeWidth; }
161 
171  void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
172 
173  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
174  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
175 
176  double lineSpacing() const { return mLineSpacing; }
177  void setLineSpacing( double s ) { mLineSpacing = s; }
178 
179  double mmPerMapUnit() const { return mMmPerMapUnit; }
180  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
181 
182  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
183  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
184 
190  double mapScale() const { return mMapScale; }
191 
197  void setMapScale( double scale ) { mMapScale = scale; }
198 
204  double mapUnitsPerPixel() const;
205 
211  void setMapUnitsPerPixel( double mapUnitsPerPixel );
212 
213  int dpi() const { return mDpi; }
214  void setDpi( int dpi ) { mDpi = dpi; }
215 
216  // utility functions
217 
231  QStringList evaluateItemText( const QString &text, const QgsExpressionContext &context ) const;
232 
237  QStringList splitStringForWrapping( const QString &stringToSplt ) const;
238 
243  void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
244 
255  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;
256 
258  QFont scaledFontPixelSize( const QFont &font ) const;
259 
261  double pixelFontSize( double pointSize ) const;
262 
264  double textWidthMillimeters( const QFont &font, const QString &text ) const;
265 
267  double fontHeightCharacterMM( const QFont &font, QChar c ) const;
268 
270  double fontAscentMillimeters( const QFont &font ) const;
271 
273  double fontDescentMillimeters( const QFont &font ) const;
274 
275  private:
276 
277  QString mTitle;
278 
280  Qt::AlignmentFlag mTitleAlignment = Qt::AlignLeft;
281 
282  QString mWrapChar;
283 
284  QColor mFontColor;
285 
287  qreal mBoxSpace = 2;
288 
290  QSizeF mSymbolSize;
291 
293  QSizeF mWmsLegendSize;
294 
296  double mLineSpacing = 1;
297 
299  double mColumnSpace = 2;
300 
302  int mColumnCount = 1;
303 
305  bool mSplitLayer = false;
306 
308  bool mEqualColumnWidth = false;
309 
310  bool mRasterSymbolStroke = true;
311  QColor mRasterStrokeColor;
312  double mRasterStrokeWidth = 0.0;
313 
314  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
315 
317  double mMmPerMapUnit = 1;
318 
320  bool mUseAdvancedEffects = true;
321 
323  double mMapScale = 1;
324 
326  int mDpi = 96;
327 
329  QColor mLayerFontColor;
330 };
331 
332 
333 
334 #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)
QColor layerFontColor() const
Returns layer font color, defaults to fontColor()
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.
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
QSizeF wmsLegendSize() const
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns style.
#define SIP_SKIP
Definition: qgis_sip.h:119
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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 setLayerFontColor(const QColor &fontColor)
Sets layer font color to fontColor Overrides fontColor()
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