QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
30 class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
31 {
32  Q_OBJECT
33  public:
34  QgsComposerLabel( QgsComposition *composition );
36 
38  virtual int type() const override { return ComposerLabel; }
39 
41  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
42 
44  void adjustSizeToText();
45 
46  QString text() { return mText; }
47  void setText( const QString& text );
48 
49  int htmlState() { return mHtmlState; }
50  void setHtmlState( int state );
51 
53  QString displayText() const;
54 
56  void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, QMap<QString, QVariant> substitutions = ( QMap<QString, QVariant>() ) );
57 
58  QFont font() const;
59  void setFont( const QFont& f );
63  Qt::AlignmentFlag vAlign() const { return mVAlignment; }
67  Qt::AlignmentFlag hAlign() const { return mHAlignment; }
72  void setHAlign( Qt::AlignmentFlag a ) {mHAlignment = a;}
77  void setVAlign( Qt::AlignmentFlag a ) { mVAlignment = a; }
78 
83  Q_DECL_DEPRECATED double margin() { return mMarginX; }
84 
90  double marginX() const { return mMarginX; }
91 
97  double marginY() const { return mMarginY; }
98 
107  void setMargin( const double m );
108 
116  void setMarginX( const double margin );
117 
125  void setMarginY( const double margin );
126 
128  void setFontColor( const QColor& c ) { mFontColor = c; }
130  QColor fontColor() const { return mFontColor; }
131 
136  bool writeXML( QDomElement& elem, QDomDocument & doc ) const override;
137 
142  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
143 
144  //Overriden to contain part of label's text
145  virtual QString displayName() const override;
146 
150  QRectF boundingRect() const override;
151 
154  virtual void setFrameEnabled( const bool drawFrame ) override;
155 
158  virtual void setFrameOutlineWidth( const double outlineWidth ) override;
159 
160  public slots:
161  void refreshExpressionContext();
162 
163 
164  private slots:
165  void loadingHtmlFinished( bool );
166 
167  private:
168  // Text
169  QString mText;
170 
171  // Html state
172  int mHtmlState;
173  double mHtmlUnitsToMM;
174  double htmlUnitsToMM(); //calculate scale factor
175  bool mHtmlLoaded;
176 
178  void itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const;
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 
200  QgsFeature* mExpressionFeature;
201  QgsVectorLayer* mExpressionLayer;
202  QMap<QString, QVariant> mSubstitutions;
203  QgsDistanceArea* mDistanceArea;
204 };
205 
206 #endif
207 
208