From 0dd3fe4314e9c3bf90b86c1b693a7ff46e599110 2012-02-15 10:59:25 From: Tero Ahola Date: 2012-02-15 10:59:25 Subject: [PATCH] Enabled theme colors in scatter again --- diff --git a/example/scatter/main.cpp b/example/scatter/main.cpp index a3749d0..e1ed334 100644 --- a/example/scatter/main.cpp +++ b/example/scatter/main.cpp @@ -11,17 +11,23 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - // Create widget and scatter series + // Create chart widget QChartView *chartWidget = new QChartView(); + + // Create scatter series with simple test data QScatterSeries *scatter = new QScatterSeries(); + *scatter << QPointF(0.5, 2.0) + << QPointF(1.0, 2.5) + << QPointF(1.5, 2.0) + << QPointF(2.0, 2.5); + chartWidget->addSeries(scatter); - // Add test data to the series + // Add another scatter series with more complex data with random component + QScatterSeries *scatter2 = new QScatterSeries(); for (qreal i(0.0); i < 20; i += 0.5) - (*scatter) << QPointF(i + (qreal)(rand() % 100) / 100.0, + (*scatter2) << QPointF(i + (qreal)(rand() % 100) / 100.0, i + (qreal)(rand() % 100) / 100.0); - - // Add series to the chart widget - chartWidget->addSeries(scatter); + chartWidget->addSeries(scatter2); // Use the chart widget as the central widget QMainWindow w; diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 449080d..45735dd 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -126,6 +126,7 @@ void ChartPresenter::handleSeriesAdded(QChartSeries* series) scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), scatterPresenter, SLOT(handleDomainChanged(const Domain&))); + m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); // scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); // scatterSeries->d->setParentItem(this); // scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 8af356e..5472231 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -8,6 +8,7 @@ #include "stackedbarchartseries.h" #include "percentbarchartseries.h" #include "qlinechartseries.h" +#include "qscatterseries.h" #include "qpieseries.h" //items @@ -16,6 +17,7 @@ #include "stackedbargroup.h" #include "linechartitem_p.h" #include "percentbargroup.h" +#include "scatterpresenter.h" #include "piepresenter.h" //themes @@ -166,6 +168,23 @@ void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,i item->addColor(QColor(255,128,0,128)); } +void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) +{ + Q_ASSERT(presenter); + Q_ASSERT(series); + + presenter->m_markerPen.setColor(m_seriesColor.at(count % m_seriesColor.size())); + +// QPen pen; +// if(pen != series->pen()){ +// item->setPen(series->pen()); +// return; +// } +// pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); +// pen.setWidthF(2); +// item->setPen(pen); +} + void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) { // create a list of slice colors based on current theme diff --git a/src/charttheme_p.h b/src/charttheme_p.h index aea5290..0d76fa0 100644 --- a/src/charttheme_p.h +++ b/src/charttheme_p.h @@ -17,6 +17,8 @@ class StackedBarGroup; class StackedBarChartSeries; class PercentBarChartSeries; class PercentBarGroup; +class QScatterSeries; +class ScatterPresenter; class PiePresenter; class QPieSeries; @@ -33,6 +35,7 @@ public: void decorate(BarGroup* item, BarChartSeries* series,int count); void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count); void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count); + void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); void decorate(PiePresenter* item, QPieSeries* series, int count); void decorate(QChartAxis& axis,AxisItem* item); diff --git a/src/qscatterseries.h b/src/qscatterseries.h index b29b32b..acbb619 100644 --- a/src/qscatterseries.h +++ b/src/qscatterseries.h @@ -23,9 +23,7 @@ public: // TODO: the name of the function? addPoint? addData? addValue? void addData(QPointF value); QScatterSeries& operator << (const QPointF &value); - void setData(QList data); - QList data(); //TODO? void insertData(int index, QPointF data); diff --git a/src/scatterpresenter.cpp b/src/scatterpresenter.cpp index 2959349..06ebafc 100644 --- a/src/scatterpresenter.cpp +++ b/src/scatterpresenter.cpp @@ -12,7 +12,7 @@ ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare m_series(series), m_boundingRect(), //m_markerColor(QColor()), - m_markerColor(QColor(255, 0, 0)), +// m_markerColor(QColor(255, 0, 0)), m_visibleChartArea() { if (parent) @@ -45,21 +45,25 @@ void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * { // TODO: The opacity should be user definable? //brush.setColor(QColor(255, 82, 0, 100)); - if (m_markerColor.isValid()) { + //if (m_series->markerPen().isValid()) { + if (false) { QPen pen = painter->pen(); QBrush brush = pen.brush(); - brush.setColor(m_markerColor); + brush.setColor(m_series->markerPen().color()); pen.setBrush(brush); pen.setWidth(4); painter->setPen(pen); } else { - //painter->setPen(m_theme.markerPen); -// brush.setColor(m_theme..lineColor); + // TODO: fix this + QPen pen = painter->pen(); + QBrush brush = pen.brush(); + brush.setColor(m_markerPen.color()); + pen.setBrush(brush); + pen.setWidth(4); + painter->setPen(pen); } - // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize - // event right after construction or maybe given a size during initialization for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); diff --git a/src/scatterpresenter.h b/src/scatterpresenter.h index 6050c97..b6d75be 100644 --- a/src/scatterpresenter.h +++ b/src/scatterpresenter.h @@ -4,6 +4,7 @@ #include "qchartglobal.h" #include "chartitem_p.h" #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -37,8 +38,8 @@ public: QRectF m_boundingRect; QList m_scenex; QList m_sceney; - QColor m_markerColor; Domain m_visibleChartArea; + QPen m_markerPen; }; QTCOMMERCIALCHART_END_NAMESPACE