@@ -0,0 +1,122 | |||||
|
1 | ||||
|
2 | #include "piepresentation.h" | |||
|
3 | #include "pieslice.h" | |||
|
4 | #include <QDebug> | |||
|
5 | ||||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
7 | ||||
|
8 | PiePresentation::PiePresentation(QGraphicsItem *parent, QPieSeries *series) : | |||
|
9 | ChartItem(parent), | |||
|
10 | m_pieSeries(series) | |||
|
11 | { | |||
|
12 | Q_ASSERT(parent); | |||
|
13 | Q_ASSERT(series); | |||
|
14 | m_rect = parentItem()->boundingRect(); | |||
|
15 | setAcceptHoverEvents(true); | |||
|
16 | } | |||
|
17 | ||||
|
18 | PiePresentation::~PiePresentation() | |||
|
19 | { | |||
|
20 | while (m_slices.count()) | |||
|
21 | delete m_slices.takeLast(); | |||
|
22 | } | |||
|
23 | ||||
|
24 | void PiePresentation::seriesChanged() | |||
|
25 | { | |||
|
26 | const qreal fullPie = 360; | |||
|
27 | qreal total = 0; | |||
|
28 | ||||
|
29 | // calculate total | |||
|
30 | foreach (QPieSlice sliceData, m_pieSeries->slices()) | |||
|
31 | total += sliceData.m_value; | |||
|
32 | ||||
|
33 | // TODO: no need to create new slices in case size changed; we should re-use the existing ones | |||
|
34 | while (m_slices.count()) | |||
|
35 | delete m_slices.takeLast(); | |||
|
36 | ||||
|
37 | // create slices | |||
|
38 | qreal angle = 0; | |||
|
39 | for (int i=0; i<m_pieSeries->count(); i++) { | |||
|
40 | QPieSlice sliceData = m_pieSeries->slice(i); | |||
|
41 | qreal span = sliceData.m_value / total * fullPie; | |||
|
42 | PieSlice *slice = new PieSlice(this, i, angle, span); | |||
|
43 | m_slices.append(slice); | |||
|
44 | angle += span; | |||
|
45 | } | |||
|
46 | ||||
|
47 | resize(); | |||
|
48 | } | |||
|
49 | ||||
|
50 | void PiePresentation::setSize(const QSizeF &size) | |||
|
51 | { | |||
|
52 | // TODO: allow user setting the size? | |||
|
53 | // TODO: allow user defining the margins? | |||
|
54 | m_rect.setSize(size); | |||
|
55 | resize(); | |||
|
56 | } | |||
|
57 | ||||
|
58 | void PiePresentation::setPlotDomain(const PlotDomain& plotDomain) | |||
|
59 | { | |||
|
60 | // TODO | |||
|
61 | } | |||
|
62 | ||||
|
63 | void PiePresentation::resize() | |||
|
64 | { | |||
|
65 | m_pieRect = m_rect; | |||
|
66 | ||||
|
67 | if (m_pieRect.width() < m_pieRect.height()) { | |||
|
68 | m_pieRect.setWidth(m_pieRect.width() * m_pieSeries->m_sizeFactor); | |||
|
69 | m_pieRect.setHeight(m_pieRect.width()); | |||
|
70 | m_pieRect.moveCenter(m_rect.center()); | |||
|
71 | } else { | |||
|
72 | m_pieRect.setHeight(m_pieRect.height() * m_pieSeries->m_sizeFactor); | |||
|
73 | m_pieRect.setWidth(m_pieRect.height()); | |||
|
74 | m_pieRect.moveCenter(m_rect.center()); | |||
|
75 | } | |||
|
76 | ||||
|
77 | switch (m_pieSeries->m_position) { | |||
|
78 | case QPieSeries::PiePositionTopLeft: { | |||
|
79 | m_pieRect.setHeight(m_pieRect.height() / 2); | |||
|
80 | m_pieRect.setWidth(m_pieRect.height()); | |||
|
81 | m_pieRect.moveCenter(QPointF(m_rect.center().x() / 2, m_rect.center().y() / 2)); | |||
|
82 | break; | |||
|
83 | } | |||
|
84 | case QPieSeries::PiePositionTopRight: { | |||
|
85 | m_pieRect.setHeight(m_pieRect.height() / 2); | |||
|
86 | m_pieRect.setWidth(m_pieRect.height()); | |||
|
87 | m_pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, m_rect.center().y() / 2)); | |||
|
88 | break; | |||
|
89 | } | |||
|
90 | case QPieSeries::PiePositionBottomLeft: { | |||
|
91 | m_pieRect.setHeight(m_pieRect.height() / 2); | |||
|
92 | m_pieRect.setWidth(m_pieRect.height()); | |||
|
93 | m_pieRect.moveCenter(QPointF(m_rect.center().x() / 2, (m_rect.center().y() / 2) * 3)); | |||
|
94 | break; | |||
|
95 | } | |||
|
96 | case QPieSeries::PiePositionBottomRight: { | |||
|
97 | m_pieRect.setHeight(m_pieRect.height() / 2); | |||
|
98 | m_pieRect.setWidth(m_pieRect.height()); | |||
|
99 | m_pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, (m_rect.center().y() / 2) * 3)); | |||
|
100 | break; | |||
|
101 | } | |||
|
102 | default: | |||
|
103 | break; | |||
|
104 | } | |||
|
105 | ||||
|
106 | qDebug() << "presentation rect:" << m_rect; | |||
|
107 | qDebug() << "pie rect:" << m_pieRect; | |||
|
108 | } | |||
|
109 | ||||
|
110 | void PiePresentation::handleDomainChanged(const Domain& domain) | |||
|
111 | { | |||
|
112 | // TODO | |||
|
113 | } | |||
|
114 | ||||
|
115 | void PiePresentation::handleGeometryChanged(const QRectF& rect) | |||
|
116 | { | |||
|
117 | setSize(rect.size()); | |||
|
118 | } | |||
|
119 | ||||
|
120 | #include "moc_piepresentation.cpp" | |||
|
121 | ||||
|
122 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,45 | |||||
|
1 | #ifndef PIEPRESENTATION_H | |||
|
2 | #define PIEPRESENTATION_H | |||
|
3 | ||||
|
4 | #include "chartitem_p.h" | |||
|
5 | #include "qpieseries.h" | |||
|
6 | ||||
|
7 | class QGraphicsItem; | |||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
9 | class PieSlice; | |||
|
10 | ||||
|
11 | class PiePresentation : public QObject, public ChartItem | |||
|
12 | { | |||
|
13 | Q_OBJECT | |||
|
14 | ||||
|
15 | public: | |||
|
16 | // TODO: use a generic data class instead of x and y | |||
|
17 | PiePresentation(QGraphicsItem *parent, QPieSeries *series); | |||
|
18 | ~PiePresentation(); | |||
|
19 | ||||
|
20 | public: // from ChartItem | |||
|
21 | void setSize(const QSizeF &size); | |||
|
22 | void setPlotDomain(const PlotDomain& data); | |||
|
23 | QRectF boundingRect() const { return m_rect; } | |||
|
24 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} | |||
|
25 | ||||
|
26 | public: | |||
|
27 | void seriesChanged(); | |||
|
28 | void resize(); | |||
|
29 | QRectF pieRect() const { return m_pieRect; } | |||
|
30 | ||||
|
31 | public Q_SLOTS: | |||
|
32 | void handleDomainChanged(const Domain& domain); | |||
|
33 | void handleGeometryChanged(const QRectF& rect); | |||
|
34 | ||||
|
35 | private: | |||
|
36 | friend class PieSlice; | |||
|
37 | QList<PieSlice*> m_slices; | |||
|
38 | QPieSeries *m_pieSeries; | |||
|
39 | QRectF m_rect; | |||
|
40 | QRectF m_pieRect; | |||
|
41 | }; | |||
|
42 | ||||
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
44 | ||||
|
45 | #endif // PIEPRESENTATION_H |
@@ -0,0 +1,93 | |||||
|
1 | #include "qpieseries.h" | |||
|
2 | #include "piepresentation.h" | |||
|
3 | #include "pieslice.h" | |||
|
4 | #include <QDebug> | |||
|
5 | ||||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
7 | ||||
|
8 | QPieSeries::QPieSeries(QObject *parent) : | |||
|
9 | QChartSeries(parent), | |||
|
10 | m_piePresentation(0), | |||
|
11 | m_sizeFactor(1.0), | |||
|
12 | m_position(PiePositionMaximized) | |||
|
13 | { | |||
|
14 | } | |||
|
15 | ||||
|
16 | QPieSeries::~QPieSeries() | |||
|
17 | { | |||
|
18 | ||||
|
19 | } | |||
|
20 | ||||
|
21 | void QPieSeries::set(QList<QPieSlice> slices) | |||
|
22 | { | |||
|
23 | m_slices = slices; | |||
|
24 | if (m_piePresentation) { | |||
|
25 | m_piePresentation->seriesChanged(); | |||
|
26 | m_piePresentation->update(); | |||
|
27 | } | |||
|
28 | } | |||
|
29 | ||||
|
30 | void QPieSeries::add(QList<QPieSlice> slices) | |||
|
31 | { | |||
|
32 | m_slices += slices; | |||
|
33 | if (m_piePresentation) { | |||
|
34 | m_piePresentation->seriesChanged(); | |||
|
35 | // TODO: m_piePresentation->seriesAppended()?? | |||
|
36 | m_piePresentation->update(); | |||
|
37 | } | |||
|
38 | } | |||
|
39 | ||||
|
40 | void QPieSeries::add(QPieSlice slice) | |||
|
41 | { | |||
|
42 | add(QList<QPieSlice>() << slice); | |||
|
43 | } | |||
|
44 | ||||
|
45 | QPieSlice QPieSeries::slice(int index) const | |||
|
46 | { | |||
|
47 | if ((index >= 0) && (index < m_slices.count())) | |||
|
48 | return m_slices.at(index); | |||
|
49 | return QPieSlice(); | |||
|
50 | } | |||
|
51 | ||||
|
52 | bool QPieSeries::update(int index, QPieSlice slice) | |||
|
53 | { | |||
|
54 | if ((index >= 0) && (index < m_slices.count())) { | |||
|
55 | m_slices[index] = slice; | |||
|
56 | if (m_piePresentation) { | |||
|
57 | m_piePresentation->seriesChanged(); | |||
|
58 | // TODO: for a nice animation we need something like | |||
|
59 | // m_piePresentation->sliceChanged(index, oldslice, newslice) | |||
|
60 | m_piePresentation->update(); | |||
|
61 | } | |||
|
62 | return true; | |||
|
63 | } | |||
|
64 | return false; | |||
|
65 | } | |||
|
66 | ||||
|
67 | void QPieSeries::setSizeFactor(qreal factor) | |||
|
68 | { | |||
|
69 | if (factor > 0.0) | |||
|
70 | m_sizeFactor = factor; | |||
|
71 | ||||
|
72 | if (m_piePresentation) { | |||
|
73 | m_piePresentation->resize(); | |||
|
74 | m_piePresentation->update(); | |||
|
75 | // TODO: do we have to update the parent item also? | |||
|
76 | // - potential issue: what if this function is called from the parent context? | |||
|
77 | } | |||
|
78 | } | |||
|
79 | ||||
|
80 | void QPieSeries::setPosition(PiePosition position) | |||
|
81 | { | |||
|
82 | m_position = position; | |||
|
83 | if (m_piePresentation) { | |||
|
84 | m_piePresentation->resize(); | |||
|
85 | m_piePresentation->update(); | |||
|
86 | // TODO: do we have to update the parent item also? | |||
|
87 | // - potential issue: what if this function is called from the parent context? | |||
|
88 | } | |||
|
89 | } | |||
|
90 | ||||
|
91 | #include "moc_qpieseries.cpp" | |||
|
92 | ||||
|
93 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,34 +1,33 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <cmath> |
|
3 | #include <cmath> | |
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartview.h> |
|
5 | #include <qchartview.h> | |
6 | #include <qpieseries.h> |
|
6 | #include <qpieseries.h> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
9 |
|
9 | |||
10 | int main(int argc, char *argv[]) |
|
10 | int main(int argc, char *argv[]) | |
11 | { |
|
11 | { | |
12 | QApplication a(argc, argv); |
|
12 | QApplication a(argc, argv); | |
13 |
|
13 | |||
14 | // Create widget and scatter series |
|
14 | // Create widget and scatter series | |
15 | QChartView *chartWidget = new QChartView(); |
|
15 | QChartView *chartWidget = new QChartView(); | |
16 | QPieSeries *series = qobject_cast<QPieSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypePie)); |
|
16 | QPieSeries *series = qobject_cast<QPieSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypePie)); | |
17 | Q_ASSERT(series); |
|
17 | Q_ASSERT(series); | |
18 |
|
18 | |||
19 | // Add test data to the series |
|
19 | // Add test data to the series | |
20 | QList<qreal> x; |
|
20 | series->add(QPieSlice(1, "test1", Qt::red)); | |
21 | for (qreal i(0.0); i < 20; i += 0.5) { |
|
21 | series->add(QPieSlice(2, "test2", Qt::green)); | |
22 | // Linear data with random component |
|
22 | series->add(QPieSlice(3, "test3", Qt::blue)); | |
23 | x.append(i + ((qreal)(rand() % 100)) / 100 ); |
|
23 | series->add(QPieSlice(4, "test4", Qt::darkRed)); | |
24 | } |
|
24 | series->add(QPieSlice(5, "test5", Qt::darkGreen)); | |
25 | series->setData(x); |
|
|||
26 |
|
25 | |||
27 | // Use the chart widget as the central widget |
|
26 | // Use the chart widget as the central widget | |
28 | QMainWindow w; |
|
27 | QMainWindow w; | |
29 | w.resize(640, 480); |
|
28 | w.resize(640, 480); | |
30 | w.setCentralWidget(chartWidget); |
|
29 | w.setCentralWidget(chartWidget); | |
31 | w.show(); |
|
30 | w.show(); | |
32 |
|
31 | |||
33 | return a.exec(); |
|
32 | return a.exec(); | |
34 | } |
|
33 | } |
@@ -1,140 +1,148 | |||||
1 | #include "chartdataset_p.h" |
|
1 | #include "chartdataset_p.h" | |
2 | //series |
|
2 | //series | |
3 | #include "qxychartseries.h" |
|
3 | #include "qxychartseries.h" | |
4 | #include "barchartseries.h" |
|
4 | #include "barchartseries.h" | |
5 | #include "stackedbarchartseries.h" |
|
5 | #include "stackedbarchartseries.h" | |
6 | #include "percentbarchartseries.h" |
|
6 | #include "percentbarchartseries.h" | |
|
7 | #include "piechart/qpieseries.h" | |||
|
8 | #include "piechart/piepresentation.h" | |||
7 |
|
9 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
11 | |||
10 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent) |
|
12 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent) | |
11 | { |
|
13 | { | |
12 | Domain domain; |
|
14 | Domain domain; | |
13 | m_domains<<domain; |
|
15 | m_domains<<domain; | |
14 | } |
|
16 | } | |
15 |
|
17 | |||
16 | ChartDataSet::~ChartDataSet() |
|
18 | ChartDataSet::~ChartDataSet() | |
17 | { |
|
19 | { | |
18 | // TODO Auto-generated destructor stub |
|
20 | // TODO Auto-generated destructor stub | |
19 | } |
|
21 | } | |
20 |
|
22 | |||
21 | const Domain& ChartDataSet::domain() const |
|
23 | const Domain& ChartDataSet::domain() const | |
22 | { |
|
24 | { | |
23 | return m_domains[m_domainIndex]; |
|
25 | return m_domains[m_domainIndex]; | |
24 | } |
|
26 | } | |
25 |
|
27 | |||
26 | void ChartDataSet::addSeries(QChartSeries* series) |
|
28 | void ChartDataSet::addSeries(QChartSeries* series) | |
27 | { |
|
29 | { | |
28 | // TODO: we should check the series not already added |
|
30 | // TODO: we should check the series not already added | |
29 | m_chartSeries << series; |
|
31 | m_chartSeries << series; | |
30 | m_domainIndex = 0; |
|
32 | m_domainIndex = 0; | |
31 | m_domains.resize(1); |
|
33 | m_domains.resize(1); | |
32 |
|
34 | |||
33 | Domain& domain = m_domains[m_domainIndex]; |
|
35 | Domain& domain = m_domains[m_domainIndex]; | |
34 |
|
36 | |||
35 | switch(series->type()) |
|
37 | switch(series->type()) | |
36 | { |
|
38 | { | |
37 | case QChartSeries::SeriesTypeLine: { |
|
39 | case QChartSeries::SeriesTypeLine: { | |
38 |
|
40 | |||
39 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
41 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
40 |
|
42 | |||
41 | for (int i = 0; i < xyseries->count(); i++) |
|
43 | for (int i = 0; i < xyseries->count(); i++) | |
42 | { |
|
44 | { | |
43 | qreal x = xyseries->x(i); |
|
45 | qreal x = xyseries->x(i); | |
44 | qreal y = xyseries->y(i); |
|
46 | qreal y = xyseries->y(i); | |
45 | domain.m_minX = qMin(domain.m_minX,x); |
|
47 | domain.m_minX = qMin(domain.m_minX,x); | |
46 | domain.m_minY = qMin(domain.m_minY,y); |
|
48 | domain.m_minY = qMin(domain.m_minY,y); | |
47 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
49 | domain.m_maxX = qMax(domain.m_maxX,x); | |
48 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
50 | domain.m_maxY = qMax(domain.m_maxY,y); | |
49 | } |
|
51 | } | |
50 | break; |
|
52 | break; | |
51 | } |
|
53 | } | |
52 | case QChartSeries::SeriesTypeBar: { |
|
54 | case QChartSeries::SeriesTypeBar: { | |
53 |
|
55 | |||
54 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
56 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
55 | qreal x = barSeries->countColumns(); |
|
57 | qreal x = barSeries->countColumns(); | |
56 | qreal y = barSeries->max(); |
|
58 | qreal y = barSeries->max(); | |
57 | domain.m_minX = qMin(domain.m_minX,x); |
|
59 | domain.m_minX = qMin(domain.m_minX,x); | |
58 | domain.m_minY = qMin(domain.m_minY,y); |
|
60 | domain.m_minY = qMin(domain.m_minY,y); | |
59 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
61 | domain.m_maxX = qMax(domain.m_maxX,x); | |
60 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
62 | domain.m_maxY = qMax(domain.m_maxY,y); | |
61 | } |
|
63 | } | |
62 | break; |
|
64 | break; | |
63 | case QChartSeries::SeriesTypeStackedBar: { |
|
65 | case QChartSeries::SeriesTypeStackedBar: { | |
64 |
|
66 | |||
65 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
67 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
66 | qreal x = stackedBarSeries->countColumns(); |
|
68 | qreal x = stackedBarSeries->countColumns(); | |
67 | qreal y = stackedBarSeries->maxColumnSum(); |
|
69 | qreal y = stackedBarSeries->maxColumnSum(); | |
68 | domain.m_minX = qMin(domain.m_minX,x); |
|
70 | domain.m_minX = qMin(domain.m_minX,x); | |
69 | domain.m_minY = qMin(domain.m_minY,y); |
|
71 | domain.m_minY = qMin(domain.m_minY,y); | |
70 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
72 | domain.m_maxX = qMax(domain.m_maxX,x); | |
71 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
73 | domain.m_maxY = qMax(domain.m_maxY,y); | |
72 | } |
|
74 | } | |
73 | break; |
|
75 | break; | |
74 | case QChartSeries::SeriesTypePercentBar: { |
|
76 | case QChartSeries::SeriesTypePercentBar: { | |
75 |
|
77 | |||
76 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
78 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
77 | qreal x = percentBarSeries->countColumns(); |
|
79 | qreal x = percentBarSeries->countColumns(); | |
78 | domain.m_minX = qMin(domain.m_minX,x); |
|
80 | domain.m_minX = qMin(domain.m_minX,x); | |
79 | domain.m_minY = 0; |
|
81 | domain.m_minY = 0; | |
80 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
82 | domain.m_maxX = qMax(domain.m_maxX,x); | |
81 | domain.m_maxY = 100; |
|
83 | domain.m_maxY = 100; | |
82 | } |
|
84 | } | |
83 | break; |
|
85 | break; | |
84 |
|
86 | |||
|
87 | case QChartSeries::SeriesTypePie: { | |||
|
88 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |||
|
89 | // TODO: domain stuff | |||
|
90 | break; | |||
|
91 | } | |||
|
92 | ||||
85 | default: { |
|
93 | default: { | |
86 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
94 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
87 | return; |
|
95 | return; | |
88 | break; |
|
96 | break; | |
89 | } |
|
97 | } | |
90 |
|
98 | |||
91 | } |
|
99 | } | |
92 |
|
100 | |||
93 | emit seriesAdded(series); |
|
101 | emit seriesAdded(series); | |
94 | emit domainChanged(domain); |
|
102 | emit domainChanged(domain); | |
95 | } |
|
103 | } | |
96 |
|
104 | |||
97 | bool ChartDataSet::nextDomain() |
|
105 | bool ChartDataSet::nextDomain() | |
98 | { |
|
106 | { | |
99 | if (m_domainIndex < m_domains.count() - 1) { |
|
107 | if (m_domainIndex < m_domains.count() - 1) { | |
100 | m_domainIndex++; |
|
108 | m_domainIndex++; | |
101 | emit domainChanged(m_domains[m_domainIndex]); |
|
109 | emit domainChanged(m_domains[m_domainIndex]); | |
102 | return true; |
|
110 | return true; | |
103 | } |
|
111 | } | |
104 | else { |
|
112 | else { | |
105 | return false; |
|
113 | return false; | |
106 | } |
|
114 | } | |
107 | } |
|
115 | } | |
108 |
|
116 | |||
109 | bool ChartDataSet::previousDomain() |
|
117 | bool ChartDataSet::previousDomain() | |
110 | { |
|
118 | { | |
111 | if (m_domainIndex > 0) { |
|
119 | if (m_domainIndex > 0) { | |
112 | m_domainIndex--; |
|
120 | m_domainIndex--; | |
113 | emit domainChanged(m_domains[m_domainIndex]); |
|
121 | emit domainChanged(m_domains[m_domainIndex]); | |
114 | return true; |
|
122 | return true; | |
115 | } |
|
123 | } | |
116 | else { |
|
124 | else { | |
117 | return false; |
|
125 | return false; | |
118 | } |
|
126 | } | |
119 | } |
|
127 | } | |
120 |
|
128 | |||
121 | void ChartDataSet::clearDomains() |
|
129 | void ChartDataSet::clearDomains() | |
122 | { |
|
130 | { | |
123 | if (m_domainIndex > 0) { |
|
131 | if (m_domainIndex > 0) { | |
124 | m_domainIndex = 0; |
|
132 | m_domainIndex = 0; | |
125 | emit domainChanged(m_domains[m_domainIndex]); |
|
133 | emit domainChanged(m_domains[m_domainIndex]); | |
126 | } |
|
134 | } | |
127 | } |
|
135 | } | |
128 |
|
136 | |||
129 | void ChartDataSet::addDomain(const Domain& domain) |
|
137 | void ChartDataSet::addDomain(const Domain& domain) | |
130 | { |
|
138 | { | |
131 | m_domains.resize(m_domainIndex + 1); |
|
139 | m_domains.resize(m_domainIndex + 1); | |
132 | m_domains << domain; |
|
140 | m_domains << domain; | |
133 | m_domainIndex++; |
|
141 | m_domainIndex++; | |
134 |
|
142 | |||
135 | emit domainChanged(domain); |
|
143 | emit domainChanged(domain); | |
136 | } |
|
144 | } | |
137 |
|
145 | |||
138 | #include "moc_chartdataset_p.cpp" |
|
146 | #include "moc_chartdataset_p.cpp" | |
139 |
|
147 | |||
140 | QTCOMMERCIALCHART_END_NAMESPACE |
|
148 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,243 +1,244 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | //series |
|
5 | //series | |
6 | #include "barchartseries.h" |
|
6 | #include "barchartseries.h" | |
7 | #include "stackedbarchartseries.h" |
|
7 | #include "stackedbarchartseries.h" | |
8 | #include "percentbarchartseries.h" |
|
8 | #include "percentbarchartseries.h" | |
9 | #include "qxychartseries.h" |
|
9 | #include "qxychartseries.h" | |
|
10 | #include "qpieseries.h" | |||
10 | //items |
|
11 | //items | |
11 | #include "axisitem_p.h" |
|
12 | #include "axisitem_p.h" | |
12 | #include "bargroup.h" |
|
13 | #include "bargroup.h" | |
13 | #include "stackedbargroup.h" |
|
14 | #include "stackedbargroup.h" | |
14 | #include "xylinechartitem_p.h" |
|
15 | #include "xylinechartitem_p.h" | |
15 | #include "percentbargroup.h" |
|
16 | #include "percentbargroup.h" | |
16 | #include "linechartanimationitem_p.h" |
|
17 | #include "linechartanimationitem_p.h" | |
|
18 | #include "piepresentation.h" | |||
17 |
|
19 | |||
18 | #include <QAbstractAnimation> |
|
20 | #include <QAbstractAnimation> | |
19 | #include <QPropertyAnimation> |
|
21 | #include <QPropertyAnimation> | |
20 |
|
22 | |||
21 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
22 |
|
24 | |||
23 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
24 | m_chart(chart), |
|
26 | m_chart(chart), | |
25 | m_dataset(dataset), |
|
27 | m_dataset(dataset), | |
26 | m_domainIndex(0), |
|
28 | m_domainIndex(0), | |
27 | m_marginSize(0), |
|
29 | m_marginSize(0), | |
28 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
30 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
29 | { |
|
31 | { | |
30 | createConnections(); |
|
32 | createConnections(); | |
31 | createDeafultAxis(); |
|
33 | createDeafultAxis(); | |
32 | } |
|
34 | } | |
33 |
|
35 | |||
34 | ChartPresenter::~ChartPresenter() |
|
36 | ChartPresenter::~ChartPresenter() | |
35 | { |
|
37 | { | |
36 | } |
|
38 | } | |
37 |
|
39 | |||
38 | void ChartPresenter::createDeafultAxis() |
|
40 | void ChartPresenter::createDeafultAxis() | |
39 | { |
|
41 | { | |
40 | //default axis |
|
42 | //default axis | |
41 | QChartAxis* axisX = new QChartAxis(this); |
|
43 | QChartAxis* axisX = new QChartAxis(this); | |
42 | QChartAxis* axisY = new QChartAxis(this); |
|
44 | QChartAxis* axisY = new QChartAxis(this); | |
43 |
|
45 | |||
44 | m_axis << new AxisItem(axisX,AxisItem::X_AXIS,m_chart); |
|
46 | m_axis << new AxisItem(axisX,AxisItem::X_AXIS,m_chart); | |
45 | m_axis << new AxisItem(axisY,AxisItem::Y_AXIS,m_chart); |
|
47 | m_axis << new AxisItem(axisY,AxisItem::Y_AXIS,m_chart); | |
46 |
|
48 | |||
47 | foreach(AxisItem* item, m_axis) { |
|
49 | foreach(AxisItem* item, m_axis) { | |
48 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
50 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
49 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
51 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
50 | } |
|
52 | } | |
51 | } |
|
53 | } | |
52 |
|
54 | |||
53 | void ChartPresenter::createConnections() |
|
55 | void ChartPresenter::createConnections() | |
54 | { |
|
56 | { | |
55 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
57 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
56 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
58 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
57 | } |
|
59 | } | |
58 |
|
60 | |||
59 | void ChartPresenter::handleGeometryChanged() |
|
61 | void ChartPresenter::handleGeometryChanged() | |
60 | { |
|
62 | { | |
61 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
63 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
62 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
64 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
63 | emit geometryChanged(m_rect); |
|
65 | emit geometryChanged(m_rect); | |
64 | } |
|
66 | } | |
65 |
|
67 | |||
66 | int ChartPresenter::margin() const |
|
68 | int ChartPresenter::margin() const | |
67 | { |
|
69 | { | |
68 | return m_marginSize; |
|
70 | return m_marginSize; | |
69 | } |
|
71 | } | |
70 |
|
72 | |||
71 | void ChartPresenter::setMargin(int margin) |
|
73 | void ChartPresenter::setMargin(int margin) | |
72 | { |
|
74 | { | |
73 | m_marginSize = margin; |
|
75 | m_marginSize = margin; | |
74 | } |
|
76 | } | |
75 |
|
77 | |||
76 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
78 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
77 | { |
|
79 | { | |
78 | switch(series->type()) |
|
80 | switch(series->type()) | |
79 | { |
|
81 | { | |
80 | case QChartSeries::SeriesTypeLine: { |
|
82 | case QChartSeries::SeriesTypeLine: { | |
81 | QXYChartSeries* lineSeries = static_cast<QXYChartSeries*>(series); |
|
83 | QXYChartSeries* lineSeries = static_cast<QXYChartSeries*>(series); | |
82 | XYLineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
84 | XYLineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
83 | item->setPen(lineSeries->pen()); |
|
85 | item->setPen(lineSeries->pen()); | |
84 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
86 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
85 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
87 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
86 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
88 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
87 | m_chartItems.insert(series,item); |
|
89 | m_chartItems.insert(series,item); | |
88 | break; |
|
90 | break; | |
89 | } |
|
91 | } | |
90 |
|
92 | |||
91 | case QChartSeries::SeriesTypeBar: { |
|
93 | case QChartSeries::SeriesTypeBar: { | |
92 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
94 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
93 | BarGroup* item = new BarGroup(*barSeries,m_chart); |
|
95 | BarGroup* item = new BarGroup(*barSeries,m_chart); | |
94 |
|
96 | |||
95 | // Add some fugly colors for 5 fist series... |
|
97 | // Add some fugly colors for 5 fist series... | |
96 | item->addColor(QColor(255,0,0,128)); |
|
98 | item->addColor(QColor(255,0,0,128)); | |
97 | item->addColor(QColor(255,255,0,128)); |
|
99 | item->addColor(QColor(255,255,0,128)); | |
98 | item->addColor(QColor(0,255,0,128)); |
|
100 | item->addColor(QColor(0,255,0,128)); | |
99 | item->addColor(QColor(0,0,255,128)); |
|
101 | item->addColor(QColor(0,0,255,128)); | |
100 | item->addColor(QColor(255,128,0,128)); |
|
102 | item->addColor(QColor(255,128,0,128)); | |
101 |
|
103 | |||
102 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
104 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
103 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
104 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
106 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
105 | m_chartItems.insert(series,item); |
|
107 | m_chartItems.insert(series,item); | |
106 | // m_axisXItem->setVisible(false); |
|
108 | // m_axisXItem->setVisible(false); | |
107 | break; |
|
109 | break; | |
108 | } |
|
110 | } | |
109 |
|
111 | |||
110 | case QChartSeries::SeriesTypeStackedBar: { |
|
112 | case QChartSeries::SeriesTypeStackedBar: { | |
111 |
|
113 | |||
112 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
114 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
113 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); |
|
115 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); | |
114 |
|
116 | |||
115 | // Add some fugly colors for 5 fist series... |
|
117 | // Add some fugly colors for 5 fist series... | |
116 | item->addColor(QColor(255,0,0,128)); |
|
118 | item->addColor(QColor(255,0,0,128)); | |
117 | item->addColor(QColor(255,255,0,128)); |
|
119 | item->addColor(QColor(255,255,0,128)); | |
118 | item->addColor(QColor(0,255,0,128)); |
|
120 | item->addColor(QColor(0,255,0,128)); | |
119 | item->addColor(QColor(0,0,255,128)); |
|
121 | item->addColor(QColor(0,0,255,128)); | |
120 | item->addColor(QColor(255,128,0,128)); |
|
122 | item->addColor(QColor(255,128,0,128)); | |
121 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
123 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
122 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
124 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
123 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
125 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
124 | m_chartItems.insert(series,item); |
|
126 | m_chartItems.insert(series,item); | |
125 | break; |
|
127 | break; | |
126 | } |
|
128 | } | |
127 |
|
129 | |||
128 | case QChartSeries::SeriesTypePercentBar: { |
|
130 | case QChartSeries::SeriesTypePercentBar: { | |
129 |
|
131 | |||
130 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
132 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
131 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); |
|
133 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); | |
132 |
|
134 | |||
133 | // Add some fugly colors for 5 fist series... |
|
135 | // Add some fugly colors for 5 fist series... | |
134 | item->addColor(QColor(255,0,0,128)); |
|
136 | item->addColor(QColor(255,0,0,128)); | |
135 | item->addColor(QColor(255,255,0,128)); |
|
137 | item->addColor(QColor(255,255,0,128)); | |
136 | item->addColor(QColor(0,255,0,128)); |
|
138 | item->addColor(QColor(0,255,0,128)); | |
137 | item->addColor(QColor(0,0,255,128)); |
|
139 | item->addColor(QColor(0,0,255,128)); | |
138 | item->addColor(QColor(255,128,0,128)); |
|
140 | item->addColor(QColor(255,128,0,128)); | |
139 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
141 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
140 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
142 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
141 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
143 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
142 | m_chartItems.insert(series,item); |
|
144 | m_chartItems.insert(series,item); | |
143 | break; |
|
145 | break; | |
144 | } |
|
146 | } | |
145 | /* |
|
147 | /* | |
146 | case QChartSeries::SeriesTypeScatter: { |
|
148 | case QChartSeries::SeriesTypeScatter: { | |
147 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
149 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
148 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
150 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
149 | scatterSeries->d->setParentItem(this); |
|
151 | scatterSeries->d->setParentItem(this); | |
150 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
152 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
151 | m_chartItems << scatterSeries->d; |
|
153 | m_chartItems << scatterSeries->d; | |
152 | m_chartTheme->addObserver(scatterSeries->d); |
|
154 | m_chartTheme->addObserver(scatterSeries->d); | |
153 |
|
155 | |||
154 | foreach (qreal x, scatterSeries->d->m_x) { |
|
156 | foreach (qreal x, scatterSeries->d->m_x) { | |
155 | domain.m_minX = qMin(domain.m_minX, x); |
|
157 | domain.m_minX = qMin(domain.m_minX, x); | |
156 | domain.m_maxX = qMax(domain.m_maxX, x); |
|
158 | domain.m_maxX = qMax(domain.m_maxX, x); | |
157 | } |
|
159 | } | |
158 | foreach (qreal y, scatterSeries->d->m_y) { |
|
160 | foreach (qreal y, scatterSeries->d->m_y) { | |
159 | domain.m_minY = qMin(domain.m_minY, y); |
|
161 | domain.m_minY = qMin(domain.m_minY, y); | |
160 | domain.m_maxY = qMax(domain.m_maxY, y); |
|
162 | domain.m_maxY = qMax(domain.m_maxY, y); | |
161 | } |
|
163 | } | |
162 |
|
164 | |||
163 | break; |
|
165 | break; | |
164 | } |
|
166 | } | |
165 | case QChartSeries::SeriesTypePie: { |
|
|||
166 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
|||
167 | pieSeries->d->setParentItem(this); |
|
|||
168 | m_chartItems << pieSeries->d; |
|
|||
169 | pieSeries->d->m_chartTheme = m_chartTheme; |
|
|||
170 | m_chartTheme->addObserver(pieSeries->d); |
|
|||
171 | break; |
|
|||
172 | } |
|
|||
173 | default: |
|
|||
174 | break; |
|
|||
175 | } |
|
|||
176 | */ |
|
167 | */ | |
177 |
|
168 | |||
|
169 | case QChartSeries::SeriesTypePie: { | |||
|
170 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |||
|
171 | PiePresentation* pieChart = new PiePresentation(m_chart, pieSeries); | |||
|
172 | pieSeries->m_piePresentation = pieChart; // TODO: remove this pointer passing use signals&slots | |||
|
173 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pieChart, SLOT(handleGeometryChanged(const QRectF&))); | |||
|
174 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pieChart, SLOT(handleDomainChanged(const Domain&))); | |||
|
175 | m_chartItems.insert(series, pieChart); | |||
|
176 | break; | |||
|
177 | } | |||
|
178 | ||||
178 | default: { |
|
179 | default: { | |
179 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
180 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
180 | break; |
|
181 | break; | |
181 | } |
|
182 | } | |
182 | } |
|
183 | } | |
183 | } |
|
184 | } | |
184 |
|
185 | |||
185 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
186 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
186 | { |
|
187 | { | |
187 | //TODO: |
|
188 | //TODO: | |
188 | } |
|
189 | } | |
189 |
|
190 | |||
190 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
|
191 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |
191 | { |
|
192 | { | |
192 | if(!rect.isValid()) return; |
|
193 | if(!rect.isValid()) return; | |
193 | QRectF r = rect.normalized(); |
|
194 | QRectF r = rect.normalized(); | |
194 | r.translate(-m_marginSize, -m_marginSize); |
|
195 | r.translate(-m_marginSize, -m_marginSize); | |
195 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
196 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
196 | m_dataset->addDomain(domain); |
|
197 | m_dataset->addDomain(domain); | |
197 | } |
|
198 | } | |
198 |
|
199 | |||
199 | void ChartPresenter::zoomIn() |
|
200 | void ChartPresenter::zoomIn() | |
200 | { |
|
201 | { | |
201 | if (!m_dataset->nextDomain()) { |
|
202 | if (!m_dataset->nextDomain()) { | |
202 | QRectF rect = m_rect; |
|
203 | QRectF rect = m_rect; | |
203 | rect.setWidth(rect.width()/2); |
|
204 | rect.setWidth(rect.width()/2); | |
204 | rect.setHeight(rect.height()/2); |
|
205 | rect.setHeight(rect.height()/2); | |
205 | rect.moveCenter(m_rect.center()); |
|
206 | rect.moveCenter(m_rect.center()); | |
206 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
207 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
207 | m_dataset->addDomain(domain); |
|
208 | m_dataset->addDomain(domain); | |
208 | } |
|
209 | } | |
209 | } |
|
210 | } | |
210 |
|
211 | |||
211 | void ChartPresenter::zoomOut() |
|
212 | void ChartPresenter::zoomOut() | |
212 | { |
|
213 | { | |
213 | m_dataset->previousDomain(); |
|
214 | m_dataset->previousDomain(); | |
214 | } |
|
215 | } | |
215 |
|
216 | |||
216 | void ChartPresenter::zoomReset() |
|
217 | void ChartPresenter::zoomReset() | |
217 | { |
|
218 | { | |
218 | m_dataset->clearDomains(); |
|
219 | m_dataset->clearDomains(); | |
219 | } |
|
220 | } | |
220 |
|
221 | |||
221 | /* |
|
222 | /* | |
222 | void ChartPresenter::setAxisX(const QChartAxis& axis) |
|
223 | void ChartPresenter::setAxisX(const QChartAxis& axis) | |
223 | { |
|
224 | { | |
224 | setAxis(m_axisXItem,axis); |
|
225 | setAxis(m_axisXItem,axis); | |
225 | } |
|
226 | } | |
226 | void ChartPresenter::setAxisY(const QChartAxis& axis) |
|
227 | void ChartPresenter::setAxisY(const QChartAxis& axis) | |
227 | { |
|
228 | { | |
228 | setAxis(m_axisYItem.at(0),axis); |
|
229 | setAxis(m_axisYItem.at(0),axis); | |
229 | } |
|
230 | } | |
230 |
|
231 | |||
231 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) |
|
232 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) | |
232 | { |
|
233 | { | |
233 | //TODO not implemented |
|
234 | //TODO not implemented | |
234 | } |
|
235 | } | |
235 |
|
236 | |||
236 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) |
|
237 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) | |
237 | { |
|
238 | { | |
238 | item->setVisible(axis.isAxisVisible()); |
|
239 | item->setVisible(axis.isAxisVisible()); | |
239 | } |
|
240 | } | |
240 | */ |
|
241 | */ | |
241 | #include "moc_chartpresenter_p.cpp" |
|
242 | #include "moc_chartpresenter_p.cpp" | |
242 |
|
243 | |||
243 | QTCOMMERCIALCHART_END_NAMESPACE |
|
244 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,74 +1,90 | |||||
1 | #include "pieslice.h" |
|
1 | #include "pieslice.h" | |
|
2 | #include "piepresentation.h" | |||
2 | #include <QPainter> |
|
3 | #include <QPainter> | |
3 | #include <QDebug> |
|
4 | #include <QDebug> | |
4 |
|
5 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
7 | |||
7 |
PieSlice::PieSlice( |
|
8 | PieSlice::PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span) | |
8 | : m_color(color), |
|
9 | :QGraphicsItem(piePresentation), | |
|
10 | m_seriesIndex(seriesIndex), | |||
9 | m_startAngle(startAngle), |
|
11 | m_startAngle(startAngle), | |
10 |
m_span(span) |
|
12 | m_span(span) | |
11 | m_rect(rect) |
|
|||
12 | { |
|
13 | { | |
|
14 | Q_ASSERT(piePresentation); | |||
13 | setAcceptHoverEvents(true); |
|
15 | setAcceptHoverEvents(true); | |
|
16 | setAcceptedMouseButtons(Qt::LeftButton); | |||
14 | } |
|
17 | } | |
15 |
|
18 | |||
16 | PieSlice::~PieSlice() |
|
19 | PieSlice::~PieSlice() | |
17 | { |
|
20 | { | |
18 | } |
|
21 | } | |
19 |
|
22 | |||
20 | QRectF PieSlice::boundingRect() const |
|
23 | QRectF PieSlice::boundingRect() const | |
21 | { |
|
24 | { | |
22 | return m_rect; |
|
25 | return shape().boundingRect(); | |
23 | } |
|
26 | } | |
24 |
|
27 | |||
25 | QPainterPath PieSlice::shape() const |
|
28 | QPainterPath PieSlice::shape() const | |
26 | { |
|
29 | { | |
|
30 | QRectF rect = (static_cast<PiePresentation*>(parentItem()))->pieRect(); | |||
27 | qreal angle = (-m_startAngle) + (90); |
|
31 | qreal angle = (-m_startAngle) + (90); | |
28 | qreal span = -m_span; |
|
32 | qreal span = -m_span; | |
29 |
|
33 | |||
30 | QPainterPath path; |
|
34 | QPainterPath path; | |
31 |
path.moveTo( |
|
35 | path.moveTo(rect.center()); | |
32 |
path.arcTo( |
|
36 | path.arcTo(rect, angle, span); | |
33 |
|
37 | |||
34 | // TODO: draw the shape so that it might have a hole in the center |
|
38 | // TODO: draw the shape so that it might have a hole in the center | |
35 | // - Sin & Cos will be needed to find inner/outer arc endpoints |
|
39 | // - Sin & Cos will be needed to find inner/outer arc endpoints | |
36 |
|
40 | |||
37 | // dx, dy are offsets from the center |
|
41 | // dx, dy are offsets from the center | |
38 | //qreal l = boundingRect().height(); |
|
42 | //qreal l = boundingRect().height(); | |
39 | //qreal dx = qSin(angle*(M_PI/180)) * l; |
|
43 | //qreal dx = qSin(angle*(M_PI/180)) * l; | |
40 | //qreal dy = qCos(angle*(M_PI/180)) * l; |
|
44 | //qreal dy = qCos(angle*(M_PI/180)) * l; | |
41 |
|
45 | |||
42 | // TODO: exploded slice? |
|
46 | // TODO: exploded slice? | |
43 |
|
47 | |||
44 | return path; |
|
48 | return path; | |
45 | } |
|
49 | } | |
46 |
|
50 | |||
47 |
void PieSlice::paint(QPainter |
|
51 | void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) | |
48 | { |
|
52 | { | |
49 | painter->setRenderHint(QPainter::Antialiasing); |
|
53 | painter->setRenderHint(QPainter::Antialiasing); | |
50 | // TODO: how to map theme settings to a pie slice? Now we |
|
54 | // TODO: how to map theme settings to a pie slice? Now we | |
51 | //painter->setPen(m_theme.linePen); |
|
55 | //painter->setPen(m_theme.linePen); | |
52 | // TODO: |
|
56 | // TODO: | |
53 | painter->setBrush(m_theme.linePen.color()); |
|
57 | ||
|
58 | QPieSlice data = (static_cast<PiePresentation*>(parentItem()))->m_pieSeries->slice(m_seriesIndex); | |||
|
59 | painter->setBrush(data.m_color); | |||
|
60 | ||||
|
61 | //painter->setBrush(m_theme.linePen.color()); | |||
54 |
|
62 | |||
55 | // From Qt docs: |
|
63 | // From Qt docs: | |
56 | // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). |
|
64 | // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). | |
57 | // Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. |
|
65 | // Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. | |
58 | // Zero degrees is at the 3 o'clock position. |
|
66 | // Zero degrees is at the 3 o'clock position. | |
59 | // |
|
67 | // | |
60 | // For sake of simplicity convert this so that zero degrees is at 12 o'clock and full circle is 360. |
|
68 | // For sake of simplicity convert this so that zero degrees is at 12 o'clock and full circle is 360. | |
61 | //qreal angle = (-m_startAngle*16) + (90*16); |
|
69 | //qreal angle = (-m_startAngle*16) + (90*16); | |
62 | //qreal span = -m_span*16; |
|
70 | //qreal span = -m_span*16; | |
63 | //painter->drawPie(boundingRect(), angle, span); |
|
71 | //painter->drawPie(boundingRect(), angle, span); | |
64 |
|
72 | |||
65 | painter->drawPath(shape()); |
|
73 | painter->drawPath(shape()); | |
|
74 | ||||
|
75 | // Draw the label | |||
|
76 | // TODO: do this better | |||
|
77 | painter->drawText(boundingRect().center(), data.m_label); | |||
66 | } |
|
78 | } | |
67 |
|
79 | |||
68 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event) |
|
80 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event) | |
69 | { |
|
81 | { | |
70 | QGraphicsItem::hoverEnterEvent(event); |
|
82 | QGraphicsItem::hoverEnterEvent(event); | |
71 |
qDebug() << "hover" << m_ |
|
83 | qDebug() << "hover" << m_seriesIndex << m_startAngle << m_span; | |
72 | } |
|
84 | } | |
73 |
|
85 | |||
|
86 | void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
|
87 | { | |||
|
88 | QGraphicsItem::mousePressEvent(event); | |||
|
89 | } | |||
74 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,34 +1,35 | |||||
1 | #ifndef PIESLICE_H |
|
1 | #ifndef PIESLICE_H | |
2 | #define PIESLICE_H |
|
2 | #define PIESLICE_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 | #include <QRectF> |
|
7 | #include <QRectF> | |
8 | #include <QColor> |
|
8 | #include <QColor> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
11 | class PiePresentation; | |||
11 |
|
12 | |||
12 | class PieSlice : public QGraphicsItem |
|
13 | class PieSlice : public QGraphicsItem | |
13 | { |
|
14 | { | |
14 | public: |
|
15 | public: | |
15 | PieSlice(const QColor& color, qreal startAngle, qreal span, QRectF rect); |
|
16 | PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span); | |
16 | ~PieSlice(); |
|
17 | ~PieSlice(); | |
17 |
|
18 | |||
18 | public: // from QGraphicsItem |
|
19 | public: // from QGraphicsItem | |
19 | QRectF boundingRect() const; |
|
20 | QRectF boundingRect() const; | |
20 | QPainterPath shape() const; |
|
21 | QPainterPath shape() const; | |
21 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
22 |
void hoverEnterEvent(QGraphicsSceneHoverEvent * |
|
23 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
|
24 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |||
23 |
|
25 | |||
24 | public: |
|
26 | private: | |
25 | QColor m_color; |
|
27 | int m_seriesIndex; | |
26 | qreal m_startAngle; |
|
28 | qreal m_startAngle; | |
27 | qreal m_span; |
|
29 | qreal m_span; | |
28 | QRectF m_rect; |
|
30 | //SeriesTheme m_theme; | |
29 | SeriesTheme m_theme; |
|
|||
30 | }; |
|
31 | }; | |
31 |
|
32 | |||
32 | QTCOMMERCIALCHART_END_NAMESPACE |
|
33 | QTCOMMERCIALCHART_END_NAMESPACE | |
33 |
|
34 | |||
34 | #endif // PIESLICE_H |
|
35 | #endif // PIESLICE_H |
@@ -1,53 +1,86 | |||||
1 | #ifndef PIESERIES_H |
|
1 | #ifndef PIESERIES_H | |
2 | #define PIESERIES_H |
|
2 | #define PIESERIES_H | |
3 |
|
3 | |||
4 | #include "qchartseries.h" |
|
4 | #include "qchartseries.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QRectF> |
|
6 | #include <QRectF> | |
7 | #include <QColor> |
|
7 | #include <QColor> | |
8 |
|
8 | |||
9 | class QGraphicsObject; |
|
9 | class QGraphicsObject; | |
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
class |
|
11 | class PiePresentation; | |
12 | class PieSlice; |
|
12 | class PieSlice; | |
13 |
|
13 | |||
|
14 | class QPieSlice | |||
|
15 | { | |||
|
16 | public: | |||
|
17 | QPieSlice() | |||
|
18 | :m_value(0), m_label("<empty>"), m_color(Qt::white), m_isExploded(false) {} | |||
|
19 | ||||
|
20 | QPieSlice(qreal value, QString label, QColor color, bool exploded = false) | |||
|
21 | :m_value(value), m_label(label), m_color(color), m_isExploded(exploded) {} | |||
|
22 | public: | |||
|
23 | qreal m_value; | |||
|
24 | QString m_label; | |||
|
25 | QColor m_color; | |||
|
26 | bool m_isExploded; | |||
|
27 | }; | |||
|
28 | ||||
14 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries |
|
29 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries | |
15 | { |
|
30 | { | |
16 | Q_OBJECT |
|
31 | Q_OBJECT | |
17 |
|
32 | |||
18 | public: |
|
33 | public: | |
19 | enum PiePosition { |
|
34 | enum PiePosition { | |
20 | PiePositionMaximized = 0, |
|
35 | PiePositionMaximized = 0, | |
21 | PiePositionTopLeft, |
|
36 | PiePositionTopLeft, | |
22 | PiePositionTopRight, |
|
37 | PiePositionTopRight, | |
23 | PiePositionBottomLeft, |
|
38 | PiePositionBottomLeft, | |
24 | PiePositionBottomRight |
|
39 | PiePositionBottomRight | |
25 | }; |
|
40 | }; | |
26 |
|
41 | |||
27 | public: |
|
42 | public: | |
28 | // TODO: use a generic data class instead of x and y |
|
43 | QPieSeries(QObject *parent = 0); | |
29 | QPieSeries(QGraphicsObject *parent = 0); |
|
|||
30 | ~QPieSeries(); |
|
44 | ~QPieSeries(); | |
31 |
|
45 | |||
32 | public: // from QChartSeries |
|
46 | public: // from QChartSeries | |
33 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } |
|
47 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } | |
34 | bool setData(QList<qreal> data); |
|
|||
35 |
|
48 | |||
36 | public: |
|
49 | public: | |
37 | void setSliceColor(int index, QColor color); |
|
50 | void set(QList<QPieSlice> slices); | |
38 | QColor sliceColor(int index); |
|
51 | void add(QList<QPieSlice> slices); | |
39 | int sliceCount(); |
|
52 | void add(QPieSlice slice); | |
|
53 | ||||
|
54 | int count() const { return m_slices.count(); } | |||
|
55 | ||||
|
56 | QList<QPieSlice> slices() const { return m_slices; } | |||
|
57 | QPieSlice slice(int index) const; | |||
|
58 | bool update(int index, QPieSlice slice); | |||
|
59 | ||||
|
60 | // TODO: convenience functions | |||
|
61 | //void updateValue(int sliceIndex, qreal value); | |||
|
62 | //void updateLabel(int sliceIndex, QString label); | |||
|
63 | //void updateColor(int sliceIndex, QColor color); | |||
|
64 | //void updateExploded(int slizeIndex, bool exploded); | |||
|
65 | ||||
40 | void setSizeFactor(qreal sizeFactor); |
|
66 | void setSizeFactor(qreal sizeFactor); | |
41 | qreal sizeFactor(); |
|
67 | qreal sizeFactor() const { return m_sizeFactor; } | |
|
68 | ||||
42 | void setPosition(PiePosition position); |
|
69 | void setPosition(PiePosition position); | |
|
70 | PiePosition position() const { return m_position; } | |||
43 |
|
71 | |||
44 | private: |
|
72 | private: | |
45 | Q_DECLARE_PRIVATE(QPieSeries) |
|
|||
46 | Q_DISABLE_COPY(QPieSeries) |
|
73 | Q_DISABLE_COPY(QPieSeries) | |
47 | friend class QChart; |
|
74 | // TODO: use PIML | |
48 | QPieSeriesPrivate *const d; |
|
75 | friend class ChartPresenter; | |
|
76 | friend class ChartDataSet; | |||
|
77 | friend class PiePresentation; | |||
|
78 | PiePresentation *m_piePresentation; | |||
|
79 | QList<QPieSlice> m_slices; | |||
|
80 | qreal m_sizeFactor; | |||
|
81 | PiePosition m_position; | |||
49 | }; |
|
82 | }; | |
50 |
|
83 | |||
51 | QTCOMMERCIALCHART_END_NAMESPACE |
|
84 | QTCOMMERCIALCHART_END_NAMESPACE | |
52 |
|
85 | |||
53 | #endif // PIESERIES_H |
|
86 | #endif // PIESERIES_H |
@@ -1,226 +1,225 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartseries.h" |
|
2 | #include "qchartseries.h" | |
3 | #include "qscatterseries.h" |
|
3 | #include "qscatterseries.h" | |
4 | #include "qscatterseries_p.h" |
|
4 | #include "qscatterseries_p.h" | |
5 | #include "qpieseries.h" |
|
5 | #include "qpieseries.h" | |
6 | #include "qpieseries_p.h" |
|
|||
7 | #include "qchartaxis.h" |
|
6 | #include "qchartaxis.h" | |
8 | #include "charttheme_p.h" |
|
7 | #include "charttheme_p.h" | |
9 | #include "chartitem_p.h" |
|
8 | #include "chartitem_p.h" | |
10 | #include "plotdomain_p.h" |
|
9 | #include "plotdomain_p.h" | |
11 | #include "axisitem_p.h" |
|
10 | #include "axisitem_p.h" | |
12 | #include "chartpresenter_p.h" |
|
11 | #include "chartpresenter_p.h" | |
13 | #include "chartdataset_p.h" |
|
12 | #include "chartdataset_p.h" | |
14 |
|
13 | |||
15 | //series |
|
14 | //series | |
16 | #include "barchartseries.h" |
|
15 | #include "barchartseries.h" | |
17 | #include "stackedbarchartseries.h" |
|
16 | #include "stackedbarchartseries.h" | |
18 | #include "percentbarchartseries.h" |
|
17 | #include "percentbarchartseries.h" | |
19 | #include "qxychartseries.h" |
|
18 | #include "qxychartseries.h" | |
20 |
|
19 | |||
21 |
|
20 | |||
22 | #include <QGraphicsScene> |
|
21 | #include <QGraphicsScene> | |
23 | #include <QGraphicsSceneResizeEvent> |
|
22 | #include <QGraphicsSceneResizeEvent> | |
24 | #include <QDebug> |
|
23 | #include <QDebug> | |
25 |
|
24 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
26 | |||
28 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
27 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
29 | m_backgroundItem(0), |
|
28 | m_backgroundItem(0), | |
30 | m_titleItem(0), |
|
29 | m_titleItem(0), | |
31 | m_axisXItem(0), |
|
30 | m_axisXItem(0), | |
32 | m_chartTheme(new ChartTheme(this)), |
|
31 | m_chartTheme(new ChartTheme(this)), | |
33 | //m_dataset(0), |
|
32 | //m_dataset(0), | |
34 | m_dataset(new ChartDataSet(this)), |
|
33 | m_dataset(new ChartDataSet(this)), | |
35 | //m_presenter(0) |
|
34 | //m_presenter(0) | |
36 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
35 | m_presenter(new ChartPresenter(this,m_dataset)) | |
37 | { |
|
36 | { | |
38 | // TODO: the default theme? |
|
37 | // TODO: the default theme? | |
39 | setTheme(QChart::ChartThemeDefault); |
|
38 | setTheme(QChart::ChartThemeDefault); | |
40 | //m_chartItems << m_axisXItem; |
|
39 | //m_chartItems << m_axisXItem; | |
41 | //m_chartItems << m_axisYItem.at(0); |
|
40 | //m_chartItems << m_axisYItem.at(0); | |
42 | } |
|
41 | } | |
43 |
|
42 | |||
44 | QChart::~QChart(){} |
|
43 | QChart::~QChart(){} | |
45 |
|
44 | |||
46 | void QChart::addSeries(QChartSeries* series) |
|
45 | void QChart::addSeries(QChartSeries* series) | |
47 | { |
|
46 | { | |
48 | m_dataset->addSeries(series); |
|
47 | m_dataset->addSeries(series); | |
49 | } |
|
48 | } | |
50 |
|
49 | |||
51 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
50 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
52 | { |
|
51 | { | |
53 | // TODO: support also other types; not only scatter and pie |
|
52 | // TODO: support also other types; not only scatter and pie | |
54 |
|
53 | |||
55 | QChartSeries *series(0); |
|
54 | QChartSeries *series(0); | |
56 |
|
55 | |||
57 | switch (type) { |
|
56 | switch (type) { | |
58 | case QChartSeries::SeriesTypeLine: { |
|
57 | case QChartSeries::SeriesTypeLine: { | |
59 | series = QXYChartSeries::create(); |
|
58 | series = QXYChartSeries::create(); | |
60 | break; |
|
59 | break; | |
61 | } |
|
60 | } | |
62 | case QChartSeries::SeriesTypeBar: { |
|
61 | case QChartSeries::SeriesTypeBar: { | |
63 | series = new BarChartSeries(this); |
|
62 | series = new BarChartSeries(this); | |
64 | break; |
|
63 | break; | |
65 | } |
|
64 | } | |
66 | case QChartSeries::SeriesTypeStackedBar: { |
|
65 | case QChartSeries::SeriesTypeStackedBar: { | |
67 | series = new StackedBarChartSeries(this); |
|
66 | series = new StackedBarChartSeries(this); | |
68 | break; |
|
67 | break; | |
69 | } |
|
68 | } | |
70 | case QChartSeries::SeriesTypePercentBar: { |
|
69 | case QChartSeries::SeriesTypePercentBar: { | |
71 | series = new PercentBarChartSeries(this); |
|
70 | series = new PercentBarChartSeries(this); | |
72 | break; |
|
71 | break; | |
73 | } |
|
72 | } | |
74 | case QChartSeries::SeriesTypeScatter: { |
|
73 | case QChartSeries::SeriesTypeScatter: { | |
75 | series = new QScatterSeries(this); |
|
74 | series = new QScatterSeries(this); | |
76 | break; |
|
75 | break; | |
77 | } |
|
76 | } | |
78 | case QChartSeries::SeriesTypePie: { |
|
77 | case QChartSeries::SeriesTypePie: { | |
79 | series = new QPieSeries(this); |
|
78 | series = new QPieSeries(this); | |
80 | break; |
|
79 | break; | |
81 | } |
|
80 | } | |
82 | default: |
|
81 | default: | |
83 | Q_ASSERT(false); |
|
82 | Q_ASSERT(false); | |
84 | break; |
|
83 | break; | |
85 | } |
|
84 | } | |
86 |
|
85 | |||
87 | addSeries(series); |
|
86 | addSeries(series); | |
88 | return series; |
|
87 | return series; | |
89 | } |
|
88 | } | |
90 |
|
89 | |||
91 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
90 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
92 | { |
|
91 | { | |
93 |
|
92 | |||
94 | if(!m_backgroundItem){ |
|
93 | if(!m_backgroundItem){ | |
95 | m_backgroundItem = new QGraphicsRectItem(this); |
|
94 | m_backgroundItem = new QGraphicsRectItem(this); | |
96 | m_backgroundItem->setZValue(-1); |
|
95 | m_backgroundItem->setZValue(-1); | |
97 | } |
|
96 | } | |
98 |
|
97 | |||
99 | m_backgroundItem->setBrush(brush); |
|
98 | m_backgroundItem->setBrush(brush); | |
100 | m_backgroundItem->update(); |
|
99 | m_backgroundItem->update(); | |
101 | } |
|
100 | } | |
102 |
|
101 | |||
103 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
102 | void QChart::setChartBackgroundPen(const QPen& pen) | |
104 | { |
|
103 | { | |
105 |
|
104 | |||
106 | if(!m_backgroundItem){ |
|
105 | if(!m_backgroundItem){ | |
107 | m_backgroundItem = new QGraphicsRectItem(this); |
|
106 | m_backgroundItem = new QGraphicsRectItem(this); | |
108 | m_backgroundItem->setZValue(-1); |
|
107 | m_backgroundItem->setZValue(-1); | |
109 | } |
|
108 | } | |
110 |
|
109 | |||
111 | m_backgroundItem->setPen(pen); |
|
110 | m_backgroundItem->setPen(pen); | |
112 | m_backgroundItem->update(); |
|
111 | m_backgroundItem->update(); | |
113 | } |
|
112 | } | |
114 |
|
113 | |||
115 | void QChart::setTitle(const QString& title,const QFont& font) |
|
114 | void QChart::setTitle(const QString& title,const QFont& font) | |
116 | { |
|
115 | { | |
117 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
116 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
118 | m_titleItem->setPlainText(title); |
|
117 | m_titleItem->setPlainText(title); | |
119 | m_titleItem->setFont(font); |
|
118 | m_titleItem->setFont(font); | |
120 | } |
|
119 | } | |
121 |
|
120 | |||
122 | int QChart::margin() const |
|
121 | int QChart::margin() const | |
123 | { |
|
122 | { | |
124 | m_presenter->margin(); |
|
123 | return m_presenter->margin(); | |
125 | } |
|
124 | } | |
126 |
|
125 | |||
127 | void QChart::setMargin(int margin) |
|
126 | void QChart::setMargin(int margin) | |
128 | { |
|
127 | { | |
129 | m_presenter->setMargin(margin); |
|
128 | m_presenter->setMargin(margin); | |
130 | } |
|
129 | } | |
131 |
|
130 | |||
132 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
131 | void QChart::setTheme(QChart::ChartThemeId theme) | |
133 | { |
|
132 | { | |
134 | m_chartTheme->setTheme(theme); |
|
133 | m_chartTheme->setTheme(theme); | |
135 |
|
134 | |||
136 | QLinearGradient backgroundGradient; |
|
135 | QLinearGradient backgroundGradient; | |
137 | backgroundGradient.setColorAt(0.0, m_chartTheme->d->m_gradientStartColor); |
|
136 | backgroundGradient.setColorAt(0.0, m_chartTheme->d->m_gradientStartColor); | |
138 | backgroundGradient.setColorAt(1.0, m_chartTheme->d->m_gradientEndColor); |
|
137 | backgroundGradient.setColorAt(1.0, m_chartTheme->d->m_gradientEndColor); | |
139 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
138 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
140 | setChartBackgroundBrush(backgroundGradient); |
|
139 | setChartBackgroundBrush(backgroundGradient); | |
141 |
|
140 | |||
142 | // TODO: Move the controlling of the series presentations into private implementation of the |
|
141 | // TODO: Move the controlling of the series presentations into private implementation of the | |
143 | // series instead of QChart controlling themes for each |
|
142 | // series instead of QChart controlling themes for each | |
144 | // In other words, the following should be used when creating xy series: |
|
143 | // In other words, the following should be used when creating xy series: | |
145 | // m_chartTheme->addObserver(xyseries) |
|
144 | // m_chartTheme->addObserver(xyseries) | |
146 | foreach (QChartSeries *series, m_chartSeries) { |
|
145 | foreach (QChartSeries *series, m_chartSeries) { | |
147 | if (series->type() == QChartSeries::SeriesTypeLine) { |
|
146 | if (series->type() == QChartSeries::SeriesTypeLine) { | |
148 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); |
|
147 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); | |
149 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); |
|
148 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); | |
150 | xyseries->setPen(seriesTheme.linePen); |
|
149 | xyseries->setPen(seriesTheme.linePen); | |
151 | } |
|
150 | } | |
152 | } |
|
151 | } | |
153 |
|
152 | |||
154 | update(); |
|
153 | update(); | |
155 | } |
|
154 | } | |
156 |
|
155 | |||
157 | QChart::ChartThemeId QChart::theme() |
|
156 | QChart::ChartThemeId QChart::theme() | |
158 | { |
|
157 | { | |
159 | return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme; |
|
158 | return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme; | |
160 | } |
|
159 | } | |
161 |
|
160 | |||
162 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
161 | void QChart::zoomInToRect(const QRectF& rectangle) | |
163 | { |
|
162 | { | |
164 | m_presenter->zoomInToRect(rectangle); |
|
163 | m_presenter->zoomInToRect(rectangle); | |
165 | } |
|
164 | } | |
166 |
|
165 | |||
167 | void QChart::zoomIn() |
|
166 | void QChart::zoomIn() | |
168 | { |
|
167 | { | |
169 | m_presenter->zoomIn(); |
|
168 | m_presenter->zoomIn(); | |
170 | } |
|
169 | } | |
171 |
|
170 | |||
172 | void QChart::zoomOut() |
|
171 | void QChart::zoomOut() | |
173 | { |
|
172 | { | |
174 | m_presenter->zoomOut(); |
|
173 | m_presenter->zoomOut(); | |
175 | } |
|
174 | } | |
176 |
|
175 | |||
177 | void QChart::zoomReset() |
|
176 | void QChart::zoomReset() | |
178 | { |
|
177 | { | |
179 | m_presenter->zoomReset(); |
|
178 | m_presenter->zoomReset(); | |
180 | } |
|
179 | } | |
181 |
|
180 | |||
182 | void QChart::setAxisX(const QChartAxis& axis) |
|
181 | void QChart::setAxisX(const QChartAxis& axis) | |
183 | { |
|
182 | { | |
184 | setAxis(m_axisXItem,axis); |
|
183 | setAxis(m_axisXItem,axis); | |
185 | } |
|
184 | } | |
186 | void QChart::setAxisY(const QChartAxis& axis) |
|
185 | void QChart::setAxisY(const QChartAxis& axis) | |
187 | { |
|
186 | { | |
188 | setAxis(m_axisYItem.at(0),axis); |
|
187 | setAxis(m_axisYItem.at(0),axis); | |
189 | } |
|
188 | } | |
190 |
|
189 | |||
191 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
|
190 | void QChart::setAxisY(const QList<QChartAxis>& axis) | |
192 | { |
|
191 | { | |
193 | //TODO not implemented |
|
192 | //TODO not implemented | |
194 | } |
|
193 | } | |
195 |
|
194 | |||
196 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) |
|
195 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) | |
197 | { |
|
196 | { | |
198 | item->setVisible(axis.isAxisVisible()); |
|
197 | item->setVisible(axis.isAxisVisible()); | |
199 | } |
|
198 | } | |
200 |
|
199 | |||
201 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
200 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
202 | { |
|
201 | { | |
203 |
|
202 | |||
204 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
203 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
205 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
204 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
206 |
|
205 | |||
207 | // recalculate title position |
|
206 | // recalculate title position | |
208 | if (m_titleItem) { |
|
207 | if (m_titleItem) { | |
209 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
208 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
210 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
209 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
211 | } |
|
210 | } | |
212 |
|
211 | |||
213 | //recalculate background gradient |
|
212 | //recalculate background gradient | |
214 | if (m_backgroundItem) { |
|
213 | if (m_backgroundItem) { | |
215 | m_backgroundItem->setRect(rect); |
|
214 | m_backgroundItem->setRect(rect); | |
216 | } |
|
215 | } | |
217 |
|
216 | |||
218 | QGraphicsWidget::resizeEvent(event); |
|
217 | QGraphicsWidget::resizeEvent(event); | |
219 | update(); |
|
218 | update(); | |
220 | } |
|
219 | } | |
221 |
|
220 | |||
222 |
|
221 | |||
223 |
|
222 | |||
224 | #include "moc_qchart.cpp" |
|
223 | #include "moc_qchart.cpp" | |
225 |
|
224 | |||
226 | QTCOMMERCIALCHART_END_NAMESPACE |
|
225 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,128 +1,132 | |||||
1 | !include( ../common.pri ) { |
|
1 | !include( ../common.pri ) { | |
2 | error( Couldn't find the common.pri file! ) |
|
2 | error( Couldn't find the common.pri file! ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TARGET = QtCommercialChart |
|
5 | TARGET = QtCommercialChart | |
6 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
6 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
7 | TEMPLATE = lib |
|
7 | TEMPLATE = lib | |
8 | QT += core \ |
|
8 | QT += core \ | |
9 | gui |
|
9 | gui | |
10 |
|
10 | |||
11 | CONFIG += debug_and_release |
|
11 | CONFIG += debug_and_release | |
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
13 |
|
13 | |||
14 | SOURCES += \ |
|
14 | SOURCES += \ | |
15 | barchart/barchartseries.cpp \ |
|
15 | barchart/barchartseries.cpp \ | |
16 | barchart/bargroup.cpp \ |
|
16 | barchart/bargroup.cpp \ | |
17 | barchart/bar.cpp \ |
|
17 | barchart/bar.cpp \ | |
18 | barchart/stackedbarchartseries.cpp \ |
|
18 | barchart/stackedbarchartseries.cpp \ | |
19 | barchart/stackedbargroup.cpp \ |
|
19 | barchart/stackedbargroup.cpp \ | |
20 | barchart/percentbarchartseries.cpp \ |
|
20 | barchart/percentbarchartseries.cpp \ | |
21 | barchart/percentbargroup.cpp \ |
|
21 | barchart/percentbargroup.cpp \ | |
22 | barchart/barlabel.cpp \ |
|
22 | barchart/barlabel.cpp \ | |
23 | xylinechart/qxychartseries.cpp \ |
|
23 | xylinechart/qxychartseries.cpp \ | |
24 | xylinechart/xylinechartitem.cpp \ |
|
24 | xylinechart/xylinechartitem.cpp \ | |
25 | xylinechart/linechartanimationitem.cpp \ |
|
25 | xylinechart/linechartanimationitem.cpp \ | |
|
26 | piechart/qpieseries.cpp \ | |||
|
27 | piechart/pieslice.cpp \ | |||
|
28 | piechart/piepresentation.cpp \ | |||
26 | plotdomain.cpp \ |
|
29 | plotdomain.cpp \ | |
27 | qscatterseries.cpp \ |
|
30 | qscatterseries.cpp \ | |
28 | qpieseries.cpp \ |
|
|||
29 | qchart.cpp \ |
|
31 | qchart.cpp \ | |
30 | axisitem.cpp \ |
|
32 | axisitem.cpp \ | |
31 | pieslice.cpp \ |
|
|||
32 | qchartview.cpp \ |
|
33 | qchartview.cpp \ | |
33 | qchartseries.cpp \ |
|
34 | qchartseries.cpp \ | |
34 | qchartaxis.cpp \ |
|
35 | qchartaxis.cpp \ | |
35 | charttheme.cpp \ |
|
36 | charttheme.cpp \ | |
36 | barchart/separator.cpp \ |
|
37 | barchart/separator.cpp \ | |
37 | barchart/bargroupbase.cpp \ |
|
38 | barchart/bargroupbase.cpp \ | |
38 | barchart/barchartseriesbase.cpp \ |
|
39 | barchart/barchartseriesbase.cpp \ | |
39 | chartdataset.cpp \ |
|
40 | chartdataset.cpp \ | |
40 | chartpresenter.cpp \ |
|
41 | chartpresenter.cpp \ | |
41 | domain.cpp |
|
42 | domain.cpp | |
42 |
|
43 | |||
|
44 | ||||
|
45 | ||||
43 | PRIVATE_HEADERS += \ |
|
46 | PRIVATE_HEADERS += \ | |
44 | xylinechart/xylinechartitem_p.h \ |
|
47 | xylinechart/xylinechartitem_p.h \ | |
45 | xylinechart/linechartanimationitem_p.h \ |
|
48 | xylinechart/linechartanimationitem_p.h \ | |
46 | barchart/barlabel_p.h \ |
|
49 | barchart/barlabel_p.h \ | |
47 | barchart/bar_p.h \ |
|
50 | barchart/bar_p.h \ | |
48 | barchart/separator_p.h \ |
|
51 | barchart/separator_p.h \ | |
|
52 | piechart/piepresentation.h \ | |||
|
53 | piechart/pieslice.h \ | |||
49 | plotdomain_p.h \ |
|
54 | plotdomain_p.h \ | |
50 | qscatterseries_p.h \ |
|
55 | qscatterseries_p.h \ | |
51 | qpieseries_p.h \ |
|
|||
52 | pieslice.h \ |
|
|||
53 | axisitem_p.h \ |
|
56 | axisitem_p.h \ | |
54 | chartitem_p.h \ |
|
57 | chartitem_p.h \ | |
55 | charttheme_p.h \ |
|
58 | charttheme_p.h \ | |
56 | chartdataset_p.h \ |
|
59 | chartdataset_p.h \ | |
57 | chartpresenter_p.h \ |
|
60 | chartpresenter_p.h \ | |
58 | domain_p.h |
|
61 | domain_p.h | |
59 |
|
62 | |||
60 | PUBLIC_HEADERS += \ |
|
63 | PUBLIC_HEADERS += \ | |
61 | qchartseries.h \ |
|
64 | qchartseries.h \ | |
62 | qscatterseries.h \ |
|
65 | qscatterseries.h \ | |
63 | qpieseries.h \ |
|
|||
64 | qchart.h \ |
|
66 | qchart.h \ | |
65 | qchartglobal.h \ |
|
67 | qchartglobal.h \ | |
66 | xylinechart/qxychartseries.h \ |
|
68 | xylinechart/qxychartseries.h \ | |
67 | barchart/barchartseries.h \ |
|
69 | barchart/barchartseries.h \ | |
68 | barchart/bargroup.h \ |
|
70 | barchart/bargroup.h \ | |
69 | barchart/stackedbarchartseries.h \ |
|
71 | barchart/stackedbarchartseries.h \ | |
70 | barchart/stackedbargroup.h \ |
|
72 | barchart/stackedbargroup.h \ | |
71 | barchart/percentbarchartseries.h \ |
|
73 | barchart/percentbarchartseries.h \ | |
72 | barchart/percentbargroup.h \ |
|
74 | barchart/percentbargroup.h \ | |
73 | barchart/barchartseriesbase.h \ |
|
75 | barchart/barchartseriesbase.h \ | |
74 | barchart/bargroupbase.h \ |
|
76 | barchart/bargroupbase.h \ | |
|
77 | piechart/qpieseries.h \ | |||
75 | qchartview.h \ |
|
78 | qchartview.h \ | |
76 | qchartaxis.h |
|
79 | qchartaxis.h | |
77 |
|
80 | |||
78 | HEADERS += $$PUBLIC_HEADERS |
|
81 | HEADERS += $$PUBLIC_HEADERS | |
79 | HEADERS += $$PRIVATE_HEADERS |
|
82 | HEADERS += $$PRIVATE_HEADERS | |
80 |
|
83 | |||
81 | INCLUDEPATH += xylinechart \ |
|
84 | INCLUDEPATH += xylinechart \ | |
82 | barchart \ |
|
85 | barchart \ | |
|
86 | piechart \ | |||
83 | . |
|
87 | . | |
84 |
|
88 | |||
85 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
89 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
86 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
90 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
87 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
91 | UI_DIR = $$CHART_BUILD_DIR/lib | |
88 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
92 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
89 |
|
93 | |||
90 |
|
94 | |||
91 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
95 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
92 |
|
96 | |||
93 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
97 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
94 | public_headers.files = $$PUBLIC_HEADERS |
|
98 | public_headers.files = $$PUBLIC_HEADERS | |
95 | target.path = $$[QT_INSTALL_LIBS] |
|
99 | target.path = $$[QT_INSTALL_LIBS] | |
96 | INSTALLS += target \ |
|
100 | INSTALLS += target \ | |
97 | public_headers |
|
101 | public_headers | |
98 |
|
102 | |||
99 |
|
103 | |||
100 | install_build_headers.name = bild_headers |
|
104 | install_build_headers.name = bild_headers | |
101 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
105 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
102 | install_build_headers.input = PUBLIC_HEADERS |
|
106 | install_build_headers.input = PUBLIC_HEADERS | |
103 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR |
|
107 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR | |
104 | install_build_headers.CONFIG += target_predeps no_link |
|
108 | install_build_headers.CONFIG += target_predeps no_link | |
105 | QMAKE_EXTRA_COMPILERS += install_build_headers |
|
109 | QMAKE_EXTRA_COMPILERS += install_build_headers | |
106 |
|
110 | |||
107 | chartversion.target = qchartversion_p.h |
|
111 | chartversion.target = qchartversion_p.h | |
108 | chartversion.commands = @echo "build_time" > $$chartversion.target; |
|
112 | chartversion.commands = @echo "build_time" > $$chartversion.target; | |
109 | chartversion.depends = $$HEADERS $$SOURCES |
|
113 | chartversion.depends = $$HEADERS $$SOURCES | |
110 | PRE_TARGETDEPS += qchartversion_p.h |
|
114 | PRE_TARGETDEPS += qchartversion_p.h | |
111 | QMAKE_CLEAN+= qchartversion_p.h |
|
115 | QMAKE_CLEAN+= qchartversion_p.h | |
112 | QMAKE_EXTRA_TARGETS += chartversion |
|
116 | QMAKE_EXTRA_TARGETS += chartversion | |
113 |
|
117 | |||
114 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
118 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
115 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
119 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
116 |
|
120 | |||
117 |
|
121 | |||
118 |
|
122 | |||
119 |
|
123 | |||
120 |
|
124 | |||
121 |
|
125 | |||
122 |
|
126 | |||
123 |
|
127 | |||
124 |
|
128 | |||
125 |
|
129 | |||
126 |
|
130 | |||
127 |
|
131 | |||
128 |
|
132 |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now