From 0db37e179fcd315b4e5d038b7b606c0f13471088 2012-08-31 10:22:50 From: Tero Ahola Date: 2012-08-31 10:22:50 Subject: [PATCH] Added ChartView.plotArea to QML API --- diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index 938a966..09199f2 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -138,7 +138,18 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! \qmlproperty Margins ChartView::minimumMargins - The minimum margins allowed between the outer bounds and the plotArea of the ChartView. + The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins + area of ChartView is used for drawing title, axes and legend. Please note that setting the + properties of minimumMargins may be bigger than the defined value, depending on other ChartView + properties that affect it's layout. If you need to know the actual plotting area used at any + given time, you can check ChartView::plotArea instead. +*/ + +/*! + \qmlproperty rect ChartView::plotArea + The area on the ChartView that is used for drawing series. This is the ChartView rect without the + margins. + \sa ChartView::minimumMargins */ /*! @@ -236,6 +247,7 @@ DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) { m_chart->setMinimumMargins(QMargins(left, top, right, bottom)); + plotAreaChanged(m_chart->plotArea()); } DeclarativeChart::~DeclarativeChart() diff --git a/plugins/declarative/declarativechart.h b/plugins/declarative/declarativechart.h index 74d9ca9..5733267 100644 --- a/plugins/declarative/declarativechart.h +++ b/plugins/declarative/declarativechart.h @@ -46,6 +46,7 @@ class DeclarativeChart : public QDeclarativeItem Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged) Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged) Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins REVISION 1) + Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) Q_ENUMS(Animation) Q_ENUMS(Theme) Q_ENUMS(SeriesType) @@ -115,6 +116,7 @@ public: qreal rightMargin(); void createDefaultAxes(QAbstractSeries* series); DeclarativeMargins *minimumMargins() { return m_minMargins; } + QRectF plotArea() { return m_chart->plotArea(); } public: Q_INVOKABLE QAbstractSeries *series(int index); @@ -141,6 +143,7 @@ Q_SIGNALS: void bottomMarginChanged(qreal margin); void leftMarginChanged(qreal margin); void rightMarginChanged(qreal margin); + void plotAreaChanged(QRectF plotArea); public Q_SLOTS: // void handleMarginsChanged(QRectF newMargins); diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml index c9a6bfe..19b2dc3 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml @@ -64,10 +64,11 @@ ChartView { legend.onColorChanged: console.log("legend.onColorChanged: " + color); legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color); - minimumMargins.onTopChanged: console.log("chart.minimumMargins.onTopChanged: " + top); - minimumMargins.onBottomChanged: console.log("chart.minimumMargins.onBottomChanged: " + bottom); - minimumMargins.onLeftChanged: console.log("chart.minimumMargins.onLeftChanged: " + left); - minimumMargins.onRightChanged: console.log("chart.minimumMargins.onRightChanged: " + right); + minimumMargins.onTopChanged: console.log("chart.minimumMargins.onTopChanged: " + top ); + minimumMargins.onBottomChanged: console.log("chart.minimumMargins.onBottomChanged: " + bottom + " " + chartView.plotArea.height); + minimumMargins.onLeftChanged: console.log("chart.minimumMargins.onLeftChanged: " + left + " " + chartView.plotArea.left); + minimumMargins.onRightChanged: console.log("chart.minimumMargins.onRightChanged: " + right + " " + chartView.plotArea.right); + onPlotAreaChanged: console.log("chart.onPlotAreaChanged, width:" + chartView.plotArea.width + " height: " + chartView.plotArea.height + " y: " + chartView.plotArea.y + " x: " + chartView.plotArea.x); ValueAxis{ onColorChanged: console.log("axisX.onColorChanged: " + color);