QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgslegendstyle.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslegendstyle.h
3  -------------------
4  begin : March 2013
5  copyright : (C) 2013 by Radim Blazek
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSLEGENDSTYLE_H
19 #define QGSLEGENDSTYLE_H
20 
21 #include <QFont>
22 #include <QMap>
23 #include <QString>
24 #include <QDomElement>
25 #include <QDomDocument>
26 
27 #include "qgis_core.h"
28 #include "qgis_sip.h"
29 #include "qgsreadwritecontext.h"
30 
35 class CORE_EXPORT QgsLegendStyle
36 {
37  public:
38 
40  enum Style
41  {
49  };
50 
51  // TODO QGIS 4.0 - use Qt enum instead
52 
54  enum Side
55  {
56  Top = 0,
57  Bottom = 1,
58  Left = 2,
59  Right = 3,
60  };
61 
63 
68  QFont font() const { return mFont; }
69 
74  void setFont( const QFont &font ) { mFont = font; }
75 
82  SIP_SKIP QFont &rfont() { return mFont; }
83 
91  double margin( Side side ) { return mMarginMap.value( side ); }
92 
100  void setMargin( Side side, double margin ) { mMarginMap[side] = margin; }
101 
106  void setMargin( double margin );
107 
114  Qt::Alignment alignment() const { return mAlignment; }
115 
122  void setAlignment( Qt::Alignment alignment ) { mAlignment = alignment; }
123 
128  void writeXml( const QString &name, QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
129 
134  void readXml( const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() );
135 
144  static QString styleName( Style s );
145 
150  static Style styleFromName( const QString &styleName );
151 
156  static QString styleLabel( Style s );
157 
158  private:
159  QFont mFont;
160  QMap<Side, double> mMarginMap;
161  Qt::Alignment mAlignment = Qt::AlignLeft;
162 };
163 
164 #endif
QgsLegendStyle::Symbol
@ Symbol
Symbol icon (excluding label)
Definition: qgslegendstyle.h:47
QgsLegendStyle::Style
Style
Component of legends which can be styled.
Definition: qgslegendstyle.h:41
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
qgsreadwritecontext.h
QgsLegendStyle::setFont
void setFont(const QFont &font)
Sets the font used for rendering this legend component.
Definition: qgslegendstyle.h:74
QgsLegendStyle::setMargin
void setMargin(Side side, double margin)
Sets the margin (in mm) for the specified side of the component.
Definition: qgslegendstyle.h:100
QgsLegendStyle::SymbolLabel
@ SymbolLabel
Symbol label (excluding icon)
Definition: qgslegendstyle.h:48
QgsLegendStyle::rfont
QFont & rfont()
Returns a modifiable reference to the component's font.
Definition: qgslegendstyle.h:82
QgsLegendStyle::Title
@ Title
Legend title.
Definition: qgslegendstyle.h:44
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsLegendStyle::Side
Side
Margin sides.
Definition: qgslegendstyle.h:55
QgsLegendStyle::Undefined
@ Undefined
Should not happen, only if corrupted project file.
Definition: qgslegendstyle.h:42
QgsLegendStyle::alignment
Qt::Alignment alignment() const
Returns the alignment for the legend component.
Definition: qgslegendstyle.h:114
qgis_sip.h
QgsLegendStyle::font
QFont font() const
Returns the font used for rendering this legend component.
Definition: qgslegendstyle.h:68
QgsLegendStyle::Hidden
@ Hidden
Special style, item is hidden including margins around.
Definition: qgslegendstyle.h:43
QgsLegendStyle::setAlignment
void setAlignment(Qt::Alignment alignment)
Sets the alignment for the legend component.
Definition: qgslegendstyle.h:122
QgsLegendStyle::Group
@ Group
Legend group title.
Definition: qgslegendstyle.h:45
QgsLegendStyle::Subgroup
@ Subgroup
Legend subgroup title.
Definition: qgslegendstyle.h:46
QgsLegendStyle
Contains detailed styling information relating to how a layout legend should be rendered.
Definition: qgslegendstyle.h:36
QgsLegendStyle::margin
double margin(Side side)
Returns the margin (in mm) for the specified side of the component.
Definition: qgslegendstyle.h:91