QGIS API Documentation  2.99.0-Master (ae4d26a)
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  void refreshExpressionContext();
174 
175 
176  private slots:
177  void loadingHtmlFinished( bool );
178 
179  private:
180  bool mFirstRender = true;
181 
182  // Text
183  QString mText;
184 
185  // Html state
186  int mHtmlState;
187  double mHtmlUnitsToMM;
188  double htmlUnitsToMM(); //calculate scale factor
189  bool mHtmlLoaded;
190 
192  void itemShiftAdjustSize( double newWidth, double newHeight, double &xShift, double &yShift ) const;
193 
195  void contentChanged();
196 
197  // Font
198  QFont mFont;
199 
201  double mMarginX;
203  double mMarginY;
204 
205  // Font color
206  QColor mFontColor;
207 
208  // Horizontal Alignment
209  Qt::AlignmentFlag mHAlignment;
210 
211  // Vertical Alignment
212  Qt::AlignmentFlag mVAlignment;
213 
215  void replaceDateText( QString &text ) const;
216 
218  QUrl createStylesheetUrl() const;
219 
220  QgsDistanceArea *mDistanceArea = nullptr;
221 
222  QgsWebPage *mWebPage = nullptr;
223 };
224 
225 #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