##// END OF EJS Templates
Temporary blocks axis layout changes
Michal Klocek -
r1303:ff9cd5b688dd
parent child
Show More
@@ -1,112 +1,112
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartaxisx_p.h"
22 22 #include "qaxis.h"
23 23 #include "qaxis_p.h"
24 24 #include "qaxiscategories_p.h"
25 25 #include "chartpresenter_p.h"
26 26 #include "chartanimator_p.h"
27 27
28 28 static int label_padding = 5;
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 ChartAxisX::ChartAxisX(QAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
33 33 {
34 34 }
35 35
36 36 ChartAxisX::~ChartAxisX()
37 37 {
38 38 }
39 39
40 40 QVector<qreal> ChartAxisX::calculateLayout() const
41 41 {
42 42 Q_ASSERT(m_ticksCount>=2);
43 43
44 44 QVector<qreal> points;
45 45 points.resize(m_ticksCount);
46 46
47 47 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
48 48 for (int i = 0; i < m_ticksCount; ++i) {
49 49 int x = i * deltaX + m_rect.left();
50 50 points[i] = x;
51 51 }
52 52 return points;
53 53 }
54 54
55 55 void ChartAxisX::updateGeometry()
56 56 {
57 57 const QVector<qreal>& layout = ChartAxis::layout();
58 58
59 59 QStringList ticksList;
60 60
61 61 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
62 62
63 63 QList<QGraphicsItem *> lines = m_grid->childItems();
64 64 QList<QGraphicsItem *> labels = m_labels->childItems();
65 65 QList<QGraphicsItem *> shades = m_shades->childItems();
66 66 QList<QGraphicsItem *> axis = m_axis->childItems();
67 67
68 68 Q_ASSERT(labels.size() == ticksList.size());
69 69 Q_ASSERT(layout.size() == ticksList.size());
70 70
71 71 qreal minWidth = 0;
72 72 qreal minHeight = 0;
73 73
74 74 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
75 75 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
76 76
77 77 for (int i = 0; i < layout.size(); ++i) {
78 78 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
79 79 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
80 80 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
81 81 if (!categories || i<1) {
82 82 labelItem->setText(ticksList.at(i));
83 83 const QRectF& rect = labelItem->boundingRect();
84 84 minWidth+=rect.width();
85 85 minHeight=qMax(rect.height(),minHeight);
86 86 QPointF center = rect.center();
87 87 labelItem->setTransformOriginPoint(center.x(), center.y());
88 88 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
89 89 }
90 90 else {
91 91 labelItem->setText(ticksList.at(i));
92 92 const QRectF& rect = labelItem->boundingRect();
93 93 minWidth+=rect.width();
94 94 minHeight=qMax(rect.height()+label_padding,minHeight);
95 95 QPointF center = rect.center();
96 96 labelItem->setTransformOriginPoint(center.x(), center.y());
97 97 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
98 98 }
99 99
100 100 if ((i+1)%2 && i>1) {
101 101 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
102 102 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
103 103 }
104 104 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
105 105 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
106 106 }
107 107
108 presenter()->setMinimumMarginWidth(this,minWidth);
109 presenter()->setMinimumMarginHeight(this,minHeight);
108 //presenter()->setMinimumMarginWidth(this,minWidth);
109 //presenter()->setMinimumMarginHeight(this,minHeight);
110 110 }
111 111
112 112 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,116 +1,116
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartaxisy_p.h"
22 22 #include "qaxis.h"
23 23 #include "qaxis_p.h"
24 24 #include "qaxiscategories_p.h"
25 25 #include "chartpresenter_p.h"
26 26 #include "chartanimator_p.h"
27 27
28 28
29 29 static int label_padding = 5;
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 ChartAxisY::ChartAxisY(QAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
34 34 {
35 35 }
36 36
37 37 ChartAxisY::~ChartAxisY()
38 38 {
39 39 }
40 40
41 41 QVector<qreal> ChartAxisY::calculateLayout() const
42 42 {
43 43 Q_ASSERT(m_ticksCount>=2);
44 44
45 45 QVector<qreal> points;
46 46 points.resize(m_ticksCount);
47 47
48 48 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
49 49 for (int i = 0; i < m_ticksCount; ++i) {
50 50 int y = i * -deltaY + m_rect.bottom();
51 51 points[i] = y;
52 52 }
53 53
54 54 return points;
55 55 }
56 56
57 57 void ChartAxisY::updateGeometry()
58 58 {
59 59 const QVector<qreal> &layout = ChartAxis::layout();
60 60
61 61 QStringList ticksList;
62 62
63 63 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
64 64
65 65 QList<QGraphicsItem *> lines = m_grid->childItems();
66 66 QList<QGraphicsItem *> labels = m_labels->childItems();
67 67 QList<QGraphicsItem *> shades = m_shades->childItems();
68 68 QList<QGraphicsItem *> axis = m_axis->childItems();
69 69
70 70 Q_ASSERT(labels.size() == ticksList.size());
71 71 Q_ASSERT(layout.size() == ticksList.size());
72 72
73 73 qreal minWidth = 0;
74 74 qreal minHeight = 0;
75 75
76 76 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
77 77 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
78 78
79 79 for (int i = 0; i < layout.size(); ++i) {
80 80 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
81 81 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
82 82 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
83 83
84 84 if (!categories || i<1) {
85 85 labelItem->setText(ticksList.at(i));
86 86 const QRectF& rect = labelItem->boundingRect();
87 87 minWidth=qMax(rect.width()+label_padding,minWidth);
88 88 minHeight+=rect.height();
89 89 QPointF center = rect.center();
90 90 labelItem->setTransformOriginPoint(center.x(), center.y());
91 91 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
92 92 }
93 93 else {
94 94 labelItem->setText(ticksList.at(i));
95 95 const QRectF& rect = labelItem->boundingRect();
96 96 minWidth=qMax(rect.width(),minWidth);
97 97 minHeight+=rect.height();
98 98 QPointF center = rect.center();
99 99 labelItem->setTransformOriginPoint(center.x(), center.y());
100 100 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y());
101 101 }
102 102
103 103 if ((i+1)%2 && i>1) {
104 104 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
105 105 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
106 106 }
107 107 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
108 108 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
109 109 }
110 110
111 presenter()->setMinimumMarginWidth(this,minWidth);
112 presenter()->setMinimumMarginHeight(this,minHeight);
111 //presenter()->setMinimumMarginWidth(this,minWidth);
112 //presenter()->setMinimumMarginHeight(this,minHeight);
113 113
114 114 }
115 115
116 116 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now