25 #include "qgssettings.h" 
   29 #include <QDoubleValidator> 
   30 #include <QFileDialog> 
   32 #include <QImageReader> 
   33 #include <QMessageBox> 
   35 #include <QProgressDialog> 
   36 #include <QSvgRenderer> 
   44   mSvgSelectorWidget->setAllowParameters( 
true );
 
   45   mSvgSelectorWidget->sourceLineEdit()->setPropertyOverrideToolButtonVisible( 
true );
 
   46   mSvgSelectorWidget->sourceLineEdit()->setLastPathSettingsKey( QStringLiteral( 
"/UI/lastSVGMarkerDir" ) );
 
   65   connect( mPictureRotationSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutPictureWidget::mPictureRotationSpinBox_valueChanged );
 
   66   connect( mRotationFromComposerMapCheckBox, &QCheckBox::stateChanged, 
this, &QgsLayoutPictureWidget::mRotationFromComposerMapCheckBox_stateChanged );
 
   67   connect( mResizeModeComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsLayoutPictureWidget::mResizeModeComboBox_currentIndexChanged );
 
   68   connect( mAnchorPointComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsLayoutPictureWidget::mAnchorPointComboBox_currentIndexChanged );
 
   71   connect( mStrokeWidthSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged );
 
   72   connect( mPictureRotationOffsetSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged );
 
   73   connect( mNorthTypeComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged );
 
   76   connect( mRadioSVG, &QRadioButton::toggled, 
this, &QgsLayoutPictureWidget::modeChanged );
 
   77   connect( mRadioRaster, &QRadioButton::toggled, 
this, &QgsLayoutPictureWidget::modeChanged );
 
   79   mSvgSelectorWidget->sourceLineEdit()->setLastPathSettingsKey( QStringLiteral( 
"/UI/lastComposerPictureDir" ) );
 
   83   mFillColorButton->setAllowOpacity( 
true );
 
   84   mFillColorButton->setColorDialogTitle( tr( 
"Select Fill Color" ) );
 
   85   mFillColorButton->setContext( QStringLiteral( 
"composer" ) );
 
   86   mStrokeColorButton->setAllowOpacity( 
true );
 
   87   mStrokeColorButton->setColorDialogTitle( tr( 
"Select Stroke Color" ) );
 
   88   mStrokeColorButton->setContext( QStringLiteral( 
"composer" ) );
 
   90   mFillColorDDBtn->registerLinkedWidget( mFillColorButton );
 
   91   mStrokeColorDDBtn->registerLinkedWidget( mStrokeColorButton );
 
   93   mNorthTypeComboBox->blockSignals( 
true );
 
   96   mNorthTypeComboBox->blockSignals( 
false );
 
   97   mPictureRotationOffsetSpinBox->setClearValue( 0.0 );
 
   98   mPictureRotationSpinBox->setClearValue( 0.0 );
 
  102   mainLayout->addWidget( mItemPropertiesWidget );
 
  104   if ( mPicture->layout() )
 
  106     mComposerMapComboBox->setCurrentLayout( mPicture->layout() );
 
  111   setGuiElementValues();
 
  113   switch ( mPicture->mode() )
 
  117       mRadioSVG->setChecked( 
true );
 
  120       mRadioRaster->setChecked( 
true );
 
  136   if ( mItemPropertiesWidget )
 
  140 void QgsLayoutPictureWidget::mPictureRotationSpinBox_valueChanged( 
double d )
 
  145     mPicture->setPictureRotation( d );
 
  146     mPicture->endCommand();
 
  150 void QgsLayoutPictureWidget::mResizeModeComboBox_currentIndexChanged( 
int )
 
  157   mPicture->beginCommand( tr( 
"Change Resize Mode" ) );
 
  159   mPicture->endCommand();
 
  169     mAnchorPointComboBox->setEnabled( 
true );
 
  173     mAnchorPointComboBox->setEnabled( 
false );
 
  177 void QgsLayoutPictureWidget::mAnchorPointComboBox_currentIndexChanged( 
int )
 
  184   mPicture->beginCommand( tr( 
"Change Placement" ) );
 
  186   mPicture->endCommand();
 
  200   mPicture = qobject_cast< QgsLayoutItemPicture * >( item );
 
  201   mItemPropertiesWidget->
