21#include <QGraphicsRectItem> 
   22#include <QGraphicsEllipseItem> 
   23#include <QGraphicsPolygonItem> 
   48  const double dx = position.x() - 
start.x();
 
   49  const double dy = position.y() - 
start.y();
 
   51  if ( constrainSquare )
 
   53    if ( std::fabs( dx ) > std::fabs( dy ) )
 
   55      width = std::fabs( dx );
 
   60      height = std::fabs( dy );
 
   64    x = 
start.x() - ( ( dx < 0 ) ? width : 0 );
 
   65    y = 
start.y() - ( ( dy < 0 ) ? height : 0 );
 
   95    x = 
start.x() - width;
 
   96    y = 
start.y() - height;
 
  101  return QRectF( x, y, width, height );
 
 
  137  if ( mRubberBandItem )
 
  139    layout()->removeItem( mRubberBandItem );
 
  140    delete mRubberBandItem;
 
 
  147  mRubberBandItem = 
new QGraphicsRectItem( 0, 0, 0, 0 );
 
  148  mRubberBandItem->setBrush( 
brush() );
 
  149  mRubberBandItem->setPen( 
pen() );
 
  150  mRubberBandStartPos = position;
 
  151  t.translate( position.x(), position.y() );
 
  152  mRubberBandItem->setTransform( t );
 
  154  layout()->addItem( mRubberBandItem );
 
 
  160  if ( !mRubberBandItem )
 
  165  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  166  const bool fromCenter = modifiers & Qt::AltModifier;
 
  168  const QRectF newRect = 
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  169  mRubberBandItem->setRect( 0, 0, newRect.width(), newRect.height() );
 
  171  t.translate( newRect.x(), newRect.y() );
 
  172  mRubberBandItem->setTransform( t );
 
 
  179  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  180  const bool fromCenter = modifiers & Qt::AltModifier;
 
  182  if ( mRubberBandItem )
 
  184    layout()->removeItem( mRubberBandItem );
 
  185    delete mRubberBandItem;
 
  186    mRubberBandItem = 
nullptr;
 
  188  return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
 
  204  if ( mRubberBandItem )
 
  206    layout()->removeItem( mRubberBandItem );
 
  207    delete mRubberBandItem;
 
 
  214  mRubberBandItem = 
new QGraphicsEllipseItem( 0, 0, 0, 0 );
 
  215  mRubberBandItem->setBrush( 
brush() );
 
  216  mRubberBandItem->setPen( 
pen() );
 
  217  mRubberBandStartPos = position;
 
  218  t.translate( position.x(), position.y() );
 
  219  mRubberBandItem->setTransform( t );
 
  221  layout()->addItem( mRubberBandItem );
 
 
  227  if ( !mRubberBandItem )
 
  232  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  233  const bool fromCenter = modifiers & Qt::AltModifier;
 
  235  const QRectF newRect = 
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  236  mRubberBandItem->setRect( 0, 0, newRect.width(), newRect.height() );
 
  238  t.translate( newRect.x(), newRect.y() );
 
  239  mRubberBandItem->setTransform( t );
 
 
  246  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  247  const bool fromCenter = modifiers & Qt::AltModifier;
 
  249  if ( mRubberBandItem )
 
  251    layout()->removeItem( mRubberBandItem );
 
  252    delete mRubberBandItem;
 
  253    mRubberBandItem = 
nullptr;
 
  255  return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
 
  275  if ( mRubberBandItem )
 
  277    layout()->removeItem( mRubberBandItem );
 
  278    delete mRubberBandItem;
 
 
  285  mRubberBandItem = 
new QGraphicsPolygonItem();
 
  286  mRubberBandItem->setBrush( 
brush() );
 
  287  mRubberBandItem->setPen( 
pen() );
 
  288  mRubberBandStartPos = position;
 
  289  t.translate( position.x(), position.y() );
 
  290  mRubberBandItem->setTransform( t );
 
  292  layout()->addItem( mRubberBandItem );
 
 
  298  if ( !mRubberBandItem )
 
  303  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  304  const bool fromCenter = modifiers & Qt::AltModifier;
 
  306  const QRectF newRect = 
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  308  const QPolygonF shapePolygon = QPolygonF() << QPointF( 0, newRect.height() )
 
  309                                 << QPointF( newRect.width(), newRect.height() )
 
  310                                 << QPointF( newRect.width() / 2.0, 0 )
 
  311                                 << QPointF( 0, newRect.height() );
 
  313  mRubberBandItem->setPolygon( shapePolygon );
 
  315  t.translate( newRect.x(), newRect.y() );
 
  316  mRubberBandItem->setTransform( t );
 
 
  323  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  324  const bool fromCenter = modifiers & Qt::AltModifier;
 
  326  if ( mRubberBandItem )
 
  328    layout()->removeItem( mRubberBandItem );
 
  329    delete mRubberBandItem;
 
  330    mRubberBandItem = 
