#include <QContextMenuEvent>
#include <QPrinter>
#include <QPalette>
+#include <QLocale>
#include <qwt_math.h>
#include <qwt_plot_canvas.h>
#include <qprinter.h>
#include <qwt_legend.h>
+#include <qwt_scale_widget.h>
#define DEFAULT_LINE_WIDTH 0 // (default) line width
#define DEFAULT_MARKER_SIZE 9 // default marker size
connect( myPlot, SIGNAL( legendClicked( QwtPlotItem* ) ),
this, SIGNAL( legendClicked( QwtPlotItem* ) ) );
+ connect( myPlot->axisWidget( QwtPlot::xBottom ), SIGNAL( scaleDivChanged() ),
+ myPlot, SLOT( onScaleDivChanged() ) );
+ connect( myPlot->axisWidget( QwtPlot::yLeft ), SIGNAL( scaleDivChanged() ),
+ myPlot, SLOT( onScaleDivChanged() ) );
+ if (mySecondY)
+ connect( myPlot->axisWidget( QwtPlot::yRight ), SIGNAL( scaleDivChanged() ),
+ myPlot, SLOT( onScaleDivChanged() ) );
+
+
/* Initial Setup - get from the preferences */
readPreferences();
return false;
}
+void Plot2d_Plot2d::onScaleDivChanged()
+{
+ QwtScaleWidget* aSW = 0;
+ if ( ( aSW = dynamic_cast<QwtScaleWidget*>(sender()) ) ) {
+ int axisId = -1;
+ switch ( aSW->alignment() ) {
+ case QwtScaleDraw::BottomScale:
+ axisId = QwtPlot::xBottom;
+ break;
+ case QwtScaleDraw::LeftScale:
+ axisId = QwtPlot::yLeft;
+ break;
+ case QwtScaleDraw::RightScale:
+ axisId = QwtPlot::yRight;
+ break;
+ default:
+ break;
+ }
+
+ if ( axisId >= 0 ) {
+ QwtScaleMap map = canvasMap(axisId);
+ double aDist = fabs(map.s2()-map.s1()) / (axisMaxMajor(axisId)*axisMaxMinor(axisId));
+
+ QString diffPrecStr;
+ diffPrecStr.sprintf("%e",aDist);
+ int deltaEpsilon = diffPrecStr.right(diffPrecStr.length()-diffPrecStr.indexOf('e')-2).toInt();
+
+ QwtScaleDraw* aQwtSD = axisScaleDraw(axisId);
+ Plot2d_ScaleDraw* aPlot2dSD = dynamic_cast<Plot2d_ScaleDraw*>(aQwtSD);
+ if ( !aPlot2dSD && deltaEpsilon > 6 || aPlot2dSD && aPlot2dSD->precision() != deltaEpsilon )
+ setAxisScaleDraw( axisId, new Plot2d_ScaleDraw(*aQwtSD, 'f', deltaEpsilon) );
+ }
+ }
+}
+
/*!
Sets the flag saying that QwtPlot geometry has been fully defined.
*/
if ( ce->type() == FITALL_EVENT )
fitAll();
}
+
+Plot2d_ScaleDraw::Plot2d_ScaleDraw( char f, int prec )
+ : QwtScaleDraw(),
+ myFormat(f),
+ myPrecision(prec)
+{
+ invalidateCache();
+}
+
+Plot2d_ScaleDraw::Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f, int prec )
+ : QwtScaleDraw(scaleDraw),
+ myFormat(f),
+ myPrecision(prec)
+{
+ invalidateCache();
+}
+
+QwtText Plot2d_ScaleDraw::label( double value ) const
+{
+ return QLocale::system().toString(value,myFormat,myPrecision);
+}
#include <QMultiHash>
#include <QList>
#include <qwt_symbol.h>
+#include <qwt_scale_draw.h>
class Plot2d_Plot2d;
class Plot2d_Prs;
protected:
bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
+protected slots:
+ void onScaleDivChanged();
+
protected:
CurveDict myCurves;
QwtPlotGrid* myGrid;
QwtPlotZoomer* myPlotZoomer;
};
+class Plot2d_ScaleDraw: public QwtScaleDraw
+{
+public:
+ Plot2d_ScaleDraw( char f = 'g', int prec = 6 );
+ Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f = 'g', int prec = 6 );
+
+ virtual QwtText label( double value ) const;
+
+ int precision() const { return myPrecision; }
+
+private:
+ char myFormat;
+ int myPrecision;
+};
+
#endif