QGIS API Documentation  2.99.0-Master (90ae728)
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 
56  QgsLegendStyle & rstyle( QgsLegendStyle::Style s ) { return mStyleMap[s]; }
58  QgsLegendStyle style( QgsLegendStyle::Style s ) const { return mStyleMap.value( s ); }
59  void setStyle( QgsLegendStyle::Style s, const QgsLegendStyle& style ) { mStyleMap[s] = style; }
60 
61  double boxSpace() const {return mBoxSpace;}
62  void setBoxSpace( double s ) {mBoxSpace = s;}
63 
64  void setWrapChar( const QString& t ) {mWrapChar = t;}
65  QString wrapChar() const {return mWrapChar;}
66 
67  double columnSpace() const {return mColumnSpace;}
68  void setColumnSpace( double s ) { mColumnSpace = s;}
69 
70  int columnCount() const { return mColumnCount; }
71  void setColumnCount( int c ) { mColumnCount = c;}
72 
73  bool splitLayer() const { return mSplitLayer; }
74  void setSplitLayer( bool s ) { mSplitLayer = s;}
75 
76  bool equalColumnWidth() const { return mEqualColumnWidth; }
77  void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
78 
79  QColor fontColor() const {return mFontColor;}
80  void setFontColor( const QColor& c ) {mFontColor = c;}
81 
82  QSizeF symbolSize() const {return mSymbolSize;}
83  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
84 
91  bool drawRasterStroke() const { return mRasterSymbolStroke; }
92 
100  void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
101 
109  QColor rasterStrokeColor() const { return mRasterStrokeColor; }
110 
119  void setRasterStrokeColor( const QColor& color ) { mRasterStrokeColor = color; }
120 
128  double rasterStrokeWidth() const { return mRasterStrokeWidth; }
129 
138  void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
139 
140  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
141  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
142 
143  double lineSpacing() const { return mLineSpacing; }
144  void setLineSpacing( double s ) { mLineSpacing = s; }
145 
146  double mmPerMapUnit() const { return mMmPerMapUnit; }
147  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
148 
149  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
150  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
151 
152  double mapScale() const { return mMapScale; }
153  void setMapScale( double scale ) { mMapScale = scale; }
154 
155  int dpi() const { return mDpi; }
156  void setDpi( int dpi ) { mDpi = dpi; }
157 
158  // utility functions
159 
163  QStringList splitStringForWrapping( const QString& stringToSplt ) const;
164 
168  void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;
169 
179  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;
180 
182  QFont scaledFontPixelSize( const QFont& font ) const;
183 
185  double pixelFontSize( double pointSize ) const;
186 
188  double textWidthMillimeters( const QFont& font, const QString& text ) const;
189 
191  double fontHeightCharacterMM( const QFont& font, QChar c ) const;
192 
194  double fontAscentMillimeters( const QFont& font ) const;
195 
197  double fontDescentMillimeters( const QFont& font ) const;
198 
199  private:
200 
201  QString mTitle;
202 
204  Qt::AlignmentFlag mTitleAlignment;
205 
206  QString mWrapChar;
207 
208  QColor mFontColor;
209 
211  qreal mBoxSpace;
212 
214  QSizeF mSymbolSize;
215 
217  QSizeF mWmsLegendSize;
218 
220  double mLineSpacing;
221 
223  double mColumnSpace;
224 
226  int mColumnCount;
227 
229  bool mSplitLayer;
230 
232  bool mEqualColumnWidth;
233 
234  bool mRasterSymbolStroke;
235  QColor mRasterStrokeColor;
236  double mRasterStrokeWidth;
237 
238  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
239 
241  double mMmPerMapUnit;
242 
244  bool mUseAdvancedEffects;
245 
247  double mMapScale;
248 
250  int mDpi;
251 };
252 
253 
254 
255 #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)
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