diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/charts/axis/cartesianchartaxis.cpp | 27 | ||||
-rw-r--r-- | src/charts/axis/chartaxiselement.cpp | 22 | ||||
-rw-r--r-- | src/charts/axis/horizontalaxis.cpp | 8 | ||||
-rw-r--r-- | src/charts/axis/valueaxis/chartvalueaxisx.cpp | 13 | ||||
-rw-r--r-- | src/charts/axis/valueaxis/chartvalueaxisy.cpp | 13 | ||||
-rw-r--r-- | src/charts/chartpresenter.cpp | 2 | ||||
-rw-r--r-- | src/charts/domain/abstractdomain.cpp | 3 | ||||
-rw-r--r-- | src/charts/layout/abstractchartlayout.cpp | 22 | ||||
-rw-r--r-- | src/charts/legend/legendmarkeritem.cpp | 2 | ||||
-rw-r--r-- | src/charts/piechart/qpieslice.cpp | 2 | ||||
-rw-r--r-- | src/charts/xychart/qxymodelmapper.cpp | 27 | ||||
-rw-r--r-- | src/chartsqml2/declarativechart.cpp | 8 |
12 files changed, 82 insertions, 67 deletions
diff --git a/src/charts/axis/cartesianchartaxis.cpp b/src/charts/axis/cartesianchartaxis.cpp index 935a9601..6389c17e 100644 --- a/src/charts/axis/cartesianchartaxis.cpp +++ b/src/charts/axis/cartesianchartaxis.cpp @@ -130,15 +130,16 @@ void CartesianChartAxis::updateMinorTickItems() expectedCount = qMax(expectedCount, 0); } else { const qreal interval = valueAxis->tickInterval(); - qreal firstMajorTick = valueAxis->tickAnchor(); + const qreal anchor = valueAxis->tickAnchor(); const qreal max = valueAxis->max(); const qreal min = valueAxis->min(); const int _minorTickCount = valueAxis->minorTickCount(); - if (min < firstMajorTick) - firstMajorTick = firstMajorTick - qCeil((firstMajorTick - min) / interval) * interval; - else - firstMajorTick = firstMajorTick + int((min - firstMajorTick) / interval) * interval; + // Find the closest major tick <= the min of the range, even if it's not drawn! + // This is where we'll start counting minor ticks from, because minor ticks + // might need to be drawn even before the first major tick. + const qreal ticksFromAnchor = (anchor - min) / interval; + const qreal firstMajorTick = anchor - std::ceil(ticksFromAnchor) * interval; const qreal deltaMinor = interval / qreal(_minorTickCount + 1); qreal minorTick = firstMajorTick + deltaMinor; @@ -265,7 +266,7 @@ bool CartesianChartAxis::isEmpty() { return axisGeometry().isEmpty() || gridGeometry().isEmpty() - || qFuzzyCompare(min(), max()); + || qFuzzyIsNull(max() - min()); } void CartesianChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) @@ -371,16 +372,16 @@ void CartesianChartAxis::updateLabelsValues(QValueAxis *axis) static_cast<ValueAxisLabel *>(labelItems().at(i))->setValue(value); } } else { - qreal value = axis->tickAnchor(); - if (value > min()) - value = value - int((value - min()) / axis->tickInterval()) * axis->tickInterval(); - else - value = value + qCeil((min() - value) / axis->tickInterval()) * axis->tickInterval(); + const qreal anchor = axis->tickAnchor(); + const qreal interval = axis->tickInterval(); + const qreal ticksFromAnchor = (anchor - min()) / interval; + const qreal firstMajorTick = anchor - std::floor(ticksFromAnchor) * interval; int i = axis->isReverse() ? labelItems().count()-1 : 0; - while (value <= max() || qFuzzyCompare(value, max())) { + qreal value = firstMajorTick; + while (value <= max()) { static_cast<ValueAxisLabel *>(labelItems().at(i))->setValue(value); - value += axis->tickInterval(); + value += interval; i += axis->isReverse() ? -1 : 1; } } diff --git a/src/charts/axis/chartaxiselement.cpp b/src/charts/axis/chartaxiselement.cpp index 33a31242..2a874216 100644 --- a/src/charts/axis/chartaxiselement.cpp +++ b/src/charts/axis/chartaxiselement.cpp @@ -339,7 +339,7 @@ bool ChartAxisElement::isEmpty() { return axisGeometry().isEmpty() || gridGeometry().isEmpty() - || qFuzzyCompare(min(), max()); + || qFuzzyIsNull(max() - min()); } qreal ChartAxisElement::min() const @@ -430,13 +430,11 @@ QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, labels << presenter()->numberToString(value, 'f', n); } } else { - qreal value = tickAnchor; - if (value > min) - value = value - int((value - min) / tickInterval) * tickInterval; - else - value = value + qCeil((min - value) / tickInterval) * tickInterval; + const qreal ticksFromAnchor = (tickAnchor - min) / tickInterval; + const qreal firstMajorTick = tickAnchor - std::floor(ticksFromAnchor) * tickInterval; - while (value <= max || qFuzzyCompare(value, max)) { + qreal value = firstMajorTick; + while (value <= max) { labels << presenter()->numberToString(value, 'f', n); value += tickInterval; } @@ -472,13 +470,11 @@ QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, labels << formatLabel(formatSpec, array, value, precision, preStr, postStr); } } else { - qreal value = tickAnchor; - if (value > min) - value = value - int((value - min) / tickInterval) * tickInterval; - else - value = value + qCeil((min - value) / tickInterval) * tickInterval; + const qreal ticksFromAnchor = (tickAnchor - min) / tickInterval; + const qreal firstMajorTick = tickAnchor - std::floor(ticksFromAnchor) * tickInterval; - while (value <= max || qFuzzyCompare(value, max)) { + qreal value = firstMajorTick; + while (value <= max) { labels << formatLabel(formatSpec, array, value, precision, preStr, postStr); value += tickInterval; } diff --git a/src/charts/axis/horizontalaxis.cpp b/src/charts/axis/horizontalaxis.cpp index 5b74b563..a54339aa 100644 --- a/src/charts/axis/horizontalaxis.cpp +++ b/src/charts/axis/horizontalaxis.cpp @@ -436,12 +436,12 @@ void HorizontalAxis::updateMinorTickGeometry() qreal minorArrowLineItemY2; switch (axis()->alignment()) { case Qt::AlignTop: - minorArrowLineItemY1 = gridGeometry().bottom(); - minorArrowLineItemY2 = gridGeometry().bottom() - labelPadding() / 2.0; + minorArrowLineItemY1 = gridGeometry().top(); + minorArrowLineItemY2 = gridGeometry().top() - labelPadding() / 2.0; break; case Qt::AlignBottom: - minorArrowLineItemY1 = gridGeometry().top(); - minorArrowLineItemY2 = gridGeometry().top() + labelPadding() / 2.0; + minorArrowLineItemY1 = gridGeometry().bottom(); + minorArrowLineItemY2 = gridGeometry().bottom() + labelPadding() / 2.0; break; default: minorArrowLineItemY1 = 0.0; diff --git a/src/charts/axis/valueaxis/chartvalueaxisx.cpp b/src/charts/axis/valueaxis/chartvalueaxisx.cpp index 3eac86e0..db943480 100644 --- a/src/charts/axis/valueaxis/chartvalueaxisx.cpp +++ b/src/charts/axis/valueaxis/chartvalueaxisx.cpp @@ -75,22 +75,21 @@ QVector<qreal> ChartValueAxisX::calculateLayout() const return points; } else { // QValueAxis::TicksDynamic const qreal interval = m_axis->tickInterval(); - qreal value = m_axis->tickAnchor(); + const qreal anchor = m_axis->tickAnchor(); const qreal maxValue = max(); const qreal minValue = min(); - // Find the first major tick right after the min of range - if (value > minValue) - value = value - int((value - minValue) / interval) * interval; - else - value = value + qCeil((minValue - value) / interval) * interval; + // Find the first major tick right after the min of the range + const qreal ticksFromAnchor = (anchor - minValue) / interval; + const qreal firstMajorTick = anchor - std::floor(ticksFromAnchor) * interval; const QRectF &gridRect = gridGeometry(); const qreal deltaX = gridRect.width() / (maxValue - minValue); QVector<qreal> points; const qreal leftPos = gridRect.left(); - while (value <= maxValue || qFuzzyCompare(value, maxValue)) { + qreal value = firstMajorTick; + while (value <= maxValue) { points << (value - minValue) * deltaX + leftPos; value += interval; } diff --git a/src/charts/axis/valueaxis/chartvalueaxisy.cpp b/src/charts/axis/valueaxis/chartvalueaxisy.cpp index c4868fc2..3ffeddf9 100644 --- a/src/charts/axis/valueaxis/chartvalueaxisy.cpp +++ b/src/charts/axis/valueaxis/chartvalueaxisy.cpp @@ -76,22 +76,21 @@ QVector<qreal> ChartValueAxisY::calculateLayout() const return points; } else { const qreal interval = m_axis->tickInterval(); - qreal value = m_axis->tickAnchor(); + const qreal anchor = m_axis->tickAnchor(); const qreal maxValue = max(); const qreal minValue = min(); - // Find the first major tick right after the min of range - if (value > minValue) - value = value - int((value - minValue) / interval) * interval; - else - value = value + qCeil((minValue - value) / interval) * interval; + // Find the first major tick right after the min of the range + const qreal ticksFromAnchor = (anchor - minValue) / interval; + const qreal firstMajorTick = anchor - std::floor(ticksFromAnchor) * interval; const QRectF &gridRect = gridGeometry(); const qreal deltaY = gridRect.height() / (maxValue - minValue); QVector<qreal> points; const qreal bottomPos = gridRect.bottom(); - while (value <= maxValue || qFuzzyCompare(value, maxValue)) { + qreal value = firstMajorTick; + while (value <= maxValue) { points << (value - minValue) * -deltaY + bottomPos; value += interval; } diff --git a/src/charts/chartpresenter.cpp b/src/charts/chartpresenter.cpp index 12d3958d..f482adf3 100644 --- a/src/charts/chartpresenter.cpp +++ b/src/charts/chartpresenter.cpp @@ -98,7 +98,7 @@ void ChartPresenter::setFixedGeometry(const QRectF &rect) void ChartPresenter::setGeometry(const QRectF rect) { - if (m_rect != rect) { + if (rect.isValid() && m_rect != rect) { m_rect = rect; if (!m_fixedRect.isNull()) return; diff --git a/src/charts/domain/abstractdomain.cpp b/src/charts/domain/abstractdomain.cpp index 36e4974a..be50d7cf 100644 --- a/src/charts/domain/abstractdomain.cpp +++ b/src/charts/domain/abstractdomain.cpp @@ -58,6 +58,9 @@ AbstractDomain::~AbstractDomain() void AbstractDomain::setSize(const QSizeF &size) { + if (!size.isValid()) + return; + if (m_size != size) { m_size=size; emit updated(); diff --git a/src/charts/layout/abstractchartlayout.cpp b/src/charts/layout/abstractchartlayout.cpp index fd3c5e97..3d31dd07 100644 --- a/src/charts/layout/abstractchartlayout.cpp +++ b/src/charts/layout/abstractchartlayout.cpp @@ -53,8 +53,12 @@ void AbstractChartLayout::setGeometry(const QRectF &rect) { if (!rect.isValid()) return; - // If the chart has a fixed geometry then don't update visually - const bool updateLayout = (!m_presenter->isFixedGeometry() || m_presenter->geometry() == rect); + + // If the chart has a fixed geometry then don't update visually, unless plotbackground is + // visible. + const bool updateLayout = (!m_presenter->isFixedGeometry() + || m_presenter->isPlotAreaBackgroundVisible() + || m_presenter->geometry() == rect); if (m_presenter->chart()->isVisible()) { QList<ChartAxisElement *> axes = m_presenter->axisItems(); ChartTitle *title = m_presenter->titleElement(); @@ -73,12 +77,14 @@ void AbstractChartLayout::setGeometry(const QRectF &rect) contentGeometry = calculateAxisGeometry(contentGeometry, axes, updateLayout); - m_presenter->setGeometry(contentGeometry); - if (updateLayout) { - if (m_presenter->chart()->chartType() == QChart::ChartTypeCartesian) - static_cast<QGraphicsRectItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry); - else - static_cast<QGraphicsEllipseItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry); + if (contentGeometry.isValid()) { + m_presenter->setGeometry(contentGeometry); + if (updateLayout) { + if (m_presenter->chart()->chartType() == QChart::ChartTypeCartesian) + static_cast<QGraphicsRectItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry); + else + static_cast<QGraphicsEllipseItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry); + } } } diff --git a/src/charts/legend/legendmarkeritem.cpp b/src/charts/legend/legendmarkeritem.cpp index 2986b687..7121783d 100644 --- a/src/charts/legend/legendmarkeritem.cpp +++ b/src/charts/legend/legendmarkeritem.cpp @@ -126,7 +126,7 @@ QFont LegendMarkerItem::font() const void LegendMarkerItem::setLabel(const QString label) { m_label = label; - updateGeometry(); + m_marker->invalidateLegend(); } QString LegendMarkerItem::label() const diff --git a/src/charts/piechart/qpieslice.cpp b/src/charts/piechart/qpieslice.cpp index f36f93a3..8ed844b6 100644 --- a/src/charts/piechart/qpieslice.cpp +++ b/src/charts/piechart/qpieslice.cpp @@ -108,11 +108,13 @@ QT_CHARTS_BEGIN_NAMESPACE /*! \property QPieSlice::label \brief The label of the slice. + \note The string can be HTML formatted. \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor */ /*! \qmlproperty string PieSlice::label The label of the slice. + \note The string can be HTML formatted. */ /*! diff --git a/src/charts/xychart/qxymodelmapper.cpp b/src/charts/xychart/qxymodelmapper.cpp index d1f2e9f5..553b67a6 100644 --- a/src/charts/xychart/qxymodelmapper.cpp +++ b/src/charts/xychart/qxymodelmapper.cpp @@ -367,31 +367,32 @@ void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottom blockSeriesSignals(); QModelIndex index; - QPointF oldPoint; QPointF newPoint; + int indexColumn = 0; + int indexRow = 0; for (int row = topLeft.row(); row <= bottomRight.row(); row++) { for (int column = topLeft.column(); column <= bottomRight.column(); column++) { index = topLeft.sibling(row, column); - if (m_orientation == Qt::Vertical && (index.column() == m_xSection || index.column() == m_ySection)) { - if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { - QModelIndex xIndex = xModelIndex(index.row() - m_first); - QModelIndex yIndex = yModelIndex(index.row() - m_first); + indexColumn = index.column(); + indexRow = index.row(); + if (m_orientation == Qt::Vertical && (indexColumn == m_xSection || indexColumn == m_ySection)) { + if (indexRow >= m_first && (m_count == - 1 || indexRow < m_first + m_count)) { + QModelIndex xIndex = xModelIndex(indexRow - m_first); + QModelIndex yIndex = yModelIndex(indexRow - m_first); if (xIndex.isValid() && yIndex.isValid()) { - oldPoint = m_series->points().at(index.row() - m_first); newPoint.setX(valueFromModel(xIndex)); newPoint.setY(valueFromModel(yIndex)); - m_series->replace(index.row() - m_first, newPoint); + m_series->replace(indexRow - m_first, newPoint); } } - } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) { - if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { - QModelIndex xIndex = xModelIndex(index.column() - m_first); - QModelIndex yIndex = yModelIndex(index.column() - m_first); + } else if (m_orientation == Qt::Horizontal && (indexRow == m_xSection || indexRow == m_ySection)) { + if (indexColumn >= m_first && (m_count == - 1 || indexColumn < m_first + m_count)) { + QModelIndex xIndex = xModelIndex(indexColumn - m_first); + QModelIndex yIndex = yModelIndex(indexColumn - m_first); if (xIndex.isValid() && yIndex.isValid()) { - oldPoint = m_series->points().at(index.column() - m_first); newPoint.setX(valueFromModel(xIndex)); newPoint.setY(valueFromModel(yIndex)); - m_series->replace(index.column() - m_first, newPoint); + m_series->replace(indexColumn - m_first, newPoint); } } } diff --git a/src/chartsqml2/declarativechart.cpp b/src/chartsqml2/declarativechart.cpp index a58e67c7..84fc9871 100644 --- a/src/chartsqml2/declarativechart.cpp +++ b/src/chartsqml2/declarativechart.cpp @@ -61,6 +61,7 @@ #include <QtCore/QTimer> #include <QtCore/QThread> #include <QtQuick/QQuickWindow> +#include <QtWidgets/QGraphicsLayout> QT_CHARTS_BEGIN_NAMESPACE @@ -632,9 +633,12 @@ void DeclarativeChart::seriesAxisAttachHelper(QAbstractSeries *series, QAbstract { if (!series->attachedAxes().contains(axis)) { // Remove & delete old axes that are not attached to any other series + // Detach old axis from series so that if it is shared with other series + // It can be deleted. foreach (QAbstractAxis* oldAxis, m_chart->axes(orientation, series)) { bool otherAttachments = false; if (oldAxis != axis) { + series->detachAxis(oldAxis); foreach (QAbstractSeries *oldSeries, m_chart->series()) { if (oldSeries != series && oldSeries->attachedAxes().contains(oldAxis)) { otherAttachments = true; @@ -1496,6 +1500,10 @@ QPointF DeclarativeChart::mapToPosition(const QPointF &value, QAbstractSeries *s void DeclarativeChart::setPlotArea(const QRectF &rect) { m_chart->setPlotArea(rect); + + // If plotArea is set inside ChartView, contentGeometry is updated too early and we end up + // with incorrect plotArea. Invalidate the layout to correct the geometry. + m_chart->layout()->invalidate(); } QT_CHARTS_END_NAMESPACE |