QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 "qgsannotationitem.h"
19#include "qgsapplication.h"
20#include "qgscalloutsregistry.h"
21
23 : QWidget( parent )
24{
25 setupUi( this );
26
27 connect( mSpinZIndex, qOverload<int>( &QSpinBox::valueChanged ), this, [ = ]
28 {
29 if ( !mBlockChangedSignal )
30 emit itemChanged();
31 } );
32 mSpinZIndex->setClearValue( 0 );
33
34 connect( mReferenceScaleGroup, &QGroupBox::toggled, this, [ = ]
35 {
36 if ( !mBlockChangedSignal )
37 emit itemChanged();
38 } );
39 connect( mReferenceScaleWidget, &QgsScaleWidget::scaleChanged, this, [ = ]
40 {
41 if ( !mBlockChangedSignal )
42 emit itemChanged();
43 } );
44 connect( mCalloutCheckBox, &QCheckBox::toggled, this, [ = ]
45 {
46 if ( !mBlockChangedSignal )
47 emit itemChanged();
48 } );
49
50 connect( mCalloutPropertiesButton, &QToolButton::clicked, this, &QgsAnnotationItemCommonPropertiesWidget::openCalloutProperties );
51}
52
54
56{
57 mSpinZIndex->setValue( item->zIndex() );
58 mReferenceScaleGroup->setChecked( item->useSymbologyReferenceScale() );
59 mReferenceScaleWidget->setScale( item->symbologyReferenceScale() );
60 mReferenceScaleGroup->setVisible( item->flags() & Qgis::AnnotationItemFlag::SupportsReferenceScale );
61 mCalloutCheckBox->setChecked( item->callout() );
62 mCallout.reset( item->callout() ? item->callout()->clone() : nullptr );
63}
64
66{
67 item->setZIndex( mSpinZIndex->value() );
68 item->setUseSymbologyReferenceScale( mReferenceScaleGroup->isChecked() );
69 item->setSymbologyReferenceScale( mReferenceScaleWidget->scale() );
70 item->setCallout( mCallout && mCalloutCheckBox->isChecked() ? mCallout->clone() : nullptr );
71}
72
74{
75 mContext = context;
76 mReferenceScaleWidget->setMapCanvas( context.mapCanvas() );
77 if ( context.mapCanvas() )
78 mReferenceScaleWidget->setShowCurrentScaleButton( true );
79}
80
85
86void QgsAnnotationItemCommonPropertiesWidget::openCalloutProperties()
87{
89 if ( !mCallout )
90 mCallout.reset( QgsApplication::calloutRegistry()->defaultCallout() );
91 widget->setCallout( mCallout.get() );
92
93 connect( widget, &QgsCalloutPanelWidget::calloutChanged, this, [this, widget]
94 {
95 mCallout.reset( widget->callout()->clone() );
96 if ( !mBlockChangedSignal )
97 emit itemChanged();
98 } );
99
100 if ( QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this ) )
101 {
102 panel->openPanel( widget );
103 }
104}
@ 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.