Qwt User's Guide
svn
|
00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** 00002 * Qwt Widget Library 00003 * Copyright (C) 1997 Josef Wilgen 00004 * Copyright (C) 2002 Uwe Rathmann 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the Qwt License, Version 1.0 00008 *****************************************************************************/ 00009 00010 #ifndef QWT_SCALE_ENGINE_H 00011 #define QWT_SCALE_ENGINE_H 00012 00013 #include "qwt_global.h" 00014 #include "qwt_scale_div.h" 00015 #include "qwt_interval.h" 00016 00017 class QwtScaleTransformation; 00018 00022 class QWT_EXPORT QwtScaleArithmetic 00023 { 00024 public: 00025 static double ceilEps( double value, double intervalSize ); 00026 static double floorEps( double value, double intervalSize ); 00027 00028 static double divideEps( double interval, double steps ); 00029 00030 static double ceil125( double x ); 00031 static double floor125( double x ); 00032 }; 00033 00047 class QWT_EXPORT QwtScaleEngine 00048 { 00049 public: 00056 enum Attribute 00057 { 00059 NoAttribute = 0x00, 00060 00062 IncludeReference = 0x01, 00063 00065 Symmetric = 0x02, 00066 00074 Floating = 0x04, 00075 00077 Inverted = 0x08 00078 }; 00079 00081 typedef QFlags<Attribute> Attributes; 00082 00083 explicit QwtScaleEngine(); 00084 virtual ~QwtScaleEngine(); 00085 00086 void setAttribute( Attribute, bool on = true ); 00087 bool testAttribute( Attribute ) const; 00088 00089 void setAttributes( Attributes ); 00090 Attributes attributes() const; 00091 00092 void setReference( double reference ); 00093 double reference() const; 00094 00095 void setMargins( double lower, double upper ); 00096 double lowerMargin() const; 00097 double upperMargin() const; 00098 00107 virtual void autoScale( int maxNumSteps, 00108 double &x1, double &x2, double &stepSize ) const = 0; 00109 00120 virtual QwtScaleDiv divideScale( double x1, double x2, 00121 int maxMajSteps, int maxMinSteps, 00122 double stepSize = 0.0 ) const = 0; 00123 00125 virtual QwtScaleTransformation *transformation() const = 0; 00126 00127 protected: 00128 bool contains( const QwtInterval &, double val ) const; 00129 QList<double> strip( const QList<double>&, const QwtInterval & ) const; 00130 double divideInterval( double interval, int numSteps ) const; 00131 00132 QwtInterval buildInterval( double v ) const; 00133 00134 private: 00135 class PrivateData; 00136 PrivateData *d_data; 00137 }; 00138 00146 class QWT_EXPORT QwtLinearScaleEngine: public QwtScaleEngine 00147 { 00148 public: 00149 virtual void autoScale( int maxSteps, 00150 double &x1, double &x2, double &stepSize ) const; 00151 00152 virtual QwtScaleDiv divideScale( double x1, double x2, 00153 int numMajorSteps, int numMinorSteps, 00154 double stepSize = 0.0 ) const; 00155 00156 virtual QwtScaleTransformation *transformation() const; 00157 00158 protected: 00159 QwtInterval align( const QwtInterval&, double stepSize ) const; 00160 00161 void buildTicks( 00162 const QwtInterval &, double stepSize, int maxMinSteps, 00163 QList<double> ticks[QwtScaleDiv::NTickTypes] ) const; 00164 00165 QList<double> buildMajorTicks( 00166 const QwtInterval &interval, double stepSize ) const; 00167 00168 void buildMinorTicks( 00169 const QList<double>& majorTicks, 00170 int maxMinMark, double step, 00171 QList<double> &, QList<double> & ) const; 00172 }; 00173 00185 class QWT_EXPORT QwtLog10ScaleEngine: public QwtScaleEngine 00186 { 00187 public: 00188 virtual void autoScale( int maxSteps, 00189 double &x1, double &x2, double &stepSize ) const; 00190 00191 virtual QwtScaleDiv divideScale( double x1, double x2, 00192 int numMajorSteps, int numMinorSteps, 00193 double stepSize = 0.0 ) const; 00194 00195 virtual QwtScaleTransformation *transformation() const; 00196 00197 protected: 00198 QwtInterval log10( const QwtInterval& ) const; 00199 QwtInterval pow10( const QwtInterval& ) const; 00200 00201 QwtInterval align( const QwtInterval&, double stepSize ) const; 00202 00203 void buildTicks( 00204 const QwtInterval &, double stepSize, int maxMinSteps, 00205 QList<double> ticks[QwtScaleDiv::NTickTypes] ) const; 00206 00207 QList<double> buildMajorTicks( 00208 const QwtInterval &interval, double stepSize ) const; 00209 00210 QList<double> buildMinorTicks( 00211 const QList<double>& majorTicks, 00212 int maxMinMark, double step ) const; 00213 }; 00214 00215 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtScaleEngine::Attributes ) 00216 00217 #endif