37#include <QDomDocument> 
   40#include <QImageReader> 
   42#include <QSvgRenderer> 
   43#include <QNetworkRequest> 
   44#include <QNetworkReply> 
   46#include <QCoreApplication> 
   91  const bool prevSmoothTransform = painter->testRenderHint( QPainter::RenderHint::SmoothPixmapTransform );
 
   93    painter->setRenderHint( QPainter::RenderHint::SmoothPixmapTransform, 
true );
 
   98    double boundRectWidthMM;
 
   99    double boundRectHeightMM;
 
  103      boundRectWidthMM = mPictureWidth;
 
  104      boundRectHeightMM = mPictureHeight;
 
  105      imageRect = QRect( 0, 0, mImage.width(), mImage.height() );
 
  109      boundRectWidthMM = rect().width();
 
  110      boundRectHeightMM = rect().height();
 
  111      imageRect = QRect( 0, 0, mImage.width(), mImage.height() );
 
  115      boundRectWidthMM = rect().width();
 
  116      boundRectHeightMM = rect().height();
 
  117      const int imageRectWidthPixels = mImage.width();
 
  118      const int imageRectHeightPixels = mImage.height();
 
  119      imageRect = clippedImageRect( boundRectWidthMM, boundRectHeightMM,
 
  120                                    QSize( imageRectWidthPixels, imageRectHeightPixels ) );
 
  124      boundRectWidthMM = rect().width();
 
  125      boundRectHeightMM = rect().height();
 
  131    if ( mResizeMode == 
Zoom )
 
  137        painter->translate( rect().width() / 2.0, rect().height() / 2.0 );
 
  138        painter->rotate( mPictureRotation );
 
  139        painter->translate( -boundRectWidthMM / 2.0, -boundRectHeightMM / 2.0 );
 
  144        const double diffX = rect().width() - boundRectWidthMM;
 
  145        const double diffY = rect().height() - boundRectHeightMM;
 
  149        switch ( mPictureAnchor )
 
  167        switch ( mPictureAnchor )
 
  185        painter->translate( dX, dY );
 
  192        painter->translate( rect().width() / 2.0, rect().height() / 2.0 );
 
  193        painter->rotate( mPictureRotation );
 
  194        painter->translate( -boundRectWidthMM / 2.0, -boundRectHeightMM / 2.0 );
 
  200      mSVG.render( painter, QRectF( 0, 0, boundRectWidthMM, boundRectHeightMM ) );
 
  204      painter->drawImage( QRectF( 0, 0, boundRectWidthMM, boundRectHeightMM ), mImage, imageRect );
 
  207  painter->setRenderHint( QPainter::RenderHint::SmoothPixmapTransform, prevSmoothTransform );
 
 
  212  const QSizeF currentPictureSize = pictureSize();
 
  213  QSizeF newSize = targetSize;
 
  216    mPictureWidth = targetSize.width();
 
  217    mPictureHeight = targetSize.height();
 
  221    if ( mResizeMode == 
ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) )
 
  223      QSizeF targetImageSize;
 
  226        targetImageSize = currentPictureSize;
 
  232        tr.rotate( mPictureRotation );
 
  233        const QRectF rotatedBounds = tr.mapRect( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ) );
 
  234        targetImageSize = QSizeF( rotatedBounds.width(), rotatedBounds.height() );
 
  239      if ( std::fabs( rect().width() - targetSize.width() ) <
 
  240           std::fabs( rect().height() - targetSize.height() ) )
 
  242        newSize.setHeight( targetImageSize.height() * newSize.width() / targetImageSize.width() );
 
  246        newSize.setWidth( targetImageSize.width() * newSize.height() / targetImageSize.height() );
 
  251      if ( !( currentPictureSize.isEmpty() ) )
 
  255        newSize.setHeight( sizeMM.
height() * 25.4 / 
mLayout->renderContext().dpi() );
 
  263                                      QRectF( 0, 0, newSize.width(), newSize.height() ), mPictureRotation );
 
  264      mPictureWidth = rotatedImageRect.width();
 
  265      mPictureHeight = rotatedImageRect.height();
 
  269      mPictureWidth = newSize.width();
 
  270      mPictureHeight = newSize.height();
 
  273    if ( newSize != targetSize )
 
 
  282QRect QgsLayoutItemPicture::clippedImageRect( 
double &boundRectWidthMM, 
double &boundRectHeightMM, QSize imageRectPixels )
 
  284  const int boundRectWidthPixels = boundRectWidthMM * 
