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