@@ -11,17 +11,23 int main(int argc, char *argv[]) | |||
|
11 | 11 | { |
|
12 | 12 | QApplication a(argc, argv); |
|
13 | 13 | |
|
14 |
// Create widget |
|
|
14 | // Create chart widget | |
|
15 | 15 | QChartView *chartWidget = new QChartView(); |
|
16 | ||
|
17 | // Create scatter series with simple test data | |
|
16 | 18 | QScatterSeries *scatter = new QScatterSeries(); |
|
19 | *scatter << QPointF(0.5, 2.0) | |
|
20 | << QPointF(1.0, 2.5) | |
|
21 | << QPointF(1.5, 2.0) | |
|
22 | << QPointF(2.0, 2.5); | |
|
23 | chartWidget->addSeries(scatter); | |
|
17 | 24 | |
|
18 | // Add test data to the series | |
|
25 | // Add another scatter series with more complex data with random component | |
|
26 | QScatterSeries *scatter2 = new QScatterSeries(); | |
|
19 | 27 | for (qreal i(0.0); i < 20; i += 0.5) |
|
20 | (*scatter) << QPointF(i + (qreal)(rand() % 100) / 100.0, | |
|
28 | (*scatter2) << QPointF(i + (qreal)(rand() % 100) / 100.0, | |
|
21 | 29 | i + (qreal)(rand() % 100) / 100.0); |
|
22 | ||
|
23 | // Add series to the chart widget | |
|
24 | chartWidget->addSeries(scatter); | |
|
30 | chartWidget->addSeries(scatter2); | |
|
25 | 31 | |
|
26 | 32 | // Use the chart widget as the central widget |
|
27 | 33 | QMainWindow w; |
@@ -126,6 +126,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
126 | 126 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
127 | 127 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), |
|
128 | 128 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); |
|
129 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); | |
|
129 | 130 | // scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
130 | 131 | // scatterSeries->d->setParentItem(this); |
|
131 | 132 | // scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
@@ -8,6 +8,7 | |||
|
8 | 8 | #include "stackedbarchartseries.h" |
|
9 | 9 | #include "percentbarchartseries.h" |
|
10 | 10 | #include "qlinechartseries.h" |
|
11 | #include "qscatterseries.h" | |
|
11 | 12 | #include "qpieseries.h" |
|
12 | 13 | |
|
13 | 14 | //items |
@@ -16,6 +17,7 | |||
|
16 | 17 | #include "stackedbargroup.h" |
|
17 | 18 | #include "linechartitem_p.h" |
|
18 | 19 | #include "percentbargroup.h" |
|
20 | #include "scatterpresenter.h" | |
|
19 | 21 | #include "piepresenter.h" |
|
20 | 22 | |
|
21 | 23 | //themes |
@@ -166,6 +168,23 void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,i | |||
|
166 | 168 | item->addColor(QColor(255,128,0,128)); |
|
167 | 169 | } |
|
168 | 170 | |
|
171 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) | |
|
172 | { | |
|
173 | Q_ASSERT(presenter); | |
|
174 | Q_ASSERT(series); | |
|
175 | ||
|
176 | presenter->m_markerPen.setColor(m_seriesColor.at(count % m_seriesColor.size())); | |
|
177 | ||
|
178 | // QPen pen; | |
|
179 | // if(pen != series->pen()){ | |
|
180 | // item->setPen(series->pen()); | |
|
181 | // return; | |
|
182 | // } | |
|
183 | // pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
|
184 | // pen.setWidthF(2); | |
|
185 | // item->setPen(pen); | |
|
186 | } | |
|
187 | ||
|
169 | 188 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) |
|
170 | 189 | { |
|
171 | 190 | // create a list of slice colors based on current theme |
@@ -17,6 +17,8 class StackedBarGroup; | |||
|
17 | 17 | class StackedBarChartSeries; |
|
18 | 18 | class PercentBarChartSeries; |
|
19 | 19 | class PercentBarGroup; |
|
20 | class QScatterSeries; | |
|
21 | class ScatterPresenter; | |
|
20 | 22 | class PiePresenter; |
|
21 | 23 | class QPieSeries; |
|
22 | 24 | |
@@ -33,6 +35,7 public: | |||
|
33 | 35 | void decorate(BarGroup* item, BarChartSeries* series,int count); |
|
34 | 36 | void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count); |
|
35 | 37 | void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count); |
|
38 | void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); | |
|
36 | 39 | void decorate(PiePresenter* item, QPieSeries* series, int count); |
|
37 | 40 | void decorate(QChartAxis& axis,AxisItem* item); |
|
38 | 41 |
@@ -23,9 +23,7 public: | |||
|
23 | 23 | // TODO: the name of the function? addPoint? addData? addValue? |
|
24 | 24 | void addData(QPointF value); |
|
25 | 25 | QScatterSeries& operator << (const QPointF &value); |
|
26 | ||
|
27 | 26 | void setData(QList<QPointF> data); |
|
28 | ||
|
29 | 27 | QList<QPointF> data(); |
|
30 | 28 | |
|
31 | 29 | //TODO? void insertData(int index, QPointF data); |
@@ -12,7 +12,7 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare | |||
|
12 | 12 | m_series(series), |
|
13 | 13 | m_boundingRect(), |
|
14 | 14 | //m_markerColor(QColor()), |
|
15 | m_markerColor(QColor(255, 0, 0)), | |
|
15 | // m_markerColor(QColor(255, 0, 0)), | |
|
16 | 16 | m_visibleChartArea() |
|
17 | 17 | { |
|
18 | 18 | if (parent) |
@@ -45,21 +45,25 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * | |||
|
45 | 45 | { |
|
46 | 46 | // TODO: The opacity should be user definable? |
|
47 | 47 | //brush.setColor(QColor(255, 82, 0, 100)); |
|
48 |
if (m_marker |
|
|
48 | //if (m_series->markerPen().isValid()) { | |
|
49 | if (false) { | |
|
49 | 50 | QPen pen = painter->pen(); |
|
50 | 51 | QBrush brush = pen.brush(); |
|
51 |
brush.setColor(m_marker |
|
|
52 | brush.setColor(m_series->markerPen().color()); | |
|
52 | 53 | pen.setBrush(brush); |
|
53 | 54 | pen.setWidth(4); |
|
54 | 55 | painter->setPen(pen); |
|
55 | 56 | } |
|
56 | 57 | else { |
|
57 | //painter->setPen(m_theme.markerPen); | |
|
58 | // brush.setColor(m_theme..lineColor); | |
|
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); | |
|
59 | 65 | } |
|
60 | 66 | |
|
61 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize | |
|
62 | // event right after construction or maybe given a size during initialization | |
|
63 | 67 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
64 | 68 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
65 | 69 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); |
@@ -4,6 +4,7 | |||
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "chartitem_p.h" |
|
6 | 6 | #include <QObject> |
|
7 | #include <QPen> | |
|
7 | 8 | |
|
8 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 10 | |
@@ -37,8 +38,8 public: | |||
|
37 | 38 | QRectF m_boundingRect; |
|
38 | 39 | QList<qreal> m_scenex; |
|
39 | 40 | QList<qreal> m_sceney; |
|
40 | QColor m_markerColor; | |
|
41 | 41 | Domain m_visibleChartArea; |
|
42 | QPen m_markerPen; | |
|
42 | 43 | }; |
|
43 | 44 | |
|
44 | 45 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now