##// END OF EJS Templates
Updates presenter example documentation
Updates presenter example documentation

File last commit:

r574:5a19c3a8f92b
r574:5a19c3a8f92b
Show More
chartview.cpp
100 lines | 2.3 KiB | text/x-c | CppLexer
Michal Klocek
Adds preseterchart example
r246 #include "chartview.h"
Michal Klocek
Rename QLineChartSeries to QLineSeries
r349 #include <qlineseries.h>
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 #include <qscatterseries.h>
#include <qsplineseries.h>
Michal Klocek
Adds area chart animations...
r560 #include <qareaseries.h>
Michal Klocek
Adds preseterchart example
r246 #include <QTime>
ChartView::ChartView(QWidget* parent):QChartView(parent),
m_index(0)
{
Michal Klocek
Adds chartPresenter example to docs
r482 QTime now = QTime::currentTime();
qsrand((uint)now.msec());
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 setChartTitle("Three random line charts");
Michal Klocek
Adds preseterchart example
r246 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
m_timer.setInterval(3000);
Michal Klocek
Adds chartPresenter example to docs
r482 //![1]
Michal Klocek
Fix ownership handling: if object has a parent do not delete it
r444 QLineSeries* series0 = new QLineSeries(this);
Michal Klocek
Adds preseterchart example
r246 QPen blue(Qt::blue);
blue.setWidth(3);
series0->setPen(blue);
Michal Klocek
Adds chartPresenter example to docs
r482
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 QScatterSeries* series1 = new QScatterSeries(this);
Michal Klocek
Adds preseterchart example
r246 QPen red(Qt::red);
red.setWidth(3);
series1->setPen(red);
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 series1->setBrush(Qt::white);
Michal Klocek
Adds chartPresenter example to docs
r482
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 QSplineSeries* series2 = new QSplineSeries(this);
Michal Klocek
Adds preseterchart example
r246 QPen green(Qt::green);
green.setWidth(3);
series2->setPen(green);
Michal Klocek
Adds area chart animations...
r560
QAreaSeries* series3 = new QAreaSeries(series0);
QPen yellow(Qt::black);
yellow.setWidth(3);
series3->setPen(yellow);
series3->setBrush(Qt::yellow);
Michal Klocek
Adds chartPresenter example to docs
r482 //![1]
Michal Klocek
Adds preseterchart example
r246
Michal Klocek
Adds chartPresenter example to docs
r482 //![2]
Michal Klocek
Adds preseterchart example
r246 int numPoints = 10;
for (int x = 0; x <= numPoints; ++x) {
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 qreal y = qrand() % 100;
series0->add(x,y);
series1->add(x,y);
series2->add(x,y);
Michal Klocek
Adds preseterchart example
r246 }
Michal Klocek
Adds chartPresenter example to docs
r482 //![2]
Michal Klocek
Adds preseterchart example
r246
Michal Klocek
Adds chartPresenter example to docs
r482 //![3]
Michal Klocek
Adds preseterchart example
r246 m_series<<series0;
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 m_titles<<chartTitle()+": LineChart";
Michal Klocek
Adds preseterchart example
r246 m_series<<series1;
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 m_titles<<chartTitle()+": ScatterChart";
Michal Klocek
Adds preseterchart example
r246 m_series<<series2;
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 m_titles<<chartTitle()+": SplineChart";
Michal Klocek
Adds area chart animations...
r560 m_series<<series3;
m_titles<<chartTitle()+": AreaChart";
Michal Klocek
Adds chartPresenter example to docs
r482 //![3]
Michal Klocek
Refactors click signal to line,area,spline,scatter charts
r571
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 addSeries(series0);
setChartTitle(m_titles.at(0));
Michal Klocek
Adds preseterchart example
r246
Michal Klocek
Updates presenter example documentation
r574 //![4]
Michal Klocek
Refactors click signal to line,area,spline,scatter charts
r571 foreach (QSeries* series, m_series) {
QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&)));
}
Michal Klocek
Updates presenter example documentation
r574 //![4]
Michal Klocek
Refactors click signal to line,area,spline,scatter charts
r571
Michal Klocek
Adds preseterchart example
r246 m_timer.start();
}
ChartView::~ChartView()
{
Michal Klocek
Fix memory leak in presenter example
r257 if(m_series.size()==0) return;
removeSeries(m_series.at(m_index));
qDeleteAll(m_series);
Michal Klocek
Adds preseterchart example
r246 }
Michal Klocek
Updates presenter example documentation
r574 //![5]
Michal Klocek
Adds preseterchart example
r246 void ChartView::handleTimeout()
{
if(m_series.size()==0) return;
removeSeries(m_series.at(m_index));
m_index++;
m_index=m_index%m_series.size();
addSeries(m_series.at(m_index));
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 setChartTitle(m_titles.at(m_index));
Michal Klocek
Adds preseterchart example
r246 }
Michal Klocek
Updates presenter example documentation
r574 //![5]
Michal Klocek
Refactors click signal to line,area,spline,scatter charts
r571
Michal Klocek
Updates presenter example documentation
r574 //![6]
Michal Klocek
Refactors click signal to line,area,spline,scatter charts
r571 void ChartView::handlePointClicked(const QPointF& point)
{
setChartTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y()));
}
Michal Klocek
Updates presenter example documentation
r574 //![6]