QGIS API Documentation  2.99.0-Master (9caa722)
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 
36 class CORE_EXPORT QgsLegendSettings
37 {
38  public:
40 
41  void setTitle( const QString &t ) { mTitle = t; }
42  QString title() const { return mTitle; }
43 
48  Qt::AlignmentFlag titleAlignment() const { return mTitleAlignment; }
49 
54  void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
55 
63  QgsLegendStyle style( QgsLegendStyle::Style s ) const { return mStyleMap.value( s ); }
64  void setStyle( QgsLegendStyle::Style s, const QgsLegendStyle &style ) { mStyleMap[s] = style; }
65 
66  double boxSpace() const {return mBoxSpace;}
67  void setBoxSpace( double s ) {mBoxSpace = s;}
68 
69  void setWrapChar( const QString &t ) {mWrapChar = t;}
70  QString wrapChar() const {return mWrapChar;}
71 
72  double columnSpace() const {return mColumnSpace;}
73  void setColumnSpace( double s ) { mColumnSpace = s;}
74 
75  int columnCount() const { return mColumnCount; }
76  void setColumnCount( int c ) { mColumnCount = c;}
77 
78  bool splitLayer() const { return mSplitLayer; }
79  void setSplitLayer( bool s ) { mSplitLayer = s;}
80 
81  bool equalColumnWidth() const { return mEqualColumnWidth; }
82  void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
83 
84  QColor fontColor() const {return mFontColor;}
85  void setFontColor( const QColor &c ) {mFontColor = c;}
86 
87  QSizeF symbolSize() const {return mSymbolSize;}
88  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
89 
96  bool drawRasterStroke() const { return mRasterSymbolStroke; }
97 
105  void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
106 
114  QColor rasterStrokeColor() const { return mRasterStrokeColor; }
115 
124  void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
125 
133  double rasterStrokeWidth() const { return mRasterStrokeWidth; }
134 
143  void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
144 
145  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
146  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
147 
148  double lineSpacing() const { return mLineSpacing; }
149  void setLineSpacing( double s ) { mLineSpacing = s; }
150 
151  double mmPerMapUnit() const { return mMmPerMapUnit; }
152  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
153 
154  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
155  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
156 
162  double mapScale() const { return mMapScale; }
163 
169  void setMapScale( double scale ) { mMapScale = scale; }
170 
171  int dpi() const { return mDpi; }
172  void setDpi( int dpi ) { mDpi = dpi; }
173 
174  // utility functions
175 
179  QStringList splitStringForWrapping( const QString &stringToSplt ) const;
180 
184  void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
185 
195  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;
196 
198  QFont scaledFontPixelSize( const QFont &font ) const;
199 
201  double pixelFontSize( double pointSize ) const;
202 
204  double textWidthMillimeters( const QFont &font, const QString &text ) const;
205 
207  double fontHeightCharacterMM( const QFont &font, QChar c ) const;
208 
210  double fontAscentMillimeters( const QFont &font ) const;
211 
213  double fontDescentMillimeters( const QFont &font ) const;
214 
215  private:
216 
217  QString mTitle;
218 
220  Qt::AlignmentFlag mTitleAlignment;
221 
222  QString mWrapChar;
223 
224  QColor mFontColor;
225 
227  qreal mBoxSpace;
228 
230  QSizeF mSymbolSize;
231 
233  QSizeF mWmsLegendSize;
234 
236  double mLineSpacing;
237 
239  double mColumnSpace;
240 
242  int mColumnCount;
243 
245  bool mSplitLayer;
246 
248  bool mEqualColumnWidth;
249 
250  bool mRasterSymbolStroke;
251  QColor mRasterStrokeColor;
252  double mRasterStrokeWidth;
253 
254  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
255 
257  double mMmPerMapUnit;
258 
260  bool mUseAdvancedEffects;
261 
263  double mMapScale;
264 
266  int mDpi;
267 };
268 
269 
270 
271 #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