@@ -0,0 +1,20 | |||||
|
1 | #include "charttheme_p.h" | |||
|
2 | ||||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
4 | ||||
|
5 | class ChartThemeGrayscale: public ChartTheme | |||
|
6 | { | |||
|
7 | public: | |||
|
8 | ChartThemeGrayscale() | |||
|
9 | { | |||
|
10 | m_seriesColor.append(QRgb(0xFF869299)); | |||
|
11 | m_seriesColor.append(QRgb(0xFFA5BDCC)); | |||
|
12 | m_seriesColor.append(QRgb(0xFFE8FFFC)); | |||
|
13 | m_seriesColor.append(QRgb(0xFFCCC2C2)); | |||
|
14 | ||||
|
15 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |||
|
16 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |||
|
17 | } | |||
|
18 | }; | |||
|
19 | ||||
|
20 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,20 | |||||
|
1 | #include "charttheme_p.h" | |||
|
2 | ||||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
4 | ||||
|
5 | class ChartThemeIcy: public ChartTheme | |||
|
6 | { | |||
|
7 | public: | |||
|
8 | ChartThemeIcy() | |||
|
9 | { | |||
|
10 | m_seriesColor.append(QRgb(0xFF0D2673)); | |||
|
11 | m_seriesColor.append(QRgb(0xFF2685BF)); | |||
|
12 | m_seriesColor.append(QRgb(0xFF3DADD9)); | |||
|
13 | m_seriesColor.append(QRgb(0xFF62C3D9)); | |||
|
14 | ||||
|
15 | m_gradientStartColor = QColor(QRgb(0xffBDE3F2)); | |||
|
16 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |||
|
17 | } | |||
|
18 | }; | |||
|
19 | ||||
|
20 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,20 | |||||
|
1 | #include "charttheme_p.h" | |||
|
2 | ||||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
4 | ||||
|
5 | class ChartThemeScientific: public ChartTheme | |||
|
6 | { | |||
|
7 | public: | |||
|
8 | ChartThemeScientific() | |||
|
9 | { | |||
|
10 | m_seriesColor.append(QRgb(0xFF000000)); | |||
|
11 | m_seriesColor.append(QRgb(0xFFFFAD00)); | |||
|
12 | m_seriesColor.append(QRgb(0xFF596A75)); | |||
|
13 | m_seriesColor.append(QRgb(0xFF474747)); | |||
|
14 | ||||
|
15 | m_gradientStartColor = QColor(QRgb(0xffafafaf)); | |||
|
16 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |||
|
17 | } | |||
|
18 | }; | |||
|
19 | ||||
|
20 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,21 | |||||
|
1 | #include "charttheme_p.h" | |||
|
2 | ||||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
4 | ||||
|
5 | class ChartThemeVanilla: public ChartTheme | |||
|
6 | { | |||
|
7 | public: | |||
|
8 | ChartThemeVanilla() | |||
|
9 | { | |||
|
10 | m_seriesColor.append(QColor(217, 197, 116)); | |||
|
11 | m_seriesColor.append(QColor(214, 168, 150)); | |||
|
12 | m_seriesColor.append(QColor(160, 160, 113)); | |||
|
13 | m_seriesColor.append(QColor(210, 210, 52)); | |||
|
14 | m_seriesColor.append(QColor(136, 114, 58)); | |||
|
15 | ||||
|
16 | m_gradientStartColor = QColor(QRgb(0xff9d844d)); | |||
|
17 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |||
|
18 | } | |||
|
19 | }; | |||
|
20 | ||||
|
21 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,244 +1,251 | |||||
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 | //series |
|
6 | //series | |
6 | #include "barchartseries.h" |
|
7 | #include "barchartseries.h" | |
7 | #include "stackedbarchartseries.h" |
|
8 | #include "stackedbarchartseries.h" | |
8 | #include "percentbarchartseries.h" |
|
9 | #include "percentbarchartseries.h" | |
9 | #include "qxychartseries.h" |
|
10 | #include "qxychartseries.h" | |
10 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
11 | //items |
|
12 | //items | |
12 | #include "axisitem_p.h" |
|
13 | #include "axisitem_p.h" | |
13 | #include "bargroup.h" |
|
14 | #include "bargroup.h" | |
14 | #include "stackedbargroup.h" |
|
15 | #include "stackedbargroup.h" | |
15 | #include "xylinechartitem_p.h" |
|
16 | #include "xylinechartitem_p.h" | |
16 | #include "percentbargroup.h" |
|
17 | #include "percentbargroup.h" | |
17 | #include "linechartanimationitem_p.h" |
|
18 | #include "linechartanimationitem_p.h" | |
18 | #include "piepresentation.h" |
|
19 | #include "piepresentation.h" | |
19 |
|
20 | |||
20 | #include <QAbstractAnimation> |
|
21 | #include <QAbstractAnimation> | |
21 | #include <QPropertyAnimation> |
|
22 | #include <QPropertyAnimation> | |
22 |
|
23 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
25 | |||
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
26 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
26 | m_chart(chart), |
|
27 | m_chart(chart), | |
27 | m_dataset(dataset), |
|
28 | m_dataset(dataset), | |
|
29 | m_chartTheme(0), | |||
28 | m_domainIndex(0), |
|
30 | m_domainIndex(0), | |
29 | m_marginSize(0), |
|
31 | m_marginSize(0), | |
30 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
32 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
31 | { |
|
33 | { | |
|
34 | setTheme(QChart::ChartThemeDefault); | |||
32 | createConnections(); |
|
35 | createConnections(); | |
33 | createDeafultAxis(); |
|
36 | createDeafultAxis(); | |
34 | } |
|
37 | } | |
35 |
|
38 | |||
36 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
37 | { |
|
40 | { | |
38 | } |
|
41 | } | |
39 |
|
42 | |||
40 | void ChartPresenter::createDeafultAxis() |
|
43 | void ChartPresenter::createDeafultAxis() | |
41 | { |
|
44 | { | |
42 | //default axis |
|
45 | //default axis | |
43 | QChartAxis* axisX = new QChartAxis(this); |
|
46 | QChartAxis* axisX = new QChartAxis(this); | |
44 | QChartAxis* axisY = new QChartAxis(this); |
|
47 | QChartAxis* axisY = new QChartAxis(this); | |
45 |
|
48 | |||
46 | m_axis << new AxisItem(axisX,AxisItem::X_AXIS,m_chart); |
|
49 | m_axis << new AxisItem(axisX,AxisItem::X_AXIS,m_chart); | |
47 | m_axis << new AxisItem(axisY,AxisItem::Y_AXIS,m_chart); |
|
50 | m_axis << new AxisItem(axisY,AxisItem::Y_AXIS,m_chart); | |
48 |
|
51 | |||
49 | foreach(AxisItem* item, m_axis) { |
|
52 | foreach(AxisItem* item, m_axis) { | |
50 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
53 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
51 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
54 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
52 | } |
|
55 | } | |
53 | } |
|
56 | } | |
54 |
|
57 | |||
55 | void ChartPresenter::createConnections() |
|
58 | void ChartPresenter::createConnections() | |
56 | { |
|
59 | { | |
57 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
60 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
58 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
61 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
59 | } |
|
62 | } | |
60 |
|
63 | |||
61 | void ChartPresenter::handleGeometryChanged() |
|
64 | void ChartPresenter::handleGeometryChanged() | |
62 | { |
|
65 | { | |
63 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
66 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
64 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
67 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
65 | emit geometryChanged(m_rect); |
|
68 | emit geometryChanged(m_rect); | |
66 | } |
|
69 | } | |
67 |
|
70 | |||
68 | int ChartPresenter::margin() const |
|
71 | int ChartPresenter::margin() const | |
69 | { |
|
72 | { | |
70 | return m_marginSize; |
|
73 | return m_marginSize; | |
71 | } |
|
74 | } | |
72 |
|
75 | |||
73 | void ChartPresenter::setMargin(int margin) |
|
76 | void ChartPresenter::setMargin(int margin) | |
74 | { |
|
77 | { | |
75 | m_marginSize = margin; |
|
78 | m_marginSize = margin; | |
76 | } |
|
79 | } | |
77 |
|
80 | |||
78 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
81 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
79 | { |
|
82 | { | |
80 | switch(series->type()) |
|
83 | switch(series->type()) | |
81 | { |
|
84 | { | |
82 | case QChartSeries::SeriesTypeLine: { |
|
85 | case QChartSeries::SeriesTypeLine: { | |
83 | QXYChartSeries* lineSeries = static_cast<QXYChartSeries*>(series); |
|
86 | QXYChartSeries* lineSeries = static_cast<QXYChartSeries*>(series); | |
84 | XYLineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
87 | XYLineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
85 | item->setPen(lineSeries->pen()); |
|
88 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
86 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
89 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
87 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
90 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
88 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
91 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
89 | m_chartItems.insert(series,item); |
|
92 | m_chartItems.insert(series,item); | |
90 | break; |
|
93 | break; | |
91 | } |
|
94 | } | |
92 |
|
95 | |||
93 | case QChartSeries::SeriesTypeBar: { |
|
96 | case QChartSeries::SeriesTypeBar: { | |
94 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
97 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
95 | BarGroup* item = new BarGroup(*barSeries,m_chart); |
|
98 | BarGroup* item = new BarGroup(*barSeries,m_chart); | |
96 |
|
99 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | ||
97 | // Add some fugly colors for 5 fist series... |
|
|||
98 | item->addColor(QColor(255,0,0,128)); |
|
|||
99 | item->addColor(QColor(255,255,0,128)); |
|
|||
100 | item->addColor(QColor(0,255,0,128)); |
|
|||
101 | item->addColor(QColor(0,0,255,128)); |
|
|||
102 | item->addColor(QColor(255,128,0,128)); |
|
|||
103 |
|
||||
104 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
100 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
101 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
106 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
102 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
107 | m_chartItems.insert(series,item); |
|
103 | m_chartItems.insert(series,item); | |
108 | // m_axisXItem->setVisible(false); |
|
104 | // m_axisXItem->setVisible(false); | |
109 | break; |
|
105 | break; | |
110 | } |
|
106 | } | |
111 |
|
107 | |||
112 | case QChartSeries::SeriesTypeStackedBar: { |
|
108 | case QChartSeries::SeriesTypeStackedBar: { | |
113 |
|
109 | |||
114 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
110 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
115 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); |
|
111 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); | |
116 |
|
112 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | ||
117 | // Add some fugly colors for 5 fist series... |
|
|||
118 | item->addColor(QColor(255,0,0,128)); |
|
|||
119 | item->addColor(QColor(255,255,0,128)); |
|
|||
120 | item->addColor(QColor(0,255,0,128)); |
|
|||
121 | item->addColor(QColor(0,0,255,128)); |
|
|||
122 | item->addColor(QColor(255,128,0,128)); |
|
|||
123 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
113 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
124 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
114 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
125 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
115 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
126 | m_chartItems.insert(series,item); |
|
116 | m_chartItems.insert(series,item); | |
127 | break; |
|
117 | break; | |
128 | } |
|
118 | } | |
129 |
|
119 | |||
130 | case QChartSeries::SeriesTypePercentBar: { |
|
120 | case QChartSeries::SeriesTypePercentBar: { | |
131 |
|
121 | |||
132 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
122 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
133 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); |
|
123 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); | |
134 |
|
124 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | ||
135 | // Add some fugly colors for 5 fist series... |
|
|||
136 | item->addColor(QColor(255,0,0,128)); |
|
|||
137 | item->addColor(QColor(255,255,0,128)); |
|
|||
138 | item->addColor(QColor(0,255,0,128)); |
|
|||
139 | item->addColor(QColor(0,0,255,128)); |
|
|||
140 | item->addColor(QColor(255,128,0,128)); |
|
|||
141 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
125 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
142 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
126 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
143 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
127 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
144 | m_chartItems.insert(series,item); |
|
128 | m_chartItems.insert(series,item); | |
145 | break; |
|
129 | break; | |
146 | } |
|
130 | } | |
147 | /* |
|
131 | /* | |
148 | case QChartSeries::SeriesTypeScatter: { |
|
132 | case QChartSeries::SeriesTypeScatter: { | |
149 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
133 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
150 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
134 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
151 | scatterSeries->d->setParentItem(this); |
|
135 | scatterSeries->d->setParentItem(this); | |
152 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
136 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
153 | m_chartItems << scatterSeries->d; |
|
137 | m_chartItems << scatterSeries->d; | |
154 | m_chartTheme->addObserver(scatterSeries->d); |
|
138 | m_chartTheme->addObserver(scatterSeries->d); | |
155 |
|
139 | |||
156 | foreach (qreal x, scatterSeries->d->m_x) { |
|
140 | foreach (qreal x, scatterSeries->d->m_x) { | |
157 | domain.m_minX = qMin(domain.m_minX, x); |
|
141 | domain.m_minX = qMin(domain.m_minX, x); | |
158 | domain.m_maxX = qMax(domain.m_maxX, x); |
|
142 | domain.m_maxX = qMax(domain.m_maxX, x); | |
159 | } |
|
143 | } | |
160 | foreach (qreal y, scatterSeries->d->m_y) { |
|
144 | foreach (qreal y, scatterSeries->d->m_y) { | |
161 | domain.m_minY = qMin(domain.m_minY, y); |
|
145 | domain.m_minY = qMin(domain.m_minY, y); | |
162 | domain.m_maxY = qMax(domain.m_maxY, y); |
|
146 | domain.m_maxY = qMax(domain.m_maxY, y); | |
163 | } |
|
147 | } | |
164 |
|
148 | |||
165 | break; |
|
149 | break; | |
166 | } |
|
150 | } | |
167 | */ |
|
151 | */ | |
168 |
|
152 | |||
169 | case QChartSeries::SeriesTypePie: { |
|
153 | case QChartSeries::SeriesTypePie: { | |
170 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
154 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
171 | PiePresentation* pieChart = new PiePresentation(m_chart, pieSeries); |
|
155 | PiePresentation* pieChart = new PiePresentation(m_chart, pieSeries); | |
172 | pieSeries->m_piePresentation = pieChart; // TODO: remove this pointer passing use signals&slots |
|
156 | pieSeries->m_piePresentation = pieChart; // TODO: remove this pointer passing use signals&slots | |
173 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pieChart, SLOT(handleGeometryChanged(const QRectF&))); |
|
157 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pieChart, SLOT(handleGeometryChanged(const QRectF&))); | |
174 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pieChart, SLOT(handleDomainChanged(const Domain&))); |
|
158 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pieChart, SLOT(handleDomainChanged(const Domain&))); | |
175 | m_chartItems.insert(series, pieChart); |
|
159 | m_chartItems.insert(series, pieChart); | |
176 | break; |
|
160 | break; | |
177 | } |
|
161 | } | |
178 |
|
162 | |||
179 | default: { |
|
163 | default: { | |
180 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
164 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
181 | break; |
|
165 | break; | |
182 | } |
|
166 | } | |
183 | } |
|
167 | } | |
184 | } |
|
168 | } | |
185 |
|
169 | |||
186 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
170 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
187 | { |
|
171 | { | |
188 | //TODO: |
|
172 | //TODO: | |
189 | } |
|
173 | } | |
190 |
|
174 | |||
191 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
|
175 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |
192 | { |
|
176 | { | |
193 | if(!rect.isValid()) return; |
|
177 | if(!rect.isValid()) return; | |
194 | QRectF r = rect.normalized(); |
|
178 | QRectF r = rect.normalized(); | |
195 | r.translate(-m_marginSize, -m_marginSize); |
|
179 | r.translate(-m_marginSize, -m_marginSize); | |
196 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
180 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
197 | m_dataset->addDomain(domain); |
|
181 | m_dataset->addDomain(domain); | |
198 | } |
|
182 | } | |
199 |
|
183 | |||
200 | void ChartPresenter::zoomIn() |
|
184 | void ChartPresenter::zoomIn() | |
201 | { |
|
185 | { | |
202 | if (!m_dataset->nextDomain()) { |
|
186 | if (!m_dataset->nextDomain()) { | |
203 | QRectF rect = m_rect; |
|
187 | QRectF rect = m_rect; | |
204 | rect.setWidth(rect.width()/2); |
|
188 | rect.setWidth(rect.width()/2); | |
205 | rect.setHeight(rect.height()/2); |
|
189 | rect.setHeight(rect.height()/2); | |
206 | rect.moveCenter(m_rect.center()); |
|
190 | rect.moveCenter(m_rect.center()); | |
207 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
191 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
208 | m_dataset->addDomain(domain); |
|
192 | m_dataset->addDomain(domain); | |
209 | } |
|
193 | } | |
210 | } |
|
194 | } | |
211 |
|
195 | |||
212 | void ChartPresenter::zoomOut() |
|
196 | void ChartPresenter::zoomOut() | |
213 | { |
|
197 | { | |
214 | m_dataset->previousDomain(); |
|
198 | m_dataset->previousDomain(); | |
215 | } |
|
199 | } | |
216 |
|
200 | |||
217 | void ChartPresenter::zoomReset() |
|
201 | void ChartPresenter::zoomReset() | |
218 | { |
|
202 | { | |
219 | m_dataset->clearDomains(); |
|
203 | m_dataset->clearDomains(); | |
220 | } |
|
204 | } | |
221 |
|
205 | |||
|
206 | void ChartPresenter::setTheme(QChart::ChartThemeId theme) | |||
|
207 | { | |||
|
208 | delete m_chartTheme; | |||
|
209 | ||||
|
210 | m_chartTheme = ChartTheme::createTheme(theme); | |||
|
211 | ||||
|
212 | m_chartTheme->decorate(m_chart); | |||
|
213 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); | |||
|
214 | ||||
|
215 | int index=0; | |||
|
216 | while (i.hasNext()) { | |||
|
217 | i.next(); | |||
|
218 | index++; | |||
|
219 | m_chartTheme->decorate(i.value(),i.key(),index); | |||
|
220 | } | |||
|
221 | } | |||
|
222 | ||||
|
223 | ||||
|
224 | QChart::ChartThemeId ChartPresenter::theme() | |||
|
225 | { | |||
|
226 | return (QChart::ChartThemeId) 0; | |||
|
227 | } | |||
|
228 | ||||
222 | /* |
|
229 | /* | |
223 | void ChartPresenter::setAxisX(const QChartAxis& axis) |
|
230 | void ChartPresenter::setAxisX(const QChartAxis& axis) | |
224 | { |
|
231 | { | |
225 | setAxis(m_axisXItem,axis); |
|
232 | setAxis(m_axisXItem,axis); | |
226 | } |
|
233 | } | |
227 | void ChartPresenter::setAxisY(const QChartAxis& axis) |
|
234 | void ChartPresenter::setAxisY(const QChartAxis& axis) | |
228 | { |
|
235 | { | |
229 | setAxis(m_axisYItem.at(0),axis); |
|
236 | setAxis(m_axisYItem.at(0),axis); | |
230 | } |
|
237 | } | |
231 |
|
238 | |||
232 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) |
|
239 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) | |
233 | { |
|
240 | { | |
234 | //TODO not implemented |
|
241 | //TODO not implemented | |
235 | } |
|
242 | } | |
236 |
|
243 | |||
237 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) |
|
244 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) | |
238 | { |
|
245 | { | |
239 | item->setVisible(axis.isAxisVisible()); |
|
246 | item->setVisible(axis.isAxisVisible()); | |
240 | } |
|
247 | } | |
241 | */ |
|
248 | */ | |
242 | #include "moc_chartpresenter_p.cpp" |
|
249 | #include "moc_chartpresenter_p.cpp" | |
243 |
|
250 | |||
244 | QTCOMMERCIALCHART_END_NAMESPACE |
|
251 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,65 +1,72 | |||||
1 | #ifndef CHARTPRESENTER_H_ |
|
1 | #ifndef CHARTPRESENTER_H_ | |
2 | #define CHARTPRESENTER_H_ |
|
2 | #define CHARTPRESENTER_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
|
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |||
5 | #include <QRectF> |
|
6 | #include <QRectF> | |
6 |
|
7 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
9 | |||
9 | class ChartItem; |
|
10 | class ChartItem; | |
10 | class QChartSeries; |
|
11 | class QChartSeries; | |
11 | class ChartDataSet; |
|
12 | class ChartDataSet; | |
12 | class QChart; |
|
13 | //class QChart; | |
13 | class Domain; |
|
14 | class Domain; | |
14 | class AxisItem; |
|
15 | class AxisItem; | |
|
16 | class ChartTheme; | |||
15 |
|
17 | |||
16 | class ChartPresenter: public QObject |
|
18 | class ChartPresenter: public QObject | |
17 | { |
|
19 | { | |
18 | Q_OBJECT |
|
20 | Q_OBJECT | |
19 | public: |
|
21 | public: | |
20 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
22 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
21 | virtual ~ChartPresenter(); |
|
23 | virtual ~ChartPresenter(); | |
22 | /* |
|
24 | /* | |
23 | void setAxisX(const QChartAxis& axis); |
|
25 | void setAxisX(const QChartAxis& axis); | |
24 | void setAxisY(const QChartAxis& axis); |
|
26 | void setAxisY(const QChartAxis& axis); | |
25 | void setAxisY(const QList<QChartAxis>& axis); |
|
27 | void setAxisY(const QList<QChartAxis>& axis); | |
26 |
|
28 | |||
27 |
|
29 | |||
28 | */ |
|
30 | */ | |
29 |
|
31 | |||
30 | void setMargin(int margin); |
|
32 | void setMargin(int margin); | |
31 | int margin() const; |
|
33 | int margin() const; | |
32 |
|
34 | |||
33 | void zoomInToRect(const QRectF& rectangle); |
|
35 | void zoomInToRect(const QRectF& rectangle); | |
34 | void zoomIn(); |
|
36 | void zoomIn(); | |
35 | void zoomOut(); |
|
37 | void zoomOut(); | |
36 | void zoomReset(); |
|
38 | void zoomReset(); | |
37 |
|
39 | |||
|
40 | void setTheme(QChart::ChartThemeId theme); | |||
|
41 | QChart::ChartThemeId theme(); | |||
|
42 | ||||
38 | private: |
|
43 | private: | |
39 | void createConnections(); |
|
44 | void createConnections(); | |
40 | void createDeafultAxis(); |
|
45 | void createDeafultAxis(); | |
41 |
|
46 | |||
42 | public slots: |
|
47 | public slots: | |
43 | void handleSeriesAdded(QChartSeries* series); |
|
48 | void handleSeriesAdded(QChartSeries* series); | |
44 | void handleSeriesRemoved(QChartSeries* series){}; |
|
49 | void handleSeriesRemoved(QChartSeries* series){}; | |
45 | void handleSeriesChanged(QChartSeries* series); |
|
50 | void handleSeriesChanged(QChartSeries* series); | |
46 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); |
|
51 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); | |
47 | void handleGeometryChanged(); |
|
52 | void handleGeometryChanged(); | |
48 |
|
53 | |||
49 | signals: |
|
54 | signals: | |
50 | void geometryChanged(const QRectF& rect); |
|
55 | void geometryChanged(const QRectF& rect); | |
51 |
|
56 | |||
52 | private: |
|
57 | private: | |
53 | QMap<QChartSeries*,ChartItem*> m_chartItems; |
|
58 | QMap<QChartSeries*,ChartItem*> m_chartItems; | |
54 | QChart* m_chart; |
|
59 | QChart* m_chart; | |
55 | ChartDataSet* m_dataset; |
|
60 | ChartDataSet* m_dataset; | |
56 | QVector<Domain> m_domains; |
|
61 | QVector<Domain> m_domains; | |
57 | QList<AxisItem*> m_axis; |
|
62 | QList<AxisItem*> m_axis; | |
|
63 | ChartTheme *m_chartTheme; | |||
58 | int m_domainIndex; |
|
64 | int m_domainIndex; | |
59 | int m_marginSize; |
|
65 | int m_marginSize; | |
60 | QRectF m_rect; |
|
66 | QRectF m_rect; | |
|
67 | ||||
61 | }; |
|
68 | }; | |
62 |
|
69 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 |
|
71 | |||
65 | #endif /* CHARTPRESENTER_H_ */ |
|
72 | #endif /* CHARTPRESENTER_H_ */ |
@@ -1,112 +1,142 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 |
|
3 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
|||
5 |
|
||||
6 | void ChartThemeData::setTheme(int theme) |
|
|||
7 | { |
|
|||
8 | m_seriesThemes.clear(); |
|
|||
9 | m_seriesIndex = 0; |
|
|||
10 | m_currentTheme = theme; |
|
|||
11 |
|
4 | |||
12 | switch (theme) { |
|
5 | //series | |
13 | case QChart::ChartThemeDefault: |
|
6 | #include "barchartseries.h" | |
14 | // line: solid, dashed, dotted |
|
7 | #include "stackedbarchartseries.h" | |
15 | // line width: 1 |
|
8 | #include "percentbarchartseries.h" | |
16 | // line color (and opacity) |
|
9 | #include "qxychartseries.h" | |
17 | // line shadow (on/off) |
|
10 | //items | |
18 | // marker shape: "x", "o", "." |
|
11 | #include "axisitem_p.h" | |
19 | // TODO: define the default theme based on the OS |
|
12 | #include "bargroup.h" | |
20 | m_seriesThemes.append(SeriesTheme(QRgb(0xff000000), 2)); |
|
13 | #include "stackedbargroup.h" | |
21 | m_seriesThemes.append(SeriesTheme(QRgb(0xff707070), 2)); |
|
14 | #include "xylinechartitem_p.h" | |
22 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
15 | #include "percentbargroup.h" | |
23 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
|||
24 | break; |
|
|||
25 | case QChart::ChartThemeVanilla: |
|
|||
26 | m_seriesThemes.append(SeriesTheme(QColor(217, 197, 116), 6)); |
|
|||
27 | m_seriesThemes.append(SeriesTheme(QColor(214, 168, 150), 4)); |
|
|||
28 | m_seriesThemes.append(SeriesTheme(QColor(160, 160, 113), 6)); |
|
|||
29 | m_seriesThemes.append(SeriesTheme(QColor(210, 210, 52), 4)); |
|
|||
30 | m_seriesThemes.append(SeriesTheme(QColor(136, 114, 58), 6)); |
|
|||
31 |
|
16 | |||
32 | m_gradientStartColor = QColor(QRgb(0xff9d844d)); |
|
17 | //themes | |
33 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
18 | #include "chartthemevanilla_p.h" | |
34 | break; |
|
19 | #include "chartthemeicy_p.h" | |
35 | case QChart::ChartThemeIcy: |
|
20 | #include "chartthemegrayscale_p.h" | |
36 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF0D2673), 2)); |
|
21 | #include "chartthemescientific_p.h" | |
37 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF2685BF), 2)); |
|
|||
38 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF3DADD9), 3)); |
|
|||
39 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF62C3D9), 2)); |
|
|||
40 |
|
22 | |||
41 | m_gradientStartColor = QColor(QRgb(0xffBDE3F2)); |
|
|||
42 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
|||
43 | break; |
|
|||
44 | case QChart::ChartThemeGrayscale: |
|
|||
45 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF869299), 2)); |
|
|||
46 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFA5BDCC), 2)); |
|
|||
47 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFE8FFFC), 3)); |
|
|||
48 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFCCC2C2), 2)); |
|
|||
49 |
|
23 | |||
50 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
51 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
|||
52 | break; |
|
|||
53 | case QChart::ChartThemeScientific: |
|
|||
54 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF000000), 3)); |
|
|||
55 | m_seriesThemes.append(SeriesTheme(QRgb(0xFFFFAD00), 2)); |
|
|||
56 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF596A75), 2)); |
|
|||
57 | m_seriesThemes.append(SeriesTheme(QRgb(0xFF474747), 2)); |
|
|||
58 |
|
25 | |||
59 | m_gradientStartColor = QColor(QRgb(0xffafafaf)); |
|
26 | /* TODO | |
60 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
|||
61 | break; |
|
|||
62 | case QChart::ChartThemeUnnamed1: |
|
27 | case QChart::ChartThemeUnnamed1: | |
63 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
28 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); | |
64 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
|
29 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); | |
65 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); |
|
30 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); | |
66 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); |
|
31 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); | |
67 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); |
|
32 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); | |
68 |
|
|
33 | ||
69 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
34 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); | |
70 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
35 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
|
36 | */ | |||
|
37 | ||||
|
38 | ChartTheme::ChartTheme() | |||
|
39 | { | |||
|
40 | m_seriesColor.append(QRgb(0xff000000)); | |||
|
41 | m_seriesColor.append(QRgb(0xff707070)); | |||
|
42 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |||
|
43 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |||
|
44 | } | |||
|
45 | ||||
|
46 | ||||
|
47 | ChartTheme* ChartTheme::createTheme(QChart::ChartThemeId theme) | |||
|
48 | { | |||
|
49 | switch(theme) { | |||
|
50 | case QChart::ChartThemeDefault: | |||
|
51 | return new ChartTheme(); | |||
|
52 | case QChart::ChartThemeVanilla: | |||
|
53 | return new ChartThemeVanilla(); | |||
|
54 | case QChart::ChartThemeIcy: | |||
|
55 | return new ChartThemeIcy(); | |||
|
56 | case QChart::ChartThemeGrayscale: | |||
|
57 | return new ChartThemeGrayscale(); | |||
|
58 | case QChart::ChartThemeScientific: | |||
|
59 | return new ChartThemeScientific(); | |||
|
60 | } | |||
|
61 | } | |||
|
62 | ||||
|
63 | void ChartTheme::decorate(QChart* chart) | |||
|
64 | { | |||
|
65 | QLinearGradient backgroundGradient; | |||
|
66 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); | |||
|
67 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); | |||
|
68 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |||
|
69 | chart->setChartBackgroundBrush(backgroundGradient); | |||
|
70 | } | |||
|
71 | //TODO helper to by removed later | |||
|
72 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) | |||
|
73 | { | |||
|
74 | switch(series->type()) | |||
|
75 | { | |||
|
76 | case QChartSeries::SeriesTypeLine: { | |||
|
77 | QXYChartSeries* s = static_cast<QXYChartSeries*>(series); | |||
|
78 | XYLineChartItem* i = static_cast<XYLineChartItem*>(item); | |||
|
79 | decorate(i,s,count); | |||
|
80 | break; | |||
|
81 | } | |||
|
82 | case QChartSeries::SeriesTypeBar: { | |||
|
83 | BarChartSeries* b = static_cast<BarChartSeries*>(series); | |||
|
84 | BarGroup* i = static_cast<BarGroup*>(item); | |||
|
85 | decorate(i,b,count); | |||
|
86 | break; | |||
|
87 | } | |||
|
88 | case QChartSeries::SeriesTypeStackedBar: { | |||
|
89 | StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series); | |||
|
90 | StackedBarGroup* i = static_cast<StackedBarGroup*>(item); | |||
|
91 | decorate(i,s,count); | |||
|
92 | break; | |||
|
93 | } | |||
|
94 | case QChartSeries::SeriesTypePercentBar: { | |||
|
95 | PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series); | |||
|
96 | PercentBarGroup* i = static_cast<PercentBarGroup*>(item); | |||
|
97 | decorate(i,s,count); | |||
71 | break; |
|
98 | break; | |
|
99 | } | |||
72 | default: |
|
100 | default: | |
73 | Q_ASSERT(false); |
|
101 | qDebug()<<"Wrong item to be decorated by theme"; | |
74 | break; |
|
102 | break; | |
75 | } |
|
103 | } | |
|
104 | ||||
76 | } |
|
105 | } | |
77 |
|
106 | |||
78 | ChartTheme::ChartTheme(QObject *parent) : |
|
107 | void ChartTheme::decorate(XYLineChartItem* item, QXYChartSeries* series,int count) | |
79 | QObject(parent), |
|
|||
80 | d(new ChartThemeData()) |
|
|||
81 | { |
|
108 | { | |
82 | d->m_currentTheme = QChart::ChartThemeInvalid; |
|
109 | item->setPen(series->pen()); | |
83 | d->m_seriesIndex = 0; |
|
|||
84 | } |
|
110 | } | |
85 |
|
111 | |||
86 | void ChartTheme::setTheme(int theme) |
|
112 | void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) | |
87 | { |
|
113 | { | |
88 | if (theme != d->m_currentTheme) { |
|
114 | item->addColor(QColor(255,0,0,128)); | |
89 | d->setTheme(theme); |
|
115 | item->addColor(QColor(255,255,0,128)); | |
90 | foreach (ChartThemeObserver *o, d->m_observers) |
|
116 | item->addColor(QColor(0,255,0,128)); | |
91 | o->themeChanged(this); |
|
117 | item->addColor(QColor(0,0,255,128)); | |
92 | } |
|
118 | item->addColor(QColor(255,128,0,128)); | |
93 | } |
|
119 | } | |
94 |
|
120 | |||
95 | SeriesTheme ChartTheme::themeForSeries() |
|
121 | void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) | |
96 | { |
|
122 | { | |
97 | if (d->m_seriesThemes.count() == 0) { |
|
123 | // Add some fugly colors for 5 fist series... | |
98 | return SeriesTheme(); |
|
124 | item->addColor(QColor(255,0,0,128)); | |
99 | } else { |
|
125 | item->addColor(QColor(255,255,0,128)); | |
100 | // Get the next available theme for the series; if no more themes available start over |
|
126 | item->addColor(QColor(0,255,0,128)); | |
101 | // beginning from the first theme in the list |
|
127 | item->addColor(QColor(0,0,255,128)); | |
102 | SeriesTheme nextTheme = |
|
128 | item->addColor(QColor(255,128,0,128)); | |
103 | d->m_seriesThemes[d->m_seriesIndex % d->m_seriesThemes.count()]; |
|
|||
104 | d->m_seriesIndex++; |
|
|||
105 | return nextTheme; |
|
|||
106 | } |
|
|||
107 | } |
|
129 | } | |
108 |
|
130 | |||
|
131 | void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) | |||
|
132 | { | |||
|
133 | // Add some fugly colors for 5 fist series... | |||
|
134 | item->addColor(QColor(255,0,0,128)); | |||
|
135 | item->addColor(QColor(255,255,0,128)); | |||
|
136 | item->addColor(QColor(0,255,0,128)); | |||
|
137 | item->addColor(QColor(0,0,255,128)); | |||
|
138 | item->addColor(QColor(255,128,0,128)); | |||
|
139 | } | |||
109 |
|
140 | |||
110 | #include "moc_charttheme_p.cpp" |
|
|||
111 |
|
141 | |||
112 | QTCOMMERCIALCHART_END_NAMESPACE |
|
142 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,84 +1,43 | |||||
1 | #ifndef CHARTTHEME_H |
|
1 | #ifndef CHARTTHEME_H | |
2 | #define CHARTTHEME_H |
|
2 | #define CHARTTHEME_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QObject> |
|
5 | #include "qchart.h" | |
6 | #include <QSharedData> |
|
|||
7 | #include <QColor> |
|
6 | #include <QColor> | |
8 | #include <QLinearGradient> |
|
|||
9 | #include <QPen> |
|
|||
10 |
|
7 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
9 | |||
13 |
class Chart |
|
10 | class ChartItem; | |
14 |
|
11 | class QChartSeries; | ||
15 | class ChartThemeObserver |
|
12 | class XYLineChartItem; | |
16 | { |
|
13 | class QXYChartSeries; | |
17 | public: |
|
14 | class BarGroup; | |
18 | virtual void themeChanged(ChartTheme *theme) = 0; |
|
15 | class BarChartSeries; | |
19 | }; |
|
16 | class StackedBarGroup; | |
20 |
|
17 | class StackedBarChartSeries; | ||
21 | /*! |
|
18 | class PercentBarChartSeries; | |
22 | * The theme specific settings for the appearance of a series. TODO: These can be overridden by setting |
|
19 | class PercentBarGroup; | |
23 | * custom settings to a QChartSeries object. |
|
20 | ||
24 | */ |
|
21 | class ChartTheme | |
25 | struct SeriesTheme { |
|
|||
26 | public: |
|
|||
27 | SeriesTheme() : |
|
|||
28 | linePen(QPen()), |
|
|||
29 | markerPen(QPen()) {} |
|
|||
30 | SeriesTheme(QColor lineColor, qreal lineWidth/*, QPen marker*/) : |
|
|||
31 | linePen(QPen(QBrush(lineColor), lineWidth)), |
|
|||
32 | markerPen(linePen) {} |
|
|||
33 |
|
||||
34 | //const QBrush & brush, qreal width, Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap, Qt::PenJoinStyle join = Qt::BevelJo |
|
|||
35 | // TODO: |
|
|||
36 | //QColor lineColor; |
|
|||
37 | QPen linePen; |
|
|||
38 | //QBrush lineBrush; |
|
|||
39 | QPen markerPen; |
|
|||
40 | //QBrush markerBrush; |
|
|||
41 | }; |
|
|||
42 |
|
||||
43 | /*! |
|
|||
44 | * Explicitly shared data class for the themes. |
|
|||
45 | */ |
|
|||
46 | class ChartThemeData : public QSharedData |
|
|||
47 | { |
|
22 | { | |
|
23 | protected: | |||
|
24 | explicit ChartTheme(); | |||
48 | public: |
|
25 | public: | |
49 | ChartThemeData() : m_currentTheme(0) {} |
|
26 | static ChartTheme* createTheme(QChart::ChartThemeId theme); | |
50 | ~ChartThemeData() {} |
|
27 | void decorate(QChart* chart); | |
51 |
|
28 | void decorate(ChartItem* item, QChartSeries* series,int count); | ||
52 | public: |
|
29 | void decorate(XYLineChartItem* item, QXYChartSeries*, int count); | |
53 | void setTheme(int theme); |
|
30 | void decorate(BarGroup* item, BarChartSeries* series,int count); | |
54 |
|
31 | void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count); | ||
55 | public: |
|
32 | void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count); | |
56 | int m_currentTheme; |
|
33 | ||
57 | QList<ChartThemeObserver *> m_observers; |
|
34 | protected: | |
58 | QColor m_gradientStartColor; |
|
35 | QColor m_gradientStartColor; | |
59 | QColor m_gradientEndColor; |
|
36 | QColor m_gradientEndColor; | |
60 |
QList< |
|
37 | QList<QColor> m_seriesColor; | |
61 | int m_seriesIndex; |
|
|||
62 | }; |
|
|||
63 |
|
38 | |||
64 | class ChartTheme : public QObject |
|
|||
65 | { |
|
|||
66 | Q_OBJECT |
|
|||
67 | public: |
|
|||
68 | explicit ChartTheme(QObject *parent = 0); |
|
|||
69 | explicit ChartTheme(const ChartTheme &other, QObject *parent = 0) : QObject(parent), d(other.d) {} |
|
|||
70 | void operator =(const ChartTheme &other) { d = other.d; } |
|
|||
71 |
|
||||
72 | void setTheme(int theme); |
|
|||
73 | SeriesTheme themeForSeries(); |
|
|||
74 | void addObserver(ChartThemeObserver *o) { d->m_observers << o; } |
|
|||
75 |
|
||||
76 | public: |
|
|||
77 | // All the graphical elements of a QChart share the same theme settings |
|
|||
78 | // so let's use explicitly shared data |
|
|||
79 | QExplicitlySharedDataPointer<ChartThemeData> d; |
|
|||
80 | }; |
|
39 | }; | |
81 |
|
40 | |||
82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
41 | QTCOMMERCIALCHART_END_NAMESPACE | |
83 |
|
42 | |||
84 | #endif // CHARTTHEME_H |
|
43 | #endif // CHARTTHEME_H |
@@ -1,90 +1,91 | |||||
1 | #include "pieslice.h" |
|
1 | #include "pieslice.h" | |
2 | #include "piepresentation.h" |
|
2 | #include "piepresentation.h" | |
3 | #include <QPainter> |
|
3 | #include <QPainter> | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | PieSlice::PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span) |
|
8 | PieSlice::PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span) | |
9 | :QGraphicsItem(piePresentation), |
|
9 | :QGraphicsItem(piePresentation), | |
10 | m_seriesIndex(seriesIndex), |
|
10 | m_seriesIndex(seriesIndex), | |
11 | m_startAngle(startAngle), |
|
11 | m_startAngle(startAngle), | |
12 | m_span(span) |
|
12 | m_span(span) | |
13 | { |
|
13 | { | |
14 | Q_ASSERT(piePresentation); |
|
14 | Q_ASSERT(piePresentation); | |
15 | setAcceptHoverEvents(true); |
|
15 | setAcceptHoverEvents(true); | |
16 | setAcceptedMouseButtons(Qt::LeftButton); |
|
16 | setAcceptedMouseButtons(Qt::LeftButton); | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | PieSlice::~PieSlice() |
|
19 | PieSlice::~PieSlice() | |
20 | { |
|
20 | { | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | QRectF PieSlice::boundingRect() const |
|
23 | QRectF PieSlice::boundingRect() const | |
24 | { |
|
24 | { | |
25 | return shape().boundingRect(); |
|
25 | return shape().boundingRect(); | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | QPainterPath PieSlice::shape() const |
|
28 | QPainterPath PieSlice::shape() const | |
29 | { |
|
29 | { | |
30 | QRectF rect = (static_cast<PiePresentation*>(parentItem()))->pieRect(); |
|
30 | QRectF rect = (static_cast<PiePresentation*>(parentItem()))->pieRect(); | |
31 | qreal angle = (-m_startAngle) + (90); |
|
31 | qreal angle = (-m_startAngle) + (90); | |
32 | qreal span = -m_span; |
|
32 | qreal span = -m_span; | |
33 |
|
33 | |||
34 | QPainterPath path; |
|
34 | QPainterPath path; | |
35 | path.moveTo(rect.center()); |
|
35 | path.moveTo(rect.center()); | |
36 | path.arcTo(rect, angle, span); |
|
36 | path.arcTo(rect, angle, span); | |
37 |
|
37 | |||
38 | // TODO: draw the shape so that it might have a hole in the center |
|
38 | // TODO: draw the shape so that it might have a hole in the center | |
39 | // - Sin & Cos will be needed to find inner/outer arc endpoints |
|
39 | // - Sin & Cos will be needed to find inner/outer arc endpoints | |
40 |
|
40 | |||
41 | // dx, dy are offsets from the center |
|
41 | // dx, dy are offsets from the center | |
42 | //qreal l = boundingRect().height(); |
|
42 | //qreal l = boundingRect().height(); | |
43 | //qreal dx = qSin(angle*(M_PI/180)) * l; |
|
43 | //qreal dx = qSin(angle*(M_PI/180)) * l; | |
44 | //qreal dy = qCos(angle*(M_PI/180)) * l; |
|
44 | //qreal dy = qCos(angle*(M_PI/180)) * l; | |
45 |
|
45 | |||
46 | // TODO: exploded slice? |
|
46 | // TODO: exploded slice? | |
47 |
|
47 | |||
48 | return path; |
|
48 | return path; | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) |
|
51 | void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) | |
52 | { |
|
52 | { | |
53 | painter->setRenderHint(QPainter::Antialiasing); |
|
53 | painter->setRenderHint(QPainter::Antialiasing); | |
54 | // TODO: how to map theme settings to a pie slice? Now we |
|
54 | // TODO: how to map theme settings to a pie slice? Now we | |
55 | //painter->setPen(m_theme.linePen); |
|
55 | //painter->setPen(m_theme.linePen); | |
56 | // TODO: |
|
56 | // TODO: | |
57 |
|
57 | |||
58 | QPieSlice data = (static_cast<PiePresentation*>(parentItem()))->m_pieSeries->slice(m_seriesIndex); |
|
58 | QPieSlice data = (static_cast<PiePresentation*>(parentItem()))->m_pieSeries->slice(m_seriesIndex); | |
59 | painter->setBrush(data.m_color); |
|
59 | painter->setBrush(data.m_color); | |
60 |
|
60 | |||
|
61 | ||||
61 | //painter->setBrush(m_theme.linePen.color()); |
|
62 | //painter->setBrush(m_theme.linePen.color()); | |
62 |
|
63 | |||
63 | // From Qt docs: |
|
64 | // From Qt docs: | |
64 | // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). |
|
65 | // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). | |
65 | // Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. |
|
66 | // Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. | |
66 | // Zero degrees is at the 3 o'clock position. |
|
67 | // Zero degrees is at the 3 o'clock position. | |
67 | // |
|
68 | // | |
68 | // For sake of simplicity convert this so that zero degrees is at 12 o'clock and full circle is 360. |
|
69 | // For sake of simplicity convert this so that zero degrees is at 12 o'clock and full circle is 360. | |
69 | //qreal angle = (-m_startAngle*16) + (90*16); |
|
70 | //qreal angle = (-m_startAngle*16) + (90*16); | |
70 | //qreal span = -m_span*16; |
|
71 | //qreal span = -m_span*16; | |
71 | //painter->drawPie(boundingRect(), angle, span); |
|
72 | //painter->drawPie(boundingRect(), angle, span); | |
72 |
|
73 | |||
73 | painter->drawPath(shape()); |
|
74 | painter->drawPath(shape()); | |
74 |
|
75 | |||
75 | // Draw the label |
|
76 | // Draw the label | |
76 | // TODO: do this better |
|
77 | // TODO: do this better | |
77 | painter->drawText(boundingRect().center(), data.m_label); |
|
78 | painter->drawText(boundingRect().center(), data.m_label); | |
78 | } |
|
79 | } | |
79 |
|
80 | |||
80 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event) |
|
81 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event) | |
81 | { |
|
82 | { | |
82 | QGraphicsItem::hoverEnterEvent(event); |
|
83 | QGraphicsItem::hoverEnterEvent(event); | |
83 | qDebug() << "hover" << m_seriesIndex << m_startAngle << m_span; |
|
84 | qDebug() << "hover" << m_seriesIndex << m_startAngle << m_span; | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
87 | void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
87 | { |
|
88 | { | |
88 | QGraphicsItem::mousePressEvent(event); |
|
89 | QGraphicsItem::mousePressEvent(event); | |
89 | } |
|
90 | } | |
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,35 +1,36 | |||||
1 | #ifndef PIESLICE_H |
|
1 | #ifndef PIESLICE_H | |
2 | #define PIESLICE_H |
|
2 | #define PIESLICE_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 | #include <QRectF> |
|
7 | #include <QRectF> | |
8 | #include <QColor> |
|
8 | #include <QColor> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 | class PiePresentation; |
|
11 | class PiePresentation; | |
12 |
|
12 | |||
13 | class PieSlice : public QGraphicsItem |
|
13 | class PieSlice : public QGraphicsItem | |
14 | { |
|
14 | { | |
15 | public: |
|
15 | public: | |
16 | PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span); |
|
16 | PieSlice(PiePresentation *piePresentation, int seriesIndex, qreal startAngle, qreal span); | |
17 | ~PieSlice(); |
|
17 | ~PieSlice(); | |
18 |
|
18 | |||
19 | public: // from QGraphicsItem |
|
19 | public: // from QGraphicsItem | |
20 | QRectF boundingRect() const; |
|
20 | QRectF boundingRect() const; | |
21 | QPainterPath shape() const; |
|
21 | QPainterPath shape() const; | |
22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
23 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
23 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
24 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
24 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
25 |
|
25 | |||
26 | private: |
|
26 | private: | |
27 | int m_seriesIndex; |
|
27 | int m_seriesIndex; | |
28 | qreal m_startAngle; |
|
28 | qreal m_startAngle; | |
29 | qreal m_span; |
|
29 | qreal m_span; | |
|
30 | QRectF m_rect; | |||
30 | //SeriesTheme m_theme; |
|
31 | //SeriesTheme m_theme; | |
31 | }; |
|
32 | }; | |
32 |
|
33 | |||
33 | QTCOMMERCIALCHART_END_NAMESPACE |
|
34 | QTCOMMERCIALCHART_END_NAMESPACE | |
34 |
|
35 | |||
35 | #endif // PIESLICE_H |
|
36 | #endif // PIESLICE_H |
@@ -1,225 +1,195 | |||||
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 "qchartaxis.h" |
|
6 | #include "qchartaxis.h" | |
7 | #include "charttheme_p.h" |
|
7 | #include "charttheme_p.h" | |
8 | #include "chartitem_p.h" |
|
8 | #include "chartitem_p.h" | |
9 | #include "plotdomain_p.h" |
|
9 | #include "plotdomain_p.h" | |
10 | #include "axisitem_p.h" |
|
10 | #include "axisitem_p.h" | |
11 | #include "chartpresenter_p.h" |
|
11 | #include "chartpresenter_p.h" | |
12 | #include "chartdataset_p.h" |
|
12 | #include "chartdataset_p.h" | |
13 |
|
13 | |||
14 | //series |
|
14 | //series | |
15 | #include "barchartseries.h" |
|
15 | #include "barchartseries.h" | |
16 | #include "stackedbarchartseries.h" |
|
16 | #include "stackedbarchartseries.h" | |
17 | #include "percentbarchartseries.h" |
|
17 | #include "percentbarchartseries.h" | |
18 | #include "qxychartseries.h" |
|
18 | #include "qxychartseries.h" | |
19 |
|
19 | |||
20 |
|
||||
21 | #include <QGraphicsScene> |
|
20 | #include <QGraphicsScene> | |
22 | #include <QGraphicsSceneResizeEvent> |
|
21 | #include <QGraphicsSceneResizeEvent> | |
23 | #include <QDebug> |
|
22 | #include <QDebug> | |
24 |
|
23 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
25 | |||
27 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
26 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
28 |
|
|
27 | m_backgroundItem(0), | |
29 |
|
|
28 | m_titleItem(0), | |
30 | m_axisXItem(0), |
|
|||
31 | m_chartTheme(new ChartTheme(this)), |
|
|||
32 | //m_dataset(0), |
|
|||
33 |
|
|
29 | m_dataset(new ChartDataSet(this)), | |
34 | //m_presenter(0) |
|
|||
35 |
|
|
30 | m_presenter(new ChartPresenter(this,m_dataset)) | |
36 | { |
|
31 | { | |
37 | // TODO: the default theme? |
|
|||
38 | setTheme(QChart::ChartThemeDefault); |
|
|||
39 | //m_chartItems << m_axisXItem; |
|
|||
40 | //m_chartItems << m_axisYItem.at(0); |
|
|||
41 | } |
|
32 | } | |
42 |
|
33 | |||
43 | QChart::~QChart(){} |
|
34 | QChart::~QChart() {} | |
44 |
|
35 | |||
45 | void QChart::addSeries(QChartSeries* series) |
|
36 | void QChart::addSeries(QChartSeries* series) | |
46 | { |
|
37 | { | |
47 | m_dataset->addSeries(series); |
|
38 | m_dataset->addSeries(series); | |
48 | } |
|
39 | } | |
49 |
|
40 | |||
|
41 | //TODO on review, is it really needed ?? | |||
50 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
42 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
51 | { |
|
43 | { | |
52 | // TODO: support also other types; not only scatter and pie |
|
44 | // TODO: support also other types; not only scatter and pie | |
53 |
|
45 | |||
54 | QChartSeries *series(0); |
|
46 | QChartSeries *series(0); | |
55 |
|
47 | |||
56 | switch (type) { |
|
48 | switch (type) { | |
57 | case QChartSeries::SeriesTypeLine: { |
|
49 | case QChartSeries::SeriesTypeLine: { | |
58 | series = QXYChartSeries::create(); |
|
50 | series = QXYChartSeries::create(); | |
59 | break; |
|
51 | break; | |
60 | } |
|
52 | } | |
61 | case QChartSeries::SeriesTypeBar: { |
|
53 | case QChartSeries::SeriesTypeBar: { | |
62 | series = new BarChartSeries(this); |
|
54 | series = new BarChartSeries(this); | |
63 | break; |
|
55 | break; | |
64 | } |
|
56 | } | |
65 | case QChartSeries::SeriesTypeStackedBar: { |
|
57 | case QChartSeries::SeriesTypeStackedBar: { | |
66 | series = new StackedBarChartSeries(this); |
|
58 | series = new StackedBarChartSeries(this); | |
67 | break; |
|
59 | break; | |
68 | } |
|
60 | } | |
69 | case QChartSeries::SeriesTypePercentBar: { |
|
61 | case QChartSeries::SeriesTypePercentBar: { | |
70 | series = new PercentBarChartSeries(this); |
|
62 | series = new PercentBarChartSeries(this); | |
71 | break; |
|
63 | break; | |
72 | } |
|
64 | } | |
73 | case QChartSeries::SeriesTypeScatter: { |
|
65 | case QChartSeries::SeriesTypeScatter: { | |
74 | series = new QScatterSeries(this); |
|
66 | series = new QScatterSeries(this); | |
75 | break; |
|
67 | break; | |
76 | } |
|
68 | } | |
77 | case QChartSeries::SeriesTypePie: { |
|
69 | case QChartSeries::SeriesTypePie: { | |
78 | series = new QPieSeries(this); |
|
70 | series = new QPieSeries(this); | |
79 | break; |
|
71 | break; | |
80 | } |
|
72 | } | |
81 | default: |
|
73 | default: | |
82 | Q_ASSERT(false); |
|
74 | Q_ASSERT(false); | |
83 | break; |
|
75 | break; | |
84 | } |
|
76 | } | |
85 |
|
77 | |||
86 | addSeries(series); |
|
78 | addSeries(series); | |
87 | return series; |
|
79 | return series; | |
88 | } |
|
80 | } | |
89 |
|
81 | |||
90 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
82 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
91 | { |
|
83 | { | |
92 |
|
84 | |||
93 | if(!m_backgroundItem){ |
|
85 | if(!m_backgroundItem) { | |
94 | m_backgroundItem = new QGraphicsRectItem(this); |
|
86 | m_backgroundItem = new QGraphicsRectItem(this); | |
95 | m_backgroundItem->setZValue(-1); |
|
87 | m_backgroundItem->setZValue(-1); | |
96 | } |
|
88 | } | |
97 |
|
89 | |||
98 | m_backgroundItem->setBrush(brush); |
|
90 | m_backgroundItem->setBrush(brush); | |
99 | m_backgroundItem->update(); |
|
91 | m_backgroundItem->update(); | |
100 | } |
|
92 | } | |
101 |
|
93 | |||
102 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
94 | void QChart::setChartBackgroundPen(const QPen& pen) | |
103 | { |
|
95 | { | |
104 |
|
96 | |||
105 | if(!m_backgroundItem){ |
|
97 | if(!m_backgroundItem) { | |
106 | m_backgroundItem = new QGraphicsRectItem(this); |
|
98 | m_backgroundItem = new QGraphicsRectItem(this); | |
107 | m_backgroundItem->setZValue(-1); |
|
99 | m_backgroundItem->setZValue(-1); | |
108 | } |
|
100 | } | |
109 |
|
101 | |||
110 | m_backgroundItem->setPen(pen); |
|
102 | m_backgroundItem->setPen(pen); | |
111 | m_backgroundItem->update(); |
|
103 | m_backgroundItem->update(); | |
112 | } |
|
104 | } | |
113 |
|
105 | |||
114 | void QChart::setTitle(const QString& title,const QFont& font) |
|
106 | void QChart::setTitle(const QString& title,const QFont& font) | |
115 | { |
|
107 | { | |
116 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
108 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
117 | m_titleItem->setPlainText(title); |
|
109 | m_titleItem->setPlainText(title); | |
118 | m_titleItem->setFont(font); |
|
110 | m_titleItem->setFont(font); | |
119 | } |
|
111 | } | |
120 |
|
112 | |||
121 | int QChart::margin() const |
|
113 | int QChart::margin() const | |
122 | { |
|
114 | { | |
123 | return m_presenter->margin(); |
|
115 | return m_presenter->margin(); | |
124 | } |
|
116 | } | |
125 |
|
117 | |||
126 | void QChart::setMargin(int margin) |
|
118 | void QChart::setMargin(int margin) | |
127 | { |
|
119 | { | |
128 | m_presenter->setMargin(margin); |
|
120 | m_presenter->setMargin(margin); | |
129 | } |
|
121 | } | |
130 |
|
122 | |||
131 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
123 | void QChart::setTheme(QChart::ChartThemeId theme) | |
132 | { |
|
124 | { | |
133 |
m_ |
|
125 | m_presenter->setTheme(theme); | |
134 |
|
||||
135 | QLinearGradient backgroundGradient; |
|
|||
136 | backgroundGradient.setColorAt(0.0, m_chartTheme->d->m_gradientStartColor); |
|
|||
137 | backgroundGradient.setColorAt(1.0, m_chartTheme->d->m_gradientEndColor); |
|
|||
138 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
|||
139 | setChartBackgroundBrush(backgroundGradient); |
|
|||
140 |
|
||||
141 | // TODO: Move the controlling of the series presentations into private implementation of the |
|
|||
142 | // series instead of QChart controlling themes for each |
|
|||
143 | // In other words, the following should be used when creating xy series: |
|
|||
144 | // m_chartTheme->addObserver(xyseries) |
|
|||
145 | foreach (QChartSeries *series, m_chartSeries) { |
|
|||
146 | if (series->type() == QChartSeries::SeriesTypeLine) { |
|
|||
147 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); |
|
|||
148 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); |
|
|||
149 | xyseries->setPen(seriesTheme.linePen); |
|
|||
150 | } |
|
|||
151 | } |
|
|||
152 |
|
||||
153 | update(); |
|
|||
154 | } |
|
126 | } | |
155 |
|
127 | |||
156 | QChart::ChartThemeId QChart::theme() |
|
128 | QChart::ChartThemeId QChart::theme() | |
157 | { |
|
129 | { | |
158 |
return (QChart::ChartThemeId) m_ |
|
130 | return (QChart::ChartThemeId) m_presenter->theme(); | |
159 | } |
|
131 | } | |
160 |
|
132 | |||
161 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
133 | void QChart::zoomInToRect(const QRectF& rectangle) | |
162 | { |
|
134 | { | |
163 | m_presenter->zoomInToRect(rectangle); |
|
135 | m_presenter->zoomInToRect(rectangle); | |
164 | } |
|
136 | } | |
165 |
|
137 | |||
166 | void QChart::zoomIn() |
|
138 | void QChart::zoomIn() | |
167 | { |
|
139 | { | |
168 | m_presenter->zoomIn(); |
|
140 | m_presenter->zoomIn(); | |
169 | } |
|
141 | } | |
170 |
|
142 | |||
171 | void QChart::zoomOut() |
|
143 | void QChart::zoomOut() | |
172 | { |
|
144 | { | |
173 | m_presenter->zoomOut(); |
|
145 | m_presenter->zoomOut(); | |
174 | } |
|
146 | } | |
175 |
|
147 | |||
176 | void QChart::zoomReset() |
|
148 | void QChart::zoomReset() | |
177 | { |
|
149 | { | |
178 | m_presenter->zoomReset(); |
|
150 | m_presenter->zoomReset(); | |
179 | } |
|
151 | } | |
180 |
|
152 | |||
181 | void QChart::setAxisX(const QChartAxis& axis) |
|
153 | void QChart::setAxisX(const QChartAxis& axis) | |
182 | { |
|
154 | { | |
183 | setAxis(m_axisXItem,axis); |
|
155 | ||
184 | } |
|
156 | } | |
185 | void QChart::setAxisY(const QChartAxis& axis) |
|
157 | void QChart::setAxisY(const QChartAxis& axis) | |
186 | { |
|
158 | { | |
187 | setAxis(m_axisYItem.at(0),axis); |
|
159 | ||
188 | } |
|
160 | } | |
189 |
|
161 | |||
190 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
|
162 | void QChart::setAxisY(const QList<QChartAxis>& axis) | |
191 | { |
|
163 | { | |
192 | //TODO not implemented |
|
164 | //TODO not implemented | |
193 | } |
|
165 | } | |
194 |
|
166 | |||
195 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) |
|
167 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) | |
196 | { |
|
168 | { | |
197 | item->setVisible(axis.isAxisVisible()); |
|
169 | ||
198 | } |
|
170 | } | |
199 |
|
171 | |||
200 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
172 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
201 | { |
|
173 | { | |
202 |
|
174 | |||
203 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
175 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
204 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
176 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
205 |
|
177 | |||
206 | // recalculate title position |
|
178 | // recalculate title position | |
207 | if (m_titleItem) { |
|
179 | if (m_titleItem) { | |
208 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
180 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
209 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
181 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
210 | } |
|
182 | } | |
211 |
|
183 | |||
212 | //recalculate background gradient |
|
184 | //recalculate background gradient | |
213 | if (m_backgroundItem) { |
|
185 | if (m_backgroundItem) { | |
214 | m_backgroundItem->setRect(rect); |
|
186 | m_backgroundItem->setRect(rect); | |
215 | } |
|
187 | } | |
216 |
|
188 | |||
217 | QGraphicsWidget::resizeEvent(event); |
|
189 | QGraphicsWidget::resizeEvent(event); | |
218 | update(); |
|
190 | update(); | |
219 | } |
|
191 | } | |
220 |
|
192 | |||
221 |
|
||||
222 |
|
||||
223 | #include "moc_qchart.cpp" |
|
193 | #include "moc_qchart.cpp" | |
224 |
|
194 | |||
225 | QTCOMMERCIALCHART_END_NAMESPACE |
|
195 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,99 +1,92 | |||||
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 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 |
|
23 | |||
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: |
|
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
25 | //class QTCOMMERCIALCHART_EXPORT QChart |
|
25 | //class QTCOMMERCIALCHART_EXPORT QChart | |
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { |
|
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
27 | // public: QChartGraphicsItem(QChart &chart); |
|
27 | // public: QChartGraphicsItem(QChart &chart); | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | * TODO: define the responsibilities |
|
30 | * TODO: define the responsibilities | |
31 | */ |
|
31 | */ | |
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | enum ChartThemeId { |
|
36 | enum ChartThemeId { | |
37 | ChartThemeInvalid = -1, |
|
37 | ChartThemeInvalid = -1, | |
38 | /*! The default theme follows the GUI style of the Operating System */ |
|
38 | /*! The default theme follows the GUI style of the Operating System */ | |
39 | ChartThemeDefault, |
|
39 | ChartThemeDefault, | |
40 | ChartThemeVanilla, |
|
40 | ChartThemeVanilla, | |
41 | ChartThemeIcy, |
|
41 | ChartThemeIcy, | |
42 | ChartThemeGrayscale, |
|
42 | ChartThemeGrayscale, | |
43 | ChartThemeScientific, |
|
43 | ChartThemeScientific, | |
44 | ChartThemeUnnamed1 |
|
44 | //ChartThemeUnnamed1 | |
45 | }; |
|
45 | }; | |
46 |
|
46 | |||
47 | public: |
|
47 | public: | |
48 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
48 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
49 | ~QChart(); |
|
49 | ~QChart(); | |
50 |
|
50 | |||
51 | void addSeries(QChartSeries* series); |
|
51 | void addSeries(QChartSeries* series); | |
52 |
|
52 | |||
53 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); |
|
53 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
54 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... |
|
54 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
55 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
55 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
56 |
|
56 | |||
57 | void setMargin(int margin); |
|
57 | void setMargin(int margin); | |
58 | int margin() const; |
|
58 | int margin() const; | |
59 | void setTheme(QChart::ChartThemeId theme); |
|
59 | void setTheme(QChart::ChartThemeId theme); | |
60 | QChart::ChartThemeId theme(); |
|
60 | QChart::ChartThemeId theme(); | |
61 |
|
61 | |||
62 | void setTitle(const QString& title,const QFont& font = QFont()); |
|
62 | void setTitle(const QString& title,const QFont& font = QFont()); | |
63 | void setChartBackgroundBrush(const QBrush& brush); |
|
63 | void setChartBackgroundBrush(const QBrush& brush); | |
64 | void setChartBackgroundPen(const QPen& pen); |
|
64 | void setChartBackgroundPen(const QPen& pen); | |
65 |
|
65 | |||
66 | void zoomInToRect(const QRectF& rectangle); |
|
66 | void zoomInToRect(const QRectF& rectangle); | |
67 | void zoomIn(); |
|
67 | void zoomIn(); | |
68 | void zoomOut(); |
|
68 | void zoomOut(); | |
69 | void zoomReset(); |
|
69 | void zoomReset(); | |
70 |
|
70 | |||
71 | void setAxisX(const QChartAxis& axis); |
|
71 | void setAxisX(const QChartAxis& axis); | |
72 | void setAxisY(const QChartAxis& axis); |
|
72 | void setAxisY(const QChartAxis& axis); | |
73 | void setAxisY(const QList<QChartAxis>& axis); |
|
73 | void setAxisY(const QList<QChartAxis>& axis); | |
74 |
|
74 | |||
75 | protected: |
|
75 | protected: | |
76 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
76 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
77 |
|
77 | |||
78 | private: |
|
78 | private: | |
79 | void setAxis(AxisItem *item, const QChartAxis& axis); |
|
79 | void setAxis(AxisItem *item, const QChartAxis& axis); | |
80 |
|
80 | |||
81 | private: |
|
81 | private: | |
82 | Q_DISABLE_COPY(QChart) |
|
82 | Q_DISABLE_COPY(QChart) | |
83 | QGraphicsRectItem* m_backgroundItem; |
|
83 | QGraphicsRectItem* m_backgroundItem; | |
84 | QGraphicsTextItem* m_titleItem; |
|
84 | QGraphicsTextItem* m_titleItem; | |
85 | AxisItem* m_axisXItem; |
|
|||
86 | QList<AxisItem*> m_axisYItem; |
|
|||
87 | QRectF m_rect; |
|
85 | QRectF m_rect; | |
88 | QList<QChartSeries *> m_chartSeries; |
|
|||
89 | QList<ChartItem *> m_chartItems; |
|
|||
90 | ChartTheme *m_chartTheme; |
|
|||
91 |
|
||||
92 |
|
||||
93 | ChartDataSet *m_dataset; |
|
86 | ChartDataSet *m_dataset; | |
94 | ChartPresenter *m_presenter; |
|
87 | ChartPresenter *m_presenter; | |
95 | }; |
|
88 | }; | |
96 |
|
89 | |||
97 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | QTCOMMERCIALCHART_END_NAMESPACE | |
98 |
|
91 | |||
99 | #endif |
|
92 | #endif |
@@ -1,140 +1,140 | |||||
1 | #include "qscatterseries.h" |
|
1 | #include "qscatterseries.h" | |
2 | #include "qscatterseries_p.h" |
|
2 | #include "qscatterseries_p.h" | |
3 | #include "qchart.h" |
|
3 | #include "qchart.h" | |
4 | #include <QPainter> |
|
4 | #include <QPainter> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | //#define QSeriesData QList<qreal> |
|
10 | //#define QSeriesData QList<qreal> | |
11 |
|
11 | |||
12 | QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) : |
|
12 | QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) : | |
13 | ChartItem(parent), |
|
13 | ChartItem(parent), | |
14 | m_boundingRect(), |
|
14 | m_boundingRect(), | |
15 | m_markerColor(QColor()), |
|
15 | m_markerColor(QColor()), | |
16 | m_visibleChartArea() |
|
16 | m_visibleChartArea() | |
17 | { |
|
17 | { | |
18 | if (parent) |
|
18 | if (parent) | |
19 | m_boundingRect = parent->boundingRect(); |
|
19 | m_boundingRect = parent->boundingRect(); | |
20 | } |
|
20 | } | |
21 |
|
21 | |||
22 | void QScatterSeriesPrivate::changeGeometry() |
|
22 | void QScatterSeriesPrivate::changeGeometry() | |
23 | { |
|
23 | { | |
24 | if (m_boundingRect.isValid()) { |
|
24 | if (m_boundingRect.isValid()) { | |
25 | prepareGeometryChange(); |
|
25 | prepareGeometryChange(); | |
26 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); |
|
26 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); | |
27 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); |
|
27 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); | |
28 | m_scenex.clear(); |
|
28 | m_scenex.clear(); | |
29 | m_sceney.clear(); |
|
29 | m_sceney.clear(); | |
30 |
|
30 | |||
31 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
|
31 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing | |
32 | foreach(qreal x, m_x) |
|
32 | foreach(qreal x, m_x) | |
33 | m_scenex.append(m_boundingRect.left() + x * scalex - m_visibleChartArea.m_minX * scalex); |
|
33 | m_scenex.append(m_boundingRect.left() + x * scalex - m_visibleChartArea.m_minX * scalex); | |
34 |
|
34 | |||
35 | foreach(qreal y, m_y) |
|
35 | foreach(qreal y, m_y) | |
36 | m_sceney.append(m_boundingRect.bottom() - y * scaley + m_visibleChartArea.m_minY * scaley); |
|
36 | m_sceney.append(m_boundingRect.bottom() - y * scaley + m_visibleChartArea.m_minY * scaley); | |
37 | } |
|
37 | } | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void QScatterSeriesPrivate::setSize(const QSizeF &size) |
|
40 | void QScatterSeriesPrivate::setSize(const QSizeF &size) | |
41 | { |
|
41 | { | |
42 | // m_boundingRect = QRectF(pos().x(), pos().y(), size.width(), size.height()); |
|
42 | // m_boundingRect = QRectF(pos().x(), pos().y(), size.width(), size.height()); | |
43 | m_boundingRect = QRectF(0, 0, size.width(), size.height()); |
|
43 | m_boundingRect = QRectF(0, 0, size.width(), size.height()); | |
44 | changeGeometry(); |
|
44 | changeGeometry(); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void QScatterSeriesPrivate::themeChanged(ChartTheme *theme) |
|
47 | void QScatterSeriesPrivate::themeChanged(ChartTheme *theme) | |
48 | { |
|
48 | { | |
49 | m_theme = theme->themeForSeries(); |
|
49 | //m_theme = theme->themeForSeries(); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain) |
|
52 | void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain) | |
53 | { |
|
53 | { | |
54 | m_visibleChartArea = plotDomain; |
|
54 | m_visibleChartArea = plotDomain; | |
55 | changeGeometry(); |
|
55 | changeGeometry(); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | QRectF QScatterSeriesPrivate::boundingRect() const |
|
58 | QRectF QScatterSeriesPrivate::boundingRect() const | |
59 | { |
|
59 | { | |
60 | return m_boundingRect; |
|
60 | return m_boundingRect; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) |
|
63 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) | |
64 | { |
|
64 | { | |
65 | // TODO: The opacity should be user definable? |
|
65 | // TODO: The opacity should be user definable? | |
66 | //brush.setColor(QColor(255, 82, 0, 100)); |
|
66 | //brush.setColor(QColor(255, 82, 0, 100)); | |
67 | if (m_markerColor.isValid()) { |
|
67 | if (m_markerColor.isValid()) { | |
68 | QPen pen = painter->pen(); |
|
68 | QPen pen = painter->pen(); | |
69 | QBrush brush = pen.brush(); |
|
69 | QBrush brush = pen.brush(); | |
70 | brush.setColor(m_markerColor); |
|
70 | brush.setColor(m_markerColor); | |
71 | pen.setBrush(brush); |
|
71 | pen.setBrush(brush); | |
72 | pen.setWidth(4); |
|
72 | pen.setWidth(4); | |
73 | painter->setPen(pen); |
|
73 | painter->setPen(pen); | |
74 | } |
|
74 | } | |
75 | else |
|
75 | else | |
76 | painter->setPen(m_theme.markerPen); |
|
76 | //painter->setPen(m_theme.markerPen); | |
77 | // brush.setColor(m_theme..lineColor); |
|
77 | // brush.setColor(m_theme..lineColor); | |
78 |
|
78 | |||
79 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize |
|
79 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize | |
80 | // event right after construction or maybe given a size during initialization |
|
80 | // event right after construction or maybe given a size during initialization | |
81 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
81 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | |
82 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
82 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | |
83 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); |
|
83 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); | |
84 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); |
|
84 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
88 | QScatterSeries::QScatterSeries(QObject *parent) : | |
89 | QChartSeries(parent), |
|
89 | QChartSeries(parent), | |
90 | d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent))) |
|
90 | d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent))) | |
91 | { |
|
91 | { | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | bool QScatterSeries::setData(QList<qreal> xlist, QList<qreal> ylist) |
|
94 | bool QScatterSeries::setData(QList<qreal> xlist, QList<qreal> ylist) | |
95 | { |
|
95 | { | |
96 | // TODO: validate data |
|
96 | // TODO: validate data | |
97 | d->m_x = xlist; |
|
97 | d->m_x = xlist; | |
98 | d->m_y = ylist; |
|
98 | d->m_y = ylist; | |
99 |
|
99 | |||
100 | // TODO: the following updates the visible chart area setting of the series, we would instead |
|
100 | // TODO: the following updates the visible chart area setting of the series, we would instead | |
101 | // need to update the _chart's_ visible area... this would require a callback or |
|
101 | // need to update the _chart's_ visible area... this would require a callback or | |
102 | // similar to the parenting QChart object... |
|
102 | // similar to the parenting QChart object... | |
103 | foreach (qreal x, d->m_x) { |
|
103 | foreach (qreal x, d->m_x) { | |
104 | d->m_visibleChartArea.m_minX = qMin(d->m_visibleChartArea.m_minX, x); |
|
104 | d->m_visibleChartArea.m_minX = qMin(d->m_visibleChartArea.m_minX, x); | |
105 | d->m_visibleChartArea.m_maxX = qMax(d->m_visibleChartArea.m_maxX, x); |
|
105 | d->m_visibleChartArea.m_maxX = qMax(d->m_visibleChartArea.m_maxX, x); | |
106 | } |
|
106 | } | |
107 | foreach (qreal y, d->m_y) { |
|
107 | foreach (qreal y, d->m_y) { | |
108 | d->m_visibleChartArea.m_minY = qMin(d->m_visibleChartArea.m_minY, y); |
|
108 | d->m_visibleChartArea.m_minY = qMin(d->m_visibleChartArea.m_minY, y); | |
109 | d->m_visibleChartArea.m_maxY = qMax(d->m_visibleChartArea.m_maxY, y); |
|
109 | d->m_visibleChartArea.m_maxY = qMax(d->m_visibleChartArea.m_maxY, y); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | d->changeGeometry(); |
|
112 | d->changeGeometry(); | |
113 |
|
113 | |||
114 | return true; |
|
114 | return true; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void QScatterSeries::setMarkerColor(QColor color) |
|
117 | void QScatterSeries::setMarkerColor(QColor color) | |
118 | { |
|
118 | { | |
119 | d->m_markerColor = color; |
|
119 | d->m_markerColor = color; | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | QColor QScatterSeries::markerColor() |
|
122 | QColor QScatterSeries::markerColor() | |
123 | { |
|
123 | { | |
124 | return d->m_markerColor; |
|
124 | return d->m_markerColor; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | // TODO: |
|
127 | // TODO: | |
128 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) |
|
128 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) | |
129 | //{ |
|
129 | //{ | |
130 | // d->rescale(xscale, yscale); |
|
130 | // d->rescale(xscale, yscale); | |
131 | //} |
|
131 | //} | |
132 |
|
132 | |||
133 | QScatterSeries::~QScatterSeries() |
|
133 | QScatterSeries::~QScatterSeries() | |
134 | { |
|
134 | { | |
135 | delete d; |
|
135 | delete d; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | #include "moc_qscatterseries.cpp" |
|
138 | #include "moc_qscatterseries.cpp" | |
139 |
|
139 | |||
140 | QTCOMMERCIALCHART_END_NAMESPACE |
|
140 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,47 +1,47 | |||||
1 | #ifndef QSCATTERSERIESPRIVATE_H |
|
1 | #ifndef QSCATTERSERIESPRIVATE_H | |
2 | #define QSCATTERSERIESPRIVATE_H |
|
2 | #define QSCATTERSERIESPRIVATE_H | |
3 |
|
3 | |||
4 | #include "qchartseries.h" |
|
4 | #include "qchartseries.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | #include "chartitem_p.h" |
|
6 | #include "chartitem_p.h" | |
7 | #include "plotdomain_p.h" |
|
7 | #include "plotdomain_p.h" | |
8 | #include <QGraphicsItem> |
|
8 | #include <QGraphicsItem> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | /*! |
|
12 | /*! | |
13 | * The PIMPL class of QScatterSeries. |
|
13 | * The PIMPL class of QScatterSeries. | |
14 | */ |
|
14 | */ | |
15 |
class QScatterSeriesPrivate : public ChartItem |
|
15 | class QScatterSeriesPrivate : public ChartItem | |
16 | { |
|
16 | { | |
17 | public: |
|
17 | public: | |
18 | QScatterSeriesPrivate(QGraphicsItem *parent); |
|
18 | QScatterSeriesPrivate(QGraphicsItem *parent); | |
19 |
|
19 | |||
20 | public: // from ChartObjectInterface |
|
20 | public: // from ChartObjectInterface | |
21 | void setSize(const QSizeF &size); |
|
21 | void setSize(const QSizeF &size); | |
22 | void setPlotDomain(const PlotDomain& data); |
|
22 | void setPlotDomain(const PlotDomain& data); | |
23 |
|
23 | |||
24 | public: // from ChartThemeObserver |
|
24 | public: // from ChartThemeObserver | |
25 | void themeChanged(ChartTheme *theme); |
|
25 | void themeChanged(ChartTheme *theme); | |
26 |
|
26 | |||
27 | public: // from QGraphicsItem |
|
27 | public: // from QGraphicsItem | |
28 | QRectF boundingRect() const; |
|
28 | QRectF boundingRect() const; | |
29 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
29 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
30 |
|
30 | |||
31 | public: |
|
31 | public: | |
32 | void changeGeometry(); |
|
32 | void changeGeometry(); | |
33 |
|
33 | |||
34 | QRectF m_boundingRect; |
|
34 | QRectF m_boundingRect; | |
35 | // TODO: use the chart data class instead of list of x and y values? |
|
35 | // TODO: use the chart data class instead of list of x and y values? | |
36 | QList<qreal> m_x; |
|
36 | QList<qreal> m_x; | |
37 | QList<qreal> m_y; |
|
37 | QList<qreal> m_y; | |
38 | QList<qreal> m_scenex; |
|
38 | QList<qreal> m_scenex; | |
39 | QList<qreal> m_sceney; |
|
39 | QList<qreal> m_sceney; | |
40 | QColor m_markerColor; |
|
40 | QColor m_markerColor; | |
41 | SeriesTheme m_theme; |
|
41 | //SeriesTheme m_theme; | |
42 | PlotDomain m_visibleChartArea; |
|
42 | PlotDomain m_visibleChartArea; | |
43 | }; |
|
43 | }; | |
44 |
|
44 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | QTCOMMERCIALCHART_END_NAMESPACE | |
46 |
|
46 | |||
47 | #endif // QSCATTERSERIESPRIVATE_H |
|
47 | #endif // QSCATTERSERIESPRIVATE_H |
@@ -1,132 +1,141 | |||||
1 | !include( ../common.pri ) { |
|
1 | !include( ../common.pri ) { | |
2 | error( Couldn't find the common.pri file! ) |
|
2 | error( Couldn't find the common.pri file! ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TARGET = QtCommercialChart |
|
5 | TARGET = QtCommercialChart | |
6 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
6 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
7 | TEMPLATE = lib |
|
7 | TEMPLATE = lib | |
8 | QT += core \ |
|
8 | QT += core \ | |
9 | gui |
|
9 | gui | |
10 |
|
10 | |||
11 | CONFIG += debug_and_release |
|
11 | CONFIG += debug_and_release | |
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
13 |
|
13 | |||
14 | SOURCES += \ |
|
14 | SOURCES += \ | |
15 | barchart/barchartseries.cpp \ |
|
15 | barchart/barchartseries.cpp \ | |
16 | barchart/bargroup.cpp \ |
|
16 | barchart/bargroup.cpp \ | |
17 | barchart/bar.cpp \ |
|
17 | barchart/bar.cpp \ | |
18 | barchart/stackedbarchartseries.cpp \ |
|
18 | barchart/stackedbarchartseries.cpp \ | |
19 | barchart/stackedbargroup.cpp \ |
|
19 | barchart/stackedbargroup.cpp \ | |
20 | barchart/percentbarchartseries.cpp \ |
|
20 | barchart/percentbarchartseries.cpp \ | |
21 | barchart/percentbargroup.cpp \ |
|
21 | barchart/percentbargroup.cpp \ | |
22 | barchart/barlabel.cpp \ |
|
22 | barchart/barlabel.cpp \ | |
23 | xylinechart/qxychartseries.cpp \ |
|
23 | xylinechart/qxychartseries.cpp \ | |
24 | xylinechart/xylinechartitem.cpp \ |
|
24 | xylinechart/xylinechartitem.cpp \ | |
25 | xylinechart/linechartanimationitem.cpp \ |
|
25 | xylinechart/linechartanimationitem.cpp \ | |
26 | piechart/qpieseries.cpp \ |
|
26 | piechart/qpieseries.cpp \ | |
27 | piechart/pieslice.cpp \ |
|
27 | piechart/pieslice.cpp \ | |
28 | piechart/piepresentation.cpp \ |
|
28 | piechart/piepresentation.cpp \ | |
29 | plotdomain.cpp \ |
|
29 | plotdomain.cpp \ | |
30 | qscatterseries.cpp \ |
|
30 | qscatterseries.cpp \ | |
31 | qchart.cpp \ |
|
31 | qchart.cpp \ | |
32 | axisitem.cpp \ |
|
32 | axisitem.cpp \ | |
33 | qchartview.cpp \ |
|
33 | qchartview.cpp \ | |
34 | qchartseries.cpp \ |
|
34 | qchartseries.cpp \ | |
35 | qchartaxis.cpp \ |
|
35 | qchartaxis.cpp \ | |
36 | charttheme.cpp \ |
|
36 | charttheme.cpp \ | |
37 | barchart/separator.cpp \ |
|
37 | barchart/separator.cpp \ | |
38 | barchart/bargroupbase.cpp \ |
|
38 | barchart/bargroupbase.cpp \ | |
39 | barchart/barchartseriesbase.cpp \ |
|
39 | barchart/barchartseriesbase.cpp \ | |
40 | chartdataset.cpp \ |
|
40 | chartdataset.cpp \ | |
41 | chartpresenter.cpp \ |
|
41 | chartpresenter.cpp \ | |
42 | domain.cpp |
|
42 | domain.cpp | |
43 |
|
43 | |||
44 |
|
44 | |||
45 |
|
45 | |||
46 | PRIVATE_HEADERS += \ |
|
46 | PRIVATE_HEADERS += \ | |
47 | xylinechart/xylinechartitem_p.h \ |
|
47 | xylinechart/xylinechartitem_p.h \ | |
48 | xylinechart/linechartanimationitem_p.h \ |
|
48 | xylinechart/linechartanimationitem_p.h \ | |
49 | barchart/barlabel_p.h \ |
|
49 | barchart/barlabel_p.h \ | |
50 | barchart/bar_p.h \ |
|
50 | barchart/bar_p.h \ | |
51 | barchart/separator_p.h \ |
|
51 | barchart/separator_p.h \ | |
52 | piechart/piepresentation.h \ |
|
52 | piechart/piepresentation.h \ | |
53 | piechart/pieslice.h \ |
|
53 | piechart/pieslice.h \ | |
54 | plotdomain_p.h \ |
|
54 | plotdomain_p.h \ | |
55 | qscatterseries_p.h \ |
|
55 | qscatterseries_p.h \ | |
56 | axisitem_p.h \ |
|
56 | axisitem_p.h \ | |
57 | chartitem_p.h \ |
|
57 | chartitem_p.h \ | |
58 | charttheme_p.h \ |
|
58 | charttheme_p.h \ | |
59 | chartdataset_p.h \ |
|
59 | chartdataset_p.h \ | |
60 | chartpresenter_p.h \ |
|
60 | chartpresenter_p.h \ | |
61 | domain_p.h |
|
61 | domain_p.h | |
62 |
|
62 | |||
63 | PUBLIC_HEADERS += \ |
|
63 | PUBLIC_HEADERS += \ | |
64 | qchartseries.h \ |
|
64 | qchartseries.h \ | |
65 | qscatterseries.h \ |
|
65 | qscatterseries.h \ | |
66 | qchart.h \ |
|
66 | qchart.h \ | |
67 | qchartglobal.h \ |
|
67 | qchartglobal.h \ | |
68 | xylinechart/qxychartseries.h \ |
|
68 | xylinechart/qxychartseries.h \ | |
69 | barchart/barchartseries.h \ |
|
69 | barchart/barchartseries.h \ | |
70 | barchart/bargroup.h \ |
|
70 | barchart/bargroup.h \ | |
71 | barchart/stackedbarchartseries.h \ |
|
71 | barchart/stackedbarchartseries.h \ | |
72 | barchart/stackedbargroup.h \ |
|
72 | barchart/stackedbargroup.h \ | |
73 | barchart/percentbarchartseries.h \ |
|
73 | barchart/percentbarchartseries.h \ | |
74 | barchart/percentbargroup.h \ |
|
74 | barchart/percentbargroup.h \ | |
75 | barchart/barchartseriesbase.h \ |
|
75 | barchart/barchartseriesbase.h \ | |
76 | barchart/bargroupbase.h \ |
|
76 | barchart/bargroupbase.h \ | |
77 | piechart/qpieseries.h \ |
|
77 | piechart/qpieseries.h \ | |
78 | qchartview.h \ |
|
78 | qchartview.h \ | |
79 | qchartaxis.h |
|
79 | qchartaxis.h | |
80 |
|
80 | |||
|
81 | THEMES += \ | |||
|
82 | themes/chartthemeicy_p.h \ | |||
|
83 | themes/chartthemegrayscale_p.h \ | |||
|
84 | themes/chartthemescientific_p.h \ | |||
|
85 | themes/chartthemevanilla_p.h \ | |||
|
86 | ||||
|
87 | ||||
81 | HEADERS += $$PUBLIC_HEADERS |
|
88 | HEADERS += $$PUBLIC_HEADERS | |
82 | HEADERS += $$PRIVATE_HEADERS |
|
89 | HEADERS += $$PRIVATE_HEADERS | |
|
90 | HEADERS += $$THEMES | |||
83 |
|
91 | |||
84 | INCLUDEPATH += xylinechart \ |
|
92 | INCLUDEPATH += xylinechart \ | |
85 | barchart \ |
|
93 | barchart \ | |
86 | piechart \ |
|
94 | piechart \ | |
|
95 | themes \ | |||
87 | . |
|
96 | . | |
88 |
|
97 | |||
89 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
98 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
90 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
99 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
91 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
100 | UI_DIR = $$CHART_BUILD_DIR/lib | |
92 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
101 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
93 |
|
102 | |||
94 |
|
103 | |||
95 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
104 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
96 |
|
105 | |||
97 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
106 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
98 | public_headers.files = $$PUBLIC_HEADERS |
|
107 | public_headers.files = $$PUBLIC_HEADERS | |
99 | target.path = $$[QT_INSTALL_LIBS] |
|
108 | target.path = $$[QT_INSTALL_LIBS] | |
100 | INSTALLS += target \ |
|
109 | INSTALLS += target \ | |
101 | public_headers |
|
110 | public_headers | |
102 |
|
111 | |||
103 |
|
112 | |||
104 | install_build_headers.name = bild_headers |
|
113 | install_build_headers.name = bild_headers | |
105 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
114 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
106 | install_build_headers.input = PUBLIC_HEADERS |
|
115 | install_build_headers.input = PUBLIC_HEADERS | |
107 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR |
|
116 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR | |
108 | install_build_headers.CONFIG += target_predeps no_link |
|
117 | install_build_headers.CONFIG += target_predeps no_link | |
109 | QMAKE_EXTRA_COMPILERS += install_build_headers |
|
118 | QMAKE_EXTRA_COMPILERS += install_build_headers | |
110 |
|
119 | |||
111 | chartversion.target = qchartversion_p.h |
|
120 | chartversion.target = qchartversion_p.h | |
112 | chartversion.commands = @echo "build_time" > $$chartversion.target; |
|
121 | chartversion.commands = @echo "build_time" > $$chartversion.target; | |
113 | chartversion.depends = $$HEADERS $$SOURCES |
|
122 | chartversion.depends = $$HEADERS $$SOURCES | |
114 | PRE_TARGETDEPS += qchartversion_p.h |
|
123 | PRE_TARGETDEPS += qchartversion_p.h | |
115 | QMAKE_CLEAN+= qchartversion_p.h |
|
124 | QMAKE_CLEAN+= qchartversion_p.h | |
116 | QMAKE_EXTRA_TARGETS += chartversion |
|
125 | QMAKE_EXTRA_TARGETS += chartversion | |
117 |
|
126 | |||
118 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
127 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
119 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
128 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
120 |
|
129 | |||
121 |
|
130 | |||
122 |
|
131 | |||
123 |
|
132 | |||
124 |
|
133 | |||
125 |
|
134 | |||
126 |
|
135 | |||
127 |
|
136 | |||
128 |
|
137 | |||
129 |
|
138 | |||
130 |
|
139 | |||
131 |
|
140 | |||
132 |
|
141 |
General Comments 0
You need to be logged in to leave comments.
Login now