Salome HOME
Implement generic "Dump view" method to be used by all views (toolbar & context menu)
[modules/gui.git] / src / Plot2d / Plot2d_ViewFrame.h
1 #ifndef PLOT2D_VIEWFRAME_H
2 #define PLOT2D_VIEWFRAME_H
3
4 #include "Plot2d_Prs.h"
5 #include "Plot2d_Curve.h"
6
7 #include <qwidget.h>
8 #include <qintdict.h>
9
10 #include <qwt_plot.h>
11 #include <qwt_legend.h>
12
13 class Plot2d_Plot2d;
14
15 typedef QIntDict<Plot2d_Curve> CurveDict;
16
17 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
18
19   Q_OBJECT
20
21   enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId, 
22    ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
23    LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
24 public:
25   /* Construction/destruction */
26   Plot2d_ViewFrame( QWidget* parent, const QString& title = "" );
27   virtual ~Plot2d_ViewFrame();
28
29   enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
30
31 public:
32   QWidget* getViewWidget();
33
34   /* display */
35   void    DisplayAll();
36   void    EraseAll();
37   void    Repaint();
38
39   void    Display( const Plot2d_Prs* );
40   void    Erase( const Plot2d_Prs*, const bool = false );
41   Plot2d_Prs* CreatePrs( const char* entry = 0 );
42
43   /* operations */
44   void    setTitle( const QString& title );
45   QString getTitle() const { return myTitle; }
46   void    displayCurve( Plot2d_Curve* curve, bool update = false );
47   void    displayCurves( curveList curves, bool update = false );
48   void    eraseCurve( Plot2d_Curve* curve, bool update = false );
49   void    eraseCurves( curveList& curves, bool update = false );
50   int     getCurves( QList<Plot2d_Curve>& clist );
51   const   CurveDict& getCurves() { return myCurves; }
52   int     hasCurve( Plot2d_Curve* curve );
53   bool    isVisible( Plot2d_Curve* curve );
54   void    updateCurve( Plot2d_Curve* curve, bool update = false );
55   void    updateLegend( const Plot2d_Prs* prs );
56   void    fitAll();
57   void    fitArea( const QRect& area );
58
59   /* view parameters */
60   void    setCurveType( int curveType, bool update = true );
61   int     getCurveType() const { return myCurveType; }
62   void    setCurveTitle( int curveKey, const QString& title );
63   void    showLegend( bool show, bool update = true );
64   void    setLegendPos( int pos );
65   int     getLegendPos() const { return myLegendPos; }
66   void    setMarkerSize( const int size, bool update = true  );
67   int     getMarkerSize() const { return myMarkerSize; }
68   void    setBackgroundColor( const QColor& color );
69   QColor  backgroundColor() const;
70   void    setXGrid( bool xMajorEnabled, const int xMajorMax,
71                     bool xMinorEnabled, const int xMinorMax, bool update = true );
72   void    setYGrid( bool yMajorEnabled, const int yMajorMax,
73                     bool yMinorEnabled, const int yMinorMax,
74                     bool y2MajorEnabled, const int y2MajorMax,
75                     bool y2MinorEnabled, const int y2MinorMax, bool update = true );
76   void    setTitle( bool enabled, const QString& title, ObjectType type, bool update = true );
77   QString getTitle( ObjectType type ) const;
78
79   void    setFont( const QFont& font, ObjectType type, bool update = true );
80   void    setHorScaleMode( const int mode, bool update = true );
81   int     getHorScaleMode() const { return myXMode; }
82   void    setVerScaleMode( const int mode, bool update = true );
83   int     getVerScaleMode() const { return myYMode; }
84
85   bool    isModeHorLinear();
86   bool    isModeVerLinear();
87   bool    isLegendShow() { return myShowLegend; };
88
89 protected:
90   int     testOperation( const QMouseEvent& );
91   void    readPreferences();
92   void    writePreferences();
93   QString getInfo( const QPoint& pnt );
94   virtual void wheelEvent( QWheelEvent* );
95
96 public slots:
97   void    onViewPan(); 
98   void    onViewZoom();
99   void    onViewFitAll();
100   void    onViewFitArea();
101   void    onViewGlobalPan(); 
102   void    onSettings();
103   void    onFitData();
104   void    onChangeBackground();
105
106 protected slots:
107   void    plotMousePressed( const QMouseEvent& );
108   void    plotMouseMoved( const QMouseEvent& );
109   void    plotMouseReleased( const QMouseEvent& );
110
111 signals:
112   void    vpModeHorChanged();
113   void    vpModeVerChanged();
114   void    vpCurveChanged();
115   void    contextMenuRequested( QContextMenuEvent *e );
116
117 protected:
118   Plot2d_Plot2d* myPlot;
119   int            myOperation;
120   QPoint         myPnt;
121   CurveDict      myCurves;
122
123   int            myCurveType;
124   bool           myShowLegend;
125   int            myLegendPos;
126   int            myMarkerSize;
127   QColor         myBackground;
128   QString        myTitle, myXTitle, myYTitle, myY2Title;
129   bool           myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
130   bool           myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
131   bool           myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
132   int            myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
133   int            myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
134   int            myXMode, myYMode;
135   double         myXDistance, myYDistance, myYDistance2;
136   bool           mySecondY;
137 };
138
139 class Plot2d_Plot2d : public QwtPlot 
140 {
141 public:
142   Plot2d_Plot2d( QWidget* parent );
143
144   void       replot();
145   void       getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
146   QwtLegend* getLegend() {
147 #if QWT_VERSION < 0x040200
148      return d_legend;
149 #else  
150      return legend(); /* mpv: porting to the Qwt 4.2.0 */
151 #endif
152   }
153   virtual QSize       sizeHint() const;
154   virtual QSizePolicy sizePolicy() const;
155   virtual QSize       minimumSizeHint() const;
156
157 protected:
158   bool       existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
159
160 protected:
161   QValueList<QColor> myColors;
162 };
163
164 #endif