nullptr;
 
  332  return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
 
QgsLayoutViewEllipseRubberBand is elliptical rubber band for use within QgsLayoutView widgets.
 
QgsLayoutViewEllipticalRubberBand(QgsLayoutView *view=nullptr)
Constructor for QgsLayoutViewEllipticalRubberBand.
 
void update(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be updated to reflect a temporary ending position (in layout coordin...
 
QgsLayoutViewEllipticalRubberBand * create(QgsLayoutView *view) const override
Creates a new instance of the QgsLayoutViewRubberBand subclass.
 
~QgsLayoutViewEllipticalRubberBand() override
 
void start(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be created at the specified starting position (in layout coordinate ...
 
QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=Qt::KeyboardModifiers()) override
Called when a rubber band use has finished and the rubber band is no longer required.
 
QgsLayoutViewRectangularRubberBand is rectangular rubber band for use within QgsLayoutView widgets.
 
QgsLayoutViewRectangularRubberBand * create(QgsLayoutView *view) const override
Creates a new instance of the QgsLayoutViewRubberBand subclass.
 
void update(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be updated to reflect a temporary ending position (in layout coordin...
 
QgsLayoutViewRectangularRubberBand(QgsLayoutView *view=nullptr)
Constructor for QgsLayoutViewRectangularRubberBand.
 
void start(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be created at the specified starting position (in layout coordinate ...
 
~QgsLayoutViewRectangularRubberBand() override
 
QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=Qt::KeyboardModifiers()) override
Called when a rubber band use has finished and the rubber band is no longer required.
 
QgsLayoutViewRubberBand is an abstract base class for temporary rubber band items in various shapes,...
 
QgsLayoutViewRubberBand(QgsLayoutView *view=nullptr)
Constructor for QgsLayoutViewRubberBand.
 
QgsLayoutView * view() const
Returns the view associated with the rubber band.
 
void sizeChanged(const QString &size)
Emitted when the size of the rubber band is changed.
 
QBrush brush() const
Returns the brush used for drawing the rubber band.
 
virtual void start(QPointF position, Qt::KeyboardModifiers modifiers)=0
Called when a rubber band should be created at the specified starting position (in layout coordinate ...
 
void setPen(const QPen &pen)
Sets the pen used for drawing the rubber band.
 
void setBrush(const QBrush &brush)
Sets the brush used for drawing the rubber band.
 
QgsLayout * layout() const
Returns the layout associated with the rubber band.
 
QPen pen() const
Returns the pen used for drawing the rubber band.
 
QRectF updateRect(QPointF start, QPointF position, bool constrainSquare, bool fromCenter)
Calculates an updated bounding box rectangle from a original start position and new position.
 
QgsLayoutViewTriangleRubberBand is triangular rubber band for use within QgsLayoutView widgets.
 
QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=Qt::KeyboardModifiers()) override
Called when a rubber band use has finished and the rubber band is no longer required.
 
QgsLayoutViewTriangleRubberBand(QgsLayoutView *view=nullptr)
Constructor for QgsLayoutViewTriangleRubberBand.
 
QgsLayoutViewTriangleRubberBand * create(QgsLayoutView *view) const override
Creates a new instance of the QgsLayoutViewRubberBand subclass.
 
void update(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be updated to reflect a temporary ending position (in layout coordin...
 
~QgsLayoutViewTriangleRubberBand() override
 
void start(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be created at the specified starting position (in layout coordinate ...
 
A graphical widget to display and interact with QgsLayouts.
 
QgsLayout * currentLayout
 
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
 
@ ZViewTool
Z-value for temporary view tool items.
 
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.