1 #include "HistogramItem.h"
6 #include <QScopedPointer>
10 #include <qwt_painter.h>
11 #include <qwt_scale_map.h>
12 #include <qwt_series_data.h>
24 QScopedPointer<QwtIntervalSeriesData> data;
66 d_data->data.reset(
new QwtIntervalSeriesData());
67 d_data->reference = 0.0;
68 d_data->attributes = HistogramItem::Auto;
70 setItemAttribute(QwtPlotItem::AutoScale,
true);
71 setItemAttribute(QwtPlotItem::Legend,
true);
84 if(d_data->reference != reference) {
85 d_data->reference = reference;
98 return d_data->reference;
109 d_data->data.reset(
new QwtIntervalSeriesData(
data));
121 return *d_data->data;
132 if(d_data->color !=
color) {
133 d_data->color =
color;
146 return d_data->color;
157 QRectF rect = d_data->data->boundingRect();
161 if(d_data->attributes & Xfy) {
162 rect = QRectF(rect.y(), rect.x(),
163 rect.height(), rect.width());
165 if(rect.left() > d_data->reference)
166 rect.setLeft(d_data->reference);
167 else if(rect.right() < d_data->reference)
168 rect.setRight(d_data->reference);
171 if(rect.bottom() < d_data->reference)
172 rect.setBottom(d_data->reference);
173 else if(rect.top() > d_data->reference)
174 rect.setTop(d_data->reference);
188 return QwtPlotItem::Rtti_PlotHistogram;
200 if(
bool(d_data->attributes & attribute) == on)
204 d_data->attributes |= attribute;
206 d_data->attributes &= ~attribute;
221 return d_data->attributes & attribute;
234 const QwtScaleMap &yMap,
const QRectF &)
const {
235 const QwtIntervalSeriesData &
data = *d_data->data;
237 painter->setPen(QPen(d_data->color));
239 const int x0 = xMap.transform(
baseline());
240 const int y0 = yMap.transform(
baseline());
242 for(
int i = 0; i < (int)
data.size(); i++) {
243 if(d_data->attributes & HistogramItem::Xfy) {
244 const int x2 = xMap.transform(
data.sample(i).value);
248 int y1 = yMap.transform(
data.sample(i).interval.minValue());
249 int y2 = yMap.transform(
data.sample(i).interval.maxValue());
253 if(i < (
int)
data.size() - 2) {
254 const int yy1 = yMap.transform(
data.sample(i + 1).interval.minValue());
255 const int yy2 = yMap.transform(
data.sample(i + 1).interval.maxValue());
257 if(y2 == qMin(yy1, yy2)) {
258 const int xx2 = xMap.transform(
259 data.sample(i + 1).interval.minValue());
260 if(xx2 != x0 && ((xx2 < x0 && x2 < x0) ||
261 (xx2 > x0 && x2 > x0))) {
268 drawBar(painter, Qt::Horizontal,
269 QRect(x0, y1, x2 - x0, y2 - y1));
272 const int y2 = yMap.transform(
data.sample(i).value);
276 int x1 = xMap.transform(
data.sample(i).interval.minValue());
277 int x2 = xMap.transform(
data.sample(i).interval.maxValue());
281 if(i < (
int)
data.size() - 2) {
282 const int xx1 = xMap.transform(
data.sample(i + 1).interval.minValue());
283 const int xx2 = xMap.transform(
data.sample(i + 1).interval.maxValue());
285 if(x2 == qMin(xx1, xx2)) {
286 const int yy2 = yMap.transform(
data.sample(i + 1).value);
287 if(yy2 != y0 && ((yy2 < y0 && y2 < y0) ||
288 (yy2 > y0 && y2 > y0))) {
295 QRect(x1, y0, x2 - x1, y2 - y0));
309 Qt::Orientation,
const QRect &rect)
const {
312 const QColor
color(painter->pen().color());
313 const QRect r = rect.normalized();
315 const int factor = 125;
316 const QColor light(
color.light(factor));
317 const QColor dark(
color.dark(factor));
319 painter->setBrush(
color);
320 painter->setPen(Qt::NoPen);
321 QwtPainter::drawRect(painter, r.x() + 1, r.y() + 1,
322 r.width() - 2, r.height() - 2);
323 painter->setBrush(Qt::NoBrush);
325 painter->setPen(QPen(light, 2));
326 QwtPainter::drawLine(painter,
327 r.left() + 1, r.top() + 2, r.right() + 1, r.top() + 2);
329 painter->setPen(QPen(dark, 2));
330 QwtPainter::drawLine(painter,
331 r.left() + 1, r.bottom(), r.right() + 1, r.bottom());
333 painter->setPen(QPen(light, 1));
335 QwtPainter::drawLine(painter,
336 r.left(), r.top() + 1, r.left(), r.bottom());
337 QwtPainter::drawLine(painter,
338 r.left() + 1, r.top() + 2, r.left() + 1, r.bottom() - 1);
340 painter->setPen(QPen(dark, 1));
342 QwtPainter::drawLine(painter,
343 r.right() + 1, r.top() + 1, r.right() + 1, r.bottom());
344 QwtPainter::drawLine(painter,
345 r.right(), r.top() + 2, r.right(), r.bottom() - 1);
370 for(
int i = 0;
getViewPort() && i < points.size(); i++) {