@@ -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(); | |
|
44 | ||
|
45 | Q_ASSERT(count >= 1); | |
|
46 | ||
|
47 | 43 | QVector<qreal> points; |
|
48 | points.resize(count + 2); | |
|
49 | 44 | |
|
50 | 45 |
const QRectF |
|
46 | qreal range = max() - min(); | |
|
47 | ||
|
48 | const qreal delta = gridRect.width()/range; | |
|
49 | ||
|
50 | if(delta<2) return points; | |
|
51 | 51 | |
|
52 | const qreal delta = gridRect.width() / (count); | |
|
53 | 52 |
qreal offset = |
|
54 | 53 | |
|
55 | if (delta < 1) | |
|
56 | return points; | |
|
54 | offset = int(offset * delta)%int(delta); | |
|
55 | ||
|
56 | int count = qFloor(range); | |
|
57 | 57 | |
|
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); | |
|
58 | if(count < 1 ) return points; | |
|
62 | 59 | |
|
63 | for (int i = -1; i < count + 1; ++i) { | |
|
60 | points.resize(count+2); | |
|
61 | ||
|
62 | for (int i = 0; i < count+2; ++i) { | |
|
64 | 63 | qreal x = offset + i * delta + gridRect.left(); |
|
65 |
points[i |
|
|
64 | points[i] = x; | |
|
66 | 65 | } |
|
66 | ||
|
67 | 67 | return points; |
|
68 | 68 | } |
|
69 | 69 | |
@@ -114,6 +114,7 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 | ||
|
117 | 118 |
qreal width |
|
118 | 119 |
qreal height |
|
119 | 120 | |
@@ -127,11 +128,12 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra | |||
|
127 | 128 | break; |
|
128 | 129 |
case Qt::PreferredSize: |
|
129 | 130 | |
|
130 |
for (int i = 0; i < ticksList.size(); ++i) |
|
|
131 | for (int i = 0; i < ticksList.size(); ++i) | |
|
132 | { | |
|
131 | 133 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
132 | 134 | width += rect.width(); |
|
133 | height = qMax(rect.height() + labelPadding(), height); | |
|
134 | 135 | } |
|
136 | height = fn.height()+labelPadding(); | |
|
135 | 137 |
width = qMax(width, |
|
136 | 138 | height += base.height(); |
|
137 | 139 |
sh = QSizeF(width, |
@@ -140,7 +142,6 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra | |||
|
140 | 142 | default: |
|
141 | 143 | break; |
|
142 | 144 | } |
|
143 | ||
|
144 | 145 | return sh; |
|
145 | 146 | } |
|
146 | 147 |
@@ -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,6 +112,7 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()); |
|
115 | ||
|
114 | 116 |
qreal width |
|
115 | 117 |
qreal height |
|
116 | 118 | |
@@ -124,10 +126,11 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra | |||
|
124 | 126 | break; |
|
125 | 127 |
case Qt::PreferredSize: |
|
126 | 128 | |
|
127 |
for (int i = 0; i < ticksList.size(); ++i) |
|
|
129 | for (int i = 0; i < ticksList.size(); ++i) | |
|
130 | { | |
|
128 | 131 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
129 | 132 |
height |
|
130 |
width |
|
|
133 | width=qMax(rect.width()+labelPadding() +1 ,width); //one pixel torelance | |
|
131 | 134 | } |
|
132 | 135 |
height |
|
133 | 136 |
width |
@@ -137,7 +140,6 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra | |||
|
137 | 140 | default: |
|
138 | 141 | break; |
|
139 | 142 | } |
|
140 | ||
|
141 | 143 | return sh; |
|
142 | 144 | } |
|
143 | 145 |
@@ -301,9 +301,8 void ChartAxis::handleDomainUpdated() | |||
|
301 | 301 | |
|
302 | 302 | QVector<qreal> layout = calculateLayout(); |
|
303 | 303 | updateLayout(layout); |
|
304 |
QSizeF before = effectiveSizeHint(Qt:: |
|
|
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 |
|
|
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() == |
|
|
52 |
Q_ASSERT(layout.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,9 +64,11 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 | |
|
71 | //items | |
|
69 | 72 |
QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem |
|
70 | 73 |
QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem |
|
71 | 74 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i)); |
@@ -73,8 +76,26 void HorizontalAxis::updateGeometry() | |||
|
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)); | |
|
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 | |
|
78 | 99 |
const QRectF |
|
79 | 100 | QPointF center = rect.center(); |
|
80 | 101 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
@@ -88,22 +109,20 void HorizontalAxis::updateGeometry() | |||
|
88 | 109 | tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); |
|
89 | 110 | } |
|
90 | 111 | |
|
112 | //label in beetwen | |
|
91 | 113 |
if |
|
92 | 114 |
const qreal delta = (layout[i |
|
93 | 115 | labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y()); |
|
94 | 116 | } |
|
95 | 117 | |
|
96 | //overlap detection | |
|
118 | //label overlap detection | |
|
97 | 119 |
if |
|
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 | 126 |
width |
|
108 | 127 | } |
|
109 | 128 | |
@@ -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 |
|
|
|
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()); |
|
152 | gridLine->setVisible(true); | |
|
132 | 153 |
gridLine = static_cast<QGraphicsLineItem |
|
133 | 154 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom()); |
|
155 | gridLine->setVisible(true); | |
|
134 | 156 | } |
|
135 | 157 | } |
|
136 | 158 |
@@ -90,6 +90,7 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||
|
90 | 90 | switch (which) { |
|
91 | 91 |
case Qt::MinimumSize: |
|
92 | 92 |
int count = qMax(ticksList.last().count(), |
|
93 | count = qMin(count,5); | |
|
93 | 94 | width = fn.averageCharWidth() * count; |
|
94 | 95 | height = fn.height() + labelPadding(); |
|
95 | 96 |
width = qMax(width, |
@@ -98,9 +99,8 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c | |||
|
98 | 99 | break; |
|
99 | 100 | } |
|
100 | 101 |
case Qt::PreferredSize: |
|
101 | for (int i = 0; i < ticksList.size(); ++i) { | |
|
102 |
|
|
|
103 | } | |
|
102 | int count = qMax(ticksList.last().count(),ticksList.first().count()); | |
|
103 | width=fn.averageCharWidth() * count; | |
|
104 | 104 |
height |
|
105 | 105 |
width |
|
106 | 106 |
height |
@@ -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,21 +91,20 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(); | |
|
94 | width = fn.boundingRect("...").width() + labelPadding(); | |
|
95 | width += base.width(); | |
|
95 | 96 | height = fn.height(); |
|
96 | 97 |
height = qMax(height, |
|
97 | width += base.width(); | |
|
98 | 98 |
sh = QSizeF(width, |
|
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(); |
|
106 | height = fn.height() * ticksList.count(); | |
|
107 | height = qMax(height,base.height()); | |
|
108 | 108 |
sh = QSizeF(width, |
|
109 | 109 | break; |
|
110 | 110 | } |
@@ -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 | |
|
61 | //arrow | |
|
62 | QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
|
63 | ||
|
64 | //arrow position | |
|
62 | 65 |
if (alignment() |
|
63 |
|
|
|
66 | arrowItem->setLine( axisRect.right() , gridRect.top(), axisRect.right(), gridRect.bottom()); | |
|
64 | 67 |
else if |
|
65 |
|
|
|
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,21 +103,21 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 | } |
|
106 | ||
|
107 | //label in beetwen | |
|
100 | 108 |
if |
|
101 | 109 |
const qreal delta = (layout[i |
|
102 | 110 | labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y()); |
|
103 | 111 | } |
|
104 | 112 | |
|
105 | //overlap detection | |
|
113 | //label overlap detection | |
|
106 | 114 |
if |
|
107 |
labelItem->pos().y() + rect.height() > |
|
|
108 |
labelItem->pos().y() < |
|
|
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 | 121 |
height |
|
116 | 122 | } |
|
117 | 123 | |
@@ -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 |
|
|
|
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()); |
|
147 | gridLine->setVisible(true); | |
|
139 | 148 |
gridLine = static_cast<QGraphicsLineItem |
|
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. |
|
|
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 |
|
|
108 |
QSizeF |
|
|
109 |
QSizeF |
|
|
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,40 +121,56 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:: |
|
|
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 | 130 |
|
|
125 | 131 |
|
|
132 | minLeft.setWidth(minLeft.width()+minSize.width()); | |
|
133 | minLeft.setHeight(qMax(minLeft.height(),minSize.height())); | |
|
126 | 134 |
|
|
127 | 135 |
|
|
128 | 136 | case Qt::AlignRight: |
|
129 | 137 |
right.setWidth(right.width() |
|
130 | 138 |
right.setHeight(qMax(right.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 | 144 |
top.setWidth(qMax(top.width(), |
|
135 | 145 |
top.setHeight(top.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; |
@@ -162,18 +182,18 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch | |||
|
162 | 182 | if (!axis->isVisible()) |
|
163 | 183 | continue; |
|
164 | 184 | |
|
165 |
QSizeF size = axis->effectiveSizeHint(Qt:: |
|
|
185 | QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize); | |
|
166 | 186 | |
|
167 | 187 |
switch |
|
168 | 188 |
case Qt::AlignLeft: |
|
169 |
qreal width = qMin(size.width(), |
|
|
189 | qreal width = qMin(size.width(),(left.width()/leftCount)); | |
|
170 | 190 |
leftOffset |
|
171 |
axis->setGeometry(QRect(chartRect.left() |
|
|
191 | axis->setGeometry(QRect(chartRect.left()-leftOffset, geometry.top(),width, geometry.bottom()),chartRect); | |
|
172 | 192 | break; |
|
173 | 193 | } |
|
174 | 194 |
case Qt::AlignRight: |
|
175 |
qreal width = qMin(size.width(), |
|
|
176 |
axis->setGeometry(QRect(chartRect.right() |
|
|
195 | qreal width = qMin(size.width(),(right.width()/rightCount)); | |
|
196 | axis->setGeometry(QRect(chartRect.right()+rightOffset,geometry.top(),width,geometry.bottom()),chartRect); | |
|
177 | 197 |
rightOffset |
|
178 | 198 | break; |
|
179 | 199 | } |
@@ -288,7 +308,7 QRectF ChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *t | |||
|
288 | 308 | title->setGeometry(geometry); |
|
289 | 309 | QPointF center = geometry.center() - title->boundingRect().center(); |
|
290 | 310 |
title->setPos(center.x(), |
|
291 |
return geometry.adjusted(0, |
|
|
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 = |
|
|
79 | sh = fn.boundingRect(m_text).size(); | |
|
80 | 80 | break; |
|
81 | 81 | case Qt::MaximumSize: |
|
82 |
sh = |
|
|
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