diff --git a/src/qchart.cpp b/src/qchart.cpp index bf53b4d..9cc8430 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -8,71 +8,105 @@ QCHART_BEGIN_NAMESPACE +class QChartPrivate +{ +public: + + QChartPrivate(QChart* parent): + m_axisX(new Axis(parent)), + m_axisY(new Axis(parent)), + m_grid(new XYGrid(parent)), + m_plotDataIndex(0), + m_marginSize(0){} + + Axis* m_axisX; + Axis* m_axisY; + XYGrid* m_grid; + QRect m_rect; + QList m_series; + QList m_plotDataList; + QList m_items; + int m_plotDataIndex; + int m_marginSize; + +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + QChart::QChart(QGraphicsItem* parent):QGraphicsItem(parent), -m_marginSize(0), -m_axisX(new Axis(this)), -m_axisY(new Axis(this)), -m_grid(new XYGrid(this)), -m_plotDataIndex(0) +d_ptr(new QChartPrivate(this)) { - // setFlags(QGraphicsItem::ItemClipsChildrenToShape); + // setFlags(QGraphicsItem::ItemClipsChildrenToShape); // set axis - m_axisY->rotate(90); - + Q_D(QChart); + d->m_axisY->rotate(90); - //TODO hardcoded values , to removed soon - XYPlotDomain* data = new XYPlotDomain(); - data->m_minX = 0.0; - data->m_maxX = 100.0; - data->m_minY = 0.0; - data->m_maxY = 100.0; - data->m_ticksX=4; - data->m_ticksY=4; + //TODO hardcoded values , to removed soon + XYPlotDomain data; + data.m_minX = 0.0; + data.m_maxX = 100.0; + data.m_minY = 0.0; + data.m_maxY = 100.0; + data.m_ticksX=4; + data.m_ticksY=4; - m_plotDataList.clear(); - m_plotDataList << data; + d->m_plotDataList.clear(); + d->m_plotDataList << data; - m_grid->setZValue(10); - m_grid->setXYPlotData(*m_plotDataList.at(0)); + d->m_grid->setZValue(10); + d->m_grid->setXYPlotData(d->m_plotDataList.at(0)); } QChart::~QChart(){} QRectF QChart::boundingRect() const { - return m_rect; + Q_D(const QChart); + return d->m_rect; } void QChart::addSeries(QChartSeries* series) { - m_series<m_series<type()) { case QChartSeries::LINE: XYLineChartItem* item = new XYLineChartItem(reinterpret_cast(series),this); - item->updateXYPlotData(*m_plotDataList.at(0)); - m_items<updateXYPlotData(d->m_plotDataList.at(0)); + d->m_items<setPos(m_rect.topLeft()); - m_grid->setSize(m_rect.size()); - m_plotDataList.at(0)->m_viewportRect = m_rect; - foreach(QGraphicsItem* item , m_items) - reinterpret_cast(item)->updateXYPlotData(*m_plotDataList.at(0)); + d->m_rect = QRect(QPoint(0,0),size.toSize()); + d->m_rect.adjust(margin(),margin(),-margin(),-margin()); + d->m_grid->setPos(d->m_rect.topLeft()); + d->m_grid->setSize(d->m_rect.size()); + d->m_plotDataList[0].m_viewportRect = d->m_rect; + foreach(QGraphicsItem* item , d->m_items) + reinterpret_cast(item)->updateXYPlotData(d->m_plotDataList.at(0)); update(); } +int QChart::margin() const +{ + Q_D(const QChart); + return d->m_marginSize; +} + void QChart::setMargin(int margin) { - m_marginSize = margin; + Q_D(QChart); + d->m_marginSize = margin; } + + QCHART_END_NAMESPACE diff --git a/src/qchart.h b/src/qchart.h index 76e5bce..d7932e6 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -10,6 +10,7 @@ class Axis; class XYGrid; class QChartSeries; class XYPlotDomain; +class QChartPrivate; class QCHART_EXPORT QChart : public QGraphicsItem { @@ -26,18 +27,15 @@ public: virtual void setSize(const QSizeF& rect); void setMargin(int margin); - int margin() const { return m_marginSize;} + int margin() const; + +protected: + QChartPrivate * const d_ptr; private: - QRect m_rect; - QList m_series; - Axis* m_axisX; - Axis* m_axisY; - XYGrid* m_grid; - QList m_plotDataList; - QList m_items; - int m_plotDataIndex; - int m_marginSize; + Q_DISABLE_COPY(QChart) + Q_DECLARE_PRIVATE(QChart) + }; QCHART_END_NAMESPACE diff --git a/src/qchartwidget.cpp b/src/qchartwidget.cpp index 1956c23..d3a146d 100644 --- a/src/qchartwidget.cpp +++ b/src/qchartwidget.cpp @@ -12,8 +12,7 @@ public: QChartWidgetPrivate(QChartWidget *parent) : m_view(0), m_scene(0), - m_chart(0), - q_ptr( parent ) + m_chart(0) { m_scene = new QGraphicsScene(); m_view = new QGraphicsView(parent); @@ -28,10 +27,10 @@ public: QGraphicsView *m_view; QGraphicsScene *m_scene; QChart* m_chart; - QChartWidget * const q_ptr; - Q_DECLARE_PUBLIC(QChartWidget); }; +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + QChartWidget::QChartWidget(QWidget *parent) : QWidget(parent), d_ptr(new QChartWidgetPrivate(this))