##// END OF EJS Templates
Add doc for QSeries title stuff
Add doc for QSeries title stuff

File last commit:

r397:e3d058df67ba
r414:4e7addfef3f4
Show More
scatterpresenter.cpp
150 lines | 4.9 KiB | text/x-c | CppLexer
Tero Ahola
Moved scatter impl into a subfolder
r194 #include "scatterpresenter_p.h"
Tero Ahola
Integrated scatter again. Missing functionality....
r158 #include "qscatterseries.h"
Tero Ahola
Fixed drawing issues in Scatter
r375 #include "chartpresenter_p.h"
Tero Ahola
Integrated scatter again. Missing functionality....
r158 #include <QPen>
#include <QPainter>
#include <QGraphicsScene>
Tero Ahola
Added clicked signal to scatter...
r316 #include <QGraphicsSceneMouseEvent>
Tero Ahola
Drop shadow in scatter
r346 #include <QGraphicsDropShadowEffect>
Tero Ahola
Integrated scatter again. Missing functionality....
r158 #include <QDebug>
Tero Ahola
Refactored chartwidgettest test data impl
r278 #include <QTime>
Tero Ahola
Integrated scatter again. Missing functionality....
r158
QTCOMMERCIALCHART_BEGIN_NAMESPACE
ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) :
ChartItem(parent),
m_series(series),
m_boundingRect(),
m_visibleChartArea()
{
if (parent)
m_boundingRect = parent->boundingRect();
if (series) {
connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged()));
}
Tero Ahola
Drop shadow in scatter
r346
Tero Ahola
Fixed drawing issues in Scatter
r375 setZValue(ChartPresenter::ScatterSeriesZValue);
// TODO: how to draw a drop shadow?
// QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
// dropShadow->setOffset(2.0);
// dropShadow->setBlurRadius(2.0);
// setGraphicsEffect(dropShadow);
Tero Ahola
Integrated scatter again. Missing functionality....
r158 }
void ScatterPresenter::handleDomainChanged(const Domain& domain)
{
m_visibleChartArea = domain;
changeGeometry();
}
void ScatterPresenter::handleGeometryChanged(const QRectF& rect)
{
Tero Ahola
Clicked, remove and clear to QScatterSeries
r394 m_boundingRect = rect.translated(-rect.topLeft());
Tero Ahola
Integrated scatter again. Missing functionality....
r158 changeGeometry();
Tero Ahola
Clicked, remove and clear to QScatterSeries
r394 setPos(rect.topLeft());
Tero Ahola
Integrated scatter again. Missing functionality....
r158 }
void ScatterPresenter::handleModelChanged()
{
// TODO: more fine grained modelChanged signaling
changeGeometry();
}
void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
Tero Ahola
Refactored chartwidgettest test data impl
r278 painter->save();
painter->setClipRect(m_boundingRect);
Tero Ahola
Fixed drawing issues in Scatter
r375 // TODO: how to draw a drop shadow?
// Now using a custom implementation for drop shadow instead of QGraphicsDropShadowEffect.
// It seems QGraphicsDropShadowEffect is quite heavy, at least on windows without open gl.
QPen dropShadowPen(QColor(0, 0, 0, 70));
dropShadowPen.setWidth(3);
painter->setPen(dropShadowPen);
painter->setBrush(dropShadowPen.color());
// painter->setRenderHint(QPainter::Antialiasing);
painter->drawPath(m_path.translated(2, 2));
Tero Ahola
Refactored chartwidgettest test data impl
r278 // Paint the shape
Tero Ahola
Added clicked signal to scatter...
r316 // The custom settings in series override those defined by the theme
Tero Ahola
Refactored chartwidgettest test data impl
r278 QPen pen = m_markerPen;
Tero Ahola
Fixing review findings in QScatterSeries
r358 if (m_series->pen().color().isValid())
pen = m_series->pen();
Tero Ahola
Fixed drawing issues in Scatter
r375 painter->setPen(pen);
Tero Ahola
Fixing review findings in QScatterSeries
r358 if (m_series->brush().color().isValid())
painter->setBrush(m_series->brush());
Tero Ahola
Documenting QScatterSeries
r261 else
Tero Ahola
Scatter series marker visuals
r195 painter->setBrush(m_markerBrush);
Tero Ahola
Fixed drawing issues in Scatter
r375
// If either pen or brush is opaque, we need to draw the polygons one-by-one
if (painter->pen().color().alpha() < 255 || painter->brush().color().alpha() < 255) {
foreach (QPolygonF pol, m_path.toSubpathPolygons())
painter->drawPolygon(pol);
} else {
painter->drawPath(m_path);
}
Tero Ahola
Added clicked signal to scatter...
r316
Tero Ahola
Refactored chartwidgettest test data impl
r278 painter->restore();
Tero Ahola
Integrated scatter again. Missing functionality....
r158 }
Tero Ahola
Scatter series documentation; now uses snippets
r300 void ScatterPresenter::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Tero Ahola
Clicked, remove and clear to QScatterSeries
r394 // Empty implementation to grab mouse release events for this item
Q_UNUSED(event)
}
Tero Ahola
Added clicked signal to scatter...
r316
Tero Ahola
Clicked, remove and clear to QScatterSeries
r394 void ScatterPresenter::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QPointF clickedPoint(
m_visibleChartArea.m_minX + (event->lastPos().x() / m_boundingRect.width()) * m_visibleChartArea.spanX(),
m_visibleChartArea.m_maxY - (event->lastPos().y() / m_boundingRect.height()) * m_visibleChartArea.spanY());
emit clicked(clickedPoint);
Tero Ahola
Scatter series documentation; now uses snippets
r300 }
Tero Ahola
Integrated scatter again. Missing functionality....
r158 void ScatterPresenter::changeGeometry()
{
if (m_boundingRect.isValid()) {
prepareGeometryChange();
qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX();
qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY();
Tero Ahola
Fixing review findings in QScatterSeries
r358 int shape = m_series->shape();
Tero Ahola
Added clicked signal to scatter...
r316 m_path = QPainterPath();
Tero Ahola
Fixed drawing issues in Scatter
r375 m_path.setFillRule(Qt::WindingFill);
Tero Ahola
Added size customization to QScatterSeries
r397 const qreal size = m_series->size();
Tero Ahola
Added clicked signal to scatter...
r316
Tero Ahola
Integrated scatter again. Missing functionality....
r158 foreach (QPointF point, m_series->data()) {
Tero Ahola
Added clicked signal to scatter...
r316 // Convert relative coordinates to absolute pixel coordinates that can be used for drawing
Tero Ahola
Clicked, remove and clear to QScatterSeries
r394 qreal x = point.x() * scalex - m_visibleChartArea.m_minX * scalex - size / 2;
qreal y = m_boundingRect.height() - point.y() * scaley + m_visibleChartArea.m_minY * scaley - size / 2;
Tero Ahola
Added clicked signal to scatter...
r316
Tero Ahola
Clicked, remove and clear to QScatterSeries
r394 if (x < scene()->width() && y < scene()->height()) {
Tero Ahola
Added clicked signal to scatter...
r316 switch (shape) {
case QScatterSeries::MarkerShapeDefault:
// Fallthrough, defaults to circle
case QScatterSeries::MarkerShapeCircle:
Tero Ahola
Clicked, remove and clear to QScatterSeries
r394 m_path.addEllipse(x, y, size, size);
Tero Ahola
Added clicked signal to scatter...
r316 break;
case QScatterSeries::MarkerShapeRectangle:
Tero Ahola
Clicked, remove and clear to QScatterSeries
r394 m_path.addRect(x, y, size, size);
Tero Ahola
Added clicked signal to scatter...
r316 break;
case QScatterSeries::MarkerShapeTiltedRectangle: {
Tero Ahola
Fixing review findings in QScatterSeries
r358 // TODO: tilt the rectangle
Tero Ahola
Clicked, remove and clear to QScatterSeries
r394 m_path.addRect(x, y, size, size);
Tero Ahola
Added clicked signal to scatter...
r316 break;
}
default:
// TODO: implement the rest of the shapes
Q_ASSERT(false);
break;
}
}
Tero Ahola
Integrated scatter again. Missing functionality....
r158 }
}
}
Tero Ahola
Moved scatter impl into a subfolder
r194 #include "moc_scatterpresenter_p.cpp"
Tero Ahola
Integrated scatter again. Missing functionality....
r158
QTCOMMERCIALCHART_END_NAMESPACE