##// END OF EJS Templates
First version of legend. Simple markers and serie names. Using drilldown as example for now.
First version of legend. Simple markers and serie names. Using drilldown as example for now.

File last commit:

r486:7ab45bf9f776
r529:73dc1554f5c7
Show More
splinewidget.cpp
102 lines | 2.7 KiB | text/x-c | CppLexer
Marek Rosa
Spline working somewhat
r401 #include "splinewidget.h"
#include "qchartview.h"
Marek Rosa
Spline with problems
r419 #include "qlineseries.h"
Marek Rosa
Spline working somewhat
r401 #include <QGridLayout>
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 #include <QPushButton>
Marek Rosa
Spline chart example added
r434 #include "qchartaxis.h"
#include <qmath.h>
Marek Rosa
Spline working somewhat
r401
QTCOMMERCIALCHART_USE_NAMESPACE
SplineWidget::SplineWidget(QWidget *parent)
: QWidget(parent)
{
Marek Rosa
Minor cleanup
r457 // qsrand(time(NULL));
Marek Rosa
Spline chart example added
r434 //! [1]
Marek Rosa
Spline working somewhat
r401 //create QSplineSeries
Marek Rosa
Spline series fix
r450 series = new QSplineSeries;
Marek Rosa
Spline chart example added
r434 //! [1]
//! [2]
// customize the series presentation settings
QPen seriesPen(Qt::blue);
seriesPen.setWidth(3);
series->setPen(seriesPen);
//! [2]
//! [add points to series]
//add data points to the series
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 series->add(QPointF(150, 100));
series->add(QPointF(200, 130));
series->add(QPointF(250, 120));
series->add(QPointF(300, 140));
Marek Rosa
Spline chart example added
r434 series->add(QPointF(350, 160));
//! [add points to series]
// series->add(QPointF(400, 120));
// series->add(QPointF(450, 150));
// series->add(QPointF(500, 145));
// series->add(QPointF(550, 170));
// series->add(QPointF(600, 190));
// series->add(QPointF(650, 210));
// series->add(QPointF(700, 190));
// series->add(QPointF(750, 180));
// series->add(QPointF(800, 170));
Marek Rosa
Spline working somewhat
r401
Marek Rosa
Spline chart example added
r434 //! [3]
// create chart view
QChartView* chart = new QChartView;
chart->addSeries(series);
Marek Rosa
Spline working somewhat
r401
Marek Rosa
Spline series fix
r450 chart->setChartTitle("Spline chart example");
Marek Rosa
Renamed SplinePresenter to SplineChartItem
r460 chart->axisX()->setMax(1500);
chart->axisY()->setMax(500);
Marek Rosa
Spline working somewhat
r401
chart->setMinimumSize(800,600);
Marek Rosa
Spline chart example added
r434 //! [3]
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431
Marek Rosa
Spline chart example added
r434 //! [4]
//add new data point button
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 QPushButton* addButton = new QPushButton("Add new point");
connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint()));
Marek Rosa
Spline chart example added
r434 // remove the last data point in the series
QPushButton* removeButton = new QPushButton("Remove point");
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint()));
Marek Rosa
Spline chart example added
r434 //! [4]
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431
Marek Rosa
Spline chart example added
r434 //! [5]
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 //butttons layout
QVBoxLayout* buttonsLayout = new QVBoxLayout;
buttonsLayout->addWidget(addButton);
buttonsLayout->addWidget(removeButton);
buttonsLayout->addStretch();
Marek Rosa
Spline working somewhat
r401
QGridLayout* mainLayout = new QGridLayout;
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 mainLayout->addWidget(chart, 1, 0);
mainLayout->addLayout(buttonsLayout, 1, 1);
Marek Rosa
Spline working somewhat
r401 setLayout(mainLayout);
Marek Rosa
Spline chart example added
r434 //! [5]
Marek Rosa
Spline working somewhat
r401 }
Marek Rosa
Spline chart example added
r434 //! [add point]
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 void SplineWidget::addNewPoint()
{
if (series->count() > 0)
Marek Rosa
Renamed SplinePresenter to SplineChartItem
r460 series->add(QPointF(series->x(series->count() - 1) + 40 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100)));
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 else
series->add(QPointF(50, 50 + qrand()%50));
}
Marek Rosa
Spline chart example added
r434 //! [add point]
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431
Marek Rosa
Spline chart example added
r434 //! [remove point]
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 void SplineWidget::removePoint()
{
if (series->count() > 0)
series->remove(QPointF(series->x(series->count() - 1), series->y(series->count() - 1)));
}
Marek Rosa
Spline chart example added
r434 //! [remove point]
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431
Marek Rosa
Spline working somewhat
r401 SplineWidget::~SplineWidget()
{
}