Used to create a histogram that can be shown in a Qwt Plot. See QmitkHistogramWidget for an example of its usage. More...
#include <QmitkHistogram.h>
Classes | |
class | HistogramData |
Public Member Functions | |
QmitkHistogram (const QString &title=QString::null) | |
QmitkHistogram (const QwtText &title) | |
virtual | ~QmitkHistogram () |
void | setData (const QwtIntervalData &data) |
const QwtIntervalData & | data () const |
void | setColor (const QColor &) |
QColor | color () const |
virtual QwtDoubleRect | boundingRect () const |
virtual void | draw (QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const |
Draw the item. | |
void | setBaseline (double reference) |
double | baseline () const |
Protected Member Functions | |
virtual void | drawBar (QPainter *, Qt::Orientation o, const QRect &) const |
Used to create a histogram that can be shown in a Qwt Plot. See QmitkHistogramWidget for an example of its usage.
Definition at line 32 of file QmitkHistogram.h.
QmitkHistogram::QmitkHistogram | ( | const QString & | title = QString::null ) |
[explicit] |
Definition at line 39 of file QmitkHistogram.cpp.
: QwtPlotItem(QwtText(title)) { init(); }
QmitkHistogram::QmitkHistogram | ( | const QwtText & | title ) | [explicit] |
Definition at line 33 of file QmitkHistogram.cpp.
: QwtPlotItem(title) { init(); }
QmitkHistogram::~QmitkHistogram | ( | ) | [virtual] |
Definition at line 45 of file QmitkHistogram.cpp.
{
delete m_Data;
}
double QmitkHistogram::baseline | ( | ) | const |
Definition at line 70 of file QmitkHistogram.cpp.
References QmitkHistogram::HistogramData::reference.
Referenced by draw().
{ return m_Data->reference; }
QwtDoubleRect QmitkHistogram::boundingRect | ( | ) | const [virtual] |
Reimplemented from QwtPlotItem.
Definition at line 100 of file QmitkHistogram.cpp.
References QwtDoubleRect::bottom(), QwtIntervalData::boundingRect(), QmitkHistogram::HistogramData::data, QwtDoubleRect::isValid(), QmitkHistogram::HistogramData::reference, QwtDoubleRect::setBottom(), QwtDoubleRect::setTop(), and QwtDoubleRect::top().
QColor QmitkHistogram::color | ( | ) | const |
Definition at line 95 of file QmitkHistogram.cpp.
References QmitkHistogram::HistogramData::color.
Referenced by drawBar(), and setColor().
{ return m_Data->color; }
const QwtIntervalData & QmitkHistogram::data | ( | ) | const |
Definition at line 81 of file QmitkHistogram.cpp.
References QmitkHistogram::HistogramData::data.
Referenced by setData().
{ return m_Data->data; }
void QmitkHistogram::draw | ( | QPainter * | painter, |
const QwtScaleMap & | xMap, | ||
const QwtScaleMap & | yMap, | ||
const QRect & | canvasRect | ||
) | const [virtual] |
Draw the item.
painter | Painter |
xMap | Maps x-values into pixel coordinates. |
yMap | Maps y-values into pixel coordinates. |
canvasRect | Contents rect of the canvas in painter coordinates |
Implements QwtPlotItem.
Definition at line 114 of file QmitkHistogram.cpp.
References baseline(), QmitkHistogram::HistogramData::color, QmitkHistogram::HistogramData::data, drawBar(), int(), QwtIntervalData::interval(), QwtDoubleInterval::maxValue(), QwtDoubleInterval::minValue(), qwtMin, QwtIntervalData::size(), QwtScaleMap::transform(), and QwtIntervalData::value().
{ const QwtIntervalData &iData = m_Data->data; painter->setPen(QPen(m_Data->color)); //const int x0 = xMap.transform(baseline()); const int y0 = yMap.transform(baseline()); for ( int i = 0; i < (int)iData.size(); i++ ) { const int y2 = yMap.transform(iData.value(i)); if ( y2 == y0 ) continue; int x1 = xMap.transform(iData.interval(i).minValue()); int x2 = xMap.transform(iData.interval(i).maxValue()); if ( x1 > x2 ) qSwap(x1, x2); if ( i < (int)iData.size() - 2 ) { const int xx1 = xMap.transform(iData.interval(i+1).minValue()); const int xx2 = xMap.transform(iData.interval(i+1).maxValue()); if ( x2 == qwtMin(xx1, xx2) ) { const int yy2 = yMap.transform(iData.value(i+1)); if ( yy2 != y0 && ( (yy2 < y0 && y2 < y0) || (yy2 > y0 && y2 > y0) ) ) { // One pixel distance between neighbored bars x2--; } } } drawBar(painter, Qt::Vertical, QRect(x1, y0, x2 - x1, y2 - y0) ); } }
void QmitkHistogram::drawBar | ( | QPainter * | painter, |
Qt::Orientation | o, | ||
const QRect & | rect | ||
) | const [protected, virtual] |
Definition at line 156 of file QmitkHistogram.cpp.
References color(), QwtPainter::drawLine(), and QwtPainter::drawRect().
Referenced by draw().
{ painter->save(); const QColor color(painter->pen().color()); #if QT_VERSION >= 0x040000 const QRect r = rect.normalized(); #else const QRect r = rect.normalize(); #endif const int factor = 125; const QColor light(color.light(factor)); const QColor dark(color.dark(factor)); painter->setBrush(color); painter->setPen(Qt::NoPen); QwtPainter::drawRect(painter, r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2); painter->setBrush(Qt::NoBrush); painter->setPen(QPen(light, 2)); #if QT_VERSION >= 0x040000 QwtPainter::drawLine(painter, r.left() + 1, r.top() + 2, r.right() + 1, r.top() + 2); #else QwtPainter::drawLine(painter, r.left(), r.top() + 2, r.right() + 1, r.top() + 2); #endif painter->setPen(QPen(dark, 2)); #if QT_VERSION >= 0x040000 QwtPainter::drawLine(painter, r.left() + 1, r.bottom(), r.right() + 1, r.bottom()); #else QwtPainter::drawLine(painter, r.left(), r.bottom(), r.right() + 1, r.bottom()); #endif painter->setPen(QPen(light, 1)); #if QT_VERSION >= 0x040000 QwtPainter::drawLine(painter, r.left(), r.top() + 1, r.left(), r.bottom()); QwtPainter::drawLine(painter, r.left() + 1, r.top() + 2, r.left() + 1, r.bottom() - 1); #else QwtPainter::drawLine(painter, r.left(), r.top() + 1, r.left(), r.bottom() + 1); QwtPainter::drawLine(painter, r.left() + 1, r.top() + 2, r.left() + 1, r.bottom()); #endif painter->setPen(QPen(dark, 1)); #if QT_VERSION >= 0x040000 QwtPainter::drawLine(painter, r.right() + 1, r.top() + 1, r.right() + 1, r.bottom()); QwtPainter::drawLine(painter, r.right(), r.top() + 2, r.right(), r.bottom() - 1); #else QwtPainter::drawLine(painter, r.right() + 1, r.top() + 1, r.right() + 1, r.bottom() + 1); QwtPainter::drawLine(painter, r.right(), r.top() + 2, r.right(), r.bottom()); #endif painter->restore(); }
void QmitkHistogram::setBaseline | ( | double | reference ) |
Definition at line 61 of file QmitkHistogram.cpp.
References QwtPlotItem::itemChanged(), and QmitkHistogram::HistogramData::reference.
{ if ( m_Data->reference != reference ) { m_Data->reference = reference; itemChanged(); } }
void QmitkHistogram::setColor | ( | const QColor & | color ) |
Definition at line 86 of file QmitkHistogram.cpp.
References color(), QmitkHistogram::HistogramData::color, and QwtPlotItem::itemChanged().
Referenced by QmitkHistogramWidget::SetHistogram().
{ if ( m_Data->color != color ) { m_Data->color = color; itemChanged(); } }
void QmitkHistogram::setData | ( | const QwtIntervalData & | data ) |
Definition at line 75 of file QmitkHistogram.cpp.
References data(), QmitkHistogram::HistogramData::data, and QwtPlotItem::itemChanged().
Referenced by QmitkHistogramWidget::SetHistogram().
{ m_Data->data = data; itemChanged(); }