Skip to content

Commit c1eef4e

Browse files
authoredJul 31, 2018
Merge pull request #7508 from elpaso/highlight-properties
Add properties to QgsHighlight for easier animations
2 parents 70b53fb + 6a4aee8 commit c1eef4e

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed
 

‎python/gui/auto_generated/qgshighlight.sip.in

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010

11-
class QgsHighlight: QgsMapCanvasItem
11+
class QgsHighlight: QObject, QgsMapCanvasItem
1212
{
1313
%Docstring
1414
A class for highlight features on the map.
@@ -51,10 +51,24 @@ and renderer.
5151
%End
5252
~QgsHighlight();
5353

54+
QColor color( ) const;
55+
%Docstring
56+
Returns the line/stroke color
57+
58+
.. versionadded:: 3.4
59+
%End
60+
5461
void setColor( const QColor &color );
5562
%Docstring
5663
Set line/stroke to color, polygon fill to color with alpha = 63.
5764
This is legacy function, use setFillColor() after setColor() if different fill color is required. *
65+
%End
66+
67+
QColor fillColor( ) const;
68+
%Docstring
69+
Returns the fill color
70+
71+
.. versionadded:: 3.4
5872
%End
5973

6074
void setFillColor( const QColor &fillColor );
@@ -63,6 +77,13 @@ Fill color for the highlight.
6377
Will be used for polygons and points.
6478

6579
.. versionadded:: 2.4
80+
%End
81+
82+
int width( ) const;
83+
%Docstring
84+
Returns the stroke width
85+
86+
.. versionadded:: 3.4
6687
%End
6788

6889
void setWidth( int width );
@@ -74,6 +95,13 @@ Set stroke width.
7495
Ignored in feature mode.
7596
%End
7697

98+
double buffer( ) const;
99+
%Docstring
100+
Returns the buffer
101+
102+
.. versionadded:: 3.4
103+
%End
104+
77105
void setBuffer( double buffer );
78106
%Docstring
79107
Set line / stroke buffer in millimeters.

‎src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ SET(QGIS_GUI_MOC_HDRS
448448
qgsgradientstopeditor.h
449449
qgsgroupwmsdatadialog.h
450450
qgshistogramwidget.h
451+
qgshighlight.h
451452
qgsidentifymenu.h
452453
qgskeyvaluewidget.h
453454
qgslistwidget.h

‎src/gui/qgshighlight.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ QgsHighlight::~QgsHighlight()
8989
delete mGeometry;
9090
}
9191

92+
9293
void QgsHighlight::setColor( const QColor &color )
9394
{
95+
mColor = color;
9496
mPen.setColor( color );
9597
QColor fillColor( color.red(), color.green(), color.blue(), 63 );
9698
mBrush.setColor( fillColor );
@@ -99,6 +101,7 @@ void QgsHighlight::setColor( const QColor &color )
99101

100102
void QgsHighlight::setFillColor( const QColor &fillColor )
101103
{
104+
mFillColor = fillColor;
102105
mBrush.setColor( fillColor );
103106
mBrush.setStyle( Qt::SolidPattern );
104107
}
@@ -178,6 +181,7 @@ double QgsHighlight::getSymbolWidth( const QgsRenderContext &context, double wid
178181

179182
void QgsHighlight::setWidth( int width )
180183
{
184+
mWidth = width;
181185
mPen.setWidth( width );
182186
}
183187

‎src/gui/qgshighlight.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ class QgsSymbol;
4646
* highlight.show()
4747
* \endcode
4848
*/
49-
class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
49+
class GUI_EXPORT QgsHighlight: public QObject, public QgsMapCanvasItem
5050
{
51+
52+
Q_OBJECT
53+
Q_PROPERTY( QColor color READ color WRITE setColor )
54+
Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
55+
Q_PROPERTY( int width READ width WRITE setWidth )
56+
Q_PROPERTY( int buffer READ buffer WRITE setBuffer )
57+
5158
public:
5259

5360
/**
@@ -68,11 +75,23 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
6875
QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature &feature, QgsVectorLayer *layer );
6976
~QgsHighlight() override;
7077

78+
/**
79+
* Returns the line/stroke color
80+
* \since QGIS 3.4
81+
*/
82+
QColor color( ) const { return mColor; }
83+
7184
/**
7285
* Set line/stroke to color, polygon fill to color with alpha = 63.
7386
* This is legacy function, use setFillColor() after setColor() if different fill color is required. */
7487
void setColor( const QColor &color );
7588

89+
/**
90+
* Returns the fill color
91+
* \since QGIS 3.4
92+
*/
93+
QColor fillColor( ) const { return mFillColor; }
94+
7695
/**
7796
* Fill color for the highlight.
7897
* Will be used for polygons and points.
@@ -81,13 +100,25 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
81100
*/
82101
void setFillColor( const QColor &fillColor );
83102

103+
/**
104+
* Returns the stroke width
105+
* \since QGIS 3.4
106+
*/
107+
int width( ) const { return mWidth; }
108+
84109
/**
85110
* Set stroke width.
86111
*
87112
* \note Ignored in feature mode.
88113
*/
89114
void setWidth( int width );
90115

116+
/**
117+
* Returns the buffer
118+
* \since QGIS 3.4
119+
*/
120+
double buffer( ) const { return mBuffer; }
121+
91122
/**
92123
* Set line / stroke buffer in millimeters.
93124
*
@@ -125,6 +156,9 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
125156
void paintLine( QPainter *p, QgsPolylineXY line );
126157
void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
127158

159+
int mWidth = 1; // line / stroke width property
160+
QColor mColor; // line / stroke color property
161+
QColor mFillColor; // line / stroke fillColor property
128162
QBrush mBrush;
129163
QPen mPen;
130164
QgsGeometry *mGeometry = nullptr;

0 commit comments

Comments
 (0)
Please sign in to comment.