##// END OF EJS Templates
Enabled theme colors in scatter again
Tero Ahola -
r182:0dd3fe4314e9
parent child
Show More
@@ -11,17 +11,23 int main(int argc, char *argv[])
11 {
11 {
12 QApplication a(argc, argv);
12 QApplication a(argc, argv);
13
13
14 // Create widget and scatter series
14 // Create chart widget
15 QChartView *chartWidget = new QChartView();
15 QChartView *chartWidget = new QChartView();
16
17 // Create scatter series with simple test data
16 QScatterSeries *scatter = new QScatterSeries();
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 for (qreal i(0.0); i < 20; i += 0.5)
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 i + (qreal)(rand() % 100) / 100.0);
29 i + (qreal)(rand() % 100) / 100.0);
22
30 chartWidget->addSeries(scatter2);
23 // Add series to the chart widget
24 chartWidget->addSeries(scatter);
25
31
26 // Use the chart widget as the central widget
32 // Use the chart widget as the central widget
27 QMainWindow w;
33 QMainWindow w;
@@ -126,6 +126,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
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 // scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
130 // scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
130 // scatterSeries->d->setParentItem(this);
131 // scatterSeries->d->setParentItem(this);
131 // scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
132 // scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
@@ -8,6 +8,7
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 "qpieseries.h"
12 #include "qpieseries.h"
12
13
13 //items
14 //items
@@ -16,6 +17,7
16 #include "stackedbargroup.h"
17 #include "stackedbargroup.h"
17 #include "linechartitem_p.h"
18 #include "linechartitem_p.h"
18 #include "percentbargroup.h"
19 #include "percentbargroup.h"
20 #include "scatterpresenter.h"
19 #include "piepresenter.h"
21 #include "piepresenter.h"
20
22
21 //themes
23 //themes
@@ -166,6 +168,23 void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,i
166 item->addColor(QColor(255,128,0,128));
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 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/)
188 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/)
170 {
189 {
171 // create a list of slice colors based on current theme
190 // create a list of slice colors based on current theme
@@ -17,6 +17,8 class StackedBarGroup;
17 class StackedBarChartSeries;
17 class StackedBarChartSeries;
18 class PercentBarChartSeries;
18 class PercentBarChartSeries;
19 class PercentBarGroup;
19 class PercentBarGroup;
20 class QScatterSeries;
21 class ScatterPresenter;
20 class PiePresenter;
22 class PiePresenter;
21 class QPieSeries;
23 class QPieSeries;
22
24
@@ -33,6 +35,7 public:
33 void decorate(BarGroup* item, BarChartSeries* series,int count);
35 void decorate(BarGroup* item, BarChartSeries* series,int count);
34 void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count);
36 void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count);
35 void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count);
37 void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count);
38 void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count);
36 void decorate(PiePresenter* item, QPieSeries* series, int count);
39 void decorate(PiePresenter* item, QPieSeries* series, int count);
37 void decorate(QChartAxis& axis,AxisItem* item);
40 void decorate(QChartAxis& axis,AxisItem* item);
38
41
@@ -23,9 +23,7 public:
23 // TODO: the name of the function? addPoint? addData? addValue?
23 // TODO: the name of the function? addPoint? addData? addValue?
24 void addData(QPointF value);
24 void addData(QPointF value);
25 QScatterSeries& operator << (const QPointF &value);
25 QScatterSeries& operator << (const QPointF &value);
26
27 void setData(QList<QPointF> data);
26 void setData(QList<QPointF> data);
28
29 QList<QPointF> data();
27 QList<QPointF> data();
30
28
31 //TODO? void insertData(int index, QPointF data);
29 //TODO? void insertData(int index, QPointF data);
@@ -12,7 +12,7 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare
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)
@@ -45,21 +45,25 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *
45 {
45 {
46 // TODO: The opacity should be user definable?
46 // TODO: The opacity should be user definable?
47 //brush.setColor(QColor(255, 82, 0, 100));
47 //brush.setColor(QColor(255, 82, 0, 100));
48 if (m_markerColor.isValid()) {
48 //if (m_series->markerPen().isValid()) {
49 if (false) {
49 QPen pen = painter->pen();
50 QPen pen = painter->pen();
50 QBrush brush = pen.brush();
51 QBrush brush = pen.brush();
51 brush.setColor(m_markerColor);
52 brush.setColor(m_series->markerPen().color());
52 pen.setBrush(brush);
53 pen.setBrush(brush);
53 pen.setWidth(4);
54 pen.setWidth(4);
54 painter->setPen(pen);
55 painter->setPen(pen);
55 }
56 }
56 else {
57 else {
57 //painter->setPen(m_theme.markerPen);
58 // TODO: fix this
58 // brush.setColor(m_theme..lineColor);
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 for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) {
67 for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) {
64 if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i))
68 if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i))
65 //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760);
69 //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760);
@@ -4,6 +4,7
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
8
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10
@@ -37,8 +38,8 public:
37 QRectF m_boundingRect;
38 QRectF m_boundingRect;
38 QList<qreal> m_scenex;
39 QList<qreal> m_scenex;
39 QList<qreal> m_sceney;
40 QList<qreal> m_sceney;
40 QColor m_markerColor;
41 Domain m_visibleChartArea;
41 Domain m_visibleChartArea;
42 QPen m_markerPen;
42 };
43 };
43
44
44 QTCOMMERCIALCHART_END_NAMESPACE
45 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now