00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PLOT2D_VIEWFRAME_H
00024 #define PLOT2D_VIEWFRAME_H
00025
00026 #include "Plot2d.h"
00027 #include "Plot2d_Curve.h"
00028
00029 #include <QWidget>
00030 #include <QMultiHash>
00031 #include <QList>
00032 #include <qwt_symbol.h>
00033 #include <qwt_scale_draw.h>
00034
00035 class Plot2d_Plot2d;
00036 class Plot2d_Prs;
00037 class Plot2d_Curve;
00038 class Plot2d_Object;
00039 class QCustomEvent;
00040 class QwtPlotItem;
00041 class QwtPlotCurve;
00042 class QwtPlotGrid;
00043 class QwtPlotZoomer;
00044
00045 typedef QMultiHash<QwtPlotCurve*, Plot2d_Curve*> CurveDict;
00046 typedef QMultiHash<QwtPlotItem*, Plot2d_Object*> ObjectDict;
00047
00048 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
00049 {
00050 Q_OBJECT
00051
00052 enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId,
00053 ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
00054 LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
00055 public:
00056
00057 Plot2d_ViewFrame( QWidget*, const QString& = "" );
00058 virtual ~Plot2d_ViewFrame();
00059
00060 enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
00061
00062 QWidget* getViewWidget();
00063
00064
00065 virtual void DisplayAll();
00066 virtual void EraseAll();
00067 void Repaint();
00068
00069 void Display( const Plot2d_Prs* );
00070 void Erase( const Plot2d_Prs*, const bool = false );
00071 Plot2d_Prs* CreatePrs( const char* = 0 );
00072
00073 virtual bool eventFilter( QObject*, QEvent* );
00074
00075
00076 void updateTitles();
00077 void setTitle( const QString& );
00078 QString getTitle() const;
00079
00080
00081 void displayCurve( Plot2d_Curve*, bool = false );
00082 void displayCurves( const curveList&, bool = false );
00083 void eraseCurve( Plot2d_Curve*, bool = false );
00084 void eraseCurves( const curveList&, bool = false );
00085 int getCurves( curveList& ) const;
00086 CurveDict getCurves() const;
00087 void updateCurve( Plot2d_Curve*, bool = false );
00088
00089
00090 void displayObject( Plot2d_Object*, bool = false );
00091 void displayObjects( const objectList&, bool = false );
00092 void eraseObject( Plot2d_Object*, bool = false );
00093 void eraseObjects( const objectList&, bool = false );
00094 int getObjects( objectList& ) const;
00095 bool isVisible( Plot2d_Object* ) const;
00096 void updateObject( Plot2d_Object*, bool = false );
00097
00098 void updateLegend( const Plot2d_Prs* );
00099 void fitAll();
00100 void fitArea( const QRect& );
00101 void fitData( const int, const double, const double,
00102 const double, const double,
00103 const double = 0, const double = 0 );
00104
00105 void getFitRanges( double&, double&, double&, double&,
00106 double&, double&);
00107
00108 void getFitRangeByCurves( double&, double&, double&, double&,
00109 double&, double& );
00110
00111
00112 void copyPreferences( Plot2d_ViewFrame* );
00113 void setCurveType( int, bool = true );
00114 int getCurveType() const;
00115 void setCurveTitle( Plot2d_Curve*, const QString& );
00116 void setObjectTitle( Plot2d_Object*, const QString& );
00117 void showLegend( bool, bool = true );
00118 void setLegendPos( int );
00119 int getLegendPos() const;
00120 void setMarkerSize( const int, bool = true );
00121 int getMarkerSize() const;
00122 void setBackgroundColor( const QColor& );
00123 QColor backgroundColor() const;
00124 void setXGrid( bool, const int, bool, const int, bool = true );
00125 void setYGrid( bool, const int, bool, const int,
00126 bool, const int, bool, const int, bool = true );
00127 void setTitle( bool, const QString&, ObjectType, bool = true );
00128 QString getTitle( ObjectType ) const;
00129
00130 void setFont( const QFont&, ObjectType, bool = true );
00131 void setHorScaleMode( const int, bool = true );
00132 int getHorScaleMode() const;
00133 void setVerScaleMode( const int, bool = true );
00134 int getVerScaleMode() const;
00135
00136 bool isModeHorLinear();
00137 bool isModeVerLinear();
00138 bool isLegendShow() const;
00139
00140
00141
00142
00143 bool isXLogEnabled() const;
00144 bool isYLogEnabled() const;
00145 void setEnableAxis( QwtPlot::Axis, bool );
00146
00147 virtual bool print( const QString&, const QString& ) const;
00148 void printPlot( QPainter*, const QRect&,
00149 const QwtPlotPrintFilter& = QwtPlotPrintFilter() ) const;
00150
00151 QString getVisualParameters();
00152 void setVisualParameters( const QString& );
00153
00154 void incrementalPan ( const int, const int );
00155 void incrementalZoom( const int, const int );
00156
00157 QwtPlotCanvas* getPlotCanvas() const;
00158 Plot2d_Curve* getClosestCurve( QPoint, double&, int& ) const;
00159
00160 Plot2d_Object* getPlotObject( QwtPlotItem* ) const;
00161
00162 protected:
00163 int testOperation( const QMouseEvent& );
00164 void readPreferences();
00165 void writePreferences();
00166 QString getInfo( const QPoint& );
00167 virtual void wheelEvent( QWheelEvent* );
00168 QwtPlotCurve* getPlotCurve( Plot2d_Curve* ) const;
00169 bool hasPlotCurve( Plot2d_Curve* ) const;
00170 void setCurveType( QwtPlotCurve*, int );
00171 QwtPlotItem* getPlotObject( Plot2d_Object* ) const;
00172 bool hasPlotObject( Plot2d_Object* ) const;
00173
00174
00175
00176
00177
00178 public slots:
00179 void onViewPan();
00180 void onViewZoom();
00181 void onViewFitAll();
00182 void onViewFitArea();
00183 void onViewGlobalPan();
00184 void onSettings();
00185 void onFitData();
00186 void onChangeBackground();
00187 void onPanLeft();
00188 void onPanRight();
00189 void onPanUp();
00190 void onPanDown();
00191 void onZoomIn();
00192 void onZoomOut();
00193
00194 protected:
00195 virtual void customEvent( QEvent* );
00196 void plotMousePressed( const QMouseEvent& );
00197 bool plotMouseMoved( const QMouseEvent& );
00198 void plotMouseReleased( const QMouseEvent& );
00199
00200 signals:
00201 void vpModeHorChanged();
00202 void vpModeVerChanged();
00203 void vpCurveChanged();
00204 void contextMenuRequested( QContextMenuEvent* );
00205 void legendClicked( QwtPlotItem* );
00206
00207 protected:
00208 Plot2d_Plot2d* myPlot;
00209 int myOperation;
00210 QPoint myPnt;
00211
00212 int myCurveType;
00213 bool myShowLegend;
00214 int myLegendPos;
00215 int myMarkerSize;
00216 QColor myBackground;
00217 QString myTitle, myXTitle, myYTitle, myY2Title;
00218 bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
00219 bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
00220 bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
00221 int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
00222 int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
00223 int myXMode, myYMode;
00224 double myXDistance, myYDistance, myYDistance2;
00225 bool mySecondY;
00226 ObjectDict myObjects;
00227 bool myIsDefTitle;
00228 };
00229
00230 class Plot2d_Plot2d : public QwtPlot
00231 {
00232 Q_OBJECT
00233 public:
00234 Plot2d_Plot2d( QWidget* );
00235 virtual ~Plot2d_Plot2d();
00236
00237 void setLogScale( int, bool );
00238
00239 void replot();
00240 QwtLegend* getLegend();
00241 QSize sizeHint() const;
00242 QSize minimumSizeHint() const;
00243 void defaultPicker();
00244 void setPickerMousePattern( int, int = Qt::NoButton );
00245
00246 bool polished() const;
00247 QwtPlotGrid* grid() const;
00248 QwtPlotZoomer* zoomer() const;
00249
00250 virtual void updateYAxisIdentifiers();
00251
00252 public slots:
00253 virtual void polish();
00254
00255 protected slots:
00256 void onScaleDivChanged();
00257
00258 protected:
00259 QwtPlotGrid* myGrid;
00260 QList<QColor> myColors;
00261 bool myIsPolished;
00262 QwtPlotZoomer* myPlotZoomer;
00263 };
00264
00265 class Plot2d_ScaleDraw: public QwtScaleDraw
00266 {
00267 public:
00268 Plot2d_ScaleDraw( char f = 'g', int prec = 6 );
00269 Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f = 'g', int prec = 6 );
00270
00271 virtual QwtText label( double value ) const;
00272
00273 int precision() const { return myPrecision; }
00274
00275 private:
00276 char myFormat;
00277 int myPrecision;
00278 };
00279
00280 #endif