Skip to content
Permalink
Browse files

Allow setting pen/brush for QgsLayoutViewRubberBand

  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent a346736 commit 5cac2f71f00dd7981c82e7aa5ee9c330e9c000d1
@@ -77,6 +77,36 @@ class QgsLayoutViewRubberBand
:rtype: QgsLayout
%End

QBrush brush() const;
%Docstring
Returns the brush used for drawing the rubber band.
.. seealso:: setBrush()
.. seealso:: pen()
:rtype: QBrush
%End

void setBrush( const QBrush &brush );
%Docstring
Sets the ``brush`` used for drawing the rubber band.
.. seealso:: brush()
.. seealso:: setPen()
%End

QPen pen() const;
%Docstring
Returns the pen used for drawing the rubber band.
.. seealso:: setPen()
.. seealso:: brush()
:rtype: QPen
%End

void setPen( const QPen &pen );
%Docstring
Sets the ``pen`` used for drawing the rubber band.
.. seealso:: pen()
.. seealso:: setBrush()
%End

protected:

QRectF updateRect( QPointF start, QPointF position, bool constrainSquare, bool fromCenter );
@@ -99,6 +99,26 @@ QRectF QgsLayoutViewRubberBand::updateRect( QPointF start, QPointF position, boo
return QRectF( x, y, width, height );
}

QPen QgsLayoutViewRubberBand::pen() const
{
return mPen;
}

void QgsLayoutViewRubberBand::setPen( const QPen &pen )
{
mPen = pen;
}

QBrush QgsLayoutViewRubberBand::brush() const
{
return mBrush;
}

void QgsLayoutViewRubberBand::setBrush( const QBrush &brush )
{
mBrush = brush;
}


QgsLayoutViewRectangularRubberBand::QgsLayoutViewRectangularRubberBand( QgsLayoutView *view )
: QgsLayoutViewRubberBand( view )
@@ -123,8 +143,8 @@ void QgsLayoutViewRectangularRubberBand::start( QPointF position, Qt::KeyboardMo
{
QTransform t;
mRubberBandItem = new QGraphicsRectItem( 0, 0, 0, 0 );
mRubberBandItem->setBrush( Qt::NoBrush );
mRubberBandItem->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
mRubberBandItem->setBrush( brush() );
mRubberBandItem->setPen( pen() );
mRubberBandStartPos = position;
t.translate( position.x(), position.y() );
mRubberBandItem->setTransform( t );
@@ -188,8 +208,8 @@ void QgsLayoutViewEllipticalRubberBand::start( QPointF position, Qt::KeyboardMod
{
QTransform t;
mRubberBandItem = new QGraphicsEllipseItem( 0, 0, 0, 0 );
mRubberBandItem->setBrush( Qt::NoBrush );
mRubberBandItem->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
mRubberBandItem->setBrush( brush() );
mRubberBandItem->setPen( pen() );
mRubberBandStartPos = position;
t.translate( position.x(), position.y() );
mRubberBandItem->setTransform( t );
@@ -20,6 +20,8 @@

#include "qgis_gui.h"
#include "qgis_sip.h"
#include <QBrush>
#include <QPen>

class QgsLayoutView;
class QGraphicsRectItem;
@@ -89,6 +91,34 @@ class GUI_EXPORT QgsLayoutViewRubberBand
*/
QgsLayout *layout() const;

/**
* Returns the brush used for drawing the rubber band.
* \see setBrush()
* \see pen()
*/
QBrush brush() const;

/**
* Sets the \a brush used for drawing the rubber band.
* \see brush()
* \see setPen()
*/
void setBrush( const QBrush &brush );

/**
* Returns the pen used for drawing the rubber band.
* \see setPen()
* \see brush()
*/
QPen pen() const;

/**
* Sets the \a pen used for drawing the rubber band.
* \see pen()
* \see setBrush()
*/
void setPen( const QPen &pen );

protected:

/**
@@ -103,6 +133,9 @@ class GUI_EXPORT QgsLayoutViewRubberBand

QgsLayoutView *mView = nullptr;

QBrush mBrush = Qt::NoBrush;
QPen mPen = QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 );

};


@@ -36,6 +36,7 @@ class TestQgsLayoutView: public QObject
void tool();
void events();
void registryUtils();
void rubberBand();

private:

@@ -271,5 +272,14 @@ void TestQgsLayoutView::registryUtils()

}

void TestQgsLayoutView::rubberBand()
{
QgsLayoutViewRectangularRubberBand band;
band.setBrush( QBrush( QColor( 255, 0, 0 ) ) );
QCOMPARE( band.brush().color(), QColor( 255, 0, 0 ) );
band.setPen( QPen( QColor( 0, 255, 0 ) ) );
QCOMPARE( band.pen().color(), QColor( 0, 255, 0 ) );
}

QGSTEST_MAIN( TestQgsLayoutView )
#include "testqgslayoutview.moc"

0 comments on commit 5cac2f7

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