mLayout->renderContext().dpi() / 25.4;
 
  285  const int boundRectHeightPixels = boundRectHeightMM * 
mLayout->renderContext().dpi() / 25.4;
 
  288  boundRectWidthMM = boundRectWidthPixels * 25.4 / 
mLayout->renderContext().dpi();
 
  289  boundRectHeightMM = boundRectHeightPixels * 25.4 / 
mLayout->renderContext().dpi();
 
  296  switch ( mPictureAnchor )
 
  306      leftClip = ( imageRectPixels.width() - boundRectWidthPixels ) / 2;
 
  311      leftClip = imageRectPixels.width() - boundRectWidthPixels;
 
  316  switch ( mPictureAnchor )
 
  326      topClip = ( imageRectPixels.height() - boundRectHeightPixels ) / 2;
 
  331      topClip = imageRectPixels.height() - boundRectHeightPixels;
 
  335  return QRect( leftClip, topClip, boundRectWidthPixels, boundRectHeightPixels );
 
  345  QVariant source( mSourcePath );
 
  348  mHasExpressionError = 
false;
 
  354    source = sourceProperty.
value( *evalContext, source, &ok );
 
  355    if ( !ok || !source.canConvert( QMetaType::QString ) )
 
  357      mHasExpressionError = 
true;
 
  364    else if ( source.userType() != QMetaType::Type::QByteArray )
 
  366      source = source.toString().trimmed();
 
  367      QgsDebugMsgLevel( QStringLiteral( 
"exprVal PictureSource:%1" ).arg( source.toString() ), 2 );
 
  371  loadPicture( source );
 
 
  374void QgsLayoutItemPicture::loadRemotePicture( 
const QString &url )
 
  384  loop.exec( QEventLoop::ExcludeUserInputEvents );
 
  386  QNetworkReply *reply = fetcher.
reply();
 
  389    QImageReader imageReader( reply );
 
  390    imageReader.setAutoTransform( 
true );
 
  392    if ( imageReader.format() == 
"pdf" )
 
  401      const QSize sizeAt72Dpi = imageReader.size();
 
  402      const QSize sizeAtTargetDpi = sizeAt72Dpi * 
mLayout->renderContext().dpi() / 72;
 
  403      imageReader.setScaledSize( sizeAtTargetDpi );
 
  406    mImage = imageReader.read();
 
  415void QgsLayoutItemPicture::loadLocalPicture( 
const QString &path )
 
  418  pic.setFileName( path );
 
  426    const QFileInfo sourceFileInfo( pic );
 
  427    const QString sourceFileSuffix = sourceFileInfo.suffix();
 
  428    if ( sourceFileSuffix.compare( QLatin1String( 
"svg" ), Qt::CaseInsensitive ) == 0 )
 
  438                                     1.0, 0, 
false, evaluatedParameters );
 
  439      mSVG.load( svgContent );
 
  440      if ( mSVG.isValid() )
 
  443        const QRect viewBox = mSVG.viewBox(); 
 
  444        mDefaultSvgSize.setWidth( viewBox.width() );
 
  445        mDefaultSvgSize.setHeight( viewBox.height() );
 
  455      QImageReader imageReader( pic.fileName() );
 
  456      imageReader.setAutoTransform( 
true );
 
  458      if ( imageReader.format() == 
"pdf" )
 
  467        const QSize sizeAt72Dpi = imageReader.size();
 
  468        const QSize sizeAtTargetDpi = sizeAt72Dpi * 
