qscatterseries.cpp
88 lines
| 2.4 KiB
| text/x-c
|
CppLexer
/ src / qscatterseries.cpp
|
r42 | #include "qscatterseries.h" | ||
#include "qscatterseries_p.h" | ||||
#include "qchart.h" | ||||
#include <QPainter> | ||||
#include <QGraphicsScene> | ||||
|
r48 | #include <QDebug> | ||
|
r42 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
//#define QSeriesData QList<qreal> | ||||
QScatterSeriesPrivate::QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent) : | ||||
QGraphicsItem(parent), | ||||
m_x(x), | ||||
|
r54 | m_y(y), | ||
m_scalex(100), // TODO: let the use define the scale (or autoscaled) | ||||
m_scaley(100) | ||||
|
r42 | { | ||
|
r54 | resize(parent->boundingRect()); | ||
|
r42 | } | ||
|
r54 | void QScatterSeriesPrivate::resize(QRectF rect) | ||
|
r42 | { | ||
|
r48 | m_scenex.clear(); | ||
m_sceney.clear(); | ||||
foreach(qreal x, m_x) | ||||
|
r54 | m_scenex.append(rect.left() + x * (rect.width() / m_scalex)); | ||
|
r48 | |||
foreach(qreal y, m_y) | ||||
|
r54 | m_sceney.append(rect.bottom() - y * (rect.height() / m_scaley)); | ||
|
r42 | } | ||
|
r54 | // TODO: | ||
//void QScatterSeriesPrivate::setAxisScale(qreal xscale, qreal yscale) | ||||
|
r42 | QRectF QScatterSeriesPrivate::boundingRect() const | ||
{ | ||||
|
r48 | return QRectF(0, 0, 55, 100); | ||
|
r42 | } | ||
void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||||
{ | ||||
QPen pen = painter->pen(); | ||||
QBrush brush = pen.brush(); | ||||
// TODO: The opacity should be user definable... | ||||
|
r54 | brush.setColor(QColor(255, 82, 0, 100)); | ||
|
r42 | pen.setBrush(brush); | ||
pen.setWidth(4); | ||||
painter->setPen(pen); | ||||
|
r48 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize | ||
// event right after construction or maybe given a size during initialization | ||||
for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | ||||
if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | ||||
//painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); | ||||
painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | ||||
|
r42 | } | ||
} | ||||
QScatterSeries::QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent) : | ||||
QChartSeries(parent), | ||||
d(new QScatterSeriesPrivate(x, y, qobject_cast<QGraphicsItem *> (parent))) | ||||
{ | ||||
|
r48 | } | ||
|
r54 | void QScatterSeries::chartSizeChanged(QRectF rect) | ||
|
r48 | { | ||
// Recalculate scatter data point locations on the scene | ||||
// d->transform().reset(); | ||||
// d->transform().translate(); | ||||
|
r54 | d->resize(rect); | ||
|
r42 | } | ||
|
r54 | // TODO: | ||
//void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) | ||||
//{ | ||||
// d->rescale(xscale, yscale); | ||||
//} | ||||
|
r42 | QScatterSeries::~QScatterSeries() | ||
{ | ||||
delete d; | ||||
} | ||||
#include "moc_qscatterseries.cpp" | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||