qscatterseries.cpp
140 lines
| 4.0 KiB
| text/x-c
|
CppLexer
/ src / qscatterseries.cpp
Tero Ahola
|
r42 | #include "qscatterseries.h" | ||
#include "qscatterseries_p.h" | ||||
#include "qchart.h" | ||||
#include <QPainter> | ||||
#include <QGraphicsScene> | ||||
Tero Ahola
|
r48 | #include <QDebug> | ||
Tero Ahola
|
r42 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
//#define QSeriesData QList<qreal> | ||||
Tero Ahola
|
r61 | QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) : | ||
Tero Ahola
|
r104 | ChartItem(parent), | ||
Tero Ahola
|
r121 | m_boundingRect(), | ||
Tero Ahola
|
r108 | m_markerColor(QColor()), | ||
Tero Ahola
|
r121 | m_visibleChartArea() | ||
Tero Ahola
|
r42 | { | ||
Tero Ahola
|
r111 | if (parent) | ||
m_boundingRect = parent->boundingRect(); | ||||
Tero Ahola
|
r42 | } | ||
Tero Ahola
|
r111 | void QScatterSeriesPrivate::changeGeometry() | ||
Tero Ahola
|
r42 | { | ||
Tero Ahola
|
r111 | if (m_boundingRect.isValid()) { | ||
prepareGeometryChange(); | ||||
qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); | ||||
qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); | ||||
m_scenex.clear(); | ||||
m_sceney.clear(); | ||||
// Convert relative coordinates to absolute pixel coordinates that can be used for drawing | ||||
foreach(qreal x, m_x) | ||||
m_scenex.append(m_boundingRect.left() + x * scalex - m_visibleChartArea.m_minX * scalex); | ||||
foreach(qreal y, m_y) | ||||
m_sceney.append(m_boundingRect.bottom() - y * scaley + m_visibleChartArea.m_minY * scaley); | ||||
} | ||||
Tero Ahola
|
r42 | } | ||
Michal Klocek
|
r115 | void QScatterSeriesPrivate::setSize(const QSizeF &size) | ||
Tero Ahola
|
r104 | { | ||
Tero Ahola
|
r111 | // m_boundingRect = QRectF(pos().x(), pos().y(), size.width(), size.height()); | ||
m_boundingRect = QRectF(0, 0, size.width(), size.height()); | ||||
changeGeometry(); | ||||
Tero Ahola
|
r104 | } | ||
Tero Ahola
|
r108 | void QScatterSeriesPrivate::themeChanged(ChartTheme *theme) | ||
Tero Ahola
|
r104 | { | ||
Michal Klocek
|
r143 | //m_theme = theme->themeForSeries(); | ||
Tero Ahola
|
r104 | } | ||
Michal Klocek
|
r149 | void QScatterSeriesPrivate::setPlotDomain(const Domain& plotDomain) | ||
Tero Ahola
|
r104 | { | ||
Michal Klocek
|
r149 | //m_visibleChartArea = plotDomain; | ||
Tero Ahola
|
r111 | changeGeometry(); | ||
Tero Ahola
|
r104 | } | ||
Tero Ahola
|
r54 | |||
Tero Ahola
|
r42 | QRectF QScatterSeriesPrivate::boundingRect() const | ||
{ | ||||
Tero Ahola
|
r111 | return m_boundingRect; | ||
Tero Ahola
|
r42 | } | ||
Tero Ahola
|
r110 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) | ||
Tero Ahola
|
r42 | { | ||
Tero Ahola
|
r103 | // TODO: The opacity should be user definable? | ||
Tero Ahola
|
r64 | //brush.setColor(QColor(255, 82, 0, 100)); | ||
Tero Ahola
|
r103 | if (m_markerColor.isValid()) { | ||
QPen pen = painter->pen(); | ||||
QBrush brush = pen.brush(); | ||||
brush.setColor(m_markerColor); | ||||
pen.setBrush(brush); | ||||
pen.setWidth(4); | ||||
painter->setPen(pen); | ||||
} | ||||
else | ||||
Michal Klocek
|
r143 | //painter->setPen(m_theme.markerPen); | ||
Tero Ahola
|
r103 | // brush.setColor(m_theme..lineColor); | ||
Tero Ahola
|
r42 | |||
Tero Ahola
|
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)); | ||||
Tero Ahola
|
r42 | } | ||
} | ||||
Tero Ahola
|
r61 | QScatterSeries::QScatterSeries(QObject *parent) : | ||
Tero Ahola
|
r42 | QChartSeries(parent), | ||
Tero Ahola
|
r61 | d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent))) | ||
Tero Ahola
|
r42 | { | ||
Tero Ahola
|
r48 | } | ||
Tero Ahola
|
r111 | bool QScatterSeries::setData(QList<qreal> xlist, QList<qreal> ylist) | ||
Tero Ahola
|
r61 | { | ||
// TODO: validate data | ||||
Tero Ahola
|
r111 | d->m_x = xlist; | ||
d->m_y = ylist; | ||||
// TODO: the following updates the visible chart area setting of the series, we would instead | ||||
// need to update the _chart's_ visible area... this would require a callback or | ||||
// similar to the parenting QChart object... | ||||
foreach (qreal x, d->m_x) { | ||||
d->m_visibleChartArea.m_minX = qMin(d->m_visibleChartArea.m_minX, x); | ||||
d->m_visibleChartArea.m_maxX = qMax(d->m_visibleChartArea.m_maxX, x); | ||||
} | ||||
foreach (qreal y, d->m_y) { | ||||
d->m_visibleChartArea.m_minY = qMin(d->m_visibleChartArea.m_minY, y); | ||||
d->m_visibleChartArea.m_maxY = qMax(d->m_visibleChartArea.m_maxY, y); | ||||
} | ||||
d->changeGeometry(); | ||||
Tero Ahola
|
r61 | return true; | ||
} | ||||
Tero Ahola
|
r64 | void QScatterSeries::setMarkerColor(QColor color) | ||
{ | ||||
d->m_markerColor = color; | ||||
} | ||||
Tero Ahola
|
r75 | QColor QScatterSeries::markerColor() | ||
{ | ||||
return d->m_markerColor; | ||||
} | ||||
Tero Ahola
|
r54 | // TODO: | ||
//void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) | ||||
//{ | ||||
// d->rescale(xscale, yscale); | ||||
//} | ||||
Tero Ahola
|
r42 | QScatterSeries::~QScatterSeries() | ||
{ | ||||
delete d; | ||||
} | ||||
#include "moc_qscatterseries.cpp" | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||