QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
91  void layerVariablesChanged();
92 
96  void symbolLevelsChanged();
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 
123  virtual QList<QgsSymbol *> selectedSymbols() { return QList<QgsSymbol *>(); }
124  virtual void refreshSymbolView() {}
125 
131  QgsDataDefinedSizeLegendWidget *createDataDefinedSizeLegendWidget( const QgsMarkerSymbol *symbol, const QgsDataDefinedSizeLegend *ddsLegend ) SIP_FACTORY;
132 
133  protected slots:
134  void contextMenuViewCategories( QPoint p );
136  void changeSymbolColor();
138  void changeSymbolOpacity();
140  void changeSymbolUnit();
142  void changeSymbolWidth();
144  void changeSymbolSize();
146  void changeSymbolAngle();
147 
148 
149  virtual void copy() {}
150  virtual void paste() {}
151 
157  virtual void pasteSymbolToSelection();
158 
159  private slots:
160 
161  void copySymbol();
162 
163  private:
164 
169  virtual void apply() SIP_FORCE;
170 
171 
172 };
173 
174 
176 
177 #include <QObject>
178 
179 class QMenu;
180 class QgsField;
181 class QgsFields;
182 
183 #include "ui_widget_set_dd_value.h"
184 #include "qgis_gui.h"
185 
186 
191 class GUI_EXPORT QgsDataDefinedValueDialog : public QDialog, public Ui::QgsDataDefinedValueBaseDialog, private QgsExpressionContextGenerator
192 {
193 
194  Q_OBJECT
195 
196  public:
197 
204  QgsDataDefinedValueDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer, const QString &label );
205 
212  void setContext( const QgsSymbolWidgetContext &context );
213 
219  QgsSymbolWidgetContext context() const;
220 
225  const QgsVectorLayer *vectorLayer() const { return mLayer; }
226 
227  public slots:
228  void dataDefinedChanged();
229 
230  protected:
231 
237  void init( int propertyKey ); // needed in children ctor to call virtual
238 
239  private:
240  QgsProperty symbolDataDefined() const SIP_FORCE;
241 
242  virtual QgsProperty symbolDataDefined( const QgsSymbol * ) const = 0 SIP_FORCE;
243  virtual double value( const QgsSymbol * ) const = 0 SIP_FORCE;
244  virtual void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) = 0 SIP_FORCE;
245 
246  QList<QgsSymbol *> mSymbolList;
247  QgsVectorLayer *mLayer = nullptr;
248 
249  QgsSymbolWidgetContext mContext;
250 
251  QgsExpressionContext createExpressionContext() const override;
252 };
253 
259 {
260  Q_OBJECT
261  public:
262  QgsDataDefinedSizeDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
263  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Size" ) )
264  {
266  if ( !symbolList.isEmpty() && symbolList.at( 0 ) && vectorLayer() )
267  {
268  mAssistantSymbol.reset( static_cast<const QgsMarkerSymbol *>( symbolList.at( 0 ) )->clone() );
269  mDDBtn->setSymbol( mAssistantSymbol );
270  }
271  }
272 
273  protected:
274  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
275 
276  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsMarkerSymbol *>( symbol )->size(); }
277 
278  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
279 
280  private:
281 
282  std::shared_ptr< QgsMarkerSymbol > mAssistantSymbol;
283 };
284 
290 {
291  Q_OBJECT
292  public:
293  QgsDataDefinedRotationDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
294  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Rotation" ) )
295  {
297  }
298 
299  protected:
300  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
301 
302  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsMarkerSymbol *>( symbol )->angle(); }
303 
304  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
305 };
306 
312 {
313  Q_OBJECT
314  public:
315  QgsDataDefinedWidthDialog( const QList<QgsSymbol *> &symbolList, QgsVectorLayer *layer )
316  : QgsDataDefinedValueDialog( symbolList, layer, tr( "Width" ) )
317  {
319  }
320 
321  protected:
322  QgsProperty symbolDataDefined( const QgsSymbol *symbol ) const override;
323 
324  double value( const QgsSymbol *symbol ) const override { return static_cast<const QgsLineSymbol *>( symbol )->width(); }
325 
326  void setDataDefined( QgsSymbol *symbol, const QgsProperty &dd ) override;
327 };
328 
329 
330 
331 #endif // QGSRENDERERWIDGET_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsDataDefinedSizeDialog::value
double value(const QgsSymbol *symbol) const override
Definition: qgsrendererwidget.h:276
QgsDataDefinedSizeDialog
Definition: qgsrendererwidget.h:258
QgsRendererWidget::refreshSymbolView
virtual void refreshSymbolView()
Definition: qgsrendererwidget.h:124
QgsProperty
A store for object properties.
Definition: qgsproperty.h:231
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
Definition: qgsfields.h:44
QgsDataDefinedValueDialog::vectorLayer
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
Definition: qgsrendererwidget.h:225
QgsSymbolWidgetContext
Definition: qgssymbolwidgetcontext.h:35
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsDataDefinedWidthDialog::QgsDataDefinedWidthDialog
QgsDataDefinedWidthDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
Definition: qgsrendererwidget.h:315
QgsDataDefinedSizeLegend
Definition: qgsdatadefinedsizelegend.h:41
QgsDataDefinedSizeDialog::QgsDataDefinedSizeDialog
QgsDataDefinedSizeDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
Definition: qgsrendererwidget.h:262
QgsDataDefinedRotationDialog::QgsDataDefinedRotationDialog
QgsDataDefinedRotationDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
Definition: qgsrendererwidget.h:293
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
Definition: qgssymbol.h:63
qgssymbolwidgetcontext.h
QgsDataDefinedWidthDialog::value
double value(const QgsSymbol *symbol) const override
Definition: qgsrendererwidget.h:324
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:1896
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsDataDefinedRotationDialog::value
double value(const QgsSymbol *symbol) const override
Definition: qgsrendererwidget.h:302
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
QgsRendererWidget::copy
virtual void copy()
Definition: qgsrendererwidget.h:149
QgsDataDefinedValueDialog
Definition: qgsrendererwidget.h:191
QgsMarkerSymbol
Definition: qgssymbol.h:917
QgsDataDefinedRotationDialog
Definition: qgsrendererwidget.h:289
QgsSymbolLayer::PropertySize
@ PropertySize
Symbol size.
Definition: qgssymbollayer.h:132
QgsLineSymbol
Definition: qgssymbol.h:1117
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
Definition: qgsrendererwidget.h:44
QgsRendererWidget::selectedSymbols
virtual QList< QgsSymbol * > selectedSymbols()
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
Definition: qgsrendererwidget.h:123
QgsFeatureRenderer
Definition: qgsrenderer.h:102
QgsRendererWidget::paste
virtual void paste()
Definition: qgsrendererwidget.h:150
SIP_FORCE
#define SIP_FORCE
Definition: qgis_sip.h:131
QgsStyle
Definition: qgsstyle.h:159
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsRendererWidget::mContext
QgsSymbolWidgetContext mContext
Context in which widget is shown.
Definition: qgsrendererwidget.h:118
QgsSymbolLayer::PropertyAngle
@ PropertyAngle
Symbol angle.
Definition: qgssymbollayer.h:133
qgspanelwidget.h
QgsExpressionContextGenerator
Definition: qgsexpressioncontextgenerator.h:36
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:311
QgsField
Definition: qgsfield.h:49