Public Types | Public Member Functions

PlotSelector Class Reference

#include <PlotSelector.h>

Inheritance diagram for PlotSelector:
Inheritance graph
[legend]
Collaboration diagram for PlotSelector:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Type { Rect, XInterval, YInterval }

Public Member Functions

 PlotSelector (QwtPlotCanvas *canvas)
virtual ~PlotSelector ()
void setType (Type type)
Type type () const
void setSelectionBrush (QBrush brush)
QBrush selectionBrush () const
void removeSelection ()
QRectF rect () const
double xIntervalLowerBound () const
double xIntervalUpperBound () const
double yIntervalLowerBound () const
double yIntervalUpperBound () const
bool eventFilter (QObject *object, QEvent *event)

Member Enumeration Documentation

Enumerator:
Rect 
XInterval 
YInterval 

{ Rect, XInterval, YInterval };


Constructor & Destructor Documentation

PlotSelector::PlotSelector ( QwtPlotCanvas canvas  ) 

  : QwtPlotPicker( canvas )
{
  //qDebug( "PlotSelector::PlotSelector" );

  setSelectionFlags( PointSelection | DragSelection );
  setRubberBand( RectRubberBand );
  setTrackerMode( AlwaysOff );

  m_type = XInterval;
  m_brush = QBrush( QColor( 255, 0, 0, 128 ) );
  m_beginPoint = QPoint();
  m_endPoint = QPoint();
  m_buttonPressed = false;
  m_plotArea = new PlotArea;
  m_plotArea->setTitle( QwtText( "SelectorPlotArea" ) );
  if ( plot() != NULL )
  {
    m_plotArea->attach( plot() );
  }
}

PlotSelector::~PlotSelector (  )  [virtual]

{
  //qDebug( "PlotSelector::~PlotSelector" );
}


Member Function Documentation

bool PlotSelector::eventFilter ( QObject object,
QEvent event 
)

Reimplemented from QwtPicker.

{
  //qDebug( "PlotSelector::eventFilter" );

  if ( object == canvas() )
  {
    switch ( event->type() )
    {
      case QEvent::MouseButtonPress:
      {
        m_buttonPressed = true;
        m_plotArea->setVisible( true );

        m_beginPoint = trackerPosition();
        if ( m_type == PlotSelector::Rect )
        {
          double xPos = plot()->canvasMap( QwtPlot::xBottom ).invTransform( m_beginPoint.x() );
          double yPos = plot()->canvasMap( QwtPlot::yLeft ).invTransform( m_beginPoint.y() );
          m_plotArea->setRect( xPos, yPos, xPos, yPos );
        }
        else if ( m_type == PlotSelector::XInterval )
        {
          double xPos = plot()->canvasMap( QwtPlot::xBottom ).invTransform( m_beginPoint.x() );
          m_plotArea->setXInterval( xPos, xPos );
        }
        else if ( m_type == PlotSelector::YInterval )
        {
          double yPos = plot()->canvasMap( QwtPlot::yLeft ).invTransform( m_beginPoint.y() );
          m_plotArea->setYInterval( yPos, yPos );
        }
        QTimer::singleShot(0, plot(), SLOT(replot()));
        break;
      }
      case QEvent::MouseButtonRelease:
      {
        m_buttonPressed = false;
        m_endPoint = trackerPosition();

        if ( m_type == PlotSelector::Rect )
        {
          double xBegin = plot()->canvasMap( QwtPlot::xBottom ).invTransform( m_beginPoint.x() );
          double yBegin = plot()->canvasMap( QwtPlot::yLeft ).invTransform( m_beginPoint.y() );
          double xEnd = plot()->canvasMap( QwtPlot::xBottom ).invTransform( m_endPoint.x() );
          double yEnd = plot()->canvasMap( QwtPlot::yLeft ).invTransform( m_endPoint.y() );
          m_plotArea->setRect( xBegin, yBegin, xEnd, yEnd );
        }
        else if ( m_type == PlotSelector::XInterval )
        {
          double xBegin = plot()->canvasMap( QwtPlot::xBottom ).invTransform( m_beginPoint.x() );
          double xEnd = plot()->canvasMap( QwtPlot::xBottom ).invTransform( m_endPoint.x() );
          m_plotArea->setXInterval( xBegin, xEnd );
        }
        else if ( m_type == PlotSelector::YInterval )
        {
          double yBegin = plot()->canvasMap( QwtPlot::yLeft ).invTransform( m_beginPoint.y() );
          double yEnd = plot()->canvasMap( QwtPlot::yLeft ).invTransform( m_endPoint.y() );
          m_plotArea->setYInterval( yBegin, yEnd );
        }

        QTimer::singleShot(0, plot(), SLOT(replot()));
        break;
      }
      case QEvent::MouseMove:
      {
        if ( m_buttonPressed == false ) break;

        QPoint position = trackerPosition();

        if ( m_type == PlotSelector::Rect )
        {
          double xBegin = plot()->canvasMap( QwtPlot::xBottom ).invTransform( m_beginPoint.x() );
          double yBegin = plot()->canvasMap( QwtPlot::yLeft ).invTransform( m_beginPoint.y() );
          double xPos = plot()->canvasMap( QwtPlot::xBottom ).invTransform( position.x() );
          double yPos = plot()->canvasMap( QwtPlot::yLeft ).invTransform( position.y() );
          m_plotArea->setRect( xBegin, yBegin, xPos, yPos );
        }
        else if ( m_type == PlotSelector::XInterval )
        {
          double xBegin = plot()->canvasMap( QwtPlot::xBottom ).invTransform( m_beginPoint.x() );
          double xPos = plot()->canvasMap( QwtPlot::xBottom ).invTransform( position.x() );
          m_plotArea->setXInterval( xBegin, xPos );
        }
        else if ( m_type == PlotSelector::YInterval )
        {
          double yBegin = plot()->canvasMap( QwtPlot::yLeft ).invTransform( m_beginPoint.y() );
          double yPos = plot()->canvasMap( QwtPlot::yLeft ).invTransform( position.y() );
          m_plotArea->setYInterval( yBegin, yPos );
        }

        QTimer::singleShot(0, plot(), SLOT(replot()));
        break;
      }
      default:
        break;
    }
  }

  return QwtPlotPicker::eventFilter( object, event );
}

QRectF PlotSelector::rect (  )  const [inline]

{ return m_plotArea->rect(); }

void PlotSelector::removeSelection (  ) 

{
  //qDebug( "PlotSelector::removeSelection" );

  m_plotArea->setVisible( false );
  QTimer::singleShot(0, plot(), SLOT(replot()));
}

QBrush PlotSelector::selectionBrush (  )  const [inline]

{ return m_plotArea->brush(); }

void PlotSelector::setSelectionBrush ( QBrush  brush  )  [inline]

{ m_plotArea->setBrush( brush ); }

void PlotSelector::setType ( Type  type  )  [inline]

{ m_type = type; }

Type PlotSelector::type (  )  const [inline]

{ return m_type; }

double PlotSelector::xIntervalLowerBound (  )  const [inline]

{ return m_plotArea->xIntervalLowerBound(); }

double PlotSelector::xIntervalUpperBound (  )  const [inline]

{ return m_plotArea->xIntervalUpperBound(); }

double PlotSelector::yIntervalLowerBound (  )  const [inline]

{ return m_plotArea->yIntervalLowerBound(); }

double PlotSelector::yIntervalUpperBound (  )  const [inline]

{ return m_plotArea->yIntervalUpperBound(); }


The documentation for this class was generated from the following files: