Signals | Public Member Functions | Protected Member Functions

PlotWidget Class Reference

#include <PlotWidget.h>

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

List of all members.

Signals

void curvePropertiesTriggered (PlotCurve *curve)
void curveRemoveTriggered (PlotCurve *curve)

Public Member Functions

 PlotWidget (QWidget *parent=0)
 ~PlotWidget ()
Plotplot ()
void enableToolBar (bool flag)
bool isToolBarEnabled ()
void enableProperties (bool flag)
bool isPropertiesEnabled ()
QActionpropertiesAction ()
void enableZoom (bool flag)
bool isZoomEnabled ()
void enableSelect (bool flag)
bool isSelectEnabled ()
QActionselectAction ()
void enableCustomOne (bool flag)
bool isCustomOneEnabled ()
QActioncustomOneAction ()
void enableContextMenu (bool flag)
bool isContextMenuEnabled ()
QMenudefaultContextMenu ()
void setContextMenu (QMenu *menu)
void enableCurveContextMenu (bool flag)
bool isCurveContextMenuEnabled ()
void enableCurveSelection (bool flag)
bool isCurveSelectionEnabled ()
void setToolBarIconSize (QSize size)
void setAxisLinear (QwtPlot::Axis axis)
void setAxisLogarithmic (QwtPlot::Axis axis)
void setAxisDate (QwtPlot::Axis axis, QDate baseDate=QDate())
void setAxisDateTime (QwtPlot::Axis axis, QDateTime baseDateTime=QDateTime())

Protected Member Functions

void showEvent (QShowEvent *event)

Constructor & Destructor Documentation

