QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 "qgis_sip.h"
21 #include <QColor>
22 #include <QSizeF>
23 
24 class QRectF;
25 
26 #include "qgslegendstyle.h"
27 
29 
38 class CORE_EXPORT QgsLegendSettings
39 {
40  public:
42 
48  void setTitle( const QString &t ) { mTitle = t; }
49 
55  QString title() const { return mTitle; }
56 
61  Qt::AlignmentFlag titleAlignment() const { return mTitleAlignment; }
62 
67  void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
68 
75 
81  QgsLegendStyle style( QgsLegendStyle::Style s ) const { return mStyleMap.value( s ); }
82 
88  void setStyle( QgsLegendStyle::Style s, const QgsLegendStyle &style ) { mStyleMap[s] = style; }
89 
96  double boxSpace() const {return mBoxSpace;}
97 
104  void setBoxSpace( double s ) {mBoxSpace = s;}
105 
114  void setWrapChar( const QString &t ) {mWrapChar = t;}
115 
124  QString wrapChar() const {return mWrapChar;}
125 
131  double columnSpace() const {return mColumnSpace;}
132 
138  void setColumnSpace( double s ) { mColumnSpace = s;}
139 
148  int columnCount() const { return mColumnCount; }
149 
158  void setColumnCount( int c ) { mColumnCount = c;}
159 
165  bool splitLayer() const { return mSplitLayer; }
166 
172  void setSplitLayer( bool s ) { mSplitLayer = s;}
173 
181  bool equalColumnWidth() const { return mEqualColumnWidth; }
182 
190  void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
191 
197  QColor fontColor() const {return mFontColor;}
198 
204  void setFontColor( const QColor &c ) {mFontColor = c;}
205 
212  QColor layerFontColor() const {return mLayerFontColor.isValid() ? mLayerFontColor : fontColor() ;}
213 
221  void setLayerFontColor( const QColor &fontColor ) {mLayerFontColor = fontColor;}
222 
228  QSizeF symbolSize() const {return mSymbolSize;}
229 
235  void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
236 
245  void setSymbolAlignment( Qt::AlignmentFlag alignment ) { mSymbolAlignment = alignment; }
246 
255  Qt::AlignmentFlag symbolAlignment() const { return mSymbolAlignment; }
256 
264  bool drawRasterStroke() const { return mRasterSymbolStroke; }
265 
274  void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
275 
284  QColor rasterStrokeColor() const { return mRasterStrokeColor; }
285 
295  void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
296 
305  double rasterStrokeWidth() const { return mRasterStrokeWidth; }
306 
316  void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
317 
323  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
324 
330  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
331 
337  double lineSpacing() const { return mLineSpacing; }
338 
344  void setLineSpacing( double s ) { mLineSpacing = s; }
345 
349  Q_DECL_DEPRECATED double mmPerMapUnit() const SIP_DEPRECATED;
350 
354  Q_DECL_DEPRECATED void setMmPerMapUnit( double mmPerMapUnit ) SIP_DEPRECATED;
355 
359  Q_DECL_DEPRECATED bool useAdvancedEffects() const SIP_DEPRECATED;
360 
364  Q_DECL_DEPRECATED void setUseAdvancedEffects( bool use ) SIP_DEPRECATED;
365 
372  Q_DECL_DEPRECATED double mapScale() const SIP_DEPRECATED;
373 
380  Q_DECL_DEPRECATED void setMapScale( double scale ) SIP_DEPRECATED;
381 
387  Q_DECL_DEPRECATED double mapUnitsPerPixel() const SIP_DEPRECATED;
388 
394  Q_DECL_DEPRECATED void setMapUnitsPerPixel( double mapUnitsPerPixel ) SIP_DEPRECATED;
395 
399  Q_DECL_DEPRECATED int dpi() const SIP_DEPRECATED;
400 
404  Q_DECL_DEPRECATED void setDpi( int dpi ) SIP_DEPRECATED;
405 
406 // utility functions
407 
421  QStringList evaluateItemText( const QString &text, const QgsExpressionContext &context ) const;
422 
427  QStringList splitStringForWrapping( const QString &stringToSplt ) const;
428 
433  void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
434 
445  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;
446 
448  QFont scaledFontPixelSize( const QFont &font ) const;
449 
451  double pixelFontSize( double pointSize ) const;
452 
454  double textWidthMillimeters( const QFont &font, const QString &text ) const;
455 
457  double fontHeightCharacterMM( const QFont &font, QChar c ) const;
458 
460  double fontAscentMillimeters( const QFont &font ) const;
461 
463  double fontDescentMillimeters( const QFont &font ) const;
464 
465  private:
466 
467  QString mTitle;
468 
470  Qt::AlignmentFlag mTitleAlignment = Qt::AlignLeft;
471 
472  QString mWrapChar;
473 
474  QColor mFontColor;
475 
477  qreal mBoxSpace = 2;
478 
480  QSizeF mSymbolSize;
481 
483  QSizeF mWmsLegendSize;
484 
486  double mLineSpacing = 1;
487 
489  double mColumnSpace = 2;
490 
492  int mColumnCount = 1;
493 
495  bool mSplitLayer = false;
496 
498  bool mEqualColumnWidth = false;
499 
500  bool mRasterSymbolStroke = true;
501  QColor mRasterStrokeColor;
502  double mRasterStrokeWidth = 0.0;
503 
504  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
505 
507  double mMmPerMapUnit = 1;
508 
510  bool mUseAdvancedEffects = true;
511 
513  double mMapScale = 1;
514 
516  int mDpi = 96;
517 
519  QColor mLayerFontColor;
520 
522  Qt::AlignmentFlag mSymbolAlignment = Qt::AlignLeft;
523 };
524 
525 
526 
527 #endif // QGSLEGENDSETTINGS_H
QgsLegendSettings::setSymbolAlignment
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
Definition: qgslegendsettings.h:245
QgsLegendSettings::setEqualColumnWidth
void setEqualColumnWidth(bool s)
Sets whether all columns should have equal widths.
Definition: qgslegendsettings.h:190
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsLegendSettings::symbolAlignment
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
Definition: qgslegendsettings.h:255
QgsLegendSettings::title
QString title() const
Returns the title for the legend, which will be rendered above all legend items.
Definition: qgslegendsettings.h:55
QgsLegendStyle::Style
Style
Component of legends which can be styled.
Definition: qgslegendstyle.h:53
QgsLegendSettings::setTitleAlignment
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
Definition: qgslegendsettings.h:67
QgsLegendSettings::columnCount
int columnCount() const
Returns the desired minimum number of columns to show in the legend.
Definition: qgslegendsettings.h:148
QgsLegendSettings::layerFontColor
QColor layerFontColor() const
Returns layer font color, defaults to fontColor()
Definition: qgslegendsettings.h:212
QgsLegendSettings::setSymbolSize
void setSymbolSize(QSizeF s)
Sets the default symbol size (in millimeters) used for legend items.
Definition: qgslegendsettings.h:235
QgsLegendSettings::setSplitLayer
void setSplitLayer(bool s)
Sets whether layer components can be split over multiple columns.
Definition: qgslegendsettings.h:172
QgsLegendSettings::style
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns the style for a legend component.
Definition: qgslegendsettings.h:81
QgsLegendSettings::setBoxSpace
void setBoxSpace(double s)
Sets the legend box space (in millimeters), which is the empty margin around the inside of the legend...
Definition: qgslegendsettings.h:104
QgsLegendSettings::rasterStrokeColor
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
Definition: qgslegendsettings.h:284
QgsLegendSettings::drawRasterStroke
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
Definition: qgslegendsettings.h:264
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsLegendSettings::rasterStrokeWidth
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.
Definition: qgslegendsettings.h:305
QgsLegendSettings::setTitle
void setTitle(const QString &t)
Sets the title for the legend, which will be rendered above all legend items.
Definition: qgslegendsettings.h:48
QgsLegendSettings::setRasterStrokeWidth
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
Definition: qgslegendsettings.h:316
QgsLegendSettings::boxSpace
double boxSpace() const
Returns the legend box space (in millimeters), which is the empty margin around the inside of the leg...
Definition: qgslegendsettings.h:96
qgis_sip.h
QgsLegendSettings::setColumnSpace
void setColumnSpace(double s)
Sets the margin space between adjacent columns (in millimeters).
Definition: qgslegendsettings.h:138
QgsLegendSettings::wmsLegendSize
QSizeF wmsLegendSize() const
Returns the size (in millimeters) of WMS legend graphics shown in the legend.
Definition: qgslegendsettings.h:323
QgsLegendSettings
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Definition: qgslegendsettings.h:38
QgsLegendSettings::titleAlignment
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
Definition: qgslegendsettings.h:61
QgsLegendSettings::setLineSpacing
void setLineSpacing(double s)
Sets the line spacing to use between lines of legend text.
Definition: qgslegendsettings.h:344
QgsLegendSettings::setDrawRasterStroke
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
Definition: qgslegendsettings.h:274
QgsLegendSettings::setStyle
void setStyle(QgsLegendStyle::Style s, const QgsLegendStyle &style)
Sets the style for a legend component.
Definition: qgslegendsettings.h:88
qgslegendstyle.h
QgsLegendSettings::setFontColor
void setFontColor(const QColor &c)
Sets the font color used for legend items.
Definition: qgslegendsettings.h:204
QgsLegendSettings::setColumnCount
void setColumnCount(int c)
Sets the desired minimum number of columns to show in the legend.
Definition: qgslegendsettings.h:158
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsLegendSettings::splitLayer
bool splitLayer() const
Returns true if layer components can be split over multiple columns.
Definition: qgslegendsettings.h:165
QgsLegendSettings::symbolSize
QSizeF symbolSize() const
Returns the default symbol size (in millimeters) used for legend items.
Definition: qgslegendsettings.h:228
QgsLegendSettings::equalColumnWidth
bool equalColumnWidth() const
Returns true if all columns should have equal widths.
Definition: qgslegendsettings.h:181
QgsLegendSettings::setLayerFontColor
void setLayerFontColor(const QColor &fontColor)
Sets layer font color to fontColor Overrides fontColor()
Definition: qgslegendsettings.h:221
QgsLegendSettings::setWmsLegendSize
void setWmsLegendSize(QSizeF s)
Sets the desired size (in millimeters) of WMS legend graphics shown in the legend.
Definition: qgslegendsettings.h:330
QgsLegendSettings::fontColor
QColor fontColor() const
Returns the font color used for legend items.
Definition: qgslegendsettings.h:197
QgsLegendSettings::lineSpacing
double lineSpacing() const
Returns the line spacing to use between lines of legend text.
Definition: qgslegendsettings.h:337
QgsLegendSettings::rstyle
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns modifiable reference to the style for a legend component.
Definition: qgslegendsettings.h:74
QgsLegendSettings::setRasterStrokeColor
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
Definition: qgslegendsettings.h:295
QgsLegendSettings::columnSpace
double columnSpace() const
Returns the margin space between adjacent columns (in millimeters).
Definition: qgslegendsettings.h:131
QgsLegendSettings::setWrapChar
void setWrapChar(const QString &t)
Sets a string to use as a wrapping character.
Definition: qgslegendsettings.h:114
QgsLegendSettings::wrapChar
QString wrapChar() const
Returns the string used as a wrapping character.
Definition: qgslegendsettings.h:124
QgsLegendStyle
Definition: qgslegendstyle.h:35