##// END OF EJS Templates
Fixed colors in spline
Marek Rosa -
r577:d1f00b1c0524
parent child
Show More
@@ -14,14 +14,14 SplineWidget::SplineWidget(QWidget *parent)
14 // qsrand(time(NULL));
14 // qsrand(time(NULL));
15 //! [1]
15 //! [1]
16 //create QSplineSeries
16 //create QSplineSeries
17 series = new QSplineSeries;
17 series = new QSplineSeries(this);
18 //! [1]
18 //! [1]
19
19
20 //! [2]
20 //! [2]
21 // customize the series presentation settings
21 // customize the series presentation settings
22 QPen seriesPen(Qt::blue);
22 QPen seriesPen(Qt::blue);
23 seriesPen.setWidth(3);
23 seriesPen.setWidth(3);
24 series->setPen(seriesPen);
24 // series->setPen(seriesPen);
25 //! [2]
25 //! [2]
26
26
27 //! [add points to series]
27 //! [add points to series]
@@ -32,20 +32,32 SplineWidget::SplineWidget(QWidget *parent)
32 series->add(QPointF(300, 140));
32 series->add(QPointF(300, 140));
33 series->add(QPointF(350, 160));
33 series->add(QPointF(350, 160));
34 //! [add points to series]
34 //! [add points to series]
35 // series->add(QPointF(400, 120));
35
36 // series->add(QPointF(450, 150));
36 QSplineSeries* series2 = new QSplineSeries;
37 // series->add(QPointF(500, 145));
37
38 // series->add(QPointF(550, 170));
38 series2->add(QPointF(400, 120));
39 series2->add(QPointF(450, 150));
40 series2->add(QPointF(500, 145));
41 series2->add(QPointF(550, 170));
42
39 // series->add(QPointF(600, 190));
43 // series->add(QPointF(600, 190));
40 // series->add(QPointF(650, 210));
44 // series->add(QPointF(650, 210));
41 // series->add(QPointF(700, 190));
45 // series->add(QPointF(700, 190));
42 // series->add(QPointF(750, 180));
46 // series->add(QPointF(750, 180));
43 // series->add(QPointF(800, 170));
47 // series->add(QPointF(800, 170));
48 QSplineSeries* series3 = new QSplineSeries;
49 series3->add(QPointF(600, 190));
50 series3->add(QPointF(650, 210));
51 series3->add(QPointF(700, 190));
52 series3->add(QPointF(750, 180));
53 series3->add(QPointF(800, 170));
44
54
45 //! [3]
55 //! [3]
46 // create chart view
56 // create chart view
47 QChartView* chart = new QChartView;
57 QChartView* chart = new QChartView;
48 chart->addSeries(series);
58 chart->addSeries(series);
59 chart->addSeries(series2);
60 chart->addSeries(series3);
49
61
50 chart->setChartTitle("Spline chart example");
62 chart->setChartTitle("Spline chart example");
51 chart->axisX()->setMax(1500);
63 chart->axisX()->setMax(1500);
@@ -192,7 +192,6 void ChartTheme::decorate(PieChartItem* item, QPieSeries* series, int index)
192 void ChartTheme::decorate(QSplineSeries* series, int index)
192 void ChartTheme::decorate(QSplineSeries* series, int index)
193 {
193 {
194 QPen pen;
194 QPen pen;
195
196 if(pen == series->pen()){
195 if(pen == series->pen()){
197 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
196 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
198 pen.setWidthF(2);
197 pen.setWidthF(2);
@@ -57,7 +57,6 void SplineChartItem::setLayout(QVector<QPointF>& points)
57
57
58 void SplineChartItem::handleUpdated()
58 void SplineChartItem::handleUpdated()
59 {
59 {
60 //m_items.setVisible(m_series->pointsVisible());
61 m_pen = m_series->pen();
60 m_pen = m_series->pen();
62 update();
61 update();
63 }
62 }
@@ -70,27 +69,28 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
70 Q_UNUSED(option);
69 Q_UNUSED(option);
71 painter->save();
70 painter->save();
72 painter->setClipRect(clipRect());
71 painter->setClipRect(clipRect());
73 painter->setPen(m_pen);
72 // painter->setPen(m_pen);
73 painter->setPen(m_series->pen());
74 painter->drawPath(m_path);
74 painter->drawPath(m_path);
75
75
76 const QVector<QPointF> points = XYChartItem::points();
76 // const QVector<QPointF> points = XYChartItem::points();
77
77
78 for (int i = 0; i < points.size() - 1; i++)
78 // for (int i = 0; i < points.size() - 1; i++)
79 {
79 // {
80 painter->setPen(Qt::red);
80 // painter->setPen(Qt::red);
81 painter->drawEllipse(points[i], 2, 2);
81 // painter->drawEllipse(points[i], 2, 2);
82
82
83 painter->setPen(Qt::blue);
83 // painter->setPen(Qt::blue);
84 // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i));
84 // // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i));
85 // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1));
85 // // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1));
86 // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4);
86 // // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4);
87 // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4);
87 // // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4);
88 }
88 // }
89 if (points.count() > 0)
89 // if (points.count() > 0)
90 {
90 // {
91 painter->setPen(Qt::red);
91 // painter->setPen(Qt::red);
92 painter->drawEllipse(points[points.count() - 1], 2, 2);
92 // painter->drawEllipse(points[points.count() - 1], 2, 2);
93 }
93 // }
94 painter->restore();
94 painter->restore();
95 }
95 }
96
96
General Comments 0
You need to be logged in to leave comments. Login now