##// END OF EJS Templates
Refactor xychartitem -> xychart
Refactor xychartitem -> xychart

File last commit:

r1218:b8de085c4198
r1218:b8de085c4198
Show More
scatterchartitem.cpp
198 lines | 5.1 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
Michal Klocek
Refactor xychartitem -> xychart
r1218 **
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
Jani Honkonen
Add license headers
r794
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 #include "scatterchartitem_p.h"
#include "qscatterseries.h"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "qscatterseries_p.h"
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 #include "chartpresenter_p.h"
#include <QPainter>
#include <QGraphicsScene>
Michal Klocek
Improves build configuration...
r996 #include <QDebug>
Michal Klocek
Refactor xychartitem -> xychart
r1218 #include <QGraphicsSceneMouseEvent>
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactors chartitem...
r677 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) :
Michal Klocek
Refactor xychartitem -> xychart
r1218 XYChart(series,presenter),
QGraphicsItem(presenter ? presenter->rootItem() : 0),
m_series(series),
m_items(this),
m_shape(QScatterSeries::MarkerShapeRectangle),
m_size(15)
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated()));
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
setZValue(ChartPresenter::ScatterSeriesZValue);
setFlags(QGraphicsItem::ItemClipsChildrenToShape);
handleUpdated();
Michal Klocek
Adds missing scatter intercation implementation...
r541 m_items.setHandlesChildEvents(false);
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 // TODO: how to draw a drop shadow?
// QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
// dropShadow->setOffset(2.0);
// dropShadow->setBlurRadius(2.0);
// setGraphicsEffect(dropShadow);
}
QRectF ScatterChartItem::boundingRect() const
{
return m_rect;
}
void ScatterChartItem::createPoints(int count)
{
for (int i = 0; i < count; ++i) {
Michal Klocek
Release compilation fixes
r689 QGraphicsItem *item = 0;
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
switch (m_shape) {
Michal Klocek
Refactor xychartitem -> xychart
r1218 case QScatterSeries::MarkerShapeCircle: {
QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size);
const QRectF& rect = i->boundingRect();
i->setPos(-rect.width()/2,-rect.height()/2);
item = new Marker(i,this);
break;
}
case QScatterSeries::MarkerShapeRectangle: {
QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size);
i->setPos(-m_size/2,-m_size/2);
item = new Marker(i,this);
break;
}
default:
qWarning()<<"Unsupported marker type";
break;
Michal Klocek
Adds missing scatter intercation implementation...
r541
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
m_items.addToGroup(item);
}
}
void ScatterChartItem::deletePoints(int count)
{
QList<QGraphicsItem *> items = m_items.childItems();
for (int i = 0; i < count; ++i) {
delete(items.takeLast());
}
}
sauimone
minor code review issues. indent, spaces, brackets etc.
r743 void ScatterChartItem::markerSelected(Marker *marker)
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 {
Michal Klocek
Refactor xychartitem -> xychart
r1218 emit XYChart::clicked(marker->point());
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
Michal Klocek
Refactors animation handling for xyseries
r1217 void ScatterChartItem::updateGeometry()
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 {
Michal Klocek
Refactors animation handling for xyseries
r1217
const QVector<QPointF>& points = geometryPoints();
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 if(points.size()==0)
{
Marek Rosa
XYSeries model support refactored
r1085 deletePoints(m_items.childItems().count());
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 return;
}
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
Michal Klocek
Bugfixes for unnesery geometry changes
r869 int diff = m_items.childItems().size() - points.size();
Michal Klocek
Refactor scatter chart to fit the other classes...
r470
if(diff>0) {
deletePoints(diff);
}
else if(diff<0) {
createPoints(-diff);
}
if(diff!=0) handleUpdated();
QList<QGraphicsItem*> items = m_items.childItems();
Tero Ahola
Added area series to QML api
r847 for (int i = 0; i < points.size(); i++) {
Michal Klocek
Adds missing scatter intercation implementation...
r541 Marker* item = static_cast<Marker*>(items.at(i));
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 const QPointF& point = points.at(i);
Michal Klocek
Fix sctter series wrong points offset issue
r536 const QRectF& rect = item->boundingRect();
Michal Klocek
Fixes and improvments to series API...
r1057 item->setPoint(point);
Michal Klocek
Fix sctter series wrong points offset issue
r536 item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2);
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 if(!clipRect().contains(point)) {
item->setVisible(false);
}
else {
item->setVisible(true);
}
}
prepareGeometryChange();
m_rect = clipRect();
Michal Klocek
Refactor xychartitem -> xychart
r1218 setPos(origin());
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Tero Ahola
Squashed bunch of warnings
r611 Q_UNUSED(painter)
Q_UNUSED(option)
Q_UNUSED(widget)
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
void ScatterChartItem::setPen(const QPen& pen)
{
foreach(QGraphicsItem* item , m_items.childItems()) {
Michal Klocek
Refactor xychartitem -> xychart
r1218 static_cast<Marker*>(item)->setPen(pen);
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
}
void ScatterChartItem::setBrush(const QBrush& brush)
{
foreach(QGraphicsItem* item , m_items.childItems()) {
Michal Klocek
Refactor xychartitem -> xychart
r1218 static_cast<Marker*>(item)->setBrush(brush);
}
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 }
void ScatterChartItem::handleUpdated()
{
int count = m_items.childItems().count();
if(count==0) return;
bool recreate = m_size != m_series->size() || m_shape != m_series->shape();
//TODO: only rewrite on size change
m_size = m_series->size();
m_shape = m_series->shape();
Michal Klocek
Refactor xychartitem -> xychart
r1218 if(recreate) {
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 deletePoints(count);
createPoints(count);
}
setPen(m_series->pen());
setBrush(m_series->brush());
}
Michal Klocek
Refactor xychartitem -> xychart
r1218 void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
emit XYChart::clicked(calculateDomainPoint(event->pos()));
}
Michal Klocek
Refactor scatter chart to fit the other classes...
r470 #include "moc_scatterchartitem_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE