diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index 83a12a8..b5aaa73 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -208,27 +208,10 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \qmlsignal ChartView::onTopMarginChanged(real margin) - The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size - related properties of the legend or chart title. -*/ - -/*! - \qmlsignal ChartView::onBottomMarginChanged(real margin) - The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size - related properties of the legend or chart title. -*/ - -/*! - \qmlsignal ChartView::onLeftMarginChanged(real margin) - The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size - related properties of the legend or chart title. -*/ - -/*! - \qmlsignal ChartView::onRightMarginChanged(real margin) - The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size - related properties of the legend or chart title. + \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. */ DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) @@ -237,17 +220,17 @@ DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) { setFlag(QGraphicsItem::ItemHasNoContents, false); m_minMargins = new DeclarativeMargins(this); - connect(m_minMargins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); - connect(m_minMargins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); - connect(m_minMargins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); - connect(m_minMargins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); - // TODO: connect to plotAreaChanged signal from m_chart + connect(m_minMargins, SIGNAL(topChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); + connect(m_minMargins, SIGNAL(bottomChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); + connect(m_minMargins, SIGNAL(leftChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); + connect(m_minMargins, SIGNAL(rightChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); } void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) { m_chart->setMinimumMargins(QMargins(left, top, right, bottom)); - plotAreaChanged(m_chart->plotArea()); + emit minimumMarginsChanged(); + emit plotAreaChanged(m_chart->plotArea()); } DeclarativeChart::~DeclarativeChart() @@ -370,6 +353,11 @@ void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF & } } QDeclarativeItem::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::setTheme(DeclarativeChart::Theme theme) diff --git a/plugins/declarative/declarativechart.h b/plugins/declarative/declarativechart.h index 5733267..2f03bbc 100644 --- a/plugins/declarative/declarativechart.h +++ b/plugins/declarative/declarativechart.h @@ -41,11 +41,11 @@ class DeclarativeChart : public QDeclarativeItem Q_PROPERTY(int count READ count) Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) - Q_PROPERTY(qreal topMargin READ topMargin NOTIFY topMarginChanged) - Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged) - 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(qreal topMargin READ topMargin) + Q_PROPERTY(qreal bottomMargin READ bottomMargin) + Q_PROPERTY(qreal leftMargin READ leftMargin) + Q_PROPERTY(qreal rightMargin READ rightMargin) + Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1) Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) Q_ENUMS(Animation) Q_ENUMS(Theme) @@ -139,14 +139,10 @@ Q_SIGNALS: void titleColorChanged(QColor color); void backgroundColorChanged(); void dropShadowEnabledChanged(bool enabled); - void topMarginChanged(qreal margin); - void bottomMarginChanged(qreal margin); - void leftMarginChanged(qreal margin); - void rightMarginChanged(qreal margin); + void minimumMarginsChanged(); void plotAreaChanged(QRectF plotArea); public Q_SLOTS: -// void handleMarginsChanged(QRectF newMargins); void changeMinimumMargins(int top, int bottom, int left, int right); void handleAxisXSet(QAbstractAxis *axis); void handleAxisYSet(QAbstractAxis *axis); diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml index 19b2dc3..6e69175 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml @@ -42,22 +42,6 @@ ChartView { onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); - onTopMarginChanged: { - console.log("chart.onTopMarginChanged: " + margin); - marginVisualizer.opacity = 1.0; - } - onBottomMarginChanged: { - console.log("chart.onBottomMarginChanged: " + margin); - marginVisualizer.opacity = 1.0; - } - onLeftMarginChanged: { - console.log("chart.onLeftMarginChanged: " + margin); - marginVisualizer.opacity = 1.0; - } - onRightMarginChanged: { - console.log("chart.onRightMarginChanged: " + margin); - marginVisualizer.opacity = 1.0; - } legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); @@ -65,10 +49,16 @@ ChartView { 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 + " " + 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); + minimumMargins.onBottomChanged: console.log("chart.minimumMargins.onBottomChanged: " + bottom); + minimumMargins.onLeftChanged: console.log("chart.minimumMargins.onLeftChanged: " + left); + minimumMargins.onRightChanged: console.log("chart.minimumMargins.onRightChanged: " + right); + onPlotAreaChanged: { + console.log("chart.onPlotAreaChanged, width: " + chartView.plotArea.width + + " height: " + chartView.plotArea.height + + " y: " + chartView.plotArea.y + + " x: " + chartView.plotArea.x); + marginVisualizer.opacity = 1.0; + } ValueAxis{ onColorChanged: console.log("axisX.onColorChanged: " + color); @@ -101,10 +91,10 @@ ChartView { color: "transparent" border.color: "red" anchors.fill: parent - anchors.topMargin: parent.topMargin - anchors.bottomMargin: parent.bottomMargin - anchors.leftMargin: parent.leftMargin - anchors.rightMargin: parent.rightMargin + anchors.topMargin: chartView.minimumMargins.top + anchors.bottomMargin: chartView.minimumMargins.bottom + anchors.leftMargin: chartView.minimumMargins.left + anchors.rightMargin: chartView.minimumMargins.right opacity: 0.0 onOpacityChanged: if (opacity > 0.9) opacity = 0.0; Behavior on opacity {