QGIS API Documentation  2.99.0-Master (cd0ba91)
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 
33 class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
34 {
35  Q_OBJECT
36  public:
39 
41  virtual int type() const override { return ComposerLabel; }
42 
44  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
45 
47  void adjustSizeToText();
48 
49  QString text() { return mText; }
50  void setText( const QString &text );
51 
52  int htmlState() { return mHtmlState; }
53  void setHtmlState( int state );
54 
56  QString displayText() const;
57 
58  QFont font() const;
59  void setFont( const QFont &f );
60 
65  Qt::AlignmentFlag vAlign() const { return mVAlignment; }
66 
71  Qt::AlignmentFlag hAlign() const { return mHAlignment; }
72 
78  void setHAlign( Qt::AlignmentFlag a ) { mHAlignment = a; }
79 
85  void setVAlign( Qt::AlignmentFlag a ) { mVAlignment = a; }
86 
93  double marginX() const { return mMarginX; }
94 
101  double marginY() const { return mMarginY; }
102 
112  void setMargin( const double m );
113 
122  void setMarginX( const double margin );
123 
132  void setMarginY( const double margin );
133 
135  void setFontColor( const QColor &c ) { mFontColor = c; }
137  QColor fontColor() const { return mFontColor; }
138 
144  bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
145 
151  bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;
152 
153  //Overridden to contain part of label's text
154  virtual QString displayName() const override;
155 
160  QRectF boundingRect() const override;
161 
165  virtual void setFrameEnabled( const bool drawFrame ) override;
166 
170  virtual void setFrameStrokeWidth( const double strokeWidth ) override;
171 
172  public slots:
173 
174  void refreshExpressionContext();
175 
176 
177  private slots:
178  void loadingHtmlFinished( bool );
179 
180  private:
181  bool mFirstRender = true;
182 
183  // Text
184  QString mText;
185 
186  // Html state
187  int mHtmlState;
188  double mHtmlUnitsToMM;
189  double htmlUnitsToMM(); //calculate scale factor
190  bool mHtmlLoaded;
191 
193  void itemShiftAdjustSize( double newWidth, double newHeight, double &xShift, double &yShift ) const;
194 
196  void contentChanged();
197 
198  // Font
199  QFont mFont;
200 
202  double mMarginX;
204  double mMarginY;
205 
206  // Font color
207  QColor mFontColor;
208 
209  // Horizontal Alignment
210  Qt::AlignmentFlag mHAlignment;
211 
212  // Vertical Alignment
213  Qt::AlignmentFlag mVAlignment;
214 
216  void replaceDateText( QString &text ) const;
217 
219  QUrl createStylesheetUrl() const;
220 
221  QgsDistanceArea *mDistanceArea = nullptr;
222 
223  QgsWebPage *mWebPage = nullptr;
224 };
225 
226 #endif
virtual QString displayName() const
Get item display name.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
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:62
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.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
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:216