QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 { return ComposerLabel; }
39 
41  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
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;
137 
142  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
143 
144  //Overriden to contain part of label's text
145  virtual QString displayName() const;
146 
150  QRectF boundingRect() const;
151 
154  virtual void setFrameEnabled( const bool drawFrame );
155 
158  virtual void setFrameOutlineWidth( const double outlineWidth );
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 
double outlineWidth
Definition: qgssvgcache.cpp:78
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:113
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.
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.
void setVAlign(Qt::AlignmentFlag a)
Mutator for the vertical alignment of the label.
virtual int type() const
return correct graphics item type.
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.