QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
50  Qt::AlignmentFlag titleAlignment() const { return mTitleAlignment; }
51 
56  void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
57 
65  QgsLegendStyle style( QgsLegendStyle::Style s ) const { return mStyleMap.value( s ); }
66  void setStyle( QgsLegendStyle::Style s, const QgsLegendStyle &style ) { mStyleMap[s] = style; }
67 
68  double boxSpace() const {return mBoxSpace;}
69  void setBoxSpace( double s ) {mBoxSpace = s;}
70 
71  void setWrapChar( const QString &t ) {mWrapChar = t;}
72  QString wrapChar() const {return mWrapChar;}
73 
74  double columnSpace() const {return mColumnSpace;}
75  void setColumnSpace( double s ) { mColumnSpace = s;}
76 
77  int columnCount() const { return mColumnCount; }
78  void setColumnCount( int c ) { mColumnCount = c;}
79 
80  bool splitLayer() const { return mSplitLayer; }
81  void setSplitLayer( bool s ) { mSplitLayer = s;}
82 
83  bool equalColumnWidth() const { return mEqualColumnWidth; }
84  void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
85 
86  QColor fontColor() const {return mFontColor;}
87  void setFontColor( const QColor &c ) {mFontColor = c;}
88 
95  QColor layerFontColor() const {return mLayerFontColor.isValid() ? mLayerFontColor : fontColor() ;}
96 
104  void setLayerFontColor( const QColor &fontColor ) {mLayerFontColor = fontColor;}
105 
106 
107  QSizeF symbolSize() const {return mSymbolSize;}
108  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
109 
118  void setSymbolAlignment( Qt::AlignmentFlag alignment ) { mSymbolAlignment = alignment; }
119 
128  Qt::AlignmentFlag symbolAlignment() const { return mSymbolAlignment; }
129 
137  bool drawRasterStroke() const { return mRasterSymbolStroke; }
138 
147  void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
148 
157  QColor rasterStrokeColor() const { return mRasterStrokeColor; }
158 
168  void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
169 
178  double rasterStrokeWidth() const { return mRasterStrokeWidth; }
179 
189  void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
190 
191  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
192  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
193 
194  double lineSpacing() const { return mLineSpacing; }
195  void setLineSpacing( double s ) { mLineSpacing = s; }
196 
197  double mmPerMapUnit() const { return mMmPerMapUnit; }
198  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
199 
200  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
201  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
202 
208  double mapScale() const { return mMapScale; }
209 
215  void setMapScale( double scale ) { mMapScale = scale; }
216 
222  double mapUnitsPerPixel() const;
223 
229  void setMapUnitsPerPixel( double mapUnitsPerPixel );
230 
231  int dpi() const { return mDpi; }
232  void setDpi( int dpi ) { mDpi = dpi; }
233 
234  // utility functions
235 
249  QStringList evaluateItemText( const QString &text, const QgsExpressionContext &context ) const;
250 
255  QStringList splitStringForWrapping( const QString &stringToSplt ) const;
256 
261  void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
262 
273  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;
274 
276  QFont scaledFontPixelSize( const QFont &font ) const;
277 
279  double pixelFontSize( double pointSize ) const;
280 
282  double textWidthMillimeters( const QFont &font, const QString &text ) const;
283 
285  double fontHeightCharacterMM( const QFont &font, QChar c ) const;
286 
288  double fontAscentMillimeters( const QFont &font ) const;
289 
291  double fontDescentMillimeters( const QFont &font ) const;
292 
293  private:
294 
295  QString mTitle;
296 
298  Qt::AlignmentFlag mTitleAlignment = Qt::AlignLeft;
299 
300  QString mWrapChar;
301 
302  QColor mFontColor;
303 
305  qreal mBoxSpace = 2;
306 
308  QSizeF mSymbolSize;
309 
311  QSizeF mWmsLegendSize;
312 
314  double mLineSpacing = 1;
315 
317  double mColumnSpace = 2;
318 
320  int mColumnCount = 1;
321 
323  bool mSplitLayer = false;
324 
326  bool mEqualColumnWidth = false;
327 
328  bool mRasterSymbolStroke = true;
329  QColor mRasterStrokeColor;
330  double mRasterStrokeWidth = 0.0;
331 
332  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
333 
335  double mMmPerMapUnit = 1;
336 
338  bool mUseAdvancedEffects = true;
339 
341  double mMapScale = 1;
342 
344  int mDpi = 96;
345 
347  QColor mLayerFontColor;
348 
350  Qt::AlignmentFlag mSymbolAlignment = Qt::AlignLeft;
351 };
352 
353 
354 
355 #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 setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
void setSymbolSize(QSizeF s)
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
QColor layerFontColor() const
Returns layer font color, defaults to fontColor()
Contains detailed styling information relating to how a layout legend should be rendered.
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:126
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)
Style
Component of legends which can be styled.
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