@@ -1,53 +1,53 | |||||
1 | #include "splinewidget.h" |
|
1 | #include "splinewidget.h" | |
2 | #include "qchartview.h" |
|
2 | #include "qchartview.h" | |
3 | #include "qsplineseries.h" |
|
3 | #include "qsplineseries.h" | |
4 |
#include "qline |
|
4 | #include "qlineseries.h" | |
5 | #include <QGridLayout> |
|
5 | #include <QGridLayout> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
7 | QTCOMMERCIALCHART_USE_NAMESPACE | |
8 |
|
8 | |||
9 | SplineWidget::SplineWidget(QWidget *parent) |
|
9 | SplineWidget::SplineWidget(QWidget *parent) | |
10 | : QWidget(parent) |
|
10 | : QWidget(parent) | |
11 | { |
|
11 | { | |
12 | //create QSplineSeries |
|
12 | //create QSplineSeries | |
13 | QSplineSeries* series = new QSplineSeries(this); |
|
13 | QSplineSeries* series = new QSplineSeries(this); | |
14 |
series->add |
|
14 | series->add(QPointF(150, 100)); | |
15 |
series->add |
|
15 | series->add(QPointF(200, 180)); | |
16 |
series->add |
|
16 | series->add(QPointF(240, 130)); | |
17 |
series->add |
|
17 | series->add(QPointF(270, 120)); | |
18 |
series->add |
|
18 | series->add(QPointF(310, 120)); | |
19 |
series->add |
|
19 | series->add(QPointF(420, 160)); | |
20 |
series->add |
|
20 | series->add(QPointF(535, 250)); | |
21 |
|
21 | |||
22 | series->calculateControlPoints(); |
|
22 | series->calculateControlPoints(); | |
23 |
|
23 | |||
24 |
QLine |
|
24 | // QLineSeries* lineSeries = new QLineSeries; | |
25 | for (int i = 0; i < series->count() - 1; i++) |
|
25 | // for (int i = 0; i < series->count() - 1; i++) | |
26 | { |
|
26 | // { | |
27 | lineSeries->add(series->at(i).x(), series->at(i).y()); |
|
27 | // lineSeries->add(series->at(i).x(), series->at(i).y()); | |
28 | lineSeries->add(series->controlPoint(2*i).x(), series->controlPoint(2*i).y()); |
|
28 | // lineSeries->add(series->controlPoint(2*i).x(), series->controlPoint(2*i).y()); | |
29 | lineSeries->add(series->controlPoint(2*i + 1).x(), series->controlPoint(2*i + 1).y()); |
|
29 | // lineSeries->add(series->controlPoint(2*i + 1).x(), series->controlPoint(2*i + 1).y()); | |
30 | } |
|
30 | // } | |
31 |
|
31 | |||
32 | // QLineChartSeries* lineSeries2 = new QLineChartSeries; |
|
32 | // QLineChartSeries* lineSeries2 = new QLineChartSeries; | |
33 | // lineSeries2->add(10, 50); |
|
33 | // lineSeries2->add(10, 50); | |
34 | // lineSeries2->add(30, 15); |
|
34 | // lineSeries2->add(30, 15); | |
35 | // lineSeries2->add(60, 40); |
|
35 | // lineSeries2->add(60, 40); | |
36 | // lineSeries2->add(90, 70); |
|
36 | // lineSeries2->add(90, 70); | |
37 | // lineSeries2->add(100, 20); |
|
37 | // lineSeries2->add(100, 20); | |
38 |
|
38 | |||
39 | //create chart view |
|
39 | //create chart view | |
40 | QChartView* chart = new QChartView; |
|
40 | QChartView* chart = new QChartView; | |
41 | chart->setMinimumSize(800,600); |
|
41 | chart->setMinimumSize(800,600); | |
42 | // chart->setGeometry(50, 50, 400, 300); |
|
42 | // chart->setGeometry(50, 50, 400, 300); | |
43 | chart->addSeries(series); |
|
43 | chart->addSeries(series); | |
44 |
|
44 | |||
45 | QGridLayout* mainLayout = new QGridLayout; |
|
45 | QGridLayout* mainLayout = new QGridLayout; | |
46 | mainLayout->addWidget(chart); |
|
46 | mainLayout->addWidget(chart); | |
47 | setLayout(mainLayout); |
|
47 | setLayout(mainLayout); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | SplineWidget::~SplineWidget() |
|
50 | SplineWidget::~SplineWidget() | |
51 | { |
|
51 | { | |
52 |
|
52 | |||
53 | } |
|
53 | } |
@@ -1,420 +1,420 | |||||
1 | #include "chartdataset_p.h" |
|
1 | #include "chartdataset_p.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | //series |
|
3 | //series | |
4 | #include "qlineseries.h" |
|
4 | #include "qlineseries.h" | |
5 | #include "qbarseries.h" |
|
5 | #include "qbarseries.h" | |
6 | #include "qstackedbarseries.h" |
|
6 | #include "qstackedbarseries.h" | |
7 | #include "qpercentbarseries.h" |
|
7 | #include "qpercentbarseries.h" | |
8 | #include "qpieseries.h" |
|
8 | #include "qpieseries.h" | |
9 | #include "qscatterseries.h" |
|
9 | #include "qscatterseries.h" | |
10 | #include "qsplineseries.h" |
|
10 | #include "qsplineseries.h" | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
14 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
15 | m_axisX(new QChartAxis(this)), |
|
15 | m_axisX(new QChartAxis(this)), | |
16 | m_axisY(new QChartAxis(this)), |
|
16 | m_axisY(new QChartAxis(this)), | |
17 | m_domainIndex(0), |
|
17 | m_domainIndex(0), | |
18 | m_axisXInitialized(false) |
|
18 | m_axisXInitialized(false) | |
19 | { |
|
19 | { | |
20 | } |
|
20 | } | |
21 |
|
21 | |||
22 | ChartDataSet::~ChartDataSet() |
|
22 | ChartDataSet::~ChartDataSet() | |
23 | { |
|
23 | { | |
24 | // TODO Auto-generated destructor stub |
|
24 | // TODO Auto-generated destructor stub | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | const Domain ChartDataSet::domain(QChartAxis *axisY) const |
|
27 | const Domain ChartDataSet::domain(QChartAxis *axisY) const | |
28 | { |
|
28 | { | |
29 | int i = m_domainMap.count(axisY); |
|
29 | int i = m_domainMap.count(axisY); | |
30 | if(i == 0){ |
|
30 | if(i == 0){ | |
31 | return Domain(); |
|
31 | return Domain(); | |
32 | } |
|
32 | } | |
33 | i = i - m_domainIndex -1; |
|
33 | i = i - m_domainIndex -1; | |
34 | return m_domainMap.values(axisY).at(i); |
|
34 | return m_domainMap.values(axisY).at(i); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) |
|
37 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |
38 | { |
|
38 | { | |
39 | // TODO: we should check the series not already added |
|
39 | // TODO: we should check the series not already added | |
40 |
|
40 | |||
41 | series->setParent(this); // take ownership |
|
41 | series->setParent(this); // take ownership | |
42 | clearDomains(); |
|
42 | clearDomains(); | |
43 |
|
43 | |||
44 | if(axisY==0) axisY = m_axisY; |
|
44 | if(axisY==0) axisY = m_axisY; | |
45 | axisY->setParent(this); // take ownership |
|
45 | axisY->setParent(this); // take ownership | |
46 |
|
46 | |||
47 | QList<QSeries*> seriesList = m_seriesMap.values(axisY); |
|
47 | QList<QSeries*> seriesList = m_seriesMap.values(axisY); | |
48 |
|
48 | |||
49 | QList<Domain> domainList = m_domainMap.values(axisY); |
|
49 | QList<Domain> domainList = m_domainMap.values(axisY); | |
50 |
|
50 | |||
51 | Q_ASSERT(domainList.size()<=1); |
|
51 | Q_ASSERT(domainList.size()<=1); | |
52 |
|
52 | |||
53 | Domain domain; |
|
53 | Domain domain; | |
54 |
|
54 | |||
55 | if(domainList.size()>0) domain = domainList.at(0); |
|
55 | if(domainList.size()>0) domain = domainList.at(0); | |
56 |
|
56 | |||
57 | switch(series->type()) |
|
57 | switch(series->type()) | |
58 | { |
|
58 | { | |
59 | case QSeries::SeriesTypeLine: { |
|
59 | case QSeries::SeriesTypeLine: { | |
60 |
|
60 | |||
61 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); |
|
61 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); | |
62 |
|
62 | |||
63 | for (int i = 0; i < xyseries->count(); i++) |
|
63 | for (int i = 0; i < xyseries->count(); i++) | |
64 | { |
|
64 | { | |
65 | qreal x = xyseries->x(i); |
|
65 | qreal x = xyseries->x(i); | |
66 | qreal y = xyseries->y(i); |
|
66 | qreal y = xyseries->y(i); | |
67 | domain.m_minX = qMin(domain.m_minX,x); |
|
67 | domain.m_minX = qMin(domain.m_minX,x); | |
68 | domain.m_minY = qMin(domain.m_minY,y); |
|
68 | domain.m_minY = qMin(domain.m_minY,y); | |
69 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
69 | domain.m_maxX = qMax(domain.m_maxX,x); | |
70 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
70 | domain.m_maxY = qMax(domain.m_maxY,y); | |
71 | } |
|
71 | } | |
72 | break; |
|
72 | break; | |
73 | } |
|
73 | } | |
74 | case QSeries::SeriesTypeBar: { |
|
74 | case QSeries::SeriesTypeBar: { | |
75 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
75 | qDebug() << "QChartSeries::SeriesTypeBar"; | |
76 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
76 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
77 | qreal x = barSeries->categoryCount(); |
|
77 | qreal x = barSeries->categoryCount(); | |
78 | qreal y = barSeries->max(); |
|
78 | qreal y = barSeries->max(); | |
79 | domain.m_minX = qMin(domain.m_minX,x); |
|
79 | domain.m_minX = qMin(domain.m_minX,x); | |
80 | domain.m_minY = qMin(domain.m_minY,y); |
|
80 | domain.m_minY = qMin(domain.m_minY,y); | |
81 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
81 | domain.m_maxX = qMax(domain.m_maxX,x); | |
82 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
82 | domain.m_maxY = qMax(domain.m_maxY,y); | |
83 | break; |
|
83 | break; | |
84 | } |
|
84 | } | |
85 | case QSeries::SeriesTypeStackedBar: { |
|
85 | case QSeries::SeriesTypeStackedBar: { | |
86 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
86 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; | |
87 |
|
87 | |||
88 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
88 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
89 | qreal x = stackedBarSeries->categoryCount(); |
|
89 | qreal x = stackedBarSeries->categoryCount(); | |
90 | qreal y = stackedBarSeries->maxCategorySum(); |
|
90 | qreal y = stackedBarSeries->maxCategorySum(); | |
91 | domain.m_minX = qMin(domain.m_minX,x); |
|
91 | domain.m_minX = qMin(domain.m_minX,x); | |
92 | domain.m_minY = qMin(domain.m_minY,y); |
|
92 | domain.m_minY = qMin(domain.m_minY,y); | |
93 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
93 | domain.m_maxX = qMax(domain.m_maxX,x); | |
94 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
94 | domain.m_maxY = qMax(domain.m_maxY,y); | |
95 | break; |
|
95 | break; | |
96 | } |
|
96 | } | |
97 | case QSeries::SeriesTypePercentBar: { |
|
97 | case QSeries::SeriesTypePercentBar: { | |
98 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
98 | qDebug() << "QChartSeries::SeriesTypePercentBar"; | |
99 |
|
99 | |||
100 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
100 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
101 | qreal x = percentBarSeries->categoryCount(); |
|
101 | qreal x = percentBarSeries->categoryCount(); | |
102 | domain.m_minX = qMin(domain.m_minX,x); |
|
102 | domain.m_minX = qMin(domain.m_minX,x); | |
103 | domain.m_minY = 0; |
|
103 | domain.m_minY = 0; | |
104 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
104 | domain.m_maxX = qMax(domain.m_maxX,x); | |
105 | domain.m_maxY = 100; |
|
105 | domain.m_maxY = 100; | |
106 | break; |
|
106 | break; | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | case QSeries::SeriesTypePie: { |
|
109 | case QSeries::SeriesTypePie: { | |
110 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
110 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
111 | // TODO: domain stuff |
|
111 | // TODO: domain stuff | |
112 | break; |
|
112 | break; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | case QSeries::SeriesTypeScatter: { |
|
115 | case QSeries::SeriesTypeScatter: { | |
116 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
116 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
117 | Q_ASSERT(scatterSeries); |
|
117 | Q_ASSERT(scatterSeries); | |
118 | foreach (QPointF point, scatterSeries->data()) { |
|
118 | foreach (QPointF point, scatterSeries->data()) { | |
119 | domain.m_minX = qMin(domain.m_minX, point.x()); |
|
119 | domain.m_minX = qMin(domain.m_minX, point.x()); | |
120 | domain.m_maxX = qMax(domain.m_maxX, point.x()); |
|
120 | domain.m_maxX = qMax(domain.m_maxX, point.x()); | |
121 | domain.m_minY = qMin(domain.m_minY, point.y()); |
|
121 | domain.m_minY = qMin(domain.m_minY, point.y()); | |
122 | domain.m_maxY = qMax(domain.m_maxY, point.y()); |
|
122 | domain.m_maxY = qMax(domain.m_maxY, point.y()); | |
123 | } |
|
123 | } | |
124 | break; |
|
124 | break; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 |
case Q |
|
127 | case QSeries::SeriesTypeSpline: { | |
128 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); |
|
128 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); | |
129 |
|
129 | |||
130 | for (int i = 0; i < splineSeries->count(); i++) |
|
130 | for (int i = 0; i < splineSeries->count(); i++) | |
131 | { |
|
131 | { | |
132 |
qreal x = splineSeries-> |
|
132 | qreal x = splineSeries->x(i); | |
133 |
qreal y = splineSeries-> |
|
133 | qreal y = splineSeries->y(i); | |
134 | domain.m_minX = qMin(domain.m_minX,x); |
|
134 | domain.m_minX = qMin(domain.m_minX,x); | |
135 | domain.m_minY = qMin(domain.m_minY,y); |
|
135 | domain.m_minY = qMin(domain.m_minY,y); | |
136 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
136 | domain.m_maxX = qMax(domain.m_maxX,x); | |
137 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
137 | domain.m_maxY = qMax(domain.m_maxY,y); | |
138 | } |
|
138 | } | |
139 | break; |
|
139 | break; | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | default: { |
|
142 | default: { | |
143 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
143 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
144 | return; |
|
144 | return; | |
145 | break; |
|
145 | break; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | if(!m_domainMap.contains(axisY)) |
|
150 | if(!m_domainMap.contains(axisY)) | |
151 | { |
|
151 | { | |
152 | emit axisAdded(axisY); |
|
152 | emit axisAdded(axisY); | |
153 | QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); |
|
153 | QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); | |
154 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
154 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | if(!m_axisXInitialized) |
|
157 | if(!m_axisXInitialized) | |
158 | { |
|
158 | { | |
159 | emit axisAdded(axisX()); |
|
159 | emit axisAdded(axisX()); | |
160 | QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); |
|
160 | QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); | |
161 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
161 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
162 | m_axisXInitialized=true; |
|
162 | m_axisXInitialized=true; | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | m_domainMap.replace(axisY,domain); |
|
165 | m_domainMap.replace(axisY,domain); | |
166 | m_seriesMap.insert(axisY,series); |
|
166 | m_seriesMap.insert(axisY,series); | |
167 | emit seriesAdded(series); |
|
167 | emit seriesAdded(series); | |
168 | setDomain(m_domainIndex,axisY); |
|
168 | setDomain(m_domainIndex,axisY); | |
169 |
|
169 | |||
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | void ChartDataSet::removeSeries(QSeries* series) |
|
172 | void ChartDataSet::removeSeries(QSeries* series) | |
173 | { |
|
173 | { | |
174 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
174 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
175 | foreach(QChartAxis* axis , keys) { |
|
175 | foreach(QChartAxis* axis , keys) { | |
176 | if(m_seriesMap.contains(axis,series)){ |
|
176 | if(m_seriesMap.contains(axis,series)){ | |
177 | emit seriesRemoved(series); |
|
177 | emit seriesRemoved(series); | |
178 | m_seriesMap.remove(axis,series); |
|
178 | m_seriesMap.remove(axis,series); | |
179 | //remove axis if no longer there |
|
179 | //remove axis if no longer there | |
180 | if(!m_seriesMap.contains(axis)){ |
|
180 | if(!m_seriesMap.contains(axis)){ | |
181 | emit axisRemoved(axis); |
|
181 | emit axisRemoved(axis); | |
182 | m_domainMap.remove(axis); |
|
182 | m_domainMap.remove(axis); | |
183 | if(axis != m_axisY) |
|
183 | if(axis != m_axisY) | |
184 | delete axis; |
|
184 | delete axis; | |
185 | } |
|
185 | } | |
186 | series->setParent(0); |
|
186 | series->setParent(0); | |
187 | break; |
|
187 | break; | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | void ChartDataSet::removeAllSeries() |
|
192 | void ChartDataSet::removeAllSeries() | |
193 | { |
|
193 | { | |
194 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
194 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
195 | foreach(QChartAxis* axis , keys) { |
|
195 | foreach(QChartAxis* axis , keys) { | |
196 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
196 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
197 | for(int i =0 ; i < seriesList.size();i++ ) |
|
197 | for(int i =0 ; i < seriesList.size();i++ ) | |
198 | { |
|
198 | { | |
199 | emit seriesRemoved(seriesList.at(i)); |
|
199 | emit seriesRemoved(seriesList.at(i)); | |
200 | delete(seriesList.at(i)); |
|
200 | delete(seriesList.at(i)); | |
201 | } |
|
201 | } | |
202 | m_seriesMap.remove(axis); |
|
202 | m_seriesMap.remove(axis); | |
203 | m_domainMap.remove(axis); |
|
203 | m_domainMap.remove(axis); | |
204 | emit axisRemoved(axis); |
|
204 | emit axisRemoved(axis); | |
205 | if(axis != m_axisY) delete axis; |
|
205 | if(axis != m_axisY) delete axis; | |
206 | } |
|
206 | } | |
207 | m_domainIndex=0; |
|
207 | m_domainIndex=0; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | bool ChartDataSet::nextDomain() |
|
210 | bool ChartDataSet::nextDomain() | |
211 | { |
|
211 | { | |
212 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
|
212 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; | |
213 |
|
213 | |||
214 | if (m_domainIndex < limit) { |
|
214 | if (m_domainIndex < limit) { | |
215 | m_domainIndex++; |
|
215 | m_domainIndex++; | |
216 | setDomain(m_domainIndex); |
|
216 | setDomain(m_domainIndex); | |
217 | return true; |
|
217 | return true; | |
218 | } |
|
218 | } | |
219 | else { |
|
219 | else { | |
220 | return false; |
|
220 | return false; | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | bool ChartDataSet::previousDomain() |
|
224 | bool ChartDataSet::previousDomain() | |
225 | { |
|
225 | { | |
226 | if (m_domainIndex > 0) { |
|
226 | if (m_domainIndex > 0) { | |
227 | m_domainIndex--; |
|
227 | m_domainIndex--; | |
228 | setDomain(m_domainIndex); |
|
228 | setDomain(m_domainIndex); | |
229 | return true; |
|
229 | return true; | |
230 | } |
|
230 | } | |
231 | else { |
|
231 | else { | |
232 | return false; |
|
232 | return false; | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void ChartDataSet::setDomain(int index) |
|
236 | void ChartDataSet::setDomain(int index) | |
237 | { |
|
237 | { | |
238 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
238 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
239 |
|
239 | |||
240 | if(domainList.count()==0) return; |
|
240 | if(domainList.count()==0) return; | |
241 |
|
241 | |||
242 | Domain domain; |
|
242 | Domain domain; | |
243 |
|
243 | |||
244 | foreach (QChartAxis* axis , domainList) { |
|
244 | foreach (QChartAxis* axis , domainList) { | |
245 | int i = m_domainMap.count(axis) - index -1; |
|
245 | int i = m_domainMap.count(axis) - index -1; | |
246 | Q_ASSERT(i>=0); |
|
246 | Q_ASSERT(i>=0); | |
247 | domain = m_domainMap.values(axis).at(i); |
|
247 | domain = m_domainMap.values(axis).at(i); | |
248 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
248 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
249 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
249 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
250 | foreach(QSeries* series, seriesList) { |
|
250 | foreach(QSeries* series, seriesList) { | |
251 | emit seriesDomainChanged(series,domain); |
|
251 | emit seriesDomainChanged(series,domain); | |
252 | } |
|
252 | } | |
253 | axis->updateRange(domain.m_minY,domain.m_maxY); |
|
253 | axis->updateRange(domain.m_minY,domain.m_maxY); | |
254 | emit axisRangeChanged(axis,labels); |
|
254 | emit axisRangeChanged(axis,labels); | |
255 |
|
255 | |||
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
258 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
259 | axisX()->updateRange(domain.m_minX,domain.m_maxY); |
|
259 | axisX()->updateRange(domain.m_minX,domain.m_maxY); | |
260 | emit axisRangeChanged(axisX(),labels); |
|
260 | emit axisRangeChanged(axisX(),labels); | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | void ChartDataSet::setDomain(int index,QChartAxis* axis) |
|
263 | void ChartDataSet::setDomain(int index,QChartAxis* axis) | |
264 | { |
|
264 | { | |
265 | int i = m_domainMap.count(axis) - index -1; |
|
265 | int i = m_domainMap.count(axis) - index -1; | |
266 | Q_ASSERT(i>=0); |
|
266 | Q_ASSERT(i>=0); | |
267 | Domain domain = m_domainMap.values(axis).at(i); |
|
267 | Domain domain = m_domainMap.values(axis).at(i); | |
268 | { |
|
268 | { | |
269 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
269 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
270 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
270 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
271 | foreach(QSeries* series, seriesList) { |
|
271 | foreach(QSeries* series, seriesList) { | |
272 | emit seriesDomainChanged(series,domain); |
|
272 | emit seriesDomainChanged(series,domain); | |
273 | } |
|
273 | } | |
274 | axis->updateRange(domain.m_minY,domain.m_maxY); |
|
274 | axis->updateRange(domain.m_minY,domain.m_maxY); | |
275 | emit axisRangeChanged(axis,labels); |
|
275 | emit axisRangeChanged(axis,labels); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
278 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
279 | axisX()->updateRange(domain.m_minX,domain.m_maxY); |
|
279 | axisX()->updateRange(domain.m_minX,domain.m_maxY); | |
280 | emit axisRangeChanged(axisX(),labels); |
|
280 | emit axisRangeChanged(axisX(),labels); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 |
|
283 | |||
284 | void ChartDataSet::clearDomains(int toIndex) |
|
284 | void ChartDataSet::clearDomains(int toIndex) | |
285 | { |
|
285 | { | |
286 | Q_ASSERT(toIndex>=0); |
|
286 | Q_ASSERT(toIndex>=0); | |
287 |
|
287 | |||
288 | m_domainIndex = toIndex; |
|
288 | m_domainIndex = toIndex; | |
289 |
|
289 | |||
290 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); |
|
290 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); | |
291 |
|
291 | |||
292 | foreach (QChartAxis* key , keys) |
|
292 | foreach (QChartAxis* key , keys) | |
293 | { |
|
293 | { | |
294 | QList<Domain> domains = m_domainMap.values(key); |
|
294 | QList<Domain> domains = m_domainMap.values(key); | |
295 | m_domainMap.remove(key); |
|
295 | m_domainMap.remove(key); | |
296 | int i = domains.size() - toIndex - 1; |
|
296 | int i = domains.size() - toIndex - 1; | |
297 | while(i--){ |
|
297 | while(i--){ | |
298 | domains.removeFirst(); |
|
298 | domains.removeFirst(); | |
299 | } |
|
299 | } | |
300 | for(int j=domains.size()-1; j>=0 ;j--) |
|
300 | for(int j=domains.size()-1; j>=0 ;j--) | |
301 | m_domainMap.insert(key,domains.at(j)); |
|
301 | m_domainMap.insert(key,domains.at(j)); | |
302 | } |
|
302 | } | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) |
|
305 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) | |
306 | { |
|
306 | { | |
307 | Q_ASSERT(rect.isValid()); |
|
307 | Q_ASSERT(rect.isValid()); | |
308 | Q_ASSERT(viewport.isValid()); |
|
308 | Q_ASSERT(viewport.isValid()); | |
309 |
|
309 | |||
310 | clearDomains(m_domainIndex); |
|
310 | clearDomains(m_domainIndex); | |
311 |
|
311 | |||
312 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
312 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
313 |
|
313 | |||
314 | Domain domain; |
|
314 | Domain domain; | |
315 |
|
315 | |||
316 | foreach (QChartAxis* axis , domainList){ |
|
316 | foreach (QChartAxis* axis , domainList){ | |
317 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); |
|
317 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); | |
318 | m_domainMap.insert(axis,domain); |
|
318 | m_domainMap.insert(axis,domain); | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | setDomain(++m_domainIndex); |
|
321 | setDomain(++m_domainIndex); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
324 | QChartAxis* ChartDataSet::axisY(QSeries* series) const | |
325 | { |
|
325 | { | |
326 | if(series == 0) return m_axisY; |
|
326 | if(series == 0) return m_axisY; | |
327 |
|
327 | |||
328 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
328 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
329 |
|
329 | |||
330 | foreach(QChartAxis* axis , keys) { |
|
330 | foreach(QChartAxis* axis , keys) { | |
331 | if(m_seriesMap.contains(axis,series)){ |
|
331 | if(m_seriesMap.contains(axis,series)){ | |
332 | return axis; |
|
332 | return axis; | |
333 | } |
|
333 | } | |
334 | } |
|
334 | } | |
335 | return 0; |
|
335 | return 0; | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) |
|
338 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) | |
339 | { |
|
339 | { | |
340 | Q_ASSERT(max>=min); |
|
340 | Q_ASSERT(max>=min); | |
341 |
|
341 | |||
342 | QStringList labels; |
|
342 | QStringList labels; | |
343 |
|
343 | |||
344 | int ticks = axis->ticksCount()-1; |
|
344 | int ticks = axis->ticksCount()-1; | |
345 |
|
345 | |||
346 | for(int i=0; i<= ticks; i++){ |
|
346 | for(int i=0; i<= ticks; i++){ | |
347 | qreal value = min + (i * (max - min)/ ticks); |
|
347 | qreal value = min + (i * (max - min)/ ticks); | |
348 | QString label = axis->axisTickLabel(value); |
|
348 | QString label = axis->axisTickLabel(value); | |
349 | if(label.isEmpty()){ |
|
349 | if(label.isEmpty()){ | |
350 | labels << QString::number(value); |
|
350 | labels << QString::number(value); | |
351 | }else{ |
|
351 | }else{ | |
352 | labels << label; |
|
352 | labels << label; | |
353 | } |
|
353 | } | |
354 | } |
|
354 | } | |
355 | return labels; |
|
355 | return labels; | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 |
|
358 | |||
359 | void ChartDataSet::handleRangeChanged(QChartAxis* axis) |
|
359 | void ChartDataSet::handleRangeChanged(QChartAxis* axis) | |
360 | { |
|
360 | { | |
361 | qreal min = axis->min(); |
|
361 | qreal min = axis->min(); | |
362 | qreal max = axis->max(); |
|
362 | qreal max = axis->max(); | |
363 |
|
363 | |||
364 | if(axis==axisX()) { |
|
364 | if(axis==axisX()) { | |
365 |
|
365 | |||
366 | m_domainIndex=0; |
|
366 | m_domainIndex=0; | |
367 |
|
367 | |||
368 | clearDomains(m_domainIndex); |
|
368 | clearDomains(m_domainIndex); | |
369 |
|
369 | |||
370 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
370 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
371 |
|
371 | |||
372 | foreach (QChartAxis* axis , domainList) { |
|
372 | foreach (QChartAxis* axis , domainList) { | |
373 |
|
373 | |||
374 | Q_ASSERT(m_domainMap.values(axis).size()==1); |
|
374 | Q_ASSERT(m_domainMap.values(axis).size()==1); | |
375 |
|
375 | |||
376 | Domain domain = m_domainMap.value(axis); |
|
376 | Domain domain = m_domainMap.value(axis); | |
377 | domain.m_minX=min; |
|
377 | domain.m_minX=min; | |
378 | domain.m_maxX=max; |
|
378 | domain.m_maxX=max; | |
379 | m_domainMap.replace(axis,domain); |
|
379 | m_domainMap.replace(axis,domain); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | setDomain(m_domainIndex); |
|
382 | setDomain(m_domainIndex); | |
383 |
|
383 | |||
384 | } |
|
384 | } | |
385 | else { |
|
385 | else { | |
386 |
|
386 | |||
387 | QList<Domain> domains = m_domainMap.values(axis); |
|
387 | QList<Domain> domains = m_domainMap.values(axis); | |
388 | m_domainMap.remove(axis); |
|
388 | m_domainMap.remove(axis); | |
389 |
|
389 | |||
390 | for(int i=0;i<domains.size();i++) |
|
390 | for(int i=0;i<domains.size();i++) | |
391 | { |
|
391 | { | |
392 | domains[i].m_minY=min; |
|
392 | domains[i].m_minY=min; | |
393 | domains[i].m_maxY=max; |
|
393 | domains[i].m_maxY=max; | |
394 | } |
|
394 | } | |
395 |
|
395 | |||
396 | for(int j=domains.size()-1; j>=0;j--) |
|
396 | for(int j=domains.size()-1; j>=0;j--) | |
397 | m_domainMap.insert(axis,domains.at(j)); |
|
397 | m_domainMap.insert(axis,domains.at(j)); | |
398 |
|
398 | |||
399 | setDomain(m_domainIndex,axis); |
|
399 | setDomain(m_domainIndex,axis); | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 |
|
402 | |||
403 | } |
|
403 | } | |
404 |
|
404 | |||
405 | void ChartDataSet::handleTickChanged(QChartAxis* axis) |
|
405 | void ChartDataSet::handleTickChanged(QChartAxis* axis) | |
406 | { |
|
406 | { | |
407 | if(axis==axisX()){ |
|
407 | if(axis==axisX()){ | |
408 | Domain domain = m_domainMap.value(axisY()); |
|
408 | Domain domain = m_domainMap.value(axisY()); | |
409 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); |
|
409 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); | |
410 | emit axisRangeChanged(axis,labels); |
|
410 | emit axisRangeChanged(axis,labels); | |
411 | }else{ |
|
411 | }else{ | |
412 | Domain domain = m_domainMap.value(axis); |
|
412 | Domain domain = m_domainMap.value(axis); | |
413 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
413 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
414 | emit axisRangeChanged(axis,labels); |
|
414 | emit axisRangeChanged(axis,labels); | |
415 | } |
|
415 | } | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | #include "moc_chartdataset_p.cpp" |
|
418 | #include "moc_chartdataset_p.cpp" | |
419 |
|
419 | |||
420 | QTCOMMERCIALCHART_END_NAMESPACE |
|
420 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,298 +1,298 | |||||
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 "qbarseries.h" |
|
7 | #include "qbarseries.h" | |
8 | #include "qstackedbarseries.h" |
|
8 | #include "qstackedbarseries.h" | |
9 | #include "qpercentbarseries.h" |
|
9 | #include "qpercentbarseries.h" | |
10 | #include "qlineseries.h" |
|
10 | #include "qlineseries.h" | |
11 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
12 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | #include "qsplineseries.h" |
|
13 | #include "qsplineseries.h" | |
14 | //items |
|
14 | //items | |
15 | #include "axisitem_p.h" |
|
15 | #include "axisitem_p.h" | |
16 | #include "axisanimationitem_p.h" |
|
16 | #include "axisanimationitem_p.h" | |
17 | #include "barpresenter_p.h" |
|
17 | #include "barpresenter_p.h" | |
18 | #include "stackedbarpresenter_p.h" |
|
18 | #include "stackedbarpresenter_p.h" | |
19 | #include "percentbarpresenter_p.h" |
|
19 | #include "percentbarpresenter_p.h" | |
20 | #include "linechartitem_p.h" |
|
20 | #include "linechartitem_p.h" | |
21 | #include "linechartanimationitem_p.h" |
|
21 | #include "linechartanimationitem_p.h" | |
22 | #include "piepresenter_p.h" |
|
22 | #include "piepresenter_p.h" | |
23 | #include "scatterpresenter_p.h" |
|
23 | #include "scatterpresenter_p.h" | |
24 | #include "splinepresenter_p.h" |
|
24 | #include "splinepresenter_p.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
28 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
29 | m_chart(chart), |
|
29 | m_chart(chart), | |
30 | m_dataset(dataset), |
|
30 | m_dataset(dataset), | |
31 | m_chartTheme(0), |
|
31 | m_chartTheme(0), | |
32 | m_marginSize(0), |
|
32 | m_marginSize(0), | |
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
34 | m_options(0) |
|
34 | m_options(0) | |
35 | { |
|
35 | { | |
36 | createConnections(); |
|
36 | createConnections(); | |
37 | setChartTheme(QChart::ChartThemeDefault); |
|
37 | setChartTheme(QChart::ChartThemeDefault); | |
38 |
|
38 | |||
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | ChartPresenter::~ChartPresenter() |
|
41 | ChartPresenter::~ChartPresenter() | |
42 | { |
|
42 | { | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | void ChartPresenter::createConnections() |
|
45 | void ChartPresenter::createConnections() | |
46 | { |
|
46 | { | |
47 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
47 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
48 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*))); |
|
48 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*))); | |
49 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
49 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
50 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); |
|
50 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); | |
51 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
51 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
52 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&))); |
|
52 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&))); | |
53 | QObject::connect(m_dataset,SIGNAL(axisRangeChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisRangeChanged(QChartAxis*,const QStringList&))); |
|
53 | QObject::connect(m_dataset,SIGNAL(axisRangeChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisRangeChanged(QChartAxis*,const QStringList&))); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | QRectF ChartPresenter::geometry() const |
|
57 | QRectF ChartPresenter::geometry() const | |
58 | { |
|
58 | { | |
59 | return m_rect; |
|
59 | return m_rect; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void ChartPresenter::handleGeometryChanged() |
|
62 | void ChartPresenter::handleGeometryChanged() | |
63 | { |
|
63 | { | |
64 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
64 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
65 |
|
|
65 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
66 | Q_ASSERT(m_rect.isValid()); |
|
66 | Q_ASSERT(m_rect.isValid()); | |
67 | emit geometryChanged(m_rect); |
|
67 | emit geometryChanged(m_rect); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | int ChartPresenter::margin() const |
|
70 | int ChartPresenter::margin() const | |
71 | { |
|
71 | { | |
72 | return m_marginSize; |
|
72 | return m_marginSize; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void ChartPresenter::setMargin(int margin) |
|
75 | void ChartPresenter::setMargin(int margin) | |
76 | { |
|
76 | { | |
77 | m_marginSize = margin; |
|
77 | m_marginSize = margin; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) |
|
80 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) | |
81 | { |
|
81 | { | |
82 |
|
82 | |||
83 | AxisItem* item ; |
|
83 | AxisItem* item ; | |
84 |
|
84 | |||
85 | if(!m_options.testFlag(QChart::GridAxisAnimations)) |
|
85 | if(!m_options.testFlag(QChart::GridAxisAnimations)) | |
86 | { |
|
86 | { | |
87 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
87 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
88 | }else{ |
|
88 | }else{ | |
89 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
89 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
92 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
93 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); |
|
93 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); | |
94 |
|
94 | |||
95 | item->handleAxisUpdate(axis); |
|
95 | item->handleAxisUpdate(axis); | |
96 | item->handleGeometryChanged(m_rect); |
|
96 | item->handleGeometryChanged(m_rect); | |
97 | m_chartTheme->decorate(axis,item); |
|
97 | m_chartTheme->decorate(axis,item); | |
98 | m_axisItems.insert(axis,item); |
|
98 | m_axisItems.insert(axis,item); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
101 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
102 | { |
|
102 | { | |
103 | AxisItem* item = m_axisItems.take(axis); |
|
103 | AxisItem* item = m_axisItems.take(axis); | |
104 | Q_ASSERT(item); |
|
104 | Q_ASSERT(item); | |
105 | delete item; |
|
105 | delete item; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 |
|
108 | |||
109 | void ChartPresenter::handleSeriesAdded(QSeries* series) |
|
109 | void ChartPresenter::handleSeriesAdded(QSeries* series) | |
110 | { |
|
110 | { | |
111 | switch(series->type()) |
|
111 | switch(series->type()) | |
112 | { |
|
112 | { | |
113 | case QSeries::SeriesTypeLine: { |
|
113 | case QSeries::SeriesTypeLine: { | |
114 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
114 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
115 | LineChartItem* item; |
|
115 | LineChartItem* item; | |
116 | if(m_options.testFlag(QChart::SeriesAnimations)){ |
|
116 | if(m_options.testFlag(QChart::SeriesAnimations)){ | |
117 | item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
117 | item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
118 | }else{ |
|
118 | }else{ | |
119 | item = new LineChartItem(this,lineSeries,m_chart); |
|
119 | item = new LineChartItem(this,lineSeries,m_chart); | |
120 | } |
|
120 | } | |
121 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
121 | m_chartTheme->decorate(item,lineSeries,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(lineSeries,SIGNAL(pointReplaced(int)),item,SLOT(handlePointReplaced(int))); |
|
123 | QObject::connect(lineSeries,SIGNAL(pointReplaced(int)),item,SLOT(handlePointReplaced(int))); | |
124 | QObject::connect(lineSeries,SIGNAL(pointAdded(int)),item,SLOT(handlePointAdded(int))); |
|
124 | QObject::connect(lineSeries,SIGNAL(pointAdded(int)),item,SLOT(handlePointAdded(int))); | |
125 | QObject::connect(lineSeries,SIGNAL(pointRemoved(int)),item,SLOT(handlePointRemoved(int))); |
|
125 | QObject::connect(lineSeries,SIGNAL(pointRemoved(int)),item,SLOT(handlePointRemoved(int))); | |
126 | QObject::connect(lineSeries,SIGNAL(updated()),item,SLOT(handleUpdated())); |
|
126 | QObject::connect(lineSeries,SIGNAL(updated()),item,SLOT(handleUpdated())); | |
127 | m_chartItems.insert(series,item); |
|
127 | m_chartItems.insert(series,item); | |
128 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
128 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
129 | item->handleUpdated(); |
|
129 | item->handleUpdated(); | |
130 | break; |
|
130 | break; | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | case QSeries::SeriesTypeBar: { |
|
133 | case QSeries::SeriesTypeBar: { | |
134 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
134 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
135 | BarPresenter* item = new BarPresenter(barSeries,m_chart); |
|
135 | BarPresenter* item = new BarPresenter(barSeries,m_chart); | |
136 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
136 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
137 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
137 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
138 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
138 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
139 | m_chartItems.insert(series,item); |
|
139 | m_chartItems.insert(series,item); | |
140 | // m_axisXItem->setVisible(false); |
|
140 | // m_axisXItem->setVisible(false); | |
141 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
141 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
142 | break; |
|
142 | break; | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | case QSeries::SeriesTypeStackedBar: { |
|
145 | case QSeries::SeriesTypeStackedBar: { | |
146 |
|
146 | |||
147 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
147 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
148 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
148 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); | |
149 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
149 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
150 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
150 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
151 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
151 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
152 | m_chartItems.insert(series,item); |
|
152 | m_chartItems.insert(series,item); | |
153 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
153 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
154 | break; |
|
154 | break; | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | case QSeries::SeriesTypePercentBar: { |
|
157 | case QSeries::SeriesTypePercentBar: { | |
158 |
|
158 | |||
159 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
159 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
160 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); |
|
160 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); | |
161 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
161 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
162 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
162 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
163 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
163 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
164 | m_chartItems.insert(series,item); |
|
164 | m_chartItems.insert(series,item); | |
165 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
165 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
166 | break; |
|
166 | break; | |
167 | } |
|
167 | } | |
168 | case QSeries::SeriesTypeScatter: { |
|
168 | case QSeries::SeriesTypeScatter: { | |
169 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
169 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
170 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
170 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); | |
171 | QObject::connect(scatterPresenter, SIGNAL(clicked(QPointF)), |
|
171 | QObject::connect(scatterPresenter, SIGNAL(clicked(QPointF)), | |
172 | scatterSeries, SIGNAL(clicked(QPointF))); |
|
172 | scatterSeries, SIGNAL(clicked(QPointF))); | |
173 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
173 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
174 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
174 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
175 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
175 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); | |
176 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
176 | m_chartItems.insert(scatterSeries, scatterPresenter); | |
177 | if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect); |
|
177 | if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect); | |
178 | break; |
|
178 | break; | |
179 | } |
|
179 | } | |
180 | case QSeries::SeriesTypePie: { |
|
180 | case QSeries::SeriesTypePie: { | |
181 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
181 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
182 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
182 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
183 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
183 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
184 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
184 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
185 |
|
185 | |||
186 | // Hide all from background when there is only piechart |
|
186 | // Hide all from background when there is only piechart | |
187 | // TODO: refactor this ugly code... should be one setting for this |
|
187 | // TODO: refactor this ugly code... should be one setting for this | |
188 | if (m_chartItems.count() == 0) { |
|
188 | if (m_chartItems.count() == 0) { | |
189 | m_chart->axisX()->setAxisVisible(false); |
|
189 | m_chart->axisX()->setAxisVisible(false); | |
190 | m_chart->axisY()->setAxisVisible(false); |
|
190 | m_chart->axisY()->setAxisVisible(false); | |
191 | m_chart->axisX()->setGridVisible(false); |
|
191 | m_chart->axisX()->setGridVisible(false); | |
192 | m_chart->axisY()->setGridVisible(false); |
|
192 | m_chart->axisY()->setGridVisible(false); | |
193 | m_chart->axisX()->setLabelsVisible(false); |
|
193 | m_chart->axisX()->setLabelsVisible(false); | |
194 | m_chart->axisY()->setLabelsVisible(false); |
|
194 | m_chart->axisY()->setLabelsVisible(false); | |
195 | m_chart->axisX()->setShadesVisible(false); |
|
195 | m_chart->axisX()->setShadesVisible(false); | |
196 | m_chart->axisY()->setShadesVisible(false); |
|
196 | m_chart->axisY()->setShadesVisible(false); | |
197 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
197 | m_chart->setChartBackgroundBrush(Qt::transparent); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | m_chartItems.insert(series, pie); |
|
200 | m_chartItems.insert(series, pie); | |
201 | pie->handleGeometryChanged(m_rect); |
|
201 | pie->handleGeometryChanged(m_rect); | |
202 | break; |
|
202 | break; | |
203 | } |
|
203 | } | |
204 |
case Q |
|
204 | case QSeries::SeriesTypeSpline: { | |
205 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series); |
|
205 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series); | |
206 | SplinePresenter* splinePresenter = new SplinePresenter(splineSeries, m_chart); |
|
206 | SplinePresenter* splinePresenter = new SplinePresenter(splineSeries, m_chart); | |
207 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), splinePresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
207 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), splinePresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
208 | m_chartTheme->decorate(splinePresenter, splineSeries, m_chartItems.count()); |
|
208 | m_chartTheme->decorate(splinePresenter, splineSeries, m_chartItems.count()); | |
209 | m_chartItems.insert(splineSeries, splinePresenter); |
|
209 | m_chartItems.insert(splineSeries, splinePresenter); | |
210 | break; |
|
210 | break; | |
211 | } |
|
211 | } | |
212 | default: { |
|
212 | default: { | |
213 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
213 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
214 | break; |
|
214 | break; | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | } |
|
217 | } | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
220 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
221 | { |
|
221 | { | |
222 | ChartItem* item = m_chartItems.take(series); |
|
222 | ChartItem* item = m_chartItems.take(series); | |
223 | delete item; |
|
223 | delete item; | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain) |
|
226 | void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain) | |
227 | { |
|
227 | { | |
228 | m_chartItems.value(series)->handleDomainChanged(domain); |
|
228 | m_chartItems.value(series)->handleDomainChanged(domain); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | void ChartPresenter::handleAxisRangeChanged(QChartAxis* axis,const QStringList& labels) |
|
231 | void ChartPresenter::handleAxisRangeChanged(QChartAxis* axis,const QStringList& labels) | |
232 | { |
|
232 | { | |
233 | m_axisItems.value(axis)->handleRangeChanged(axis,labels); |
|
233 | m_axisItems.value(axis)->handleRangeChanged(axis,labels); | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
236 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
237 | { |
|
237 | { | |
238 | delete m_chartTheme; |
|
238 | delete m_chartTheme; | |
239 |
|
239 | |||
240 | m_chartTheme = ChartTheme::createTheme(theme); |
|
240 | m_chartTheme = ChartTheme::createTheme(theme); | |
241 |
|
241 | |||
242 | m_chartTheme->decorate(m_chart); |
|
242 | m_chartTheme->decorate(m_chart); | |
243 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); |
|
243 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); | |
244 |
|
244 | |||
245 | int index=0; |
|
245 | int index=0; | |
246 | while (i.hasNext()) { |
|
246 | while (i.hasNext()) { | |
247 | i.next(); |
|
247 | i.next(); | |
248 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
248 | m_chartTheme->decorate(i.value(),i.key(),index); | |
249 | index++; |
|
249 | index++; | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); |
|
252 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); | |
253 | while (j.hasNext()) { |
|
253 | while (j.hasNext()) { | |
254 | j.next(); |
|
254 | j.next(); | |
255 | m_chartTheme->decorate(j.key(),j.value()); |
|
255 | m_chartTheme->decorate(j.key(),j.value()); | |
256 | } |
|
256 | } | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
259 | QChart::ChartTheme ChartPresenter::chartTheme() | |
260 | { |
|
260 | { | |
261 | return m_chartTheme->id(); |
|
261 | return m_chartTheme->id(); | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
264 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
265 | { |
|
265 | { | |
266 | if(m_options!=options) { |
|
266 | if(m_options!=options) { | |
267 |
|
267 | |||
268 | m_options=options; |
|
268 | m_options=options; | |
269 |
|
269 | |||
270 | //recreate elements |
|
270 | //recreate elements | |
271 |
|
271 | |||
272 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
272 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
273 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
273 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
274 |
|
274 | |||
275 | foreach(QChartAxis* axis, axisList) { |
|
275 | foreach(QChartAxis* axis, axisList) { | |
276 | handleAxisRemoved(axis); |
|
276 | handleAxisRemoved(axis); | |
277 | handleAxisAdded(axis); |
|
277 | handleAxisAdded(axis); | |
278 | } |
|
278 | } | |
279 | foreach(QSeries* series, seriesList) { |
|
279 | foreach(QSeries* series, seriesList) { | |
280 | handleSeriesRemoved(series); |
|
280 | handleSeriesRemoved(series); | |
281 | handleSeriesAdded(series); |
|
281 | handleSeriesAdded(series); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | //now reintialize view data |
|
284 | //now reintialize view data | |
285 | //TODO: make it more nice |
|
285 | //TODO: make it more nice | |
286 | m_dataset->setDomain(m_dataset->domainIndex()); |
|
286 | m_dataset->setDomain(m_dataset->domainIndex()); | |
287 | } |
|
287 | } | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
290 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
291 | { |
|
291 | { | |
292 | return m_options; |
|
292 | return m_options; | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 |
|
295 | |||
296 | #include "moc_chartpresenter_p.cpp" |
|
296 | #include "moc_chartpresenter_p.cpp" | |
297 |
|
297 | |||
298 | QTCOMMERCIALCHART_END_NAMESPACE |
|
298 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,289 +1,289 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
4 | #include <QTime> |
|
4 | #include <QTime> | |
5 |
|
5 | |||
6 | //series |
|
6 | //series | |
7 | #include "qbarset.h" |
|
7 | #include "qbarset.h" | |
8 | #include "qbarseries.h" |
|
8 | #include "qbarseries.h" | |
9 | #include "qstackedbarseries.h" |
|
9 | #include "qstackedbarseries.h" | |
10 | #include "qpercentbarseries.h" |
|
10 | #include "qpercentbarseries.h" | |
11 | #include "qlineseries.h" |
|
11 | #include "qlineseries.h" | |
12 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | #include "qpieseries.h" |
|
13 | #include "qpieseries.h" | |
14 | #include "qpieslice.h" |
|
14 | #include "qpieslice.h" | |
15 | #include "qsplineseries.h" |
|
15 | #include "qsplineseries.h" | |
16 |
|
16 | |||
17 | //items |
|
17 | //items | |
18 | #include "axisitem_p.h" |
|
18 | #include "axisitem_p.h" | |
19 | #include "barpresenter_p.h" |
|
19 | #include "barpresenter_p.h" | |
20 | #include "stackedbarpresenter_p.h" |
|
20 | #include "stackedbarpresenter_p.h" | |
21 | #include "percentbarpresenter_p.h" |
|
21 | #include "percentbarpresenter_p.h" | |
22 | #include "linechartitem_p.h" |
|
22 | #include "linechartitem_p.h" | |
23 | #include "scatterpresenter_p.h" |
|
23 | #include "scatterpresenter_p.h" | |
24 | #include "piepresenter.h" |
|
24 | #include "piepresenter_p.h" | |
25 | #include "splinepresenter_p.h" |
|
25 | #include "splinepresenter_p.h" | |
26 |
|
26 | |||
27 | //themes |
|
27 | //themes | |
28 | #include "chartthemevanilla_p.h" |
|
28 | #include "chartthemevanilla_p.h" | |
29 | #include "chartthemeicy_p.h" |
|
29 | #include "chartthemeicy_p.h" | |
30 | #include "chartthemegrayscale_p.h" |
|
30 | #include "chartthemegrayscale_p.h" | |
31 | #include "chartthemescientific_p.h" |
|
31 | #include "chartthemescientific_p.h" | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /* TODO |
|
36 | /* TODO | |
37 | case QChart::ChartThemeUnnamed1: |
|
37 | case QChart::ChartThemeUnnamed1: | |
38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); | |
39 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
|
39 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); | |
40 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); |
|
40 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); | |
41 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); |
|
41 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); | |
42 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); |
|
42 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); | |
43 |
|
43 | |||
44 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
44 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); | |
45 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
45 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
48 | ChartTheme::ChartTheme(QChart::ChartTheme id) | |
49 | { |
|
49 | { | |
50 | m_id = id; |
|
50 | m_id = id; | |
51 | m_seriesColor.append(QRgb(0xff000000)); |
|
51 | m_seriesColor.append(QRgb(0xff000000)); | |
52 | m_seriesColor.append(QRgb(0xff707070)); |
|
52 | m_seriesColor.append(QRgb(0xff707070)); | |
53 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
53 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
54 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
54 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
55 |
|
55 | |||
56 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
56 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
60 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
61 | { |
|
61 | { | |
62 | switch(theme) { |
|
62 | switch(theme) { | |
63 | case QChart::ChartThemeDefault: |
|
63 | case QChart::ChartThemeDefault: | |
64 | return new ChartThemeIcy(); |
|
64 | return new ChartThemeIcy(); | |
65 | case QChart::ChartThemeVanilla: |
|
65 | case QChart::ChartThemeVanilla: | |
66 | return new ChartThemeVanilla(); |
|
66 | return new ChartThemeVanilla(); | |
67 | case QChart::ChartThemeIcy: |
|
67 | case QChart::ChartThemeIcy: | |
68 | return new ChartThemeIcy(); |
|
68 | return new ChartThemeIcy(); | |
69 | case QChart::ChartThemeGrayscale: |
|
69 | case QChart::ChartThemeGrayscale: | |
70 | return new ChartThemeGrayscale(); |
|
70 | return new ChartThemeGrayscale(); | |
71 | case QChart::ChartThemeScientific: |
|
71 | case QChart::ChartThemeScientific: | |
72 | return new ChartThemeScientific(); |
|
72 | return new ChartThemeScientific(); | |
73 | } |
|
73 | } | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | void ChartTheme::decorate(QChart* chart) |
|
76 | void ChartTheme::decorate(QChart* chart) | |
77 | { |
|
77 | { | |
78 | QLinearGradient backgroundGradient; |
|
78 | QLinearGradient backgroundGradient; | |
79 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); |
|
79 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); | |
80 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); |
|
80 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); | |
81 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
81 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
82 | chart->setChartBackgroundBrush(backgroundGradient); |
|
82 | chart->setChartBackgroundBrush(backgroundGradient); | |
83 | } |
|
83 | } | |
84 | //TODO helper to by removed later |
|
84 | //TODO helper to by removed later | |
85 | void ChartTheme::decorate(ChartItem* item, QSeries* series,int count) |
|
85 | void ChartTheme::decorate(ChartItem* item, QSeries* series,int count) | |
86 | { |
|
86 | { | |
87 | switch(series->type()) |
|
87 | switch(series->type()) | |
88 | { |
|
88 | { | |
89 | case QSeries::SeriesTypeLine: { |
|
89 | case QSeries::SeriesTypeLine: { | |
90 | QLineSeries* s = static_cast<QLineSeries*>(series); |
|
90 | QLineSeries* s = static_cast<QLineSeries*>(series); | |
91 | LineChartItem* i = static_cast<LineChartItem*>(item); |
|
91 | LineChartItem* i = static_cast<LineChartItem*>(item); | |
92 | decorate(i,s,count); |
|
92 | decorate(i,s,count); | |
93 | break; |
|
93 | break; | |
94 | } |
|
94 | } | |
95 | case QSeries::SeriesTypeBar: { |
|
95 | case QSeries::SeriesTypeBar: { | |
96 | QBarSeries* b = static_cast<QBarSeries*>(series); |
|
96 | QBarSeries* b = static_cast<QBarSeries*>(series); | |
97 | BarPresenter* i = static_cast<BarPresenter*>(item); |
|
97 | BarPresenter* i = static_cast<BarPresenter*>(item); | |
98 | decorate(i,b,count); |
|
98 | decorate(i,b,count); | |
99 | break; |
|
99 | break; | |
100 | } |
|
100 | } | |
101 | case QSeries::SeriesTypeStackedBar: { |
|
101 | case QSeries::SeriesTypeStackedBar: { | |
102 | QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series); |
|
102 | QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series); | |
103 | StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item); |
|
103 | StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item); | |
104 | decorate(i,s,count); |
|
104 | decorate(i,s,count); | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
107 | case QSeries::SeriesTypePercentBar: { |
|
107 | case QSeries::SeriesTypePercentBar: { | |
108 | QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series); |
|
108 | QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series); | |
109 | PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item); |
|
109 | PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item); | |
110 | decorate(i,s,count); |
|
110 | decorate(i,s,count); | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 | case QSeries::SeriesTypeScatter: { |
|
113 | case QSeries::SeriesTypeScatter: { | |
114 | QScatterSeries* s = qobject_cast<QScatterSeries*>(series); |
|
114 | QScatterSeries* s = qobject_cast<QScatterSeries*>(series); | |
115 | Q_ASSERT(s); |
|
115 | Q_ASSERT(s); | |
116 | ScatterPresenter* i = static_cast<ScatterPresenter*>(item); |
|
116 | ScatterPresenter* i = static_cast<ScatterPresenter*>(item); | |
117 | Q_ASSERT(i); |
|
117 | Q_ASSERT(i); | |
118 | decorate(i, s, count); |
|
118 | decorate(i, s, count); | |
119 | break; |
|
119 | break; | |
120 | } |
|
120 | } | |
121 | case QSeries::SeriesTypePie: { |
|
121 | case QSeries::SeriesTypePie: { | |
122 | QPieSeries* s = static_cast<QPieSeries*>(series); |
|
122 | QPieSeries* s = static_cast<QPieSeries*>(series); | |
123 | PiePresenter* i = static_cast<PiePresenter*>(item); |
|
123 | PiePresenter* i = static_cast<PiePresenter*>(item); | |
124 | decorate(i,s,count); |
|
124 | decorate(i,s,count); | |
125 | break; |
|
125 | break; | |
126 | } |
|
126 | } | |
127 | default: |
|
127 | default: | |
128 | qDebug()<<"Wrong item to be decorated by theme"; |
|
128 | qDebug()<<"Wrong item to be decorated by theme"; | |
129 | break; |
|
129 | break; | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count) |
|
134 | void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count) | |
135 | { |
|
135 | { | |
136 | QPen pen; |
|
136 | QPen pen; | |
137 | if(pen != series->pen()){ |
|
137 | if(pen != series->pen()){ | |
138 | item->setPen(series->pen()); |
|
138 | item->setPen(series->pen()); | |
139 | return; |
|
139 | return; | |
140 | } |
|
140 | } | |
141 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
141 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
142 | pen.setWidthF(2); |
|
142 | pen.setWidthF(2); | |
143 | item->setPen(pen); |
|
143 | item->setPen(pen); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count) |
|
146 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count) | |
147 | { |
|
147 | { | |
148 | QList<QBarSet*> sets = series->barSets(); |
|
148 | QList<QBarSet*> sets = series->barSets(); | |
149 | for (int i=0; i<series->barsetCount(); i++) { |
|
149 | for (int i=0; i<series->barsetCount(); i++) { | |
150 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
150 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
151 | } |
|
151 | } | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count) |
|
154 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count) | |
155 | { |
|
155 | { | |
156 | QList<QBarSet*> sets = series->barSets(); |
|
156 | QList<QBarSet*> sets = series->barSets(); | |
157 | for (int i=0; i<series->barsetCount(); i++) { |
|
157 | for (int i=0; i<series->barsetCount(); i++) { | |
158 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
158 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count) |
|
162 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count) | |
163 | { |
|
163 | { | |
164 | QList<QBarSet*> sets = series->barSets(); |
|
164 | QList<QBarSet*> sets = series->barSets(); | |
165 | for (int i=0; i<series->barsetCount(); i++) { |
|
165 | for (int i=0; i<series->barsetCount(); i++) { | |
166 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
166 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
167 | } |
|
167 | } | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) |
|
170 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) | |
171 | { |
|
171 | { | |
172 | Q_ASSERT(presenter); |
|
172 | Q_ASSERT(presenter); | |
173 | Q_ASSERT(series); |
|
173 | Q_ASSERT(series); | |
174 |
|
174 | |||
175 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); |
|
175 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); | |
176 | // TODO: define alpha in the theme? or in the series? |
|
176 | // TODO: define alpha in the theme? or in the series? | |
177 | //color.setAlpha(120); |
|
177 | //color.setAlpha(120); | |
178 |
|
178 | |||
179 | QBrush brush(color, Qt::SolidPattern); |
|
179 | QBrush brush(color, Qt::SolidPattern); | |
180 | presenter->m_markerBrush = brush; |
|
180 | presenter->m_markerBrush = brush; | |
181 |
|
181 | |||
182 | QPen pen(brush, 3); |
|
182 | QPen pen(brush, 3); | |
183 | pen.setColor(color); |
|
183 | pen.setColor(color); | |
184 | presenter->m_markerPen = pen; |
|
184 | presenter->m_markerPen = pen; | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) |
|
187 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) | |
188 | { |
|
188 | { | |
189 | // create a list of slice colors based on current theme |
|
189 | // create a list of slice colors based on current theme | |
190 | int i = 0; |
|
190 | int i = 0; | |
191 | QList<QColor> colors; |
|
191 | QList<QColor> colors; | |
192 | while (colors.count() < series->count()) { |
|
192 | while (colors.count() < series->count()) { | |
193 |
|
193 | |||
194 | // get base color |
|
194 | // get base color | |
195 | QColor c = m_seriesColor[i++]; |
|
195 | QColor c = m_seriesColor[i++]; | |
196 | i = i % m_seriesColor.count(); |
|
196 | i = i % m_seriesColor.count(); | |
197 |
|
197 | |||
198 | // dont use black colors... looks bad |
|
198 | // dont use black colors... looks bad | |
199 | if (c == Qt::black) |
|
199 | if (c == Qt::black) | |
200 | continue; |
|
200 | continue; | |
201 |
|
201 | |||
202 | // by default use the "raw" theme color |
|
202 | // by default use the "raw" theme color | |
203 | if (!colors.contains(c)) { |
|
203 | if (!colors.contains(c)) { | |
204 | colors << c; |
|
204 | colors << c; | |
205 | continue; |
|
205 | continue; | |
206 | } |
|
206 | } | |
207 | // ...ok we need to generate something that looks like the same color |
|
207 | // ...ok we need to generate something that looks like the same color | |
208 | // but different lightness |
|
208 | // but different lightness | |
209 |
|
209 | |||
210 | int tryCount = 0; |
|
210 | int tryCount = 0; | |
211 | while (tryCount++ < 100) { |
|
211 | while (tryCount++ < 100) { | |
212 |
|
212 | |||
213 | // find maximum value we can raise the lightness |
|
213 | // find maximum value we can raise the lightness | |
214 | int lMax = 255; |
|
214 | int lMax = 255; | |
215 | if (lMax > 255 - c.red()) |
|
215 | if (lMax > 255 - c.red()) | |
216 | lMax = 255 - c.red(); |
|
216 | lMax = 255 - c.red(); | |
217 | if (lMax > 255 - c.green()) |
|
217 | if (lMax > 255 - c.green()) | |
218 | lMax = 255 - c.green(); |
|
218 | lMax = 255 - c.green(); | |
219 | if (lMax > 255 - c.blue()) |
|
219 | if (lMax > 255 - c.blue()) | |
220 | lMax = 255 - c.blue(); |
|
220 | lMax = 255 - c.blue(); | |
221 |
|
221 | |||
222 | // find maximum value we can make it darker |
|
222 | // find maximum value we can make it darker | |
223 | int dMax = 255; |
|
223 | int dMax = 255; | |
224 | if (dMax > c.red()) |
|
224 | if (dMax > c.red()) | |
225 | dMax = c.red(); |
|
225 | dMax = c.red(); | |
226 | if (dMax > c.green()) |
|
226 | if (dMax > c.green()) | |
227 | dMax = c.green(); |
|
227 | dMax = c.green(); | |
228 | if (dMax > c.blue()) |
|
228 | if (dMax > c.blue()) | |
229 | dMax = c.blue(); |
|
229 | dMax = c.blue(); | |
230 |
|
230 | |||
231 | int max = dMax + lMax; |
|
231 | int max = dMax + lMax; | |
232 | if (max == 0) { |
|
232 | if (max == 0) { | |
233 | // no room to make color lighter or darker... |
|
233 | // no room to make color lighter or darker... | |
234 | qDebug() << "cannot generate a color for pie!"; |
|
234 | qDebug() << "cannot generate a color for pie!"; | |
235 | break; |
|
235 | break; | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | // generate random color |
|
238 | // generate random color | |
239 | int r = c.red() - dMax; |
|
239 | int r = c.red() - dMax; | |
240 | int g = c.green() - dMax; |
|
240 | int g = c.green() - dMax; | |
241 | int b = c.blue() - dMax; |
|
241 | int b = c.blue() - dMax; | |
242 | int d = qrand() % max; |
|
242 | int d = qrand() % max; | |
243 | c.setRgb(r+d, g+d, b+d); |
|
243 | c.setRgb(r+d, g+d, b+d); | |
244 |
|
244 | |||
245 | // found a unique color? |
|
245 | // found a unique color? | |
246 | if (!colors.contains(c)) |
|
246 | if (!colors.contains(c)) | |
247 | break; |
|
247 | break; | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | qDebug() << "generated a color for pie" << c; |
|
250 | qDebug() << "generated a color for pie" << c; | |
251 | colors << c; |
|
251 | colors << c; | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | // finally update colors |
|
254 | // finally update colors | |
255 | foreach (QPieSlice* s, series->slices()) { |
|
255 | foreach (QPieSlice* s, series->slices()) { | |
256 | QColor c = colors.takeFirst(); |
|
256 | QColor c = colors.takeFirst(); | |
257 | s->setPen(c); |
|
257 | s->setPen(c); | |
258 | s->setBrush(c); |
|
258 | s->setBrush(c); | |
259 | } |
|
259 | } | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 |
|
262 | |||
263 | void ChartTheme::decorate(QChartAxis* axis,AxisItem* item) |
|
263 | void ChartTheme::decorate(QChartAxis* axis,AxisItem* item) | |
264 | { |
|
264 | { | |
265 | //TODO: dummy defults for now |
|
265 | //TODO: dummy defults for now | |
266 | axis->setLabelsBrush(Qt::black); |
|
266 | axis->setLabelsBrush(Qt::black); | |
267 | axis->setLabelsPen(Qt::NoPen); |
|
267 | axis->setLabelsPen(Qt::NoPen); | |
268 | axis->setShadesPen(Qt::NoPen); |
|
268 | axis->setShadesPen(Qt::NoPen); | |
269 | axis->setShadesOpacity(0.5); |
|
269 | axis->setShadesOpacity(0.5); | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | void ChartTheme::decorate(SplinePresenter* presenter, QSplineSeries* series, int count) |
|
272 | void ChartTheme::decorate(SplinePresenter* presenter, QSplineSeries* series, int count) | |
273 | { |
|
273 | { | |
274 | Q_ASSERT(presenter); |
|
274 | Q_ASSERT(presenter); | |
275 | Q_ASSERT(series); |
|
275 | Q_ASSERT(series); | |
276 |
|
276 | |||
277 | // QColor color = m_seriesColor.at(count % m_seriesColor.size()); |
|
277 | // QColor color = m_seriesColor.at(count % m_seriesColor.size()); | |
278 | // TODO: define alpha in the theme? or in the series? |
|
278 | // TODO: define alpha in the theme? or in the series? | |
279 | //color.setAlpha(120); |
|
279 | //color.setAlpha(120); | |
280 |
|
280 | |||
281 | // QBrush brush(color, Qt::SolidPattern); |
|
281 | // QBrush brush(color, Qt::SolidPattern); | |
282 | // presenter->m_markerBrush = brush; |
|
282 | // presenter->m_markerBrush = brush; | |
283 |
|
283 | |||
284 | // QPen pen(brush, 3); |
|
284 | // QPen pen(brush, 3); | |
285 | // pen.setColor(color); |
|
285 | // pen.setColor(color); | |
286 | // presenter->m_markerPen = pen; |
|
286 | // presenter->m_markerPen = pen; | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | QTCOMMERCIALCHART_END_NAMESPACE |
|
289 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,61 +1,61 | |||||
1 | #ifndef LINECHARTITEM_H |
|
1 | #ifndef LINECHARTITEM_H | |
2 | #define LINECHARTITEM_H |
|
2 | #define LINECHARTITEM_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "chartitem_p.h" |
|
5 | #include "chartitem_p.h" | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class ChartPresenter; |
|
10 | class ChartPresenter; | |
11 | class QLineSeries; |
|
11 | class QLineSeries; | |
12 |
|
12 | |||
13 | class LineChartItem : public QObject , public ChartItem |
|
13 | class LineChartItem : public QObject , public ChartItem | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 | public: |
|
16 | public: | |
17 | LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent = 0); |
|
17 | LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent = 0); | |
18 | ~ LineChartItem(){}; |
|
18 | ~ LineChartItem(){}; | |
19 |
|
19 | |||
20 | //from QGraphicsItem |
|
20 | //from QGraphicsItem | |
21 | QRectF boundingRect() const; |
|
21 | QRectF boundingRect() const; | |
22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
23 | QPainterPath shape() const; |
|
23 | QPainterPath shape() const; | |
24 |
|
24 | |||
25 | void setPen(const QPen& pen); |
|
25 | void setPen(const QPen& pen); | |
26 | void setPointsVisible(bool visible); |
|
26 | void setPointsVisible(bool visible); | |
27 |
|
27 | |||
28 | public slots: |
|
28 | public slots: | |
29 | void handlePointAdded(int index); |
|
29 | void handlePointAdded(int index); | |
30 | void handlePointRemoved(int index); |
|
30 | void handlePointRemoved(int index); | |
31 | void handlePointReplaced(int index); |
|
31 | void handlePointReplaced(int index); | |
32 | void handleUpdated(); |
|
32 | void handleUpdated(); | |
33 | void handleDomainChanged(const Domain& domain); |
|
33 | void handleDomainChanged(const Domain& domain); | |
34 | void handleGeometryChanged(const QRectF& size); |
|
34 | void handleGeometryChanged(const QRectF& size); | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | virtual void updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints); |
|
37 | virtual void updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints); | |
38 | virtual void updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint); |
|
38 | virtual void updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint); | |
39 | void applyGeometry(QVector<QPointF>& points); |
|
39 | virtual void applyGeometry(QVector<QPointF>& points); | |
40 | void createPoints(int count); |
|
40 | void createPoints(int count); | |
41 | void clearPoints(int count); |
|
41 | void clearPoints(int count); | |
42 | QPointF calculateGeometryPoint(int index) const; |
|
42 | QPointF calculateGeometryPoint(int index) const; | |
43 | QVector<QPointF> calculateGeometryPoints() const; |
|
43 | QVector<QPointF> calculateGeometryPoints() const; | |
44 |
|
44 | |||
45 | private: |
|
45 | protected: | |
46 | ChartPresenter* m_presenter; |
|
|||
47 | QPainterPath m_path; |
|
46 | QPainterPath m_path; | |
|
47 | QRectF m_rect; | |||
48 | QLineSeries* m_series; |
|
48 | QLineSeries* m_series; | |
|
49 | ChartPresenter* m_presenter; | |||
49 | QSizeF m_size; |
|
50 | QSizeF m_size; | |
50 | QRectF m_rect; |
|
|||
51 |
|
|
51 | QRectF m_clipRect; | |
52 | Domain m_domain; |
|
52 | Domain m_domain; | |
53 | QGraphicsItemGroup m_items; |
|
53 | QGraphicsItemGroup m_items; | |
54 | QVector<QPointF> m_points; |
|
54 | QVector<QPointF> m_points; | |
55 | QPen m_pen; |
|
55 | QPen m_pen; | |
56 |
|
56 | |||
57 | }; |
|
57 | }; | |
58 |
|
58 | |||
59 | QTCOMMERCIALCHART_END_NAMESPACE |
|
59 | QTCOMMERCIALCHART_END_NAMESPACE | |
60 |
|
60 | |||
61 | #endif |
|
61 | #endif |
@@ -1,57 +1,59 | |||||
1 | #ifndef QLINESERIES_H_ |
|
1 | #ifndef QLINESERIES_H_ | |
2 | #define QLINESERIES_H_ |
|
2 | #define QLINESERIES_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qseries.h" |
|
5 | #include "qseries.h" | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 | #include <QPen> |
|
7 | #include <QPen> | |
8 | #include <QBrush> |
|
8 | #include <QBrush> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | class QTCOMMERCIALCHART_EXPORT QLineSeries : public QSeries |
|
12 | class QTCOMMERCIALCHART_EXPORT QLineSeries : public QSeries | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | QLineSeries(QObject* parent=0); |
|
16 | QLineSeries(QObject* parent=0); | |
17 | virtual ~QLineSeries(); |
|
17 | virtual ~QLineSeries(); | |
18 |
|
18 | |||
19 | public: // from QChartSeries |
|
19 | public: // from QChartSeries | |
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeLine;} |
|
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeLine;} | |
21 | void add(qreal x, qreal y); |
|
21 | void add(qreal x, qreal y); | |
22 | void add(const QPointF& point); |
|
22 | void add(const QPointF& point); | |
23 | void replace(qreal x,qreal y); |
|
23 | void replace(qreal x,qreal y); | |
24 | void replace(const QPointF& point); |
|
24 | void replace(const QPointF& point); | |
25 | void remove(qreal x); |
|
25 | void remove(qreal x); | |
26 | void remove(const QPointF& point); |
|
26 | void remove(const QPointF& point); | |
27 | void clear(); |
|
27 | void clear(); | |
28 |
|
28 | |||
29 | void setPen(const QPen& pen); |
|
29 | void setPen(const QPen& pen); | |
30 | QPen pen() const { return m_pen;} |
|
30 | QPen pen() const { return m_pen;} | |
31 |
|
31 | |||
32 | void setPointsVisible(bool visible); |
|
32 | void setPointsVisible(bool visible); | |
33 | bool pointsVisible() const {return m_pointsVisible;} |
|
33 | bool pointsVisible() const {return m_pointsVisible;} | |
34 |
|
34 | |||
35 | int count() const; |
|
35 | int count() const; | |
36 | qreal x(int pos) const; |
|
36 | qreal x(int pos) const; | |
37 | qreal y(int pos) const; |
|
37 | qreal y(int pos) const; | |
38 |
|
38 | |||
39 | QLineSeries& operator << (const QPointF &point); |
|
39 | QLineSeries& operator << (const QPointF &point); | |
40 | friend QDebug operator<< (QDebug d, const QLineSeries series); |
|
40 | friend QDebug operator<< (QDebug d, const QLineSeries series); | |
41 |
|
41 | |||
42 | signals: |
|
42 | signals: | |
43 | void pointReplaced(int index); |
|
43 | void pointReplaced(int index); | |
44 | void pointRemoved(int index); |
|
44 | void pointRemoved(int index); | |
45 | void pointAdded(int index); |
|
45 | void pointAdded(int index); | |
46 | void updated(); |
|
46 | void updated(); | |
47 |
|
47 | |||
48 | private: |
|
48 | protected: | |
49 | QVector<qreal> m_x; |
|
49 | QVector<qreal> m_x; | |
50 | QVector<qreal> m_y; |
|
50 | QVector<qreal> m_y; | |
|
51 | ||||
|
52 | private: | |||
51 | QPen m_pen; |
|
53 | QPen m_pen; | |
52 | bool m_pointsVisible; |
|
54 | bool m_pointsVisible; | |
53 | }; |
|
55 | }; | |
54 |
|
56 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
57 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
58 | |||
57 | #endif |
|
59 | #endif |
@@ -1,110 +1,110 | |||||
1 | #include "qsplineseries.h" |
|
1 | #include "qsplineseries.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | QSplineSeries::QSplineSeries(QObject *parent) : |
|
5 | QSplineSeries::QSplineSeries(QObject *parent) : | |
6 |
Q |
|
6 | QLineSeries(parent) | |
7 | { |
|
7 | { | |
8 | } |
|
8 | } | |
9 |
|
9 | |||
10 | QSplineSeries& QSplineSeries::operator << (const QPointF &value) |
|
10 | //QSplineSeries& QSplineSeries::operator << (const QPointF &value) | |
11 | { |
|
11 | //{ | |
12 | // d->m_data.append(value); |
|
12 | //// d->m_data.append(value); | |
13 | m_data.append(value); |
|
13 | // m_data.append(value); | |
14 | // emit changed(); |
|
14 | //// emit changed(); | |
15 | return *this; |
|
15 | // return *this; | |
16 | } |
|
16 | //} | |
17 |
|
17 | |||
18 | void QSplineSeries::addData(QPointF value) |
|
18 | //void QSplineSeries::addData(QPointF value) | |
19 | { |
|
19 | //{ | |
20 | m_data.append(value); |
|
20 | // m_data.append(value); | |
21 | } |
|
21 | //} | |
22 |
|
22 | |||
23 | void QSplineSeries::calculateControlPoints() |
|
23 | void QSplineSeries::calculateControlPoints() | |
24 | { |
|
24 | { | |
25 |
|
25 | |||
26 | // Based on http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit |
|
26 | // Based on http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit | |
27 | // CPOL Licence |
|
27 | // CPOL Licence | |
28 |
|
28 | |||
29 |
int n = m_ |
|
29 | int n = m_x.size() - 1; | |
30 | if (n == 1) |
|
30 | if (n == 1) | |
31 | { // Special case: Bezier curve should be a straight line. |
|
31 | { // Special case: Bezier curve should be a straight line. | |
32 | // firstControlPoints = new Point[1]; |
|
32 | // firstControlPoints = new Point[1]; | |
33 | // 3P1 = 2P0 + P3 |
|
33 | // 3P1 = 2P0 + P3 | |
34 |
m_controlPoints.append(QPointF((2 * m_ |
|
34 | m_controlPoints.append(QPointF((2 * m_x[0] + m_x[1]) / 3, (2 * m_y[0] + m_y[1]) / 3)); | |
35 |
|
35 | |||
36 | // P2 = 2P1 P0 |
|
36 | // P2 = 2P1 P0 | |
37 |
m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - m_ |
|
37 | m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - m_x[0], 2 * m_controlPoints[0].y() - m_y[0])); | |
38 | return; |
|
38 | return; | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | // Calculate first Bezier control points |
|
41 | // Calculate first Bezier control points | |
42 | // Right hand side vector |
|
42 | // Right hand side vector | |
43 | // Set of equations for P0 to Pn points. |
|
43 | // Set of equations for P0 to Pn points. | |
44 | // |
|
44 | // | |
45 | // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 | |
|
45 | // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 | | |
46 | // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 | |
|
46 | // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 | | |
47 | // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 | |
|
47 | // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 | | |
48 | // | . . . . . . . . . . . . | | ... | | ... | |
|
48 | // | . . . . . . . . . . . . | | ... | | ... | | |
49 | // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi | |
|
49 | // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi | | |
50 | // | . . . . . . . . . . . . | | ... | | ... | |
|
50 | // | . . . . . . . . . . . . | | ... | | ... | | |
51 | // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) | |
|
51 | // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) | | |
52 | // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn | |
|
52 | // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn | | |
53 | // |
|
53 | // | |
54 | QList<qreal> rhs; |
|
54 | QList<qreal> rhs; | |
55 |
rhs.append(m_ |
|
55 | rhs.append(m_x[0] + 2 * m_x[1]); | |
56 |
|
56 | |||
57 | // Set right hand side X values |
|
57 | // Set right hand side X values | |
58 |
for (int i = 1; i < m_ |
|
58 | for (int i = 1; i < m_x.size() - 1; ++i) | |
59 |
rhs.append(4 * m_ |
|
59 | rhs.append(4 * m_x[i] + 2 * m_x[i + 1]); | |
60 |
|
60 | |||
61 |
rhs.append((8 * m_ |
|
61 | rhs.append((8 * m_x[n - 1] + m_x[n]) / 2.0); | |
62 | // Get first control points X-values |
|
62 | // Get first control points X-values | |
63 | QList<qreal> x = getFirstControlPoints(rhs); |
|
63 | QList<qreal> x = getFirstControlPoints(rhs); | |
64 |
rhs[0] = m_ |
|
64 | rhs[0] = m_y[0] + 2 * m_y[1]; | |
65 |
|
65 | |||
66 | // Set right hand side Y values |
|
66 | // Set right hand side Y values | |
67 |
for (int i = 1; i < m_ |
|
67 | for (int i = 1; i < m_y.size() - 1; ++i) | |
68 |
rhs[i] = 4 * m_ |
|
68 | rhs[i] = 4 * m_y[i] + 2 * m_y[i + 1]; | |
69 |
|
69 | |||
70 |
rhs[n - 1] = (8 * m_ |
|
70 | rhs[n - 1] = (8 * m_y[n - 1] + m_y[n]) / 2.0; | |
71 | // Get first control points Y-values |
|
71 | // Get first control points Y-values | |
72 | QList<qreal> y = getFirstControlPoints(rhs); |
|
72 | QList<qreal> y = getFirstControlPoints(rhs); | |
73 |
|
73 | |||
74 | // Fill output arrays. |
|
74 | // Fill output arrays. | |
75 | // firstControlPoints = new Point[n]; |
|
75 | // firstControlPoints = new Point[n]; | |
76 | // secondControlPoints = new Point[n]; |
|
76 | // secondControlPoints = new Point[n]; | |
77 |
for (int i = 0; i < m_ |
|
77 | for (int i = 0; i < m_x.size(); ++i) | |
78 | { |
|
78 | { | |
79 | // First control point |
|
79 | // First control point | |
80 | m_controlPoints.append(QPointF(x[i], y[i])); |
|
80 | m_controlPoints.append(QPointF(x[i], y[i])); | |
81 | // Second control point |
|
81 | // Second control point | |
82 | if (i < n - 1) |
|
82 | if (i < n - 1) | |
83 |
m_controlPoints.append(QPointF(2 * m_ |
|
83 | m_controlPoints.append(QPointF(2 * m_x[i + 1] - x[i + 1], 2 * m_y[i + 1] - y[i + 1])); | |
84 | else |
|
84 | else | |
85 |
m_controlPoints.append(QPointF((m_ |
|
85 | m_controlPoints.append(QPointF((m_x[n] + x[n - 1]) / 2, (m_y[n] + y[n - 1]) / 2)); | |
86 | } |
|
86 | } | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | QList<qreal> QSplineSeries::getFirstControlPoints(QList<qreal> rhs) |
|
89 | QList<qreal> QSplineSeries::getFirstControlPoints(QList<qreal> rhs) | |
90 | { |
|
90 | { | |
91 | QList<qreal> x; // Solution vector. |
|
91 | QList<qreal> x; // Solution vector. | |
92 | QList<qreal> tmp; // Temp workspace. |
|
92 | QList<qreal> tmp; // Temp workspace. | |
93 |
|
93 | |||
94 | qreal b = 2.0; |
|
94 | qreal b = 2.0; | |
95 | x.append(rhs[0] / b); |
|
95 | x.append(rhs[0] / b); | |
96 | tmp.append(0); |
|
96 | tmp.append(0); | |
97 | for (int i = 1; i < rhs.size(); i++) // Decomposition and forward substitution. |
|
97 | for (int i = 1; i < rhs.size(); i++) // Decomposition and forward substitution. | |
98 | { |
|
98 | { | |
99 | tmp.append(1 / b); |
|
99 | tmp.append(1 / b); | |
100 | b = (i < rhs.size() - 1 ? 4.0 : 3.5) - tmp[i]; |
|
100 | b = (i < rhs.size() - 1 ? 4.0 : 3.5) - tmp[i]; | |
101 | x.append((rhs[i] - x[i - 1]) / b); |
|
101 | x.append((rhs[i] - x[i - 1]) / b); | |
102 | } |
|
102 | } | |
103 | for (int i = 1; i < rhs.size(); i++) |
|
103 | for (int i = 1; i < rhs.size(); i++) | |
104 | x[rhs.size() - i - 1] -= tmp[rhs.size() - i] * x[rhs.size() - i]; // Backsubstitution. |
|
104 | x[rhs.size() - i - 1] -= tmp[rhs.size() - i] * x[rhs.size() - i]; // Backsubstitution. | |
105 |
|
105 | |||
106 | return x; |
|
106 | return x; | |
107 | } |
|
107 | } | |
108 | #include "moc_qsplineseries.cpp" |
|
108 | #include "moc_qsplineseries.cpp" | |
109 |
|
109 | |||
110 | QTCOMMERCIALCHART_END_NAMESPACE |
|
110 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,41 +1,41 | |||||
1 | #ifndef QSPLINESERIES_H |
|
1 | #ifndef QSPLINESERIES_H | |
2 | #define QSPLINESERIES_H |
|
2 | #define QSPLINESERIES_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QtGlobal> |
|
5 | #include <QtGlobal> | |
6 |
#include "q |
|
6 | #include "qlineseries.h" | |
7 | #include <QList> |
|
7 | #include <QList> | |
8 | #include <QPointF> |
|
8 | #include <QPointF> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 |
class QSplineSeries : public Q |
|
12 | class QSplineSeries : public QLineSeries | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 |
|
16 | |||
17 | QSplineSeries(QObject *parent = 0); |
|
17 | QSplineSeries(QObject *parent = 0); | |
18 |
Q |
|
18 | QSeriesType type() const { return QSeries::SeriesTypeSpline; } | |
19 | void addData(QPointF value); |
|
19 | // void addData(QPointF value); | |
20 | QSplineSeries& operator << (const QPointF &value); |
|
20 | // QSplineSeries& operator << (const QPointF &value); | |
21 | void calculateControlPoints(); |
|
21 | void calculateControlPoints(); | |
22 | QList<qreal> getFirstControlPoints(QList<qreal> rhs); |
|
22 | QList<qreal> getFirstControlPoints(QList<qreal> rhs); | |
23 |
|
23 | |||
24 |
int count() const { return m_ |
|
24 | int count() const { return m_x.size(); } | |
25 |
|
25 | |||
26 | QPointF at(int index) const { return m_data[index]; } |
|
26 | // QPointF at(int index) const { return m_data[index]; } | |
27 | QPointF controlPoint(int index) const { return m_controlPoints[index]; } |
|
27 | QPointF controlPoint(int index) const { return m_controlPoints[index]; } | |
28 |
|
28 | |||
29 | signals: |
|
29 | signals: | |
30 |
|
30 | |||
31 | public slots: |
|
31 | public slots: | |
32 |
|
32 | |||
33 | private: |
|
33 | private: | |
34 | QList<QPointF> m_data; |
|
34 | // QList<QPointF> m_data; | |
35 | QList<QPointF> m_controlPoints; |
|
35 | QList<QPointF> m_controlPoints; | |
36 |
|
36 | |||
37 | }; |
|
37 | }; | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_END_NAMESPACE |
|
39 | QTCOMMERCIALCHART_END_NAMESPACE | |
40 |
|
40 | |||
41 | #endif // QSPLINESERIES_H |
|
41 | #endif // QSPLINESERIES_H |
@@ -1,72 +1,106 | |||||
1 | #include "splinepresenter_p.h" |
|
1 | #include "splinepresenter_p.h" | |
2 | #include <QPainter> |
|
2 | #include <QPainter> | |
3 |
|
3 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
5 | |||
6 | SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) : |
|
6 | SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) : | |
7 |
LineChartItem( |
|
7 | LineChartItem(0, series, parent)//,m_boundingRect() | |
8 | { |
|
8 | { | |
9 | // if (parent) |
|
9 | // if (parent) | |
10 | // m_boundingRect = parent->boundingRect(); |
|
10 | // m_boundingRect = parent->boundingRect(); | |
11 | // else |
|
11 | // else | |
12 | // m_boundingRect = QRectF(10,50, 250, 250); |
|
12 | // m_boundingRect = QRectF(10,50, 250, 250); | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | //void SplinePresenter::handleGeometryChanged(const QRectF&) |
|
15 | //void SplinePresenter::handleGeometryChanged(const QRectF&) | |
16 | //{ |
|
16 | //{ | |
17 | // update(); |
|
17 | // update(); | |
18 | //} |
|
18 | //} | |
19 |
|
19 | |||
20 | //void SplinePresenter::handleDomainChanged(const Domain& domain) |
|
20 | //void SplinePresenter::handleDomainChanged(const Domain& domain) | |
21 | //{ |
|
21 | //{ | |
22 | // // |
|
22 | // // | |
23 | //} |
|
23 | //} | |
24 |
|
24 | |||
25 |
|
|
25 | QPointF SplinePresenter::calculateGeometryControlPoint(int index) const | |
26 | { |
|
26 | { | |
|
27 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |||
|
28 | const qreal deltaX = m_size.width()/m_domain.spanX(); | |||
|
29 | const qreal deltaY = m_size.height()/m_domain.spanY(); | |||
|
30 | qreal x = (splineSeries->controlPoint(index).x() - m_domain.m_minX)* deltaX; | |||
|
31 | qreal y = (splineSeries->controlPoint(index).y() - m_domain.m_minY)*-deltaY + m_size.height(); | |||
|
32 | return QPointF(x,y); | |||
|
33 | } | |||
|
34 | ||||
|
35 | void SplinePresenter::applyGeometry(QVector<QPointF>& points) | |||
|
36 | { | |||
|
37 | if(points.size()==0) return; | |||
27 |
|
38 | |||
28 | if(m_data.size()==0) return; |
|
39 | // QList<QGraphicsItem*> items = m_items.childItems(); | |
29 |
|
40 | |||
30 | prepareGeometryChange(); |
|
41 | QPainterPath splinePath; | |
31 | QPainterPath path; |
|
42 | const QPointF& point = points.at(0); | |
32 | const QPointF& point = m_data.at(0); |
|
43 | splinePath.moveTo(point); | |
33 | path.moveTo(point); |
|
44 | // QGraphicsItem* item = items.at(0); | |
|
45 | // item->setPos(point.x()-1,point.y()-1); | |||
|
46 | // if(!m_clipRect.contains(point)) item->setVisible(false); | |||
|
47 | ||||
|
48 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |||
|
49 | for (int i = 0; i < splineSeries->count() - 1; i++) | |||
|
50 | { | |||
|
51 | const QPointF& point = points.at(i + 1); | |||
|
52 | // painter->setPen(Qt::red); | |||
|
53 | // splinePath.cubicTo(qobject_cast<QSplineSeries*>(m_series)->controlPoint(2 * i), qobject_cast<QSplineSeries*>(m_series)->controlPoint(2 * i + 1), QPointF(m_series->x(i + 1), m_series->y(i + 1))); | |||
|
54 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); | |||
|
55 | // painter->drawEllipse(m_series->at(i), 4, 4); | |||
34 |
|
56 | |||
35 | foreach( const QPointF& point , m_data) { |
|
57 | // painter->setPen(Qt::blue); | |
36 | path.lineTo(point); |
|
58 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); | |
|
59 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); | |||
|
60 | // painter->drawEllipse(m_series->controlPoint(2 * i), 4, 4); | |||
|
61 | // painter->drawEllipse(m_series->controlPoint(2 * i + 1), 4, 4); | |||
37 | } |
|
62 | } | |
38 |
|
63 | |||
39 | m_path = path; |
|
64 | // for(int i=1 ; i< points.size();i++) { | |
40 | m_rect = path.boundingRect(); |
|
65 | // QGraphicsItem* item = items.at(i); | |
|
66 | // const QPointF& point = points.at(i); | |||
|
67 | // item->setPos(point.x()-1,point.y()-1); | |||
|
68 | // if(!m_clipRect.contains(point)) item->setVisible(false); | |||
|
69 | // path.lineTo(point); | |||
|
70 | // } | |||
|
71 | ||||
|
72 | prepareGeometryChange(); | |||
|
73 | m_path = splinePath; | |||
|
74 | m_rect = splinePath.boundingRect(); | |||
41 | } |
|
75 | } | |
42 |
|
76 | |||
43 | //void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
77 | //void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
44 | //{ |
|
78 | //{ | |
45 | // Q_UNUSED(widget); |
|
79 | // Q_UNUSED(widget); | |
46 | // Q_UNUSED(option); |
|
80 | // Q_UNUSED(option); | |
47 | // painter->save(); |
|
81 | // painter->save(); | |
48 |
|
82 | |||
49 | // painter->setPen(Qt::SolidLine); |
|
83 | // painter->setPen(Qt::SolidLine); | |
50 |
|
84 | |||
51 | // QPainterPath splinePath; |
|
85 | // QPainterPath splinePath; | |
52 | // splinePath.moveTo(m_series->at(0)); |
|
86 | // splinePath.moveTo(m_series->at(0)); | |
53 | // for (int i = 0; i < m_series->count() - 1; i++) |
|
87 | // for (int i = 0; i < m_series->count() - 1; i++) | |
54 | // { |
|
88 | // { | |
55 | // painter->setPen(Qt::red); |
|
89 | // painter->setPen(Qt::red); | |
56 | // splinePath.cubicTo(m_series->controlPoint(2 * i), m_series->controlPoint(2 * i + 1), m_series->at(i + 1)); |
|
90 | // splinePath.cubicTo(m_series->controlPoint(2 * i), m_series->controlPoint(2 * i + 1), m_series->at(i + 1)); | |
57 | // painter->drawEllipse(m_series->at(i), 4, 4); |
|
91 | // painter->drawEllipse(m_series->at(i), 4, 4); | |
58 |
|
92 | |||
59 | // painter->setPen(Qt::blue); |
|
93 | // painter->setPen(Qt::blue); | |
60 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); |
|
94 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); | |
61 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); |
|
95 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); | |
62 | // painter->drawEllipse(m_series->controlPoint(2 * i), 4, 4); |
|
96 | // painter->drawEllipse(m_series->controlPoint(2 * i), 4, 4); | |
63 | // painter->drawEllipse(m_series->controlPoint(2 * i + 1), 4, 4); |
|
97 | // painter->drawEllipse(m_series->controlPoint(2 * i + 1), 4, 4); | |
64 | // } |
|
98 | // } | |
65 | // painter->setPen(Qt::red); |
|
99 | // painter->setPen(Qt::red); | |
66 | // painter->drawPath(splinePath); |
|
100 | // painter->drawPath(splinePath); | |
67 | // painter->restore(); |
|
101 | // painter->restore(); | |
68 | //} |
|
102 | //} | |
69 |
|
103 | |||
70 | #include "moc_splinepresenter_p.cpp" |
|
104 | #include "moc_splinepresenter_p.cpp" | |
71 |
|
105 | |||
72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
106 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,40 | |||||
1 | #ifndef SPLINEPRESENTER_P_H |
|
1 | #ifndef SPLINEPRESENTER_P_H | |
2 | #define SPLINEPRESENTER_P_H |
|
2 | #define SPLINEPRESENTER_P_H | |
3 |
|
3 | |||
4 | #include "chartitem_p.h" |
|
4 | #include "chartitem_p.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include "qsplineseries.h" |
|
6 | #include "qsplineseries.h" | |
7 | #include "linechartitem_p.h" |
|
7 | #include "linechartitem_p.h" | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class SplinePresenter : public LineChartItem |
|
11 | class SplinePresenter : public LineChartItem | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 | SplinePresenter(QSplineSeries* series, QGraphicsObject *parent = 0); |
|
15 | SplinePresenter(QSplineSeries* series, QGraphicsObject *parent = 0); | |
16 |
|
16 | |||
17 | void updateGeometry(); |
|
17 | void updateGeometry(); | |
18 |
|
18 | |||
|
19 | void applyGeometry(QVector<QPointF>& points); | |||
|
20 | ||||
|
21 | QPointF calculateGeometryControlPoint(int index) const; | |||
|
22 | ||||
19 | // QRectF boundingRect() const { return m_boundingRect; } |
|
23 | // QRectF boundingRect() const { return m_boundingRect; } | |
20 | // void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
24 | // void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
21 |
|
25 | |||
22 | signals: |
|
26 | signals: | |
23 |
|
27 | |||
24 | public slots: |
|
28 | public slots: | |
25 | // void handleDomainChanged(const Domain& domain); |
|
29 | // void handleDomainChanged(const Domain& domain); | |
26 | // void handleGeometryChanged(const QRectF& rect); |
|
30 | // void handleGeometryChanged(const QRectF& rect); | |
27 |
|
31 | |||
28 | private: |
|
32 | private: | |
29 | QSplineSeries* m_series; |
|
33 | // QSplineSeries* m_series; | |
30 | // QRectF m_boundingRect; |
|
34 | // QRectF m_boundingRect; | |
31 |
|
35 | |||
32 | }; |
|
36 | }; | |
33 |
|
37 | |||
34 | QTCOMMERCIALCHART_END_NAMESPACE |
|
38 | QTCOMMERCIALCHART_END_NAMESPACE | |
35 |
|
39 | |||
36 | #endif // SPLINEPRESENTER_P_H |
|
40 | #endif // SPLINEPRESENTER_P_H |
@@ -1,96 +1,91 | |||||
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 += axisitem.cpp \ |
|
9 | SOURCES += axisitem.cpp \ | |
10 | axisanimationitem.cpp \ |
|
10 | axisanimationitem.cpp \ | |
11 | chartdataset.cpp \ |
|
11 | chartdataset.cpp \ | |
12 | chartpresenter.cpp \ |
|
12 | chartpresenter.cpp \ | |
13 | charttheme.cpp \ |
|
13 | charttheme.cpp \ | |
14 | domain.cpp \ |
|
14 | domain.cpp \ | |
15 | qchart.cpp \ |
|
15 | qchart.cpp \ | |
16 | qchartaxis.cpp \ |
|
16 | qchartaxis.cpp \ | |
17 | qchartview.cpp \ |
|
17 | qchartview.cpp \ | |
18 | qseries.cpp |
|
18 | qseries.cpp | |
19 | PRIVATE_HEADERS += axisitem_p.h \ |
|
19 | PRIVATE_HEADERS += axisitem_p.h \ | |
20 | axisanimationitem_p.h \ |
|
20 | axisanimationitem_p.h \ | |
21 | chartdataset_p.h \ |
|
21 | chartdataset_p.h \ | |
22 | chartitem_p.h \ |
|
22 | chartitem_p.h \ | |
23 | chartpresenter_p.h \ |
|
23 | chartpresenter_p.h \ | |
24 | charttheme_p.h \ |
|
24 | charttheme_p.h \ | |
25 | domain_p.h |
|
25 | domain_p.h | |
26 | PUBLIC_HEADERS += qchart.h \ |
|
26 | PUBLIC_HEADERS += qchart.h \ | |
27 | qchartaxis.h \ |
|
27 | qchartaxis.h \ | |
28 | qchartglobal.h \ |
|
28 | qchartglobal.h \ | |
29 | qseries.h \ |
|
29 | qseries.h \ | |
30 | qchartview.h |
|
30 | qchartview.h | |
31 | include(linechart/linechart.pri) |
|
31 | include(linechart/linechart.pri) | |
32 | include(barchart/barchart.pri) |
|
32 | include(barchart/barchart.pri) | |
33 | include(piechart/piechart.pri) |
|
33 | include(piechart/piechart.pri) | |
34 | include(scatterseries/scatter.pri) |
|
34 | include(scatterseries/scatter.pri) | |
35 | include(splinechart/splinechart.pri) |
|
35 | include(splinechart/splinechart.pri) | |
36 |
|
36 | |||
37 | THEMES += themes/chartthemeicy_p.h \ |
|
37 | THEMES += themes/chartthemeicy_p.h \ | |
38 | themes/chartthemegrayscale_p.h \ |
|
38 | themes/chartthemegrayscale_p.h \ | |
39 | themes/chartthemescientific_p.h \ |
|
39 | themes/chartthemescientific_p.h \ | |
40 | themes/chartthemevanilla_p.h |
|
40 | themes/chartthemevanilla_p.h | |
41 | HEADERS += $$PUBLIC_HEADERS |
|
41 | HEADERS += $$PUBLIC_HEADERS | |
42 | HEADERS += $$PRIVATE_HEADERS |
|
42 | HEADERS += $$PRIVATE_HEADERS | |
43 | HEADERS += $$THEMES |
|
43 | HEADERS += $$THEMES | |
44 | INCLUDEPATH += linechart \ |
|
44 | INCLUDEPATH += linechart \ | |
45 | barchart \ |
|
45 | barchart \ | |
46 | themes \ |
|
46 | themes \ | |
47 | . |
|
47 | . | |
48 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
48 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
49 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
49 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
50 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
50 | UI_DIR = $$CHART_BUILD_DIR/lib | |
51 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
51 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
52 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
52 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
53 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
53 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
54 | public_headers.files = $$PUBLIC_HEADERS |
|
54 | public_headers.files = $$PUBLIC_HEADERS | |
55 | target.path = $$[QT_INSTALL_LIBS] |
|
55 | target.path = $$[QT_INSTALL_LIBS] | |
56 | INSTALLS += target \ |
|
56 | INSTALLS += target \ | |
57 | public_headers |
|
57 | public_headers | |
58 | install_build_public_headers.name = bild_public_headers |
|
58 | install_build_public_headers.name = bild_public_headers | |
59 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
59 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
60 | install_build_public_headers.input = PUBLIC_HEADERS |
|
60 | install_build_public_headers.input = PUBLIC_HEADERS | |
61 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
61 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
62 | ${QMAKE_FILE_NAME} \ |
|
62 | ${QMAKE_FILE_NAME} \ | |
63 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
63 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
64 | install_build_public_headers.CONFIG += target_predeps \ |
|
64 | install_build_public_headers.CONFIG += target_predeps \ | |
65 | no_link |
|
65 | no_link | |
66 | install_build_private_headers.name = bild_private_headers |
|
66 | install_build_private_headers.name = bild_private_headers | |
67 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
67 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
68 | install_build_private_headers.input = PRIVATE_HEADERS |
|
68 | install_build_private_headers.input = PRIVATE_HEADERS | |
69 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
69 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
70 | ${QMAKE_FILE_NAME} \ |
|
70 | ${QMAKE_FILE_NAME} \ | |
71 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
71 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
72 | install_build_private_headers.CONFIG += target_predeps \ |
|
72 | install_build_private_headers.CONFIG += target_predeps \ | |
73 | no_link |
|
73 | no_link | |
74 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
74 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
75 | install_build_private_headers |
|
75 | install_build_private_headers | |
76 | chartversion.target = qchartversion_p.h |
|
76 | chartversion.target = qchartversion_p.h | |
77 | chartversion.commands = @echo \ |
|
77 | chartversion.commands = @echo \ | |
78 | "build_time" \ |
|
78 | "build_time" \ | |
79 | > \ |
|
79 | > \ | |
80 | $$chartversion.target; |
|
80 | $$chartversion.target; | |
81 | chartversion.depends = $$HEADERS \ |
|
81 | chartversion.depends = $$HEADERS \ | |
82 | $$SOURCES |
|
82 | $$SOURCES | |
83 | PRE_TARGETDEPS += qchartversion_p.h |
|
83 | PRE_TARGETDEPS += qchartversion_p.h | |
84 | QMAKE_CLEAN += qchartversion_p.h |
|
84 | QMAKE_CLEAN += qchartversion_p.h | |
85 | QMAKE_EXTRA_TARGETS += chartversion |
|
85 | QMAKE_EXTRA_TARGETS += chartversion | |
86 | unix:QMAKE_DISTCLEAN += -r \ |
|
86 | unix:QMAKE_DISTCLEAN += -r \ | |
87 | $$CHART_BUILD_HEADER_DIR \ |
|
87 | $$CHART_BUILD_HEADER_DIR \ | |
88 | $$CHART_BUILD_LIB_DIR |
|
88 | $$CHART_BUILD_LIB_DIR | |
89 | win32:QMAKE_DISTCLEAN += /Q \ |
|
89 | win32:QMAKE_DISTCLEAN += /Q \ | |
90 | $$CHART_BUILD_HEADER_DIR \ |
|
90 | $$CHART_BUILD_HEADER_DIR \ | |
91 | <<<<<<< HEAD |
|
|||
92 | $$CHART_BUILD_LIB_DIR |
|
91 | $$CHART_BUILD_LIB_DIR | |
93 | ======= |
|
|||
94 | $$CHART_BUILD_LIB_DIR |
|
|||
95 |
|
||||
96 | >>>>>>> spline |
|
General Comments 0
You need to be logged in to leave comments.
Login now