QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 <memory>
19
20#include "qgis.h"
21#include "qgis_gui.h"
22#include "qgis_sip.h"
23
24#include <QPointer>
25#include <QToolButton>
26
27class QgsMapCanvas;
28class QgsVectorLayer;
30class QgsPanelWidget;
31class QgsMessageBar;
32class QMimeData;
33class QgsSymbol;
35
45class GUI_EXPORT QgsSymbolButton : public QToolButton
46{
47 Q_OBJECT
48
49 Q_PROPERTY( QString dialogTitle READ dialogTitle WRITE setDialogTitle )
50
51 public:
56 QgsSymbolButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
57 ~QgsSymbolButton() override;
58
59 QSize minimumSizeHint() const override;
60 QSize sizeHint() const override;
61
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
206 bool fixedSizeConstraints() const;
207
208 public slots:
209
216 void setSymbol( QgsSymbol *symbol SIP_TRANSFER );
217
222 void setColor( const QColor &color );
223
228 void copySymbol();
229
235 void pasteSymbol();
236
241 void copyColor();
242
248 void pasteColor();
249
257 void setShowNull( bool showNull );
258
266 void setToNull();
267
277 void setToDefaultSymbol();
278
284 void setFixedSizeConstraints( bool fixedSizeConstraints );
285
286 signals:
287
293 void changed();
294
295 protected:
296 void changeEvent( QEvent *e ) override;
297 void showEvent( QShowEvent *e ) override;
298 void resizeEvent( QResizeEvent *event ) override;
299
300 // Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
301 void mousePressEvent( QMouseEvent *e ) override;
302 // Reimplemented to allow dragging colors/symbols from button
303 void mouseMoveEvent( QMouseEvent *e ) override;
304 void mouseReleaseEvent( QMouseEvent *e ) override;
305 void keyPressEvent( QKeyEvent *e ) override;
306 // Reimplemented to accept dragged colors
307 void dragEnterEvent( QDragEnterEvent *e ) override;
308
309 // Reimplemented to reset button appearance after drag leave
310 void dragLeaveEvent( QDragLeaveEvent *e ) override;
311
312 // Reimplemented to accept dropped colors
313 void dropEvent( QDropEvent *e ) override;
314
315 void wheelEvent( QWheelEvent *event ) override;
316
317 private slots:
318
319 void showSettingsDialog();
320 void updateSymbolFromWidget( QgsSymbolSelectorWidget *widget );
321
325 void prepareMenu();
326
327 void addRecentColor( const QColor &color );
328
332 void activatePicker();
333
334 private:
335 QSize mSizeHint;
336
337 QString mDialogTitle;
338
340
341 QgsMapCanvas *mMapCanvas = nullptr;
342 QgsMessageBar *mMessageBar = nullptr;
343
344 QPoint mDragStartPosition;
345
346 QMenu *mMenu = nullptr;
347
348 QPointer<QgsVectorLayer> mLayer;
349
350 QSize mIconSize;
351
352 std::unique_ptr<QgsSymbol> mSymbol;
353
354 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
355
356 bool mPickingColor = false;
357
358 bool mShowNull = false;
359
360 bool mFixedSizeConstraints = true;
361
362 std::unique_ptr<QgsSymbol> mDefaultSymbol;
363
368 void updatePreview( const QColor &color = QColor(), QgsSymbol *tempSymbol = nullptr );
369
379 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
380
384 QPixmap createColorIcon( const QColor &color ) const;
385
392 void stopPicking( QPoint eventPos, bool samplingColor = true );
393
394 void showColorDialog();
395
396 void updateSizeHint();
397};
398
399#endif // QGSSYMBOLBUTTON_H
SymbolType
Symbol types.
Definition qgis.h:610
@ Fill
Fill symbol.
Definition qgis.h:613
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 an inline panel.
void wheelEvent(QWheelEvent *event) override
void mouseReleaseEvent(QMouseEvent *e) override
QSize sizeHint() const override
void changeEvent(QEvent *e) override
QgsSymbolButton(QWidget *parent=nullptr, const QString &dialogTitle=QString())
Construct a new symbol button.
~QgsSymbolButton() override
void mousePressEvent(QMouseEvent *e) override
void dragEnterEvent(QDragEnterEvent *e) override
void showEvent(QShowEvent *e) override
void setSymbolType(Qgis::SymbolType type)
Sets the symbol type which the button requires.
void setDialogTitle(const QString &title)
Sets the title for the symbol settings dialog window.
void keyPressEvent(QKeyEvent *e) override
void resizeEvent(QResizeEvent *event) override
QSize minimumSizeHint() const override
void dropEvent(QDropEvent *e) override
void changed()
Emitted when the symbol's settings are changed.
void dragLeaveEvent(QDragLeaveEvent *e) override
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.
void mouseMoveEvent(QMouseEvent *e) override
Symbol selector widget that can be used to select and build a symbol.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Represents a vector layer which manages a vector based dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36