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