PlotWidget::PlotWidget ( QWidget parent = 0  ) 

  : QWidget( parent )
{
  //qDebug( "PlotWidget::PlotWidget" );

  // Tool button layout
  m_toolBarEnabled = true;
  m_toolBarWidget = new QWidget();
  QVBoxLayout* toolButtonLayout = new QVBoxLayout;
  toolButtonLayout->setContentsMargins( 0, 0, 0, 0 );
  m_toolBarWidget->setLayout( toolButtonLayout );

  // Properties
  m_propertiesEnabled = true;
  m_propertiesAction = new QAction( QIcon( QPixmap( ":/PhytoLib/icons/Plot/32x32/Properties.png" ) ),
                                           "Properties", this );
  connect( m_propertiesAction, SIGNAL( triggered( bool ) ), this, SLOT( propertiesTriggered() ) );
  m_propertiesToolButton = new QToolButton;
  m_propertiesToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
  m_propertiesToolButton->setDefaultAction( m_propertiesAction );
  toolButtonLayout->addWidget( m_propertiesToolButton );

  // Zoom
  m_zoomEnabled = true;
  m_zoomAction = new QAction( QIcon( QPixmap( ":/PhytoLib/icons/Plot/32x32/Zoom.png" ) ),
                                     "Zoom", this );
  m_zoomAction->setCheckable( true );
  m_zoomAction->setChecked( true );
  connect( m_zoomAction, SIGNAL( triggered( bool ) ), this, SLOT( zoomTriggered( bool ) ) );
  m_zoomToolButton = new QToolButton;
  m_zoomToolButton->setToolTip( "Toggle zoom" );
  m_zoomToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
  m_zoomToolButton->setDefaultAction( m_zoomAction );
  toolButtonLayout->addWidget( m_zoomToolButton );

  // Select
  m_selectEnabled = true;
  m_selectAction = new QAction( QIcon( QPixmap( ":/PhytoLib/icons/Plot/32x32/Select.png" ) ),
                                "Select", this );
  m_selectAction->setCheckable( true );
  m_selectAction->setChecked( false );
  connect( m_selectAction, SIGNAL( triggered( bool ) ), this, SLOT( selectTriggered( bool ) ) );
  m_selectToolButton = new QToolButton;
  m_selectToolButton->setToolTip( "Toggle zoom" );
  m_selectToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
  m_selectToolButton->setDefaultAction( m_selectAction );
  toolButtonLayout->addWidget( m_selectToolButton );

  // Zoom out
  m_zoomOutAction = new QAction( QIcon( QPixmap( ":/PhytoLib/icons/Plot/32x32/ZoomOut.png" ) ),
                                        "Zoom out", this );
  connect( m_zoomOutAction, SIGNAL( triggered( bool ) ), this, SLOT( zoomOutTriggered( bool ) ) );
  m_zoomOutToolButton = new QToolButton;
  m_zoomOutToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
  m_zoomOutToolButton->setDefaultAction( m_zoomOutAction );
  toolButtonLayout->addWidget( m_zoomOutToolButton );

  // Zoom out full
  m_zoomOutFullAction = new QAction( QIcon( QPixmap( ":/PhytoLib/icons/Plot/32x32/ZoomOutFull.png" ) ),
                                        "Zoom out full", this );
  connect( m_zoomOutFullAction, SIGNAL( triggered( bool ) ), this, SLOT( zoomOutFullTriggered( bool ) ) );
  m_zoomOutFullToolButton = new QToolButton;
  m_zoomOutFullToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
  m_zoomOutFullToolButton->setDefaultAction( m_zoomOutFullAction );
  toolButtonLayout->addWidget( m_zoomOutFullToolButton );

  // Save graph
  m_saveGraphAction = new QAction("Save", this);
  connect(m_saveGraphAction, SIGNAL(triggered()), this, SLOT(saveGraph()));
  m_saveGraphToolButton = new QToolButton;
  m_saveGraphToolButton->setDefaultAction(m_saveGraphAction);
  toolButtonLayout->addWidget(m_saveGraphToolButton);

  // Custom One
  m_customOneEnabled = false;
  m_customOneAction = new QAction( QIcon( QPixmap( ":/PhytoLib/icons/Plot/32x32/Properties.png" ) ),
                                   "Custom 1", this );
  m_customOneAction->setCheckable( false );
  m_customOneToolButton = new QToolButton;
  m_customOneToolButton->setToolTip( "Custom 1" );
  m_customOneToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
  m_customOneToolButton->setDefaultAction( m_customOneAction );
  m_customOneToolButton->setVisible( false );
  toolButtonLayout->addWidget( m_customOneToolButton );

  toolButtonLayout->insertStretch( -1 );

  // Plot
  m_plot = new Plot;
  // TODO: Ugly hack to avoid that part of the axis label gets chopped off
  // If we add a very small axis title it doesn't happen

  //m_plot->setAxisTitle( QwtPlot::yLeft, "Y1" );
  m_plot->enableAxis(QwtPlot::yRight);
  //m_plot->setAxisTitle( QwtPlot::yRight, "Y2" );
  connect(m_plot, SIGNAL(signal_curveAttached(PlotCurve*)),
          this, SLOT(zoomOutFullTriggered()));

  // Main layout
  QHBoxLayout* layout = new QHBoxLayout;
  layout->setContentsMargins( 0, 0, 0, 0 );
  layout->addWidget( m_toolBarWidget );
  layout->addWidget( m_plot );
  setLayout( layout );

  // Context menu
  m_contextMenuEnabled = true;
  m_externalContextMenu = NULL;
  m_contextMenu = NULL;
  connect( m_plot, SIGNAL( customContextMenuRequested( const QPoint& ) ),
           this, SLOT( contextMenuRequested( const QPoint& ) ) );

  // Curve context menu
  m_curveContextMenu = NULL;
  connect( m_plot, SIGNAL( curveContextMenuRequested( const QPoint&, PlotCurve* ) ),
           this, SLOT( curveContextMenuRequested( const QPoint&, PlotCurve* ) ) );
  m_curveContextMenuEnabled = false;
  m_contextCurve = NULL;
  m_curvePropertiesAction = new QAction( QIcon( QPixmap( ":/PhytoLib/icons/Plot/32x32/Properties.png" ) ),
                                         "Properties", this );
  connect( m_curvePropertiesAction, SIGNAL( triggered( bool ) ),
           this, SLOT( curvePropertiesTriggered() ) );
  m_curveRemoveAction = new QAction( "Remove", this );
  connect( m_curveRemoveAction, SIGNAL( triggered( bool ) ),
           this, SLOT( curveRemoveTriggered() ) );

  // Canvas context menu
  connect( m_plot->canvas(), SIGNAL( customContextMenuRequested( const QPoint& ) ),
           this, SLOT( canvasContextMenuRequested( const QPoint& ) ) );

  // Curve selection
  m_curveSelectionEnabled = false;
  m_selectedCurve = NULL;
  connect( m_plot, SIGNAL( canvasMousePressed( const QPoint& ) ),
           this, SLOT( canvasMousePressed( const QPoint& ) ) );
  connect( m_plot, SIGNAL( mouseMoved() ),
           this, SLOT( mouseMoved() ) );
  connect( m_plot, SIGNAL( deleteKeyPressed() ),
           this, SLOT( deleteKeyPressed() ) );

  zoomTriggered( true );
}

