@@ -48,14 +48,8 SplineWidget::SplineWidget(QWidget *parent) | |||||
48 | chart->addSeries(series); |
|
48 | chart->addSeries(series); | |
49 |
|
49 | |||
50 | chart->setChartTitle("Spline chart example"); |
|
50 | chart->setChartTitle("Spline chart example"); | |
51 |
|
||||
52 | // chart->setMinimumSize(800,600); |
|
|||
53 | // chart->axisX()->setRange(0, 1500); |
|
|||
54 |
|
||||
55 | // chart->axisX()->setMax(1500); |
|
|||
56 | // chart->axisY()->setRange(0, 400); |
|
|||
57 |
|
|
51 | chart->axisX()->setMax(1500); | |
58 | // chart-> |
|
52 | chart->axisY()->setMax(500); | |
59 |
|
53 | |||
60 | chart->setMinimumSize(800,600); |
|
54 | chart->setMinimumSize(800,600); | |
61 | //! [3] |
|
55 | //! [3] | |
@@ -88,7 +82,7 SplineWidget::SplineWidget(QWidget *parent) | |||||
88 | void SplineWidget::addNewPoint() |
|
82 | void SplineWidget::addNewPoint() | |
89 | { |
|
83 | { | |
90 | if (series->count() > 0) |
|
84 | if (series->count() > 0) | |
91 |
series->add(QPointF(series->x(series->count() - 1) + |
|
85 | series->add(QPointF(series->x(series->count() - 1) + 40 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100))); | |
92 | else |
|
86 | else | |
93 | series->add(QPointF(50, 50 + qrand()%50)); |
|
87 | series->add(QPointF(50, 50 + qrand()%50)); | |
94 | } |
|
88 | } |
@@ -23,7 +23,7 | |||||
23 | #include "linechartanimationitem_p.h" |
|
23 | #include "linechartanimationitem_p.h" | |
24 | #include "piepresenter_p.h" |
|
24 | #include "piepresenter_p.h" | |
25 | #include "scatterpresenter_p.h" |
|
25 | #include "scatterpresenter_p.h" | |
26 |
#include "spline |
|
26 | #include "splinechartitem_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
@@ -257,7 +257,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||||
257 |
|
257 | |||
258 | case QSeries::SeriesTypeSpline: { |
|
258 | case QSeries::SeriesTypeSpline: { | |
259 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series); |
|
259 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series); | |
260 |
Spline |
|
260 | SplineChartItem* splinePresenter = new SplineChartItem(splineSeries, m_chart); | |
261 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), splinePresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
261 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), splinePresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
262 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),splinePresenter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
262 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),splinePresenter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
263 | //initialize |
|
263 | //initialize |
@@ -24,7 +24,7 | |||||
24 | #include "areachartitem_p.h" |
|
24 | #include "areachartitem_p.h" | |
25 | #include "scatterpresenter_p.h" |
|
25 | #include "scatterpresenter_p.h" | |
26 | #include "piepresenter_p.h" |
|
26 | #include "piepresenter_p.h" | |
27 |
#include "spline |
|
27 | #include "splinechartitem_p.h" | |
28 |
|
28 | |||
29 | //themes |
|
29 | //themes | |
30 | #include "chartthemevanilla_p.h" |
|
30 | #include "chartthemevanilla_p.h" | |
@@ -299,19 +299,19 void ChartTheme::decorate(QChartAxis* axis,AxisItem* item) | |||||
299 | axis->setShadesOpacity(0.5); |
|
299 | axis->setShadesOpacity(0.5); | |
300 | } |
|
300 | } | |
301 |
|
301 | |||
302 |
void ChartTheme::decorate(Spline |
|
302 | void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int count) | |
303 | { |
|
303 | { | |
304 |
Q_ASSERT( |
|
304 | Q_ASSERT(item); | |
305 | Q_ASSERT(series); |
|
305 | Q_ASSERT(series); | |
306 |
|
306 | |||
307 | QPen pen; |
|
307 | QPen pen; | |
308 | if(pen != series->pen()){ |
|
308 | if(pen != series->pen()){ | |
309 |
|
|
309 | item->setPen(series->pen()); | |
310 | return; |
|
310 | return; | |
311 | } |
|
311 | } | |
312 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
312 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
313 | pen.setWidthF(series->pen().widthF()); |
|
313 | pen.setWidthF(series->pen().widthF()); | |
314 |
|
|
314 | item->setPen(pen); | |
315 |
|
315 | |||
316 | // QColor color = m_seriesColor.at(count % m_seriesColor.size()); |
|
316 | // QColor color = m_seriesColor.at(count % m_seriesColor.size()); | |
317 | // TODO: define alpha in the theme? or in the series? |
|
317 | // TODO: define alpha in the theme? or in the series? |
@@ -21,7 +21,7 class QScatterSeries; | |||||
21 | class ScatterPresenter; |
|
21 | class ScatterPresenter; | |
22 | class PiePresenter; |
|
22 | class PiePresenter; | |
23 | class QPieSeries; |
|
23 | class QPieSeries; | |
24 |
class Spline |
|
24 | class SplineChartItem; | |
25 | class QSplineSeries; |
|
25 | class QSplineSeries; | |
26 | class AreaChartItem; |
|
26 | class AreaChartItem; | |
27 | class QAreaSeries; |
|
27 | class QAreaSeries; | |
@@ -43,7 +43,7 public: | |||||
43 | void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); |
|
43 | void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); | |
44 | void decorate(PiePresenter* item, QPieSeries* series, int count); |
|
44 | void decorate(PiePresenter* item, QPieSeries* series, int count); | |
45 | void decorate(QChartAxis* axis,AxisItem* item); |
|
45 | void decorate(QChartAxis* axis,AxisItem* item); | |
46 |
void decorate(Spline |
|
46 | void decorate(SplineChartItem* presenter, QSplineSeries* series, int count); | |
47 |
|
47 | |||
48 | protected: |
|
48 | protected: | |
49 | QChart::ChartTheme m_id; |
|
49 | QChart::ChartTheme m_id; |
@@ -3,10 +3,10 DEPENDPATH += $$PWD | |||||
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/qsplineseries.cpp \ |
|
5 | $$PWD/qsplineseries.cpp \ | |
6 |
$$PWD/spline |
|
6 | $$PWD/splinechartitem.cpp | |
7 |
|
7 | |||
8 | PRIVATE_HEADERS += \ |
|
8 | PRIVATE_HEADERS += \ | |
9 |
$$PWD/spline |
|
9 | $$PWD/splinechartitem_p.h | |
10 |
|
10 | |||
11 | PUBLIC_HEADERS += \ |
|
11 | PUBLIC_HEADERS += \ | |
12 | $$PWD/qsplineseries.h |
|
12 | $$PWD/qsplineseries.h |
@@ -1,9 +1,9 | |||||
1 |
#include "spline |
|
1 | #include "splinechartitem_p.h" | |
2 | #include <QPainter> |
|
2 | #include <QPainter> | |
3 |
|
3 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
5 | |||
6 |
Spline |
|
6 | SplineChartItem::SplineChartItem(QSplineSeries* series, QGraphicsObject *parent) : | |
7 | LineChartItem(series, parent)//,m_boundingRect() |
|
7 | LineChartItem(series, parent)//,m_boundingRect() | |
8 | { |
|
8 | { | |
9 | // |
|
9 | // | |
@@ -11,7 +11,7 SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) | |||||
11 |
|
11 | |||
12 |
|
12 | |||
13 |
|
13 | |||
14 |
QPointF Spline |
|
14 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const | |
15 | { |
|
15 | { | |
16 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); |
|
16 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
17 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
17 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
@@ -21,7 +21,7 QPointF SplinePresenter::calculateGeometryControlPoint(int index) const | |||||
21 | return QPointF(x,y); |
|
21 | return QPointF(x,y); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 |
void Spline |
|
24 | void SplineChartItem::applyGeometry(QVector<QPointF>& points) | |
25 | { |
|
25 | { | |
26 | if(points.size()==0) return; |
|
26 | if(points.size()==0) return; | |
27 |
|
27 | |||
@@ -41,7 +41,7 void SplinePresenter::applyGeometry(QVector<QPointF>& points) | |||||
41 | m_rect = splinePath.boundingRect(); |
|
41 | m_rect = splinePath.boundingRect(); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 |
void Spline |
|
44 | void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
45 | { |
|
45 | { | |
46 | Q_UNUSED(widget); |
|
46 | Q_UNUSED(widget); | |
47 | Q_UNUSED(option); |
|
47 | Q_UNUSED(option); | |
@@ -70,6 +70,6 void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *o | |||||
70 | painter->restore(); |
|
70 | painter->restore(); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 |
#include "moc_spline |
|
73 | #include "moc_splinechartitem_p.cpp" | |
74 |
|
74 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,5 +1,5 | |||||
1 |
#ifndef SPLINE |
|
1 | #ifndef SPLINECHARTITEM_P_H | |
2 |
#define SPLINE |
|
2 | #define SPLINECHARTITEM_P_H | |
3 |
|
3 | |||
4 | #include "chartitem_p.h" |
|
4 | #include "chartitem_p.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
@@ -8,11 +8,11 | |||||
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 |
class Spline |
|
11 | class SplineChartItem : public LineChartItem | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 |
Spline |
|
15 | SplineChartItem(QSplineSeries* series, QGraphicsObject *parent = 0); | |
16 |
|
16 | |||
17 | void updateGeometry(); |
|
17 | void updateGeometry(); | |
18 |
|
18 | |||
@@ -25,4 +25,4 public: | |||||
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_END_NAMESPACE |
|
26 | QTCOMMERCIALCHART_END_NAMESPACE | |
27 |
|
27 | |||
28 |
#endif // SPLINE |
|
28 | #endif // SPLINECHARTITEM_P_H |
General Comments 0
You need to be logged in to leave comments.
Login now