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