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 );
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<Plot2d_ScaleDraw*>( aScale ) )
+ aCustomScale->setLabelFormat( theFormat );
+}
/*!
Creates presentation of object
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;
+}
#include <QList>
#include <qwt_symbol.h>
#include <qwt_plot_curve.h>
+#include <qwt_scale_draw.h>
class Plot2d_Plot2d;
class Plot2d_Prs;
static bool closeColors( const QColor& color1, const QColor& color2 );
+ PLOT2D_EXPORT void setLabelFormat( const int theAxisId, const QString& theFormat );
+
public slots:
virtual void polish();
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