QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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;
34
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
173 void setDefaultSymbol( QgsSymbol *symbol SIP_TRANSFER );
174
183 const QgsSymbol *defaultSymbol() const;
184
191 bool showNull() const;
192
199 bool isNull() const;
200
201 public slots:
202
209 void setSymbol( QgsSymbol *symbol SIP_TRANSFER );
210
215 void setColor( const QColor &color );
216
221 void copySymbol();
222
228 void pasteSymbol();
229
234 void copyColor();
235
241 void pasteColor();
242
250 void setShowNull( bool showNull );
251
259 void setToNull();
260
270 void setToDefaultSymbol();
271
272 signals:
273
279 void changed();
280
281 protected:
282
283 void changeEvent( QEvent *e ) override;
284 void showEvent( QShowEvent *e ) override;
285 void resizeEvent( QResizeEvent *event ) override;
286
287 // Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
288 void mousePressEvent( QMouseEvent *e ) override;
289 // Reimplemented to allow dragging colors/symbols from button
290 void mouseMoveEvent( QMouseEvent *e ) override;
291 void mouseReleaseEvent( QMouseEvent *e ) override;
292 void keyPressEvent( QKeyEvent *e ) override;
293 // Reimplemented to accept dragged colors
294 void dragEnterEvent( QDragEnterEvent *e ) override;
295
296 // Reimplemented to reset button appearance after drag leave
297 void dragLeaveEvent( QDragLeaveEvent *e ) override;
298
299 // Reimplemented to accept dropped colors
300 void dropEvent( QDropEvent *e ) override;
301
302 void wheelEvent( QWheelEvent *event ) override;
303
304 private slots:
305
306 void showSettingsDialog();
307 void updateSymbolFromWidget( QgsSymbolSelectorWidget *widget );
308
312 void prepareMenu();
313
314 void addRecentColor( const QColor &color );
315
319 void activatePicker();
320
321 private:
322
323 QSize mSizeHint;
324
325 QString mDialogTitle;
326
328
329 QgsMapCanvas *mMapCanvas = nullptr;
330 QgsMessageBar *mMessageBar = nullptr;
331
332 QPoint mDragStartPosition;
333
334 QMenu *mMenu = nullptr;
335
336 QPointer< QgsVectorLayer > mLayer;
337
338 QSize mIconSize;
339
340 std::unique_ptr< QgsSymbol > mSymbol;
341
342 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
343
344 bool mPickingColor = false;
345
346 bool mShowNull = false;
347
348 std::unique_ptr< QgsSymbol > mDefaultSymbol;
349
354 void updatePreview( const QColor &color = QColor(), QgsSymbol *tempSymbol = nullptr );
355
365 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
366
370 QPixmap createColorIcon( const QColor &color ) const;
371
378 void stopPicking( QPoint eventPos, bool samplingColor = true );
379
380 void showColorDialog();
381
382 void updateSizeHint();
383
384};
385
386#endif // QGSSYMBOLBUTTON_H
SymbolType
Symbol types.
Definition qgis.h:574
@ Fill
Fill symbol.
Abstract interface for generating an expression context.
Map canvas is a class for displaying all GIS data types on a canvas.
A bar for displaying non-blocking messages to the user.
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.
Symbol selector widget that can be used to select and build a symbol.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
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