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