##// END OF EJS Templates
merge fix
Marek Rosa -
r383:0e6beaefdebb merge
parent child
Show More
@@ -0,0 +1,36
1 #include "qpercentbarseries.h"
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
5 /*!
6 \class QPercentBarSeries
7 \brief part of QtCommercial chart API.
8
9 QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage
10 of all bars in category. One QPercentBarSeries can contain multible QBarSet data sets.
11 QBarSeries groups the data from sets to categories, which are defined by QStringList.
12
13 \mainclass
14
15 \sa QBarSet, QStackedBarSeries, QBarSeries
16 */
17
18 /*!
19 \fn virtual QSeriesType QPercentBarSeries::type() const
20 \brief Returns type of series.
21 \sa QSeries, QSeriesType
22 */
23
24 /*!
25 Constructs empty QPercentBarSeries. Parameter \a category defines the categories for chart.
26 QPercentBarSeries is QObject which is a child of a \a parent.
27 */
28 QPercentBarSeries::QPercentBarSeries(QStringList categories, QObject *parent)
29 : QBarSeries(categories, parent)
30 {
31 }
32
33 #include "moc_qpercentbarseries.cpp"
34
35 QTCOMMERCIALCHART_END_NAMESPACE
36
@@ -0,0 +1,21
1 #ifndef PERCENTBARSERIES_H
2 #define PERCENTBARSERIES_H
3
4 #include <QStringList>
5 #include "qbarseries.h"
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
9 class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries
10 {
11 Q_OBJECT
12 public:
13 QPercentBarSeries(QStringList categories, QObject* parent=0);
14
15 virtual QSeriesType type() const { return QSeries::SeriesTypePercentBar; }
16 };
17
18 QTCOMMERCIALCHART_END_NAMESPACE
19
20
21 #endif // PERCENTBARSERIES_H
@@ -0,0 +1,36
1 #include "qstackedbarseries.h"
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
5 /*!
6 \class QStackedBarSeries
7 \brief part of QtCommercial chart API.
8
9 QStackedBarSeries represents a series of data shown as bars. All bars in same category are
10 stacked on top of each other. One QStackedBarSeries can contain multible QBarSet data sets.
11 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
12
13 \mainclass
14
15 \sa QBarSet, QPercentBarSeries, QBarSeries
16 */
17
18 /*!
19 \fn virtual QSeriesType QStackedBarSeries::type() const
20 \brief Returns type of series.
21 \sa QSeries, QSeriesType
22 */
23
24 /*!
25 Constructs empty QStackedBarSeries. Parameter \a category defines the categories for chart.
26 QStackedBarSeries is QObject which is a child of a \a parent.
27 */
28 QStackedBarSeries::QStackedBarSeries(QStringList categories, QObject *parent)
29 : QBarSeries(categories, parent)
30 {
31 }
32
33 #include "moc_qstackedbarseries.cpp"
34
35 QTCOMMERCIALCHART_END_NAMESPACE
36
@@ -0,0 +1,20
1 #ifndef STACKEDBARSERIES_H
2 #define STACKEDBARSERIES_H
3
4 #include <QStringList>
5 #include "qbarseries.h"
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
9 class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries
10 {
11 Q_OBJECT
12 public:
13 QStackedBarSeries(QStringList categories, QObject* parent=0);
14
15 virtual QSeriesType type() const { return QSeries::SeriesTypeStackedBar; }
16 };
17
18 QTCOMMERCIALCHART_END_NAMESPACE
19
20 #endif // STACKEDBARSERIES_H
@@ -13,8 +13,8 integrated_build:{
13
13
14 CONFIG += ordered
14 CONFIG += ordered
15 QMAKE_CXXFLAGS += -g -Wall
15 QMAKE_CXXFLAGS += -g -Wall
16 unix:QMAKE_DISTCLEAN += -r build bin doc/html
16 unix:QMAKE_DISTCLEAN += -r build bin include lib doc/html
17 win32:QMAKE_DISTCLEAN += /Q /s build bin doc\\html
17 win32:QMAKE_DISTCLEAN += /Q /s build bin include lib doc\\html
18
18
19 # install feature file
19 # install feature file
20 feature.path = $$[QT_INSTALL_DATA]/mkspecs/features
20 feature.path = $$[QT_INSTALL_DATA]/mkspecs/features
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -13,19 +13,18
13 <tr>
13 <tr>
14 <td valign="top">
14 <td valign="top">
15 <ul>
15 <ul>
16 <li><a href="qbarcategory.html">QBarCategory</a></li>
16 <li><a href="qbarseries.html">QBarSeries</a></li>
17 <li><a href="qbarchartseries.html">QBarChartSeries</a></li>
18 <li><a href="qbarset.html">QBarSet</a></li>
17 <li><a href="qbarset.html">QBarSet</a></li>
19 <li><a href="qchart.html">QChart</a></li>
18 <li><a href="qchart.html">QChart</a></li>
20 <li><a href="qchartaxis.html">QChartAxis</a></li>
19 <li><a href="qchartaxis.html">QChartAxis</a></li>
21 <li><a href="qchartseries.html">QChartSeries</a></li>
22 <li><a href="qchartview.html">QChartView</a></li>
20 <li><a href="qchartview.html">QChartView</a></li>
23 <li><a href="qlinechartseries.html">QLineChartSeries</a></li>
21 <li><a href="qlineseries.html">QLineSeries</a></li>
24 <li><a href="qpercentbarchartseries.html">QPercentBarChartSeries</a></li>
22 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
25 <li><a href="qpieseries.html">QPieSeries</a></li>
23 <li><a href="qpieseries.html">QPieSeries</a></li>
26 <li><a href="qpieslice.html">QPieSlice</a></li>
24 <li><a href="qpieslice.html">QPieSlice</a></li>
27 <li><a href="qscatterseries.html">QScatterSeries</a></li>
25 <li><a href="qscatterseries.html">QScatterSeries</a></li>
28 <li><a href="qstackedbarchartseries.html">QStackedBarChartSeries</a></li>
26 <li><a href="qseries.html">QSeries</a></li>
27 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
29 </ul>
28 </ul>
30 </td>
29 </td>
31 </tr>
30 </tr>
@@ -5,5 +5,22
5
5
6 The example shows how to create simple line chart.
6 The example shows how to create simple line chart.
7
7
8 ...
8 \image linechart.png
9
10 To create line charts, QLineSeries instance is needed. Here we create two line series and we set the color and width of line.
11
12 \snippet ../example/linechart/main.cpp 1
13
14 We add data to be shown to both series. We can use add() member function or use stream operator.
15
16 \snippet ../example/linechart/main.cpp 2
17
18 In the end we create QChartView instance, set title, set anti-aliasing and add both series.
19
20 \snippet ../example/linechart/main.cpp 3
21
22 Chart is ready to be shown.
23
24 \snippet ../example/linechart/main.cpp 4
25
9 */ No newline at end of file
26 */
@@ -7,17 +7,21
7 <img src="images/qt_commercial_logo.png" alt="qtcommercial"/>
7 <img src="images/qt_commercial_logo.png" alt="qtcommercial"/>
8
8
9 <p>
9 <p>
10 QCharts is a part of Qt Commercial addons package. It provides a set of simple chart components which are available for Qt Commercial customers.
10 QCharts is a part of Qt Commercial addons package. It provides a set of easy to use chart
11 It uses Qt Graphics View Framework, therefore charts can be easily integrated 2D modern user interfaces. QCharts can be used as QWidgets, QGraphicsWidget or QML elements.
11 components which are available for Qt Commercial customers. It uses Qt Graphics View
12 Users can easily create impressive graphs by selecting one of the charts themes.
12 Framework, therefore charts can be easily integrated to modern 2D user interfaces. QCharts can
13 be used as QWidgets, QGraphicsWidget or QML elements. Users can easily create impressive
14 graphs by selecting one of the charts themes.
13 </p>
15 </p>
16
14 <table><tr>
17 <table><tr>
15 <td><img src="images/linechart.png" alt="linechart" /></td>
18 <td><a href="example-linechart.html"><img src="images/linechart.png" alt="linechart" /></a></td>
16 <td><img src="images/chartview_example_bar.jpg " alt="barchart" /></td>
19 <td><img src="images/chartview_example_bar.jpg " alt="barchart" /></td>
17 <td><img src="images/chartview_example_pie.jpg " alt="piechart" /></td>
18 </tr>
20 </tr>
19 <tr>
21 <tr>
20 <td><img src="images/chartview_example.jpg " alt="linechart" /></td>
22 <td><img src="images/chartview_example.jpg " alt="linechart" /></td>
23 <td><img src="images/chartview_example_pie.jpg " alt="piechart" /></td>
24 </tr><tr>
21 <td><img src="images/chartview_example_scatter.jpg " alt="scatterchart" /></td>
25 <td><img src="images/chartview_example_scatter.jpg " alt="scatterchart" /></td>
22 <td><img src="images/chartview_example_theme.jpg " alt="themechart" /></td>
26 <td><img src="images/chartview_example_theme.jpg " alt="themechart" /></td>
23 </tr>
27 </tr>
@@ -3,10 +3,12
3
3
4 .qchart
4 .qchart
5 {
5 {
6 width: 80%;
6 width:1000px;
7 margin-left: auto;
7 margin-left: auto;
8 margin-right: auto;
8 margin-right: auto;
9 margin-top: 50px;
9 margin-top: 50px;
10 max-width:100%;
11 overflow-x: auto;
10 }
12 }
11
13
12 .qchart img
14 .qchart img
@@ -16,13 +18,16
16
18
17 .qchart table
19 .qchart table
18 {
20 {
21 width:1000px;
19 margin-top: 50px;
22 margin-top: 50px;
23 max-width:100%;
20 }
24 }
21
25
22 /* basic elements */
26 /* basic elements */
23 html
27 html
24 {
28 {
25 color: #000000;
29 color: #000000;
30 min-width: 1000px;
26 background: #FFFFFF;
31 background: #FFFFFF;
27 }
32 }
28 table
33 table
@@ -1,7 +1,7
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qlinechartseries.h>
4 #include <qlineseries.h>
5 #include <qchart.h>
5 #include <qchart.h>
6 #include <qchartaxis.h>
6 #include <qchartaxis.h>
7 #include <cmath>
7 #include <cmath>
@@ -16,11 +16,11 int main(int argc, char *argv[])
16
16
17 QMainWindow window;
17 QMainWindow window;
18
18
19 QLineChartSeries* series0 = new QLineChartSeries();
19 QLineSeries* series0 = new QLineSeries();
20 QPen blue(Qt::blue);
20 QPen blue(Qt::blue);
21 blue.setWidth(3);
21 blue.setWidth(3);
22 series0->setPen(blue);
22 series0->setPen(blue);
23 QLineChartSeries* series1 = new QLineChartSeries();
23 QLineSeries* series1 = new QLineSeries();
24 QPen red(Qt::red);
24 QPen red(Qt::red);
25 red.setWidth(3);
25 red.setWidth(3);
26 series1->setPen(red);
26 series1->setPen(red);
@@ -1,9 +1,9
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qbarchartseries.h>
4 #include <qbarseries.h>
5 #include <qbarset.h>
5 #include <qbarset.h>
6 #include <qbarcategory.h>
6 #include <QStringList>
7
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
9
@@ -13,9 +13,9 int main(int argc, char *argv[])
13 QMainWindow window;
13 QMainWindow window;
14
14
15 //! [1]
15 //! [1]
16 // Create category
16 // Define categories
17 QBarCategory *category = new QBarCategory;
17 QStringList catecories;
18 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18 catecories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
19 //! [1]
19 //! [1]
20
20
21 //! [2]
21 //! [2]
@@ -36,7 +36,7 int main(int argc, char *argv[])
36
36
37 //! [3]
37 //! [3]
38 // Create series and add sets to it
38 // Create series and add sets to it
39 QBarChartSeries* series= new QBarChartSeries(category);
39 QBarSeries* series= new QBarSeries(catecories);
40
40
41 series->addBarSet(set0);
41 series->addBarSet(set0);
42 series->addBarSet(set1);
42 series->addBarSet(set1);
@@ -47,8 +47,8 int main(int argc, char *argv[])
47
47
48 //! [4]
48 //! [4]
49 // Enable some features
49 // Enable some features
50 series->enableToolTip();
50 series->setToolTipEnabled();
51 series->enableFloatingValues();
51 series->setFloatingValuesEnabled();
52 //! [4]
52 //! [4]
53
53
54 //! [5]
54 //! [5]
@@ -2,12 +2,12
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartglobal.h>
3 #include <qchartglobal.h>
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qlinechartseries.h>
5 #include <qlineseries.h>
6 #include <qscatterseries.h>
6 #include <qscatterseries.h>
7 #include <qbarchartseries.h>
7 #include <qbarseries.h>
8 #include <qbarset.h>
8 #include <qbarset.h>
9 #include <qbarcategory.h>
10 #include <qpieseries.h>
9 #include <qpieseries.h>
10 #include <QStringList>
11
11
12 QTCOMMERCIALCHART_USE_NAMESPACE
12 QTCOMMERCIALCHART_USE_NAMESPACE
13
13
@@ -19,19 +19,22 int main(int argc, char *argv[])
19 // Create chart view
19 // Create chart view
20 QChartView *chartView = new QChartView();
20 QChartView *chartView = new QChartView();
21 chartView->setRenderHint(QPainter::Antialiasing);
21 chartView->setRenderHint(QPainter::Antialiasing);
22 chartView->setChartTitle("Simple Line Chart");
22 // Add series to the chart
23 // Add series to the chart
23 QLineChartSeries *line = new QLineChartSeries();
24 QLineSeries *line = new QLineSeries();
24 line->add(0.0, 0.8);
25 line->add(0.0, 0.8);
25 line->add(1.1, 1.1);
26 line->add(1.1, 1.1);
26 line->add(2.0, 2.5);
27 line->add(2.0, 2.5);
27 chartView->addSeries(line);
28 chartView->addSeries(line);
28 //! [1]
29 //! [1]
29
30
31 chartView->setChartTitle("\'Scietific\' theme");
30 //! [2]
32 //! [2]
31 // Change theme
33 // Change theme
32 chartView->setChartTheme(QChart::ChartThemeScientific);
34 chartView->setChartTheme(QChart::ChartThemeScientific);
33 //! [2]
35 //! [2]
34
36
37 chartView->setChartTitle("Simple Pie Chart");
35 //! [3]
38 //! [3]
36 // Add pie series
39 // Add pie series
37 // ...
40 // ...
@@ -41,6 +44,7 int main(int argc, char *argv[])
41 chartView->addSeries(pie);
44 chartView->addSeries(pie);
42 //! [3]
45 //! [3]
43
46
47 chartView->setChartTitle("Simple Scatter Chart");
44 //! [4]
48 //! [4]
45 // Add scatter series
49 // Add scatter series
46 // ...
50 // ...
@@ -52,14 +56,15 int main(int argc, char *argv[])
52 chartView->addSeries(scatter);
56 chartView->addSeries(scatter);
53 //! [4]
57 //! [4]
54
58
59 chartView->setChartTitle("Simple Bar Chart");
55 //! [5]
60 //! [5]
56 // ...
61 // ...
57 // Add bar series
62 // Add bar series
58 QBarCategory *barCategory = new QBarCategory();
63 QStringList barCategory;
59 *barCategory << "Jan"
64 barCategory << "Jan"
60 << "Feb"
65 << "Feb"
61 << "Mar";
66 << "Mar";
62 QBarChartSeries *bar = new QBarChartSeries(barCategory);
67 QBarSeries *bar = new QBarSeries(barCategory);
63 QBarSet *barSet = new QBarSet("Sales");
68 QBarSet *barSet = new QBarSet("Sales");
64 *barSet << 123.2
69 *barSet << 123.2
65 << 301.3
70 << 301.3
@@ -69,8 +74,9 int main(int argc, char *argv[])
69 //! [5]
74 //! [5]
70
75
71 QMainWindow w;
76 QMainWindow w;
72 w.resize(380, 250);
77 w.resize(400, 300);
73 w.setCentralWidget(chartView);
78 w.setCentralWidget(chartView);
79 w.setWindowFlags(Qt::FramelessWindowHint);
74 w.show();
80 w.show();
75
81
76 return a.exec();
82 return a.exec();
@@ -1,7 +1,7
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qlinechartseries.h>
4 #include <qlineseries.h>
5 #include <qchart.h>
5 #include <qchart.h>
6 #include <cmath>
6 #include <cmath>
7
7
@@ -15,11 +15,11 int main(int argc, char *argv[])
15
15
16 QMainWindow window;
16 QMainWindow window;
17
17
18 QLineChartSeries* series0 = new QLineChartSeries();
18 QLineSeries* series0 = new QLineSeries();
19 QPen blue(Qt::blue);
19 QPen blue(Qt::blue);
20 blue.setWidth(3);
20 blue.setWidth(3);
21 series0->setPen(blue);
21 series0->setPen(blue);
22 QLineChartSeries* series1 = new QLineChartSeries();
22 QLineSeries* series1 = new QLineSeries();
23 QPen red(Qt::red);
23 QPen red(Qt::red);
24 red.setWidth(3);
24 red.setWidth(3);
25 series1->setPen(red);
25 series1->setPen(red);
@@ -1,7 +1,7
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qlinechartseries.h>
4 #include <qlineseries.h>
5 #include <qchart.h>
5 #include <qchart.h>
6 #include <cmath>
6 #include <cmath>
7 #include "wavegenerator.h"
7 #include "wavegenerator.h"
@@ -13,11 +13,11 int main(int argc, char *argv[])
13
13
14 QMainWindow window;
14 QMainWindow window;
15
15
16 QLineChartSeries* series0 = new QLineChartSeries();
16 QLineSeries* series0 = new QLineSeries();
17 QPen blue(Qt::blue);
17 QPen blue(Qt::blue);
18 blue.setWidth(3);
18 blue.setWidth(3);
19 series0->setPen(blue);
19 series0->setPen(blue);
20 QLineChartSeries* series1 = new QLineChartSeries();
20 QLineSeries* series1 = new QLineSeries();
21 QPen red(Qt::red);
21 QPen red(Qt::red);
22 red.setWidth(3);
22 red.setWidth(3);
23 series1->setPen(red);
23 series1->setPen(red);
@@ -2,7 +2,7
2 #include <QTime>
2 #include <QTime>
3 #include <QObject>
3 #include <QObject>
4 #include <cmath>
4 #include <cmath>
5 #include <qlinechartseries.h>
5 #include <qlineseries.h>
6
6
7 QTCOMMERCIALCHART_USE_NAMESPACE
7 QTCOMMERCIALCHART_USE_NAMESPACE
8
8
@@ -14,7 +14,7 class WaveGenerator: public QObject
14 Q_OBJECT
14 Q_OBJECT
15
15
16 public:
16 public:
17 WaveGenerator(QLineChartSeries* series1, QLineChartSeries* series2) :
17 WaveGenerator(QLineSeries* series1, QLineSeries* series2) :
18 m_series1(series1),
18 m_series1(series1),
19 m_series2(series2),
19 m_series2(series2),
20 m_wave(0),
20 m_wave(0),
@@ -44,16 +44,16 public slots:
44
44
45 for (qreal i = 0, x = 0; x <= 2*PI; x+=m_step, i++) {
45 for (qreal i = 0, x = 0; x <= 2*PI; x+=m_step, i++) {
46 fluctuate = qrand() % 100;
46 fluctuate = qrand() % 100;
47 m_series1->set(i, x, fabs(sin(x)*fluctuate));
47 m_series1->replace(x, fabs(sin(x)*fluctuate));
48 fluctuate = qrand() % 100;
48 fluctuate = qrand() % 100;
49 m_series2->set(i, x, fabs(cos(x)*fluctuate));
49 m_series2->replace(x, fabs(cos(x)*fluctuate));
50 }
50 }
51
51
52 }
52 }
53
53
54 private:
54 private:
55 QLineChartSeries* m_series1;
55 QLineSeries* m_series1;
56 QLineChartSeries* m_series2;
56 QLineSeries* m_series2;
57 int m_wave;
57 int m_wave;
58 qreal m_step;
58 qreal m_step;
59 QTimer m_timer;
59 QTimer m_timer;
@@ -13,12 +13,12
13 #include <qscatterseries.h>
13 #include <qscatterseries.h>
14 #include <qchartview.h>
14 #include <qchartview.h>
15 #include <qchartaxis.h>
15 #include <qchartaxis.h>
16 #include <qbarcategory.h>
17 #include <qbarset.h>
16 #include <qbarset.h>
18 #include <QListWidget>
17 #include <QListWidget>
19 #include <QPrinter>
18 #include <QPrinter>
20 #include <QPrintDialog>
19 #include <QPrintDialog>
21 #include <QRadioButton>
20 #include <QRadioButton>
21 #include <QStringList>
22
22
23 QTCOMMERCIALCHART_USE_NAMESPACE
23 QTCOMMERCIALCHART_USE_NAMESPACE
24
24
@@ -122,10 +122,11 void Widget::refreshChart()
122 if (barChartRadioButton->isChecked())
122 if (barChartRadioButton->isChecked())
123 {
123 {
124 // use the sorted selected coutries list to initialize BarCategory
124 // use the sorted selected coutries list to initialize BarCategory
125 QBarCategory* category = new QBarCategory;
125 QStringList category;
126 for (int i = 0; i < selectedCountriesStrings.size(); i++)
126 for (int i = 0; i < selectedCountriesStrings.size(); i++)
127 *category << selectedCountriesStrings[i];
127 category << selectedCountriesStrings[i];
128 QBarChartSeries* series0 = new QBarChartSeries(category);
128 QBarChartSeries* series0 = new QBarChartSeries(category);
129 series0 = new QBarSeries(category);
129
130
130 // prepare the selected counries SQL query
131 // prepare the selected counries SQL query
131 QString countriesQuery = "country IN (";
132 QString countriesQuery = "country IN (";
@@ -3,7 +3,6
3
3
4 #include <QtGui/QWidget>
4 #include <QtGui/QWidget>
5 #include <qchartview.h>
5 #include <qchartview.h>
6 #include <qbarchartseries.h>
7 #include <QSqlDatabase>
6 #include <QSqlDatabase>
8
7
9 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -28,7 +27,6 private:
28 QListWidget* countrieslist;
27 QListWidget* countrieslist;
29 QListWidget* yearslist;
28 QListWidget* yearslist;
30 QSqlDatabase db;
29 QSqlDatabase db;
31 // QBarChartSeries* series0;
32 QRadioButton* barChartRadioButton;
30 QRadioButton* barChartRadioButton;
33 QRadioButton* scatterChartRadioButton;
31 QRadioButton* scatterChartRadioButton;
34 };
32 };
@@ -1,7 +1,7
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qlinechartseries.h>
4 #include <qlineseries.h>
5 #include <qchart.h>
5 #include <qchart.h>
6 #include <cmath>
6 #include <cmath>
7
7
@@ -11,16 +11,14 int main(int argc, char *argv[])
11 {
11 {
12 QApplication a(argc, argv);
12 QApplication a(argc, argv);
13
13
14 QMainWindow window;
15
16 //![1]
14 //![1]
17
15
18 QLineChartSeries* series0 = new QLineChartSeries();
16 QLineSeries* series0 = new QLineSeries();
19 QPen blue(Qt::blue);
17 QPen blue(Qt::blue);
20 blue.setWidth(3);
18 blue.setWidth(3);
21 series0->setPen(blue);
19 series0->setPen(blue);
22
20
23 QLineChartSeries* series1 = new QLineChartSeries();
21 QLineSeries* series1 = new QLineSeries();
24 QPen red(Qt::red);
22 QPen red(Qt::red);
25 red.setWidth(3);
23 red.setWidth(3);
26 series1->setPen(red);
24 series1->setPen(red);
@@ -33,24 +31,23 int main(int argc, char *argv[])
33 series0->add(7, 4);
31 series0->add(7, 4);
34 series0->add(10,5);
32 series0->add(10,5);
35
33
36 series1->add(1, 1);
34 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10,2);
37 series1->add(3, 3);
38 series1->add(7, 6);
39 series1->add(8, 3);
40 series1->add(10,2);
41 //![2]
35 //![2]
42 //![3]
36 //![3]
37 QMainWindow window;
43 QChartView* chartView = new QChartView(&window);
38 QChartView* chartView = new QChartView(&window);
44
39
45 chartView->setRenderHint(QPainter::Antialiasing);
46 chartView->setChartTitle("Basic line chart example");
40 chartView->setChartTitle("Basic line chart example");
41 chartView->setRenderHint(QPainter::Antialiasing);
42
47 chartView->addSeries(series0);
43 chartView->addSeries(series0);
48 chartView->addSeries(series1);
44 chartView->addSeries(series1);
49 //![3]
45 //![3]
50
46 //![4]
51 window.setCentralWidget(chartView);
47 window.setCentralWidget(chartView);
52 window.resize(400, 300);
48 window.resize(400, 300);
53 window.show();
49 window.show();
50 //![4]
54
51
55 return a.exec();
52 return a.exec();
56 }
53 }
@@ -1,10 +1,10
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <QStandardItemModel>
3 #include <QStandardItemModel>
4 #include <qpercentbarchartseries.h>
4 #include <qpercentbarseries.h>
5 #include <qbarcategory.h>
6 #include <qchartview.h>
5 #include <qchartview.h>
7 #include <qbarset.h>
6 #include <qbarset.h>
7 #include <QStringList>
8
8
9 QTCOMMERCIALCHART_USE_NAMESPACE
9 QTCOMMERCIALCHART_USE_NAMESPACE
10
10
@@ -14,9 +14,9 int main(int argc, char *argv[])
14 QMainWindow window;
14 QMainWindow window;
15
15
16 //! [1]
16 //! [1]
17 // Create category
17 // Define categories
18 QBarCategory *category = new QBarCategory;
18 QStringList categories;
19 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
19 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
20 //! [1]
20 //! [1]
21
21
22 //! [2]
22 //! [2]
@@ -36,7 +36,7 int main(int argc, char *argv[])
36
36
37 //! [3]
37 //! [3]
38 // Create series and add sets to it
38 // Create series and add sets to it
39 QPercentBarChartSeries* series = new QPercentBarChartSeries(category);
39 QPercentBarSeries* series = new QPercentBarSeries(categories);
40
40
41 series->addBarSet(set0);
41 series->addBarSet(set0);
42 series->addBarSet(set1);
42 series->addBarSet(set1);
@@ -47,8 +47,8 int main(int argc, char *argv[])
47
47
48 //! [4]
48 //! [4]
49 // Enable features
49 // Enable features
50 series->enableToolTip();
50 series->setToolTipEnabled();
51 series->enableFloatingValues();
51 series->setFloatingValuesEnabled();
52 //! [4]
52 //! [4]
53
53
54 //! [5]
54 //! [5]
@@ -4,7 +4,6
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qpieseries.h>
5 #include <qpieseries.h>
6 #include <qpieslice.h>
6 #include <qpieslice.h>
7 #include "customslice.h"
8
7
9 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
10
9
@@ -14,23 +13,22 int main(int argc, char *argv[])
14
13
15 QMainWindow window;
14 QMainWindow window;
16
15
16 QChartView* chartView = new QChartView(&window);
17
18 //! [1]
17 QPieSeries *series = new QPieSeries();
19 QPieSeries *series = new QPieSeries();
18 series->add(5, "Slice 1");
20 series->add(1, "Slice 1");
19 series->add(2, "Slice 2");
21 series->add(2, "Slice 2");
20 series->add(3, "Slice 3");
22 series->add(3, "Slice 3");
21 series->add(4, "Slice 4");
23 series->add(4, "Slice 4");
22 series->add(5, "Slice 5");
24 series->add(5, "Slice 5");
23 series->add(6, "Slice 6");
24 series->add(7, "Slice 7");
25 series->add(new CustomSlice(8));
26 series->enableClickExplodes(true);
27 series->enableHoverHighlight(true);
28
29 QChartView* chartView = new QChartView(&window);
30 chartView->setRenderHint(QPainter::Antialiasing);
31 chartView->setChartTheme(QChart::ChartThemeIcy);
32 chartView->setChartTitle("Simple piechart");
33 chartView->addSeries(series);
25 chartView->addSeries(series);
26 //! [1]
27
28 //! [2]
29 series->enableHoverHighlight(true);
30 series->enableClickExplodes(true);
31 //! [2]
34
32
35 window.setCentralWidget(chartView);
33 window.setCentralWidget(chartView);
36 window.resize(600, 600);
34 window.resize(600, 600);
@@ -2,7 +2,7
2 error( "Couldn't find the example.pri file!" )
2 error( "Couldn't find the example.pri file!" )
3 }
3 }
4 TARGET = piechart
4 TARGET = piechart
5 SOURCES += main.cpp customslice.cpp
5 SOURCES += main.cpp
6 HEADERS += customslice.h
6 HEADERS +=
7
7
8
8
@@ -1,5 +1,5
1 #include "chartview.h"
1 #include "chartview.h"
2 #include <qlinechartseries.h>
2 #include <qlineseries.h>
3 #include <QTime>
3 #include <QTime>
4
4
5 ChartView::ChartView(QWidget* parent):QChartView(parent),
5 ChartView::ChartView(QWidget* parent):QChartView(parent),
@@ -11,15 +11,15 m_index(0)
11 QTime now = QTime::currentTime();
11 QTime now = QTime::currentTime();
12 qsrand((uint)now.msec());
12 qsrand((uint)now.msec());
13
13
14 QLineChartSeries* series0 = new QLineChartSeries();
14 QLineSeries* series0 = new QLineSeries();
15 QPen blue(Qt::blue);
15 QPen blue(Qt::blue);
16 blue.setWidth(3);
16 blue.setWidth(3);
17 series0->setPen(blue);
17 series0->setPen(blue);
18 QLineChartSeries* series1 = new QLineChartSeries();
18 QLineSeries* series1 = new QLineSeries();
19 QPen red(Qt::red);
19 QPen red(Qt::red);
20 red.setWidth(3);
20 red.setWidth(3);
21 series1->setPen(red);
21 series1->setPen(red);
22 QLineChartSeries* series2 = new QLineChartSeries();
22 QLineSeries* series2 = new QLineSeries();
23 QPen green(Qt::green);
23 QPen green(Qt::green);
24 green.setWidth(3);
24 green.setWidth(3);
25 series2->setPen(green);
25 series2->setPen(green);
@@ -18,7 +18,7 public slots:
18
18
19 private:
19 private:
20 QTimer m_timer;
20 QTimer m_timer;
21 QList<QChartSeries*> m_series;
21 QList<QSeries*> m_series;
22 int m_index;
22 int m_index;
23 };
23 };
24
24
@@ -27,14 +27,9 int main(int argc, char *argv[])
27 chartView->addSeries(scatter);
27 chartView->addSeries(scatter);
28 //! [1]
28 //! [1]
29
29
30 // Add some more data
31 //! [2]
32 scatter->addData(QPointF(2.0, 5.5));
33 //! [2]
34
35 // And more
30 // And more
36 //! [3]
31 //! [3]
37 *scatter << QPointF(2.0, 5.5);
32 *scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4);
38 //! [3]
33 //! [3]
39
34
40 // Add another scatter series (re-use the previous pointer)
35 // Add another scatter series (re-use the previous pointer)
@@ -46,14 +41,14 int main(int argc, char *argv[])
46 }
41 }
47 //! [4]
42 //! [4]
48 QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern);
43 QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern);
49 scatter->setMarkerBrush(brush);
44 scatter->setBrush(brush);
50 //! [4]
45 //! [4]
51 //! [5]
46 //! [5]
52 QPen pen(QColor(0, 255, 0, 80), 3);
47 QPen pen(QColor(0, 255, 0, 80), 3);
53 scatter->setMarkerPen(pen);
48 scatter->setPen(pen);
54 //! [5]
49 //! [5]
55 //! [6]
50 //! [6]
56 scatter->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
51 scatter->setShape(QScatterSeries::MarkerShapeRectangle);
57 //! [6]
52 //! [6]
58 chartView->addSeries(scatter);
53 chartView->addSeries(scatter);
59
54
@@ -1,9 +1,9
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qstackedbarchartseries.h>
4 #include <qstackedbarseries.h>
5 #include <qbarset.h>
5 #include <qbarset.h>
6 #include <qbarcategory.h>
6 #include <QStringList>
7
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
9
@@ -13,9 +13,9 int main(int argc, char *argv[])
13 QMainWindow window;
13 QMainWindow window;
14
14
15 //! [1]
15 //! [1]
16 // Create category
16 // Define categories
17 QBarCategory *category = new QBarCategory;
17 QStringList catecories;
18 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18 catecories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
19 //! [1]
19 //! [1]
20
20
21 //! [2]
21 //! [2]
@@ -35,7 +35,7 int main(int argc, char *argv[])
35
35
36 //! [3]
36 //! [3]
37 // Create series and add sets to it
37 // Create series and add sets to it
38 QStackedBarChartSeries* series = new QStackedBarChartSeries(category);
38 QStackedBarSeries* series = new QStackedBarSeries(catecories);
39
39
40 series->addBarSet(set0);
40 series->addBarSet(set0);
41 series->addBarSet(set1);
41 series->addBarSet(set1);
@@ -46,8 +46,8 int main(int argc, char *argv[])
46
46
47 //! [4]
47 //! [4]
48 // Enable features
48 // Enable features
49 series->enableToolTip();
49 series->setToolTipEnabled();
50 series->enableFloatingValues();
50 series->setFloatingValuesEnabled();
51 //! [4]
51 //! [4]
52
52
53 //! [5]
53 //! [5]
@@ -1,7 +1,7
1 #include "chartwidget.h"
1 #include "chartwidget.h"
2 #include <QApplication>
2 #include <QApplication>
3 #include <QMainWindow>
3 #include <QMainWindow>
4 #include <qlinechartseries.h>
4 #include <qlineseries.h>
5 #include <cmath>
5 #include <cmath>
6
6
7 QTCOMMERCIALCHART_USE_NAMESPACE
7 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -14,11 +14,11 int main(int argc, char *argv[])
14
14
15 QMainWindow window;
15 QMainWindow window;
16
16
17 QLineChartSeries* series0 = new QLineChartSeries();
17 QLineSeries* series0 = new QLineSeries();
18 QPen blue(Qt::blue);
18 QPen blue(Qt::blue);
19 blue.setWidth(3);
19 blue.setWidth(3);
20 series0->setPen(blue);
20 series0->setPen(blue);
21 QLineChartSeries* series1 = new QLineChartSeries();
21 QLineSeries* series1 = new QLineSeries();
22 QPen red(Qt::red);
22 QPen red(Qt::red);
23 red.setWidth(3);
23 red.setWidth(3);
24 series1->setPen(red);
24 series1->setPen(red);
@@ -1,7 +1,7
1 #include "declarativelineseries.h"
1 #include "declarativelineseries.h"
2 #include "declarativechart.h"
2 #include "declarativechart.h"
3 #include "qchart.h"
3 #include "qchart.h"
4 #include "qlinechartseries.h"
4 #include "qlineseries.h"
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
@@ -23,7 +23,7 void DeclarativeLineSeries::setParentForSeries()
23 qDebug() << "creating line series for chart: " << chart;
23 qDebug() << "creating line series for chart: " << chart;
24 Q_ASSERT(chart);
24 Q_ASSERT(chart);
25
25
26 m_series = new QLineChartSeries();
26 m_series = new QLineSeries();
27 Q_ASSERT(m_series);
27 Q_ASSERT(m_series);
28 for (int i(0); i < m_data.count(); i++) {
28 for (int i(0); i < m_data.count(); i++) {
29 ScatterElement *element = m_data.at(i);
29 ScatterElement *element = m_data.at(i);
@@ -8,7 +8,7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QChart;
10 class QChart;
11 class QLineChartSeries;
11 class QLineSeries;
12
12
13 class DeclarativeLineSeries : public QDeclarativeItem
13 class DeclarativeLineSeries : public QDeclarativeItem
14 {
14 {
@@ -30,7 +30,7 private slots:
30
30
31 private:
31 private:
32 QChart *m_chart;
32 QChart *m_chart;
33 QLineChartSeries *m_series;
33 QLineSeries *m_series;
34 QList<ScatterElement *> m_data;
34 QList<ScatterElement *> m_data;
35 };
35 };
36
36
@@ -59,7 +59,7 void DeclarativeScatterSeries::appendData(QDeclarativeListProperty<ScatterElemen
59 if (series) {
59 if (series) {
60 series->m_data.append(element);
60 series->m_data.append(element);
61 if (series->m_series)
61 if (series->m_series)
62 series->m_series->addData(QPointF(element->x(), element->y()));
62 series->m_series->add(element->x(), element->y());
63 }
63 }
64 }
64 }
65
65
@@ -95,7 +95,7 void AxisItem::handleAxisUpdate(QChartAxis* axis)
95 setGridOpacity(0);
95 setGridOpacity(0);
96 }
96 }
97
97
98 if(axis->isLabelsVisible())
98 if(axis->labelsVisible())
99 {
99 {
100 setLabelsOpacity(100);
100 setLabelsOpacity(100);
101 }
101 }
@@ -103,7 +103,7 void AxisItem::handleAxisUpdate(QChartAxis* axis)
103 setLabelsOpacity(0);
103 setLabelsOpacity(0);
104 }
104 }
105
105
106 if(axis->isShadesVisible()) {
106 if(axis->shadesVisible()) {
107 setShadesOpacity(axis->shadesOpacity());
107 setShadesOpacity(axis->shadesOpacity());
108 }
108 }
109 else {
109 else {
@@ -8,11 +8,10 SOURCES += \
8 $$PWD/barpresenter.cpp \
8 $$PWD/barpresenter.cpp \
9 $$PWD/barpresenterbase.cpp \
9 $$PWD/barpresenterbase.cpp \
10 $$PWD/percentbarpresenter.cpp \
10 $$PWD/percentbarpresenter.cpp \
11 $$PWD/qbarcategory.cpp \
11 $$PWD/qbarseries.cpp \
12 $$PWD/qbarchartseries.cpp \
13 $$PWD/qbarset.cpp \
12 $$PWD/qbarset.cpp \
14 $$PWD/qpercentbarchartseries.cpp \
13 $$PWD/qpercentbarseries.cpp \
15 $$PWD/qstackedbarchartseries.cpp \
14 $$PWD/qstackedbarseries.cpp \
16 $$PWD/separator.cpp \
15 $$PWD/separator.cpp \
17 $$PWD/stackedbarpresenter.cpp \
16 $$PWD/stackedbarpresenter.cpp \
18 $$PWD/barvalue.cpp
17 $$PWD/barvalue.cpp
@@ -21,18 +20,17 PRIVATE_HEADERS += \
21 $$PWD/bar_p.h \
20 $$PWD/bar_p.h \
22 $$PWD/barchartmodel_p.h \
21 $$PWD/barchartmodel_p.h \
23 $$PWD/barlabel_p.h \
22 $$PWD/barlabel_p.h \
24 $$PWD/barpresenter.h \
23 $$PWD/barpresenter_p.h \
25 $$PWD/barpresenterbase.h \
24 $$PWD/barpresenterbase_p.h \
26 $$PWD/percentbarpresenter.h \
25 $$PWD/percentbarpresenter_p.h \
27 $$PWD/separator_p.h \
26 $$PWD/separator_p.h \
28 $$PWD/stackedbarpresenter.h \
27 $$PWD/stackedbarpresenter_p.h \
29 $$PWD/barvalue_p.h
28 $$PWD/barvalue_p.h
30
29
31 PUBLIC_HEADERS += \
30 PUBLIC_HEADERS += \
32 $$PWD/qbarcategory.h \
31 $$PWD/qbarseries.h \
33 $$PWD/qbarchartseries.h \
34 $$PWD/qbarset.h \
32 $$PWD/qbarset.h \
35 $$PWD/qpercentbarchartseries.h \
33 $$PWD/qpercentbarseries.h \
36 $$PWD/qstackedbarchartseries.h
34 $$PWD/qstackedbarseries.h
37
35
38
36
@@ -2,26 +2,19
2 #include <QVector>
2 #include <QVector>
3 #include <QDebug>
3 #include <QDebug>
4 #include "barchartmodel_p.h"
4 #include "barchartmodel_p.h"
5 #include "qbarcategory.h"
6 #include "qbarset.h"
5 #include "qbarset.h"
7
6
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
8
10 BarChartModel::BarChartModel(QBarCategory *category, QObject *parent) :
9 BarChartModel::BarChartModel(QStringList categories, QObject *parent) :
11 QObject(parent)
10 QObject(parent)
12 ,mCategory(category)
11 ,mCategory(categories)
13 {
12 {
14 }
13 }
15
14
16 BarChartModel::~BarChartModel()
15 QStringList BarChartModel::category()
17 {
16 {
18 delete mCategory;
17 return mCategory;
19 }
20
21
22 QBarCategory& BarChartModel::category()
23 {
24 return *mCategory;
25 }
18 }
26
19
27 void BarChartModel::addBarSet(QBarSet *set)
20 void BarChartModel::addBarSet(QBarSet *set)
@@ -36,32 +29,25 void BarChartModel::removeBarSet(QBarSet *set)
36 }
29 }
37 }
30 }
38
31
39 QBarSet* BarChartModel::nextSet(bool getFirst)
32 QBarSet* BarChartModel::setAt(int index)
40 {
33 {
41 if (getFirst) {
34 return mDataModel.at(index);
42 mCurrentSet = 0;
43 }
44
45 if ((mDataModel.count() <= 0) || (mDataModel.count() <= mCurrentSet)) {
46 return 0;
47 }
48
49 QBarSet* set = mDataModel.at(mCurrentSet);
50 mCurrentSet++;
51 return set;
52 }
35 }
53
36
54 QBarSet* BarChartModel::setAt(int index)
37 QList<QBarSet*> BarChartModel::barSets()
55 {
38 {
56 return mDataModel.at(index);
39 return mDataModel;
57 }
40 }
58
41
59 QList<QString> BarChartModel::legend()
42 QList<QSeries::Legend> BarChartModel::legend()
60 {
43 {
61 QList<QString> legend;
44 QList<QSeries::Legend> legend;
62
45
63 for (int i=0; i<mDataModel.count(); i++) {
46 for (int i=0; i<mDataModel.count(); i++) {
64 legend.append(mDataModel.at(i)->name());
47 QSeries::Legend l;
48 l.mName = mDataModel.at(i)->name();
49 l.mPen = mDataModel.at(i)->pen();
50 legend.append(l);
65 }
51 }
66 return legend;
52 return legend;
67 }
53 }
@@ -192,7 +178,7 qreal BarChartModel::maxCategorySum()
192
178
193 QString BarChartModel::label(int category)
179 QString BarChartModel::label(int category)
194 {
180 {
195 return mCategory->label(category);
181 return mCategory.at(category);
196 }
182 }
197
183
198 #include "moc_barchartmodel_p.cpp"
184 #include "moc_barchartmodel_p.cpp"
@@ -2,7 +2,9
2 #define BARCHARTMODEL_H
2 #define BARCHARTMODEL_H
3
3
4 #include <QObject>
4 #include <QObject>
5 #include <QStringList>
5 #include "qchartglobal.h"
6 #include "qchartglobal.h"
7 #include <qseries.h>
6
8
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
10
@@ -10,21 +12,20 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 // TODO: Implement as QAbstractItemModel?
12 // TODO: Implement as QAbstractItemModel?
11
13
12 class QBarSet;
14 class QBarSet;
13 class QBarCategory;
14
15
15 class BarChartModel : public QObject //, public QAbstractItemModel
16 class BarChartModel : public QObject //, public QAbstractItemModel
16 {
17 {
17 Q_OBJECT
18 Q_OBJECT
18 public:
19 public:
19 explicit BarChartModel(QBarCategory *category, QObject *parent = 0);
20 explicit BarChartModel(QStringList categories, QObject *parent = 0);
20 ~BarChartModel();
21
21
22 QBarCategory& category();
22 QStringList category();
23 void addBarSet(QBarSet *set);
23 void addBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
25 QBarSet* nextSet(bool getFirst);
26 QBarSet *setAt(int index);
25 QBarSet *setAt(int index);
27 QList<QString> legend();
26 QList<QBarSet*> barSets();
27
28 QList<QSeries::Legend> legend();
28
29
29 int countSets(); // Number of sets in model
30 int countSets(); // Number of sets in model
30 int countCategories(); // Number of categories
31 int countCategories(); // Number of categories
@@ -48,7 +49,7 public slots:
48 private:
49 private:
49
50
50 QList<QBarSet*> mDataModel;
51 QList<QBarSet*> mDataModel;
51 QBarCategory* mCategory; // Owned
52 QStringList mCategory;
52
53
53 int mCurrentSet;
54 int mCurrentSet;
54
55
@@ -1,4 +1,4
1 #include "barpresenter.h"
1 #include "barpresenter_p.h"
2 #include "bar_p.h"
2 #include "bar_p.h"
3 #include "barlabel_p.h"
3 #include "barlabel_p.h"
4 #include "barvalue_p.h"
4 #include "barvalue_p.h"
@@ -7,7 +7,7
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 BarPresenter::BarPresenter(QBarChartSeries *series, QGraphicsItem *parent) :
10 BarPresenter::BarPresenter(QBarSeries *series, QGraphicsItem *parent) :
11 BarPresenterBase(series, parent)
11 BarPresenterBase(series, parent)
12 {
12 {
13 mBarDefaultWidth = 15;
13 mBarDefaultWidth = 15;
@@ -17,7 +17,7 void BarPresenter::layoutChanged()
17 {
17 {
18 // Scale bars to new layout
18 // Scale bars to new layout
19 // Layout for bars:
19 // Layout for bars:
20 if (mSeries->countSets() <= 0) {
20 if (mSeries->barsetCount() <= 0) {
21 qDebug() << "No sets in model!";
21 qDebug() << "No sets in model!";
22 return;
22 return;
23 }
23 }
@@ -29,8 +29,8 void BarPresenter::layoutChanged()
29
29
30 // TODO: better way to auto-layout?
30 // TODO: better way to auto-layout?
31 // Use reals for accurancy (we might get some compiler warnings... :)
31 // Use reals for accurancy (we might get some compiler warnings... :)
32 int categoryCount = mSeries->countCategories();
32 int categoryCount = mSeries->categoryCount();
33 int setCount = mSeries->countSets();
33 int setCount = mSeries->barsetCount();
34
34
35 qreal tW = mWidth;
35 qreal tW = mWidth;
36 qreal tH = mHeight;
36 qreal tH = mHeight;
@@ -52,7 +52,7 void BarPresenter::layoutChanged()
52
52
53 // TODO: width settable per bar?
53 // TODO: width settable per bar?
54 bar->resize(mBarDefaultWidth, barHeight);
54 bar->resize(mBarDefaultWidth, barHeight);
55 bar->setBrush(mSeries->setAt(set)->brush());
55 bar->setBrush(mSeries->barsetAt(set)->brush());
56 bar->setPos(xPos, yPos-barHeight);
56 bar->setPos(xPos, yPos-barHeight);
57 itemIndex++;
57 itemIndex++;
58 xPos += mBarDefaultWidth;
58 xPos += mBarDefaultWidth;
@@ -67,10 +67,10 void BarPresenter::layoutChanged()
67
67
68 // Position floating values
68 // Position floating values
69 itemIndex = 0;
69 itemIndex = 0;
70 for (int category=0; category < mSeries->countCategories(); category++) {
70 for (int category=0; category < mSeries->categoryCount(); category++) {
71 qreal xPos = xStepPerSet * category + ((tW + mBarDefaultWidth*setCount)/(categoryCount*2));
71 qreal xPos = xStepPerSet * category + ((tW + mBarDefaultWidth*setCount)/(categoryCount*2));
72 qreal yPos = mHeight;
72 qreal yPos = mHeight;
73 for (int set=0; set < mSeries->countSets(); set++) {
73 for (int set=0; set < mSeries->barsetCount(); set++) {
74 qreal barHeight = mSeries->valueAt(set,category) * scale;
74 qreal barHeight = mSeries->valueAt(set,category) * scale;
75 BarValue* value = mFloatingValues.at(itemIndex);
75 BarValue* value = mFloatingValues.at(itemIndex);
76
76
@@ -92,6 +92,6 void BarPresenter::layoutChanged()
92 mLayoutDirty = true;
92 mLayoutDirty = true;
93 }
93 }
94
94
95 #include "moc_barpresenter.cpp"
95 #include "moc_barpresenter_p.cpp"
96
96
97 QTCOMMERCIALCHART_END_NAMESPACE
97 QTCOMMERCIALCHART_END_NAMESPACE
@@ -2,19 +2,19
2 #define BARPRESENTER_H
2 #define BARPRESENTER_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "barpresenterbase.h"
5 #include "barpresenterbase_p.h"
6 #include <QGraphicsItem>
6 #include <QGraphicsItem>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QBarChartSeries;
10 class QBarSeries;
11
11
12 // Presenter for parallel bars. Grouping of bars is done on category basis.
12 // Presenter for parallel bars. Grouping of bars is done on category basis.
13 class BarPresenter : public BarPresenterBase
13 class BarPresenter : public BarPresenterBase
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16 public:
16 public:
17 explicit BarPresenter(QBarChartSeries *series, QGraphicsItem *parent = 0);
17 explicit BarPresenter(QBarSeries *series, QGraphicsItem *parent = 0);
18
18
19 private:
19 private:
20
20
@@ -1,16 +1,16
1 #include "barpresenterbase.h"
1 #include "barpresenterbase_p.h"
2 #include "bar_p.h"
2 #include "bar_p.h"
3 #include "barvalue_p.h"
3 #include "barvalue_p.h"
4 #include "barlabel_p.h"
4 #include "barlabel_p.h"
5 #include "separator_p.h"
5 #include "separator_p.h"
6 #include "qbarset.h"
6 #include "qbarset.h"
7 #include "qbarchartseries.h"
7 #include "qbarseries.h"
8 #include <QDebug>
8 #include <QDebug>
9 #include <QToolTip>
9 #include <QToolTip>
10
10
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
12
13 BarPresenterBase::BarPresenterBase(QBarChartSeries *series, QGraphicsItem *parent)
13 BarPresenterBase::BarPresenterBase(QBarSeries *series, QGraphicsItem *parent)
14 : ChartItem(parent)
14 : ChartItem(parent)
15 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
15 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
16 ,mLayoutSet(false)
16 ,mLayoutSet(false)
@@ -68,9 +68,9 void BarPresenterBase::dataChanged()
68 mFloatingValues.clear();
68 mFloatingValues.clear();
69
69
70 // Create new graphic items for bars
70 // Create new graphic items for bars
71 for (int c=0; c<mSeries->countCategories(); c++) {
71 for (int c=0; c<mSeries->categoryCount(); c++) {
72 for (int s=0; s<mSeries->countSets(); s++) {
72 for (int s=0; s<mSeries->barsetCount(); s++) {
73 QBarSet *set = mSeries->setAt(s);
73 QBarSet *set = mSeries->barsetAt(s);
74 Bar *bar = new Bar(this);
74 Bar *bar = new Bar(this);
75 childItems().append(bar);
75 childItems().append(bar);
76 mBars.append(bar);
76 mBars.append(bar);
@@ -81,7 +81,7 void BarPresenterBase::dataChanged()
81 }
81 }
82
82
83 // Create labels
83 // Create labels
84 int count = mSeries->countCategories();
84 int count = mSeries->categoryCount();
85 for (int i=0; i<count; i++) {
85 for (int i=0; i<count; i++) {
86 BarLabel* label = new BarLabel(this);
86 BarLabel* label = new BarLabel(this);
87 label->set(mSeries->label(i));
87 label->set(mSeries->label(i));
@@ -90,7 +90,7 void BarPresenterBase::dataChanged()
90 }
90 }
91
91
92 // Create separators
92 // Create separators
93 count = mSeries->countCategories() - 1; // There is one less separator than columns
93 count = mSeries->categoryCount() - 1; // There is one less separator than columns
94 for (int i=0; i<count; i++) {
94 for (int i=0; i<count; i++) {
95 Separator* sep = new Separator(this);
95 Separator* sep = new Separator(this);
96 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
96 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
@@ -100,9 +100,9 void BarPresenterBase::dataChanged()
100 }
100 }
101
101
102 // Create floating values
102 // Create floating values
103 for (int category=0; category<mSeries->countCategories(); category++) {
103 for (int category=0; category<mSeries->categoryCount(); category++) {
104 for (int s=0; s<mSeries->countSets(); s++) {
104 for (int s=0; s<mSeries->barsetCount(); s++) {
105 QBarSet *set = mSeries->setAt(s);
105 QBarSet *set = mSeries->barsetAt(s);
106 BarValue *value = new BarValue(*set, this);
106 BarValue *value = new BarValue(*set, this);
107 childItems().append(value);
107 childItems().append(value);
108 mFloatingValues.append(value);
108 mFloatingValues.append(value);
@@ -153,6 +153,6 void BarPresenterBase::enableSeparators(bool enabled)
153 mSeparatorsEnabled = enabled;
153 mSeparatorsEnabled = enabled;
154 }
154 }
155
155
156 #include "moc_barpresenterbase.cpp"
156 #include "moc_barpresenterbase_p.cpp"
157
157
158 QTCOMMERCIALCHART_END_NAMESPACE
158 QTCOMMERCIALCHART_END_NAMESPACE
@@ -2,7 +2,7
2 #define BARPRESENTERBASE_H
2 #define BARPRESENTERBASE_H
3
3
4 #include "chartitem_p.h"
4 #include "chartitem_p.h"
5 #include "qbarchartseries.h"
5 #include "qbarseries.h"
6 #include <QPen>
6 #include <QPen>
7 #include <QBrush>
7 #include <QBrush>
8 #include <QGraphicsItem>
8 #include <QGraphicsItem>
@@ -20,7 +20,7 class BarPresenterBase : public QObject, public ChartItem
20 {
20 {
21 Q_OBJECT
21 Q_OBJECT
22 public:
22 public:
23 BarPresenterBase(QBarChartSeries *series, QGraphicsItem *parent = 0);
23 BarPresenterBase(QBarSeries *series, QGraphicsItem *parent = 0);
24 ~BarPresenterBase();
24 ~BarPresenterBase();
25
25
26 public:
26 public:
@@ -57,7 +57,7 protected:
57 bool mSeparatorsEnabled;
57 bool mSeparatorsEnabled;
58
58
59 // Owned
59 // Owned
60 QBarChartSeries* mSeries;
60 QBarSeries* mSeries;
61
61
62 // Not owned.
62 // Not owned.
63 QList<Bar*> mBars;
63 QList<Bar*> mBars;
@@ -1,4 +1,4
1 #include "percentbarpresenter.h"
1 #include "percentbarpresenter_p.h"
2 #include "bar_p.h"
2 #include "bar_p.h"
3 #include "barlabel_p.h"
3 #include "barlabel_p.h"
4 #include "barvalue_p.h"
4 #include "barvalue_p.h"
@@ -9,7 +9,7
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11
11
12 PercentBarPresenter::PercentBarPresenter(QBarChartSeries *series, QGraphicsItem *parent) :
12 PercentBarPresenter::PercentBarPresenter(QBarSeries *series, QGraphicsItem *parent) :
13 BarPresenterBase(series, parent)
13 BarPresenterBase(series, parent)
14 {
14 {
15 }
15 }
@@ -18,7 +18,7 void PercentBarPresenter::layoutChanged()
18 {
18 {
19 // Scale bars to new layout
19 // Scale bars to new layout
20 // Layout for bars:
20 // Layout for bars:
21 if (mSeries->countSets() <= 0) {
21 if (mSeries->barsetCount() <= 0) {
22 qDebug() << "No sets in model!";
22 qDebug() << "No sets in model!";
23 // Nothing to do.
23 // Nothing to do.
24 return;
24 return;
@@ -31,7 +31,7 void PercentBarPresenter::layoutChanged()
31
31
32 // TODO: better way to auto-layout
32 // TODO: better way to auto-layout
33 // Use reals for accurancy (we might get some compiler warnings... :)
33 // Use reals for accurancy (we might get some compiler warnings... :)
34 int count = mSeries->countCategories();
34 int count = mSeries->categoryCount();
35 int itemIndex(0);
35 int itemIndex(0);
36 int labelIndex(0);
36 int labelIndex(0);
37 qreal tW = mWidth;
37 qreal tW = mWidth;
@@ -40,17 +40,17 void PercentBarPresenter::layoutChanged()
40 qreal xPos = ((tW/tC) - mBarDefaultWidth / 2);
40 qreal xPos = ((tW/tC) - mBarDefaultWidth / 2);
41 qreal h = mHeight;
41 qreal h = mHeight;
42
42
43 for (int category = 0; category < mSeries->countCategories(); category++) {
43 for (int category = 0; category < mSeries->categoryCount(); category++) {
44 qreal colSum = mSeries->categorySum(category);
44 qreal colSum = mSeries->categorySum(category);
45 qreal scale = (h / colSum);
45 qreal scale = (h / colSum);
46 qreal yPos = h;
46 qreal yPos = h;
47 for (int set=0; set < mSeries->countSets(); set++) {
47 for (int set=0; set < mSeries->barsetCount(); set++) {
48 qreal barHeight = mSeries->valueAt(set, category) * scale;
48 qreal barHeight = mSeries->valueAt(set, category) * scale;
49 Bar* bar = mBars.at(itemIndex);
49 Bar* bar = mBars.at(itemIndex);
50
50
51 // TODO: width settable per bar?
51 // TODO: width settable per bar?
52 bar->resize(mBarDefaultWidth, barHeight);
52 bar->resize(mBarDefaultWidth, barHeight);
53 bar->setBrush(mSeries->setAt(set)->brush());
53 bar->setBrush(mSeries->barsetAt(set)->brush());
54 bar->setPos(xPos, yPos-barHeight);
54 bar->setPos(xPos, yPos-barHeight);
55 itemIndex++;
55 itemIndex++;
56 yPos -= barHeight;
56 yPos -= barHeight;
@@ -65,7 +65,7 void PercentBarPresenter::layoutChanged()
65
65
66 // Position separators
66 // Position separators
67 xPos = xStep + xStep/2;
67 xPos = xStep + xStep/2;
68 for (int s=0; s < mSeries->countCategories() - 1; s++) {
68 for (int s=0; s < mSeries->categoryCount() - 1; s++) {
69 Separator* sep = mSeparators.at(s);
69 Separator* sep = mSeparators.at(s);
70 sep->setPos(xPos,0);
70 sep->setPos(xPos,0);
71 sep->setSize(QSizeF(1,mHeight));
71 sep->setSize(QSizeF(1,mHeight));
@@ -75,11 +75,11 void PercentBarPresenter::layoutChanged()
75 // Position floating values
75 // Position floating values
76 itemIndex = 0;
76 itemIndex = 0;
77 xPos = ((tW/tC) - mBarDefaultWidth / 2);
77 xPos = ((tW/tC) - mBarDefaultWidth / 2);
78 for (int category=0; category < mSeries->countCategories(); category++) {
78 for (int category=0; category < mSeries->categoryCount(); category++) {
79 qreal yPos = h;
79 qreal yPos = h;
80 qreal colSum = mSeries->categorySum(category);
80 qreal colSum = mSeries->categorySum(category);
81 qreal scale = (h / colSum);
81 qreal scale = (h / colSum);
82 for (int set=0; set < mSeries->countSets(); set++) {
82 for (int set=0; set < mSeries->barsetCount(); set++) {
83 qreal barHeight = mSeries->valueAt(set,category) * scale;
83 qreal barHeight = mSeries->valueAt(set,category) * scale;
84 BarValue* value = mFloatingValues.at(itemIndex);
84 BarValue* value = mFloatingValues.at(itemIndex);
85
85
@@ -107,6 +107,6 void PercentBarPresenter::layoutChanged()
107 mLayoutDirty = true;
107 mLayoutDirty = true;
108 }
108 }
109
109
110 #include "moc_percentbarpresenter.cpp"
110 #include "moc_percentbarpresenter_p.cpp"
111
111
112 QTCOMMERCIALCHART_END_NAMESPACE
112 QTCOMMERCIALCHART_END_NAMESPACE
@@ -3,8 +3,8
3
3
4 #include "chartitem_p.h"
4 #include "chartitem_p.h"
5 #include "bar_p.h"
5 #include "bar_p.h"
6 #include "qpercentbarchartseries.h"
6 #include "qpercentbarseries.h"
7 #include "barpresenterbase.h"
7 #include "barpresenterbase_p.h"
8 #include <QGraphicsItem>
8 #include <QGraphicsItem>
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -13,7 +13,7 class PercentBarPresenter : public BarPresenterBase
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 public:
15 public:
16 PercentBarPresenter(QBarChartSeries *series, QGraphicsItem *parent = 0);
16 PercentBarPresenter(QBarSeries *series, QGraphicsItem *parent = 0);
17
17
18 private:
18 private:
19
19
@@ -1,6 +1,5
1 #include <QDebug>
1 #include <QDebug>
2 #include "qbarchartseries.h"
2 #include "qbarseries.h"
3 #include "qbarcategory.h"
4 #include "qbarset.h"
3 #include "qbarset.h"
5 #include "barchartmodel_p.h"
4 #include "barchartmodel_p.h"
6
5
@@ -8,74 +7,58
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
8
10 /*!
9 /*!
11 \class QBarChartSeries
10 \class QBarSeries
12 \brief part of QtCommercial chart API.
11 \brief part of QtCommercial chart API.
13
12
14 QBarChartSeries represents a series of data shown as bars. One QBarChartSeries can contain multible
13 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
15 QBarSet data sets. QBarChartSeries groups the data from sets to categories, which are defined
14 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
16 by QBarCategory class.
15 by QStringList.
17
16
18 \mainclass
17 \mainclass
19
18
20 Example on how to create category:
19 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
21 \snippet ../example/barchart/main.cpp 1
22
23 Example on how to create sets of data:
24 \snippet ../example/barchart/main.cpp 2
25
26 Example on how to add sets to bar chart:
27 \snippet ../example/barchart/main.cpp 3
28
29 Example on how to enable tooltip and floating values:
30 \snippet ../example/barchart/main.cpp 4
31
32 Example on how to create view and apply theme:
33 \snippet ../example/barchart/main.cpp 5
34
35 \sa QBarCategory, QBarSet, QStackedBarChartSeries, QPercentBarChartSeries
36 */
20 */
37
21
38 /*!
22 /*!
39 \fn virtual QChartSeriesType QBarChartSeries::type() const
23 \fn virtual QSeriesType QBarSeries::type() const
40 \brief Returns type of series.
24 \brief Returns type of series.
41 \sa QChartSeries, QChartSeriesType
25 \sa QSeries, QSeriesType
42 */
26 */
43 /*!
27 /*!
44 \fn void QBarChartSeries::changed(int index)
28 \fn void QBarSeries::changed(int index)
45 \brief \internal \a index
29 \brief \internal \a index
46 */
30 */
47 /*!
31 /*!
48 \fn void QBarChartSeries::floatingValuesEnabled(bool enabled)
32 \fn void QBarSeries::floatingValuesEnabled(bool enabled)
49 \brief \internal \a enabled
33 \brief \internal \a enabled
50 */
34 */
51 /*!
35 /*!
52 \fn void QBarChartSeries::toolTipEnabled(bool enabled)
36 \fn void QBarSeries::toolTipEnabled(bool enabled)
53 \brief \internal \a enabled
37 \brief \internal \a enabled
54 */
38 */
55 /*!
39 /*!
56 \fn void QBarChartSeries::separatorsEnabled(bool enabled)
40 \fn void QBarSeries::separatorsEnabled(bool enabled)
57 \brief \internal \a enabled
41 \brief \internal \a enabled
58 */
42 */
59 /*!
43 /*!
60 \fn void QBarChartSeries::showToolTip(QPoint pos, QString tip)
44 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
61 \brief \internal \a pos \a tip
45 \brief \internal \a pos \a tip
62 */
46 */
63
47
64 /*!
48 /*!
65 Constructs empty QBarChartSeries. Parameter \a category defines the categories for chart.
49 Constructs empty QBarSeries. Parameter \a category defines the categories for chart.
66 Takes ownership of \a category.
50 QBarSeries is QObject which is a child of a \a parent.
67 QBarChartSeries is QObject which is a child of a \a parent.
68 */
51 */
69 QBarChartSeries::QBarChartSeries(QBarCategory *category, QObject *parent)
52 QBarSeries::QBarSeries(QStringList categories, QObject *parent)
70 : QChartSeries(parent)
53 : QSeries(parent)
71 ,mModel(new BarChartModel(category, this))
54 ,mModel(new BarChartModel(categories, this))
72 {
55 {
73 }
56 }
74
57
75 /*!
58 /*!
76 Adds a set of bars to series. Takes ownership of \a set
59 Adds a set of bars to series. Takes ownership of \a set
77 */
60 */
78 void QBarChartSeries::addBarSet(QBarSet *set)
61 void QBarSeries::addBarSet(QBarSet *set)
79 {
62 {
80 mModel->addBarSet(set);
63 mModel->addBarSet(set);
81 }
64 }
@@ -83,7 +66,7 void QBarChartSeries::addBarSet(QBarSet *set)
83 /*!
66 /*!
84 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
67 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
85 */
68 */
86 void QBarChartSeries::removeBarSet(QBarSet *set)
69 void QBarSeries::removeBarSet(QBarSet *set)
87 {
70 {
88 mModel->removeBarSet(set);
71 mModel->removeBarSet(set);
89 }
72 }
@@ -91,7 +74,7 void QBarChartSeries::removeBarSet(QBarSet *set)
91 /*!
74 /*!
92 Returns number of sets in series.
75 Returns number of sets in series.
93 */
76 */
94 int QBarChartSeries::countSets()
77 int QBarSeries::barsetCount()
95 {
78 {
96 return mModel->countSets();
79 return mModel->countSets();
97 }
80 }
@@ -99,36 +82,31 int QBarChartSeries::countSets()
99 /*!
82 /*!
100 Returns number of categories in series
83 Returns number of categories in series
101 */
84 */
102 int QBarChartSeries::countCategories()
85 int QBarSeries::categoryCount()
103 {
86 {
104 return mModel->countCategories();
87 return mModel->countCategories();
105 }
88 }
106
89
107 /*!
90 /*!
108 Simple iterator for set. Returns pointer to next set in series.
91 Returns a list of sets in series. Keeps ownership of sets.
109 Returns first set, if parameter \a getFirst is true.
110 If series is empty, returns 0.
111 Returns 0 after last set.
112 */
92 */
113 QBarSet* QBarChartSeries::nextSet(bool getFirst)
93 QList<QBarSet*> QBarSeries::barSets()
114 {
94 {
115 return mModel->nextSet(getFirst);
95 return mModel->barSets();
116 }
96 }
117
97
118 /*!
98 /*!
119 Returns set indexed by \a index. Doesn't check for index bounds.
99 \internal \a index
120 Assumes that \a index is between 0 and number of sets. Use countSets() to get valid index bound.
121 \sa countSets()
122 */
100 */
123 QBarSet* QBarChartSeries::setAt(int index)
101 QBarSet* QBarSeries::barsetAt(int index)
124 {
102 {
125 return mModel->setAt(index);
103 return mModel->setAt(index);
126 }
104 }
127
105
128 /*!
106 /*!
129 Returns legend of series. Legend is a list of set names in series.
107 Returns legend of series.
130 */
108 */
131 QList<QString> QBarChartSeries::legend()
109 QList<QSeries::Legend> QBarSeries::legend()
132 {
110 {
133 return mModel->legend();
111 return mModel->legend();
134 }
112 }
@@ -136,7 +114,7 QList<QString> QBarChartSeries::legend()
136 /*!
114 /*!
137 \internal \a category
115 \internal \a category
138 */
116 */
139 QString QBarChartSeries::label(int category)
117 QString QBarSeries::label(int category)
140 {
118 {
141 return mModel->label(category);
119 return mModel->label(category);
142 }
120 }
@@ -146,7 +124,7 QString QBarChartSeries::label(int category)
146 Floating values are bar values, that are displayed on top of each bar.
124 Floating values are bar values, that are displayed on top of each bar.
147 Calling without parameter \a enabled, enables the floating values
125 Calling without parameter \a enabled, enables the floating values
148 */
126 */
149 void QBarChartSeries::enableFloatingValues(bool enabled)
127 void QBarSeries::setFloatingValuesEnabled(bool enabled)
150 {
128 {
151 if (enabled) {
129 if (enabled) {
152 for (int i=0; i<mModel->countSets(); i++) {
130 for (int i=0; i<mModel->countSets(); i++) {
@@ -166,7 +144,7 void QBarChartSeries::enableFloatingValues(bool enabled)
166 Tooltip shows the name of set, when mouse is hovering on top of bar.
144 Tooltip shows the name of set, when mouse is hovering on top of bar.
167 Calling without parameter \a enabled, enables the tooltip
145 Calling without parameter \a enabled, enables the tooltip
168 */
146 */
169 void QBarChartSeries::enableToolTip(bool enabled)
147 void QBarSeries::setToolTipEnabled(bool enabled)
170 {
148 {
171 if (enabled) {
149 if (enabled) {
172 for (int i=0; i<mModel->countSets(); i++) {
150 for (int i=0; i<mModel->countSets(); i++) {
@@ -186,7 +164,7 void QBarChartSeries::enableToolTip(bool enabled)
186 Separators are visual elements that are drawn between categories.
164 Separators are visual elements that are drawn between categories.
187 Calling without parameter \a enabled, enables the separators
165 Calling without parameter \a enabled, enables the separators
188 */
166 */
189 void QBarChartSeries::enableSeparators(bool enabled)
167 void QBarSeries::setSeparatorsEnabled(bool enabled)
190 {
168 {
191 emit separatorsEnabled(enabled);
169 emit separatorsEnabled(enabled);
192 }
170 }
@@ -194,7 +172,7 void QBarChartSeries::enableSeparators(bool enabled)
194 /*!
172 /*!
195 \internal
173 \internal
196 */
174 */
197 qreal QBarChartSeries::min()
175 qreal QBarSeries::min()
198 {
176 {
199 return mModel->min();
177 return mModel->min();
200 }
178 }
@@ -202,7 +180,7 qreal QBarChartSeries::min()
202 /*!
180 /*!
203 \internal
181 \internal
204 */
182 */
205 qreal QBarChartSeries::max()
183 qreal QBarSeries::max()
206 {
184 {
207 return mModel->max();
185 return mModel->max();
208 }
186 }
@@ -210,7 +188,7 qreal QBarChartSeries::max()
210 /*!
188 /*!
211 \internal \a set \a category
189 \internal \a set \a category
212 */
190 */
213 qreal QBarChartSeries::valueAt(int set, int category)
191 qreal QBarSeries::valueAt(int set, int category)
214 {
192 {
215 return mModel->valueAt(set,category);
193 return mModel->valueAt(set,category);
216 }
194 }
@@ -218,7 +196,7 qreal QBarChartSeries::valueAt(int set, int category)
218 /*!
196 /*!
219 \internal \a set \a category
197 \internal \a set \a category
220 */
198 */
221 qreal QBarChartSeries::percentageAt(int set, int category)
199 qreal QBarSeries::percentageAt(int set, int category)
222 {
200 {
223 return mModel->percentageAt(set,category);
201 return mModel->percentageAt(set,category);
224 }
202 }
@@ -226,7 +204,7 qreal QBarChartSeries::percentageAt(int set, int category)
226 /*!
204 /*!
227 \internal \a category
205 \internal \a category
228 */
206 */
229 qreal QBarChartSeries::categorySum(int category)
207 qreal QBarSeries::categorySum(int category)
230 {
208 {
231 return mModel->categorySum(category);
209 return mModel->categorySum(category);
232 }
210 }
@@ -234,7 +212,7 qreal QBarChartSeries::categorySum(int category)
234 /*!
212 /*!
235 \internal
213 \internal
236 */
214 */
237 qreal QBarChartSeries::maxCategorySum()
215 qreal QBarSeries::maxCategorySum()
238 {
216 {
239 return mModel->maxCategorySum();
217 return mModel->maxCategorySum();
240 }
218 }
@@ -242,11 +220,11 qreal QBarChartSeries::maxCategorySum()
242 /*!
220 /*!
243 \internal
221 \internal
244 */
222 */
245 BarChartModel& QBarChartSeries::model()
223 BarChartModel& QBarSeries::model()
246 {
224 {
247 return *mModel;
225 return *mModel;
248 }
226 }
249
227
250 #include "moc_qbarchartseries.cpp"
228 #include "moc_qbarseries.cpp"
251
229
252 QTCOMMERCIALCHART_END_NAMESPACE
230 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,36 +1,35
1 #ifndef BARCHARTSERIES_H
1 #ifndef BARSERIES_H
2 #define BARCHARTSERIES_H
2 #define BARSERIES_H
3
3
4 #include "qchartseries.h"
4 #include "qseries.h"
5 #include <QStringList>
5
6
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
8
8 class QBarCategory;
9 class QBarSet;
9 class QBarSet;
10 class BarChartModel;
10 class BarChartModel;
11
11
12 // Container for series
12 // Container for series
13 class QTCOMMERCIALCHART_EXPORT QBarChartSeries : public QChartSeries
13 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16 public:
16 public:
17 QBarChartSeries(QBarCategory *category, QObject* parent=0);
17 QBarSeries(QStringList categories, QObject* parent=0);
18
18
19 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
19 virtual QSeriesType type() const { return QSeries::SeriesTypeBar; }
20
20
21 void addBarSet(QBarSet *set); // Takes ownership of set
21 void addBarSet(QBarSet *set); // Takes ownership of set
22 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
22 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
23 int countSets();
23 int barsetCount();
24 int countCategories();
24 int categoryCount();
25 QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true
25 QList<QBarSet*> barSets();
26 QBarSet *setAt(int index);
26 QList<QSeries::Legend> legend();
27
28 QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
29
27
30 public:
28 public:
31 // TODO: Functions below this are not part of api and will be moved
29 // TODO: Functions below this are not part of api and will be moved
32 // to private implementation, when we start using it
30 // to private implementation, when we start using it
33 // TODO: TO PIMPL --->
31 // TODO: TO PIMPL --->
32 QBarSet *barsetAt(int index);
34 QString label(int category);
33 QString label(int category);
35 qreal min();
34 qreal min();
36 qreal max();
35 qreal max();
@@ -53,9 +52,9 signals:
53 // <--- TO PIMPL
52 // <--- TO PIMPL
54
53
55 public Q_SLOTS:
54 public Q_SLOTS:
56 void enableFloatingValues(bool enabled=true); // enables floating values on top of bars
55 void setFloatingValuesEnabled(bool enabled=true); // enables floating values on top of bars
57 void enableToolTip(bool enabled=true); // enables tooltips
56 void setToolTipEnabled(bool enabled=true); // enables tooltips
58 void enableSeparators(bool enabled=true); // enables separators between categories
57 void setSeparatorsEnabled(bool enabled=true); // enables separators between categories
59
58
60 protected:
59 protected:
61 BarChartModel* mModel;
60 BarChartModel* mModel;
@@ -63,4 +62,4 protected:
63
62
64 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
65
64
66 #endif // BARCHARTSERIES_H
65 #endif // BARSERIES_H
@@ -15,10 +15,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
15
15
16 \mainclass
16 \mainclass
17
17
18 Example on how to create sets of data:
18 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
19 \snippet ../example/barchart/main.cpp 2
20
21 \sa QBarCategory, QBarChartSeries, QStackedBarChartSeries, QPercentBarChartSeries
22 */
19 */
23
20
24 /*!
21 /*!
@@ -104,7 +101,7 void QBarSet::setValue(int index, qreal value)
104 /*!
101 /*!
105 Sets pen for set. Bars of this set are drawn using \a pen
102 Sets pen for set. Bars of this set are drawn using \a pen
106 */
103 */
107 void QBarSet::setPen(const QPen& pen)
104 void QBarSet::setPen(QPen pen)
108 {
105 {
109 mPen = pen;
106 mPen = pen;
110 }
107 }
@@ -112,7 +109,7 void QBarSet::setPen(const QPen& pen)
112 /*!
109 /*!
113 Returns pen of the set.
110 Returns pen of the set.
114 */
111 */
115 const QPen& QBarSet::pen() const
112 QPen QBarSet::pen()
116 {
113 {
117 return mPen;
114 return mPen;
118 }
115 }
@@ -120,7 +117,7 const QPen& QBarSet::pen() const
120 /*!
117 /*!
121 Sets brush for the set. Bars of this set are drawn using \a brush
118 Sets brush for the set. Bars of this set are drawn using \a brush
122 */
119 */
123 void QBarSet::setBrush(const QBrush& brush)
120 void QBarSet::setBrush(QBrush brush)
124 {
121 {
125 mBrush = brush;
122 mBrush = brush;
126 }
123 }
@@ -128,7 +125,7 void QBarSet::setBrush(const QBrush& brush)
128 /*!
125 /*!
129 Returns brush of the set.
126 Returns brush of the set.
130 */
127 */
131 const QBrush& QBarSet::brush() const
128 QBrush QBarSet::brush()
132 {
129 {
133 return mBrush;
130 return mBrush;
134 }
131 }
@@ -21,11 +21,11 public:
21 qreal valueAt(int index); // for modifying individual values
21 qreal valueAt(int index); // for modifying individual values
22 void setValue(int index, qreal value); // setter for individual value
22 void setValue(int index, qreal value); // setter for individual value
23
23
24 void setPen(const QPen& pen);
24 void setPen(QPen pen);
25 const QPen& pen() const;
25 QPen pen();
26
26
27 void setBrush(const QBrush& brush);
27 void setBrush(QBrush brush);
28 const QBrush& brush() const;
28 QBrush brush();
29
29
30 Q_SIGNALS:
30 Q_SIGNALS:
31 void clicked(); // Clicked and hover signals exposed to user
31 void clicked(); // Clicked and hover signals exposed to user
@@ -1,4 +1,4
1 #include "stackedbarpresenter.h"
1 #include "stackedbarpresenter_p.h"
2 #include "bar_p.h"
2 #include "bar_p.h"
3 #include "barlabel_p.h"
3 #include "barlabel_p.h"
4 #include "barvalue_p.h"
4 #include "barvalue_p.h"
@@ -8,7 +8,7
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 StackedBarPresenter::StackedBarPresenter(QBarChartSeries *series, QGraphicsItem *parent) :
11 StackedBarPresenter::StackedBarPresenter(QBarSeries *series, QGraphicsItem *parent) :
12 BarPresenterBase(series,parent)
12 BarPresenterBase(series,parent)
13 {
13 {
14 }
14 }
@@ -17,13 +17,13 void StackedBarPresenter::layoutChanged()
17 {
17 {
18 // Scale bars to new layout
18 // Scale bars to new layout
19 // Layout for bars:
19 // Layout for bars:
20 if (mSeries->countSets() <= 0) {
20 if (mSeries->barsetCount() <= 0) {
21 qDebug() << "No sets in model!";
21 qDebug() << "No sets in model!";
22 // Nothing to do.
22 // Nothing to do.
23 return;
23 return;
24 }
24 }
25
25
26 if (mSeries->countCategories() == 0) {
26 if (mSeries->categoryCount() == 0) {
27 qDebug() << "No categories in model!";
27 qDebug() << "No categories in model!";
28 // Nothing to do
28 // Nothing to do
29 return;
29 return;
@@ -44,18 +44,18 void StackedBarPresenter::layoutChanged()
44 int itemIndex(0);
44 int itemIndex(0);
45 int labelIndex(0);
45 int labelIndex(0);
46 qreal tW = mWidth;
46 qreal tW = mWidth;
47 qreal tC = mSeries->countCategories() + 1;
47 qreal tC = mSeries->categoryCount() + 1;
48 qreal xStep = (tW/tC);
48 qreal xStep = (tW/tC);
49 qreal xPos = ((tW/tC) - mBarDefaultWidth / 2);
49 qreal xPos = ((tW/tC) - mBarDefaultWidth / 2);
50
50
51 for (int category = 0; category < mSeries->countCategories(); category++) {
51 for (int category = 0; category < mSeries->categoryCount(); category++) {
52 qreal yPos = h;
52 qreal yPos = h;
53 for (int set=0; set < mSeries->countSets(); set++) {
53 for (int set=0; set < mSeries->barsetCount(); set++) {
54 qreal barHeight = mSeries->valueAt(set, category) * scale;
54 qreal barHeight = mSeries->valueAt(set, category) * scale;
55 Bar* bar = mBars.at(itemIndex);
55 Bar* bar = mBars.at(itemIndex);
56
56
57 bar->resize(mBarDefaultWidth, barHeight);
57 bar->resize(mBarDefaultWidth, barHeight);
58 bar->setBrush(mSeries->setAt(set)->brush());
58 bar->setBrush(mSeries->barsetAt(set)->brush());
59 bar->setPos(xPos, yPos-barHeight);
59 bar->setPos(xPos, yPos-barHeight);
60 itemIndex++;
60 itemIndex++;
61 yPos -= barHeight;
61 yPos -= barHeight;
@@ -70,7 +70,7 void StackedBarPresenter::layoutChanged()
70
70
71 // Position separators
71 // Position separators
72 xPos = xStep + xStep/2;
72 xPos = xStep + xStep/2;
73 for (int s=0; s < mSeries->countCategories() - 1; s++) {
73 for (int s=0; s < mSeries->categoryCount() - 1; s++) {
74 Separator* sep = mSeparators.at(s);
74 Separator* sep = mSeparators.at(s);
75 sep->setPos(xPos,0);
75 sep->setPos(xPos,0);
76 sep->setSize(QSizeF(1,mHeight));
76 sep->setSize(QSizeF(1,mHeight));
@@ -80,9 +80,9 void StackedBarPresenter::layoutChanged()
80 // Position floating values
80 // Position floating values
81 itemIndex = 0;
81 itemIndex = 0;
82 xPos = ((tW/tC) - mBarDefaultWidth / 2);
82 xPos = ((tW/tC) - mBarDefaultWidth / 2);
83 for (int category=0; category < mSeries->countCategories(); category++) {
83 for (int category=0; category < mSeries->categoryCount(); category++) {
84 qreal yPos = h;
84 qreal yPos = h;
85 for (int set=0; set < mSeries->countSets(); set++) {
85 for (int set=0; set < mSeries->barsetCount(); set++) {
86 qreal barHeight = mSeries->valueAt(set,category) * scale;
86 qreal barHeight = mSeries->valueAt(set,category) * scale;
87 BarValue* value = mFloatingValues.at(itemIndex);
87 BarValue* value = mFloatingValues.at(itemIndex);
88
88
@@ -106,6 +106,6 void StackedBarPresenter::layoutChanged()
106 mLayoutDirty = true;
106 mLayoutDirty = true;
107 }
107 }
108
108
109 #include "moc_stackedbarpresenter.cpp"
109 #include "moc_stackedbarpresenter_p.cpp"
110
110
111 QTCOMMERCIALCHART_END_NAMESPACE
111 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,8 +1,8
1 #ifndef STACKEDBARPRESENTER_H
1 #ifndef STACKEDBARPRESENTER_H
2 #define STACKEDBARPRESENTER_H
2 #define STACKEDBARPRESENTER_H
3
3
4 #include "barpresenterbase.h"
4 #include "barpresenterbase_p.h"
5 #include "qstackedbarchartseries.h"
5 #include "qstackedbarseries.h"
6 #include <QGraphicsItem>
6 #include <QGraphicsItem>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -11,7 +11,7 class StackedBarPresenter : public BarPresenterBase
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13 public:
13 public:
14 StackedBarPresenter(QBarChartSeries *series, QGraphicsItem *parent = 0);
14 StackedBarPresenter(QBarSeries *series, QGraphicsItem *parent = 0);
15
15
16 private:
16 private:
17 // From BarPresenterBase
17 // From BarPresenterBase
@@ -1,10 +1,10
1 #include "chartdataset_p.h"
1 #include "chartdataset_p.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 //series
3 //series
4 #include "qlinechartseries.h"
4 #include "qlineseries.h"
5 #include "qbarchartseries.h"
5 #include "qbarseries.h"
6 #include "qstackedbarchartseries.h"
6 #include "qstackedbarseries.h"
7 #include "qpercentbarchartseries.h"
7 #include "qpercentbarseries.h"
8 #include "qpieseries.h"
8 #include "qpieseries.h"
9 #include "qscatterseries.h"
9 #include "qscatterseries.h"
10
10
@@ -33,7 +33,7 const Domain ChartDataSet::domain(QChartAxis *axisY) const
33 return m_domainMap.values(axisY).at(i);
33 return m_domainMap.values(axisY).at(i);
34 }
34 }
35
35
36 void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY)
36 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
37 {
37 {
38 // TODO: we should check the series not already added
38 // TODO: we should check the series not already added
39
39
@@ -43,7 +43,7 void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY)
43 if(axisY==0) axisY = m_axisY;
43 if(axisY==0) axisY = m_axisY;
44 axisY->setParent(this); // take ownership
44 axisY->setParent(this); // take ownership
45
45
46 QList<QChartSeries*> seriesList = m_seriesMap.values(axisY);
46 QList<QSeries*> seriesList = m_seriesMap.values(axisY);
47
47
48 QList<Domain> domainList = m_domainMap.values(axisY);
48 QList<Domain> domainList = m_domainMap.values(axisY);
49
49
@@ -55,9 +55,9 void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY)
55
55
56 switch(series->type())
56 switch(series->type())
57 {
57 {
58 case QChartSeries::SeriesTypeLine: {
58 case QSeries::SeriesTypeLine: {
59
59
60 QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series);
60 QLineSeries* xyseries = static_cast<QLineSeries*>(series);
61
61
62 for (int i = 0; i < xyseries->count(); i++)
62 for (int i = 0; i < xyseries->count(); i++)
63 {
63 {
@@ -70,10 +70,10 void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY)
70 }
70 }
71 break;
71 break;
72 }
72 }
73 case QChartSeries::SeriesTypeBar: {
73 case QSeries::SeriesTypeBar: {
74 qDebug() << "QChartSeries::SeriesTypeBar";
74 qDebug() << "QChartSeries::SeriesTypeBar";
75 QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series);
75 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
76 qreal x = barSeries->countCategories();
76 qreal x = barSeries->categoryCount();
77 qreal y = barSeries->max();
77 qreal y = barSeries->max();
78 domain.m_minX = qMin(domain.m_minX,x);
78 domain.m_minX = qMin(domain.m_minX,x);
79 domain.m_minY = qMin(domain.m_minY,y);
79 domain.m_minY = qMin(domain.m_minY,y);
@@ -81,11 +81,11 void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY)
81 domain.m_maxY = qMax(domain.m_maxY,y);
81 domain.m_maxY = qMax(domain.m_maxY,y);
82 break;
82 break;
83 }
83 }
84 case QChartSeries::SeriesTypeStackedBar: {
84 case QSeries::SeriesTypeStackedBar: {
85 qDebug() << "QChartSeries::SeriesTypeStackedBar";
85 qDebug() << "QChartSeries::SeriesTypeStackedBar";
86
86
87 QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series);
87 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
88 qreal x = stackedBarSeries->countCategories();
88 qreal x = stackedBarSeries->categoryCount();
89 qreal y = stackedBarSeries->maxCategorySum();
89 qreal y = stackedBarSeries->maxCategorySum();
90 domain.m_minX = qMin(domain.m_minX,x);
90 domain.m_minX = qMin(domain.m_minX,x);
91 domain.m_minY = qMin(domain.m_minY,y);
91 domain.m_minY = qMin(domain.m_minY,y);
@@ -93,11 +93,11 void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY)
93 domain.m_maxY = qMax(domain.m_maxY,y);
93 domain.m_maxY = qMax(domain.m_maxY,y);
94 break;
94 break;
95 }
95 }
96 case QChartSeries::SeriesTypePercentBar: {
96 case QSeries::SeriesTypePercentBar: {
97 qDebug() << "QChartSeries::SeriesTypePercentBar";
97 qDebug() << "QChartSeries::SeriesTypePercentBar";
98
98
99 QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series);
99 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
100 qreal x = percentBarSeries->countCategories();
100 qreal x = percentBarSeries->categoryCount();
101 domain.m_minX = qMin(domain.m_minX,x);
101 domain.m_minX = qMin(domain.m_minX,x);
102 domain.m_minY = 0;
102 domain.m_minY = 0;
103 domain.m_maxX = qMax(domain.m_maxX,x);
103 domain.m_maxX = qMax(domain.m_maxX,x);
@@ -105,13 +105,13 void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY)
105 break;
105 break;
106 }
106 }
107
107
108 case QChartSeries::SeriesTypePie: {
108 case QSeries::SeriesTypePie: {
109 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
109 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
110 // TODO: domain stuff
110 // TODO: domain stuff
111 break;
111 break;
112 }
112 }
113
113
114 case QChartSeries::SeriesTypeScatter: {
114 case QSeries::SeriesTypeScatter: {
115 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
115 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
116 Q_ASSERT(scatterSeries);
116 Q_ASSERT(scatterSeries);
117 foreach (QPointF point, scatterSeries->data()) {
117 foreach (QPointF point, scatterSeries->data()) {
@@ -160,7 +160,7 void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY)
160
160
161 }
161 }
162
162
163 void ChartDataSet::removeSeries(QChartSeries* series)
163 void ChartDataSet::removeSeries(QSeries* series)
164 {
164 {
165 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
165 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
166 foreach(QChartAxis* axis , keys) {
166 foreach(QChartAxis* axis , keys) {
@@ -184,7 +184,7 void ChartDataSet::removeAllSeries()
184 {
184 {
185 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
185 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
186 foreach(QChartAxis* axis , keys) {
186 foreach(QChartAxis* axis , keys) {
187 QList<QChartSeries*> seriesList = m_seriesMap.values(axis);
187 QList<QSeries*> seriesList = m_seriesMap.values(axis);
188 for(int i =0 ; i < seriesList.size();i++ )
188 for(int i =0 ; i < seriesList.size();i++ )
189 {
189 {
190 emit seriesRemoved(seriesList.at(i));
190 emit seriesRemoved(seriesList.at(i));
@@ -228,6 +228,8 void ChartDataSet::setDomain(int index)
228 {
228 {
229 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
229 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
230
230
231 if(domainList.count()==0) return;
232
231 Domain domain;
233 Domain domain;
232
234
233 foreach (QChartAxis* axis , domainList) {
235 foreach (QChartAxis* axis , domainList) {
@@ -235,8 +237,8 void ChartDataSet::setDomain(int index)
235 Q_ASSERT(i>=0);
237 Q_ASSERT(i>=0);
236 domain = m_domainMap.values(axis).at(i);
238 domain = m_domainMap.values(axis).at(i);
237 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
239 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
238 QList<QChartSeries*> seriesList = m_seriesMap.values(axis);
240 QList<QSeries*> seriesList = m_seriesMap.values(axis);
239 foreach(QChartSeries* series, seriesList) {
241 foreach(QSeries* series, seriesList) {
240 emit seriesDomainChanged(series,domain);
242 emit seriesDomainChanged(series,domain);
241 }
243 }
242 emit axisLabelsChanged(axis,labels);
244 emit axisLabelsChanged(axis,labels);
@@ -281,8 +283,8 void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport)
281 foreach (QChartAxis* axis , domainList){
283 foreach (QChartAxis* axis , domainList){
282 domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height());
284 domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height());
283 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
285 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
284 QList<QChartSeries*> seriesList = m_seriesMap.values(axis);
286 QList<QSeries*> seriesList = m_seriesMap.values(axis);
285 foreach(QChartSeries* series, seriesList){
287 foreach(QSeries* series, seriesList){
286 emit seriesDomainChanged(series,domain);
288 emit seriesDomainChanged(series,domain);
287 }
289 }
288 emit axisLabelsChanged(axis,labels);
290 emit axisLabelsChanged(axis,labels);
@@ -295,7 +297,7 void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport)
295 m_domainIndex++;
297 m_domainIndex++;
296 }
298 }
297
299
298 QChartAxis* ChartDataSet::axisY(QChartSeries* series) const
300 QChartAxis* ChartDataSet::axisY(QSeries* series) const
299 {
301 {
300 if(series == 0) return m_axisY;
302 if(series == 0) return m_axisY;
301
303
@@ -1,7 +1,7
1 #ifndef CHARTDATASET_P_H_
1 #ifndef CHARTDATASET_P_H_
2 #define CHARTDATASET_P_H_
2 #define CHARTDATASET_P_H_
3
3
4 #include "qchartseries.h"
4 #include "qseries.h"
5 #include "domain_p.h"
5 #include "domain_p.h"
6 #include <QVector>
6 #include <QVector>
7
7
@@ -16,8 +16,8 public:
16 ChartDataSet(QObject* parent=0);
16 ChartDataSet(QObject* parent=0);
17 virtual ~ChartDataSet();
17 virtual ~ChartDataSet();
18
18
19 void addSeries(QChartSeries* series,QChartAxis *axisY = 0);
19 void addSeries(QSeries* series,QChartAxis *axisY = 0);
20 void removeSeries(QChartSeries* series);
20 void removeSeries(QSeries* series);
21 void removeAllSeries();
21 void removeAllSeries();
22 void addDomain(const QRectF& rect, const QRectF& viewport);
22 void addDomain(const QRectF& rect, const QRectF& viewport);
23 bool nextDomain();
23 bool nextDomain();
@@ -28,15 +28,15 public:
28 void setDomain(int index);
28 void setDomain(int index);
29
29
30 QChartAxis* axisX() const { return m_axisX;};
30 QChartAxis* axisX() const { return m_axisX;};
31 QChartAxis* axisY(QChartSeries* series = 0) const;
31 QChartAxis* axisY(QSeries* series = 0) const;
32
32
33 signals:
33 signals:
34 void seriesAdded(QChartSeries* series);
34 void seriesAdded(QSeries* series);
35 void seriesRemoved(QChartSeries* series);
35 void seriesRemoved(QSeries* series);
36 void axisAdded(QChartAxis* axis);
36 void axisAdded(QChartAxis* axis);
37 void axisRemoved(QChartAxis* axis);
37 void axisRemoved(QChartAxis* axis);
38 void axisLabelsChanged(QChartAxis* axis, const QStringList& labels);
38 void axisLabelsChanged(QChartAxis* axis, const QStringList& labels);
39 void seriesDomainChanged(QChartSeries* series,const Domain& domain);
39 void seriesDomainChanged(QSeries* series,const Domain& domain);
40
40
41 private slots:
41 private slots:
42 void handleMinChanged(qreal min);
42 void handleMinChanged(qreal min);
@@ -48,7 +48,7 private:
48
48
49 private:
49 private:
50 QMultiMap<QChartAxis*, Domain> m_domainMap;
50 QMultiMap<QChartAxis*, Domain> m_domainMap;
51 QMultiMap<QChartAxis*, QChartSeries*> m_seriesMap;
51 QMultiMap<QChartAxis*, QSeries*> m_seriesMap;
52 QChartAxis* m_axisX;
52 QChartAxis* m_axisX;
53 QChartAxis* m_axisY;
53 QChartAxis* m_axisY;
54 int m_domainIndex;
54 int m_domainIndex;
@@ -4,21 +4,21
4 #include "chartdataset_p.h"
4 #include "chartdataset_p.h"
5 #include "charttheme_p.h"
5 #include "charttheme_p.h"
6 //series
6 //series
7 #include "qbarchartseries.h"
7 #include "qbarseries.h"
8 #include "qstackedbarchartseries.h"
8 #include "qstackedbarseries.h"
9 #include "qpercentbarchartseries.h"
9 #include "qpercentbarseries.h"
10 #include "qlinechartseries.h"
10 #include "qlineseries.h"
11 #include "qpieseries.h"
11 #include "qpieseries.h"
12 #include "qscatterseries.h"
12 #include "qscatterseries.h"
13 //items
13 //items
14 #include "axisitem_p.h"
14 #include "axisitem_p.h"
15 #include "axisanimationitem_p.h"
15 #include "axisanimationitem_p.h"
16 #include "barpresenter.h"
16 #include "barpresenter_p.h"
17 #include "stackedbarpresenter.h"
17 #include "stackedbarpresenter_p.h"
18 #include "percentbarpresenter_p.h"
18 #include "linechartitem_p.h"
19 #include "linechartitem_p.h"
19 #include "percentbarpresenter.h"
20 #include "linechartanimationitem_p.h"
20 #include "linechartanimationitem_p.h"
21 #include "piepresenter.h"
21 #include "piepresenter_p.h"
22 #include "scatterpresenter_p.h"
22 #include "scatterpresenter_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -43,11 +43,11 ChartPresenter::~ChartPresenter()
43 void ChartPresenter::createConnections()
43 void ChartPresenter::createConnections()
44 {
44 {
45 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
45 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
46 QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*)));
46 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*)));
47 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QChartSeries*)),this,SLOT(handleSeriesRemoved(QChartSeries*)));
47 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
48 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*)));
48 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*)));
49 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
49 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
50 QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QChartSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QChartSeries*,const Domain&)));
50 QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&)));
51 QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&)));
51 QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&)));
52 }
52 }
53
53
@@ -104,12 +104,12 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
104 }
104 }
105
105
106
106
107 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
107 void ChartPresenter::handleSeriesAdded(QSeries* series)
108 {
108 {
109 switch(series->type())
109 switch(series->type())
110 {
110 {
111 case QChartSeries::SeriesTypeLine: {
111 case QSeries::SeriesTypeLine: {
112 QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series);
112 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
113 LineChartItem* item;
113 LineChartItem* item;
114 if(m_options.testFlag(QChart::SeriesAnimations)){
114 if(m_options.testFlag(QChart::SeriesAnimations)){
115 item = new LineChartAnimationItem(this,lineSeries,m_chart);
115 item = new LineChartAnimationItem(this,lineSeries,m_chart);
@@ -118,13 +118,13 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
118 }
118 }
119 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
119 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
120 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
120 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
121 QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
121 QObject::connect(lineSeries,SIGNAL(pointChanged(int)),item,SLOT(handleModelChanged(int)));
122 m_chartItems.insert(series,item);
122 m_chartItems.insert(series,item);
123 break;
123 break;
124 }
124 }
125
125
126 case QChartSeries::SeriesTypeBar: {
126 case QSeries::SeriesTypeBar: {
127 QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series);
127 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
128 BarPresenter* item = new BarPresenter(barSeries,m_chart);
128 BarPresenter* item = new BarPresenter(barSeries,m_chart);
129 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
129 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
130 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
130 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
@@ -134,9 +134,9 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
134 break;
134 break;
135 }
135 }
136
136
137 case QChartSeries::SeriesTypeStackedBar: {
137 case QSeries::SeriesTypeStackedBar: {
138
138
139 QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series);
139 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
140 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
140 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
141 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
141 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
142 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
142 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
@@ -145,9 +145,9 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
145 break;
145 break;
146 }
146 }
147
147
148 case QChartSeries::SeriesTypePercentBar: {
148 case QSeries::SeriesTypePercentBar: {
149
149
150 QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series);
150 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
151 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
151 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
152 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
152 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
153 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
153 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
@@ -155,7 +155,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
155 m_chartItems.insert(series,item);
155 m_chartItems.insert(series,item);
156 break;
156 break;
157 }
157 }
158 case QChartSeries::SeriesTypeScatter: {
158 case QSeries::SeriesTypeScatter: {
159 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
159 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
160 ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart);
160 ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart);
161 QObject::connect(scatterPresenter, SIGNAL(clicked()), scatterSeries, SIGNAL(clicked()));
161 QObject::connect(scatterPresenter, SIGNAL(clicked()), scatterSeries, SIGNAL(clicked()));
@@ -165,7 +165,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
165 m_chartItems.insert(scatterSeries, scatterPresenter);
165 m_chartItems.insert(scatterSeries, scatterPresenter);
166 break;
166 break;
167 }
167 }
168 case QChartSeries::SeriesTypePie: {
168 case QSeries::SeriesTypePie: {
169 QPieSeries *s = qobject_cast<QPieSeries *>(series);
169 QPieSeries *s = qobject_cast<QPieSeries *>(series);
170 PiePresenter* pie = new PiePresenter(m_chart, s);
170 PiePresenter* pie = new PiePresenter(m_chart, s);
171 m_chartTheme->decorate(pie, s, m_chartItems.count());
171 m_chartTheme->decorate(pie, s, m_chartItems.count());
@@ -197,18 +197,18 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
197 if(m_rect.isValid()) emit geometryChanged(m_rect);
197 if(m_rect.isValid()) emit geometryChanged(m_rect);
198 }
198 }
199
199
200 void ChartPresenter::handleSeriesRemoved(QChartSeries* series)
200 void ChartPresenter::handleSeriesRemoved(QSeries* series)
201 {
201 {
202 ChartItem* item = m_chartItems.take(series);
202 ChartItem* item = m_chartItems.take(series);
203 delete item;
203 delete item;
204 }
204 }
205
205
206 void ChartPresenter::handleSeriesChanged(QChartSeries* series)
206 void ChartPresenter::handleSeriesChanged(QSeries* series)
207 {
207 {
208 //TODO:
208 //TODO:
209 }
209 }
210
210
211 void ChartPresenter::handleSeriesDomainChanged(QChartSeries* series, const Domain& domain)
211 void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain)
212 {
212 {
213 m_chartItems.value(series)->handleDomainChanged(domain);
213 m_chartItems.value(series)->handleDomainChanged(domain);
214 }
214 }
@@ -225,7 +225,7 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
225 m_chartTheme = ChartTheme::createTheme(theme);
225 m_chartTheme = ChartTheme::createTheme(theme);
226
226
227 m_chartTheme->decorate(m_chart);
227 m_chartTheme->decorate(m_chart);
228 QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems);
228 QMapIterator<QSeries*,ChartItem*> i(m_chartItems);
229
229
230 int index=0;
230 int index=0;
231 while (i.hasNext()) {
231 while (i.hasNext()) {
@@ -255,13 +255,13 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
255 //recreate elements
255 //recreate elements
256
256
257 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
257 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
258 QList<QChartSeries*> seriesList = m_chartItems.uniqueKeys();
258 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
259
259
260 foreach(QChartAxis* axis, axisList) {
260 foreach(QChartAxis* axis, axisList) {
261 handleAxisRemoved(axis);
261 handleAxisRemoved(axis);
262 handleAxisAdded(axis);
262 handleAxisAdded(axis);
263 }
263 }
264 foreach(QChartSeries* series, seriesList) {
264 foreach(QSeries* series, seriesList) {
265 handleSeriesRemoved(series);
265 handleSeriesRemoved(series);
266 handleSeriesAdded(series);
266 handleSeriesAdded(series);
267 }
267 }
@@ -9,7 +9,7
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class ChartItem;
11 class ChartItem;
12 class QChartSeries;
12 class QSeries;
13 class ChartDataSet;
13 class ChartDataSet;
14 //class QChart;
14 //class QChart;
15 class Domain;
15 class Domain;
@@ -20,7 +20,14 class ChartPresenter: public QObject
20 {
20 {
21 Q_OBJECT
21 Q_OBJECT
22 public:
22 public:
23 enum ZValues { BackgroundZValue = -1 , ShadesZValue, GridZValue, AxisZValue , LineChartZValue };
23 enum ZValues {
24 BackgroundZValue = -1,
25 ShadesZValue,
26 GridZValue,
27 AxisZValue,
28 LineChartZValue,
29 ScatterSeriesZValue
30 };
24
31
25 ChartPresenter(QChart* chart,ChartDataSet *dataset);
32 ChartPresenter(QChart* chart,ChartDataSet *dataset);
26 virtual ~ChartPresenter();
33 virtual ~ChartPresenter();
@@ -40,18 +47,18 private:
40 void createConnections();
47 void createConnections();
41
48
42 public slots:
49 public slots:
43 void handleSeriesAdded(QChartSeries* series);
50 void handleSeriesAdded(QSeries* series);
44 void handleSeriesRemoved(QChartSeries* series);
51 void handleSeriesRemoved(QSeries* series);
45 void handleAxisAdded(QChartAxis* axis);
52 void handleAxisAdded(QChartAxis* axis);
46 void handleAxisRemoved(QChartAxis* axis);
53 void handleAxisRemoved(QChartAxis* axis);
47 void handleSeriesDomainChanged(QChartSeries* series, const Domain& domain);
54 void handleSeriesDomainChanged(QSeries* series, const Domain& domain);
48 void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels);
55 void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels);
49 void handleSeriesChanged(QChartSeries* series);
56 void handleSeriesChanged(QSeries* series);
50 void handleGeometryChanged();
57 void handleGeometryChanged();
51 signals:
58 signals:
52 void geometryChanged(const QRectF& rect);
59 void geometryChanged(const QRectF& rect);
53 private:
60 private:
54 QMap<QChartSeries*,ChartItem*> m_chartItems;
61 QMap<QSeries*,ChartItem*> m_chartItems;
55 QMap<QChartAxis*,AxisItem*> m_axisItems;
62 QMap<QChartAxis*,AxisItem*> m_axisItems;
56 QChart* m_chart;
63 QChart* m_chart;
57 ChartDataSet* m_dataset;
64 ChartDataSet* m_dataset;
@@ -5,22 +5,22
5
5
6 //series
6 //series
7 #include "qbarset.h"
7 #include "qbarset.h"
8 #include "qbarchartseries.h"
8 #include "qbarseries.h"
9 #include "qstackedbarchartseries.h"
9 #include "qstackedbarseries.h"
10 #include "qpercentbarchartseries.h"
10 #include "qpercentbarseries.h"
11 #include "qlinechartseries.h"
11 #include "qlineseries.h"
12 #include "qscatterseries.h"
12 #include "qscatterseries.h"
13 #include "qpieseries.h"
13 #include "qpieseries.h"
14 #include "qpieslice.h"
14 #include "qpieslice.h"
15
15
16 //items
16 //items
17 #include "axisitem_p.h"
17 #include "axisitem_p.h"
18 #include "barpresenter.h"
18 #include "barpresenter_p.h"
19 #include "stackedbarpresenter.h"
19 #include "stackedbarpresenter_p.h"
20 #include "percentbarpresenter_p.h"
20 #include "linechartitem_p.h"
21 #include "linechartitem_p.h"
21 #include "percentbarpresenter.h"
22 #include "scatterpresenter_p.h"
22 #include "scatterpresenter_p.h"
23 #include "piepresenter.h"
23 #include "piepresenter_p.h"
24
24
25 //themes
25 //themes
26 #include "chartthemevanilla_p.h"
26 #include "chartthemevanilla_p.h"
@@ -80,35 +80,35 void ChartTheme::decorate(QChart* chart)
80 chart->setChartBackgroundBrush(backgroundGradient);
80 chart->setChartBackgroundBrush(backgroundGradient);
81 }
81 }
82 //TODO helper to by removed later
82 //TODO helper to by removed later
83 void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count)
83 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count)
84 {
84 {
85 switch(series->type())
85 switch(series->type())
86 {
86 {
87 case QChartSeries::SeriesTypeLine: {
87 case QSeries::SeriesTypeLine: {
88 QLineChartSeries* s = static_cast<QLineChartSeries*>(series);
88 QLineSeries* s = static_cast<QLineSeries*>(series);
89 LineChartItem* i = static_cast<LineChartItem*>(item);
89 LineChartItem* i = static_cast<LineChartItem*>(item);
90 decorate(i,s,count);
90 decorate(i,s,count);
91 break;
91 break;
92 }
92 }
93 case QChartSeries::SeriesTypeBar: {
93 case QSeries::SeriesTypeBar: {
94 QBarChartSeries* b = static_cast<QBarChartSeries*>(series);
94 QBarSeries* b = static_cast<QBarSeries*>(series);
95 BarPresenter* i = static_cast<BarPresenter*>(item);
95 BarPresenter* i = static_cast<BarPresenter*>(item);
96 decorate(i,b,count);
96 decorate(i,b,count);
97 break;
97 break;
98 }
98 }
99 case QChartSeries::SeriesTypeStackedBar: {
99 case QSeries::SeriesTypeStackedBar: {
100 QStackedBarChartSeries* s = static_cast<QStackedBarChartSeries*>(series);
100 QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series);
101 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
101 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
102 decorate(i,s,count);
102 decorate(i,s,count);
103 break;
103 break;
104 }
104 }
105 case QChartSeries::SeriesTypePercentBar: {
105 case QSeries::SeriesTypePercentBar: {
106 QPercentBarChartSeries* s = static_cast<QPercentBarChartSeries*>(series);
106 QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series);
107 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
107 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
108 decorate(i,s,count);
108 decorate(i,s,count);
109 break;
109 break;
110 }
110 }
111 case QChartSeries::SeriesTypeScatter: {
111 case QSeries::SeriesTypeScatter: {
112 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
112 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
113 Q_ASSERT(s);
113 Q_ASSERT(s);
114 ScatterPresenter* i = static_cast<ScatterPresenter*>(item);
114 ScatterPresenter* i = static_cast<ScatterPresenter*>(item);
@@ -116,7 +116,7 void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count)
116 decorate(i, s, count);
116 decorate(i, s, count);
117 break;
117 break;
118 }
118 }
119 case QChartSeries::SeriesTypePie: {
119 case QSeries::SeriesTypePie: {
120 QPieSeries* s = static_cast<QPieSeries*>(series);
120 QPieSeries* s = static_cast<QPieSeries*>(series);
121 PiePresenter* i = static_cast<PiePresenter*>(item);
121 PiePresenter* i = static_cast<PiePresenter*>(item);
122 decorate(i,s,count);
122 decorate(i,s,count);
@@ -129,7 +129,7 void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count)
129
129
130 }
130 }
131
131
132 void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count)
132 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
133 {
133 {
134 QPen pen;
134 QPen pen;
135 if(pen != series->pen()){
135 if(pen != series->pen()){
@@ -141,24 +141,27 void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int coun
141 item->setPen(pen);
141 item->setPen(pen);
142 }
142 }
143
143
144 void ChartTheme::decorate(BarPresenter* item, QBarChartSeries* series,int count)
144 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
145 {
145 {
146 for (int i=0; i<series->countSets(); i++) {
146 QList<QBarSet*> sets = series->barSets();
147 series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
147 for (int i=0; i<series->barsetCount(); i++) {
148 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
148 }
149 }
149 }
150 }
150
151
151 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarChartSeries* series,int count)
152 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
152 {
153 {
153 for (int i=0; i<series->countSets(); i++) {
154 QList<QBarSet*> sets = series->barSets();
154 series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
155 for (int i=0; i<series->barsetCount(); i++) {
156 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
155 }
157 }
156 }
158 }
157
159
158 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarChartSeries* series,int count)
160 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
159 {
161 {
160 for (int i=0; i<series->countSets(); i++) {
162 QList<QBarSet*> sets = series->barSets();
161 series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
163 for (int i=0; i<series->barsetCount(); i++) {
164 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
162 }
165 }
163 }
166 }
164
167
@@ -190,6 +193,10 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/)
190 QColor c = m_seriesColor[i++];
193 QColor c = m_seriesColor[i++];
191 i = i % m_seriesColor.count();
194 i = i % m_seriesColor.count();
192
195
196 // dont use black colors... looks bad
197 if (c == Qt::black)
198 continue;
199
193 // by default use the "raw" theme color
200 // by default use the "raw" theme color
194 if (!colors.contains(c)) {
201 if (!colors.contains(c)) {
195 colors << c;
202 colors << c;
@@ -8,14 +8,14
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class ChartItem;
10 class ChartItem;
11 class QChartSeries;
11 class QSeries;
12 class LineChartItem;
12 class LineChartItem;
13 class QLineChartSeries;
13 class QLineSeries;
14 class BarPresenter;
14 class BarPresenter;
15 class QBarChartSeries;
15 class QBarSeries;
16 class StackedBarPresenter;
16 class StackedBarPresenter;
17 class QStackedBarChartSeries;
17 class QStackedBarSeries;
18 class QPercentBarChartSeries;
18 class QPercentBarSeries;
19 class PercentBarPresenter;
19 class PercentBarPresenter;
20 class QScatterSeries;
20 class QScatterSeries;
21 class ScatterPresenter;
21 class ScatterPresenter;
@@ -30,11 +30,11 public:
30 static ChartTheme* createTheme(QChart::ChartTheme theme);
30 static ChartTheme* createTheme(QChart::ChartTheme theme);
31 QChart::ChartTheme id() const {return m_id;}
31 QChart::ChartTheme id() const {return m_id;}
32 void decorate(QChart* chart);
32 void decorate(QChart* chart);
33 void decorate(ChartItem* item, QChartSeries* series,int count);
33 void decorate(ChartItem* item, QSeries* series,int count);
34 void decorate(LineChartItem* item, QLineChartSeries*, int count);
34 void decorate(BarPresenter* item, QBarSeries* series,int count);
35 void decorate(BarPresenter* item, QBarChartSeries* series,int count);
35 void decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count);
36 void decorate(StackedBarPresenter* item, QStackedBarChartSeries* series,int count);
36 void decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count);
37 void decorate(PercentBarPresenter* item, QPercentBarChartSeries* series,int count);
37 void decorate(LineChartItem* item, QLineSeries*, int count);
38 void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count);
38 void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count);
39 void decorate(PiePresenter* item, QPieSeries* series, int count);
39 void decorate(PiePresenter* item, QPieSeries* series, int count);
40 void decorate(QChartAxis* axis,AxisItem* item);
40 void decorate(QChartAxis* axis,AxisItem* item);
@@ -4,11 +4,11 DEPENDPATH += $$PWD
4 SOURCES += \
4 SOURCES += \
5 $$PWD/linechartanimationitem.cpp \
5 $$PWD/linechartanimationitem.cpp \
6 $$PWD/linechartitem.cpp \
6 $$PWD/linechartitem.cpp \
7 $$PWD/qlinechartseries.cpp
7 $$PWD/qlineseries.cpp
8
8
9 PRIVATE_HEADERS += \
9 PRIVATE_HEADERS += \
10 $$PWD/linechartitem_p.h \
10 $$PWD/linechartitem_p.h \
11 $$PWD/linechartanimationitem_p.h
11 $$PWD/linechartanimationitem_p.h
12
12
13 PUBLIC_HEADERS += \
13 PUBLIC_HEADERS += \
14 $$PWD/qlinechartseries.h No newline at end of file
14 $$PWD/qlineseries.h No newline at end of file
@@ -7,7 +7,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 const static int duration = 500;
7 const static int duration = 500;
8
8
9
9
10 LineChartAnimationItem::LineChartAnimationItem(ChartPresenter* presenter, QLineChartSeries* series,QGraphicsItem *parent):
10 LineChartAnimationItem::LineChartAnimationItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent):
11 LineChartItem(presenter,series,parent)
11 LineChartItem(presenter,series,parent)
12 {
12 {
13
13
@@ -14,7 +14,7 class LineChartAnimationItem : public LineChartItem {
14 Q_PROPERTY(int a_addPoints READ ar_addPoints WRITE aw_addPoints);
14 Q_PROPERTY(int a_addPoints READ ar_addPoints WRITE aw_addPoints);
15 // Q_PROPERTY(QPointF a_setPoint READ ar_setPoint WRITE aw_setPoint);
15 // Q_PROPERTY(QPointF a_setPoint READ ar_setPoint WRITE aw_setPoint);
16 public:
16 public:
17 LineChartAnimationItem(ChartPresenter* presenter, QLineChartSeries *series, QGraphicsItem *parent = 0);
17 LineChartAnimationItem(ChartPresenter* presenter, QLineSeries *series, QGraphicsItem *parent = 0);
18 virtual ~LineChartAnimationItem();
18 virtual ~LineChartAnimationItem();
19
19
20 void addPoints(const QVector<QPointF>& points);
20 void addPoints(const QVector<QPointF>& points);
@@ -1,5 +1,5
1 #include "linechartitem_p.h"
1 #include "linechartitem_p.h"
2 #include "qlinechartseries.h"
2 #include "qlineseries.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include <QPainter>
4 #include <QPainter>
5
5
@@ -8,7 +8,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 //TODO: optimazie : remove points which are not visible
9 //TODO: optimazie : remove points which are not visible
10
10
11 LineChartItem::LineChartItem(ChartPresenter* presenter, QLineChartSeries* series,QGraphicsItem *parent):ChartItem(parent),
11 LineChartItem::LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent):ChartItem(parent),
12 m_presenter(presenter),
12 m_presenter(presenter),
13 m_series(series),
13 m_series(series),
14 m_dirtyData(false),
14 m_dirtyData(false),
@@ -36,7 +36,7 void LineChartItem::addPoints(const QVector<QPointF>& points)
36 const QPointF& point =m_data[i];
36 const QPointF& point =m_data[i];
37 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
37 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
38 item->setPos(point.x()-1,point.y()-1);;
38 item->setPos(point.x()-1,point.y()-1);;
39 if(!m_clipRect.contains(point) || !m_series->isPointsVisible()) item->setVisible(false);
39 if(!m_clipRect.contains(point) || !m_series->pointsVisible()) item->setVisible(false);
40 m_points << item;
40 m_points << item;
41 }
41 }
42 }
42 }
@@ -47,7 +47,7 void LineChartItem::addPoint(const QPointF& point)
47 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
47 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
48 m_clipRect.contains(point);
48 m_clipRect.contains(point);
49 item->setPos(point.x()-1,point.y()-1);
49 item->setPos(point.x()-1,point.y()-1);
50 if(!m_clipRect.contains(point) || !m_series->isPointsVisible()) item->setVisible(false);
50 if(!m_clipRect.contains(point) || !m_series->pointsVisible()) item->setVisible(false);
51 m_points << item;
51 m_points << item;
52 }
52 }
53
53
@@ -111,7 +111,7 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
111 painter->restore();
111 painter->restore();
112 }
112 }
113
113
114 void LineChartItem::calculatePoint(QPointF& point, int index, const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const
114 void LineChartItem::calculatePoint(QPointF& point, int index, const QLineSeries* series,const QSizeF& size, const Domain& domain) const
115 {
115 {
116 const qreal deltaX = size.width()/domain.spanX();
116 const qreal deltaX = size.width()/domain.spanX();
117 const qreal deltaY = size.height()/domain.spanY();
117 const qreal deltaY = size.height()/domain.spanY();
@@ -122,7 +122,7 void LineChartItem::calculatePoint(QPointF& point, int index, const QLineChartSe
122 }
122 }
123
123
124
124
125 void LineChartItem::calculatePoints(QVector<QPointF>& points, QHash<int,int>& hash,const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const
125 void LineChartItem::calculatePoints(QVector<QPointF>& points, QHash<int,int>& hash,const QLineSeries* series,const QSizeF& size, const Domain& domain) const
126 {
126 {
127 const qreal deltaX = size.width()/domain.spanX();
127 const qreal deltaX = size.width()/domain.spanX();
128 const qreal deltaY = size.height()/domain.spanY();
128 const qreal deltaY = size.height()/domain.spanY();
@@ -8,14 +8,14
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class ChartPresenter;
10 class ChartPresenter;
11 class QLineChartSeries;
11 class QLineSeries;
12 class LineChartAnimationItem;
12 class LineChartAnimationItem;
13
13
14 class LineChartItem : public QObject , public ChartItem
14 class LineChartItem : public QObject , public ChartItem
15 {
15 {
16 Q_OBJECT
16 Q_OBJECT
17 public:
17 public:
18 LineChartItem(ChartPresenter* presenter, QLineChartSeries* series,QGraphicsItem *parent = 0);
18 LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent = 0);
19 ~ LineChartItem(){};
19 ~ LineChartItem(){};
20
20
21 //from QGraphicsItem
21 //from QGraphicsItem
@@ -43,8 +43,8 protected:
43 virtual void updateData();
43 virtual void updateData();
44 virtual void updateDomain();
44 virtual void updateDomain();
45 //refactor
45 //refactor
46 void calculatePoint(QPointF& point, int index, const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const;
46 void calculatePoint(QPointF& point, int index, const QLineSeries* series,const QSizeF& size, const Domain& domain) const;
47 void calculatePoints(QVector<QPointF>& points,QHash<int,int>& hash,const QLineChartSeries* series, const QSizeF& size, const Domain& domain) const;
47 void calculatePoints(QVector<QPointF>& points,QHash<int,int>& hash,const QLineSeries* series, const QSizeF& size, const Domain& domain) const;
48
48
49 protected slots:
49 protected slots:
50 void handleModelChanged(int index);
50 void handleModelChanged(int index);
@@ -61,7 +61,7 private:
61 QList<QGraphicsItem*> m_points;
61 QList<QGraphicsItem*> m_points;
62 QVector<QPointF> m_data;
62 QVector<QPointF> m_data;
63 QHash<int,int> m_hash;
63 QHash<int,int> m_hash;
64 QLineChartSeries* m_series;
64 QLineSeries* m_series;
65 QPen m_pen;
65 QPen m_pen;
66 bool m_dirtyData;
66 bool m_dirtyData;
67 bool m_dirtyGeometry;
67 bool m_dirtyGeometry;
@@ -1,10 +1,10
1 #include "qlinechartseries.h"
1 #include "qlineseries.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
5 /*!
6 \class QLineChartSeries
6 \class QLineSeries
7 \brief The QLineChartSeries class is used for making line charts.
7 \brief The QLineSeries class is used for making line charts.
8
8
9 \mainclass
9 \mainclass
10
10
@@ -13,41 +13,47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
13
14 \image linechart.png
14 \image linechart.png
15
15
16 To create line charts, users need to first QLineChartSeries object.
16 Creating basic line chart is simple:
17
17 \code
18 \snippet ../example/linechart/main.cpp 1
18 QLineSeries* series = new QLineSeries();
19
19 series->add(0, 6);
20 Populate with the data
20 series->add(2, 4);
21
21 ...
22 \snippet ../example/linechart/main.cpp 2
22 chartView->addSeries(series);
23
23 \endcode
24 Add created series objects to QChartView or QChart instance.
25
26 \snippet ../example/linechart/main.cpp 3
27
28 */
24 */
29
25
30 /*!
26 /*!
31 \fn virtual QChartSeriesType QLineChartSeries::type() const
27 \fn virtual QSeriesType QLineSeries::type() const
32 \brief Returns type of series.
28 \brief Returns type of series.
33 \sa QChartSeries, QChartSeriesType
29 \sa QSeries, QSeriesType
34 */
30 */
35
31
36 /*!
32 /*!
37 \fn QPen QLineChartSeries::pen() const
33 \fn QPen QLineSeries::pen() const
38 \brief Returns the pen used to draw line for this series.
34 \brief Returns the pen used to draw line for this series.
39 \sa setPen()
35 \sa setPen()
40 */
36 */
41
37
42 /*!
38 /*!
43 \fn bool QLineChartSeries::isPointsVisible() const
39 \fn bool QLineSeries::pointsVisible() const
44 \brief Returns if the points are drawn for this series.
40 \brief Returns if the points are drawn for this series.
45 \sa setPointsVisible()
41 \sa setPointsVisible()
46 */
42 */
47
43
48
44
49 /*!
45 /*!
50 \fn void QLineChartSeries::changed(int index)
46 \fn void QLineSeries::pointChanged(int index)
47 \brief \internal \a index
48 */
49
50 /*!
51 \fn void QLineSeries::pointAdded(int index)
52 \brief \internal \a index
53 */
54
55 /*!
56 \fn void QLineSeries::pointRemoved(int index)
51 \brief \internal \a index
57 \brief \internal \a index
52 */
58 */
53
59
@@ -55,7 +61,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
55 Constructs empty series object which is a child of \a parent.
61 Constructs empty series object which is a child of \a parent.
56 When series object is added to QChartView or QChart instance ownerships is transfered.
62 When series object is added to QChartView or QChart instance ownerships is transfered.
57 */
63 */
58 QLineChartSeries::QLineChartSeries(QObject* parent):QChartSeries(parent),
64 QLineSeries::QLineSeries(QObject* parent):QSeries(parent),
59 m_pointsVisible(false)
65 m_pointsVisible(false)
60 {
66 {
61 }
67 }
@@ -63,59 +69,73 m_pointsVisible(false)
63 Destroys the object. Series added to QChartView or QChart instances are owned by those,
69 Destroys the object. Series added to QChartView or QChart instances are owned by those,
64 and are deleted when mentioned object are destroyed.
70 and are deleted when mentioned object are destroyed.
65 */
71 */
66 QLineChartSeries::~QLineChartSeries()
72 QLineSeries::~QLineSeries()
67 {
73 {
68 }
74 }
69
75
70 /*!
76 /*!
71 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
77 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
72 Function returns index, which can be used to modify data.
73 */
78 */
74 int QLineChartSeries::add(qreal x,qreal y)
79 void QLineSeries::add(qreal x,qreal y)
75 {
80 {
81 Q_ASSERT(m_x.size() == m_y.size());
76 m_x<<x;
82 m_x<<x;
77 m_y<<y;
83 m_y<<y;
78 return m_x.size()-1;
84 emit pointAdded(m_x.size()-1);
79 }
85 }
80
86
81 /*!
87 /*!
82 This is an overloaded function.
88 This is an overloaded function.
83 Adds data \a point to the series. Points are connected with lines on the chart.
89 Adds data \a point to the series. Points are connected with lines on the chart.
84 Function returns index, which can be used to modify data.
85 */
90 */
86 int QLineChartSeries::add(const QPointF& point)
91 void QLineSeries::add(const QPointF& point)
87 {
92 {
88 m_x<<point.x();
93 add(point.x(),point.y());
89 m_y<<point.y();
90 return m_x.size()-1;
91 }
94 }
92
95
93 /*!
96 /*!
94 Modifies data within \a index, sets new \a x and \a y values.
97 Modifies \a y value for given \a x a value.
95 */
98 */
96 void QLineChartSeries::set(int index,qreal x,qreal y)
99 void QLineSeries::replace(qreal x,qreal y)
97 {
100 {
101 int index = m_x.indexOf(x);
98 m_x[index]=x;
102 m_x[index]=x;
99 m_y[index]=y;
103 m_y[index]=y;
100 emit changed(index);
104 emit pointChanged(index);
101 }
105 }
102
106
103 /*!
107 /*!
104 This is an overloaded function.
108 This is an overloaded function.
105 Modifies data within \a index, sets new \a point value.
109 Replaces current y value of for given \a point x value with \a point y value.
106 */
110 */
107 void QLineChartSeries::set(int index,const QPointF& point)
111 void QLineSeries::replace(const QPointF& point)
108 {
112 {
109 m_x[index]=point.x();
113 replace(point.x(),point.y());
110 m_y[index]=point.y();
111 emit changed(index);
112 }
114 }
113
115
116 /*!
117 Removes current \a x and y value.
118 */
119 void QLineSeries::remove(qreal x)
120 {
121 int index = m_x.indexOf(x);
122 m_x.remove(index);
123 m_y.remove(index);
124 emit pointRemoved(index);
125 }
126
127 /*!
128 Removes current \a point x value. Note \a point y value is ignored.
129 */
130 void QLineSeries::remove(const QPointF& point)
131 {
132 remove(point.x());
133 }
114
134
115 /*!
135 /*!
116 Clears all the data.
136 Clears all the data.
117 */
137 */
118 void QLineChartSeries::clear()
138 void QLineSeries::clear()
119 {
139 {
120 m_x.clear();
140 m_x.clear();
121 m_y.clear();
141 m_y.clear();
@@ -124,7 +144,7 void QLineChartSeries::clear()
124 /*!
144 /*!
125 \internal \a pos
145 \internal \a pos
126 */
146 */
127 qreal QLineChartSeries::x(int pos) const
147 qreal QLineSeries::x(int pos) const
128 {
148 {
129 return m_x.at(pos);
149 return m_x.at(pos);
130 }
150 }
@@ -132,7 +152,7 qreal QLineChartSeries::x(int pos) const
132 /*!
152 /*!
133 \internal \a pos
153 \internal \a pos
134 */
154 */
135 qreal QLineChartSeries::y(int pos) const
155 qreal QLineSeries::y(int pos) const
136 {
156 {
137 return m_y.at(pos);
157 return m_y.at(pos);
138 }
158 }
@@ -140,7 +160,7 qreal QLineChartSeries::y(int pos) const
140 /*!
160 /*!
141 Returns number of data points within series.
161 Returns number of data points within series.
142 */
162 */
143 int QLineChartSeries::count() const
163 int QLineSeries::count() const
144 {
164 {
145 Q_ASSERT(m_x.size() == m_y.size());
165 Q_ASSERT(m_x.size() == m_y.size());
146
166
@@ -151,7 +171,7 int QLineChartSeries::count() const
151 /*!
171 /*!
152 Sets \a pen used for drawing given series..
172 Sets \a pen used for drawing given series..
153 */
173 */
154 void QLineChartSeries::setPen(const QPen& pen)
174 void QLineSeries::setPen(const QPen& pen)
155 {
175 {
156 m_pen=pen;
176 m_pen=pen;
157 }
177 }
@@ -159,12 +179,12 void QLineChartSeries::setPen(const QPen& pen)
159 /*!
179 /*!
160 Sets if data points are \a visible and should be drawn on line.
180 Sets if data points are \a visible and should be drawn on line.
161 */
181 */
162 void QLineChartSeries::setPointsVisible(bool visible)
182 void QLineSeries::setPointsVisible(bool visible)
163 {
183 {
164 m_pointsVisible=visible;
184 m_pointsVisible=visible;
165 }
185 }
166
186
167 QDebug operator<< (QDebug debug, const QLineChartSeries series)
187 QDebug operator<< (QDebug debug, const QLineSeries series)
168 {
188 {
169 Q_ASSERT(series.m_x.size() == series.m_y.size());
189 Q_ASSERT(series.m_x.size() == series.m_y.size());
170
190
@@ -176,7 +196,18 QDebug operator<< (QDebug debug, const QLineChartSeries series)
176 return debug.space();
196 return debug.space();
177 }
197 }
178
198
199 /*!
200 Stream operator for adding a data \a point to the series.
201 \sa add()
202 */
203
204 QLineSeries& QLineSeries::operator<< (const QPointF &point)
205 {
206 add(point);
207 return *this;
208 }
209
179
210
180 #include "moc_qlinechartseries.cpp"
211 #include "moc_qlineseries.cpp"
181
212
182 QTCOMMERCIALCHART_END_NAMESPACE
213 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,42 +1,48
1 #ifndef QLINECHARTSERIES_H_
1 #ifndef QLINESERIES_H_
2 #define QLINECHARTSERIES_H_
2 #define QLINESERIES_H_
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchartseries.h"
5 #include "qseries.h"
6 #include <QDebug>
6 #include <QDebug>
7 #include <QPen>
7 #include <QPen>
8 #include <QBrush>
8 #include <QBrush>
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 class QTCOMMERCIALCHART_EXPORT QLineChartSeries : public QChartSeries
12 class QTCOMMERCIALCHART_EXPORT QLineSeries : public QSeries
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 public:
15 public:
16 QLineChartSeries(QObject* parent=0);
16 QLineSeries(QObject* parent=0);
17 virtual ~QLineChartSeries();
17 virtual ~QLineSeries();
18
18
19 public: // from QChartSeries
19 public: // from QChartSeries
20 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeLine;}
20 virtual QSeriesType type() const { return QSeries::SeriesTypeLine;}
21 int add(qreal x, qreal y);
21 void add(qreal x, qreal y);
22 int add(const QPointF& point);
22 void add(const QPointF& point);
23 void set(int index,qreal x,qreal y);
23 void replace(qreal x,qreal y);
24 void set(int index,const QPointF& point);
24 void replace(const QPointF& point);
25 void remove(qreal x);
26 void remove(const QPointF& point);
25 void clear();
27 void clear();
26
28
27 void setPen(const QPen& pen);
29 void setPen(const QPen& pen);
28 QPen pen() const { return m_pen;}
30 QPen pen() const { return m_pen;}
29
31
30 void setPointsVisible(bool visible);
32 void setPointsVisible(bool visible);
31 bool isPointsVisible() const {return m_pointsVisible;}
33 bool pointsVisible() const {return m_pointsVisible;}
32
34
33 int count() const;
35 int count() const;
34 qreal x(int pos) const;
36 qreal x(int pos) const;
35 qreal y(int pos) const;
37 qreal y(int pos) const;
36 friend QDebug operator<< (QDebug d, const QLineChartSeries series);
38
39 QLineSeries& operator << (const QPointF &point);
40 friend QDebug operator<< (QDebug d, const QLineSeries series);
37
41
38 signals:
42 signals:
39 void changed(int index);
43 void pointChanged(int index);
44 void pointRemoved(int index);
45 void pointAdded(int index);
40
46
41 private:
47 private:
42 QVector<qreal> m_x;
48 QVector<qreal> m_x;
@@ -9,9 +9,9 SOURCES += \
9 $$PWD/qpieslice.cpp
9 $$PWD/qpieslice.cpp
10
10
11 PRIVATE_HEADERS += \
11 PRIVATE_HEADERS += \
12 $$PWD/piepresenter.h \
12 $$PWD/piepresenter_p.h \
13 $$PWD/pieslice.h \
13 $$PWD/pieslice_p.h \
14 $$PWD/pieslicelabel.h
14 $$PWD/pieslicelabel_p.h
15
15
16 PUBLIC_HEADERS += \
16 PUBLIC_HEADERS += \
17 $$PWD/qpieseries.h \
17 $$PWD/qpieseries.h \
@@ -1,8 +1,8
1
1
2 #include "piepresenter.h"
2 #include "piepresenter_p.h"
3 #include "pieslice.h"
3 #include "pieslice_p.h"
4 #include "qpieslice.h"
4 #include "qpieslice.h"
5 #include "pieslicelabel.h"
5 #include "pieslicelabel_p.h"
6 #include "qpieseries.h"
6 #include "qpieseries.h"
7 #include <qmath.h>
7 #include <qmath.h>
8 #include <QDebug>
8 #include <QDebug>
@@ -123,7 +123,7 void PiePresenter::updateGeometry()
123 foreach (QPieSlice* s, m_series->m_slices) {
123 foreach (QPieSlice* s, m_series->m_slices) {
124
124
125 // calculate the farthest point in the slice from the pie center
125 // calculate the farthest point in the slice from the pie center
126 qreal centerAngle = s->angle() + (s->angleSpan() / 2);
126 qreal centerAngle = s->m_startAngle + (s->m_angleSpan / 2);
127 qreal len = pieRadius + s->labelArmLength() + s->explodeDistance();
127 qreal len = pieRadius + s->labelArmLength() + s->explodeDistance();
128 QPointF dp(qSin(centerAngle*(PI/180)) * len, -qCos(centerAngle*(PI/180)) * len);
128 QPointF dp(qSin(centerAngle*(PI/180)) * len, -qCos(centerAngle*(PI/180)) * len);
129 QPointF p = pieRect.center() + dp;
129 QPointF p = pieRect.center() + dp;
@@ -205,6 +205,6 void PiePresenter::deleteSlice(QPieSlice* sliceData)
205 delete m_slices.take(sliceData);
205 delete m_slices.take(sliceData);
206 }
206 }
207
207
208 #include "moc_piepresenter.cpp"
208 #include "moc_piepresenter_p.cpp"
209
209
210 QTCOMMERCIALCHART_END_NAMESPACE
210 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file renamed from src/piechart/piepresenter.h to src/piechart/piepresenter_p.h
NO CONTENT: file renamed from src/piechart/piepresenter.h to src/piechart/piepresenter_p.h
@@ -1,6 +1,6
1 #include "pieslice.h"
1 #include "pieslice_p.h"
2 #include "pieslicelabel.h"
2 #include "pieslicelabel_p.h"
3 #include "piepresenter.h"
3 #include "piepresenter_p.h"
4 #include "qpieseries.h"
4 #include "qpieseries.h"
5 #include "qpieslice.h"
5 #include "qpieslice.h"
6 #include <QPainter>
6 #include <QPainter>
@@ -21,7 +21,7 QPointF offset(qreal angle, qreal length)
21 PieSlice::PieSlice(QGraphicsItem* parent)
21 PieSlice::PieSlice(QGraphicsItem* parent)
22 :QGraphicsObject(parent),
22 :QGraphicsObject(parent),
23 m_slicelabel(new PieSliceLabel(this)),
23 m_slicelabel(new PieSliceLabel(this)),
24 m_angle(0),
24 m_startAngle(0),
25 m_angleSpan(0),
25 m_angleSpan(0),
26 m_isExploded(false),
26 m_isExploded(false),
27 m_explodeDistance(0)
27 m_explodeDistance(0)
@@ -80,7 +80,7 void PieSlice::updateGeometry()
80 prepareGeometryChange();
80 prepareGeometryChange();
81
81
82 // calculate center angle
82 // calculate center angle
83 qreal centerAngle = m_angle + (m_angleSpan/2);
83 qreal centerAngle = m_startAngle + (m_angleSpan/2);
84
84
85 // adjust rect for exploding
85 // adjust rect for exploding
86 QRectF rect = m_pieRect;
86 QRectF rect = m_pieRect;
@@ -94,7 +94,7 void PieSlice::updateGeometry()
94 // TODO: draw the shape so that it might have a hole in the center
94 // TODO: draw the shape so that it might have a hole in the center
95 QPainterPath path;
95 QPainterPath path;
96 path.moveTo(rect.center());
96 path.moveTo(rect.center());
97 path.arcTo(rect, -m_angle + 90, -m_angleSpan);
97 path.arcTo(rect, -m_startAngle + 90, -m_angleSpan);
98 path.closeSubpath();
98 path.closeSubpath();
99 m_path = path;
99 m_path = path;
100
100
@@ -113,8 +113,8 void PieSlice::updateData(const QPieSlice* sliceData)
113 {
113 {
114 // TODO: compare what has changes to avoid unneccesary geometry updates
114 // TODO: compare what has changes to avoid unneccesary geometry updates
115
115
116 m_angle = sliceData->angle();
116 m_startAngle = sliceData->startAngle();
117 m_angleSpan = sliceData->angleSpan();
117 m_angleSpan = sliceData->m_angleSpan;
118 m_isExploded = sliceData->isExploded();
118 m_isExploded = sliceData->isExploded();
119 m_explodeDistance = sliceData->explodeDistance(); // TODO: expose to public API
119 m_explodeDistance = sliceData->explodeDistance(); // TODO: expose to public API
120 m_pen = sliceData->pen();
120 m_pen = sliceData->pen();
@@ -130,6 +130,6 void PieSlice::updateData(const QPieSlice* sliceData)
130 update();
130 update();
131 }
131 }
132
132
133 #include "moc_pieslice.cpp"
133 #include "moc_pieslice_p.cpp"
134
134
135 QTCOMMERCIALCHART_END_NAMESPACE
135 QTCOMMERCIALCHART_END_NAMESPACE
@@ -49,7 +49,7 private:
49 QRectF m_pieRect;
49 QRectF m_pieRect;
50 QPainterPath m_path;
50 QPainterPath m_path;
51
51
52 qreal m_angle;
52 qreal m_startAngle;
53 qreal m_angleSpan;
53 qreal m_angleSpan;
54
54
55 bool m_isExploded;
55 bool m_isExploded;
@@ -1,4 +1,4
1 #include "pieslicelabel.h"
1 #include "pieslicelabel_p.h"
2 #include <QPainter>
2 #include <QPainter>
3 #include <qmath.h>
3 #include <qmath.h>
4 #include <QGraphicsTextItem>
4 #include <QGraphicsTextItem>
1 NO CONTENT: file renamed from src/piechart/pieslicelabel.h to src/piechart/pieslicelabel_p.h
NO CONTENT: file renamed from src/piechart/pieslicelabel.h to src/piechart/pieslicelabel_p.h
@@ -1,8 +1,5
1 #include "qpieseries.h"
1 #include "qpieseries.h"
2 #include "qpieslice.h"
2 #include "qpieslice.h"
3 #include "piepresenter.h"
4 #include "pieslice.h"
5 #include <QFontMetrics>
6 #include <QDebug>
3 #include <QDebug>
7
4
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -113,13 +110,21 bool QPieSeries::ChangeSet::isEmpty() const
113
110
114 By default the pie is defined as full but it can be a partial pie.
111 By default the pie is defined as full but it can be a partial pie.
115 This can be done by setting a starting angle and angle span to the series.
112 This can be done by setting a starting angle and angle span to the series.
113
114 Example on how to create a chart with pie series:
115 \snippet ../example/piechart/main.cpp 1
116
117 To help with the most common user intercation scenarions there some convenience functions. Specifically
118 exploding and higlighting:
119 \snippet ../example/piechart/main.cpp 2
120
116 */
121 */
117
122
118 /*!
123 /*!
119 Constructs a series object which is a child of \a parent.
124 Constructs a series object which is a child of \a parent.
120 */
125 */
121 QPieSeries::QPieSeries(QObject *parent) :
126 QPieSeries::QPieSeries(QObject *parent) :
122 QChartSeries(parent),
127 QSeries(parent),
123 m_sizeFactor(1.0),
128 m_sizeFactor(1.0),
124 m_position(PiePositionMaximized),
129 m_position(PiePositionMaximized),
125 m_pieStartAngle(0),
130 m_pieStartAngle(0),
@@ -139,14 +144,13 QPieSeries::~QPieSeries()
139 /*!
144 /*!
140 Returns QChartSeries::SeriesTypePie.
145 Returns QChartSeries::SeriesTypePie.
141 */
146 */
142 QChartSeries::QChartSeriesType QPieSeries::type() const
147 QSeries::QSeriesType QPieSeries::type() const
143 {
148 {
144 return QChartSeries::SeriesTypePie;
149 return QSeries::SeriesTypePie;
145 }
150 }
146
151
147 /*!
152 /*!
148 Sets an array of values to the series.
153 \internal \a data
149 TO BE REMOVED
150 */
154 */
151 bool QPieSeries::setData(QList<qreal> data)
155 bool QPieSeries::setData(QList<qreal> data)
152 {
156 {
@@ -154,22 +158,22 bool QPieSeries::setData(QList<qreal> data)
154 QList<QPieSlice*> slices;
158 QList<QPieSlice*> slices;
155 foreach (qreal value, data)
159 foreach (qreal value, data)
156 slices << new QPieSlice(value, QString::number(value));
160 slices << new QPieSlice(value, QString::number(value));
157 set(slices);
161 replace(slices);
158 return true;
162 return true;
159 }
163 }
160
164
161 /*!
165 /*!
162 Sets an array of \a slices to the series.
166 Sets an array of \a slices to the series replacing the existing slices.
163 Slice ownership is passed to the series.
167 Slice ownership is passed to the series.
164 */
168 */
165 void QPieSeries::set(QList<QPieSlice*> slices)
169 void QPieSeries::replace(QList<QPieSlice*> slices)
166 {
170 {
167 clear();
171 clear();
168 add(slices);
172 add(slices);
169 }
173 }
170
174
171 /*!
175 /*!
172 Adds an array of slices to the series.
176 Adds an array of \a slices to the series.
173 Slice ownership is passed to the series.
177 Slice ownership is passed to the series.
174 */
178 */
175 void QPieSeries::add(QList<QPieSlice*> slices)
179 void QPieSeries::add(QList<QPieSlice*> slices)
@@ -345,9 +349,10 void QPieSeries::setLabelsVisible(bool visible)
345 }
349 }
346
350
347 /*!
351 /*!
348 Convenience method for exploding a slice when user clicks the pie.
352 Convenience method for exploding a slice when user clicks the pie. Set \a enable to true to
353 explode slices by clicking.
349
354
350 \sa QPieSlice::isExploded(), QPieSlice::setExploded()
355 \sa QPieSlice::isExploded(), QPieSlice::setExploded(), QPieSlice::setExplodeDistance()
351 */
356 */
352 void QPieSeries::enableClickExplodes(bool enable)
357 void QPieSeries::enableClickExplodes(bool enable)
353 {
358 {
@@ -360,6 +365,7 void QPieSeries::enableClickExplodes(bool enable)
360 /*!
365 /*!
361 Convenience method for highlighting a slice when user hovers over the slice.
366 Convenience method for highlighting a slice when user hovers over the slice.
362 It changes the slice color to be lighter and shows the label of the slice.
367 It changes the slice color to be lighter and shows the label of the slice.
368 Set \a enable to true to highlight a slice when user hovers on top of it.
363
369
364 \sa QPieSlice::isExploded(), QPieSlice::setExploded()
370 \sa QPieSlice::isExploded(), QPieSlice::setExploded()
365 */
371 */
@@ -512,8 +518,8 void QPieSeries::updateDerivativeData()
512 changed = true;
518 changed = true;
513 }
519 }
514
520
515 if (s->m_angle != sliceAngle) {
521 if (s->m_startAngle != sliceAngle) {
516 s->m_angle = sliceAngle;
522 s->m_startAngle = sliceAngle;
517 changed = true;
523 changed = true;
518 }
524 }
519 sliceAngle += sliceSpan;
525 sliceAngle += sliceSpan;
@@ -1,7 +1,7
1 #ifndef PIESERIES_H
1 #ifndef PIESERIES_H
2 #define PIESERIES_H
2 #define PIESERIES_H
3
3
4 #include "qchartseries.h"
4 #include "qseries.h"
5 #include <QObject>
5 #include <QObject>
6 #include <QRectF>
6 #include <QRectF>
7 #include <QColor>
7 #include <QColor>
@@ -15,7 +15,7 class PiePresenter;
15 class PieSlice;
15 class PieSlice;
16 class QPieSlice;
16 class QPieSlice;
17
17
18 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries
18 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries
19 {
19 {
20 Q_OBJECT
20 Q_OBJECT
21
21
@@ -55,11 +55,11 public:
55 virtual ~QPieSeries();
55 virtual ~QPieSeries();
56
56
57 public: // from QChartSeries
57 public: // from QChartSeries
58 QChartSeriesType type() const;
58 QSeriesType type() const;
59 virtual bool setData(QList<qreal> data); // TODO: remove this
59 virtual bool setData(QList<qreal> data); // TODO: remove this
60
60
61 public:
61 public:
62 void set(QList<QPieSlice*> slices);
62 void replace(QList<QPieSlice*> slices);
63 void add(QList<QPieSlice*> slices);
63 void add(QList<QPieSlice*> slices);
64 void add(QPieSlice* slice);
64 void add(QPieSlice* slice);
65 QPieSlice* add(qreal value, QString name);
65 QPieSlice* add(qreal value, QString name);
@@ -9,7 +9,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 /*!
10 /*!
11 \class QPieSlice
11 \class QPieSlice
12 \brief Defines a slice a pie series.
12 \brief Defines a slice in pie series.
13
13
14 Holds all the data of a single slice in a QPieSeries and provides the means
14 Holds all the data of a single slice in a QPieSeries and provides the means
15 to modify slice data and customize the visual appearance of the slice.
15 to modify slice data and customize the visual appearance of the slice.
@@ -35,7 +35,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 Note that QPieSeries takes ownership of the slice when it is set/added.
36 Note that QPieSeries takes ownership of the slice when it is set/added.
37
37
38 \sa QPieSeries::set(), QPieSeries::add()
38 \sa QPieSeries::replace(), QPieSeries::add()
39 */
39 */
40 QPieSlice::QPieSlice(QObject *parent)
40 QPieSlice::QPieSlice(QObject *parent)
41 :QObject(parent),
41 :QObject(parent),
@@ -44,7 +44,7 QPieSlice::QPieSlice(QObject *parent)
44 m_isExploded(false),
44 m_isExploded(false),
45 m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE),
45 m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE),
46 m_percentage(0),
46 m_percentage(0),
47 m_angle(0),
47 m_startAngle(0),
48 m_angleSpan(0),
48 m_angleSpan(0),
49 m_pen(DEFAULT_PEN_COLOR),
49 m_pen(DEFAULT_PEN_COLOR),
50 m_brush(DEFAULT_BRUSH_COLOR),
50 m_brush(DEFAULT_BRUSH_COLOR),
@@ -57,7 +57,7 QPieSlice::QPieSlice(QObject *parent)
57 /*!
57 /*!
58 Constructs an empty slice with given \a value, \a label and a \a parent.
58 Constructs an empty slice with given \a value, \a label and a \a parent.
59 Note that QPieSeries takes ownership of the slice when it is set/added.
59 Note that QPieSeries takes ownership of the slice when it is set/added.
60 \sa QPieSeries::set(), QPieSeries::add()
60 \sa QPieSeries::replace(), QPieSeries::add()
61 */
61 */
62 QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
62 QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
63 :QObject(parent),
63 :QObject(parent),
@@ -67,7 +67,7 QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
67 m_isExploded(false),
67 m_isExploded(false),
68 m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE),
68 m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE),
69 m_percentage(0),
69 m_percentage(0),
70 m_angle(0),
70 m_startAngle(0),
71 m_angleSpan(0),
71 m_angleSpan(0),
72 m_pen(DEFAULT_PEN_COLOR),
72 m_pen(DEFAULT_PEN_COLOR),
73 m_brush(DEFAULT_BRUSH_COLOR),
73 m_brush(DEFAULT_BRUSH_COLOR),
@@ -150,21 +150,21 qreal QPieSlice::percentage() const
150
150
151 Updated internally after the slice is added to the series.
151 Updated internally after the slice is added to the series.
152 */
152 */
153 qreal QPieSlice::angle() const
153 qreal QPieSlice::startAngle() const
154 {
154 {
155 return m_angle;
155 return m_startAngle;
156 }
156 }
157
157
158 /*!
158 /*!
159 Returns the angle span of this slice in the series it belongs to.
159 Returns the end angle of this slice in the series it belongs to.
160
160
161 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
161 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
162
162
163 Updated internally after the slice is added to the series.
163 Updated internally after the slice is added to the series.
164 */
164 */
165 qreal QPieSlice::angleSpan() const
165 qreal QPieSlice::endAngle() const
166 {
166 {
167 return m_angleSpan;
167 return m_startAngle + m_angleSpan;
168 }
168 }
169
169
170 /*!
170 /*!
@@ -29,8 +29,8 public:
29
29
30 // generated data
30 // generated data
31 qreal percentage() const;
31 qreal percentage() const;
32 qreal angle() const;
32 qreal startAngle() const;
33 qreal angleSpan() const;
33 qreal endAngle() const;
34
34
35 // customization
35 // customization
36 QPen pen() const;
36 QPen pen() const;
@@ -70,6 +70,7 private:
70 // TODO: use private class
70 // TODO: use private class
71 friend class QPieSeries;
71 friend class QPieSeries;
72 friend class PiePresenter;
72 friend class PiePresenter;
73 friend class PieSlice;
73
74
74 // data
75 // data
75 qreal m_value;
76 qreal m_value;
@@ -80,7 +81,7 private:
80
81
81 // generated data
82 // generated data
82 qreal m_percentage;
83 qreal m_percentage;
83 qreal m_angle;
84 qreal m_startAngle;
84 qreal m_angleSpan;
85 qreal m_angleSpan;
85
86
86 // customization
87 // customization
@@ -65,7 +65,7 QChart::~QChart()
65 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
65 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
66 the y axis).
66 the y axis).
67 */
67 */
68 void QChart::addSeries(QChartSeries* series, QChartAxis* axisY)
68 void QChart::addSeries(QSeries* series, QChartAxis* axisY)
69 {
69 {
70 m_dataset->addSeries(series, axisY);
70 m_dataset->addSeries(series, axisY);
71 }
71 }
@@ -76,7 +76,7 void QChart::addSeries(QChartSeries* series, QChartAxis* axisY)
76 It does not delete the pointed QChartSeries data object
76 It does not delete the pointed QChartSeries data object
77 \sa addSeries(), removeAllSeries()
77 \sa addSeries(), removeAllSeries()
78 */
78 */
79 void QChart::removeSeries(QChartSeries* series)
79 void QChart::removeSeries(QSeries* series)
80 {
80 {
81 m_dataset->removeSeries(series);
81 m_dataset->removeSeries(series);
82 }
82 }
@@ -2,7 +2,7
2 #define QCHART_H
2 #define QCHART_H
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <qchartseries.h>
5 #include <qseries.h>
6 #include <QGraphicsWidget>
6 #include <QGraphicsWidget>
7 #include <QLinearGradient>
7 #include <QLinearGradient>
8 #include <QFont>
8 #include <QFont>
@@ -12,7 +12,7 class QGraphicsSceneResizeEvent;
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
13
14 class AxisItem;
14 class AxisItem;
15 class QChartSeries;
15 class QSeries;
16 class PlotDomain;
16 class PlotDomain;
17 class BarPresenter;
17 class BarPresenter;
18 class QChartAxis;
18 class QChartAxis;
@@ -47,8 +47,8 public:
47 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
47 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
48 ~QChart();
48 ~QChart();
49
49
50 void addSeries(QChartSeries* series, QChartAxis* axisY = 0);
50 void addSeries(QSeries* series, QChartAxis* axisY = 0);
51 void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached
51 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
52 void removeAllSeries(); // deletes series and axis
52 void removeAllSeries(); // deletes series and axis
53
53
54 void setMargin(int margin);
54 void setMargin(int margin);
@@ -40,7 +40,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 */
40 */
41
41
42 /*!
42 /*!
43 \fn bool QChartAxis::isLabelsVisible() const
43 \fn bool QChartAxis::labelsVisible() const
44 \brief Returns if grid is visible
44 \brief Returns if grid is visible
45 \sa setLabelsVisible()
45 \sa setLabelsVisible()
46 */
46 */
@@ -70,7 +70,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
70 */
70 */
71
71
72 /*!
72 /*!
73 \fn bool QChartAxis::isShadesVisible() const
73 \fn bool QChartAxis::shadesVisible() const
74 \brief Returns if shades are visible.
74 \brief Returns if shades are visible.
75 \sa setShadesVisible()
75 \sa setShadesVisible()
76 */
76 */
@@ -28,7 +28,7 public:
28 QPen gridPen() const {return m_gridPen;}
28 QPen gridPen() const {return m_gridPen;}
29
29
30 //labels handling
30 //labels handling
31 bool isLabelsVisible() const { return m_labelsVisible;};
31 bool labelsVisible() const { return m_labelsVisible;};
32 void setLabelsVisible(bool visible);
32 void setLabelsVisible(bool visible);
33 void setLabelsPen(const QPen& pen);
33 void setLabelsPen(const QPen& pen);
34 QPen labelsPen() const { return m_labelsPen;}
34 QPen labelsPen() const { return m_labelsPen;}
@@ -40,7 +40,7 public:
40 int labelsAngle() const { return m_labelsAngle;};
40 int labelsAngle() const { return m_labelsAngle;};
41
41
42 //shades handling
42 //shades handling
43 bool isShadesVisible() const { return m_shadesVisible;};
43 bool shadesVisible() const { return m_shadesVisible;};
44 void setShadesVisible(bool visible);
44 void setShadesVisible(bool visible);
45 void setShadesPen(const QPen& pen);
45 void setShadesPen(const QPen& pen);
46 QPen shadesPen() const { return m_shadesPen;}
46 QPen shadesPen() const { return m_shadesPen;}
@@ -75,7 +75,7 void QChartView::resizeEvent(QResizeEvent *event)
75 the y axis).
75 the y axis).
76 \sa removeSeries(), removeAllSeries()
76 \sa removeSeries(), removeAllSeries()
77 */
77 */
78 void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
78 void QChartView::addSeries(QSeries* series,QChartAxis *axisY)
79 {
79 {
80 m_chart->addSeries(series,axisY);
80 m_chart->addSeries(series,axisY);
81 }
81 }
@@ -86,7 +86,7 void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
86 It does not delete the pointed QChartSeries data object
86 It does not delete the pointed QChartSeries data object
87 \sa addSeries(), removeAllSeries()
87 \sa addSeries(), removeAllSeries()
88 */
88 */
89 void QChartView::removeSeries(QChartSeries* series)
89 void QChartView::removeSeries(QSeries* series)
90 {
90 {
91 m_chart->removeSeries(series);
91 m_chart->removeSeries(series);
92 }
92 }
@@ -2,7 +2,7
2 #define QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchartseries.h"
5 #include "qseries.h"
6 #include "qchart.h"
6 #include "qchart.h"
7 #include <QGraphicsView>
7 #include <QGraphicsView>
8
8
@@ -24,8 +24,8 public:
24 //implement from QWidget
24 //implement from QWidget
25 void resizeEvent(QResizeEvent *event);
25 void resizeEvent(QResizeEvent *event);
26
26
27 void addSeries(QChartSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership
27 void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership
28 void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached
28 void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached
29 void removeAllSeries(); // deletes series and axis
29 void removeAllSeries(); // deletes series and axis
30 int margin() const;
30 int margin() const;
31
31
@@ -1,7 +1,7
1 #include "qchartseries.h"
1 #include "qseries.h"
2
2
3 /*!
3 /*!
4 \class QChartSeries
4 \class QSeries
5 \brief Base class for all QtCommercial Chart series.
5 \brief Base class for all QtCommercial Chart series.
6 \mainclass
6 \mainclass
7
7
@@ -10,7 +10,7
10 */
10 */
11
11
12 /*!
12 /*!
13 \enum QChartSeries::QChartSeriesType
13 \enum QSeries::QSeriesType
14
14
15 The type of the series object.
15 The type of the series object.
16
16
@@ -25,22 +25,22
25 */
25 */
26
26
27 /*!
27 /*!
28 \fn QChartSeries::QChartSeries(QObject *parent)
28 \fn QSeries::QSeries(QObject *parent)
29 \brief Constructs ChartSeries object with \a parent.
29 \brief Constructs ChartSeries object with \a parent.
30 */
30 */
31
31
32 /*!
32 /*!
33 \fn QChartSeries::~QChartSeries()
33 \fn QSeries::~QSeries()
34 \brief Virtual destructor for the chart series.
34 \brief Virtual destructor for the chart series.
35 */
35 */
36
36
37 /*!
37 /*!
38 \fn QChartSeriesType QChartSeries::type() const
38 \fn QSeriesType QSeries::type() const
39 \brief The type of the series.
39 \brief The type of the series.
40 */
40 */
41
41
42 /*!
42 /*!
43 \fn bool QChartSeries::setModel(QAbstractItemModel *model)
43 \fn bool QSeries::setModel(QAbstractItemModel *model)
44 \brief Use the \a model to provide data for the series. The model overrides possible user data
44 \brief Use the \a model to provide data for the series. The model overrides possible user data
45 set with QChartSeries type specific data setters. For example if you call both
45 set with QChartSeries type specific data setters. For example if you call both
46 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
46 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
@@ -48,5 +48,5
48 */
48 */
49
49
50 QTCOMMERCIALCHART_BEGIN_NAMESPACE
50 QTCOMMERCIALCHART_BEGIN_NAMESPACE
51 #include "moc_qchartseries.cpp"
51 #include "moc_qseries.cpp"
52 QTCOMMERCIALCHART_END_NAMESPACE
52 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,17 +1,18
1 #ifndef QCHARTSERIES_H
1 #ifndef QSERIES_H
2 #define QCHARTSERIES_H
2 #define QSERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QObject>
5 #include <QObject>
6 #include <QAbstractItemModel>
6 #include <QAbstractItemModel>
7 #include <QPen>
7
8
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10
10 class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject
11 class QTCOMMERCIALCHART_EXPORT QSeries : public QObject
11 {
12 {
12 Q_OBJECT
13 Q_OBJECT
13 public:
14 public:
14 enum QChartSeriesType {
15 enum QSeriesType {
15 SeriesTypeLine,
16 SeriesTypeLine,
16 SeriesTypeArea,
17 SeriesTypeArea,
17 SeriesTypeBar,
18 SeriesTypeBar,
@@ -22,14 +23,24 public:
22 SeriesTypeSpline
23 SeriesTypeSpline
23 };
24 };
24
25
26 // Helper class to contain legend and color for it
27 // TODO: This as private class?
28 class Legend {
29 public:
30 QString mName;
31 QPen mPen;
32 };
33
25 protected:
34 protected:
26 QChartSeries(QObject *parent = 0) : QObject(parent) {}
35 QSeries(QObject *parent = 0) : QObject(parent) {}
27
36
28 public:
37 public:
29 virtual ~QChartSeries() {}
38 virtual ~QSeries() {}
30 virtual QChartSeriesType type() const = 0;
39 virtual QSeriesType type() const = 0;
31 // TODO
40 // TODO
32 virtual bool setModel(QAbstractItemModel* /*model*/) { return false; }
41 virtual bool setModel(QAbstractItemModel* /*model*/) { return false; }
42
43 virtual QList<QSeries::Legend> legend() { QList<QSeries::Legend> l; return l; }
33 };
44 };
34
45
35 QTCOMMERCIALCHART_END_NAMESPACE
46 QTCOMMERCIALCHART_END_NAMESPACE
@@ -41,16 +41,6
41 */
41 */
42
42
43 /*!
43 /*!
44 \fn void QScatterSeries::hoverEnter()
45 \brief TODO
46 */
47
48 /*!
49 \fn void QScatterSeries::hoverLeave()
50 \brief TODO
51 */
52
53 /*!
54 \fn void QScatterSeries::changed()
44 \fn void QScatterSeries::changed()
55 \brief TODO
45 \brief TODO
56 */
46 */
@@ -59,20 +49,17 QTCOMMERCIALCHART_BEGIN_NAMESPACE
59
49
60 QScatterSeriesPrivate::QScatterSeriesPrivate() :
50 QScatterSeriesPrivate::QScatterSeriesPrivate() :
61 m_data(QList<QPointF>()),
51 m_data(QList<QPointF>()),
62 m_markerPen(QPen()),
52 m_markerPen(QPen(QColor::Invalid)),
63 m_markerBrush(QBrush()),
53 m_markerBrush(QBrush(QColor::Invalid)),
64 m_markerShape(QScatterSeries::MarkerShapeDefault)
54 m_markerShape(QScatterSeries::MarkerShapeDefault)
65 {
55 {
66 // Initialize pen color to invalid to use a theme color by default
67 m_markerPen.setColor(QColor::Invalid);
68 m_markerBrush.setColor(QColor::Invalid);
69 }
56 }
70
57
71 /*!
58 /*!
72 Constructs a series object which is a child of \a parent.
59 Constructs a series object which is a child of \a parent.
73 */
60 */
74 QScatterSeries::QScatterSeries(QObject *parent) :
61 QScatterSeries::QScatterSeries(QObject *parent) :
75 QChartSeries(parent),
62 QSeries(parent),
76 d(new QScatterSeriesPrivate())
63 d(new QScatterSeriesPrivate())
77 {
64 {
78 }
65 }
@@ -86,11 +73,18 QScatterSeries::~QScatterSeries()
86 }
73 }
87
74
88 /*!
75 /*!
76 Add single data point with \a x and \a y coordinates to the series.
77 */
78 void QScatterSeries::add(qreal x, qreal y)
79 {
80 d->m_data.append(QPointF(x, y));
81 emit changed();
82 }
83
84 /*!
89 Add single data point with \a value to the series.
85 Add single data point with \a value to the series.
90 For example:
91 \snippet ../example/scatter/main.cpp 2
92 */
86 */
93 void QScatterSeries::addData(QPointF value)
87 void QScatterSeries::add(QPointF value)
94 {
88 {
95 d->m_data.append(value);
89 d->m_data.append(value);
96 emit changed();
90 emit changed();
@@ -99,7 +93,7 void QScatterSeries::addData(QPointF value)
99 /*!
93 /*!
100 Add list of \a points to the series.
94 Add list of \a points to the series.
101 */
95 */
102 void QScatterSeries::addData(QList<QPointF> points)
96 void QScatterSeries::add(QList<QPointF> points)
103 {
97 {
104 d->m_data.append(points);
98 d->m_data.append(points);
105 emit changed();
99 emit changed();
@@ -107,7 +101,7 void QScatterSeries::addData(QList<QPointF> points)
107
101
108 /*!
102 /*!
109 Stream operator for adding a data point with \a value to the series.
103 Stream operator for adding a data point with \a value to the series.
110 \sa addData()
104 \sa add()
111
105
112 For example:
106 For example:
113 \snippet ../example/scatter/main.cpp 3
107 \snippet ../example/scatter/main.cpp 3
@@ -121,7 +115,7 QScatterSeries& QScatterSeries::operator << (const QPointF &value)
121
115
122 /*!
116 /*!
123 Stream operator for adding a list of points to the series.
117 Stream operator for adding a list of points to the series.
124 \sa addData()
118 \sa add()
125 */
119 */
126 QScatterSeries& QScatterSeries::operator << (QList<QPointF> value)
120 QScatterSeries& QScatterSeries::operator << (QList<QPointF> value)
127 {
121 {
@@ -158,10 +152,10 QList<QPointF> QScatterSeries::data()
158 beatiful markers defined by the chart's theme:
152 beatiful markers defined by the chart's theme:
159 \image scatter_example_pen.jpg
153 \image scatter_example_pen.jpg
160
154
161 \sa setMarkerBrush()
155 \sa setBrush()
162 \sa QChart::setChartTheme()
156 \sa QChart::setChartTheme()
163 */
157 */
164 void QScatterSeries::setMarkerPen(QPen pen)
158 void QScatterSeries::setPen(QPen pen)
165 {
159 {
166 d->m_markerPen = pen;
160 d->m_markerPen = pen;
167 }
161 }
@@ -169,7 +163,7 void QScatterSeries::setMarkerPen(QPen pen)
169 /*!
163 /*!
170 Returns the pen used for drawing markers.
164 Returns the pen used for drawing markers.
171 */
165 */
172 QPen QScatterSeries::markerPen()
166 QPen QScatterSeries::pen()
173 {
167 {
174 return d->m_markerPen;
168 return d->m_markerPen;
175 }
169 }
@@ -184,10 +178,10 QPen QScatterSeries::markerPen()
184 Would fill your scatter markers with an opaque red color:
178 Would fill your scatter markers with an opaque red color:
185 \image scatter_example_brush.jpg
179 \image scatter_example_brush.jpg
186
180
187 \sa setMarkerPen()
181 \sa setPen()
188 \sa QChart::setChartTheme()
182 \sa QChart::setChartTheme()
189 */
183 */
190 void QScatterSeries::setMarkerBrush(QBrush brush)
184 void QScatterSeries::setBrush(QBrush brush)
191 {
185 {
192 d->m_markerBrush = brush;
186 d->m_markerBrush = brush;
193 }
187 }
@@ -195,7 +189,7 void QScatterSeries::setMarkerBrush(QBrush brush)
195 /*!
189 /*!
196 Returns the brush used for drawing markers.
190 Returns the brush used for drawing markers.
197 */
191 */
198 QBrush QScatterSeries::markerBrush()
192 QBrush QScatterSeries::brush()
199 {
193 {
200 return d->m_markerBrush;
194 return d->m_markerBrush;
201 }
195 }
@@ -210,7 +204,7 QBrush QScatterSeries::markerBrush()
210 Would make your scatter marker items rectangle:
204 Would make your scatter marker items rectangle:
211 \image scatter_example_shape.jpg
205 \image scatter_example_shape.jpg
212 */
206 */
213 void QScatterSeries::setMarkerShape(MarkerShape shape)
207 void QScatterSeries::setShape(MarkerShape shape)
214 {
208 {
215 d->m_markerShape = shape;
209 d->m_markerShape = shape;
216 }
210 }
@@ -218,7 +212,7 void QScatterSeries::setMarkerShape(MarkerShape shape)
218 /*!
212 /*!
219 Returns the shape used for drawing markers.
213 Returns the shape used for drawing markers.
220 */
214 */
221 QScatterSeries::MarkerShape QScatterSeries::markerShape()
215 QScatterSeries::MarkerShape QScatterSeries::shape()
222 {
216 {
223 return (QScatterSeries::MarkerShape) d->m_markerShape;
217 return (QScatterSeries::MarkerShape) d->m_markerShape;
224 }
218 }
@@ -1,14 +1,14
1 #ifndef QSCATTERSERIES_H
1 #ifndef QSCATTERSERIES_H
2 #define QSCATTERSERIES_H
2 #define QSCATTERSERIES_H
3
3
4 #include "qchartseries.h"
4 #include "qseries.h"
5 #include <QRectF>
5 #include <QRectF>
6 #include <QColor>
6 #include <QColor>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 class QScatterSeriesPrivate;
9 class QScatterSeriesPrivate;
10
10
11 class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries
11 class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QSeries
12 {
12 {
13 Q_OBJECT
13 Q_OBJECT
14
14
@@ -30,31 +30,28 public:
30 ~QScatterSeries();
30 ~QScatterSeries();
31
31
32 public: // from QChartSeries
32 public: // from QChartSeries
33 QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; }
33 QSeriesType type() const { return QSeries::SeriesTypeScatter; }
34
34
35 public:
35 public:
36 void addData(QPointF value);
36 void add(qreal x, qreal y);
37 void addData(QList<QPointF> points);
37 void add(QPointF value);
38 void add(QList<QPointF> points);
38 void setData(QList<QPointF> points);
39 void setData(QList<QPointF> points);
39 QScatterSeries& operator << (const QPointF &value);
40 QScatterSeries& operator << (const QPointF &value);
40 QScatterSeries& operator << (QList<QPointF> points);
41 QScatterSeries& operator << (QList<QPointF> points);
41 QList<QPointF> data();
42 QList<QPointF> data();
42 //TODO: insertData?
43 //TODO: insert, replace, remove, clear...?
43
44
44 QPen markerPen();
45 QPen pen();
45 QBrush markerBrush();
46 void setPen(QPen pen);
46 MarkerShape markerShape();
47 QBrush brush();
48 void setBrush(QBrush brush);
49 MarkerShape shape();
50 void setShape(MarkerShape shape);
47 // TODO: marker size?
51 // TODO: marker size?
48
52
49 public Q_SLOTS:
50 void setMarkerPen(QPen pen);
51 void setMarkerBrush(QBrush brush);
52 void setMarkerShape(MarkerShape shape);
53
54 Q_SIGNALS:
53 Q_SIGNALS:
55 void clicked(/* TODO: parameters? */);
54 void clicked(/* TODO: parameters? */);
56 void hoverEnter(/* TODO: parameters? */);
57 void hoverLeave(/* TODO: parameters? */);
58 // TODO: move to PIMPL for simplicity or does the user ever need changed signals?
55 // TODO: move to PIMPL for simplicity or does the user ever need changed signals?
59 // TODO: more finegrained signaling for performance reasons
56 // TODO: more finegrained signaling for performance reasons
60 // (check QPieSeries implementation with change sets)
57 // (check QPieSeries implementation with change sets)
@@ -1,9 +1,11
1 #include "scatterpresenter_p.h"
1 #include "scatterpresenter_p.h"
2 #include "qscatterseries.h"
2 #include "qscatterseries.h"
3 #include "chartpresenter_p.h"
3 #include <QPen>
4 #include <QPen>
4 #include <QPainter>
5 #include <QPainter>
5 #include <QGraphicsScene>
6 #include <QGraphicsScene>
6 #include <QGraphicsSceneMouseEvent>
7 #include <QGraphicsSceneMouseEvent>
8 #include <QGraphicsDropShadowEffect>
7 #include <QDebug>
9 #include <QDebug>
8 #include <QTime>
10 #include <QTime>
9
11
@@ -13,8 +15,6 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare
13 ChartItem(parent),
15 ChartItem(parent),
14 m_series(series),
16 m_series(series),
15 m_boundingRect(),
17 m_boundingRect(),
16 //m_markerColor(QColor()),
17 // m_markerColor(QColor(255, 0, 0)),
18 m_visibleChartArea()
18 m_visibleChartArea()
19 {
19 {
20 if (parent)
20 if (parent)
@@ -23,6 +23,14 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare
23 if (series) {
23 if (series) {
24 connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged()));
24 connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged()));
25 }
25 }
26
27 setZValue(ChartPresenter::ScatterSeriesZValue);
28
29 // TODO: how to draw a drop shadow?
30 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
31 // dropShadow->setOffset(2.0);
32 // dropShadow->setBlurRadius(2.0);
33 // setGraphicsEffect(dropShadow);
26 }
34 }
27
35
28 void ScatterPresenter::handleDomainChanged(const Domain& domain)
36 void ScatterPresenter::handleDomainChanged(const Domain& domain)
@@ -48,25 +56,34 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *
48 painter->save();
56 painter->save();
49 painter->setClipRect(m_boundingRect);
57 painter->setClipRect(m_boundingRect);
50
58
59 // TODO: how to draw a drop shadow?
60 // Now using a custom implementation for drop shadow instead of QGraphicsDropShadowEffect.
61 // It seems QGraphicsDropShadowEffect is quite heavy, at least on windows without open gl.
62 QPen dropShadowPen(QColor(0, 0, 0, 70));
63 dropShadowPen.setWidth(3);
64 painter->setPen(dropShadowPen);
65 painter->setBrush(dropShadowPen.color());
66 // painter->setRenderHint(QPainter::Antialiasing);
67 painter->drawPath(m_path.translated(2, 2));
68
51 // Paint the shape
69 // Paint the shape
52 // The custom settings in series override those defined by the theme
70 // The custom settings in series override those defined by the theme
53 QPen pen = m_markerPen;
71 QPen pen = m_markerPen;
54 if (m_series->markerPen().color().isValid())
72 if (m_series->pen().color().isValid())
55 pen = m_series->markerPen();
73 pen = m_series->pen();
56 if (m_series->markerBrush().color().isValid())
74 painter->setPen(pen);
57 painter->setBrush(m_series->markerBrush());
75 if (m_series->brush().color().isValid())
76 painter->setBrush(m_series->brush());
58 else
77 else
59 painter->setBrush(m_markerBrush);
78 painter->setBrush(m_markerBrush);
60 painter->setPen(pen);
61 painter->drawPath(m_path);
62
79
63 // TODO: how to draw a drop shadow?
80 // If either pen or brush is opaque, we need to draw the polygons one-by-one
64 QPen dropShadowPen(QColor(0, 0, 0, 70));
81 if (painter->pen().color().alpha() < 255 || painter->brush().color().alpha() < 255) {
65 dropShadowPen.setWidth(3);
82 foreach (QPolygonF pol, m_path.toSubpathPolygons())
66 painter->setPen(dropShadowPen);
83 painter->drawPolygon(pol);
67 painter->setBrush(Qt::NoBrush);
84 } else {
68 painter->setRenderHint(QPainter::Antialiasing);
85 painter->drawPath(m_path);
69 painter->drawPath(m_path.translated(2, 2));
86 }
70
87
71 painter->restore();
88 painter->restore();
72 }
89 }
@@ -87,8 +104,9 void ScatterPresenter::changeGeometry()
87 qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX();
104 qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX();
88 qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY();
105 qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY();
89
106
90 int shape = m_series->markerShape();
107 int shape = m_series->shape();
91 m_path = QPainterPath();
108 m_path = QPainterPath();
109 m_path.setFillRule(Qt::WindingFill);
92
110
93 foreach (QPointF point, m_series->data()) {
111 foreach (QPointF point, m_series->data()) {
94 // Convert relative coordinates to absolute pixel coordinates that can be used for drawing
112 // Convert relative coordinates to absolute pixel coordinates that can be used for drawing
@@ -109,14 +127,8 void ScatterPresenter::changeGeometry()
109 m_path.addRect(x, y, 9, 9);
127 m_path.addRect(x, y, 9, 9);
110 break;
128 break;
111 case QScatterSeries::MarkerShapeTiltedRectangle: {
129 case QScatterSeries::MarkerShapeTiltedRectangle: {
112 // TODO:
130 // TODO: tilt the rectangle
113 // static const QPointF points[4] = {
131 m_path.addRect(x, y, 9, 9);
114 // QPointF(-1.0 + x, 0.0 + y),
115 // QPointF(0.0 + x, 1.0 + y),
116 // QPointF(1.0 + x, 0.0 + y),
117 // QPointF(0.0 + x, -1.0 + y)
118 // };
119 //m_path.addPolygon(QPolygon(4, &points));
120 break;
132 break;
121 }
133 }
122 default:
134 default:
@@ -2,7 +2,7
2 #define QSCATTERSERIESPRIVATE_H
2 #define QSCATTERSERIESPRIVATE_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchartseries.h"
5 #include "qseries.h"
6 #include <QPen>
6 #include <QPen>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -6,8 +6,7 QT += core \
6 gui
6 gui
7 CONFIG += debug_and_release
7 CONFIG += debug_and_release
8 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
8 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
9 SOURCES += \
9 SOURCES += axisitem.cpp \
10 axisitem.cpp \
11 axisanimationitem.cpp \
10 axisanimationitem.cpp \
12 chartdataset.cpp \
11 chartdataset.cpp \
13 chartpresenter.cpp \
12 chartpresenter.cpp \
@@ -15,28 +14,24 SOURCES += \
15 domain.cpp \
14 domain.cpp \
16 qchart.cpp \
15 qchart.cpp \
17 qchartaxis.cpp \
16 qchartaxis.cpp \
18 qchartseries.cpp \
17 qchartview.cpp \
19 qchartview.cpp
18 qseries.cpp
20 PRIVATE_HEADERS += \
19 PRIVATE_HEADERS += axisitem_p.h \
21 axisitem_p.h \
22 axisanimationitem_p.h \
20 axisanimationitem_p.h \
23 chartdataset_p.h \
21 chartdataset_p.h \
24 chartitem_p.h \
22 chartitem_p.h \
25 chartpresenter_p.h \
23 chartpresenter_p.h \
26 charttheme_p.h \
24 charttheme_p.h \
27 domain_p.h
25 domain_p.h
28 PUBLIC_HEADERS += \
26 PUBLIC_HEADERS += qchart.h \
29 qchart.h \
30 qchartaxis.h \
27 qchartaxis.h \
31 qchartglobal.h \
28 qchartglobal.h \
32 qchartseries.h \
29 qseries.h \
33 qchartview.h \
30 qchartview.h
34
35 include(linechart/linechart.pri)
31 include(linechart/linechart.pri)
36 include(barchart/barchart.pri)
32 include(barchart/barchart.pri)
37 include(piechart/piechart.pri)
33 include(piechart/piechart.pri)
38 include(scatterseries/scatter.pri)
34 include(scatterseries/scatter.pri)
39
40 THEMES += themes/chartthemeicy_p.h \
35 THEMES += themes/chartthemeicy_p.h \
41 themes/chartthemegrayscale_p.h \
36 themes/chartthemegrayscale_p.h \
42 themes/chartthemescientific_p.h \
37 themes/chartthemescientific_p.h \
@@ -74,7 +69,8 install_build_private_headers.commands = $$QMAKE_COPY \
74 $$CHART_BUILD_PRIVATE_HEADER_DIR
69 $$CHART_BUILD_PRIVATE_HEADER_DIR
75 install_build_private_headers.CONFIG += target_predeps \
70 install_build_private_headers.CONFIG += target_predeps \
76 no_link
71 no_link
77 QMAKE_EXTRA_COMPILERS += install_build_public_headers install_build_private_headers
72 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
73 install_build_private_headers
78 chartversion.target = qchartversion_p.h
74 chartversion.target = qchartversion_p.h
79 chartversion.commands = @echo \
75 chartversion.commands = @echo \
80 "build_time" \
76 "build_time" \
@@ -91,4 +87,3 unix:QMAKE_DISTCLEAN += -r \
91 win32:QMAKE_DISTCLEAN += /Q \
87 win32:QMAKE_DISTCLEAN += /Q \
92 $$CHART_BUILD_HEADER_DIR \
88 $$CHART_BUILD_HEADER_DIR \
93 $$CHART_BUILD_LIB_DIR
89 $$CHART_BUILD_LIB_DIR
94
@@ -1,7 +1,6
1 #include <QtTest/QtTest>
1 #include <QtTest/QtTest>
2 #include <qchartaxis.h>
2 #include <qchartaxis.h>
3 #include <qchartseries.h>
3 #include <qlineseries.h>
4 #include <qlinechartseries.h>
5 #include <private/chartdataset_p.h>
4 #include <private/chartdataset_p.h>
6 #include <private/domain_p.h>
5 #include <private/domain_p.h>
7
6
@@ -9,8 +8,8 QTCOMMERCIALCHART_USE_NAMESPACE
9
8
10 Q_DECLARE_METATYPE(Domain)
9 Q_DECLARE_METATYPE(Domain)
11 Q_DECLARE_METATYPE(QChartAxis*)
10 Q_DECLARE_METATYPE(QChartAxis*)
12 Q_DECLARE_METATYPE(QChartSeries*)
11 Q_DECLARE_METATYPE(QSeries*)
13 Q_DECLARE_METATYPE(QLineChartSeries*)
12 Q_DECLARE_METATYPE(QLineSeries*)
14
13
15 class tst_ChartDataSet: public QObject {
14 class tst_ChartDataSet: public QObject {
16 Q_OBJECT
15 Q_OBJECT
@@ -47,7 +46,7 void tst_ChartDataSet::initTestCase()
47 {
46 {
48 qRegisterMetaType<Domain>("Domain");
47 qRegisterMetaType<Domain>("Domain");
49 qRegisterMetaType<QChartAxis*>();
48 qRegisterMetaType<QChartAxis*>();
50 qRegisterMetaType<QChartSeries*>();
49 qRegisterMetaType<QSeries*>();
51 }
50 }
52
51
53 void tst_ChartDataSet::cleanupTestCase()
52 void tst_ChartDataSet::cleanupTestCase()
@@ -99,7 +98,7 void tst_ChartDataSet::addDomain()
99 ChartDataSet dataSet;
98 ChartDataSet dataSet;
100
99
101 Domain domain1(0, 1000, 0, 1000);
100 Domain domain1(0, 1000, 0, 1000);
102 QLineChartSeries series;
101 QLineSeries series;
103 series.add(0, 0);
102 series.add(0, 0);
104 series.add(1000, 1000);
103 series.add(1000, 1000);
105
104
@@ -111,10 +110,10 void tst_ChartDataSet::addDomain()
111 QSignalSpy spy1(&dataSet,
110 QSignalSpy spy1(&dataSet,
112 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
111 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
113 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
112 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
114 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
113 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*)));
115 QSignalSpy spy4(&dataSet,
114 QSignalSpy spy4(&dataSet,
116 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
115 SIGNAL(seriesDomainChanged(QSeries*, Domain const&)));
117 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
116 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
118
117
119 Domain domain2 = dataSet.domain(dataSet.axisY());
118 Domain domain2 = dataSet.domain(dataSet.axisY());
120 QVERIFY(domain1 == domain2);
119 QVERIFY(domain1 == domain2);
@@ -157,10 +156,10 void tst_ChartDataSet::addSeries()
157 QSignalSpy spy1(&dataSet,
156 QSignalSpy spy1(&dataSet,
158 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
157 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
159 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
158 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
160 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
159 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*)));
161 QSignalSpy spy4(&dataSet,
160 QSignalSpy spy4(&dataSet,
162 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
161 SIGNAL(seriesDomainChanged(QSeries*, Domain const&)));
163 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
162 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
164
163
165 QList<QChartAxis*> axisList;
164 QList<QChartAxis*> axisList;
166
165
@@ -173,7 +172,7 void tst_ChartDataSet::addSeries()
173
172
174 for (int i = 0; i < seriesCount; i++) {
173 for (int i = 0; i < seriesCount; i++) {
175 QChartAxis* axisY = 0;
174 QChartAxis* axisY = 0;
176 QLineChartSeries* series = new QLineChartSeries();
175 QLineSeries* series = new QLineSeries();
177 if (iterator != axisList.end()) {
176 if (iterator != axisList.end()) {
178 axisY = *iterator;
177 axisY = *iterator;
179 iterator++;
178 iterator++;
@@ -218,10 +217,10 void tst_ChartDataSet::axisY()
218
217
219 QVERIFY2(defaultAxisY, "Missing axisY.");
218 QVERIFY2(defaultAxisY, "Missing axisY.");
220
219
221 QLineChartSeries* series1 = new QLineChartSeries();
220 QLineSeries* series1 = new QLineSeries();
222 dataSet.addSeries(series1);
221 dataSet.addSeries(series1);
223
222
224 QLineChartSeries* series2 = new QLineChartSeries();
223 QLineSeries* series2 = new QLineSeries();
225 dataSet.addSeries(series2, axisY);
224 dataSet.addSeries(series2, axisY);
226
225
227 QVERIFY(dataSet.axisY(series1) == defaultAxisY);
226 QVERIFY(dataSet.axisY(series1) == defaultAxisY);
@@ -244,7 +243,7 void tst_ChartDataSet::clearDomains()
244 QFETCH(int, indexCount);
243 QFETCH(int, indexCount);
245
244
246 Domain domain1(0, 100, 0, 100);
245 Domain domain1(0, 100, 0, 100);
247 QLineChartSeries* series = new QLineChartSeries();
246 QLineSeries* series = new QLineSeries();
248 series->add(0, 0);
247 series->add(0, 0);
249 series->add(100, 100);
248 series->add(100, 100);
250
249
@@ -271,10 +270,10 void tst_ChartDataSet::clearDomains()
271 QSignalSpy spy1(&dataSet,
270 QSignalSpy spy1(&dataSet,
272 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
271 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
273 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
272 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
274 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
273 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*)));
275 QSignalSpy spy4(&dataSet,
274 QSignalSpy spy4(&dataSet,
276 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
275 SIGNAL(seriesDomainChanged(QSeries*, Domain const&)));
277 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
276 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
278
277
279 dataSet.clearDomains(indexCount);
278 dataSet.clearDomains(indexCount);
280
279
@@ -315,13 +314,13 void tst_ChartDataSet::domain()
315 QFETCH(Domain, domain);
314 QFETCH(Domain, domain);
316
315
317 ChartDataSet dataSet;
316 ChartDataSet dataSet;
318 QLineChartSeries* series1 = new QLineChartSeries();
317 QLineSeries* series1 = new QLineSeries();
319 series1->add(domain1.m_minX, domain1.m_minY);
318 series1->add(domain1.m_minX, domain1.m_minY);
320 series1->add(domain1.m_maxX, domain1.m_maxY);
319 series1->add(domain1.m_maxX, domain1.m_maxY);
321 QLineChartSeries* series2 = new QLineChartSeries();
320 QLineSeries* series2 = new QLineSeries();
322 series2->add(domain2.m_minX, domain2.m_minY);
321 series2->add(domain2.m_minX, domain2.m_minY);
323 series2->add(domain2.m_maxX, domain2.m_maxY);
322 series2->add(domain2.m_maxX, domain2.m_maxY);
324 QLineChartSeries* series3 = new QLineChartSeries();
323 QLineSeries* series3 = new QLineSeries();
325 series3->add(domain3.m_minX, domain3.m_minY);
324 series3->add(domain3.m_minX, domain3.m_minY);
326 series3->add(domain3.m_maxX, domain3.m_maxY);
325 series3->add(domain3.m_maxX, domain3.m_maxY);
327
326
@@ -329,10 +328,10 void tst_ChartDataSet::domain()
329 QSignalSpy spy1(&dataSet,
328 QSignalSpy spy1(&dataSet,
330 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
329 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
331 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
330 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
332 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
331 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*)));
333 QSignalSpy spy4(&dataSet,
332 QSignalSpy spy4(&dataSet,
334 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
333 SIGNAL(seriesDomainChanged(QSeries*, Domain const&)));
335 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
334 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
336
335
337 dataSet.addSeries(series1);
336 dataSet.addSeries(series1);
338 dataSet.addSeries(series2);
337 dataSet.addSeries(series2);
@@ -370,7 +369,7 void tst_ChartDataSet::nextpreviousDomain()
370 ChartDataSet dataSet;
369 ChartDataSet dataSet;
371
370
372 Domain domain1(0, 1000, 0, 1000);
371 Domain domain1(0, 1000, 0, 1000);
373 QLineChartSeries* series = new QLineChartSeries();
372 QLineSeries* series = new QLineSeries();
374 series->add(0, 0);
373 series->add(0, 0);
375 series->add(1000, 1000);
374 series->add(1000, 1000);
376
375
@@ -406,10 +405,10 void tst_ChartDataSet::nextpreviousDomain()
406 QSignalSpy spy1(&dataSet,
405 QSignalSpy spy1(&dataSet,
407 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
406 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
408 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
407 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
409 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
408 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*)));
410 QSignalSpy spy4(&dataSet,
409 QSignalSpy spy4(&dataSet,
411 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
410 SIGNAL(seriesDomainChanged(QSeries*, Domain const&)));
412 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
411 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
413
412
414 Domain domain;
413 Domain domain;
415
414
@@ -476,7 +475,7 void tst_ChartDataSet::removeSeries()
476 ChartDataSet dataSet;
475 ChartDataSet dataSet;
477
476
478 QList<QChartAxis*> axisList;
477 QList<QChartAxis*> axisList;
479 QList<QChartSeries*> seriesList;
478 QList<QSeries*> seriesList;
480
479
481 for (int i = 0; i < axisYCount; i++) {
480 for (int i = 0; i < axisYCount; i++) {
482 QChartAxis* axis = new QChartAxis();
481 QChartAxis* axis = new QChartAxis();
@@ -487,7 +486,7 void tst_ChartDataSet::removeSeries()
487
486
488 for (int i = 0; i < seriesCount; i++) {
487 for (int i = 0; i < seriesCount; i++) {
489 QChartAxis* axisY = 0;
488 QChartAxis* axisY = 0;
490 QLineChartSeries* series = new QLineChartSeries();
489 QLineSeries* series = new QLineSeries();
491 if (iterator != axisList.end()) {
490 if (iterator != axisList.end()) {
492 axisY = *iterator;
491 axisY = *iterator;
493 iterator++;
492 iterator++;
@@ -504,10 +503,10 void tst_ChartDataSet::removeSeries()
504 QSignalSpy spy1(&dataSet,
503 QSignalSpy spy1(&dataSet,
505 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
504 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
506 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
505 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
507 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
506 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*)));
508 QSignalSpy spy4(&dataSet,
507 QSignalSpy spy4(&dataSet,
509 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
508 SIGNAL(seriesDomainChanged(QSeries*, Domain const&)));
510 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
509 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
511
510
512 for (int i = 0; i < seriesCount; i++) {
511 for (int i = 0; i < seriesCount; i++) {
513 dataSet.removeSeries(seriesList.at(i));
512 dataSet.removeSeries(seriesList.at(i));
@@ -559,7 +558,7 void tst_ChartDataSet::removeAllSeries()
559
558
560 for (int i = 0; i < seriesCount; i++) {
559 for (int i = 0; i < seriesCount; i++) {
561 QChartAxis* axisY = 0;
560 QChartAxis* axisY = 0;
562 QLineChartSeries* series = new QLineChartSeries();
561 QLineSeries* series = new QLineSeries();
563 if (iterator != axisList.end()) {
562 if (iterator != axisList.end()) {
564 axisY = *iterator;
563 axisY = *iterator;
565 iterator++;
564 iterator++;
@@ -574,9 +573,9 void tst_ChartDataSet::removeAllSeries()
574 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
573 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
575 QSignalSpy spy1(&dataSet, SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
574 QSignalSpy spy1(&dataSet, SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
576 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
575 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
577 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
576 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*)));
578 QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
577 QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&)));
579 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
578 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
580
579
581 dataSet.removeAllSeries();
580 dataSet.removeAllSeries();
582 //default axis
581 //default axis
@@ -8,7 +8,7
8 #include <QLabel>
8 #include <QLabel>
9 #include <QDebug>
9 #include <QDebug>
10
10
11 DataSerieDialog::DataSerieDialog(QString defaultType, QWidget *parent) :
11 DataSerieDialog::DataSerieDialog(QWidget *parent) :
12 QDialog(parent)
12 QDialog(parent)
13 {
13 {
14 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
14 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
@@ -53,6 +53,7 QGroupBox *DataSerieDialog::seriesTypeSelector()
53
53
54 QGroupBox *groupBox = new QGroupBox("Series type");
54 QGroupBox *groupBox = new QGroupBox("Series type");
55 groupBox->setLayout(layout);
55 groupBox->setLayout(layout);
56 selectRadio(groupBox, 0);
56
57
57 return groupBox;
58 return groupBox;
58 }
59 }
@@ -72,6 +73,7 QGroupBox *DataSerieDialog::columnCountSelector()
72
73
73 QGroupBox *groupBox = new QGroupBox("Column count");
74 QGroupBox *groupBox = new QGroupBox("Column count");
74 groupBox->setLayout(layout);
75 groupBox->setLayout(layout);
76 selectRadio(groupBox, 0);
75
77
76 return groupBox;
78 return groupBox;
77 }
79 }
@@ -91,6 +93,7 QGroupBox *DataSerieDialog::rowCountSelector()
91
93
92 QGroupBox *groupBox = new QGroupBox("Row count");
94 QGroupBox *groupBox = new QGroupBox("Row count");
93 groupBox->setLayout(layout);
95 groupBox->setLayout(layout);
96 selectRadio(groupBox, 0);
94
97
95 return groupBox;
98 return groupBox;
96 }
99 }
@@ -99,9 +102,7 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
99 {
102 {
100 QVBoxLayout *layout = new QVBoxLayout();
103 QVBoxLayout *layout = new QVBoxLayout();
101
104
102 QRadioButton *radio1 = new QRadioButton("Linear");
105 layout->addWidget(new QRadioButton("Linear"));
103 radio1->setChecked(true);
104 layout->addWidget(radio1);
105 layout->addWidget(new QRadioButton("Constant"));
106 layout->addWidget(new QRadioButton("Constant"));
106 layout->addWidget(new QRadioButton("Random"));
107 layout->addWidget(new QRadioButton("Random"));
107 layout->addWidget(new QRadioButton("Sin"));
108 layout->addWidget(new QRadioButton("Sin"));
@@ -109,6 +110,7 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
109
110
110 QGroupBox *groupBox = new QGroupBox("Data Characteristics");
111 QGroupBox *groupBox = new QGroupBox("Data Characteristics");
111 groupBox->setLayout(layout);
112 groupBox->setLayout(layout);
113 selectRadio(groupBox, 0);
112
114
113 return groupBox;
115 return groupBox;
114 }
116 }
@@ -123,6 +125,24 void DataSerieDialog::accept()
123 QDialog::accept();
125 QDialog::accept();
124 }
126 }
125
127
128 void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection)
129 {
130 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
131 Q_ASSERT(layout);
132 Q_ASSERT(layout->count());
133
134 QLayoutItem *item = 0;
135 if (defaultSelection == -1) {
136 item = layout->itemAt(0);
137 } else if (layout->count() > defaultSelection) {
138 item = layout->itemAt(defaultSelection);
139 }
140 Q_ASSERT(item);
141 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
142 Q_ASSERT(radio);
143 radio->setChecked(true);
144 }
145
126 QString DataSerieDialog::radioSelection(QGroupBox *groupBox)
146 QString DataSerieDialog::radioSelection(QGroupBox *groupBox)
127 {
147 {
128 QString selection;
148 QString selection;
@@ -10,7 +10,7 class DataSerieDialog : public QDialog
10 {
10 {
11 Q_OBJECT
11 Q_OBJECT
12 public:
12 public:
13 explicit DataSerieDialog(QString defaultType, QWidget *parent = 0);
13 explicit DataSerieDialog(QWidget *parent = 0);
14
14
15 signals:
15 signals:
16 void accepted(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsDefined);
16 void accepted(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsDefined);
@@ -23,6 +23,7 private:
23 QGroupBox *columnCountSelector();
23 QGroupBox *columnCountSelector();
24 QGroupBox *rowCountSelector();
24 QGroupBox *rowCountSelector();
25 QGroupBox *dataCharacteristicsSelector();
25 QGroupBox *dataCharacteristicsSelector();
26 void selectRadio(QGroupBox *groupBox, int defaultSelection);
26 QString radioSelection(QGroupBox *groupBox);
27 QString radioSelection(QGroupBox *groupBox);
27 QGroupBox *m_seriesTypeSelector;
28 QGroupBox *m_seriesTypeSelector;
28 QGroupBox *m_columnCountSelector;
29 QGroupBox *m_columnCountSelector;
@@ -1,14 +1,12
1 #include "mainwidget.h"
1 #include "mainwidget.h"
2 #include "dataseriedialog.h"
2 #include "dataseriedialog.h"
3 #include "qchartseries.h"
4 #include "qpieseries.h"
3 #include "qpieseries.h"
5 #include "qscatterseries.h"
4 #include "qscatterseries.h"
6 #include <qlinechartseries.h>
5 #include <qlineseries.h>
7 #include <qbarset.h>
6 #include <qbarset.h>
8 #include <qbarcategory.h>
7 #include <qbarseries.h>
9 #include <qbarchartseries.h>
8 #include <qstackedbarseries.h>
10 #include <qstackedbarchartseries.h>
9 #include <qpercentbarseries.h>
11 #include <qpercentbarchartseries.h>
12 #include <QPushButton>
10 #include <QPushButton>
13 #include <QComboBox>
11 #include <QComboBox>
14 #include <QSpinBox>
12 #include <QSpinBox>
@@ -26,10 +24,12
26 QTCOMMERCIALCHART_USE_NAMESPACE
24 QTCOMMERCIALCHART_USE_NAMESPACE
27
25
28 MainWidget::MainWidget(QWidget *parent) :
26 MainWidget::MainWidget(QWidget *parent) :
29 QWidget(parent)
27 QWidget(parent),
28 m_addSerieDialog(0),
29 m_chartView(0)
30 {
30 {
31 m_chartWidget = new QChartView(this);
31 m_chartView = new QChartView(this);
32 m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand);
32 m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand);
33
33
34 // Grid layout for the controls for configuring the chart widget
34 // Grid layout for the controls for configuring the chart widget
35 QGridLayout *grid = new QGridLayout();
35 QGridLayout *grid = new QGridLayout();
@@ -39,10 +39,8 MainWidget::MainWidget(QWidget *parent) :
39 initBackroundCombo(grid);
39 initBackroundCombo(grid);
40 initScaleControls(grid);
40 initScaleControls(grid);
41 initThemeCombo(grid);
41 initThemeCombo(grid);
42 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
42 initCheckboxes(grid);
43 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool)));
43
44 zoomCheckBox->setChecked(true);
45 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
46 // add row with empty label to make all the other rows static
44 // add row with empty label to make all the other rows static
47 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
45 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
48 grid->setRowStretch(grid->rowCount() - 1, 1);
46 grid->setRowStretch(grid->rowCount() - 1, 1);
@@ -61,7 +59,7 MainWidget::MainWidget(QWidget *parent) :
61 // mainLayout->addLayout(m_scatterLayout, 1, 0);
59 // mainLayout->addLayout(m_scatterLayout, 1, 0);
62
60
63 // Add layouts and the chart widget to the main layout
61 // Add layouts and the chart widget to the main layout
64 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
62 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
65 setLayout(mainLayout);
63 setLayout(mainLayout);
66 }
64 }
67
65
@@ -135,6 +133,26 void MainWidget::initThemeCombo(QGridLayout *grid)
135 grid->addWidget(chartTheme, 8, 1);
133 grid->addWidget(chartTheme, 8, 1);
136 }
134 }
137
135
136 // Different check boxes for customizing chart
137 void MainWidget::initCheckboxes(QGridLayout *grid)
138 {
139 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
140 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
141 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
142 zoomCheckBox->setChecked(true);
143 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
144
145 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
146 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
147 aliasCheckBox->setChecked(false);
148 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
149 }
150
151 void MainWidget::antiAliasToggled(bool enabled)
152 {
153 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
154 }
155
138 void MainWidget::initPieControls()
156 void MainWidget::initPieControls()
139 {
157 {
140 // Pie series specific settings
158 // Pie series specific settings
@@ -164,10 +182,12 void MainWidget::initPieControls()
164
182
165 void MainWidget::addSeries()
183 void MainWidget::addSeries()
166 {
184 {
167 DataSerieDialog dialog(m_defaultSeriesName, this);
185 if (!m_addSerieDialog) {
168 connect(&dialog, SIGNAL(accepted(QString, int, int, QString, bool)),
186 m_addSerieDialog = new DataSerieDialog(this);
187 connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)),
169 this, SLOT(addSeries(QString, int, int, QString, bool)));
188 this, SLOT(addSeries(QString, int, int, QString, bool)));
170 dialog.exec();
189 }
190 m_addSerieDialog->exec();
171 }
191 }
172
192
173 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
193 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
@@ -219,11 +239,11 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
219 if (seriesName.contains("line", Qt::CaseInsensitive)) {
239 if (seriesName.contains("line", Qt::CaseInsensitive)) {
220 for (int j(0); j < data.count(); j ++) {
240 for (int j(0); j < data.count(); j ++) {
221 QList<qreal> column = data.at(j);
241 QList<qreal> column = data.at(j);
222 QLineChartSeries *series = new QLineChartSeries();
242 QLineSeries *series = new QLineSeries();
223 for (int i(0); i < column.count(); i++) {
243 for (int i(0); i < column.count(); i++) {
224 series->add(i, column.at(i));
244 series->add(i, column.at(i));
225 }
245 }
226 m_chartWidget->addSeries(series);
246 m_chartView->addSeries(series);
227 setCurrentSeries(series);
247 setCurrentSeries(series);
228 }
248 }
229 } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) {
249 } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) {
@@ -233,7 +253,7 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
233 for (int i(0); i < column.count(); i++) {
253 for (int i(0); i < column.count(); i++) {
234 (*series) << QPointF(i, column.at(i));
254 (*series) << QPointF(i, column.at(i));
235 }
255 }
236 m_chartWidget->addSeries(series);
256 m_chartView->addSeries(series);
237 setCurrentSeries(series);
257 setCurrentSeries(series);
238 }
258 }
239 } else if (seriesName.contains("pie", Qt::CaseInsensitive)) {
259 } else if (seriesName.contains("pie", Qt::CaseInsensitive)) {
@@ -244,24 +264,23 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
244 for (int i(0); i < column.count(); i++) {
264 for (int i(0); i < column.count(); i++) {
245 series->add(column.at(i), labels.at(i));
265 series->add(column.at(i), labels.at(i));
246 }
266 }
247 m_chartWidget->addSeries(series);
267 m_chartView->addSeries(series);
248 setCurrentSeries(series);
268 setCurrentSeries(series);
249 }
269 }
250 } else if (seriesName == "Bar"
270 } else if (seriesName == "Bar"
251 || seriesName == "Stacked bar"
271 || seriesName == "Stacked bar"
252 || seriesName == "Percent bar") {
272 || seriesName == "Percent bar") {
253 // TODO: replace QBarCategory with QStringList?
273 QStringList category;
254 QBarCategory *category = new QBarCategory;
255 QStringList labels = generateLabels(rowCount);
274 QStringList labels = generateLabels(rowCount);
256 foreach(QString label, labels)
275 foreach(QString label, labels)
257 *category << label;
276 category << label;
258 QBarChartSeries* series = 0;
277 QBarSeries* series = 0;
259 if (seriesName == "Bar")
278 if (seriesName == "Bar")
260 series = new QBarChartSeries(category, this);
279 series = new QBarSeries(category, this);
261 else if (seriesName == "Stacked bar")
280 else if (seriesName == "Stacked bar")
262 series = new QStackedBarChartSeries(category, this);
281 series = new QStackedBarSeries(category, this);
263 else
282 else
264 series = new QPercentBarChartSeries(category, this);
283 series = new QPercentBarSeries(category, this);
265
284
266 for (int j(0); j < data.count(); j++) {
285 for (int j(0); j < data.count(); j++) {
267 QList<qreal> column = data.at(j);
286 QList<qreal> column = data.at(j);
@@ -271,34 +290,34 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
271 }
290 }
272 series->addBarSet(set);
291 series->addBarSet(set);
273 }
292 }
274 series->enableFloatingValues();
293 series->setFloatingValuesEnabled(true);
275 series->enableToolTip();
294 series->setToolTipEnabled(true);
276 series->enableSeparators(false);
295 series->setSeparatorsEnabled(false);
277 m_chartWidget->addSeries(series);
296 m_chartView->addSeries(series);
278 setCurrentSeries(series);
297 setCurrentSeries(series);
279 }
298 }
280
299
281 // TODO: spline and area
300 // TODO: spline and area
282 }
301 }
283
302
284 void MainWidget::setCurrentSeries(QChartSeries *series)
303 void MainWidget::setCurrentSeries(QSeries *series)
285 {
304 {
286 if (series) {
305 if (series) {
287 m_currentSeries = series;
306 m_currentSeries = series;
288 switch (m_currentSeries->type()) {
307 switch (m_currentSeries->type()) {
289 case QChartSeries::SeriesTypeLine:
308 case QSeries::SeriesTypeLine:
290 break;
309 break;
291 case QChartSeries::SeriesTypeScatter:
310 case QSeries::SeriesTypeScatter:
292 break;
311 break;
293 case QChartSeries::SeriesTypePie:
312 case QSeries::SeriesTypePie:
294 break;
313 break;
295 case QChartSeries::SeriesTypeBar:
314 case QSeries::SeriesTypeBar:
296 qDebug() << "setCurrentSeries (bar)";
315 qDebug() << "setCurrentSeries (bar)";
297 break;
316 break;
298 case QChartSeries::SeriesTypeStackedBar:
317 case QSeries::SeriesTypeStackedBar:
299 qDebug() << "setCurrentSeries (Stackedbar)";
318 qDebug() << "setCurrentSeries (Stackedbar)";
300 break;
319 break;
301 case QChartSeries::SeriesTypePercentBar:
320 case QSeries::SeriesTypePercentBar:
302 qDebug() << "setCurrentSeries (Percentbar)";
321 qDebug() << "setCurrentSeries (Percentbar)";
303 break;
322 break;
304 default:
323 default:
@@ -350,7 +369,7 void MainWidget::yMaxChanged(int value)
350 void MainWidget::changeChartTheme(int themeIndex)
369 void MainWidget::changeChartTheme(int themeIndex)
351 {
370 {
352 qDebug() << "changeChartTheme: " << themeIndex;
371 qDebug() << "changeChartTheme: " << themeIndex;
353 m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex);
372 m_chartView->setChartTheme((QChart::ChartTheme) themeIndex);
354 //TODO: remove this hack. This is just to make it so that theme change is seen immediately.
373 //TODO: remove this hack. This is just to make it so that theme change is seen immediately.
355 QSize s = size();
374 QSize s = size();
356 s.setWidth(s.width()+1);
375 s.setWidth(s.width()+1);
@@ -12,6 +12,7 class QGridLayout;
12 QTCOMMERCIALCHART_USE_NAMESPACE
12 QTCOMMERCIALCHART_USE_NAMESPACE
13
13
14 #define RealList QList<qreal>
14 #define RealList QList<qreal>
15 class DataSerieDialog;
15
16
16 class MainWidget : public QWidget
17 class MainWidget : public QWidget
17 {
18 {
@@ -25,6 +26,7 private:
25 void initBackroundCombo(QGridLayout *grid);
26 void initBackroundCombo(QGridLayout *grid);
26 void initScaleControls(QGridLayout *grid);
27 void initScaleControls(QGridLayout *grid);
27 void initThemeCombo(QGridLayout *grid);
28 void initThemeCombo(QGridLayout *grid);
29 void initCheckboxes(QGridLayout *grid);
28 void initPieControls();
30 void initPieControls();
29
31
30 private slots:
32 private slots:
@@ -36,7 +38,8 private slots:
36 void xMaxChanged(int value);
38 void xMaxChanged(int value);
37 void yMinChanged(int value);
39 void yMinChanged(int value);
38 void yMaxChanged(int value);
40 void yMaxChanged(int value);
39 void setCurrentSeries(QChartSeries *series);
41 void antiAliasToggled(bool enabled);
42 void setCurrentSeries(QSeries *series);
40 void changeChartTheme(int themeIndex);
43 void changeChartTheme(int themeIndex);
41 void setPieSizeFactor(double margin);
44 void setPieSizeFactor(double margin);
42 void setPiePosition(int position);
45 void setPiePosition(int position);
@@ -44,14 +47,15 private slots:
44 QStringList generateLabels(int count);
47 QStringList generateLabels(int count);
45
48
46 private:
49 private:
47 QChartView *m_chartWidget;
50 DataSerieDialog *m_addSerieDialog;
51 QChartView *m_chartView;
48 QCheckBox *m_autoScaleCheck;
52 QCheckBox *m_autoScaleCheck;
49 QSpinBox *m_xMinSpin;
53 QSpinBox *m_xMinSpin;
50 QSpinBox *m_xMaxSpin;
54 QSpinBox *m_xMaxSpin;
51 QSpinBox *m_yMinSpin;
55 QSpinBox *m_yMinSpin;
52 QSpinBox *m_yMaxSpin;
56 QSpinBox *m_yMaxSpin;
53 QString m_defaultSeriesName;
57 QString m_defaultSeriesName;
54 QChartSeries *m_currentSeries;
58 QSeries *m_currentSeries;
55 QGridLayout *m_scatterLayout;
59 QGridLayout *m_scatterLayout;
56 QGridLayout *m_pieLayout;
60 QGridLayout *m_pieLayout;
57 };
61 };
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now