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/ or email : webmaster.salome@opencascade.com
19 #ifndef PLOT2D_VIEWFRAME_H
20 #define PLOT2D_VIEWFRAME_H
22 #include "Plot2d_Curve.h"
30 typedef QIntDict<Plot2d_Curve> CurveDict;
32 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
36 enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId,
37 ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
38 LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
40 /* Construction/destruction */
41 Plot2d_ViewFrame( QWidget* parent, const QString& title = "" );
42 virtual ~Plot2d_ViewFrame();
44 enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
47 QWidget* getViewWidget();
54 void Display( const Plot2d_Prs* );
55 void Erase( const Plot2d_Prs*, const bool = false );
56 Plot2d_Prs* CreatePrs( const char* entry = 0 );
60 void setTitle( const QString& title );
61 QString getTitle() const { return myTitle; }
62 void displayCurve( Plot2d_Curve* curve, bool update = false );
63 void displayCurves( const curveList& curves, bool update = false );
64 void eraseCurve( Plot2d_Curve* curve, bool update = false );
65 void eraseCurves( const curveList& curves, bool update = false );
66 int getCurves( curveList& clist );
67 const CurveDict& getCurves() { return myCurves; }
68 int hasCurve( Plot2d_Curve* curve );
69 bool isVisible( Plot2d_Curve* curve );
70 void updateCurve( Plot2d_Curve* curve, bool update = false );
71 void updateLegend( const Plot2d_Prs* prs );
73 void fitArea( const QRect& area );
74 void fitData(const int mode,
75 const double xMin, const double xMax,
76 const double yMin, const double yMax,
77 const double y2Min = 0, const double y2Max = 0);
79 void getFitRanges(double& xMin, double& xMax,
80 double& yMin, double& yMax,
81 double& y2Min, double& y2Max);
84 void copyPreferences( Plot2d_ViewFrame* );
85 void setCurveType( int curveType, bool update = true );
86 int getCurveType() const { return myCurveType; }
87 void setCurveTitle( int curveKey, const QString& title );
88 void showLegend( bool show, bool update = true );
89 void setLegendPos( int pos );
90 int getLegendPos() const { return myLegendPos; }
91 void setMarkerSize( const int size, bool update = true );
92 int getMarkerSize() const { return myMarkerSize; }
93 void setBackgroundColor( const QColor& color );
94 QColor backgroundColor() const;
95 void setXGrid( bool xMajorEnabled, const int xMajorMax,
96 bool xMinorEnabled, const int xMinorMax, bool update = true );
97 void setYGrid( bool yMajorEnabled, const int yMajorMax,
98 bool yMinorEnabled, const int yMinorMax,
99 bool y2MajorEnabled, const int y2MajorMax,
100 bool y2MinorEnabled, const int y2MinorMax, bool update = true );
101 void setTitle( bool enabled, const QString& title, ObjectType type, bool update = true );
102 QString getTitle( ObjectType type ) const;
104 void setFont( const QFont& font, ObjectType type, bool update = true );
105 void setHorScaleMode( const int mode, bool update = true );
106 int getHorScaleMode() const { return myXMode; }
107 void setVerScaleMode( const int mode, bool update = true );
108 int getVerScaleMode() const { return myYMode; }
110 bool isModeHorLinear();
111 bool isModeVerLinear();
112 bool isLegendShow() { return myShowLegend; };
114 // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x:
115 // it crashes if switched to X/Y logarithmic mode, when one or more points have
116 // non-positive X/Y coordinate
117 bool isXLogEnabled() const;
118 bool isYLogEnabled() const;
120 virtual bool print( const QString& file, const QString& format ) const;
122 QString getVisualParameters();
123 void setVisualParameters( const QString& parameters );
125 void incrementalPan ( const int incrX, const int incrY );
126 void incrementalZoom( const int incrX, const int incrY );
129 int testOperation( const QMouseEvent& );
130 void readPreferences();
131 void writePreferences();
132 QString getInfo( const QPoint& pnt );
133 virtual void wheelEvent( QWheelEvent* );
139 void onViewFitArea();
140 void onViewGlobalPan();
143 void onChangeBackground();
153 virtual void customEvent( QCustomEvent* );
156 void plotMousePressed( const QMouseEvent& );
157 void plotMouseMoved( const QMouseEvent& );
158 void plotMouseReleased( const QMouseEvent& );
161 void vpModeHorChanged();
162 void vpModeVerChanged();
163 void vpCurveChanged();
164 void contextMenuRequested( QContextMenuEvent *e );
167 Plot2d_Plot2d* myPlot;
177 QString myTitle, myXTitle, myYTitle, myY2Title;
178 bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
179 bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
180 bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
181 int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
182 int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
183 int myXMode, myYMode;
184 double myXDistance, myYDistance, myYDistance2;
188 class Plot2d_Plot2d : public QwtPlot
192 Plot2d_Plot2d( QWidget* parent );
195 void getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
196 QwtLegend* getLegend() {
197 #if QWT_VERSION < 0x040200
200 return legend(); /* mpv: porting to the Qwt 4.2.0 */
203 virtual QSize sizeHint() const;
204 virtual QSizePolicy sizePolicy() const;
205 virtual QSize minimumSizeHint() const;
207 bool polished() const { return myIsPolished; }
210 virtual void polish();
213 bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
216 QValueList<QColor> myColors;