summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2014-10-21 10:25:57 +0300
committerMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2014-10-21 10:58:17 +0300
commitbf30bed1cefb384a38e97492d4a4c5e4f4a2b86e (patch)
tree0dced9bf29a2dff74dd1f53e5afbd11df6ea1a9c
parent38dcfecdb5955680ae46fd9a8c9c4b1fa3fd084d (diff)
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>
-rw-r--r--src/charts/chartpresenter.cpp1
-rw-r--r--src/charts/chartpresenter_p.h3
-rw-r--r--src/charts/qchart.cpp11
-rw-r--r--src/charts/qchart.h4
-rw-r--r--src/chartsqml2/declarativechart.cpp14
5 files changed, 16 insertions, 17 deletions
diff --git a/src/charts/chartpresenter.cpp b/src/charts/chartpresenter.cpp
index 4eb0757c..f92fb5c5 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 238ae3f1..1c338b11 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<ChartItem *> m_chartItems;
diff --git a/src/charts/qchart.cpp b/src/charts/qchart.cpp
index 69584a82..a7f58941 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 40712c5d..d4d386d9 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<QChartPrivate> d_ptr;
diff --git a/src/chartsqml2/declarativechart.cpp b/src/chartsqml2/declarativechart.cpp
index 8f67f2e8..89010d3c 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<QRectF> region)