Added plotAreaChanged signal to chart.

The plotArea property was also introduced, though it was previously
available via getter function.
The signal with same name on QML side was linked to the new signal.

Task-number: QTRD-3330
Change-Id: I8d985762194800e1b8743d0a7429ef4d0356bd98
Reviewed-by: Mika Salmela <mika.salmela@theqtcompany.com>
This commit is contained in:
Miikka Heikkinen 2014-10-21 10:25:57 +03:00
parent 38dcfecdb5
commit bf30bed1ce
5 changed files with 16 additions and 17 deletions

View File

@ -67,6 +67,7 @@ void ChartPresenter::setGeometry(const QRectF rect)
chart->domain()->setSize(rect.size());
chart->setPos(rect.topLeft());
}
emit plotAreaChanged(m_rect);
}
}

View File

@ -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<ChartItem *> m_chartItems;

View File

@ -168,6 +168,12 @@ QT_CHARTS_BEGIN_NAMESPACE
\sa localizeNumbers
*/
/*!
\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.
@ -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()

View File

@ -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<QChartPrivate> d_ptr;

View File

@ -264,13 +264,6 @@ QT_CHARTS_BEGIN_NAMESPACE
Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
*/
/*!
\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<QRectF> region)