QGIS API Documentation  2.99.0-Master (37c43df)
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; }
49 
54  void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
55 
59  QgsComposerLegendStyle style( QgsComposerLegendStyle::Style s ) const { return mStyleMap.value( s ); }
60  void setStyle( QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle& style ) { mStyleMap[s] = style; }
61 
62  double boxSpace() const {return mBoxSpace;}
63  void setBoxSpace( double s ) {mBoxSpace = s;}
64 
65  void setWrapChar( const QString& t ) {mWrapChar = t;}
66  QString wrapChar() const {return mWrapChar;}
67 
68  double columnSpace() const {return mColumnSpace;}
69  void setColumnSpace( double s ) { mColumnSpace = s;}
70 
71  int columnCount() const { return mColumnCount; }
72  void setColumnCount( int c ) { mColumnCount = c;}
73 
74  bool splitLayer() const { return mSplitLayer; }
75  void setSplitLayer( bool s ) { mSplitLayer = s;}
76 
77  bool equalColumnWidth() const { return mEqualColumnWidth; }
78  void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
79 
80  QColor fontColor() const {return mFontColor;}
81  void setFontColor( const QColor& c ) {mFontColor = c;}
82 
83  QSizeF symbolSize() const {return mSymbolSize;}
84  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
85 
92  bool drawRasterBorder() const { return mRasterSymbolBorder; }
93 
101  void setDrawRasterBorder( bool enabled ) { mRasterSymbolBorder = enabled; }
102 
110  QColor rasterBorderColor() const { return mRasterBorderColor; }
111 
120  void setRasterBorderColor( const QColor& color ) { mRasterBorderColor = color; }
121 
129  double rasterBorderWidth() const { return mRasterBorderWidth; }
130 
139  void setRasterBorderWidth( double width ) { mRasterBorderWidth = width; }
140 
141  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
142  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
143 
144  double lineSpacing() const { return mLineSpacing; }
145  void setLineSpacing( double s ) { mLineSpacing = s; }
146 
147  double mmPerMapUnit() const { return mMmPerMapUnit; }
148  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
149 
150  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
151  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
152 
153  double mapScale() const { return mMapScale; }
154  void setMapScale( double scale ) { mMapScale = scale; }
155 
156  int dpi() const { return mDpi; }
157  void setDpi( int dpi ) { mDpi = dpi; }
158 
159  // utility functions
160 
164  QStringList splitStringForWrapping( const QString& stringToSplt ) const;
165 
169  void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;
170 
180  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;
181 
183  QFont scaledFontPixelSize( const QFont& font ) const;
184 
186  double pixelFontSize( double pointSize ) const;
187 
189  double textWidthMillimeters( const QFont& font, const QString& text ) const;
190 
192  double fontHeightCharacterMM( const QFont& font, QChar c ) const;
193 
195  double fontAscentMillimeters( const QFont& font ) const;
196 
198  double fontDescentMillimeters( const QFont& font ) const;
199 
200  private:
201 
202  QString mTitle;
203 
205  Qt::AlignmentFlag mTitleAlignment;
206 
207  QString mWrapChar;
208 
209  QColor mFontColor;
210 
212  qreal mBoxSpace;
213 
215  QSizeF mSymbolSize;
216 
218  QSizeF mWmsLegendSize;
219 
221  double mLineSpacing;
222 
224  double mColumnSpace;
225 
227  int mColumnCount;
228 
230  bool mSplitLayer;
231 
233  bool mEqualColumnWidth;
234 
235  bool mRasterSymbolBorder;
236  QColor mRasterBorderColor;
237  double mRasterBorderWidth;
238 
239  QMap<QgsComposerLegendStyle::Style, QgsComposerLegendStyle> mStyleMap;
240 
242  double mMmPerMapUnit;
243 
245  bool mUseAdvancedEffects;
246 
248  double mMapScale;
249 
251  int mDpi;
252 };
253 
254 
255 
256 #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
QgsComposerLegendStyle & rstyle(QgsComposerLegendStyle::Style s)
Returns reference to modifiable style.
QString wrapChar() const
void setSymbolSize(QSizeF s)
double rasterBorderWidth() const
Returns the border width (in millimeters) for the border drawn around raster symbol items...
void setStyle(QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle &style)
QSizeF wmsLegendSize() const
void setRasterBorderWidth(double width)
Sets the border width 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...
QgsComposerLegendStyle style(QgsComposerLegendStyle::Style s) const
Returns style.
void setTitle(const QString &t)
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
void setDrawRasterBorder(bool enabled)
Sets whether a border will be drawn around raster symbol items.
void setDpi(int dpi)
double boxSpace() const
void setFontColor(const QColor &c)
void setColumnSpace(double s)
Abstract base class for the legend item types.
QSizeF symbolSize() const
void setLineSpacing(double s)
Composer legend components style.
void setWmsLegendSize(QSizeF s)
void setUseAdvancedEffects(bool use)
bool equalColumnWidth() const
void setColumnCount(int c)
double columnSpace() const
QColor rasterBorderColor() const
Returns the border color for the border drawn around raster symbol items.
double lineSpacing() const
QColor fontColor() const
bool drawRasterBorder() const
Returns whether a border will be drawn around raster symbol items.
bool splitLayer() const
double mmPerMapUnit() const
void setSplitLayer(bool s)
void setRasterBorderColor(const QColor &color)
Sets the border color for the border drawn around raster symbol items.
QString title() const