Skip to content

Commit d055def

Browse files
authored
Merge pull request #4907 from nyalldawson/symbol_button
New QgsSymbolButton widget
2 parents db745df + 6202f06 commit d055def

File tree

54 files changed

+1666
-544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1666
-544
lines changed

python/core/qgscolorramp.sip

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class QgsGradientColorRamp : QgsColorRamp
144144
\param stops optional list of additional color stops
145145
%End
146146

147-
static QgsColorRamp *create( const QgsStringMap &properties = QgsStringMap() );
147+
static QgsColorRamp *create( const QgsStringMap &properties = QgsStringMap() ) /Factory/;
148148
%Docstring
149149
Creates a new QgsColorRamp from a map of properties
150150
:rtype: QgsColorRamp
@@ -477,7 +477,7 @@ class QgsPresetSchemeColorRamp : QgsColorRamp, QgsColorScheme
477477
not available in Python bindings - use setColors instead
478478
%End
479479

480-
static QgsColorRamp *create( const QgsStringMap &properties = QgsStringMap() );
480+
static QgsColorRamp *create( const QgsStringMap &properties = QgsStringMap() ) /Factory/;
481481
%Docstring
482482
Returns a new QgsPresetSchemeColorRamp color ramp created using the properties encoded in a string
483483
map.
@@ -541,7 +541,7 @@ class QgsColorBrewerColorRamp : QgsColorRamp
541541
\param inverted invert ramp ordering
542542
%End
543543

544-
static QgsColorRamp *create( const QgsStringMap &properties = QgsStringMap() );
544+
static QgsColorRamp *create( const QgsStringMap &properties = QgsStringMap() ) /Factory/;
545545
%Docstring
546546
Returns a new QgsColorBrewerColorRamp color ramp created using the properties encoded in a string
547547
map.
@@ -647,7 +647,7 @@ class QgsCptCityColorRamp : QgsGradientColorRamp
647647
\param doLoadFile load cpt-city ramp from file
648648
%End
649649

650-
static QgsColorRamp *create( const QgsStringMap &properties = QgsStringMap() );
650+
static QgsColorRamp *create( const QgsStringMap &properties = QgsStringMap() ) /Factory/;
651651
%Docstring
652652
:rtype: QgsColorRamp
653653
%End

python/core/symbology-ng/qgssymbol.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ return new default symbol for specified geometry type
8888
:rtype: QgsSymbolLayer
8989
%End
9090

91-
int symbolLayerCount();
91+
int symbolLayerCount() const;
9292
%Docstring
9393
Returns total number of symbol layers contained in the symbol.
9494
:return: count of symbol layers

python/core/symbology-ng/qgssymbollayer.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ class QgsSymbolLayer
231231

232232
virtual QgsSymbol *subSymbol();
233233
%Docstring
234+
Returns the symbol's sub symbol, if present.
234235
:rtype: QgsSymbol
235236
%End
237+
236238
virtual bool setSubSymbol( QgsSymbol *symbol /Transfer/ );
237239
%Docstring
238240
set layer's subsymbol. takes ownership of the passed symbol

python/core/symbology-ng/qgssymbollayerregistry.sip

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Create a symbol layer of this type given the map of properties.
5252
Create widget for symbol layer of this type. Can return NULL if there's no GUI
5353
:rtype: QgsSymbolLayerWidget
5454
%End
55-
virtual QgsSymbolLayer *createSymbolLayerFromSld( QDomElement & );
55+
virtual QgsSymbolLayer *createSymbolLayerFromSld( QDomElement & ) /Factory/;
5656
%Docstring
5757
Create a symbol layer of this type given the map of properties.
5858
:rtype: QgsSymbolLayer
@@ -85,9 +85,9 @@ Convenience metadata class that uses static functions to create symbol layer and
8585

8686

8787

88-
virtual QgsSymbolLayer *createSymbolLayer( const QgsStringMap &map );
89-
virtual QgsSymbolLayerWidget *createSymbolLayerWidget( const QgsVectorLayer *vl );
90-
virtual QgsSymbolLayer *createSymbolLayerFromSld( QDomElement &elem );
88+
virtual QgsSymbolLayer *createSymbolLayer( const QgsStringMap &map ) /Factory/;
89+
virtual QgsSymbolLayerWidget *createSymbolLayerWidget( const QgsVectorLayer *vl ) /Factory/;
90+
virtual QgsSymbolLayer *createSymbolLayerFromSld( QDomElement &elem ) /Factory/;
9191
virtual void resolvePaths( QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving );
9292

9393
protected:
@@ -133,7 +133,7 @@ create a new instance of symbol layer given symbol layer name and properties
133133
:rtype: QgsSymbolLayer
134134
%End
135135

136-
QgsSymbolLayer *createSymbolLayerFromSld( const QString &name, QDomElement &element ) const;
136+
QgsSymbolLayer *createSymbolLayerFromSld( const QString &name, QDomElement &element ) const /Factory/;
137137
%Docstring
138138
create a new instance of symbol layer given symbol layer name and SLD
139139
:rtype: QgsSymbolLayer

