42#include "moc_qgsannotationitemwidget_impl.cpp"
44using namespace Qt::StringLiterals;
48QgsAnnotationPolygonItemWidget::QgsAnnotationPolygonItemWidget( QWidget *parent )
54 mSelector->setDockMode( dockMode() );
56 if ( !mBlockChangedSignal )
64 QVBoxLayout *layout =
new QVBoxLayout();
65 layout->setContentsMargins( 0, 0, 0, 0 );
66 layout->addWidget( mSelector );
67 mSymbolSelectorFrame->setLayout( layout );
70 if ( !mBlockChangedSignal )
79 mPropertiesWidget->updateItem( newItem );
87 polygonItem->setSymbol( mSymbol->clone() );
88 mPropertiesWidget->updateItem( polygonItem );
92void QgsAnnotationPolygonItemWidget::setDockMode(
bool dockMode )
96 mSelector->setDockMode( dockMode );
103 mSelector->setContext( context );
104 mPropertiesWidget->setContext( context );
107QgsAnnotationPolygonItemWidget::~QgsAnnotationPolygonItemWidget() =
default;
115 mItem.reset( polygonItem->
clone() );
116 if ( mItem->symbol() )
118 mSymbol.reset( mItem->symbol()->clone() );
124 mBlockChangedSignal =
true;
125 mSelector->loadSymbol( mSymbol.get() );
126 mSelector->updatePreview();
127 mPropertiesWidget->setItem( mItem.get() );
128 mBlockChangedSignal =
false;
138QgsAnnotationLineItemWidget::QgsAnnotationLineItemWidget( QWidget *parent )
144 mSelector->setDockMode( dockMode() );
146 if ( !mBlockChangedSignal )
154 QVBoxLayout *layout =
new QVBoxLayout();
155 layout->setContentsMargins( 0, 0, 0, 0 );
156 layout->addWidget( mSelector );
157 mSymbolSelectorFrame->setLayout( layout );
160 if ( !mBlockChangedSignal )
169 mPropertiesWidget->updateItem( newItem );
177 lineItem->setSymbol( mSymbol->clone() );
178 mPropertiesWidget->updateItem( lineItem );
182void QgsAnnotationLineItemWidget::setDockMode(
bool dockMode )
186 mSelector->setDockMode( dockMode );
193 mSelector->setContext( context );
194 mPropertiesWidget->setContext( context );
197QgsAnnotationLineItemWidget::~QgsAnnotationLineItemWidget() =
default;
205 mItem.reset( lineItem->
clone() );
206 if ( mItem->symbol() )
208 mSymbol.reset( mItem->symbol()->clone() );
214 mBlockChangedSignal =
true;
215 mSelector->loadSymbol( mSymbol.get() );
216 mSelector->updatePreview();
217 mPropertiesWidget->setItem( mItem.get() );
218 mBlockChangedSignal =
false;
228QgsAnnotationMarkerItemWidget::QgsAnnotationMarkerItemWidget( QWidget *parent )
234 mSelector->setDockMode( dockMode() );
236 if ( !mBlockChangedSignal )
244 QVBoxLayout *layout =
new QVBoxLayout();
245 layout->setContentsMargins( 0, 0, 0, 0 );
246 layout->addWidget( mSelector );
247 mSymbolSelectorFrame->setLayout( layout );
250 if ( !mBlockChangedSignal )
259 mPropertiesWidget->updateItem( newItem );
267 markerItem->setSymbol( mSymbol->clone() );
268 mPropertiesWidget->updateItem( markerItem );
272void QgsAnnotationMarkerItemWidget::setDockMode(
bool dockMode )
276 mSelector->setDockMode( dockMode );
283 mSelector->setContext( context );
284 mPropertiesWidget->setContext( context );
287QgsAnnotationMarkerItemWidget::~QgsAnnotationMarkerItemWidget() =
default;
295 mItem.reset( markerItem->
clone() );
296 if ( mItem->symbol() )
298 mSymbol.reset( mItem->symbol()->clone() );
304 mBlockChangedSignal =
true;
305 mSelector->loadSymbol( mSymbol.get() );
306 mSelector->updatePreview();
307 mPropertiesWidget->setItem( mItem.get() );
308 mBlockChangedSignal =
false;
318QgsAnnotationPointTextItemWidget::QgsAnnotationPointTextItemWidget( QWidget *parent )
327 mSpinTextAngle->setClearValue( 0 );
329 populateRotationModeComboBox( mRotationModeCombo );
331 mAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
336 if ( !mBlockChangedSignal )
340 if ( !mBlockChangedSignal )
343 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsAnnotationPointTextItemWidget::mInsertExpressionButton_clicked );
345 if ( !mBlockChangedSignal )
349 connect( mSpinTextAngle, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] {
350 if ( !mBlockChangedSignal )
354 connect( mRotationModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] {
355 if ( !mBlockChangedSignal )
360 if ( !mBlockChangedSignal )
368 updateItem( newItem );
376 mBlockChangedSignal =
true;
377 pointTextItem->setFormat( mTextFormatButton->textFormat() );
378 pointTextItem->setText( mTextFormatButton->textFormat().allowHtmlFormatting() ? mTextEdit->toHtml() : mTextEdit->toPlainText() );
379 pointTextItem->setAngle( mSpinTextAngle->value() );
381 pointTextItem->setAlignment( mAlignmentComboBox->currentAlignment() );
382 mBlockChangedSignal =
false;
383 mPropertiesWidget->updateItem( pointTextItem );
390 if ( mTextFormatButton )
392 mTextFormatButton->setMapCanvas( context.
mapCanvas() );
393 mTextFormatButton->setMessageBar( context.
messageBar() );
395 mPropertiesWidget->setContext( context );
398void QgsAnnotationPointTextItemWidget::focusDefaultWidget()
400 mTextEdit->textEdit()->selectAll();
401 mTextEdit->setFocus();
404QgsAnnotationPointTextItemWidget::~QgsAnnotationPointTextItemWidget() =
default;
412 mItem.reset( textItem->
clone() );
414 mBlockChangedSignal =
true;
415 mTextFormatButton->setTextFormat( mItem->format() );
417 mTextEdit->
setText( mItem->text() );
418 mSpinTextAngle->setValue( mItem->angle() );
419 mRotationModeCombo->setCurrentIndex( mRotationModeCombo->findData( QVariant::fromValue( mItem->rotationMode() ) ) );
420 mAlignmentComboBox->setCurrentAlignment( mItem->alignment() & Qt::AlignHorizontal_Mask );
421 mPropertiesWidget->setItem( mItem.get() );
422 mBlockChangedSignal =
false;
427void QgsAnnotationPointTextItemWidget::mInsertExpressionButton_clicked()
432 if ( context().expressionContext() )
439 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
440 if ( exprDlg.exec() == QDialog::Accepted )
442 expression = exprDlg.expressionText().trimmed();
443 if ( !expression.isEmpty() )
445 mTextEdit->textEdit()->insertPlainText(
"[%" + expression +
"%]" );
455QgsAnnotationLineTextItemWidget::QgsAnnotationLineTextItemWidget( QWidget *parent )
471 if ( !mBlockChangedSignal )
475 if ( !mBlockChangedSignal )
478 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsAnnotationLineTextItemWidget::mInsertExpressionButton_clicked );
480 if ( !mBlockChangedSignal )
484 mOffsetUnitWidget->setUnits(
487 mSpinOffset->setClearValue( 0.0 );
488 connect( mSpinOffset,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, [
this] {
489 if ( !mBlockChangedSignal )
494 if ( !mBlockChangedSignal )
498 connect( mAlignmentCombo, qOverload< int >( &QComboBox::currentIndexChanged ),
this, [
this] {
499 if ( !mBlockChangedSignal )
504QgsAnnotationLineTextItemWidget::~QgsAnnotationLineTextItemWidget() =
default;
509 updateItem( newItem );
517 mBlockChangedSignal =
true;
518 lineTextItem->setFormat( mTextFormatButton->textFormat() );
519 lineTextItem->setText( mTextFormatButton->textFormat().allowHtmlFormatting() ? mTextEdit->toHtml() : mTextEdit->toPlainText() );
521 lineTextItem->setOffsetFromLine( mSpinOffset->value() );
522 lineTextItem->setOffsetFromLineUnit( mOffsetUnitWidget->unit() );
523 lineTextItem->setOffsetFromLineMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
527 mBlockChangedSignal =
false;
528 mPropertiesWidget->updateItem( lineTextItem );
535 if ( mTextFormatButton )
537 mTextFormatButton->setMapCanvas( context.
mapCanvas() );
538 mTextFormatButton->setMessageBar( context.
messageBar() );
540 mPropertiesWidget->setContext( context );
543void QgsAnnotationLineTextItemWidget::focusDefaultWidget()
545 mTextEdit->textEdit()->selectAll();
546 mTextEdit->setFocus();
555 mItem.reset( textItem->
clone() );
557 mBlockChangedSignal =
true;
558 mTextFormatButton->setTextFormat( mItem->format() );
560 mTextEdit->
setText( mItem->text() );
561 mPropertiesWidget->setItem( mItem.get() );
563 mSpinOffset->setValue( mItem->offsetFromLine() );
564 mOffsetUnitWidget->setUnit( mItem->offsetFromLineUnit() );
565 mOffsetUnitWidget->setMapUnitScale( mItem->offsetFromLineMapUnitScale() );
567 mAlignmentCombo->setCurrentIndex( mAlignmentCombo->findData( QVariant::fromValue( mItem->textAnchor() ) ) );
569 mBlockChangedSignal =
false;
574void QgsAnnotationLineTextItemWidget::mInsertExpressionButton_clicked()
579 if ( context().expressionContext() )
586 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
587 if ( exprDlg.exec() == QDialog::Accepted )
589 expression = exprDlg.expressionText().trimmed();
590 if ( !expression.isEmpty() )
592 mTextEdit->textEdit()->insertPlainText(
"[%" + expression +
"%]" );
602QgsAnnotationRectangleTextItemWidget::QgsAnnotationRectangleTextItemWidget( QWidget *parent )
611 populateRotationModeComboBox( mRotationModeCombo );
613 mSizeUnitWidget->setUnits(
618 mBackgroundSymbolButton->setDialogTitle( tr(
"Background" ) );
619 mBackgroundSymbolButton->registerExpressionContextGenerator(
this );
621 mFrameSymbolButton->setDialogTitle( tr(
"Frame" ) );
622 mFrameSymbolButton->registerExpressionContextGenerator(
this );
624 mSpinBottomMargin->setClearValue( 0 );
625 mSpinTopMargin->setClearValue( 0 );
626 mSpinRightMargin->setClearValue( 0 );
627 mSpinLeftMargin->setClearValue( 0 );
628 mMarginUnitWidget->setUnits(
636 mAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight | Qt::AlignJustify );
637 mVerticalAlignmentComboBox->setAvailableAlignments( Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom );
645 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsAnnotationRectangleTextItemWidget::mInsertExpressionButton_clicked );
649 connect( mFrameCheckbox, &QGroupBox::toggled,
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
650 connect( mBackgroundCheckbox, &QGroupBox::toggled,
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
651 connect( mBackgroundSymbolButton, &
QgsSymbolButton::changed,
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
652 connect( mFrameSymbolButton, &
QgsSymbolButton::changed,
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
653 connect( mSpinTopMargin, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
654 connect( mSpinRightMargin, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
655 connect( mSpinLeftMargin, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
656 connect( mSpinBottomMargin, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
661 connect( mWidthSpinBox, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::setWidth );
662 connect( mHeightSpinBox, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::setHeight );
664 connect( mSizeModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsAnnotationRectangleTextItemWidget::sizeModeChanged );
665 connect( mRotationModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
666 mSpinAngle->setClearValue( 0 );
667 connect( mSpinAngle, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
668 mWidgetFixedSize->hide();
675 updateItem( newItem );
683 mBlockChangedSignal =
true;
684 rectTextItem->setFormat( mTextFormatButton->textFormat() );
685 rectTextItem->setText( mTextFormatButton->textFormat().allowHtmlFormatting() ? mTextEdit->toHtml() : mTextEdit->toPlainText() );
686 rectTextItem->setAlignment( mAlignmentComboBox->currentAlignment() | mVerticalAlignmentComboBox->currentAlignment() );
690 rectTextItem->setFixedSize( QSizeF( mWidthSpinBox->value(), mHeightSpinBox->value() ) );
691 rectTextItem->setFixedSizeUnit( mSizeUnitWidget->unit() );
693 rectTextItem->setRotation( mSpinAngle->value() );
696 rectTextItem->setBackgroundEnabled( mBackgroundCheckbox->isChecked() );
697 rectTextItem->setFrameEnabled( mFrameCheckbox->isChecked() );
698 rectTextItem->setBackgroundSymbol( mBackgroundSymbolButton->clonedSymbol<
QgsFillSymbol>() );
699 rectTextItem->setFrameSymbol( mFrameSymbolButton->clonedSymbol<
QgsFillSymbol>() );
701 rectTextItem->setMargins(
QgsMargins( mSpinLeftMargin->value(), mSpinTopMargin->value(), mSpinRightMargin->value(), mSpinBottomMargin->value() ) );
702 rectTextItem->setMarginsUnit( mMarginUnitWidget->unit() );
704 if ( mUpdateItemPosition )
706 rectTextItem->setBounds( mItem->bounds() );
707 mUpdateItemPosition =
false;
710 mBlockChangedSignal =
false;
712 mPropertiesWidget->updateItem( rectTextItem );
719 if ( mTextFormatButton )
721 mTextFormatButton->setMapCanvas( context.
mapCanvas() );
722 mTextFormatButton->setMessageBar( context.
messageBar() );
724 mBackgroundSymbolButton->setMapCanvas( context.
mapCanvas() );
725 mBackgroundSymbolButton->setMessageBar( context.
messageBar() );
726 mFrameSymbolButton->setMapCanvas( context.
mapCanvas() );
727 mFrameSymbolButton->setMessageBar( context.
messageBar() );
728 mPropertiesWidget->setContext( context );
734 if ( context().expressionContext() )
738 return expressionContext;
741void QgsAnnotationRectangleTextItemWidget::focusDefaultWidget()
743 mTextEdit->textEdit()->selectAll();
744 mTextEdit->setFocus();
747QgsAnnotationRectangleTextItemWidget::~QgsAnnotationRectangleTextItemWidget() =
default;
755 mItem.reset( textItem->
clone() );
757 mBlockChangedSignal =
true;
758 mTextFormatButton->setTextFormat( mItem->format() );
760 mTextEdit->
setText( mItem->text() );
761 mAlignmentComboBox->setCurrentAlignment( mItem->alignment() & Qt::AlignHorizontal_Mask );
762 mVerticalAlignmentComboBox->setCurrentAlignment( mItem->alignment() & Qt::AlignVertical_Mask );
763 mPropertiesWidget->setItem( mItem.get() );
767 mBackgroundSymbolButton->setSymbol( symbol->clone() );
771 mFrameSymbolButton->setSymbol( symbol->clone() );
773 mMarginUnitWidget->setUnit( textItem->
marginsUnit() );
774 mSpinLeftMargin->setValue( textItem->
margins().
left() );
775 mSpinTopMargin->setValue( textItem->
margins().
top() );
776 mSpinRightMargin->setValue( textItem->
margins().
right() );
779 mWidthSpinBox->setValue( textItem->
fixedSize().width() );
780 mHeightSpinBox->setValue( textItem->
fixedSize().height() );
782 mSizeModeCombo->setCurrentIndex( mSizeModeCombo->findData( QVariant::fromValue( textItem->
placementMode() ) ) );
783 mRotationModeCombo->setCurrentIndex( mRotationModeCombo->findData( QVariant::fromValue( textItem->
rotationMode() ) ) );
784 mSpinAngle->setValue( textItem->
rotation() );
786 mBlockChangedSignal =
false;
791void QgsAnnotationRectangleTextItemWidget::onWidgetChanged()
793 if ( !mBlockChangedSignal )
797void QgsAnnotationRectangleTextItemWidget::sizeModeChanged()
803 mWidgetFixedSize->hide();
809 const QgsRectangle itemBoundsMapUnits = details->boundingBox();
812 const QgsPointXY topLeftPixels = canvas->mapSettings().mapToPixel().transform( itemBoundsMapUnits.
xMinimum(), itemBoundsMapUnits.
yMinimum() );
813 const QgsPointXY bottomRightPixels = canvas->mapSettings().mapToPixel().transform( itemBoundsMapUnits.
xMaximum(), itemBoundsMapUnits.
yMaximum() );
814 const double widthPixels = std::abs( bottomRightPixels.
x() - topLeftPixels.
x() );
815 const double heightPixels = std::abs( bottomRightPixels.
y() - topLeftPixels.
y() );
818 const double pixelsPerMm = canvas->mapSettings().outputDpi() / 25.4;
820 mItem->setFixedSize( QSizeF( widthPixels / pixelsPerMm, heightPixels / pixelsPerMm ) );
823 whileBlocking( mWidthSpinBox )->setValue( mItem->fixedSize().width() );
824 whileBlocking( mHeightSpinBox )->setValue( mItem->fixedSize().height() );
825 whileBlocking( mSizeUnitWidget )->setUnit( mItem->fixedSizeUnit() );
827 mUpdateItemPosition =
true;
831 mWidgetFixedSize->show();
842 const double centerX = ( itemBounds.
center().x() - canvas->extent().xMinimum() ) / canvas->extent().width();
843 const double centerY = ( canvas->extent().yMaximum() - itemBounds.
center().
y() ) / canvas->extent().height();
845 mUpdateItemPosition =
true;
849 mWidgetFixedSize->hide();
857void QgsAnnotationRectangleTextItemWidget::setWidth()
862void QgsAnnotationRectangleTextItemWidget::setHeight()
867void QgsAnnotationRectangleTextItemWidget::mInsertExpressionButton_clicked()
873 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
874 if ( exprDlg.exec() == QDialog::Accepted )
876 expression = exprDlg.expressionText().trimmed();
877 if ( !expression.isEmpty() )
879 mTextEdit->textEdit()->insertPlainText(
"[%" + expression +
"%]" );
889QgsAnnotationPictureItemWidget::QgsAnnotationPictureItemWidget( QWidget *parent )
903 populateRotationModeComboBox( mRotationModeCombo );
905 mSizeUnitWidget->setUnits(
910 mBackgroundSymbolButton->setDialogTitle( tr(
"Background" ) );
911 mBackgroundSymbolButton->registerExpressionContextGenerator(
this );
913 mFrameSymbolButton->setDialogTitle( tr(
"Frame" ) );
914 mFrameSymbolButton->registerExpressionContextGenerator(
this );
916 mHeight3DSpinBox->setClearValue( 0, tr(
"Default" ) );
917 mWidth3DSpinBox->setClearValue( 0, tr(
"Default" ) );
920 if ( !mBlockChangedSignal )
924 connect( mSizeModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsAnnotationPictureItemWidget::sizeModeChanged );
926 connect( m3DSizeModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
928 connect( mRotationModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
930 mSpinAngle->setClearValue( 0 );
931 connect( mSpinAngle, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
933 connect( mHeight3DSpinBox, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
934 connect( mWidth3DSpinBox, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
936 connect( mRadioSVG, &QRadioButton::toggled,
this, &QgsAnnotationPictureItemWidget::modeChanged );
937 connect( mRadioRaster, &QRadioButton::toggled,
this, &QgsAnnotationPictureItemWidget::modeChanged );
939 if ( !mRadioSVG->isChecked() && QFileInfo( source ).suffix().compare(
"svg"_L1, Qt::CaseInsensitive ) == 0 )
941 mRadioSVG->setChecked(
true );
947 connect( mLockAspectRatioCheck, &QCheckBox::toggled,
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
948 connect( mFrameCheckbox, &QGroupBox::toggled,
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
949 connect( mBackgroundCheckbox, &QGroupBox::toggled,
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
950 connect( mBackgroundSymbolButton, &
QgsSymbolButton::changed,
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
954 connect( mWidthSpinBox, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationPictureItemWidget::setWidth );
955 connect( mHeightSpinBox, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationPictureItemWidget::setHeight );
959QgsAnnotationPictureItemWidget::~QgsAnnotationPictureItemWidget() =
default;
964 updateItem( newItem );
972 const bool svg = mRadioSVG->isChecked();
974 const QString path = mSourceLineEdit->source();
975 pictureItem->setPath( newFormat, path );
978 switch ( pictureItem->placementMode() )
981 pictureItem->setLockAspectRatio( mLockAspectRatioCheck->isChecked() );
985 pictureItem->setLockAspectRatio( mLockAspectRatio->isChecked() );
989 pictureItem->setFixedSize( QSizeF( mWidthSpinBox->value(), mHeightSpinBox->value() ) );
990 pictureItem->setFixedSizeUnit( mSizeUnitWidget->unit() );
992 pictureItem->setRotation( mSpinAngle->value() );
995 pictureItem->setBackgroundEnabled( mBackgroundCheckbox->isChecked() );
996 pictureItem->setFrameEnabled( mFrameCheckbox->isChecked() );
997 pictureItem->setBackgroundSymbol( mBackgroundSymbolButton->clonedSymbol<
QgsFillSymbol>() );
998 pictureItem->setFrameSymbol( mFrameSymbolButton->clonedSymbol<
QgsFillSymbol>() );
1001 if ( mWidth3DSpinBox->value() > 0 && mHeight3DSpinBox->value() > 0 )
1003 pictureItem->setBillboard3DSize( QSizeF( mWidth3DSpinBox->value(), mHeight3DSpinBox->value() ) );
1007 pictureItem->setBillboard3DSize( QSizeF() );
1010 if ( mUpdateItemPosition )
1012 pictureItem->setBounds( mItem->bounds() );
1013 mUpdateItemPosition =
false;
1016 mPropertiesWidget->updateItem( pictureItem );
1020void QgsAnnotationPictureItemWidget::setDockMode(
bool dockMode )
1028 mPropertiesWidget->setContext( context );
1029 mBackgroundSymbolButton->setMapCanvas( context.
mapCanvas() );
1030 mBackgroundSymbolButton->setMessageBar( context.
messageBar() );
1031 mFrameSymbolButton->setMapCanvas( context.
mapCanvas() );
1032 mFrameSymbolButton->setMessageBar( context.
messageBar() );
1038 if ( context().expressionContext() )
1042 return expressionContext;
1045void QgsAnnotationPictureItemWidget::focusDefaultWidget()
1047 mSourceLineEdit->setFocus();
1056 mItem.reset( pictureItem->
clone() );
1058 mBlockChangedSignal =
true;
1059 mPropertiesWidget->setItem( mItem.get() );
1061 mLockAspectRatioCheck->setChecked( mItem->lockAspectRatio() );
1062 mLockAspectRatio->setLocked( mItem->lockAspectRatio() );
1063 switch ( pictureItem->
format() )
1066 mRadioSVG->setChecked(
true );
1069 mRadioRaster->setChecked(
true );
1075 mSourceLineEdit->setSource( pictureItem->
path() );
1079 mBackgroundSymbolButton->setSymbol( symbol->clone() );
1081 mFrameCheckbox->setChecked( pictureItem->
frameEnabled() );
1083 mFrameSymbolButton->setSymbol( symbol->clone() );
1085 mWidthSpinBox->setValue( pictureItem->
fixedSize().width() );
1086 mHeightSpinBox->setValue( pictureItem->
fixedSize().height() );
1087 mSizeModeCombo->setCurrentIndex( mSizeModeCombo->findData( QVariant::fromValue( pictureItem->
placementMode() ) ) );
1088 mSpinAngle->setValue( pictureItem->
rotation() );
1089 mRotationModeCombo->setCurrentIndex( mRotationModeCombo->findData( QVariant::fromValue( pictureItem->
rotationMode() ) ) );
1092 mHeight3DSpinBox->setValue( pictureItem->
billboard3DSize().height() );
1094 m3DSizeModeCombo->setCurrentIndex( m3DSizeModeCombo->findData( QVariant::fromValue( pictureItem->
billboard3DScaleMode() ) ) );
1097 mBlockChangedSignal =
false;
1102void QgsAnnotationPictureItemWidget::showEvent( QShowEvent *event )
1106 mGroupAppearance3D->setVisible( !layer || layer->
renderer3D() );
1108 QgsAnnotationItemBaseWidget::showEvent( event );
1111void QgsAnnotationPictureItemWidget::onWidgetChanged()
1113 if ( !mBlockChangedSignal )
1117void QgsAnnotationPictureItemWidget::modeChanged(
bool checked )
1122 const bool svg = mRadioSVG->isChecked();
1132void QgsAnnotationPictureItemWidget::sizeModeChanged()
1138 mSizeStackedWidget->setCurrentWidget( mPageSpatialBounds );
1142 mSizeStackedWidget->setCurrentWidget( mPageFixedSize );
1150 const QgsRectangle itemBounds = details->boundingBox();
1153 const double centerX = ( itemBounds.
center().x() - canvas->extent().xMinimum() ) / canvas->extent().width();
1154 const double centerY = ( canvas->extent().yMaximum() - itemBounds.
center().
y() ) / canvas->extent().height();
1156 mUpdateItemPosition =
true;
1160 mSizeStackedWidget->setCurrentWidget( mPageFixedSize );
1168void QgsAnnotationPictureItemWidget::setWidth()
1170 if ( mLockAspectRatio->locked() )
1172 const double ratio = pictureAspectRatio();
1174 whileBlocking( mHeightSpinBox )->setValue( mWidthSpinBox->value() * ratio );
1180void QgsAnnotationPictureItemWidget::setHeight()
1182 if ( mLockAspectRatio->locked() )
1184 const double ratio = pictureAspectRatio();
1186 whileBlocking( mWidthSpinBox )->setValue( mHeightSpinBox->value() / ratio );
1192void QgsAnnotationPictureItemWidget::setLockAspectRatio(
bool locked )
1194 if ( locked && !mBlockChangedSignal )
1196 const double ratio = pictureAspectRatio();
1198 whileBlocking( mHeightSpinBox )->setValue( mWidthSpinBox->value() * ratio );
1204double QgsAnnotationPictureItemWidget::pictureAspectRatio()
const
1206 const bool svg = mRadioSVG->isChecked();
1207 const QString path = mSourceLineEdit->source();
1217 if ( size.isValid() && size.width() > 0 )
1218 return size.height() / size.width();
SymbolRotationMode
Modes for handling how symbol and text entity rotation is handled when maps are rotated.
TextAnchorPoint
Anchor point of label text.
@ EndOfText
Anchor using end of text.
@ StartOfText
Anchor using start of text.
@ CenterOfText
Anchor using center of text.
PictureFormat
Picture formats.
@ Unknown
Invalid or unknown image type.
BillboardScaleMode
3D billboard scaling modes.
@ ViewIndependent
Billboard has a fixed pixel size on the screen, regardless of the camera distance.
@ Perspective
Billboard size is scaled with perspective distance from camera, using world units.
@ Percentage
Percentage of another measurement (e.g., canvas size, feature size).
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes).
@ MetersInMapUnits
Meters value as Map units.
AnnotationPlacementMode
Annotation item placement modes.
@ SpatialBounds
Item is rendered inside fixed spatial bounds, and size will depend on map scale.
@ FixedSize
Item is rendered at a fixed size, regardless of map scale. Item's location is georeferenced to a spat...
@ RelativeToMapFrame
Items size and placement is relative to the map's frame, and the item will always be rendered in the ...
void sourceChanged(const QString &source)
Emitted whenever the file source is changed in the widget.
void changed()
Emitted when the alignment is changed.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Represents a map layer containing a set of georeferenced annotations, e.g.
An annotation item which renders a line symbol along a line geometry.
void setSymbol(QgsLineSymbol *symbol)
Sets the symbol used to render the marker item.
QgsAnnotationLineItem * clone() const override
Returns a clone of the item.
An annotation item which renders text along a line geometry.
QgsAnnotationLineTextItem * clone() const override
Returns a clone of the item.
void setText(const QString &text)
Sets the text rendered by the item.
An annotation item which renders a marker symbol at a point location.
void setSymbol(QgsMarkerSymbol *symbol)
Sets the symbol used to render the marker item.
QgsAnnotationMarkerItem * clone() const override
Returns a clone of the item.
An annotation item which renders a picture.
Qgis::PictureFormat format() const
Returns the picture format.
QString path() const
Returns the path of the image used to render the item.
QSizeF billboard3DSize() const
Returns the 3D billboard size for the picture.
QgsAnnotationPictureItem * clone() const override
Returns a clone of the item.
Qgis::BillboardScaleMode billboard3DScaleMode() const
Returns the 3D billboard scale mode for the picture.
An annotation item which renders a text string at a point location.
void setText(const QString &text)
Sets the text rendered by the item.
QgsAnnotationPointTextItem * clone() const override
Returns a clone of the item.
An annotation item which renders a fill symbol for a polygon geometry.
void setSymbol(QgsFillSymbol *symbol)
Sets the symbol used to render the polygon item.
QgsAnnotationPolygonItem * clone() const override
Returns a clone of the item.
double rotation() const
Returns the rotation of the item, in degrees clockwise.
Qgis::SymbolRotationMode rotationMode() const
Returns the method used to render the item with respect to the rotation of the map.
Qgis::RenderUnit fixedSizeUnit() const
Returns the units to use for fixed item sizes, when the placementMode() is Qgis::AnnotationPlacementM...
QSizeF fixedSize() const
Returns the fixed size to use for the item, when the placementMode() is Qgis::AnnotationPlacementMode...
bool frameEnabled() const
Returns true if the item's frame should be rendered.
const QgsFillSymbol * frameSymbol() const
Returns the symbol used to render the item's frame.
Qgis::AnnotationPlacementMode placementMode() const
Returns the placement mode for the item.
bool backgroundEnabled() const
Returns true if the item's background should be rendered.
const QgsFillSymbol * backgroundSymbol() const
Returns the symbol used to render the item's background.
An annotation item which renders paragraphs of text within a rectangle.
QgsAnnotationRectangleTextItem * clone() const override
Returns a clone of the item.
const QgsMargins & margins() const
Returns the margins between the outside of the item's frame and the interior text.
void setText(const QString &text)
Sets the text rendered by the item.
Qgis::RenderUnit marginsUnit() const
Returns the units for the margins between the item's frame and the interior text.
static QgsRecentStyleHandler * recentStyleHandler()
Returns the handler for recently used style items.
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
A generic dialog for building expression strings.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static QString findAndSelectActiveExpression(QgsCodeEditor *editor, const QString &pattern=QString())
Find the expression under the cursor in the given editor and select it.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
static std::unique_ptr< QgsFillSymbol > createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
QSize originalSize(const QString &path, bool blocking=false) const
Returns the original size (in pixels) of the image at the specified path.
static std::unique_ptr< QgsLineSymbol > createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
Defines the four margins of a rectangle.
double top() const
Returns the top margin.
double right() const
Returns the right margin.
double bottom() const
Returns the bottom margin.
double left() const
Returns the left margin.
static std::unique_ptr< QgsMarkerSymbol > createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void pushRecentSymbol(const QString &identifier, QgsSymbol *symbol)
Pushes a recently used symbol with the specified identifier.
A rectangle specified with double values.
static QgsRectangle fromCenterAndSize(const QgsPointXY ¢er, double width, double height)
Creates a new rectangle, given the specified center point and width and height.
Contains information about a rendered annotation item.
@ PlainText
Plain text mode.
@ QgsTextRenderer
QGIS text renderer mode, exposes the HTML/CSS subset supported by the QgsTextRenderer class.
void textChanged()
Emitted when the text contents are changed.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
QSizeF svgViewboxSize(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >())
Calculates the viewbox size of a (possibly cached) SVG file.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
Abstract base class for all rendered symbols.
QList< Qgis::RenderUnit > RenderUnitList
List of render units.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.