QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  void setDockMode( bool dockMode ) override;
83 
84  signals:
85 
92 
97 
98  protected:
99  QgsVectorLayer *mLayer = nullptr;
100  QgsStyle *mStyle = nullptr;
101  QMenu *contextMenu = nullptr;
102  QAction *mCopyAction = nullptr;
103  QAction *mPasteAction = nullptr;
104 
109  QAction *mCopySymbolAction = nullptr;
110 
115  QAction *mPasteSymbolAction = nullptr;
116 
119 
124  virtual QList<QgsSymbol *> selectedSymbols() { return QList<QgsSymbol *>(); }
125  virtual void refreshSymbolView() {}
126 
132  QgsDataDefinedSizeLegendWidget *createDataDefinedSizeLegendWidget( const QgsMarkerSymbol *symbol, const QgsDataDefinedSizeLegend *ddsLegend ) SIP_FACTORY;
133 
134  protected slots:
135  void contextMenuViewCategories( QPoint p );
137  void changeSymbolColor();
139  void changeSymbolOpacity();
141  void changeSymbolUnit();
143  void changeSymbolWidth();
145  void changeSymbolSize();
147  void changeSymbolAngle();
148 
149 
150  virtual void copy() {}
151  virtual void paste() {}
152 
158  virtual void pasteSymbolToSelection();
159 
160  private slots:
161 
162  void copySymbol();
163 
164  private:
165 
170  virtual void apply() SIP_FORCE;
171 
172 
173 };
174 
175 
177 
178 #include <QObject>
179 
180 class QMenu;
181 class QgsField;
182 class QgsFields;
183 
184 #include "ui_widget_set_dd_value.h"
185 #include "qgis_gui.h"
186 
187 
192 class GUI_EXPORT QgsDataDefinedValueDialog : public QDialog, public Ui::QgsDataDefinedValueBaseDialog, private QgsExpressionContextGenerator
193 {
194 
195  Q_OBJECT
196 
197  public:
198 
205  QgsDataDefinedValueDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer, const QString &label );
206 
213  void setContext( const QgsSymbolWidgetContext &context );
214 
220  QgsSymbolWidgetContext context() const;
221 
226  const QgsVectorLayer *vectorLayer() const { return mLayer; }
227 
228  public slots:
229  void dataDefinedChanged();
230 
231  protected:
232 
238  void init( int propertyKey ); // needed in children ctor to call virtual
239 
240  private:
241  QgsProperty symbolDataDefined() const SIP_FORCE;
242 
243  virtual QgsProperty symbolDataDefined( const QgsSymbol * ) const = 0 SIP_FORCE;
244  virtual double value( const QgsSymbol * ) const = 0 SIP_FORCE;
245  virtual void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) = 0 SIP_FORCE;
246 
247  QList<QgsSymbol *> mSymbolList;
248  QgsVectorLayer *mLayer = nullptr;
249 
250  QgsSymbolWidgetContext mContext;
251 
252  QgsExpressionContext createExpressionContext() const override;
253 };
254 
260 {
261  Q_OBJECT
262  public:
263  QgsDataDefinedSizeDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
264  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Size" ) )
265  {
267  if ( !symbolList.isEmpty() && symbolList.at( 0 ) && vectorLayer() )
268  {
269  mAssistantSymbol.reset( static_cast<const QgsMarkerSymbol *>( symbolList.at( 0 ) )->clone() );
270  mDDBtn->setSymbol( mAssistantSymbol );
271  }
272  }
273 
274  protected:
275  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
276 
277  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsMarkerSymbol *>( symbol )->size(); }
278 
279  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
280 
281  private:
282 
283  std::shared_ptr< QgsMarkerSymbol > mAssistantSymbol;
284 };
285 
291 {
292  Q_OBJECT
293  public:
294  QgsDataDefinedRotationDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
295  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Rotation" ) )
296  {
298  }
299 
300  protected:
301  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
302 
303  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsMarkerSymbol *>( symbol )->angle(); }
304 
305  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
306 };
307 
313 {
314  Q_OBJECT
315  public:
316  QgsDataDefinedWidthDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
317  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Width" ) )
318  {
320  }
321 
322  protected:
323  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
324 
325  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsLineSymbol *>( symbol )->width(); }
326 
327  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
328 };
329 
330 
331 
332 #endif // QGSRENDERERWIDGET_H
QgsRendererWidget::renderer
virtual QgsFeatureRenderer * renderer()=0
Returns pointer to the renderer (no transfer of ownership)
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsDataDefinedSizeDialog::value
double value(const QgsSymbol *symbol) const override
Definition: qgsrendererwidget.h:277
QgsDataDefinedSizeDialog
Definition: qgsrendererwidget.h:260
QgsRendererWidget::refreshSymbolView
virtual void refreshSymbolView()
Definition: qgsrendererwidget.h:125
QgsProperty
A store for object properties.
Definition: qgsproperty.h:232
QgsPanelWidget::setDockMode
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
Definition: qgspanelwidget.cpp:44
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
QgsDataDefinedValueDialog::vectorLayer
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
Definition: qgsrendererwidget.h:226
QgsSymbolWidgetContext
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
Definition: qgssymbolwidgetcontext.h:36
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:85
QgsDataDefinedWidthDialog::QgsDataDefinedWidthDialog
QgsDataDefinedWidthDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
Definition: qgsrendererwidget.h:316
QgsDataDefinedSizeLegend
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Definition: qgsdatadefinedsizelegend.h:42
QgsDataDefinedSizeDialog::QgsDataDefinedSizeDialog
QgsDataDefinedSizeDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
Definition: qgsrendererwidget.h:263
QgsDataDefinedRotationDialog::QgsDataDefinedRotationDialog
QgsDataDefinedRotationDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
Definition: qgsrendererwidget.h:294
QgsRendererWidget::symbolLevelsChanged
void symbolLevelsChanged()
Emitted when the symbol levels settings have been changed.
QgsDataDefinedSizeLegendWidget::QgsDataDefinedSizeLegendWidget
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 ...
Definition: qgsdatadefinedsizelegendwidget.cpp:34
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
qgssymbolwidgetcontext.h
QgsDataDefinedWidthDialog::value
double value(const QgsSymbol *symbol) const override
Definition: qgsrendererwidget.h:325
QgsRendererWidget::vectorLayer
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
Definition: qgsrendererwidget.h:75
QgsMarkerSymbol::clone
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
Definition: qgssymbol.cpp:1937
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsDataDefinedRotationDialog::value
double value(const QgsSymbol *symbol) const override
Definition: qgsrendererwidget.h:303
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:30
QgsRendererWidget::copy
virtual void copy()
Definition: qgsrendererwidget.h:150
QgsDataDefinedValueDialog
Utility classes for "en masse" size definition.
Definition: qgsrendererwidget.h:193
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:931
QgsDataDefinedRotationDialog
Definition: qgsrendererwidget.h:291
QgsSymbolLayer::PropertySize
@ PropertySize
Symbol size.
Definition: qgssymbollayer.h:132
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1131
qgssymbollayer.h
QgsDataDefinedValueDialog::init
void init(int propertyKey)
Should be called in the constructor of child classes.
Definition: qgsrendererwidget.cpp:438
QgsSymbolLayer::PropertyStrokeWidth
@ PropertyStrokeWidth
Stroke width.
Definition: qgssymbollayer.h:137
QgsRendererWidget
Base class for renderer settings widgets.
Definition: qgsrendererwidget.h:45
QgsRendererWidget::selectedSymbols
virtual QList< QgsSymbol * > selectedSymbols()
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
Definition: qgsrendererwidget.h:124
QgsFeatureRenderer
Definition: qgsrenderer.h:103
QgsRendererWidget::paste
virtual void paste()
Definition: qgsrendererwidget.h:151
SIP_FORCE
#define SIP_FORCE
Definition: qgis_sip.h:131
QgsStyle
Definition: qgsstyle.h:160
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsRendererWidget::mContext
QgsSymbolWidgetContext mContext
Context in which widget is shown.
Definition: qgsrendererwidget.h:118
QgsRendererWidget::layerVariablesChanged
void layerVariablesChanged()
Emitted when expression context variables on the associated vector layers have been changed.
QgsSymbolLayer::PropertyAngle
@ PropertyAngle
Symbol angle.
Definition: qgssymbollayer.h:133
qgspanelwidget.h
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:37
MathUtils::angle
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
qgssymbol.h
QgsDataDefinedWidthDialog
Definition: qgsrendererwidget.h:313
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50