QGIS API Documentation  2.99.0-Master (716ff6c)
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 <QColor>
21 #include <QSizeF>
22 
23 class QRectF;
24 
25 #include "qgslegendstyle.h"
26 
27 
35 class CORE_EXPORT QgsLegendSettings
36 {
37  public:
39 
40  void setTitle( const QString &t ) { mTitle = t; }
41  QString title() const { return mTitle; }
42 
47  Qt::AlignmentFlag titleAlignment() const { return mTitleAlignment; }
48 
53  void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
54 
60  SIP_SKIP QgsLegendStyle &rstyle( QgsLegendStyle::Style s ) { return mStyleMap[s]; }
62  QgsLegendStyle style( QgsLegendStyle::Style s ) const { return mStyleMap.value( s ); }
63  void setStyle( QgsLegendStyle::Style s, const QgsLegendStyle &style ) { mStyleMap[s] = style; }
64 
65  double boxSpace() const {return mBoxSpace;}
66  void setBoxSpace( double s ) {mBoxSpace = s;}
67 
68  void setWrapChar( const QString &t ) {mWrapChar = t;}
69  QString wrapChar() const {return mWrapChar;}
70 
71  double columnSpace() const {return mColumnSpace;}
72  void setColumnSpace( double s ) { mColumnSpace = s;}
73 
74  int columnCount() const { return mColumnCount; }
75  void setColumnCount( int c ) { mColumnCount = c;}
76 
77  bool splitLayer() const { return mSplitLayer; }
78  void setSplitLayer( bool s ) { mSplitLayer = s;}
79 
80  bool equalColumnWidth() const { return mEqualColumnWidth; }
81  void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
82 
83  QColor fontColor() const {return mFontColor;}
84  void setFontColor( const QColor &c ) {mFontColor = c;}
85 
86  QSizeF symbolSize() const {return mSymbolSize;}
87  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
88 
95  bool drawRasterStroke() const { return mRasterSymbolStroke; }
96 
104  void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
105 
113  QColor rasterStrokeColor() const { return mRasterStrokeColor; }
114 
123  void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
124 
132  double rasterStrokeWidth() const { return mRasterStrokeWidth; }
133 
142  void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
143 
144  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
145  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
146 
147  double lineSpacing() const { return mLineSpacing; }
148  void setLineSpacing( double s ) { mLineSpacing = s; }
149 
150  double mmPerMapUnit() const { return mMmPerMapUnit; }
151  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
152 
153  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
154  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
155 
156  double mapScale() const { return mMapScale; }
157  void setMapScale( double scale ) { mMapScale = scale; }
158 
159  int dpi() const { return mDpi; }
160  void setDpi( int dpi ) { mDpi = dpi; }
161 
162  // utility functions
163 
167  QStringList splitStringForWrapping( const QString &stringToSplt ) const;
168 
172  void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
173 
183  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;
184 
186  QFont scaledFontPixelSize( const QFont &font ) const;
187 
189  double pixelFontSize( double pointSize ) const;
190 
192  double textWidthMillimeters( const QFont &font, const QString &text ) const;
193 
195  double fontHeightCharacterMM( const QFont &font, QChar c ) const;
196 
198  double fontAscentMillimeters( const QFont &font ) const;
199 
201  double fontDescentMillimeters( const QFont &font ) const;
202 
203  private:
204 
205  QString mTitle;
206 
208  Qt::AlignmentFlag mTitleAlignment;
209 
210  QString mWrapChar;
211 
212  QColor mFontColor;
213 
215  qreal mBoxSpace;
216 
218  QSizeF mSymbolSize;
219 
221  QSizeF mWmsLegendSize;
222 
224  double mLineSpacing;
225 
227  double mColumnSpace;
228 
230  int mColumnCount;
231 
233  bool mSplitLayer;
234 
236  bool mEqualColumnWidth;
237 
238  bool mRasterSymbolStroke;
239  QColor mRasterStrokeColor;
240  double mRasterStrokeWidth;
241 
242  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
243 
245  double mMmPerMapUnit;
246 
248  bool mUseAdvancedEffects;
249 
251  double mMapScale;
252 
254  int mDpi;
255 };
256 
257 
258 
259 #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.
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)
#define SIP_SKIP
Definition: qgis.h:439
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