mLayout->renderContext().dpi() / 72;
 
  469        imageReader.setScaledSize( sizeAtTargetDpi );
 
  472      if ( imageReader.read( &mImage ) )
 
  484void QgsLayoutItemPicture::loadPictureUsingCache( 
const QString &path )
 
  486  if ( path.isEmpty() )
 
  489    mSVG.load( QByteArray() );
 
  500      bool fitsInCache = 
false;
 
  501      bool isMissing = 
false;
 
  503      if ( mImage.isNull() || isMissing )
 
  520      mSVG.load( svgContent );
 
  524        const QRect viewBox = mSVG.viewBox(); 
 
  525        mDefaultSvgSize.setWidth( viewBox.width() );
 
  526        mDefaultSvgSize.setHeight( viewBox.height() );
 
  537void QgsLayoutItemPicture::updateNorthArrowRotation( 
double rotation )
 
  543void QgsLayoutItemPicture::loadPicture( 
const QVariant &data )
 
  545  mIsMissingImage = 
false;
 
  546  QVariant imageData( data );
 
  547  mEvaluatedPath = data.toString();
 
  549  if ( mEvaluatedPath.startsWith( QLatin1String( 
"base64:" ), Qt::CaseInsensitive ) && mMode == 
FormatUnknown )
 
  551    const QByteArray base64 = mEvaluatedPath.mid( 7 ).toLocal8Bit(); 
 
  552    imageData = QByteArray::fromBase64( base64, QByteArray::OmitTrailingEquals );
 
  555  if ( imageData.userType() == QMetaType::Type::QByteArray )
 
  557    if ( mImage.loadFromData( imageData.toByteArray() ) )
 
  562  else if ( mMode == 
FormatUnknown  && mEvaluatedPath.startsWith( QLatin1String( 
"http" ) ) )
 
  565    loadRemotePicture( mEvaluatedPath );
 
  570    loadLocalPicture( mEvaluatedPath );
 
  574    loadPictureUsingCache( mEvaluatedPath );
 
  581  else if ( mHasExpressionError || !mEvaluatedPath.isEmpty() )
 
  584    mIsMissingImage = 
true;
 
  587      const QString badFile( QStringLiteral( 
":/images/composer/missing_image.png" ) );
 
  588      QImageReader imageReader( badFile );
 
  589      if ( imageReader.read( &mImage ) )
 
  594      const QString badFile( QStringLiteral( 
":/images/composer/missing_image.svg" ) );
 
  595      mSVG.load( badFile );
 
  596      if ( mSVG.isValid() )
 
  599        const QRect viewBox = mSVG.viewBox(); 
 
  600        mDefaultSvgSize.setWidth( viewBox.width() );
 
  601        mDefaultSvgSize.setHeight( viewBox.height() );
 
  611QRectF QgsLayoutItemPicture::boundedImageRect( 
double deviceWidth, 
double deviceHeight )
 
  613  double imageToDeviceRatio;
 
  614  if ( mImage.width() / deviceWidth > mImage.height() / deviceHeight )
 
  616    imageToDeviceRatio = deviceWidth / mImage.width();
 
  617    const double height = imageToDeviceRatio * mImage.height();
 
  618    return QRectF( 0, 0, deviceWidth, height );
 
  622    imageToDeviceRatio = deviceHeight / mImage.height();
 
  623    const double width = imageToDeviceRatio * mImage.width();
 
  624    return QRectF( 0, 0, width, deviceHeight );
 
  628QRectF QgsLayoutItemPicture::boundedSVGRect( 
double deviceWidth, 
double deviceHeight )
 
  630  double imageToSvgRatio;
 
  631  if ( deviceWidth / mDefaultSvgSize.width() > deviceHeight / mDefaultSvgSize.height() )
 
  633    imageToSvgRatio = deviceHeight / mDefaultSvgSize.height();
 
  634    const double width = mDefaultSvgSize.width() * imageToSvgRatio;
 
  635    return QRectF( 0, 0, width, deviceHeight );
 
  639    imageToSvgRatio = deviceWidth / mDefaultSvgSize.width();
 
  640    const double height = mDefaultSvgSize.height() * imageToSvgRatio;
 
  641    return QRectF( 0, 0, deviceWidth, height );
 
  645QSizeF QgsLayoutItemPicture::pictureSize()
 
  649    return mDefaultSvgSize;
 
  653    return QSizeF( mImage.width(), mImage.height() );
 
  657    return QSizeF( 0, 0 );
 
  663  return mIsMissingImage;
 
 
  668  return mEvaluatedPath;
 
 
  673  const QVariantMap parameters = 
