QGIS API Documentation  2.17.0-Master (8784312)
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 <QColor>
20 #include <QSizeF>
21 
22 class QRectF;
23 
24 #include "qgscomposerlegendstyle.h"
25 
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; }
53  void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
54 
58  QgsComposerLegendStyle style( QgsComposerLegendStyle::Style s ) const { return mStyleMap.value( s ); }
59  void setStyle( QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle& 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 drawRasterBorder() const { return mRasterSymbolBorder; }
92 
100  void setDrawRasterBorder( bool enabled ) { mRasterSymbolBorder = enabled; }
101 
109  QColor rasterBorderColor() const { return mRasterBorderColor; }
110 
119  void setRasterBorderColor( const QColor& color ) { mRasterBorderColor = color; }
120 
128  double rasterBorderWidth() const { return mRasterBorderWidth; }
129 
138  void setRasterBorderWidth( double width ) { mRasterBorderWidth = 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 mRasterSymbolBorder;
235  QColor mRasterBorderColor;
236  double mRasterBorderWidth;
237 
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.
QString wrapChar() const
void setWrapChar(const QString &t)
double boxSpace() const
void setEqualColumnWidth(bool s)
void setBoxSpace(double s)
void setMmPerMapUnit(double mmPerMapUnit)
double lineSpacing() const
QgsComposerLegendStyle & rstyle(QgsComposerLegendStyle::Style s)
Returns reference to modifiable style.
int columnCount() const
void setSymbolSize(QSizeF s)
double columnSpace() const
double mmPerMapUnit() const
QgsComposerLegendStyle style(QgsComposerLegendStyle::Style s) const
Returns style.
bool equalColumnWidth() const
void setStyle(QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle &style)
QColor fontColor() const
void setRasterBorderWidth(double width)
Sets the border width for the border drawn around raster symbol items.
QColor rasterBorderColor() const
Returns the border color for the border drawn around raster symbol items.
void setMapScale(double scale)
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
void setTitle(const QString &t)
void setDrawRasterBorder(bool enabled)
Sets whether a border will be drawn around raster symbol items.
void setDpi(int dpi)
void setFontColor(const QColor &c)
void setColumnSpace(double s)
Abstract base class for the legend item types.
void setLineSpacing(double s)
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
double mapScale() const
Composer legend components style.
void setWmsLegendSize(QSizeF s)
void setUseAdvancedEffects(bool use)
bool useAdvancedEffects() const
bool drawRasterBorder() const
Returns whether a border will be drawn around raster symbol items.
bool splitLayer() const
double rasterBorderWidth() const
Returns the border width (in millimeters) for the border drawn around raster symbol items...
void setColumnCount(int c)
QString title() const
QSizeF symbolSize() const
QSizeF wmsLegendSize() const
void setSplitLayer(bool s)
void setRasterBorderColor(const QColor &color)
Sets the border color for the border drawn around raster symbol items.