10#include "qwt_plot_multi_barchart.h"
11#include "qwt_scale_map.h"
12#include "qwt_column_symbol.h"
14#include "qwt_graphic.h"
15#include "qwt_legend_data.h"
20inline static bool qwtIsIncreasing(
25 for (
int i = 0; i < values.size(); i++ )
27 const double y = values[ i ];
35class QwtPlotMultiBarChart::PrivateData
75void QwtPlotMultiBarChart::init()
77 m_data =
new PrivateData;
105 s.reserve( samples.size() );
107 for (
int i = 0; i < samples.size(); i++ )
140 m_data->barTitles = titles;
150 return m_data->barTitles;
166 if ( valueIndex < 0 )
170 m_data->symbolMap.find(valueIndex);
171 if ( it == m_data->symbolMap.end() )
175 m_data->symbolMap.insert( valueIndex,
symbol );
183 if (
symbol != it.value() )
189 m_data->symbolMap.remove( valueIndex );
213 m_data->symbolMap.constFind( valueIndex );
215 return ( it == m_data->symbolMap.constEnd() ) ? NULL : it.value();
229 m_data->symbolMap.constFind( valueIndex );
231 return ( it == m_data->symbolMap.constEnd() ) ? NULL : it.value();
239 qDeleteAll( m_data->symbolMap );
240 m_data->symbolMap.clear();
264 int sampleIndex,
int valueIndex )
const
266 Q_UNUSED( sampleIndex );
267 Q_UNUSED( valueIndex );
280 if (
style != m_data->style )
282 m_data->style =
style;
295 return m_data->style;
304 const size_t numSamples =
dataSize();
306 if ( numSamples == 0 )
317 if ( rect.height() >= 0 )
319 if ( rect.bottom() < baseLine )
320 rect.setBottom( baseLine );
321 if ( rect.top() > baseLine )
322 rect.setTop( baseLine );
327 double xMin, xMax, yMin, yMax;
330 yMin = yMax = baseLine;
334 for (
size_t i = 0; i < numSamples; i++ )
349 yMin = qwtMinF( yMin, y );
350 yMax = qwtMaxF( yMax, y );
352 rect.setRect( xMin, yMin, xMax - xMin, yMax - yMin );
356 rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() );
376 const QRectF& canvasRect,
int from,
int to )
const
389 const QwtInterval interval( br.left(), br.right() );
393 for (
int i = from; i <= to; i++ )
396 canvasRect, interval, i,
sample( i ) );
417 const QRectF& canvasRect,
const QwtInterval& boundingInterval,
436 if ( m_data->style ==
Stacked )
439 canvasRect, index, sampleW,
sample );
444 canvasRect, index, sampleW,
sample );
463 const QRectF& canvasRect,
int index,
double sampleWidth,
466 Q_UNUSED( canvasRect );
479 for (
int i = 0; i < numBars; i++ )
481 const double x1 = x0 + i * barWidth;
482 const double x2 = x1 + barWidth;
496 drawBar( painter, index, i, barRect );
506 for (
int i = 0; i < numBars; i++ )
508 double y1 = y0 + i * barHeight;
509 double y2 = y1 + barHeight;
523 drawBar( painter, index, i, barRect );
543 const QRectF& canvasRect,
int index,
546 Q_UNUSED( canvasRect );
559 const bool increasing = qwtIsIncreasing( yMap,
sample.
set );
569 for (
int i = 0; i < numBars; i++ )
576 const double y2 = yMap.
transform( sum + si );
578 if ( ( y2 > y1 ) != increasing )
587 drawBar( painter, index, i, bar );
602 const bool increasing = qwtIsIncreasing( xMap,
sample.
set );
611 for (
int i = 0; i <
sample.
set.size(); i++ )
618 const double x2 = xMap.
transform( sum + si );
620 if ( ( x2 > x1 ) != increasing )
629 drawBar( painter, index, i, bar );
653 int sampleIndex,
int valueIndex,
const QwtColumnRect& rect )
const
656 if ( sampleIndex >= 0 )
661 sym =
symbol( valueIndex );
665 sym->
draw( painter, rect );
673 columnSymbol.
draw( painter, rect );
690 list.reserve( m_data->barTitles.size() );
692 for (
int i = 0; i < m_data->barTitles.size(); i++ )
696 data.setValue( QwtLegendData::TitleRole,
697 QVariant::fromValue( m_data->barTitles[i] ) );
701 data.setValue( QwtLegendData::IconRole,
721 const QSizeF& size )
const
731 QPainter painter( &icon );
732 painter.setRenderHint( QPainter::Antialiasing,
735 drawBar( &painter, -1, index, column );
Template class for data, that is organized as QVector.
Directed rectangle representing bounding rectangle and orientation of a column.
QwtInterval vInterval
Interval for the vertical coordinates.
QwtInterval hInterval
Interval for the horizontal coordinates.
@ LeftToRight
From left to right.
@ TopToBottom
From top to bottom.
@ BottomToTop
From bottom to top.
@ RightToLeft
From right to left.
Direction direction
Direction.
A drawing primitive for columns.
@ Plain
A plain frame style.
virtual void draw(QPainter *, const QwtColumnRect &) const
void setFrameStyle(FrameStyle)
void setLineWidth(int width)
A paint device for scalable graphics.
void setRenderHint(RenderHint, bool on=true)
void setDefaultSize(const QSizeF &)
Set a default size.
A class representing an interval.
QwtInterval normalized() const
Normalize the limits of the interval.
double width() const
Return the width of an interval.
@ ExcludeMaximum
Max value is not included in the interval.
@ ExcludeMinimum
Min value is not included in the interval.
@ IncludeBorders
Min/Max values are inside the interval.
void setBorderFlags(BorderFlags)
Attributes of an entry on a legend.
Abstract base class for bar chart items.
double sampleWidth(const QwtScaleMap &map, double canvasSize, double boundingSize, double value) const
virtual void legendChanged()
@ Rtti_PlotMultiBarChart
For QwtPlotMultiBarChart.
@ RenderAntialiased
Enable antialiasing.
bool testRenderHint(RenderHint) const
virtual void itemChanged()
QSize legendIconSize() const
QwtPlotMultiBarChart displays a series of a samples that consist each of a set of values.
QList< QwtText > barTitles() const
virtual QwtGraphic legendIcon(int index, const QSizeF &) const override
virtual ~QwtPlotMultiBarChart()
Destructor.
virtual QwtColumnSymbol * specialSymbol(int sampleIndex, int valueIndex) const
Create a symbol for special values.
QwtPlotMultiBarChart(const QString &title=QString())
void setStyle(ChartStyle style)
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const override
virtual void drawSample(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, const QwtInterval &boundingInterval, int index, const QwtSetSample &) const
void drawStackedBars(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int index, double sampleWidth, const QwtSetSample &) const
void setSymbol(int valueIndex, QwtColumnSymbol *)
Add a symbol to the symbol map.
virtual QList< QwtLegendData > legendData() const override
void drawGroupedBars(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int index, double sampleWidth, const QwtSetSample &) const
virtual int rtti() const override
void setBarTitles(const QList< QwtText > &)
Set the titles for the bars.
virtual QRectF boundingRect() const override
@ Grouped
The bars of a set are displayed side by side.
const QwtColumnSymbol * symbol(int valueIndex) const
virtual void drawBar(QPainter *, int sampleIndex, int valueIndex, const QwtColumnRect &) const
void setSamples(const QVector< QwtSetSample > &)
Qt::Orientation orientation() const
virtual QRectF boundingRect() const override
double transform(double s) const
virtual QRectF boundingRect() const
virtual T sample(size_t i) const =0
QwtSetSample sample(int index) const
virtual size_t dataSize() const override
QwtSeriesData< QwtSetSample > * data()
void setData(QwtSeriesData< QwtSetSample > *series)
A sample of the types (x1...xn, y) or (x, y1..yn)
QVector< double > set
Vector of values associated to value.
A class representing a text.