QGIS API Documentation  2.99.0-Master (314842d)
qgscomposerlabel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerlabel.h
3  -------------------
4  begin : January 2005
5  copyright : (C) 2005 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 #ifndef QGSCOMPOSERLABEL_H
18 #define QGSCOMPOSERLABEL_H
19 
20 #include "qgis_core.h"
21 #include "qgscomposeritem.h"
22 #include <QFont>
23 
24 class QgsVectorLayer;
25 class QgsFeature;
26 class QgsDistanceArea;
27 class QgsWebPage;
28 
32 class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
33 {
34  Q_OBJECT
35  public:
36  QgsComposerLabel( QgsComposition *composition );
38 
40  virtual int type() const override { return ComposerLabel; }
41 
43  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
44 
46  void adjustSizeToText();
47 
48  QString text() { return mText; }
49  void setText( const QString &text );
50 
51  int htmlState() { return mHtmlState; }
52  void setHtmlState( int state );
53 
55  QString displayText() const;
56 
57  QFont font() const;
58  void setFont( const QFont &f );
59 
63  Qt::AlignmentFlag vAlign() const { return mVAlignment; }
64 
68  Qt::AlignmentFlag hAlign() const { return mHAlignment; }
69 
74  void setHAlign( Qt::AlignmentFlag a ) {mHAlignment = a;}
75 
80  void setVAlign( Qt::AlignmentFlag a ) { mVAlignment = a; }
81 
87  double marginX() const { return mMarginX; }
88 
94  double marginY() const { return mMarginY; }
95 
104  void setMargin( const double m );
105 
113  void setMarginX( const double margin );
114 
122  void setMarginY( const double margin );
123 
125  void setFontColor( const QColor &c ) { mFontColor = c; }
127  QColor fontColor() const { return mFontColor; }
128 
133  bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
134 
139  bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;
140 
141  //Overridden to contain part of label's text
142  virtual QString displayName() const override;
143 
147  QRectF boundingRect() const override;
148 
151  virtual void setFrameEnabled( const bool drawFrame ) override;
152 
155  virtual void setFrameStrokeWidth( const double strokeWidth ) override;
156 
157  public slots:
158  void refreshExpressionContext();
159 
160 
161  private slots:
162  void loadingHtmlFinished( bool );
163 
164  private:
165  bool mFirstRender = true;
166 
167  // Text
168  QString mText;
169 
170  // Html state
171  int mHtmlState;
172  double mHtmlUnitsToMM;
173  double htmlUnitsToMM(); //calculate scale factor
174  bool mHtmlLoaded;
175 
177  void itemShiftAdjustSize( double newWidth, double newHeight, double &xShift, double &yShift ) const;
178 
180  void contentChanged();
181 
182  // Font
183  QFont mFont;
184 
186  double mMarginX;
188  double mMarginY;
189 
190  // Font color
191  QColor mFontColor;
192 
193  // Horizontal Alignment
194  Qt::AlignmentFlag mHAlignment;
195 
196  // Vertical Alignment
197  Qt::AlignmentFlag mVAlignment;
198 
200  void replaceDateText( QString &text ) const;
201 
203  QUrl createStylesheetUrl() const;
204 
205  QgsDistanceArea *mDistanceArea = nullptr;
206 
207  QgsWebPage *mWebPage = nullptr;
208 };
209 
210 #endif
virtual QString displayName() const
Get item display name.
virtual void setFrameStrokeWidth(const double strokeWidth)
Sets frame stroke width.
A item that forms part of a map composition.
QColor fontColor() const
Get font color.
virtual void setFrameEnabled(const bool drawFrame)
Set whether this item has a frame drawn around it or not.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:136
Qt::AlignmentFlag vAlign() const
Accessor for the vertical alignment of the label.
void setFontColor(const QColor &c)
Sets text color.
Qt::AlignmentFlag hAlign() const
Accessor for the horizontal alignment of the label.
virtual bool readXml(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
double marginX() const
Returns the horizontal margin between the edge of the frame and the label contents.
Graphics scene for map printing.
General purpose distance and area calculator.
virtual int type() const override
Return correct graphics item type.
void setVAlign(Qt::AlignmentFlag a)
Mutator for the vertical alignment of the label.
double marginY() const
Returns the vertical margin between the edge of the frame and the label contents. ...
A label that can be placed onto a map composition.
virtual bool writeXml(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
void setHAlign(Qt::AlignmentFlag a)
Mutator for the horizontal alignment of the label.
Represents a vector layer which manages a vector based data sets.
QWebPage subclass which redirects JavaScript errors and console output to the QGIS message log...
Definition: qgswebpage.h:208