QGIS API Documentation  3.6.0-Noosa (5873452)
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 
91  QSizeF symbolSize() const {return mSymbolSize;}
92  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
93 
101  bool drawRasterStroke() const { return mRasterSymbolStroke; }
102 
111  void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
112 
121  QColor rasterStrokeColor() const { return mRasterStrokeColor; }
122 
132  void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
133 
142  double rasterStrokeWidth() const { return mRasterStrokeWidth; }
143 
153  void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
154 
155  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
156  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
157 
158  double lineSpacing() const { return mLineSpacing; }
159  void setLineSpacing( double s ) { mLineSpacing = s; }
160 
161  double mmPerMapUnit() const { return mMmPerMapUnit; }
162  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
163 
164  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
165  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
166 
172  double mapScale() const { return mMapScale; }
173 
179  void setMapScale( double scale ) { mMapScale = scale; }
180 
181  int dpi() const { return mDpi; }
182  void setDpi( int dpi ) { mDpi = dpi; }
183 
184  // utility functions
185 
199  QStringList evaluateItemText( const QString &text, const QgsExpressionContext &context ) const;
200 
205  QStringList splitStringForWrapping( const QString &stringToSplt ) const;
206 
211  void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
212 
223  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;
224 
226  QFont scaledFontPixelSize( const QFont &font ) const;
227 
229  double pixelFontSize( double pointSize ) const;
230 
232  double textWidthMillimeters( const QFont &font, const QString &text ) const;
233 
235  double fontHeightCharacterMM( const QFont &font, QChar c ) const;
236 
238  double fontAscentMillimeters( const QFont &font ) const;
239 
241  double fontDescentMillimeters( const QFont &font ) const;
242 
243  private:
244 
245  QString mTitle;
246 
248  Qt::AlignmentFlag mTitleAlignment = Qt::AlignLeft;
249 
250  QString mWrapChar;
251 
252  QColor mFontColor;
253 
255  qreal mBoxSpace = 2;
256 
258  QSizeF mSymbolSize;
259 
261  QSizeF mWmsLegendSize;
262 
264  double mLineSpacing = 1;
265 
267  double mColumnSpace = 2;
268 
270  int mColumnCount = 1;
271 
273  bool mSplitLayer = false;
274 
276  bool mEqualColumnWidth = false;
277 
278  bool mRasterSymbolStroke = true;
279  QColor mRasterStrokeColor;
280  double mRasterStrokeWidth = 0.0;
281 
282  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
283 
285  double mMmPerMapUnit = 1;
286 
288  bool mUseAdvancedEffects = true;
289 
291  double mMapScale = 1;
292 
294  int mDpi = 96;
295 };
296 
297 
298 
299 #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.
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 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