29#include <QDoubleValidator>
32#include <QImageReader>
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 );
77 connect( mRadioSVG, &QRadioButton::toggled,
this, &QgsLayoutPictureWidget::modeChanged );
78 connect( mRadioRaster, &QRadioButton::toggled,
this, &QgsLayoutPictureWidget::modeChanged );
80 mSvgSelectorWidget->sourceLineEdit()->setLastPathSettingsKey( QStringLiteral(
"/UI/lastComposerPictureDir" ) );
84 mFillColorButton->setAllowOpacity(
true );
85 mFillColorButton->setColorDialogTitle( tr(
"Select Fill Color" ) );
86 mFillColorButton->setContext( QStringLiteral(
"composer" ) );
87 mStrokeColorButton->setAllowOpacity(
true );
88 mStrokeColorButton->setColorDialogTitle( tr(
"Select Stroke Color" ) );
89 mStrokeColorButton->setContext( QStringLiteral(
"composer" ) );
91 mFillColorDDBtn->registerLinkedWidget( mFillColorButton );
92 mStrokeColorDDBtn->registerLinkedWidget( mStrokeColorButton );
94 mNorthTypeComboBox->blockSignals(
true );
97 mNorthTypeComboBox->blockSignals(
false );
98 mPictureRotationOffsetSpinBox->setClearValue( 0.0 );
99 mPictureRotationSpinBox->setClearValue( 0.0 );
103 mainLayout->addWidget( mItemPropertiesWidget );
105 if ( mPicture->layout() )
107 mComposerMapComboBox->setCurrentLayout( mPicture->layout() );
112 setGuiElementValues();
126 if ( mItemPropertiesWidget )
130void QgsLayoutPictureWidget::mPictureRotationSpinBox_valueChanged(
double d )
135 mPicture->setPictureRotation( d );
136 mPicture->endCommand();
140void QgsLayoutPictureWidget::mResizeModeComboBox_currentIndexChanged(
int )
147 mPicture->beginCommand( tr(
"Change Resize Mode" ) );
149 mPicture->endCommand();
159 mAnchorPointComboBox->setEnabled(
true );
163 mAnchorPointComboBox->setEnabled(
false );
167void QgsLayoutPictureWidget::mAnchorPointComboBox_currentIndexChanged(
int )
174 mPicture->beginCommand( tr(
"Change Placement" ) );
176 mPicture->endCommand();
190 mPicture = qobject_cast< QgsLayoutItemPicture * >( item );
191 mItemPropertiesWidget->
setItem( mPicture );
199 setGuiElementValues();
204void QgsLayoutPictureWidget::mRotationFromComposerMapCheckBox_stateChanged(
int state )
211 mPicture->beginCommand( tr(
"Toggle Rotation Sync" ) );
212 if ( state == Qt::Unchecked )
214 mPicture->setLinkedMap(
nullptr );
215 mPictureRotationSpinBox->setEnabled(
true );
216 mComposerMapComboBox->setEnabled(
false );
217 mNorthTypeComboBox->setEnabled(
false );
218 mPictureRotationOffsetSpinBox->setEnabled(
false );
219 mPicture->setPictureRotation( mPictureRotationSpinBox->value() );
223 QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( mComposerMapComboBox->currentItem() );
224 mPicture->setLinkedMap( map );
225 mPictureRotationSpinBox->setEnabled(
false );
226 mNorthTypeComboBox->setEnabled(
true );
227 mPictureRotationOffsetSpinBox->setEnabled(
true );
228 mComposerMapComboBox->setEnabled(
true );
230 mPicture->endCommand();
233void QgsLayoutPictureWidget::mapChanged(
QgsLayoutItem *item )
241 const QgsLayout *layout = mPicture->layout();
253 mPicture->beginCommand( tr(
"Change Rotation Map" ) );
254 mPicture->setLinkedMap( map );
256 mPicture->endCommand();
259void QgsLayoutPictureWidget::setPicRotationSpinValue(
double r )
261 mPictureRotationSpinBox->blockSignals(
true );
262 mPictureRotationSpinBox->setValue( r );
263 mPictureRotationSpinBox->blockSignals(
false );
266void QgsLayoutPictureWidget::setGuiElementValues()
271 mPictureRotationSpinBox->blockSignals(
true );
272 mComposerMapComboBox->blockSignals(
true );
273 mRotationFromComposerMapCheckBox->blockSignals(
true );
274 mNorthTypeComboBox->blockSignals(
true );
275 mPictureRotationOffsetSpinBox->blockSignals(
true );
276 mResizeModeComboBox->blockSignals(
true );
277 mAnchorPointComboBox->blockSignals(
true );
278 mFillColorButton->blockSignals(
true );
279 mStrokeColorButton->blockSignals(
true );
280 mStrokeWidthSpinBox->blockSignals(
true );
282 mPictureRotationSpinBox->setValue( mPicture->pictureRotation() );
284 mComposerMapComboBox->setItem( mPicture->linkedMap() );
286 if ( mPicture->linkedMap() )
288 mRotationFromComposerMapCheckBox->setCheckState( Qt::Checked );
289 mPictureRotationSpinBox->setEnabled(
false );
290 mComposerMapComboBox->setEnabled(
true );
291 mNorthTypeComboBox->setEnabled(
true );
292 mPictureRotationOffsetSpinBox->setEnabled(
true );
296 mRotationFromComposerMapCheckBox->setCheckState( Qt::Unchecked );
297 mPictureRotationSpinBox->setEnabled(
true );
298 mComposerMapComboBox->setEnabled(
false );
299 mNorthTypeComboBox->setEnabled(
false );
300 mPictureRotationOffsetSpinBox->setEnabled(
false );
302 mNorthTypeComboBox->setCurrentIndex( mNorthTypeComboBox->findData( mPicture->northMode() ) );
303 mPictureRotationOffsetSpinBox->setValue( mPicture->northOffset() );
305 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mPicture->resizeMode() ) );
310 mAnchorPointComboBox->setCurrentIndex( mAnchorPointComboBox->findData( mPicture->pictureAnchor() ) );
315 mAnchorPointComboBox->setEnabled(
true );
319 mAnchorPointComboBox->setEnabled(
false );
322 switch ( mPicture->originalMode() )
326 mRadioSVG->setChecked(
true );
329 mRadioRaster->setChecked(
true );
333 mSvgSelectorWidget->setSvgPath( mPicture->picturePath() );
334 mSvgSelectorWidget->setSvgParameters( mPicture->svgDynamicParameters() );
336 updateSvgParamGui(
false );
337 mFillColorButton->setColor( mPicture->svgFillColor() );
338 mStrokeColorButton->setColor( mPicture->svgStrokeColor() );
339 mStrokeWidthSpinBox->setValue( mPicture->svgStrokeWidth() );
341 mRotationFromComposerMapCheckBox->blockSignals(
false );
342 mPictureRotationSpinBox->blockSignals(
false );
343 mComposerMapComboBox->blockSignals(
false );
344 mNorthTypeComboBox->blockSignals(
false );
345 mPictureRotationOffsetSpinBox->blockSignals(
false );
346 mResizeModeComboBox->blockSignals(
false );
347 mAnchorPointComboBox->blockSignals(
false );
348 mFillColorButton->blockSignals(
false );
349 mStrokeColorButton->blockSignals(
false );
350 mStrokeWidthSpinBox->blockSignals(
false );
356void QgsLayoutPictureWidget::updateSvgParamGui(
bool resetValues )
361 const QString picturePath = mPicture->picturePath();
364 bool hasFillParam, hasFillOpacityParam, hasStrokeParam, hasStrokeWidthParam, hasStrokeOpacityParam;
365 QColor defaultFill, defaultStroke;
366 double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
367 bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
369 hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
370 hasStrokeParam, hasDefaultStrokeColor, defaultStroke,
371 hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth,
372 hasStrokeOpacityParam, hasDefaultStrokeOpacity, defaultStrokeOpacity );
376 QColor fill = mFillColorButton->color();
377 const double newOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
378 if ( hasDefaultFillColor )
382 fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : newOpacity );
383 mFillColorButton->setColor( fill );
385 mFillColorButton->setEnabled( hasFillParam );
386 mFillColorDDBtn->setEnabled( hasFillParam );
387 mFillColorButton->setAllowOpacity( hasFillOpacityParam );
390 QColor stroke = mStrokeColorButton->color();
391 const double newOpacity = hasStrokeOpacityParam ? stroke.alphaF() : 1.0;
392 if ( hasDefaultStrokeColor )
394 stroke = defaultStroke;
396 stroke.setAlphaF( hasDefaultStrokeOpacity ? defaultStrokeOpacity : newOpacity );
397 mStrokeColorButton->setColor( stroke );
399 mStrokeColorButton->setEnabled( hasStrokeParam );
400 mStrokeColorDDBtn->setEnabled( hasStrokeParam );
401 mStrokeColorButton->setAllowOpacity( hasStrokeOpacityParam );
402 if ( hasDefaultStrokeWidth && resetValues )
404 mStrokeWidthSpinBox->setValue( defaultStrokeWidth );
406 mStrokeWidthSpinBox->setEnabled( hasStrokeWidthParam );
407 mStrokeWidthDDBtn->setEnabled( hasStrokeWidthParam );
410void QgsLayoutPictureWidget::mFillColorButton_colorChanged(
const QColor &color )
413 mPicture->setSvgFillColor( color );
414 mPicture->endCommand();
418void QgsLayoutPictureWidget::mStrokeColorButton_colorChanged(
const QColor &color )
421 mPicture->setSvgStrokeColor( color );
422 mPicture->endCommand();
426void QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged(
double d )
429 mPicture->setSvgStrokeWidth( d );
430 mPicture->endCommand();
434void QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged(
double d )
437 mPicture->setNorthOffset( d );
438 mPicture->endCommand();
442void QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged(
int index )
444 mPicture->beginCommand( tr(
"Change Picture North Mode" ) );
446 mPicture->endCommand();
450void QgsLayoutPictureWidget::modeChanged(
bool checked )
455 const bool svg = mRadioSVG->isChecked();
463 mSvgSelectorWidget->setBrowserVisible( svg );
464 mSvgSelectorWidget->setAllowParameters( svg );
465 mSVGParamsGroupBox->setVisible( svg );
467 if ( mPicture && mPicture->mode() != newFormat )
469 mPicture->beginCommand( tr(
"Change Picture Type" ) );
470 mPicture->setMode( newFormat );
471 mPicture->endCommand();
475void QgsLayoutPictureWidget::sourceChanged(
const QString &source )
479 mPicture->beginCommand( tr(
"Change Picture" ) );
482 mPicture->endCommand();
487void QgsLayoutPictureWidget::setSvgDynamicParameters(
const QMap<QString, QgsProperty> ¶meters )
489 mPicture->beginCommand( tr(
"Set SVG parameters" ) );
490 mPicture->setSvgDynamicParameters( parameters );
492 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.