QGIS API Documentation  2.99.0-Master (8ec3eaf)
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 "qgscomposeritem.h"
21 #include <QFont>
22 
23 class QgsVectorLayer;
24 class QgsFeature;
25 class QgsDistanceArea;
26 class QgsWebPage;
27 
31 class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
32 {
33  Q_OBJECT
34  public:
35  QgsComposerLabel( QgsComposition *composition );
37 
39  virtual int type() const override { return ComposerLabel; }
40 
42  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
43 
45  void adjustSizeToText();
46 
47  QString text() { return mText; }
48  void setText( const QString& text );
49 
50  int htmlState() { return mHtmlState; }
51  void setHtmlState( int state );
52 
54  QString displayText() const;
55 
56  QFont font() const;
57  void setFont( const QFont& f );
58 
62  Qt::AlignmentFlag vAlign() const { return mVAlignment; }
63 
67  Qt::AlignmentFlag hAlign() const { return mHAlignment; }
68 
73  void setHAlign( Qt::AlignmentFlag a ) {mHAlignment = a;}
74 
79  void setVAlign( Qt::AlignmentFlag a ) { mVAlignment = a; }
80 
86  double marginX() const { return mMarginX; }
87 
93  double marginY() const { return mMarginY; }
94 
103  void setMargin( const double m );
104 
112  void setMarginX( const double margin );
113 
121  void setMarginY( const double margin );
122 
124  void setFontColor( const QColor& c ) { mFontColor = c; }
126  QColor fontColor() const { return mFontColor; }
127 
132  bool writeXml( QDomElement& elem, QDomDocument & doc ) const override;
133 
138  bool readXml( const QDomElement& itemElem, const QDomDocument& doc ) override;
139 
140  //Overridden to contain part of label's text
141  virtual QString displayName() const override;
142 
146  QRectF boundingRect() const override;
147 
150  virtual void setFrameEnabled( const bool drawFrame ) override;
151 
154  virtual void setFrameOutlineWidth( const double outlineWidth ) override;
155 
156  public slots:
157  void refreshExpressionContext();
158 
159 
160  private slots:
161  void loadingHtmlFinished( bool );
162 
163  private:
164  // Text
165  QString mText;
166 
167  // Html state
168  int mHtmlState;
169  double mHtmlUnitsToMM;
170  double htmlUnitsToMM(); //calculate scale factor
171  bool mHtmlLoaded;
172 
174  void itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const;
175 
177  void contentChanged();
178 
179  // Font
180  QFont mFont;
181 
183  double mMarginX;
185  double mMarginY;
186 
187  // Font color
188  QColor mFontColor;
189 
190  // Horizontal Alignment
191  Qt::AlignmentFlag mHAlignment;
192 
193  // Vertical Alignment
194  Qt::AlignmentFlag mVAlignment;
195 
197  void replaceDateText( QString& text ) const;
198 
200  QUrl createStylesheetUrl() const;
201 
202  QScopedPointer<QgsFeature> mExpressionFeature;
203  QgsVectorLayer* mExpressionLayer;
204  QgsDistanceArea* mDistanceArea;
205 
206  QgsWebPage* mWebPage;
207 };
208 
209 #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:135
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:207