19#include "moc_qgslayoutpicturewidget.cpp"
30#include <QDoubleValidator>
33#include <QImageReader>
36#include <QProgressDialog>
37#include <QSvgRenderer>
45 mSvgSelectorWidget->setAllowParameters(
true );
46 mSvgSelectorWidget->sourceLineEdit()->setPropertyOverrideToolButtonVisible(
true );
47 mSvgSelectorWidget->sourceLineEdit()->setLastPathSettingsKey( QStringLiteral(
"/UI/lastSVGMarkerDir" ) );
66 connect( mPictureRotationSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPictureWidget::mPictureRotationSpinBox_valueChanged );
67 connect( mRotationFromComposerMapCheckBox, &QCheckBox::stateChanged,
this, &QgsLayoutPictureWidget::mRotationFromComposerMapCheckBox_stateChanged );
68 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPictureWidget::mResizeModeComboBox_currentIndexChanged );
69 connect( mAnchorPointComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPictureWidget::mAnchorPointComboBox_currentIndexChanged );
72 connect( mStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged );
73 connect( mPictureRotationOffsetSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged );
74 connect( mNorthTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged );
78 connect( mRadioSVG, &QRadioButton::toggled,
this, &QgsLayoutPictureWidget::modeChanged );
79 connect( mRadioRaster, &QRadioButton::toggled,
this, &QgsLayoutPictureWidget::modeChanged );
81 mSvgSelectorWidget->sourceLineEdit()->setLastPathSettingsKey( QStringLiteral(
"/UI/lastComposerPictureDir" ) );
85 mFillColorButton->setAllowOpacity(
true );
86 mFillColorButton->setColorDialogTitle( tr(
"Select Fill Color" ) );
87 mFillColorButton->setContext( QStringLiteral(
"composer" ) );
88 mStrokeColorButton->setAllowOpacity(
true );
89 mStrokeColorButton->setColorDialogTitle( tr(
"Select Stroke Color" ) );
90 mStrokeColorButton->setContext( QStringLiteral(
"composer" ) );
92 mFillColorDDBtn->registerLinkedWidget( mFillColorButton );
93 mStrokeColorDDBtn->registerLinkedWidget( mStrokeColorButton );
95 mNorthTypeComboBox->blockSignals(
true );
98 mNorthTypeComboBox->blockSignals(
false );
99 mPictureRotationOffsetSpinBox->setClearValue( 0.0 );
100 mPictureRotationSpinBox->setClearValue( 0.0 );
104 mainLayout->addWidget( mItemPropertiesWidget );
106 if ( mPicture->layout() )
108 mComposerMapComboBox->setCurrentLayout( mPicture->layout() );
113 setGuiElementValues();
127 if ( mItemPropertiesWidget )
131void QgsLayoutPictureWidget::mPictureRotationSpinBox_valueChanged(
double d )
136 mPicture->setPictureRotation( d );
137 mPicture->endCommand();
141void QgsLayoutPictureWidget::mResizeModeComboBox_currentIndexChanged(
int )
148 mPicture->beginCommand( tr(
"Change Resize Mode" ) );
150 mPicture->endCommand();
160 mAnchorPointComboBox->setEnabled(
true );
164 mAnchorPointComboBox->setEnabled(
false );
168void QgsLayoutPictureWidget::mAnchorPointComboBox_currentIndexChanged(
int )
175 mPicture->beginCommand( tr(
"Change Placement" ) );
177 mPicture->endCommand();
191 mPicture = qobject_cast< QgsLayoutItemPicture * >( item );
192 mItemPropertiesWidget->
setItem( mPicture );
200 setGuiElementValues();
205void QgsLayoutPictureWidget::mRotationFromComposerMapCheckBox_stateChanged(
int state )
212 mPicture->beginCommand( tr(
"Toggle Rotation Sync" ) );
213 if ( state == Qt::Unchecked )
215 mPicture->setLinkedMap(
nullptr );
216 mPictureRotationSpinBox->setEnabled(
true );
217 mComposerMapComboBox->setEnabled(
false );
218 mNorthTypeComboBox->setEnabled(
false );
219 mPictureRotationOffsetSpinBox->setEnabled(
false );
220 mPicture->setPictureRotation( mPictureRotationSpinBox->value() );
224 QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( mComposerMapComboBox->currentItem() );
225 mPicture->setLinkedMap( map );
226 mPictureRotationSpinBox->setEnabled(
false );
227 mNorthTypeComboBox->setEnabled(
true );
228 mPictureRotationOffsetSpinBox->setEnabled(
true );
229 mComposerMapComboBox->setEnabled(
true );
231 mPicture->endCommand();
234void QgsLayoutPictureWidget::mapChanged(
QgsLayoutItem *item )
242 const QgsLayout *layout = mPicture->layout();
254 mPicture->beginCommand( tr(
"Change Rotation Map" ) );
255 mPicture->setLinkedMap( map );
257 mPicture->endCommand();
260void QgsLayoutPictureWidget::setPicRotationSpinValue(
double r )
262 mPictureRotationSpinBox->blockSignals(
true );
263 mPictureRotationSpinBox->setValue( r );
264 mPictureRotationSpinBox->blockSignals(
false );
267void QgsLayoutPictureWidget::setGuiElementValues()
272 mPictureRotationSpinBox->blockSignals(
true );
273 mComposerMapComboBox->blockSignals(
true );
274 mRotationFromComposerMapCheckBox->blockSignals(
true );
275 mNorthTypeComboBox->blockSignals(
true );
276 mPictureRotationOffsetSpinBox->blockSignals(
true );
277 mResizeModeComboBox->blockSignals(
true );
278 mAnchorPointComboBox->blockSignals(
true );
279 mFillColorButton->blockSignals(
true );
280 mStrokeColorButton->blockSignals(
true );
281 mStrokeWidthSpinBox->blockSignals(
true );
283 mPictureRotationSpinBox->setValue( mPicture->pictureRotation() );
285 mComposerMapComboBox->setItem( mPicture->linkedMap() );
287 if ( mPicture->linkedMap() )
289 mRotationFromComposerMapCheckBox->setCheckState( Qt::Checked );
290 mPictureRotationSpinBox->setEnabled(
false );
291 mComposerMapComboBox->setEnabled(
true );
292 mNorthTypeComboBox->setEnabled(
true );
293 mPictureRotationOffsetSpinBox->setEnabled(
true );
297 mRotationFromComposerMapCheckBox->setCheckState( Qt::Unchecked );
298 mPictureRotationSpinBox->setEnabled(
true );
299 mComposerMapComboBox->setEnabled(
false );
300 mNorthTypeComboBox->setEnabled(
false );
301 mPictureRotationOffsetSpinBox->setEnabled(
false );
303 mNorthTypeComboBox->setCurrentIndex( mNorthTypeComboBox->findData( mPicture->northMode() ) );
304 mPictureRotationOffsetSpinBox->setValue( mPicture->northOffset() );
306 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mPicture->resizeMode() ) );
311 mAnchorPointComboBox->setCurrentIndex( mAnchorPointComboBox->findData( mPicture->pictureAnchor() ) );
316 mAnchorPointComboBox->setEnabled(
true );
320 mAnchorPointComboBox->setEnabled(
false );
323 switch ( mPicture->originalMode() )
327 mRadioSVG->setChecked(
true );
330 mRadioRaster->setChecked(
true );
334 mSvgSelectorWidget->setSvgPath( mPicture->picturePath() );
335 mSvgSelectorWidget->setSvgParameters( mPicture->svgDynamicParameters() );
337 updateSvgParamGui(
false );
338 mFillColorButton->setColor( mPicture->svgFillColor() );
339 mStrokeColorButton->setColor( mPicture->svgStrokeColor() );
340 mStrokeWidthSpinBox->setValue( mPicture->svgStrokeWidth() );
342 mRotationFromComposerMapCheckBox->blockSignals(
false );
343 mPictureRotationSpinBox->blockSignals(
false );
344 mComposerMapComboBox->blockSignals(
false );
345 mNorthTypeComboBox->blockSignals(
false );
346 mPictureRotationOffsetSpinBox->blockSignals(
false );
347 mResizeModeComboBox->blockSignals(
false );
348 mAnchorPointComboBox->blockSignals(
false );
349 mFillColorButton->blockSignals(
false );
350 mStrokeColorButton->blockSignals(
false );
351 mStrokeWidthSpinBox->blockSignals(
false );
357void QgsLayoutPictureWidget::updateSvgParamGui(
bool resetValues )
362 const QString picturePath = mPicture->picturePath();
365 bool hasFillParam, hasFillOpacityParam, hasStrokeParam, hasStrokeWidthParam, hasStrokeOpacityParam;
366 QColor defaultFill, defaultStroke;
367 double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
368 bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
370 hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
371 hasStrokeParam, hasDefaultStrokeColor, defaultStroke,
372 hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth,
373 hasStrokeOpacityParam, hasDefaultStrokeOpacity, defaultStrokeOpacity );
377 QColor fill = mFillColorButton->color();
378 const double newOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
379 if ( hasDefaultFillColor )
383 fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : newOpacity );
384 mFillColorButton->setColor( fill );
386 mFillColorButton->setEnabled( hasFillParam );
387 mFillColorDDBtn->setEnabled( hasFillParam );
388 mFillColorButton->setAllowOpacity( hasFillOpacityParam );
391 QColor stroke = mStrokeColorButton->color();
392 const double newOpacity = hasStrokeOpacityParam ? stroke.alphaF() : 1.0;
393 if ( hasDefaultStrokeColor )
395 stroke = defaultStroke;
397 stroke.setAlphaF( hasDefaultStrokeOpacity ? defaultStrokeOpacity : newOpacity );
398 mStrokeColorButton->setColor( stroke );
400 mStrokeColorButton->setEnabled( hasStrokeParam );
401 mStrokeColorDDBtn->setEnabled( hasStrokeParam );
402 mStrokeColorButton->setAllowOpacity( hasStrokeOpacityParam );
403 if ( hasDefaultStrokeWidth && resetValues )
405 mStrokeWidthSpinBox->setValue( defaultStrokeWidth );
407 mStrokeWidthSpinBox->setEnabled( hasStrokeWidthParam );
408 mStrokeWidthDDBtn->setEnabled( hasStrokeWidthParam );
411void QgsLayoutPictureWidget::mFillColorButton_colorChanged(
const QColor &color )
414 mPicture->setSvgFillColor( color );
415 mPicture->endCommand();
419void QgsLayoutPictureWidget::mStrokeColorButton_colorChanged(
const QColor &color )
422 mPicture->setSvgStrokeColor( color );
423 mPicture->endCommand();
427void QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged(
double d )
430 mPicture->setSvgStrokeWidth( d );
431 mPicture->endCommand();
435void QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged(
double d )
438 mPicture->setNorthOffset( d );
439 mPicture->endCommand();
443void QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged(
int index )
445 mPicture->beginCommand( tr(
"Change Picture North Mode" ) );
447 mPicture->endCommand();
451void QgsLayoutPictureWidget::modeChanged(
bool checked )
456 const bool svg = mRadioSVG->isChecked();
464 mSvgSelectorWidget->setBrowserVisible( svg );
465 mSvgSelectorWidget->setAllowParameters( svg );
466 mSVGParamsGroupBox->setVisible( svg );
468 if ( mPicture && mPicture->mode() != newFormat )
470 mPicture->beginCommand( tr(
"Change Picture Type" ) );
471 mPicture->setMode( newFormat );
472 mPicture->endCommand();
476void QgsLayoutPictureWidget::sourceChanged(
const QString &source )
480 mPicture->beginCommand( tr(
"Change Picture" ) );
483 mPicture->endCommand();
488void QgsLayoutPictureWidget::setSvgDynamicParameters(
const QMap<QString, QgsProperty> ¶meters )
490 mPicture->beginCommand( tr(
"Set SVG parameters" ) );
491 mPicture->setSvgDynamicParameters( parameters );
493 mPicture->endCommand();
The Qgis class provides global constants for use throughout the application.
PictureFormat
Picture formats.
@ Unknown
Invalid or unknown image type.
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.
@ 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.
@ PictureSvgBackgroundColor
SVG background color.
@ PictureSource
Picture source url.
@ PictureSvgStrokeWidth
SVG stroke width.
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.