diff --git a/qmlplugin/declarativechart.cpp b/qmlplugin/declarativechart.cpp index f2ba366..2487e14 100644 --- a/qmlplugin/declarativechart.cpp +++ b/qmlplugin/declarativechart.cpp @@ -7,7 +7,6 @@ DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) m_chart(new QChart(this)) { setFlag(QGraphicsItem::ItemHasNoContents, false); -// m_chart->setMargin(50); // TODO: should not be needed? } DeclarativeChart::ChartTheme DeclarativeChart::theme() @@ -18,8 +17,21 @@ DeclarativeChart::ChartTheme DeclarativeChart::theme() void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { - if (newGeometry.isValid()) - m_chart->resize(newGeometry.width(), newGeometry.height()); + qDebug() << "geometryChanged " << this << " old geometry: " << oldGeometry; + if (newGeometry.isValid()) { + if (newGeometry.width() > 0 && newGeometry.height() > 0) { + // TODO: setting margin should not be needed to make axis visible? + const int margin = 30; + if (m_chart->margin() == 0 + && newGeometry.width() > (margin * 2) + && newGeometry.height() > (margin * 2)) { + m_chart->setMargin(margin); + m_chart->resize(newGeometry.width(), newGeometry.height()); + } else { + m_chart->resize(newGeometry.width(), newGeometry.height()); + } + } + } } #include "moc_declarativechart.cpp" diff --git a/qmlplugin/declarativeseries.cpp b/qmlplugin/declarativeseries.cpp index 7dc9dfc..7710083 100644 --- a/qmlplugin/declarativeseries.cpp +++ b/qmlplugin/declarativeseries.cpp @@ -86,15 +86,6 @@ void DeclarativeSeries::initSeries() } } -QVariant DeclarativeSeries::itemChange(GraphicsItemChange change, - const QVariant &value) -{ - // For debugging purposes only: -// qDebug() << QString::number(change) << " : " << value.toString(); - return QGraphicsItem::itemChange(change, value); -} - - #include "moc_declarativeseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/qmlplugin/declarativeseries.h b/qmlplugin/declarativeseries.h index 0d57425..0392a95 100644 --- a/qmlplugin/declarativeseries.h +++ b/qmlplugin/declarativeseries.h @@ -34,9 +34,6 @@ signals: public slots: void setParentForSeries(); -public: // from QDeclarativeItem - QVariant itemChange(GraphicsItemChange, const QVariant &); - public: void setSeriesType(SeriesType type); SeriesType seriesType() { return m_seriesType; } diff --git a/test/qmlchart/qml/qmlchart/main.qml b/test/qmlchart/qml/qmlchart/main.qml index a89563c..8a75b2d 100644 --- a/test/qmlchart/qml/qmlchart/main.qml +++ b/test/qmlchart/qml/qmlchart/main.qml @@ -30,28 +30,6 @@ Rectangle { // console.log("Component.onCompleted: " + chartModel.get(0).dataX); } - // TODO: a bug: drawing order affects the drawing; if you draw chart1 first (by changing the - // z-order), then chart2 is not shown at all. By drawing chart2 first, both are visible. - Chart { - id: chart2 - anchors.top: chart1.bottom - anchors.bottom: parent.bottom - anchors.left: parent.left - anchors.right: parent.right - theme: Chart.ThemeScientific - - ScatterSeries { - id: scatterSeries - data: [ - ScatterElement { x: 1.1; y: 2.1 }, - ScatterElement { x: 1.2; y: 2.0 }, - ScatterElement { x: 1.4; y: 2.3 }, - ScatterElement { x: 3.1; y: 5.3 }, - ScatterElement { x: 4.1; y: 3.7 } - ] - } - } - Chart { id: chart1 anchors.top: parent.top @@ -59,19 +37,60 @@ Rectangle { anchors.right: parent.right height: parent.height / 2 theme: Chart.ThemeIcy - opacity: 0.3 +// opacity: 0.3 Series { seriesType: Series.SeriesTypePie } - Series { - seriesType: Series.SeriesTypeLine - } + // TODO: a bug: drawing order affects the drawing; if you draw chart1 first (by changing the + // z-order), then chart2 is not shown at all. By drawing chart2 first, both are visible. + // Also, if you don't draw line series on chart1 (only pie), both charts are visible. +// Series { +// seriesType: Series.SeriesTypeLine +// } // TODO: // Series { // seriesType: Series.SeriesTypeBar // } } + + Chart { + id: chart2 + anchors.top: chart1.bottom + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + theme: Chart.ThemeScientific + + ScatterSeries { + data: [ + ScatterElement { x: 1.1; y: 2.1 }, + ScatterElement { x: 1.2; y: 2.0 }, + ScatterElement { x: 1.4; y: 2.3 } + ] + } + ScatterSeries { + data: [ + ScatterElement { x: 1.2; y: 2.2 }, + ScatterElement { x: 1.3; y: 2.2 }, + ScatterElement { x: 1.7; y: 2.6 } + ] + } + ScatterSeries { + data: [ + ScatterElement { x: 1.3; y: 2.3 }, + ScatterElement { x: 1.5; y: 2.4 }, + ScatterElement { x: 2.0; y: 2.9 } + ] + } + ScatterSeries { + data: [ + ScatterElement { x: 1.4; y: 2.4 }, + ScatterElement { x: 1.8; y: 2.7 }, + ScatterElement { x: 2.5; y: 3.2 } + ] + } + } }