10#include "qwt_plot_grid.h"
11#include "qwt_painter.h"
13#include "qwt_scale_map.h"
14#include "qwt_scale_div.h"
19static inline bool qwtFuzzyGreaterOrEqual(
double d1,
double d2 )
21 return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 );
24class QwtPlotGrid::PrivateData
30 , xMinEnabled( false )
31 , yMinEnabled( false )
51 m_data =
new PrivateData;
78 if ( m_data->xEnabled != on )
80 m_data->xEnabled = on;
94 if ( m_data->yEnabled != on )
96 m_data->yEnabled = on;
110 if ( m_data->xMinEnabled != on )
112 m_data->xMinEnabled = on;
126 if ( m_data->yMinEnabled != on )
128 m_data->yMinEnabled = on;
142 if ( m_data->xScaleDiv != scaleDiv )
144 m_data->xScaleDiv = scaleDiv;
156 if ( m_data->yScaleDiv != scaleDiv )
158 m_data->yScaleDiv = scaleDiv;
178 setPen( QPen( color, width, style ) );
189 if ( m_data->majorPen != pen || m_data->minorPen != pen )
191 m_data->majorPen = pen;
192 m_data->minorPen = pen;
225 if ( m_data->majorPen != pen )
227 m_data->majorPen = pen;
260 if ( m_data->minorPen != pen )
262 m_data->minorPen = pen;
284 const QRectF& canvasRect )
const
288 minorPen.setCapStyle( Qt::FlatCap );
292 if ( m_data->xEnabled && m_data->xMinEnabled )
294 drawLines( painter, canvasRect, Qt::Vertical, xMap,
296 drawLines( painter, canvasRect, Qt::Vertical, xMap,
300 if ( m_data->yEnabled && m_data->yMinEnabled )
302 drawLines( painter, canvasRect, Qt::Horizontal, yMap,
304 drawLines( painter, canvasRect, Qt::Horizontal, yMap,
310 majorPen.setCapStyle( Qt::FlatCap );
314 if ( m_data->xEnabled )
316 drawLines( painter, canvasRect, Qt::Vertical, xMap,
320 if ( m_data->yEnabled )
322 drawLines( painter, canvasRect, Qt::Horizontal, yMap,
327void QwtPlotGrid::drawLines( QPainter* painter,
const QRectF& canvasRect,
328 Qt::Orientation orientation,
const QwtScaleMap& scaleMap,
331 const double x1 = canvasRect.left();
332 const double x2 = canvasRect.right() - 1.0;
333 const double y1 = canvasRect.top();
334 const double y2 = canvasRect.bottom() - 1.0;
338 for (
int i = 0; i < values.count(); i++ )
340 double value = scaleMap.
transform( values[i] );
342 value = qRound( value );
344 if ( orientation == Qt::Horizontal )
346 if ( qwtFuzzyGreaterOrEqual( value, y1 ) &&
347 qwtFuzzyGreaterOrEqual( y2, value ) )
354 if ( qwtFuzzyGreaterOrEqual( value, x1 ) &&
355 qwtFuzzyGreaterOrEqual( x2, value ) )
369 return m_data->majorPen;
378 return m_data->minorPen;
387 return m_data->xEnabled;
396 return m_data->xMinEnabled;
405 return m_data->yEnabled;
414 return m_data->yMinEnabled;
421 return m_data->xScaleDiv;
427 return m_data->yScaleDiv;
static bool roundingAlignment()
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
void setMajorPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const override
Draw the grid.
const QwtScaleDiv & yScaleDiv() const
QwtPlotGrid()
Enables major grid, disables minor grid.
void enableY(bool)
Enable or disable horizontal grid lines.
const QPen & minorPen() const
void enableX(bool)
Enable or disable vertical grid lines.
const QPen & majorPen() const
void setXDiv(const QwtScaleDiv &)
virtual void updateScaleDiv(const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv) override
void setPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
void enableXMin(bool)
Enable or disable minor vertical grid lines.
virtual int rtti() const override
const QwtScaleDiv & xScaleDiv() const
void enableYMin(bool)
Enable or disable minor horizontal grid lines.
void setYDiv(const QwtScaleDiv &)
void setMinorPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
virtual ~QwtPlotGrid()
Destructor.
Base class for items on the plot canvas.
virtual void legendChanged()
void setZ(double z)
Set the z value.
@ Rtti_PlotGrid
For QwtPlotGrid.
void setItemInterest(ItemInterest, bool on=true)
virtual void itemChanged()
A class representing a scale division.
QList< double > ticks(int tickType) const
@ MediumTick
Medium ticks.
double transform(double s) const
A class representing a text.