From 917f2d37819322fb7f97b908fec4404c90bcdd1a 2012-03-27 17:32:46 From: Michal Klocek Date: 2012-03-27 17:32:46 Subject: [PATCH] Uninfy examples , updated public API changes --- diff --git a/examples/areachart/main.cpp b/examples/areachart/main.cpp index a178380..9328e38 100644 --- a/examples/areachart/main.cpp +++ b/examples/areachart/main.cpp @@ -1,57 +1,94 @@ +/**************************************************************************** + ** + ** 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:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Digia nor the names of its contributors + ** may be used to endorse or promote products derived from this + ** software without specific prior written permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** + ****************************************************************************/ + #include #include #include #include #include -#include QTCOMMERCIALCHART_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); - //![1] - QLineSeries* series0 = new QLineSeries(); QLineSeries* series1 = new QLineSeries(); - //![1] //![2] - *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12,6) << QPointF(16,7) << QPointF(18,5); - *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12,3) << QPointF(16,4) << QPointF(18,3); + *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6) + << QPointF(16, 7) << QPointF(18, 5); + *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3) + << QPointF(16, 4) << QPointF(18, 3); //![2] //![3] - - QAreaSeries* series = new QAreaSeries(series0,series1); + QAreaSeries* series = new QAreaSeries(series0, series1); QPen pen(0x059605); pen.setWidth(3); series->setPen(pen); QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1)); - gradient.setColorAt(0.0,0x3cc63c); + gradient.setColorAt(0.0, 0x3cc63c); gradient.setColorAt(1.0, 0x26f626); gradient.setCoordinateMode(QGradient::ObjectBoundingMode); series->setBrush(gradient); - //![3] //![4] - QMainWindow window; - QChartView* chartView = new QChartView(&window); - - chartView->setChartTitle("Simple area chart example"); - chartView->setRenderHint(QPainter::Antialiasing); - - chartView->addSeries(series); - chartView->axisX()->setRange(0,20); - chartView->axisY()->setRange(0,10); + QChart* chart = new QChart(); + chart->addSeries(series); + chart->setTitle("Simple areachart example"); + chart->axisX()->setRange(0, 20); + chart->axisY()->setRange(0, 10); //![4] //![5] + QChartView* chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![5] +//![6] + QMainWindow window; window.setCentralWidget(chartView); window.resize(400, 300); window.show(); -//![5] - +//![6] return a.exec(); } diff --git a/examples/barchart/barchart.pro b/examples/barchart/barchart.pro index f9e3a14..54e9c0a 100644 --- a/examples/barchart/barchart.pro +++ b/examples/barchart/barchart.pro @@ -3,8 +3,5 @@ } TARGET = barchart -SOURCES += main.cpp \ - chartwidget.cpp -HEADERS += \ - chartwidget.h +SOURCES += main.cpp diff --git a/examples/barchart/chartwidget.cpp b/examples/barchart/chartwidget.cpp deleted file mode 100644 index d6c7532..0000000 --- a/examples/barchart/chartwidget.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "chartwidget.h" - -ChartWidget::ChartWidget(QWidget *parent) : - QChartView(parent) -{ -} diff --git a/examples/barchart/chartwidget.h b/examples/barchart/chartwidget.h deleted file mode 100644 index b5625e3..0000000 --- a/examples/barchart/chartwidget.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef CHARTWIDGET_H -#define CHARTWIDGET_H - -#include - -QTCOMMERCIALCHART_USE_NAMESPACE - - -class ChartWidget : public QChartView -{ - Q_OBJECT -public: - explicit ChartWidget(QWidget *parent = 0); - -signals: - -public slots: - -}; - -#endif // CHARTWIDGET_H diff --git a/examples/barchart/main.cpp b/examples/barchart/main.cpp index 01d887f..e29c805 100644 --- a/examples/barchart/main.cpp +++ b/examples/barchart/main.cpp @@ -1,27 +1,60 @@ +/**************************************************************************** + ** + ** 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:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Digia nor the names of its contributors + ** may be used to endorse or promote products derived from this + ** software without specific prior written permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** + ****************************************************************************/ + #include #include -#include -#include -#include -#include -#include +#include +#include +#include QTCOMMERCIALCHART_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); - QMainWindow window; - - //! [1] - // Define categories - QStringList categories; +//![1] + QBarCategories categories; categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - //! [1] - - //! [2] - // Create some test sets for chat - +//![1] +//![2] QBarSet *set0 = new QBarSet("Bub"); QBarSet *set1 = new QBarSet("Bob"); QBarSet *set2 = new QBarSet("Guybrush"); @@ -33,48 +66,29 @@ int main(int argc, char *argv[]) *set2 << 3 << 5 << 8 << 13 << 8 << 5; *set3 << 5 << 6 << 7 << 3 << 4 << 5; *set4 << 9 << 7 << 5 << 3 << 1 << 2; - //! [2] - - //! [3] - // Create series and add sets to it - QBarSeries* series= new QBarSeries(categories); - +//![2] +//![3] + QBarSeries* series = new QBarSeries(categories); series->addBarSet(set0); series->addBarSet(set1); series->addBarSet(set2); series->addBarSet(set3); series->addBarSet(set4); - //! [3] - - //! [4] - // Enable tooltip - series->setToolTipEnabled(); - - // Connect clicked signal of set to toggle floating values of set. - QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues())); - QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues())); - QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues())); - QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues())); - QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues())); - //! [4] - - //! [5] - // Create view for chart and add series to it. Apply theme. - - QChartView* chartView = new QChartView(&window); - chartView->addSeries(series); - chartView->setChartTitle("simple barchart"); - chartView->setChartTheme(QChart::ChartThemeIcy); - //! [5] - - //! [6] - chartView->axisX()->setGridLineVisible(false); - //! [6] - +//![3] +//![4] + QChart* chart = new QChart(); + chart->addSeries(series); + chart->setTitle("Simple barchart example"); +//![4] +//![5] + QChartView* chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![5] +//![6] + QMainWindow window; window.setCentralWidget(chartView); window.resize(400, 300); window.show(); - +//![6] return a.exec(); } - diff --git a/examples/colorlinechart/main.cpp b/examples/colorlinechart/main.cpp index ae123b6..0aa695a 100644 --- a/examples/colorlinechart/main.cpp +++ b/examples/colorlinechart/main.cpp @@ -1,55 +1,95 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia nor the names of its contributors +** may be used to endorse or promote products derived from this +** software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +****************************************************************************/ + #include #include -#include -#include -#include -#include +#include +#include QTCOMMERCIALCHART_USE_NAMESPACE -#define PI 3.14159265358979 - int main(int argc, char *argv[]) { QApplication a(argc, argv); - QMainWindow window; - - QLineSeries* series0 = new QLineSeries(); +//![1] + QLineSeries* series = new QLineSeries(); QPen blue(Qt::blue); blue.setWidth(3); - series0->setPen(blue); - QLineSeries* series1 = new QLineSeries(); - QPen red(Qt::red); - red.setWidth(3); - series1->setPen(red); - - int numPoints = 100; - - for (int x = 0; x <= numPoints; ++x) { - series0->add(x, fabs(sin(PI/50*x)*100)); - series1->add(x, fabs(cos(PI/50*x)*100)); - } - - QChartView* chartView = new QChartView(&window); - chartView->setRenderHint(QPainter::Antialiasing); - + series->setPen(blue); +//![1] +//![2] + *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5); +//![2] +//![3] + QChart* chart = new QChart(); + chart->addSeries(series); + chart->setTitle("Custom colors example"); +//![3] +//![4] QFont font; font.setPixelSize(18); - chartView->setChartTitleFont(font); - chartView->setChartTitle("Custom color line chart example"); - chartView->addSeries(series0); - chartView->addSeries(series1); + chart->setTitleFont(font); + chart->setTitleBrush(Qt::red); QLinearGradient backgroundGradient; - backgroundGradient.setColorAt(0.0, Qt::blue); - backgroundGradient.setColorAt(1.0, Qt::yellow); + backgroundGradient.setColorAt(0.0, Qt::lightGray); + backgroundGradient.setColorAt(1.0, Qt::white); backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); - chartView->setChartBackgroundBrush(backgroundGradient); + chart->setBackgroundBrush(backgroundGradient); + QPen black(Qt::black); + chart->axisX()->setGridLinePen(black); + chart->axisX()->setAxisPen(black); + chart->axisY()->setGridLinePen(black); + chart->axisY()->setAxisPen(black); +//![4] +//![5] + QChartView* chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![5] + QMainWindow window; window.setCentralWidget(chartView); window.resize(400, 300); window.show(); - +//![5] return a.exec(); } diff --git a/examples/examples.pro b/examples/examples.pro index df146a0..cc22fa3 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,23 +1,32 @@ TEMPLATE = subdirs -SUBDIRS += linechart \ - zoomlinechart \ - colorlinechart \ +SUBDIRS += \ + areachart \ + #axischart \ barchart \ - stackedbarchart \ + #chartview \ + colorlinechart \ + #customcolors \ + #dynamiclinechart \ + #ekgchart \ + #gdpbarchart \ + linechart \ + #multichart \ percentbarchart \ - scatterchart \ piechart \ - piechartdrilldown \ - dynamiclinechart \ - axischart \ - multichart \ - gdpbarchart \ - presenterchart \ - chartview \ - scatterinteractions \ - splinechart \ - areachart \ - stackedbarchartdrilldown \ - customcolors \ - tablemodelchart \ - ekgchart + #piechartdrilldown \ + #presenterchart \ + scatterchart \ + #scatterinteractions \ + #splinechart \ + stackedbarchart \ + #stackedbarchartdrilldown \ + #tablemodelchart \ + zoomlinechart + + + + + + + + diff --git a/examples/linechart/main.cpp b/examples/linechart/main.cpp index 039b3d6..82d63d7 100644 --- a/examples/linechart/main.cpp +++ b/examples/linechart/main.cpp @@ -1,15 +1,54 @@ +/**************************************************************************** +** +** 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia nor the names of its contributors +** may be used to endorse or promote products derived from this +** software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +****************************************************************************/ + #include #include #include #include -#include QTCOMMERCIALCHART_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); - //![1] QLineSeries* series0 = new QLineSeries(); QPen blue(Qt::blue); @@ -27,25 +66,26 @@ int main(int argc, char *argv[]) series0->add(2, 4); series0->add(3, 8); series0->add(7, 4); - series0->add(10,5); + series0->add(10, 5); - *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10,2); + *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2); //![2] //![3] - QMainWindow window; - QChartView* chartView = new QChartView(&window); - - chartView->setChartTitle("Simple line chart"); - chartView->setRenderHint(QPainter::Antialiasing); + QChart* chart = new QChart(); - chartView->addSeries(series0); - chartView->addSeries(series1); + chart->addSeries(series0); + chart->addSeries(series1); + chart->setTitle("Simple line chart example"); //![3] //![4] + QChartView* chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![4] +//![5] + QMainWindow window; window.setCentralWidget(chartView); window.resize(400, 300); window.show(); -//![4] - +//![5] return a.exec(); } diff --git a/examples/percentbarchart/chartwidget.cpp b/examples/percentbarchart/chartwidget.cpp deleted file mode 100644 index d6c7532..0000000 --- a/examples/percentbarchart/chartwidget.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "chartwidget.h" - -ChartWidget::ChartWidget(QWidget *parent) : - QChartView(parent) -{ -} diff --git a/examples/percentbarchart/chartwidget.h b/examples/percentbarchart/chartwidget.h deleted file mode 100644 index c7567ba..0000000 --- a/examples/percentbarchart/chartwidget.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef CHARTWIDGET_H -#define CHARTWIDGET_H - -#include - -QTCOMMERCIALCHART_USE_NAMESPACE - - -class ChartWidget : public QChartView -{ - Q_OBJECT -public: - explicit ChartWidget(QWidget *parent = 0); -}; - -#endif // CHARTWIDGET_H diff --git a/examples/percentbarchart/main.cpp b/examples/percentbarchart/main.cpp index a0f21c9..5fbaf11 100644 --- a/examples/percentbarchart/main.cpp +++ b/examples/percentbarchart/main.cpp @@ -1,27 +1,60 @@ +/**************************************************************************** + ** + ** 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:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Digia nor the names of its contributors + ** may be used to endorse or promote products derived from this + ** software without specific prior written permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** + ****************************************************************************/ + #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include QTCOMMERCIALCHART_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); - QMainWindow window; - - //! [1] - // Define categories - QStringList categories; +//![1] + QBarCategories categories; categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - //! [1] - - //! [2] - // Create some test sets for chat +//![1] +//![2] QBarSet *set0 = new QBarSet("Bub"); QBarSet *set1 = new QBarSet("Bob"); QBarSet *set2 = new QBarSet("Guybrush"); @@ -33,51 +66,30 @@ int main(int argc, char *argv[]) *set2 << 3 << 5 << 8 << 13 << 8 << 5; *set3 << 5 << 6 << 7 << 3 << 4 << 5; *set4 << 9 << 7 << 5 << 3 << 1 << 2; - //! [2] - - //! [3] - // Create series and add sets to it +//![2] +//![3] QPercentBarSeries* series = new QPercentBarSeries(categories); - series->addBarSet(set0); series->addBarSet(set1); series->addBarSet(set2); series->addBarSet(set3); series->addBarSet(set4); - //! [3] - - //! [4] - // Enable tooltip - series->setToolTipEnabled(); - - // Connect clicked signal of set to toggle floating values of set. - // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values. - QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues())); - QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues())); - QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues())); - QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues())); - QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues())); - //! [4] - - //! [5] - // Create view for chart and add series to it. Apply theme. - - QChartView* chartView = new QChartView(&window); - chartView->addSeries(series); - chartView->setChartTitle("simple percent barchart"); - chartView->setChartTheme(QChart::ChartThemeIcy); - //! [5] - - //! [6] - //chartView->axisX()->setAxisVisible(false); - chartView->axisX()->setGridLineVisible(false); - chartView->axisX()->setLabelsVisible(false); - //! [6] - +//! [3] +//![4] + QChart* chart = new QChart(); + chart->addSeries(series); + chart->setTitle("Simple precentbarchart example"); +//![4] +//![5] + QChartView* chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![5] +//![6] + QMainWindow window; window.setCentralWidget(chartView); window.resize(400, 300); window.show(); - +//![6] return a.exec(); } diff --git a/examples/percentbarchart/percentbarchart.pro b/examples/percentbarchart/percentbarchart.pro index 3b0e6fc..dc48fde 100644 --- a/examples/percentbarchart/percentbarchart.pro +++ b/examples/percentbarchart/percentbarchart.pro @@ -3,8 +3,5 @@ } TARGET = percentbarchart -SOURCES += main.cpp \ - chartwidget.cpp -HEADERS += \ - chartwidget.h +SOURCES += main.cpp diff --git a/examples/piechart/main.cpp b/examples/piechart/main.cpp index fbc97b1..aa20814 100644 --- a/examples/piechart/main.cpp +++ b/examples/piechart/main.cpp @@ -1,9 +1,49 @@ -#include +/**************************************************************************** + ** + ** 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:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Digia nor the names of its contributors + ** may be used to endorse or promote products derived from this + ** software without specific prior written permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** + ****************************************************************************/ + +#include #include -#include -#include -#include -#include +#include +#include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -11,34 +51,36 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - QMainWindow window; - - QChartView* chartView = new QChartView(&window); - chartView->setRenderHint(QPainter::Antialiasing); - chartView->setChartTitle("Simple pie chart"); - - //! [1] +//![1] QPieSeries *series = new QPieSeries(); series->add(1, "Slice 1"); series->add(2, "Slice 2"); series->add(3, "Slice 3"); series->add(4, "Slice 4"); series->add(5, "Slice 5"); - //! [1] +//![1] - //! [2] +//![2] QPieSlice *slice = series->slices().first(); slice->setExploded(); slice->setLabelVisible(); slice->setSlicePen(QPen(Qt::darkGreen, 2)); slice->setSliceBrush(Qt::green); - //! [2] - - chartView->addSeries(series); - +//![2] +//![3] + QChart* chart = new QChart(); + chart->addSeries(series); + chart->setTitle("Simple piechart example"); +//![3] +//![4] + QChartView* chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![4] +//![5] + QMainWindow window; window.setCentralWidget(chartView); - window.resize(600, 600); + window.resize(400, 300); window.show(); - +//![5] return a.exec(); } diff --git a/examples/scatterchart/main.cpp b/examples/scatterchart/main.cpp index 5217ec7..d38b193 100644 --- a/examples/scatterchart/main.cpp +++ b/examples/scatterchart/main.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** + ** + ** 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:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Digia nor the names of its contributors + ** may be used to endorse or promote products derived from this + ** software without specific prior written permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** + ****************************************************************************/ + #include #include #include @@ -8,41 +49,50 @@ QTCOMMERCIALCHART_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); - -//! [1] - QScatterSeries *scatter = new QScatterSeries(); - - QBrush brush(Qt::red); +//![1] QPen pen(Qt::black); pen.setWidth(2); + QBrush blue(Qt::blue); + QBrush red(Qt::red); - scatter->setPen(pen); - scatter->setBrush(brush); - scatter->setShape(QScatterSeries::MarkerShapeCircle); - scatter->setSize(15.0); -//! [1] - -//! [2] - for (qreal i(0.0); i < 20; i += 0.5) { - qreal x = i + (qreal) (rand() % 100) / 100.0; - qreal y = i + (qreal) (rand() % 100) / 100.0; - scatter->add(x, y); - } - *scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4); -//! [2] - -//! [3] - QMainWindow window; - QChartView *chartView = new QChartView(&window); - chartView->setRenderHint(QPainter::Antialiasing); - chartView->setChartTitle("Simple scatter chart example"); - chartView->addSeries(scatter); -//! [3] + QScatterSeries *series0 = new QScatterSeries(); + series0->setPen(pen); + series0->setBrush(blue); + series0->setShape(QScatterSeries::MarkerShapeCircle); + series0->setSize(15.0); -//! [4] + QScatterSeries *series1 = new QScatterSeries(); + series1->setPen(pen); + series1->setBrush(red); + series1->setShape(QScatterSeries::MarkerShapeCircle); + series1->setSize(15.0); +//![1] + +//![2] + series0->add(0, 6); + series0->add(2, 4); + series0->add(3, 8); + series0->add(7, 4); + series0->add(10, 5); + + *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2); +//![2] +//![3] + QChart* chart = new QChart(); + + chart->addSeries(series0); + chart->addSeries(series1); + chart->setTitle("Simple scatterchart example"); +//![3] +//![4] + QChartView* chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![4] +//![5] + QMainWindow window; window.setCentralWidget(chartView); window.resize(400, 300); window.show(); -//! [4] +//![5] return a.exec(); } diff --git a/examples/stackedbarchart/chartwidget.cpp b/examples/stackedbarchart/chartwidget.cpp deleted file mode 100644 index d6c7532..0000000 --- a/examples/stackedbarchart/chartwidget.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "chartwidget.h" - -ChartWidget::ChartWidget(QWidget *parent) : - QChartView(parent) -{ -} diff --git a/examples/stackedbarchart/chartwidget.h b/examples/stackedbarchart/chartwidget.h deleted file mode 100644 index b5625e3..0000000 --- a/examples/stackedbarchart/chartwidget.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef CHARTWIDGET_H -#define CHARTWIDGET_H - -#include - -QTCOMMERCIALCHART_USE_NAMESPACE - - -class ChartWidget : public QChartView -{ - Q_OBJECT -public: - explicit ChartWidget(QWidget *parent = 0); - -signals: - -public slots: - -}; - -#endif // CHARTWIDGET_H diff --git a/examples/stackedbarchart/main.cpp b/examples/stackedbarchart/main.cpp index 179a7d9..dc1a037 100644 --- a/examples/stackedbarchart/main.cpp +++ b/examples/stackedbarchart/main.cpp @@ -1,26 +1,60 @@ +/**************************************************************************** + ** + ** 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:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Digia nor the names of its contributors + ** may be used to endorse or promote products derived from this + ** software without specific prior written permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** + ****************************************************************************/ + #include #include -#include -#include -#include -#include -#include +#include +#include +#include QTCOMMERCIALCHART_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); - QMainWindow window; - - //! [1] - // Define categories - QStringList categories; +//![1] + QBarCategories categories; categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - //! [1] - - //! [2] - // Create some test sets for chat +//![1] +//![2] QBarSet *set0 = new QBarSet("Bub"); QBarSet *set1 = new QBarSet("Bob"); QBarSet *set2 = new QBarSet("Guybrush"); @@ -32,48 +66,30 @@ int main(int argc, char *argv[]) *set2 << 3 << 5 << 8 << 13 << 8 << 5; *set3 << 5 << 6 << 7 << 3 << 4 << 5; *set4 << 9 << 7 << 5 << 3 << 1 << 2; - //! [2] - - //! [3] - // Create series and add sets to it +//![2] +//![3] QStackedBarSeries* series = new QStackedBarSeries(categories); - series->addBarSet(set0); series->addBarSet(set1); series->addBarSet(set2); series->addBarSet(set3); series->addBarSet(set4); - //! [3] - - //! [4] - // Enable tooltip - series->setToolTipEnabled(); - - // Connect clicked signal of set to toggle floating values of set. - QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues())); - QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues())); - QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues())); - QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues())); - QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues())); - //! [4] - - //! [5] - // Create view for chart and add series to it. Apply theme. - - QChartView* chartView = new QChartView(&window); - chartView->addSeries(series); - chartView->setChartTitle("simple stacked barchart"); - chartView->setChartTheme(QChart::ChartThemeIcy); - //! [5] - - //! [6] - chartView->axisX()->setGridLineVisible(false); - //! [6] - +//![3] +//![4] + QChart* chart = new QChart(); + chart->addSeries(series); + chart->setTitle("Simple stackedbarchart example"); +//![4] +//![5] + QChartView* chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![5] +//![6] + QMainWindow window; window.setCentralWidget(chartView); window.resize(400, 300); window.show(); - +//![6] return a.exec(); } diff --git a/examples/stackedbarchart/stackedbarchart.pro b/examples/stackedbarchart/stackedbarchart.pro index 5fee60a..a41bff4 100644 --- a/examples/stackedbarchart/stackedbarchart.pro +++ b/examples/stackedbarchart/stackedbarchart.pro @@ -2,8 +2,4 @@ error( "Couldn't find the examples.pri file!" ) } TARGET = stackedbarchart -SOURCES += main.cpp \ - chartwidget.cpp -HEADERS += \ - chartwidget.h - +SOURCES += main.cpp \ No newline at end of file diff --git a/examples/stackedbarchartdrilldown/chartwidget.cpp b/examples/stackedbarchartdrilldown/chartwidget.cpp index d6c7532..266b5fa 100644 --- a/examples/stackedbarchartdrilldown/chartwidget.cpp +++ b/examples/stackedbarchartdrilldown/chartwidget.cpp @@ -1,6 +1,6 @@ #include "chartwidget.h" -ChartWidget::ChartWidget(QWidget *parent) : +ChartView::ChartView(QWidget *parent) : QChartView(parent) { } diff --git a/examples/stackedbarchartdrilldown/chartwidget.h b/examples/stackedbarchartdrilldown/chartwidget.h index b5625e3..e22e5dc 100644 --- a/examples/stackedbarchartdrilldown/chartwidget.h +++ b/examples/stackedbarchartdrilldown/chartwidget.h @@ -6,11 +6,11 @@ QTCOMMERCIALCHART_USE_NAMESPACE -class ChartWidget : public QChartView +class ChartView : public QChartView { Q_OBJECT public: - explicit ChartWidget(QWidget *parent = 0); + explicit ChartView(QWidget *parent = 0); signals: diff --git a/examples/zoomlinechart/chartwidget.cpp b/examples/zoomlinechart/chartwidget.cpp deleted file mode 100644 index 50d0937..0000000 --- a/examples/zoomlinechart/chartwidget.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "chartwidget.h" -#include - -ChartWidget::ChartWidget(QWidget *parent) - : QChartView(parent), - m_rubberBand(QRubberBand::Rectangle,this) -{ -} - -void ChartWidget::mousePressEvent(QMouseEvent *event) -{ - if(event->button()!=Qt::LeftButton) return; - - int margin = 25; - QRect rect(margin,margin,width()-2*margin,height()-2*margin); - - m_origin = event->pos(); - - if (!rect.contains(m_origin)) return; - - m_rubberBand.setGeometry(QRect(m_origin, QSize())); - m_rubberBand.show(); - - event->accept(); -} - -void ChartWidget::mouseMoveEvent(QMouseEvent *event) -{ - if(m_rubberBand.isVisible()) - m_rubberBand.setGeometry(QRect(m_origin, event->pos()).normalized()); -} - -void ChartWidget::mouseReleaseEvent(QMouseEvent *event) -{ - if( event->button()==Qt::LeftButton && m_rubberBand.isVisible()) { - m_rubberBand.hide(); - - QRect rect = m_rubberBand.geometry(); - zoomIn(rect); - event->accept(); - } - - if(event->button()==Qt::RightButton) { - zoomOut(); - } -} - - -void ChartWidget::keyPressEvent(QKeyEvent *event) -{ - switch (event->key()) { - case Qt::Key_Plus: - zoomIn(); - break; - case Qt::Key_Minus: - zoomOut(); - break; - case Qt::Key_Left: - scrollLeft(); - break; - case Qt::Key_Right: - scrollRight(); - break; - case Qt::Key_Up: - scrollUp(); - break; - case Qt::Key_Down: - scrollDown(); - break; - default: - QGraphicsView::keyPressEvent(event); - break; - } -} diff --git a/examples/zoomlinechart/chartwidget.h b/examples/zoomlinechart/chartwidget.h deleted file mode 100644 index b696287..0000000 --- a/examples/zoomlinechart/chartwidget.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef CHARTWIDGET_H -#define CHARTWIDGET_H -#include -#include - -QTCOMMERCIALCHART_USE_NAMESPACE - -class ChartWidget : public QChartView -{ - Q_OBJECT - -public: - ChartWidget(QWidget *parent = 0); - -protected: - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void keyPressEvent(QKeyEvent *event); - -private: - bool rubberBandIsShown; - QRubberBand m_rubberBand; - QPoint m_origin; - -}; - -#endif diff --git a/examples/zoomlinechart/main.cpp b/examples/zoomlinechart/main.cpp index 2fefb9e..a44a3ac 100644 --- a/examples/zoomlinechart/main.cpp +++ b/examples/zoomlinechart/main.cpp @@ -1,45 +1,87 @@ -#include "chartwidget.h" +/**************************************************************************** + ** + ** 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:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Digia nor the names of its contributors + ** may be used to endorse or promote products derived from this + ** software without specific prior written permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** + ****************************************************************************/ + +#include "chartview.h" #include #include #include -#include QTCOMMERCIALCHART_USE_NAMESPACE -#define PI 3.14159265358979 - int main(int argc, char *argv[]) { QApplication a(argc, argv); - QMainWindow window; - +//![1] QLineSeries* series0 = new QLineSeries(); QPen blue(Qt::blue); blue.setWidth(3); series0->setPen(blue); + QLineSeries* series1 = new QLineSeries(); QPen red(Qt::red); red.setWidth(3); series1->setPen(red); +//![1] +//![2] + *series0 << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10, 5); + *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2); +//![2] +//![3] + QChart* chart = new QChart(); - int numPoints = 100; - - for (int x = 0; x <= numPoints; ++x) { - series0->add(x, fabs(sin(PI/50*x)*100)); - series1->add(x, fabs(cos(PI/50*x)*100)); - } - - ChartWidget* chartWidget = new ChartWidget(&window); - chartWidget->setRenderHint(QPainter::Antialiasing); - chartWidget->setChartTitle("Zoom in/out line chart example"); - chartWidget->setAnimationOptions(QChart::AllAnimations); - chartWidget->addSeries(series0); - chartWidget->addSeries(series1); - - window.setCentralWidget(chartWidget); - window.resize(400, 300); - window.show(); - + chart->addSeries(series0); + chart->addSeries(series1); + chart->setTitle("Zoom in/out chart example"); + chart->setAnimationOptions(QChart::AllAnimations); +//![3] +//![4] + ChartView* chartView = new ChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); +//![4] +//![5] + QMainWindow window; + window.setCentralWidget(chartView); + window.resize(400, 300); + window.show(); +//![5] return a.exec(); } diff --git a/examples/zoomlinechart/zoomlinechart.pro b/examples/zoomlinechart/zoomlinechart.pro index 8f1ef10..3e6f937 100644 --- a/examples/zoomlinechart/zoomlinechart.pro +++ b/examples/zoomlinechart/zoomlinechart.pro @@ -2,8 +2,8 @@ error( "Couldn't find the examples.pri file!" ) } TARGET = zoomlinechart -HEADERS += chartwidget.h -SOURCES += main.cpp chartwidget.cpp +HEADERS += chartview.h +SOURCES += main.cpp chartview.cpp