diff --git a/src/charts/chartpresenter.cpp b/src/charts/chartpresenter.cpp index 4eb0757..f92fb5c 100644 --- a/src/charts/chartpresenter.cpp +++ b/src/charts/chartpresenter.cpp @@ -67,6 +67,7 @@ void ChartPresenter::setGeometry(const QRectF rect) chart->domain()->setSize(rect.size()); chart->setPos(rect.topLeft()); } + emit plotAreaChanged(m_rect); } } diff --git a/src/charts/chartpresenter_p.h b/src/charts/chartpresenter_p.h index 238ae3f..1c338b1 100644 --- a/src/charts/chartpresenter_p.h +++ b/src/charts/chartpresenter_p.h @@ -169,6 +169,9 @@ public Q_SLOTS: void handleAxisAdded(QAbstractAxis *axis); void handleAxisRemoved(QAbstractAxis *axis); +signals: + void plotAreaChanged(const QRectF &plotArea); + private: QChart *m_chart; QList m_chartItems; diff --git a/src/charts/qchart.cpp b/src/charts/qchart.cpp index 69584a8..a7f5894 100644 --- a/src/charts/qchart.cpp +++ b/src/charts/qchart.cpp @@ -169,6 +169,12 @@ QT_CHARTS_BEGIN_NAMESPACE */ /*! + \property QChart::plotArea + Holds the rectangle within which the drawing of the chart is done. + It does not include the area defined by margins. +*/ + +/*! \internal Constructs a chart object of \a type which is a child of a \a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. @@ -526,10 +532,6 @@ QChart::ChartType QChart::chartType() const return d_ptr->m_type; } -/*! - Returns the the rectangle within which the drawing of the chart is done. - It does not include the area defined by margins. - */ QRectF QChart::plotArea() const { return d_ptr->m_presenter->geometry(); @@ -762,6 +764,7 @@ QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); + QObject::connect(m_presenter, &ChartPresenter::plotAreaChanged, q, &QChart::plotAreaChanged); } QChartPrivate::~QChartPrivate() diff --git a/src/charts/qchart.h b/src/charts/qchart.h index 40712c5..d4d386d 100644 --- a/src/charts/qchart.h +++ b/src/charts/qchart.h @@ -51,6 +51,7 @@ class QT_CHARTS_EXPORT QChart : public QGraphicsWidget Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible) Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers) Q_PROPERTY(QLocale locale READ locale WRITE setLocale) + Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged) Q_ENUMS(ChartTheme) Q_ENUMS(AnimationOption) Q_ENUMS(ChartType) @@ -163,6 +164,9 @@ public: ChartType chartType() const; +signals: + void plotAreaChanged(const QRectF &plotArea); + protected: explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags); QScopedPointer d_ptr; diff --git a/src/chartsqml2/declarativechart.cpp b/src/chartsqml2/declarativechart.cpp index 8f67f2e..89010d3 100644 --- a/src/chartsqml2/declarativechart.cpp +++ b/src/chartsqml2/declarativechart.cpp @@ -265,13 +265,6 @@ QT_CHARTS_BEGIN_NAMESPACE */ /*! - \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) - The plot area of the chart has changed. This may happen for example, if you modify minimumMargins - or if you resize the chart, or if you modify font size related properties of the legend or chart - title. -*/ - -/*! \qmlsignal ChartView::seriesAdded(AbstractSeries series) The \a series has been added to the chart. */ @@ -327,6 +320,7 @@ void DeclarativeChart::initChart(QChart::ChartType type) connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); + connect(m_chart, &QChart::plotAreaChanged, this, &DeclarativeChart::plotAreaChanged); } void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) @@ -338,7 +332,6 @@ void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int r { m_chart->setMargins(QMargins(left, top, right, bottom)); emit minimumMarginsChanged(); - emit plotAreaChanged(m_chart->plotArea()); } DeclarativeChart::~DeclarativeChart() @@ -454,11 +447,6 @@ void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF & } } QQuickItem::geometryChanged(newGeometry, oldGeometry); - - // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or - // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is - // to implement it here for the QML API purposes. - emit plotAreaChanged(m_chart->plotArea()); } void DeclarativeChart::sceneChanged(QList region)