Skip to content

Commit 22c4740

Browse files
committed
[FEATURE] New standard widget for symbol buttons
Button widgets for configuring symbol properties were reimplemented multiple times throughout the codebase. This commit creates a new standard QgsSymbolButton widget which should be used whenever a button for configuring symbol properties is required. Features include: - automatic use of inline panels whenever possible - dropdown menu with shortcuts to color settings, copy/pasting colors - accepts drag and dropped colors to set symbol color
1 parent 9a12249 commit 22c4740

File tree

7 files changed

+904
-0
lines changed

7 files changed

+904
-0
lines changed

python/gui/gui_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
%Include qgsstatusbar.sip
189189
%Include qgssublayersdialog.sip
190190
%Include qgssubstitutionlistwidget.sip
191+
%Include qgssymbolbutton.sip
191192
%Include qgstablewidgetbase.sip
192193
%Include qgstabwidget.sip
193194
%Include qgstaskmanagerwidget.sip

python/gui/qgssymbolbutton.sip

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/qgssymbolbutton.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
class QgsSymbolButton : QToolButton
12+
{
13+
%Docstring
14+
A button for creating and modifying QgsSymbol settings.
15+
16+
The button shows a preview icon for the current symbol, and will open a detailed symbol editor dialog (or
17+
panel widget) when clicked.
18+
19+
.. versionadded:: 3.0
20+
%End
21+
22+
%TypeHeaderCode
23+
#include "qgssymbolbutton.h"
24+
%End
25+
public:
26+
27+
QgsSymbolButton( QWidget *parent /TransferThis/ = 0, const QString &dialogTitle = QString() );
28+
%Docstring
29+
Construct a new symbol button.
30+
Use ``dialogTitle`` string to define the title to show in the symbol settings dialog.
31+
%End
32+
33+
virtual QSize minimumSizeHint() const;
34+
35+
void setDialogTitle( const QString &title );
36+
%Docstring
37+
Sets the ``title`` for the symbol settings dialog window.
38+
.. seealso:: dialogTitle()
39+
%End
40+
41+
QString dialogTitle() const;
42+
%Docstring
43+
Returns the title for the symbol settings dialog window.
44+
.. seealso:: setDialogTitle()
45+
:rtype: str
46+
%End
47+
48+
QgsSymbol *symbol();
49+
%Docstring
50+
Returns the current symbol defined by the button.
51+
.. seealso:: setSymbol()
52+
.. seealso:: changed()
53+
:rtype: QgsSymbol
54+
%End
55+
56+
QgsMapCanvas *mapCanvas() const;
57+
%Docstring
58+
Returns the map canvas associated with the widget.
59+
.. seealso:: setMapCanvas()
60+
:rtype: QgsMapCanvas
61+
%End
62+
63+
void setMapCanvas( QgsMapCanvas *canvas );
64+
%Docstring
65+
Sets a map ``canvas`` to associate with the widget. This allows the
66+
widget to fetch current settings from the map canvas, such as current scale.
67+
.. seealso:: mapCanvas()
68+
%End
69+
70+
QgsVectorLayer *layer() const;
71+
%Docstring
72+
Returns the layer associated with the widget.
73+
.. seealso:: setLayer()
74+
:rtype: QgsVectorLayer
75+
%End
76+
77+
void setLayer( QgsVectorLayer *layer );
78+
%Docstring
79+
Sets a ``layer`` to associate with the widget. This allows the
80+
widget to setup layer related settings within the symbol settings dialog,
81+
such as correctly populating data defined override buttons.
82+
.. seealso:: layer()
83+
%End
84+
85+
void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
86+
%Docstring
87+
Register an expression context generator class that will be used to retrieve
88+
an expression context for the button when required.
89+
%End
90+
91+
public slots:
92+
93+
void setSymbol( QgsSymbol *symbol /Transfer/ );
94+
%Docstring
95+
Sets the ``symbol`` for the button. Ownership of ``symbol`` is transferred to the
96+
button.
97+
.. seealso:: symbol()
98+
.. seealso:: changed()
99+
%End
100+
101+
void setColor( const QColor &color );
102+
%Docstring
103+
Sets the current ``color`` for the symbol. Will emit a changed() signal if the color is different
104+
to the previous symbol color.
105+
%End
106+
107+
void copyColor();
108+
%Docstring
109+
Copies the current symbol color to the clipboard.
110+
.. seealso:: pasteColor()
111+
%End
112+
113+
void pasteColor();
114+
%Docstring
115+
Pastes a color from the clipboard to the symbol. If clipboard does not contain a valid
116+
color or string representation of a color, then no change is applied.
117+
.. seealso:: copyColor()
118+
%End
119+
120+
signals:
121+
122+
void changed();
123+
%Docstring
124+
Emitted when the symbol's settings are changed.
125+
.. seealso:: symbol()
126+
.. seealso:: setSymbol()
127+
%End
128+
129+
protected:
130+
131+
virtual void changeEvent( QEvent *e );
132+
133+
virtual void showEvent( QShowEvent *e );
134+
135+
virtual void resizeEvent( QResizeEvent *event );
136+
137+
138+
virtual void mousePressEvent( QMouseEvent *e );
139+
140+
virtual void mouseMoveEvent( QMouseEvent *e );
141+
142+
virtual void dragEnterEvent( QDragEnterEvent *e );
143+
144+
145+
virtual void dragLeaveEvent( QDragLeaveEvent *e );
146+
147+
148+
virtual void dropEvent( QDropEvent *e );
149+
150+
151+
};
152+
153+
/************************************************************************
154+
* This file has been generated automatically from *
155+
* *
156+
* src/gui/qgssymbolbutton.h *
157+
* *
158+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
159+
************************************************************************/

src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ SET(QGIS_GUI_SRCS
336336
qgssubstitutionlistwidget.cpp
337337
qgssqlcomposerdialog.cpp
338338
qgsstatusbar.cpp
339+
qgssymbolbutton.cpp
339340
qgstablewidgetbase.cpp
340341
qgstabwidget.cpp
341342
qgstablewidgetitem.cpp
@@ -492,6 +493,7 @@ SET(QGIS_GUI_MOC_HDRS
492493
qgsstatusbar.h
493494
qgssublayersdialog.h
494495
qgssubstitutionlistwidget.h
496+
qgssymbolbutton.h
495497
qgstablewidgetbase.h
496498
qgstabwidget.h
497499
qgstaskmanagerwidget.h

0 commit comments

Comments
 (0)