• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

PlotWidget.h

Go to the documentation of this file.
00001 #ifndef PLOT_WIDGET_H
00002 #define PLOT_WIDGET_H
00003 
00004 #include <QDebug>
00005 #include <QDateTime>
00006 #include <QMenu>
00007 #include <QHBoxLayout>
00008 #include <QToolButton>
00009 #include <QVBoxLayout>
00010 #include <QWidget>
00011 
00012 #include "Plot/Plot.h"
00013 #include "Plot/PlotPropertiesDialog.h"
00014 
00015 class PlotWidget : public QWidget
00016 {
00017   Q_OBJECT
00018 
00019   //=====================================================================================
00020   // Constructors and destructor
00021   //=====================================================================================
00022   public:
00023     PlotWidget( QWidget* parent = 0 );
00024     ~PlotWidget();
00025 
00026   //=====================================================================================
00027   // Signals
00028   //=====================================================================================
00029   signals:
00030     //void propertiesTriggered();
00031     void curvePropertiesTriggered( PlotCurve* curve );
00032     void curveRemoveTriggered( PlotCurve* curve );
00033 
00034   //=====================================================================================
00035   // Slots
00036   //=====================================================================================
00037   private slots:
00038     void zoomTriggered( bool flag );
00039     void selectTriggered( bool flag );
00040     void zoomOutTriggered( bool flag );
00041     void zoomOutFullTriggered( bool flag = true );
00042     void contextMenuRequested( const QPoint& point );
00043     void curveContextMenuRequested( const QPoint& point, PlotCurve* plotCurve );
00044     void curvePropertiesTriggered();
00045     void curveRemoveTriggered();
00046     void canvasContextMenuRequested( const QPoint& point );
00047     // Curve selection
00048     void canvasMousePressed( const QPoint& point );
00049     void canvasCurveHighlightRemove();
00050     void mouseMoved();
00051     void deleteKeyPressed();
00052     void propertiesTriggered(){
00053         //Setup props
00054         PlotProperties props;
00055         props.enableGrid(plot()->gridIsEnabled());
00056         props.setYAxisAutoscale(plot()->axisAutoScale(QwtPlot::yLeft));
00057         props.setYAxisMaximum(plot()->axisScaleDiv(QwtPlot::yLeft)->upperBound());
00058         props.setYAxisMinimum(plot()->axisScaleDiv(QwtPlot::yLeft)->lowerBound());
00059 
00060         props.setXAxisAutoscale(plot()->axisAutoScale(QwtPlot::xBottom));
00061         qDebug() << QDateTime().fromTime_t(plot()->axisScaleDiv(QwtPlot::xBottom)->upperBound()).date() << QDateTime().fromTime_t(plot()->axisScaleDiv(QwtPlot::xBottom)->lowerBound()).date();
00062         props.setXAxisMaximum(QDateTime().fromTime_t(plot()->axisScaleDiv(QwtPlot::xBottom)->upperBound()).date());
00063         props.setXAxisMinimum(QDateTime().fromTime_t(plot()->axisScaleDiv(QwtPlot::xBottom)->lowerBound()).date());
00064 
00065         PlotPropertiesDialog dialog(&props);
00066         if ( dialog.exec() == QDialog::Accepted ){
00067             plot()->enableGrid(props.isGridEnabled());
00068             qDebug() << plot()->axisWidget(1);
00069 
00070             if (props.yAxisAutoscale() == false)
00071             {
00072                 // By setting the axis scale, autoscale on that axis is turned off
00073                 double minimum = props.yAxisMinimum();
00074                 double maximum = props.yAxisMaximum();
00075                 plot()->setAxisScale( QwtPlot::yLeft, minimum, maximum );
00076             }
00077             else
00078             {
00079                 // Turn on autoscale on this axis
00080                 plot()->setAxisAutoScale(QwtPlot::yLeft);
00081             }
00082 
00083             if (props.xAxisAutoscale() == false){
00084                 double min = QDateTime(props.xAxisMinimum()).toTime_t();
00085                 double max = QDateTime(props.xAxisMaximum()).toTime_t();
00086                 plot()->setAxisScale(QwtPlot::xBottom, min, max);
00087             } else {
00088                 // Turn on autoscale on this axis
00089                 plot()->setAxisAutoScale(QwtPlot::xBottom);
00090             }
00091 
00092             plot()->replot();
00093         }
00094     }
00095     void saveGraph();
00096   //=====================================================================================
00097   // Methods
00098   //=====================================================================================
00099   public:
00100     Plot* plot() { return m_plot; }
00101 
00102     void enableToolBar( bool flag );
00103     bool isToolBarEnabled() { return m_toolBarEnabled; }
00104     void enableProperties( bool flag );
00105     bool isPropertiesEnabled() { return m_propertiesEnabled; }
00106     QAction* propertiesAction() { return m_propertiesAction; }
00107     void enableZoom( bool flag );
00108     bool isZoomEnabled() { return m_zoomEnabled; }
00109     void enableSelect( bool flag );
00110     bool isSelectEnabled() { return m_selectEnabled; }
00111     QAction* selectAction() { return m_selectAction; }
00112     void enableCustomOne( bool flag );
00113     bool isCustomOneEnabled() { return m_customOneEnabled; }
00114     QAction* customOneAction() { return m_customOneAction; }
00115 
00116     // Context menu
00117     void enableContextMenu( bool flag ) { m_contextMenuEnabled = flag; }
00118     bool isContextMenuEnabled() { return m_contextMenuEnabled; }
00119     QMenu* defaultContextMenu() { return m_contextMenu; }
00120     void setContextMenu( QMenu* menu );
00121     // Curve context menu
00122     void enableCurveContextMenu( bool flag ) { m_curveContextMenuEnabled = flag; }
00123     bool isCurveContextMenuEnabled() { return m_curveContextMenuEnabled; }
00124 
00125     // Curve selection
00126     void enableCurveSelection( bool flag ) { m_curveSelectionEnabled = flag; };
00127     bool isCurveSelectionEnabled() { return m_curveSelectionEnabled; }
00128 
00129     void setToolBarIconSize( QSize size );
00130 
00131     void setAxisLinear( QwtPlot::Axis axis );
00132     void setAxisLogarithmic( QwtPlot::Axis axis );
00133     void setAxisDate( QwtPlot::Axis axis, QDate baseDate = QDate() );
00134     void setAxisDateTime( QwtPlot::Axis axis, QDateTime baseDateTime = QDateTime() );
00135 
00136 protected:
00137     void showEvent(QShowEvent *event){
00138         //hack to fix the bug of PlotZoomer not working on first use.
00139         static int i = 0;
00140         if (i++ == 0) zoomOutFullTriggered(true);
00141         m_plot->updateLayout();
00142         m_plot->updateAxes();
00143         QWidget::showEvent(event);
00144     }
00145 
00146   //=====================================================================================
00147   // Members
00148   //=====================================================================================
00149   private:
00150     Plot*         m_plot;
00151 
00152     QWidget*      m_toolBarWidget;
00153     QAction*      m_propertiesAction;
00154     QToolButton*  m_propertiesToolButton;
00155     QAction*      m_zoomAction;
00156     QToolButton*  m_zoomToolButton;
00157     QAction*      m_selectAction;
00158     QToolButton*  m_selectToolButton;
00159     QAction*      m_zoomOutAction;
00160     QToolButton*  m_zoomOutToolButton;
00161     QAction*      m_zoomOutFullAction;
00162     QToolButton*  m_zoomOutFullToolButton;
00163     QAction*      m_customOneAction;
00164     QToolButton*  m_customOneToolButton;
00165     QAction*      m_saveGraphAction;
00166     QToolButton*  m_saveGraphToolButton;
00167     bool          m_toolBarEnabled;
00168     bool          m_propertiesEnabled;
00169     bool          m_zoomEnabled;
00170     bool          m_selectEnabled;
00171     bool          m_customOneEnabled;
00172 
00173     // Context menu
00174     bool          m_contextMenuEnabled;
00175     QMenu*        m_contextMenu;
00176     QMenu*        m_externalContextMenu;
00177     // Curve context menu
00178     QMenu*        m_curveContextMenu;
00179     bool          m_curveContextMenuEnabled;
00180     PlotCurve*    m_contextCurve;
00181     QAction*      m_curvePropertiesAction;
00182     QAction*      m_curveRemoveAction;
00183     // Curve selection
00184     PlotCurve*    m_selectedCurve;
00185     bool          m_curveSelectionEnabled;
00186 };
00187 
00188 #endif

Generated on Tue Aug 24 2010 15:58:55 for Smartlet by  doxygen 1.7.1