QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
45class GUI_EXPORT QgsSymbolButton : public QToolButton
46{
47 Q_OBJECT
48
49 Q_PROPERTY( QString dialogTitle READ dialogTitle WRITE setDialogTitle )
50
51 public:
52
57 QgsSymbolButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
59
60 QSize minimumSizeHint() const override;
61 QSize sizeHint() const override;
62
69 void setSymbolType( Qgis::SymbolType type );
70
75 Qgis::SymbolType symbolType() const { return mType; }
76
81 void setDialogTitle( const QString &title );
82
87 QString dialogTitle() const;
88
94 QgsSymbol *symbol();
95
102 template <class SymbolType> SymbolType *clonedSymbol() SIP_SKIP
103 {
104 QgsSymbol *tmpSymbol = mSymbol.get();
105 SymbolType *symbolCastToType = dynamic_cast<SymbolType *>( tmpSymbol );
106
107 if ( symbolCastToType )
108 {
109 return symbolCastToType->clone();
110 }
111 else
112 {
113 //could not cast
114 return nullptr;
115 }
116 }
117
122 QgsMapCanvas *mapCanvas() const;
123
129 void setMapCanvas( QgsMapCanvas *canvas );
130
137 void setMessageBar( QgsMessageBar *bar );
138
144 QgsMessageBar *messageBar() const;
145
150 QgsVectorLayer *layer() const;
151
158 void setLayer( QgsVectorLayer *layer );
159
164 void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
165
174 void setDefaultSymbol( QgsSymbol *symbol SIP_TRANSFER );
175
184 const QgsSymbol *defaultSymbol() const;
185
192 bool showNull() const;
193
200 bool isNull() const;
201
202 public slots:
203
210 void setSymbol( QgsSymbol *symbol SIP_TRANSFER );
211
216 void setColor( const QColor &color );
217
222 void copySymbol();
223
229 void pasteSymbol();
230
235 void copyColor();
236
242 void pasteColor();
243
251 void setShowNull( bool showNull );
252
260 void setToNull();
261
271 void setToDefaultSymbol();
272
273 signals:
274
280 void changed();
281
282 protected:
283
284 void changeEvent( QEvent *e ) override;
285 void showEvent( QShowEvent *e ) override;
286 void resizeEvent( QResizeEvent *event ) override;
287
288 // Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
289 void mousePressEvent( QMouseEvent *e ) override;
290 // Reimplemented to allow dragging colors/symbols from button
291 void mouseMoveEvent( QMouseEvent *e ) override;
292 void mouseReleaseEvent( QMouseEvent *e ) override;
293 void keyPressEvent( QKeyEvent *e ) override;
294 // Reimplemented to accept dragged colors
295 void dragEnterEvent( QDragEnterEvent *e ) override;
296
297 // Reimplemented to reset button appearance after drag leave
298 void dragLeaveEvent( QDragLeaveEvent *e ) override;
299
300 // Reimplemented to accept dropped colors
301 void dropEvent( QDropEvent *e ) override;
302
303 void wheelEvent( QWheelEvent *event ) override;
304
305 private slots:
306
307 void showSettingsDialog();
308 void updateSymbolFromWidget( QgsSymbolSelectorWidget *widget );
309
313 void prepareMenu();
314
315 void addRecentColor( const QColor &color );
316
320 void activatePicker();
321
322 private:
323
324 QSize mSizeHint;
325
326 QString mDialogTitle;
327
329
330 QgsMapCanvas *mMapCanvas = nullptr;
331 QgsMessageBar *mMessageBar = nullptr;
332
333 QPoint mDragStartPosition;
334
335 QMenu *mMenu = nullptr;
336
337 QPointer< QgsVectorLayer > mLayer;
338
339 QSize mIconSize;
340
341 std::unique_ptr< QgsSymbol > mSymbol;
342
343 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
344
345 bool mPickingColor = false;
346
347 bool mShowNull = false;
348
349 std::unique_ptr< QgsSymbol > mDefaultSymbol;
350
355 void updatePreview( const QColor &color = QColor(), QgsSymbol *tempSymbol = nullptr );
356
366 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
367
371 QPixmap createColorIcon( const QColor &color ) const;
372
379 void stopPicking( QPoint eventPos, bool samplingColor = true );
380
381 void showColorDialog();
382
383 void updateSizeHint();
384
385};
386
387#endif // QGSSYMBOLBUTTON_H
SymbolType
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:368
@ 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:94
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