19#include "moc_qgsplotrubberband.cpp" 
   22#include <QGraphicsScene> 
   23#include <QGraphicsRectItem> 
   43  const double dx = position.x() - 
start.x();
 
   44  const double dy = position.y() - 
start.y();
 
   46  if ( constrainSquare )
 
   48    if ( std::fabs( dx ) > std::fabs( dy ) )
 
   50      width = std::fabs( dx );
 
   55      height = std::fabs( dy );
 
   59    x = 
start.x() - ( ( dx < 0 ) ? width : 0 );
 
   60    y = 
start.y() - ( ( dy < 0 ) ? height : 0 );
 
   90    x = 
start.x() - width;
 
   91    y = 
start.y() - height;
 
   96  return QRectF( x, y, width, height );
 
 
  127  if ( mRubberBandItem )
 
  129    canvas()->scene()->removeItem( mRubberBandItem );
 
  130    delete mRubberBandItem;
 
 
  137  mRubberBandItem = 
new QGraphicsRectItem( 0, 0, 0, 0 );
 
  138  mRubberBandItem->setBrush( 
brush() );
 
  139  mRubberBandItem->setPen( 
pen() );
 
  140  mRubberBandStartPos = position;
 
  141  t.translate( position.x(), position.y() );
 
  142  mRubberBandItem->setTransform( t );
 
  143  mRubberBandItem->setZValue( 1000 );
 
  144  canvas()->scene()->addItem( mRubberBandItem );
 
  145  canvas()->scene()->update();
 
 
  150  if ( !mRubberBandItem )
 
  155  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  156  const bool fromCenter = modifiers & Qt::AltModifier;
 
  158  const QRectF newRect = 
updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
  159  mRubberBandItem->setRect( 0, 0, newRect.width(), newRect.height() );
 
  161  t.translate( newRect.x(), newRect.y() );
 
  162  mRubberBandItem->setTransform( t );
 
 
  167  const bool constrainSquare = modifiers & Qt::ShiftModifier;
 
  168  const bool fromCenter = modifiers & Qt::AltModifier;
 
  170  if ( mRubberBandItem )
 
  172    canvas()->scene()->removeItem( mRubberBandItem );
 
  173    delete mRubberBandItem;
 
  174    mRubberBandItem = 
nullptr;
 
  176  return updateRect( mRubberBandStartPos, position, constrainSquare, fromCenter );
 
 
Plot canvas is a class for displaying interactive 2d charts and plots.
 
void start(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be created at the specified starting position (in canvas coordinate ...
 
void update(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be updated to reflect a temporary ending position (in canvas coordin...
 
QgsPlotRectangularRubberBand(QgsPlotCanvas *canvas=nullptr)
Constructor for QgsPlotRectangularRubberBand.
 
~QgsPlotRectangularRubberBand() 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.
 
An abstract base class for temporary rubber band items in various shapes, for use within QgsPlotCanva...
 
QBrush brush() const
Returns the brush used for drawing the rubber band.
 
void setBrush(const QBrush &brush)
Sets the brush used for drawing the rubber band.
 
QgsPlotRubberBand(QgsPlotCanvas *canvas=nullptr)
Constructor for QgsPlotRubberBand.
 
QgsPlotCanvas * canvas() const
Returns the canvas associated with 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.
 
virtual void start(QPointF position, Qt::KeyboardModifiers modifiers)=0
Called when a rubber band should be created at the specified starting position (in canvas coordinate ...
 
void setPen(const QPen &pen)
Sets the pen used for drawing the rubber band.
 
QPen pen() const
Returns the pen used for drawing the rubber band.