qwt_plot_abstract_barchart.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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 
13 static inline double qwtTransformWidth(
14  const QwtScaleMap &map, double value, double width )
15 {
16  const double w2 = 0.5 * width;
17 
18  const double v1 = map.transform( value - w2 );
19  const double v2 = map.transform( value + w2 );
20 
21  return qAbs( v2 - v1 );
22 }
23 
25 {
26 public:
29  layoutHint( 0.5 ),
30  spacing( 10 ),
31  margin( 5 ),
32  baseline( 0.0 )
33  {
34  }
35 
37  double layoutHint;
38  int spacing;
39  int margin;
40  double baseline;
41 };
42 
48  QwtPlotSeriesItem( title )
49 {
50  d_data = new PrivateData;
51 
55  setZ( 19.0 );
56 }
57 
60 {
61  delete d_data;
62 }
63 
73 {
74  if ( policy != d_data->layoutPolicy )
75  {
76  d_data->layoutPolicy = policy;
77  itemChanged();
78  }
79 }
80 
89 {
90  return d_data->layoutPolicy;
91 }
92 
102 {
103  hint = qMax( 0.0, hint );
104  if ( hint != d_data->layoutHint )
105  {
106  d_data->layoutHint = hint;
107  itemChanged();
108  }
109 }
110 
119 {
120  return d_data->layoutHint;
121 }
122 
132 {
133  spacing = qMax( spacing, 0 );
134  if ( spacing != d_data->spacing )
135  {
137  itemChanged();
138  }
139 }
140 
146 {
147  return d_data->spacing;
148 }
160 {
161  margin = qMax( margin, 0 );
162  if ( margin != d_data->margin )
163  {
164  d_data->margin = margin;
165  itemChanged();
166  }
167 }
168 
176 {
177  return d_data->margin;
178 }
179 
195 {
196  if ( value != d_data->baseline )
197  {
198  d_data->baseline = value;
199  itemChanged();
200  }
201 }
202 
208 {
209  return d_data->baseline;
210 }
211 
225  double canvasSize, double boundingSize, double value ) const
226 {
227  double width;
228 
229  switch( d_data->layoutPolicy )
230  {
231  case ScaleSamplesToAxes:
232  {
233  width = qwtTransformWidth( map, value, d_data->layoutHint );
234  break;
235  }
236  case ScaleSampleToCanvas:
237  {
238  width = canvasSize * d_data->layoutHint;
239  break;
240  }
241  case FixedSampleSize:
242  {
243  width = d_data->layoutHint;
244  break;
245  }
246  case AutoAdjustSamples:
247  default:
248  {
249  const size_t numSamples = dataSize();
250 
251  double w = 1.0;
252  if ( numSamples > 1 )
253  {
254  w = qAbs( boundingSize / ( numSamples - 1 ) );
255  }
256 
257  width = qwtTransformWidth( map, value, w );
258  width -= d_data->spacing;
259  width = qMax( width, d_data->layoutHint );
260  }
261  }
262 
263  return width;
264 }
265 
289  const QwtScaleMap &yMap, const QRectF &canvasRect,
290  double &left, double &top, double &right, double &bottom ) const
291 {
292  double hint = -1.0;
293 
294  switch( layoutPolicy() )
295  {
296  case ScaleSampleToCanvas:
297  {
298  if ( orientation() == Qt::Vertical )
299  hint = 0.5 * canvasRect.width() * d_data->layoutHint;
300  else
301  hint = 0.5 * canvasRect.height() * d_data->layoutHint;
302 
303  break;
304  }
305  case FixedSampleSize:
306  {
307  hint = 0.5 * d_data->layoutHint;
308  break;
309  }
310  case AutoAdjustSamples:
311  case ScaleSamplesToAxes:
312  default:
313  {
314  const size_t numSamples = dataSize();
315  if ( numSamples <= 0 )
316  break;
317 
318  // doesn't work for nonlinear scales
319 
320  const QRectF br = dataRect();
321  double spacing = 0.0;
322  double sampleWidthS = 1.0;
323 
324  if ( layoutPolicy() == ScaleSamplesToAxes )
325  {
326  sampleWidthS = qMax( d_data->layoutHint, 0.0 );
327  }
328  else
329  {
330  spacing = d_data->spacing;
331 
332  if ( numSamples > 1 )
333  {
334  sampleWidthS = qAbs( br.width() / ( numSamples - 1 ) );
335  }
336  }
337 
338  double ds, w;
339  if ( orientation() == Qt::Vertical )
340  {
341  ds = qAbs( xMap.sDist() );
342  w = canvasRect.width();
343  }
344  else
345  {
346  ds = qAbs( yMap.sDist() );
347  w = canvasRect.height();
348  }
349 
350  const double sampleWidthP = ( w - spacing * ( numSamples - 1 ) )
351  * sampleWidthS / ( ds + sampleWidthS );
352 
353  hint = 0.5 * sampleWidthP;
354  hint += qMax( d_data->margin, 0 );
355  }
356  }
357 
358  if ( orientation() == Qt::Vertical )
359  {
360  left = right = hint;
361  top = bottom = -1.0; // no hint
362  }
363  else
364  {
365  left = right = -1.0; // no hint
366  top = bottom = hint;
367  }
368 }
Qt::Orientation orientation() const
QwtPlotAbstractBarChart(const QwtText &title)
static double qwtTransformWidth(const QwtScaleMap &map, double value, double width)
double sDist() const
virtual ~QwtPlotAbstractBarChart()
Destructor.
virtual void getCanvasMarginHint(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, double &left, double &top, double &right, double &bottom) const
Calculate a hint for the canvas margin.
Abstract base class for bar chart items.
QwtPlotAbstractBarChart::LayoutPolicy layoutPolicy
void setMargin(int)
Set the margin.
void setSpacing(int)
Set the spacing.
LayoutPolicy
Mode how to calculate the bar width.
The item is represented on the legend.
A class representing a text.
Definition: qwt_text.h:51
void setZ(double z)
Set the z value.
A scale map.
Definition: qwt_scale_map.h:30
virtual void itemChanged()
TFSIMD_FORCE_INLINE const tfScalar & w() const
virtual size_t dataSize() const =0
void setBaseline(double)
Set the baseline.
double sampleWidth(const QwtScaleMap &map, double canvasSize, double dataSize, double value) const
Base class for plot items representing a series of samples.
void setItemAttribute(ItemAttribute, bool on=true)
double transform(double s) const
virtual QRectF dataRect() const =0
const QwtText & title() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17