PlotWidget::~PlotWidget (  ) 

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


Member Function Documentation

void PlotWidget::curvePropertiesTriggered ( PlotCurve curve  )  [signal]

Referenced by PlotWidget().

void PlotWidget::curveRemoveTriggered ( PlotCurve curve  )  [signal]

Referenced by PlotWidget().

QAction* PlotWidget::customOneAction (  )  [inline]

{ return m_customOneAction; }

QMenu* PlotWidget::defaultContextMenu (  )  [inline]

{ return m_contextMenu; }

void PlotWidget::enableContextMenu ( bool  flag  )  [inline]

{ m_contextMenuEnabled = flag; }

void PlotWidget::enableCurveContextMenu ( bool  flag  )  [inline]

{ m_curveContextMenuEnabled = flag; }

void PlotWidget::enableCurveSelection ( bool  flag  )  [inline]

{ m_curveSelectionEnabled = flag; };

void PlotWidget::enableCustomOne ( bool  flag  ) 

{
  //qDebug( "PlotWidget::enableCustomOne" );

  m_customOneEnabled = flag;
  m_customOneToolButton->setVisible( flag );
}

void PlotWidget::enableProperties ( bool  flag  ) 

{
  //qDebug( "PlotWidget::enableProperties" );

  m_propertiesEnabled = flag;
  m_propertiesToolButton->setVisible( flag );
}

void PlotWidget::enableSelect ( bool  flag  ) 

Referenced by Grapher::Grapher().

{
  //qDebug( "PlotWidget::enableSelect" );

  m_selectEnabled = flag;
  m_selectToolButton->setVisible( flag );

  // Handle the case where both modes are disabled
  if ( m_zoomEnabled == false && m_selectEnabled == false )
  {
    // Set the default arrow cursor, depending on what is enabled another cursor will be set
    m_plot->canvas()->setCursor( Qt::ArrowCursor );
    // Disable the zoomers
    if ( m_plot->zoomerLeft() == NULL ) return;
    m_plot->zoomerLeft()->setEnabled( false );
    if ( m_plot->zoomerRight() == NULL ) return;
    m_plot->zoomerRight()->setEnabled( false );
    // Disable the selector
    if ( m_plot->selector() == NULL ) return;
    m_plot->selector()->setEnabled( false );
  }

  zoomTriggered( m_zoomEnabled );
  selectTriggered( m_selectEnabled );
}

void PlotWidget::enableToolBar ( bool  flag  ) 

{
  //qDebug( "PlotWidget::setToolBarEnabled" );

  m_toolBarEnabled = flag;
  m_toolBarWidget->setVisible( flag );
}

void PlotWidget::enableZoom ( bool  flag  ) 

{
  //qDebug( "PlotWidget::enableZoom" );

  m_zoomEnabled = flag;
  m_zoomToolButton->setVisible( flag );
  m_zoomOutToolButton->setVisible( flag );
  m_zoomOutFullToolButton->setVisible( flag );

  // Handle the case where both modes are disabled
  if ( m_zoomEnabled == false && m_selectEnabled == false )
  {
    // Set the default arrow cursor, depending on what is enabled another cursor will be set
    m_plot->canvas()->setCursor( Qt::ArrowCursor );
    // Disable the zoomers
    if ( m_plot->zoomerLeft() == NULL ) return;
    m_plot->zoomerLeft()->setEnabled( false );
    if ( m_plot->zoomerRight() == NULL ) return;
    m_plot->zoomerRight()->setEnabled( false );
    // Disable the selector
    if ( m_plot->selector() == NULL ) return;
    m_plot->selector()->setEnabled( false );
  }

  // Toggle the appropriate mode (if one of them is enabled)
  zoomTriggered( m_zoomEnabled );
  selectTriggered( m_selectEnabled );
}

bool PlotWidget::isContextMenuEnabled (  )  [inline]

{ return m_contextMenuEnabled; }

