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();
158 mAnchorPointComboBox->setEnabled(
true );
162 mAnchorPointComboBox->setEnabled(
false );
166void QgsLayoutPictureWidget::mAnchorPointComboBox_currentIndexChanged(
int )
173 mPicture->beginCommand( tr(
"Change Placement" ) );
175 mPicture->endCommand();
189 mPicture = qobject_cast<QgsLayoutItemPicture *>( item );
190 mItemPropertiesWidget->
setItem( mPicture );
198 setGuiElementValues();
203void QgsLayoutPictureWidget::mRotationFromComposerMapCheckBox_stateChanged(
int state )
210 mPicture->beginCommand( tr(
"Toggle Rotation Sync" ) );
211 if ( state == Qt::Unchecked )
213 mPicture->setLinkedMap(
nullptr );
214 mPictureRotationSpinBox->setEnabled(
true );
215 mComposerMapComboBox->setEnabled(
false );
216 mNorthTypeComboBox->setEnabled(
false );
217 mPictureRotationOffsetSpinBox->setEnabled(
false );
218 mPicture->setPictureRotation( mPictureRotationSpinBox->value() );
222 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( mComposerMapComboBox->currentItem() );
223 mPicture->setLinkedMap( map );
224 mPictureRotationSpinBox->setEnabled(
false );
225 mNorthTypeComboBox->setEnabled(
true );
226 mPictureRotationOffsetSpinBox->setEnabled(
true );
227 mComposerMapComboBox->setEnabled(
true );
229 mPicture->endCommand();
232void QgsLayoutPictureWidget::mapChanged(
QgsLayoutItem *item )
240 const QgsLayout *layout = mPicture->layout();
252 mPicture->beginCommand( tr(
"Change Rotation Map" ) );
253 mPicture->setLinkedMap( map );
255 mPicture->endCommand();
258void QgsLayoutPictureWidget::setPicRotationSpinValue(
double r )
260 mPictureRotationSpinBox->blockSignals(
true );
261 mPictureRotationSpinBox->setValue( r );
262 mPictureRotationSpinBox->blockSignals(
false );
265void QgsLayoutPictureWidget::setGuiElementValues()
270 mPictureRotationSpinBox->blockSignals(
true );
271 mComposerMapComboBox->blockSignals(
true );
272 mRotationFromComposerMapCheckBox->blockSignals(
true );
273 mNorthTypeComboBox->blockSignals(
true );
274 mPictureRotationOffsetSpinBox->blockSignals(
true );
275 mResizeModeComboBox->blockSignals(
true );
276 mAnchorPointComboBox->blockSignals(
true );
277 mFillColorButton->blockSignals(
true );
278 mStrokeColorButton->blockSignals(
true );
279 mStrokeWidthSpinBox->blockSignals(
true );
281 mPictureRotationSpinBox->setValue( mPicture->pictureRotation() );
283 mComposerMapComboBox->setItem( mPicture->linkedMap() );
285 if ( mPicture->linkedMap() )
287 mRotationFromComposerMapCheckBox->setCheckState( Qt::Checked );
288 mPictureRotationSpinBox->setEnabled(
false );
289 mComposerMapComboBox->setEnabled(
true );
290 mNorthTypeComboBox->setEnabled(
true );
291 mPictureRotationOffsetSpinBox->setEnabled(
true );
295 mRotationFromComposerMapCheckBox->setCheckState( Qt::Unchecked );
296 mPictureRotationSpinBox->setEnabled(
true );
297 mComposerMapComboBox->setEnabled(
false );
298 mNorthTypeComboBox->setEnabled(
false );
299 mPictureRotationOffsetSpinBox->setEnabled(
false );
301 mNorthTypeComboBox->setCurrentIndex( mNorthTypeComboBox->findData( mPicture->northMode() ) );
302 mPictureRotationOffsetSpinBox->setValue( mPicture->northOffset() );
304 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mPicture->resizeMode() ) );
308 mAnchorPointComboBox->setCurrentIndex( mAnchorPointComboBox->findData( mPicture->pictureAnchor() ) );
312 mAnchorPointComboBox->setEnabled(
true );
316 mAnchorPointComboBox->setEnabled(
false );
319 switch ( mPicture->originalMode() )
323 mRadioSVG->setChecked(
true );
326 mRadioRaster->setChecked(
true );
330 mSvgSelectorWidget->setSvgPath( mPicture->picturePath() );
331 mSvgSelectorWidget->setSvgParameters( mPicture->svgDynamicParameters() );
333 updateSvgParamGui(
false );
334 mFillColorButton->setColor( mPicture->svgFillColor() );
335 mStrokeColorButton->setColor( mPicture->svgStrokeColor() );
336 mStrokeWidthSpinBox->setValue( mPicture->svgStrokeWidth() );
338 mRotationFromComposerMapCheckBox->blockSignals(
false );
339 mPictureRotationSpinBox->blockSignals(
false );
340 mComposerMapComboBox->blockSignals(
false );
341 mNorthTypeComboBox->blockSignals(
false );
342 mPictureRotationOffsetSpinBox->blockSignals(
false );
343 mResizeModeComboBox->blockSignals(
false );
344 mAnchorPointComboBox->blockSignals(
false );
345 mFillColorButton->blockSignals(
false );
346 mStrokeColorButton->blockSignals(
false );
347 mStrokeWidthSpinBox->blockSignals(
false );
353void QgsLayoutPictureWidget::updateSvgParamGui(
bool resetValues )
358 const QString picturePath = mPicture->picturePath();
361 bool hasFillParam, hasFillOpacityParam, hasStrokeParam, hasStrokeWidthParam, hasStrokeOpacityParam;
362 QColor defaultFill, defaultStroke;
363 double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
364 bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
365 QgsApplication::svgCache()->
containsParams( picturePath, hasFillParam, hasDefaultFillColor, defaultFill, hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity, hasStrokeParam, hasDefaultStrokeColor, defaultStroke, hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth, hasStrokeOpacityParam, hasDefaultStrokeOpacity, defaultStrokeOpacity );
369 QColor fill = mFillColorButton->color();
370 const double newOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
371 if ( hasDefaultFillColor )
375 fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : newOpacity );
376 mFillColorButton->setColor( fill );
378 mFillColorButton->setEnabled( hasFillParam );
379 mFillColorDDBtn->setEnabled( hasFillParam );
380 mFillColorButton->setAllowOpacity( hasFillOpacityParam );
383 QColor stroke = mStrokeColorButton->color();
384 const double newOpacity = hasStrokeOpacityParam ? stroke.alphaF() : 1.0;
385 if ( hasDefaultStrokeColor )
387 stroke = defaultStroke;
389 stroke.setAlphaF( hasDefaultStrokeOpacity ? defaultStrokeOpacity : newOpacity );
390 mStrokeColorButton->setColor( stroke );
392 mStrokeColorButton->setEnabled( hasStrokeParam );
393 mStrokeColorDDBtn->setEnabled( hasStrokeParam );
394 mStrokeColorButton->setAllowOpacity( hasStrokeOpacityParam );
395 if ( hasDefaultStrokeWidth && resetValues )
397 mStrokeWidthSpinBox->setValue( defaultStrokeWidth );
399 mStrokeWidthSpinBox->setEnabled( hasStrokeWidthParam );
400 mStrokeWidthDDBtn->setEnabled( hasStrokeWidthParam );
403void QgsLayoutPictureWidget::mFillColorButton_colorChanged(
const QColor &color )
406 mPicture->setSvgFillColor( color );
407 mPicture->endCommand();
411void QgsLayoutPictureWidget::mStrokeColorButton_colorChanged(
const QColor &color )
414 mPicture->setSvgStrokeColor( color );
415 mPicture->endCommand();
419void QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged(
double d )
422 mPicture->setSvgStrokeWidth( d );
423 mPicture->endCommand();
427void QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged(
double d )
430 mPicture->setNorthOffset( d );
431 mPicture->endCommand();
435void QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged(
int index )
437 mPicture->beginCommand( tr(
"Change Picture North Mode" ) );
439 mPicture->endCommand();
443void QgsLayoutPictureWidget::modeChanged(
bool checked )
448 const bool svg = mRadioSVG->isChecked();
456 mSvgSelectorWidget->setBrowserVisible( svg );
457 mSvgSelectorWidget->setAllowParameters( svg );
458 mSVGParamsGroupBox->setVisible( svg );
460 if ( mPicture && mPicture->mode() != newFormat )
462 mPicture->beginCommand( tr(
"Change Picture Type" ) );
463 mPicture->setMode( newFormat );
464 mPicture->endCommand();
468void QgsLayoutPictureWidget::sourceChanged(
const QString &source )
472 mPicture->beginCommand( tr(
"Change Picture" ) );
475 mPicture->endCommand();
480void QgsLayoutPictureWidget::setSvgDynamicParameters(
const QMap<QString, QgsProperty> ¶meters )
482 mPicture->beginCommand( tr(
"Set SVG parameters" ) );
483 mPicture->setSvgDynamicParameters( parameters );
485 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.