QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgssymbolbutton.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssymbolbutton.h
3 -----------------
4 Date : July 2017
5 Copyright : (C) 2017 by Nyall Dawson
6 Email : nyall dot dawson 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#ifndef QGSSYMBOLBUTTON_H
16#define QGSSYMBOLBUTTON_H
17
18#include "qgis_gui.h"
19#include "qgis_sip.h"
20#include "qgis.h"
21
22#include <QToolButton>
23#include <QPointer>
24#include <memory>
25
26class QgsMapCanvas;
27class QgsVectorLayer;
29class QgsPanelWidget;
30class QgsMessageBar;
31class QMimeData;
32class QgsSymbol;
33
44class GUI_EXPORT QgsSymbolButton : public QToolButton
45{
46 Q_OBJECT
47
48 Q_PROPERTY( QString dialogTitle READ dialogTitle WRITE setDialogTitle )
49
50 public:
51
56 QgsSymbolButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
58
59 QSize minimumSizeHint() const override;
60 QSize sizeHint() const override;
61
68 void setSymbolType( Qgis::SymbolType type );
69
74 Qgis::SymbolType symbolType() const { return mType; }
75
80 void setDialogTitle( const QString &title );
81
86 QString dialogTitle() const;
87
93 QgsSymbol *symbol();
94
101 template <class SymbolType> SymbolType *clonedSymbol() SIP_SKIP
102 {
103 QgsSymbol *tmpSymbol = mSymbol.get();
104 SymbolType *symbolCastToType = dynamic_cast<SymbolType *>( tmpSymbol );
105
106 if ( symbolCastToType )
107 {
108 return symbolCastToType->clone();
109 }
110 else
111 {
112 //could not cast
113 return nullptr;
114 }
115 }
116
121 QgsMapCanvas *mapCanvas() const;
122
128 void setMapCanvas( QgsMapCanvas *canvas );
129
136 void setMessageBar( QgsMessageBar *bar );
137
143 QgsMessageBar *messageBar() const;
144
149 QgsVectorLayer *layer() const;
150
157 void setLayer( QgsVectorLayer *layer );
158
163 void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
164
165 public slots:
166
173 void setSymbol( QgsSymbol *symbol SIP_TRANSFER );
174
179 void setColor( const QColor &color );
180
185 void copySymbol();
186
192 void pasteSymbol();
193
198 void copyColor();
199
205 void pasteColor();
206
214 void setShowNull( bool showNull );
215
222 bool showNull() const;
223
230 bool isNull() const;
231
238 void setToNull();
239
240 signals:
241
247 void changed();
248
249 protected:
250
251 void changeEvent( QEvent *e ) override;
252 void showEvent( QShowEvent *e ) override;
253 void resizeEvent( QResizeEvent *event ) override;
254
255 // Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
256 void mousePressEvent( QMouseEvent *e ) override;
257 // Reimplemented to allow dragging colors/symbols from button
258 void mouseMoveEvent( QMouseEvent *e ) override;
259 void mouseReleaseEvent( QMouseEvent *e ) override;
260 void keyPressEvent( QKeyEvent *e ) override;
261 // Reimplemented to accept dragged colors
262 void dragEnterEvent( QDragEnterEvent *e ) override;
263
264 // Reimplemented to reset button appearance after drag leave
265 void dragLeaveEvent( QDragLeaveEvent *e ) override;
266
267 // Reimplemented to accept dropped colors
268 void dropEvent( QDropEvent *e ) override;
269
270 void wheelEvent( QWheelEvent *event ) override;
271
272 private slots:
273
274 void showSettingsDialog();
275 void updateSymbolFromWidget();
276 void cleanUpSymbolSelector( QgsPanelWidget *container );
277
281 void prepareMenu();
282
283 void addRecentColor( const QColor &color );
284
288 void activatePicker();
289
290 private:
291
292 QSize mSizeHint;
293
294 QString mDialogTitle;
295
297
298 QgsMapCanvas *mMapCanvas = nullptr;
299 QgsMessageBar *mMessageBar = nullptr;
300
301 QPoint mDragStartPosition;
302
303 QMenu *mMenu = nullptr;
304
305 QPointer< QgsVectorLayer > mLayer;
306
307 QSize mIconSize;
308
309 std::unique_ptr< QgsSymbol > mSymbol;
310
311 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
312
313 bool mPickingColor = false;
314
315 bool mShowNull = false;
316
321 void updatePreview( const QColor &color = QColor(), QgsSymbol *tempSymbol = nullptr );
322
332 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
333
337 QPixmap createColorIcon( const QColor &color ) const;
338
345 void stopPicking( QPoint eventPos, bool samplingColor = true );
346
347 void showColorDialog();
348
349 void updateSizeHint();
350
351};
352
353#endif // QGSSYMBOLBUTTON_H
SymbolType
Symbol types.
Definition: qgis.h:206
@ Fill
Fill symbol.
Abstract interface for generating an expression context.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
Base class for any widget that can be shown as a inline panel.
A button for creating and modifying QgsSymbol settings.
void changed()
Emitted when the symbol's settings are changed.
Qgis::SymbolType symbolType() const
Returns the symbol type which the button requires.
SymbolType * clonedSymbol()
Returns a clone of the current symbol (as the specified template type) defined by the button.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36