QGIS API Documentation  3.2.0-Bonn (bc43194)
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 QGSRENDERERV2WIDGET_H
16 #define QGSRENDERERV2WIDGET_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 
91  protected:
92  QgsVectorLayer *mLayer = nullptr;
93  QgsStyle *mStyle = nullptr;
94  QMenu *contextMenu = nullptr;
95  QAction *mCopyAction = nullptr;
96  QAction *mPasteAction = nullptr;
97 
100 
104  virtual QList<QgsSymbol *> selectedSymbols() { return QList<QgsSymbol *>(); }
105  virtual void refreshSymbolView() {}
106 
112  QgsDataDefinedSizeLegendWidget *createDataDefinedSizeLegendWidget( const QgsMarkerSymbol *symbol, const QgsDataDefinedSizeLegend *ddsLegend ) SIP_FACTORY;
113 
114  protected slots:
115  void contextMenuViewCategories( QPoint p );
117  void changeSymbolColor();
119  void changeSymbolOpacity();
121  void changeSymbolUnit();
123  void changeSymbolWidth();
125  void changeSymbolSize();
127  void changeSymbolAngle();
128 
129  virtual void copy() {}
130  virtual void paste() {}
131 
132  private:
133 
138  virtual void apply() SIP_FORCE;
139 
140 
141 };
142 
143 
145 
146 #include <QObject>
147 
148 class QMenu;
149 class QgsField;
150 class QgsFields;
151 
152 #include "ui_widget_set_dd_value.h"
153 #include "qgis_gui.h"
154 
155 
160 class GUI_EXPORT QgsDataDefinedValueDialog : public QDialog, public Ui::QgsDataDefinedValueBaseDialog, private QgsExpressionContextGenerator
161 {
162 
163  Q_OBJECT
164 
165  public:
166 
173  QgsDataDefinedValueDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer, const QString &label );
174 
181  void setContext( const QgsSymbolWidgetContext &context );
182 
188  QgsSymbolWidgetContext context() const;
189 
194  const QgsVectorLayer *vectorLayer() const { return mLayer; }
195 
196  public slots:
197  void dataDefinedChanged();
198 
199  protected:
200 
206  void init( int propertyKey ); // needed in children ctor to call virtual
207 
208  private:
209  QgsProperty symbolDataDefined() const SIP_FORCE;
210 
211  virtual QgsProperty symbolDataDefined( const QgsSymbol * ) const = 0 SIP_FORCE;
212  virtual double value( const QgsSymbol * ) const = 0 SIP_FORCE;
213  virtual void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) = 0 SIP_FORCE;
214 
215  QList<QgsSymbol *> mSymbolList;
216  QgsVectorLayer *mLayer = nullptr;
217 
218  QgsSymbolWidgetContext mContext;
219 
221 };
222 
228 {
229  Q_OBJECT
230  public:
231  QgsDataDefinedSizeDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
232  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Size" ) )
233  {
235  if ( !symbolList.isEmpty() && symbolList.at( 0 ) && vectorLayer() )
236  {
237  mAssistantSymbol.reset( static_cast<const QgsMarkerSymbol *>( symbolList.at( 0 ) )->clone() );
238  mDDBtn->setSymbol( mAssistantSymbol );
239  }
240  }
241 
242  protected:
243  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
244 
245  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsMarkerSymbol *>( symbol )->size(); }
246 
247  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
248 
249  private:
250 
251  std::shared_ptr< QgsMarkerSymbol > mAssistantSymbol;
252 };
253 
259 {
260  Q_OBJECT
261  public:
262  QgsDataDefinedRotationDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
263  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Rotation" ) )
264  {
266  }
267 
268  protected:
269  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
270 
271  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsMarkerSymbol *>( symbol )->angle(); }
272 
273  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
274 };
275 
281 {
282  Q_OBJECT
283  public:
284  QgsDataDefinedWidthDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
285  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Width" ) )
286  {
288  }
289 
290  protected:
291  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
292 
293  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsLineSymbol *>( symbol )->width(); }
294 
295  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
296 };
297 
298 
299 
300 #endif // QGSRENDERERV2WIDGET_H
double value(const QgsSymbol *symbol) const override
virtual void refreshSymbolView()
Base class for renderer settings widgets.
double value(const QgsSymbol *symbol) const override
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:74
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
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...
Widget for configuration of appearance of legend for marker symbols with data-defined size...
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:124
#define SIP_FACTORY
Definition: qgis_sip.h:69
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...