10#include "qwt_plot_abstract_barchart.h"
11#include "qwt_scale_map.h"
14static inline double qwtTransformWidth(
15 const QwtScaleMap& map,
double value,
double width )
17 const double w2 = 0.5 * width;
19 const double v1 = map.
transform( value - w2 );
20 const double v2 = map.
transform( value + w2 );
22 return qAbs( v2 - v1 );
25class QwtPlotAbstractBarChart::PrivateData
51 m_data =
new PrivateData;
75 if ( policy != m_data->layoutPolicy )
77 m_data->layoutPolicy = policy;
91 return m_data->layoutPolicy;
104 hint = qwtMaxF( 0.0, hint );
105 if ( hint != m_data->layoutHint )
107 m_data->layoutHint = hint;
121 return m_data->layoutHint;
135 if (
spacing != m_data->spacing )
148 return m_data->spacing;
163 if (
margin != m_data->margin )
178 return m_data->margin;
197 if ( value != m_data->baseline )
199 m_data->baseline = value;
210 return m_data->baseline;
226 double canvasSize,
double boundingSize,
double value )
const
230 switch( m_data->layoutPolicy )
234 width = qwtTransformWidth( map, value, m_data->layoutHint );
239 width = canvasSize * m_data->layoutHint;
244 width = m_data->layoutHint;
250 const size_t numSamples =
dataSize();
253 if ( numSamples > 1 )
255 w = qAbs( boundingSize / ( numSamples - 1 ) );
258 width = qwtTransformWidth( map, value, w );
259 width -= m_data->spacing;
260 width = qwtMaxF( width, m_data->layoutHint );
289 double& left,
double& top,
double& right,
double& bottom )
const
298 hint = 0.5 * canvasRect.width() * m_data->layoutHint;
300 hint = 0.5 * canvasRect.height() * m_data->layoutHint;
306 hint = 0.5 * m_data->layoutHint;
313 const size_t numSamples =
dataSize();
314 if ( numSamples <= 0 )
321 double sampleWidthS = 1.0;
325 sampleWidthS = qwtMaxF( m_data->layoutHint, 0.0 );
331 if ( numSamples > 1 )
333 sampleWidthS = qAbs( br.width() / ( numSamples - 1 ) );
340 ds = qAbs( xMap.
sDist() );
341 w = canvasRect.width();
345 ds = qAbs( yMap.
sDist() );
346 w = canvasRect.height();
349 const double sampleWidthP = ( w -
spacing * ( numSamples - 1 ) )
350 * sampleWidthS / ( ds + sampleWidthS );
352 hint = 0.5 * sampleWidthP;
353 hint += qMax( m_data->margin, 0 );
virtual QRectF dataRect() const =0
virtual size_t dataSize() const =0
Abstract base class for bar chart items.
void setSpacing(int)
Set the spacing.
double layoutHint() const
QwtPlotAbstractBarChart(const QwtText &title)
double sampleWidth(const QwtScaleMap &map, double canvasSize, double boundingSize, double value) const
virtual ~QwtPlotAbstractBarChart()
Destructor.
void setMargin(int)
Set the margin.
virtual void getCanvasMarginHint(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, double &left, double &top, double &right, double &bottom) const override
Calculate a hint for the canvas margin.
LayoutPolicy layoutPolicy() const
void setLayoutPolicy(LayoutPolicy)
void setBaseline(double)
Set the baseline.
LayoutPolicy
Mode how to calculate the bar width.
void setLayoutHint(double)
void setZ(double z)
Set the z value.
void setItemAttribute(ItemAttribute, bool on=true)
virtual void itemChanged()
@ Legend
The item is represented on the legend.
Base class for plot items representing a series of samples.
Qt::Orientation orientation() const
double transform(double s) const
A class representing a text.