QGIS API Documentation  2.12.0-Lyon
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 #include "qgsexpressioncontext.h"
29 
30 #include "qgswebview.h"
31 #include "qgswebframe.h"
32 #include "qgswebpage.h"
33 
34 #include <QCoreApplication>
35 #include <QDate>
36 #include <QDomElement>
37 #include <QPainter>
38 #include <QSettings>
39 #include <QTimer>
40 #include <QEventLoop>
41 
43  : QgsComposerItem( composition )
44  , mHtmlState( 0 )
45  , mHtmlUnitsToMM( 1.0 )
46  , mHtmlLoaded( false )
47  , mMarginX( 1.0 )
48  , mMarginY( 1.0 )
49  , mFontColor( QColor( 0, 0, 0 ) )
50  , mHAlignment( Qt::AlignLeft )
51  , mVAlignment( Qt::AlignTop )
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 
72  //a label added while atlas preview is enabled needs to have the expression context set,
73  //otherwise fields in the label aren't correctly evaluated until atlas preview feature changes (#9457)
75 
76  if ( mComposition )
77  {
78  //connect to atlas feature changes
79  //to update the expression context
80  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) );
81  }
82 }
83 
85 {
86  delete mDistanceArea;
87 }
88 
89 void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
90 {
91  Q_UNUSED( itemStyle );
92  Q_UNUSED( pWidget );
93  if ( !painter )
94  {
95  return;
96  }
97  if ( !shouldDrawItem() )
98  {
99  return;
100  }
101 
102  drawBackground( painter );
103  painter->save();
104 
105  //antialiasing on
106  painter->setRenderHint( QPainter::Antialiasing, true );
107 
108  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
109  double xPenAdjust = mMarginX < 0 ? -penWidth : penWidth;
110  double yPenAdjust = mMarginY < 0 ? -penWidth : penWidth;
111  QRectF painterRect( xPenAdjust + mMarginX, yPenAdjust + mMarginY, rect().width() - 2 * xPenAdjust - 2 * mMarginX, rect().height() - 2 * yPenAdjust - 2 * mMarginY );
112 
113  QString textToDraw = displayText();
114 
115  if ( mHtmlState )
116  {
117  painter->scale( 1.0 / mHtmlUnitsToMM / 10.0, 1.0 / mHtmlUnitsToMM / 10.0 );
118  QWebPage *webPage = new QWebPage();
120 
121  //Setup event loop and timeout for rendering html
122  QEventLoop loop;
123  QTimer timeoutTimer;
124  timeoutTimer.setSingleShot( true );
125 
126  //This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/
127  QPalette palette = webPage->palette();
128  palette.setBrush( QPalette::Base, Qt::transparent );
129  webPage->setPalette( palette );
130  //webPage->setAttribute(Qt::WA_OpaquePaintEvent, false); //this does not compile, why ?
131 
132  webPage->setViewportSize( QSize( painterRect.width() * mHtmlUnitsToMM * 10.0, painterRect.height() * mHtmlUnitsToMM * 10.0 ) );
133  webPage->mainFrame()->setZoomFactor( 10.0 );
134  webPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
135  webPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
136 
137  // QGIS segfaults when rendering web page while in composer if html
138  // contains images. So if we are not printing the composition, then
139  // disable image loading
142  {
143  webPage->settings()->setAttribute( QWebSettings::AutoLoadImages, false );
144  }
145 
146  //Connect timeout and webpage loadFinished signals to loop
147  connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
148  connect( webPage, SIGNAL( loadFinished( bool ) ), &loop, SLOT( quit() ) );
149 
150  //mHtmlLoaded tracks whether the QWebPage has completed loading
151  //its html contents, set it initially to false. The loadingHtmlFinished slot will
152  //set this to true after html is loaded.
153  mHtmlLoaded = false;
154  connect( webPage, SIGNAL( loadFinished( bool ) ), SLOT( loadingHtmlFinished( bool ) ) );
155 
156  webPage->mainFrame()->setHtml( textToDraw );
157 
158  //For very basic html labels with no external assets, the html load will already be
159  //complete before we even get a chance to start the QEventLoop. Make sure we check
160  //this before starting the loop
161  if ( !mHtmlLoaded )
162  {
163  // Start a 20 second timeout in case html loading will never complete
164  timeoutTimer.start( 20000 );
165  // Pause until html is loaded
166  loop.exec();
167  }
168  webPage->mainFrame()->render( painter );//DELETE WEBPAGE ?
169  }
170  else
171  {
172  painter->setFont( mFont );
173  //debug
174  //painter->setPen( QColor( Qt::red ) );
175  //painter->drawRect( painterRect );
176  QgsComposerUtils::drawText( painter, painterRect, textToDraw, mFont, mFontColor, mHAlignment, mVAlignment, Qt::TextWordWrap );
177  }
178 
179  painter->restore();
180 
181  drawFrame( painter );
182  if ( isSelected() )
183  {
184  drawSelectionBoxes( painter );
185  }
186 }
187 
188 /*Track when QWebPage has finished loading its html contents*/
189 void QgsComposerLabel::loadingHtmlFinished( bool result )
190 {
191  Q_UNUSED( result );
192  mHtmlLoaded = true;
193 }
194 
195 double QgsComposerLabel::htmlUnitsToMM()
196 {
197  if ( !mComposition )
198  {
199  return 1.0;
200  }
201 
202  //TODO : fix this more precisely so that the label's default text size is the same with or without "display as html"
203  return ( mComposition->printResolution() / 72.0 ); //webkit seems to assume a standard dpi of 72
204 }
205 
207 {
208  mText = text;
209  emit itemChanged();
210 
211  if ( mComposition && id().isEmpty() && !mHtmlState )
212  {
213  //notify the model that the display name has changed
215  }
216 }
217 
219 {
220  if ( state == mHtmlState )
221  {
222  return;
223  }
224 
225  mHtmlState = state;
226 
227  if ( mComposition && id().isEmpty() )
228  {
229  //notify the model that the display name has changed
231  }
232 }
233 
235 {
236  mExpressionFeature.reset( feature ? new QgsFeature( *feature ) : 0 );
237  mExpressionLayer = layer;
238  mSubstitutions = substitutions;
239 
240  //setup distance area conversion
241  if ( layer )
242  {
243  mDistanceArea->setSourceCrs( layer->crs().srsid() );
244  }
245  else if ( mComposition )
246  {
247  //set to composition's mapsettings' crs
248  mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
249  }
250  if ( mComposition )
251  {
253  }
254  mDistanceArea->setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
255 
256  // Force label to redraw -- fixes label printing for labels with blend modes when used with atlas
257  update();
258 }
259 
261 {
262  mSubstitutions = substitutions;
263 }
264 
266 {
267  mExpressionLayer = 0;
268  mExpressionFeature.reset();
269 
270  if ( !mComposition )
271  return;
272 
273  QgsVectorLayer* layer = 0;
275  {
277  }
278 
279  //setup distance area conversion
280  if ( layer )
281  {
282  mDistanceArea->setSourceCrs( layer->crs().srsid() );
283  }
284  else
285  {
286  //set to composition's mapsettings' crs
287  mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
288  }
290  mDistanceArea->setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
291 
292  update();
293 }
294 
296 {
297  QString displayText = mText;
298  replaceDateText( displayText );
299  QMap<QString, QVariant> subs = mSubstitutions;
300 
302  //overwrite layer/feature if they have been set via setExpressionContext
303  //TODO remove when setExpressionContext is removed
304  if ( mExpressionFeature.data() )
305  context->setFeature( *mExpressionFeature.data() );
306  if ( mExpressionLayer )
307  context->setFields( mExpressionLayer->fields() );
308 
309  return QgsExpression::replaceExpressionText( displayText, context.data(), &subs, mDistanceArea );
310 }
311 
312 void QgsComposerLabel::replaceDateText( QString& text ) const
313 {
314  QString constant = "$CURRENT_DATE";
315  int currentDatePos = text.indexOf( constant );
316  if ( currentDatePos != -1 )
317  {
318  //check if there is a bracket just after $CURRENT_DATE
319  QString formatText;
320  int openingBracketPos = text.indexOf( "(", currentDatePos );
321  int closingBracketPos = text.indexOf( ")", openingBracketPos + 1 );
322  if ( openingBracketPos != -1 &&
323  closingBracketPos != -1 &&
324  ( closingBracketPos - openingBracketPos ) > 1 &&
325  openingBracketPos == currentDatePos + constant.size() )
326  {
327  formatText = text.mid( openingBracketPos + 1, closingBracketPos - openingBracketPos - 1 );
328  text.replace( currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString( formatText ) );
329  }
330  else //no bracket
331  {
332  text.replace( "$CURRENT_DATE", QDate::currentDate().toString() );
333  }
334  }
335 }
336 
338 {
339  mFont = f;
340 }
341 
342 void QgsComposerLabel::setMargin( const double m )
343 {
344  mMarginX = m;
345  mMarginY = m;
347 }
348 
349 void QgsComposerLabel::setMarginX( const double margin )
350 {
351  mMarginX = margin;
353 }
354 
355 void QgsComposerLabel::setMarginY( const double margin )
356 {
357  mMarginY = margin;
359 }
360 
362 {
363  double textWidth = QgsComposerUtils::textWidthMM( mFont, displayText() );
364  double fontHeight = QgsComposerUtils::fontHeightMM( mFont );
365 
366  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
367 
368  double width = textWidth + 2 * mMarginX + 2 * penWidth + 1;
369  double height = fontHeight + 2 * mMarginY + 2 * penWidth;
370 
371  //keep alignment point constant
372  double xShift = 0;
373  double yShift = 0;
374  itemShiftAdjustSize( width, height, xShift, yShift );
375 
376  //update rect for data defined size and position
377  QRectF evaluatedRect = evalItemRect( QRectF( pos().x() + xShift, pos().y() + yShift, width, height ) );
378  setSceneRect( evaluatedRect );
379 }
380 
382 {
383  return mFont;
384 }
385 
387 {
388  QString alignment;
389 
390  if ( elem.isNull() )
391  {
392  return false;
393  }
394 
395  QDomElement composerLabelElem = doc.createElement( "ComposerLabel" );
396 
397  composerLabelElem.setAttribute( "htmlState", mHtmlState );
398 
399  composerLabelElem.setAttribute( "labelText", mText );
400  composerLabelElem.setAttribute( "marginX", QString::number( mMarginX ) );
401  composerLabelElem.setAttribute( "marginY", QString::number( mMarginY ) );
402  composerLabelElem.setAttribute( "halign", mHAlignment );
403  composerLabelElem.setAttribute( "valign", mVAlignment );
404 
405  //font
406  QDomElement labelFontElem = QgsFontUtils::toXmlElement( mFont, doc, "LabelFont" );
407  composerLabelElem.appendChild( labelFontElem );
408 
409  //font color
410  QDomElement fontColorElem = doc.createElement( "FontColor" );
411  fontColorElem.setAttribute( "red", mFontColor.red() );
412  fontColorElem.setAttribute( "green", mFontColor.green() );
413  fontColorElem.setAttribute( "blue", mFontColor.blue() );
414  composerLabelElem.appendChild( fontColorElem );
415 
416  elem.appendChild( composerLabelElem );
417  return _writeXML( composerLabelElem, doc );
418 }
419 
420 bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument& doc )
421 {
422  QString alignment;
423 
424  if ( itemElem.isNull() )
425  {
426  return false;
427  }
428 
429  //restore label specific properties
430 
431  //text
432  mText = itemElem.attribute( "labelText" );
433 
434  //html state
435  mHtmlState = itemElem.attribute( "htmlState" ).toInt();
436 
437  //margin
438  bool marginXOk = false;
439  bool marginYOk = false;
440  mMarginX = itemElem.attribute( "marginX" ).toDouble( &marginXOk );
441  mMarginY = itemElem.attribute( "marginY" ).toDouble( &marginYOk );
442  if ( !marginXOk || !marginYOk )
443  {
444  //upgrade old projects where margins where stored in a single attribute
445  double margin = itemElem.attribute( "margin", "1.0" ).toDouble();
446  mMarginX = margin;
447  mMarginY = margin;
448  }
449 
450  //Horizontal alignment
451  mHAlignment = ( Qt::AlignmentFlag )( itemElem.attribute( "halign" ).toInt() );
452 
453  //Vertical alignment
454  mVAlignment = ( Qt::AlignmentFlag )( itemElem.attribute( "valign" ).toInt() );
455 
456  //font
457  QgsFontUtils::setFromXmlChildNode( mFont, itemElem, "LabelFont" );
458 
459  //font color
460  QDomNodeList fontColorList = itemElem.elementsByTagName( "FontColor" );
461  if ( fontColorList.size() > 0 )
462  {
463  QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
464  int red = fontColorElem.attribute( "red", "0" ).toInt();
465  int green = fontColorElem.attribute( "green", "0" ).toInt();
466  int blue = fontColorElem.attribute( "blue", "0" ).toInt();
467  mFontColor = QColor( red, green, blue );
468  }
469  else
470  {
471  mFontColor = QColor( 0, 0, 0 );
472  }
473 
474  //restore general composer item properties
475  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
476  if ( composerItemList.size() > 0 )
477  {
478  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
479 
480  //rotation
481  if ( composerItemElem.attribute( "rotation", "0" ).toDouble() != 0 )
482  {
483  //check for old (pre 2.1) rotation attribute
484  setItemRotation( composerItemElem.attribute( "rotation", "0" ).toDouble() );
485  }
486 
487  _readXML( composerItemElem, doc );
488  }
489  emit itemChanged();
490  return true;
491 }
492 
494 {
495  if ( !id().isEmpty() )
496  {
497  return id();
498  }
499 
500  if ( mHtmlState )
501  {
502  return tr( "<HTML label>" );
503  }
504 
505  //if no id, default to portion of label text
506  QString text = mText;
507  if ( text.isEmpty() )
508  {
509  return tr( "<label>" );
510  }
511  if ( text.length() > 25 )
512  {
513  return QString( tr( "%1..." ) ).arg( text.left( 25 ).simplified() );
514  }
515  else
516  {
517  return text.simplified();
518  }
519 }
520 
522 {
523  QRectF rectangle = rect();
524  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
525  rectangle.adjust( -penWidth, -penWidth, penWidth, penWidth );
526 
527  if ( mMarginX < 0 )
528  {
529  rectangle.adjust( mMarginX, 0, -mMarginX, 0 );
530  }
531  if ( mMarginY < 0 )
532  {
533  rectangle.adjust( 0, mMarginY, 0, -mMarginY );
534  }
535 
536  return rectangle;
537 }
538 
539 void QgsComposerLabel::setFrameEnabled( const bool drawFrame )
540 {
543 }
544 
545 void QgsComposerLabel::setFrameOutlineWidth( const double outlineWidth )
546 {
549 }
550 
551 void QgsComposerLabel::itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const
552 {
553  //keep alignment point constant
554  double currentWidth = rect().width();
555  double currentHeight = rect().height();
556  xShift = 0;
557  yShift = 0;
558 
559  if ( mItemRotation >= 0 && mItemRotation < 90 )
560  {
561  if ( mHAlignment == Qt::AlignHCenter )
562  {
563  xShift = - ( newWidth - currentWidth ) / 2.0;
564  }
565  else if ( mHAlignment == Qt::AlignRight )
566  {
567  xShift = - ( newWidth - currentWidth );
568  }
569  if ( mVAlignment == Qt::AlignVCenter )
570  {
571  yShift = -( newHeight - currentHeight ) / 2.0;
572  }
573  else if ( mVAlignment == Qt::AlignBottom )
574  {
575  yShift = - ( newHeight - currentHeight );
576  }
577  }
578  if ( mItemRotation >= 90 && mItemRotation < 180 )
579  {
580  if ( mHAlignment == Qt::AlignHCenter )
581  {
582  yShift = -( newHeight - currentHeight ) / 2.0;
583  }
584  else if ( mHAlignment == Qt::AlignRight )
585  {
586  yShift = -( newHeight - currentHeight );
587  }
588  if ( mVAlignment == Qt::AlignTop )
589  {
590  xShift = -( newWidth - currentWidth );
591  }
592  else if ( mVAlignment == Qt::AlignVCenter )
593  {
594  xShift = -( newWidth - currentWidth / 2.0 );
595  }
596  }
597  else if ( mItemRotation >= 180 && mItemRotation < 270 )
598  {
599  if ( mHAlignment == Qt::AlignHCenter )
600  {
601  xShift = -( newWidth - currentWidth ) / 2.0;
602  }
603  else if ( mHAlignment == Qt::AlignLeft )
604  {
605  xShift = -( newWidth - currentWidth );
606  }
607  if ( mVAlignment == Qt::AlignVCenter )
608  {
609  yShift = ( newHeight - currentHeight ) / 2.0;
610  }
611  else if ( mVAlignment == Qt::AlignTop )
612  {
613  yShift = ( newHeight - currentHeight );
614  }
615  }
616  else if ( mItemRotation >= 270 && mItemRotation < 360 )
617  {
618  if ( mHAlignment == Qt::AlignHCenter )
619  {
620  yShift = -( newHeight - currentHeight ) / 2.0;
621  }
622  else if ( mHAlignment == Qt::AlignLeft )
623  {
624  yShift = -( newHeight - currentHeight );
625  }
626  if ( mVAlignment == Qt::AlignBottom )
627  {
628  xShift = -( newWidth - currentWidth );
629  }
630  else if ( mVAlignment == Qt::AlignVCenter )
631  {
632  xShift = -( newWidth - currentWidth / 2.0 );
633  }
634  }
635 }
void setBrush(ColorRole role, const QBrush &brush)
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
void setSubstitutions(const QMap< QString, QVariant > &substitutions=(QMap< QString, QVariant >()))
Sets the list of local variable substitutions for evaluating expressions in label text...
QgsComposerModel * itemsModel()
Returns the items model attached to the composition.
QgsFields fields() const
Returns the list of fields of this layer.
long srsid() const
Get the SrsId - if possible.
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:176
double toDouble(bool *ok) const
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the objects's current state.
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:75
void reset(T *other)
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)
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
Q_DECL_DEPRECATED void setExpressionContext(QgsFeature *feature, QgsVectorLayer *layer, const QMap< QString, QVariant > &substitutions=(QMap< QString, QVariant >()))
Sets the current feature, the current layer and a list of local variable substitutions for evaluating...
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
int toInt(bool *ok, int base) const
bool isEmpty() const
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=0)
Evaluates an item's bounding rect to consider data defined position and size of item and reference po...
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.
T * data() const
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
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.
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:353
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()
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
char * toString(const QLatin1String &string)
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 Q_DECL_DEPRECATED 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)