QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  int splitLayer() const { return mSplitLayer; }
74  void setSplitLayer( bool s ) { mSplitLayer = s;}
75 
76  int 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 
85  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
86  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
87 
88  double lineSpacing() const { return mLineSpacing; }
89  void setLineSpacing( double s ) { mLineSpacing = s; }
90 
91  double mmPerMapUnit() const { return mMmPerMapUnit; }
92  void setMmPerMapUnit( double mmPerMapUnit ) { mMmPerMapUnit = mmPerMapUnit; }
93 
94  bool useAdvancedEffects() const { return mUseAdvancedEffects; }
95  void setUseAdvancedEffects( bool use ) { mUseAdvancedEffects = use; }
96 
97  double mapScale() const { return mMapScale; }
98  void setMapScale( double scale ) { mMapScale = scale; }
99 
100  int dpi() const { return mDpi; }
101  void setDpi( int dpi ) { mDpi = dpi; }
102 
103  // utility functions
104 
107  QStringList splitStringForWrapping( QString stringToSplt ) const;
108 
111  void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;
112 
122  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;
123 
125  QFont scaledFontPixelSize( const QFont& font ) const;
126 
128  double pixelFontSize( double pointSize ) const;
129 
131  double textWidthMillimeters( const QFont& font, const QString& text ) const;
132 
134  double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
135 
137  double fontAscentMillimeters( const QFont& font ) const;
138 
140  double fontDescentMillimeters( const QFont& font ) const;
141 
142  private:
143 
144  QString mTitle;
145 
147  Qt::AlignmentFlag mTitleAlignment;
148 
149  QString mWrapChar;
150 
151  QColor mFontColor;
152 
154  qreal mBoxSpace;
155 
157  QSizeF mSymbolSize;
158 
160  QSizeF mWmsLegendSize;
161 
163  double mLineSpacing;
164 
166  double mColumnSpace;
167 
169  int mColumnCount;
170 
172  bool mSplitLayer;
173 
175  bool mEqualColumnWidth;
176 
177  QMap<QgsComposerLegendStyle::Style, QgsComposerLegendStyle> mStyleMap;
178 
180  double mMmPerMapUnit;
181 
183  bool mUseAdvancedEffects;
184 
186  double mMapScale;
187 
189  int mDpi;
190 };
191 
192 
193 
194 #endif // QGSLEGENDSETTINGS_H