18 #include <qwt_painter.h>
20 #include <qwt_scale_map.h>
24 class QmitkHistogram::HistogramData
27 QwtIntervalSeriesData
data;
47 void QmitkHistogram::init()
49 m_Data =
new HistogramData();
50 m_Data->reference = 0.0;
52 setItemAttribute(QwtPlotItem::AutoScale,
true);
53 setItemAttribute(QwtPlotItem::Legend,
true);
60 if (m_Data->reference != reference)
62 m_Data->reference = reference;
69 return m_Data->reference;
74 m_Data->data.setSamples(data.samples());
85 if (m_Data->color != color)
87 m_Data->color =
color;
99 QRectF rect = m_Data->data.boundingRect();
103 if (rect.bottom() < m_Data->reference)
104 rect.setBottom(m_Data->reference);
105 else if (rect.top() > m_Data->reference)
106 rect.setTop(m_Data->reference);
111 void QmitkHistogram::draw(QPainter *painter,
const QwtScaleMap &xMap,
const QwtScaleMap &yMap,
const QRectF &)
const
113 const QwtIntervalSeriesData &iData = m_Data->data;
115 painter->setPen(QPen(m_Data->color));
117 const int y0 = yMap.transform(
baseline());
119 for (
int i = 0; i < (int)iData.size(); i++)
121 const int y2 = yMap.transform(iData.sample(i).value);
125 int x1 = xMap.transform(iData.sample(i).interval.minValue());
126 int x2 = xMap.transform(iData.sample(i).interval.maxValue());
130 if (i < (
int)iData.size() - 2)
132 const int xx1 = xMap.transform(iData.sample(i + 1).interval.minValue());
133 const int xx2 = xMap.transform(iData.sample(i + 1).interval.maxValue());
135 if (x2 == qMin(xx1, xx2))
137 const int yy2 = yMap.transform(iData.sample(i + 1).value);
138 if (yy2 != y0 && ((yy2 < y0 && y2 < y0) || (yy2 > y0 && y2 > y0)))
145 drawBar(painter, Qt::Vertical, QRect(x1, y0, x2 - x1, y2 - y0));
153 const QColor
color(painter->pen().color());
154 const QRect r = rect.normalized();
155 const int factor = 125;
156 const QColor light(
color.light(factor));
157 const QColor dark(
color.dark(factor));
159 painter->setBrush(
color);
160 painter->setPen(Qt::NoPen);
161 QwtPainter::drawRect(painter, r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2);
162 painter->setBrush(Qt::NoBrush);
164 painter->setPen(QPen(light, 2));
166 QwtPainter::drawLine(painter, r.left() + 1, r.top() + 2, r.right() + 1, r.top() + 2);
168 painter->setPen(QPen(dark, 2));
170 QwtPainter::drawLine(painter, r.left() + 1, r.bottom(), r.right() + 1, r.bottom());
172 painter->setPen(QPen(light, 1));
174 QwtPainter::drawLine(painter, r.left(), r.top() + 1, r.left(), r.bottom());
175 QwtPainter::drawLine(painter, r.left() + 1, r.top() + 2, r.left() + 1, r.bottom() - 1);
177 painter->setPen(QPen(dark, 1));
179 QwtPainter::drawLine(painter, r.right() + 1, r.top() + 1, r.right() + 1, r.bottom());
180 QwtPainter::drawLine(painter, r.right(), r.top() + 2, r.right(), r.bottom() - 1);
virtual void drawBar(QPainter *, Qt::Orientation o, const QRect &) const
void setColor(const QColor &)
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &) const override
virtual ~QmitkHistogram()
QmitkHistogram(const QString &title=QString::null)
virtual QRectF boundingRect() const override
void setData(const QwtIntervalSeriesData &data)
const QwtIntervalSeriesData & data() const
void setBaseline(double reference)