QGIS API Documentation  2.99.0-Master (0a63d1f)
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 setFrameOutlineWidth( const double outlineWidth ) override;
156 
157  public slots:
158  void refreshExpressionContext();
159 
160 
161  private slots:
162  void loadingHtmlFinished( bool );
163 
164  private:
165  // Text
166  QString mText;
167 
168  // Html state
169  int mHtmlState;
170  double mHtmlUnitsToMM;
171  double htmlUnitsToMM(); //calculate scale factor
172  bool mHtmlLoaded;
173 
175  void itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const;
176 
178  void contentChanged();
179 
180  // Font
181  QFont mFont;
182 
184  double mMarginX;
186  double mMarginY;
187 
188  // Font color
189  QColor mFontColor;
190 
191  // Horizontal Alignment
192  Qt::AlignmentFlag mHAlignment;
193 
194  // Vertical Alignment
195  Qt::AlignmentFlag mVAlignment;
196 
198  void replaceDateText( QString& text ) const;
199 
201  QUrl createStylesheetUrl() const;
202 
203  QScopedPointer<QgsFeature> mExpressionFeature;
204  QgsVectorLayer* mExpressionLayer;
205  QgsDistanceArea* mDistanceArea;
206 
207  QgsWebPage* mWebPage;
208 };
209 
210 #endif
virtual QString displayName() const
Get item display name.
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.
virtual void setFrameOutlineWidth(const double outlineWidth)
Sets frame outline width.
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