From b95152c576f866ffd63548c526b89cac7a2856df Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 10 Nov 2016 15:08:57 +0300 Subject: [PATCH] 0004010: External 20836 News syntax for script ggs Point 1: XLABEL_FORMAT, YLABEL_FORMAT. --- src/Plot2d/Plot2d_ViewFrame.cxx | 47 ++++++++++++++++++++++++++++++++- src/Plot2d/Plot2d_ViewFrame.h | 24 +++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 749b0218b..edaf43c31 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -2229,12 +2229,22 @@ Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent ) defaultPicker(); + // custom scale draws allowing to specify the label format + for( int anAxisId = QwtPlot::yLeft; anAxisId < QwtPlot::axisCnt; anAxisId++ ) + { + if( QwtScaleDraw* aScale = axisScaleDraw( anAxisId ) ) + { + QwtScaleDraw* aCustomScale = new Plot2d_ScaleDraw(); + setAxisScaleDraw( anAxisId, aCustomScale ); + } + } + // auto scaling by default setAxisAutoScale( QwtPlot::yLeft ); setAxisAutoScale( QwtPlot::yRight ); setAxisAutoScale( QwtPlot::xBottom ); -// grid + // grid myGrid = new QwtPlotGrid(); QPen aMajPen = myGrid->majPen(); aMajPen.setStyle( Qt::DashLine ); @@ -2576,6 +2586,15 @@ void Plot2d_Plot2d::polish() myIsPolished = true; } +/*! + Sets the custom label format for the specified axis. +*/ +void Plot2d_Plot2d::setLabelFormat( const int theAxisId, const QString& theFormat ) +{ + if( QwtScaleDraw* aScale = axisScaleDraw( theAxisId ) ) + if( Plot2d_ScaleDraw* aCustomScale = dynamic_cast( aScale ) ) + aCustomScale->setLabelFormat( theFormat ); +} /*! Creates presentation of object @@ -3097,3 +3116,29 @@ bool Plot2d_ViewFrame::isTimeColorization() return true; return false; } + +/*! + Convert a numerical value to a text label using the custom format (if it is defined) +*/ +QwtText Plot2d_ScaleDraw::label( double theValue ) const +{ + if( !myLabelFormat.isEmpty() ) + return QString().sprintf( myLabelFormat.toLatin1().constData(), theValue ); + return QwtScaleDraw::label( theValue ); +} + +/*! + Sets the label format +*/ +void Plot2d_ScaleDraw::setLabelFormat( const QString& theFormat ) +{ + myLabelFormat = theFormat; +} + +/*! + Gets the label format +*/ +const QString& Plot2d_ScaleDraw::labelFormat() const +{ + return myLabelFormat; +} diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index d8570b457..4ad6f7057 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -26,6 +26,7 @@ #include #include #include +#include class Plot2d_Plot2d; class Plot2d_Prs; @@ -296,6 +297,8 @@ public: static bool closeColors( const QColor& color1, const QColor& color2 ); + PLOT2D_EXPORT void setLabelFormat( const int theAxisId, const QString& theFormat ); + public slots: virtual void polish(); @@ -358,4 +361,25 @@ private: QColor myInactiveColor; }; +//! The class is derived from QwtScaleDraw. +/*! + The class is derived from QwtScaleDraw. Its main purpose is redefining + label() virtual method in order to provide possibility to customize + the numerical format of the Plot2d axis labels. +*/ + +class Plot2d_ScaleDraw : public QwtScaleDraw +{ +public: + Plot2d_ScaleDraw() : QwtScaleDraw() {} + + virtual QwtText label( double theValue ) const; + + void setLabelFormat( const QString& theFormat ); + const QString& labelFormat() const; + +private: + QString myLabelFormat; +}; + #endif -- 2.39.2