##// END OF EJS Templates
Refactored QML example to multiple views
Refactored QML example to multiple views

File last commit:

r838:b700a1337503
r887:1270a0b0cca2
Show More
splinewidget.cpp
135 lines | 3.9 KiB | text/x-c | CppLexer
Jani Honkonen
Add/modify license headers
r830 /****************************************************************************
**
** 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$
**
****************************************************************************/
Marek Rosa
Spline working somewhat
r401 #include "splinewidget.h"
#include <QGridLayout>
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 #include <QPushButton>
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 #include <QTime>
Jani Honkonen
include headers without the .h in examples
r838 #include <QChartView>
#include <QSplineSeries>
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
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
Marek Rosa
Spline chart example added
r434 //! [1]
Marek Rosa
Spline working somewhat
r401 //create QSplineSeries
Marek Rosa
Fixed colors in spline
r577 series = new QSplineSeries(this);
Marek Rosa
Spline chart example added
r434 //! [1]
//! [2]
// customize the series presentation settings
QPen seriesPen(Qt::blue);
seriesPen.setWidth(3);
Marek Rosa
Fixed colors in spline
r577 // series->setPen(seriesPen);
Marek Rosa
Spline chart example added
r434 //! [2]
//! [add points to series]
//add data points to the series
Jani Honkonen
rename functions add() -> append()
r796 series->append(QPointF(150, 100));
series->append(QPointF(200, 130));
series->append(QPointF(250, 120));
series->append(QPointF(300, 140));
series->append(QPointF(350, 160));
Marek Rosa
Spline chart example added
r434 //! [add points to series]
Marek Rosa
Fixed colors in spline
r577
QSplineSeries* series2 = new QSplineSeries;
Jani Honkonen
rename functions add() -> append()
r796 series2->append(QPointF(400, 120));
series2->append(QPointF(450, 150));
series2->append(QPointF(500, 145));
series2->append(QPointF(550, 170));
Marek Rosa
Fixed colors in spline
r577
Jani Honkonen
rename functions add() -> append()
r796 // series->append(QPointF(600, 190));
// series->append(QPointF(650, 210));
// series->append(QPointF(700, 190));
// series->append(QPointF(750, 180));
// series->append(QPointF(800, 170));
Marek Rosa
Fixed colors in spline
r577 QSplineSeries* series3 = new QSplineSeries;
Jani Honkonen
rename functions add() -> append()
r796 series3->append(QPointF(600, 190));
series3->append(QPointF(650, 210));
series3->append(QPointF(700, 190));
series3->append(QPointF(750, 180));
series3->append(QPointF(800, 170));
Marek Rosa
Spline working somewhat
r401
Marek Rosa
Spline chart example added
r434 //! [3]
// create chart view
Jani Honkonen
Make splinechart compile
r832 QChart* chart = new QChart;
Marek Rosa
Spline chart example added
r434 chart->addSeries(series);
Marek Rosa
Fixed colors in spline
r577 chart->addSeries(series2);
chart->addSeries(series3);
Marek Rosa
Spline working somewhat
r401
Jani Honkonen
Make splinechart compile
r832 chart->setTitle("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;
Jani Honkonen
Make splinechart compile
r832 QChartView *chartView = new QChartView(chart);
mainLayout->addWidget(chartView, 1, 0);
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 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)
Jani Honkonen
rename functions add() -> append()
r796 series->append(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
Jani Honkonen
rename functions add() -> append()
r796 series->append(QPointF(50, 50 + qrand()%50));
Marek Rosa
Added automatic refresh of control points on add/remove point. Spline example updated
r431 }
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()
{
}