From b54fe1e3a54d9a290df23c4310e11aab886209ac Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 21 Mar 2017 15:49:42 +1000 Subject: [PATCH] Use a clearer marker for main canvas position in view windows --- python/gui/qgsvertexmarker.sip | 13 +++++---- src/app/qgsmapcanvasdockwidget.cpp | 1 + src/gui/qgsvertexmarker.cpp | 16 +++++++---- src/gui/qgsvertexmarker.h | 45 ++++++++++++++++++++++++++---- 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/python/gui/qgsvertexmarker.sip b/python/gui/qgsvertexmarker.sip index 561d057f793..ab447bc5c08 100644 --- a/python/gui/qgsvertexmarker.sip +++ b/python/gui/qgsvertexmarker.sip @@ -17,23 +17,24 @@ class QgsVertexMarker : QgsMapCanvasItem ICON_CIRCLE }; - QgsVertexMarker( QgsMapCanvas* mapCanvas /TransferThis/ ); + QgsVertexMarker( QgsMapCanvas *mapCanvas /TransferThis/ ); - void setCenter( const QgsPoint& point ); + void setCenter( const QgsPoint &point ); void setIconType( int iconType ); void setIconSize( int iconSize ); - - void setColor( const QColor& color ); + void setColor( const QColor &color ); + QColor color() const; + void setFillColor( const QColor &color ); + QColor fillColor() const; void setPenWidth( int width ); - void paint( QPainter* p ); + void paint( QPainter *p ); QRectF boundingRect() const; virtual void updatePosition(); - }; diff --git a/src/app/qgsmapcanvasdockwidget.cpp b/src/app/qgsmapcanvasdockwidget.cpp index 2fe5200142e..a57c9f72d5f 100644 --- a/src/app/qgsmapcanvasdockwidget.cpp +++ b/src/app/qgsmapcanvasdockwidget.cpp @@ -48,6 +48,7 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa mXyMarker->setIconType( QgsVertexMarker::ICON_CIRCLE ); mXyMarker->setIconSize( 6 ); mXyMarker->setColor( QColor( 30, 30, 30, 225 ) ); + mXyMarker->setFillColor( QColor( 255, 255, 255, 225 ) ); mPanTool = new QgsMapToolPan( mMapCanvas ); mMapCanvas->setMapTool( mPanTool ); diff --git a/src/gui/qgsvertexmarker.cpp b/src/gui/qgsvertexmarker.cpp index b87c8969242..c4e2d7dbf9a 100644 --- a/src/gui/qgsvertexmarker.cpp +++ b/src/gui/qgsvertexmarker.cpp @@ -20,12 +20,7 @@ QgsVertexMarker::QgsVertexMarker( QgsMapCanvas *mapCanvas ) : QgsMapCanvasItem( mapCanvas ) -{ - mIconSize = 10; - mIconType = ICON_X; - mColor = QColor( 255, 0, 0 ); - mPenWidth = 1; -} +{} void QgsVertexMarker::setIconType( int type ) { @@ -47,6 +42,13 @@ void QgsVertexMarker::setCenter( const QgsPoint &point ) void QgsVertexMarker::setColor( const QColor &color ) { mColor = color; + update(); +} + +void QgsVertexMarker::setFillColor( const QColor &color ) +{ + mFillColor = color; + update(); } void QgsVertexMarker::setPenWidth( int width ) @@ -61,6 +63,8 @@ void QgsVertexMarker::paint( QPainter *p ) QPen pen( mColor ); pen.setWidth( mPenWidth ); p->setPen( pen ); + QBrush brush( mFillColor ); + p->setBrush( brush ); switch ( mIconType ) { diff --git a/src/gui/qgsvertexmarker.h b/src/gui/qgsvertexmarker.h index 62c4a857a50..157f46f21be 100644 --- a/src/gui/qgsvertexmarker.h +++ b/src/gui/qgsvertexmarker.h @@ -47,8 +47,39 @@ class GUI_EXPORT QgsVertexMarker : public QgsMapCanvasItem void setIconSize( int iconSize ); + /** + * Sets the stroke \a color for the marker. + * @see color() + * @see setFillColor() + */ void setColor( const QColor &color ); + /** + * Returns the stroke color for the marker. + * @see setColor() + * @see fillColor() + * @note added in QGIS 3.0 + */ + QColor color() const { return mColor; } + + /** + * Sets the fill \a color for the marker. This setting only + * applies to some icon types. + * @note added in QGIS 3.0 + * @see fillColor() + * @see setColor() + */ + void setFillColor( const QColor &color ); + + /** + * Returns the fill \a color for the marker. This setting only + * applies to some icon types. + * @note added in QGIS 3.0 + * @see setFillColor() + * @see color() + */ + QColor fillColor() const { return mFillColor; } + void setPenWidth( int width ); void paint( QPainter *p ) override; @@ -57,22 +88,26 @@ class GUI_EXPORT QgsVertexMarker : public QgsMapCanvasItem virtual void updatePosition() override; - protected: + private: //! icon to be shown - int mIconType; + int mIconType = ICON_X; //! size - int mIconSize; + int mIconSize = 10; //! coordinates of the point in the center QgsPoint mCenter; //! color of the marker - QColor mColor; + QColor mColor = QColor( 255, 0, 0 ); //! pen width - int mPenWidth; + int mPenWidth = 1; + + //! Fill color + QColor mFillColor = QColor( 0, 0, 0, 0 ); + }; #endif