QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
59  Q_DECL_DEPRECATED void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, const QMap<QString, QVariant>& substitutions = ( QMap<QString, QVariant>() ) );
60 
64  void setSubstitutions( const QMap<QString, QVariant>& substitutions = ( QMap<QString, QVariant>() ) );
65 
66  QFont font() const;
67  void setFont( const QFont& f );
71  Qt::AlignmentFlag vAlign() const { return mVAlignment; }
75  Qt::AlignmentFlag hAlign() const { return mHAlignment; }
80  void setHAlign( Qt::AlignmentFlag a ) {mHAlignment = a;}
85  void setVAlign( Qt::AlignmentFlag a ) { mVAlignment = a; }
86 
91  Q_DECL_DEPRECATED double margin() { return mMarginX; }
92 
98  double marginX() const { return mMarginX; }
99 
105  double marginY() const { return mMarginY; }
106 
115  void setMargin( const double m );
116 
124  void setMarginX( const double margin );
125 
133  void setMarginY( const double margin );
134 
136  void setFontColor( const QColor& c ) { mFontColor = c; }
138  QColor fontColor() const { return mFontColor; }
139 
144  bool writeXML( QDomElement& elem, QDomDocument & doc ) const override;
145 
150  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
151 
152  //Overridden to contain part of label's text
153  virtual QString displayName() const override;
154 
158  QRectF boundingRect() const override;
159 
162  virtual void setFrameEnabled( const bool drawFrame ) override;
163 
166  virtual void setFrameOutlineWidth( const double outlineWidth ) override;
167 
168  public slots:
169  void refreshExpressionContext();
170 
171 
172  private slots:
173  void loadingHtmlFinished( bool );
174 
175  private:
176  // Text
177  QString mText;
178 
179  // Html state
180  int mHtmlState;
181  double mHtmlUnitsToMM;
182  double htmlUnitsToMM(); //calculate scale factor
183  bool mHtmlLoaded;
184 
186  void itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const;
187 
189  void contentChanged();
190 
191  // Font
192  QFont mFont;
193 
195  double mMarginX;
197  double mMarginY;
198 
199  // Font color
200  QColor mFontColor;
201 
202  // Horizontal Alignment
203  Qt::AlignmentFlag mHAlignment;
204 
205  // Vertical Alignment
206  Qt::AlignmentFlag mVAlignment;
207 
209  void replaceDateText( QString& text ) const;
210 
212  QUrl createStylesheetUrl() const;
213 
214  QScopedPointer<QgsFeature> mExpressionFeature;
215  QgsVectorLayer* mExpressionLayer;
216  QMap<QString, QVariant> mSubstitutions;
217  QgsDistanceArea* mDistanceArea;
218 
219  QgsWebPage* mWebPage;
220 };
221 
222 #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.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
Qt::AlignmentFlag vAlign() const
Accessor for the vertical alignment of the label.
void setFontColor(const QColor &c)
Sets text color.
virtual QRectF boundingRect() const
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Qt::AlignmentFlag hAlign() const
Accessor for the horizontal alignment of the label.
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 bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
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. ...
Q_DECL_DEPRECATED double margin()
Returns the margin between the edge of the frame and the label contents.
A label that can be placed onto a map composition.
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:211