QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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( nullptr )
53  , mDistanceArea( nullptr )
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  mWebPage = new QgsWebPage( this );
84  mWebPage->setIdentifier( tr( "Composer label item" ) );
85  mWebPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() );
86 
87  //This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/
88  QPalette palette = mWebPage->palette();
89  palette.setBrush( QPalette::Base, Qt::transparent );
90  mWebPage->setPalette( palette );
91  //webPage->setAttribute(Qt::WA_OpaquePaintEvent, false); //this does not compile, why ?
92 
93  mWebPage->mainFrame()->setZoomFactor( 10.0 );
94  mWebPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
95  mWebPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
96 
97  connect( mWebPage, SIGNAL( loadFinished( bool ) ), SLOT( loadingHtmlFinished( bool ) ) );
98 }
99 
101 {
102  delete mDistanceArea;
103  delete mWebPage;
104 }
105 
106 void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
107 {
108  Q_UNUSED( itemStyle );
109  Q_UNUSED( pWidget );
110  if ( !painter )
111  {
112  return;
113  }
114  if ( !shouldDrawItem() )
115  {
116  return;
117  }
118 
119  drawBackground( painter );
120  painter->save();
121 
122  //antialiasing on
123  painter->setRenderHint( QPainter::Antialiasing, true );
124 
125  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
126  double xPenAdjust = mMarginX < 0 ? -penWidth : penWidth;
127  double yPenAdjust = mMarginY < 0 ? -penWidth : penWidth;
128  QRectF painterRect( xPenAdjust + mMarginX, yPenAdjust + mMarginY, rect().width() - 2 * xPenAdjust - 2 * mMarginX, rect().height() - 2 * yPenAdjust - 2 * mMarginY );
129 
130  if ( mHtmlState )
131  {
132  painter->scale( 1.0 / mHtmlUnitsToMM / 10.0, 1.0 / mHtmlUnitsToMM / 10.0 );
133  mWebPage->setViewportSize( QSize( painterRect.width() * mHtmlUnitsToMM * 10.0, painterRect.height() * mHtmlUnitsToMM * 10.0 ) );
134  mWebPage->settings()->setUserStyleSheetUrl( createStylesheetUrl() );
135  mWebPage->mainFrame()->render( painter );
136  }
137  else
138  {
139  const QString textToDraw = displayText();
140  painter->setFont( mFont );
141  //debug
142  //painter->setPen( QColor( Qt::red ) );
143  //painter->drawRect( painterRect );
144  QgsComposerUtils::drawText( painter, painterRect, textToDraw, mFont, mFontColor, mHAlignment, mVAlignment, Qt::TextWordWrap );
145  }
146 
147  painter->restore();
148 
149  drawFrame( painter );
150  if ( isSelected() )
151  {
152  drawSelectionBoxes( painter );
153  }
154 }
155 
156 void QgsComposerLabel::contentChanged()
157 {
158  if ( mHtmlState )
159  {
160  const QString textToDraw = displayText();
161 
162  //mHtmlLoaded tracks whether the QWebPage has completed loading
163  //its html contents, set it initially to false. The loadingHtmlFinished slot will
164  //set this to true after html is loaded.
165  mHtmlLoaded = false;
166 
167  const QUrl baseUrl = QUrl::fromLocalFile( QgsProject::instance()->fileInfo().absoluteFilePath() );
168  mWebPage->mainFrame()->setHtml( textToDraw, baseUrl );
169 
170  //For very basic html labels with no external assets, the html load will already be
171  //complete before we even get a chance to start the QEventLoop. Make sure we check
172  //this before starting the loop
173  if ( !mHtmlLoaded )
174  {
175  //Setup event loop and timeout for rendering html
176  QEventLoop loop;
177 
178  //Connect timeout and webpage loadFinished signals to loop
179  connect( mWebPage, SIGNAL( loadFinished( bool ) ), &loop, SLOT( quit() ) );
180 
181  // Start a 20 second timeout in case html loading will never complete
182  QTimer timeoutTimer;
183  timeoutTimer.setSingleShot( true );
184  connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
185  timeoutTimer.start( 20000 );
186 
187  // Pause until html is loaded
188  loop.exec();
189  }
190  }
191 }
192 
193 /*Track when QWebPage has finished loading its html contents*/
194 void QgsComposerLabel::loadingHtmlFinished( bool result )
195 {
196  Q_UNUSED( result );
197  mHtmlLoaded = true;
198 }
199 
200 double QgsComposerLabel::htmlUnitsToMM()
201 {
202  if ( !mComposition )
203  {
204  return 1.0;
205  }
206 
207  //TODO : fix this more precisely so that the label's default text size is the same with or without "display as html"
208  return ( mComposition->printResolution() / 72.0 ); //webkit seems to assume a standard dpi of 72
209 }
210 
212 {
213  mText = text;
214  emit itemChanged();
215 
216  contentChanged();
217 
218  if ( mComposition && id().isEmpty() && !mHtmlState )
219  {
220  //notify the model that the display name has changed
222  }
223 }
224 
226 {
227  if ( state == mHtmlState )
228  {
229  return;
230  }
231 
232  mHtmlState = state;
233  contentChanged();
234 
235  if ( mComposition && id().isEmpty() )
236  {
237  //notify the model that the display name has changed
239  }
240 }
241 
243 {
244  mExpressionFeature.reset( feature ? new QgsFeature( *feature ) : nullptr );
245  mExpressionLayer = layer;
246  mSubstitutions = substitutions;
247 
248  //setup distance area conversion
249  if ( layer )
250  {
251  mDistanceArea->setSourceCrs( layer->crs().srsid() );
252  }
253  else if ( mComposition )
254  {
255  //set to composition's mapsettings' crs
256  mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
257  }
258  if ( mComposition )
259  {
261  }
262  mDistanceArea->setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
263  contentChanged();
264 
265  // Force label to redraw -- fixes label printing for labels with blend modes when used with atlas
266  update();
267 }
268 
270 {
271  mSubstitutions = substitutions;
272 }
273 
275 {
276  mExpressionLayer = nullptr;
277  mExpressionFeature.reset();
278 
279  if ( !mComposition )
280  return;
281 
282  QgsVectorLayer* layer = nullptr;
284  {
286  }
287 
288  //setup distance area conversion
289  if ( layer )
290  {
291  mDistanceArea->setSourceCrs( layer->crs().srsid() );
292  }
293  else
294  {
295  //set to composition's mapsettings' crs
296  mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
297  }
299  mDistanceArea->setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
300  contentChanged();
301 
302  update();
303 }
304 
306 {
307  QString displayText = mText;
308  replaceDateText( displayText );
309  QMap<QString, QVariant> subs = mSubstitutions;
310 
312  //overwrite layer/feature if they have been set via setExpressionContext
313  //TODO remove when setExpressionContext is removed
314  if ( mExpressionFeature.data() )
315  context->setFeature( *mExpressionFeature.data() );
316  if ( mExpressionLayer )
317  context->setFields( mExpressionLayer->fields() );
318 
319  return QgsExpression::replaceExpressionText( displayText, context.data(), &subs, mDistanceArea );
320 }
321 
322 void QgsComposerLabel::replaceDateText( QString& text ) const
323 {
324  QString constant = "$CURRENT_DATE";
325  int currentDatePos = text.indexOf( constant );
326  if ( currentDatePos != -1 )
327  {
328  //check if there is a bracket just after $CURRENT_DATE
329  QString formatText;
330  int openingBracketPos = text.indexOf( '(', currentDatePos );
331  int closingBracketPos = text.indexOf( ')', openingBracketPos + 1 );
332  if ( openingBracketPos != -1 &&
333  closingBracketPos != -1 &&
334  ( closingBracketPos - openingBracketPos ) > 1 &&
335  openingBracketPos == currentDatePos + constant.size() )
336  {
337  formatText = text.mid( openingBracketPos + 1, closingBracketPos - openingBracketPos - 1 );
338  text.replace( currentDatePos, closingBracketPos - currentDatePos + 1, QDate::currentDate().toString( formatText ) );
339  }
340  else //no bracket
341  {
342  text.replace( "$CURRENT_DATE", QDate::currentDate().toString() );
343  }
344  }
345 }
346 
348 {
349  mFont = f;
350 }
351 
352 void QgsComposerLabel::setMargin( const double m )
353 {
354  mMarginX = m;
355  mMarginY = m;
357 }
358 
360 {
361  mMarginX = margin;
363 }
364 
366 {
367  mMarginY = margin;
369 }
370 
372 {
373  double textWidth = QgsComposerUtils::textWidthMM( mFont, displayText() );
374  double fontHeight = QgsComposerUtils::fontHeightMM( mFont );
375 
376  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
377 
378  double width = textWidth + 2 * mMarginX + 2 * penWidth + 1;
379  double height = fontHeight + 2 * mMarginY + 2 * penWidth;
380 
381  //keep alignment point constant
382  double xShift = 0;
383  double yShift = 0;
384  itemShiftAdjustSize( width, height, xShift, yShift );
385 
386  //update rect for data defined size and position
387  QRectF evaluatedRect = evalItemRect( QRectF( pos().x() + xShift, pos().y() + yShift, width, height ) );
388  setSceneRect( evaluatedRect );
389 }
390 
392 {
393  return mFont;
394 }
395 
397 {
398  if ( elem.isNull() )
399  {
400  return false;
401  }
402 
403  QDomElement composerLabelElem = doc.createElement( "ComposerLabel" );
404 
405  composerLabelElem.setAttribute( "htmlState", mHtmlState );
406 
407  composerLabelElem.setAttribute( "labelText", mText );
408  composerLabelElem.setAttribute( "marginX", QString::number( mMarginX ) );
409  composerLabelElem.setAttribute( "marginY", QString::number( mMarginY ) );
410  composerLabelElem.setAttribute( "halign", mHAlignment );
411  composerLabelElem.setAttribute( "valign", mVAlignment );
412 
413  //font
414  QDomElement labelFontElem = QgsFontUtils::toXmlElement( mFont, doc, "LabelFont" );
415  composerLabelElem.appendChild( labelFontElem );
416 
417  //font color
418  QDomElement fontColorElem = doc.createElement( "FontColor" );
419  fontColorElem.setAttribute( "red", mFontColor.red() );
420  fontColorElem.setAttribute( "green", mFontColor.green() );
421  fontColorElem.setAttribute( "blue", mFontColor.blue() );
422  composerLabelElem.appendChild( fontColorElem );
423 
424  elem.appendChild( composerLabelElem );
425  return _writeXML( composerLabelElem, doc );
426 }
427 
428 bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument& doc )
429 {
430  if ( itemElem.isNull() )
431  {
432  return false;
433  }
434 
435  //restore label specific properties
436 
437  //text
438  mText = itemElem.attribute( "labelText" );
439 
440  //html state
441  mHtmlState = itemElem.attribute( "htmlState" ).toInt();
442 
443  //margin
444  bool marginXOk = false;
445  bool marginYOk = false;
446  mMarginX = itemElem.attribute( "marginX" ).toDouble( &marginXOk );
447  mMarginY = itemElem.attribute( "marginY" ).toDouble( &marginYOk );
448  if ( !marginXOk || !marginYOk )
449  {
450  //upgrade old projects where margins where stored in a single attribute
451  double margin = itemElem.attribute( "margin", "1.0" ).toDouble();
452  mMarginX = margin;
453  mMarginY = margin;
454  }
455 
456  //Horizontal alignment
457  mHAlignment = static_cast< Qt::AlignmentFlag >( itemElem.attribute( "halign" ).toInt() );
458 
459  //Vertical alignment
460  mVAlignment = static_cast< Qt::AlignmentFlag >( itemElem.attribute( "valign" ).toInt() );
461 
462  //font
463  QgsFontUtils::setFromXmlChildNode( mFont, itemElem, "LabelFont" );
464 
465  //font color
466  QDomNodeList fontColorList = itemElem.elementsByTagName( "FontColor" );
467  if ( !fontColorList.isEmpty() )
468  {
469  QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
470  int red = fontColorElem.attribute( "red", "0" ).toInt();
471  int green = fontColorElem.attribute( "green", "0" ).toInt();
472  int blue = fontColorElem.attribute( "blue", "0" ).toInt();
473  mFontColor = QColor( red, green, blue );
474  }
475  else
476  {
477  mFontColor = QColor( 0, 0, 0 );
478  }
479 
480  //restore general composer item properties
481  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
482  if ( !composerItemList.isEmpty() )
483  {
484  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
485 
486  //rotation
487  if ( !qgsDoubleNear( composerItemElem.attribute( "rotation", "0" ).toDouble(), 0.0 ) )
488  {
489  //check for old (pre 2.1) rotation attribute
490  setItemRotation( composerItemElem.attribute( "rotation", "0" ).toDouble() );
491  }
492 
493  _readXML( composerItemElem, doc );
494  }
495  emit itemChanged();
496  contentChanged();
497  return true;
498 }
499 
501 {
502  if ( !id().isEmpty() )
503  {
504  return id();
505  }
506 
507  if ( mHtmlState )
508  {
509  return tr( "<HTML label>" );
510  }
511 
512  //if no id, default to portion of label text
513  QString text = mText;
514  if ( text.isEmpty() )
515  {
516  return tr( "<label>" );
517  }
518  if ( text.length() > 25 )
519  {
520  return QString( tr( "%1..." ) ).arg( text.left( 25 ).simplified() );
521  }
522  else
523  {
524  return text.simplified();
525  }
526 }
527 
529 {
530  QRectF rectangle = rect();
531  double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0;
532  rectangle.adjust( -penWidth, -penWidth, penWidth, penWidth );
533 
534  if ( mMarginX < 0 )
535  {
536  rectangle.adjust( mMarginX, 0, -mMarginX, 0 );
537  }
538  if ( mMarginY < 0 )
539  {
540  rectangle.adjust( 0, mMarginY, 0, -mMarginY );
541  }
542 
543  return rectangle;
544 }
545 
547 {
550 }
551 
552 void QgsComposerLabel::setFrameOutlineWidth( const double outlineWidth )
553 {
556 }
557 
558 void QgsComposerLabel::itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const
559 {
560  //keep alignment point constant
561  double currentWidth = rect().width();
562  double currentHeight = rect().height();
563  xShift = 0;
564  yShift = 0;
565 
566  if ( mItemRotation >= 0 && mItemRotation < 90 )
567  {
568  if ( mHAlignment == Qt::AlignHCenter )
569  {
570  xShift = - ( newWidth - currentWidth ) / 2.0;
571  }
572  else if ( mHAlignment == Qt::AlignRight )
573  {
574  xShift = - ( newWidth - currentWidth );
575  }
576  if ( mVAlignment == Qt::AlignVCenter )
577  {
578  yShift = -( newHeight - currentHeight ) / 2.0;
579  }
580  else if ( mVAlignment == Qt::AlignBottom )
581  {
582  yShift = - ( newHeight - currentHeight );
583  }
584  }
585  if ( mItemRotation >= 90 && mItemRotation < 180 )
586  {
587  if ( mHAlignment == Qt::AlignHCenter )
588  {
589  yShift = -( newHeight - currentHeight ) / 2.0;
590  }
591  else if ( mHAlignment == Qt::AlignRight )
592  {
593  yShift = -( newHeight - currentHeight );
594  }
595  if ( mVAlignment == Qt::AlignTop )
596  {
597  xShift = -( newWidth - currentWidth );
598  }
599  else if ( mVAlignment == Qt::AlignVCenter )
600  {
601  xShift = -( newWidth - currentWidth / 2.0 );
602  }
603  }
604  else if ( mItemRotation >= 180 && mItemRotation < 270 )
605  {
606  if ( mHAlignment == Qt::AlignHCenter )
607  {
608  xShift = -( newWidth - currentWidth ) / 2.0;
609  }
610  else if ( mHAlignment == Qt::AlignLeft )
611  {
612  xShift = -( newWidth - currentWidth );
613  }
614  if ( mVAlignment == Qt::AlignVCenter )
615  {
616  yShift = ( newHeight - currentHeight ) / 2.0;
617  }
618  else if ( mVAlignment == Qt::AlignTop )
619  {
620  yShift = ( newHeight - currentHeight );
621  }
622  }
623  else if ( mItemRotation >= 270 && mItemRotation < 360 )
624  {
625  if ( mHAlignment == Qt::AlignHCenter )
626  {
627  yShift = -( newHeight - currentHeight ) / 2.0;
628  }
629  else if ( mHAlignment == Qt::AlignLeft )
630  {
631  yShift = -( newHeight - currentHeight );
632  }
633  if ( mVAlignment == Qt::AlignBottom )
634  {
635  xShift = -( newWidth - currentWidth );
636  }
637  else if ( mVAlignment == Qt::AlignVCenter )
638  {
639  xShift = -( newWidth - currentWidth / 2.0 );
640  }
641  }
642 }
643 
644 QUrl QgsComposerLabel::createStylesheetUrl() const
645 {
646  QString stylesheet;
647  stylesheet += QString( "body { margin: %1 %2;" ).arg( qMax( mMarginY * mHtmlUnitsToMM, 0.0 ) ).arg( qMax( mMarginX * mHtmlUnitsToMM, 0.0 ) );
648  stylesheet += QgsFontUtils::asCSS( mFont, 0.352778 * mHtmlUnitsToMM );
649  stylesheet += QString( "color: %1;" ).arg( mFontColor.name() );
650  stylesheet += QString( "text-align: %1; }" ).arg( mHAlignment == Qt::AlignLeft ? "left" : mHAlignment == Qt::AlignRight ? "right" : "center" );
651 
652  QByteArray ba;
653  ba.append( stylesheet.toUtf8() );
654  QUrl cssFileURL = QUrl( "data:text/css;charset=utf-8;base64," + ba.toBase64() );
655 
656  return cssFileURL;
657 }
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.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
QString name() const
QString displayText() const
Returns the text as it appears on screen (with replaced data field)
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.
void itemChanged()
Emitted when the item changes.
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
int printResolution() const
void scale(qreal sx, qreal sy)
const QgsCoordinateReferenceSystem & crs() const
Returns layer&#39;s spatial reference system.
A item that forms part of a map composition.
int size() const
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=nullptr)
Evaluates an item&#39;s bounding rect to consider data defined position and size of item and reference po...
QString simplified() const
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
static void drawText(QPainter *painter, 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 ...
void save()
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:187
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
double toDouble(bool *ok) const
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the item&#39;s current state.
QString tr(const char *sourceText, const char *disambiguation, int n)
void adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:353
void update(const QRectF &rect)
void updateItemDisplayName(QgsComposerItem *item)
Must be called when an item&#39;s display name is modified.
const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
Definition: qgis.cpp:76
static QString asCSS(const QFont &font, double pointToPixelMultiplier=1.0)
Returns a CSS string representing the specified font as closely as possible.
void reset(T *other)
QgsFields fields() const
Returns the list of fields of this layer.
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
bool isEmpty() const
void setFont(const QFont &font)
QPointF pos() const
QString number(int n, int base)
void setHtml(const QString &html, const QUrl &baseUrl)
void setUserStyleSheetUrl(const QUrl &location)
int exec(QFlags< QEventLoop::ProcessEventsFlag > flags)
virtual void drawSelectionBoxes(QPainter *p)
Draws additional graphics on selected items.
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...
int toInt(bool *ok, int base) const
bool isEmpty() const
QWebFrame * mainFrame() const
QgsComposerLabel(QgsComposition *composition)
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.
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&#39;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.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
QByteArray & append(char ch)
T * data() const
int green() const
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
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.
QDate currentDate()
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:382
void setFamily(const QString &family)
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
static Q_DECL_DEPRECATED QString replaceExpressionText(const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=nullptr, const QgsDistanceArea *distanceArea=nullptr)
This function currently replaces each expression between [% and %] in the string with the result of i...
Q_DECL_DEPRECATED double margin()
Returns the margin between the edge of the frame and the label contents.
void start(int msec)
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
qreal height() const
QgsAtlasComposition & atlasComposition()
bool hasFrame() const
Whether this item has a frame or not.
QByteArray toBase64() const
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
QDomElement createElement(const QString &tagName)
long srsid() const
Returns the SrsId, if available.
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 id() const
Get item&#39;s id (which is not necessarly unique)
QWebPage subclass which redirects JavaScript errors and console output to the QGIS message log...
Definition: qgswebpage.h:211
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
double mItemRotation
Item rotation in degrees, clockwise.
bool enabled() const
Returns whether the atlas generation is enabled.
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.
QUrl fromLocalFile(const QString &localFile)
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.
QByteArray toUtf8() const
virtual void setFrameOutlineWidth(const double outlineWidth) override
Reimplemented to call prepareGeometryChange after changing outline width.