QGIS API Documentation  2.13.0-Master
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 
162  QStringList splitStringForWrapping( const QString& stringToSplt ) const;
163 
166  void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;
167 
177  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;
178 
180  QFont scaledFontPixelSize( const QFont& font ) const;
181 
183  double pixelFontSize( double pointSize ) const;
184 
186  double textWidthMillimeters( const QFont& font, const QString& text ) const;
187 
189  double fontHeightCharacterMM( const QFont& font, QChar c ) const;
190 
192  double fontAscentMillimeters( const QFont& font ) const;
193 
195  double fontDescentMillimeters( const QFont& font ) const;
196 
197  private:
198 
199  QString mTitle;
200 
202  Qt::AlignmentFlag mTitleAlignment;
203 
204  QString mWrapChar;
205 
206  QColor mFontColor;
207 
209  qreal mBoxSpace;
210 
212  QSizeF mSymbolSize;
213 
215  QSizeF mWmsLegendSize;
216 
218  double mLineSpacing;
219 
221  double mColumnSpace;
222 
224  int mColumnCount;
225 
227  bool mSplitLayer;
228 
230  bool mEqualColumnWidth;
231 
232  bool mRasterSymbolBorder;
233  QColor mRasterBorderColor;
234  double mRasterBorderWidth;
235 
237 
239  double mMmPerMapUnit;
240 
242  bool mUseAdvancedEffects;
243 
245  double mMapScale;
246 
248  int mDpi;
249 };
250 
251 
252 
253 #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.