QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 drawToAllPartsToggled( bool active );
157 
158  private:
159  std::unique_ptr< QgsSimpleLineCallout > mCallout;
160 
161 };
162 
163 class GUI_EXPORT QgsManhattanLineCalloutWidget : public QgsSimpleLineCalloutWidget
164 {
165  Q_OBJECT
166 
167  public:
168 
169  QgsManhattanLineCalloutWidget( QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr );
170 
171  static QgsCalloutWidget *create( QgsVectorLayer *vl ) SIP_FACTORY { return new QgsManhattanLineCalloutWidget( vl ); }
172 
173 };
174 
175 #endif
177 
178 #endif // QGSCALLOUTWIDGET_H
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:47
Property
Data definable properties.
Definition: qgscallout.h:70
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:402
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