QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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:
52
57 QgsSymbolButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );
58 ~QgsSymbolButton() override;
59
60 QSize minimumSizeHint() const override;
61 QSize sizeHint() const override;
62
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
207 bool fixedSizeConstraints() const;
208
209 public slots:
210
217 void setSymbol( QgsSymbol *symbol SIP_TRANSFER );
218
223 void setColor( const QColor &color );
224
229 void copySymbol();
230
236 void pasteSymbol();
237
242 void copyColor();
243
249 void pasteColor();
250
258 void setShowNull( bool showNull );
259
267 void setToNull();
268
278 void setToDefaultSymbol();
279
285 void setFixedSizeConstraints( bool fixedSizeConstraints );
286
287 signals:
288
294 void changed();
295
296 protected:
297 void changeEvent( QEvent *e ) override;
298 void showEvent( QShowEvent *e ) override;
299 void resizeEvent( QResizeEvent *event ) override;
300
301 // Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
302 void mousePressEvent( QMouseEvent *e ) override;
303 // Reimplemented to allow dragging colors/symbols from button
304 void mouseMoveEvent( QMouseEvent *e ) override;
305 void mouseReleaseEvent( QMouseEvent *e ) override;
306 void keyPressEvent( QKeyEvent *e ) override;
307 // Reimplemented to accept dragged colors
308 void dragEnterEvent( QDragEnterEvent *e ) override;
309
310 // Reimplemented to reset button appearance after drag leave
311 void dragLeaveEvent( QDragLeaveEvent *e ) override;
312
313 // Reimplemented to accept dropped colors
314 void dropEvent( QDropEvent *e ) override;
315
316 void wheelEvent( QWheelEvent *event ) override;
317
318 private slots:
319
320 void showSettingsDialog();
321 void updateSymbolFromWidget( QgsSymbolSelectorWidget *widget );
322
326 void prepareMenu();
327
328 void addRecentColor( const QColor &color );
329
333 void activatePicker();
334
335 private:
336 QSize mSizeHint;
337
338 QString mDialogTitle;
339
341
342 QgsMapCanvas *mMapCanvas = nullptr;
343 QgsMessageBar *mMessageBar = nullptr;
344
345 QPoint mDragStartPosition;
346
347 QMenu *mMenu = nullptr;
348
349 QPointer<QgsVectorLayer> mLayer;
350
351 QSize mIconSize;
352
353 std::unique_ptr<QgsSymbol> mSymbol;
354
355 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
356
357 bool mPickingColor = false;
358
359 bool mShowNull = false;
360
361 bool mFixedSizeConstraints = true;
362
363 std::unique_ptr<QgsSymbol> mDefaultSymbol;
364
369 void updatePreview( const QColor &color = QColor(), QgsSymbol *tempSymbol = nullptr );
370
380 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor, bool &hasAlpha );
381
385 QPixmap createColorIcon( const QColor &color ) const;
386
393 void stopPicking( QPoint eventPos, bool samplingColor = true );
394
395 void showColorDialog();
396
397 void updateSizeHint();
398};
399
400#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