QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 : blazek@itc.it
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 
58  Q_DECL_DEPRECATED void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, QMap<QString, QVariant> substitutions = ( QMap<QString, QVariant>() ) );
59 
63  void setSubstitutions( QMap<QString, QVariant> substitutions = ( QMap<QString, QVariant>() ) );
64 
65  QFont font() const;
66  void setFont( const QFont& f );
70  Qt::AlignmentFlag vAlign() const { return mVAlignment; }
74  Qt::AlignmentFlag hAlign() const { return mHAlignment; }
79  void setHAlign( Qt::AlignmentFlag a ) {mHAlignment = a;}
84  void setVAlign( Qt::AlignmentFlag a ) { mVAlignment = a; }
85 
90  Q_DECL_DEPRECATED double margin() { return mMarginX; }
91 
97  double marginX() const { return mMarginX; }
98 
104  double marginY() const { return mMarginY; }
105 
114  void setMargin( const double m );
115 
123  void setMarginX( const double margin );
124 
132  void setMarginY( const double margin );
133 
135  void setFontColor( const QColor& c ) { mFontColor = c; }
137  QColor fontColor() const { return mFontColor; }
138 
143  bool writeXML( QDomElement& elem, QDomDocument & doc ) const override;
144 
149  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
150 
151  //Overriden to contain part of label's text
152  virtual QString displayName() const override;
153 
157  QRectF boundingRect() const override;
158 
161  virtual void setFrameEnabled( const bool drawFrame ) override;
162 
165  virtual void setFrameOutlineWidth( const double outlineWidth ) override;
166 
167  public slots:
168  void refreshExpressionContext();
169 
170 
171  private slots:
172  void loadingHtmlFinished( bool );
173 
174  private:
175  // Text
176  QString mText;
177 
178  // Html state
179  int mHtmlState;
180  double mHtmlUnitsToMM;
181  double htmlUnitsToMM(); //calculate scale factor
182  bool mHtmlLoaded;
183 
185  void itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const;
186 
187  // Font
188  QFont mFont;
189 
191  double mMarginX;
193  double mMarginY;
194 
195  // Font color
196  QColor mFontColor;
197 
198  // Horizontal Alignment
199  Qt::AlignmentFlag mHAlignment;
200 
201  // Vertical Alignment
202  Qt::AlignmentFlag mVAlignment;
203 
205  void replaceDateText( QString& text ) const;
206 
207  QScopedPointer<QgsFeature> mExpressionFeature;
208  QgsVectorLayer* mExpressionLayer;
209  QMap<QString, QVariant> mSubstitutions;
210  QgsDistanceArea* mDistanceArea;
211 };
212 
213 #endif
214 
215 
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
QColor fontColor() const
Get font color.
double marginY() const
Returns the vertical margin between the edge of the frame and the label contents. ...
A item that forms part of a map composition.
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:162
void setFontColor(const QColor &c)
Sets text color.
Qt::AlignmentFlag vAlign() const
Accessor for the vertical alignment of the label.
double marginX() const
Returns the horizontal margin between the edge of the frame and the label contents.
virtual QRectF boundingRect() const
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Graphics scene for map printing.
virtual QString displayName() const
Get item display name.
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.
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.
Qt::AlignmentFlag hAlign() const
Accessor for the horizontal alignment of the label.