mCustomProperties.
value( QStringLiteral( 
"svg-dynamic-parameters" ), QVariantMap() ).toMap();
 
 
  684void QgsLayoutItemPicture::shapeChanged()
 
  686  if ( mMode == 
FormatSVG && !mLoadingSvg )
 
  696  const double oldRotation = mPictureRotation;
 
  697  mPictureRotation = rotation;
 
  699  if ( mResizeMode == 
Zoom )
 
  702    const QSizeF currentPictureSize = pictureSize();
 
  704    mPictureWidth = rotatedImageRect.width();
 
  705    mPictureHeight = rotatedImageRect.height();
 
  710    const QSizeF currentPictureSize = pictureSize();
 
  711    const QRectF oldRect = QRectF( pos().x(), pos().y(), rect().width(), rect().height() );
 
  718    tr.rotate( mPictureRotation );
 
  719    QRectF newRect = tr.mapRect( QRectF( 0, 0, rotatedImageRect.width(), rotatedImageRect.height() ) );
 
  722    newRect.moveCenter( oldRect.center() );
 
 
  769  mOriginalMode = format;
 
 
  782  QString imagePath = mSourcePath;
 
  786  if ( imagePath.endsWith( QLatin1String( 
".svg" ), Qt::CaseInsensitive ) )
 
  789    imagePath = pathResolver.
writePath( imagePath );
 
  791  elem.setAttribute( QStringLiteral( 
"file" ), imagePath );
 
  792  elem.setAttribute( QStringLiteral( 
"pictureWidth" ), QString::number( mPictureWidth ) );
 
  793  elem.setAttribute( QStringLiteral( 
"pictureHeight" ), QString::number( mPictureHeight ) );
 
  794  elem.setAttribute( QStringLiteral( 
"resizeMode" ), QString::number( 
static_cast< int >( mResizeMode ) ) );
 
  795  elem.setAttribute( QStringLiteral( 
"anchorPoint" ), QString::number( 
static_cast< int >( mPictureAnchor ) ) );
 
  798  elem.setAttribute( QStringLiteral( 
"svgBorderWidth" ), QString::number( mSvgStrokeWidth ) );
 
  799  elem.setAttribute( QStringLiteral( 
"mode" ), mOriginalMode );
 
  802  elem.setAttribute( QStringLiteral( 
"pictureRotation" ), QString::number( mPictureRotation ) );
 
  805    elem.setAttribute( QStringLiteral( 
"mapUuid" ), QString() );
 
  809    elem.setAttribute( QStringLiteral( 
"mapUuid" ), mNorthArrowHandler->
linkedMap()->
uuid() );
 
  811  elem.setAttribute( QStringLiteral( 
"northMode" ), mNorthArrowHandler->
northMode() );
 
  812  elem.setAttribute( QStringLiteral( 
"northOffset" ), mNorthArrowHandler->
northOffset() );
 
 
  818  mPictureWidth = itemElem.attribute( QStringLiteral( 
"pictureWidth" ), QStringLiteral( 
"10" ) ).toDouble();
 
  819  mPictureHeight = itemElem.attribute( QStringLiteral( 
"pictureHeight" ), QStringLiteral( 
"10" ) ).toDouble();
 
  826  mSvgStrokeWidth = itemElem.attribute( QStringLiteral( 
"svgBorderWidth" ), QStringLiteral( 
"0.2" ) ).toDouble();
 
  827  mOriginalMode = 
