QGIS API Documentation  2.0.1-Dufour
 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 : 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 
29 class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
30 {
31  Q_OBJECT
32  public:
33  QgsComposerLabel( QgsComposition *composition );
35 
37  virtual int type() const { return ComposerLabel; }
38 
40  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
41 
43  void adjustSizeToText();
44 
45  QString text() { return mText; }
46  void setText( const QString& text );
47 
48  int htmlState() { return mHtmlState; }
49  void setHtmlState( int state ) {mHtmlState = state;}
50 
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;}
79  double margin() {return mMargin;}
81  void setMargin( double m ) {mMargin = m;}
82 
85  void setFontColor( const QColor& c ) {mFontColor = c;}
88  QColor fontColor() const {return mFontColor;}
89 
90  void setSceneRect( const QRectF& rectangle );
91 
96  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
97 
102  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
103 
104  public slots:
105  virtual void setRotation( double r );
106 
107  private slots:
108  void loadingHtmlFinished( bool );
109 
110  private:
111  // Text
112  QString mText;
113 
114  // Html state
117  double htmlUnitsToMM(); //calculate scale factor
119 
121  void itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const;
122 
123  // Font
124  QFont mFont;
125 
126  // Border between text and fram (in mm)
127  double mMargin;
128 
129  // Font color
130  QColor mFontColor;
131 
132  // Horizontal Alignment
133  Qt::AlignmentFlag mHAlignment;
134 
135  // Vertical Alignment
136  Qt::AlignmentFlag mVAlignment;
137 
139  void replaceDateText( QString& text ) const;
140 
145 
148  QMap<QString, QVariant> mSubstitutions;
149 
150 
151 };
152 
153 #endif
154 
155 
QgsVectorLayer * mExpressionLayer
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)=0
sets state from Dom document
void setHtmlState(int state)
QColor fontColor() const
Get font color.
virtual void setRotation(double r)
A item that forms part of a map composition.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:114
void setFontColor(const QColor &c)
Sets text color.
Qt::AlignmentFlag vAlign() const
Accessor for the vertical alignment of the label.
QgsFeature * mExpressionFeature
double margin()
brief Accessor for the margin of the label
QMap< QString, QVariant > mSubstitutions
Qt::AlignmentFlag mHAlignment
double mTextBoxHeight
Height of the text box.
Graphics scene for map printing.
double mTextBoxWidth
Width of the text box.
void setMargin(double m)
brief Mutator for the margin of the label
Qt::AlignmentFlag mVAlignment
void setVAlign(Qt::AlignmentFlag a)
Mutator for the vertical alignment of the label.
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
virtual int type() const
return correct graphics item type.
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.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const =0
stores state in Dom element