Skip to content

Commit

Permalink
QgsHighlight improvements
Browse files Browse the repository at this point in the history
* Doxygen improvements
* Fix unrequired casting
* Remove unrequired contructor
  • Loading branch information
m-kuhn committed Nov 8, 2017
1 parent d79ac26 commit e1ffb28
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 46 deletions.
39 changes: 28 additions & 11 deletions python/gui/qgshighlight.sip
Expand Up @@ -13,22 +13,30 @@ class QgsHighlight: QgsMapCanvasItem
%Docstring %Docstring
A class for highlight features on the map. A class for highlight features on the map.


The QgsHighlight class provides a transparent overlay widget The QgsHighlight class provides a transparent overlay canvas item
for highlighting features on the map. for highlighting features or geometries on a map canvas.

\code{.py}
color = QColor(Qt.red)
highlight = QgsHighlight(mapCanvas, feature, layer)
highlight.setColor(color)
color.setAlpha(50)
highlight.setFillColor(color)
highlight.show()
\endcode
%End %End


%TypeHeaderCode %TypeHeaderCode
#include "qgshighlight.h" #include "qgshighlight.h"
%End %End
public: public:



QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer );
QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsVectorLayer *layer );
%Docstring %Docstring
Constructor for QgsHighlight Constructor for QgsHighlight
\param mapCanvas associated map canvas \param mapCanvas associated map canvas
\param geom initial geometry of highlight \param geom initial geometry of highlight
\param layer associated vector layer \param layer associated map layer
%End %End


QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature &feature, QgsVectorLayer *layer ); QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature &feature, QgsVectorLayer *layer );
Expand All @@ -49,29 +57,38 @@ for highlighting features on the map.


void setFillColor( const QColor &fillColor ); void setFillColor( const QColor &fillColor );
%Docstring %Docstring
Set polygons fill color. Fill color for the highlight.
.. versionadded:: 2.3 Will be used for polygons and points.

.. versionadded:: 2.4
%End %End


void setWidth( int width ); void setWidth( int width );
%Docstring %Docstring
Set stroke width. Ignored in feature mode. Set stroke width.

.. note::

Ignored in feature mode.
%End %End


void setBuffer( double buffer ); void setBuffer( double buffer );
%Docstring %Docstring
Set line / stroke buffer in millimeters. Set line / stroke buffer in millimeters.
.. versionadded:: 2.3
.. versionadded:: 2.4
%End %End


void setMinWidth( double width ); void setMinWidth( double width );
%Docstring %Docstring
Set minimum line / stroke width in millimeters. Set minimum line / stroke width in millimeters.
.. versionadded:: 2.3
.. versionadded:: 2.4
%End %End


const QgsMapLayer *layer() const; QgsMapLayer *layer() const;
%Docstring %Docstring
Return the layer for which this highlight has been created.
:rtype: QgsMapLayer :rtype: QgsMapLayer
%End %End


Expand Down
16 changes: 1 addition & 15 deletions src/gui/qgshighlight.cpp
Expand Up @@ -49,29 +49,15 @@
QgsHighlight::QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer ) QgsHighlight::QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer )
: QgsMapCanvasItem( mapCanvas ) : QgsMapCanvasItem( mapCanvas )
, mLayer( layer ) , mLayer( layer )
, mBuffer( 0 )
, mMinWidth( 0 )
{
mGeometry = !geom.isNull() ? new QgsGeometry( geom ) : nullptr;
init();
}

QgsHighlight::QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsVectorLayer *layer )
: QgsMapCanvasItem( mapCanvas )
, mLayer( static_cast<QgsMapLayer *>( layer ) )
, mBuffer( 0 )
, mMinWidth( 0 )
{ {
mGeometry = !geom.isNull() ? new QgsGeometry( geom ) : nullptr; mGeometry = !geom.isNull() ? new QgsGeometry( geom ) : nullptr;
init(); init();
} }


QgsHighlight::QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature &feature, QgsVectorLayer *layer ) QgsHighlight::QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature &feature, QgsVectorLayer *layer )
: QgsMapCanvasItem( mapCanvas ) : QgsMapCanvasItem( mapCanvas )
, mLayer( static_cast<QgsMapLayer *>( layer ) ) , mLayer( layer )
, mFeature( feature ) , mFeature( feature )
, mBuffer( 0 )
, mMinWidth( 0 )
{ {
init(); init();
} }
Expand Down
54 changes: 34 additions & 20 deletions src/gui/qgshighlight.h
Expand Up @@ -34,8 +34,17 @@ class QgsSymbol;
* \ingroup gui * \ingroup gui
* A class for highlight features on the map. * A class for highlight features on the map.
* *
* The QgsHighlight class provides a transparent overlay widget * The QgsHighlight class provides a transparent overlay canvas item
for highlighting features on the map. * for highlighting features or geometries on a map canvas.
*
* \code{.py}
* color = QColor(Qt.red)
* highlight = QgsHighlight(mapCanvas, feature, layer)
* highlight.setColor(color)
* color.setAlpha(50)
* highlight.setFillColor(color)
* highlight.show()
* \endcode
*/ */
class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
{ {
Expand All @@ -46,17 +55,8 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
* \param mapCanvas associated map canvas * \param mapCanvas associated map canvas
* \param geom initial geometry of highlight * \param geom initial geometry of highlight
* \param layer associated map layer * \param layer associated map layer
* \note not available in Python bindings
*/
QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer ) SIP_SKIP;

/**
* Constructor for QgsHighlight
* \param mapCanvas associated map canvas
* \param geom initial geometry of highlight
* \param layer associated vector layer
*/ */
QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsVectorLayer *layer ); QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer );


/** /**
* Constructor for highlighting true feature shape using feature attributes * Constructor for highlighting true feature shape using feature attributes
Expand All @@ -74,24 +74,38 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
void setColor( const QColor &color ); void setColor( const QColor &color );


/** /**
* Set polygons fill color. * Fill color for the highlight.
* \since QGIS 2.3 */ * Will be used for polygons and points.
*
* \since QGIS 2.4
*/
void setFillColor( const QColor &fillColor ); void setFillColor( const QColor &fillColor );


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


/** /**
* Set line / stroke buffer in millimeters. * Set line / stroke buffer in millimeters.
* \since QGIS 2.3 */ *
* \since QGIS 2.4
*/
void setBuffer( double buffer ) { mBuffer = buffer; } void setBuffer( double buffer ) { mBuffer = buffer; }


/** /**
* Set minimum line / stroke width in millimeters. * Set minimum line / stroke width in millimeters.
* \since QGIS 2.3 */ *
* \since QGIS 2.4
*/
void setMinWidth( double width ) { mMinWidth = width; } void setMinWidth( double width ) { mMinWidth = width; }


const QgsMapLayer *layer() const { return mLayer; } /**
* Return the layer for which this highlight has been created.
*/
QgsMapLayer *layer() const { return mLayer; }


virtual void updatePosition() override; virtual void updatePosition() override;


Expand All @@ -116,8 +130,8 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
QgsGeometry *mGeometry = nullptr; QgsGeometry *mGeometry = nullptr;
QgsMapLayer *mLayer = nullptr; QgsMapLayer *mLayer = nullptr;
QgsFeature mFeature; QgsFeature mFeature;
double mBuffer; // line / stroke buffer in pixels double mBuffer = 0; // line / stroke buffer in pixels
double mMinWidth; // line / stroke minimum width in pixels double mMinWidth = 0; // line / stroke minimum width in pixels
}; };


#endif #endif

0 comments on commit e1ffb28

Please sign in to comment.