summaryrefslogtreecommitdiffstats
path: root/src/qchartview.cpp
diff options
context:
space:
mode:
authorJani Honkonen <jani.honkonen@digia.com>2012-09-14 12:42:46 +0300
committerJani Honkonen <jani.honkonen@digia.com>2012-09-14 15:27:27 +0300
commit4b7228265b304c5788ba8e809fa08a6e8f610ebc (patch)
tree9507a00b6890f24c83b75dcf04092fcd78dddb5e /src/qchartview.cpp
parentb660f2141c1820cb460cac441ab16a940605b09d (diff)
Implement QChartView::setChart()
Diffstat (limited to 'src/qchartview.cpp')
-rw-r--r--src/qchartview.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/qchartview.cpp b/src/qchartview.cpp
index 919c5982..bf1e782a 100644
--- a/src/qchartview.cpp
+++ b/src/qchartview.cpp
@@ -88,6 +88,18 @@ QChart* QChartView::chart() const
}
/*!
+ Sets the current chart to \a chart. Ownership of the new chart is passed to chartview
+ and ownership of the previous chart is released.
+
+ To avoid memory leaks users needs to make sure the previous chart is deleted.
+*/
+
+void QChartView::setChart(QChart *chart)
+{
+ d_ptr->setChart(chart);
+}
+
+/*!
Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed.
*/
void QChartView::setRubberBand(const RubberBands& rubberBand)
@@ -191,9 +203,7 @@ void QChartView::mouseReleaseEvent(QMouseEvent *event)
void QChartView::resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
- d_ptr->m_chart->resize(size());
- setMinimumSize(d_ptr->m_chart->minimumSize().toSize());
- setSceneRect(d_ptr->m_chart->geometry());
+ d_ptr->resize();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -221,6 +231,29 @@ QChartViewPrivate::~QChartViewPrivate()
}
+void QChartViewPrivate::setChart(QChart *chart)
+{
+ Q_ASSERT(chart);
+
+ if (m_chart == chart)
+ return;
+
+ if (m_chart)
+ m_scene->removeItem(m_chart);
+
+ m_chart = chart;
+ m_scene->addItem(m_chart);
+
+ resize();
+}
+
+void QChartViewPrivate::resize()
+{
+ m_chart->resize(q_ptr->size());
+ q_ptr->setMinimumSize(m_chart->minimumSize().toSize());
+ q_ptr->setSceneRect(m_chart->geometry());
+}
+
#include "moc_qchartview.cpp"
QTCOMMERCIALCHART_END_NAMESPACE