1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #ifndef PLOT2D_VIEWFRAME_H
20 #define PLOT2D_VIEWFRAME_H
22 #include "Plot2d_Curve.h"
29 typedef QIntDict<Plot2d_Curve> CurveDict;
31 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
35 enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId,
36 ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
37 LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
39 /* Construction/destruction */
40 Plot2d_ViewFrame( QWidget* parent, const QString& title = "" );
41 virtual ~Plot2d_ViewFrame();
43 enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
46 QWidget* getViewWidget();
53 void Display( const Plot2d_Prs* );
54 void Erase( const Plot2d_Prs*, const bool = false );
55 Plot2d_Prs* CreatePrs( const char* entry = 0 );
59 void setTitle( const QString& title );
60 QString getTitle() const { return myTitle; }
61 void displayCurve( Plot2d_Curve* curve, bool update = false );
62 void displayCurves( const curveList& curves, bool update = false );
63 void eraseCurve( Plot2d_Curve* curve, bool update = false );
64 void eraseCurves( const curveList& curves, bool update = false );
65 int getCurves( curveList& clist );
66 const CurveDict& getCurves() { return myCurves; }
67 int hasCurve( Plot2d_Curve* curve );
68 bool isVisible( Plot2d_Curve* curve );
69 void updateCurve( Plot2d_Curve* curve, bool update = false );
70 void updateLegend( const Plot2d_Prs* prs );
72 void fitArea( const QRect& area );
73 void fitData(const int mode,
74 const double xMin, const double xMax,
75 const double yMin, const double yMax,
76 const double y2Min = 0, const double y2Max = 0);
78 void getFitRanges(double& xMin, double& xMax,
79 double& yMin, double& yMax,
80 double& y2Min, double& y2Max);
83 void copyPreferences( Plot2d_ViewFrame* );
84 void setCurveType( int curveType, bool update = true );
85 int getCurveType() const { return myCurveType; }
86 void setCurveTitle( int curveKey, const QString& title );
87 void showLegend( bool show, bool update = true );
88 void setLegendPos( int pos );
89 int getLegendPos() const { return myLegendPos; }
90 void setMarkerSize( const int size, bool update = true );
91 int getMarkerSize() const { return myMarkerSize; }
92 void setBackgroundColor( const QColor& color );
93 QColor backgroundColor() const;
94 void setXGrid( bool xMajorEnabled, const int xMajorMax,
95 bool xMinorEnabled, const int xMinorMax, bool update = true );
96 void setYGrid( bool yMajorEnabled, const int yMajorMax,
97 bool yMinorEnabled, const int yMinorMax,
98 bool y2MajorEnabled, const int y2MajorMax,
99 bool y2MinorEnabled, const int y2MinorMax, bool update = true );
100 void setTitle( bool enabled, const QString& title, ObjectType type, bool update = true );
101 QString getTitle( ObjectType type ) const;
103 void setFont( const QFont& font, ObjectType type, bool update = true );
104 void setHorScaleMode( const int mode, bool update = true );
105 int getHorScaleMode() const { return myXMode; }
106 void setVerScaleMode( const int mode, bool update = true );
107 int getVerScaleMode() const { return myYMode; }
109 bool isModeHorLinear();
110 bool isModeVerLinear();
111 bool isLegendShow() { return myShowLegend; };
113 // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x:
114 // it crashes if switched to X/Y logarithmic mode, when one or more points have
115 // non-positive X/Y coordinate
116 bool isXLogEnabled() const;
117 bool isYLogEnabled() const;
119 virtual bool print( const QString& file, const QString& format ) const;
122 int testOperation( const QMouseEvent& );
123 void readPreferences();
124 void writePreferences();
125 QString getInfo( const QPoint& pnt );
126 virtual void wheelEvent( QWheelEvent* );
132 void onViewFitArea();
133 void onViewGlobalPan();
136 void onChangeBackground();
139 void plotMousePressed( const QMouseEvent& );
140 void plotMouseMoved( const QMouseEvent& );
141 void plotMouseReleased( const QMouseEvent& );
144 void vpModeHorChanged();
145 void vpModeVerChanged();
146 void vpCurveChanged();
147 void contextMenuRequested( QContextMenuEvent *e );
150 Plot2d_Plot2d* myPlot;
160 QString myTitle, myXTitle, myYTitle, myY2Title;
161 bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
162 bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
163 bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
164 int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
165 int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
166 int myXMode, myYMode;
167 double myXDistance, myYDistance, myYDistance2;
171 class Plot2d_Plot2d : public QwtPlot
174 Plot2d_Plot2d( QWidget* parent );
177 void getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
178 QwtLegend* getLegend() {
179 #if QWT_VERSION < 0x040200
182 return legend(); /* mpv: porting to the Qwt 4.2.0 */
185 virtual QSize sizeHint() const;
186 virtual QSizePolicy sizePolicy() const;
187 virtual QSize minimumSizeHint() const;
190 bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
193 QValueList<QColor> myColors;