@@ -1,39 +1,57 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <cmath> |
|
3 | #include <cmath> | |
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartview.h> |
|
5 | #include <qchartview.h> | |
6 | #include <qscatterseries.h> |
|
6 | #include <qscatterseries.h> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
9 |
|
9 | |||
10 | int main(int argc, char *argv[]) |
|
10 | int main(int argc, char *argv[]) | |
11 | { |
|
11 | { | |
12 | QApplication a(argc, argv); |
|
12 | QApplication a(argc, argv); | |
13 |
|
13 | |||
14 | // Create chart widget |
|
14 | // Create chart widget | |
15 | QChartView *chartWidget = new QChartView(); |
|
15 | QChartView *chartWidget = new QChartView(); | |
16 |
|
16 | |||
17 |
// |
|
17 | // Add scatter series with simple test data | |
18 | QScatterSeries *scatter = new QScatterSeries(); |
|
18 | QScatterSeries *scatter = new QScatterSeries(); | |
19 |
*scatter << QPointF(0.5, |
|
19 | *scatter << QPointF(0.5, 5.0) | |
20 |
<< QPointF(1.0, |
|
20 | << QPointF(1.0, 4.5) | |
21 |
<< QPointF(1. |
|
21 | << QPointF(1.0, 5.5) | |
22 |
<< QPointF( |
|
22 | << QPointF(1.5, 5.0) | |
|
23 | << QPointF(2.0, 4.5) | |||
|
24 | << QPointF(2.0, 5.5) | |||
|
25 | << QPointF(2.5, 5.0); | |||
23 | chartWidget->addSeries(scatter); |
|
26 | chartWidget->addSeries(scatter); | |
24 |
|
27 | |||
25 | // Add another scatter series with more complex data with random component |
|
28 | // Add another scatter series | |
|
29 | // - more data with random component | |||
26 | QScatterSeries *scatter2 = new QScatterSeries(); |
|
30 | QScatterSeries *scatter2 = new QScatterSeries(); | |
27 | for (qreal i(0.0); i < 20; i += 0.5) |
|
31 | for (qreal i(0.0); i < 20; i += 0.05) { | |
28 | (*scatter2) << QPointF(i + (qreal)(rand() % 100) / 100.0, |
|
32 | (*scatter2) << QPointF(i + (qreal)(rand() % 100) / 100.0, | |
29 | i + (qreal)(rand() % 100) / 100.0); |
|
33 | i + (qreal)(rand() % 100) / 100.0); | |
|
34 | } | |||
30 | chartWidget->addSeries(scatter2); |
|
35 | chartWidget->addSeries(scatter2); | |
|
36 | // Custom pen and brush (not those defined by the chart theme) | |||
|
37 | // - uses opaque color | |||
|
38 | QColor color("#2685BF"); | |||
|
39 | color.setAlpha(80); | |||
|
40 | QBrush brush(Qt::SolidPattern); | |||
|
41 | brush.setColor(color); | |||
|
42 | scatter2->setMarkerBrush(brush); | |||
|
43 | QPen pen; | |||
|
44 | pen.setColor(color); | |||
|
45 | pen.setWidth(2); | |||
|
46 | scatter2->setMarkerPen(pen); | |||
|
47 | // use a rectangle as the marker shape | |||
|
48 | scatter2->setMarkerShape(QScatterSeries::MarkerShapeRectangle); | |||
31 |
|
49 | |||
32 | // Use the chart widget as the central widget |
|
50 | // Use the chart widget as the central widget | |
33 | QMainWindow w; |
|
51 | QMainWindow w; | |
34 | w.resize(640, 480); |
|
52 | w.resize(640, 480); | |
35 | w.setCentralWidget(chartWidget); |
|
53 | w.setCentralWidget(chartWidget); | |
36 | w.show(); |
|
54 | w.show(); | |
37 |
|
55 | |||
38 | return a.exec(); |
|
56 | return a.exec(); | |
39 | } |
|
57 | } |
@@ -1,272 +1,269 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | //series |
|
6 | //series | |
7 | #include "barchartseries.h" |
|
7 | #include "barchartseries.h" | |
8 | #include "stackedbarchartseries.h" |
|
8 | #include "stackedbarchartseries.h" | |
9 | #include "percentbarchartseries.h" |
|
9 | #include "percentbarchartseries.h" | |
10 | #include "qlinechartseries.h" |
|
10 | #include "qlinechartseries.h" | |
11 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
12 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | //items |
|
13 | //items | |
14 | #include "axisitem_p.h" |
|
14 | #include "axisitem_p.h" | |
15 | #include "bargroup.h" |
|
15 | #include "bargroup.h" | |
16 | #include "stackedbargroup.h" |
|
16 | #include "stackedbargroup.h" | |
17 | #include "linechartitem_p.h" |
|
17 | #include "linechartitem_p.h" | |
18 | #include "percentbargroup.h" |
|
18 | #include "percentbargroup.h" | |
19 | #include "linechartanimationitem_p.h" |
|
19 | #include "linechartanimationitem_p.h" | |
20 | #include "piepresenter.h" |
|
20 | #include "piepresenter.h" | |
21 | #include "scatterpresenter_p.h" |
|
21 | #include "scatterpresenter_p.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
26 | m_chart(chart), |
|
26 | m_chart(chart), | |
27 | m_dataset(dataset), |
|
27 | m_dataset(dataset), | |
28 | m_chartTheme(0), |
|
28 | m_chartTheme(0), | |
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)), |
|
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)), | |
30 | m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)), |
|
30 | m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)), | |
31 | m_domainIndex(0), |
|
31 | m_domainIndex(0), | |
32 | m_marginSize(0), |
|
32 | m_marginSize(0), | |
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
34 | { |
|
34 | { | |
35 | setChartTheme(QChart::ChartThemeDefault); |
|
35 | setChartTheme(QChart::ChartThemeDefault); | |
36 | createConnections(); |
|
36 | createConnections(); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void ChartPresenter::createConnections() |
|
43 | void ChartPresenter::createConnections() | |
44 | { |
|
44 | { | |
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
47 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&))); |
|
47 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&))); | |
48 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&))); |
|
48 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&))); | |
49 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&))); |
|
49 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&))); | |
50 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&))); |
|
50 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&))); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void ChartPresenter::handleGeometryChanged() |
|
53 | void ChartPresenter::handleGeometryChanged() | |
54 | { |
|
54 | { | |
55 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
55 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
56 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
56 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
57 | Q_ASSERT(m_rect.isValid()); |
|
57 | Q_ASSERT(m_rect.isValid()); | |
58 | emit geometryChanged(m_rect); |
|
58 | emit geometryChanged(m_rect); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | int ChartPresenter::margin() const |
|
61 | int ChartPresenter::margin() const | |
62 | { |
|
62 | { | |
63 | return m_marginSize; |
|
63 | return m_marginSize; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void ChartPresenter::setMargin(int margin) |
|
66 | void ChartPresenter::setMargin(int margin) | |
67 | { |
|
67 | { | |
68 | m_marginSize = margin; |
|
68 | m_marginSize = margin; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
71 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
72 | { |
|
72 | { | |
73 | qDebug() << " ChartPresenter::handleSeriesAdded"; |
|
73 | qDebug() << " ChartPresenter::handleSeriesAdded"; | |
74 | switch(series->type()) |
|
74 | switch(series->type()) | |
75 | { |
|
75 | { | |
76 | case QChartSeries::SeriesTypeLine: { |
|
76 | case QChartSeries::SeriesTypeLine: { | |
77 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); |
|
77 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); | |
78 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
78 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
79 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
79 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
80 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
80 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
81 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
81 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
82 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
82 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
83 | m_chartItems.insert(series,item); |
|
83 | m_chartItems.insert(series,item); | |
84 | break; |
|
84 | break; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | case QChartSeries::SeriesTypeBar: { |
|
87 | case QChartSeries::SeriesTypeBar: { | |
88 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
88 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
89 | BarGroup* item = new BarGroup(barSeries->model(),m_chart); |
|
89 | BarGroup* item = new BarGroup(barSeries->model(),m_chart); | |
90 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
90 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
91 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
91 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
92 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
92 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
93 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
93 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
94 | m_chartItems.insert(series,item); |
|
94 | m_chartItems.insert(series,item); | |
95 | // m_axisXItem->setVisible(false); |
|
95 | // m_axisXItem->setVisible(false); | |
96 | break; |
|
96 | break; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | case QChartSeries::SeriesTypeStackedBar: { |
|
99 | case QChartSeries::SeriesTypeStackedBar: { | |
100 |
|
100 | |||
101 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
101 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
102 | StackedBarGroup* item = new StackedBarGroup(stackedBarSeries->model(),m_chart); |
|
102 | StackedBarGroup* item = new StackedBarGroup(stackedBarSeries->model(),m_chart); | |
103 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
103 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
104 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
104 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
106 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
106 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
107 | m_chartItems.insert(series,item); |
|
107 | m_chartItems.insert(series,item); | |
108 | break; |
|
108 | break; | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | case QChartSeries::SeriesTypePercentBar: { |
|
111 | case QChartSeries::SeriesTypePercentBar: { | |
112 |
|
112 | |||
113 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
113 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
114 | PercentBarGroup* item = new PercentBarGroup(percentBarSeries->model(),m_chart); |
|
114 | PercentBarGroup* item = new PercentBarGroup(percentBarSeries->model(),m_chart); | |
115 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
115 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
116 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
116 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
117 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
117 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
118 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
118 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
119 | m_chartItems.insert(series,item); |
|
119 | m_chartItems.insert(series,item); | |
120 | break; |
|
120 | break; | |
121 | } |
|
121 | } | |
122 | case QChartSeries::SeriesTypeScatter: { |
|
122 | case QChartSeries::SeriesTypeScatter: { | |
123 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
123 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
124 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
124 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); | |
125 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
125 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
126 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
126 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
127 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), |
|
127 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), | |
128 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); |
|
128 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); | |
129 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
129 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); | |
130 | // scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
|||
131 | // scatterSeries->d->setParentItem(this); |
|
|||
132 | // scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
|||
133 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
130 | m_chartItems.insert(scatterSeries, scatterPresenter); | |
134 | break; |
|
131 | break; | |
135 | } |
|
132 | } | |
136 | case QChartSeries::SeriesTypePie: { |
|
133 | case QChartSeries::SeriesTypePie: { | |
137 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
134 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
138 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
135 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
139 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
136 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
140 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
137 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
141 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); |
|
138 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); | |
142 | m_chartItems.insert(series, pie); |
|
139 | m_chartItems.insert(series, pie); | |
143 | break; |
|
140 | break; | |
144 | } |
|
141 | } | |
145 | default: { |
|
142 | default: { | |
146 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
143 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
147 | break; |
|
144 | break; | |
148 | } |
|
145 | } | |
149 | } |
|
146 | } | |
150 |
|
147 | |||
151 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
148 | if(m_rect.isValid()) emit geometryChanged(m_rect); | |
152 | } |
|
149 | } | |
153 |
|
150 | |||
154 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
151 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
155 | { |
|
152 | { | |
156 | //TODO: |
|
153 | //TODO: | |
157 | } |
|
154 | } | |
158 |
|
155 | |||
159 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
|
156 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |
160 | { |
|
157 | { | |
161 | if(!rect.isValid()) return; |
|
158 | if(!rect.isValid()) return; | |
162 | QRectF r = rect.normalized(); |
|
159 | QRectF r = rect.normalized(); | |
163 | r.translate(-m_marginSize, -m_marginSize); |
|
160 | r.translate(-m_marginSize, -m_marginSize); | |
164 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); |
|
161 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); | |
165 | m_dataset->addDomain(domain); |
|
162 | m_dataset->addDomain(domain); | |
166 | } |
|
163 | } | |
167 |
|
164 | |||
168 | void ChartPresenter::zoomIn() |
|
165 | void ChartPresenter::zoomIn() | |
169 | { |
|
166 | { | |
170 | if (!m_dataset->nextDomain()) { |
|
167 | if (!m_dataset->nextDomain()) { | |
171 | QRectF rect = m_rect; |
|
168 | QRectF rect = m_rect; | |
172 | rect.setWidth(rect.width()/2); |
|
169 | rect.setWidth(rect.width()/2); | |
173 | rect.setHeight(rect.height()/2); |
|
170 | rect.setHeight(rect.height()/2); | |
174 | rect.moveCenter(m_rect.center()); |
|
171 | rect.moveCenter(m_rect.center()); | |
175 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
172 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
176 | m_dataset->addDomain(domain); |
|
173 | m_dataset->addDomain(domain); | |
177 | } |
|
174 | } | |
178 | } |
|
175 | } | |
179 |
|
176 | |||
180 | void ChartPresenter::zoomOut() |
|
177 | void ChartPresenter::zoomOut() | |
181 | { |
|
178 | { | |
182 | m_dataset->previousDomain(); |
|
179 | m_dataset->previousDomain(); | |
183 | } |
|
180 | } | |
184 |
|
181 | |||
185 | void ChartPresenter::zoomReset() |
|
182 | void ChartPresenter::zoomReset() | |
186 | { |
|
183 | { | |
187 | m_dataset->clearDomains(); |
|
184 | m_dataset->clearDomains(); | |
188 | } |
|
185 | } | |
189 |
|
186 | |||
190 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
187 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
191 | { |
|
188 | { | |
192 | delete m_chartTheme; |
|
189 | delete m_chartTheme; | |
193 |
|
190 | |||
194 | m_chartTheme = ChartTheme::createTheme(theme); |
|
191 | m_chartTheme = ChartTheme::createTheme(theme); | |
195 |
|
192 | |||
196 | m_chartTheme->decorate(m_chart); |
|
193 | m_chartTheme->decorate(m_chart); | |
197 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); |
|
194 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); | |
198 |
|
195 | |||
199 | int index=0; |
|
196 | int index=0; | |
200 | while (i.hasNext()) { |
|
197 | while (i.hasNext()) { | |
201 | i.next(); |
|
198 | i.next(); | |
202 | index++; |
|
199 | index++; | |
203 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
200 | m_chartTheme->decorate(i.value(),i.key(),index); | |
204 | } |
|
201 | } | |
205 |
|
202 | |||
206 | m_chartTheme->decorate(m_axisX, m_axisXItem); |
|
203 | m_chartTheme->decorate(m_axisX, m_axisXItem); | |
207 | m_chartTheme->decorate(m_axisY, m_axisYItem); |
|
204 | m_chartTheme->decorate(m_axisY, m_axisYItem); | |
208 |
|
205 | |||
209 | } |
|
206 | } | |
210 |
|
207 | |||
211 |
|
208 | |||
212 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
209 | QChart::ChartTheme ChartPresenter::chartTheme() | |
213 | { |
|
210 | { | |
214 | return m_chartTheme->id(); |
|
211 | return m_chartTheme->id(); | |
215 | } |
|
212 | } | |
216 |
|
213 | |||
217 | void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) |
|
214 | void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) | |
218 | { |
|
215 | { | |
219 | //if(m_axisX != axis) { |
|
216 | //if(m_axisX != axis) { | |
220 | m_axisX = axis; |
|
217 | m_axisX = axis; | |
221 | m_axisXItem->handleAxisChanged(m_axisX); |
|
218 | m_axisXItem->handleAxisChanged(m_axisX); | |
222 | //} |
|
219 | //} | |
223 | } |
|
220 | } | |
224 |
|
221 | |||
225 | void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) |
|
222 | void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) | |
226 | { |
|
223 | { | |
227 | // if(m_axisY != axis) { |
|
224 | // if(m_axisY != axis) { | |
228 | m_axisY = axis; |
|
225 | m_axisY = axis; | |
229 | m_axisYItem->handleAxisChanged(m_axisY); |
|
226 | m_axisYItem->handleAxisChanged(m_axisY); | |
230 | //} |
|
227 | //} | |
231 | } |
|
228 | } | |
232 |
|
229 | |||
233 | QChartAxis ChartPresenter::defaultAxisX() const |
|
230 | QChartAxis ChartPresenter::defaultAxisX() const | |
234 | { |
|
231 | { | |
235 | return m_axisX; |
|
232 | return m_axisX; | |
236 | } |
|
233 | } | |
237 |
|
234 | |||
238 | QChartAxis ChartPresenter::defaultAxisY() const |
|
235 | QChartAxis ChartPresenter::defaultAxisY() const | |
239 | { |
|
236 | { | |
240 | return m_axisY; |
|
237 | return m_axisY; | |
241 | } |
|
238 | } | |
242 |
|
239 | |||
243 | QChartAxis ChartPresenter::axisY(int id) const |
|
240 | QChartAxis ChartPresenter::axisY(int id) const | |
244 | { |
|
241 | { | |
245 | return m_axis.value(id); |
|
242 | return m_axis.value(id); | |
246 | } |
|
243 | } | |
247 |
|
244 | |||
248 | int ChartPresenter::addAxisY(const QChartAxis& axis) |
|
245 | int ChartPresenter::addAxisY(const QChartAxis& axis) | |
249 | { |
|
246 | { | |
250 | int key =0 ; |
|
247 | int key =0 ; | |
251 |
|
248 | |||
252 | while(m_axis.contains(key)){ |
|
249 | while(m_axis.contains(key)){ | |
253 | key++; |
|
250 | key++; | |
254 | //TODO overflow |
|
251 | //TODO overflow | |
255 | } |
|
252 | } | |
256 |
|
253 | |||
257 | m_axis.insert(key,axis); |
|
254 | m_axis.insert(key,axis); | |
258 | m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); |
|
255 | m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); | |
259 |
|
256 | |||
260 | return key; |
|
257 | return key; | |
261 | } |
|
258 | } | |
262 |
|
259 | |||
263 |
|
260 | |||
264 | void ChartPresenter::removeAxisY(int id) |
|
261 | void ChartPresenter::removeAxisY(int id) | |
265 | { |
|
262 | { | |
266 | m_axis.remove(id); |
|
263 | m_axis.remove(id); | |
267 | delete m_axisItems.take(id); |
|
264 | delete m_axisItems.take(id); | |
268 | } |
|
265 | } | |
269 |
|
266 | |||
270 | #include "moc_chartpresenter_p.cpp" |
|
267 | #include "moc_chartpresenter_p.cpp" | |
271 |
|
268 | |||
272 | QTCOMMERCIALCHART_END_NAMESPACE |
|
269 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,247 +1,255 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
4 |
|
4 | |||
5 |
|
5 | |||
6 | //series |
|
6 | //series | |
7 | #include "barchartseries.h" |
|
7 | #include "barchartseries.h" | |
8 | #include "stackedbarchartseries.h" |
|
8 | #include "stackedbarchartseries.h" | |
9 | #include "percentbarchartseries.h" |
|
9 | #include "percentbarchartseries.h" | |
10 | #include "qlinechartseries.h" |
|
10 | #include "qlinechartseries.h" | |
11 | #include "qscatterseries.h" |
|
11 | #include "qscatterseries.h" | |
12 | #include "qpieseries.h" |
|
12 | #include "qpieseries.h" | |
13 |
|
13 | |||
14 | //items |
|
14 | //items | |
15 | #include "axisitem_p.h" |
|
15 | #include "axisitem_p.h" | |
16 | #include "bargroup.h" |
|
16 | #include "bargroup.h" | |
17 | #include "stackedbargroup.h" |
|
17 | #include "stackedbargroup.h" | |
18 | #include "linechartitem_p.h" |
|
18 | #include "linechartitem_p.h" | |
19 | #include "percentbargroup.h" |
|
19 | #include "percentbargroup.h" | |
20 | #include "scatterpresenter_p.h" |
|
20 | #include "scatterpresenter_p.h" | |
21 | #include "piepresenter.h" |
|
21 | #include "piepresenter.h" | |
22 |
|
22 | |||
23 | //themes |
|
23 | //themes | |
24 | #include "chartthemevanilla_p.h" |
|
24 | #include "chartthemevanilla_p.h" | |
25 | #include "chartthemeicy_p.h" |
|
25 | #include "chartthemeicy_p.h" | |
26 | #include "chartthemegrayscale_p.h" |
|
26 | #include "chartthemegrayscale_p.h" | |
27 | #include "chartthemescientific_p.h" |
|
27 | #include "chartthemescientific_p.h" | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /* TODO |
|
32 | /* TODO | |
33 | case QChart::ChartThemeUnnamed1: |
|
33 | case QChart::ChartThemeUnnamed1: | |
34 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
34 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); | |
35 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
|
35 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); | |
36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); |
|
36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); | |
37 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); |
|
37 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); | |
38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); |
|
38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); | |
39 |
|
39 | |||
40 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
40 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); | |
41 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
41 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
42 | */ |
|
42 | */ | |
43 |
|
43 | |||
44 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
44 | ChartTheme::ChartTheme(QChart::ChartTheme id) | |
45 | { |
|
45 | { | |
46 | m_id = id; |
|
46 | m_id = id; | |
47 | m_seriesColor.append(QRgb(0xff000000)); |
|
47 | m_seriesColor.append(QRgb(0xff000000)); | |
48 | m_seriesColor.append(QRgb(0xff707070)); |
|
48 | m_seriesColor.append(QRgb(0xff707070)); | |
49 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
49 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
50 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
50 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
54 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
55 | { |
|
55 | { | |
56 | switch(theme) { |
|
56 | switch(theme) { | |
57 | case QChart::ChartThemeDefault: |
|
57 | case QChart::ChartThemeDefault: | |
58 | return new ChartTheme(); |
|
58 | return new ChartTheme(); | |
59 | case QChart::ChartThemeVanilla: |
|
59 | case QChart::ChartThemeVanilla: | |
60 | return new ChartThemeVanilla(); |
|
60 | return new ChartThemeVanilla(); | |
61 | case QChart::ChartThemeIcy: |
|
61 | case QChart::ChartThemeIcy: | |
62 | return new ChartThemeIcy(); |
|
62 | return new ChartThemeIcy(); | |
63 | case QChart::ChartThemeGrayscale: |
|
63 | case QChart::ChartThemeGrayscale: | |
64 | return new ChartThemeGrayscale(); |
|
64 | return new ChartThemeGrayscale(); | |
65 | case QChart::ChartThemeScientific: |
|
65 | case QChart::ChartThemeScientific: | |
66 | return new ChartThemeScientific(); |
|
66 | return new ChartThemeScientific(); | |
67 | } |
|
67 | } | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void ChartTheme::decorate(QChart* chart) |
|
70 | void ChartTheme::decorate(QChart* chart) | |
71 | { |
|
71 | { | |
72 | QLinearGradient backgroundGradient; |
|
72 | QLinearGradient backgroundGradient; | |
73 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); |
|
73 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); | |
74 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); |
|
74 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); | |
75 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
75 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
76 | chart->setChartBackgroundBrush(backgroundGradient); |
|
76 | chart->setChartBackgroundBrush(backgroundGradient); | |
77 | } |
|
77 | } | |
78 | //TODO helper to by removed later |
|
78 | //TODO helper to by removed later | |
79 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) |
|
79 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) | |
80 | { |
|
80 | { | |
81 | switch(series->type()) |
|
81 | switch(series->type()) | |
82 | { |
|
82 | { | |
83 | case QChartSeries::SeriesTypeLine: { |
|
83 | case QChartSeries::SeriesTypeLine: { | |
84 | QLineChartSeries* s = static_cast<QLineChartSeries*>(series); |
|
84 | QLineChartSeries* s = static_cast<QLineChartSeries*>(series); | |
85 | LineChartItem* i = static_cast<LineChartItem*>(item); |
|
85 | LineChartItem* i = static_cast<LineChartItem*>(item); | |
86 | decorate(i,s,count); |
|
86 | decorate(i,s,count); | |
87 | break; |
|
87 | break; | |
88 | } |
|
88 | } | |
89 | case QChartSeries::SeriesTypeBar: { |
|
89 | case QChartSeries::SeriesTypeBar: { | |
90 | BarChartSeries* b = static_cast<BarChartSeries*>(series); |
|
90 | BarChartSeries* b = static_cast<BarChartSeries*>(series); | |
91 | BarGroup* i = static_cast<BarGroup*>(item); |
|
91 | BarGroup* i = static_cast<BarGroup*>(item); | |
92 | decorate(i,b,count); |
|
92 | decorate(i,b,count); | |
93 | break; |
|
93 | break; | |
94 | } |
|
94 | } | |
95 | case QChartSeries::SeriesTypeStackedBar: { |
|
95 | case QChartSeries::SeriesTypeStackedBar: { | |
96 | StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series); |
|
96 | StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series); | |
97 | StackedBarGroup* i = static_cast<StackedBarGroup*>(item); |
|
97 | StackedBarGroup* i = static_cast<StackedBarGroup*>(item); | |
98 | decorate(i,s,count); |
|
98 | decorate(i,s,count); | |
99 | break; |
|
99 | break; | |
100 | } |
|
100 | } | |
101 | case QChartSeries::SeriesTypePercentBar: { |
|
101 | case QChartSeries::SeriesTypePercentBar: { | |
102 | PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series); |
|
102 | PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series); | |
103 | PercentBarGroup* i = static_cast<PercentBarGroup*>(item); |
|
103 | PercentBarGroup* i = static_cast<PercentBarGroup*>(item); | |
104 | decorate(i,s,count); |
|
104 | decorate(i,s,count); | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
|
107 | case QChartSeries::SeriesTypeScatter: { | |||
|
108 | QScatterSeries* s = qobject_cast<QScatterSeries*>(series); | |||
|
109 | Q_ASSERT(s); | |||
|
110 | ScatterPresenter* i = static_cast<ScatterPresenter*>(item); | |||
|
111 | Q_ASSERT(i); | |||
|
112 | decorate(i, s, count); | |||
|
113 | break; | |||
|
114 | } | |||
107 | case QChartSeries::SeriesTypePie: { |
|
115 | case QChartSeries::SeriesTypePie: { | |
108 | QPieSeries* s = static_cast<QPieSeries*>(series); |
|
116 | QPieSeries* s = static_cast<QPieSeries*>(series); | |
109 | PiePresenter* i = static_cast<PiePresenter*>(item); |
|
117 | PiePresenter* i = static_cast<PiePresenter*>(item); | |
110 | decorate(i,s,count); |
|
118 | decorate(i,s,count); | |
111 | break; |
|
119 | break; | |
112 | } |
|
120 | } | |
113 | default: |
|
121 | default: | |
114 | qDebug()<<"Wrong item to be decorated by theme"; |
|
122 | qDebug()<<"Wrong item to be decorated by theme"; | |
115 | break; |
|
123 | break; | |
116 | } |
|
124 | } | |
117 |
|
125 | |||
118 | } |
|
126 | } | |
119 |
|
127 | |||
120 | void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count) |
|
128 | void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count) | |
121 | { |
|
129 | { | |
122 | QPen pen; |
|
130 | QPen pen; | |
123 | if(pen != series->pen()){ |
|
131 | if(pen != series->pen()){ | |
124 | item->setPen(series->pen()); |
|
132 | item->setPen(series->pen()); | |
125 | return; |
|
133 | return; | |
126 | } |
|
134 | } | |
127 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
135 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
128 | pen.setWidthF(2); |
|
136 | pen.setWidthF(2); | |
129 | item->setPen(pen); |
|
137 | item->setPen(pen); | |
130 | } |
|
138 | } | |
131 |
|
139 | |||
132 | void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) |
|
140 | void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) | |
133 | { |
|
141 | { | |
134 | // TODO: better way to descide series color and remove hard coded colors. |
|
142 | // TODO: better way to descide series color and remove hard coded colors. | |
135 | item->resetBrushes(); |
|
143 | item->resetBrushes(); | |
136 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
144 | for (int i=0; i<m_seriesColor.count(); i++) { | |
137 | QBrush brush(m_seriesColor.at(i)); |
|
145 | QBrush brush(m_seriesColor.at(i)); | |
138 | item->addBrush(brush); |
|
146 | item->addBrush(brush); | |
139 | } |
|
147 | } | |
140 | item->addBrush(QBrush(QColor(255,0,0,128))); |
|
148 | item->addBrush(QBrush(QColor(255,0,0,128))); | |
141 | item->addBrush(QBrush(QColor(255,255,0,128))); |
|
149 | item->addBrush(QBrush(QColor(255,255,0,128))); | |
142 | item->addBrush(QBrush(QColor(0,255,0,128))); |
|
150 | item->addBrush(QBrush(QColor(0,255,0,128))); | |
143 | item->addBrush(QBrush(QColor(0,0,255,128))); |
|
151 | item->addBrush(QBrush(QColor(0,0,255,128))); | |
144 | item->addBrush(QBrush(QColor(255,128,0,128))); |
|
152 | item->addBrush(QBrush(QColor(255,128,0,128))); | |
145 | } |
|
153 | } | |
146 |
|
154 | |||
147 | void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) |
|
155 | void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) | |
148 | { |
|
156 | { | |
149 | // TODO: better way to descide series color and remove hard coded colors. |
|
157 | // TODO: better way to descide series color and remove hard coded colors. | |
150 | item->resetBrushes(); |
|
158 | item->resetBrushes(); | |
151 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
159 | for (int i=0; i<m_seriesColor.count(); i++) { | |
152 | QBrush brush(m_seriesColor.at(i)); |
|
160 | QBrush brush(m_seriesColor.at(i)); | |
153 | item->addBrush(brush); |
|
161 | item->addBrush(brush); | |
154 | } |
|
162 | } | |
155 | item->addBrush(QBrush(QColor(255,0,0,128))); |
|
163 | item->addBrush(QBrush(QColor(255,0,0,128))); | |
156 | item->addBrush(QBrush(QColor(255,255,0,128))); |
|
164 | item->addBrush(QBrush(QColor(255,255,0,128))); | |
157 | item->addBrush(QBrush(QColor(0,255,0,128))); |
|
165 | item->addBrush(QBrush(QColor(0,255,0,128))); | |
158 | item->addBrush(QBrush(QColor(0,0,255,128))); |
|
166 | item->addBrush(QBrush(QColor(0,0,255,128))); | |
159 | item->addBrush(QBrush(QColor(255,128,0,128))); |
|
167 | item->addBrush(QBrush(QColor(255,128,0,128))); | |
160 | } |
|
168 | } | |
161 |
|
169 | |||
162 | void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) |
|
170 | void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) | |
163 | { |
|
171 | { | |
164 | // TODO: better way to descide series color and remove hard coded colors. |
|
172 | // TODO: better way to descide series color and remove hard coded colors. | |
165 | item->resetBrushes(); |
|
173 | item->resetBrushes(); | |
166 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
174 | for (int i=0; i<m_seriesColor.count(); i++) { | |
167 | QBrush brush(m_seriesColor.at(i)); |
|
175 | QBrush brush(m_seriesColor.at(i)); | |
168 | item->addBrush(brush); |
|
176 | item->addBrush(brush); | |
169 | } |
|
177 | } | |
170 | item->addBrush(QBrush(QColor(255,0,0,128))); |
|
178 | item->addBrush(QBrush(QColor(255,0,0,128))); | |
171 | item->addBrush(QBrush(QColor(255,255,0,128))); |
|
179 | item->addBrush(QBrush(QColor(255,255,0,128))); | |
172 | item->addBrush(QBrush(QColor(0,255,0,128))); |
|
180 | item->addBrush(QBrush(QColor(0,255,0,128))); | |
173 | item->addBrush(QBrush(QColor(0,0,255,128))); |
|
181 | item->addBrush(QBrush(QColor(0,0,255,128))); | |
174 | item->addBrush(QBrush(QColor(255,128,0,128))); |
|
182 | item->addBrush(QBrush(QColor(255,128,0,128))); | |
175 | } |
|
183 | } | |
176 |
|
184 | |||
177 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) |
|
185 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) | |
178 | { |
|
186 | { | |
179 | Q_ASSERT(presenter); |
|
187 | Q_ASSERT(presenter); | |
180 | Q_ASSERT(series); |
|
188 | Q_ASSERT(series); | |
181 |
|
189 | |||
182 |
|
|
190 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); | |
|
191 | // TODO: define alpha in the theme? or in the series? | |||
|
192 | color.setAlpha(120); | |||
|
193 | ||||
|
194 | QBrush brush(color, Qt::SolidPattern); | |||
|
195 | presenter->m_markerBrush = brush; | |||
183 |
|
196 | |||
184 |
|
|
197 | QPen pen(brush, 1); | |
185 | // if(pen != series->pen()){ |
|
198 | pen.setColor(color); | |
186 | // item->setPen(series->pen()); |
|
199 | presenter->m_markerPen = pen; | |
187 | // return; |
|
|||
188 | // } |
|
|||
189 | // pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
|||
190 | // pen.setWidthF(2); |
|
|||
191 | // item->setPen(pen); |
|
|||
192 | } |
|
200 | } | |
193 |
|
201 | |||
194 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) |
|
202 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) | |
195 | { |
|
203 | { | |
196 | // create a list of slice colors based on current theme |
|
204 | // create a list of slice colors based on current theme | |
197 | int i = 0; |
|
205 | int i = 0; | |
198 | QList<QColor> colors; |
|
206 | QList<QColor> colors; | |
199 | while (colors.count() < series->count()) { |
|
207 | while (colors.count() < series->count()) { | |
200 |
|
208 | |||
201 | // get base color |
|
209 | // get base color | |
202 | QColor c = m_seriesColor[i++]; |
|
210 | QColor c = m_seriesColor[i++]; | |
203 | i = i % m_seriesColor.count(); |
|
211 | i = i % m_seriesColor.count(); | |
204 |
|
212 | |||
205 | // -1 means achromatic color -> cannot manipulate lightness |
|
213 | // -1 means achromatic color -> cannot manipulate lightness | |
206 | // TODO: find a better way to randomize lightness |
|
214 | // TODO: find a better way to randomize lightness | |
207 | if (c.toHsv().hue() == -1) |
|
215 | if (c.toHsv().hue() == -1) | |
208 | qWarning() << "ChartTheme::decorate() warning: achromatic theme color"; |
|
216 | qWarning() << "ChartTheme::decorate() warning: achromatic theme color"; | |
209 |
|
217 | |||
210 | // randomize lightness |
|
218 | // randomize lightness | |
211 | qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter |
|
219 | qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter | |
212 | c = c.lighter(f); |
|
220 | c = c.lighter(f); | |
213 |
|
221 | |||
214 | // find duplicates |
|
222 | // find duplicates | |
215 | bool isUnique = true; |
|
223 | bool isUnique = true; | |
216 | foreach (QColor color, colors) { |
|
224 | foreach (QColor color, colors) { | |
217 | if (c == color) |
|
225 | if (c == color) | |
218 | isUnique = false; |
|
226 | isUnique = false; | |
219 | } |
|
227 | } | |
220 |
|
228 | |||
221 | // add to array if unique |
|
229 | // add to array if unique | |
222 | //if (isUnique) |
|
230 | //if (isUnique) | |
223 | colors << c; |
|
231 | colors << c; | |
224 | } |
|
232 | } | |
225 |
|
233 | |||
226 | // finally update colors |
|
234 | // finally update colors | |
227 | foreach (QPieSliceId id, series->ids()) { |
|
235 | foreach (QPieSliceId id, series->ids()) { | |
228 | QPieSlice s = series->slice(id); |
|
236 | QPieSlice s = series->slice(id); | |
229 | s.setPen(QPen(Qt::black)); // TODO: get from theme |
|
237 | s.setPen(QPen(Qt::black)); // TODO: get from theme | |
230 | s.setBrush(colors.takeFirst()); |
|
238 | s.setBrush(colors.takeFirst()); | |
231 | series->update(s); |
|
239 | series->update(s); | |
232 | } |
|
240 | } | |
233 | } |
|
241 | } | |
234 |
|
242 | |||
235 |
|
243 | |||
236 | void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) |
|
244 | void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) | |
237 | { |
|
245 | { | |
238 | //TODO: dummy defults for now |
|
246 | //TODO: dummy defults for now | |
239 |
|
247 | |||
240 | axis.setLabelsBrush(Qt::black); |
|
248 | axis.setLabelsBrush(Qt::black); | |
241 | axis.setLabelsPen(Qt::NoPen); |
|
249 | axis.setLabelsPen(Qt::NoPen); | |
242 | axis.setShadesPen(Qt::NoPen); |
|
250 | axis.setShadesPen(Qt::NoPen); | |
243 | axis.setShadesOpacity(0.5); |
|
251 | axis.setShadesOpacity(0.5); | |
244 | item->handleAxisChanged(axis); |
|
252 | item->handleAxisChanged(axis); | |
245 | } |
|
253 | } | |
246 |
|
254 | |||
247 | QTCOMMERCIALCHART_END_NAMESPACE |
|
255 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,59 +1,85 | |||||
1 | #include "qscatterseries.h" |
|
1 | #include "qscatterseries.h" | |
2 | #include "scatterseries_p.h" |
|
2 | #include "scatterseries_p.h" | |
3 | #include "qchart.h" |
|
3 | #include "qchart.h" | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | QScatterSeriesPrivate::QScatterSeriesPrivate() : |
|
7 | QScatterSeriesPrivate::QScatterSeriesPrivate() : | |
8 | m_data(QList<QPointF>()) |
|
8 | m_data(QList<QPointF>()), | |
|
9 | m_markerPen(QPen()), | |||
|
10 | m_markerBrush(QBrush()), | |||
|
11 | m_markerShape(QScatterSeries::MarkerShapeDefault) | |||
9 | { |
|
12 | { | |
|
13 | // Initialize pen color to invalid to use a theme color by default | |||
|
14 | m_markerPen.setColor(QColor::Invalid); | |||
|
15 | m_markerBrush.setColor(QColor::Invalid); | |||
10 | } |
|
16 | } | |
11 |
|
17 | |||
12 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
18 | QScatterSeries::QScatterSeries(QObject *parent) : | |
13 | QChartSeries(parent), |
|
19 | QChartSeries(parent), | |
14 | d(new QScatterSeriesPrivate()) |
|
20 | d(new QScatterSeriesPrivate()) | |
15 | { |
|
21 | { | |
16 | } |
|
22 | } | |
17 |
|
23 | |||
18 | QScatterSeries::~QScatterSeries() |
|
24 | QScatterSeries::~QScatterSeries() | |
19 | { |
|
25 | { | |
20 | delete d; |
|
26 | delete d; | |
21 | } |
|
27 | } | |
22 |
|
28 | |||
23 | void QScatterSeries::addData(QPointF value) |
|
29 | void QScatterSeries::addData(QPointF value) | |
24 | { |
|
30 | { | |
25 | d->m_data.append(value); |
|
31 | d->m_data.append(value); | |
26 | emit changed(); |
|
32 | emit changed(); | |
27 | } |
|
33 | } | |
28 |
|
34 | |||
29 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) |
|
35 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) | |
30 | { |
|
36 | { | |
31 | d->m_data.append(value); |
|
37 | d->m_data.append(value); | |
32 | emit changed(); |
|
38 | emit changed(); | |
33 | return *this; |
|
39 | return *this; | |
34 | } |
|
40 | } | |
35 |
|
41 | |||
36 | void QScatterSeries::setData(QList<QPointF> data) |
|
42 | void QScatterSeries::setData(QList<QPointF> data) | |
37 | { |
|
43 | { | |
38 | d->m_data = data; |
|
44 | d->m_data = data; | |
39 | emit changed(); |
|
45 | emit changed(); | |
40 | } |
|
46 | } | |
41 |
|
47 | |||
42 | QList<QPointF> QScatterSeries::data() |
|
48 | QList<QPointF> QScatterSeries::data() | |
43 | { |
|
49 | { | |
44 | return d->m_data; |
|
50 | return d->m_data; | |
45 | } |
|
51 | } | |
46 |
|
52 | |||
47 | void QScatterSeries::setMarkerPen(QPen pen) |
|
53 | void QScatterSeries::setMarkerPen(QPen pen) | |
48 | { |
|
54 | { | |
49 | d->m_markerPen = pen; |
|
55 | d->m_markerPen = pen; | |
50 | } |
|
56 | } | |
51 |
|
57 | |||
52 | QPen QScatterSeries::markerPen() |
|
58 | QPen QScatterSeries::markerPen() | |
53 | { |
|
59 | { | |
54 | return d->m_markerPen; |
|
60 | return d->m_markerPen; | |
55 | } |
|
61 | } | |
56 |
|
62 | |||
|
63 | void QScatterSeries::setMarkerBrush(QBrush brush) | |||
|
64 | { | |||
|
65 | d->m_markerBrush = brush; | |||
|
66 | } | |||
|
67 | ||||
|
68 | QBrush QScatterSeries::markerBrush() | |||
|
69 | { | |||
|
70 | return d->m_markerBrush; | |||
|
71 | } | |||
|
72 | ||||
|
73 | void QScatterSeries::setMarkerShape(MarkerShape shape) | |||
|
74 | { | |||
|
75 | d->m_markerShape = shape; | |||
|
76 | } | |||
|
77 | ||||
|
78 | QScatterSeries::MarkerShape QScatterSeries::markerShape() | |||
|
79 | { | |||
|
80 | return (QScatterSeries::MarkerShape) d->m_markerShape; | |||
|
81 | } | |||
|
82 | ||||
57 | #include "moc_qscatterseries.cpp" |
|
83 | #include "moc_qscatterseries.cpp" | |
58 |
|
84 | |||
59 | QTCOMMERCIALCHART_END_NAMESPACE |
|
85 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,66 | |||||
1 | #ifndef QSCATTERSERIES_H |
|
1 | #ifndef QSCATTERSERIES_H | |
2 | #define QSCATTERSERIES_H |
|
2 | #define QSCATTERSERIES_H | |
3 |
|
3 | |||
4 | #include "qchartseries.h" |
|
4 | #include "qchartseries.h" | |
5 | #include <QRectF> |
|
5 | #include <QRectF> | |
6 | #include <QColor> |
|
6 | #include <QColor> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 | class QScatterSeriesPrivate; |
|
9 | class QScatterSeriesPrivate; | |
10 |
|
10 | |||
11 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries |
|
11 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
|
14 | ||||
|
15 | public: | |||
|
16 | enum MarkerShape { | |||
|
17 | // TODO: to be defined by the graphics design | |||
|
18 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot | |||
|
19 | MarkerShapeDefault = 0, | |||
|
20 | MarkerShapePoint, | |||
|
21 | MarkerShapeX, | |||
|
22 | MarkerShapeRectangle, | |||
|
23 | MarkerShapeTiltedRectangle, | |||
|
24 | MarkerShapeTriangle, | |||
|
25 | MarkerShapeCircle | |||
|
26 | }; | |||
|
27 | ||||
14 | public: |
|
28 | public: | |
15 | //QScatterSeries(QSeriesData *data, QObject *chart); |
|
|||
16 | QScatterSeries(QObject *parent = 0); |
|
29 | QScatterSeries(QObject *parent = 0); | |
17 | ~QScatterSeries(); |
|
30 | ~QScatterSeries(); | |
18 |
|
31 | |||
19 | public: // from QChartSeries |
|
32 | public: // from QChartSeries | |
20 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } |
|
33 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } | |
21 |
|
34 | |||
22 | public: |
|
35 | public: | |
23 | // TODO: the name of the function? addPoint? addData? addValue? |
|
36 | // TODO: the name of the function? addPoint? addData? addValue? | |
24 | void addData(QPointF value); |
|
37 | void addData(QPointF value); | |
25 | QScatterSeries& operator << (const QPointF &value); |
|
38 | QScatterSeries& operator << (const QPointF &value); | |
26 | void setData(QList<QPointF> data); |
|
39 | void setData(QList<QPointF> data); | |
27 | QList<QPointF> data(); |
|
40 | QList<QPointF> data(); | |
28 |
|
41 | //TODO: insertData? | ||
29 | //TODO? void insertData(int index, QPointF data); |
|
|||
30 |
|
42 | |||
31 | void setMarkerPen(QPen pen); |
|
43 | void setMarkerPen(QPen pen); | |
32 | QPen markerPen(); |
|
44 | QPen markerPen(); | |
33 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot |
|
45 | void setMarkerBrush(QBrush brush); | |
34 | //void setMarkerShape(MarkerShape shape); |
|
46 | QBrush markerBrush(); | |
|
47 | void setMarkerShape(MarkerShape shape); | |||
|
48 | MarkerShape markerShape(); | |||
|
49 | // TODO: marker size? | |||
35 |
|
50 | |||
36 | Q_SIGNALS: |
|
51 | Q_SIGNALS: | |
37 | // TODO: move to PIMPL? |
|
52 | // TODO: move to PIMPL for simplicity or does the user ever need these signals? | |
38 | // TODO: more finegrained signaling for performance reasons |
|
53 | // TODO: more finegrained signaling for performance reasons | |
|
54 | // (check QPieSeries implementation with change sets) | |||
39 | void changed(); |
|
55 | void changed(); | |
40 |
|
56 | |||
41 | //public Q_SLOTS: |
|
57 | //public Q_SLOTS: | |
42 | private: |
|
58 | private: | |
43 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
59 | Q_DECLARE_PRIVATE(QScatterSeries) | |
44 | Q_DISABLE_COPY(QScatterSeries) |
|
60 | Q_DISABLE_COPY(QScatterSeries) | |
45 | QScatterSeriesPrivate *const d; |
|
61 | QScatterSeriesPrivate *const d; | |
46 | }; |
|
62 | }; | |
47 |
|
63 | |||
48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
64 | QTCOMMERCIALCHART_END_NAMESPACE | |
49 |
|
65 | |||
50 | #endif // QSCATTERSERIES_H |
|
66 | #endif // QSCATTERSERIES_H |
@@ -1,94 +1,111 | |||||
1 | #include "scatterpresenter_p.h" |
|
1 | #include "scatterpresenter_p.h" | |
2 | #include "qscatterseries.h" |
|
2 | #include "qscatterseries.h" | |
3 | #include <QPen> |
|
3 | #include <QPen> | |
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 | ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) : |
|
10 | ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) : | |
11 | ChartItem(parent), |
|
11 | ChartItem(parent), | |
12 | m_series(series), |
|
12 | m_series(series), | |
13 | m_boundingRect(), |
|
13 | m_boundingRect(), | |
14 | //m_markerColor(QColor()), |
|
14 | //m_markerColor(QColor()), | |
15 | // m_markerColor(QColor(255, 0, 0)), |
|
15 | // m_markerColor(QColor(255, 0, 0)), | |
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 | if (series) { |
|
21 | if (series) { | |
22 | connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged())); |
|
22 | connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged())); | |
23 | } |
|
23 | } | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | void ScatterPresenter::handleDomainChanged(const Domain& domain) |
|
26 | void ScatterPresenter::handleDomainChanged(const Domain& domain) | |
27 | { |
|
27 | { | |
28 | m_visibleChartArea = domain; |
|
28 | m_visibleChartArea = domain; | |
29 | changeGeometry(); |
|
29 | changeGeometry(); | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | void ScatterPresenter::handleGeometryChanged(const QRectF& rect) |
|
32 | void ScatterPresenter::handleGeometryChanged(const QRectF& rect) | |
33 | { |
|
33 | { | |
34 | m_boundingRect = rect; |
|
34 | m_boundingRect = rect; | |
35 | changeGeometry(); |
|
35 | changeGeometry(); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void ScatterPresenter::handleModelChanged() |
|
38 | void ScatterPresenter::handleModelChanged() | |
39 | { |
|
39 | { | |
40 | // TODO: more fine grained modelChanged signaling |
|
40 | // TODO: more fine grained modelChanged signaling | |
41 | changeGeometry(); |
|
41 | changeGeometry(); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) |
|
44 | void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) | |
45 | { |
|
45 | { | |
46 | // TODO: The opacity should be user definable? |
|
46 | // TODO: Optimization: avoid setting on every paint method call? | |
47 | //brush.setColor(QColor(255, 82, 0, 100)); |
|
47 | // The custom settings in series override those defined by the theme | |
48 |
|
|
48 | if (m_series->markerPen().color().isValid()) { | |
49 | if (false) { |
|
49 | painter->setPen(m_series->markerPen()); | |
50 | QPen pen = painter->pen(); |
|
50 | painter->setBrush(m_series->markerBrush()); | |
51 | QBrush brush = pen.brush(); |
|
51 | } else { | |
52 | brush.setColor(m_series->markerPen().color()); |
|
52 | painter->setPen(m_markerPen); | |
53 |
p |
|
53 | painter->setBrush(m_markerBrush); | |
54 | pen.setWidth(4); |
|
|||
55 | painter->setPen(pen); |
|
|||
56 | } |
|
|||
57 | else { |
|
|||
58 | // TODO: fix this |
|
|||
59 | QPen pen = painter->pen(); |
|
|||
60 | QBrush brush = pen.brush(); |
|
|||
61 | brush.setColor(m_markerPen.color()); |
|
|||
62 | pen.setBrush(brush); |
|
|||
63 | pen.setWidth(4); |
|
|||
64 | painter->setPen(pen); |
|
|||
65 | } |
|
54 | } | |
66 |
|
55 | |||
|
56 | int shape = m_series->markerShape(); | |||
|
57 | ||||
67 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
58 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | |
68 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
59 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | |
69 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); |
|
60 | // Paint a shape | |
|
61 | switch (shape) { | |||
|
62 | case QScatterSeries::MarkerShapeDefault: | |||
|
63 | // Fallthrough, defaults to circle | |||
|
64 | case QScatterSeries::MarkerShapeCircle: | |||
|
65 | painter->drawChord(m_scenex.at(i), m_sceney.at(i), 9, 9, 0, 5760); | |||
|
66 | break; | |||
|
67 | case QScatterSeries::MarkerShapePoint: | |||
70 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); |
|
68 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | |
|
69 | break; | |||
|
70 | case QScatterSeries::MarkerShapeRectangle: | |||
|
71 | painter->drawRect(m_scenex.at(i), m_sceney.at(i), 9, 9); | |||
|
72 | break; | |||
|
73 | case QScatterSeries::MarkerShapeTiltedRectangle: | |||
|
74 | // TODO: | |||
|
75 | static const QPointF points[4] = { | |||
|
76 | QPointF(-1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), | |||
|
77 | QPointF(0.0 + m_scenex.at(i), 1.0 + m_sceney.at(i)), | |||
|
78 | QPointF(1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), | |||
|
79 | QPointF(0.0 + m_scenex.at(i), -1.0 + m_sceney.at(i)) | |||
|
80 | }; | |||
|
81 | painter->drawPolygon(points, 4); | |||
|
82 | break; | |||
|
83 | default: | |||
|
84 | // TODO: implement the rest of the shapes | |||
|
85 | Q_ASSERT(false); | |||
|
86 | break; | |||
|
87 | } | |||
71 | } |
|
88 | } | |
72 | } |
|
89 | } | |
73 |
|
90 | |||
74 | void ScatterPresenter::changeGeometry() |
|
91 | void ScatterPresenter::changeGeometry() | |
75 | { |
|
92 | { | |
76 | if (m_boundingRect.isValid()) { |
|
93 | if (m_boundingRect.isValid()) { | |
77 |
|
94 | |||
78 | prepareGeometryChange(); |
|
95 | prepareGeometryChange(); | |
79 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); |
|
96 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); | |
80 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); |
|
97 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); | |
81 | m_scenex.clear(); |
|
98 | m_scenex.clear(); | |
82 | m_sceney.clear(); |
|
99 | m_sceney.clear(); | |
83 |
|
100 | |||
84 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
|
101 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing | |
85 | foreach (QPointF point, m_series->data()) { |
|
102 | foreach (QPointF point, m_series->data()) { | |
86 | m_scenex.append(m_boundingRect.left() + point.x() * scalex - m_visibleChartArea.m_minX * scalex); |
|
103 | m_scenex.append(m_boundingRect.left() + point.x() * scalex - m_visibleChartArea.m_minX * scalex); | |
87 | m_sceney.append(m_boundingRect.bottom() - point.y() * scaley + m_visibleChartArea.m_minY * scaley); |
|
104 | m_sceney.append(m_boundingRect.bottom() - point.y() * scaley + m_visibleChartArea.m_minY * scaley); | |
88 | } |
|
105 | } | |
89 | } |
|
106 | } | |
90 | } |
|
107 | } | |
91 |
|
108 | |||
92 | #include "moc_scatterpresenter_p.cpp" |
|
109 | #include "moc_scatterpresenter_p.cpp" | |
93 |
|
110 | |||
94 | QTCOMMERCIALCHART_END_NAMESPACE |
|
111 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,47 +1,48 | |||||
1 | #ifndef SCATTERPRESENTER_H |
|
1 | #ifndef SCATTERPRESENTER_H | |
2 | #define SCATTERPRESENTER_H |
|
2 | #define SCATTERPRESENTER_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "chartitem_p.h" |
|
5 | #include "chartitem_p.h" | |
6 | #include <QObject> |
|
6 | #include <QObject> | |
7 | #include <QPen> |
|
7 | #include <QPen> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class QScatterSeries; |
|
11 | class QScatterSeries; | |
12 |
|
12 | |||
13 | /*! |
|
13 | /*! | |
14 | * The "business logic" of scatter series. This is a QObject that does not have a parent QObject. |
|
14 | * The "business logic" of scatter series. This is a QObject that does not have a parent QObject. | |
15 | * The QGraphicsItem parent owns the object instead. |
|
15 | * The QGraphicsItem parent owns the object instead. | |
16 | */ |
|
16 | */ | |
17 | class ScatterPresenter : public QObject, public ChartItem |
|
17 | class ScatterPresenter : public QObject, public ChartItem | |
18 | { |
|
18 | { | |
19 | Q_OBJECT |
|
19 | Q_OBJECT | |
20 | public: |
|
20 | public: | |
21 | explicit ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent = 0); |
|
21 | explicit ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent = 0); | |
22 |
|
22 | |||
23 | public: // from ChartItem |
|
23 | public: // from ChartItem | |
24 | QRectF boundingRect() const { return m_boundingRect; } |
|
24 | QRectF boundingRect() const { return m_boundingRect; } | |
25 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); |
|
25 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); | |
26 |
|
26 | |||
27 | signals: |
|
27 | signals: | |
28 |
|
28 | |||
29 | public Q_SLOTS: |
|
29 | public Q_SLOTS: | |
30 | void handleDomainChanged(const Domain& domain); |
|
30 | void handleDomainChanged(const Domain& domain); | |
31 | void handleGeometryChanged(const QRectF& rect); |
|
31 | void handleGeometryChanged(const QRectF& rect); | |
32 | void handleModelChanged(); |
|
32 | void handleModelChanged(); | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | void changeGeometry(); |
|
35 | void changeGeometry(); | |
36 |
|
36 | |||
37 | QScatterSeries *m_series; |
|
37 | QScatterSeries *m_series; | |
38 | QRectF m_boundingRect; |
|
38 | QRectF m_boundingRect; | |
39 | QList<qreal> m_scenex; |
|
39 | QList<qreal> m_scenex; | |
40 | QList<qreal> m_sceney; |
|
40 | QList<qreal> m_sceney; | |
41 | Domain m_visibleChartArea; |
|
41 | Domain m_visibleChartArea; | |
42 | QPen m_markerPen; |
|
42 | QPen m_markerPen; | |
|
43 | QBrush m_markerBrush; | |||
43 | }; |
|
44 | }; | |
44 |
|
45 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
46 | QTCOMMERCIALCHART_END_NAMESPACE | |
46 |
|
47 | |||
47 | #endif // SCATTERPRESENTER_H |
|
48 | #endif // SCATTERPRESENTER_H |
@@ -1,25 +1,27 | |||||
1 | #ifndef QSCATTERSERIESPRIVATE_H |
|
1 | #ifndef QSCATTERSERIESPRIVATE_H | |
2 | #define QSCATTERSERIESPRIVATE_H |
|
2 | #define QSCATTERSERIESPRIVATE_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartseries.h" |
|
5 | #include "qchartseries.h" | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | /*! |
|
10 | /*! | |
11 | * The PIMPL class of QScatterSeries. |
|
11 | * The PIMPL class of QScatterSeries. | |
12 | */ |
|
12 | */ | |
13 | class QScatterSeriesPrivate |
|
13 | class QScatterSeriesPrivate | |
14 | { |
|
14 | { | |
15 | public: |
|
15 | public: | |
16 | QScatterSeriesPrivate(); |
|
16 | QScatterSeriesPrivate(); | |
17 |
|
17 | |||
18 | public: |
|
18 | public: | |
19 | QList<QPointF> m_data; |
|
19 | QList<QPointF> m_data; | |
20 | QPen m_markerPen; |
|
20 | QPen m_markerPen; | |
|
21 | QBrush m_markerBrush; | |||
|
22 | int m_markerShape; | |||
21 | }; |
|
23 | }; | |
22 |
|
24 | |||
23 | QTCOMMERCIALCHART_END_NAMESPACE |
|
25 | QTCOMMERCIALCHART_END_NAMESPACE | |
24 |
|
26 | |||
25 | #endif // QSCATTERSERIESPRIVATE_H |
|
27 | #endif // QSCATTERSERIESPRIVATE_H |
General Comments 0
You need to be logged in to leave comments.
Login now