##// END OF EJS Templates
Fix zorder of axis, and ticks
Michal Klocek -
r272:1946c776c83b
parent child
Show More
@@ -16,11 +16,13 m_shadesEnabled(true),
16 16 m_grid(parent),
17 17 m_shades(parent),
18 18 m_labels(parent),
19 m_origin(0,0)
19 m_axis(parent)
20 20 {
21 21 //initial initialization
22 m_axis.setZValue(ChartPresenter::AxisZValue);
22 23 m_shades.setZValue(ChartPresenter::ShadesZValue);
23 24 m_grid.setZValue(ChartPresenter::GridZValue);
25 setFlags(QGraphicsItem::ItemHasNoContents);
24 26 }
25 27
26 28 AxisItem::~AxisItem()
@@ -34,10 +36,12 QRectF AxisItem::boundingRect() const
34 36
35 37 void AxisItem::createItems(int count)
36 38 {
39 m_axis.addToGroup(new QGraphicsLineItem(this));
37 40 for (int i = 0; i < count; ++i) {
38 41 m_grid.addToGroup(new QGraphicsLineItem(this));
39 42 m_labels.addToGroup(new QGraphicsSimpleTextItem(this));
40 43 if(i%2) m_shades.addToGroup(new QGraphicsRectItem(this));
44 m_axis.addToGroup(new QGraphicsLineItem(this));
41 45 }
42 46 }
43 47
@@ -55,6 +59,10 void AxisItem::clear()
55 59 delete item;
56 60 }
57 61
62 foreach(QGraphicsItem* item , m_axis.childItems()) {
63 delete item;
64 }
65
58 66 m_thicksList.clear();
59 67
60 68 }
@@ -66,10 +74,12 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
66 74
67 75 void AxisItem::updateItem(int count)
68 76 {
77 if(count ==0) return;
69 78
70 79 QList<QGraphicsItem *> lines = m_grid.childItems();
71 80 QList<QGraphicsItem *> labels = m_labels.childItems();
72 81 QList<QGraphicsItem *> shades = m_shades.childItems();
82 QList<QGraphicsItem *> axis = m_axis.childItems();
73 83
74 84 switch (m_type)
75 85 {
@@ -77,7 +87,8 void AxisItem::updateItem(int count)
77 87 {
78 88 const qreal deltaX = m_rect.width() / (count-1);
79 89
80 m_axis.setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
90 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
91 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
81 92
82 93 for (int i = 0; i < count; ++i) {
83 94 int x = i * deltaX + m_rect.left();
@@ -88,11 +99,12 void AxisItem::updateItem(int count)
88 99 QPointF center = labelItem->boundingRect().center();
89 100 labelItem->setTransformOriginPoint(center.x(), center.y());
90 101 labelItem->setPos(x - center.x(), m_rect.bottom() + label_padding);
91
92 102 if(i%2){
93 103 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
94 104 rectItem->setRect(x,m_rect.top(),deltaX,m_rect.height());
95 105 }
106 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
107 lineItem->setLine(x,m_rect.bottom(),x,m_rect.bottom()+5);
96 108 }
97 109 }
98 110 break;
@@ -101,7 +113,8 void AxisItem::updateItem(int count)
101 113 {
102 114 const qreal deltaY = m_rect.height()/ (count-1);
103 115
104 m_axis.setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
116 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
117 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
105 118
106 119 for (int i = 0; i < count; ++i) {
107 120 int y = i * -deltaY + m_rect.bottom();
@@ -116,6 +129,8 void AxisItem::updateItem(int count)
116 129 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
117 130 rectItem->setRect(m_rect.left(),y,m_rect.width(),deltaY);
118 131 }
132 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
133 lineItem->setLine(m_rect.left()-5,y,m_rect.left(),y);
119 134 }
120 135 }
121 136 break;
@@ -170,14 +185,14 void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels)
170 185 {
171 186 m_thicksList=labels;
172 187 QList<QGraphicsItem*> items = m_labels.childItems();
173 if(items.size()!=m_thicksList.size()){
188 //if(items.size()!=m_thicksList.size()){
174 189 clear();
175 190 m_thicksList=labels;
176 191 createItems(m_thicksList.size());
177 192 updateItem(m_thicksList.size());
178 193 items = m_labels.childItems();
179 194 handleAxisUpdate(axis);
180 }
195 // }
181 196
182 197 Q_ASSERT(items.size()==m_thicksList.size());
183 198
@@ -283,7 +298,9 void AxisItem::setShadesPen(const QPen& pen)
283 298
284 299 void AxisItem::setAxisPen(const QPen& pen)
285 300 {
286 m_axis.setPen(pen);
301 foreach(QGraphicsItem* item , m_axis.childItems()) {
302 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
303 }
287 304 }
288 305
289 306 void AxisItem::setGridPen(const QPen& pen)
@@ -66,9 +66,8 private:
66 66 QGraphicsItemGroup m_grid;
67 67 QGraphicsItemGroup m_shades;
68 68 QGraphicsItemGroup m_labels;
69 QGraphicsLineItem m_axis;
69 QGraphicsItemGroup m_axis;
70 70 QStringList m_thicksList;
71 QPointF m_origin;
72 71
73 72 };
74 73
@@ -86,6 +86,7 void QChart::createChartBackgroundItem()
86 86 {
87 87 if(!m_backgroundItem) {
88 88 m_backgroundItem = new QGraphicsRectItem(this);
89 m_backgroundItem->setPen(Qt::NoPen);
89 90 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
90 91 }
91 92 }
General Comments 0
You need to be logged in to leave comments. Login now