From c6b7296833b8f48b1196d93aacf0821c80b9236f 2012-01-23 08:18:53 From: Michal Klocek Date: 2012-01-23 08:18:53 Subject: [PATCH] Removes PIMPL for now * removes wrongly implmented qchartprivate * removes wrongly implemented qchart * pimpl will be done before release --- diff --git a/src/qchart.cpp b/src/qchart.cpp index 1480451..9efd131 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -13,52 +13,30 @@ QTCOMMERCIALCHART_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_plotDomainList; - QList m_xyLineChartItems; - QList m_items; - int m_plotDataIndex; - int m_marginSize; - -}; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), -d(new QChartPrivate(this)) + m_axisX(new Axis(this)), + m_axisY(new Axis(this)), + m_grid(new XYGrid(this)), + m_plotDataIndex(0), + m_marginSize(0) { // setFlags(QGraphicsItem::ItemClipsChildrenToShape); // set axis - d->m_axisY->rotate(90); + m_axisY->rotate(90); } QChart::~QChart(){} QRectF QChart::boundingRect() const { - return d->m_rect; + return m_rect; } void QChart::addSeries(QChartSeries* series) { // TODO: we should check the series not already added - d->m_series<type()) { @@ -83,8 +61,8 @@ void QChart::addSeries(QChartSeries* series) XYLineChartItem* item = new XYLineChartItem(xyseries,this); item->updateXYPlotDomain(domain); - d->m_plotDomainList<m_xyLineChartItems< x, QList y, QChartSeries: void QChart::setSize(const QSizeF& size) { - 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()); + m_rect = QRect(QPoint(0,0),size.toSize()); + m_rect.adjust(margin(),margin(), -margin(), -margin()); + m_grid->setPos(m_rect.topLeft()); + m_grid->setSize(m_rect.size()); // TODO: calculate the scale // TODO: calculate the origo @@ -142,27 +120,29 @@ void QChart::setSize(const QSizeF& size) const qreal yscale = size.height() / 100; emit sizeChanged(QRectF(0, 0, size.width(), size.height()), xscale, yscale); - for (int i(0); i < d->m_plotDomainList.size(); i++) - d->m_plotDomainList[i].m_viewportRect = d->m_rect; + for (int i(0); i < m_plotDomainList.size(); i++) + m_plotDomainList[i].m_viewportRect = m_rect; // TODO: line chart items are updated separately as they don't support update // via sizeChanged signal - foreach(XYLineChartItem* item , d->m_xyLineChartItems) - item->updateXYPlotDomain(d->m_plotDomainList.at(d->m_plotDataIndex)); + foreach(XYLineChartItem* item ,m_xyLineChartItems) + item->updateXYPlotDomain(m_plotDomainList.at(m_plotDataIndex)); + + + if (m_plotDomainList.count()) + m_grid->setXYPlotData(m_plotDomainList.at(m_plotDataIndex)); - if (d->m_plotDomainList.count()) - d->m_grid->setXYPlotData(d->m_plotDomainList.at(d->m_plotDataIndex)); update(); } int QChart::margin() const { - return d->m_marginSize; + return m_marginSize; } void QChart::setMargin(int margin) { - d->m_marginSize = margin; + m_marginSize = margin; } #include "moc_qchart.cpp" diff --git a/src/qchart.h b/src/qchart.h index 590b855..0d6d98d 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -11,7 +11,7 @@ class Axis; class XYGrid; class QChartSeries; class XYPlotDomain; -class QChartPrivate; +class XYLineChartItem; // TODO: We don't need to have QChart tied to QGraphicsItem: //class QTCOMMERCIALCHART_EXPORT QChart @@ -45,9 +45,17 @@ signals: void sizeChanged(QRectF rect, qreal xscale, qreal yscale); private: -// Q_DECLARE_PRIVATE(QChart) Q_DISABLE_COPY(QChart) - QChartPrivate *d; + Axis* m_axisX; + Axis* m_axisY; + XYGrid* m_grid; + QRect m_rect; + QList m_series; + QList m_plotDomainList; + QList m_xyLineChartItems; + QList m_items; + int m_plotDataIndex; + int m_marginSize; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qchartwidget.cpp b/src/qchartwidget.cpp index 27a86c8..6541717 100644 --- a/src/qchartwidget.cpp +++ b/src/qchartwidget.cpp @@ -6,52 +6,28 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QChartWidgetPrivate -{ -public: - QChartWidgetPrivate(QChartWidget *parent) : - m_view(0), - m_scene(0), - m_chart(0) - { - m_scene = new QGraphicsScene(); - m_view = new QGraphicsView(parent); - m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_view->setScene(m_scene); - m_chart = new QChart(); - m_scene->addItem(m_chart); - m_view->show(); - } - - ~QChartWidgetPrivate() { - } - - QGraphicsView *m_view; - QGraphicsScene *m_scene; - QChart* m_chart; -}; - -/////////////////////////////////////////////////////////////////////////////////////////////////// - QChartWidget::QChartWidget(QWidget *parent) : - QWidget(parent), - d_ptr(new QChartWidgetPrivate(this)) +QWidget(parent) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_scene = new QGraphicsScene(); + m_view = new QGraphicsView(parent); + m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_view->setScene(m_scene); + m_chart = new QChart(); + m_scene->addItem(m_chart); + m_view->show(); } QChartWidget::~QChartWidget() { - delete d_ptr; } void QChartWidget::resizeEvent(QResizeEvent *event) { - Q_D(QChartWidget); - d->m_view->resize(size().width(),size().height()); - d->m_scene->setSceneRect(0,0,size().width(),size().height()); - d->m_chart->setSize(size()); + m_view->resize(size().width(),size().height()); + m_scene->setSceneRect(0,0,size().width(),size().height()); + m_chart->setSize(size()); QWidget::resizeEvent(event); } @@ -63,14 +39,12 @@ QSize QChartWidget::sizeHint() const void QChartWidget::addSeries(QChartSeries* series) { - Q_D(QChartWidget); - d->m_chart->addSeries(series); + m_chart->addSeries(series); } QChartSeries* QChartWidget::createSeries(QList x, QList y, QChartSeries::QChartSeriesType type) { - Q_D(QChartWidget); - return d->m_chart->createSeries(x, y, type); + return m_chart->createSeries(x, y, type); } #include "moc_qchartwidget.cpp" diff --git a/src/qchartwidget.h b/src/qchartwidget.h index abd2574..85984b4 100644 --- a/src/qchartwidget.h +++ b/src/qchartwidget.h @@ -5,6 +5,9 @@ #include "qchart.h" #include +class QGraphicsView; +class QGraphicsScene; + QTCOMMERCIALCHART_BEGIN_NAMESPACE class QChartSeries; @@ -24,12 +27,12 @@ public: // TODO: addSeries and createSeries are optional solutions void addSeries(QChartSeries* series); QChartSeries* createSeries(QList x, QList y, QChartSeries::QChartSeriesType type); -protected: - QChartWidgetPrivate * const d_ptr; private: Q_DISABLE_COPY(QChartWidget) - Q_DECLARE_PRIVATE(QChartWidget) + QGraphicsView *m_view; + QGraphicsScene *m_scene; + QChart* m_chart; };