QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgscalloutwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscalloutwidget.h
3  ---------------------
4  begin : July 2019
5  copyright : (C) 2019 by 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 #ifndef QGSCALLOUTWIDGET_H
16 #define QGSCALLOUTWIDGET_H
17 
19 #include "qgis_sip.h"
20 #include "qgssymbolwidgetcontext.h"
21 #include "qgscallout.h"
22 #include <QWidget>
23 #include <QStandardItemModel>
24 
25 class QgsVectorLayer;
26 class QgsMapCanvas;
27 
34 class GUI_EXPORT QgsCalloutWidget : public QWidget, protected QgsExpressionContextGenerator
35 {
36  Q_OBJECT
37 
38  public:
39 
45  QgsCalloutWidget( QWidget *parent SIP_TRANSFERTHIS, QgsVectorLayer *vl = nullptr )
46  : QWidget( parent )
47  , mVectorLayer( vl )
48  {}
49 
54  virtual void setCallout( QgsCallout *callout ) = 0;
55 
61  virtual QgsCallout *callout() = 0;
62 
68  virtual void setContext( const QgsSymbolWidgetContext &context );
69 
74  QgsSymbolWidgetContext context() const;
75 
79  const QgsVectorLayer *vectorLayer() const { return mVectorLayer; }
80 
84  virtual void setGeometryType( QgsWkbTypes::GeometryType type ) = 0;
85 
86  protected:
87 
93  void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsCallout::Property key );
94 
96 
97  private:
98  QgsVectorLayer *mVectorLayer = nullptr;
99 
100  QgsMapCanvas *mMapCanvas = nullptr;
101 
102  signals:
103 
108  void changed();
109 
110  private slots:
111  void updateDataDefinedProperty();
112 
113  void createAuxiliaryField();
114 
115  private:
116  QgsSymbolWidgetContext mContext;
117 };
118 
119 
121 
122 #include "ui_widget_simplelinecallout.h"
123 
125 
126 #ifndef SIP_RUN
128 
129 class GUI_EXPORT QgsSimpleLineCalloutWidget : public QgsCalloutWidget, private Ui::WidgetSimpleLineCallout
130 {
131  Q_OBJECT
132 
133  public:
134 
135  QgsSimpleLineCalloutWidget( QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr );
136 
137  static QgsCalloutWidget *create( QgsVectorLayer *vl ) SIP_FACTORY { return new QgsSimpleLineCalloutWidget( vl ); }
138 
139  void setCallout( QgsCallout *callout ) override;
140 
141  QgsCallout *callout() override;
142 
143  void setGeometryType( QgsWkbTypes::GeometryType type ) override;
144 
145  private slots:
146 
147  void minimumLengthChanged();
148  void minimumLengthUnitWidgetChanged();
149  void offsetFromAnchorUnitWidgetChanged();
150  void offsetFromAnchorChanged();
151  void offsetFromLabelUnitWidgetChanged();
152  void offsetFromLabelChanged();
153  void lineSymbolChanged();
154  void mAnchorPointComboBox_currentIndexChanged( int index );
155  void mLabelAnchorPointComboBox_currentIndexChanged( int index );
156  void mCalloutBlendComboBox_currentIndexChanged( int index );
157  void drawToAllPartsToggled( bool active );
158 
159  private:
160  std::unique_ptr< QgsSimpleLineCallout > mCallout;
161 
162 };
163 
164 class GUI_EXPORT QgsManhattanLineCalloutWidget : public QgsSimpleLineCalloutWidget
165 {
166  Q_OBJECT
167 
168  public:
169 
170  QgsManhattanLineCalloutWidget( QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr );
171 
172  static QgsCalloutWidget *create( QgsVectorLayer *vl ) SIP_FACTORY { return new QgsManhattanLineCalloutWidget( vl ); }
173 
174 };
175 
176 
178 
179 #include "ui_widget_curvedlinecallout.h"
180 
183 
184 class GUI_EXPORT QgsCurvedLineCalloutWidget : public QgsCalloutWidget, private Ui::WidgetCurvedLineCallout
185 {
186  Q_OBJECT
187 
188  public:
189 
190  QgsCurvedLineCalloutWidget( QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr );
191 
192  static QgsCalloutWidget *create( QgsVectorLayer *vl ) SIP_FACTORY { return new QgsCurvedLineCalloutWidget( vl ); }
193 
194  void setCallout( QgsCallout *callout ) override;
195 
196  QgsCallout *callout() override;
197 
198  void setGeometryType( QgsWkbTypes::GeometryType type ) override;
199 
200  private slots:
201 
202  void minimumLengthChanged();
203  void minimumLengthUnitWidgetChanged();
204  void offsetFromAnchorUnitWidgetChanged();
205  void offsetFromAnchorChanged();
206  void offsetFromLabelUnitWidgetChanged();
207  void offsetFromLabelChanged();
208  void lineSymbolChanged();
209  void mAnchorPointComboBox_currentIndexChanged( int index );
210  void mLabelAnchorPointComboBox_currentIndexChanged( int index );
211  void mCalloutBlendComboBox_currentIndexChanged( int index );
212  void drawToAllPartsToggled( bool active );
213 
214  private:
215  std::unique_ptr< QgsCurvedLineCallout > mCallout;
216 
217 };
218 
219 
221 
222 #include "ui_widget_ballooncallout.h"
223 
224 class QgsBalloonCallout;
225 
226 class GUI_EXPORT QgsBalloonCalloutWidget : public QgsCalloutWidget, private Ui::WidgetBalloonCallout
227 {
228  Q_OBJECT
229 
230  public:
231 
232  QgsBalloonCalloutWidget( QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr );
233 
234  static QgsCalloutWidget *create( QgsVectorLayer *vl ) SIP_FACTORY { return new QgsBalloonCalloutWidget( vl ); }
235 
236  void setCallout( QgsCallout *callout ) override;
237 
238  QgsCallout *callout() override;
239 
240  void setGeometryType( QgsWkbTypes::GeometryType type ) override;
241 
242  private slots:
243 
244  void offsetFromAnchorUnitWidgetChanged();
245  void offsetFromAnchorChanged();
246  void fillSymbolChanged();
247  void mAnchorPointComboBox_currentIndexChanged( int index );
248  void mCalloutBlendComboBox_currentIndexChanged( int index );
249 
250  private:
251  std::unique_ptr< QgsBalloonCallout > mCallout;
252 
253 };
254 
255 #endif
257 
258 #endif // QGSCALLOUTWIDGET_H
A cartoon talking bubble callout style.
Definition: qgscallout.h:890
Base class for widgets which allow control over the properties of callouts.
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
virtual void setCallout(QgsCallout *callout)=0
Sets the callout to show in the widget.
virtual void setGeometryType(QgsWkbTypes::GeometryType type)=0
Sets the geometry type of the features to customize the widget accordingly.
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
virtual QgsCallout * callout()=0
Returns the callout defined by the current settings in the widget.
QgsCalloutWidget(QWidget *parent, QgsVectorLayer *vl=nullptr)
Constructor for QgsCalloutWidget.
Abstract base class for callout renderers.
Definition: qgscallout.h:52
Property
Data definable properties.
Definition: qgscallout.h:83
Draws curved lines as callouts.
Definition: qgscallout.h:790
Abstract interface for generating an expression context.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:86
A button for controlling property overrides which may apply to a widget.
A simple direct line callout style.
Definition: qgscallout.h:510
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
Represents a vector layer which manages a vector based data sets.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_FACTORY
Definition: qgis_sip.h:76