##// END OF EJS Templates
Updates axis drawing code...
Michal Klocek -
r2133:8c175959daec
parent child
Show More
@@ -51,8 +51,10 public:
51 51
52 52 int count = series->barSets().first()->count();
53 53
54 for (int i = 0; i < count; i++)
55 barcategory->append(QString::number(i));
54
55 for (int i = 0; i < count; i++) {
56 barcategory->append("BarSet " + QString::number(i));
57 }
56 58
57 59 chart->setAxisY(valueaxis, series);
58 60 chart->setAxisX(barcategory, series);
@@ -51,8 +51,9 public:
51 51
52 52 int count = series->barSets().first()->count();
53 53
54 for (int i = 0; i < count; i++)
55 barcategory->append(QString::number(i));
54 for (int i = 0; i < count; i++) {
55 barcategory->append("BarSet " + QString::number(i));
56 }
56 57
57 58 chart->setAxisX(valueaxis, series);
58 59 chart->setAxisY(barcategory, series);
@@ -40,30 +40,30 ChartBarCategoryAxisX::~ChartBarCategoryAxisX()
40 40
41 41 QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const
42 42 {
43 int count = m_categoriesAxis->d_ptr->count();
43 QVector<qreal> points;
44 44
45 Q_ASSERT(count >= 1);
45 const QRectF& gridRect = gridGeometry();
46 qreal range = max() - min();
46 47
47 QVector<qreal> points;
48 points.resize(count + 2);
48 const qreal delta = gridRect.width()/range;
49 49
50 const QRectF &gridRect = gridGeometry();
50 if(delta<2) return points;
51
52 qreal offset =-min()-0.5;
53
54 offset = int(offset * delta)%int(delta);
51 55
52 const qreal delta = gridRect.width() / (count);
53 qreal offset = -min() - 0.5;
56 int count = qFloor(range);
54 57
55 if (delta < 1)
56 return points;
58 if(count < 1 ) return points;
57 59
58 if (offset < 0)
59 offset = int(offset * gridRect.width() / (max() - min())) % int(delta) + delta;
60 else
61 offset = int(offset * gridRect.width() / (max() - min())) % int(delta);
60 points.resize(count+2);
62 61
63 for (int i = -1; i < count + 1; ++i) {
62 for (int i = 0; i < count+2; ++i) {
64 63 qreal x = offset + i * delta + gridRect.left();
65 points[i + 1] = x;
64 points[i] = x;
66 65 }
66
67 67 return points;
68 68 }
69 69
@@ -114,34 +114,35 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra
114 114 QSizeF sh;
115 115 QSizeF base = ChartAxis::sizeHint(which, constraint);
116 116 QStringList ticksList = createCategoryLabels(ChartAxis::layout());
117 qreal width = 0;
118 qreal height = 0;
119
120 switch (which) {
121 case Qt::MinimumSize:
122 width = fn.boundingRect("...").width();
123 height = fn.height() + labelPadding();
124 width = qMax(width, base.width());
125 height += base.height();
126 sh = QSizeF(width, height);
127 break;
128 case Qt::PreferredSize: {
129
130 for (int i = 0; i < ticksList.size(); ++i) {
131 QRectF rect = fn.boundingRect(ticksList.at(i));
132 width += rect.width();
133 height = qMax(rect.height() + labelPadding(), height);
134 }
135 width = qMax(width, base.width());
136 height += base.height();
137 sh = QSizeF(width, height);
138 break;
139 }
140 default:
141 break;
142 }
143 117
144 return sh;
118 qreal width=0;
119 qreal height=0;
120
121 switch (which) {
122 case Qt::MinimumSize:
123 width = fn.boundingRect("...").width();
124 height = fn.height()+labelPadding();
125 width=qMax(width,base.width());
126 height += base.height();
127 sh = QSizeF(width,height);
128 break;
129 case Qt::PreferredSize:{
130
131 for (int i = 0; i < ticksList.size(); ++i)
132 {
133 QRectF rect = fn.boundingRect(ticksList.at(i));
134 width += rect.width();
135 }
136 height = fn.height()+labelPadding();
137 width = qMax(width,base.width());
138 height += base.height();
139 sh = QSizeF(width,height);
140 break;
141 }
142 default:
143 break;
144 }
145 return sh;
145 146 }
146 147
147 148 QTCOMMERCIALCHART_END_NAMESPACE
@@ -23,6 +23,7
23 23 #include "qbarcategoryaxis_p.h"
24 24 #include <qmath.h>
25 25 #include <QFontMetrics>
26 #include <QDebug>
26 27
27 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 29
@@ -111,34 +112,35 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra
111 112 QSizeF sh;
112 113 QSizeF base = ChartAxis::sizeHint(which, constraint);
113 114 QStringList ticksList = createCategoryLabels(ChartAxis::layout());
114 qreal width = 0;
115 qreal height = 0;
116
117 switch (which) {
118 case Qt::MinimumSize:
119 width = fn.boundingRect("...").width() + labelPadding();
120 height = fn.height();
121 width += base.width();
122 height = qMax(height, base.height());
123 sh = QSizeF(width, height);
124 break;
125 case Qt::PreferredSize: {
126
127 for (int i = 0; i < ticksList.size(); ++i) {
128 QRectF rect = fn.boundingRect(ticksList.at(i));
129 height += rect.height();
130 width = qMax(rect.width() + labelPadding(), width);
131 }
132 height = qMax(height, base.height());
133 width += base.width();
134 sh = QSizeF(width, height);
135 break;
136 }
137 default:
138 break;
139 }
140 115
141 return sh;
116 qreal width=0;
117 qreal height=0;
118
119 switch (which) {
120 case Qt::MinimumSize:
121 width = fn.boundingRect("...").width() + labelPadding();
122 height = fn.height();
123 width+=base.width();
124 height=qMax(height,base.height());
125 sh = QSizeF(width,height);
126 break;
127 case Qt::PreferredSize:{
128
129 for (int i = 0; i < ticksList.size(); ++i)
130 {
131 QRectF rect = fn.boundingRect(ticksList.at(i));
132 height+=rect.height();
133 width=qMax(rect.width()+labelPadding() +1 ,width); //one pixel torelance
134 }
135 height=qMax(height,base.height());
136 width+=base.width();
137 sh = QSizeF(width,height);
138 break;
139 }
140 default:
141 break;
142 }
143 return sh;
142 144 }
143 145
144 146 QTCOMMERCIALCHART_END_NAMESPACE
@@ -301,9 +301,8 void ChartAxis::handleDomainUpdated()
301 301
302 302 QVector<qreal> layout = calculateLayout();
303 303 updateLayout(layout);
304 QSizeF before = effectiveSizeHint(Qt::MinimumSize);
305
306 QSizeF after = sizeHint(Qt::MinimumSize);
304 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
305 QSizeF after = sizeHint(Qt::PreferredSize);
307 306
308 307 if (before != after) {
309 308 QGraphicsLayoutItem::updateGeometry();
@@ -21,6 +21,7
21 21 #include "horizontalaxis_p.h"
22 22 #include "qabstractaxis.h"
23 23 #include <QFontMetrics>
24 #include <qmath.h>
24 25 #include <QDebug>
25 26
26 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -41,15 +42,15 void HorizontalAxis::updateGeometry()
41 42 if (layout.isEmpty())
42 43 return;
43 44
44 QStringList ticksList = labels();
45 QStringList labelList = labels();
45 46
46 47 QList<QGraphicsItem *> lines = lineItems();
47 48 QList<QGraphicsItem *> labels = labelItems();
48 49 QList<QGraphicsItem *> shades = shadeItems();
49 50 QList<QGraphicsItem *> axis = arrowItems();
50 51
51 Q_ASSERT(labels.size() == ticksList.size());
52 Q_ASSERT(layout.size() == ticksList.size());
52 Q_ASSERT(labels.size() == labelList.size());
53 Q_ASSERT(layout.size() == labelList.size());
53 54
54 55 const QRectF &axisRect = axisGeometry();
55 56 const QRectF &gridRect = gridGeometry();
@@ -63,19 +64,39 void HorizontalAxis::updateGeometry()
63 64 arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top());
64 65
65 66 qreal width = 0;
67 QFontMetrics fn(font());
66 68
67 69 for (int i = 0; i < layout.size(); ++i) {
68 70
69 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i));
70 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(axis.at(i + 1));
71 //items
72 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i));
73 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(axis.at(i + 1));
71 74 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
72 75
73 76 //grid line
74 77 gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom());
75 78
76 //label text
77 labelItem->setText(ticksList.at(i));
78 const QRectF &rect = labelItem->boundingRect();
79 //label text wrapping
80 if(intervalAxis()&& i+1!=layout.size()) {
81 //wrapping in case of interval axis
82 const qreal delta = layout[i+1] - layout[i];
83 QString text = labelList.at(i);
84 if (fn.boundingRect(text).width() > delta )
85 {
86 QString label = text + "...";
87 while (fn.boundingRect(label).width() > delta && label.length() > 3)
88 label.remove(label.length() - 4, 1);
89 labelItem->setText(label);
90 }
91 else {
92 labelItem->setText(text);
93 }
94 }else{
95 labelItem->setText(labelList.at(i));
96 }
97
98 //label transformation origin point
99 const QRectF& rect = labelItem->boundingRect();
79 100 QPointF center = rect.center();
80 101 labelItem->setTransformOriginPoint(center.x(), center.y());
81 102
@@ -88,23 +109,21 void HorizontalAxis::updateGeometry()
88 109 tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding());
89 110 }
90 111
91 if (intervalAxis() && i + 1 != layout.size()) {
92 const qreal delta = (layout[i + 1] - layout[i]) / 2;
112 //label in beetwen
113 if(intervalAxis()&& i+1!=layout.size()) {
114 const qreal delta = (layout[i+1] - layout[i])/2;
93 115 labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y());
94 116 }
95 117
96 //overlap detection
97 if (labelItem->pos().x() <= width ||
118 //label overlap detection
119 if(labelItem->pos().x() <= width ||
98 120 labelItem->pos().x() < axisRect.left() ||
99 121 labelItem->pos().x() + rect.width() > axisRect.right()) {
100 122 labelItem->setVisible(false);
101 gridItem->setVisible(false);
102 tickItem->setVisible(false);
103 } else {
123 }
124 else {
104 125 labelItem->setVisible(true);
105 gridItem->setVisible(true);
106 tickItem->setVisible(true);
107 width = rect.width() + labelItem->pos().x();
126 width=rect.width()+labelItem->pos().x();
108 127 }
109 128
110 129 //shades
@@ -118,8 +137,9 void HorizontalAxis::updateGeometry()
118 137 if (x < gridRect.left() || x > gridRect.right()) {
119 138 gridItem->setVisible(false);
120 139 tickItem->setVisible(false);
121 if (intervalAxis() && (labelItem->pos().x() < gridRect.left() || labelItem->pos().x() + rect.width() > gridRect.right()))
122 labelItem->setVisible(false);
140 }else{
141 gridItem->setVisible(true);
142 tickItem->setVisible(true);
123 143 }
124 144
125 145 }
@@ -129,8 +149,10 void HorizontalAxis::updateGeometry()
129 149 QGraphicsLineItem *gridLine;
130 150 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size()));
131 151 gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom());
132 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size() + 1));
152 gridLine->setVisible(true);
153 gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1));
133 154 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom());
155 gridLine->setVisible(true);
134 156 }
135 157 }
136 158
@@ -88,23 +88,23 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
88 88 qreal height = 0;
89 89
90 90 switch (which) {
91 case Qt::MinimumSize: {
92 int count = qMax(ticksList.last().count(), ticksList.first().count());
91 case Qt::MinimumSize:{
92 int count = qMax(ticksList.last().count(),ticksList.first().count());
93 count = qMin(count,5);
93 94 width = fn.averageCharWidth() * count;
94 95 height = fn.height() + labelPadding();
95 width = qMax(width, base.width());
96 width = qMax(width,base.width());
96 97 height += base.height();
97 sh = QSizeF(width, height);
98 sh = QSizeF(width,height);
98 99 break;
99 100 }
100 case Qt::PreferredSize: {
101 for (int i = 0; i < ticksList.size(); ++i) {
102 width += fn.averageCharWidth() * ticksList.at(i).count();
103 }
104 height = fn.height() + labelPadding();
105 width = qMax(width, base.width());
106 height += base.height();
107 sh = QSizeF(width, height);
101 case Qt::PreferredSize:{
102 int count = qMax(ticksList.last().count(),ticksList.first().count());
103 width=fn.averageCharWidth() * count;
104 height=fn.height()+labelPadding();
105 width=qMax(width,base.width());
106 height+=base.height();
107 sh = QSizeF(width,height);
108 108 break;
109 109 }
110 110 default:
@@ -26,6 +26,7
26 26 #include <QGraphicsLayout>
27 27 #include <QFontMetrics>
28 28 #include <qmath.h>
29 #include <QDebug>
29 30
30 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 32
@@ -90,22 +91,21 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
90 91
91 92 switch (which) {
92 93 case Qt::MinimumSize: {
93 int count = qMax(ticksList.first().count() , ticksList.last().count());
94 width = fn.averageCharWidth() * count + labelPadding();
95 height = fn.height();
96 height = qMax(height, base.height());
94 width = fn.boundingRect("...").width() + labelPadding();
97 95 width += base.width();
98 sh = QSizeF(width, height);
96 height = fn.height();
97 height = qMax(height,base.height());
98 sh = QSizeF(width,height);
99 99 break;
100 100 }
101 case Qt::PreferredSize: {
102 for (int i = 0; i < ticksList.size(); ++i) {
103 width = qMax(qreal(fn.averageCharWidth() * ticksList.at(i).count()) + labelPadding(), width);
104 height += fn.height();
105 }
106 height = qMax(height, base.height());
101 case Qt::PreferredSize:
102 {
103 int count = qMax(ticksList.first().count() , ticksList.last().count());
104 width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance
107 105 width += base.width();
108 sh = QSizeF(width, height);
106 height = fn.height() * ticksList.count();
107 height = qMax(height,base.height());
108 sh = QSizeF(width,height);
109 109 break;
110 110 }
111 111 default:
@@ -57,17 +57,21 void VerticalAxis::updateGeometry()
57 57
58 58 qreal height = axisRect.bottom();
59 59
60 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem *>(axis.at(0));
61 60
62 if (alignment() == Qt::AlignLeft)
63 lineItem->setLine(axisRect.right() , gridRect.top(), axisRect.right(), gridRect.bottom());
64 else if (alignment() == Qt::AlignRight)
65 lineItem->setLine(axisRect.left() , gridRect.top(), axisRect.left(), gridRect.bottom());
61 //arrow
62 QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem*>(axis.at(0));
63
64 //arrow position
65 if (alignment()==Qt::AlignLeft)
66 arrowItem->setLine( axisRect.right() , gridRect.top(), axisRect.right(), gridRect.bottom());
67 else if(alignment()==Qt::AlignRight)
68 arrowItem->setLine( axisRect.left() , gridRect.top(), axisRect.left(), gridRect.bottom());
66 69
67 70 QFontMetrics fn(font());
68 71
69 72 for (int i = 0; i < layout.size(); ++i) {
70 73
74 //items
71 75 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i));
72 76 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(axis.at(i + 1));
73 77 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
@@ -75,7 +79,7 void VerticalAxis::updateGeometry()
75 79 //grid line
76 80 gridItem->setLine(gridRect.left() , layout[i], gridRect.right(), layout[i]);
77 81
78 //label text
82 //label text wrapping
79 83 QString text = labelList.at(i);
80 84 if (fn.boundingRect(text).width() > axisRect.right() - axisRect.left() - labelPadding()) {
81 85 QString label = text + "...";
@@ -85,7 +89,9 void VerticalAxis::updateGeometry()
85 89 } else {
86 90 labelItem->setText(text);
87 91 }
92 //label transformation origin point
88 93 const QRectF &rect = labelItem->boundingRect();
94
89 95 QPointF center = rect.center();
90 96 labelItem->setTransformOriginPoint(center.x(), center.y());
91 97
@@ -97,22 +103,22 void VerticalAxis::updateGeometry()
97 103 labelItem->setPos(axisRect.left() + labelPadding() , layout[i] - center.y());
98 104 tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]);
99 105 }
100 if (intervalAxis() && i + 1 != layout.size()) {
101 const qreal delta = (layout[i + 1] - layout[i]) / 2;
106
107 //label in beetwen
108 if(intervalAxis()&& i+1!=layout.size()) {
109 const qreal delta = (layout[i+1] - layout[i])/2;
102 110 labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y());
103 111 }
104 112
105 //overlap detection
106 if (labelItem->pos().y() + rect.height() > height ||
107 labelItem->pos().y() + rect.height() > axisRect.bottom() ||
108 labelItem->pos().y() < axisRect.top()) {
113 //label overlap detection
114 if(labelItem->pos().y() + rect.height() > height ||
115 labelItem->pos().y() + rect.height()/2 > gridRect.bottom() ||
116 labelItem->pos().y() + rect.height()/2 < gridRect.top()) {
109 117 labelItem->setVisible(false);
110 gridItem->setVisible(false);
111 tickItem->setVisible(false);
112 } else {
118 }
119 else {
113 120 labelItem->setVisible(true);
114 gridItem->setVisible(true);
115 height = labelItem->pos().y();
121 height=labelItem->pos().y();
116 122 }
117 123
118 124 //shades
@@ -123,11 +129,13 void VerticalAxis::updateGeometry()
123 129
124 130 // check if the grid line and the axis tick should be shown
125 131 qreal y = gridItem->line().p1().y();
126 if (y < gridRect.top() || y > gridRect.bottom()) {
132 if ((y < gridRect.top() || y > gridRect.bottom()))
133 {
127 134 gridItem->setVisible(false);
128 135 tickItem->setVisible(false);
129 if (intervalAxis() && (labelItem->pos().y() < gridRect.top() || labelItem->pos().y() + rect.height() > gridRect.bottom()))
130 labelItem->setVisible(false);
136 }else{
137 gridItem->setVisible(true);
138 tickItem->setVisible(true);
131 139 }
132 140
133 141 }
@@ -136,8 +144,10 void VerticalAxis::updateGeometry()
136 144 QGraphicsLineItem *gridLine;
137 145 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size()));
138 146 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top());
139 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size() + 1));
147 gridLine->setVisible(true);
148 gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1));
140 149 gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom());
150 gridLine->setVisible(true);
141 151 }
142 152 }
143 153
@@ -29,7 +29,7
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 static const qreal golden_ratio = 0.25;
32 static const qreal golden_ratio = 0.4;
33 33
34 34 ChartLayout::ChartLayout(ChartPresenter *presenter)
35 35 : m_presenter(presenter),
@@ -103,10 +103,14 QRectF ChartLayout::calculateBackgroundMinimum(const QRectF &minimum) const
103 103
104 104 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const
105 105 {
106 QSizeF left;
107 QSizeF right;
108 QSizeF bottom;
109 QSizeF top;
106 QSizeF left(0,0);
107 QSizeF minLeft(0,0);
108 QSizeF right(0,0);
109 QSizeF minRight(0,0);
110 QSizeF bottom(0,0);
111 QSizeF minBottom(0,0);
112 QSizeF top(0,0);
113 QSizeF minTop(0,0);
110 114 int leftCount = 0;
111 115 int rightCount = 0;
112 116 int topCount = 0;
@@ -117,64 +121,80 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
117 121 if (!axis->isVisible())
118 122 continue;
119 123
120 QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize);
124 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
125 //this is used to get single thick font size
126 QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize);
121 127
122 128 switch (axis->alignment()) {
123 129 case Qt::AlignLeft:
124 left.setWidth(left.width() + size.width());
125 left.setHeight(qMax(left.height(), size.height()));
126 leftCount++;
127 break;
130 left.setWidth(left.width()+size.width());
131 left.setHeight(qMax(left.height(),size.height()));
132 minLeft.setWidth(minLeft.width()+minSize.width());
133 minLeft.setHeight(qMax(minLeft.height(),minSize.height()));
134 leftCount++;
135 break;
128 136 case Qt::AlignRight:
129 right.setWidth(right.width() + size.width());
130 right.setHeight(qMax(right.height(), size.height()));
137 right.setWidth(right.width()+size.width());
138 right.setHeight(qMax(right.height(),size.height()));
139 minRight.setWidth(minRight.width()+minSize.width());
140 minRight.setHeight(qMax(minRight.height(),minSize.height()));
131 141 rightCount++;
132 142 break;
133 143 case Qt::AlignTop:
134 top.setWidth(qMax(top.width(), size.width()));
135 top.setHeight(top.height() + size.height());
144 top.setWidth(qMax(top.width(),size.width()));
145 top.setHeight(top.height()+size.height());
146 minTop.setWidth(qMax(minTop.width(),minSize.width()));
147 minTop.setHeight(minTop.height()+minSize.height());
136 148 topCount++;
137 149 break;
138 150 case Qt::AlignBottom:
139 151 bottom.setWidth(qMax(bottom.width(), size.width()));
140 152 bottom.setHeight(bottom.height() + size.height());
153 minBottom.setWidth(qMax(minBottom.width(),minSize.width()));
154 minBottom.setHeight(minBottom.height() + minSize.height());
141 155 bottomCount++;
142 156 break;
143 157 }
144 158 }
145 159
146 left.setWidth(qMax(qMax(top.width() / 2, bottom.width() / 2), left.width()));
147 left.setWidth(qMin(left.width(), golden_ratio * geometry.width()));
148 right.setWidth(qMax(qMax(top.width() / 2, bottom.width() / 2), right.width()));
149 right.setWidth(qMin(right.width(), golden_ratio * geometry.width()));
150 top.setHeight(qMax(qMax(left.height() / 2, right.height() / 2), top.height()));
151 bottom.setHeight(qMax(qMax(left.height() / 2, right.height() / 2), bottom.height()));
160 int horizontal = leftCount + rightCount;
161 qreal hratio = 0 ;
162 if(horizontal>0)
163 hratio = (golden_ratio*geometry.width())/horizontal;
164
165 if(leftCount>0)
166 left.setWidth(qMin(left.width(),hratio*leftCount));
167 if(rightCount>0)
168 right.setWidth(qMin(right.width(),hratio*rightCount));
152 169
153 QRectF chartRect = geometry.adjusted(left.width(), top.height(), -right.width(), -bottom.height());
170 qreal minHeight = qMax(minLeft.height(),minRight.height());
171 qreal minWidth = qMax(minTop.width(),minBottom.width());
172
173 QRectF chartRect = geometry.adjusted(qMax(left.width(),minWidth/2), qMax(top.height(), minHeight/2),-qMax(right.width(),minWidth/2),-qMax(bottom.height(),minHeight/2));
154 174
155 175 qreal leftOffset = 0;
156 176 qreal rightOffset = 0;
157 177 qreal topOffset = 0;
158 178 qreal bottomOffset = 0;
159 179
160 foreach(ChartAxis * axis , axes) {
180 foreach(ChartAxis* axis , axes) {
161 181
162 182 if (!axis->isVisible())
163 183 continue;
164 184
165 QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize);
185 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
166 186
167 switch (axis->alignment()) {
168 case Qt::AlignLeft: {
169 qreal width = qMin(size.width(), left.width() / leftCount);
170 leftOffset += width;
171 axis->setGeometry(QRect(chartRect.left() - leftOffset, chartRect.top() - (size.height() + 1) / 2, width, chartRect.height() + size.height() + 2), chartRect);
187 switch(axis->alignment()){
188 case Qt::AlignLeft:{
189 qreal width = qMin(size.width(),(left.width()/leftCount));
190 leftOffset+=width;
191 axis->setGeometry(QRect(chartRect.left()-leftOffset, geometry.top(),width, geometry.bottom()),chartRect);
172 192 break;
173 193 }
174 case Qt::AlignRight: {
175 qreal width = qMin(size.width(), right.width() / rightCount);
176 axis->setGeometry(QRect(chartRect.right() + rightOffset, chartRect.top() - (size.height() + 1) / 2, width, chartRect.height() + size.height() + 2), chartRect);
177 rightOffset += width;
194 case Qt::AlignRight:{
195 qreal width = qMin(size.width(),(right.width()/rightCount));
196 axis->setGeometry(QRect(chartRect.right()+rightOffset,geometry.top(),width,geometry.bottom()),chartRect);
197 rightOffset+=width;
178 198 break;
179 199 }
180 200 case Qt::AlignTop:
@@ -287,8 +307,8 QRectF ChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *t
287 307 {
288 308 title->setGeometry(geometry);
289 309 QPointF center = geometry.center() - title->boundingRect().center();
290 title->setPos(center.x(), title->pos().y());
291 return geometry.adjusted(0, title->boundingRect().height(), 0, 0);
310 title->setPos(center.x(),title->pos().y());
311 return geometry.adjusted(0,title->boundingRect().height()+1,0,0);
292 312 }
293 313
294 314 QRectF ChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const
@@ -76,10 +76,10 QSizeF ChartTitle::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
76 76 sh = QSizeF(fn.boundingRect("...").width(), fn.height());
77 77 break;
78 78 case Qt::PreferredSize:
79 sh = QSizeF(fn.boundingRect(m_text).width(), fn.height());
79 sh = fn.boundingRect(m_text).size();
80 80 break;
81 81 case Qt::MaximumSize:
82 sh = QSizeF(fn.boundingRect(m_text).width(), fn.height());
82 sh = fn.boundingRect(m_text).size();
83 83 break;
84 84 case Qt::MinimumDescent:
85 85 sh = QSizeF(0, fn.descent());
General Comments 0
You need to be logged in to leave comments. Login now