QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposerlabel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerlabel.cpp
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 
18 #include "qgscomposerlabel.h"
19 #include "qgscomposition.h"
20 #include "qgscomposerutils.h"
21 #include "qgsexpression.h"
23 #include "qgscomposermodel.h"
24 #include "qgsvectorlayer.h"
25 #include "qgsproject.h"
26 #include "qgsdistancearea.h"
27 #include "qgsfontutils.h"
28 
29 #include "qgswebview.h"
30 #include "qgswebframe.h"
31 #include "qgswebpage.h"
32 
33 #include <QCoreApplication>
34 #include <QDate>
35 #include <QDomElement>
36 #include <QPainter>
37 #include <QSettings>
38 #include <QTimer>
39 #include <QEventLoop>
40 
42  : QgsComposerItem( composition )
43  , mHtmlState( 0 )
44  , mHtmlUnitsToMM( 1.0 )
45  , mHtmlLoaded( false )
46  , mMarginX( 1.0 )
47  , mMarginY( 1.0 )
48  , mFontColor( QColor( 0, 0, 0 ) )
49  , mHAlignment( Qt::AlignLeft )
50  , mVAlignment( Qt::AlignTop )
51  , mExpressionFeature( 0 )
52  , mExpressionLayer( 0 )
53  , mDistanceArea( 0 )
54 {
55  mDistanceArea = new QgsDistanceArea();
56  mHtmlUnitsToMM = htmlUnitsToMM();
57 
58  //get default composer font from settings
59  QSettings settings;
60  QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
61  if ( !defaultFontString.isEmpty() )
62  {
63  mFont.setFamily( defaultFontString );
64  }
65 
66  //default to a 10 point font size
67  mFont.setPointSizeF( 10 );
68 
69  //default to no background
70  setBackgroundEnabled( false );
71 
73  {
74  //a label added while atlas preview is enabled needs to have the expression context set,
75  //otherwise fields in the label aren't correctly evaluated until atlas preview feature changes (#9457)
77  }
78 
79  if ( mComposition )
80  {
81  //connect to atlas feature changes
82  //to update the expression context
83  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) );
84  }
85 }
86 
88 {
89  delete mDistanceArea;
90 }
91 
92 void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
93 {
94  Q_UNUSED( itemStyle );
95  Q_UNUSED( pWidget );
96  if ( !painter )
97  {
98  return;
99  }
100  if ( !shouldDrawItem() )
101  {
102  return;
103  }
104 
105  drawBackground( painter );
106  painter->save();
107 
108  //antialiasing on
109  painter->setRenderHint( QPainter::Antialiasing, true );
110 
111  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
112  double xPenAdjust = mMarginX < 0 ? -penWidth : penWidth;
113  double yPenAdjust = mMarginY < 0 ? -penWidth : penWidth;
114  QRectF painterRect( xPenAdjust + mMarginX, yPenAdjust + mMarginY, rect().width() - 2 * xPenAdjust - 2 * mMarginX, rect().height() - 2 * yPenAdjust - 2 * mMarginY );
115 
116  QString textToDraw = displayText();
117 
118  if ( mHtmlState )
119  {
120  painter->scale( 1.0 / mHtmlUnitsToMM / 10.0, 1.0 / mHtmlUnitsToMM / 10.0 );
121  QWebPage *webPage = new QWebPage();
123 
124  //Setup event loop and timeout for rendering html
125  QEventLoop loop;
126  QTimer timeoutTimer;
127  timeoutTimer.setSingleShot( true );
128 
129  //This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/
130  QPalette palette = webPage->palette();
131  palette.setBrush( QPalette::Base, Qt::transparent );
132  webPage->setPalette( palette );
133  //webPage->setAttribute(Qt::WA_OpaquePaintEvent, false); //this does not compile, why ?
134 
135  webPage->setViewportSize( QSize( painterRect.width() * mHtmlUnitsToMM * 10.0, painterRect.height() * mHtmlUnitsToMM * 10.0 ) );
136  webPage->mainFrame()->setZoomFactor( 10.0 );
137  webPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
138  webPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
139 
140  // QGIS segfaults when rendering web page while in composer if html
141  // contains images. So if we are not printing the composition, then
142  // disable image loading
145  {
146  webPage->settings()->setAttribute( QWebSettings::AutoLoadImages, false );
147  }
148 
149  //Connect timeout and webpage loadFinished signals to loop
150  connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
151  connect( webPage, SIGNAL( loadFinished( bool ) ), &loop, SLOT( quit() ) );
152 
153  //mHtmlLoaded tracks whether the QWebPage has completed loading
154  //its html contents, set it initially to false. The loadingHtmlFinished slot will
155  //set this to true after html is loaded.
156  mHtmlLoaded = false;
157  connect( webPage, SIGNAL( loadFinished( bool ) ), SLOT( loadingHtmlFinished( bool ) ) );
158 
159  webPage->mainFrame()->setHtml( textToDraw );
160 
161  //For very basic html labels with no external assets, the html load will already be
162  //complete before we even get a chance to start the QEventLoop. Make sure we check
163  //this before starting the loop
164  if ( !mHtmlLoaded )
165  {
166  // Start a 20 second timeout in case html loading will never complete
167  timeoutTimer.start( 20000 );
168  // Pause until html is loaded
169  loop.exec();
170  }
171  webPage->mainFrame()->render( painter );//DELETE WEBPAGE ?
172  }
173  else
174  {
175  painter->setFont( mFont );
176  //debug
177  //painter->setPen( QColor( Qt::red ) );
178  //painter->drawRect( painterRect );
179  QgsComposerUtils::drawText( painter, painterRect, textToDraw, mFont, mFontColor, mHAlignment, mVAlignment, Qt::TextWordWrap );
180  }
181 
182  painter->restore();
183 
184  drawFrame( painter );
185  if ( isSelected() )
186  {
187  drawSelectionBoxes( painter );
188  }
189 }
190 
191 /*Track when QWebPage has finished loading its html contents*/
192 void QgsComposerLabel::loadingHtmlFinished( bool result )
193 {
194  Q_UNUSED( result );
195  mHtmlLoaded = true;
196 }
197 
198 double QgsComposerLabel::htmlUnitsToMM()
199 {
200  if ( !mComposition )
201  {
202  return 1.0;
203  }
204 
205  //TODO : fix this more precisely so that the label's default text size is the same with or without "display as html"
206  return ( mComposition->printResolution() / 72.0 ); //webkit seems to assume a standard dpi of 72
207 }
208 
210 {
211  mText = text;
212  emit itemChanged();
213 
214  if ( mComposition && id().isEmpty() && !mHtmlState )
215  {
216  //notify the model that the display name has changed
218  }
219 }
220 
222 {
223  if ( state == mHtmlState )
224  {
225  return;
226  }
227 
228  mHtmlState = state;
229 
230  if ( mComposition && id().isEmpty() )
231  {
232  //notify the model that the display name has changed
234  }
235 }
236 
238 {
239  mExpressionFeature = feature;
240  mExpressionLayer = layer;
241  mSubstitutions = substitutions;
242 
243  //setup distance area conversion
244  if ( layer )
245  {
246  mDistanceArea->setSourceCrs( layer->crs().srsid() );
247  }
248  else if ( mComposition )
249  {
250  //set to composition's mapsettings' crs
251  mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
252  }
253  if ( mComposition )
254  {
256  }
257  mDistanceArea->setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
258 
259  // Force label to redraw -- fixes label printing for labels with blend modes when used with atlas
260  update();
261 }
262 
264 {
265  QgsVectorLayer * vl = 0;
266  QgsFeature* feature = 0;
267 
269  {
271  }
273  {
275  }
276 
277  setExpressionContext( feature, vl );
278 }
279 
281 {
282  QString displayText = mText;
283  replaceDateText( displayText );
284  QMap<QString, QVariant> subs = mSubstitutions;
285  subs[ "$page" ] = QVariant(( int )mComposition->itemPageNumber( this ) + 1 );
286  return QgsExpression::replaceExpressionText( displayText, mExpressionFeature, mExpressionLayer, &subs, mDistanceArea );
287 }
288 
289 void QgsComposerLabel::replaceDateText( QString& text ) const
290 {
291  QString constant = "$CURRENT_DATE";
292  int currentDatePos = text.indexOf( constant );
293  if ( currentDatePos != -1 )
294  {
295  //check if there is a bracket just after $CURRENT_DATE
296  QString formatText;
297  int openingBracketPos = text.indexOf( "(", currentDatePos );
298  int closingBracketPos = text.indexOf( ")", openingBracketPos + 1 );
299  if ( openingBracketPos != -1 &&
300  closingBracketPos != -1 &&
301  ( closingBracketPos - openingBracketPos ) > 1 &&
302  openingBracketPos == currentDatePos + constant.size() )
303  {
304  formatText = text.mid( openingBracketPos + 1, closingBracketPos - openingBracketPos - 1 );
305  text.replace( currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString( formatText ) );
306  }
307  else //no bracket
308  {
309  text.replace( "$CURRENT_DATE", QDate::currentDate().toString() );
310  }
311  }
312 }
313 
315 {
316  mFont = f;
317 }
318 
319 void QgsComposerLabel::setMargin( const double m )
320 {
321  mMarginX = m;
322  mMarginY = m;
324 }
325 
326 void QgsComposerLabel::setMarginX( const double margin )
327 {
328  mMarginX = margin;
330 }
331 
332 void QgsComposerLabel::setMarginY( const double margin )
333 {
334  mMarginY = margin;
336 }
337 
339 {
340  double textWidth = QgsComposerUtils::textWidthMM( mFont, displayText() );
341  double fontHeight = QgsComposerUtils::fontHeightMM( mFont );
342 
343  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
344 
345  double width = textWidth + 2 * mMarginX + 2 * penWidth + 1;
346  double height = fontHeight + 2 * mMarginY + 2 * penWidth;
347 
348  //keep alignment point constant
349  double xShift = 0;
350  double yShift = 0;
351  itemShiftAdjustSize( width, height, xShift, yShift );
352 
353  //update rect for data defined size and position
354  QRectF evaluatedRect = evalItemRect( QRectF( pos().x() + xShift, pos().y() + yShift, width, height ) );
355  setSceneRect( evaluatedRect );
356 }
357 
359 {
360  return mFont;
361 }
362 
364 {
365  QString alignment;
366 
367  if ( elem.isNull() )
368  {
369  return false;
370  }
371 
372  QDomElement composerLabelElem = doc.createElement( "ComposerLabel" );
373 
374  composerLabelElem.setAttribute( "htmlState", mHtmlState );
375 
376  composerLabelElem.setAttribute( "labelText", mText );
377  composerLabelElem.setAttribute( "marginX", QString::number( mMarginX ) );
378  composerLabelElem.setAttribute( "marginY", QString::number( mMarginY ) );
379  composerLabelElem.setAttribute( "halign", mHAlignment );
380  composerLabelElem.setAttribute( "valign", mVAlignment );
381 
382  //font
383  QDomElement labelFontElem = QgsFontUtils::toXmlElement( mFont, doc, "LabelFont" );
384  composerLabelElem.appendChild( labelFontElem );
385 
386  //font color
387  QDomElement fontColorElem = doc.createElement( "FontColor" );
388  fontColorElem.setAttribute( "red", mFontColor.red() );
389  fontColorElem.setAttribute( "green", mFontColor.green() );
390  fontColorElem.setAttribute( "blue", mFontColor.blue() );
391  composerLabelElem.appendChild( fontColorElem );
392 
393  elem.appendChild( composerLabelElem );
394  return _writeXML( composerLabelElem, doc );
395 }
396 
397 bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument& doc )
398 {
399  QString alignment;
400 
401  if ( itemElem.isNull() )
402  {
403  return false;
404  }
405 
406  //restore label specific properties
407 
408  //text
409  mText = itemElem.attribute( "labelText" );
410 
411  //html state
412  mHtmlState = itemElem.attribute( "htmlState" ).toInt();
413 
414  //margin
415  bool marginXOk = false;
416  bool marginYOk = false;
417  mMarginX = itemElem.attribute( "marginX" ).toDouble( &marginXOk );
418  mMarginY = itemElem.attribute( "marginY" ).toDouble( &marginYOk );
419  if ( !marginXOk || !marginYOk )
420  {
421  //upgrade old projects where margins where stored in a single attribute
422  double margin = itemElem.attribute( "margin", "1.0" ).toDouble();
423  mMarginX = margin;
424  mMarginY = margin;
425  }
426 
427  //Horizontal alignment
428  mHAlignment = ( Qt::AlignmentFlag )( itemElem.attribute( "halign" ).toInt() );
429 
430  //Vertical alignment
431  mVAlignment = ( Qt::AlignmentFlag )( itemElem.attribute( "valign" ).toInt() );
432 
433  //font
434  QgsFontUtils::setFromXmlChildNode( mFont, itemElem, "LabelFont" );
435 
436  //font color
437  QDomNodeList fontColorList = itemElem.elementsByTagName( "FontColor" );
438  if ( fontColorList.size() > 0 )
439  {
440  QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
441  int red = fontColorElem.attribute( "red", "0" ).toInt();
442  int green = fontColorElem.attribute( "green", "0" ).toInt();
443  int blue = fontColorElem.attribute( "blue", "0" ).toInt();
444  mFontColor = QColor( red, green, blue );
445  }
446  else
447  {
448  mFontColor = QColor( 0, 0, 0 );
449  }
450 
451  //restore general composer item properties
452  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
453  if ( composerItemList.size() > 0 )
454  {
455  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
456 
457  //rotation
458  if ( composerItemElem.attribute( "rotation", "0" ).toDouble() != 0 )
459  {
460  //check for old (pre 2.1) rotation attribute
461  setItemRotation( composerItemElem.attribute( "rotation", "0" ).toDouble() );
462  }
463 
464  _readXML( composerItemElem, doc );
465  }
466  emit itemChanged();
467  return true;
468 }
469 
471 {
472  if ( !id().isEmpty() )
473  {
474  return id();
475  }
476 
477  if ( mHtmlState )
478  {
479  return tr( "<HTML label>" );
480  }
481 
482  //if no id, default to portion of label text
483  QString text = mText;
484  if ( text.isEmpty() )
485  {
486  return tr( "<label>" );
487  }
488  if ( text.length() > 25 )
489  {
490  return QString( tr( "%1..." ) ).arg( text.left( 25 ).simplified() );
491  }
492  else
493  {
494  return text.simplified();
495  }
496 }
497 
499 {
500  QRectF rectangle = rect();
501  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
502  rectangle.adjust( -penWidth, -penWidth, penWidth, penWidth );
503 
504  if ( mMarginX < 0 )
505  {
506  rectangle.adjust( mMarginX, 0, -mMarginX, 0 );
507  }
508  if ( mMarginY < 0 )
509  {
510  rectangle.adjust( 0, mMarginY, 0, -mMarginY );
511  }
512 
513  return rectangle;
514 }
515 
516 void QgsComposerLabel::setFrameEnabled( const bool drawFrame )
517 {
520 }
521 
522 void QgsComposerLabel::setFrameOutlineWidth( const double outlineWidth )
523 {
526 }
527 
528 void QgsComposerLabel::itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const
529 {
530  //keep alignment point constant
531  double currentWidth = rect().width();
532  double currentHeight = rect().height();
533  xShift = 0;
534  yShift = 0;
535 
536  if ( mItemRotation >= 0 && mItemRotation < 90 )
537  {
538  if ( mHAlignment == Qt::AlignHCenter )
539  {
540  xShift = - ( newWidth - currentWidth ) / 2.0;
541  }
542  else if ( mHAlignment == Qt::AlignRight )
543  {
544  xShift = - ( newWidth - currentWidth );
545  }
546  if ( mVAlignment == Qt::AlignVCenter )
547  {
548  yShift = -( newHeight - currentHeight ) / 2.0;
549  }
550  else if ( mVAlignment == Qt::AlignBottom )
551  {
552  yShift = - ( newHeight - currentHeight );
553  }
554  }
555  if ( mItemRotation >= 90 && mItemRotation < 180 )
556  {
557  if ( mHAlignment == Qt::AlignHCenter )
558  {
559  yShift = -( newHeight - currentHeight ) / 2.0;
560  }
561  else if ( mHAlignment == Qt::AlignRight )
562  {
563  yShift = -( newHeight - currentHeight );
564  }
565  if ( mVAlignment == Qt::AlignTop )
566  {
567  xShift = -( newWidth - currentWidth );
568  }
569  else if ( mVAlignment == Qt::AlignVCenter )
570  {
571  xShift = -( newWidth - currentWidth / 2.0 );
572  }
573  }
574  else if ( mItemRotation >= 180 && mItemRotation < 270 )
575  {
576  if ( mHAlignment == Qt::AlignHCenter )
577  {
578  xShift = -( newWidth - currentWidth ) / 2.0;
579  }
580  else if ( mHAlignment == Qt::AlignLeft )
581  {
582  xShift = -( newWidth - currentWidth );
583  }
584  if ( mVAlignment == Qt::AlignVCenter )
585  {
586  yShift = ( newHeight - currentHeight ) / 2.0;
587  }
588  else if ( mVAlignment == Qt::AlignTop )
589  {
590  yShift = ( newHeight - currentHeight );
591  }
592  }
593  else if ( mItemRotation >= 270 && mItemRotation < 360 )
594  {
595  if ( mHAlignment == Qt::AlignHCenter )
596  {
597  yShift = -( newHeight - currentHeight ) / 2.0;
598  }
599  else if ( mHAlignment == Qt::AlignLeft )
600  {
601  yShift = -( newHeight - currentHeight );
602  }
603  if ( mVAlignment == Qt::AlignBottom )
604  {
605  xShift = -( newWidth - currentWidth );
606  }
607  else if ( mVAlignment == Qt::AlignVCenter )
608  {
609  xShift = -( newWidth - currentWidth / 2.0 );
610  }
611  }
612 }
void setBrush(ColorRole role, const QBrush &brush)
QgsComposition::AtlasMode atlasMode() const
Returns the current atlas mode of the composition.
QDomNodeList elementsByTagName(const QString &tagname) const
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
qreal x() const
qreal y() const
void setHtmlState(int state)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
sets state from Dom document
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const
QgsComposerModel * itemsModel()
Returns the items model attached to the composition.
void itemChanged()
Emitted when the item changes.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
void scale(qreal sx, qreal sy)
A item that forms part of a map composition.
int size() const
QString simplified() const
void save()
static void drawText(QPainter *painter, const QPointF &pos, const QString &text, const QFont &font, const QColor &color=QColor())
Draws text on a painter at a specific position, taking care of composer specific issues (calculation ...
bool enabled() const
Returns whether the atlas generation is enabled.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
virtual void drawFrame(QPainter *p)
Draw black frame around item.
virtual void setFrameEnabled(const bool drawFrame)
Set whether this item has a frame drawn around it or not.
bool setEllipsoid(const QString &ellipsoid)
sets ellipsoid by its acronym
void setFont(const QFont &f)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
double toDouble(bool *ok) const
QString tr(const char *sourceText, const char *disambiguation, int n)
void adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
void update(const QRectF &rect)
void updateItemDisplayName(QgsComposerItem *item)
Must be called when an item's display name is modified.
const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
Definition: qgis.cpp:74
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
stores state in Dom element
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
QDomElement toElement() const
void setFont(const QFont &font)
QPointF pos() const
QString number(int n, int base)
int itemPageNumber(const QgsComposerItem *) const
Returns on which page number (0-based) is displayed an item.
void setHtml(const QString &html, const QUrl &baseUrl)
QFont font() const
int exec(QFlags< QEventLoop::ProcessEventsFlag > flags)
virtual void drawSelectionBoxes(QPainter *p)
Draws additional graphics on selected items.
int printResolution() const
int red() const
void setAttribute(const QString &name, const QString &value)
bool isSelected() const
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
int toInt(bool *ok, int base) const
bool isEmpty() const
QWebFrame * mainFrame() const
The QWebPage class is a collection of stubs to mimic the API of a QWebPage on systems where QtWebkit ...
Definition: qgswebpage.h:99
QgsComposerLabel(QgsComposition *composition)
void setZoomFactor(qreal factor)
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
void setBackgroundEnabled(const bool drawBackground)
Set whether this item has a Background drawn around it or not.
QRectF boundingRect() const override
In case of negative margins, the bounding rect may be larger than the label's frame.
void setMarginX(const double margin)
Sets the horizontal margin between the edge of the frame and the label contents.
void prepareGeometryChange()
Graphics scene for map printing.
QgsFeature * currentFeature()
Returns the current atlas feature.
int green() const
void setAttribute(WebAttribute attribute, bool on)
void setMarginY(const double margin)
Sets the vertical margin between the edge of the frame and the label contents.
QWebSettings * settings() const
void setPointSizeF(qreal pointSize)
bool isNull() const
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint.
virtual void setFrameOutlineWidth(const double outlineWidth)
Sets frame outline width.
void restore()
General purpose distance and area calculator.
static double textWidthMM(const QFont &font, const QString &text)
Calculate font width in millimeters for a string, including workarounds for QT font rendering issues...
QgsComposition * mComposition
QString & replace(int position, int n, QChar after)
int blue() const
static double fontHeightMM(const QFont &font)
Calculate font height in millimeters, including workarounds for QT font rendering issues The font hei...
QVariant value(const QString &key, const QVariant &defaultValue) const
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false)
Evaluates an item's bounding rect to consider data defined position and size of item and reference po...
void render(QPainter *painter)
qreal width() const
QString mid(int position, int n) const
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
char * toString(const T &value)
static QgsNetworkAccessManager * instance()
returns a pointer to the single instance
virtual void setItemRotation(const double r, const bool adjustPosition=false)
Sets the item rotation.
virtual void drawBackground(QPainter *p)
Draw background.
bool hasFrame() const
Whether this item has a frame or not.
QDate currentDate()
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:351
void setFamily(const QString &family)
void setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy)
void setMargin(const double m)
Sets the margin between the edge of the frame and the label contents.
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...
qreal widthF() const
int length() const
void setText(const QString &text)
QString left(int n) const
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
Q_DECL_DEPRECATED double margin()
Returns the margin between the edge of the frame and the label contents.
void start(int msec)
qreal height() const
QgsAtlasComposition & atlasComposition()
void setExpressionContext(QgsFeature *feature, QgsVectorLayer *layer, QMap< QString, QVariant > substitutions=(QMap< QString, QVariant >()))
Sets the current feature, the current layer and a list of local variable substitutions for evaluating...
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
int size() const
QDomElement createElement(const QString &tagName)
QgsComposition::PlotStyle plotStyle() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
void setViewportSize(const QSize &size) const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
QString displayText() const
Returns the text as it appears on screen (with replaced data field)
void setNetworkAccessManager(QNetworkAccessManager *manager)
double mItemRotation
Item rotation in degrees, clockwise.
void adjustSizeToText()
resizes the widget such that the text fits to the item.
void setEllipsoidalMode(bool flag)
sets whether coordinates must be projected to ellipsoid before measuring
QDomNode at(int index) const
QRectF rect() const
virtual void setFrameEnabled(const bool drawFrame) override
Reimplemented to call prepareGeometryChange after toggling frame.
void setSingleShot(bool singleShot)
virtual QString displayName() const override
Get item display name.
static QString replaceExpressionText(const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=0, const QgsDistanceArea *distanceArea=0)
This function currently replaces each expression between [% and %] in the string with the result of i...
virtual void setFrameOutlineWidth(const double outlineWidth) override
Reimplemented to call prepareGeometryChange after changing outline width.
QString id() const
Get item's id (which is not necessarly unique)