diff --git a/examples/stackedbarchartdrilldown/main.cpp b/examples/stackedbarchartdrilldown/main.cpp index e409e68..05dc315 100644 --- a/examples/stackedbarchartdrilldown/main.cpp +++ b/examples/stackedbarchartdrilldown/main.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/src/qchart.cpp b/src/qchart.cpp index f59faaf..da79bbe 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -269,9 +269,9 @@ QChartAxis* QChart::axisY() const } /*! - Returns the legend object of the chart + Returns the legend object of the chart. Ownership stays in chart. */ -QLegend* QChart::legend() +QLegend* QChart::legend() const { return m_legend; } @@ -341,9 +341,10 @@ void QChart::updateLayout() // recalculate legend position if (m_legend) { - m_legend->setMaximumSize(rect.size()); - m_legend->setPos(rect.topLeft()); - m_legend->setPreferredLayout(QLegend::PreferredLayoutHorizontal); + if (m_legend->parentObject() == this) { + m_legend->setMaximumSize(rect.size()); + m_legend->setPos(rect.topLeft()); + } } } diff --git a/src/qchart.h b/src/qchart.h index f081c73..b0f3425 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -90,9 +90,7 @@ public: QChartAxis* axisX() const; QChartAxis* axisY() const; - // TODO: take (and give) legend instead of this. - QLegend* legend(); - + QLegend* legend() const; int padding() const; diff --git a/src/qlegend.cpp b/src/qlegend.cpp index 6300485..3fac73c 100644 --- a/src/qlegend.cpp +++ b/src/qlegend.cpp @@ -30,7 +30,7 @@ QLegend::QLegend(QGraphicsItem *parent) ,m_brush(Qt::darkGray) // TODO: from theme? ,mPreferredLayout(QLegend::PreferredLayoutVertical) { -// setVisible(false); + setVisible(false); setZValue(ChartPresenter::LegendZValue); } @@ -90,6 +90,7 @@ QSizeF QLegend::maximumSize() const void QLegend::setMaximumSize(const QSizeF size) { mMaximumSize = size; + layoutChanged(); } void QLegend::setSize(const QSizeF size) @@ -106,13 +107,13 @@ void QLegend::setSize(const QSizeF size) void QLegend::setPos(const QPointF &pos) { mPos = pos; + layoutChanged(); } void QLegend::handleSeriesAdded(QSeries* series, Domain* domain) { Q_UNUSED(domain) -// mSeriesList.append(series); createMarkers(series); connectSeries(series); layoutChanged(); @@ -132,7 +133,6 @@ void QLegend::handleSeriesRemoved(QSeries* series) deleteMarkers(series); } -// mSeriesList.removeOne(series); layoutChanged(); } @@ -374,7 +374,6 @@ void QLegend::deleteMarkers(QSeries *series) void QLegend::layoutChanged() { // Calculate layout for markers and text - qDebug() << "Marker count:" << mMarkers.count(); if (mMarkers.count() <= 0) { // Nothing to do return; diff --git a/src/qlegend.h b/src/qlegend.h index 98c1643..53a9c6b 100644 --- a/src/qlegend.h +++ b/src/qlegend.h @@ -74,7 +74,6 @@ private: QSizeF mMinimumSize; QSizeF mMaximumSize; -// QList mSeriesList; QList mMarkers; QBrush m_brush; diff --git a/src/qseries.cpp b/src/qseries.cpp index 57bb67f..379a0d2 100644 --- a/src/qseries.cpp +++ b/src/qseries.cpp @@ -48,11 +48,6 @@ */ /*! - \fn QList QSeries::legend() - \brief Returns the legend of the series. If series is empty, empty list is returned. -*/ - -/*! \fn void QSeries::setTitle(QString title) \brief Sets a \a title for the series.