static_cast< Format >( itemElem.attribute( QStringLiteral( 
"mode" ), QString::number( 
FormatUnknown ) ).toInt() );
 
  828  mMode = mOriginalMode;
 
  830  const QDomNodeList composerItemList = itemElem.elementsByTagName( QStringLiteral( 
"ComposerItem" ) );
 
  831  if ( !composerItemList.isEmpty() )
 
  833    const QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
 
  835    if ( !
qgsDoubleNear( composerItemElem.attribute( QStringLiteral( 
"rotation" ), QStringLiteral( 
"0" ) ).toDouble(), 0.0 ) )
 
  838      mPictureRotation = composerItemElem.attribute( QStringLiteral( 
"rotation" ), QStringLiteral( 
"0" ) ).toDouble();
 
  842  mDefaultSvgSize = QSize( 0, 0 );
 
  844  if ( itemElem.hasAttribute( QStringLiteral( 
"sourceExpression" ) ) )
 
  847    const QString sourceExpression = itemElem.attribute( QStringLiteral( 
"sourceExpression" ), QString() );
 
  848    const QString useExpression = itemElem.attribute( QStringLiteral( 
"useExpression" ) );
 
  849    bool expressionActive;
 
  850    expressionActive = ( useExpression.compare( QLatin1String( 
"true" ), Qt::CaseInsensitive ) == 0 );
 
  855  QString imagePath = itemElem.attribute( QStringLiteral( 
"file" ) );
 
  859  if ( imagePath.endsWith( QLatin1String( 
".svg" ), Qt::CaseInsensitive ) )
 
  862    imagePath = pathResolver.
readPath( imagePath );
 
  864  mSourcePath = imagePath;
 
  867  if ( !
qgsDoubleNear( itemElem.attribute( QStringLiteral( 
"pictureRotation" ), QStringLiteral( 
"0" ) ).toDouble(), 0.0 ) )
 
  869    mPictureRotation = itemElem.attribute( QStringLiteral( 
"pictureRotation" ), QStringLiteral( 
"0" ) ).toDouble();
 
  874  mNorthArrowHandler->
setNorthOffset( itemElem.attribute( QStringLiteral( 
"northOffset" ), QStringLiteral( 
"0" ) ).toDouble() );
 
  877  mRotationMapUuid = itemElem.attribute( QStringLiteral( 
"mapUuid" ) );
 
 
  909  mPictureAnchor = anchor;
 
 
  915  mSvgFillColor = color;
 
 
  921  mSvgStrokeColor = color;
 
 
  927  mSvgStrokeWidth = width;
 
 
  933  if ( mOriginalMode == 
mode )
 
  936  mOriginalMode = 
mode;
 
 
  943  if ( !
mLayout || mRotationMapUuid.isEmpty() )
 
  949    mNorthArrowHandler->
setLinkedMap( qobject_cast< QgsLayoutItemMap * >( 
mLayout->itemByUuid( mRotationMapUuid, 
true ) ) );
 
 
@ Millimeters
Millimeters.
 
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color.
 
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
 
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
 
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
 
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
 
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
 
static QString colorToString(const QColor &color)
Encodes a color into a string value.
 
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
 
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
 
bool isValid() const
Returns the validity of this feature.
 
QImage pathAsImage(const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache, bool blocking=false, double targetDpi=96, int frameNumber=-1, bool *isMissing=nullptr)
Returns the specified path rendered as an image.
 
Layout graphical items for displaying a map.
 
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
 
void setResizeMode(QgsLayoutItemPicture::ResizeMode mode)
Sets the resize mode used for drawing the picture within the item bounds.
 
void setSvgDynamicParameters(const QMap< QString, QgsProperty > ¶meters)
Sets the SVG dynamic parameters.
 
QMap< QString, QgsProperty > svgDynamicParameters() const
Returns the SVG dynamic parameters.
 
QString picturePath() const
Returns the path of the source image.
 
