diff --git a/example/axischart/main.cpp b/example/axischart/main.cpp index 97ae989..409fb7f 100644 --- a/example/axischart/main.cpp +++ b/example/axischart/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) axis.setGridPen(Qt::DashLine); chartView->setDefaultAxisX(axis); - //axis.setShadesBrush(Qt::gray); + axis.setShadesBrush(Qt::gray); chartView->setDefaultAxisY(axis); window.setCentralWidget(chartView); diff --git a/src/axisitem.cpp b/src/axisitem.cpp index d20b7a0..1531ab9 100644 --- a/src/axisitem.cpp +++ b/src/axisitem.cpp @@ -13,11 +13,13 @@ m_ticks(4), m_type(type), m_labelsAngle(0), m_shadesEnabled(true), -m_grid(this), -m_shades(this), -m_labels(this) +m_grid(parent), +m_shades(parent), +m_labels(parent) { //initial initialization + m_shades.setZValue(0); + m_grid.setZValue(2); createItems(); } @@ -73,6 +75,8 @@ void AxisItem::updateDomain() { const qreal deltaX = m_rect.width() / m_ticks; + m_axis.setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); + for (int i = 0; i <= m_ticks; ++i) { int x = i * deltaX + m_rect.left(); @@ -100,6 +104,8 @@ void AxisItem::updateDomain() { const qreal deltaY = m_rect.height()/ m_ticks; + m_axis.setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); + for (int i = 0; i <= m_ticks; ++i) { int y = i * -deltaY + m_rect.bottom(); @@ -131,6 +137,13 @@ void AxisItem::updateDomain() void AxisItem::handleAxisChanged(const QChartAxis& axis) { + if(axis.isAxisVisible()) { + setAxisOpacity(100); + } + else { + setAxisOpacity(0); + } + if(axis.isGridVisible()) { setGridOpacity(100); } @@ -168,6 +181,7 @@ void AxisItem::handleAxisChanged(const QChartAxis& axis) break; } + setAxisPen(axis.axisPen()); setLabelsPen(axis.labelsPen()); setLabelsBrush(axis.labelsBrush()); setLabelsFont(axis.labelFont()); @@ -191,6 +205,16 @@ void AxisItem::handleGeometryChanged(const QRectF& rect) update(); } +void AxisItem::setAxisOpacity(qreal opacity) +{ + m_axis.setOpacity(opacity); +} + +qreal AxisItem::axisOpacity() const +{ + return m_axis.opacity(); +} + void AxisItem::setGridOpacity(qreal opacity) { m_grid.setOpacity(opacity); @@ -267,6 +291,11 @@ void AxisItem::setShadesPen(const QPen& pen) } } +void AxisItem::setAxisPen(const QPen& pen) +{ + m_axis.setPen(pen); +} + void AxisItem::setGridPen(const QPen& pen) { foreach(QGraphicsItem* item , m_grid.childItems()) { diff --git a/src/axisitem_p.h b/src/axisitem_p.h index 4317de4..fc21bf1 100644 --- a/src/axisitem_p.h +++ b/src/axisitem_p.h @@ -24,6 +24,9 @@ public: AxisType axisType() const {return m_type;}; + void setAxisOpacity(qreal opacity); + qreal axisOpacity() const; + void setGridOpacity(qreal opacity); qreal gridOpacity() const; @@ -42,6 +45,7 @@ public: void setShadesBrush(const QBrush& brush); void setShadesPen(const QPen& pen); + void setAxisPen(const QPen& pen); void setGridPen(const QPen& pen); void setLabelsPen(const QPen& pen); @@ -67,6 +71,7 @@ private: QGraphicsItemGroup m_grid; QGraphicsItemGroup m_shades; QGraphicsItemGroup m_labels; + QGraphicsLineItem m_axis; }; diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 39fdd44..8c53977 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -239,6 +239,7 @@ void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) axis.setLabelsBrush(Qt::black); axis.setLabelsPen(Qt::NoPen); + axis.setShadesPen(Qt::NoPen); item->handleAxisChanged(axis); } diff --git a/src/qchartaxis.cpp b/src/qchartaxis.cpp index b7ca0b7..2161e81 100644 --- a/src/qchartaxis.cpp +++ b/src/qchartaxis.cpp @@ -22,11 +22,6 @@ void QChartAxis::setAxisPen(const QPen& pen) m_axisPen=pen; } -void QChartAxis::setAxisBrush(const QBrush& brush) -{ - m_axisBrush=brush; -} - void QChartAxis::setAxisVisible(bool visible) { m_axisVisible=visible;