QGIS API Documentation  2.11.0-Master
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 : 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 
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  subs[ "$page" ] = QVariant(( int )mComposition->itemPageNumber( this ) + 1 );
301 
303  //overwrite layer/feature if they have been set via setExpressionContext
304  //TODO remove when setExpressionContext is removed
305  if ( mExpressionFeature.data() )
306  context->setFeature( *mExpressionFeature.data() );
307  if ( mExpressionLayer )
308  context->setFields( mExpressionLayer->fields() );
309 
310  return QgsExpression::replaceExpressionText( displayText, context.data(), &subs, mDistanceArea );
311 }
312 
313 void QgsComposerLabel::replaceDateText( QString& text ) const
314 {
315  QString constant = "$CURRENT_DATE";
316  int currentDatePos = text.indexOf( constant );
317  if ( currentDatePos != -1 )
318  {
319  //check if there is a bracket just after $CURRENT_DATE
320  QString formatText;
321  int openingBracketPos = text.indexOf( "(", currentDatePos );
322  int closingBracketPos = text.indexOf( ")", openingBracketPos + 1 );
323  if ( openingBracketPos != -1 &&
324  closingBracketPos != -1 &&
325  ( closingBracketPos - openingBracketPos ) > 1 &&
326  openingBracketPos == currentDatePos + constant.size() )
327  {
328  formatText = text.mid( openingBracketPos + 1, closingBracketPos - openingBracketPos - 1 );
329  text.replace( currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString( formatText ) );
330  }
331  else //no bracket
332  {
333  text.replace( "$CURRENT_DATE", QDate::currentDate().toString() );
334  }
335  }
336 }
337 
339 {
340  mFont = f;
341 }
342 
343 void QgsComposerLabel::setMargin( const double m )
344 {
345  mMarginX = m;
346  mMarginY = m;
348 }
349 
350 void QgsComposerLabel::setMarginX( const double margin )
351 {
352  mMarginX = margin;
354 }
355 
356 void QgsComposerLabel::setMarginY( const double margin )
357 {
358  mMarginY = margin;
360 }
361 
363 {
364  double textWidth = QgsComposerUtils::textWidthMM( mFont, displayText() );
365  double fontHeight = QgsComposerUtils::fontHeightMM( mFont );
366 
367  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
368 
369  double width = textWidth + 2 * mMarginX + 2 * penWidth + 1;
370  double height = fontHeight + 2 * mMarginY + 2 * penWidth;
371 
372  //keep alignment point constant
373  double xShift = 0;
374  double yShift = 0;
375  itemShiftAdjustSize( width, height, xShift, yShift );
376 
377  //update rect for data defined size and position
378  QRectF evaluatedRect = evalItemRect( QRectF( pos().x() + xShift, pos().y() + yShift, width, height ) );
379  setSceneRect( evaluatedRect );
380 }
381 
383 {
384  return mFont;
385 }
386 
388 {
389  QString alignment;
390 
391  if ( elem.isNull() )
392  {
393  return false;
394  }
395 
396  QDomElement composerLabelElem = doc.createElement( "ComposerLabel" );
397 
398  composerLabelElem.setAttribute( "htmlState", mHtmlState );
399 
400  composerLabelElem.setAttribute( "labelText", mText );
401  composerLabelElem.setAttribute( "marginX", QString::number( mMarginX ) );
402  composerLabelElem.setAttribute( "marginY", QString::number( mMarginY ) );
403  composerLabelElem.setAttribute( "halign", mHAlignment );
404  composerLabelElem.setAttribute( "valign", mVAlignment );
405 
406  //font
407  QDomElement labelFontElem = QgsFontUtils::toXmlElement( mFont, doc, "LabelFont" );
408  composerLabelElem.appendChild( labelFontElem );
409 
410  //font color
411  QDomElement fontColorElem = doc.createElement( "FontColor" );
412  fontColorElem.setAttribute( "red", mFontColor.red() );
413  fontColorElem.setAttribute( "green", mFontColor.green() );
414  fontColorElem.setAttribute( "blue", mFontColor.blue() );
415  composerLabelElem.appendChild( fontColorElem );
416 
417  elem.appendChild( composerLabelElem );
418  return _writeXML( composerLabelElem, doc );
419 }
420 
421 bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument& doc )
422 {
423  QString alignment;
424 
425  if ( itemElem.isNull() )
426  {
427  return false;
428  }
429 
430  //restore label specific properties
431 
432  //text
433  mText = itemElem.attribute( "labelText" );
434 
435  //html state
436  mHtmlState = itemElem.attribute( "htmlState" ).toInt();
437 
438  //margin
439  bool marginXOk = false;
440  bool marginYOk = false;
441  mMarginX = itemElem.attribute( "marginX" ).toDouble( &marginXOk );
442  mMarginY = itemElem.attribute( "marginY" ).toDouble( &marginYOk );
443  if ( !marginXOk || !marginYOk )
444  {
445  //upgrade old projects where margins where stored in a single attribute
446  double margin = itemElem.attribute( "margin", "1.0" ).toDouble();
447  mMarginX = margin;
448  mMarginY = margin;
449  }
450 
451  //Horizontal alignment
452  mHAlignment = ( Qt::AlignmentFlag )( itemElem.attribute( "halign" ).toInt() );
453 
454  //Vertical alignment
455  mVAlignment = ( Qt::AlignmentFlag )( itemElem.attribute( "valign" ).toInt() );
456 
457  //font
458  QgsFontUtils::setFromXmlChildNode( mFont, itemElem, "LabelFont" );
459 
460  //font color
461  QDomNodeList fontColorList = itemElem.elementsByTagName( "FontColor" );
462  if ( fontColorList.size() > 0 )
463  {
464  QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
465  int red = fontColorElem.attribute( "red", "0" ).toInt();
466  int green = fontColorElem.attribute( "green", "0" ).toInt();
467  int blue = fontColorElem.attribute( "blue", "0" ).toInt();
468  mFontColor = QColor( red, green, blue );
469  }
470  else
471  {
472  mFontColor = QColor( 0, 0, 0 );
473  }
474 
475  //restore general composer item properties
476  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
477  if ( composerItemList.size() > 0 )
478  {
479  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
480 
481  //rotation
482  if ( composerItemElem.attribute( "rotation", "0" ).toDouble() != 0 )
483  {
484  //check for old (pre 2.1) rotation attribute
485  setItemRotation( composerItemElem.attribute( "rotation", "0" ).toDouble() );
486  }
487 
488  _readXML( composerItemElem, doc );
489  }
490  emit itemChanged();
491  return true;
492 }
493 
495 {
496  if ( !id().isEmpty() )
497  {
498  return id();
499  }
500 
501  if ( mHtmlState )
502  {
503  return tr( "<HTML label>" );
504  }
505 
506  //if no id, default to portion of label text
507  QString text = mText;
508  if ( text.isEmpty() )
509  {
510  return tr( "<label>" );
511  }
512  if ( text.length() > 25 )
513  {
514  return QString( tr( "%1..." ) ).arg( text.left( 25 ).simplified() );
515  }
516  else
517  {
518  return text.simplified();
519  }
520 }
521 
523 {
524  QRectF rectangle = rect();
525  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
526  rectangle.adjust( -penWidth, -penWidth, penWidth, penWidth );
527 
528  if ( mMarginX < 0 )
529  {
530  rectangle.adjust( mMarginX, 0, -mMarginX, 0 );
531  }
532  if ( mMarginY < 0 )
533  {
534  rectangle.adjust( 0, mMarginY, 0, -mMarginY );
535  }
536 
537  return rectangle;
538 }
539 
540 void QgsComposerLabel::setFrameEnabled( const bool drawFrame )
541 {
544 }
545 
546 void QgsComposerLabel::setFrameOutlineWidth( const double outlineWidth )
547 {
550 }
551 
552 void QgsComposerLabel::itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const
553 {
554  //keep alignment point constant
555  double currentWidth = rect().width();
556  double currentHeight = rect().height();
557  xShift = 0;
558  yShift = 0;
559 
560  if ( mItemRotation >= 0 && mItemRotation < 90 )
561  {
562  if ( mHAlignment == Qt::AlignHCenter )
563  {
564  xShift = - ( newWidth - currentWidth ) / 2.0;
565  }
566  else if ( mHAlignment == Qt::AlignRight )
567  {
568  xShift = - ( newWidth - currentWidth );
569  }
570  if ( mVAlignment == Qt::AlignVCenter )
571  {
572  yShift = -( newHeight - currentHeight ) / 2.0;
573  }
574  else if ( mVAlignment == Qt::AlignBottom )
575  {
576  yShift = - ( newHeight - currentHeight );
577  }
578  }
579  if ( mItemRotation >= 90 && mItemRotation < 180 )
580  {
581  if ( mHAlignment == Qt::AlignHCenter )
582  {
583  yShift = -( newHeight - currentHeight ) / 2.0;
584  }
585  else if ( mHAlignment == Qt::AlignRight )
586  {
587  yShift = -( newHeight - currentHeight );
588  }
589  if ( mVAlignment == Qt::AlignTop )
590  {
591  xShift = -( newWidth - currentWidth );
592  }
593  else if ( mVAlignment == Qt::AlignVCenter )
594  {
595  xShift = -( newWidth - currentWidth / 2.0 );
596  }
597  }
598  else if ( mItemRotation >= 180 && mItemRotation < 270 )
599  {
600  if ( mHAlignment == Qt::AlignHCenter )
601  {
602  xShift = -( newWidth - currentWidth ) / 2.0;
603  }
604  else if ( mHAlignment == Qt::AlignLeft )
605  {
606  xShift = -( newWidth - currentWidth );
607  }
608  if ( mVAlignment == Qt::AlignVCenter )
609  {
610  yShift = ( newHeight - currentHeight ) / 2.0;
611  }
612  else if ( mVAlignment == Qt::AlignTop )
613  {
614  yShift = ( newHeight - currentHeight );
615  }
616  }
617  else if ( mItemRotation >= 270 && mItemRotation < 360 )
618  {
619  if ( mHAlignment == Qt::AlignHCenter )
620  {
621  yShift = -( newHeight - currentHeight ) / 2.0;
622  }
623  else if ( mHAlignment == Qt::AlignLeft )
624  {
625  yShift = -( newHeight - currentHeight );
626  }
627  if ( mVAlignment == Qt::AlignBottom )
628  {
629  xShift = -( newWidth - currentWidth );
630  }
631  else if ( mVAlignment == Qt::AlignVCenter )
632  {
633  xShift = -( newWidth - currentWidth / 2.0 );
634  }
635  }
636 }
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
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:162
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:74
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)
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
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
void setSubstitutions(QMap< QString, QVariant > substitutions=(QMap< QString, QVariant >()))
Sets the list of local variable substitutions for evaluating expressions in label text...
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:352
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()
Q_DECL_DEPRECATED 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
QChar * data()
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)