QGIS API Documentation  3.20.0-Odense (decaadbb31)
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
51 
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 
105  QgsSymbolSelectorWidget( QgsSymbol *symbol, QgsStyle *style, QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr );
106 
108  QMenu *advancedMenu();
109 
117 
124 
129  QgsSymbol *symbol() { return mSymbol; }
130 
131  // TODO QGIS 4.0 - transfer ownership of symbol to widget!
132 
139  void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent = nullptr ) SIP_SKIP;
140 
141  public slots:
142 
146  void moveLayerDown();
147 
151  void moveLayerUp();
152 
156  void addLayer();
157 
161  void removeLayer();
162 
166  void lockLayer();
167 
172  void duplicateLayer();
173 
178  void layerChanged();
179 
183  void updateLayerPreview();
184 
188  void updatePreview();
189 
191  void symbolChanged();
192 
197  void changeLayer( QgsSymbolLayer *layer );
198 
199  signals:
200 
205 
206  private slots:
207 
212  void projectDataChanged();
213 
217  void layersAboutToBeRemoved( const QList<QgsMapLayer *> &layers );
218 
219  private:
220 
224  void reloadSymbol();
225 
229  void updateUi();
230 
234  void updateLockButton();
235 
236  SymbolLayerItem *currentLayerItem();
237 
242  QgsSymbolLayer *currentLayer();
243 
248  void moveLayerByOffset( int offset );
249 
254  void setWidget( QWidget *widget );
255 
256  QgsStyle *mStyle = nullptr;
257  QgsSymbol *mSymbol = nullptr;
258  QMenu *mAdvancedMenu = nullptr;
259  QgsVectorLayer *mVectorLayer = nullptr;
260 
261  QStandardItemModel *mSymbolLayersModel = nullptr;
262  QWidget *mPresentWidget = nullptr;
263 
264  std::unique_ptr<DataDefinedRestorer> mDataDefineRestorer;
265  QgsSymbolWidgetContext mContext;
266  QgsFeature mPreviewFeature;
267  QgsExpressionContext mPreviewExpressionContext;
268  bool mBlockModified = false;
269 
270 };
271 
276 class GUI_EXPORT QgsSymbolSelectorDialog : public QDialog
277 {
278  Q_OBJECT
279 
280  public:
281 
291  QgsSymbolSelectorDialog( QgsSymbol *symbol, QgsStyle *style, QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr, bool embedded = false );
292 
294  QMenu *advancedMenu();
295 
303 
310 
315  QgsSymbol *symbol();
316 
322  void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent = nullptr ) SIP_SKIP;
323 
328  QDialogButtonBox *buttonBox() const;
329 
330  public slots:
331 
332  void moveLayerDown();
333  void moveLayerUp();
334 
335  void addLayer();
336  void removeLayer();
337 
338  void lockLayer();
339 
344  void duplicateLayer();
345 
346  void layerChanged();
347 
348  void updateLayerPreview();
349  void updatePreview();
350 
352  void symbolChanged();
353 
358  void changeLayer( QgsSymbolLayer *layer );
359 
360  protected:
361 
362  // Reimplements dialog keyPress event so we can ignore it
363  void keyPressEvent( QKeyEvent *e ) override;
364 
365  private slots:
366 
367  void showHelp();
368 
369  signals:
370 
372 
373  private:
374 
375  void reloadSymbol();
376 
377  void updateUi();
378 
379  void updateLockButton();
380 
381  SymbolLayerItem *currentLayerItem();
382 
383  QgsSymbolLayer *currentLayer();
384 
385  void moveLayerByOffset( int offset );
386 
387  void setWidget( QWidget *widget );
388 
389  QgsSymbolSelectorWidget *mSelectorWidget = nullptr;
390  QDialogButtonBox *mButtonBox = nullptr;
391  QgsSymbolWidgetContext mContext;
392 
393 };
394 
395 #endif
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:30
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:86
Base class for all map layer types.
Definition: qgsmaplayer.h:70
Abstract base class for marker symbol layers.
A marker symbol type, for rendering Point and MultiPoint geometries.
Base class for any widget that can be shown as a inline panel.
void keyPressEvent(QKeyEvent *event) override
Overridden key press event to handle the esc event on the widget.
A store for object properties.
Definition: qgsproperty.h:232
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
QgsSymbolSelectorDialog(QgsSymbol *symbol, QgsStyle *style, QgsVectorLayer *vl, QWidget *parent=nullptr, bool embedded=false)
Constructor for QgsSymbolSelectorDialog.
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
QMenu * advancedMenu()
Returns menu for "advanced" button - create it if doesn't exist and show the advanced button.
void symbolChanged()
Slot to update tree when a new symbol from style.
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
void duplicateLayer()
Duplicates the current symbol layer and places the duplicated layer above the current symbol layer.
void changeLayer(QgsSymbolLayer *layer)
alters tree and sets proper widget when Layer Type is changed
void loadSymbol(QgsSymbol *symbol, SymbolLayerItem *parent=nullptr)
Loads the given symbol into the widget.
Symbol selector widget that can be used to select and build a symbol.
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:38
Represents a vector layer which manages a vector based data sets.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126