From c0a0231bdee18187a08e115ad538e383878dec80 2012-03-13 11:15:30 From: Tero Ahola Date: 2012-03-13 11:15:30 Subject: [PATCH] Enabled legend again; it is now created before presenter --- diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 94dd477..aa11b42 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -68,7 +68,7 @@ void ChartTheme::decorate(QChart* chart) void ChartTheme::decorate(QLegend* legend) { - //legend->setBackgroundBrush(m_backgroundGradient); + legend->setBackgroundBrush(m_backgroundGradient); } void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series, int index) diff --git a/src/qchart.cpp b/src/qchart.cpp index 242fc72..3569718 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -49,12 +49,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), m_backgroundItem(0), m_titleItem(0), + m_legend(new QLegend(this)), m_dataset(new ChartDataSet(this)), m_presenter(new ChartPresenter(this,m_dataset)) { - createLegend(); -// connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); -// connect(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*))); } /*! @@ -62,8 +62,8 @@ QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget( */ QChart::~QChart() { -// disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); -// disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); + disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); + disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); } /*! @@ -181,16 +181,6 @@ void QChart::createChartTitleItem() } } -void QChart::createLegend() -{ - // TODO: Why we have null pointer, even if this is created in constructor? - if(!m_legend) { - m_legend = new QLegend(this); - m_legend->setZValue(ChartPresenter::LegendZValue); - } -} - - /*! Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. \sa setMargin() @@ -282,7 +272,6 @@ QChartAxis* QChart::axisY() const */ QLegend* QChart::legend() { - createLegend(); return m_legend; } diff --git a/src/qchart.h b/src/qchart.h index 6d4fa78..1b9e66d 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -85,16 +85,15 @@ protected: private: inline void createChartBackgroundItem(); inline void createChartTitleItem(); - inline void createLegend(); private: Q_DISABLE_COPY(QChart) QGraphicsRectItem* m_backgroundItem; QGraphicsSimpleTextItem* m_titleItem; QRectF m_rect; + QLegend* m_legend; ChartDataSet *m_dataset; ChartPresenter *m_presenter; - QLegend* m_legend; }; QTCOMMERCIALCHART_END_NAMESPACE