QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 #include "qgis.h"
22 
23 #include "ui_qgssymbolselectordialogbase.h"
24 
25 #include "qgspanelwidget.h"
26 #include "qgssymbolwidgetcontext.h"
27 #include "qgsproperty.h"
28 #include "qgshelp.h"
29 
30 #include <QStandardItemModel>
31 #include <QDialogButtonBox>
32 #include "qgis_gui.h"
33 
34 class QgsStyle;
35 class QgsSymbol;
36 class QgsSymbolLayer;
37 class QgsVectorLayer;
38 
39 class QMenu;
40 class QWidget;
41 
42 class SymbolLayerItem;
43 class QgsMarkerSymbol;
44 class QgsLineSymbol;
46 class QgsLineSymbolLayer;
47 
48 class QgsMapCanvas;
49 
50 #ifndef SIP_RUN
51 
53 class DataDefinedRestorer: public QObject
54 {
55  Q_OBJECT
56  public:
57  DataDefinedRestorer( QgsSymbol *symbol, const QgsSymbolLayer *symbolLayer );
58 
59  public slots:
60  void restore();
61 
62  private:
63  QgsMarkerSymbol *mMarker = nullptr;
64  const QgsMarkerSymbolLayer *mMarkerSymbolLayer = nullptr;
65  double mSize;
66  double mAngle;
67  QPointF mMarkerOffset;
68  QgsProperty mDDSize;
69  QgsProperty mDDAngle;
70 
71  QgsLineSymbol *mLine = nullptr;
72  const QgsLineSymbolLayer *mLineSymbolLayer = nullptr;
73  double mWidth;
74  double mLineOffset;
75  QgsProperty mDDWidth;
76 
77  void save();
78 };
80 #endif
81 
83 
88 class GUI_EXPORT QgsSymbolSelectorWidget: public QgsPanelWidget, private Ui::QgsSymbolSelectorDialogBase
89 {
90  Q_OBJECT
93 
94  public:
95 
96  // TODO QGIS 4.0 - transfer ownership of symbol to widget!
97 
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 
137  void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent = nullptr ) SIP_SKIP;
138 
139  protected:
140 
144  void loadSymbol();
145 
149  void updateUi();
150 
154  void updateLockButton();
155 
157  SymbolLayerItem *currentLayerItem() SIP_SKIP;
158 
164 
169  void moveLayerByOffset( int offset );
170 
175  void setWidget( QWidget *widget );
176 
177  signals:
178 
182  void symbolModified();
183 
184  public slots:
185 
189  void moveLayerDown();
190 
194  void moveLayerUp();
195 
199  void addLayer();
200 
204  void removeLayer();
205 
209  void lockLayer();
210 
215  void duplicateLayer();
216 
221  void layerChanged();
222 
226  void updateLayerPreview();
227 
231  void updatePreview();
232 
234  void symbolChanged();
235 
240  void changeLayer( QgsSymbolLayer *layer );
241 
242 
243  protected: // data
244  QgsStyle *mStyle = nullptr;
245  QgsSymbol *mSymbol = nullptr;
246  QMenu *mAdvancedMenu = nullptr;
247  QgsVectorLayer *mVectorLayer = nullptr;
248 
249  QStandardItemModel *model = nullptr;
250  QWidget *mPresentWidget = nullptr;
251 
252  private:
253  std::unique_ptr<DataDefinedRestorer> mDataDefineRestorer;
254  QgsSymbolWidgetContext mContext;
255  QgsFeature mPreviewFeature;
256  QgsExpressionContext mPreviewExpressionContext;
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 
282  QMenu *advancedMenu();
283 
290  void setContext( const QgsSymbolWidgetContext &context );
291 
297  QgsSymbolWidgetContext context() const;
298 
303  QgsSymbol *symbol();
304 
305  protected:
306  // Reimplements dialog keyPress event so we can ignore it
307  void keyPressEvent( QKeyEvent *e ) override;
308 
309  void loadSymbol();
310 
312  void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent ) SIP_SKIP;
313 
314  void updateUi();
315 
316  void updateLockButton();
317 
319  SymbolLayerItem *currentLayerItem() SIP_SKIP;
320  QgsSymbolLayer *currentLayer();
321 
322  void moveLayerByOffset( int offset );
323 
324  void setWidget( QWidget *widget );
325 
326  signals:
327  void symbolModified();
328 
329  public slots:
330  void moveLayerDown();
331  void moveLayerUp();
332 
333  void addLayer();
334  void removeLayer();
335 
336  void lockLayer();
337 
342  void duplicateLayer();
343 
344  void layerChanged();
345 
346  void updateLayerPreview();
347  void updatePreview();
348 
350  void symbolChanged();
351 
356  void changeLayer( QgsSymbolLayer *layer );
357 
358  private:
359  QgsSymbolSelectorWidget *mSelectorWidget = nullptr;
360  QDialogButtonBox *mButtonBox = nullptr;
361  QgsSymbolWidgetContext mContext;
362 
363  private slots:
364  void showHelp();
365 };
366 
367 #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:74
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
#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...
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
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.