bool PlotWidget::isCurveContextMenuEnabled (  )  [inline]

{ return m_curveContextMenuEnabled; }

bool PlotWidget::isCurveSelectionEnabled (  )  [inline]

{ return m_curveSelectionEnabled; }

bool PlotWidget::isCustomOneEnabled (  )  [inline]

{ return m_customOneEnabled; }

bool PlotWidget::isPropertiesEnabled (  )  [inline]

{ return m_propertiesEnabled; }

bool PlotWidget::isSelectEnabled (  )  [inline]

{ return m_selectEnabled; }

bool PlotWidget::isToolBarEnabled (  )  [inline]

{ return m_toolBarEnabled; }

bool PlotWidget::isZoomEnabled (  )  [inline]

{ return m_zoomEnabled; }

Plot* PlotWidget::plot (  )  [inline]

Referenced by Grapher::addCurve(), Grapher::Grapher(), and Grapher::removeCurve().

{ return m_plot; }

QAction* PlotWidget::propertiesAction (  )  [inline]

{ return m_propertiesAction; }

QAction* PlotWidget::selectAction (  )  [inline]

{ return m_selectAction; }

void PlotWidget::setAxisDate ( QwtPlot::Axis  axis,
QDate  baseDate = QDate() 
)

{
  //qDebug( "PlotWidget::setAxisNumerical" );

  m_plot->tracker()->enableDateTracker( true );
  m_plot->tracker()->setBaseDate( baseDate );
  m_plot->tracker()->enableDateTimeTracker( false );
  m_plot->setAxisScaleDraw( axis, new PlotDateScale( baseDate ) );
  m_plot->setAxisScaleEngine( axis, new PlotDateScaleEngine() );
}

void PlotWidget::setAxisDateTime ( QwtPlot::Axis  axis,
QDateTime  baseDateTime = QDateTime() 
)

Referenced by Grapher::Grapher().

{
  //qDebug( "PlotWidget::setAxisNumerical" );

  m_plot->tracker()->enableDateTimeTracker( true );
  m_plot->tracker()->setBaseDateTime( baseDateTime );
  m_plot->tracker()->enableDateTracker( false );
  m_plot->setAxisScaleDraw( axis, new PlotDateTimeScale( baseDateTime ) );
  m_plot->setAxisScaleEngine( axis, new PlotDateTimeScaleEngine() );
}

void PlotWidget::setAxisLinear ( QwtPlot::Axis  axis  ) 

{
  //qDebug( "PlotWidget::setAxisNumerical" );

  m_plot->tracker()->enableDateTimeTracker( false );
  m_plot->tracker()->enableDateTracker( false );
  m_plot->setAxisScaleDraw( axis, new QwtScaleDraw() );
  m_plot->setAxisScaleEngine( axis, new QwtLinearScaleEngine() );
}

void PlotWidget::setAxisLogarithmic ( QwtPlot::Axis  axis  ) 

{
  //qDebug( "PlotWidget::setAxisNumerical" );

  m_plot->tracker()->enableDateTimeTracker( false );
  m_plot->tracker()->enableDateTracker( false );
  m_plot->setAxisScaleDraw( axis, new QwtScaleDraw() );
  m_plot->setAxisScaleEngine( axis, new QwtLog10ScaleEngine() );
}

void PlotWidget::setContextMenu ( QMenu menu  ) 

{
  //qDebug( "PlotWidget::setUserDefinedContextMenu" );

  m_externalContextMenu = menu;
}

void PlotWidget::setToolBarIconSize ( QSize  size  ) 

{
  //qDebug( "PlotWidget::setToolBarIconSize" );

  m_propertiesToolButton->setIconSize( size );
  m_zoomToolButton->setIconSize( size );
  m_selectToolButton->setIconSize( size );
  m_zoomOutToolButton->setIconSize( size );
  m_zoomOutFullToolButton->setIconSize( size );
  m_customOneToolButton->setIconSize( size );
}

void PlotWidget::showEvent ( QShowEvent event  )  [inline, protected]

Reimplemented from QWidget.

                                     {
        //hack to fix the bug of PlotZoomer not working on first use.
        static int i = 0;
        if (i++ == 0) zoomOutFullTriggered(true);
        m_plot->updateLayout();
        m_plot->updateAxes();
        QWidget::showEvent(event);
    }


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