##// 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 m_grid(parent),
16 m_grid(parent),
17 m_shades(parent),
17 m_shades(parent),
18 m_labels(parent),
18 m_labels(parent),
19 m_origin(0,0)
19 m_axis(parent)
20 {
20 {
21 //initial initialization
21 //initial initialization
22 m_axis.setZValue(ChartPresenter::AxisZValue);
22 m_shades.setZValue(ChartPresenter::ShadesZValue);
23 m_shades.setZValue(ChartPresenter::ShadesZValue);
23 m_grid.setZValue(ChartPresenter::GridZValue);
24 m_grid.setZValue(ChartPresenter::GridZValue);
25 setFlags(QGraphicsItem::ItemHasNoContents);
24 }
26 }
25
27
26 AxisItem::~AxisItem()
28 AxisItem::~AxisItem()
@@ -34,10 +36,12 QRectF AxisItem::boundingRect() const
34
36
35 void AxisItem::createItems(int count)
37 void AxisItem::createItems(int count)
36 {
38 {
39 m_axis.addToGroup(new QGraphicsLineItem(this));
37 for (int i = 0; i < count; ++i) {
40 for (int i = 0; i < count; ++i) {
38 m_grid.addToGroup(new QGraphicsLineItem(this));
41 m_grid.addToGroup(new QGraphicsLineItem(this));
39 m_labels.addToGroup(new QGraphicsSimpleTextItem(this));
42 m_labels.addToGroup(new QGraphicsSimpleTextItem(this));
40 if(i%2) m_shades.addToGroup(new QGraphicsRectItem(this));
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 delete item;
59 delete item;
56 }
60 }
57
61
62 foreach(QGraphicsItem* item , m_axis.childItems()) {
63 delete item;
64 }
65
58 m_thicksList.clear();
66 m_thicksList.clear();
59
67
60 }
68 }
@@ -66,10 +74,12 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
66
74
67 void AxisItem::updateItem(int count)
75 void AxisItem::updateItem(int count)
68 {
76 {
77 if(count ==0) return;
69
78
70 QList<QGraphicsItem *> lines = m_grid.childItems();
79 QList<QGraphicsItem *> lines = m_grid.childItems();
71 QList<QGraphicsItem *> labels = m_labels.childItems();
80 QList<QGraphicsItem *> labels = m_labels.childItems();
72 QList<QGraphicsItem *> shades = m_shades.childItems();
81 QList<QGraphicsItem *> shades = m_shades.childItems();
82 QList<QGraphicsItem *> axis = m_axis.childItems();
73
83
74 switch (m_type)
84 switch (m_type)
75 {
85 {
@@ -77,7 +87,8 void AxisItem::updateItem(int count)
77 {
87 {
78 const qreal deltaX = m_rect.width() / (count-1);
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 for (int i = 0; i < count; ++i) {
93 for (int i = 0; i < count; ++i) {
83 int x = i * deltaX + m_rect.left();
94 int x = i * deltaX + m_rect.left();
@@ -88,11 +99,12 void AxisItem::updateItem(int count)
88 QPointF center = labelItem->boundingRect().center();
99 QPointF center = labelItem->boundingRect().center();
89 labelItem->setTransformOriginPoint(center.x(), center.y());
100 labelItem->setTransformOriginPoint(center.x(), center.y());
90 labelItem->setPos(x - center.x(), m_rect.bottom() + label_padding);
101 labelItem->setPos(x - center.x(), m_rect.bottom() + label_padding);
91
92 if(i%2){
102 if(i%2){
93 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
103 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
94 rectItem->setRect(x,m_rect.top(),deltaX,m_rect.height());
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 break;
110 break;
@@ -101,7 +113,8 void AxisItem::updateItem(int count)
101 {
113 {
102 const qreal deltaY = m_rect.height()/ (count-1);
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 for (int i = 0; i < count; ++i) {
119 for (int i = 0; i < count; ++i) {
107 int y = i * -deltaY + m_rect.bottom();
120 int y = i * -deltaY + m_rect.bottom();
@@ -116,6 +129,8 void AxisItem::updateItem(int count)
116 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
129 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
117 rectItem->setRect(m_rect.left(),y,m_rect.width(),deltaY);
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 break;
136 break;
@@ -170,14 +185,14 void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels)
170 {
185 {
171 m_thicksList=labels;
186 m_thicksList=labels;
172 QList<QGraphicsItem*> items = m_labels.childItems();
187 QList<QGraphicsItem*> items = m_labels.childItems();
173 if(items.size()!=m_thicksList.size()){
188 //if(items.size()!=m_thicksList.size()){
174 clear();
189 clear();
175 m_thicksList=labels;
190 m_thicksList=labels;
176 createItems(m_thicksList.size());
191 createItems(m_thicksList.size());
177 updateItem(m_thicksList.size());
192 updateItem(m_thicksList.size());
178 items = m_labels.childItems();
193 items = m_labels.childItems();
179 handleAxisUpdate(axis);
194 handleAxisUpdate(axis);
180 }
195 // }
181
196
182 Q_ASSERT(items.size()==m_thicksList.size());
197 Q_ASSERT(items.size()==m_thicksList.size());
183
198
@@ -283,7 +298,9 void AxisItem::setShadesPen(const QPen& pen)
283
298
284 void AxisItem::setAxisPen(const QPen& pen)
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 void AxisItem::setGridPen(const QPen& pen)
306 void AxisItem::setGridPen(const QPen& pen)
@@ -66,9 +66,8 private:
66 QGraphicsItemGroup m_grid;
66 QGraphicsItemGroup m_grid;
67 QGraphicsItemGroup m_shades;
67 QGraphicsItemGroup m_shades;
68 QGraphicsItemGroup m_labels;
68 QGraphicsItemGroup m_labels;
69 QGraphicsLineItem m_axis;
69 QGraphicsItemGroup m_axis;
70 QStringList m_thicksList;
70 QStringList m_thicksList;
71 QPointF m_origin;
72
71
73 };
72 };
74
73
@@ -86,6 +86,7 void QChart::createChartBackgroundItem()
86 {
86 {
87 if(!m_backgroundItem) {
87 if(!m_backgroundItem) {
88 m_backgroundItem = new QGraphicsRectItem(this);
88 m_backgroundItem = new QGraphicsRectItem(this);
89 m_backgroundItem->setPen(Qt::NoPen);
89 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
90 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
90 }
91 }
91 }
92 }
General Comments 0
You need to be logged in to leave comments. Login now