python/core/symbology-ng/qgssymbollayerutils.sip

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,15 @@ Writes a symbol definition to XML
337337
:rtype: bool
338338
%End
339339

340-
static QgsSymbolLayer *createFillLayerFromSld( QDomElement &element );
340+
static QgsSymbolLayer *createFillLayerFromSld( QDomElement &element ) /Factory/;
341341
%Docstring
342342
:rtype: QgsSymbolLayer
343343
%End
344-
static QgsSymbolLayer *createLineLayerFromSld( QDomElement &element );
344+
static QgsSymbolLayer *createLineLayerFromSld( QDomElement &element ) /Factory/;
345345
%Docstring
346346
:rtype: QgsSymbolLayer
347347
%End
348-
static QgsSymbolLayer *createMarkerLayerFromSld( QDomElement &element );
348+
static QgsSymbolLayer *createMarkerLayerFromSld( QDomElement &element ) /Factory/;
349349
%Docstring
350350
:rtype: QgsSymbolLayer
351351
%End
@@ -548,6 +548,25 @@ Writes a collection of symbols to XML with specified tagName for the top-level e
548548

549549
static void clearSymbolMap( QgsSymbolMap &symbols );
550550

551+
static QMimeData *symbolToMimeData( QgsSymbol *symbol ) /Factory/;
552+
%Docstring
553+
Creates new mime data from a ``symbol``.
554+
This also sets the mime color data to match the symbol's color, so that copied symbols
555+
can be paste in places where a color is expected.
556+
.. seealso:: symbolFromMimeData()
557+
.. versionadded:: 3.0
558+
:rtype: QMimeData
559+
%End
560+
561+
static QgsSymbol *symbolFromMimeData( const QMimeData *data ) /Factory/;
562+
%Docstring
563+
Attempts to parse ``mime`` data as a symbol. A new symbol instance will be returned
564+
if the data was successfully converted to a symbol.
565+
.. seealso:: symbolToMimeData()
566+
.. versionadded:: 3.0
567+
:rtype: QgsSymbol
568+
%End
569+
551570
static QgsColorRamp *loadColorRamp( QDomElement &element ) /Factory/;
552571
%Docstring
553572
Creates a color ramp from the settings encoded in an XML element
@@ -577,7 +596,7 @@ Writes a collection of symbols to XML with specified tagName for the top-level e
577596
:rtype: QVariant
578597
%End
579598

580-
static QgsColorRamp *loadColorRamp( const QVariant &value );
599+
static QgsColorRamp *loadColorRamp( const QVariant &value ) /Factory/;
581600
%Docstring
582601
Load a color ramp from a QVariantMap, wrapped in a QVariant.
583602
You can use QgsXmlUtils.readVariant to load it from an XML document.
@@ -605,7 +624,7 @@ Writes a collection of symbols to XML with specified tagName for the top-level e
605624
:rtype: list of QColor
606625
%End
607626

608-
static QMimeData *colorToMimeData( const QColor &color );
627+
static QMimeData *colorToMimeData( const QColor &color ) /Factory/;
609628
%Docstring
610629
Creates mime data from a color. Sets both the mime data's color data, and the
611630
mime data's text with the color's hex code.
@@ -636,7 +655,7 @@ Writes a collection of symbols to XML with specified tagName for the top-level e
636655
:rtype: QgsNamedColorList
637656
%End
638657