setItem( mPicture );
 
  209   setGuiElementValues();
 
  214 void QgsLayoutPictureWidget::mRotationFromComposerMapCheckBox_stateChanged( 
int state )
 
  221   mPicture->beginCommand( tr( 
"Toggle Rotation Sync" ) );
 
  222   if ( state == Qt::Unchecked )
 
  224     mPicture->setLinkedMap( 
nullptr );
 
  225     mPictureRotationSpinBox->setEnabled( 
true );
 
  226     mComposerMapComboBox->setEnabled( 
false );
 
  227     mNorthTypeComboBox->setEnabled( 
false );
 
  228     mPictureRotationOffsetSpinBox->setEnabled( 
false );
 
  229     mPicture->setPictureRotation( mPictureRotationSpinBox->value() );
 
  233     QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( mComposerMapComboBox->currentItem() );
 
  234     mPicture->setLinkedMap( map );
 
  235     mPictureRotationSpinBox->setEnabled( 
false );
 
  236     mNorthTypeComboBox->setEnabled( 
true );
 
  237     mPictureRotationOffsetSpinBox->setEnabled( 
true );
 
  238     mComposerMapComboBox->setEnabled( 
true );
 
  240   mPicture->endCommand();
 
  243 void QgsLayoutPictureWidget::mapChanged( 
QgsLayoutItem *item )
 
  251   const QgsLayout *layout = mPicture->layout();
 
  263   mPicture->beginCommand( tr( 
"Change Rotation Map" ) );
 
  264   mPicture->setLinkedMap( map );
 
  266   mPicture->endCommand();
 
  269 void QgsLayoutPictureWidget::setPicRotationSpinValue( 
double r )
 
  271   mPictureRotationSpinBox->blockSignals( 
true );
 
  272   mPictureRotationSpinBox->setValue( r );
 
  273   mPictureRotationSpinBox->blockSignals( 
false );
 
  276 void QgsLayoutPictureWidget::setGuiElementValues()
 
  281     mPictureRotationSpinBox->blockSignals( 
true );
 
  282     mComposerMapComboBox->blockSignals( 
true );
 
  283     mRotationFromComposerMapCheckBox->blockSignals( 
true );
 
  284     mNorthTypeComboBox->blockSignals( 
true );
 
  285     mPictureRotationOffsetSpinBox->blockSignals( 
true );
 
  286     mResizeModeComboBox->blockSignals( 
true );
 
  287     mAnchorPointComboBox->blockSignals( 
true );
 
  288     mFillColorButton->blockSignals( 
true );
 
  289     mStrokeColorButton->blockSignals( 
true );
 
  290     mStrokeWidthSpinBox->blockSignals( 
true );
 
  292     mPictureRotationSpinBox->setValue( mPicture->pictureRotation() );
 
  294     mComposerMapComboBox->setItem( mPicture->linkedMap() );
 
  296     if ( mPicture->linkedMap() )
 
  298       mRotationFromComposerMapCheckBox->setCheckState( Qt::Checked );
 
  299       mPictureRotationSpinBox->setEnabled( 
false );
 
  300       mComposerMapComboBox->setEnabled( 
true );
 
  301       mNorthTypeComboBox->setEnabled( 
true );
 
  302       mPictureRotationOffsetSpinBox->setEnabled( 
true );
 
  306       mRotationFromComposerMapCheckBox->setCheckState( Qt::Unchecked );
 
  307       mPictureRotationSpinBox->setEnabled( 
true );
 
  308       mComposerMapComboBox->setEnabled( 
false );
 
  309       mNorthTypeComboBox->setEnabled( 
false );
 
  310       mPictureRotationOffsetSpinBox->setEnabled( 
false );
 
  312     mNorthTypeComboBox->setCurrentIndex( mNorthTypeComboBox->findData( mPicture->northMode() ) );
 
  313     mPictureRotationOffsetSpinBox->setValue( mPicture->northOffset() );
 
  315     mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mPicture->resizeMode() ) );
 
  320     mAnchorPointComboBox->setCurrentIndex( mAnchorPointComboBox->findData( mPicture->pictureAnchor() ) );
 
  325       mAnchorPointComboBox->setEnabled( 
true );
 
  329       mAnchorPointComboBox->setEnabled( 
false );
 
  332     mSvgSelectorWidget->setSvgParameters( mPicture->svgDynamicParameters() );
 
  334     updateSvgParamGui( 
false );
 
  335     mFillColorButton->setColor( mPicture->svgFillColor() );
 
  336     mStrokeColorButton->setColor( mPicture->svgStrokeColor() );
 
  337     mStrokeWidthSpinBox->setValue( mPicture->svgStrokeWidth() );
 
  339     mRotationFromComposerMapCheckBox->blockSignals( 
false );
 
  340     mPictureRotationSpinBox->blockSignals( 
false );
 
  341     mComposerMapComboBox->blockSignals( 
false );
 
  342     mNorthTypeComboBox->blockSignals( 
false );
 
  343     mPictureRotationOffsetSpinBox->blockSignals( 
false );
 
  344     mResizeModeComboBox->blockSignals( 
false );
 
  345     mAnchorPointComboBox->blockSignals( 
false );
 
  346     mFillColorButton->blockSignals( 
false );
 
  347     mStrokeColorButton->blockSignals( 
false );
 
  348     mStrokeWidthSpinBox->blockSignals( 
false );
 
  354 void QgsLayoutPictureWidget::updateSvgParamGui( 
bool resetValues )
 
  359   QString picturePath = mPicture->picturePath();
 
  362   bool hasFillParam, hasFillOpacityParam, hasStrokeParam, hasStrokeWidthParam, hasStrokeOpacityParam;
 
  363   QColor defaultFill, defaultStroke;
 
  364   double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
 
  365   bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
 
  367       hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
 
  368       hasStrokeParam, hasDefaultStrokeColor, defaultStroke,
 
  369       hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth,
 
  370       hasStrokeOpacityParam, hasDefaultStrokeOpacity, defaultStrokeOpacity );
 
  374     QColor fill = mFillColorButton->color();
 
  375     double newOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
 
  376     if ( hasDefaultFillColor )
 
  380     fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : newOpacity );
 
  381     mFillColorButton->setColor( fill );
 
  383   mFillColorButton->setEnabled( hasFillParam );
 
  384   mFillColorButton->setAllowOpacity( hasFillOpacityParam );
 
  387     QColor stroke = mStrokeColorButton->color();
 
  388     double newOpacity = hasStrokeOpacityParam ? stroke.alphaF() : 1.0;
 
  389     if ( hasDefaultStrokeColor )
 
  391       stroke = defaultStroke;
 
  393     stroke.setAlphaF( hasDefaultStrokeOpacity ? defaultStrokeOpacity : newOpacity );
 
  394     mStrokeColorButton->setColor( stroke );
 
  396   mStrokeColorButton->setEnabled( hasStrokeParam );
 
  397   mStrokeColorButton->setAllowOpacity( hasStrokeOpacityParam );
 
  398   if ( hasDefaultStrokeWidth && resetValues )
 
  400     mStrokeWidthSpinBox->setValue( defaultStrokeWidth );
 
  402   mStrokeWidthSpinBox->setEnabled( hasStrokeWidthParam );
 
  405 void QgsLayoutPictureWidget::mFillColorButton_colorChanged( 
const QColor &color )
 
  408   mPicture->setSvgFillColor( color );
 
  409   mPicture->endCommand();
 
  413 void QgsLayoutPictureWidget::mStrokeColorButton_colorChanged( 
const QColor &color )
 
  416   mPicture->setSvgStrokeColor( color );
 
  417   mPicture->endCommand();
 
  421 void QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged( 
double d )
 
  424   mPicture->setSvgStrokeWidth( d );
 
  425   mPicture->endCommand();
 
  429 void QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged( 
double d )
 
  432   mPicture->setNorthOffset( d );
 
  433   mPicture->endCommand();
 
  437 void QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged( 
int index )
 
  439   mPicture->beginCommand( tr( 
"Change Picture North Mode" ) );
 
  441   mPicture->endCommand();
 
  445 void QgsLayoutPictureWidget::modeChanged( 
bool checked )
 
  450   bool svg = mRadioSVG->isChecked();
 
  458   mSvgSelectorWidget->setBrowserVisible( svg );
 
  459   mSvgSelectorWidget->setAllowParameters( svg );
 
  460   mSVGParamsGroupBox->setVisible( svg );
 
  462   if ( mPicture && mPicture->mode() != newFormat )
 
  464     mPicture->beginCommand( tr( 
"Change Picture Type" ) );
 
  465     mPicture->setMode( newFormat );
 
  466     mPicture->endCommand();
 
  470 void QgsLayoutPictureWidget::sourceChanged( 
const QString &source )
 
  474     mPicture->beginCommand( tr( 
"Change Picture" ) );
 
  477     mPicture->endCommand();
 
  482 void QgsLayoutPictureWidget::setSvgDynamicParameters( 
const QMap<QString, QgsProperty> ¶meters )
 
  484   mPicture->beginCommand( tr( 
"Set SVG parameters" ) );
 
  485   mPicture->setSvgDynamicParameters( parameters );
 
  487   mPicture->endCommand();
 
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
Layout graphical items for displaying a map.
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
void pictureRotationChanged(double newRotation)
Emitted on picture rotation change.
NorthMode
Method for syncing rotation to a map's North direction.
@ GridNorth
Align to grid north.
@ TrueNorth
Align to true north.
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.
@ LayoutPicture
Picture item.
Base class for graphical items within a QgsLayout.
@ UndoPictureStrokeWidth
Picture stroke width.
@ UndoPictureRotation
Picture rotation.
@ UndoPictureFillColor
Picture fill color.
@ UndoPictureNorthOffset
Picture north offset.
@ UndoPictureStrokeColor
Picture stroke color.
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.
int type() const override
Returns a unique graphics item type identifier.
void changed()
Emitted when the object's properties change.
@ PictureSvgStrokeColor
SVG stroke color.
@ PictureSvgStrokeWidth
SVG stroke width.
@ PictureSvgBackgroundColor
SVG background color.
@ PictureSource
Picture source url.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Interface for master layout type objects, such as print layouts and reports.
void containsParams(const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasStrokeParam, QColor &defaultStrokeColor, bool &hasStrokeWidthParam, double &defaultStrokeWidth, bool blocking=false) const
Tests if an SVG file contains parameters for fill, stroke color, stroke width.
void sourceChanged(const QString &source)
Emitted whenever the SVG source is changed in the widget.