From: ouv Date: Mon, 31 Aug 2009 09:50:33 +0000 (+0000) Subject: Implementation of the logarithmic scaling mode X-Git-Tag: CTH_15~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2714e8fac43ca5d457a993e6c5c1d7aa71114553;p=modules%2Fgui.git Implementation of the logarithmic scaling mode --- diff --git a/src/Qtx/QtxColorScale.cxx b/src/Qtx/QtxColorScale.cxx index 44589c9c1..a993910fe 100755 --- a/src/Qtx/QtxColorScale.cxx +++ b/src/Qtx/QtxColorScale.cxx @@ -50,6 +50,7 @@ QtxColorScale::QtxColorScale( QWidget* parent, Qt::WindowFlags f ) myDumpMode( NoDump ), myColorMode( Auto ), myLabelMode( Auto ), + myScalingMode( Linear ), myFlags( AtBorder | WrapTitle ), myLabelPos( Right ), myTitlePos( Center ) @@ -73,6 +74,7 @@ QtxColorScale::QtxColorScale( const int num, QWidget* parent, Qt::WindowFlags f myDumpMode( NoDump ), myColorMode( Auto ), myLabelMode( Auto ), + myScalingMode( Linear ), myFlags( AtBorder | WrapTitle ), myLabelPos( Right ), myTitlePos( Center ) @@ -167,6 +169,15 @@ int QtxColorScale::colorMode() const return myColorMode; } +/*! + \brief Get scaling mode. + \return current scaling mode (QtxColorScale::ScalingMode) +*/ +int QtxColorScale::scalingMode() const +{ + return myScalingMode; +} + /*! \brief Get number of color scale intervals. \return number of intervals @@ -416,6 +427,19 @@ void QtxColorScale::setColorMode( const int mode ) updateScale(); } +/*! + \brief Set color scale scaling mode. + \param mode new scaling mode (QtxColorScale::ScalingMode) +*/ +void QtxColorScale::setScalingMode( const int mode ) +{ + if ( myScalingMode == mode ) + return; + + myScalingMode = mode; + updateScale(); +} + /*! \brief Set color scale dump mode. \param mode new dump mode (QtxColorScale::DumpMode) @@ -822,7 +846,7 @@ void QtxColorScale::drawScale( QPainter* p, const QColor& bg, const bool transp, labels.prepend( getLabel( idx ) ); } } - + if ( testFlags( AtBorder ) ) { if ( reverse ) @@ -1002,7 +1026,20 @@ double QtxColorScale::getNumber( const int idx ) const { double val = 0; if ( intervalsNumber() > 0 ) - val = minimum() + idx * ( qAbs( maximum() - minimum() ) / intervalsNumber() ); + { + if ( scalingMode() == Linear ) + val = minimum() + idx * ( qAbs( maximum() - minimum() ) / intervalsNumber() ); + else if ( scalingMode() == Logarithmic ) + { + if ( minimum() > 0 && maximum() > 0 ) + { + double logMin = log10( minimum() ); + double logMax = log10( maximum() ); + double logVal = logMin + idx * ( qAbs( logMax - logMin ) / intervalsNumber() ); + val = pow( 10, logVal ); + } + } + } return val; } diff --git a/src/Qtx/QtxColorScale.h b/src/Qtx/QtxColorScale.h index 10014c8d9..d5b74c685 100755 --- a/src/Qtx/QtxColorScale.h +++ b/src/Qtx/QtxColorScale.h @@ -43,6 +43,11 @@ public: Auto, //!< auto User //!< user defined } Mode; + //! Color scale scaling mode. + typedef enum { + Linear, //!< linear + Logarithmic //!< logarithmic + } ScalingMode; //! Color scale title, label position. typedef enum { None, //!< do not draw @@ -78,6 +83,7 @@ public: int dumpMode() const; int labelMode() const; int colorMode() const; + int scalingMode() const; int intervalsNumber() const; QString title() const; @@ -96,6 +102,7 @@ public: void setDumpMode( const int ); void setColorMode( const int ); void setLabelMode( const int ); + void setScalingMode( const int ); void setIntervalsNumber( const int ); void setTitle( const QString& ); @@ -151,6 +158,7 @@ private: int myDumpMode; //!< dump mode (QtxColorScale::DumpMode) int myColorMode; //!< color mode (QtxColorScale::Mode) int myLabelMode; //!< label mode (QtxColorScale::Mode) + int myScalingMode; //!< scaling mode (QtxColorScale::ScalingMode) QList myColors; //!< list of colors QList myLabels; //!< list of labels