639-
static QMimeData *colorListToMimeData( const QgsNamedColorList &colorList, const bool allFormats = true );
658+
static QMimeData *colorListToMimeData( const QgsNamedColorList &colorList, const bool allFormats = true ) /Factory/;
640659
%Docstring
641660
Creates mime data from a list of named colors
642661
\param colorList list of named colors

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: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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 setSymbolType( QgsSymbol::SymbolType type );
36+
%Docstring
37+
Sets the symbol ``type`` which the button requires.
38+
If the type differs from the current symbol type, the symbol will be reset
39+
to a default symbol style of the new type.
40+
.. seealso:: symbolType()
41+
%End
42+
43+
QgsSymbol::SymbolType symbolType() const;
44+
%Docstring
45+
Returns the symbol type which the button requires.
46+
.. seealso:: setSymbolType()
47+
:rtype: QgsSymbol.SymbolType
48+
%End
49+
50+
void setDialogTitle( const QString &title );
51+
%Docstring
52+
Sets the ``title`` for the symbol settings dialog window.
53+
.. seealso:: dialogTitle()
54+
%End
55+
56+
QString dialogTitle() const;
57+
%Docstring
58+
Returns the title for the symbol settings dialog window.
59+
.. seealso:: setDialogTitle()
60+
:rtype: str
61+
%End
62+
63+
QgsSymbol *symbol();
64+
%Docstring
65+
Returns the current symbol defined by the button.
66+
.. seealso:: setSymbol()
67+
.. seealso:: changed()
68+
:rtype: QgsSymbol
69+
%End
70+
71+
72+
QgsMapCanvas *mapCanvas() const;
73+
%Docstring
74+
Returns the map canvas associated with the widget.
75+
.. seealso:: setMapCanvas()
76+
:rtype: QgsMapCanvas
77+
%End
78+
79+
void setMapCanvas( QgsMapCanvas *canvas );
80+
%Docstring
81+
Sets a map ``canvas`` to associate with the widget. This allows the
82+
widget to fetch current settings from the map canvas, such as current scale.
83+
.. seealso:: mapCanvas()
84+
%End
85+
86+
QgsVectorLayer *layer() const;
87+
%Docstring
88+
Returns the layer associated with the widget.
89+
.. seealso:: setLayer()
90+
:rtype: QgsVectorLayer
91+
%End
92+
93+
void setLayer( QgsVectorLayer *layer );
94+
%Docstring
95+
Sets a ``layer`` to associate with the widget. This allows the
96+
widget to setup layer related settings within the symbol settings dialog,
97+
such as correctly populating data defined override buttons.
98+
.. seealso:: layer()
99+
%End
100+
101+
void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
102+
%Docstring
103+
Register an expression context generator class that will be used to retrieve
104+
an expression context for the button when required.
105+
%End
106+
107+
public slots:
108+
109+
void setSymbol( QgsSymbol *symbol /Transfer/ );
110+
%Docstring
111+
Sets the ``symbol`` for the button. Ownership of ``symbol`` is transferred to the
112+
button.
113+
.. seealso:: symbol()
114+
.. seealso:: changed()
115+
%End
116+
117+
void setColor( const QColor &color );
118+
%Docstring
119+
Sets the current ``color`` for the symbol. Will emit a changed() signal if the color is different
120+
to the previous symbol color.
121+
%End
122+
123+
void copySymbol();
124+
%Docstring
125+
Copies the current symbol to the clipboard.
126+
.. seealso:: pasteSymbol()
127+
%End
128+
129+
void pasteSymbol();
130+
%Docstring
131+
Pastes a symbol from the clipboard. If clipboard does not contain a valid
132+
symbol then no change is applied.
133+
.. seealso:: copySymbol()
134+
%End
135+
136+
void copyColor();
137+
%Docstring
138+
Copies the current symbol color to the clipboard.
139+
.. seealso:: pasteColor()
140+
%End
141+
142+
void pasteColor();
143+
%Docstring
144+
Pastes a color from the clipboard to the symbol. If clipboard does not contain a valid
145+
color or string representation of a color, then no change is applied.
146+
.. seealso:: copyColor()
147+
%End
148+
149+
signals:
150+
151+
void changed();
152+
%Docstring
153+
Emitted when the symbol's settings are changed.
154+
.. seealso:: symbol()
155+
.. seealso:: setSymbol()
156+
%End
157+
158+
protected:
159+
160+
virtual void changeEvent( QEvent *e );
161+
162+
virtual void showEvent( QShowEvent *e );
163+
164+
virtual void resizeEvent( QResizeEvent *event );
165+
166+
167+
virtual void mousePressEvent( QMouseEvent *e );
168+
169+
virtual void mouseMoveEvent( QMouseEvent *e );
170+
171+
virtual void dragEnterEvent( QDragEnterEvent *e );
172+
173+
174+
virtual void dragLeaveEvent( QDragLeaveEvent *e );
175+
176+
177+
virtual void dropEvent( QDropEvent *e );
178+
179+
180+
};
181+
182+
/************************************************************************
183+
* This file has been generated automatically from *
184+
* *
185+
* src/gui/qgssymbolbutton.h *
186+
* *
187+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
188+
************************************************************************/

python/gui/symbology-ng/qgspointclusterrendererwidget.sip

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313

14-
class QgsPointClusterRendererWidget: QgsRendererWidget
14+
class QgsPointClusterRendererWidget: QgsRendererWidget, QgsExpressionContextGenerator
1515
{
1616
%Docstring
1717
A widget which allows configuration of the properties for a QgsPointClusterRenderer.
@@ -48,6 +48,9 @@ class QgsPointClusterRendererWidget: QgsRendererWidget
4848
virtual void setContext( const QgsSymbolWidgetContext &context );
4949

5050

51+
virtual QgsExpressionContext createExpressionContext() const;
52+
53+
5154
};
5255

5356
/************************************************************************

python/gui/symbology-ng/qgspointdisplacementrendererwidget.sip

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212

13-
class QgsPointDisplacementRendererWidget: QgsRendererWidget
13+
class QgsPointDisplacementRendererWidget: QgsRendererWidget, QgsExpressionContextGenerator
1414
{
1515

1616
%TypeHeaderCode
@@ -29,6 +29,9 @@ class QgsPointDisplacementRendererWidget: QgsRendererWidget
2929
virtual void setContext( const QgsSymbolWidgetContext &context );
3030

3131

32+
virtual QgsExpressionContext createExpressionContext() const;
33+
34+
3235
};
3336

3437
/************************************************************************

0 commit comments

Comments
 (0)