@@ -1,46 +1,51 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qxychartseries.h> |
|
4 | #include <qxychartseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
9 |
|
9 | |||
10 | #define PI 3.14159265358979 |
|
10 | #define PI 3.14159265358979 | |
11 |
|
11 | |||
12 | int main(int argc, char *argv[]) |
|
12 | int main(int argc, char *argv[]) | |
13 | { |
|
13 | { | |
14 | QApplication a(argc, argv); |
|
14 | QApplication a(argc, argv); | |
15 |
|
15 | |||
16 | QMainWindow window; |
|
16 | QMainWindow window; | |
17 |
|
17 | |||
18 | QXYChartSeries* series0 = QXYChartSeries::create(); |
|
18 | QXYChartSeries* series0 = QXYChartSeries::create(); | |
19 | QPen blue(Qt::blue); |
|
19 | QPen blue(Qt::blue); | |
20 | blue.setWidth(3); |
|
20 | blue.setWidth(3); | |
21 | series0->setPen(blue); |
|
21 | series0->setPen(blue); | |
22 | QXYChartSeries* series1 = QXYChartSeries::create(); |
|
22 | QXYChartSeries* series1 = QXYChartSeries::create(); | |
23 | QPen red(Qt::red); |
|
23 | QPen red(Qt::red); | |
24 | red.setWidth(3); |
|
24 | red.setWidth(3); | |
25 | series1->setPen(red); |
|
25 | series1->setPen(red); | |
26 |
|
26 | |||
27 | int numPoints = 100; |
|
27 | int numPoints = 100; | |
28 |
|
28 | |||
29 | for (int x = 0; x <= numPoints; ++x) { |
|
29 | for (int x = 0; x <= numPoints; ++x) { | |
30 | series0->add(x, abs(sin(PI/50*x)*100)); |
|
30 | series0->add(x, abs(sin(PI/50*x)*100)); | |
31 | series1->add(x, abs(cos(PI/50*x)*100)); |
|
31 | series1->add(x, abs(cos(PI/50*x)*100)); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QChartView* chartView = new QChartView(&window); |
|
34 | QChartView* chartView = new QChartView(&window); | |
35 | chartView->setRenderHint(QPainter::Antialiasing); |
|
35 | chartView->setRenderHint(QPainter::Antialiasing); | |
36 | chartView->setTitle("Custom color line chart example"); |
|
36 | chartView->setTitle("Custom color line chart example"); | |
37 | chartView->addSeries(series0); |
|
37 | chartView->addSeries(series0); | |
38 | chartView->addSeries(series1); |
|
38 | chartView->addSeries(series1); | |
39 | chartView->setBackground(Qt::blue,Qt::yellow,QChart::HorizonatlGradientOrientation); |
|
39 | ||
|
40 | QLinearGradient backgroundGradient; | |||
|
41 | backgroundGradient.setColorAt(0.0, Qt::blue); | |||
|
42 | backgroundGradient.setColorAt(1.0, Qt::yellow); | |||
|
43 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |||
|
44 | chartView->setChartBackgroundBrush(backgroundGradient); | |||
40 |
|
45 | |||
41 | window.setCentralWidget(chartView); |
|
46 | window.setCentralWidget(chartView); | |
42 | window.resize(400, 300); |
|
47 | window.resize(400, 300); | |
43 | window.show(); |
|
48 | window.show(); | |
44 |
|
49 | |||
45 | return a.exec(); |
|
50 | return a.exec(); | |
46 | } |
|
51 | } |
@@ -1,414 +1,433 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartseries.h" |
|
2 | #include "qchartseries.h" | |
3 | #include "qscatterseries.h" |
|
3 | #include "qscatterseries.h" | |
4 | #include "qscatterseries_p.h" |
|
4 | #include "qscatterseries_p.h" | |
5 | #include "qpieseries.h" |
|
5 | #include "qpieseries.h" | |
6 | #include "qpieseries_p.h" |
|
6 | #include "qpieseries_p.h" | |
7 | #include "qxychartseries.h" |
|
7 | #include "qxychartseries.h" | |
8 | #include "qchartaxis.h" |
|
8 | #include "qchartaxis.h" | |
9 | #include "barchartseries.h" |
|
9 | #include "barchartseries.h" | |
10 | #include "bargroup.h" |
|
10 | #include "bargroup.h" | |
11 | #include "stackedbarchartseries.h" |
|
11 | #include "stackedbarchartseries.h" | |
12 | #include "stackedbargroup.h" |
|
12 | #include "stackedbargroup.h" | |
13 | #include "percentbarchartseries.h" |
|
13 | #include "percentbarchartseries.h" | |
14 | #include "percentbargroup.h" |
|
14 | #include "percentbargroup.h" | |
15 | #include "charttheme_p.h" |
|
15 | #include "charttheme_p.h" | |
16 | #include "chartitem_p.h" |
|
16 | #include "chartitem_p.h" | |
17 |
|
17 | |||
18 | #include "xylinechartitem_p.h" |
|
18 | #include "xylinechartitem_p.h" | |
19 | #include "plotdomain_p.h" |
|
19 | #include "plotdomain_p.h" | |
20 | #include "axisitem_p.h" |
|
20 | #include "axisitem_p.h" | |
21 | #include <QGraphicsScene> |
|
21 | #include <QGraphicsScene> | |
22 | #include <QGraphicsSceneResizeEvent> |
|
22 | #include <QGraphicsSceneResizeEvent> | |
23 | #include <QDebug> |
|
23 | #include <QDebug> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
27 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
28 | m_backgroundItem(0), |
|
28 | m_backgroundItem(0), | |
29 | m_titleItem(0), |
|
29 | m_titleItem(0), | |
30 | m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), |
|
30 | m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), | |
31 | m_plotDataIndex(0), |
|
31 | m_plotDataIndex(0), | |
32 | m_marginSize(0), |
|
32 | m_marginSize(0), | |
33 | m_chartTheme(new ChartTheme(this)) |
|
33 | m_chartTheme(new ChartTheme(this)) | |
34 | { |
|
34 | { | |
35 | // TODO: the default theme? |
|
35 | // TODO: the default theme? | |
36 | setTheme(QChart::ChartThemeDefault); |
|
36 | setTheme(QChart::ChartThemeDefault); | |
37 |
|
37 | |||
38 | PlotDomain domain; |
|
38 | PlotDomain domain; | |
39 | m_plotDomainList << domain; |
|
39 | m_plotDomainList << domain; | |
40 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); |
|
40 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); | |
41 | m_chartItems << m_axisXItem; |
|
41 | m_chartItems << m_axisXItem; | |
42 | m_chartItems << m_axisYItem.at(0); |
|
42 | m_chartItems << m_axisYItem.at(0); | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | QChart::~QChart(){} |
|
45 | QChart::~QChart(){} | |
46 |
|
46 | |||
47 | void QChart::addSeries(QChartSeries* series) |
|
47 | void QChart::addSeries(QChartSeries* series) | |
48 | { |
|
48 | { | |
49 | // TODO: we should check the series not already added |
|
49 | // TODO: we should check the series not already added | |
50 | Q_ASSERT(series); |
|
50 | Q_ASSERT(series); | |
51 | Q_ASSERT(series->type() != QChartSeries::SeriesTypeInvalid); |
|
51 | Q_ASSERT(series->type() != QChartSeries::SeriesTypeInvalid); | |
52 |
|
52 | |||
53 | m_chartSeries << series; |
|
53 | m_chartSeries << series; | |
54 |
|
54 | |||
55 | m_plotDataIndex = 0 ; |
|
55 | m_plotDataIndex = 0 ; | |
56 | m_plotDomainList.resize(1); |
|
56 | m_plotDomainList.resize(1); | |
57 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
57 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
58 |
|
58 | |||
59 | switch(series->type()) |
|
59 | switch(series->type()) | |
60 | { |
|
60 | { | |
61 | case QChartSeries::SeriesTypeLine: { |
|
61 | case QChartSeries::SeriesTypeLine: { | |
62 |
|
62 | |||
63 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
63 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
64 |
|
64 | |||
65 | for (int i = 0 ; i < xyseries->count() ; i++) { |
|
65 | for (int i = 0 ; i < xyseries->count() ; i++) { | |
66 | qreal x = xyseries->x(i); |
|
66 | qreal x = xyseries->x(i); | |
67 | qreal y = xyseries->y(i); |
|
67 | qreal y = xyseries->y(i); | |
68 | domain.m_minX = qMin(domain.m_minX,x); |
|
68 | domain.m_minX = qMin(domain.m_minX,x); | |
69 | domain.m_minY = qMin(domain.m_minY,y); |
|
69 | domain.m_minY = qMin(domain.m_minY,y); | |
70 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
70 | domain.m_maxX = qMax(domain.m_maxX,x); | |
71 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
71 | domain.m_maxY = qMax(domain.m_maxY,y); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); |
|
74 | XYLineChartItem* item = new XYLineChartItem(xyseries,0,this); | |
75 |
|
75 | |||
76 | m_chartItems << item; |
|
76 | m_chartItems << item; | |
77 | // TODO: |
|
77 | // TODO: | |
78 | //m_chartTheme->addObserver(xyseries); |
|
78 | //m_chartTheme->addObserver(xyseries); | |
79 |
|
79 | |||
80 | break; |
|
80 | break; | |
81 | } |
|
81 | } | |
82 | case QChartSeries::SeriesTypeBar: { |
|
82 | case QChartSeries::SeriesTypeBar: { | |
83 |
|
83 | |||
84 | qDebug() << "barSeries added"; |
|
84 | qDebug() << "barSeries added"; | |
85 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
85 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
86 | BarGroup* barGroup = new BarGroup(*barSeries,this); |
|
86 | BarGroup* barGroup = new BarGroup(*barSeries,this); | |
87 |
|
87 | |||
88 | // Add some fugly colors for 5 fist series... |
|
88 | // Add some fugly colors for 5 fist series... | |
89 | barGroup->addColor(QColor(255,0,0,128)); |
|
89 | barGroup->addColor(QColor(255,0,0,128)); | |
90 | barGroup->addColor(QColor(255,255,0,128)); |
|
90 | barGroup->addColor(QColor(255,255,0,128)); | |
91 | barGroup->addColor(QColor(0,255,0,128)); |
|
91 | barGroup->addColor(QColor(0,255,0,128)); | |
92 | barGroup->addColor(QColor(0,0,255,128)); |
|
92 | barGroup->addColor(QColor(0,0,255,128)); | |
93 | barGroup->addColor(QColor(255,128,0,128)); |
|
93 | barGroup->addColor(QColor(255,128,0,128)); | |
94 |
|
94 | |||
95 | m_chartItems << barGroup; |
|
95 | m_chartItems << barGroup; | |
96 | childItems().append(barGroup); |
|
96 | childItems().append(barGroup); | |
97 |
|
97 | |||
98 | qreal x = barSeries->countColumns(); |
|
98 | qreal x = barSeries->countColumns(); | |
99 | qreal y = barSeries->max(); |
|
99 | qreal y = barSeries->max(); | |
100 | domain.m_minX = qMin(domain.m_minX,x); |
|
100 | domain.m_minX = qMin(domain.m_minX,x); | |
101 | domain.m_minY = qMin(domain.m_minY,y); |
|
101 | domain.m_minY = qMin(domain.m_minY,y); | |
102 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
102 | domain.m_maxX = qMax(domain.m_maxX,x); | |
103 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
103 | domain.m_maxY = qMax(domain.m_maxY,y); | |
104 | m_axisXItem->setVisible(false); |
|
104 | m_axisXItem->setVisible(false); | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
107 | case QChartSeries::SeriesTypeStackedBar: { |
|
107 | case QChartSeries::SeriesTypeStackedBar: { | |
108 |
|
108 | |||
109 | qDebug() << "barSeries added"; |
|
109 | qDebug() << "barSeries added"; | |
110 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
110 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
111 | StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this); |
|
111 | StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this); | |
112 |
|
112 | |||
113 | // Add some fugly colors for 5 fist series... |
|
113 | // Add some fugly colors for 5 fist series... | |
114 | stackedBarGroup->addColor(QColor(255,0,0,128)); |
|
114 | stackedBarGroup->addColor(QColor(255,0,0,128)); | |
115 | stackedBarGroup->addColor(QColor(255,255,0,128)); |
|
115 | stackedBarGroup->addColor(QColor(255,255,0,128)); | |
116 | stackedBarGroup->addColor(QColor(0,255,0,128)); |
|
116 | stackedBarGroup->addColor(QColor(0,255,0,128)); | |
117 | stackedBarGroup->addColor(QColor(0,0,255,128)); |
|
117 | stackedBarGroup->addColor(QColor(0,0,255,128)); | |
118 | stackedBarGroup->addColor(QColor(255,128,0,128)); |
|
118 | stackedBarGroup->addColor(QColor(255,128,0,128)); | |
119 |
|
119 | |||
120 | m_chartItems << stackedBarGroup; |
|
120 | m_chartItems << stackedBarGroup; | |
121 | childItems().append(stackedBarGroup); |
|
121 | childItems().append(stackedBarGroup); | |
122 |
|
122 | |||
123 | qreal x = stackedBarSeries->countColumns(); |
|
123 | qreal x = stackedBarSeries->countColumns(); | |
124 | qreal y = stackedBarSeries->maxColumnSum(); |
|
124 | qreal y = stackedBarSeries->maxColumnSum(); | |
125 | domain.m_minX = qMin(domain.m_minX,x); |
|
125 | domain.m_minX = qMin(domain.m_minX,x); | |
126 | domain.m_minY = qMin(domain.m_minY,y); |
|
126 | domain.m_minY = qMin(domain.m_minY,y); | |
127 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
127 | domain.m_maxX = qMax(domain.m_maxX,x); | |
128 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
128 | domain.m_maxY = qMax(domain.m_maxY,y); | |
129 | m_axisXItem->setVisible(false); |
|
129 | m_axisXItem->setVisible(false); | |
130 | break; |
|
130 | break; | |
131 | } |
|
131 | } | |
132 | case QChartSeries::SeriesTypePercentBar: { |
|
132 | case QChartSeries::SeriesTypePercentBar: { | |
133 |
|
133 | |||
134 | qDebug() << "barSeries added"; |
|
134 | qDebug() << "barSeries added"; | |
135 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
135 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
136 | PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this); |
|
136 | PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this); | |
137 |
|
137 | |||
138 | // Add some fugly colors for 5 fist series... |
|
138 | // Add some fugly colors for 5 fist series... | |
139 | percentBarGroup->addColor(QColor(255,0,0,128)); |
|
139 | percentBarGroup->addColor(QColor(255,0,0,128)); | |
140 | percentBarGroup->addColor(QColor(255,255,0,128)); |
|
140 | percentBarGroup->addColor(QColor(255,255,0,128)); | |
141 | percentBarGroup->addColor(QColor(0,255,0,128)); |
|
141 | percentBarGroup->addColor(QColor(0,255,0,128)); | |
142 | percentBarGroup->addColor(QColor(0,0,255,128)); |
|
142 | percentBarGroup->addColor(QColor(0,0,255,128)); | |
143 | percentBarGroup->addColor(QColor(255,128,0,128)); |
|
143 | percentBarGroup->addColor(QColor(255,128,0,128)); | |
144 |
|
144 | |||
145 | m_chartItems << percentBarGroup; |
|
145 | m_chartItems << percentBarGroup; | |
146 | childItems().append(percentBarGroup); |
|
146 | childItems().append(percentBarGroup); | |
147 |
|
147 | |||
148 | qreal x = percentBarSeries->countColumns(); |
|
148 | qreal x = percentBarSeries->countColumns(); | |
149 | domain.m_minX = qMin(domain.m_minX,x); |
|
149 | domain.m_minX = qMin(domain.m_minX,x); | |
150 | domain.m_minY = 0; |
|
150 | domain.m_minY = 0; | |
151 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
151 | domain.m_maxX = qMax(domain.m_maxX,x); | |
152 | domain.m_maxY = 100; |
|
152 | domain.m_maxY = 100; | |
153 | m_axisXItem->setVisible(false); |
|
153 | m_axisXItem->setVisible(false); | |
154 | break; |
|
154 | break; | |
155 | } |
|
155 | } | |
156 | case QChartSeries::SeriesTypeScatter: { |
|
156 | case QChartSeries::SeriesTypeScatter: { | |
157 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
157 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
158 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
158 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
159 | scatterSeries->d->setParentItem(this); |
|
159 | scatterSeries->d->setParentItem(this); | |
160 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
160 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
161 | m_chartItems << scatterSeries->d; |
|
161 | m_chartItems << scatterSeries->d; | |
162 | m_chartTheme->addObserver(scatterSeries->d); |
|
162 | m_chartTheme->addObserver(scatterSeries->d); | |
163 |
|
163 | |||
164 | foreach (qreal x, scatterSeries->d->m_x) { |
|
164 | foreach (qreal x, scatterSeries->d->m_x) { | |
165 | domain.m_minX = qMin(domain.m_minX, x); |
|
165 | domain.m_minX = qMin(domain.m_minX, x); | |
166 | domain.m_maxX = qMax(domain.m_maxX, x); |
|
166 | domain.m_maxX = qMax(domain.m_maxX, x); | |
167 | } |
|
167 | } | |
168 | foreach (qreal y, scatterSeries->d->m_y) { |
|
168 | foreach (qreal y, scatterSeries->d->m_y) { | |
169 | domain.m_minY = qMin(domain.m_minY, y); |
|
169 | domain.m_minY = qMin(domain.m_minY, y); | |
170 | domain.m_maxY = qMax(domain.m_maxY, y); |
|
170 | domain.m_maxY = qMax(domain.m_maxY, y); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | break; |
|
173 | break; | |
174 | } |
|
174 | } | |
175 | case QChartSeries::SeriesTypePie: { |
|
175 | case QChartSeries::SeriesTypePie: { | |
176 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
176 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
177 | pieSeries->d->setParentItem(this); |
|
177 | pieSeries->d->setParentItem(this); | |
178 | m_chartItems << pieSeries->d; |
|
178 | m_chartItems << pieSeries->d; | |
179 | pieSeries->d->m_chartTheme = m_chartTheme; |
|
179 | pieSeries->d->m_chartTheme = m_chartTheme; | |
180 | m_chartTheme->addObserver(pieSeries->d); |
|
180 | m_chartTheme->addObserver(pieSeries->d); | |
181 | break; |
|
181 | break; | |
182 | } |
|
182 | } | |
183 | default: |
|
183 | default: | |
184 | break; |
|
184 | break; | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | // Update all the items to match the new visible area of the chart |
|
187 | // Update all the items to match the new visible area of the chart | |
188 | foreach(ChartItem* i, m_chartItems) |
|
188 | foreach(ChartItem* i, m_chartItems) | |
189 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
189 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
192 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
193 | { |
|
193 | { | |
194 | // TODO: support also other types; not only scatter and pie |
|
194 | // TODO: support also other types; not only scatter and pie | |
195 |
|
195 | |||
196 | QChartSeries *series(0); |
|
196 | QChartSeries *series(0); | |
197 |
|
197 | |||
198 | switch (type) { |
|
198 | switch (type) { | |
199 | case QChartSeries::SeriesTypeLine: { |
|
199 | case QChartSeries::SeriesTypeLine: { | |
200 | series = QXYChartSeries::create(); |
|
200 | series = QXYChartSeries::create(); | |
201 | break; |
|
201 | break; | |
202 | } |
|
202 | } | |
203 | case QChartSeries::SeriesTypeBar: { |
|
203 | case QChartSeries::SeriesTypeBar: { | |
204 | series = new BarChartSeries(this); |
|
204 | series = new BarChartSeries(this); | |
205 | break; |
|
205 | break; | |
206 | } |
|
206 | } | |
207 | case QChartSeries::SeriesTypeStackedBar: { |
|
207 | case QChartSeries::SeriesTypeStackedBar: { | |
208 | series = new StackedBarChartSeries(this); |
|
208 | series = new StackedBarChartSeries(this); | |
209 | break; |
|
209 | break; | |
210 | } |
|
210 | } | |
211 | case QChartSeries::SeriesTypePercentBar: { |
|
211 | case QChartSeries::SeriesTypePercentBar: { | |
212 | series = new PercentBarChartSeries(this); |
|
212 | series = new PercentBarChartSeries(this); | |
213 | break; |
|
213 | break; | |
214 | } |
|
214 | } | |
215 | case QChartSeries::SeriesTypeScatter: { |
|
215 | case QChartSeries::SeriesTypeScatter: { | |
216 | series = new QScatterSeries(this); |
|
216 | series = new QScatterSeries(this); | |
217 | break; |
|
217 | break; | |
218 | } |
|
218 | } | |
219 | case QChartSeries::SeriesTypePie: { |
|
219 | case QChartSeries::SeriesTypePie: { | |
220 | series = new QPieSeries(this); |
|
220 | series = new QPieSeries(this); | |
221 | break; |
|
221 | break; | |
222 | } |
|
222 | } | |
223 | default: |
|
223 | default: | |
224 | Q_ASSERT(false); |
|
224 | Q_ASSERT(false); | |
225 | break; |
|
225 | break; | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | addSeries(series); |
|
228 | addSeries(series); | |
229 | return series; |
|
229 | return series; | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) |
|
232 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) | |
233 | { |
|
233 | { | |
234 |
|
234 | |||
235 | if(!m_backgroundItem){ |
|
235 | if(!m_backgroundItem){ | |
236 | m_backgroundItem = new QGraphicsRectItem(this); |
|
236 | m_backgroundItem = new QGraphicsRectItem(this); | |
237 | m_backgroundItem->setZValue(-1); |
|
237 | m_backgroundItem->setZValue(-1); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | m_bacgroundOrinetation = orientation; |
|
240 | m_bacgroundOrinetation = orientation; | |
241 | m_backgroundGradient.setColorAt(0.0, startColor); |
|
241 | m_backgroundGradient.setColorAt(0.0, startColor); | |
242 | m_backgroundGradient.setColorAt(1.0, endColor); |
|
242 | m_backgroundGradient.setColorAt(1.0, endColor); | |
243 | m_backgroundGradient.setStart(0,0); |
|
243 | m_backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
244 |
|
244 | |||
245 | if(orientation == VerticalGradientOrientation){ |
|
245 | if(orientation == VerticalGradientOrientation){ | |
246 |
m_backgroundGradient.setFinalStop(0, |
|
246 | m_backgroundGradient.setFinalStop(0,1); | |
247 | }else{ |
|
247 | }else{ | |
248 |
m_backgroundGradient.setFinalStop( |
|
248 | m_backgroundGradient.setFinalStop(1,0); | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | m_backgroundItem->setBrush(m_backgroundGradient); |
|
251 | m_backgroundItem->setBrush(m_backgroundGradient); | |
252 | m_backgroundItem->setPen(Qt::NoPen); |
|
252 | m_backgroundItem->setPen(Qt::NoPen); | |
253 | m_backgroundItem->update(); |
|
253 | m_backgroundItem->update(); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
|
256 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |||
|
257 | { | |||
|
258 | ||||
|
259 | if(!m_backgroundItem){ | |||
|
260 | m_backgroundItem = new QGraphicsRectItem(this); | |||
|
261 | m_backgroundItem->setZValue(-1); | |||
|
262 | } | |||
|
263 | ||||
|
264 | m_backgroundItem->setBrush(brush); | |||
|
265 | m_backgroundItem->update(); | |||
|
266 | } | |||
|
267 | ||||
|
268 | void QChart::setChartBackgroundPen(const QPen& pen) | |||
|
269 | { | |||
|
270 | ||||
|
271 | if(!m_backgroundItem){ | |||
|
272 | m_backgroundItem = new QGraphicsRectItem(this); | |||
|
273 | m_backgroundItem->setZValue(-1); | |||
|
274 | } | |||
|
275 | ||||
|
276 | m_backgroundItem->setPen(pen); | |||
|
277 | m_backgroundItem->update(); | |||
|
278 | } | |||
|
279 | ||||
256 | void QChart::setTitle(const QString& title,const QFont& font) |
|
280 | void QChart::setTitle(const QString& title,const QFont& font) | |
257 | { |
|
281 | { | |
258 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
282 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
259 | m_titleItem->setPlainText(title); |
|
283 | m_titleItem->setPlainText(title); | |
260 | m_titleItem->setFont(font); |
|
284 | m_titleItem->setFont(font); | |
261 | } |
|
285 | } | |
262 |
|
286 | |||
263 | int QChart::margin() const |
|
287 | int QChart::margin() const | |
264 | { |
|
288 | { | |
265 | return m_marginSize; |
|
289 | return m_marginSize; | |
266 | } |
|
290 | } | |
267 |
|
291 | |||
268 | void QChart::setMargin(int margin) |
|
292 | void QChart::setMargin(int margin) | |
269 | { |
|
293 | { | |
270 | m_marginSize = margin; |
|
294 | m_marginSize = margin; | |
271 | } |
|
295 | } | |
272 |
|
296 | |||
273 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
297 | void QChart::setTheme(QChart::ChartThemeId theme) | |
274 | { |
|
298 | { | |
275 | m_chartTheme->setTheme(theme); |
|
299 | m_chartTheme->setTheme(theme); | |
276 | setBackground(m_chartTheme->d->m_gradientStartColor, |
|
300 | setBackground(m_chartTheme->d->m_gradientStartColor, | |
277 | m_chartTheme->d->m_gradientEndColor, |
|
301 | m_chartTheme->d->m_gradientEndColor, | |
278 | m_bacgroundOrinetation); |
|
302 | m_bacgroundOrinetation); | |
279 |
|
303 | |||
280 | // TODO: Move the controlling of the series presentations into private implementation of the |
|
304 | // TODO: Move the controlling of the series presentations into private implementation of the | |
281 | // series instead of QChart controlling themes for each |
|
305 | // series instead of QChart controlling themes for each | |
282 | // In other words, the following should be used when creating xy series: |
|
306 | // In other words, the following should be used when creating xy series: | |
283 | // m_chartTheme->addObserver(xyseries) |
|
307 | // m_chartTheme->addObserver(xyseries) | |
284 | foreach (QChartSeries *series, m_chartSeries) { |
|
308 | foreach (QChartSeries *series, m_chartSeries) { | |
285 | if (series->type() == QChartSeries::SeriesTypeLine) { |
|
309 | if (series->type() == QChartSeries::SeriesTypeLine) { | |
286 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); |
|
310 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); | |
287 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); |
|
311 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); | |
288 | xyseries->setPen(seriesTheme.linePen); |
|
312 | xyseries->setPen(seriesTheme.linePen); | |
289 | } |
|
313 | } | |
290 | } |
|
314 | } | |
291 |
|
315 | |||
292 | update(); |
|
316 | update(); | |
293 | } |
|
317 | } | |
294 |
|
318 | |||
295 | QChart::ChartThemeId QChart::theme() |
|
319 | QChart::ChartThemeId QChart::theme() | |
296 | { |
|
320 | { | |
297 | return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme; |
|
321 | return (QChart::ChartThemeId) m_chartTheme->d->m_currentTheme; | |
298 | } |
|
322 | } | |
299 |
|
323 | |||
300 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
324 | void QChart::zoomInToRect(const QRectF& rectangle) | |
301 | { |
|
325 | { | |
302 |
|
326 | |||
303 | if(!rectangle.isValid()) return; |
|
327 | if(!rectangle.isValid()) return; | |
304 |
|
328 | |||
305 | qreal margin = this->margin(); |
|
329 | qreal margin = this->margin(); | |
306 |
|
330 | |||
307 | QRectF rect = rectangle.normalized(); |
|
331 | QRectF rect = rectangle.normalized(); | |
308 | rect.translate(-margin, -margin); |
|
332 | rect.translate(-margin, -margin); | |
309 |
|
333 | |||
310 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; |
|
334 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; | |
311 |
|
335 | |||
312 | PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin); |
|
336 | PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin); | |
313 |
|
337 | |||
314 | m_plotDomainList.resize(m_plotDataIndex + 1); |
|
338 | m_plotDomainList.resize(m_plotDataIndex + 1); | |
315 | m_plotDomainList<<domain; |
|
339 | m_plotDomainList<<domain; | |
316 | m_plotDataIndex++; |
|
340 | m_plotDataIndex++; | |
317 |
|
341 | |||
318 | foreach (ChartItem* item, m_chartItems) |
|
342 | foreach (ChartItem* item, m_chartItems) | |
319 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
343 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
320 | update(); |
|
344 | update(); | |
321 | } |
|
345 | } | |
322 |
|
346 | |||
323 | void QChart::zoomIn() |
|
347 | void QChart::zoomIn() | |
324 | { |
|
348 | { | |
325 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { |
|
349 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { | |
326 | m_plotDataIndex++; |
|
350 | m_plotDataIndex++; | |
327 | foreach (ChartItem* item, m_chartItems) |
|
351 | foreach (ChartItem* item, m_chartItems) | |
328 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
352 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
329 | update(); |
|
353 | update(); | |
330 | } else { |
|
354 | } else { | |
331 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
355 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
332 | rect.setWidth(rect.width()/2); |
|
356 | rect.setWidth(rect.width()/2); | |
333 | rect.setHeight(rect.height()/2); |
|
357 | rect.setHeight(rect.height()/2); | |
334 | rect.moveCenter(m_rect.center()); |
|
358 | rect.moveCenter(m_rect.center()); | |
335 | zoomInToRect(rect); |
|
359 | zoomInToRect(rect); | |
336 | } |
|
360 | } | |
337 | } |
|
361 | } | |
338 |
|
362 | |||
339 | void QChart::zoomOut() |
|
363 | void QChart::zoomOut() | |
340 | { |
|
364 | { | |
341 | if (m_plotDataIndex > 0) { |
|
365 | if (m_plotDataIndex > 0) { | |
342 | m_plotDataIndex--; |
|
366 | m_plotDataIndex--; | |
343 | foreach (ChartItem* item, m_chartItems) |
|
367 | foreach (ChartItem* item, m_chartItems) | |
344 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
368 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
345 | update(); |
|
369 | update(); | |
346 | } |
|
370 | } | |
347 | } |
|
371 | } | |
348 |
|
372 | |||
349 | void QChart::zoomReset() |
|
373 | void QChart::zoomReset() | |
350 | { |
|
374 | { | |
351 | if (m_plotDataIndex > 0) { |
|
375 | if (m_plotDataIndex > 0) { | |
352 | m_plotDataIndex = 0; |
|
376 | m_plotDataIndex = 0; | |
353 | foreach (ChartItem* item, m_chartItems) |
|
377 | foreach (ChartItem* item, m_chartItems) | |
354 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
378 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
355 | update(); |
|
379 | update(); | |
356 | } |
|
380 | } | |
357 | } |
|
381 | } | |
358 |
|
382 | |||
359 | void QChart::setAxisX(const QChartAxis& axis) |
|
383 | void QChart::setAxisX(const QChartAxis& axis) | |
360 | { |
|
384 | { | |
361 | setAxis(m_axisXItem,axis); |
|
385 | setAxis(m_axisXItem,axis); | |
362 | } |
|
386 | } | |
363 | void QChart::setAxisY(const QChartAxis& axis) |
|
387 | void QChart::setAxisY(const QChartAxis& axis) | |
364 | { |
|
388 | { | |
365 | setAxis(m_axisYItem.at(0),axis); |
|
389 | setAxis(m_axisYItem.at(0),axis); | |
366 | } |
|
390 | } | |
367 |
|
391 | |||
368 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
|
392 | void QChart::setAxisY(const QList<QChartAxis>& axis) | |
369 | { |
|
393 | { | |
370 | //TODO not implemented |
|
394 | //TODO not implemented | |
371 | } |
|
395 | } | |
372 |
|
396 | |||
373 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) |
|
397 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) | |
374 | { |
|
398 | { | |
375 | item->setVisible(axis.isAxisVisible()); |
|
399 | item->setVisible(axis.isAxisVisible()); | |
376 | } |
|
400 | } | |
377 |
|
401 | |||
378 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
402 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
379 | { |
|
403 | { | |
380 |
|
404 | |||
381 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
405 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
382 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
406 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
383 |
|
407 | |||
384 | // recalculate title position |
|
408 | // recalculate title position | |
385 | if (m_titleItem) { |
|
409 | if (m_titleItem) { | |
386 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
410 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
387 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
411 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
388 | } |
|
412 | } | |
389 |
|
413 | |||
390 | //recalculate background gradient |
|
414 | //recalculate background gradient | |
391 | if (m_backgroundItem) { |
|
415 | if (m_backgroundItem) { | |
392 | m_backgroundItem->setRect(rect); |
|
416 | m_backgroundItem->setRect(rect); | |
393 | if (m_bacgroundOrinetation == HorizonatlGradientOrientation) |
|
|||
394 | m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(), 0); |
|
|||
395 | else |
|
|||
396 | m_backgroundGradient.setFinalStop(0, m_backgroundItem->rect().height()); |
|
|||
397 | m_backgroundItem->setBrush(m_backgroundGradient); |
|
|||
398 | } |
|
417 | } | |
399 |
|
418 | |||
400 | // resize and reposition childs |
|
419 | // resize and reposition childs | |
401 | foreach (ChartItem *item, m_chartItems) { |
|
420 | foreach (ChartItem *item, m_chartItems) { | |
402 | item->setPos(rect.topLeft()); |
|
421 | item->setPos(rect.topLeft()); | |
403 | item->setSize(rect.size()); |
|
422 | item->setSize(rect.size()); | |
404 | } |
|
423 | } | |
405 |
|
424 | |||
406 | QGraphicsWidget::resizeEvent(event); |
|
425 | QGraphicsWidget::resizeEvent(event); | |
407 | update(); |
|
426 | update(); | |
408 | } |
|
427 | } | |
409 |
|
428 | |||
410 |
|
429 | |||
411 |
|
430 | |||
412 | #include "moc_qchart.cpp" |
|
431 | #include "moc_qchart.cpp" | |
413 |
|
432 | |||
414 | QTCOMMERCIALCHART_END_NAMESPACE |
|
433 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,100 +1,103 | |||||
1 | #ifndef CHART_H |
|
1 | #ifndef CHART_H | |
2 | #define CHART_H |
|
2 | #define CHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QChartSeries; |
|
15 | class QChartSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarGroup; |
|
17 | class BarGroup; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 |
|
21 | |||
22 | // TODO: We don't need to have QChart tied to QGraphicsItem: |
|
22 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
23 | //class QTCOMMERCIALCHART_EXPORT QChart |
|
23 | //class QTCOMMERCIALCHART_EXPORT QChart | |
24 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { |
|
24 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
25 | // public: QChartGraphicsItem(QChart &chart); |
|
25 | // public: QChartGraphicsItem(QChart &chart); | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | * TODO: define the responsibilities |
|
28 | * TODO: define the responsibilities | |
29 | */ |
|
29 | */ | |
30 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
30 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | public: |
|
33 | public: | |
34 | enum GradientOrientation { |
|
34 | enum GradientOrientation { | |
35 | HorizonatlGradientOrientation, |
|
35 | HorizonatlGradientOrientation, | |
36 | VerticalGradientOrientation |
|
36 | VerticalGradientOrientation | |
37 | }; |
|
37 | }; | |
38 | enum ChartThemeId { |
|
38 | enum ChartThemeId { | |
39 | ChartThemeInvalid = -1, |
|
39 | ChartThemeInvalid = -1, | |
40 | /*! The default theme follows the GUI style of the Operating System */ |
|
40 | /*! The default theme follows the GUI style of the Operating System */ | |
41 | ChartThemeDefault, |
|
41 | ChartThemeDefault, | |
42 | ChartThemeVanilla, |
|
42 | ChartThemeVanilla, | |
43 | ChartThemeIcy, |
|
43 | ChartThemeIcy, | |
44 | ChartThemeGrayscale, |
|
44 | ChartThemeGrayscale, | |
45 | //ChartThemeScientific, |
|
45 | //ChartThemeScientific, | |
46 | ChartThemeUnnamed1 |
|
46 | ChartThemeUnnamed1 | |
47 | }; |
|
47 | }; | |
48 |
|
48 | |||
49 | public: |
|
49 | public: | |
50 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
50 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
51 | ~QChart(); |
|
51 | ~QChart(); | |
52 |
|
52 | |||
53 | void addSeries(QChartSeries* series); |
|
53 | void addSeries(QChartSeries* series); | |
54 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); |
|
54 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
55 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... |
|
55 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
56 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
56 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
57 |
|
57 | |||
58 | void setMargin(int margin); |
|
58 | void setMargin(int margin); | |
59 | int margin() const; |
|
59 | int margin() const; | |
60 | void setTheme(QChart::ChartThemeId theme); |
|
60 | void setTheme(QChart::ChartThemeId theme); | |
61 | QChart::ChartThemeId theme(); |
|
61 | QChart::ChartThemeId theme(); | |
62 |
|
62 | |||
63 | void setTitle(const QString& title,const QFont& font = QFont()); |
|
63 | void setTitle(const QString& title,const QFont& font = QFont()); | |
64 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, GradientOrientation orientation = VerticalGradientOrientation); |
|
64 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, GradientOrientation orientation = VerticalGradientOrientation); | |
65 |
|
65 | |||
|
66 | void setChartBackgroundBrush(const QBrush& brush); | |||
|
67 | void setChartBackgroundPen(const QPen& pen); | |||
|
68 | ||||
66 | void zoomInToRect(const QRectF& rectangle); |
|
69 | void zoomInToRect(const QRectF& rectangle); | |
67 | void zoomIn(); |
|
70 | void zoomIn(); | |
68 | void zoomOut(); |
|
71 | void zoomOut(); | |
69 | void zoomReset(); |
|
72 | void zoomReset(); | |
70 |
|
73 | |||
71 | void setAxisX(const QChartAxis& axis); |
|
74 | void setAxisX(const QChartAxis& axis); | |
72 | void setAxisY(const QChartAxis& axis); |
|
75 | void setAxisY(const QChartAxis& axis); | |
73 | void setAxisY(const QList<QChartAxis>& axis); |
|
76 | void setAxisY(const QList<QChartAxis>& axis); | |
74 |
|
77 | |||
75 | protected: |
|
78 | protected: | |
76 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
79 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
77 |
|
80 | |||
78 | private: |
|
81 | private: | |
79 | void setAxis(AxisItem *item, const QChartAxis& axis); |
|
82 | void setAxis(AxisItem *item, const QChartAxis& axis); | |
80 |
|
83 | |||
81 | private: |
|
84 | private: | |
82 | Q_DISABLE_COPY(QChart) |
|
85 | Q_DISABLE_COPY(QChart) | |
83 | QGraphicsRectItem* m_backgroundItem; |
|
86 | QGraphicsRectItem* m_backgroundItem; | |
84 | QLinearGradient m_backgroundGradient; |
|
87 | QLinearGradient m_backgroundGradient; | |
85 | GradientOrientation m_bacgroundOrinetation; |
|
88 | GradientOrientation m_bacgroundOrinetation; | |
86 | QGraphicsTextItem* m_titleItem; |
|
89 | QGraphicsTextItem* m_titleItem; | |
87 | AxisItem* m_axisXItem; |
|
90 | AxisItem* m_axisXItem; | |
88 | QList<AxisItem*> m_axisYItem; |
|
91 | QList<AxisItem*> m_axisYItem; | |
89 | QRectF m_rect; |
|
92 | QRectF m_rect; | |
90 | QList<QChartSeries *> m_chartSeries; |
|
93 | QList<QChartSeries *> m_chartSeries; | |
91 | QList<ChartItem *> m_chartItems; |
|
94 | QList<ChartItem *> m_chartItems; | |
92 | QVector<PlotDomain> m_plotDomainList; |
|
95 | QVector<PlotDomain> m_plotDomainList; | |
93 | int m_plotDataIndex; |
|
96 | int m_plotDataIndex; | |
94 | int m_marginSize; |
|
97 | int m_marginSize; | |
95 | ChartTheme *m_chartTheme; |
|
98 | ChartTheme *m_chartTheme; | |
96 | }; |
|
99 | }; | |
97 |
|
100 | |||
98 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE | |
99 |
|
102 | |||
100 | #endif |
|
103 | #endif |
@@ -1,77 +1,85 | |||||
1 | #include "qchartview.h" |
|
1 | #include "qchartview.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include <QGraphicsView> |
|
3 | #include <QGraphicsView> | |
4 | #include <QGraphicsScene> |
|
4 | #include <QGraphicsScene> | |
5 | #include <QRubberBand> |
|
5 | #include <QRubberBand> | |
6 | #include <QResizeEvent> |
|
6 | #include <QResizeEvent> | |
7 | #include <QDebug> |
|
7 | #include <QDebug> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | QChartView::QChartView(QWidget *parent) : |
|
11 | QChartView::QChartView(QWidget *parent) : | |
12 | QGraphicsView(parent), |
|
12 | QGraphicsView(parent), | |
13 | m_scene(new QGraphicsScene()), |
|
13 | m_scene(new QGraphicsScene()), | |
14 | m_chart(new QChart()) |
|
14 | m_chart(new QChart()) | |
15 | { |
|
15 | { | |
16 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
16 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
17 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
17 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
18 | setScene(m_scene); |
|
18 | setScene(m_scene); | |
19 | m_chart->setMargin(50); |
|
19 | m_chart->setMargin(50); | |
20 | m_scene->addItem(m_chart); |
|
20 | m_scene->addItem(m_chart); | |
21 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
21 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | QChartView::~QChartView() |
|
24 | QChartView::~QChartView() | |
25 | { |
|
25 | { | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | void QChartView::resizeEvent(QResizeEvent *event) |
|
28 | void QChartView::resizeEvent(QResizeEvent *event) | |
29 | { |
|
29 | { | |
30 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
30 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
31 | m_chart->resize(size()); |
|
31 | m_chart->resize(size()); | |
32 | QWidget::resizeEvent(event); |
|
32 | QWidget::resizeEvent(event); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | void QChartView::addSeries(QChartSeries* series) |
|
36 | void QChartView::addSeries(QChartSeries* series) | |
37 | { |
|
37 | { | |
38 | m_chart->addSeries(series); |
|
38 | m_chart->addSeries(series); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) |
|
41 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) | |
42 | { |
|
42 | { | |
43 |
|
43 | |||
44 | return m_chart->createSeries(type); |
|
44 | return m_chart->createSeries(type); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void QChartView::zoomInToRect(const QRect& rectangle) |
|
47 | void QChartView::zoomInToRect(const QRect& rectangle) | |
48 | { |
|
48 | { | |
49 | m_chart->zoomInToRect(rectangle); |
|
49 | m_chart->zoomInToRect(rectangle); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void QChartView::zoomIn() |
|
52 | void QChartView::zoomIn() | |
53 | { |
|
53 | { | |
54 | m_chart->zoomIn(); |
|
54 | m_chart->zoomIn(); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void QChartView::zoomOut() |
|
57 | void QChartView::zoomOut() | |
58 | { |
|
58 | { | |
59 | m_chart->zoomOut(); |
|
59 | m_chart->zoomOut(); | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | int QChartView::margin() const |
|
62 | int QChartView::margin() const | |
63 | { |
|
63 | { | |
64 | return m_chart->margin(); |
|
64 | return m_chart->margin(); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void QChartView::setTitle(const QString& title) |
|
67 | void QChartView::setTitle(const QString& title) | |
68 | { |
|
68 | { | |
69 | m_chart->setTitle(title); |
|
69 | m_chart->setTitle(title); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void QChartView::setBackground(const QColor& startColor, const QColor& endColor, QChart::GradientOrientation orientation) |
|
72 | void QChartView::setBackground(const QColor& startColor, const QColor& endColor, QChart::GradientOrientation orientation) | |
73 | { |
|
73 | { | |
74 | m_chart->setBackground(startColor,endColor,orientation); |
|
74 | m_chart->setBackground(startColor,endColor,orientation); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
|
77 | void QChartView::setChartBackgroundBrush(const QBrush& brush) | |||
|
78 | { | |||
|
79 | m_chart->setChartBackgroundBrush(brush); | |||
|
80 | } | |||
|
81 | void QChartView::setChartBackgroundPen(const QPen& pen) | |||
|
82 | { | |||
|
83 | m_chart->setChartBackgroundPen(pen); | |||
|
84 | } | |||
77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
85 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,53 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartseries.h" |
|
5 | #include "qchartseries.h" | |
6 | #include "qchart.h" |
|
6 | #include "qchart.h" | |
7 | #include <QGraphicsView> |
|
7 | #include <QGraphicsView> | |
8 |
|
8 | |||
9 | class QGraphicsScene; |
|
9 | class QGraphicsScene; | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | class QChart; |
|
13 | class QChart; | |
14 |
|
14 | |||
15 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
15 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
16 | { |
|
16 | { | |
17 | public: |
|
17 | public: | |
18 | explicit QChartView(QWidget *parent = 0); |
|
18 | explicit QChartView(QWidget *parent = 0); | |
19 | ~QChartView(); |
|
19 | ~QChartView(); | |
20 |
|
20 | |||
21 | //implement from QWidget |
|
21 | //implement from QWidget | |
22 | void resizeEvent(QResizeEvent *event); |
|
22 | void resizeEvent(QResizeEvent *event); | |
23 |
|
23 | |||
24 | void addSeries(QChartSeries* series); |
|
24 | void addSeries(QChartSeries* series); | |
25 | // Convenience function |
|
25 | // Convenience function | |
26 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
26 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
27 |
|
27 | |||
28 | int margin() const; |
|
28 | int margin() const; | |
29 | void setTitle(const QString& title); |
|
29 | void setTitle(const QString& title); | |
|
30 | ||||
|
31 | //Obsolete | |||
30 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, QChart::GradientOrientation orientation = QChart::VerticalGradientOrientation); |
|
32 | void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, QChart::GradientOrientation orientation = QChart::VerticalGradientOrientation); | |
|
33 | ||||
|
34 | ||||
|
35 | void setChartBackgroundBrush(const QBrush& brush); | |||
|
36 | void setChartBackgroundPen(const QPen& pen); | |||
|
37 | ||||
31 | void zoomInToRect(const QRect& rectangle); |
|
38 | void zoomInToRect(const QRect& rectangle); | |
32 | void zoomIn(); |
|
39 | void zoomIn(); | |
33 | void zoomOut(); |
|
40 | void zoomOut(); | |
34 |
|
41 | |||
35 | private: |
|
42 | private: | |
36 | QGraphicsScene *m_scene; |
|
43 | QGraphicsScene *m_scene; | |
37 | QChart* m_chart; |
|
44 | QChart* m_chart; | |
38 | QPoint m_origin; |
|
45 | QPoint m_origin; | |
39 | Q_DISABLE_COPY(QChartView) |
|
46 | Q_DISABLE_COPY(QChartView) | |
40 |
|
47 | |||
41 |
|
48 | |||
42 | }; |
|
49 | }; | |
43 |
|
50 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | QTCOMMERCIALCHART_END_NAMESPACE | |
45 |
|
52 | |||
46 | #endif // QCHARTWIDGET_H |
|
53 | #endif // QCHARTWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now