QGIS API Documentation  3.6.0-Noosa (5873452)
qgssymbolselectordialog.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbolselectordialog.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 
16 #ifndef QGSSYMBOLSELECTORDIALOG_H
17 #define QGSSYMBOLSELECTORDIALOG_H
18 
19 #include <QDialog>
20 #include "qgis_sip.h"
21 
22 #include "ui_qgssymbolselectordialogbase.h"
23 
24 #include "qgspanelwidget.h"
25 #include "qgssymbolwidgetcontext.h"
26 #include "qgsproperty.h"
27 #include "qgshelp.h"
28 
29 #include <QStandardItemModel>
30 #include <QDialogButtonBox>
31 #include "qgis_gui.h"
32 
33 class QgsStyle;
34 class QgsSymbol;
35 class QgsSymbolLayer;
36 class QgsVectorLayer;
37 
38 class QMenu;
39 class QWidget;
40 
41 class SymbolLayerItem;
42 class QgsMarkerSymbol;
43 class QgsLineSymbol;
45 class QgsLineSymbolLayer;
46 
47 class QgsMapCanvas;
48 
49 #ifndef SIP_RUN
50 
52 class DataDefinedRestorer: public QObject
53 {
54  Q_OBJECT
55  public:
56  DataDefinedRestorer( QgsSymbol *symbol, const QgsSymbolLayer *symbolLayer );
57 
58  public slots:
59  void restore();
60 
61  private:
62  QgsMarkerSymbol *mMarker = nullptr;
63  const QgsMarkerSymbolLayer *mMarkerSymbolLayer = nullptr;
64  double mSize;
65  double mAngle;
66  QPointF mMarkerOffset;
67  QgsProperty mDDSize;
68  QgsProperty mDDAngle;
69 
70  QgsLineSymbol *mLine = nullptr;
71  const QgsLineSymbolLayer *mLineSymbolLayer = nullptr;
72  double mWidth;
73  double mLineOffset;
74  QgsProperty mDDWidth;
75 
76  void save();
77 };
79 #endif
80 
82 
87 class GUI_EXPORT QgsSymbolSelectorWidget: public QgsPanelWidget, private Ui::QgsSymbolSelectorDialogBase
88 {
89  Q_OBJECT
92 
93  public:
94 
95  // TODO QGIS 4.0 - transfer ownership of symbol to widget!
96 
104  QgsSymbolSelectorWidget( QgsSymbol *symbol, QgsStyle *style, QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr );
105 
107  QMenu *advancedMenu();
108 
116 
123 
128  QgsSymbol *symbol() { return mSymbol; }
129 
130  protected:
131 
135  void loadSymbol();
136 
143  void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent ) SIP_SKIP;
144 
148  void updateUi();
149 
153  void updateLockButton();
154 
156  SymbolLayerItem *currentLayerItem() SIP_SKIP;
157 
163 
168  void moveLayerByOffset( int offset );
169 
174  void setWidget( QWidget *widget );
175 
176  signals:
177 
181  void symbolModified();
182 
183  public slots:
184 
188  void moveLayerDown();
189 
193  void moveLayerUp();
194 
198  void addLayer();
199 
203  void removeLayer();
204 
208  void lockLayer();
209 
214  void duplicateLayer();
215 
220  void layerChanged();
221 
225  void updateLayerPreview();
226 
230  void updatePreview();
231 
233  void symbolChanged();
234 
239  void changeLayer( QgsSymbolLayer *layer );
240 
241 
242  protected: // data
243  QgsStyle *mStyle = nullptr;
244  QgsSymbol *mSymbol = nullptr;
245  QMenu *mAdvancedMenu = nullptr;
246  QgsVectorLayer *mVectorLayer = nullptr;
247 
248  QStandardItemModel *model = nullptr;
249  QWidget *mPresentWidget = nullptr;
250 
251  private:
252  std::unique_ptr<DataDefinedRestorer> mDataDefineRestorer;
253  QgsSymbolWidgetContext mContext;
254  QgsFeature mPreviewFeature;
255  QgsExpressionContext mPreviewExpressionContext;
256  bool mBlockModified = false;
257 
258 };
259 
264 class GUI_EXPORT QgsSymbolSelectorDialog : public QDialog
265 {
266  Q_OBJECT
267 
268  public:
269 
279  QgsSymbolSelectorDialog( QgsSymbol *symbol, QgsStyle *style, QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr, bool embedded = false );
280  ~QgsSymbolSelectorDialog() override;
281 
283  QMenu *advancedMenu();
284 
291  void setContext( const QgsSymbolWidgetContext &context );
292 
298  QgsSymbolWidgetContext context() const;
299 
304  QgsSymbol *symbol();
305 
306  protected:
307  // Reimplements dialog keyPress event so we can ignore it
308  void keyPressEvent( QKeyEvent *e ) override;
309 
310  void loadSymbol();
311 
313  void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent ) SIP_SKIP;
314 
315  void updateUi();
316 
317  void updateLockButton();
318 
320  SymbolLayerItem *currentLayerItem() SIP_SKIP;
321  QgsSymbolLayer *currentLayer();
322 
323  void moveLayerByOffset( int offset );
324 
325  void setWidget( QWidget *widget );
326 
327  signals:
328  void symbolModified();
329 
330  public slots:
331  void moveLayerDown();
332  void moveLayerUp();
333 
334  void addLayer();
335  void removeLayer();
336 
337  void lockLayer();
338 
343  void duplicateLayer();
344 
345  void layerChanged();
346 
347  void updateLayerPreview();
348  void updatePreview();
349 
351  void symbolChanged();
352 
357  void changeLayer( QgsSymbolLayer *layer );
358 
359  private:
360  QgsSymbolSelectorWidget *mSelectorWidget = nullptr;
361  QDialogButtonBox *mButtonBox = nullptr;
362  QgsSymbolWidgetContext mContext;
363 
364  private slots:
365  void showHelp();
366 };
367 
368 #endif
void duplicateLayer()
Duplicates the current symbol layer and places the duplicated layer above the current symbol layer...
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
Base class for any widget that can be shown as a inline panel.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:73
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:732
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:920
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
#define SIP_SKIP
Definition: qgis_sip.h:119
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...
void symbolChanged()
Slot to update tree when a new symbol from style.
Symbol selector widget that can be used to select and build a symbol.
A store for object properties.
Definition: qgsproperty.h:229
QMenu * advancedMenu()
Returns menu for "advanced" button - create it if doesn&#39;t exist and show the advanced button...
SymbolLayerItem * currentLayerItem()
Abstract base class for marker symbol layers.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
void changeLayer(QgsSymbolLayer *layer)
alters tree and sets proper widget when Layer Type is changed
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
Represents a vector layer which manages a vector based data sets.