void setPictureAnchor(QgsLayoutItem::ReferencePoint anchor)
Sets the picture's anchor point, which controls how it is placed within the picture item's frame.
 
void setNorthMode(NorthMode mode)
Sets the mode used to align the picture to a map's North.
 
double northOffset() const
Returns the offset added to the picture's rotation from a map's North.
 
QgsLayoutItemPicture(QgsLayout *layout)
Constructor for QgsLayoutItemPicture, with the specified parent layout.
 
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map object for rotation.
 
void setPictureRotation(double rotation)
Sets the picture rotation within the item bounds, in degrees clockwise.
 
bool isMissingImage() const
Returns true if the source image is missing and the picture cannot be rendered.
 
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
 
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
 
void setPicturePath(const QString &path, Format format=FormatUnknown)
Sets the source path of the image (may be svg or a raster format).
 
void setSvgStrokeWidth(double width)
Sets the stroke width (in layout units) used for parametrized SVG files.
 
QgsLayoutItemMap * linkedMap() const
Returns the linked rotation map, if set.
 
void pictureRotationChanged(double newRotation)
Emitted on picture rotation change.
 
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
 
static QgsLayoutItemPicture * create(QgsLayout *layout)
Returns a new picture item for the specified layout.
 
NorthMode
Method for syncing rotation to a map's North direction.
 
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
 
Format mode() const
Returns the current picture mode (image format), FormatUnknown if given picture format is unknown.
 
QString evaluatedPath() const
Returns the current evaluated picture path, which includes the result of data defined path overrides.
 
QSizeF applyItemSizeConstraint(QSizeF targetSize) override
Applies any item-specific size constraint handling to a given targetSize in layout units.
 
void setSvgStrokeColor(const QColor &color)
Sets the stroke color used for parametrized SVG files.
 
int type() const override
 
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties) override
 
QIcon icon() const override
Returns the item's icon.
 
