QGIS API Documentation 3.41.0-Master (d5b93354e9c)
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:
55 QgsSymbolButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
57
58 QSize minimumSizeHint() const override;
59 QSize sizeHint() const override;
60
67 void setSymbolType( Qgis::SymbolType type );
68
73 Qgis::SymbolType symbolType() const { return mType; }
74
79 void setDialogTitle( const QString &title );
80
85 QString dialogTitle() const;
86
92 QgsSymbol *symbol();
93
100 template<class SymbolType> SymbolType *clonedSymbol() SIP_SKIP
101 {
102 QgsSymbol *tmpSymbol = mSymbol.get();
103 SymbolType *symbolCastToType = dynamic_cast<SymbolType *>( tmpSymbol );
104
105 if ( symbolCastToType )
106 {
107 return symbolCastToType->clone();
108 }
109 else
110 {
111 //could not cast
112 return nullptr;
113 }
114 }
115
120 QgsMapCanvas *mapCanvas() const;
121
127 void setMapCanvas( QgsMapCanvas *canvas );
128
135 void setMessageBar( QgsMessageBar *bar );
136
142 QgsMessageBar *messageBar() const;
143
148 QgsVectorLayer *layer() const;
149
156 void setLayer( QgsVectorLayer *layer );
157
162 void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
163
172 void setDefaultSymbol( QgsSymbol *symbol SIP_TRANSFER );
173
182 const QgsSymbol *defaultSymbol() const;
183
190 bool showNull() const;
191
198 bool isNull() const;
199
200 public slots:
201
208 void setSymbol( QgsSymbol *symbol SIP_TRANSFER );
209
214 void setColor( const QColor &color );
215
220 void copySymbol();
221
227 void pasteSymbol();
228
233 void copyColor();
234
240 void pasteColor();
241
249 void setShowNull( bool showNull );
250
258 void setToNull();
259
269 void setToDefaultSymbol();
270
271 signals:
272
278 void changed();
279
280 protected:
281 void changeEvent( QEvent *e ) override;
282 void showEvent( QShowEvent *e ) override;
283 void resizeEvent( QResizeEvent *event ) override;
284
285 // Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
286 void mousePressEvent( QMouseEvent *e ) override;
287 // Reimplemented to allow dragging colors/symbols from button
288 void mouseMoveEvent( QMouseEvent *e ) override;
289 void mouseReleaseEvent( QMouseEvent *e ) override;
290 void keyPressEvent( QKeyEvent *e ) override;
291 // Reimplemented to accept dragged colors
292 void dragEnterEvent( QDragEnterEvent *e ) override;
293
294 // Reimplemented to reset button appearance after drag leave
295 void dragLeaveEvent( QDragLeaveEvent *e ) override;
296
297 // Reimplemented to accept dropped colors
298 void dropEvent( QDropEvent *e ) override;
299
300 void wheelEvent( QWheelEvent *event ) override;
301
302 private slots:
303
304 void showSettingsDialog();
305 void updateSymbolFromWidget( QgsSymbolSelectorWidget *widget );
306
310 void prepareMenu();
311
312 void addRecentColor( const QColor &color );
313
317 void activatePicker();
318
319 private:
320 QSize mSizeHint;
321
322 QString mDialogTitle;
323
325
326 QgsMapCanvas *mMapCanvas = nullptr;
327 QgsMessageBar *mMessageBar = nullptr;
328
329 QPoint mDragStartPosition;
330
331 QMenu *mMenu = nullptr;
332
333 QPointer<QgsVectorLayer> mLayer;
334
335 QSize mIconSize;
336
337 std::unique_ptr<QgsSymbol> mSymbol;
338
339 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
340
341 bool mPickingColor = false;
342
343 bool mShowNull = false;
344
345 std::unique_ptr<QgsSymbol> mDefaultSymbol;
346
351 void updatePreview( const QColor &color = QColor(), QgsSymbol *tempSymbol = nullptr );
352
362 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
363
367 QPixmap createColorIcon( const QColor &color ) const;
368
375 void stopPicking( QPoint eventPos, bool samplingColor = true );
376
377 void showColorDialog();
378
379 void updateSizeHint();
380};
381
382#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