34QgsAnnotationPolygonItemWidget::QgsAnnotationPolygonItemWidget( QWidget *parent )
40 mSelector->setDockMode( dockMode() );
43 if ( !mBlockChangedSignal )
51 QVBoxLayout *layout =
new QVBoxLayout();
52 layout->setContentsMargins( 0, 0, 0, 0 );
53 layout->addWidget( mSelector );
54 mSymbolSelectorFrame->setLayout( layout );
58 if ( !mBlockChangedSignal )
67 mPropertiesWidget->updateItem( newItem );
75 polygonItem->
setSymbol( mSymbol->clone() );
76 mPropertiesWidget->updateItem( polygonItem );
80void QgsAnnotationPolygonItemWidget::setDockMode(
bool dockMode )
84 mSelector->setDockMode( dockMode );
91 mSelector->setContext( context );
92 mPropertiesWidget->setContext( context );
95QgsAnnotationPolygonItemWidget::~QgsAnnotationPolygonItemWidget() =
default;
103 mItem.reset( polygonItem->
clone() );
104 if ( mItem->symbol() )
106 mSymbol.reset( mItem->symbol()->clone() );
112 mBlockChangedSignal =
true;
113 mSelector->loadSymbol( mSymbol.get() );
114 mSelector->updatePreview();
115 mPropertiesWidget->setItem( mItem.get() );
116 mBlockChangedSignal =
false;
126QgsAnnotationLineItemWidget::QgsAnnotationLineItemWidget( QWidget *parent )
132 mSelector->setDockMode( dockMode() );
135 if ( !mBlockChangedSignal )
143 QVBoxLayout *layout =
new QVBoxLayout();
144 layout->setContentsMargins( 0, 0, 0, 0 );
145 layout->addWidget( mSelector );
146 mSymbolSelectorFrame->setLayout( layout );
150 if ( !mBlockChangedSignal )
159 mPropertiesWidget->updateItem( newItem );
168 mPropertiesWidget->updateItem( lineItem );
172void QgsAnnotationLineItemWidget::setDockMode(
bool dockMode )
176 mSelector->setDockMode( dockMode );
183 mSelector->setContext( context );
184 mPropertiesWidget->setContext( context );
187QgsAnnotationLineItemWidget::~QgsAnnotationLineItemWidget() =
default;
195 mItem.reset( lineItem->
clone() );
196 if ( mItem->symbol() )
198 mSymbol.reset( mItem->symbol()->clone() );
204 mBlockChangedSignal =
true;
205 mSelector->loadSymbol( mSymbol.get() );
206 mSelector->updatePreview();
207 mPropertiesWidget->setItem( mItem.get() );
208 mBlockChangedSignal =
false;
218QgsAnnotationMarkerItemWidget::QgsAnnotationMarkerItemWidget( QWidget *parent )
224 mSelector->setDockMode( dockMode() );
227 if ( !mBlockChangedSignal )
235 QVBoxLayout *layout =
new QVBoxLayout();
236 layout->setContentsMargins( 0, 0, 0, 0 );
237 layout->addWidget( mSelector );
238 mSymbolSelectorFrame->setLayout( layout );
242 if ( !mBlockChangedSignal )
251 mPropertiesWidget->updateItem( newItem );
259 markerItem->
setSymbol( mSymbol->clone() );
260 mPropertiesWidget->updateItem( markerItem );
264void QgsAnnotationMarkerItemWidget::setDockMode(
bool dockMode )
268 mSelector->setDockMode( dockMode );
275 mSelector->setContext( context );
276 mPropertiesWidget->setContext( context );
279QgsAnnotationMarkerItemWidget::~QgsAnnotationMarkerItemWidget() =
default;
287 mItem.reset( markerItem->
clone() );
288 if ( mItem->symbol() )
290 mSymbol.reset( mItem->symbol()->clone() );
296 mBlockChangedSignal =
true;
297 mSelector->loadSymbol( mSymbol.get() );
298 mSelector->updatePreview();
299 mPropertiesWidget->setItem( mItem.get() );
300 mBlockChangedSignal =
false;
311QgsAnnotationPointTextItemWidget::QgsAnnotationPointTextItemWidget( QWidget *parent )
317 QVBoxLayout *vLayout =
new QVBoxLayout();
318 vLayout->setContentsMargins( 0, 0, 0, 0 );
319 vLayout->addWidget( mTextFormatWidget );
320 mTextFormatWidgetContainer->setLayout( vLayout );
322 mTextEdit->setMaximumHeight( mTextEdit->fontMetrics().height() * 10 );
324 mSpinTextAngle->setClearValue( 0 );
329 mAlignmentComboBox->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
331 mTextFormatWidget->setDockMode( dockMode() );
334 if ( !mBlockChangedSignal )
337 connect( mTextEdit, &QPlainTextEdit::textChanged,
this, [ = ]
339 if ( !mBlockChangedSignal )
342 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsAnnotationPointTextItemWidget::mInsertExpressionButton_clicked );
345 if ( !mBlockChangedSignal )
349 connect( mSpinTextAngle, qOverload< double >( &QgsDoubleSpinBox::valueChanged ),
this, [ = ]
351 if ( !mBlockChangedSignal )
355 connect( mRotationModeCombo, qOverload< int >( &QComboBox::currentIndexChanged ),
this, [ = ]
357 if ( !mBlockChangedSignal )
363 if ( !mBlockChangedSignal )
371 newItem->
setFormat( mTextFormatWidget->format() );
372 newItem->
setText( mTextEdit->toPlainText() );
373 newItem->
setAngle( mSpinTextAngle->value() );
375 newItem->
setAlignment( mAlignmentComboBox->currentAlignment() );
376 mPropertiesWidget->updateItem( newItem );
384 pointTextItem->
setFormat( mTextFormatWidget->format() );
385 pointTextItem->setText( mTextEdit->toPlainText() );
386 pointTextItem->setAngle( mSpinTextAngle->value() );
388 pointTextItem->setAlignment( mAlignmentComboBox->currentAlignment() );
389 mPropertiesWidget->updateItem( pointTextItem );
393void QgsAnnotationPointTextItemWidget::setDockMode(
bool dockMode )
396 if ( mTextFormatWidget )
397 mTextFormatWidget->setDockMode( dockMode );
403 if ( mTextFormatWidget )
404 mTextFormatWidget->setContext( context );
405 mPropertiesWidget->setContext( context );
408void QgsAnnotationPointTextItemWidget::focusDefaultWidget()
410 mTextEdit->selectAll();
411 mTextEdit->setFocus();
414QgsAnnotationPointTextItemWidget::~QgsAnnotationPointTextItemWidget() =
default;
422 mItem.reset( textItem->
clone() );
424 mBlockChangedSignal =
true;
425 mTextFormatWidget->
setFormat( mItem->format() );
426 mTextEdit->setPlainText( mItem->text() );
427 mSpinTextAngle->setValue( mItem->angle() );
428 mRotationModeCombo->setCurrentIndex( mRotationModeCombo->findData( QVariant::fromValue( mItem->rotationMode() ) ) );
429 mAlignmentComboBox->setCurrentAlignment( mItem->alignment() & Qt::AlignHorizontal_Mask );
430 mPropertiesWidget->setItem( mItem.get() );
431 mBlockChangedSignal =
false;
436void QgsAnnotationPointTextItemWidget::mInsertExpressionButton_clicked()
438 QString selText = mTextEdit->textCursor().selectedText();
441 selText = selText.replace( QChar( 0x2029 ), QChar(
'\n' ) );
444 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
445 selText = selText.mid( 2, selText.size() - 4 );
448 if ( context().expressionContext() )
455 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
456 if ( exprDlg.exec() == QDialog::Accepted )
458 QString expression = exprDlg.expressionText();
459 if ( !expression.isEmpty() )
461 mTextEdit->insertPlainText(
"[%" + expression +
"%]" );
471QgsAnnotationLineTextItemWidget::QgsAnnotationLineTextItemWidget( QWidget *parent )
477 QVBoxLayout *vLayout =
new QVBoxLayout();
478 vLayout->setContentsMargins( 0, 0, 0, 0 );
479 vLayout->addWidget( mTextFormatWidget );
480 mTextFormatWidgetContainer->setLayout( vLayout );
482 mTextEdit->setMaximumHeight( mTextEdit->fontMetrics().height() * 10 );
484 mTextFormatWidget->setDockMode( dockMode() );
487 if ( !mBlockChangedSignal )
490 connect( mTextEdit, &QPlainTextEdit::textChanged,
this, [ = ]
492 if ( !mBlockChangedSignal )
495 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsAnnotationLineTextItemWidget::mInsertExpressionButton_clicked );
498 if ( !mBlockChangedSignal )
504 mSpinOffset->setClearValue( 0.0 );
505 connect( mSpinOffset,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, [ = ]
507 if ( !mBlockChangedSignal )
513 if ( !mBlockChangedSignal )
518QgsAnnotationLineTextItemWidget::~QgsAnnotationLineTextItemWidget() =
default;
523 newItem->
setFormat( mTextFormatWidget->format() );
524 newItem->
setText( mTextEdit->toPlainText() );
530 mPropertiesWidget->updateItem( newItem );
538 lineTextItem->
setFormat( mTextFormatWidget->format() );
539 lineTextItem->setText( mTextEdit->toPlainText() );
541 lineTextItem->setOffsetFromLine( mSpinOffset->value() );
542 lineTextItem->setOffsetFromLineUnit( mOffsetUnitWidget->unit() );
543 lineTextItem->setOffsetFromLineMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
545 mPropertiesWidget->updateItem( lineTextItem );
549void QgsAnnotationLineTextItemWidget::setDockMode(
bool dockMode )
552 if ( mTextFormatWidget )
553 mTextFormatWidget->setDockMode( dockMode );
559 if ( mTextFormatWidget )
560 mTextFormatWidget->setContext( context );
561 mPropertiesWidget->setContext( context );
564void QgsAnnotationLineTextItemWidget::focusDefaultWidget()
566 mTextEdit->selectAll();
567 mTextEdit->setFocus();
576 mItem.reset( textItem->
clone() );
578 mBlockChangedSignal =
true;
579 mTextFormatWidget->
setFormat( mItem->format() );
580 mTextEdit->setPlainText( mItem->text() );
581 mPropertiesWidget->setItem( mItem.get() );
583 mSpinOffset->setValue( mItem->offsetFromLine() );
584 mOffsetUnitWidget->setUnit( mItem->offsetFromLineUnit() );
585 mOffsetUnitWidget->setMapUnitScale( mItem->offsetFromLineMapUnitScale() );
587 mBlockChangedSignal =
false;
592void QgsAnnotationLineTextItemWidget::mInsertExpressionButton_clicked()
594 QString selText = mTextEdit->textCursor().selectedText();
597 selText = selText.replace( QChar( 0x2029 ), QChar(
'\n' ) );
600 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
601 selText = selText.mid( 2, selText.size() - 4 );
604 if ( context().expressionContext() )
611 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
612 if ( exprDlg.exec() == QDialog::Accepted )
614 QString expression = exprDlg.expressionText();
615 if ( !expression.isEmpty() )
617 mTextEdit->insertPlainText(
"[%" + expression +
"%]" );
SymbolRotationMode
Modes for handling how symbol and text entity rotation is handled when maps are rotated.
@ RespectMapRotation
Entity is rotated along with the map.
@ IgnoreMapRotation
Entity ignores map rotation.
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MetersInMapUnits
Meters value as Map units.
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() override
Returns a clone of the item.
An annotation item which renders text along a line geometry.
void setOffsetFromLine(double distance)
Sets the offset distance from the line geometry() to the text's baseline.
void setOffsetFromLineMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the offset from line geometry() distance.
void setText(const QString &text)
Sets the text rendered by the item.
void setOffsetFromLineUnit(Qgis::RenderUnit unit)
Sets the unit for the offset from line geometry() distance.
QgsAnnotationLineTextItem * clone() override
Returns a clone of the item.
void setFormat(const QgsTextFormat &format)
Sets the text format used to render the text.
An annotation item which renders a marker symbol at a point location.
QgsAnnotationMarkerItem * clone() override
Returns a clone of the item.
void setSymbol(QgsMarkerSymbol *symbol)
Sets the symbol used to render the marker 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.
void setFormat(const QgsTextFormat &format)
Sets the text format used to render the text.
void setAngle(double angle)
Sets the text's rotation angle, in degrees clockwise.
void setAlignment(Qt::Alignment alignment)
Sets the text's alignment relative to the reference point().
QgsAnnotationPointTextItem * clone() override
Returns a clone of the item.
void setRotationMode(Qgis::SymbolRotationMode mode)
Sets the rotation mode for the text 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() override
Returns a clone of the item.
static QgsRecentStyleHandler * recentStyleHandler()
Returns the handler for recently used style items.
A generic dialog for building expression strings.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
static QgsLineSymbol * createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
static 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.
static QgsStyle * defaultStyle()
Returns default application-wide style.
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.
A widget for customizing text formatting settings.
void widgetChanged()
Emitted when the text format defined by the widget changes.
QList< Qgis::RenderUnit > RenderUnitList
List of render units.