From dab4dfead39d02e711a9f2b5bfd7a42b30125fba 2015-09-07 07:56:05 From: Titta Heikkala Date: 2015-09-07 07:56:05 Subject: [PATCH] Added minor ticks to value axis Added possibility to set minor tick for value axis. By default the count of minor ticks is zero. The arrow of minor ticks follows the color and pen of the arrows of the major ticks as it's part of axis. Change-Id: I8a422caaeedcd18ee6144e8636e3903d16f0632c Task-number: QTRD-3294 Reviewed-by: Miikka Heikkinen --- diff --git a/src/charts/axis/cartesianchartaxis.cpp b/src/charts/axis/cartesianchartaxis.cpp index 8e71d60..374d846 100644 --- a/src/charts/axis/cartesianchartaxis.cpp +++ b/src/charts/axis/cartesianchartaxis.cpp @@ -89,6 +89,35 @@ void CartesianChartAxis::createItems(int count) } } +void CartesianChartAxis::updateMinorTickItems() +{ + QValueAxis *valueAxis = qobject_cast(this->axis()); + if (valueAxis) { + int currentCount = minorArrowItems().size(); + int expectedCount = valueAxis->minorTickCount() * (valueAxis->tickCount() - 1); + int diff = expectedCount - currentCount; + if (diff > 0) { + for (int i = 0; i < diff; i++) { + QGraphicsLineItem *minorArrow = new QGraphicsLineItem(this); + QGraphicsLineItem *minorGrid = new QGraphicsLineItem(this); + minorArrow->setPen(valueAxis->linePen()); + minorGrid->setPen(valueAxis->minorGridLinePen()); + minorArrowGroup()->addToGroup(minorArrow); + minorGridGroup()->addToGroup(minorGrid); + } + } else { + QList minorGridLines = minorGridItems(); + QList minorArrows = minorArrowItems(); + for (int i = 0; i > diff; i--) { + if (!minorGridLines.isEmpty()) + delete(minorGridLines.takeLast()); + if (!minorArrows.isEmpty()) + delete(minorArrows.takeLast()); + } + } + } +} + void CartesianChartAxis::deleteItems(int count) { QList lines = gridItems(); @@ -114,6 +143,8 @@ void CartesianChartAxis::updateLayout(QVector &layout) else if (diff < 0) createItems(-diff); + updateMinorTickItems(); + if (animation()) { switch (presenter()->state()) { case ChartPresenter::ZoomInState: @@ -182,6 +213,18 @@ void CartesianChartAxis::handleGridPenChanged(const QPen &pen) static_cast(item)->setPen(pen); } +void CartesianChartAxis::handleMinorArrowPenChanged(const QPen &pen) +{ + foreach (QGraphicsItem *item, minorArrowItems()) + static_cast(item)->setPen(pen); +} + +void CartesianChartAxis::handleMinorGridPenChanged(const QPen &pen) +{ + foreach (QGraphicsItem *item, minorGridItems()) + static_cast(item)->setPen(pen); +} + void CartesianChartAxis::handleShadesBrushChanged(const QBrush &brush) { foreach (QGraphicsItem *item, shadeItems()) diff --git a/src/charts/axis/cartesianchartaxis_p.h b/src/charts/axis/cartesianchartaxis_p.h index e945936..c59443a 100644 --- a/src/charts/axis/cartesianchartaxis_p.h +++ b/src/charts/axis/cartesianchartaxis_p.h @@ -60,10 +60,13 @@ public Q_SLOTS: virtual void handleGridPenChanged(const QPen &pen); virtual void handleShadesBrushChanged(const QBrush &brush); virtual void handleShadesPenChanged(const QPen &pen); + virtual void handleMinorArrowPenChanged(const QPen &pen); + virtual void handleMinorGridPenChanged(const QPen &pen); private: void createItems(int count); void deleteItems(int count); + void updateMinorTickItems(); private: QRectF m_gridRect; diff --git a/src/charts/axis/chartaxiselement.cpp b/src/charts/axis/chartaxiselement.cpp index 90cce21..1667f0c 100644 --- a/src/charts/axis/chartaxiselement.cpp +++ b/src/charts/axis/chartaxiselement.cpp @@ -48,6 +48,8 @@ ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, boo m_animation(0), m_grid(new QGraphicsItemGroup(item)), m_arrow(new QGraphicsItemGroup(item)), + m_minorGrid(new QGraphicsItemGroup(item)), + m_minorArrow(new QGraphicsItemGroup(item)), m_shades(new QGraphicsItemGroup(item)), m_labels(new QGraphicsItemGroup(item)), m_title(new QGraphicsTextItem(item)), @@ -57,9 +59,12 @@ ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, boo //initial initialization m_arrow->setHandlesChildEvents(false); m_arrow->setZValue(ChartPresenter::AxisZValue); + m_minorArrow->setHandlesChildEvents(false); + m_minorArrow->setZValue(ChartPresenter::AxisZValue); m_labels->setZValue(ChartPresenter::AxisZValue); m_shades->setZValue(ChartPresenter::ShadesZValue); m_grid->setZValue(ChartPresenter::GridZValue); + m_minorGrid->setZValue(ChartPresenter::GridZValue); m_title->setZValue(ChartPresenter::GridZValue); m_title->document()->setDocumentMargin(ChartPresenter::textMargin()); handleVisibleChanged(axis->isVisible()); @@ -92,6 +97,14 @@ void ChartAxisElement::connectSlots() QObject::connect(axis(), SIGNAL(titleVisibleChanged(bool)), this, SLOT(handleTitleVisibleChanged(bool))); QObject::connect(axis()->d_ptr.data(), SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(handleRangeChanged(qreal, qreal))); QObject::connect(axis(), SIGNAL(reverseChanged(bool)), this, SLOT(handleReverseChanged(bool))); + QObject::connect(axis(), SIGNAL(lineVisibleChanged(bool)), + this, SLOT(handleMinorArrowVisibleChanged(bool))); + QObject::connect(axis(), SIGNAL(linePenChanged(const QPen&)), this, + SLOT(handleMinorArrowPenChanged(const QPen&))); + QObject::connect(axis(), SIGNAL(minorGridVisibleChanged(bool)), + this, SLOT(handleMinorGridVisibleChanged(bool))); + QObject::connect(axis(), SIGNAL(minorGridLinePenChanged(const QPen&)), + this, SLOT(handleMinorGridPenChanged(const QPen&))); } void ChartAxisElement::handleArrowVisibleChanged(bool visible) @@ -99,11 +112,21 @@ void ChartAxisElement::handleArrowVisibleChanged(bool visible) m_arrow->setVisible(visible); } +void ChartAxisElement::handleMinorArrowVisibleChanged(bool visible) +{ + m_minorArrow->setVisible(visible); +} + void ChartAxisElement::handleGridVisibleChanged(bool visible) { m_grid->setVisible(visible); } +void ChartAxisElement::handleMinorGridVisibleChanged(bool visible) +{ + m_minorGrid->setVisible(visible); +} + void ChartAxisElement::handleLabelsVisibleChanged(bool visible) { QGraphicsLayoutItem::updateGeometry(); @@ -174,12 +197,16 @@ void ChartAxisElement::handleVisibleChanged(bool visible) if (!visible) { m_grid->setVisible(visible); m_arrow->setVisible(visible); + m_minorGrid->setVisible(visible); + m_minorArrow->setVisible(visible); m_shades->setVisible(visible); m_labels->setVisible(visible); m_title->setVisible(visible); } else { m_grid->setVisible(axis()->isGridLineVisible()); m_arrow->setVisible(axis()->isLineVisible()); + m_minorGrid->setVisible(axis()->isMinorGridLineVisible()); + m_minorArrow->setVisible(axis()->isLineVisible()); m_shades->setVisible(axis()->shadesVisible()); m_labels->setVisible(axis()->labelsVisible()); m_title->setVisible(axis()->isTitleVisible()); diff --git a/src/charts/axis/chartaxiselement_p.h b/src/charts/axis/chartaxiselement_p.h index f1acf63..3ca2797 100644 --- a/src/charts/axis/chartaxiselement_p.h +++ b/src/charts/axis/chartaxiselement_p.h @@ -96,14 +96,18 @@ protected: virtual void updateLayout(QVector &layout) = 0; QList gridItems() { return m_grid->childItems(); } + QList minorGridItems() { return m_minorGrid->childItems(); } QList labelItems() { return m_labels->childItems(); } QList shadeItems() { return m_shades->childItems(); } QList arrowItems() { return m_arrow->childItems(); } + QList minorArrowItems() { return m_minorArrow->childItems(); } QGraphicsTextItem *titleItem() const { return m_title.data(); } QGraphicsItemGroup *gridGroup() { return m_grid.data(); } + QGraphicsItemGroup *minorGridGroup() { return m_minorGrid.data(); } QGraphicsItemGroup *labelGroup() { return m_labels.data(); } QGraphicsItemGroup *shadeGroup() { return m_shades.data(); } QGraphicsItemGroup *arrowGroup() { return m_arrow.data(); } + QGraphicsItemGroup *minorArrowGroup() { return m_minorArrow.data(); } public Q_SLOTS: void handleVisibleChanged(bool visible); @@ -116,6 +120,8 @@ public Q_SLOTS: virtual void handleShadesPenChanged(const QPen &pen) = 0; virtual void handleArrowPenChanged(const QPen &pen) = 0; virtual void handleGridPenChanged(const QPen &pen) = 0; + virtual void handleMinorArrowPenChanged(const QPen &pen) = 0; + virtual void handleMinorGridPenChanged(const QPen &pen) = 0; void handleLabelsBrushChanged(const QBrush &brush); void handleLabelsFontChanged(const QFont &font); void handleTitleBrushChanged(const QBrush &brush); @@ -124,6 +130,9 @@ public Q_SLOTS: void handleTitleVisibleChanged(bool visible); void handleRangeChanged(qreal min, qreal max); void handleReverseChanged(bool reverse); + void handleMinorArrowVisibleChanged(bool visible); + void handleMinorGridVisibleChanged(bool visible); + Q_SIGNALS: void clicked(); @@ -141,6 +150,8 @@ private: QRectF m_axisRect; QScopedPointer m_grid; QScopedPointer m_arrow; + QScopedPointer m_minorGrid; + QScopedPointer m_minorArrow; QScopedPointer m_shades; QScopedPointer m_labels; QScopedPointer m_title; diff --git a/src/charts/axis/horizontalaxis.cpp b/src/charts/axis/horizontalaxis.cpp index 875bf47..fa4b038 100644 --- a/src/charts/axis/horizontalaxis.cpp +++ b/src/charts/axis/horizontalaxis.cpp @@ -94,6 +94,8 @@ void HorizontalAxis::updateGeometry() QList lines = gridItems(); QList shades = shadeItems(); + QList minorLines = minorGridItems(); + QList minorArrows = minorArrowItems(); for (int i = 0; i < layout.size(); ++i) { //items @@ -279,6 +281,54 @@ void HorizontalAxis::updateGeometry() tickItem->setVisible(true); } + // add minor ticks + QValueAxis *valueAxis = qobject_cast(axis()); + if ((i + 1) != layout.size() && valueAxis) { + int minorTickCount = valueAxis->minorTickCount(); + if (minorTickCount != 0) { + qreal minorTickDistance = (layout[i] - layout[i + 1]) / qreal(minorTickCount + 1); + for (int j = 0; j < minorTickCount; j++) { + QGraphicsLineItem *minorGridItem = + static_cast(minorLines.at(i * minorTickCount + j)); + QGraphicsLineItem *minorArrowItem = + static_cast(minorArrows.at(i * minorTickCount + j)); + if (i == 0) { + minorGridItem->setLine(gridRect.left() - minorTickDistance * qreal(j + 1), + gridRect.top(), + gridRect.left() - minorTickDistance * qreal(j + 1), + gridRect.bottom()); + } else { + minorGridItem->setLine(gridItem->line().p1().x() + - minorTickDistance * qreal(j + 1), + gridRect.top(), + gridItem->line().p1().x() + - minorTickDistance * qreal(j + 1), + gridRect.bottom()); + } + if (axis()->alignment() == Qt::AlignTop) { + minorArrowItem->setLine(minorGridItem->line().p1().x(), + axisRect.bottom(), + minorGridItem->line().p1().x(), + axisRect.bottom() - labelPadding() / 2); + } else if (axis()->alignment() == Qt::AlignBottom){ + minorArrowItem->setLine(minorGridItem->line().p1().x(), + axisRect.top(), + minorGridItem->line().p1().x(), + axisRect.top() + labelPadding() / 2); + } + + // check if the minor grid line and the axis tick should be shown + qreal minorXPos = minorGridItem->line().p1().x(); + if (minorXPos < gridRect.left() || minorXPos > gridRect.right()) { + minorGridItem->setVisible(false); + minorArrowItem->setVisible(false); + } else { + minorGridItem->setVisible(true); + minorArrowItem->setVisible(true); + } + } + } + } } //begin/end grid line in case labels between diff --git a/src/charts/axis/polarchartaxis.cpp b/src/charts/axis/polarchartaxis.cpp index 0d111d0..6bf15ab 100644 --- a/src/charts/axis/polarchartaxis.cpp +++ b/src/charts/axis/polarchartaxis.cpp @@ -19,6 +19,7 @@ #include #include #include +#include QT_CHARTS_BEGIN_NAMESPACE @@ -77,6 +78,8 @@ void PolarChartAxis::updateLayout(QVector &layout) else if (diff < 0) createItems(-diff); + updateMinorTickItems(); + if (animation()) { animation()->setValues(ChartAxisElement::layout(), layout); presenter()->startAnimation(animation()); diff --git a/src/charts/axis/polarchartaxis_p.h b/src/charts/axis/polarchartaxis_p.h index 34ade89..3a1cea6 100644 --- a/src/charts/axis/polarchartaxis_p.h +++ b/src/charts/axis/polarchartaxis_p.h @@ -54,6 +54,7 @@ protected: protected: // virtual functions virtual void createItems(int count) = 0; virtual void createAxisLabels(const QVector &layout) = 0; + virtual void updateMinorTickItems() = 0; public Q_SLOTS: virtual void handleShadesBrushChanged(const QBrush &brush); diff --git a/src/charts/axis/polarchartaxisangular.cpp b/src/charts/axis/polarchartaxisangular.cpp index 9b22058..b09ebc0 100644 --- a/src/charts/axis/polarchartaxisangular.cpp +++ b/src/charts/axis/polarchartaxisangular.cpp @@ -51,6 +51,8 @@ void PolarChartAxisAngular::updateGeometry() QList gridItemList = gridItems(); QList labelItemList = labelItems(); QList shadeItemList = shadeItems(); + QList minorGridItemList = minorGridItems(); + QList minorArrowItemList = minorArrowItems(); QGraphicsTextItem *title = titleItem(); QGraphicsEllipseItem *axisLine = static_cast(arrowItemList.at(0)); @@ -217,6 +219,36 @@ void PolarChartAxisAngular::updateGeometry() shadeItem->setVisible(true); firstShade = false; } + + // Minor ticks + QValueAxis *valueAxis = qobject_cast(axis()); + if ((i + 1) != layout.size() && valueAxis) { + int minorTickCount = valueAxis->minorTickCount(); + if (minorTickCount != 0) { + qreal minorAngularCoordinate = (layout[i + 1] - layout[i]) + / qreal(minorTickCount + 1); + for (int j = 0; j < minorTickCount; j++) { + QGraphicsLineItem *minorGridItem = + static_cast(minorGridItemList.at(i * minorTickCount + j)); + QGraphicsLineItem *minorTickItem = + static_cast(minorArrowItemList.at(i * minorTickCount + j)); + qreal minorAngle = 90.0 - angularCoordinate + - minorAngularCoordinate * qreal(j + 1); + QLineF minorGridLine = QLineF::fromPolar(radius, minorAngle); + minorGridLine.translate(center); + minorGridItem->setLine(minorGridLine); + minorGridItem->setVisible(true); + + QLineF minorTickLine(QLineF::fromPolar(radius - tickWidth() + 1, + minorAngle).p2(), + QLineF::fromPolar(radius + tickWidth() - 1, + minorAngle).p2()); + minorTickLine.translate(center); + minorTickItem->setLine(minorTickLine); + minorTickItem->setVisible(true); + } + } + } } // Title, centered above the chart @@ -299,6 +331,19 @@ void PolarChartAxisAngular::handleGridPenChanged(const QPen &pen) static_cast(item)->setPen(pen); } +void PolarChartAxisAngular::handleMinorArrowPenChanged(const QPen &pen) +{ + foreach (QGraphicsItem *item, minorArrowItems()) { + static_cast(item)->setPen(pen); + } +} + +void PolarChartAxisAngular::handleMinorGridPenChanged(const QPen &pen) +{ + foreach (QGraphicsItem *item, minorGridItems()) + static_cast(item)->setPen(pen); +} + QSizeF PolarChartAxisAngular::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { Q_UNUSED(which); @@ -426,6 +471,36 @@ QRectF PolarChartAxisAngular::moveLabelToPosition(qreal angularCoordinate, QPoin return labelRect; } +void PolarChartAxisAngular::updateMinorTickItems() +{ + QValueAxis *valueAxis = qobject_cast(this->axis()); + if (valueAxis) { + int currentCount = minorArrowItems().size(); + int expectedCount = valueAxis->minorTickCount() * (valueAxis->tickCount() - 1); + int diff = expectedCount - currentCount; + if (diff > 0) { + for (int i = 0; i < diff; i++) { + QGraphicsLineItem *minorArrow = new QGraphicsLineItem(presenter()->rootItem()); + QGraphicsLineItem *minorGrid = new QGraphicsLineItem(presenter()->rootItem()); + minorArrow->setPen(valueAxis->linePen()); + minorGrid->setPen(valueAxis->minorGridLinePen()); + minorArrowGroup()->addToGroup(minorArrow); + minorGridGroup()->addToGroup(minorGrid); + } + } else { + QList minorGridLines = minorGridItems(); + QList minorArrows = minorArrowItems(); + for (int i = 0; i > diff; i--) { + if (!minorGridLines.isEmpty()) + delete(minorGridLines.takeLast()); + if (!minorArrows.isEmpty()) + delete(minorArrows.takeLast()); + } + } + } +} + + #include "moc_polarchartaxisangular_p.cpp" QT_CHARTS_END_NAMESPACE diff --git a/src/charts/axis/polarchartaxisangular_p.h b/src/charts/axis/polarchartaxisangular_p.h index a1cb076..0e600a1 100644 --- a/src/charts/axis/polarchartaxisangular_p.h +++ b/src/charts/axis/polarchartaxisangular_p.h @@ -45,12 +45,15 @@ public: virtual void updateGeometry(); virtual void createItems(int count); + virtual void updateMinorTickItems(); qreal preferredAxisRadius(const QSizeF &maxSize); public Q_SLOTS: virtual void handleArrowPenChanged(const QPen &pen); virtual void handleGridPenChanged(const QPen &pen); + virtual void handleMinorArrowPenChanged(const QPen &pen); + virtual void handleMinorGridPenChanged(const QPen &pen); private: QRectF moveLabelToPosition(qreal angularCoordinate, QPointF labelPoint, QRectF labelRect) const; diff --git a/src/charts/axis/polarchartaxisradial.cpp b/src/charts/axis/polarchartaxisradial.cpp index 5e3cec5..af22a03 100644 --- a/src/charts/axis/polarchartaxisradial.cpp +++ b/src/charts/axis/polarchartaxisradial.cpp @@ -47,6 +47,8 @@ void PolarChartAxisRadial::updateGeometry() QList gridItemList = gridItems(); QList labelItemList = labelItems(); QList shadeItemList = shadeItems(); + QList minorGridItemList = minorGridItems(); + QList minorArrowItemList = minorArrowItems(); QGraphicsTextItem* title = titleItem(); qreal radius = axisGeometry().height() / 2.0; @@ -200,6 +202,37 @@ void PolarChartAxisRadial::updateGeometry() shadeItem->setVisible(true); firstShade = false; } + + // Minor ticks + QValueAxis *valueAxis = qobject_cast(axis()); + if ((i + 1) != layout.size() && valueAxis) { + int minorTickCount = valueAxis->minorTickCount(); + if (minorTickCount != 0) { + qreal minorRadialCoordinate = (layout[i + 1] - layout[i]) + / qreal(minorTickCount + 1) * 2.0; + for (int j = 0; j < minorTickCount; j++) { + QGraphicsEllipseItem *minorGridItem = + static_cast(minorGridItemList.at(i * minorTickCount + j)); + QGraphicsLineItem *minorTickItem = + static_cast(minorArrowItemList.at(i * minorTickCount + j)); + + QRectF minorGridRect; + minorGridRect.setWidth(minorRadialCoordinate * qreal(i + 1) + + minorRadialCoordinate * qreal(i * minorTickCount + j)); + minorGridRect.setHeight(minorRadialCoordinate * qreal(i + 1) + + minorRadialCoordinate + * qreal(i * minorTickCount + j)); + minorGridRect.moveCenter(center); + minorGridItem->setRect(minorGridRect); + minorGridItem->setVisible(true); + + QLineF minorTickLine(-tickWidth() + 1, 0.0, tickWidth() - 1, 0.0); + tickLine.translate(center.rx(), minorGridRect.top()); + minorTickItem->setLine(minorTickLine); + minorTickItem->setVisible(true); + } + } + } } // Title, along the 0 axis @@ -275,6 +308,18 @@ void PolarChartAxisRadial::handleGridPenChanged(const QPen &pen) static_cast(item)->setPen(pen); } +void PolarChartAxisRadial::handleMinorArrowPenChanged(const QPen &pen) +{ + foreach (QGraphicsItem *item, minorArrowItems()) + static_cast(item)->setPen(pen); +} + +void PolarChartAxisRadial::handleMinorGridPenChanged(const QPen &pen) +{ + foreach (QGraphicsItem *item, minorGridItems()) + static_cast(item)->setPen(pen); +} + QSizeF PolarChartAxisRadial::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { Q_UNUSED(which); @@ -290,6 +335,35 @@ qreal PolarChartAxisRadial::preferredAxisRadius(const QSizeF &maxSize) return radius; } +void PolarChartAxisRadial::updateMinorTickItems() +{ + QValueAxis *valueAxis = qobject_cast(this->axis()); + if (valueAxis) { + int currentCount = minorArrowItems().size(); + int expectedCount = valueAxis->minorTickCount() * (valueAxis->tickCount() - 1); + int diff = expectedCount - currentCount; + if (diff > 0) { + for (int i = 0; i < diff; i++) { + QGraphicsLineItem *minorArrow = new QGraphicsLineItem(presenter()->rootItem()); + QGraphicsEllipseItem *minorGrid = new QGraphicsEllipseItem(presenter()->rootItem()); + minorArrow->setPen(valueAxis->linePen()); + minorGrid->setPen(valueAxis->minorGridLinePen()); + minorArrowGroup()->addToGroup(minorArrow); + minorGridGroup()->addToGroup(minorGrid); + } + } else { + QList minorGridLines = minorGridItems(); + QList minorArrows = minorArrowItems(); + for (int i = 0; i > diff; i--) { + if (!minorGridLines.isEmpty()) + delete(minorGridLines.takeLast()); + if (!minorArrows.isEmpty()) + delete(minorArrows.takeLast()); + } + } + } +} + #include "moc_polarchartaxisradial_p.cpp" QT_CHARTS_END_NAMESPACE diff --git a/src/charts/axis/polarchartaxisradial_p.h b/src/charts/axis/polarchartaxisradial_p.h index 1949810..fbf1842 100644 --- a/src/charts/axis/polarchartaxisradial_p.h +++ b/src/charts/axis/polarchartaxisradial_p.h @@ -45,12 +45,15 @@ public: virtual void updateGeometry(); virtual void createItems(int count); + virtual void updateMinorTickItems(); qreal preferredAxisRadius(const QSizeF &maxSize); public Q_SLOTS: virtual void handleArrowPenChanged(const QPen &pen); virtual void handleGridPenChanged(const QPen &pen); + virtual void handleMinorArrowPenChanged(const QPen &pen); + virtual void handleMinorGridPenChanged(const QPen &pen); }; QT_CHARTS_END_NAMESPACE diff --git a/src/charts/axis/qabstractaxis.cpp b/src/charts/axis/qabstractaxis.cpp index 95d7f43..d290e40 100644 --- a/src/charts/axis/qabstractaxis.cpp +++ b/src/charts/axis/qabstractaxis.cpp @@ -114,6 +114,15 @@ QT_CHARTS_BEGIN_NAMESPACE */ /*! + \property QAbstractAxis::minorGridVisible + The visibility of the minor grid lines. Applies only to QValueAxis. +*/ +/*! + \qmlproperty bool AbstractAxis::minorGridVisible + The visibility of the minor grid lines. Applies only to QValueAxis. +*/ + +/*! \property QAbstractAxis::color The color of the axis and ticks. */ @@ -128,6 +137,11 @@ QT_CHARTS_BEGIN_NAMESPACE */ /*! + \property QAbstractAxis::minorGridLinePen + The pen of the minor grid line. Applies only to QValueAxis. +*/ + +/*! \property QAbstractAxis::labelsFont The font of the axis labels. */ @@ -326,11 +340,25 @@ QT_CHARTS_BEGIN_NAMESPACE */ /*! + \fn void QAbstractAxis::minorGridVisibleChanged(bool visible) + Visibility of the minor grid lines of the axis has changed to \a visible. +*/ +/*! + \qmlsignal AbstractAxis::onMinorGridVisibleChanged(bool visible) + Visibility of the minor grid lines of the axis has changed to \a visible. +*/ + +/*! \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) The pen of the grid line has changed to \a pen. */ /*! + \fn void QAbstractAxis::minorGridLinePenChanged(const QPen& pen) + The pen of the minor grid line has changed to \a pen. +*/ + +/*! \fn void QAbstractAxis::colorChanged(QColor color) Emitted if the \a color of the axis is changed. */ @@ -505,6 +533,19 @@ bool QAbstractAxis::isGridLineVisible() const return d_ptr->m_gridLineVisible; } +void QAbstractAxis::setMinorGridLineVisible(bool visible) +{ + if (d_ptr->m_minorGridLineVisible != visible) { + d_ptr->m_minorGridLineVisible = visible; + emit minorGridVisibleChanged(visible); + } +} + +bool QAbstractAxis::isMinorGridLineVisible() const +{ + return d_ptr->m_minorGridLineVisible; +} + /*! Sets \a pen used to draw grid line. */ @@ -527,6 +568,22 @@ QPen QAbstractAxis::gridLinePen() const return d_ptr->m_gridLinePen; } +void QAbstractAxis::setMinorGridLinePen(const QPen &pen) +{ + if (d_ptr->m_minorGridLinePen != pen) { + d_ptr->m_minorGridLinePen = pen; + emit minorGridLinePenChanged(pen); + } +} + +QPen QAbstractAxis::minorGridLinePen() const +{ + if (d_ptr->m_minorGridLinePen == QChartPrivate::defaultPen()) + return QPen(); + else + return d_ptr->m_minorGridLinePen; +} + void QAbstractAxis::setLabelsVisible(bool visible) { if (d_ptr->m_labelsVisible != visible) { @@ -873,6 +930,8 @@ QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) m_axisBrush(QChartPrivate::defaultBrush()), m_gridLineVisible(true), m_gridLinePen(QChartPrivate::defaultPen()), + m_minorGridLineVisible(true), + m_minorGridLinePen(QChartPrivate::defaultPen()), m_labelsVisible(true), m_labelsBrush(QChartPrivate::defaultBrush()), m_labelsFont(QChartPrivate::defaultFont()), @@ -918,6 +977,8 @@ void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) if (forced || QChartPrivate::defaultPen() == m_gridLinePen) q_ptr->setGridLinePen(theme->girdLinePen()); + if (forced || QChartPrivate::defaultPen() == m_minorGridLinePen) + q_ptr->setMinorGridLinePen(theme->minorGridLinePen()); if (forced || QChartPrivate::defaultBrush() == m_labelsBrush) q_ptr->setLabelsBrush(theme->labelBrush()); diff --git a/src/charts/axis/qabstractaxis.h b/src/charts/axis/qabstractaxis.h index 585a1c6..48a16a7 100644 --- a/src/charts/axis/qabstractaxis.h +++ b/src/charts/axis/qabstractaxis.h @@ -46,6 +46,8 @@ class QT_CHARTS_EXPORT QAbstractAxis : public QObject //grid Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) Q_PROPERTY(QPen gridLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged) + Q_PROPERTY(bool minorGridVisible READ isMinorGridLineVisible WRITE setMinorGridLineVisible NOTIFY minorGridVisibleChanged) + Q_PROPERTY(QPen minorGridLinePen READ minorGridLinePen WRITE setMinorGridLinePen NOTIFY minorGridLinePenChanged) //shades Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) @@ -103,6 +105,10 @@ public: void setGridLineVisible(bool visible = true); void setGridLinePen(const QPen &pen); QPen gridLinePen() const; + bool isMinorGridLineVisible() const; + void setMinorGridLineVisible(bool visible = true); + void setMinorGridLinePen(const QPen &pen); + QPen minorGridLinePen() const; //labels handling bool labelsVisible() const; @@ -160,6 +166,8 @@ Q_SIGNALS: void labelsAngleChanged(int angle); void gridLinePenChanged(const QPen &pen); void gridVisibleChanged(bool visible); + void minorGridVisibleChanged(bool visible); + void minorGridLinePenChanged(const QPen &pen); void colorChanged(QColor color); void labelsColorChanged(QColor color); void titleTextChanged(const QString &title); diff --git a/src/charts/axis/qabstractaxis_p.h b/src/charts/axis/qabstractaxis_p.h index 6b5f0c2..208b467 100644 --- a/src/charts/axis/qabstractaxis_p.h +++ b/src/charts/axis/qabstractaxis_p.h @@ -100,6 +100,8 @@ private: bool m_gridLineVisible; QPen m_gridLinePen; + bool m_minorGridLineVisible; + QPen m_minorGridLinePen; bool m_labelsVisible; QBrush m_labelsBrush; diff --git a/src/charts/axis/valueaxis/chartvalueaxisx.cpp b/src/charts/axis/valueaxis/chartvalueaxisx.cpp index 6492f91..f72b991 100644 --- a/src/charts/axis/valueaxis/chartvalueaxisx.cpp +++ b/src/charts/axis/valueaxis/chartvalueaxisx.cpp @@ -33,6 +33,8 @@ ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, QGraphicsItem *item ) m_axis(axis) { QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); + QObject::connect(m_axis, SIGNAL(minorTickCountChanged(int)), + this, SLOT(handleMinorTickCountChanged(int))); QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); } @@ -72,6 +74,14 @@ void ChartValueAxisX::handleTickCountChanged(int tick) if(presenter()) presenter()->layout()->invalidate(); } +void ChartValueAxisX::handleMinorTickCountChanged(int tick) +{ + Q_UNUSED(tick); + QGraphicsLayoutItem::updateGeometry(); + if (presenter()) + presenter()->layout()->invalidate(); +} + void ChartValueAxisX::handleLabelFormatChanged(const QString &format) { Q_UNUSED(format); diff --git a/src/charts/axis/valueaxis/chartvalueaxisx_p.h b/src/charts/axis/valueaxis/chartvalueaxisx_p.h index b220f90..e58fd8f 100644 --- a/src/charts/axis/valueaxis/chartvalueaxisx_p.h +++ b/src/charts/axis/valueaxis/chartvalueaxisx_p.h @@ -47,6 +47,7 @@ protected: void updateGeometry(); private Q_SLOTS: void handleTickCountChanged(int tick); + void handleMinorTickCountChanged(int tick); void handleLabelFormatChanged(const QString &format); private: diff --git a/src/charts/axis/valueaxis/chartvalueaxisy.cpp b/src/charts/axis/valueaxis/chartvalueaxisy.cpp index 85f6bd8..e143ea2 100644 --- a/src/charts/axis/valueaxis/chartvalueaxisy.cpp +++ b/src/charts/axis/valueaxis/chartvalueaxisy.cpp @@ -32,6 +32,8 @@ ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, QGraphicsItem *item) m_axis(axis) { QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); + QObject::connect(m_axis, SIGNAL(minorTickCountChanged(int)), + this, SLOT(handleMinorTickCountChanged(int))); QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); } @@ -73,6 +75,14 @@ void ChartValueAxisY::handleTickCountChanged(int tick) if (presenter()) presenter()->layout()->invalidate(); } +void ChartValueAxisY::handleMinorTickCountChanged(int tick) +{ + Q_UNUSED(tick); + QGraphicsLayoutItem::updateGeometry(); + if (presenter()) + presenter()->layout()->invalidate(); +} + void ChartValueAxisY::handleLabelFormatChanged(const QString &format) { Q_UNUSED(format); diff --git a/src/charts/axis/valueaxis/chartvalueaxisy_p.h b/src/charts/axis/valueaxis/chartvalueaxisy_p.h index 896d8e7..4c4faf1 100644 --- a/src/charts/axis/valueaxis/chartvalueaxisy_p.h +++ b/src/charts/axis/valueaxis/chartvalueaxisy_p.h @@ -47,6 +47,7 @@ protected: void updateGeometry(); private Q_SLOTS: void handleTickCountChanged(int tick); + void handleMinorTickCountChanged(int tick); void handleLabelFormatChanged(const QString &format); private: diff --git a/src/charts/axis/valueaxis/polarchartvalueaxisangular.cpp b/src/charts/axis/valueaxis/polarchartvalueaxisangular.cpp index 0c196b6..bcd7811 100644 --- a/src/charts/axis/valueaxis/polarchartvalueaxisangular.cpp +++ b/src/charts/axis/valueaxis/polarchartvalueaxisangular.cpp @@ -26,6 +26,8 @@ PolarChartValueAxisAngular::PolarChartValueAxisAngular(QValueAxis *axis, QGraphi : PolarChartAxisAngular(axis, item) { QObject::connect(axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); + QObject::connect(axis, SIGNAL(minorTickCountChanged(int)), + this, SLOT(handleMinorTickCountChanged(int))); QObject::connect(axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); } @@ -65,6 +67,14 @@ void PolarChartValueAxisAngular::handleTickCountChanged(int tick) presenter()->layout()->invalidate(); } +void PolarChartValueAxisAngular::handleMinorTickCountChanged(int tick) +{ + Q_UNUSED(tick); + QGraphicsLayoutItem::updateGeometry(); + if (presenter()) + presenter()->layout()->invalidate(); +} + void PolarChartValueAxisAngular::handleLabelFormatChanged(const QString &format) { Q_UNUSED(format); diff --git a/src/charts/axis/valueaxis/polarchartvalueaxisangular_p.h b/src/charts/axis/valueaxis/polarchartvalueaxisangular_p.h index 4dd178d..682ba46 100644 --- a/src/charts/axis/valueaxis/polarchartvalueaxisangular_p.h +++ b/src/charts/axis/valueaxis/polarchartvalueaxisangular_p.h @@ -29,6 +29,7 @@ #define POLARCHARTVALUEAXISANGULAR_P_H #include +#include QT_CHARTS_BEGIN_NAMESPACE @@ -46,6 +47,7 @@ public: private Q_SLOTS: void handleTickCountChanged(int tick); + void handleMinorTickCountChanged(int tick); void handleLabelFormatChanged(const QString &format); }; diff --git a/src/charts/axis/valueaxis/polarchartvalueaxisradial.cpp b/src/charts/axis/valueaxis/polarchartvalueaxisradial.cpp index dffa88e..c447e38 100644 --- a/src/charts/axis/valueaxis/polarchartvalueaxisradial.cpp +++ b/src/charts/axis/valueaxis/polarchartvalueaxisradial.cpp @@ -26,6 +26,8 @@ PolarChartValueAxisRadial::PolarChartValueAxisRadial(QValueAxis *axis, QGraphics : PolarChartAxisRadial(axis, item) { QObject::connect(axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); + QObject::connect(axis, SIGNAL(minorTickCountChanged(int)), + this, SLOT(handleMinorTickCountChanged(int))); QObject::connect(axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); } @@ -64,6 +66,14 @@ void PolarChartValueAxisRadial::handleTickCountChanged(int tick) presenter()->layout()->invalidate(); } +void PolarChartValueAxisRadial::handleMinorTickCountChanged(int tick) +{ + Q_UNUSED(tick); + QGraphicsLayoutItem::updateGeometry(); + if (presenter()) + presenter()->layout()->invalidate(); +} + void PolarChartValueAxisRadial::handleLabelFormatChanged(const QString &format) { Q_UNUSED(format); diff --git a/src/charts/axis/valueaxis/polarchartvalueaxisradial_p.h b/src/charts/axis/valueaxis/polarchartvalueaxisradial_p.h index 4e3f110..38b748c 100644 --- a/src/charts/axis/valueaxis/polarchartvalueaxisradial_p.h +++ b/src/charts/axis/valueaxis/polarchartvalueaxisradial_p.h @@ -46,6 +46,7 @@ public: private Q_SLOTS: void handleTickCountChanged(int tick); + void handleMinorTickCountChanged(int tick); void handleLabelFormatChanged(const QString &format); }; diff --git a/src/charts/axis/valueaxis/qvalueaxis.cpp b/src/charts/axis/valueaxis/qvalueaxis.cpp index 8e9223c..c17440e 100644 --- a/src/charts/axis/valueaxis/qvalueaxis.cpp +++ b/src/charts/axis/valueaxis/qvalueaxis.cpp @@ -99,13 +99,24 @@ QT_CHARTS_BEGIN_NAMESPACE /*! \property QValueAxis::tickCount - Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. - The default value is 5, and it can not be below 2. + Defines the number of ticks on the axis. This indicates how many grid lines are drawn on the + chart. The default value is 5, and it can not be below 2. */ /*! - \qmlproperty real ValueAxis::tickCount - Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. - The default value is 5, and it can not be below 2. + \qmlproperty int ValueAxis::tickCount + Defines the number of ticks on the axis. This indicates how many grid lines are drawn on the + chart. The default value is 5, and it can not be below 2. +*/ + +/*! + \property QValueAxis::minorTickCount + Defines the number of minor ticks on the axis. This indicates how many grid lines are drawn + between major ticks on the chart. Labels are not drawn for minor ticks. The default value is 0. +*/ +/*! + \qmlproperty int ValueAxis::minorTickCount + Defines the number of minor ticks on the axis. This indicates how many grid lines are drawn + between major ticks on the chart. Labels are not drawn for minor ticks. The default value is 0. */ /*! @@ -157,6 +168,15 @@ QT_CHARTS_BEGIN_NAMESPACE */ /*! + \fn void QValueAxis::minorTickCountChanged(int minorTickCount) + Axis emits signal when \a minorTickCount of axis has changed. +*/ +/*! + \qmlsignal ValueAxis::minorTickCountChanged(int minorTickCount) + Axis emits signal when \a minorTickCount of axis has changed. +*/ + +/*! \fn void QValueAxis::rangeChanged(qreal min, qreal max) Axis emits signal when \a min or \a max of axis has changed. */ @@ -247,6 +267,21 @@ int QValueAxis::tickCount() const return d->m_tickCount; } +void QValueAxis::setMinorTickCount(int count) +{ + Q_D(QValueAxis); + if (d->m_minorTickCount != count && count >= 0) { + d->m_minorTickCount = count; + emit minorTickCountChanged(count); + } +} + +int QValueAxis::minorTickCount() const +{ + Q_D(const QValueAxis); + return d->m_minorTickCount; +} + void QValueAxis::setLabelFormat(const QString &format) { Q_D(QValueAxis); @@ -295,6 +330,7 @@ QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) m_min(0), m_max(0), m_tickCount(5), + m_minorTickCount(0), m_format(QString::null), m_applying(false) { diff --git a/src/charts/axis/valueaxis/qvalueaxis.h b/src/charts/axis/valueaxis/qvalueaxis.h index cc4248a..3846785 100644 --- a/src/charts/axis/valueaxis/qvalueaxis.h +++ b/src/charts/axis/valueaxis/qvalueaxis.h @@ -32,6 +32,7 @@ class QT_CHARTS_EXPORT QValueAxis : public QAbstractAxis Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged) + Q_PROPERTY(int minorTickCount READ minorTickCount WRITE setMinorTickCount NOTIFY minorTickCountChanged) public: explicit QValueAxis(QObject *parent = 0); @@ -53,6 +54,8 @@ public: //ticks handling void setTickCount(int count); int tickCount() const; + void setMinorTickCount(int count); + int minorTickCount() const; void setLabelFormat(const QString &format); QString labelFormat() const; @@ -65,6 +68,7 @@ Q_SIGNALS: void maxChanged(qreal max); void rangeChanged(qreal min, qreal max); void tickCountChanged(int tickCount); + void minorTickCountChanged(int tickCount); void labelFormatChanged(const QString &format); private: diff --git a/src/charts/axis/valueaxis/qvalueaxis_p.h b/src/charts/axis/valueaxis/qvalueaxis_p.h index 2dc1c62..acf745f 100644 --- a/src/charts/axis/valueaxis/qvalueaxis_p.h +++ b/src/charts/axis/valueaxis/qvalueaxis_p.h @@ -57,6 +57,7 @@ private: qreal m_min; qreal m_max; int m_tickCount; + int m_minorTickCount; QString m_format; bool m_applying; Q_DECLARE_PUBLIC(QValueAxis) diff --git a/src/charts/axis/verticalaxis.cpp b/src/charts/axis/verticalaxis.cpp index f42b8e0..dfa1a3b 100644 --- a/src/charts/axis/verticalaxis.cpp +++ b/src/charts/axis/verticalaxis.cpp @@ -96,6 +96,8 @@ void VerticalAxis::updateGeometry() QList lines = gridItems(); QList shades = shadeItems(); + QList minorLines = minorGridItems(); + QList minorArrows = minorArrowItems(); for (int i = 0; i < layout.size(); ++i) { //items @@ -296,6 +298,54 @@ void VerticalAxis::updateGeometry() tickItem->setVisible(true); } + // add minor ticks + QValueAxis *valueAxis = qobject_cast(axis()); + if ((i + 1) != layout.size() && valueAxis) { + int minorTickCount = valueAxis->minorTickCount(); + if (minorTickCount != 0) { + qreal minorTickDistance = (layout[i] - layout[i + 1]) / qreal(minorTickCount + 1); + for (int j = 0; j < minorTickCount; j++) { + QGraphicsLineItem *minorGridItem = + static_cast(minorLines.at(i * minorTickCount + j)); + QGraphicsLineItem *minorArrowItem = + static_cast(minorArrows.at(i * minorTickCount + j)); + if (i == 0) { + minorGridItem->setLine(gridRect.left(), + gridRect.bottom() - minorTickDistance * qreal(j + 1), + gridRect.right(), + gridRect.bottom() - minorTickDistance * qreal(j + 1)); + } else { + minorGridItem->setLine(gridRect.left(), + gridItem->line().p1().y() + - minorTickDistance * qreal(j + 1), + gridRect.right(), + gridItem->line().p1().y() + - minorTickDistance * qreal(j + 1)); + } + if (axis()->alignment() == Qt::AlignLeft) { + minorArrowItem->setLine(gridRect.left() - labelPadding() / 2, + minorGridItem->line().p1().y(), + gridRect.left(), + minorGridItem->line().p1().y()); + } else if (axis()->alignment() == Qt::AlignRight){ + minorArrowItem->setLine(gridRect.right(), + minorGridItem->line().p1().y(), + gridRect.right() + labelPadding() / 2, + minorGridItem->line().p1().y()); + } + + // check if the minor grid line and the axis tick should be shown + qreal minorYPos = minorGridItem->line().p1().y(); + if (minorYPos < gridRect.top() || minorYPos > gridRect.bottom()) { + minorGridItem->setVisible(false); + minorArrowItem->setVisible(false); + } else { + minorGridItem->setVisible(true); + minorArrowItem->setVisible(true); + } + } + } + } } //begin/end grid line in case labels between if (intervalAxis()) { diff --git a/src/charts/themes/charttheme_p.h b/src/charts/themes/charttheme_p.h index a0fdc18..143e135 100644 --- a/src/charts/themes/charttheme_p.h +++ b/src/charts/themes/charttheme_p.h @@ -66,6 +66,7 @@ public: BackgroundShadesMode backgroundShades() const { return m_backgroundShades; } bool isBackgroundDropShadowEnabled() const { return m_backgroundDropShadowEnabled; } QPen girdLinePen() const { return m_gridLinePen; } + QPen minorGridLinePen() const { return m_minorGridLinePen; } protected: QChart::ChartTheme m_id; @@ -83,6 +84,7 @@ protected: BackgroundShadesMode m_backgroundShades; bool m_backgroundDropShadowEnabled; QPen m_gridLinePen; + QPen m_minorGridLinePen; }; diff --git a/src/charts/themes/chartthemebluecerulean_p.h b/src/charts/themes/chartthemebluecerulean_p.h index 0f8db28..3b1c37d 100644 --- a/src/charts/themes/chartthemebluecerulean_p.h +++ b/src/charts/themes/chartthemebluecerulean_p.h @@ -57,6 +57,9 @@ public: m_axisLinePen.setWidth(2); m_gridLinePen = QPen(QRgb(0x84a2b0)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0x84a2b0)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; m_outlinePen = QPen(QRgb(0xebebeb)); m_outlinePen.setWidthF(2.0); diff --git a/src/charts/themes/chartthemeblueicy_p.h b/src/charts/themes/chartthemeblueicy_p.h index 25ba6fe..469d6bc 100644 --- a/src/charts/themes/chartthemeblueicy_p.h +++ b/src/charts/themes/chartthemeblueicy_p.h @@ -59,6 +59,9 @@ public: m_axisLinePen.setWidth(2); m_gridLinePen = QPen(QRgb(0xe2e2e2)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0xe2e2e2)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; m_outlinePen = QPen(QRgb(0x474747)); m_outlinePen.setWidthF(2.0); diff --git a/src/charts/themes/chartthemebluencs_p.h b/src/charts/themes/chartthemebluencs_p.h index 4cdc897..40e04b3 100644 --- a/src/charts/themes/chartthemebluencs_p.h +++ b/src/charts/themes/chartthemebluencs_p.h @@ -58,6 +58,9 @@ public: m_axisLinePen.setWidth(2); m_gridLinePen = QPen(QRgb(0xe2e2e2)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0xe2e2e2)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; m_outlinePen = QPen(QRgb(0x474747)); m_outlinePen.setWidthF(2.0); diff --git a/src/charts/themes/chartthemebrownsand_p.h b/src/charts/themes/chartthemebrownsand_p.h index 38c4e42..cfdfb69 100644 --- a/src/charts/themes/chartthemebrownsand_p.h +++ b/src/charts/themes/chartthemebrownsand_p.h @@ -58,6 +58,9 @@ public: m_axisLinePen.setWidth(2); m_gridLinePen = QPen(QRgb(0xd4cec3)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0xd4cec3)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; m_outlinePen = QPen(QRgb(0x222222)); m_outlinePen.setWidthF(2.0); diff --git a/src/charts/themes/chartthemedark_p.h b/src/charts/themes/chartthemedark_p.h index c069403..2779dff 100644 --- a/src/charts/themes/chartthemedark_p.h +++ b/src/charts/themes/chartthemedark_p.h @@ -58,6 +58,9 @@ public: m_axisLinePen.setWidth(2); m_gridLinePen = QPen(QRgb(0x86878c)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0x86878c)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; m_outlinePen = QPen(QRgb(0xd6d6d6)); m_outlinePen.setWidthF(2.0); diff --git a/src/charts/themes/chartthemehighcontrast_p.h b/src/charts/themes/chartthemehighcontrast_p.h index 785cf07..9af53fc 100644 --- a/src/charts/themes/chartthemehighcontrast_p.h +++ b/src/charts/themes/chartthemehighcontrast_p.h @@ -59,6 +59,9 @@ public: m_axisLinePen.setWidth(2); m_gridLinePen = QPen(QRgb(0x8c8c8c)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0x8c8c8c)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShadesBrush = QBrush(QRgb(0xffeecd)); m_backgroundShades = BackgroundShadesHorizontal; m_outlinePen = QPen(QColor(Qt::black)); diff --git a/src/charts/themes/chartthemelight_p.h b/src/charts/themes/chartthemelight_p.h index b2bbe27..135f6ed 100644 --- a/src/charts/themes/chartthemelight_p.h +++ b/src/charts/themes/chartthemelight_p.h @@ -60,6 +60,9 @@ public: m_labelBrush = QBrush(QRgb(0x404044)); m_gridLinePen = QPen(QRgb(0xe2e2e2)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0xe2e2e2)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; m_outlinePen = QPen(0x4d4d4d); m_outlinePen.setWidthF(2.0); diff --git a/src/charts/themes/chartthemeqt_p.h b/src/charts/themes/chartthemeqt_p.h index 9fe1f09..a9e98c4 100644 --- a/src/charts/themes/chartthemeqt_p.h +++ b/src/charts/themes/chartthemeqt_p.h @@ -61,6 +61,9 @@ public: m_axisLinePen.setWidth(1); m_gridLinePen = QPen(QRgb(0xd7d6d5)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0xd7d6d5)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; m_outlinePen = QPen(QRgb(0x35322f)); m_outlinePen.setWidthF(2.0); diff --git a/src/charts/themes/chartthemesystem_p.h b/src/charts/themes/chartthemesystem_p.h index 00ace09..4b7fb5f 100644 --- a/src/charts/themes/chartthemesystem_p.h +++ b/src/charts/themes/chartthemesystem_p.h @@ -96,6 +96,9 @@ public: m_labelBrush = QBrush(QRgb(0x404044)); m_gridLinePen = QPen(QRgb(0xe2e2e2)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0xe2e2e2)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; #elif defined(Q_OS_LINUX) @@ -119,6 +122,9 @@ public: m_labelBrush = QBrush(QRgb(0x404044)); m_gridLinePen = QPen(QRgb(0xe2e2e2)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QBrush(QRgb(0x404044)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; #elif defined(Q_OS_MAC) @@ -142,6 +148,9 @@ public: m_labelBrush = QBrush(QRgb(0x404044)); m_gridLinePen = QPen(QRgb(0xe2e2e2)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0xe2e2e2)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; #else @@ -165,6 +174,9 @@ public: m_labelBrush = QBrush(QRgb(0x404044)); m_gridLinePen = QPen(QRgb(0xe2e2e2)); m_gridLinePen.setWidth(1); + m_minorGridLinePen = QPen(QRgb(0xe2e2e2)); + m_minorGridLinePen.setWidth(1); + m_minorGridLinePen.setStyle(Qt::DashLine); m_backgroundShades = BackgroundShadesNone; #endif } diff --git a/tests/auto/qabstractaxis/tst_qabstractaxis.cpp b/tests/auto/qabstractaxis/tst_qabstractaxis.cpp index 254b806..ad240e1 100644 --- a/tests/auto/qabstractaxis/tst_qabstractaxis.cpp +++ b/tests/auto/qabstractaxis/tst_qabstractaxis.cpp @@ -58,6 +58,8 @@ void tst_QAbstractAxis::qabstractaxis() QCOMPARE(m_axis->labelsFont(), QFont()); QCOMPARE(m_axis->labelsVisible(), true); QCOMPARE(m_axis->orientation(), Qt::Orientation(0)); + QCOMPARE(m_axis->minorGridLinePen(), QPen()); + QCOMPARE(m_axis->isMinorGridLineVisible(), true); m_axis->setLineVisible(false); m_axis->setLinePen(QPen()); m_axis->setLinePenColor(QColor()); @@ -77,6 +79,8 @@ void tst_QAbstractAxis::qabstractaxis() m_axis->setShadesPen(QPen()); m_axis->setShadesVisible(false); m_axis->setVisible(false); + m_axis->setMinorGridLinePen(QPen()); + m_axis->setMinorGridLineVisible(false); //TODO QCOMPARE(m_axis->shadesBrush(), QBrush()); QCOMPARE(m_axis->shadesPen(), QPen()); QCOMPARE(m_axis->shadesVisible(), false); @@ -106,6 +110,7 @@ void tst_QAbstractAxis::axisPen() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->setLinePen(axisPen); QCOMPARE(m_axis->linePen(), axisPen); @@ -119,6 +124,7 @@ void tst_QAbstractAxis::axisPen() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); m_chart->setAxisX(m_axis, m_series); m_view->show(); @@ -179,6 +185,52 @@ void tst_QAbstractAxis::gridLinePen() //TODO QCOMPARE(m_axis->gridLinePen(), gridLinePen); } +void tst_QAbstractAxis::minorGridLinePen_data() +{ + + QTest::addColumn("minorGridLinePen"); + QTest::newRow("null") << QPen(); + QTest::newRow("blue") << QPen(Qt::blue); + QTest::newRow("black") << QPen(Qt::black); + QTest::newRow("red") << QPen(Qt::red); + +} + +void tst_QAbstractAxis::minorGridLinePen() +{ + QFETCH(QPen, minorGridLinePen); + + QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); + QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); + QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); + QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); + QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); + QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); + QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); + QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); + QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); + + m_axis->setMinorGridLinePen(minorGridLinePen); + QCOMPARE(m_axis->minorGridLinePen(), minorGridLinePen); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); + QCOMPARE(spy4.count(), 0); + QCOMPARE(spy5.count(), 0); + QCOMPARE(spy6.count(), 0); + QCOMPARE(spy7.count(), 0); + QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); + + m_chart->setAxisX(m_axis, m_series); + m_view->show(); + QTest::qWaitForWindowShown(m_view); + +} + void tst_QAbstractAxis::lineVisible_data() { QTest::addColumn("lineVisible"); @@ -201,6 +253,7 @@ void tst_QAbstractAxis::lineVisible() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->setLineVisible(lineVisible); QCOMPARE(m_axis->isLineVisible(), lineVisible); @@ -214,6 +267,7 @@ void tst_QAbstractAxis::lineVisible() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); m_chart->setAxisX(m_axis, m_series); m_view->show(); @@ -264,6 +318,51 @@ void tst_QAbstractAxis::gridLineVisible() } +void tst_QAbstractAxis::minorGridLineVisible_data() +{ + QTest::addColumn("minorGridLineVisible"); + QTest::newRow("true") << true; + QTest::newRow("false") << false; +} + +void tst_QAbstractAxis::minorGridLineVisible() +{ + QFETCH(bool, minorGridLineVisible); + + m_axis->setMinorGridLineVisible(!minorGridLineVisible); + + QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool))); + QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor))); + QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool))); + QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor))); + QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool))); + QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor))); + QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); + QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); + QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); + + m_axis->setMinorGridLineVisible(minorGridLineVisible); + QCOMPARE(m_axis->isMinorGridLineVisible(), minorGridLineVisible); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); + QCOMPARE(spy4.count(), 0); + QCOMPARE(spy5.count(), 0); + QCOMPARE(spy6.count(), 0); + QCOMPARE(spy7.count(), 0); + QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 1); + + m_chart->setAxisX(m_axis, m_series); + m_view->show(); + QTest::qWaitForWindowShown(m_view); + QCOMPARE(m_axis->isMinorGridLineVisible(), minorGridLineVisible); + +} + void tst_QAbstractAxis::visible_data() { QTest::addColumn("visible"); @@ -286,6 +385,7 @@ void tst_QAbstractAxis::visible() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->setVisible(visible); QCOMPARE(m_axis->isVisible(), visible); @@ -299,6 +399,7 @@ void tst_QAbstractAxis::visible() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 1); + QCOMPARE(spy9.count(), 0); m_chart->setAxisX(m_axis, m_series); m_view->show(); @@ -327,6 +428,7 @@ void tst_QAbstractAxis::labelsAngle() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->setLabelsAngle(labelsAngle); QCOMPARE(m_axis->labelsAngle(), labelsAngle); @@ -340,6 +442,7 @@ void tst_QAbstractAxis::labelsAngle() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); m_chart->setAxisX(m_axis, m_series); m_view->show(); @@ -370,6 +473,7 @@ void tst_QAbstractAxis::labelsBrush() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->setLabelsBrush(labelsBrush); QCOMPARE(m_axis->labelsBrush(), labelsBrush); @@ -383,6 +487,7 @@ void tst_QAbstractAxis::labelsBrush() //TODO QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); m_view->show(); QTest::qWaitForWindowShown(m_view); @@ -421,6 +526,7 @@ void tst_QAbstractAxis::labelsFont() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->setLabelsFont(labelsFont); QCOMPARE(m_axis->labelsFont(), labelsFont); @@ -434,6 +540,7 @@ void tst_QAbstractAxis::labelsFont() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); m_view->show(); QTest::qWaitForWindowShown(m_view); @@ -463,6 +570,7 @@ void tst_QAbstractAxis::labelsVisible() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->setLabelsVisible(labelsVisible); QCOMPARE(m_axis->labelsVisible(), labelsVisible); @@ -476,6 +584,7 @@ void tst_QAbstractAxis::labelsVisible() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); m_chart->setAxisX(m_axis, m_series); m_view->show(); @@ -503,6 +612,7 @@ void tst_QAbstractAxis::orientation() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); if(orientation==Qt::Vertical){ m_chart->setAxisY(m_axis,m_series); @@ -520,6 +630,7 @@ void tst_QAbstractAxis::orientation() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); m_view->show(); QTest::qWaitForWindowShown(m_view); @@ -604,6 +715,7 @@ void tst_QAbstractAxis::shadesBrush() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->setShadesBrush(shadesBrush); QCOMPARE(m_axis->shadesBrush(), shadesBrush); @@ -617,6 +729,7 @@ void tst_QAbstractAxis::shadesBrush() //TODO QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); m_view->show(); QTest::qWaitForWindowShown(m_view); @@ -655,6 +768,7 @@ void tst_QAbstractAxis::shadesPen() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->setShadesPen(shadesPen); QCOMPARE(m_axis->shadesPen(), shadesPen); @@ -668,6 +782,7 @@ void tst_QAbstractAxis::shadesPen() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); m_chart->setAxisX(m_axis, m_series); m_view->show(); @@ -697,6 +812,7 @@ void tst_QAbstractAxis::shadesVisible() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->setShadesVisible(shadesVisible); QCOMPARE(m_axis->shadesVisible(), shadesVisible); @@ -710,6 +826,7 @@ void tst_QAbstractAxis::shadesVisible() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 1); QCOMPARE(spy8.count(), 0); + QCOMPARE(spy9.count(), 0); m_chart->setAxisX(m_axis, m_series); m_view->show(); @@ -736,6 +853,7 @@ void tst_QAbstractAxis::show() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->show(); @@ -748,6 +866,7 @@ void tst_QAbstractAxis::show() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 1); + QCOMPARE(spy9.count(), 0); QCOMPARE(m_axis->isVisible(), true); } @@ -770,6 +889,7 @@ void tst_QAbstractAxis::hide() QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor))); QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool))); QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool))); + QSignalSpy spy9(m_axis, SIGNAL(minorGridVisibleChanged(bool))); m_axis->hide(); @@ -782,6 +902,7 @@ void tst_QAbstractAxis::hide() QCOMPARE(spy6.count(), 0); QCOMPARE(spy7.count(), 0); QCOMPARE(spy8.count(), 1); + QCOMPARE(spy9.count(), 0); QCOMPARE(m_axis->isVisible(),false); } diff --git a/tests/auto/qabstractaxis/tst_qabstractaxis.h b/tests/auto/qabstractaxis/tst_qabstractaxis.h index b1572c1..6be7a23 100644 --- a/tests/auto/qabstractaxis/tst_qabstractaxis.h +++ b/tests/auto/qabstractaxis/tst_qabstractaxis.h @@ -43,10 +43,14 @@ private slots: void axisPenColor(); void gridLinePen_data(); void gridLinePen(); + void minorGridLinePen_data(); + void minorGridLinePen(); void lineVisible_data(); void lineVisible(); void gridLineVisible_data(); void gridLineVisible(); + void minorGridLineVisible_data(); + void minorGridLineVisible(); void visible_data(); void visible(); void labelsAngle_data(); diff --git a/tests/manual/chartviewer/window.cpp b/tests/manual/chartviewer/window.cpp index ee0c249..73600d9 100644 --- a/tests/manual/chartviewer/window.cpp +++ b/tests/manual/chartviewer/window.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,10 @@ Window::Window(const QVariantHash ¶meters, QWidget *parent) m_legendComboBox(0), m_templateComboBox(0), m_viewComboBox(0), + m_xTickSpinBox(0), + m_yTickSpinBox(0), + m_minorXTickSpinBox(0), + m_minorYTickSpinBox(0), m_openGLCheckBox(0), m_zoomCheckBox(0), m_scrollCheckBox(0), @@ -78,6 +83,14 @@ Window::Window(const QVariantHash ¶meters, QWidget *parent) settingsLayout->addItem(m_widgetHash["templateComboBox"]); settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); + settingsLayout->addItem(m_widgetHash["xTickLabel"]); + settingsLayout->addItem(m_widgetHash["xTickSpinBox"]); + settingsLayout->addItem(m_widgetHash["yTickLabel"]); + settingsLayout->addItem(m_widgetHash["yTickSpinBox"]); + settingsLayout->addItem(m_widgetHash["minorXTickLabel"]); + settingsLayout->addItem(m_widgetHash["minorXTickSpinBox"]); + settingsLayout->addItem(m_widgetHash["minorYTickLabel"]); + settingsLayout->addItem(m_widgetHash["minorYTickSpinBox"]); settingsLayout->addStretch(); m_baseLayout->setOrientation(Qt::Horizontal); @@ -114,6 +127,10 @@ void Window::connectSignals() QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); + QObject::connect(m_xTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); + QObject::connect(m_yTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); + QObject::connect(m_minorXTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); + QObject::connect(m_minorYTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); @@ -128,6 +145,14 @@ void Window::createProxyWidgets() { m_themeComboBox = createThemeBox(); m_viewComboBox = createViewBox(); + m_xTickSpinBox = new QSpinBox(); + m_xTickSpinBox->setMinimum(2); + m_xTickSpinBox->setValue(5); + m_yTickSpinBox = new QSpinBox(); + m_yTickSpinBox->setMinimum(2); + m_yTickSpinBox->setValue(5); + m_minorXTickSpinBox = new QSpinBox(); + m_minorYTickSpinBox = new QSpinBox(); m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); m_animatedComboBox = createAnimationBox(); m_legendComboBox = createLegendBox(); @@ -141,6 +166,14 @@ void Window::createProxyWidgets() m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); + m_widgetHash["xTickLabel"] = m_scene->addWidget(new QLabel("X Tick")); + m_widgetHash["xTickSpinBox"] = m_scene->addWidget(m_xTickSpinBox); + m_widgetHash["yTickLabel"] = m_scene->addWidget(new QLabel("Y Tick")); + m_widgetHash["yTickSpinBox"] = m_scene->addWidget(m_yTickSpinBox); + m_widgetHash["minorXTickLabel"] = m_scene->addWidget(new QLabel("Minor X Tick")); + m_widgetHash["minorXTickSpinBox"] = m_scene->addWidget(m_minorXTickSpinBox); + m_widgetHash["minorYTickLabel"] = m_scene->addWidget(new QLabel("Minor Y Tick")); + m_widgetHash["minorYTickSpinBox"] = m_scene->addWidget(m_minorYTickSpinBox); m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); @@ -288,6 +321,10 @@ void Window::updateUI() checkAnimationOptions(); checkLegend(); checkState(); + checkXTick(); + checkYTick(); + checkMinorXTick(); + checkMinorYTick(); } void Window::checkView() @@ -299,6 +336,50 @@ void Window::checkView() } } +void Window::checkXTick() +{ + foreach (QChart *chart, m_grid->charts()) { + if (qobject_cast(chart->axisX())) { + QValueAxis *valueAxis = qobject_cast(chart->axisX()); + valueAxis->setGridLineVisible(); + valueAxis->setTickCount(m_xTickSpinBox->value()); + } + } +} + +void Window::checkYTick() +{ + foreach (QChart *chart, m_grid->charts()) { + if (qobject_cast(chart->axisY())) { + QValueAxis *valueAxis = qobject_cast(chart->axisY()); + valueAxis->setGridLineVisible(); + valueAxis->setTickCount(m_yTickSpinBox->value()); + } + } +} + +void Window::checkMinorXTick() +{ + foreach (QChart *chart, m_grid->charts()) { + if (qobject_cast(chart->axisX())) { + QValueAxis *valueAxis = qobject_cast(chart->axisX()); + valueAxis->setMinorGridLineVisible(); + valueAxis->setMinorTickCount(m_minorXTickSpinBox->value()); + } + } +} + +void Window::checkMinorYTick() +{ + foreach (QChart *chart, m_grid->charts()) { + if (qobject_cast(chart->axisY())) { + QValueAxis *valueAxis = qobject_cast(chart->axisY()); + valueAxis->setMinorGridLineVisible(); + valueAxis->setMinorTickCount(m_minorYTickSpinBox->value()); + } + } +} + void Window::checkLegend() { Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); diff --git a/tests/manual/chartviewer/window.h b/tests/manual/chartviewer/window.h index 26e13f9..c3762c6 100644 --- a/tests/manual/chartviewer/window.h +++ b/tests/manual/chartviewer/window.h @@ -22,6 +22,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE class QCheckBox; @@ -69,6 +70,10 @@ private: inline void checkTheme(); inline void checkState(); inline void checkTemplate(); + inline void checkXTick(); + inline void checkYTick(); + inline void checkMinorXTick(); + inline void checkMinorYTick(); QMenu *createMenu(); QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); void initializeFromParamaters(const QVariantHash ¶meters); @@ -80,6 +85,10 @@ private: QGraphicsWidget *m_form; QComboBox *m_themeComboBox; + QSpinBox *m_xTickSpinBox; + QSpinBox *m_yTickSpinBox; + QSpinBox *m_minorXTickSpinBox; + QSpinBox *m_minorYTickSpinBox; QCheckBox *m_antialiasCheckBox; QComboBox *m_animatedComboBox; QComboBox *m_legendComboBox; diff --git a/tests/manual/polarcharttest/mainwindow.cpp b/tests/manual/polarcharttest/mainwindow.cpp index cf82550..c8ae0ea 100644 --- a/tests/manual/polarcharttest/mainwindow.cpp +++ b/tests/manual/polarcharttest/mainwindow.cpp @@ -52,6 +52,8 @@ MainWindow::MainWindow(QWidget *parent) : m_titleVisible(true), m_gridVisible(true), m_arrowVisible(true), + m_minorGridVisible(true), + m_minorArrowVisible(true), m_angularShadesBrush(new QBrush(Qt::NoBrush)), m_radialShadesBrush(new QBrush(Qt::NoBrush)), m_labelBrush(new QBrush(Qt::black)), @@ -62,6 +64,7 @@ MainWindow::MainWindow(QWidget *parent) : m_radialShadesPen(new QPen(Qt::NoPen)), m_gridPen(new QPen(QRgb(0x010101))), // Note: Pure black is default color, so it gets overridden by m_arrowPen(new QPen(QRgb(0x010101))), // default theme if set to that initially. This is an example of workaround. + m_minorGridPen(new QPen(QBrush(QRgb(0x010101)), 1, Qt::DashLine)), m_backgroundPen(new QPen(Qt::NoPen)), m_plotAreaBackgroundPen(new QPen(Qt::NoPen)), m_labelFormat(QString("%.2f")), @@ -126,6 +129,8 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->angularTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(angularTicksChanged(int))); connect(ui->radialTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(radialTicksChanged(int))); + connect(ui->angularMinorTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(angularMinorTicksChanged(int))); + connect(ui->radialMinorTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(radialMinorTicksChanged(int))); connect(ui->anglesSpin, SIGNAL(valueChanged(int)), this, SLOT(anglesChanged(int))); connect(ui->radialMinSpin, SIGNAL(valueChanged(double)), this, SLOT(radialMinChanged(double))); connect(ui->radialMaxSpin, SIGNAL(valueChanged(double)), this, SLOT(radialMaxChanged(double))); @@ -142,6 +147,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->titleFontSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(titleFontSizeChanged(int))); connect(ui->titleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(titleIndexChanged(int))); connect(ui->gridComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(gridIndexChanged(int))); + connect(ui->minorGridComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(minorGridIndexChanged(int))); connect(ui->arrowComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(arrowIndexChanged(int))); connect(ui->logBaseSpin, SIGNAL(valueChanged(double)), this, SLOT(logBaseChanged(double))); connect(ui->angularAxisComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(angularAxisIndexChanged(int))); @@ -439,6 +445,8 @@ void MainWindow::setAngularAxis(MainWindow::AxisMode mode) m_angularAxis->setGridLineVisible(m_gridVisible); m_angularAxis->setLinePen(*m_arrowPen); m_angularAxis->setLineVisible(m_arrowVisible); + m_angularAxis->setMinorGridLinePen(*m_minorGridPen); + m_angularAxis->setMinorGridLineVisible(m_minorGridVisible); m_chart->addAxis(m_angularAxis, QPolarChart::PolarOrientationAngular); @@ -507,6 +515,8 @@ void MainWindow::setRadialAxis(MainWindow::AxisMode mode) m_radialAxis->setGridLineVisible(m_gridVisible); m_radialAxis->setLinePen(*m_arrowPen); m_radialAxis->setLineVisible(m_arrowVisible); + m_radialAxis->setMinorGridLinePen(*m_minorGridPen); + m_radialAxis->setMinorGridLineVisible(m_minorGridVisible); m_chart->addAxis(m_radialAxis, QPolarChart::PolarOrientationRadial); @@ -572,6 +582,22 @@ void MainWindow::radialTicksChanged(int value) static_cast(m_radialAxis)->setTickCount(m_radialTickCount); } +void MainWindow::angularMinorTicksChanged(int value) +{ + // Minor tick valid only for QValueAxis + m_angularMinorTickCount = value; + if (m_angularAxisMode == AxisModeValue) + static_cast(m_angularAxis)->setMinorTickCount(m_angularMinorTickCount); +} + +void MainWindow::radialMinorTicksChanged(int value) +{ + // Minor tick valid only for QValueAxis + m_radialMinorTickCount = value; + if (m_radialAxisMode == AxisModeValue) + static_cast(m_radialAxis)->setMinorTickCount(m_radialMinorTickCount); +} + void MainWindow::anglesChanged(int value) { m_labelsAngle = value; @@ -860,6 +886,36 @@ void MainWindow::gridIndexChanged(int index) m_radialAxis->setGridLineVisible(m_gridVisible); } +void MainWindow::minorGridIndexChanged(int index) +{ + delete m_minorGridPen; + + switch (index) { + case 0: + m_minorGridPen = new QPen(Qt::NoPen); + m_minorGridVisible = false; + break; + case 1: + m_minorGridPen = new QPen(Qt::black); + m_minorGridPen->setStyle(Qt::DashLine); + m_minorGridVisible = true; + break; + case 2: + m_minorGridPen = new QPen(Qt::green); + m_minorGridPen->setStyle(Qt::DotLine); + m_minorGridPen->setWidth(1); + m_minorGridVisible = true; + break; + default: + break; + } + + m_angularAxis->setMinorGridLinePen(*m_minorGridPen); + m_angularAxis->setMinorGridLineVisible(m_minorGridVisible); + m_radialAxis->setMinorGridLinePen(*m_minorGridPen); + m_radialAxis->setMinorGridLineVisible(m_minorGridVisible); +} + void MainWindow::arrowIndexChanged(int index) { delete m_arrowPen; @@ -913,6 +969,7 @@ void MainWindow::angularAxisIndexChanged(int index) break; case 1: setAngularAxis(AxisModeValue); + angularMinorTicksChanged(ui->angularMinorTicksSpin->value()); break; case 2: setAngularAxis(AxisModeLogValue); @@ -936,6 +993,7 @@ void MainWindow::radialAxisIndexChanged(int index) break; case 1: setRadialAxis(AxisModeValue); + radialMinorTicksChanged(ui->radialMinorTicksSpin->value()); break; case 2: setRadialAxis(AxisModeLogValue); diff --git a/tests/manual/polarcharttest/mainwindow.h b/tests/manual/polarcharttest/mainwindow.h index 0f813fe..d267481 100644 --- a/tests/manual/polarcharttest/mainwindow.h +++ b/tests/manual/polarcharttest/mainwindow.h @@ -51,6 +51,8 @@ public: public slots: void angularTicksChanged(int value); void radialTicksChanged(int value); + void angularMinorTicksChanged(int value); + void radialMinorTicksChanged(int value); void anglesChanged(int value); void angularMinChanged(double value); void angularMaxChanged(double value); @@ -67,6 +69,7 @@ public slots: void titleFontChanged(const QFont &font); void titleFontSizeChanged(int value); void gridIndexChanged(int index); + void minorGridIndexChanged(int index); void arrowIndexChanged(int index); void angularRangeChanged(qreal min, qreal max); void radialRangeChanged(qreal min, qreal max); @@ -109,6 +112,8 @@ private: int m_angularTickCount; int m_radialTickCount; + int m_angularMinorTickCount; + int m_radialMinorTickCount; qreal m_labelsAngle; qreal m_angularMin; qreal m_angularMax; @@ -120,6 +125,8 @@ private: bool m_titleVisible; bool m_gridVisible; bool m_arrowVisible; + bool m_minorGridVisible; + bool m_minorArrowVisible; QBrush *m_angularShadesBrush; QBrush *m_radialShadesBrush; QBrush *m_labelBrush; @@ -130,6 +137,7 @@ private: QPen *m_radialShadesPen; QPen *m_gridPen; QPen *m_arrowPen; + QPen *m_minorGridPen; QPen *m_backgroundPen; QPen *m_plotAreaBackgroundPen; QString m_labelFormat; diff --git a/tests/manual/polarcharttest/mainwindow.ui b/tests/manual/polarcharttest/mainwindow.ui index cc4b199..58ee203 100644 --- a/tests/manual/polarcharttest/mainwindow.ui +++ b/tests/manual/polarcharttest/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 1193 - 956 + 1004 @@ -35,231 +35,13 @@ Settings - - - - 110 - 90 - 71 - 22 - - - - - - - 10 - 90 - 101 - 16 - - - - Radial Tick count - - - - - - 10 - 120 - 101 - 16 - - - - Angular Tick count - - - - - - 110 - 120 - 71 - 22 - - - - - - - 110 - 150 - 71 - 22 - - - - -9999 - - - 9999 - - - 5 - - - - - - 10 - 150 - 101 - 16 - - - - Label angles - - - - - - 10 - 180 - 101 - 16 - - - - Angular min - - - - - - 10 - 210 - 101 - 16 - - - - Angular max - - - - - - 90 - 180 - 91 - 22 - - - - 5 - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - 10.000000000000000 - - - - - - 90 - 210 - 91 - 22 - - - - 5 - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - 10.000000000000000 - - - - - - 90 - 270 - 91 - 22 - - - - 5 - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - 10.000000000000000 - - - - - - 90 - 240 - 91 - 22 - - - - 5 - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - 10.000000000000000 - - - - - - 10 - 270 - 101 - 16 - - - - Radial max - - - - - - 10 - 240 - 101 - 16 - - - - Radial min - - 10 - 300 - 171 - 22 + 313 + 187 + 20 @@ -282,9 +64,9 @@ 10 - 330 - 171 - 22 + 339 + 175 + 20 @@ -303,75 +85,13 @@ - - - - 10 - 360 - 101 - 16 - - - - Label format - - - - - - 100 - 360 - 81 - 20 - - - - - - - 10 - 390 - 101 - 16 - - - - Label font size - - - - - - 10 - 420 - 171 - 22 - - - - - - - 100 - 390 - 81 - 22 - - - - -100000 - - - 100000 - - 10 - 480 - 171 - 22 + 471 + 104 + 20 @@ -399,9 +119,9 @@ 10 - 450 - 171 - 22 + 445 + 134 + 20 @@ -423,29 +143,13 @@ - - - - 100 - 510 - 81 - 22 - - - - -100000 - - - 100000 - - 10 - 570 - 171 - 22 + 551 + 130 + 20 @@ -483,36 +187,13 @@ - - - - 10 - 540 - 171 - 22 - - - - - - - 10 - 510 - 101 - 16 - - - - Title font size - - 10 - 600 - 171 - 22 + 577 + 104 + 20 @@ -544,9 +225,9 @@ 10 - 630 - 171 - 22 + 603 + 114 + 20 @@ -578,9 +259,9 @@ 10 - 20 - 171 - 22 + 23 + 134 + 20 @@ -616,9 +297,9 @@ 10 - 50 - 171 - 22 + 49 + 126 + 20 @@ -650,188 +331,13 @@ - - - - 10 - 660 - 101 - 16 - - - - Log Base - - - - - - 90 - 660 - 91 - 22 - - - - 5 - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - 8.000000000000000 - - - - - - 10 - 690 - 91 - 16 - - - - Nice Numbers - - - - - - 100 - 710 - 81 - 20 - - - - - - - 10 - 710 - 101 - 16 - - - - DateTime format - - - - - - 100 - 690 - 141 - 16 - - - - More Categories - - - - - - 10 - 730 - 31 - 16 - - - - 1 - - - - - - 40 - 730 - 31 - 16 - - - - 2 - - - - - - 70 - 730 - 31 - 16 - - - - 3 - - - - - - 10 - 750 - 31 - 16 - - - - 4 - - - - - - 40 - 750 - 31 - 16 - - - - 5 - - - - - - 70 - 750 - 31 - 16 - - - - 6 - - - - - - 100 - 740 - 31 - 16 - - - - 7 - - 10 - 770 - 171 - 22 + 814 + 131 + 20 @@ -888,8 +394,8 @@ 10 - 800 - 171 + 840 + 117 16 @@ -901,9 +407,9 @@ 10 - 820 - 171 - 22 + 877 + 195 + 20 @@ -935,9 +441,9 @@ 10 - 850 - 171 - 22 + 903 + 165 + 20 @@ -965,6 +471,434 @@ + + + + 10 + 207 + 185 + 100 + + + + + + + 5 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 10.000000000000000 + + + + + + + Radial max + + + + + + + Radial min + + + + + + + Angular max + + + + + + + 5 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 10.000000000000000 + + + + + + + Angular min + + + + + + + 5 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 10.000000000000000 + + + + + + + 5 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 10.000000000000000 + + + + + + + + + 10 + 365 + 210 + 74 + + + + + + + Label format + + + + + + + + + + Label font size + + + + + + + -100000 + + + 100000 + + + + + + + + + + + + 10 + 497 + 190 + 48 + + + + + + + Title font size + + + + + + + -100000 + + + 100000 + + + + + + + + + + + + 10 + 655 + 168 + 22 + + + + + + + Log Base + + + + + + + 5 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 8.000000000000000 + + + + + + + + + 10 + 692 + 198 + 19 + + + + + + + Nice Numbers + + + + + + + More Categories + + + + + + + + + 10 + 729 + 221 + 22 + + + + + + + DateTime format + + + + + + + + + + + + 10 + 766 + 136 + 42 + + + + + + + 1 + + + + + + + 2 + + + + + + + 3 + + + + + + + 7 + + + + + + + 4 + + + + + + + 5 + + + + + + + 6 + + + + + + + + + 10 + 75 + 178 + 126 + + + + + + + Angular Tick count + + + + + + + -9999 + + + 9999 + + + 5 + + + + + + + + + + Radial Tick count + + + + + + + Angular Minor Tick count + + + + + + + + + + + + + Radial Minor Tick count + + + + + + + + + + Label angles + + + + + + + + + 10 + 630 + 141 + 20 + + + + + 0 + 0 + + + + 1 + + + + Invisible minor grid + + + + + Black minor grid + + + + + Custom minor grid pen + + + diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorAxis.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorAxis.qml index dedd14d..67f7de2 100644 --- a/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorAxis.qml +++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/ChartEditorAxis.qml @@ -61,6 +61,10 @@ Row { onClicked: axis.gridVisible = !axis.gridVisible; } Button { + text: "axis minor grid visible" + onClicked: axis.minorGridVisible = !axis.minorGridVisible; + } + Button { text: "axis shades visible" onClicked: axis.shadesVisible = !axis.shadesVisible; } @@ -102,10 +106,17 @@ Row { } Button { text: "axis tick count -" - onClicked: axis.tickCount--; } Button { + text: "axis minor tick count +" + onClicked: axis.minorTickCount++; + } + Button { + text: "axis minor tick count -" + onClicked: axis.minorTickCount--; + } + Button { text: "axis reverse" onClicked: axis.reverse = !axis.reverse; }