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 );
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 )
130 void QgsLayoutPictureWidget::mPictureRotationSpinBox_valueChanged(
double d )
135 mPicture->setPictureRotation( d );
136 mPicture->endCommand();
140 void QgsLayoutPictureWidget::mResizeModeComboBox_currentIndexChanged(
int )
147 mPicture->beginCommand( tr(
"Change Resize Mode" ) );
149 mPicture->endCommand();
159 mAnchorPointComboBox->setEnabled(
true );
163 mAnchorPointComboBox->setEnabled(
false );
167 void 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();
204 void 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();
233 void QgsLayoutPictureWidget::mapChanged(
QgsLayoutItem *item )
241 const QgsLayout *layout = mPicture->layout();
253 mPicture->beginCommand( tr(
"Change Rotation Map" ) );
254 mPicture->setLinkedMap( map );
256 mPicture->endCommand();
259 void QgsLayoutPictureWidget::setPicRotationSpinValue(
double r )
261 mPictureRotationSpinBox->blockSignals(
true );
262 mPictureRotationSpinBox->setValue( r );
263 mPictureRotationSpinBox->blockSignals(
false );
266 void 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->mode() )
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 );
356 void 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 mFillColorButton->setAllowOpacity( hasFillOpacityParam );
389 QColor stroke = mStrokeColorButton->color();
390 const double newOpacity = hasStrokeOpacityParam ? stroke.alphaF() : 1.0;
391 if ( hasDefaultStrokeColor )
393 stroke = defaultStroke;
395 stroke.setAlphaF( hasDefaultStrokeOpacity ? defaultStrokeOpacity : newOpacity );
396 mStrokeColorButton->setColor( stroke );
398 mStrokeColorButton->setEnabled( hasStrokeParam );
399 mStrokeColorButton->setAllowOpacity( hasStrokeOpacityParam );
400 if ( hasDefaultStrokeWidth && resetValues )
402 mStrokeWidthSpinBox->setValue( defaultStrokeWidth );
404 mStrokeWidthSpinBox->setEnabled( hasStrokeWidthParam );
407 void QgsLayoutPictureWidget::mFillColorButton_colorChanged(
const QColor &color )
410 mPicture->setSvgFillColor( color );
411 mPicture->endCommand();
415 void QgsLayoutPictureWidget::mStrokeColorButton_colorChanged(
const QColor &color )
418 mPicture->setSvgStrokeColor( color );
419 mPicture->endCommand();
423 void QgsLayoutPictureWidget::mStrokeWidthSpinBox_valueChanged(
double d )
426 mPicture->setSvgStrokeWidth( d );
427 mPicture->endCommand();
431 void QgsLayoutPictureWidget::mPictureRotationOffsetSpinBox_valueChanged(
double d )
434 mPicture->setNorthOffset( d );
435 mPicture->endCommand();
439 void QgsLayoutPictureWidget::mNorthTypeComboBox_currentIndexChanged(
int index )
441 mPicture->beginCommand( tr(
"Change Picture North Mode" ) );
443 mPicture->endCommand();
447 void QgsLayoutPictureWidget::modeChanged(
bool checked )
452 const bool svg = mRadioSVG->isChecked();
460 mSvgSelectorWidget->setBrowserVisible( svg );
461 mSvgSelectorWidget->setAllowParameters( svg );
462 mSVGParamsGroupBox->setVisible( svg );
464 if ( mPicture && mPicture->mode() != newFormat )
466 mPicture->beginCommand( tr(
"Change Picture Type" ) );
467 mPicture->setMode( newFormat );
468 mPicture->endCommand();
472 void QgsLayoutPictureWidget::sourceChanged(
const QString &source )
476 mPicture->beginCommand( tr(
"Change Picture" ) );
479 mPicture->endCommand();
484 void QgsLayoutPictureWidget::setSvgDynamicParameters(
const QMap<QString, QgsProperty> ¶meters )
486 mPicture->beginCommand( tr(
"Set SVG parameters" ) );
487 mPicture->setSvgDynamicParameters( parameters );
489 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.