QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 
243  double maximumSymbolSize() const {return mMaxSymbolSize; }
244 
253  void setMaximumSymbolSize( double size ) { mMaxSymbolSize = size;}
254 
261  double minimumSymbolSize() const {return mMinSymbolSize; }
262 
271  void setMinimumSymbolSize( double size ) { mMinSymbolSize = size;}
272 
281  void setSymbolAlignment( Qt::AlignmentFlag alignment ) { mSymbolAlignment = alignment; }
282 
291  Qt::AlignmentFlag symbolAlignment() const { return mSymbolAlignment; }
292 
300  bool drawRasterStroke() const { return mRasterSymbolStroke; }
301 
310  void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
311 
320  QColor rasterStrokeColor() const { return mRasterStrokeColor; }
321 
331  void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
332 
341  double rasterStrokeWidth() const { return mRasterStrokeWidth; }
342 
352  void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
353 
359  QSizeF wmsLegendSize() const {return mWmsLegendSize;}
360 
366  void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
367 
373  double lineSpacing() const { return mLineSpacing; }
374 
380  void setLineSpacing( double s ) { mLineSpacing = s; }
381 
385  Q_DECL_DEPRECATED double mmPerMapUnit() const SIP_DEPRECATED;
386 
390  Q_DECL_DEPRECATED void setMmPerMapUnit( double mmPerMapUnit ) SIP_DEPRECATED;
391 
395  Q_DECL_DEPRECATED bool useAdvancedEffects() const SIP_DEPRECATED;
396 
400  Q_DECL_DEPRECATED void setUseAdvancedEffects( bool use ) SIP_DEPRECATED;
401 
408  Q_DECL_DEPRECATED double mapScale() const SIP_DEPRECATED;
409 
416  Q_DECL_DEPRECATED void setMapScale( double scale ) SIP_DEPRECATED;
417 
423  Q_DECL_DEPRECATED double mapUnitsPerPixel() const SIP_DEPRECATED;
424 
430  Q_DECL_DEPRECATED void setMapUnitsPerPixel( double mapUnitsPerPixel ) SIP_DEPRECATED;
431 
435  Q_DECL_DEPRECATED int dpi() const SIP_DEPRECATED;
436 
440  Q_DECL_DEPRECATED void setDpi( int dpi ) SIP_DEPRECATED;
441 
442 // utility functions
443 
457  QStringList evaluateItemText( const QString &text, const QgsExpressionContext &context ) const;
458 
463  QStringList splitStringForWrapping( const QString &stringToSplt ) const;
464 
469  void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
470 
481  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;
482 
484  QFont scaledFontPixelSize( const QFont &font ) const;
485 
487  double pixelFontSize( double pointSize ) const;
488 
490  double textWidthMillimeters( const QFont &font, const QString &text ) const;
491 
493  double fontHeightCharacterMM( const QFont &font, QChar c ) const;
494 
496  double fontAscentMillimeters( const QFont &font ) const;
497 
499  double fontDescentMillimeters( const QFont &font ) const;
500 
501  private:
502 
503  QString mTitle;
504 
506  Qt::AlignmentFlag mTitleAlignment = Qt::AlignLeft;
507 
508  QString mWrapChar;
509 
510  QColor mFontColor;
511 
513  qreal mBoxSpace = 2;
514 
516  QSizeF mSymbolSize;
517 
519  double mMaxSymbolSize = 0.0;
520 
522  double mMinSymbolSize = 0.0;
523 
525  QSizeF mWmsLegendSize;
526 
528  double mLineSpacing = 1;
529 
531  double mColumnSpace = 2;
532 
534  int mColumnCount = 1;
535 
537  bool mSplitLayer = false;
538 
540  bool mEqualColumnWidth = false;
541 
542  bool mRasterSymbolStroke = true;
543  QColor mRasterStrokeColor;
544  double mRasterStrokeWidth = 0.0;
545 
546  QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap;
547 
549  double mMmPerMapUnit = 1;
550 
552  bool mUseAdvancedEffects = true;
553 
555  double mMapScale = 1;
556 
558  int mDpi = 96;
559 
561  QColor mLayerFontColor;
562 
564  Qt::AlignmentFlag mSymbolAlignment = Qt::AlignLeft;
565 };
566 
567 
568 
569 #endif // QGSLEGENDSETTINGS_H
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
int columnCount() const
Returns the desired minimum number of columns to show in the legend.
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
QString wrapChar() const
Returns the string used as a wrapping character.
void setFontColor(const QColor &c)
Sets the font color used for legend items.
void setWrapChar(const QString &t)
Sets a string to use as a wrapping character.
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
QColor layerFontColor() const
Returns layer font color, defaults to fontColor()
void setStyle(QgsLegendStyle::Style s, const QgsLegendStyle &style)
Sets the style for a legend component.
void setColumnSpace(double s)
Sets the margin space between adjacent columns (in millimeters).
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns the style for a legend component.
void setLayerFontColor(const QColor &fontColor)
Sets layer font color to fontColor Overrides fontColor()
void setTitle(const QString &t)
Sets the title for the legend, which will be rendered above all legend items.
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
QSizeF wmsLegendSize() const
Returns the size (in millimeters) of WMS legend graphics shown in the legend.
double minimumSymbolSize() const
Returns the minimum symbol size (in mm).
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.
void setLineSpacing(double s)
Sets the line spacing to use between lines of legend text.
void setColumnCount(int c)
Sets the desired minimum number of columns to show in the legend.
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns modifiable reference to the style for a legend component.
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
QSizeF symbolSize() const
Returns the default symbol size (in millimeters) used for legend items.
QColor fontColor() const
Returns the font color used for legend items.
double maximumSymbolSize() const
Returns the maximum symbol size (in mm).
QString title() const
Returns the title for the legend, which will be rendered above all legend items.
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
void setSplitLayer(bool s)
Sets whether layer components can be split over multiple columns.
double columnSpace() const
Returns the margin space between adjacent columns (in millimeters).
void setEqualColumnWidth(bool s)
Sets whether all columns should have equal widths.
void setBoxSpace(double s)
Sets the legend box space (in millimeters), which is the empty margin around the inside of the legend...
double boxSpace() const
Returns the legend box space (in millimeters), which is the empty margin around the inside of the leg...
void setMaximumSymbolSize(double size)
Set the maximum symbol size for symbol (in millimeters).
double lineSpacing() const
Returns the line spacing to use between lines of legend text.
bool splitLayer() const
Returns true if layer components can be split over multiple columns.
void setMinimumSymbolSize(double size)
Set the minimum symbol size for symbol (in millimeters).
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
bool equalColumnWidth() const
Returns true if all columns should have equal widths.
void setSymbolSize(QSizeF s)
Sets the default symbol size (in millimeters) used for legend items.
void setWmsLegendSize(QSizeF s)
Sets the desired size (in millimeters) of WMS legend graphics shown in the legend.
Contains detailed styling information relating to how a layout legend should be rendered.
Style
Component of legends which can be styled.
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
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_SKIP
Definition: qgis_sip.h:126