Skip to content
Permalink
Browse files

Add properties to QgsHighlight for easier animations

  • Loading branch information
elpaso committed Jul 31, 2018
1 parent 70b53fb commit 222fe2362e94b8f8aca3a00876cfc5a9139ac648
Showing with 69 additions and 2 deletions.
  1. +29 −1 python/gui/auto_generated/qgshighlight.sip.in
  2. +1 −0 src/gui/CMakeLists.txt
  3. +4 −0 src/gui/qgshighlight.cpp
  4. +35 −1 src/gui/qgshighlight.h
@@ -8,7 +8,7 @@



class QgsHighlight: QgsMapCanvasItem
class QgsHighlight: QObject, QgsMapCanvasItem
{
%Docstring
A class for highlight features on the map.
@@ -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 );
@@ -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 );
@@ -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.
@@ -448,6 +448,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsgradientstopeditor.h
qgsgroupwmsdatadialog.h
qgshistogramwidget.h
qgshighlight.h
qgsidentifymenu.h
qgskeyvaluewidget.h
qgslistwidget.h
@@ -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 );
@@ -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 );
}
@@ -178,6 +181,7 @@ double QgsHighlight::getSymbolWidth( const QgsRenderContext &context, double wid

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

@@ -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:

/**
@@ -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.
@@ -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.
*
@@ -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;

0 comments on commit 222fe23

Please sign in to comment.
You can’t perform that action at this time.