QGIS API Documentation  2.5.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 
54  QString displayText() const;
55 
57  void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, QMap<QString, QVariant> substitutions = ( QMap<QString, QVariant>() ) );
58 
59  QFont font() const;
60  void setFont( const QFont& f );
64  Qt::AlignmentFlag vAlign() const { return mVAlignment; }
68  Qt::AlignmentFlag hAlign() const { return mHAlignment; }
73  void setHAlign( Qt::AlignmentFlag a ) {mHAlignment = a;}
78  void setVAlign( Qt::AlignmentFlag a ) { mVAlignment = a; }
80  double margin() { return mMargin; }
82  void setMargin( double m ) { mMargin = m; }
83 
86  void setFontColor( const QColor& c ) { mFontColor = c; }
89  QColor fontColor() const { return mFontColor; }
90 
95  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
96 
101  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
102 
103  //Overriden to contain part of label's text
104  virtual QString displayName() const;
105 
106  public slots:
107  void refreshExpressionContext();
108 
109 
110  private slots:
111  void loadingHtmlFinished( bool );
112 
113  private:
114  // Text
115  QString mText;
116 
117  // Html state
118  int mHtmlState;
119  double mHtmlUnitsToMM;
120  double htmlUnitsToMM(); //calculate scale factor
121  bool mHtmlLoaded;
122 
124  void itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const;
125 
126  // Font
127  QFont mFont;
128 
129  // Border between text and fram (in mm)
130  double mMargin;
131 
132  // Font color
133  QColor mFontColor;
134 
135  // Horizontal Alignment
136  Qt::AlignmentFlag mHAlignment;
137 
138  // Vertical Alignment
139  Qt::AlignmentFlag mVAlignment;
140 
142  void replaceDateText( QString& text ) const;
143 
144  QgsFeature* mExpressionFeature;
145  QgsVectorLayer* mExpressionLayer;
146  QMap<QString, QVariant> mSubstitutions;
147  QgsDistanceArea* mDistanceArea;
148 };
149 
150 #endif
151 
152 
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
Definition: qgscomposerobject.cpp:61
QColor fontColor() const
Get font color.
Definition: qgscomposerlabel.h:89
int htmlState()
Definition: qgscomposerlabel.h:49
A item that forms part of a map composition.
Definition: qgscomposeritem.h:38
Definition: qgscomposeritem.h:51
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.
Definition: qgscomposerlabel.h:86
Qt::AlignmentFlag vAlign() const
Accessor for the vertical alignment of the label.
Definition: qgscomposerlabel.h:64
double margin()
brief Accessor for the margin of the label
Definition: qgscomposerlabel.h:80
Graphics scene for map printing.
Definition: qgscomposition.h:73
void setMargin(double m)
brief Mutator for the margin of the label
Definition: qgscomposerlabel.h:82
virtual QString displayName() const
Get item display name.
Definition: qgscomposeritem.cpp:1406
General purpose distance and area calculator.
Definition: qgsdistancearea.h:34
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
Definition: qgscomposerobject.cpp:74
void setVAlign(Qt::AlignmentFlag a)
Mutator for the vertical alignment of the label.
Definition: qgscomposerlabel.h:78
virtual int type() const
return correct graphics item type.
Definition: qgscomposerlabel.h:38
A label that can be placed onto a map composition.
Definition: qgscomposerlabel.h:30
QString text()
Definition: qgscomposerlabel.h:46
void setHAlign(Qt::AlignmentFlag a)
Mutator for the horizontal alignment of the label.
Definition: qgscomposerlabel.h:73
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
Qt::AlignmentFlag hAlign() const
Accessor for the horizontal alignment of the label.
Definition: qgscomposerlabel.h:68