diff --git a/doc/src/classes.qdoc b/doc/src/classes.qdoc
index 698d1d6..4e5f827 100644
--- a/doc/src/classes.qdoc
+++ b/doc/src/classes.qdoc
@@ -54,6 +54,7 @@
QSplineSeries
QStackedBarSeries
QXYSeries
+ QLegend
diff --git a/src/qchart.cpp b/src/qchart.cpp
index 60df8bf..7d7490f 100644
--- a/src/qchart.cpp
+++ b/src/qchart.cpp
@@ -266,9 +266,39 @@ QChartAxis* QChart::axisY() const
/*!
Returns the legend object of the chart. Ownership stays in chart.
*/
-QLegend* QChart::legend() const
+QLegend& QChart::legend() const
{
- return m_legend;
+ return *m_legend;
+}
+
+/*!
+ Gives ownership of legend to user.
+*/
+QLegend* QChart::takeLegend()
+{
+ QLegend* l = m_legend;
+ m_legend = 0;
+ return l;
+}
+
+/*!
+ Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one
+*/
+void QChart::giveLegend(QLegend* legend)
+{
+ if (m_legend) {
+ // Should not happen.
+ qDebug() << "Warning! Giving more than one legend to chart."
+ delete m_legend;
+ }
+
+ m_legend = legend;
+
+ // Reconnect legend, in case not already connected.
+ disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
+ disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
+ connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
+ connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
}
/*!
diff --git a/src/qchart.h b/src/qchart.h
index a5d352c..5b288dd 100644
--- a/src/qchart.h
+++ b/src/qchart.h
@@ -87,7 +87,9 @@ public:
QChartAxis* axisX() const;
QChartAxis* axisY() const;
- QLegend* legend() const;
+ QLegend& legend() const;
+ QLegend* takeLegend();
+ void giveLegend(QLegend* legend);
int padding() const;
diff --git a/src/qlegend.cpp b/src/qlegend.cpp
index 98c4e00..f1689ce 100644
--- a/src/qlegend.cpp
+++ b/src/qlegend.cpp
@@ -23,6 +23,20 @@
QTCOMMERCIALCHART_BEGIN_NAMESPACE
/*!
+ \class QLegend
+ \brief part of QtCommercial chart API.
+
+ QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
+ series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
+ handle the drawing manually.
+ User isn't supposed to create or delete legend objects, but can reference it via QChart class.
+
+ \mainclass
+
+ \sa QChart, QSeries
+*/
+
+/*!
\enum QLegend::PreferredLayout
This enum describes the possible position for legend inside chart.
@@ -35,17 +49,17 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE
/*!
- \fn void clicked(QSeries* series, Qt::MouseButton button)
+ \fn void QLegend::clicked(QSeries* series, Qt::MouseButton button)
\brief Notifies when series has been clicked on legend \a series \a button
*/
/*!
- \fn void clicked(QBarSet* barset, Qt::MouseButton button);
+ \fn void QLegend::clicked(QBarSet* barset, Qt::MouseButton button)
\brief Notifies when barset has been clicked on legend \a barset \a button
*/
/*!
- \fn void clicked(QPieSlice* slice, Qt::MouseButton button);
+ \fn void QLegend::clicked(QPieSlice* slice, Qt::MouseButton button)
\brief Notifies when pie slice has been clicked on legend \a slice \a button
*/
@@ -141,7 +155,7 @@ QPen QLegend::pen() const
/*!
Sets the \a preferred layout for legend. Legend tries to paint itself on the defined position in chart.
- sa \QLegend::PreferredLayout
+ \sa QLegend::PreferredLayout
*/
void QLegend::setPreferredLayout(QLegend::PreferredLayout preferred)
{