QGIS API Documentation  3.0.2-Girona (307d082)
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 
103  QgsSymbolSelectorWidget( QgsSymbol *symbol, QgsStyle *style, QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr );
104 
106  QMenu *advancedMenu();
107 
115 
122 
127  QgsSymbol *symbol() { return mSymbol; }
128 
129  protected:
130 
134  void loadSymbol();
135 
142  void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent ) SIP_SKIP;
143 
147  void updateUi();
148 
152  void updateLockButton();
153 
155  SymbolLayerItem *currentLayerItem() SIP_SKIP;
156 
162 
167  void moveLayerByOffset( int offset );
168 
173  void setWidget( QWidget *widget );
174 
175  signals:
176 
180  void symbolModified();
181 
182  public slots:
183 
187  void moveLayerDown();
188 
192  void moveLayerUp();
193 
197  void addLayer();
198 
202  void removeLayer();
203 
207  void lockLayer();
208 
213  void duplicateLayer();
214 
219  void layerChanged();
220 
224  void updateLayerPreview();
225 
229  void updatePreview();
230 
232  void symbolChanged();
233 
238  void changeLayer( QgsSymbolLayer *layer );
239 
240 
241  protected: // data
242  QgsStyle *mStyle = nullptr;
243  QgsSymbol *mSymbol = nullptr;
244  QMenu *mAdvancedMenu = nullptr;
245  QgsVectorLayer *mVectorLayer = nullptr;
246 
247  QStandardItemModel *model = nullptr;
248  QWidget *mPresentWidget = nullptr;
249 
250  private:
251  std::unique_ptr<DataDefinedRestorer> mDataDefineRestorer;
252  QgsSymbolWidgetContext mContext;
253  QgsFeature mPreviewFeature;
254  QgsExpressionContext mPreviewExpressionContext;
255 
256 };
257 
262 class GUI_EXPORT QgsSymbolSelectorDialog : public QDialog
263 {
264  Q_OBJECT
265 
266  public:
267 
277  QgsSymbolSelectorDialog( QgsSymbol *symbol, QgsStyle *style, QgsVectorLayer *vl, QWidget *parent SIP_TRANSFERTHIS = nullptr, bool embedded = false );
278  ~QgsSymbolSelectorDialog() override;
279 
281  QMenu *advancedMenu();
282 
289  void setContext( const QgsSymbolWidgetContext &context );
290 
296  QgsSymbolWidgetContext context() const;
297 
302  QgsSymbol *symbol();
303 
304  protected:
305  // Reimplements dialog keyPress event so we can ignore it
306  void keyPressEvent( QKeyEvent *e ) override;
307 
308  void loadSymbol();
309 
311  void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent ) SIP_SKIP;
312 
313  void updateUi();
314 
315  void updateLockButton();
316 
318  SymbolLayerItem *currentLayerItem() SIP_SKIP;
319  QgsSymbolLayer *currentLayer();
320 
321  void moveLayerByOffset( int offset );
322 
323  void setWidget( QWidget *widget );
324 
325  signals:
326  void symbolModified();
327 
328  public slots:
329  void moveLayerDown();
330  void moveLayerUp();
331 
332  void addLayer();
333  void removeLayer();
334 
335  void lockLayer();
336 
341  void duplicateLayer();
342 
343  void layerChanged();
344 
345  void updateLayerPreview();
346  void updatePreview();
347 
349  void symbolChanged();
350 
355  void changeLayer( QgsSymbolLayer *layer );
356 
357  private:
358  QgsSymbolSelectorWidget *mSelectorWidget = nullptr;
359  QDialogButtonBox *mButtonBox = nullptr;
360  QgsSymbolWidgetContext mContext;
361 
362  private slots:
363  void showHelp();
364 };
365 
366 #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
QgsSymbol * symbol()
Return 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:62
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
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()
return 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()
Return the symbol that is currently active in the widget.
Represents a vector layer which manages a vector based data sets.