void refreshPicture(const QgsExpressionContext *context=nullptr)
Recalculates the source image (if using an expression for picture's source) and reloads and redraws t...
 
void setMode(Format mode)
Sets the current picture mode (image format).
 
NorthMode northMode() const
Returns the mode used to align the picture to a map's North.
 
void setSvgFillColor(const QColor &color)
Sets the fill color used for parametrized SVG files.
 
void recalculateSize()
Forces a recalculation of the picture's frame size.
 
ResizeMode
Controls how pictures are scaled within the item's frame.
 
@ FrameToImageSize
Sets size of frame to match original size of image without scaling.
 
@ ZoomResizeFrame
Enlarges image to fit frame, then resizes frame to fit resultant image.
 
@ Clip
Draws image at original size and clips any portion which falls outside frame.
 
@ Stretch
Stretches image to fit frame, ignores aspect ratio.
 
@ Zoom
Enlarges image to fit frame while maintaining aspect ratio of picture.
 
Format
Format of source image.
 
@ FormatRaster
Raster image.
 
@ FormatUnknown
Invalid or unknown image type.
 
void setNorthOffset(double offset)
Sets the offset added to the picture's rotation from a map's North.
 
@ LayoutPicture
Picture item.
 
Contains settings and helpers relating to a render of a QgsLayoutItem.
 
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
 
Base class for graphical items within a QgsLayout.
 
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
 
ReferencePoint
Fixed position reference point.
 
@ LowerMiddle
Lower center of item.
 
@ MiddleLeft
Middle left of item.
 
@ UpperRight
Upper right corner of item.
 
@ LowerLeft
Lower left corner of item.
 
@ UpperLeft
Upper left corner of item.
 
@ UpperMiddle
Upper center of item.
 
@ MiddleRight
Middle right of item.
 
@ LowerRight
Lower right corner of item.
 
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
 
void sizePositionChanged()
Emitted when the item's size or position changes.
 
virtual QString uuid() const
Returns the item identification string.
 
void attemptSetSceneRect(const QRectF &rect, bool includesFrame=false)
Attempts to update the item's position and size to match the passed rect in layout coordinates.
 
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
 
An object which handles north-arrow type behavior for layout items.
 
void setNorthOffset(double offset)
Sets the offset added to the arrows's rotation from a map's North.
 
NorthMode northMode() const
Returns the mode used to calculate the arrow rotation.
 
QgsLayoutItemMap * linkedMap() const
Returns the linked rotation map, if set.
 
void arrowRotationChanged(double newRotation)
Emitted on arrow rotation change.
 
NorthMode
Method for syncing rotation to a map's North direction.
 
void setNorthMode(NorthMode mode)
Sets the mode used to calculate the arrow rotation.
 
void setLinkedMap(QgsLayoutItemMap *map)
Sets the linked map item.
 
double northOffset() const
Returns the offset added to the arrows's rotation from a map's North.
 
QgsObjectCustomProperties mCustomProperties
Custom properties for object.
 
QgsPropertyCollection mDataDefinedProperties
 
const QgsLayout * layout() const
Returns the layout the object is attached to.
 
void changed()
Emitted when the object's properties change.
 
QPointer< QgsLayout > mLayout
 
DataDefinedProperty
Data defined properties for different item types.
 
@ PictureSvgStrokeColor
SVG stroke color.
 
@ PictureSvgBackgroundColor
SVG background color.
 
@ PictureSource
Picture source url.
 
@ PictureSvgStrokeWidth
SVG stroke width.
 
@ AllProperties
All properties for item.
 
void dpiChanged()
Emitted when the context's DPI is changed.
 
@ FlagAntialiasing
Use antialiasing when drawing items.
 
void changed()
Emitted certain settings in the context is changed, e.g.
 
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
 
double height() const
Returns the height of the size.
 
void setWidth(const double width)
Sets the width for the size.
 
double width() const
Returns the width of the size.
 
static QRectF largestRotatedRectWithinBounds(const QRectF &originalRect, const QRectF &boundsRect, double rotation)
Calculates the largest scaled version of originalRect which fits within boundsRect,...
 
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
 
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
 
QgsLayoutReportContext & reportContext()
Returns a reference to the layout's report context, which stores information relating to the current ...
 
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
 
HTTP network content fetcher.
 
void finished()
Emitted when content has loaded.
 
QNetworkReply * reply()
Returns a reference to the network reply.
 
void fetchContent(const QUrl &url, const QString &authcfg=QString())
Fetches content from a remote URL and handles redirects.
 
void setValue(const QString &key, const QVariant &value)
Add an entry to the store with the specified key.
 
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for the given key.
 
Resolves relative paths into absolute paths and vice versa.
 
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
 
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
 
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
 
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
 
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const final
Prepares the collection against a specified expression context.
 
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
 
A store for object properties.
 
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
 
static QVariantMap propertyMapToVariantMap(const QMap< QString, QgsProperty > &propertyMap)
Convert a map of QgsProperty to a map of QVariant This is useful to save a map of properties.
 
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
 
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
 
static QMap< QString, QgsProperty > variantMapToPropertyMap(const QVariantMap &variantMap)
Convert a map of QVariant to a map of QgsProperty This is useful to restore a map of properties.
 
The class is used as a container of context for various read/write operations on other objects.
 
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
 
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
 
QPainter * painter()
Returns the destination QPainter for the render operation.
 
Scoped object for saving and restoring a QPainter object's state.
 
QByteArray svgContent(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >(), bool *isMissingImage=nullptr)
Gets the SVG content corresponding to the given path.
 
static QgsStringMap evaluatePropertiesMap(const QMap< QString, QgsProperty > &propertiesMap, const QgsExpressionContext &context)
Evaluates a map of properties using the given context and returns a variant map with evaluated expres...
 
static QString svgSymbolPathToName(const QString &path, const QgsPathResolver &pathResolver)
Determines an SVG symbol's name from its path.
 
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
 
QMap< QString, QString > QgsStringMap
 
#define QgsDebugMsgLevel(str, level)