41#include "moc_qgsannotationitemwidget_impl.cpp"
43using namespace Qt::StringLiterals;
47QgsAnnotationPolygonItemWidget::QgsAnnotationPolygonItemWidget( QWidget *parent )
53 mSelector->setDockMode( dockMode() );
55 if ( !mBlockChangedSignal )
63 QVBoxLayout *layout =
new QVBoxLayout();
64 layout->setContentsMargins( 0, 0, 0, 0 );
65 layout->addWidget( mSelector );
66 mSymbolSelectorFrame->setLayout( layout );
69 if ( !mBlockChangedSignal )
78 mPropertiesWidget->updateItem( newItem );
86 polygonItem->setSymbol( mSymbol->clone() );
87 mPropertiesWidget->updateItem( polygonItem );
91void QgsAnnotationPolygonItemWidget::setDockMode(
bool dockMode )
95 mSelector->setDockMode( dockMode );
102 mSelector->setContext( context );
103 mPropertiesWidget->setContext( context );
106QgsAnnotationPolygonItemWidget::~QgsAnnotationPolygonItemWidget() =
default;
114 mItem.reset( polygonItem->
clone() );
115 if ( mItem->symbol() )
117 mSymbol.reset( mItem->symbol()->clone() );
123 mBlockChangedSignal =
true;
124 mSelector->loadSymbol( mSymbol.get() );
125 mSelector->updatePreview();
126 mPropertiesWidget->setItem( mItem.get() );
127 mBlockChangedSignal =
false;
137QgsAnnotationLineItemWidget::QgsAnnotationLineItemWidget( QWidget *parent )
143 mSelector->setDockMode( dockMode() );
145 if ( !mBlockChangedSignal )
153 QVBoxLayout *layout =
new QVBoxLayout();
154 layout->setContentsMargins( 0, 0, 0, 0 );
155 layout->addWidget( mSelector );
156 mSymbolSelectorFrame->setLayout( layout );
159 if ( !mBlockChangedSignal )
168 mPropertiesWidget->updateItem( newItem );
176 lineItem->setSymbol( mSymbol->clone() );
177 mPropertiesWidget->updateItem( lineItem );
181void QgsAnnotationLineItemWidget::setDockMode(
bool dockMode )
185 mSelector->setDockMode( dockMode );
192 mSelector->setContext( context );
193 mPropertiesWidget->setContext( context );
196QgsAnnotationLineItemWidget::~QgsAnnotationLineItemWidget() =
default;
204 mItem.reset( lineItem->
clone() );
205 if ( mItem->symbol() )
207 mSymbol.reset( mItem->symbol()->clone() );
213 mBlockChangedSignal =
true;
214 mSelector->loadSymbol( mSymbol.get() );
215 mSelector->updatePreview();
216 mPropertiesWidget->setItem( mItem.get() );
217 mBlockChangedSignal =
false;
227QgsAnnotationMarkerItemWidget::QgsAnnotationMarkerItemWidget( QWidget *parent )
233 mSelector->setDockMode( dockMode() );
235 if ( !mBlockChangedSignal )
243 QVBoxLayout *layout =
new QVBoxLayout();
244 layout->setContentsMargins( 0, 0, 0, 0 );
245 layout->addWidget( mSelector );
246 mSymbolSelectorFrame->setLayout( layout );
249 if ( !mBlockChangedSignal )
258 mPropertiesWidget->updateItem( newItem );
266 markerItem->setSymbol( mSymbol->clone() );
267 mPropertiesWidget->updateItem( markerItem );
271void QgsAnnotationMarkerItemWidget::setDockMode(
bool dockMode )
275 mSelector->setDockMode( dockMode );
282 mSelector->setContext( context );
283 mPropertiesWidget->setContext( context );
286QgsAnnotationMarkerItemWidget::~QgsAnnotationMarkerItemWidget() =
default;
294 mItem.reset( markerItem->
clone() );
295 if ( mItem->symbol() )
297 mSymbol.reset( mItem->symbol()->clone() );
303 mBlockChangedSignal =
true;
304 mSelector->loadSymbol( mSymbol.get() );
305 mSelector->updatePreview();
306 mPropertiesWidget->setItem( mItem.get() );
307 mBlockChangedSignal =
false;
317QgsAnnotationPointTextItemWidget::QgsAnnotationPointTextItemWidget( QWidget *parent )
326 mSpinTextAngle->setClearValue( 0 );
328 populateRotationModeComboBox( mRotationModeCombo );
330 mAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
335 if ( !mBlockChangedSignal )
339 if ( !mBlockChangedSignal )
342 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsAnnotationPointTextItemWidget::mInsertExpressionButton_clicked );
344 if ( !mBlockChangedSignal )
348 connect( mSpinTextAngle, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, [
this] {
349 if ( !mBlockChangedSignal )
353 connect( mRotationModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this] {
354 if ( !mBlockChangedSignal )
359 if ( !mBlockChangedSignal )
367 updateItem( newItem );
375 mBlockChangedSignal =
true;
376 pointTextItem->setFormat( mTextFormatButton->textFormat() );
377 pointTextItem->setText( mTextFormatButton->textFormat().allowHtmlFormatting() ? mTextEdit->toHtml() : mTextEdit->toPlainText() );
378 pointTextItem->setAngle( mSpinTextAngle->value() );
380 pointTextItem->setAlignment( mAlignmentComboBox->currentAlignment() );
381 mBlockChangedSignal =
false;
382 mPropertiesWidget->updateItem( pointTextItem );
389 if ( mTextFormatButton )
391 mTextFormatButton->setMapCanvas( context.
mapCanvas() );
392 mTextFormatButton->setMessageBar( context.
messageBar() );
394 mPropertiesWidget->setContext( context );
397void QgsAnnotationPointTextItemWidget::focusDefaultWidget()
399 mTextEdit->textEdit()->selectAll();
400 mTextEdit->setFocus();
403QgsAnnotationPointTextItemWidget::~QgsAnnotationPointTextItemWidget() =
default;
411 mItem.reset( textItem->
clone() );
413 mBlockChangedSignal =
true;
414 mTextFormatButton->setTextFormat( mItem->format() );
416 mTextEdit->
setText( mItem->text() );
417 mSpinTextAngle->setValue( mItem->angle() );
418 mRotationModeCombo->setCurrentIndex( mRotationModeCombo->findData( QVariant::fromValue( mItem->rotationMode() ) ) );
419 mAlignmentComboBox->setCurrentAlignment( mItem->alignment() & Qt::AlignHorizontal_Mask );
420 mPropertiesWidget->setItem( mItem.get() );
421 mBlockChangedSignal =
false;
426void QgsAnnotationPointTextItemWidget::mInsertExpressionButton_clicked()
431 if ( context().expressionContext() )
438 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
439 if ( exprDlg.exec() == QDialog::Accepted )
441 expression = exprDlg.expressionText().trimmed();
442 if ( !expression.isEmpty() )
444 mTextEdit->textEdit()->insertPlainText(
"[%" + expression +
"%]" );
454QgsAnnotationLineTextItemWidget::QgsAnnotationLineTextItemWidget( QWidget *parent )
470 if ( !mBlockChangedSignal )
474 if ( !mBlockChangedSignal )
477 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsAnnotationLineTextItemWidget::mInsertExpressionButton_clicked );
479 if ( !mBlockChangedSignal )
483 mOffsetUnitWidget->setUnits(
486 mSpinOffset->setClearValue( 0.0 );
487 connect( mSpinOffset,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, [
this] {
488 if ( !mBlockChangedSignal )
493 if ( !mBlockChangedSignal )
497 connect( mAlignmentCombo, qOverload< int >( &QComboBox::currentIndexChanged ),
this, [
this] {
498 if ( !mBlockChangedSignal )
503QgsAnnotationLineTextItemWidget::~QgsAnnotationLineTextItemWidget() =
default;
508 updateItem( newItem );
516 mBlockChangedSignal =
true;
517 lineTextItem->setFormat( mTextFormatButton->textFormat() );
518 lineTextItem->setText( mTextFormatButton->textFormat().allowHtmlFormatting() ? mTextEdit->toHtml() : mTextEdit->toPlainText() );
520 lineTextItem->setOffsetFromLine( mSpinOffset->value() );
521 lineTextItem->setOffsetFromLineUnit( mOffsetUnitWidget->unit() );
522 lineTextItem->setOffsetFromLineMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
526 mBlockChangedSignal =
false;
527 mPropertiesWidget->updateItem( lineTextItem );
534 if ( mTextFormatButton )
536 mTextFormatButton->setMapCanvas( context.
mapCanvas() );
537 mTextFormatButton->setMessageBar( context.
messageBar() );
539 mPropertiesWidget->setContext( context );
542void QgsAnnotationLineTextItemWidget::focusDefaultWidget()
544 mTextEdit->textEdit()->selectAll();
545 mTextEdit->setFocus();
554 mItem.reset( textItem->
clone() );
556 mBlockChangedSignal =
true;
557 mTextFormatButton->setTextFormat( mItem->format() );
559 mTextEdit->
setText( mItem->text() );
560 mPropertiesWidget->setItem( mItem.get() );
562 mSpinOffset->setValue( mItem->offsetFromLine() );
563 mOffsetUnitWidget->setUnit( mItem->offsetFromLineUnit() );
564 mOffsetUnitWidget->setMapUnitScale( mItem->offsetFromLineMapUnitScale() );
566 mAlignmentCombo->setCurrentIndex( mAlignmentCombo->findData( QVariant::fromValue( mItem->textAnchor() ) ) );
568 mBlockChangedSignal =
false;
573void QgsAnnotationLineTextItemWidget::mInsertExpressionButton_clicked()
578 if ( context().expressionContext() )
585 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
586 if ( exprDlg.exec() == QDialog::Accepted )
588 expression = exprDlg.expressionText().trimmed();
589 if ( !expression.isEmpty() )
591 mTextEdit->textEdit()->insertPlainText(
"[%" + expression +
"%]" );
601QgsAnnotationRectangleTextItemWidget::QgsAnnotationRectangleTextItemWidget( QWidget *parent )
610 populateRotationModeComboBox( mRotationModeCombo );
612 mSizeUnitWidget->setUnits(
617 mBackgroundSymbolButton->setDialogTitle( tr(
"Background" ) );
618 mBackgroundSymbolButton->registerExpressionContextGenerator(
this );
620 mFrameSymbolButton->setDialogTitle( tr(
"Frame" ) );
621 mFrameSymbolButton->registerExpressionContextGenerator(
this );
623 mSpinBottomMargin->setClearValue( 0 );
624 mSpinTopMargin->setClearValue( 0 );
625 mSpinRightMargin->setClearValue( 0 );
626 mSpinLeftMargin->setClearValue( 0 );
627 mMarginUnitWidget->setUnits(
635 mAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight | Qt::AlignJustify );
636 mVerticalAlignmentComboBox->setAvailableAlignments( Qt::AlignTop | Qt::AlignVCenter | Qt::AlignBottom );
644 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsAnnotationRectangleTextItemWidget::mInsertExpressionButton_clicked );
648 connect( mFrameCheckbox, &QGroupBox::toggled,
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
649 connect( mBackgroundCheckbox, &QGroupBox::toggled,
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
650 connect( mBackgroundSymbolButton, &
QgsSymbolButton::changed,
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
651 connect( mFrameSymbolButton, &
QgsSymbolButton::changed,
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
652 connect( mSpinTopMargin, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
653 connect( mSpinRightMargin, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
654 connect( mSpinLeftMargin, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
655 connect( mSpinBottomMargin, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
660 connect( mWidthSpinBox, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::setWidth );
661 connect( mHeightSpinBox, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::setHeight );
663 connect( mSizeModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsAnnotationRectangleTextItemWidget::sizeModeChanged );
664 connect( mRotationModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
665 mSpinAngle->setClearValue( 0 );
666 connect( mSpinAngle, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsAnnotationRectangleTextItemWidget::onWidgetChanged );
667 mWidgetFixedSize->hide();
674 updateItem( newItem );
682 mBlockChangedSignal =
true;
683 rectTextItem->setFormat( mTextFormatButton->textFormat() );
684 rectTextItem->setText( mTextFormatButton->textFormat().allowHtmlFormatting() ? mTextEdit->toHtml() : mTextEdit->toPlainText() );
685 rectTextItem->setAlignment( mAlignmentComboBox->currentAlignment() | mVerticalAlignmentComboBox->currentAlignment() );
689 rectTextItem->setFixedSize( QSizeF( mWidthSpinBox->value(), mHeightSpinBox->value() ) );
690 rectTextItem->setFixedSizeUnit( mSizeUnitWidget->unit() );
692 rectTextItem->setRotation( mSpinAngle->value() );
695 rectTextItem->setBackgroundEnabled( mBackgroundCheckbox->isChecked() );
696 rectTextItem->setFrameEnabled( mFrameCheckbox->isChecked() );
697 rectTextItem->setBackgroundSymbol( mBackgroundSymbolButton->clonedSymbol<
QgsFillSymbol>() );
698 rectTextItem->setFrameSymbol( mFrameSymbolButton->clonedSymbol<
QgsFillSymbol>() );
700 rectTextItem->setMargins(
QgsMargins( mSpinLeftMargin->value(), mSpinTopMargin->value(), mSpinRightMargin->value(), mSpinBottomMargin->value() ) );
701 rectTextItem->setMarginsUnit( mMarginUnitWidget->unit() );
703 if ( mUpdateItemPosition )
705 rectTextItem->setBounds( mItem->bounds() );
706 mUpdateItemPosition =
false;
709 mBlockChangedSignal =
false;
711 mPropertiesWidget->updateItem( rectTextItem );
718 if ( mTextFormatButton )
720 mTextFormatButton->setMapCanvas( context.
mapCanvas() );
721 mTextFormatButton->setMessageBar( context.
messageBar() );
723 mBackgroundSymbolButton->setMapCanvas( context.
mapCanvas() );
724 mBackgroundSymbolButton->setMessageBar( context.
messageBar() );
725 mFrameSymbolButton->setMapCanvas( context.
mapCanvas() );
726 mFrameSymbolButton->setMessageBar( context.
messageBar() );
727 mPropertiesWidget->setContext( context );
733 if ( context().expressionContext() )
737 return expressionContext;
740void QgsAnnotationRectangleTextItemWidget::focusDefaultWidget()
742 mTextEdit->textEdit()->selectAll();
743 mTextEdit->setFocus();
746QgsAnnotationRectangleTextItemWidget::~QgsAnnotationRectangleTextItemWidget() =
default;
754 mItem.reset( textItem->
clone() );
756 mBlockChangedSignal =
true;
757 mTextFormatButton->setTextFormat( mItem->format() );
759 mTextEdit->
setText( mItem->text() );
760 mAlignmentComboBox->setCurrentAlignment( mItem->alignment() & Qt::AlignHorizontal_Mask );
761 mVerticalAlignmentComboBox->setCurrentAlignment( mItem->alignment() & Qt::AlignVertical_Mask );
762 mPropertiesWidget->setItem( mItem.get() );
766 mBackgroundSymbolButton->setSymbol( symbol->clone() );
770 mFrameSymbolButton->setSymbol( symbol->clone() );
772 mMarginUnitWidget->setUnit( textItem->
marginsUnit() );
773 mSpinLeftMargin->setValue( textItem->
margins().
left() );
774 mSpinTopMargin->setValue( textItem->
margins().
top() );
775 mSpinRightMargin->setValue( textItem->
margins().
right() );
778 mWidthSpinBox->setValue( textItem->
fixedSize().width() );
779 mHeightSpinBox->setValue( textItem->
fixedSize().height() );
781 mSizeModeCombo->setCurrentIndex( mSizeModeCombo->findData( QVariant::fromValue( textItem->
placementMode() ) ) );
782 mRotationModeCombo->setCurrentIndex( mRotationModeCombo->findData( QVariant::fromValue( textItem->
rotationMode() ) ) );
783 mSpinAngle->setValue( textItem->
rotation() );
785 mBlockChangedSignal =
false;
790void QgsAnnotationRectangleTextItemWidget::onWidgetChanged()
792 if ( !mBlockChangedSignal )
796void QgsAnnotationRectangleTextItemWidget::sizeModeChanged()
802 mWidgetFixedSize->hide();
808 const QgsRectangle itemBoundsMapUnits = details->boundingBox();
811 const QgsPointXY topLeftPixels = canvas->mapSettings().mapToPixel().transform( itemBoundsMapUnits.
xMinimum(), itemBoundsMapUnits.
yMinimum() );
812 const QgsPointXY bottomRightPixels = canvas->mapSettings().mapToPixel().transform( itemBoundsMapUnits.
xMaximum(), itemBoundsMapUnits.
yMaximum() );
813 const double widthPixels = std::abs( bottomRightPixels.
x() - topLeftPixels.
x() );
814 const double heightPixels = std::abs( bottomRightPixels.
y() - topLeftPixels.
y() );
817 const double pixelsPerMm = canvas->mapSettings().outputDpi() / 25.4;
819 mItem->setFixedSize( QSizeF( widthPixels / pixelsPerMm, heightPixels / pixelsPerMm ) );
822 whileBlocking( mWidthSpinBox )->setValue( mItem->fixedSize().width() );
823 whileBlocking( mHeightSpinBox )->setValue( mItem->fixedSize().height() );
824 whileBlocking( mSizeUnitWidget )->setUnit( mItem->fixedSizeUnit() );
826 mUpdateItemPosition =
true;
830 mWidgetFixedSize->show();
841 const double centerX = ( itemBounds.
center().x() - canvas->extent().xMinimum() ) / canvas->extent().width();
842 const double centerY = ( canvas->extent().yMaximum() - itemBounds.
center().
y() ) / canvas->extent().height();
844 mUpdateItemPosition =
true;
848 mWidgetFixedSize->hide();
856void QgsAnnotationRectangleTextItemWidget::setWidth()
861void QgsAnnotationRectangleTextItemWidget::setHeight()
866void QgsAnnotationRectangleTextItemWidget::mInsertExpressionButton_clicked()
872 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
873 if ( exprDlg.exec() == QDialog::Accepted )
875 expression = exprDlg.expressionText().trimmed();
876 if ( !expression.isEmpty() )
878 mTextEdit->textEdit()->insertPlainText(
"[%" + expression +
"%]" );
888QgsAnnotationPictureItemWidget::QgsAnnotationPictureItemWidget( QWidget *parent )
899 populateRotationModeComboBox( mRotationModeCombo );
901 mSizeUnitWidget->setUnits(
906 mBackgroundSymbolButton->setDialogTitle( tr(
"Background" ) );
907 mBackgroundSymbolButton->registerExpressionContextGenerator(
this );
909 mFrameSymbolButton->setDialogTitle( tr(
"Frame" ) );
910 mFrameSymbolButton->registerExpressionContextGenerator(
this );
913 if ( !mBlockChangedSignal )
917 connect( mSizeModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsAnnotationPictureItemWidget::sizeModeChanged );
919 connect( mRotationModeCombo, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
921 mSpinAngle->setClearValue( 0 );
922 connect( mSpinAngle, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
924 connect( mRadioSVG, &QRadioButton::toggled,
this, &QgsAnnotationPictureItemWidget::modeChanged );
925 connect( mRadioRaster, &QRadioButton::toggled,
this, &QgsAnnotationPictureItemWidget::modeChanged );
927 if ( !mRadioSVG->isChecked() && QFileInfo( source ).suffix().compare(
"svg"_L1, Qt::CaseInsensitive ) == 0 )
929 mRadioSVG->setChecked(
true );
935 connect( mLockAspectRatioCheck, &QCheckBox::toggled,
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
936 connect( mFrameCheckbox, &QGroupBox::toggled,
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
937 connect( mBackgroundCheckbox, &QGroupBox::toggled,
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
938 connect( mBackgroundSymbolButton, &
QgsSymbolButton::changed,
this, &QgsAnnotationPictureItemWidget::onWidgetChanged );
942 connect( mWidthSpinBox, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationPictureItemWidget::setWidth );
943 connect( mHeightSpinBox, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsAnnotationPictureItemWidget::setHeight );
947QgsAnnotationPictureItemWidget::~QgsAnnotationPictureItemWidget() =
default;
952 updateItem( newItem );
960 const bool svg = mRadioSVG->isChecked();
962 const QString path = mSourceLineEdit->source();
963 pictureItem->setPath( newFormat, path );
966 switch ( pictureItem->placementMode() )
969 pictureItem->setLockAspectRatio( mLockAspectRatioCheck->isChecked() );
973 pictureItem->setLockAspectRatio( mLockAspectRatio->isChecked() );
977 pictureItem->setFixedSize( QSizeF( mWidthSpinBox->value(), mHeightSpinBox->value() ) );
978 pictureItem->setFixedSizeUnit( mSizeUnitWidget->unit() );
980 pictureItem->setRotation( mSpinAngle->value() );
983 pictureItem->setBackgroundEnabled( mBackgroundCheckbox->isChecked() );
984 pictureItem->setFrameEnabled( mFrameCheckbox->isChecked() );
985 pictureItem->setBackgroundSymbol( mBackgroundSymbolButton->clonedSymbol<
QgsFillSymbol>() );
986 pictureItem->setFrameSymbol( mFrameSymbolButton->clonedSymbol<
QgsFillSymbol>() );
988 if ( mUpdateItemPosition )
990 pictureItem->setBounds( mItem->bounds() );
991 mUpdateItemPosition =
false;
994 mPropertiesWidget->updateItem( pictureItem );
998void QgsAnnotationPictureItemWidget::setDockMode(
bool dockMode )
1006 mPropertiesWidget->setContext( context );
1007 mBackgroundSymbolButton->setMapCanvas( context.
mapCanvas() );
1008 mBackgroundSymbolButton->setMessageBar( context.
messageBar() );
1009 mFrameSymbolButton->setMapCanvas( context.
mapCanvas() );
1010 mFrameSymbolButton->setMessageBar( context.
messageBar() );
1016 if ( context().expressionContext() )
1020 return expressionContext;
1023void QgsAnnotationPictureItemWidget::focusDefaultWidget()
1025 mSourceLineEdit->setFocus();
1034 mItem.reset( pictureItem->
clone() );
1036 mBlockChangedSignal =
true;
1037 mPropertiesWidget->setItem( mItem.get() );
1039 mLockAspectRatioCheck->setChecked( mItem->lockAspectRatio() );
1040 mLockAspectRatio->setLocked( mItem->lockAspectRatio() );
1041 switch ( pictureItem->
format() )
1044 mRadioSVG->setChecked(
true );
1047 mRadioRaster->setChecked(
true );
1053 mSourceLineEdit->setSource( pictureItem->
path() );
1057 mBackgroundSymbolButton->setSymbol( symbol->clone() );
1059 mFrameCheckbox->setChecked( pictureItem->
frameEnabled() );
1061 mFrameSymbolButton->setSymbol( symbol->clone() );
1063 mWidthSpinBox->setValue( pictureItem->
fixedSize().width() );
1064 mHeightSpinBox->setValue( pictureItem->
fixedSize().height() );
1065 mSizeModeCombo->setCurrentIndex( mSizeModeCombo->findData( QVariant::fromValue( pictureItem->
placementMode() ) ) );
1066 mSpinAngle->setValue( pictureItem->
rotation() );
1067 mRotationModeCombo->setCurrentIndex( mRotationModeCombo->findData( QVariant::fromValue( pictureItem->
rotationMode() ) ) );
1070 mBlockChangedSignal =
false;
1075void QgsAnnotationPictureItemWidget::onWidgetChanged()
1077 if ( !mBlockChangedSignal )
1081void QgsAnnotationPictureItemWidget::modeChanged(
bool checked )
1086 const bool svg = mRadioSVG->isChecked();
1096void QgsAnnotationPictureItemWidget::sizeModeChanged()
1102 mSizeStackedWidget->setCurrentWidget( mPageSpatialBounds );
1106 mSizeStackedWidget->setCurrentWidget( mPageFixedSize );
1114 const QgsRectangle itemBounds = details->boundingBox();
1117 const double centerX = ( itemBounds.
center().x() - canvas->extent().xMinimum() ) / canvas->extent().width();
1118 const double centerY = ( canvas->extent().yMaximum() - itemBounds.
center().
y() ) / canvas->extent().height();
1120 mUpdateItemPosition =
true;
1124 mSizeStackedWidget->setCurrentWidget( mPageFixedSize );
1132void QgsAnnotationPictureItemWidget::setWidth()
1134 if ( mLockAspectRatio->locked() )
1136 const double ratio = pictureAspectRatio();
1138 whileBlocking( mHeightSpinBox )->setValue( mWidthSpinBox->value() * ratio );
1144void QgsAnnotationPictureItemWidget::setHeight()
1146 if ( mLockAspectRatio->locked() )
1148 const double ratio = pictureAspectRatio();
1150 whileBlocking( mWidthSpinBox )->setValue( mHeightSpinBox->value() / ratio );
1156void QgsAnnotationPictureItemWidget::setLockAspectRatio(
bool locked )
1158 if ( locked && !mBlockChangedSignal )
1160 const double ratio = pictureAspectRatio();
1162 whileBlocking( mHeightSpinBox )->setValue( mWidthSpinBox->value() * ratio );
1168double QgsAnnotationPictureItemWidget::pictureAspectRatio()
const
1170 const bool svg = mRadioSVG->isChecked();
1171 const QString path = mSourceLineEdit->source();
1181 if ( size.isValid() && size.width() > 0 )
1182 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.
@ 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.
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.
QgsAnnotationPictureItem * clone() const override
Returns a clone of the item.
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.
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.