QGIS API Documentation  2.99.0-Master (ba079d8)
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 
157  double mapScale() const { return mMapScale; }
158  void setMapScale( double scale ) { mMapScale = scale; }
159 
160  int dpi() const { return mDpi; }
161  void setDpi( int dpi ) { mDpi = dpi; }
162 
163  // utility functions
164 
168  QStringList splitStringForWrapping( const QString &stringToSplt ) const;
169 
173  void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
174 
184  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;
185 
187  QFont scaledFontPixelSize( const QFont &font ) const;
188 
190  double pixelFontSize( double pointSize ) const;
191 
193  double textWidthMillimeters( const QFont &font, const QString &text ) const;
194 
196  double fontHeightCharacterMM( const QFont &font, QChar c ) const;
197 
199  double fontAscentMillimeters( const QFont &font ) const;
200 
202  double fontDescentMillimeters( const QFont &font ) const;
203 
204  private:
205 
206  QString mTitle;
207 
209  Qt::AlignmentFlag mTitleAlignment;
210 
211  QString mWrapChar;
212 
213  QColor mFontColor;
214 
216  qreal mBoxSpace;
217 
219  QSizeF mSymbolSize;
220 
222  QSizeF mWmsLegendSize;
223 
225  double mLineSpacing;
226 
228  double mColumnSpace;
229 
231  int mColumnCount;
232 
234  bool mSplitLayer;
235 
237  bool mEqualColumnWidth;
238 
239  bool mRasterSymbolStroke;
240  QColor mRasterStrokeColor;
241  double mRasterStrokeWidth;
242 
243  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
244 
246  double mMmPerMapUnit;
247 
249  bool mUseAdvancedEffects;
250 
252  double mMapScale;
253 
255  int mDpi;
256 };
257 
258 
259 
260 #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
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:102
void setMapScale(double 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