Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Examples  

qsaxes.h

00001 /***************************************************************************
00002                                    qsaxes.h
00003                              -------------------
00004     version              : 0.1
00005     begin                : 01-January-2000
00006 
00007     copyright            : (C) 2000 by Kamil Dobkowski
00008     email                : kamildobk@poczta.onet.pl
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
00017  *                                                                         *
00018  ***************************************************************************/
00019 
00020 
00021 #ifndef QSAXES_H
00022 #define QSAXES_H
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include<math.h>
00029 #include<list.h>
00030 #include<qstring.h>
00031 #include<qlist.h>
00032 #include"qsgraphicaldata.h"
00033 #include"qsdrv.h"
00034 #include"qscobject.h"
00035 #include"qsprojection.h"
00036 
00037 class QTimer;
00038 class QSPlot;
00039 class QSAxes;
00040 
00051 class QSCAxesShadow : public QSCGroup {
00052     friend QSAxes;
00053     Q_OBJECT
00054   public:
00058         virtual ~QSCAxesShadow();
00059     virtual void setAutoUpdates( bool enabled );
00063         virtual void setParentAxes( QSAxes * );
00064     virtual void setBox( const QSRectf& rect, QSDrv *drv );
00065     virtual QSRectf box( QSDrv *drv );
00066     virtual bool isHit(  const QSPt2f &p, QSDrv* drv );
00067     virtual bool isAxesShadow();
00068     virtual int style();
00069         virtual QString name();
00070     virtual void draw( QSDrv *drv, bool blocking, bool transparent );
00071     virtual void paintSkeleton( QPainter *p, double dpi = 72.0 );   
00072     virtual void paint( QPainter *p, double dpi = 72.0, bool blocking=true, bool transparent=true );
00073     virtual bool busy() const;
00074     virtual void stop();
00075     virtual void loadStateFromStream( QDataStream& stream, QSObjectFactory *factory );
00076     virtual void saveStateToStream( QDataStream& stream, QSObjectFactory *factory );
00077 
00078   public slots:
00079     virtual void forceUpdate();
00080 
00081   protected:
00085     QSCAxesShadow( QSAxes *parent );    
00086 
00087   private slots:
00088     virtual void slot_object_added( QSCObject *object );
00089     virtual void slot_object_removed( QSCObject *object );
00090     virtual void slot_draw_objects( QSDrv *drv, bool, bool );
00091     virtual void slot_update();
00092     void slot_draw_ends();
00093 
00094   };
00095 
00096 //----------------------------------------------------------------------------------------------------//
00097 
00110 class QSAxes : public QSGraphicalData
00111    {
00112     Q_OBJECT
00113     friend QSPlot;
00114     Q_PROPERTY( double xPosMM READ xPosMM WRITE setXPosMM )
00115     Q_PROPERTY( double yPosMM READ yPosMM WRITE setYPosMM )
00116     Q_PROPERTY( double widthMM READ widthMM WRITE setWidthMM )
00117     Q_PROPERTY( double heightMM READ heightMM WRITE setHeightMM )
00118     Q_PROPERTY( bool drawInBackground READ drawInBackground WRITE setDrawInBackground )
00119     Q_PROPERTY( bool axesOnly READ axesOnly WRITE setAxesOnly )
00120         Q_PROPERTY( QString background READ background_property WRITE set_background_property )
00121 
00122     public:
00127     enum InternalState { Waiting = 0, Busy };
00138     enum CoordinateSystem { mmCoord, normCoord, worldCoord, dataCoord };
00144     enum ElementCategory { GeneralCategory, AxisCategory, GridCategory, DatasetCategory, UnknownCategory };
00148     QSAxes( QObject * parent, const QSProjection *proj, const char * name=0 );
00152     virtual ~QSAxes();
00160         InternalState state() const { return m_internal_state; }
00164         virtual void stop();
00169     bool complete() const { return m_is_complete; }
00170 
00171     //----------------------------------------------------------------//
00179     void setPosMM( const QSPt2f& pos_mm );
00183     void setXPosMM( double x_mm );
00187     void setYPosMM( double y_mm );  
00194     void setSizeMM( const QSPt2f& size_mm );
00198     void setWidthMM( double w_mm );
00202     void setHeightMM( double h_mm );
00206     QSPt2f posMM() const { return m_pos_mm; }
00210     double xPosMM() const { return m_pos_mm.x; }
00214     double yPosMM() const { return m_pos_mm.y; }
00218     QSPt2f sizeMM() const { return m_size_mm; }
00222     double widthMM() const { return m_size_mm.x; }
00226     double heightMM() const { return m_size_mm.y; }
00230       QSRectf calculateCanvasRect( double dpi = 72.0 );
00235       void setCanvasRect( const QSRectf& r );
00240       QSRectf canvasRect() const { return QSRectf( m_cpos.x, m_cpos.y, m_csize.x, m_csize.y ); }
00245       void setFitToCanvasRect( bool enabled );
00249       bool fitToCanvasRect() const { return m_transformation_rect; }
00254      void setDrawInBackground( bool enabled );
00258      bool drawInBackground() const { return m_draw_in_background; }
00259 
00260      //-------------------------------------------------------------//
00261 
00265      void setAxesOnly( bool enabled );
00269      bool axesOnly() const { return m_axes_only; }
00273      void setBackground( const QSGFill& fill );
00277      QSGFill background() const;
00278 
00279      //------------------------------------------------------------//
00284      virtual void rememberCurrentView( int index );
00285 
00289      virtual void setRememberedView( int index );
00290 
00291      //------------------------------------------------------------//
00296      virtual void initMappings( QSDrv *drv );
00303      double canvasToNormalizedX( double value ) const ;
00307      double canvasToNormalizedY( double value ) const ;
00311      QSPt2f canvasToNormalized( const QSPt2f& pos ) const;
00315      double normalizedXToCanvas( double value ) const ;
00319      double normalizedYToCanvas( double value ) const ;
00323      QSPt2f normalizedToCanvas( const QSPt2f& pos ) const;
00328      QSPt2f dataToCanvas( const QSPt3f& pos, QSAxis *xAxis, QSAxis *yAxis, QSAxis *zAxis ) const;
00333      QSPt2f dataToCanvas( const QSPt2f& pos, QSAxis *xAxis, QSAxis *yAxis ) const;
00339      virtual QSPt3f mixedToCanvas( const QSPt3f& pos, CoordinateSystem in_coords[3], double dpi, QSAxis *xAxis, QSAxis *yAxis, QSAxis *zAxis ) const = 0;
00345      virtual QSPt3f canvasToMixed( const QSPt3f& pos, CoordinateSystem out_coords[3], double dpi, QSAxis *xAxis, QSAxis *yAxis, QSAxis *zAxis ) const = 0;
00346 
00347      //------------------------------------------------------------//
00348 
00353       void setAutoUpdates( bool enabled );
00357       bool autoUpdates() const { return m_auto_updates; }
00358 
00359      //----------------------------------------------------------------//
00360 
00364       virtual int childCount() const;
00369       virtual QSData *child( int index ) const;
00370 
00371       //----------------------------------------------------------------//
00372 
00376       int plotCount() const;
00382       void plotAdd( QSPlot *p );
00388       void plotInsert( int beforePos, QSPlot *p );
00393       void plotRemove( QSPlot *p );
00398       void plotDelete( QSPlot *p );
00404       QSPlot *plot( int index ) const ;
00408       int plotIndex( QSPlot *o ) const ;
00412       void plotToFront( QSPlot *o );
00416       void plotToBack( QSPlot *o );
00420       void plotRaise( QSPlot *o );
00424       void plotLower( QSPlot * o );
00428       void plotReorder( int position, QSPlot * o );
00429 
00430      //----------------------------------------------------------------//
00431 
00432 
00436       int axisCount() const;
00442       void axisAdd( QSAxis *axis );
00448       void axisInsert( int position, QSAxis *axis );
00457       bool axisRemove( QSAxis *axis );
00465       bool axisDelete( QSAxis *axis );
00470       QSAxis *axisOfType( int axisType ) const;
00476       QSAxis *axis( int index ) const;
00480       int axisIndex( QSAxis *axis ) const ;
00484       void axisToFront( QSAxis *axis );
00488       void axisToBack( QSAxis *axis );
00492       void axisRaise( QSAxis *axis );
00496       void axisLower( QSAxis *axis );
00500       void axisReorder( int position, QSAxis *axis );
00501 
00502      //----------------------------------------------------------------//
00503      //----------------------------------------------------------------//
00504 
00511      QSCAxesShadow *shadowObject();
00512 
00513      //----------------------------------------------------------------//
00514 
00518       virtual QString posInfo( QSPt2f& pos );
00519 
00520       //--------------------------------------------------------------------------//
00521 
00529       virtual void paintPlot( QPainter *p, double dpi=72.0, bool blocking=true, bool transparent=true ) = 0;
00537       virtual void drawPlot( QSDrv *drv, bool blocking=true, bool transparent=true ) = 0;
00541       virtual void paintSkeleton( QPainter *p, double dpi=72.0, bool reallyFast=false );
00545       void forceUpdate() { emit sigUpdate(); }
00549       QSDrv *run_gDriver() const { return m_drv; }
00553       double run_dpi() const { return m_curr_dpi; }
00557       const QSProjection *proj() const { return m_proj; }
00558     
00559       //----------------------------------------------------------------//
00560 
00561         void set_background_property( const QString& value );
00562     QString background_property() const;
00566     virtual void loadStateFromStream( QDataStream& stream, QSObjectFactory *factory );
00570     virtual void saveStateToStream( QDataStream& stream, QSObjectFactory *factory );
00571 
00572     signals:
00576         void sigDataChanged( QSGraphicalData *b, int channel );
00580         void sigUpdate();
00584         void sigRangesValid();
00588         void sigUserDraw( QSDrv *drv, bool blocking, bool transparent );
00592         void sigDrawEnds();
00593 
00594       //----------------------------------------------------------------//
00595 
00596     protected:
00597 
00601       virtual void dataChanging( QSData *object, int channel = -1 );
00605       virtual void dataChanged( QSData *object, int channel = -1 );
00609       virtual void parametersChanging();
00613       virtual void parametersChanged();
00617       virtual void start( QSDrv *drv, bool blocking, bool transparent );
00622       virtual void axisRangesCalculated() { emit sigRangesValid(); }
00627       virtual void allocRuntimeData() {}
00632       virtual void freeRuntimeData() {}
00636       virtual void drawAxis( QSAxis */*axis*/ ) {}
00640       virtual void drawGrid( QSAxis */*axis*/, bool /*major*/ ) {}
00644       virtual void childEvent ( QChildEvent * );
00645 
00646       struct margins_t {
00647          int l;
00648          int r;
00649          int t;
00650          int b;
00651         } m_m;
00652 
00653       InternalState  m_internal_state;
00654       QSGFill        m_bckg_fill;
00655       QSPt2f         m_csize;
00656       QSPt2f         m_cpos;
00657       QSPt2f         m_pos_mm;
00658       QSPt2f         m_size_mm;
00659       double         m_curr_dpi;
00660       QSDrv         *m_drv;
00661       bool           m_bkg_handler;
00662       bool           m_axes_only;
00663       bool       m_really_fast;
00664       bool       m_blocking;
00665       bool       m_transparent;
00666       QSCAxesShadow     *m_shadow_object;
00667       bool           m_transformation_rect;
00668       bool           m_draw_in_background;
00669       const QSProjection  *m_proj;
00670       int        m_curr_dataset_nr;
00671 
00672      private:
00673     struct qsaxes_private_data;
00674         qsaxes_private_data *d;
00675         QTimer *m_timer;
00676 
00677     // change to fields
00678     bool m_runtime_data_allocated;
00679     bool m_current_started;
00680     bool m_is_complete;
00681     bool m_auto_updates;
00682     bool m_delete_driver;
00683     double m_almost_zero;
00684     void calculate_auto_ranges();
00685 
00686    private slots:
00687       void work_proc();
00688 };
00689    
00690 //---------------------------------------------------------------------------------------------------//
00691 
00698 class QSAxesChild : public QSGraphicalData
00699  {
00700   Q_OBJECT
00701   public:
00706     QSAxesChild( QSAxes *parentAxes, const char *name=0 );
00710     virtual ~QSAxesChild();
00714     QSAxes *parentAxes() const { return m_axes; }
00715 
00716   protected:
00717     QSAxes *m_axes;
00718  };
00719 
00720 #endif
00721 
00722 
00723 

Generated on Mon Mar 18 19:16:30 2002 for KMatplot library by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002