QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsannotationitemcommonpropertieswidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsannotationitemcommonpropertieswidget.cpp
3 ------------------------
4 Date : September 2021
5 Copyright : (C) 2021 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsannotationitemcommonpropertieswidget.cpp"
18#include "qgsannotationitem.h"
20#include "qgsapplication.h"
21#include "qgscalloutsregistry.h"
22
24 : QWidget( parent )
25{
26 setupUi( this );
27
28 connect( mSpinZIndex, qOverload<int>( &QSpinBox::valueChanged ), this, [ = ]
29 {
30 if ( !mBlockChangedSignal )
31 emit itemChanged();
32 } );
33 mSpinZIndex->setClearValue( 0 );
34
35 connect( mReferenceScaleGroup, &QGroupBox::toggled, this, [ = ]
36 {
37 if ( !mBlockChangedSignal )
38 emit itemChanged();
39 } );
40 connect( mReferenceScaleWidget, &QgsScaleWidget::scaleChanged, this, [ = ]
41 {
42 if ( !mBlockChangedSignal )
43 emit itemChanged();
44 } );
45 connect( mCalloutCheckBox, &QCheckBox::toggled, this, [ = ]
46 {
47 if ( !mBlockChangedSignal )
48 emit itemChanged();
49 } );
50
51 connect( mCalloutPropertiesButton, &QToolButton::clicked, this, &QgsAnnotationItemCommonPropertiesWidget::openCalloutProperties );
52}
53
55
57{
58 mSpinZIndex->setValue( item->zIndex() );
59 mReferenceScaleGroup->setChecked( item->useSymbologyReferenceScale() );
60 mReferenceScaleWidget->setScale( item->symbologyReferenceScale() );
61 mReferenceScaleGroup->setVisible( item->flags() & Qgis::AnnotationItemFlag::SupportsReferenceScale );
62 mCalloutCheckBox->setChecked( item->callout() );
63 mCallout.reset( item->callout() ? item->callout()->clone() : nullptr );
64}
65
67{
68 item->setZIndex( mSpinZIndex->value() );
69 item->setUseSymbologyReferenceScale( mReferenceScaleGroup->isChecked() );
70 item->setSymbologyReferenceScale( mReferenceScaleWidget->scale() );
71 item->setCallout( mCallout && mCalloutCheckBox->isChecked() ? mCallout->clone() : nullptr );
72}
73
75{
76 mContext = context;
77 mReferenceScaleWidget->setMapCanvas( context.mapCanvas() );
78 if ( context.mapCanvas() )
79 mReferenceScaleWidget->setShowCurrentScaleButton( true );
80}
81
86
87void QgsAnnotationItemCommonPropertiesWidget::openCalloutProperties()
88{
90 if ( !mCallout )
91 mCallout.reset( QgsApplication::calloutRegistry()->defaultCallout() );
92 widget->setCallout( mCallout.get() );
93
94 connect( widget, &QgsCalloutPanelWidget::calloutChanged, this, [this, widget]
95 {
96 mCallout.reset( widget->callout()->clone() );
97 if ( !mBlockChangedSignal )
98 emit itemChanged();
99 } );
100
101 if ( QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this ) )
102 {
103 panel->openPanel( widget );
104 }
105}
@ SupportsReferenceScale
Item supports reference scale based rendering.
QgsAnnotationItemCommonPropertiesWidget(QWidget *parent)
Constructor for QgsAnnotationItemCommonPropertiesWidget.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the widget is shown, e.g., the associated map canvas and expression context...
QgsSymbolWidgetContext context() const
Returns the context in which the widget is shown, e.g., the associated map canvas and expression cont...
void setItem(QgsAnnotationItem *item)
Sets the item whose properties should be shown in the widget.
void itemChanged()
Emitted when the annotation item definition in the widget is changed by the user.
void updateItem(QgsAnnotationItem *item)
Updates an item, setting the properties defined in the widget.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
void setUseSymbologyReferenceScale(bool enabled)
Sets whether the annotation item uses a symbology reference scale.
void setZIndex(int index)
Sets the item's z index, which controls the order in which annotation items are rendered in the layer...
bool useSymbologyReferenceScale() const
Returns true if the annotation item uses a symbology reference scale.
void setCallout(QgsCallout *callout)
Sets the item's callout renderer, responsible for drawing item callouts.
void setSymbologyReferenceScale(double scale)
Sets the annotation's symbology reference scale.
virtual Qgis::AnnotationItemFlags flags() const
Returns item flags.
int zIndex() const
Returns the item's z index, which controls the order in which annotation items are rendered in the la...
QgsCallout * callout() const
Returns the item's callout renderer, responsible for drawing item callouts.
double symbologyReferenceScale() const
Returns the annotation's symbology reference scale.
static QgsCalloutRegistry * calloutRegistry()
Returns the application's callout registry, used for managing callout types.
A panel widget for configuration of callouts.
QgsCallout * callout()
Returns a new callout, respecting the configuration from the widget.
void calloutChanged()
Emitted when the callout defined by the widget changes.
void setCallout(const QgsCallout *callout)
Sets the widget state to match the specified callout.
virtual QgsCallout * clone() const =0
Duplicates a callout by creating a deep copy of the callout.
Base class for any widget that can be shown as a inline panel.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
void scaleChanged(double scale)
Emitted when user has finished editing/selecting a new scale.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.