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

qsaxis.h

00001 /***************************************************************************
00002                                    qsaxis.h
00003                              -------------------
00004     version              : 0.1
00005     begin                :
00006     copyright            : (C) 2001 by Kamil Dobkowski
00007     email                : kamildobk@poczta.onet.pl
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 
00020 #ifndef QSAXIS_H
00021 #define QSAXIS_H
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include"qsaxes.h"
00028 #include<qstring.h>
00029 #include<math.h>
00030 #include<list.h>
00031 
00032 
00033 //---------------------------------------------------------------------------------------------------//
00034 
00041 class QSAxisTic;
00042 class QSAxisTic {
00043 
00044           public:
00045        double  m_value;   // value of the tic
00046            bool    m_major;   // major or minor tics
00047            double  m_pos;     // tic position on axis in world coordnates
00048        int     m_angle;   // label angle
00049        QString m_label;
00050        QSGFont m_font;
00051        QSGLine m_line;
00052            QSGFill m_fill;    // used to fill area below the tic
00053        bool m_is_fill_defined;
00054            QSAxisTic( double value = 0.0, bool major = true );
00055           ~QSAxisTic();
00056            bool operator<( const QSAxisTic& t ) { return m_pos < t.m_pos; }
00057       };
00058 
00059 //---------------------------------------------------------------------------------------------------//
00060 
00064 typedef struct {
00065     double min;
00066     double max;
00067     double base;
00068     int scale;
00069     bool round;
00070     bool reversed;
00071     } axis_remembered_view_t;
00072 
00073 //---------------------------------------------------------------------------------------------------//
00074 
00084 class QSAxis : public QSAxesChild
00085  {
00086   Q_OBJECT
00087   friend QSAxes;
00088     Q_PROPERTY( bool visible READ visible WRITE setVisible )
00089     Q_PROPERTY( bool oppositePosition READ oppositePosition WRITE setOppositePosition )
00090     Q_PROPERTY( bool defaultPosition READ defaultPosition WRITE setDefaultPosition )
00091     Q_PROPERTY( bool reversed READ reversed WRITE setReversed )
00092     Q_PROPERTY( bool scrollable READ scrollable WRITE setScrollable )
00093 
00094     Q_PROPERTY( QString arrow1 READ arrow1_property WRITE set_arrow1_property )
00095     Q_PROPERTY( QString arrow2 READ arrow2_property WRITE set_arrow2_property )
00096     Q_PROPERTY( double min READ rangeMin WRITE setRangeMin )
00097     Q_PROPERTY( double max READ rangeMax WRITE setRangeMax )
00098     Q_PROPERTY( int scaleType READ scaleType WRITE setScaleType )
00099     Q_PROPERTY( double scaleBase READ scaleBase WRITE setScaleBase )
00100     Q_PROPERTY( double majorGridStep READ majorGridStep WRITE setMajorGridStep )
00101     Q_PROPERTY( double minorGridStep READ minorGridStep WRITE setMinorGridStep )
00102 
00103     Q_PROPERTY( double position READ position WRITE setPosition )
00104     Q_PROPERTY( bool ticsVisible READ ticsVisible WRITE setTicsVisible )
00105     Q_PROPERTY( bool ticsOuter READ ticsOuter WRITE setTicsOuter )
00106     Q_PROPERTY( QString ticsFormat READ ticsFormat WRITE setTicsFormat )
00107     Q_PROPERTY( int ticsAngle READ ticsAngle WRITE setTicsAngle )
00108     Q_PROPERTY( bool roundRangeToTicStep READ roundRangeToTicStep WRITE setRoundRangeToTicStep )
00109 
00110     Q_PROPERTY( double ticLabelPos1 READ ticLabelPos1 WRITE setTicLabelPos1 )
00111     Q_PROPERTY( double ticLabelPos2 READ ticLabelPos2 WRITE setTicLabelPos2 )
00112     Q_PROPERTY( double titlePosition READ titlePosition WRITE setTitlePosition )
00113     Q_PROPERTY( double titleDistance READ titleDistance WRITE setTitleDistance )
00114 
00115   public:
00119      static const double minLogValue;
00123      static const double minScaleBase;
00127      static const double minRangeValue;
00131      static const double maxRangeValue;
00135       static const double minRange;
00136 
00140      enum AxisScale { LinearScale, LogScale };
00144      enum AxisRange { RangeSet, RangeVisible, RangeData };
00148      enum AxisType { XAxisType, YAxisType, ZAxisType, VAxisType, UnknownAxisType };
00153      QSAxis( AxisType type, QSAxes *parentAxes, const char *name=0 );
00157      virtual ~QSAxis();
00161      double dataToWorld( double value ) const;
00165      double worldToData( double value ) const;
00169      AxisType type() const { return m_type; }
00173      void setVisible( bool enabled );
00177      void setOppositePosition( bool enabled );
00181      void setDefaultPosition( bool enabled );
00185      void setReversed( bool reversed );
00189      void setScrollable( bool enabled );
00193      bool visible() const { return m_visible; }
00197      bool oppositePosition() const { return m_opposite; }
00201      bool defaultPosition() const { return m_default; }
00205      bool reversed() const { return m_reversed; }
00209      bool scrollable() const { return m_scrollable; }
00213      void setArrow1( const QSGArrow& arrow );
00217      void setArrow2( const QSGArrow& arrow );
00221      QSGArrow arrow1() const { return m_arrow1; }
00225      QSGArrow arrow2() const { return m_arrow2; }
00230      void setRange( double min, double max );
00235      void setRangeMin( double min );
00240      void setRangeMax( double max );
00244      void setScale( AxisScale scale, double base = 10.0 );
00248      void setScaleType( int scale );
00252      void setScaleBase( double base );
00256      void setPosition( double pos );
00267      double min( AxisRange type = RangeSet ) const;
00271      double max( AxisRange type = RangeSet ) const;
00275      double rangeMin() const { return min(); }
00279      double rangeMax() const { return max(); }
00283      double scaleBase() const { return m_base; }
00287      int scaleType() const { return m_scale; }
00291      double position() const { return m_pos; }
00295      void setGridStep( double major = -4.0, double minor = -20.0 );
00299      void setMajorGridStep( double step );
00303      void setMinorGridStep( double step );
00307      double majorGridStep() const { return m_majd; }
00311      double minorGridStep() const { return m_mind; }
00315      const list<QSAxisTic> *tics() const { return &m_tics; }
00319      const QSAxisTic &lastTic() const { return m_last_tic; }
00323      void setTicsVisible( bool visible );
00327      void setTicsOuter( bool enabled );
00331      void setTicsFormat( const QString& format );
00335      void setTicsAngle( int angle );
00339      void setRoundRangeToTicStep( bool enabled );
00343      QString ticsFormat() const { return m_tics_format; }
00347      int ticsAngle() const { return m_tics_angle; }
00351      bool ticsVisible() const { return m_tics_visible; }
00355      bool ticsOuter() const { return m_tics_outer; }
00359      bool roundRangeToTicStep() const { return m_round; }
00363     void setTicLabelPos1( double pos );
00367     void setTicLabelPos2( double pos );
00371     double ticLabelPos1() const { return m_tic_label_pos1; }
00375     double ticLabelPos2() const { return m_tic_label_pos2; }
00379     void setTitlePosition( double value );
00383     void setTitleDistance( double value );
00387     double titlePosition() const { return m_title_position; }
00391     double titleDistance() const { return m_title_distance; }
00392     
00397      void sprintfTic( QString& buffer, double value, const QString& format = QString::null );
00402      virtual void rememberCurrentView( int index );
00403 
00407      virtual void setRememberedView( int index );
00408 
00409     void set_arrow1_property( const QString& data );
00410     void set_arrow2_property( const QString& data );
00411     QString arrow1_property() const;
00412     QString arrow2_property() const;
00413         virtual ColumnType columnType( int channel, int column ) const;
00414     virtual void loadStateFromStream( QDataStream& stream, QSObjectFactory *factory );
00415     virtual void saveStateToStream( QDataStream& stream, QSObjectFactory *factory );
00416 
00420      enum Channels {
00421         TicsChannel = 0,
00422         LineStyles  = 1,
00423         FontStyles  = 2,
00424         FillStyles  = 3
00425         };
00429      enum LineElement {
00430         AxisLine = 0,
00431                 MajorGridLine,
00432                 MinorGridLine
00433         };
00437      enum FontElement {
00438                 TitleFont = 0,
00439                 TicsFont
00440         };
00441 
00446     static void sprintfTic( QString& buffer, const QString& format, double value, double factor, double base, double exponent );
00447 
00448     axis_remembered_view_t rememberedViews[3];
00449 
00450   protected:
00455      virtual void initAxis( double dataMin, double dataMax, bool isData = true );
00456 
00457   private:
00458      bool m_visible;
00459      AxisType  m_type;   // type of the axis
00460      bool      m_opposite;
00461      bool      m_default; // default position
00462      QSGArrow  m_arrow1;
00463      QSGArrow  m_arrow2;    
00464      double    m_min;    // min set by user
00465      double    m_max;    // max set by user
00466      double    m_vmin;   // visible axis min
00467      double    m_vmax;   // visible axis max
00468      double    m_dmax;   // data min
00469      double    m_dmin;   // data max
00470      double    m_base;   // axis scale base
00471      AxisScale m_scale;  // scale type
00472      double    m_pos;    // length proportional to other axes lengths
00473      bool      m_round; // adjust range to contain an integer number of tics.
00474      bool      m_reversed;  // reversed axis direction
00475      bool      m_scrollable;
00476 
00477      double    m_majd;      // major density
00478      double    m_mind;      // minor density
00479 
00480      QString   m_tics_format; // format of tics values
00481      bool      m_tics_outer;    // outer tics
00482      bool      m_tics_visible;  // show tics
00483      int       m_tics_angle;
00484 
00485      double    m_wscale;    // see axisToWorld
00486      double    m_wmin;      // see axisToWorld
00487 
00488     double m_tic_label_pos1;
00489     double m_tic_label_pos2;
00490 
00491     double m_title_position;
00492     double m_title_distance;
00493     
00494 
00495      list<QSAxisTic> m_tics; // QList ?!
00496      QSAxisTic m_last_tic;
00497 
00498      void init_axis_mappings();
00499      void init_ranges( bool is_data );
00500      void find_closest( double *valM, int *valE, const double MSD[], int MSD_number );
00501      void to_float_point( double value, double *mantissa, int *exponent );
00502      void init_tics();
00503      void init_auto_tics_values();
00504      double round_tic( double v );
00505  };
00506 
00507 #endif
00508 
00509 
00510 

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