qwt_plot_abstract_barchart.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
11 #include "qwt_scale_map.h"
12 #include "qwt_math.h"
13 
14 static inline double qwtTransformWidth(
15  const QwtScaleMap& map, double value, double width )
16 {
17  const double w2 = 0.5 * width;
18 
19  const double v1 = map.transform( value - w2 );
20  const double v2 = map.transform( value + w2 );
21 
22  return qAbs( v2 - v1 );
23 }
24 
26 {
27  public:
30  , layoutHint( 0.5 )
31  , spacing( 10 )
32  , margin( 5 )
33  , baseline( 0.0 )
34  {
35  }
36 
38  double layoutHint;
39  int spacing;
40  int margin;
41  double baseline;
42 };
43 
49  : QwtPlotSeriesItem( title )
50 {
51  m_data = new PrivateData;
52 
56  setZ( 19.0 );
57 }
58 
61 {
62  delete m_data;
63 }
64 
74 {
75  if ( policy != m_data->layoutPolicy )
76  {
77  m_data->layoutPolicy = policy;
78  itemChanged();
79  }
80 }
81 
90 {
91  return m_data->layoutPolicy;
92 }
93 
103 {
104  hint = qwtMaxF( 0.0, hint );
105  if ( hint != m_data->layoutHint )
106  {
107  m_data->layoutHint = hint;
108  itemChanged();
109  }
110 }
111 
120 {
121  return m_data->layoutHint;
122 }
123 
133 {
134  spacing = qMax( spacing, 0 );
135  if ( spacing != m_data->spacing )
136  {
138  itemChanged();
139  }
140 }
141 
147 {
148  return m_data->spacing;
149 }
161 {
162  margin = qMax( margin, 0 );
163  if ( margin != m_data->margin )
164  {
165  m_data->margin = margin;
166  itemChanged();
167  }
168 }
169 
177 {
178  return m_data->margin;
179 }
180 
196 {
197  if ( value != m_data->baseline )
198  {
199  m_data->baseline = value;
200  itemChanged();
201  }
202 }
203 
209 {
210  return m_data->baseline;
211 }
212 
226  double canvasSize, double boundingSize, double value ) const
227 {
228  double width;
229 
230  switch( m_data->layoutPolicy )
231  {
232  case ScaleSamplesToAxes:
233  {
234  width = qwtTransformWidth( map, value, m_data->layoutHint );
235  break;
236  }
237  case ScaleSampleToCanvas:
238  {
239  width = canvasSize * m_data->layoutHint;
240  break;
241  }
242  case FixedSampleSize:
243  {
244  width = m_data->layoutHint;
245  break;
246  }
247  case AutoAdjustSamples:
248  default:
249  {
250  const size_t numSamples = dataSize();
251 
252  double w = 1.0;
253  if ( numSamples > 1 )
254  {
255  w = qAbs( boundingSize / ( numSamples - 1 ) );
256  }
257 
258  width = qwtTransformWidth( map, value, w );
259  width -= m_data->spacing;
260  width = qwtMaxF( width, m_data->layoutHint );
261  }
262  }
263 
264  return width;
265 }
266 
290  const QwtScaleMap& yMap, const QRectF& canvasRect,
291  double& left, double& top, double& right, double& bottom ) const
292 {
293  double hint = -1.0;
294 
295  switch( layoutPolicy() )
296  {
297  case ScaleSampleToCanvas:
298  {
299  if ( orientation() == Qt::Vertical )
300  hint = 0.5 * canvasRect.width() * m_data->layoutHint;
301  else
302  hint = 0.5 * canvasRect.height() * m_data->layoutHint;
303 
304  break;
305  }
306  case FixedSampleSize:
307  {
308  hint = 0.5 * m_data->layoutHint;
309  break;
310  }
311  case AutoAdjustSamples:
312  case ScaleSamplesToAxes:
313  default:
314  {
315  const size_t numSamples = dataSize();
316  if ( numSamples <= 0 )
317  break;
318 
319  // doesn't work for nonlinear scales
320 
321  const QRectF br = dataRect();
322  double spacing = 0.0;
323  double sampleWidthS = 1.0;
324 
325  if ( layoutPolicy() == ScaleSamplesToAxes )
326  {
327  sampleWidthS = qwtMaxF( m_data->layoutHint, 0.0 );
328  }
329  else
330  {
332 
333  if ( numSamples > 1 )
334  {
335  sampleWidthS = qAbs( br.width() / ( numSamples - 1 ) );
336  }
337  }
338 
339  double ds, w;
340  if ( orientation() == Qt::Vertical )
341  {
342  ds = qAbs( xMap.sDist() );
343  w = canvasRect.width();
344  }
345  else
346  {
347  ds = qAbs( yMap.sDist() );
348  w = canvasRect.height();
349  }
350 
351  const double sampleWidthP = ( w - spacing * ( numSamples - 1 ) )
352  * sampleWidthS / ( ds + sampleWidthS );
353 
354  hint = 0.5 * sampleWidthP;
355  hint += qMax( m_data->margin, 0 );
356  }
357  }
358 
359  if ( orientation() == Qt::Vertical )
360  {
361  left = right = hint;
362  top = bottom = -1.0; // no hint
363  }
364  else
365  {
366  left = right = -1.0; // no hint
367  top = bottom = hint;
368  }
369 }
qwtTransformWidth
static double qwtTransformWidth(const QwtScaleMap &map, double value, double width)
Definition: qwt_plot_abstract_barchart.cpp:14
left
lu_byte left
Definition: lparser.c:1226
QwtPlotAbstractBarChart::setLayoutPolicy
void setLayoutPolicy(LayoutPolicy)
Definition: qwt_plot_abstract_barchart.cpp:73
sol::stack::top
int top(lua_State *L)
Definition: sol.hpp:11684
QwtPlotAbstractBarChart::PrivateData::layoutHint
double layoutHint
Definition: qwt_plot_abstract_barchart.cpp:38
QwtPlotSeriesItem
Base class for plot items representing a series of samples.
Definition: qwt_plot_seriesitem.h:24
QwtPlotSeriesItem::orientation
Qt::Orientation orientation() const
Definition: qwt_plot_seriesitem.cpp:77
QwtPlotAbstractBarChart::PrivateData::margin
int margin
Definition: qwt_plot_abstract_barchart.cpp:40
QwtPlotItem::Margins
@ Margins
Definition: qwt_plot_item.h:164
QwtPlotAbstractBarChart::PrivateData
Definition: qwt_plot_abstract_barchart.cpp:25
QwtPlotAbstractBarChart::m_data
PrivateData * m_data
Definition: qwt_plot_abstract_barchart.h:99
QwtPlotAbstractBarChart::margin
int margin() const
Definition: qwt_plot_abstract_barchart.cpp:176
right
lu_byte right
Definition: lparser.c:1227
QwtPlotAbstractBarChart::baseline
double baseline() const
Definition: qwt_plot_abstract_barchart.cpp:208
QwtPlotAbstractBarChart::setSpacing
void setSpacing(int)
Set the spacing.
Definition: qwt_plot_abstract_barchart.cpp:132
qwt_math.h
QwtPlotAbstractBarChart::setMargin
void setMargin(int)
Set the margin.
Definition: qwt_plot_abstract_barchart.cpp:160
QwtAbstractSeriesStore::dataRect
virtual QRectF dataRect() const =0
QwtPlotAbstractBarChart::layoutHint
double layoutHint() const
Definition: qwt_plot_abstract_barchart.cpp:119
QwtPlotItem::Legend
@ Legend
The item is represented on the legend.
Definition: qwt_plot_item.h:150
QwtPlotAbstractBarChart::~QwtPlotAbstractBarChart
virtual ~QwtPlotAbstractBarChart()
Destructor.
Definition: qwt_plot_abstract_barchart.cpp:60
QwtPlotAbstractBarChart::PrivateData::PrivateData
PrivateData()
Definition: qwt_plot_abstract_barchart.cpp:28
QwtPlotAbstractBarChart::AutoAdjustSamples
@ AutoAdjustSamples
Definition: qwt_plot_abstract_barchart.h:55
QwtPlotAbstractBarChart::PrivateData::spacing
int spacing
Definition: qwt_plot_abstract_barchart.cpp:39
QwtPlotAbstractBarChart::setLayoutHint
void setLayoutHint(double)
Definition: qwt_plot_abstract_barchart.cpp:102
QwtPlotItem::AutoScale
@ AutoScale
Definition: qwt_plot_item.h:157
QwtPlotAbstractBarChart::ScaleSamplesToAxes
@ ScaleSamplesToAxes
Definition: qwt_plot_abstract_barchart.h:60
qwt_scale_map.h
QwtText
A class representing a text.
Definition: qwt_text.h:51
range_format::map
@ map
QwtPlotAbstractBarChart::PrivateData::baseline
double baseline
Definition: qwt_plot_abstract_barchart.cpp:41
QwtPlotAbstractBarChart::getCanvasMarginHint
virtual void getCanvasMarginHint(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, double &left, double &top, double &right, double &bottom) const QWT_OVERRIDE
Calculate a hint for the canvas margin.
Definition: qwt_plot_abstract_barchart.cpp:289
qwtMaxF
QWT_CONSTEXPR float qwtMaxF(float a, float b)
Definition: qwt_math.h:127
QwtPlotItem::setZ
void setZ(double z)
Set the z value.
Definition: qwt_plot_item.cpp:165
QwtPlotAbstractBarChart::LayoutPolicy
LayoutPolicy
Mode how to calculate the bar width.
Definition: qwt_plot_abstract_barchart.h:39
QwtPlotAbstractBarChart::FixedSampleSize
@ FixedSampleSize
Definition: qwt_plot_abstract_barchart.h:73
QwtPlotItem::itemChanged
virtual void itemChanged()
Definition: qwt_plot_item.cpp:481
QwtScaleMap
A scale map.
Definition: qwt_scale_map.h:26
QwtPlotAbstractBarChart::setBaseline
void setBaseline(double)
Set the baseline.
Definition: qwt_plot_abstract_barchart.cpp:195
QwtPlotItem::setItemAttribute
void setItemAttribute(ItemAttribute, bool on=true)
Definition: qwt_plot_item.cpp:228
QwtScaleMap::sDist
double sDist() const
Definition: qwt_scale_map.h:123
QwtPlotAbstractBarChart
Abstract base class for bar chart items.
Definition: qwt_plot_abstract_barchart.h:24
QwtPlotAbstractBarChart::ScaleSampleToCanvas
@ ScaleSampleToCanvas
Definition: qwt_plot_abstract_barchart.h:68
qwt_plot_abstract_barchart.h
QwtPlotAbstractBarChart::PrivateData::layoutPolicy
QwtPlotAbstractBarChart::LayoutPolicy layoutPolicy
Definition: qwt_plot_abstract_barchart.cpp:37
QwtPlotAbstractBarChart::sampleWidth
double sampleWidth(const QwtScaleMap &map, double canvasSize, double boundingSize, double value) const
Definition: qwt_plot_abstract_barchart.cpp:225
QwtPlotAbstractBarChart::QwtPlotAbstractBarChart
QwtPlotAbstractBarChart(const QwtText &title)
Definition: qwt_plot_abstract_barchart.cpp:48
QwtPlotAbstractBarChart::spacing
int spacing() const
Definition: qwt_plot_abstract_barchart.cpp:146
QwtPlotAbstractBarChart::layoutPolicy
LayoutPolicy layoutPolicy() const
Definition: qwt_plot_abstract_barchart.cpp:89
QwtAbstractSeriesStore::dataSize
virtual size_t dataSize() const =0


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45