QGIS API Documentation  3.9.0-Master (224899f119)
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 
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 
204  void symbolModified();
205 
206  private:
207 
211  void reloadSymbol();
212 
216  void updateUi();
217 
221  void updateLockButton();
222 
223  SymbolLayerItem *currentLayerItem();
224 
229  QgsSymbolLayer *currentLayer();
230 
235  void moveLayerByOffset( int offset );
236 
241  void setWidget( QWidget *widget );
242 
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  std::unique_ptr<DataDefinedRestorer> mDataDefineRestorer;
252  QgsSymbolWidgetContext mContext;
253  QgsFeature mPreviewFeature;
254  QgsExpressionContext mPreviewExpressionContext;
255  bool mBlockModified = false;
256 
257 };
258 
263 class GUI_EXPORT QgsSymbolSelectorDialog : public QDialog
264 {
265  Q_OBJECT
266 
267  public:
268 
278  QgsSymbolSelectorDialog( QgsSymbol *symbol, QgsStyle *style, QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr, bool embedded = false );
279 
281  QMenu *advancedMenu();
282 
289  void setContext( const QgsSymbolWidgetContext &context );
290 
296  QgsSymbolWidgetContext context() const;
297 
302  QgsSymbol *symbol();
303 
309  void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent = nullptr ) SIP_SKIP;
310 
315  QDialogButtonBox *buttonBox() const;
316 
317  public slots:
318 
319  void moveLayerDown();
320  void moveLayerUp();
321 
322  void addLayer();
323  void removeLayer();
324 
325  void lockLayer();
326 
331  void duplicateLayer();
332 
333  void layerChanged();
334 
335  void updateLayerPreview();
336  void updatePreview();
337 
339  void symbolChanged();
340 
345  void changeLayer( QgsSymbolLayer *layer );
346 
347  protected:
348 
349  // Reimplements dialog keyPress event so we can ignore it
350  void keyPressEvent( QKeyEvent *e ) override;
351 
352  private slots:
353 
354  void showHelp();
355 
356  signals:
357 
358  void symbolModified();
359 
360  private:
361 
362  void reloadSymbol();
363 
364  void updateUi();
365 
366  void updateLockButton();
367 
368  SymbolLayerItem *currentLayerItem();
369 
370  QgsSymbolLayer *currentLayer();
371 
372  void moveLayerByOffset( int offset );
373 
374  void setWidget( QWidget *widget );
375 
376  QgsSymbolSelectorWidget *mSelectorWidget = nullptr;
377  QDialogButtonBox *mButtonBox = nullptr;
378  QgsSymbolWidgetContext mContext;
379 
380 };
381 
382 #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:53
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:859
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1059
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:126
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...
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.
void loadSymbol(QgsSymbol *symbol, SymbolLayerItem *parent=nullptr)
Loads the given symbol into the widget.