QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsrendererwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendererwidget.h
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk 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 QGSRENDERERWIDGET_H
16 #define QGSRENDERERWIDGET_H
17 
18 #include <QWidget>
19 #include <QMenu>
20 #include <QStackedWidget>
21 #include "qgssymbol.h"
22 #include "qgspanelwidget.h"
23 #include "qgssymbolwidgetcontext.h"
24 #include "qgssymbollayer.h"
25 
28 class QgsVectorLayer;
29 class QgsStyle;
30 class QgsFeatureRenderer;
31 class QgsMapCanvas;
32 
44 class GUI_EXPORT QgsRendererWidget : public QgsPanelWidget
45 {
46  Q_OBJECT
47  public:
48  QgsRendererWidget( QgsVectorLayer *layer, QgsStyle *style );
49 
51  virtual QgsFeatureRenderer *renderer() = 0;
52 
54  void showSymbolLevelsDialog( QgsFeatureRenderer *r );
55 
62  virtual void setContext( const QgsSymbolWidgetContext &context );
63 
69  QgsSymbolWidgetContext context() const;
70 
75  const QgsVectorLayer *vectorLayer() const { return mLayer; }
76 
80  void applyChanges();
81 
82  signals:
83 
89  void layerVariablesChanged();
90 
94  void symbolLevelsChanged();
95 
96  protected:
97  QgsVectorLayer *mLayer = nullptr;
98  QgsStyle *mStyle = nullptr;
99  QMenu *contextMenu = nullptr;
100  QAction *mCopyAction = nullptr;
101  QAction *mPasteAction = nullptr;
102 
107  QAction *mCopySymbolAction = nullptr;
108 
113  QAction *mPasteSymbolAction = nullptr;
114 
117 
121  virtual QList<QgsSymbol *> selectedSymbols() { return QList<QgsSymbol *>(); }
122  virtual void refreshSymbolView() {}
123 
129  QgsDataDefinedSizeLegendWidget *createDataDefinedSizeLegendWidget( const QgsMarkerSymbol *symbol, const QgsDataDefinedSizeLegend *ddsLegend ) SIP_FACTORY;
130 
131  protected slots:
132  void contextMenuViewCategories( QPoint p );
134  void changeSymbolColor();
136  void changeSymbolOpacity();
138  void changeSymbolUnit();
140  void changeSymbolWidth();
142  void changeSymbolSize();
144  void changeSymbolAngle();
145 
146 
147  virtual void copy() {}
148  virtual void paste() {}
149 
155  virtual void pasteSymbolToSelection();
156 
157  private slots:
158 
159  void copySymbol();
160 
161  private:
162 
167  virtual void apply() SIP_FORCE;
168 
169 
170 };
171 
172 
174 
175 #include <QObject>
176 
177 class QMenu;
178 class QgsField;
179 class QgsFields;
180 
181 #include "ui_widget_set_dd_value.h"
182 #include "qgis_gui.h"
183 
184 
189 class GUI_EXPORT QgsDataDefinedValueDialog : public QDialog, public Ui::QgsDataDefinedValueBaseDialog, private QgsExpressionContextGenerator
190 {
191 
192  Q_OBJECT
193 
194  public:
195 
202  QgsDataDefinedValueDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer, const QString &label );
203 
210  void setContext( const QgsSymbolWidgetContext &context );
211 
217  QgsSymbolWidgetContext context() const;
218 
223  const QgsVectorLayer *vectorLayer() const { return mLayer; }
224 
225  public slots:
226  void dataDefinedChanged();
227 
228  protected:
229 
235  void init( int propertyKey ); // needed in children ctor to call virtual
236 
237  private:
238  QgsProperty symbolDataDefined() const SIP_FORCE;
239 
240  virtual QgsProperty symbolDataDefined( const QgsSymbol * ) const = 0 SIP_FORCE;
241  virtual double value( const QgsSymbol * ) const = 0 SIP_FORCE;
242  virtual void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) = 0 SIP_FORCE;
243 
244  QList<QgsSymbol *> mSymbolList;
245  QgsVectorLayer *mLayer = nullptr;
246 
247  QgsSymbolWidgetContext mContext;
248 
250 };
251 
257 {
258  Q_OBJECT
259  public:
260  QgsDataDefinedSizeDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
261  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Size" ) )
262  {
264  if ( !symbolList.isEmpty() && symbolList.at( 0 ) && vectorLayer() )
265  {
266  mAssistantSymbol.reset( static_cast<const QgsMarkerSymbol *>( symbolList.at( 0 ) )->clone() );
267  mDDBtn->setSymbol( mAssistantSymbol );
268  }
269  }
270 
271  protected:
272  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
273 
274  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsMarkerSymbol *>( symbol )->size(); }
275 
276  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
277 
278  private:
279 
280  std::shared_ptr< QgsMarkerSymbol > mAssistantSymbol;
281 };
282 
288 {
289  Q_OBJECT
290  public:
291  QgsDataDefinedRotationDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
292  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Rotation" ) )
293  {
295  }
296 
297  protected:
298  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
299 
300  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsMarkerSymbol *>( symbol )->angle(); }
301 
302  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
303 };
304 
310 {
311  Q_OBJECT
312  public:
313  QgsDataDefinedWidthDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
314  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Width" ) )
315  {
317  }
318 
319  protected:
320  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
321 
322  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsLineSymbol *>( symbol )->width(); }
323 
324  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
325 };
326 
327 
328 
329 #endif // QGSRENDERERWIDGET_H
double value(const QgsSymbol *symbol) const override
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
virtual void refreshSymbolView()
Base class for renderer settings widgets.
double value(const QgsSymbol *symbol) const override
QgsDataDefinedSizeLegendWidget(const QgsDataDefinedSizeLegend *ddsLegend, const QgsProperty &ddSize, QgsMarkerSymbol *overrideSymbol, QgsMapCanvas *canvas=nullptr, QWidget *parent=nullptr)
Creates the dialog and initializes the content to what is passed in the legend configuration (may be ...
Container of fields for a vector layer.
Definition: qgsfields.h:42
Base class for any widget that can be shown as a inline panel.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:75
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:860
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1060
Utility classes for "en masse" size definition.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
#define SIP_FORCE
Definition: qgis_sip.h:131
#define SIP_FACTORY
Definition: qgis_sip.h:76
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
A store for object properties.
Definition: qgsproperty.h:229
virtual void paste()
virtual void copy()
Abstract interface for generating an expression context.
double value(const QgsSymbol *symbol) const override
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
QgsSymbolWidgetContext mContext
Context in which widget is shown.
virtual QList< QgsSymbol * > selectedSymbols()
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
void init(int propertyKey)
Should be called in the constructor of child classes.
QgsDataDefinedRotationDialog(const QList< QgsSymbol *> &symbolList, QgsVectorLayer *layer)
QgsDataDefinedSizeDialog(const QList< QgsSymbol *> &symbolList, QgsVectorLayer *layer)
QgsDataDefinedWidthDialog(const QList< QgsSymbol *> &symbolList, QgsVectorLayer *layer)
Represents a vector layer which manages a vector based data sets.
Object that keeps configuration of appearance of marker symbol&#39;s data-defined size in legend...