Skip to content

Commit

Permalink
Add properties to QgsHighlight for easier animations
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jul 31, 2018
1 parent 70b53fb commit 222fe23
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
30 changes: 29 additions & 1 deletion python/gui/auto_generated/qgshighlight.sip.in
Expand Up @@ -8,7 +8,7 @@



class QgsHighlight: QgsMapCanvasItem
class QgsHighlight: QObject, QgsMapCanvasItem
{
%Docstring
A class for highlight features on the map.
Expand Down Expand Up @@ -51,10 +51,24 @@ and renderer.
%End
~QgsHighlight();

QColor color( ) const;
%Docstring
Return line/stroke color

.. versionadded:: 3.4
%End

void setColor( const QColor &color );
%Docstring
Set line/stroke to color, polygon fill to color with alpha = 63.
This is legacy function, use setFillColor() after setColor() if different fill color is required. *
%End

QColor fillColor( ) const;
%Docstring
Return fill color

.. versionadded:: 3.4
%End

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

.. versionadded:: 2.4
%End

int width( ) const;
%Docstring
Return stroke width

.. versionadded:: 3.4
%End

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

double buffer( ) const;
%Docstring
Return buffer

.. versionadded:: 3.4
%End

void setBuffer( double buffer );
%Docstring
Set line / stroke buffer in millimeters.
Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -448,6 +448,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsgradientstopeditor.h
qgsgroupwmsdatadialog.h
qgshistogramwidget.h
qgshighlight.h
qgsidentifymenu.h
qgskeyvaluewidget.h
qgslistwidget.h
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgshighlight.cpp
Expand Up @@ -89,8 +89,10 @@ QgsHighlight::~QgsHighlight()
delete mGeometry;
}


void QgsHighlight::setColor( const QColor &color )
{
mColor = color;
mPen.setColor( color );
QColor fillColor( color.red(), color.green(), color.blue(), 63 );
mBrush.setColor( fillColor );
Expand All @@ -99,6 +101,7 @@ void QgsHighlight::setColor( const QColor &color )

void QgsHighlight::setFillColor( const QColor &fillColor )
{
mFillColor = fillColor;
mBrush.setColor( fillColor );
mBrush.setStyle( Qt::SolidPattern );
}
Expand Down Expand Up @@ -178,6 +181,7 @@ double QgsHighlight::getSymbolWidth( const QgsRenderContext &context, double wid

void QgsHighlight::setWidth( int width )
{
mWidth = width;
mPen.setWidth( width );
}

Expand Down
36 changes: 35 additions & 1 deletion src/gui/qgshighlight.h
Expand Up @@ -46,8 +46,15 @@ class QgsSymbol;
* highlight.show()
* \endcode
*/
class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
class GUI_EXPORT QgsHighlight: public QObject, public QgsMapCanvasItem
{

Q_OBJECT
Q_PROPERTY( QColor color READ color WRITE setColor )
Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
Q_PROPERTY( int width READ width WRITE setWidth )
Q_PROPERTY( int buffer READ buffer WRITE setBuffer )

public:

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

/**
* Return line/stroke color
* \since QGIS 3.4
*/
QColor color( ) const { return mColor; }

/**
* Set line/stroke to color, polygon fill to color with alpha = 63.
* This is legacy function, use setFillColor() after setColor() if different fill color is required. */
void setColor( const QColor &color );

/**
* Return fill color
* \since QGIS 3.4
*/
QColor fillColor( ) const { return mFillColor; }

/**
* Fill color for the highlight.
* Will be used for polygons and points.
Expand All @@ -81,13 +100,25 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
*/
void setFillColor( const QColor &fillColor );

/**
* Return stroke width
* \since QGIS 3.4
*/
int width( ) const { return mWidth; }

/**
* Set stroke width.
*
* \note Ignored in feature mode.
*/
void setWidth( int width );

/**
* Return buffer
* \since QGIS 3.4
*/
double buffer( ) const { return mBuffer; }

/**
* Set line / stroke buffer in millimeters.
*
Expand Down Expand Up @@ -125,6 +156,9 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
void paintLine( QPainter *p, QgsPolylineXY line );
void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );

int mWidth = 1; // line / stroke width property
QColor mColor; // line / stroke color property
QColor mFillColor; // line / stroke fillColor property
QBrush mBrush;
QPen mPen;
QgsGeometry *mGeometry = nullptr;
Expand Down

0 comments on commit 222fe23

Please sign in to comment.