@@ -61,48 +61,48 void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayo | |||||
61 | if (state() != QAbstractAnimation::Stopped) stop(); |
|
61 | if (state() != QAbstractAnimation::Stopped) stop(); | |
62 |
|
62 | |||
63 | if (newLayout.count() == 0) |
|
63 | if (newLayout.count() == 0) | |
64 | return; |
|
64 | return; | |
65 |
|
65 | |||
66 | switch (m_type) { |
|
66 | switch (m_type) { | |
67 |
|
|
67 | case ZoomOutAnimation: { | |
68 |
|
|
68 | QRectF rect = m_axis->gridGeometry(); | |
69 |
|
|
69 | oldLayout.resize(newLayout.count()); | |
70 |
|
||||
71 | for(int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) { |
|
|||
72 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom(); |
|
|||
73 | oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top(); |
|
|||
74 | } |
|
|||
75 | } |
|
|||
76 | break; |
|
|||
77 | case ZoomInAnimation: { |
|
|||
78 | int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0); |
|
|||
79 | oldLayout.resize(newLayout.count()); |
|
|||
80 |
|
70 | |||
81 |
|
|
71 | for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) { | |
82 | oldLayout[i]= oldLayout[index]; |
|
72 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom(); | |
|
73 | oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top(); | |||
83 | } |
|
74 | } | |
84 | break; |
|
75 | } | |
85 | case MoveForwardAnimation: { |
|
76 | break; | |
86 | oldLayout.resize(newLayout.count()); |
|
77 | case ZoomInAnimation: { | |
|
78 | int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0); | |||
|
79 | oldLayout.resize(newLayout.count()); | |||
87 |
|
80 | |||
88 |
|
|
81 | for (int i = 0; i < oldLayout.count(); i++) | |
89 |
oldLayout[i]= oldLayout[ |
|
82 | oldLayout[i] = oldLayout[index]; | |
90 |
|
|
83 | } | |
91 |
|
|
84 | break; | |
92 |
|
|
85 | case MoveForwardAnimation: { | |
93 |
|
|
86 | oldLayout.resize(newLayout.count()); | |
94 |
|
87 | |||
95 |
|
|
88 | for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j) | |
96 | oldLayout[i]= oldLayout[j]; |
|
89 | oldLayout[i] = oldLayout[j]; | |
97 |
|
|
90 | } | |
98 |
|
|
91 | break; | |
99 | default: { |
|
92 | case MoveBackwordAnimation: { | |
100 |
|
|
93 | oldLayout.resize(newLayout.count()); | |
101 | QRectF rect = m_axis->gridGeometry(); |
|
94 | ||
102 |
|
|
95 | for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j) | |
|
96 | oldLayout[i] = oldLayout[j]; | |||
|
97 | } | |||
|
98 | break; | |||
|
99 | default: { | |||
|
100 | oldLayout.resize(newLayout.count()); | |||
|
101 | QRectF rect = m_axis->gridGeometry(); | |||
|
102 | for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j) | |||
103 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top(); |
|
103 | oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top(); | |
104 |
|
|
104 | } | |
105 |
|
|
105 | break; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | QVariantAnimation::KeyValues value; |
|
108 | QVariantAnimation::KeyValues value; |
@@ -128,37 +128,37 QVariant SplineAnimation::interpolated(const QVariant &start, const QVariant &en | |||||
128 | case RemovePointAnimation: |
|
128 | case RemovePointAnimation: | |
129 | case AddPointAnimation: |
|
129 | case AddPointAnimation: | |
130 | case ReplacePointAnimation: { |
|
130 | case ReplacePointAnimation: { | |
131 |
|
|
131 | if (startPair.first.count() != endPair.first.count()) | |
132 |
|
|
132 | break; | |
133 |
|
|
133 | Q_ASSERT(startPair.first.count() * 2 - 2 == startPair.second.count()); | |
134 |
|
|
134 | Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count()); | |
135 |
|
|
135 | for (int i = 0; i < endPair.first.count(); i++) { | |
136 |
|
|
136 | qreal x = startPair.first[i].x() + ((endPair.first[i].x() - startPair.first[i].x()) * progress); | |
137 |
|
|
137 | qreal y = startPair.first[i].y() + ((endPair.first[i].y() - startPair.first[i].y()) * progress); | |
138 |
|
|
138 | result.first << QPointF(x, y); | |
139 |
|
|
139 | if (i + 1 >= endPair.first.count()) | |
140 |
|
|
140 | continue; | |
141 |
|
|
141 | x = startPair.second[i * 2].x() + ((endPair.second[i * 2].x() - startPair.second[i * 2].x()) * progress); | |
142 |
|
|
142 | y = startPair.second[i * 2].y() + ((endPair.second[i * 2].y() - startPair.second[i * 2].y()) * progress); | |
143 |
|
|
143 | result.second << QPointF(x, y); | |
144 |
|
|
144 | x = startPair.second[i * 2 + 1].x() + ((endPair.second[i * 2 + 1].x() - startPair.second[i * 2 + 1].x()) * progress); | |
145 |
|
|
145 | y = startPair.second[i * 2 + 1].y() + ((endPair.second[i * 2 + 1].y() - startPair.second[i * 2 + 1].y()) * progress); | |
146 |
|
|
146 | result.second << QPointF(x, y); | |
147 | } |
|
|||
148 | } |
|
147 | } | |
149 | break; |
|
148 | } | |
|
149 | break; | |||
150 | case NewAnimation: { |
|
150 | case NewAnimation: { | |
151 |
|
|
151 | Q_ASSERT(endPair.first.count() * 2 - 2 == endPair.second.count()); | |
152 |
|
|
152 | int count = endPair.first.count() * qBound(qreal(0), progress, qreal(1)); | |
153 |
|
|
153 | for (int i = 0; i < count; i++) { | |
154 |
|
|
154 | result.first << endPair.first[i]; | |
155 |
|
|
155 | if (i + 1 == count) | |
156 |
|
|
156 | break; | |
157 |
|
|
157 | result.second << endPair.second[2 * i]; | |
158 |
|
|
158 | result.second << endPair.second[2 * i + 1]; | |
159 | } |
|
|||
160 | } |
|
159 | } | |
161 | break; |
|
160 | } | |
|
161 | break; | |||
162 | default: |
|
162 | default: | |
163 | qWarning() << "Unknown type of animation"; |
|
163 | qWarning() << "Unknown type of animation"; | |
164 | break; |
|
164 | break; |
@@ -27,8 +27,9 | |||||
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 |
ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis,ChartPresenter *presenter) |
|
30 | ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis, ChartPresenter *presenter) | |
31 | m_categoriesAxis(axis) |
|
31 | : HorizontalAxis(axis, presenter, true), | |
|
32 | m_categoriesAxis(axis) | |||
32 | { |
|
33 | { | |
33 |
|
34 | |||
34 | } |
|
35 | } | |
@@ -41,28 +42,27 QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const | |||||
41 | { |
|
42 | { | |
42 | int count = m_categoriesAxis->d_ptr->count(); |
|
43 | int count = m_categoriesAxis->d_ptr->count(); | |
43 |
|
44 | |||
44 | Q_ASSERT(count>=1); |
|
45 | Q_ASSERT(count >= 1); | |
45 |
|
46 | |||
46 | QVector<qreal> points; |
|
47 | QVector<qreal> points; | |
47 | points.resize(count+2); |
|
48 | points.resize(count + 2); | |
48 |
|
49 | |||
49 |
const QRectF& |
|
50 | const QRectF &gridRect = gridGeometry(); | |
50 |
|
51 | |||
51 | const qreal delta = gridRect.width()/(count); |
|
52 | const qreal delta = gridRect.width() / (count); | |
52 | qreal offset =-min()-0.5; |
|
53 | qreal offset = -min() - 0.5; | |
53 |
|
54 | |||
54 |
if(delta<1) |
|
55 | if (delta < 1) | |
|
56 | return points; | |||
55 |
|
57 | |||
56 |
if(offset<0) |
|
58 | if (offset < 0) | |
57 | offset = int(offset * gridRect.width()/(max() - min()))%int(delta) + delta; |
|
59 | offset = int(offset * gridRect.width() / (max() - min())) % int(delta) + delta; | |
58 |
|
|
60 | else | |
59 | else { |
|
61 | offset = int(offset * gridRect.width() / (max() - min())) % int(delta); | |
60 | offset = int(offset * gridRect.width()/(max() - min()))%int(delta); |
|
|||
61 | } |
|
|||
62 |
|
62 | |||
63 | for (int i = -1; i < count+1; ++i) { |
|
63 | for (int i = -1; i < count + 1; ++i) { | |
64 | qreal x = offset + i * delta + gridRect.left(); |
|
64 | qreal x = offset + i * delta + gridRect.left(); | |
65 | points[i+1] = x; |
|
65 | points[i + 1] = x; | |
66 | } |
|
66 | } | |
67 | return points; |
|
67 | return points; | |
68 | } |
|
68 | } | |
@@ -70,15 +70,14 QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const | |||||
70 | QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& layout) const |
|
70 | QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& layout) const | |
71 | { |
|
71 | { | |
72 | QStringList result ; |
|
72 | QStringList result ; | |
73 |
const QRectF& |
|
73 | const QRectF &gridRect = gridGeometry(); | |
74 |
|
74 | |||
75 | qreal d = (max() - min())/gridRect.width(); |
|
75 | qreal d = (max() - min()) / gridRect.width(); | |
76 | for (int i = 0;i < layout.count()-1; ++i) { |
|
76 | for (int i = 0; i < layout.count() - 1; ++i) { | |
77 | qreal x = qFloor((((layout[i] + layout[i+1])/2-gridRect.left())*d + min()+0.5)); |
|
77 | qreal x = qFloor((((layout[i] + layout[i + 1]) / 2 - gridRect.left()) * d + min() + 0.5)); | |
78 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { |
|
78 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { | |
79 | result << m_categoriesAxis->categories().at(x); |
|
79 | result << m_categoriesAxis->categories().at(x); | |
80 | } |
|
80 | } else { | |
81 | else { |
|
|||
82 | // No label for x coordinate |
|
81 | // No label for x coordinate | |
83 | result << ""; |
|
82 | result << ""; | |
84 | } |
|
83 | } | |
@@ -91,22 +90,23 QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& la | |||||
91 | void ChartBarCategoryAxisX::updateGeometry() |
|
90 | void ChartBarCategoryAxisX::updateGeometry() | |
92 | { |
|
91 | { | |
93 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
92 | const QVector<qreal>& layout = ChartAxis::layout(); | |
94 |
if(layout.isEmpty()) |
|
93 | if (layout.isEmpty()) | |
|
94 | return; | |||
95 | setLabels(createCategoryLabels(layout)); |
|
95 | setLabels(createCategoryLabels(layout)); | |
96 | HorizontalAxis::updateGeometry(); |
|
96 | HorizontalAxis::updateGeometry(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void ChartBarCategoryAxisX::handleAxisUpdated() |
|
99 | void ChartBarCategoryAxisX::handleAxisUpdated() | |
100 | { |
|
100 | { | |
101 | if(m_categoriesAxis->categories()!=m_categories) |
|
101 | if (m_categoriesAxis->categories() != m_categories) { | |
102 | { |
|
102 | m_categories = m_categoriesAxis->categories(); | |
103 | m_categories=m_categoriesAxis->categories(); |
|
103 | if (ChartAxis::layout().count() == m_categoriesAxis->d_ptr->count() + 2) | |
104 | if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) updateGeometry(); |
|
104 | updateGeometry(); | |
105 | } |
|
105 | } | |
106 | ChartAxis::handleAxisUpdated(); |
|
106 | ChartAxis::handleAxisUpdated(); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 |
QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF& |
|
109 | QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
110 | { |
|
110 | { | |
111 | Q_UNUSED(constraint) |
|
111 | Q_UNUSED(constraint) | |
112 |
|
112 | |||
@@ -114,35 +114,34 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constra | |||||
114 | QSizeF sh; |
|
114 | QSizeF sh; | |
115 | QSizeF base = ChartAxis::sizeHint(which, constraint); |
|
115 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |
116 | QStringList ticksList = createCategoryLabels(ChartAxis::layout()); |
|
116 | QStringList ticksList = createCategoryLabels(ChartAxis::layout()); | |
117 | qreal width=0; |
|
117 | qreal width = 0; | |
118 | qreal height=0; |
|
118 | qreal height = 0; | |
119 |
|
119 | |||
120 |
|
|
120 | switch (which) { | |
121 |
|
|
121 | case Qt::MinimumSize: | |
122 |
|
|
122 | width = fn.boundingRect("...").width(); | |
123 |
|
|
123 | height = fn.height() + labelPadding(); | |
124 |
|
|
124 | width = qMax(width, base.width()); | |
125 |
|
|
125 | height += base.height(); | |
126 |
|
|
126 | sh = QSizeF(width, height); | |
127 |
|
|
127 | break; | |
128 |
|
|
128 | case Qt::PreferredSize: { | |
129 |
|
129 | |||
130 |
|
|
130 | for (int i = 0; i < ticksList.size(); ++i) { | |
131 | { |
|
131 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |
132 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
132 | width += rect.width(); | |
133 | width+=rect.width(); |
|
133 | height = qMax(rect.height() + labelPadding(), height); | |
134 | height=qMax(rect.height()+labelPadding(),height); |
|
|||
135 | } |
|
|||
136 | width=qMax(width,base.width()); |
|
|||
137 | height+=base.height(); |
|
|||
138 | sh = QSizeF(width,height); |
|
|||
139 | break; |
|
|||
140 | } |
|
134 | } | |
141 | default: |
|
135 | width = qMax(width, base.width()); | |
142 | break; |
|
136 | height += base.height(); | |
143 | } |
|
137 | sh = QSizeF(width, height); | |
|
138 | break; | |||
|
139 | } | |||
|
140 | default: | |||
|
141 | break; | |||
|
142 | } | |||
144 |
|
143 | |||
145 |
|
|
144 | return sh; | |
146 | } |
|
145 | } | |
147 |
|
146 | |||
148 | QTCOMMERCIALCHART_END_NAMESPACE |
|
147 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -26,8 +26,9 | |||||
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 |
ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis,ChartPresenter *presenter) |
|
29 | ChartBarCategoryAxisY::ChartBarCategoryAxisY(QBarCategoryAxis *axis, ChartPresenter *presenter) | |
30 | m_categoriesAxis(axis) |
|
30 | : VerticalAxis(axis, presenter, true), | |
|
31 | m_categoriesAxis(axis) | |||
31 | { |
|
32 | { | |
32 | } |
|
33 | } | |
33 |
|
34 | |||
@@ -39,28 +40,27 QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const | |||||
39 | { |
|
40 | { | |
40 | int count = m_categoriesAxis->d_ptr->count(); |
|
41 | int count = m_categoriesAxis->d_ptr->count(); | |
41 |
|
42 | |||
42 | Q_ASSERT(count>=1); |
|
43 | Q_ASSERT(count >= 1); | |
43 |
|
44 | |||
44 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
45 | points.resize(count+2); |
|
46 | points.resize(count + 2); | |
46 |
|
47 | |||
47 |
const QRectF& |
|
48 | const QRectF &gridRect = gridGeometry(); | |
48 |
|
49 | |||
49 | const qreal delta = gridRect.height()/(count); |
|
50 | const qreal delta = gridRect.height() / (count); | |
50 | qreal offset = - min() - 0.5; |
|
51 | qreal offset = - min() - 0.5; | |
51 |
|
52 | |||
52 |
if(delta<1) |
|
53 | if (delta < 1) | |
|
54 | return points; | |||
53 |
|
55 | |||
54 |
if(offset<0) |
|
56 | if (offset < 0) | |
55 | offset = int(offset * gridRect.height()/(max() - min()))%int(delta) + delta; |
|
57 | offset = int(offset * gridRect.height() / (max() - min())) % int(delta) + delta; | |
56 |
|
|
58 | else | |
57 | else { |
|
59 | offset = int(offset * gridRect.height() / (max() - min())) % int(delta); | |
58 | offset = int(offset * gridRect.height()/(max() - min()))%int(delta); |
|
|||
59 | } |
|
|||
60 |
|
60 | |||
61 | for (int i = -1; i < count +1; ++i) { |
|
61 | for (int i = -1; i < count + 1; ++i) { | |
62 | int y = gridRect.bottom() - i * delta - offset; |
|
62 | int y = gridRect.bottom() - i * delta - offset; | |
63 | points[i+1] = y; |
|
63 | points[i + 1] = y; | |
64 | } |
|
64 | } | |
65 | return points; |
|
65 | return points; | |
66 | } |
|
66 | } | |
@@ -68,14 +68,13 QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const | |||||
68 | QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& layout) const |
|
68 | QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& layout) const | |
69 | { |
|
69 | { | |
70 | QStringList result; |
|
70 | QStringList result; | |
71 |
const QRectF& |
|
71 | const QRectF &gridRect = gridGeometry(); | |
72 | qreal d = (max() - min())/gridRect.height(); |
|
72 | qreal d = (max() - min()) / gridRect.height(); | |
73 | for (int i = 0;i < layout.count()-1; ++i) { |
|
73 | for (int i = 0; i < layout.count() - 1; ++i) { | |
74 | qreal x = qFloor(((gridRect.height()- (layout[i+1] + layout[i])/2 + gridRect.top())*d + min()+0.5)); |
|
74 | qreal x = qFloor(((gridRect.height() - (layout[i + 1] + layout[i]) / 2 + gridRect.top()) * d + min() + 0.5)); | |
75 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { |
|
75 | if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) { | |
76 | result << m_categoriesAxis->categories().at(x); |
|
76 | result << m_categoriesAxis->categories().at(x); | |
77 | } |
|
77 | } else { | |
78 | else { |
|
|||
79 | // No label for x coordinate |
|
78 | // No label for x coordinate | |
80 | result << ""; |
|
79 | result << ""; | |
81 | } |
|
80 | } | |
@@ -87,7 +86,8 QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& la | |||||
87 | void ChartBarCategoryAxisY::updateGeometry() |
|
86 | void ChartBarCategoryAxisY::updateGeometry() | |
88 | { |
|
87 | { | |
89 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
88 | const QVector<qreal>& layout = ChartAxis::layout(); | |
90 |
if(layout.isEmpty()) |
|
89 | if (layout.isEmpty()) | |
|
90 | return; | |||
91 | setLabels(createCategoryLabels(layout)); |
|
91 | setLabels(createCategoryLabels(layout)); | |
92 | VerticalAxis::updateGeometry(); |
|
92 | VerticalAxis::updateGeometry(); | |
93 | } |
|
93 | } | |
@@ -95,17 +95,15 void ChartBarCategoryAxisY::updateGeometry() | |||||
95 | void ChartBarCategoryAxisY::handleAxisUpdated() |
|
95 | void ChartBarCategoryAxisY::handleAxisUpdated() | |
96 | { |
|
96 | { | |
97 |
|
97 | |||
98 | if(m_categoriesAxis->categories()!=m_categories) |
|
98 | if (m_categoriesAxis->categories() != m_categories) { | |
99 | { |
|
99 | m_categories = m_categoriesAxis->categories(); | |
100 | m_categories=m_categoriesAxis->categories(); |
|
100 | if (ChartAxis::layout().count() == m_categoriesAxis->d_ptr->count() + 2) | |
101 | if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) { |
|
|||
102 | updateGeometry(); |
|
101 | updateGeometry(); | |
103 | } |
|
|||
104 | } |
|
102 | } | |
105 | ChartAxis::handleAxisUpdated(); |
|
103 | ChartAxis::handleAxisUpdated(); | |
106 | } |
|
104 | } | |
107 |
|
105 | |||
108 |
QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF& |
|
106 | QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
109 | { |
|
107 | { | |
110 | Q_UNUSED(constraint) |
|
108 | Q_UNUSED(constraint) | |
111 |
|
109 | |||
@@ -113,35 +111,34 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constra | |||||
113 | QSizeF sh; |
|
111 | QSizeF sh; | |
114 | QSizeF base = ChartAxis::sizeHint(which, constraint); |
|
112 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |
115 | QStringList ticksList = createCategoryLabels(ChartAxis::layout()); |
|
113 | QStringList ticksList = createCategoryLabels(ChartAxis::layout()); | |
116 | qreal width=0; |
|
114 | qreal width = 0; | |
117 | qreal height=0; |
|
115 | qreal height = 0; | |
118 |
|
116 | |||
119 |
|
|
117 | switch (which) { | |
120 |
|
|
118 | case Qt::MinimumSize: | |
121 |
|
|
119 | width = fn.boundingRect("...").width() + labelPadding(); | |
122 |
|
|
120 | height = fn.height(); | |
123 |
|
|
121 | width += base.width(); | |
124 |
|
|
122 | height = qMax(height, base.height()); | |
125 |
|
|
123 | sh = QSizeF(width, height); | |
126 |
|
|
124 | break; | |
127 |
|
|
125 | case Qt::PreferredSize: { | |
128 |
|
126 | |||
129 |
|
|
127 | for (int i = 0; i < ticksList.size(); ++i) { | |
130 | { |
|
128 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |
131 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
129 | height += rect.height(); | |
132 | height+=rect.height(); |
|
130 | width = qMax(rect.width() + labelPadding(), width); | |
133 | width=qMax(rect.width()+labelPadding(),width); |
|
|||
134 | } |
|
|||
135 | height=qMax(height,base.height()); |
|
|||
136 | width+=base.width(); |
|
|||
137 | sh = QSizeF(width,height); |
|
|||
138 | break; |
|
|||
139 | } |
|
131 | } | |
140 | default: |
|
132 | height = qMax(height, base.height()); | |
141 | break; |
|
133 | width += base.width(); | |
142 | } |
|
134 | sh = QSizeF(width, height); | |
|
135 | break; | |||
|
136 | } | |||
|
137 | default: | |||
|
138 | break; | |||
|
139 | } | |||
143 |
|
140 | |||
144 |
|
|
141 | return sh; | |
145 | } |
|
142 | } | |
146 |
|
143 | |||
147 | QTCOMMERCIALCHART_END_NAMESPACE |
|
144 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -163,26 +163,25 QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent) | |||||
163 | void QBarCategoryAxis::append(const QStringList &categories) |
|
163 | void QBarCategoryAxis::append(const QStringList &categories) | |
164 | { |
|
164 | { | |
165 | if (categories.isEmpty()) |
|
165 | if (categories.isEmpty()) | |
166 | return; |
|
166 | return; | |
167 |
|
167 | |||
168 | Q_D(QBarCategoryAxis); |
|
168 | Q_D(QBarCategoryAxis); | |
169 |
|
169 | |||
170 | int count = d->m_categories.count(); |
|
170 | int count = d->m_categories.count(); | |
171 |
|
171 | |||
172 | foreach(QString category, categories) |
|
172 | foreach(QString category, categories) { | |
173 | { |
|
173 | if (!d->m_categories.contains(category) && !category.isNull()) { | |
174 | if(!d->m_categories.contains(category) && !category.isNull()) { |
|
|||
175 | d->m_categories.append(category); |
|
174 | d->m_categories.append(category); | |
176 | } |
|
175 | } | |
177 | } |
|
176 | } | |
178 |
|
177 | |||
179 |
if(d->m_categories.count() == count) |
|
178 | if (d->m_categories.count() == count) | |
|
179 | return; | |||
180 |
|
180 | |||
181 |
if (count == 0) |
|
181 | if (count == 0) | |
182 | setRange(d->m_categories.first(), d->m_categories.last()); |
|
182 | setRange(d->m_categories.first(), d->m_categories.last()); | |
183 |
|
|
183 | else | |
184 | setRange(d->m_minCategory, d->m_categories.last()); |
|
184 | setRange(d->m_minCategory, d->m_categories.last()); | |
185 | } |
|
|||
186 |
|
185 | |||
187 | emit categoriesChanged(); |
|
186 | emit categoriesChanged(); | |
188 | } |
|
187 | } | |
@@ -198,17 +197,16 void QBarCategoryAxis::append(const QString &category) | |||||
198 |
|
197 | |||
199 | int count = d->m_categories.count(); |
|
198 | int count = d->m_categories.count(); | |
200 |
|
199 | |||
201 |
if(!d->m_categories.contains(category) && !category.isNull()) |
|
200 | if (!d->m_categories.contains(category) && !category.isNull()) | |
202 | d->m_categories.append(category); |
|
201 | d->m_categories.append(category); | |
203 | } |
|
|||
204 |
|
202 | |||
205 |
if(d->m_categories.count() == count) |
|
203 | if (d->m_categories.count() == count) | |
|
204 | return; | |||
206 |
|
205 | |||
207 |
if (count == 0) |
|
206 | if (count == 0) | |
208 | setRange(d->m_categories.last(), d->m_categories.last()); |
|
207 | setRange(d->m_categories.last(), d->m_categories.last()); | |
209 |
|
|
208 | else | |
210 | setRange(d->m_minCategory, d->m_categories.last()); |
|
209 | setRange(d->m_minCategory, d->m_categories.last()); | |
211 | } |
|
|||
212 |
|
210 | |||
213 | emit categoriesChanged(); |
|
211 | emit categoriesChanged(); | |
214 | } |
|
212 | } | |
@@ -223,17 +221,18 void QBarCategoryAxis::remove(const QString &category) | |||||
223 |
|
221 | |||
224 | if (d->m_categories.contains(category)) { |
|
222 | if (d->m_categories.contains(category)) { | |
225 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
223 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
226 | if (!d->m_categories.isEmpty()){ |
|
224 | if (!d->m_categories.isEmpty()) { | |
227 | if(d->m_minCategory == category){ |
|
225 | if (d->m_minCategory == category) { | |
228 | setRange(d->m_categories.first(), d->m_maxCategory); |
|
226 | setRange(d->m_categories.first(), d->m_maxCategory); | |
229 | } else if(d->m_maxCategory == category){ |
|
227 | } else if (d->m_maxCategory == category) { | |
230 | setRange(d->m_minCategory, d->m_categories.last()); |
|
228 | setRange(d->m_minCategory, d->m_categories.last()); | |
231 | } else { |
|
229 | } else { | |
232 | d->updateCategoryDomain(); |
|
230 | d->updateCategoryDomain(); | |
233 | d->emitUpdated(); |
|
231 | d->emitUpdated(); | |
234 | } |
|
232 | } | |
235 | }else |
|
233 | } else { | |
236 | setRange(QString::null, QString::null); |
|
234 | setRange(QString::null, QString::null); | |
|
235 | } | |||
237 | emit categoriesChanged(); |
|
236 | emit categoriesChanged(); | |
238 | } |
|
237 | } | |
239 | } |
|
238 | } | |
@@ -248,17 +247,17 void QBarCategoryAxis::insert(int index, const QString &category) | |||||
248 |
|
247 | |||
249 | int count = d->m_categories.count(); |
|
248 | int count = d->m_categories.count(); | |
250 |
|
249 | |||
251 |
if(!d->m_categories.contains(category) && !category.isNull()) |
|
250 | if (!d->m_categories.contains(category) && !category.isNull()) | |
252 | d->m_categories.insert(index, category); |
|
251 | d->m_categories.insert(index, category); | |
253 | } |
|
|||
254 |
|
252 | |||
255 |
if(d->m_categories.count() == count) |
|
253 | if (d->m_categories.count() == count) | |
|
254 | return; | |||
256 |
|
255 | |||
257 | if (count == 0) { |
|
256 | if (count == 0) { | |
258 | setRange(d->m_categories.first(), d->m_categories.first()); |
|
257 | setRange(d->m_categories.first(), d->m_categories.first()); | |
259 | } else if (index == 0) { |
|
258 | } else if (index == 0) { | |
260 | setRange(d->m_categories.first(), d->m_maxCategory); |
|
259 | setRange(d->m_categories.first(), d->m_maxCategory); | |
261 | } else if (index == count){ |
|
260 | } else if (index == count) { | |
262 | setRange(d->m_minCategory, d->m_categories.last()); |
|
261 | setRange(d->m_minCategory, d->m_categories.last()); | |
263 | } else { |
|
262 | } else { | |
264 | d->updateCategoryDomain(); |
|
263 | d->updateCategoryDomain(); | |
@@ -281,9 +280,9 void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCat | |||||
281 |
|
280 | |||
282 | if (pos != -1 && !d->m_categories.contains(newCategory) && !newCategory.isNull()) { |
|
281 | if (pos != -1 && !d->m_categories.contains(newCategory) && !newCategory.isNull()) { | |
283 | d->m_categories.replace(pos, newCategory); |
|
282 | d->m_categories.replace(pos, newCategory); | |
284 | if(d->m_minCategory == oldCategory) { |
|
283 | if (d->m_minCategory == oldCategory) { | |
285 | setRange(newCategory, d->m_maxCategory); |
|
284 | setRange(newCategory, d->m_maxCategory); | |
286 | } else if(d->m_maxCategory == oldCategory) { |
|
285 | } else if (d->m_maxCategory == oldCategory) { | |
287 | setRange(d->m_minCategory, newCategory); |
|
286 | setRange(d->m_minCategory, newCategory); | |
288 | } else { |
|
287 | } else { | |
289 | d->emitUpdated(); |
|
288 | d->emitUpdated(); | |
@@ -299,7 +298,7 void QBarCategoryAxis::clear() | |||||
299 | { |
|
298 | { | |
300 | Q_D(QBarCategoryAxis); |
|
299 | Q_D(QBarCategoryAxis); | |
301 | d->m_categories.clear(); |
|
300 | d->m_categories.clear(); | |
302 |
|
|
301 | setRange(QString::null, QString::null); | |
303 | emit categoriesChanged(); |
|
302 | emit categoriesChanged(); | |
304 | } |
|
303 | } | |
305 |
|
304 | |||
@@ -404,9 +403,9 void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCa | |||||
404 | d->emitUpdated(); |
|
403 | d->emitUpdated(); | |
405 | } |
|
404 | } | |
406 |
|
405 | |||
407 |
if (d->m_categories.indexOf(maxCategory) < d->m_categories.indexOf(minCategory)) |
|
406 | if (d->m_categories.indexOf(maxCategory) < d->m_categories.indexOf(minCategory)) | |
408 | return; |
|
407 | return; | |
409 | } |
|
408 | ||
410 | if (!minCategory.isEmpty() && d->m_minCategory != minCategory && d->m_categories.contains(minCategory)) { |
|
409 | if (!minCategory.isEmpty() && d->m_minCategory != minCategory && d->m_categories.contains(minCategory)) { | |
411 | d->m_minCategory = minCategory; |
|
410 | d->m_minCategory = minCategory; | |
412 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; |
|
411 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; |
@@ -28,8 +28,9 | |||||
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 |
ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis,ChartPresenter *presenter) |
|
31 | ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, ChartPresenter *presenter) | |
32 | m_axis(axis) |
|
32 | : HorizontalAxis(axis, presenter, true), | |
|
33 | m_axis(axis) | |||
33 | { |
|
34 | { | |
34 | } |
|
35 | } | |
35 |
|
36 | |||
@@ -45,12 +46,12 QVector<qreal> ChartCategoryAxisX::calculateLayout() const | |||||
45 | if (tickCount < 2) |
|
46 | if (tickCount < 2) | |
46 | return points; |
|
47 | return points; | |
47 |
|
48 | |||
48 |
const QRectF& |
|
49 | const QRectF &gridRect = gridGeometry(); | |
49 | qreal range = m_axis->max() - m_axis->min(); |
|
50 | qreal range = m_axis->max() - m_axis->min(); | |
50 | if (range > 0) { |
|
51 | if (range > 0) { | |
51 | points.resize(tickCount); |
|
52 | points.resize(tickCount); | |
52 | qreal scale = gridRect.width() / range; |
|
53 | qreal scale = gridRect.width() / range; | |
53 | for (int i = 0; i < tickCount; ++i) |
|
54 | for (int i = 0; i < tickCount; ++i) { | |
54 | if (i < tickCount - 1) { |
|
55 | if (i < tickCount - 1) { | |
55 | int x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - m_axis->min()) * scale + gridRect.left(); |
|
56 | int x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - m_axis->min()) * scale + gridRect.left(); | |
56 | points[i] = x; |
|
57 | points[i] = x; | |
@@ -58,6 +59,7 QVector<qreal> ChartCategoryAxisX::calculateLayout() const | |||||
58 | int x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - m_axis->min()) * scale + gridRect.left(); |
|
59 | int x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - m_axis->min()) * scale + gridRect.left(); | |
59 | points[i] = x; |
|
60 | points[i] = x; | |
60 | } |
|
61 | } | |
|
62 | } | |||
61 | } |
|
63 | } | |
62 |
|
64 | |||
63 | return points; |
|
65 | return points; | |
@@ -65,7 +67,7 QVector<qreal> ChartCategoryAxisX::calculateLayout() const | |||||
65 |
|
67 | |||
66 | void ChartCategoryAxisX::updateGeometry() |
|
68 | void ChartCategoryAxisX::updateGeometry() | |
67 | { |
|
69 | { | |
68 | setLabels(m_axis->categoriesLabels()<<""); |
|
70 | setLabels(m_axis->categoriesLabels() << ""); | |
69 | HorizontalAxis::updateGeometry(); |
|
71 | HorizontalAxis::updateGeometry(); | |
70 | } |
|
72 | } | |
71 |
|
73 | |||
@@ -75,7 +77,7 void ChartCategoryAxisX::handleAxisUpdated() | |||||
75 | ChartAxis::handleAxisUpdated(); |
|
77 | ChartAxis::handleAxisUpdated(); | |
76 | } |
|
78 | } | |
77 |
|
79 | |||
78 |
QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF& |
|
80 | QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
79 | { |
|
81 | { | |
80 | Q_UNUSED(constraint) |
|
82 | Q_UNUSED(constraint) | |
81 |
|
83 | |||
@@ -83,31 +85,30 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constraint | |||||
83 | QSizeF sh; |
|
85 | QSizeF sh; | |
84 | QSizeF base = ChartAxis::sizeHint(which, constraint); |
|
86 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |
85 | QStringList ticksList ; //TODO: |
|
87 | QStringList ticksList ; //TODO: | |
86 | qreal width=0; |
|
88 | qreal width = 0; | |
87 | qreal height=0; |
|
89 | qreal height = 0; | |
88 |
|
90 | |||
89 | switch (which) { |
|
91 | switch (which) { | |
90 |
|
|
92 | case Qt::MinimumSize: | |
91 | width = fn.boundingRect("...").width(); |
|
93 | width = fn.boundingRect("...").width(); | |
92 | height = fn.height() + labelPadding(); |
|
94 | height = fn.height() + labelPadding(); | |
93 | width=qMax(width,base.width()); |
|
95 | width = qMax(width, base.width()); | |
94 | height+=base.height(); |
|
96 | height += base.height(); | |
95 | sh = QSizeF(width,height); |
|
97 | sh = QSizeF(width, height); | |
96 | break; |
|
98 | break; | |
97 |
|
|
99 | case Qt::PreferredSize: { | |
98 |
|
100 | |||
99 |
|
|
101 | for (int i = 0; i < ticksList.size(); ++i) { | |
100 | { |
|
102 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |
101 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
103 | width += rect.width(); | |
102 | width+=rect.width(); |
|
104 | height = qMax(rect.height() + labelPadding(), height); | |
103 | height=qMax(rect.height()+labelPadding(),height); |
|
|||
104 | } |
|
|||
105 | width=qMax(width,base.width()); |
|
|||
106 | height+=base.height(); |
|
|||
107 | sh = QSizeF(width,height); |
|
|||
108 | break; |
|
|||
109 | } |
|
105 | } | |
110 | default: |
|
106 | width = qMax(width, base.width()); | |
|
107 | height += base.height(); | |||
|
108 | sh = QSizeF(width, height); | |||
|
109 | break; | |||
|
110 | } | |||
|
111 | default: | |||
111 | break; |
|
112 | break; | |
112 | } |
|
113 | } | |
113 |
|
114 |
@@ -44,11 +44,14 public: | |||||
44 | ~ChartCategoryAxisX(); |
|
44 | ~ChartCategoryAxisX(); | |
45 |
|
45 | |||
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; | |
|
47 | ||||
47 | protected: |
|
48 | protected: | |
48 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
49 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
50 | Q_SLOTS |
|
51 | ||
|
52 | public Q_SLOTS: | |||
51 | void handleAxisUpdated(); |
|
53 | void handleAxisUpdated(); | |
|
54 | ||||
52 | private: |
|
55 | private: | |
53 | QCategoryAxis *m_axis; |
|
56 | QCategoryAxis *m_axis; | |
54 | }; |
|
57 | }; |
@@ -28,8 +28,9 | |||||
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 |
ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis,ChartPresenter *presenter) |
|
31 | ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis, ChartPresenter *presenter) | |
32 | m_axis(axis) |
|
32 | : VerticalAxis(axis, presenter, true), | |
|
33 | m_axis(axis) | |||
33 | { |
|
34 | { | |
34 | } |
|
35 | } | |
35 |
|
36 | |||
@@ -45,12 +46,12 QVector<qreal> ChartCategoryAxisY::calculateLayout() const | |||||
45 | if (tickCount < 2) |
|
46 | if (tickCount < 2) | |
46 | return points; |
|
47 | return points; | |
47 |
|
48 | |||
48 |
const QRectF& |
|
49 | const QRectF &gridRect = gridGeometry(); | |
49 | qreal range = m_axis->max() - m_axis->min(); |
|
50 | qreal range = m_axis->max() - m_axis->min(); | |
50 | if (range > 0) { |
|
51 | if (range > 0) { | |
51 | points.resize(tickCount); |
|
52 | points.resize(tickCount); | |
52 | qreal scale = gridRect.height() / range; |
|
53 | qreal scale = gridRect.height() / range; | |
53 | for (int i = 0; i < tickCount; ++i) |
|
54 | for (int i = 0; i < tickCount; ++i) { | |
54 | if (i < tickCount - 1) { |
|
55 | if (i < tickCount - 1) { | |
55 | int y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - m_axis->min()) * scale + gridRect.bottom(); |
|
56 | int y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - m_axis->min()) * scale + gridRect.bottom(); | |
56 | points[i] = y; |
|
57 | points[i] = y; | |
@@ -58,6 +59,7 QVector<qreal> ChartCategoryAxisY::calculateLayout() const | |||||
58 | int y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - m_axis->min()) * scale + gridRect.bottom(); |
|
59 | int y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - m_axis->min()) * scale + gridRect.bottom(); | |
59 | points[i] = y; |
|
60 | points[i] = y; | |
60 | } |
|
61 | } | |
|
62 | } | |||
61 | } |
|
63 | } | |
62 |
|
64 | |||
63 | return points; |
|
65 | return points; | |
@@ -65,7 +67,7 QVector<qreal> ChartCategoryAxisY::calculateLayout() const | |||||
65 |
|
67 | |||
66 | void ChartCategoryAxisY::updateGeometry() |
|
68 | void ChartCategoryAxisY::updateGeometry() | |
67 | { |
|
69 | { | |
68 | setLabels(m_axis->categoriesLabels()<<""); |
|
70 | setLabels(m_axis->categoriesLabels() << ""); | |
69 | VerticalAxis::updateGeometry(); |
|
71 | VerticalAxis::updateGeometry(); | |
70 | } |
|
72 | } | |
71 |
|
73 | |||
@@ -75,7 +77,7 void ChartCategoryAxisY::handleAxisUpdated() | |||||
75 | ChartAxis::handleAxisUpdated(); |
|
77 | ChartAxis::handleAxisUpdated(); | |
76 | } |
|
78 | } | |
77 |
|
79 | |||
78 |
QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF& |
|
80 | QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
79 | { |
|
81 | { | |
80 | Q_UNUSED(constraint) |
|
82 | Q_UNUSED(constraint) | |
81 |
|
83 | |||
@@ -83,35 +85,34 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constraint | |||||
83 | QSizeF sh; |
|
85 | QSizeF sh; | |
84 | QSizeF base = ChartAxis::sizeHint(which, constraint); |
|
86 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |
85 | QStringList ticksList; //TODO:: |
|
87 | QStringList ticksList; //TODO:: | |
86 | qreal width=0; |
|
88 | qreal width = 0; | |
87 | qreal height=0; |
|
89 | qreal height = 0; | |
88 |
|
90 | |||
89 |
|
|
91 | switch (which) { | |
90 |
|
|
92 | case Qt::MinimumSize: | |
91 |
|
|
93 | width = fn.boundingRect("...").width() + labelPadding(); | |
92 |
|
|
94 | height = fn.height(); | |
93 |
|
|
95 | width = qMax(width, base.width()); | |
94 |
|
|
96 | height += base.height(); | |
95 |
|
|
97 | sh = QSizeF(width, height); | |
96 |
|
|
98 | break; | |
97 |
|
|
99 | case Qt::PreferredSize: { | |
98 |
|
100 | |||
99 |
|
|
101 | for (int i = 0; i < ticksList.size(); ++i) { | |
100 | { |
|
102 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |
101 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
103 | height += rect.height(); | |
102 | height+=rect.height(); |
|
104 | width = qMax(rect.width() + labelPadding(), width); | |
103 | width=qMax(rect.width()+labelPadding(),width); |
|
|||
104 | } |
|
|||
105 | height=qMax(height,base.height()); |
|
|||
106 | width+=base.width(); |
|
|||
107 | sh = QSizeF(width,height); |
|
|||
108 | break; |
|
|||
109 | } |
|
105 | } | |
110 | default: |
|
106 | height = qMax(height, base.height()); | |
111 | break; |
|
107 | width += base.width(); | |
112 | } |
|
108 | sh = QSizeF(width, height); | |
|
109 | break; | |||
|
110 | } | |||
|
111 | default: | |||
|
112 | break; | |||
|
113 | } | |||
113 |
|
114 | |||
114 |
|
|
115 | return sh; | |
115 | } |
|
116 | } | |
116 |
|
117 | |||
117 | QTCOMMERCIALCHART_END_NAMESPACE |
|
118 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -44,11 +44,14 public: | |||||
44 | ~ChartCategoryAxisY(); |
|
44 | ~ChartCategoryAxisY(); | |
45 |
|
45 | |||
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
46 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; | |
|
47 | ||||
47 | protected: |
|
48 | protected: | |
48 | QVector<qreal> calculateLayout() const; |
|
49 | QVector<qreal> calculateLayout() const; | |
49 | void updateGeometry(); |
|
50 | void updateGeometry(); | |
50 | Q_SLOTS |
|
51 | ||
|
52 | public Q_SLOTS: | |||
51 | void handleAxisUpdated(); |
|
53 | void handleAxisUpdated(); | |
|
54 | ||||
52 | private: |
|
55 | private: | |
53 | QCategoryAxis *m_axis; |
|
56 | QCategoryAxis *m_axis; | |
54 | }; |
|
57 | }; |
@@ -32,19 +32,20 | |||||
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 |
ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter, bool intervalAxis) |
|
35 | ChartAxis::ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis) | |
36 | m_chartAxis(axis), |
|
36 | : ChartElement(presenter), | |
37 | m_labelsAngle(0), |
|
37 | m_chartAxis(axis), | |
38 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), |
|
38 | m_labelsAngle(0), | |
39 |
|
|
39 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), | |
40 |
|
|
40 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), | |
41 |
|
|
41 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), | |
42 |
|
|
42 | m_arrow(new QGraphicsItemGroup(presenter->rootItem())), | |
43 | m_min(0), |
|
43 | m_title(new QGraphicsSimpleTextItem(presenter->rootItem())), | |
44 |
|
|
44 | m_min(0), | |
45 |
|
|
45 | m_max(0), | |
46 |
|
|
46 | m_animation(0), | |
47 | m_intervalAxis(intervalAxis) |
|
47 | m_labelPadding(5), | |
|
48 | m_intervalAxis(intervalAxis) | |||
48 | { |
|
49 | { | |
49 | //initial initialization |
|
50 | //initial initialization | |
50 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
51 | m_arrow->setZValue(ChartPresenter::AxisZValue); | |
@@ -53,7 +54,7 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter, bool interva | |||||
53 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
54 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
54 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
55 | m_grid->setZValue(ChartPresenter::GridZValue); | |
55 |
|
56 | |||
56 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
57 | QObject::connect(m_chartAxis->d_ptr.data(), SIGNAL(updated()), this, SLOT(handleAxisUpdated())); | |
57 |
|
58 | |||
58 | QGraphicsSimpleTextItem item; |
|
59 | QGraphicsSimpleTextItem item; | |
59 | m_font = item.font(); |
|
60 | m_font = item.font(); | |
@@ -64,29 +65,31 ChartAxis::~ChartAxis() | |||||
64 | { |
|
65 | { | |
65 | } |
|
66 | } | |
66 |
|
67 | |||
67 |
void ChartAxis::setAnimation(AxisAnimation* |
|
68 | void ChartAxis::setAnimation(AxisAnimation *animation) | |
68 | { |
|
69 | { | |
69 | m_animation=animation; |
|
70 | m_animation = animation; | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
73 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
73 | { |
|
74 | { | |
74 | m_layoutVector=layout; |
|
75 | m_layoutVector = layout; | |
75 | } |
|
76 | } | |
76 |
|
77 | |||
77 | void ChartAxis::createItems(int count) |
|
78 | void ChartAxis::createItems(int count) | |
78 | { |
|
79 | { | |
79 | if (m_arrow->children().size() == 0) |
|
80 | if (m_arrow->children().size() == 0) | |
80 | m_arrow->addToGroup(new AxisItem(this,presenter()->rootItem())); |
|
81 | m_arrow->addToGroup(new AxisItem(this, presenter()->rootItem())); | |
81 | if (m_intervalAxis && m_grid->children().size() == 0){ |
|
82 | ||
82 | for(int i = 0 ; i < 2 ;i ++) |
|
83 | if (m_intervalAxis && m_grid->children().size() == 0) { | |
|
84 | for (int i = 0 ; i < 2 ; i ++) | |||
83 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
85 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); | |
84 | } |
|
86 | } | |
|
87 | ||||
85 | for (int i = 0; i < count; ++i) { |
|
88 | for (int i = 0; i < count; ++i) { | |
86 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
89 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); | |
87 | m_labels->addToGroup(new QGraphicsSimpleTextItem(presenter()->rootItem())); |
|
90 | m_labels->addToGroup(new QGraphicsSimpleTextItem(presenter()->rootItem())); | |
88 | m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
91 | m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); | |
89 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) |
|
92 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2) | |
90 | m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem())); |
|
93 | m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem())); | |
91 | } |
|
94 | } | |
92 | } |
|
95 | } | |
@@ -99,7 +102,8 void ChartAxis::deleteItems(int count) | |||||
99 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
102 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
100 |
|
103 | |||
101 | for (int i = 0; i < count; ++i) { |
|
104 | for (int i = 0; i < count; ++i) { | |
102 |
if (lines.size()%2 && lines.size() > 1) |
|
105 | if (lines.size() % 2 && lines.size() > 1) | |
|
106 | delete(shades.takeLast()); | |||
103 | delete(lines.takeLast()); |
|
107 | delete(lines.takeLast()); | |
104 | delete(labels.takeLast()); |
|
108 | delete(labels.takeLast()); | |
105 | delete(axis.takeLast()); |
|
109 | delete(axis.takeLast()); | |
@@ -110,41 +114,38 void ChartAxis::updateLayout(QVector<qreal> &layout) | |||||
110 | { |
|
114 | { | |
111 | int diff = m_layoutVector.size() - layout.size(); |
|
115 | int diff = m_layoutVector.size() - layout.size(); | |
112 |
|
116 | |||
113 |
if (diff>0) |
|
117 | if (diff > 0) | |
114 | deleteItems(diff); |
|
118 | deleteItems(diff); | |
115 | } |
|
119 | else if (diff < 0) | |
116 | else if (diff<0) { |
|
|||
117 | createItems(-diff); |
|
120 | createItems(-diff); | |
118 | } |
|
|||
119 |
|
121 | |||
120 | if(diff<0) handleAxisUpdated(); |
|
122 | if (diff < 0) handleAxisUpdated(); | |
121 |
|
123 | |||
122 | if (m_animation) { |
|
124 | if (m_animation) { | |
123 |
|
|
125 | switch (presenter()->state()) { | |
124 |
|
|
126 | case ChartPresenter::ZoomInState: | |
125 |
|
|
127 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); | |
126 |
|
|
128 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
127 |
|
|
129 | break; | |
128 |
|
|
130 | case ChartPresenter::ZoomOutState: | |
129 |
|
|
131 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); | |
130 |
|
|
132 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
131 |
|
|
133 | break; | |
132 |
|
|
134 | case ChartPresenter::ScrollUpState: | |
133 |
|
|
135 | case ChartPresenter::ScrollLeftState: | |
134 |
|
|
136 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); | |
135 |
|
|
137 | break; | |
136 |
|
|
138 | case ChartPresenter::ScrollDownState: | |
137 |
|
|
139 | case ChartPresenter::ScrollRightState: | |
138 |
|
|
140 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); | |
139 |
|
|
141 | break; | |
140 |
|
|
142 | case ChartPresenter::ShowState: | |
141 |
|
|
143 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); | |
142 |
|
|
144 | break; | |
143 |
|
|
145 | } | |
144 |
|
|
146 | m_animation->setValues(m_layoutVector, layout); | |
145 |
|
|
147 | presenter()->startAnimation(m_animation); | |
146 | } |
|
148 | } else { | |
147 | else { |
|
|||
148 | setLayout(layout); |
|
149 | setLayout(layout); | |
149 | updateGeometry(); |
|
150 | updateGeometry(); | |
150 | } |
|
151 | } | |
@@ -212,74 +213,65 void ChartAxis::setShadesVisibility(bool visible) | |||||
212 |
|
213 | |||
213 | void ChartAxis::setLabelsAngle(int angle) |
|
214 | void ChartAxis::setLabelsAngle(int angle) | |
214 | { |
|
215 | { | |
215 |
foreach(QGraphicsItem* |
|
216 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
216 |
|
|
217 | item->setRotation(angle); | |
217 | } |
|
|||
218 |
|
218 | |||
219 | m_labelsAngle=angle; |
|
219 | m_labelsAngle = angle; | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | void ChartAxis::setLabelsPen(const QPen &pen) |
|
222 | void ChartAxis::setLabelsPen(const QPen &pen) | |
223 | { |
|
223 | { | |
224 |
foreach(QGraphicsItem* |
|
224 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
225 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
225 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); | |
226 | } |
|
|||
227 | } |
|
226 | } | |
228 |
|
227 | |||
229 | void ChartAxis::setLabelsBrush(const QBrush &brush) |
|
228 | void ChartAxis::setLabelsBrush(const QBrush &brush) | |
230 | { |
|
229 | { | |
231 |
foreach(QGraphicsItem* |
|
230 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
232 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
231 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); | |
233 | } |
|
|||
234 | } |
|
232 | } | |
235 |
|
233 | |||
236 | void ChartAxis::setLabelsFont(const QFont &font) |
|
234 | void ChartAxis::setLabelsFont(const QFont &font) | |
237 | { |
|
235 | { | |
238 |
foreach(QGraphicsItem* |
|
236 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
239 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
237 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); | |
240 | } |
|
238 | ||
241 | if(m_font!=font) { |
|
239 | if (m_font != font) { | |
242 | m_font = font; |
|
240 | m_font = font; | |
243 |
foreach(QGraphicsItem* |
|
241 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
244 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
242 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); | |
245 | } |
|
|||
246 | QGraphicsLayoutItem::updateGeometry(); |
|
243 | QGraphicsLayoutItem::updateGeometry(); | |
247 | presenter()->layout()->invalidate(); |
|
244 | presenter()->layout()->invalidate(); | |
248 |
|
||||
249 | } |
|
245 | } | |
250 | } |
|
246 | } | |
251 |
|
247 | |||
252 | void ChartAxis::setShadesBrush(const QBrush &brush) |
|
248 | void ChartAxis::setShadesBrush(const QBrush &brush) | |
253 | { |
|
249 | { | |
254 |
foreach(QGraphicsItem* |
|
250 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
255 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
251 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); | |
256 | } |
|
|||
257 | } |
|
252 | } | |
258 |
|
253 | |||
259 | void ChartAxis::setShadesPen(const QPen &pen) |
|
254 | void ChartAxis::setShadesPen(const QPen &pen) | |
260 | { |
|
255 | { | |
261 |
foreach(QGraphicsItem* |
|
256 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
262 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
257 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); | |
263 | } |
|
|||
264 | } |
|
258 | } | |
265 |
|
259 | |||
266 | void ChartAxis::setArrowPen(const QPen &pen) |
|
260 | void ChartAxis::setArrowPen(const QPen &pen) | |
267 | { |
|
261 | { | |
268 |
foreach(QGraphicsItem* |
|
262 | foreach (QGraphicsItem *item , m_arrow->childItems()) | |
269 |
|
|
263 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
270 | } |
|
|||
271 | } |
|
264 | } | |
272 |
|
265 | |||
273 | void ChartAxis::setGridPen(const QPen &pen) |
|
266 | void ChartAxis::setGridPen(const QPen &pen) | |
274 | { |
|
267 | { | |
275 |
foreach(QGraphicsItem* |
|
268 | foreach (QGraphicsItem *item , m_grid->childItems()) | |
276 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
269 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
277 | } |
|
|||
278 | } |
|
270 | } | |
279 |
|
271 | |||
280 | void ChartAxis::setLabelPadding(int padding) |
|
272 | void ChartAxis::setLabelPadding(int padding) | |
281 | { |
|
273 | { | |
282 | m_labelPadding=padding; |
|
274 | m_labelPadding = padding; | |
283 | } |
|
275 | } | |
284 |
|
276 | |||
285 | bool ChartAxis::isEmpty() |
|
277 | bool ChartAxis::isEmpty() | |
@@ -289,22 +281,19 bool ChartAxis::isEmpty() | |||||
289 |
|
281 | |||
290 | void ChartAxis::handleDomainUpdated() |
|
282 | void ChartAxis::handleDomainUpdated() | |
291 | { |
|
283 | { | |
292 |
Domain* |
|
284 | Domain *domain = qobject_cast<Domain *>(sender()); | |
293 | qreal min(0); |
|
285 | qreal min(0); | |
294 | qreal max(0); |
|
286 | qreal max(0); | |
295 |
|
287 | |||
296 | if(m_chartAxis->orientation()==Qt::Horizontal) { |
|
288 | if (m_chartAxis->orientation() == Qt::Horizontal) { | |
297 | min = domain->minX(); |
|
289 | min = domain->minX(); | |
298 | max = domain->maxX(); |
|
290 | max = domain->maxX(); | |
299 | } |
|
291 | } else if (m_chartAxis->orientation() == Qt::Vertical) { | |
300 | else if (m_chartAxis->orientation()==Qt::Vertical) |
|
|||
301 | { |
|
|||
302 | min = domain->minY(); |
|
292 | min = domain->minY(); | |
303 | max = domain->maxY(); |
|
293 | max = domain->maxY(); | |
304 | } |
|
294 | } | |
305 |
|
295 | |||
306 | if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) |
|
296 | if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) { | |
307 | { |
|
|||
308 | m_min = min; |
|
297 | m_min = min; | |
309 | m_max = max; |
|
298 | m_max = max; | |
310 |
|
299 | |||
@@ -314,9 +303,9 void ChartAxis::handleDomainUpdated() | |||||
314 | updateLayout(layout); |
|
303 | updateLayout(layout); | |
315 | QSizeF before = effectiveSizeHint(Qt::MinimumSize); |
|
304 | QSizeF before = effectiveSizeHint(Qt::MinimumSize); | |
316 |
|
305 | |||
317 | QSizeF after= sizeHint(Qt::MinimumSize); |
|
306 | QSizeF after = sizeHint(Qt::MinimumSize); | |
318 |
|
307 | |||
319 | if(before!=after) { |
|
308 | if (before != after) { | |
320 | QGraphicsLayoutItem::updateGeometry(); |
|
309 | QGraphicsLayoutItem::updateGeometry(); | |
321 | //we don't want to call invalidate on layout, since it will change minimum size of component, |
|
310 | //we don't want to call invalidate on layout, since it will change minimum size of component, | |
322 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, |
|
311 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, | |
@@ -329,8 +318,8 void ChartAxis::handleDomainUpdated() | |||||
329 |
|
318 | |||
330 | void ChartAxis::handleAxisUpdated() |
|
319 | void ChartAxis::handleAxisUpdated() | |
331 | { |
|
320 | { | |
332 |
if(isEmpty()) |
|
321 | if (isEmpty()) | |
333 |
|
322 | return; | ||
334 |
|
323 | |||
335 | bool visible = m_chartAxis->isVisible(); |
|
324 | bool visible = m_chartAxis->isVisible(); | |
336 |
|
325 | |||
@@ -349,9 +338,9 void ChartAxis::handleAxisUpdated() | |||||
349 | setTitleText(m_chartAxis->title()); |
|
338 | setTitleText(m_chartAxis->title()); | |
350 | } |
|
339 | } | |
351 |
|
340 | |||
352 |
void ChartAxis::setTitleText(const QString& |
|
341 | void ChartAxis::setTitleText(const QString &title) | |
353 | { |
|
342 | { | |
354 | if(m_titleText!=title) { |
|
343 | if (m_titleText != title) { | |
355 | m_titleText = title; |
|
344 | m_titleText = title; | |
356 | m_axisRect = QRect(); |
|
345 | m_axisRect = QRect(); | |
357 | QGraphicsLayoutItem::updateGeometry(); |
|
346 | QGraphicsLayoutItem::updateGeometry(); | |
@@ -369,44 +358,43 void ChartAxis::hide() | |||||
369 |
|
358 | |||
370 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) |
|
359 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) | |
371 | { |
|
360 | { | |
372 |
|
|
361 | m_gridRect = grid; | |
373 |
|
|
362 | m_axisRect = axis; | |
374 |
|
363 | |||
375 |
|
|
364 | if (isEmpty()) | |
|
365 | return; | |||
376 |
|
366 | |||
377 |
|
|
367 | if (!m_titleText.isNull()) { | |
378 |
|
|
368 | QFontMetrics fn(m_title->font()); | |
379 |
|
369 | |||
380 |
|
|
370 | int size(0); | |
381 |
|
371 | |||
382 |
|
|
372 | if (orientation() == Qt::Horizontal) | |
383 | size = grid.width(); |
|
373 | size = grid.width(); | |
384 |
|
|
374 | else if (orientation() == Qt::Vertical) | |
385 | size = grid.height(); |
|
375 | size = grid.height(); | |
386 |
|
376 | |||
387 |
|
|
377 | if (fn.boundingRect(m_titleText).width() > size) { | |
388 | { |
|
378 | QString string = m_titleText + "..."; | |
389 | QString string = m_titleText + "..."; |
|
379 | while (fn.boundingRect(string).width() > size && string.length() > 3) | |
390 | while (fn.boundingRect(string).width() > size && string.length() > 3) |
|
|||
391 | string.remove(string.length() - 4, 1); |
|
380 | string.remove(string.length() - 4, 1); | |
392 |
|
|
381 | m_title->setText(string); | |
393 |
|
|
382 | } else { | |
394 | else |
|
|||
395 | m_title->setText(m_titleText); |
|
383 | m_title->setText(m_titleText); | |
|
384 | } | |||
396 |
|
385 | |||
397 |
|
|
386 | QPointF center = grid.center() - m_title->boundingRect().center(); | |
398 |
|
|
387 | if (orientation() == Qt::Horizontal) { | |
399 |
|
|
388 | m_title->setPos(center.x(), m_axisRect.bottom() - m_title->boundingRect().height()); | |
400 | } |
|
389 | } else if (orientation() == Qt::Vertical) { | |
401 | else if(orientation()==Qt::Vertical) { |
|
390 | m_title->setTransformOriginPoint(m_title->boundingRect().center()); | |
402 | m_title->setTransformOriginPoint(m_title->boundingRect().center()); |
|
391 | m_title->setRotation(270); | |
403 | m_title->setRotation(270); |
|
392 | m_title->setPos(m_axisRect.left() - m_title->boundingRect().width() / 2 + m_title->boundingRect().height() / 2, center.y()); | |
404 | m_title->setPos(m_axisRect.left()- m_title->boundingRect().width()/2+m_title->boundingRect().height()/2,center.y()); |
|
|||
405 | } |
|
|||
406 | } |
|
393 | } | |
|
394 | } | |||
407 |
|
395 | |||
408 |
|
|
396 | QVector<qreal> layout = calculateLayout(); | |
409 |
|
|
397 | updateLayout(layout); | |
410 |
|
398 | |||
411 | } |
|
399 | } | |
412 |
|
400 | |||
@@ -430,41 +418,36 bool ChartAxis::isVisible() | |||||
430 | return m_chartAxis->isVisible(); |
|
418 | return m_chartAxis->isVisible(); | |
431 | } |
|
419 | } | |
432 |
|
420 | |||
433 |
void ChartAxis::setLabels(const QStringList& |
|
421 | void ChartAxis::setLabels(const QStringList &labels) | |
434 | { |
|
422 | { | |
435 | m_labelsList=labels; |
|
423 | m_labelsList = labels; | |
436 | } |
|
424 | } | |
437 |
|
425 | |||
438 |
QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF& |
|
426 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
439 | { |
|
427 | { | |
440 |
|
428 | |||
441 | Q_UNUSED(constraint); |
|
429 | Q_UNUSED(constraint); | |
442 | QFontMetrics fn(m_title->font()); |
|
430 | QFontMetrics fn(m_title->font()); | |
443 | QSizeF sh; |
|
431 | QSizeF sh; | |
444 |
|
432 | |||
445 |
if(m_titleText.isNull()) |
|
433 | if (m_titleText.isNull()) | |
446 |
|
434 | return sh; | ||
447 | switch(which) { |
|
|||
448 | case Qt::MinimumSize: |
|
|||
449 | if(orientation()==Qt::Horizontal) { |
|
|||
450 | sh = QSizeF(fn.boundingRect ("...").width(),fn.height()); |
|
|||
451 | } |
|
|||
452 | else if(orientation()==Qt::Vertical) { |
|
|||
453 | sh = QSizeF(fn.height(),fn.boundingRect ("...").width()); |
|
|||
454 | } |
|
|||
455 |
|
435 | |||
|
436 | switch (which) { | |||
|
437 | case Qt::MinimumSize: | |||
|
438 | if (orientation() == Qt::Horizontal) | |||
|
439 | sh = QSizeF(fn.boundingRect("...").width(), fn.height()); | |||
|
440 | else if (orientation() == Qt::Vertical) | |||
|
441 | sh = QSizeF(fn.height(), fn.boundingRect("...").width()); | |||
456 | break; |
|
442 | break; | |
457 |
|
|
443 | case Qt::MaximumSize: | |
458 |
|
|
444 | case Qt::PreferredSize: | |
459 |
if(orientation()==Qt::Horizontal) |
|
445 | if (orientation() == Qt::Horizontal) | |
460 | sh = QSizeF(fn.boundingRect(m_chartAxis->title()).width(),fn.height()); |
|
446 | sh = QSizeF(fn.boundingRect(m_chartAxis->title()).width(), fn.height()); | |
461 | } |
|
447 | else if (orientation() == Qt::Vertical) | |
462 | else if(orientation()==Qt::Vertical) { |
|
448 | sh = QSizeF(fn.height(), fn.boundingRect(m_chartAxis->title()).width()); | |
463 | sh = QSizeF(fn.height(),fn.boundingRect(m_chartAxis->title()).width()); |
|
|||
464 | } |
|
|||
465 |
|
||||
466 | break; |
|
449 | break; | |
467 |
|
|
450 | default: | |
468 | break; |
|
451 | break; | |
469 | } |
|
452 | } | |
470 |
|
453 | |||
@@ -473,28 +456,27 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||||
473 |
|
456 | |||
474 | QStringList ChartAxis::createValueLabels(int ticks) const |
|
457 | QStringList ChartAxis::createValueLabels(int ticks) const | |
475 | { |
|
458 | { | |
476 | Q_ASSERT(m_max>m_min); |
|
459 | Q_ASSERT(m_max > m_min); | |
477 | Q_ASSERT(ticks>1); |
|
460 | Q_ASSERT(ticks > 1); | |
478 |
|
461 | |||
479 | QStringList labels; |
|
462 | QStringList labels; | |
480 |
|
463 | |||
481 | int n = qMax(int(-qFloor(log10((m_max-m_min)/(ticks-1)))),0); |
|
464 | int n = qMax(int(-qFloor(log10((m_max - m_min) / (ticks - 1)))), 0); | |
482 | n++; |
|
465 | n++; | |
483 |
|
466 | |||
484 | QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis); |
|
467 | QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis); | |
485 |
|
468 | |||
486 | QString format = axis->labelFormat(); |
|
469 | QString format = axis->labelFormat(); | |
487 |
|
470 | |||
488 | if(format.isNull()) { |
|
471 | if (format.isNull()) { | |
489 | for (int i=0; i< ticks; i++) { |
|
472 | for (int i = 0; i < ticks; i++) { | |
490 | qreal value = m_min + (i * (m_max - m_min)/ (ticks-1)); |
|
473 | qreal value = m_min + (i * (m_max - m_min) / (ticks - 1)); | |
491 | labels << QString::number(value,'f',n); |
|
474 | labels << QString::number(value, 'f', n); | |
492 | } |
|
475 | } | |
493 | } |
|
476 | } else { | |
494 | else { |
|
|||
495 | QByteArray array = format.toAscii(); |
|
477 | QByteArray array = format.toAscii(); | |
496 | for (int i=0; i< ticks; i++) { |
|
478 | for (int i = 0; i < ticks; i++) { | |
497 | qreal value = m_min + (i * (m_max - m_min)/ (ticks-1)); |
|
479 | qreal value = m_min + (i * (m_max - m_min) / (ticks - 1)); | |
498 | labels << QString().sprintf(array, value); |
|
480 | labels << QString().sprintf(array, value); | |
499 | } |
|
481 | } | |
500 | } |
|
482 | } | |
@@ -502,18 +484,17 QStringList ChartAxis::createValueLabels(int ticks) const | |||||
502 | return labels; |
|
484 | return labels; | |
503 | } |
|
485 | } | |
504 |
|
486 | |||
505 |
QStringList ChartAxis::createDateTimeLabels(const QString& |
|
487 | QStringList ChartAxis::createDateTimeLabels(const QString &format, int ticks) const | |
506 | { |
|
488 | { | |
507 | Q_ASSERT(m_max>m_min); |
|
489 | Q_ASSERT(m_max > m_min); | |
508 | Q_ASSERT(ticks>1); |
|
490 | Q_ASSERT(ticks > 1); | |
509 | QStringList labels; |
|
491 | QStringList labels; | |
510 | int n = qMax(int(-floor(log10((m_max-m_min)/(ticks-1)))),0); |
|
492 | int n = qMax(int(-floor(log10((m_max - m_min) / (ticks - 1)))), 0); | |
511 | n++; |
|
493 | n++; | |
512 | for (int i=0; i< ticks; i++) { |
|
494 | for (int i = 0; i < ticks; i++) { | |
513 | qreal value = m_min + (i * (m_max - m_min)/ (ticks-1)); |
|
495 | qreal value = m_min + (i * (m_max - m_min) / (ticks - 1)); | |
514 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); |
|
496 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); | |
515 | } |
|
497 | } | |
516 |
|
||||
517 | return labels; |
|
498 | return labels; | |
518 | } |
|
499 | } | |
519 |
|
500 |
@@ -103,7 +103,7 public: | |||||
103 | QRectF axisGeometry() const { return m_axisRect; } |
|
103 | QRectF axisGeometry() const { return m_axisRect; } | |
104 | QRectF gridGeometry() const { return m_gridRect; } |
|
104 | QRectF gridGeometry() const { return m_gridRect; } | |
105 |
|
105 | |||
106 |
void setLabels(const QStringList& |
|
106 | void setLabels(const QStringList &labels); | |
107 | QStringList labels() const { return m_labelsList; } |
|
107 | QStringList labels() const { return m_labelsList; } | |
108 |
|
108 | |||
109 | //this flag indicates that axis is used to show intervals it means labels are in between ticks |
|
109 | //this flag indicates that axis is used to show intervals it means labels are in between ticks | |
@@ -112,7 +112,7 public: | |||||
112 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; |
|
112 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; | |
113 |
|
113 | |||
114 | protected: |
|
114 | protected: | |
115 | void setGeometry(const QRectF &size){ Q_UNUSED(size);}; |
|
115 | void setGeometry(const QRectF &size) { Q_UNUSED(size);}; | |
116 | virtual void updateGeometry() = 0; |
|
116 | virtual void updateGeometry() = 0; | |
117 | virtual QVector<qreal> calculateLayout() const = 0; |
|
117 | virtual QVector<qreal> calculateLayout() const = 0; | |
118 |
|
118 | |||
@@ -125,7 +125,7 protected: | |||||
125 | qreal min() const {return m_min; } |
|
125 | qreal min() const {return m_min; } | |
126 | qreal max() const {return m_max; } |
|
126 | qreal max() const {return m_max; } | |
127 | QStringList createValueLabels(int ticks) const; |
|
127 | QStringList createValueLabels(int ticks) const; | |
128 |
QStringList createDateTimeLabels(const QString& |
|
128 | QStringList createDateTimeLabels(const QString &format, int ticks) const; | |
129 |
|
129 | |||
130 | public Q_SLOTS: |
|
130 | public Q_SLOTS: | |
131 | virtual void handleAxisUpdated(); |
|
131 | virtual void handleAxisUpdated(); | |
@@ -158,8 +158,8 private: | |||||
158 | QStringList m_labelsList; |
|
158 | QStringList m_labelsList; | |
159 | bool m_intervalAxis; |
|
159 | bool m_intervalAxis; | |
160 |
|
160 | |||
161 | friend class AxisAnimation; |
|
161 | friend class AxisAnimation; | |
162 | friend class AxisItem; |
|
162 | friend class AxisItem; | |
163 |
|
163 | |||
164 | }; |
|
164 | }; | |
165 |
|
165 |
@@ -28,8 +28,10 | |||||
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 |
ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis,ChartPresenter *presenter) |
|
31 | ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis, ChartPresenter *presenter) | |
32 | m_tickCount(0),m_axis(axis) |
|
32 | : HorizontalAxis(axis, presenter), | |
|
33 | m_tickCount(0), | |||
|
34 | m_axis(axis) | |||
33 | { |
|
35 | { | |
34 | } |
|
36 | } | |
35 |
|
37 | |||
@@ -39,12 +41,12 ChartDateTimeAxisX::~ChartDateTimeAxisX() | |||||
39 |
|
41 | |||
40 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const |
|
42 | QVector<qreal> ChartDateTimeAxisX::calculateLayout() const | |
41 | { |
|
43 | { | |
42 | Q_ASSERT(m_tickCount>=2); |
|
44 | Q_ASSERT(m_tickCount >= 2); | |
43 |
|
45 | |||
44 | QVector<qreal> points; |
|
46 | QVector<qreal> points; | |
45 | points.resize(m_tickCount); |
|
47 | points.resize(m_tickCount); | |
46 |
const QRectF& |
|
48 | const QRectF &gridRect = gridGeometry(); | |
47 | const qreal deltaX = gridRect.width()/(m_tickCount-1); |
|
49 | const qreal deltaX = gridRect.width() / (m_tickCount - 1); | |
48 | for (int i = 0; i < m_tickCount; ++i) { |
|
50 | for (int i = 0; i < m_tickCount; ++i) { | |
49 | int x = i * deltaX + gridRect.left(); |
|
51 | int x = i * deltaX + gridRect.left(); | |
50 | points[i] = x; |
|
52 | points[i] = x; | |
@@ -55,8 +57,9 QVector<qreal> ChartDateTimeAxisX::calculateLayout() const | |||||
55 | void ChartDateTimeAxisX::updateGeometry() |
|
57 | void ChartDateTimeAxisX::updateGeometry() | |
56 | { |
|
58 | { | |
57 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
59 | const QVector<qreal>& layout = ChartAxis::layout(); | |
58 |
if(layout.isEmpty()) |
|
60 | if (layout.isEmpty()) | |
59 | setLabels(createDateTimeLabels(m_axis->format(),layout.size())); |
|
61 | return; | |
|
62 | setLabels(createDateTimeLabels(m_axis->format(), layout.size())); | |||
60 | HorizontalAxis::updateGeometry(); |
|
63 | HorizontalAxis::updateGeometry(); | |
61 | } |
|
64 | } | |
62 |
|
65 | |||
@@ -66,41 +69,40 void ChartDateTimeAxisX::handleAxisUpdated() | |||||
66 | ChartAxis::handleAxisUpdated(); |
|
69 | ChartAxis::handleAxisUpdated(); | |
67 | } |
|
70 | } | |
68 |
|
71 | |||
69 |
QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF& |
|
72 | QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
70 | { |
|
73 | { | |
71 | Q_UNUSED(constraint) |
|
74 | Q_UNUSED(constraint) | |
72 |
|
75 | |||
73 | QFontMetrics fn(font()); |
|
76 | QFontMetrics fn(font()); | |
74 | QSizeF sh; |
|
77 | QSizeF sh; | |
75 |
|
78 | |||
76 |
|
|
79 | switch (which) { | |
77 |
|
|
80 | case Qt::MinimumSize: | |
78 |
|
|
81 | sh = QSizeF(fn.boundingRect("...").width(), fn.height()); | |
79 |
|
|
82 | break; | |
80 |
|
|
83 | case Qt::PreferredSize: { | |
81 |
|
||||
82 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
|||
83 | if(layout.isEmpty()) break; |
|
|||
84 | QStringList ticksList; |
|
|||
85 |
|
84 | |||
|
85 | const QVector<qreal>& layout = ChartAxis::layout(); | |||
|
86 | if (layout.isEmpty()) | |||
|
87 | break; | |||
|
88 | QStringList ticksList; | |||
86 |
|
89 | |||
87 |
|
|
90 | qreal width = 0; | |
88 |
|
|
91 | qreal height = 0; | |
89 |
|
92 | |||
90 |
|
|
93 | for (int i = 0; i < ticksList.size(); ++i) { | |
91 | { |
|
94 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |
92 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
95 | width += rect.width(); | |
93 | width+=rect.width(); |
|
96 | height += qMax(rect.height() + labelPadding(), height); | |
94 | height+=qMax(rect.height()+labelPadding(),height); |
|
|||
95 | } |
|
|||
96 | sh = QSizeF(width,height); |
|
|||
97 | break; |
|
|||
98 | } |
|
97 | } | |
99 | default: |
|
98 | sh = QSizeF(width, height); | |
100 |
|
|
99 | break; | |
101 |
|
|
100 | } | |
|
101 | default: | |||
|
102 | break; | |||
|
103 | } | |||
102 |
|
104 | |||
103 |
|
|
105 | return sh; | |
104 | } |
|
106 | } | |
105 |
|
107 | |||
106 | QTCOMMERCIALCHART_END_NAMESPACE |
|
108 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -28,8 +28,10 | |||||
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 |
ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis,ChartPresenter *presenter) |
|
31 | ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis, ChartPresenter *presenter) | |
32 | m_tickCount(0),m_axis(axis) |
|
32 | : VerticalAxis(axis, presenter), | |
|
33 | m_tickCount(0), | |||
|
34 | m_axis(axis) | |||
33 | { |
|
35 | { | |
34 | } |
|
36 | } | |
35 |
|
37 | |||
@@ -39,12 +41,12 ChartDateTimeAxisY::~ChartDateTimeAxisY() | |||||
39 |
|
41 | |||
40 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const |
|
42 | QVector<qreal> ChartDateTimeAxisY::calculateLayout() const | |
41 | { |
|
43 | { | |
42 | Q_ASSERT(m_tickCount>=2); |
|
44 | Q_ASSERT(m_tickCount >= 2); | |
43 |
|
45 | |||
44 | QVector<qreal> points; |
|
46 | QVector<qreal> points; | |
45 | points.resize(m_tickCount); |
|
47 | points.resize(m_tickCount); | |
46 |
const QRectF& |
|
48 | const QRectF &gridRect = gridGeometry(); | |
47 | const qreal deltaY = gridRect.height()/(m_tickCount-1); |
|
49 | const qreal deltaY = gridRect.height() / (m_tickCount - 1); | |
48 | for (int i = 0; i < m_tickCount; ++i) { |
|
50 | for (int i = 0; i < m_tickCount; ++i) { | |
49 | int y = i * -deltaY + gridRect.bottom(); |
|
51 | int y = i * -deltaY + gridRect.bottom(); | |
50 | points[i] = y; |
|
52 | points[i] = y; | |
@@ -56,8 +58,9 QVector<qreal> ChartDateTimeAxisY::calculateLayout() const | |||||
56 | void ChartDateTimeAxisY::updateGeometry() |
|
58 | void ChartDateTimeAxisY::updateGeometry() | |
57 | { |
|
59 | { | |
58 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
60 | const QVector<qreal> &layout = ChartAxis::layout(); | |
59 |
if(layout.isEmpty()) |
|
61 | if (layout.isEmpty()) | |
60 | setLabels(createDateTimeLabels(m_axis->format(),layout.size())); |
|
62 | return; | |
|
63 | setLabels(createDateTimeLabels(m_axis->format(), layout.size())); | |||
61 | VerticalAxis::updateGeometry(); |
|
64 | VerticalAxis::updateGeometry(); | |
62 | } |
|
65 | } | |
63 |
|
66 | |||
@@ -67,41 +70,39 void ChartDateTimeAxisY::handleAxisUpdated() | |||||
67 | ChartAxis::handleAxisUpdated(); |
|
70 | ChartAxis::handleAxisUpdated(); | |
68 | } |
|
71 | } | |
69 |
|
72 | |||
70 |
QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF& |
|
73 | QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
71 | { |
|
74 | { | |
72 | Q_UNUSED(constraint) |
|
75 | Q_UNUSED(constraint) | |
73 |
|
76 | |||
74 | QFontMetrics fn(font()); |
|
77 | QFontMetrics fn(font()); | |
75 | QSizeF sh; |
|
78 | QSizeF sh; | |
76 |
|
79 | |||
77 |
|
|
80 | switch (which) { | |
78 |
|
|
81 | case Qt::MinimumSize: | |
79 |
|
|
82 | sh = QSizeF(fn.boundingRect("...").width(), fn.height()); | |
80 |
|
|
83 | break; | |
81 |
|
|
84 | case Qt::PreferredSize: { | |
82 |
|
85 | |||
83 |
|
|
86 | const QVector<qreal>& layout = ChartAxis::layout(); | |
84 |
|
|
87 | if (layout.isEmpty()) break; | |
85 |
|
|
88 | QStringList ticksList; | |
86 |
|
89 | |||
|
90 | qreal width = 0; | |||
|
91 | qreal height = 0; | |||
87 |
|
92 | |||
88 | qreal width=0; |
|
93 | for (int i = 0; i < ticksList.size(); ++i) { | |
89 | qreal height=0; |
|
94 | QRectF rect = fn.boundingRect(ticksList.at(i)); | |
90 |
|
95 | width += rect.width(); | ||
91 | for (int i = 0; i < ticksList.size(); ++i) |
|
96 | height += qMax(rect.height() + labelPadding(), height); | |
92 | { |
|
|||
93 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
|||
94 | width+=rect.width(); |
|
|||
95 | height+=qMax(rect.height()+labelPadding(),height); |
|
|||
96 | } |
|
|||
97 | sh = QSizeF(width,height); |
|
|||
98 | break; |
|
|||
99 | } |
|
97 | } | |
100 | default: |
|
98 | sh = QSizeF(width, height); | |
101 |
|
|
99 | break; | |
102 |
|
|
100 | } | |
|
101 | default: | |||
|
102 | break; | |||
|
103 | } | |||
103 |
|
104 | |||
104 |
|
|
105 | return sh; | |
105 | } |
|
106 | } | |
106 |
|
107 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
108 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -25,7 +25,8 | |||||
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 |
HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, ChartPresenter *presenter,bool intervalAxis) |
|
28 | HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis) | |
|
29 | : ChartAxis(axis, presenter, intervalAxis) | |||
29 | { |
|
30 | { | |
30 | } |
|
31 | } | |
31 |
|
32 | |||
@@ -37,7 +38,8 void HorizontalAxis::updateGeometry() | |||||
37 | { |
|
38 | { | |
38 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
39 | const QVector<qreal>& layout = ChartAxis::layout(); | |
39 |
|
40 | |||
40 |
if(layout.isEmpty()) |
|
41 | if (layout.isEmpty()) | |
|
42 | return; | |||
41 |
|
43 | |||
42 | QStringList ticksList = labels(); |
|
44 | QStringList ticksList = labels(); | |
43 |
|
45 | |||
@@ -49,86 +51,85 void HorizontalAxis::updateGeometry() | |||||
49 | Q_ASSERT(labels.size() == ticksList.size()); |
|
51 | Q_ASSERT(labels.size() == ticksList.size()); | |
50 | Q_ASSERT(layout.size() == ticksList.size()); |
|
52 | Q_ASSERT(layout.size() == ticksList.size()); | |
51 |
|
53 | |||
52 |
const QRectF& |
|
54 | const QRectF &axisRect = axisGeometry(); | |
53 |
const QRectF& |
|
55 | const QRectF &gridRect = gridGeometry(); | |
54 |
|
56 | |||
55 | //arrow |
|
57 | //arrow | |
56 | QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
58 | QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem *>(axis.at(0)); | |
57 |
|
59 | |||
58 | if (alignment()==Qt::AlignTop) |
|
60 | if (alignment() == Qt::AlignTop) | |
59 | arrowItem->setLine(gridRect.left(), axisRect.bottom(), gridRect.right(), axisRect.bottom()); |
|
61 | arrowItem->setLine(gridRect.left(), axisRect.bottom(), gridRect.right(), axisRect.bottom()); | |
60 | else if(alignment()==Qt::AlignBottom) |
|
62 | else if (alignment() == Qt::AlignBottom) | |
61 | arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top()); |
|
63 | arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top()); | |
62 |
|
64 | |||
63 | qreal width = 0; |
|
65 | qreal width = 0; | |
64 |
|
66 | |||
65 | for (int i = 0; i < layout.size(); ++i) { |
|
67 | for (int i = 0; i < layout.size(); ++i) { | |
66 |
|
68 | |||
67 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
69 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i)); | |
68 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
70 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(axis.at(i + 1)); | |
69 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
71 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i)); | |
70 |
|
72 | |||
71 | //grid line |
|
73 | //grid line | |
72 | gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom()); |
|
74 | gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom()); | |
73 |
|
75 | |||
74 | //label text |
|
76 | //label text | |
75 | labelItem->setText(ticksList.at(i)); |
|
77 | labelItem->setText(ticksList.at(i)); | |
76 |
const QRectF& |
|
78 | const QRectF &rect = labelItem->boundingRect(); | |
77 | QPointF center = rect.center(); |
|
79 | QPointF center = rect.center(); | |
78 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
80 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
79 |
|
81 | |||
80 | //ticks and label position |
|
82 | //ticks and label position | |
81 | if (alignment()==Qt::AlignTop){ |
|
83 | if (alignment() == Qt::AlignTop) { | |
82 | labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() - labelPadding()); |
|
84 | labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() - labelPadding()); | |
83 | tickItem->setLine(layout[i],axisRect.bottom(),layout[i],axisRect.bottom() - labelPadding()); |
|
85 | tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding()); | |
84 | }else if(alignment()==Qt::AlignBottom){ |
|
86 | } else if (alignment() == Qt::AlignBottom) { | |
85 | labelItem->setPos(layout[i] - center.x(), axisRect.top() + labelPadding()); |
|
87 | labelItem->setPos(layout[i] - center.x(), axisRect.top() + labelPadding()); | |
86 | tickItem->setLine(layout[i],axisRect.top(),layout[i],axisRect.top() + labelPadding()); |
|
88 | tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); | |
87 | } |
|
89 | } | |
88 |
|
90 | |||
89 | if(intervalAxis()&& i+1!=layout.size()) { |
|
91 | if (intervalAxis() && i + 1 != layout.size()) { | |
90 | const qreal delta = (layout[i+1] - layout[i])/2; |
|
92 | const qreal delta = (layout[i + 1] - layout[i]) / 2; | |
91 | labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y()); |
|
93 | labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y()); | |
92 | } |
|
94 | } | |
93 |
|
95 | |||
94 | //overlap detection |
|
96 | //overlap detection | |
95 | if(labelItem->pos().x() <= width || |
|
97 | if (labelItem->pos().x() <= width || | |
96 | labelItem->pos().x() < axisRect.left() || |
|
98 | labelItem->pos().x() < axisRect.left() || | |
97 | labelItem->pos().x() + rect.width() > axisRect.right()) { |
|
99 | labelItem->pos().x() + rect.width() > axisRect.right()) { | |
98 | labelItem->setVisible(false); |
|
100 | labelItem->setVisible(false); | |
99 | gridItem->setVisible(false); |
|
101 | gridItem->setVisible(false); | |
100 | tickItem->setVisible(false); |
|
102 | tickItem->setVisible(false); | |
101 | } |
|
103 | } else { | |
102 | else { |
|
|||
103 | labelItem->setVisible(true); |
|
104 | labelItem->setVisible(true); | |
104 | gridItem->setVisible(true); |
|
105 | gridItem->setVisible(true); | |
105 | tickItem->setVisible(true); |
|
106 | tickItem->setVisible(true); | |
106 | width=rect.width()+labelItem->pos().x(); |
|
107 | width = rect.width() + labelItem->pos().x(); | |
107 | } |
|
108 | } | |
108 |
|
109 | |||
109 | //shades |
|
110 | //shades | |
110 | if ((i+1)%2 && i>1) { |
|
111 | if ((i + 1) % 2 && i > 1) { | |
111 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
112 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1)); | |
112 | rectItem->setRect(layout[i-1],gridRect.top(),layout[i]-layout[i-1],gridRect.height()); |
|
113 | rectItem->setRect(layout[i - 1], gridRect.top(), layout[i] - layout[i - 1], gridRect.height()); | |
113 | } |
|
114 | } | |
114 |
|
115 | |||
115 | // check if the grid line and the axis tick should be shown |
|
116 | // check if the grid line and the axis tick should be shown | |
116 | qreal x = gridItem->line().p1().x(); |
|
117 | qreal x = gridItem->line().p1().x(); | |
117 | if (x < gridRect.left() || x > gridRect.right()) { |
|
118 | if (x < gridRect.left() || x > gridRect.right()) { | |
118 |
|
|
119 | gridItem->setVisible(false); | |
119 |
|
|
120 | tickItem->setVisible(false); | |
120 |
|
|
121 | if (intervalAxis() && (labelItem->pos().x() < gridRect.left() || labelItem->pos().x() + rect.width() > gridRect.right())) | |
121 |
|
|
122 | labelItem->setVisible(false); | |
122 | } |
|
123 | } | |
123 |
|
124 | |||
124 | } |
|
125 | } | |
125 |
|
126 | |||
126 | //begin/end grid line in case labels between |
|
127 | //begin/end grid line in case labels between | |
127 | if(intervalAxis()) { |
|
128 | if (intervalAxis()) { | |
128 | QGraphicsLineItem *gridLine; |
|
129 | QGraphicsLineItem *gridLine; | |
129 | gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size())); |
|
130 | gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size())); | |
130 | gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom()); |
|
131 | gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom()); | |
131 | gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1)); |
|
132 | gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size() + 1)); | |
132 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom()); |
|
133 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom()); | |
133 | } |
|
134 | } | |
134 | } |
|
135 | } |
@@ -37,7 +37,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
37 | class HorizontalAxis : public ChartAxis |
|
37 | class HorizontalAxis : public ChartAxis | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 | HorizontalAxis(QAbstractAxis *axis, ChartPresenter *presenter,bool intervalAxis = false); |
|
40 | HorizontalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false); | |
41 | ~HorizontalAxis(); |
|
41 | ~HorizontalAxis(); | |
42 | protected: |
|
42 | protected: | |
43 | void updateGeometry(); |
|
43 | void updateGeometry(); |
@@ -260,9 +260,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
260 | QChart when axis added. |
|
260 | QChart when axis added. | |
261 | */ |
|
261 | */ | |
262 |
|
262 | |||
263 |
QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) |
|
263 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) | |
264 | QObject(parent), |
|
264 | : QObject(parent), | |
265 | d_ptr(&d) |
|
265 | d_ptr(&d) | |
266 | { |
|
266 | { | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
@@ -272,7 +272,8 d_ptr(&d) | |||||
272 |
|
272 | |||
273 | QAbstractAxis::~QAbstractAxis() |
|
273 | QAbstractAxis::~QAbstractAxis() | |
274 | { |
|
274 | { | |
275 | if(d_ptr->m_dataset) qFatal("Still binded axis detected !"); |
|
275 | if (d_ptr->m_dataset) | |
|
276 | qFatal("Still binded axis detected !"); | |||
276 | } |
|
277 | } | |
277 |
|
278 | |||
278 | /*! |
|
279 | /*! | |
@@ -280,10 +281,10 QAbstractAxis::~QAbstractAxis() | |||||
280 | */ |
|
281 | */ | |
281 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
282 | void QAbstractAxis::setLinePen(const QPen &pen) | |
282 | { |
|
283 | { | |
283 |
|
|
284 | if (d_ptr->m_axisPen != pen) { | |
284 |
|
|
285 | d_ptr->m_axisPen = pen; | |
285 |
|
|
286 | d_ptr->emitUpdated(); | |
286 | } |
|
287 | } | |
287 | } |
|
288 | } | |
288 |
|
289 | |||
289 | /*! |
|
290 | /*! | |
@@ -318,7 +319,7 void QAbstractAxis::setLineVisible(bool visible) | |||||
318 | d_ptr->m_arrowVisible = visible; |
|
319 | d_ptr->m_arrowVisible = visible; | |
319 | d_ptr->emitUpdated(); |
|
320 | d_ptr->emitUpdated(); | |
320 | emit lineVisibleChanged(visible); |
|
321 | emit lineVisibleChanged(visible); | |
321 | } |
|
322 | } | |
322 | } |
|
323 | } | |
323 |
|
324 | |||
324 | bool QAbstractAxis::isLineVisible() const |
|
325 | bool QAbstractAxis::isLineVisible() const | |
@@ -332,7 +333,7 void QAbstractAxis::setGridLineVisible(bool visible) | |||||
332 | d_ptr->m_gridLineVisible = visible; |
|
333 | d_ptr->m_gridLineVisible = visible; | |
333 | d_ptr->emitUpdated(); |
|
334 | d_ptr->emitUpdated(); | |
334 | emit gridVisibleChanged(visible); |
|
335 | emit gridVisibleChanged(visible); | |
335 | } |
|
336 | } | |
336 | } |
|
337 | } | |
337 |
|
338 | |||
338 | bool QAbstractAxis::isGridLineVisible() const |
|
339 | bool QAbstractAxis::isGridLineVisible() const | |
@@ -348,7 +349,7 void QAbstractAxis::setGridLinePen(const QPen &pen) | |||||
348 | if (d_ptr->m_gridLinePen != pen) { |
|
349 | if (d_ptr->m_gridLinePen != pen) { | |
349 | d_ptr->m_gridLinePen = pen; |
|
350 | d_ptr->m_gridLinePen = pen; | |
350 | d_ptr->emitUpdated(); |
|
351 | d_ptr->emitUpdated(); | |
351 | } |
|
352 | } | |
352 | } |
|
353 | } | |
353 |
|
354 | |||
354 | /*! |
|
355 | /*! | |
@@ -365,7 +366,7 void QAbstractAxis::setLabelsVisible(bool visible) | |||||
365 | d_ptr->m_labelsVisible = visible; |
|
366 | d_ptr->m_labelsVisible = visible; | |
366 | d_ptr->emitUpdated(); |
|
367 | d_ptr->emitUpdated(); | |
367 | emit labelsVisibleChanged(visible); |
|
368 | emit labelsVisibleChanged(visible); | |
368 | } |
|
369 | } | |
369 | } |
|
370 | } | |
370 |
|
371 | |||
371 | bool QAbstractAxis::labelsVisible() const |
|
372 | bool QAbstractAxis::labelsVisible() const | |
@@ -381,7 +382,7 void QAbstractAxis::setLabelsPen(const QPen &pen) | |||||
381 | if (d_ptr->m_labelsPen != pen) { |
|
382 | if (d_ptr->m_labelsPen != pen) { | |
382 | d_ptr->m_labelsPen = pen; |
|
383 | d_ptr->m_labelsPen = pen; | |
383 | d_ptr->emitUpdated(); |
|
384 | d_ptr->emitUpdated(); | |
384 | } |
|
385 | } | |
385 | } |
|
386 | } | |
386 |
|
387 | |||
387 | /*! |
|
388 | /*! | |
@@ -400,7 +401,7 void QAbstractAxis::setLabelsBrush(const QBrush &brush) | |||||
400 | if (d_ptr->m_labelsBrush != brush) { |
|
401 | if (d_ptr->m_labelsBrush != brush) { | |
401 | d_ptr->m_labelsBrush = brush; |
|
402 | d_ptr->m_labelsBrush = brush; | |
402 | d_ptr->emitUpdated(); |
|
403 | d_ptr->emitUpdated(); | |
403 | } |
|
404 | } | |
404 | } |
|
405 | } | |
405 |
|
406 | |||
406 | /*! |
|
407 | /*! | |
@@ -419,7 +420,7 void QAbstractAxis::setLabelsFont(const QFont &font) | |||||
419 | if (d_ptr->m_labelsFont != font) { |
|
420 | if (d_ptr->m_labelsFont != font) { | |
420 | d_ptr->m_labelsFont = font; |
|
421 | d_ptr->m_labelsFont = font; | |
421 | d_ptr->emitUpdated(); |
|
422 | d_ptr->emitUpdated(); | |
422 | } |
|
423 | } | |
423 | } |
|
424 | } | |
424 |
|
425 | |||
425 | /*! |
|
426 | /*! | |
@@ -435,7 +436,7 void QAbstractAxis::setLabelsAngle(int angle) | |||||
435 | if (d_ptr->m_labelsAngle != angle) { |
|
436 | if (d_ptr->m_labelsAngle != angle) { | |
436 | d_ptr->m_labelsAngle = angle; |
|
437 | d_ptr->m_labelsAngle = angle; | |
437 | d_ptr->emitUpdated(); |
|
438 | d_ptr->emitUpdated(); | |
438 | } |
|
439 | } | |
439 | } |
|
440 | } | |
440 |
|
441 | |||
441 | int QAbstractAxis::labelsAngle() const |
|
442 | int QAbstractAxis::labelsAngle() const | |
@@ -463,7 +464,7 void QAbstractAxis::setTitleVisible(bool visible) | |||||
463 | if (d_ptr->m_titleVisible != visible) { |
|
464 | if (d_ptr->m_titleVisible != visible) { | |
464 | d_ptr->m_titleVisible = visible; |
|
465 | d_ptr->m_titleVisible = visible; | |
465 | d_ptr->emitUpdated(); |
|
466 | d_ptr->emitUpdated(); | |
466 | } |
|
467 | } | |
467 | } |
|
468 | } | |
468 |
|
469 | |||
469 | bool QAbstractAxis::titleVisible() const |
|
470 | bool QAbstractAxis::titleVisible() const | |
@@ -479,7 +480,7 void QAbstractAxis::setTitlePen(const QPen &pen) | |||||
479 | if (d_ptr->m_titlePen != pen) { |
|
480 | if (d_ptr->m_titlePen != pen) { | |
480 | d_ptr->m_titlePen = pen; |
|
481 | d_ptr->m_titlePen = pen; | |
481 | d_ptr->emitUpdated(); |
|
482 | d_ptr->emitUpdated(); | |
482 | } |
|
483 | } | |
483 | } |
|
484 | } | |
484 |
|
485 | |||
485 | /*! |
|
486 | /*! | |
@@ -498,7 +499,7 void QAbstractAxis::setTitleBrush(const QBrush &brush) | |||||
498 | if (d_ptr->m_titleBrush != brush) { |
|
499 | if (d_ptr->m_titleBrush != brush) { | |
499 | d_ptr->m_titleBrush = brush; |
|
500 | d_ptr->m_titleBrush = brush; | |
500 | d_ptr->emitUpdated(); |
|
501 | d_ptr->emitUpdated(); | |
501 | } |
|
502 | } | |
502 | } |
|
503 | } | |
503 |
|
504 | |||
504 | /*! |
|
505 | /*! | |
@@ -517,7 +518,7 void QAbstractAxis::setTitleFont(const QFont &font) | |||||
517 | if (d_ptr->m_titleFont != font) { |
|
518 | if (d_ptr->m_titleFont != font) { | |
518 | d_ptr->m_titleFont = font; |
|
519 | d_ptr->m_titleFont = font; | |
519 | d_ptr->emitUpdated(); |
|
520 | d_ptr->emitUpdated(); | |
520 | } |
|
521 | } | |
521 | } |
|
522 | } | |
522 |
|
523 | |||
523 | /*! |
|
524 | /*! | |
@@ -528,17 +529,17 QFont QAbstractAxis::titleFont() const | |||||
528 | return d_ptr->m_titleFont; |
|
529 | return d_ptr->m_titleFont; | |
529 | } |
|
530 | } | |
530 |
|
531 | |||
531 |
void QAbstractAxis::setTitle(const QString& |
|
532 | void QAbstractAxis::setTitle(const QString &title) | |
532 | { |
|
533 | { | |
533 |
|
|
534 | if (d_ptr->m_title != title) { | |
534 |
|
|
535 | d_ptr->m_title = title; | |
535 |
|
|
536 | d_ptr->emitUpdated(); | |
536 | } |
|
537 | } | |
537 | } |
|
538 | } | |
538 |
|
539 | |||
539 | QString QAbstractAxis::title() const |
|
540 | QString QAbstractAxis::title() const | |
540 | { |
|
541 | { | |
541 |
|
|
542 | return d_ptr->m_title; | |
542 | } |
|
543 | } | |
543 |
|
544 | |||
544 |
|
545 | |||
@@ -548,7 +549,7 void QAbstractAxis::setShadesVisible(bool visible) | |||||
548 | d_ptr->m_shadesVisible = visible; |
|
549 | d_ptr->m_shadesVisible = visible; | |
549 | d_ptr->emitUpdated(); |
|
550 | d_ptr->emitUpdated(); | |
550 | emit shadesVisibleChanged(visible); |
|
551 | emit shadesVisibleChanged(visible); | |
551 | } |
|
552 | } | |
552 | } |
|
553 | } | |
553 |
|
554 | |||
554 | bool QAbstractAxis::shadesVisible() const |
|
555 | bool QAbstractAxis::shadesVisible() const | |
@@ -564,7 +565,7 void QAbstractAxis::setShadesPen(const QPen &pen) | |||||
564 | if (d_ptr->m_shadesPen != pen) { |
|
565 | if (d_ptr->m_shadesPen != pen) { | |
565 | d_ptr->m_shadesPen = pen; |
|
566 | d_ptr->m_shadesPen = pen; | |
566 | d_ptr->emitUpdated(); |
|
567 | d_ptr->emitUpdated(); | |
567 | } |
|
568 | } | |
568 | } |
|
569 | } | |
569 |
|
570 | |||
570 | /*! |
|
571 | /*! | |
@@ -630,8 +631,8 bool QAbstractAxis::isVisible() const | |||||
630 | */ |
|
631 | */ | |
631 | void QAbstractAxis::setVisible(bool visible) |
|
632 | void QAbstractAxis::setVisible(bool visible) | |
632 | { |
|
633 | { | |
633 | if(d_ptr->m_visible!=visible){ |
|
634 | if (d_ptr->m_visible != visible) { | |
634 | d_ptr->m_visible=visible; |
|
635 | d_ptr->m_visible = visible; | |
635 | d_ptr->emitUpdated(); |
|
636 | d_ptr->emitUpdated(); | |
636 | emit visibleChanged(visible); |
|
637 | emit visibleChanged(visible); | |
637 | } |
|
638 | } | |
@@ -681,7 +682,7 void QAbstractAxis::setMax(const QVariant &max) | |||||
681 | */ |
|
682 | */ | |
682 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
683 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) | |
683 | { |
|
684 | { | |
684 | d_ptr->setRange(min,max); |
|
685 | d_ptr->setRange(min, max); | |
685 | } |
|
686 | } | |
686 |
|
687 | |||
687 |
|
688 | |||
@@ -700,25 +701,25 Qt::Alignment QAbstractAxis::alignment() const | |||||
700 |
|
701 | |||
701 | void QAbstractAxis::setAlignment(Qt::Alignment alignment) |
|
702 | void QAbstractAxis::setAlignment(Qt::Alignment alignment) | |
702 | { |
|
703 | { | |
703 | d_ptr->m_alignment=alignment; |
|
704 | d_ptr->m_alignment = alignment; | |
704 | } |
|
705 | } | |
705 |
|
706 | |||
706 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
707 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
707 |
|
708 | |||
708 |
QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* |
|
709 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) | |
709 | q_ptr(q), |
|
710 | : q_ptr(q), | |
710 | m_orientation(Qt::Orientation(0)), |
|
711 | m_orientation(Qt::Orientation(0)), | |
711 | m_alignment(0), |
|
712 | m_alignment(0), | |
712 | m_dataset(0), |
|
713 | m_dataset(0), | |
713 | m_visible(true), |
|
714 | m_visible(true), | |
714 | m_arrowVisible(true), |
|
715 | m_arrowVisible(true), | |
715 | m_gridLineVisible(true), |
|
716 | m_gridLineVisible(true), | |
716 | m_labelsVisible(true), |
|
717 | m_labelsVisible(true), | |
717 | m_labelsAngle(0), |
|
718 | m_labelsAngle(0), | |
718 | m_shadesVisible(false), |
|
719 | m_shadesVisible(false), | |
719 | m_shadesBrush(Qt::SolidPattern), |
|
720 | m_shadesBrush(Qt::SolidPattern), | |
720 | m_shadesOpacity(1.0), |
|
721 | m_shadesOpacity(1.0), | |
721 | m_dirty(false) |
|
722 | m_dirty(false) | |
722 | { |
|
723 | { | |
723 |
|
724 | |||
724 | } |
|
725 | } | |
@@ -730,24 +731,24 QAbstractAxisPrivate::~QAbstractAxisPrivate() | |||||
730 |
|
731 | |||
731 | void QAbstractAxisPrivate::emitUpdated() |
|
732 | void QAbstractAxisPrivate::emitUpdated() | |
732 | { |
|
733 | { | |
733 | if(!m_dirty){ |
|
734 | if (!m_dirty) { | |
734 | m_dirty=true; |
|
735 | m_dirty = true; | |
735 | emit updated(); |
|
736 | emit updated(); | |
736 | } |
|
737 | } | |
737 | } |
|
738 | } | |
738 |
|
739 | |||
739 | void QAbstractAxisPrivate::setDirty(bool dirty) |
|
740 | void QAbstractAxisPrivate::setDirty(bool dirty) | |
740 | { |
|
741 | { | |
741 | m_dirty=dirty; |
|
742 | m_dirty = dirty; | |
742 | } |
|
743 | } | |
743 |
|
744 | |||
744 | void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation) |
|
745 | void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation) | |
745 | { |
|
746 | { | |
746 | m_orientation=orientation; |
|
747 | m_orientation = orientation; | |
747 | if(m_orientation==Qt::Horizontal && !m_alignment) |
|
748 | if (m_orientation == Qt::Horizontal && !m_alignment) | |
748 | m_alignment=Qt::AlignBottom; |
|
749 | m_alignment = Qt::AlignBottom; | |
749 | else if(m_orientation==Qt::Vertical && !m_alignment) |
|
750 | else if (m_orientation == Qt::Vertical && !m_alignment) | |
750 | m_alignment=Qt::AlignLeft; |
|
751 | m_alignment = Qt::AlignLeft; | |
751 | } |
|
752 | } | |
752 |
|
753 | |||
753 |
|
754 |
@@ -125,7 +125,7 public: | |||||
125 |
|
125 | |||
126 | Qt::Orientation orientation() const; |
|
126 | Qt::Orientation orientation() const; | |
127 | Qt::Alignment alignment() const; |
|
127 | Qt::Alignment alignment() const; | |
128 |
void setAlignment( |
|
128 | void setAlignment(Qt::Alignment alignment); | |
129 |
|
129 | |||
130 | //range handling |
|
130 | //range handling | |
131 | void setMin(const QVariant &min); |
|
131 | void setMin(const QVariant &min); |
@@ -30,8 +30,9 | |||||
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 |
ChartValueAxisX::ChartValueAxisX(QValueAxis *axis,ChartPresenter *presenter) |
|
33 | ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, ChartPresenter *presenter) | |
34 | m_tickCount(0),m_axis(axis) |
|
34 | : HorizontalAxis(axis, presenter), | |
|
35 | m_tickCount(0), m_axis(axis) | |||
35 | { |
|
36 | { | |
36 | } |
|
37 | } | |
37 |
|
38 | |||
@@ -41,13 +42,13 ChartValueAxisX::~ChartValueAxisX() | |||||
41 |
|
42 | |||
42 | QVector<qreal> ChartValueAxisX::calculateLayout() const |
|
43 | QVector<qreal> ChartValueAxisX::calculateLayout() const | |
43 | { |
|
44 | { | |
44 | Q_ASSERT(m_tickCount>=2); |
|
45 | Q_ASSERT(m_tickCount >= 2); | |
45 |
|
46 | |||
46 | QVector<qreal> points; |
|
47 | QVector<qreal> points; | |
47 | points.resize(m_tickCount); |
|
48 | points.resize(m_tickCount); | |
48 |
|
49 | |||
49 |
const QRectF& |
|
50 | const QRectF &gridRect = gridGeometry(); | |
50 | const qreal deltaX = gridRect.width()/(m_tickCount-1); |
|
51 | const qreal deltaX = gridRect.width() / (m_tickCount - 1); | |
51 | for (int i = 0; i < m_tickCount; ++i) { |
|
52 | for (int i = 0; i < m_tickCount; ++i) { | |
52 | int x = i * deltaX + gridRect.left(); |
|
53 | int x = i * deltaX + gridRect.left(); | |
53 | points[i] = x; |
|
54 | points[i] = x; | |
@@ -58,7 +59,8 QVector<qreal> ChartValueAxisX::calculateLayout() const | |||||
58 | void ChartValueAxisX::updateGeometry() |
|
59 | void ChartValueAxisX::updateGeometry() | |
59 | { |
|
60 | { | |
60 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
61 | const QVector<qreal>& layout = ChartAxis::layout(); | |
61 |
if(layout.isEmpty()) |
|
62 | if (layout.isEmpty()) | |
|
63 | return; | |||
62 | setLabels(createValueLabels(layout.size())); |
|
64 | setLabels(createValueLabels(layout.size())); | |
63 | HorizontalAxis::updateGeometry(); |
|
65 | HorizontalAxis::updateGeometry(); | |
64 | } |
|
66 | } | |
@@ -73,7 +75,7 void ChartValueAxisX::handleAxisUpdated() | |||||
73 | ChartAxis::handleAxisUpdated(); |
|
75 | ChartAxis::handleAxisUpdated(); | |
74 | } |
|
76 | } | |
75 |
|
77 | |||
76 |
QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF& |
|
78 | QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
77 | { |
|
79 | { | |
78 | Q_UNUSED(constraint) |
|
80 | Q_UNUSED(constraint) | |
79 |
|
81 | |||
@@ -82,28 +84,27 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constraint) c | |||||
82 |
|
84 | |||
83 | QSizeF base = ChartAxis::sizeHint(which, constraint); |
|
85 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |
84 | QStringList ticksList = createValueLabels(m_tickCount); |
|
86 | QStringList ticksList = createValueLabels(m_tickCount); | |
85 | qreal width=0; |
|
87 | qreal width = 0; | |
86 | qreal height=0; |
|
88 | qreal height = 0; | |
87 |
|
89 | |||
88 | switch (which) { |
|
90 | switch (which) { | |
89 | case Qt::MinimumSize:{ |
|
91 | case Qt::MinimumSize: { | |
90 | int count = qMax(ticksList.last().count(),ticksList.first().count()); |
|
92 | int count = qMax(ticksList.last().count(), ticksList.first().count()); | |
91 | width=fn.averageCharWidth()*count; |
|
93 | width = fn.averageCharWidth() * count; | |
92 | height=fn.height()+labelPadding(); |
|
94 | height = fn.height() + labelPadding(); | |
93 | width=qMax(width,base.width()); |
|
95 | width = qMax(width, base.width()); | |
94 | height+=base.height(); |
|
96 | height += base.height(); | |
95 | sh = QSizeF(width,height); |
|
97 | sh = QSizeF(width, height); | |
96 | break; |
|
98 | break; | |
97 | } |
|
99 | } | |
98 | case Qt::PreferredSize:{ |
|
100 | case Qt::PreferredSize: { | |
99 | for (int i = 0; i < ticksList.size(); ++i) |
|
101 | for (int i = 0; i < ticksList.size(); ++i) { | |
100 | { |
|
102 | width += fn.averageCharWidth() * ticksList.at(i).count(); | |
101 | width+=fn.averageCharWidth()*ticksList.at(i).count(); |
|
|||
102 | } |
|
103 | } | |
103 | height=fn.height()+labelPadding(); |
|
104 | height = fn.height() + labelPadding(); | |
104 | width=qMax(width,base.width()); |
|
105 | width = qMax(width, base.width()); | |
105 | height+=base.height(); |
|
106 | height += base.height(); | |
106 | sh = QSizeF(width,height); |
|
107 | sh = QSizeF(width, height); | |
107 | break; |
|
108 | break; | |
108 | } |
|
109 | } | |
109 | default: |
|
110 | default: |
@@ -29,8 +29,10 | |||||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 |
ChartValueAxisY::ChartValueAxisY(QValueAxis *axis,ChartPresenter *presenter) |
|
32 | ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, ChartPresenter *presenter) | |
33 | m_tickCount(0),m_axis(axis) |
|
33 | : VerticalAxis(axis, presenter), | |
|
34 | m_tickCount(0), | |||
|
35 | m_axis(axis) | |||
34 | { |
|
36 | { | |
35 | } |
|
37 | } | |
36 |
|
38 | |||
@@ -40,14 +42,14 ChartValueAxisY::~ChartValueAxisY() | |||||
40 |
|
42 | |||
41 | QVector<qreal> ChartValueAxisY::calculateLayout() const |
|
43 | QVector<qreal> ChartValueAxisY::calculateLayout() const | |
42 | { |
|
44 | { | |
43 | Q_ASSERT(m_tickCount>=2); |
|
45 | Q_ASSERT(m_tickCount >= 2); | |
44 |
|
46 | |||
45 | QVector<qreal> points; |
|
47 | QVector<qreal> points; | |
46 | points.resize(m_tickCount); |
|
48 | points.resize(m_tickCount); | |
47 |
|
49 | |||
48 |
const QRectF& |
|
50 | const QRectF &gridRect = gridGeometry(); | |
49 |
|
51 | |||
50 | const qreal deltaY = gridRect.height()/(m_tickCount-1); |
|
52 | const qreal deltaY = gridRect.height() / (m_tickCount - 1); | |
51 | for (int i = 0; i < m_tickCount; ++i) { |
|
53 | for (int i = 0; i < m_tickCount; ++i) { | |
52 | int y = i * -deltaY + gridRect.bottom(); |
|
54 | int y = i * -deltaY + gridRect.bottom(); | |
53 | points[i] = y; |
|
55 | points[i] = y; | |
@@ -59,7 +61,8 QVector<qreal> ChartValueAxisY::calculateLayout() const | |||||
59 | void ChartValueAxisY::updateGeometry() |
|
61 | void ChartValueAxisY::updateGeometry() | |
60 | { |
|
62 | { | |
61 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
63 | const QVector<qreal> &layout = ChartAxis::layout(); | |
62 |
if(layout.isEmpty()) |
|
64 | if (layout.isEmpty()) | |
|
65 | return; | |||
63 | setLabels(createValueLabels(layout.size())); |
|
66 | setLabels(createValueLabels(layout.size())); | |
64 | VerticalAxis::updateGeometry(); |
|
67 | VerticalAxis::updateGeometry(); | |
65 | } |
|
68 | } | |
@@ -74,7 +77,7 void ChartValueAxisY::handleAxisUpdated() | |||||
74 | ChartAxis::handleAxisUpdated(); |
|
77 | ChartAxis::handleAxisUpdated(); | |
75 | } |
|
78 | } | |
76 |
|
79 | |||
77 |
QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF& |
|
80 | QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
78 | { |
|
81 | { | |
79 | Q_UNUSED(constraint) |
|
82 | Q_UNUSED(constraint) | |
80 |
|
83 | |||
@@ -82,29 +85,27 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constraint) c | |||||
82 | QSizeF sh; |
|
85 | QSizeF sh; | |
83 | QSizeF base = ChartAxis::sizeHint(which, constraint); |
|
86 | QSizeF base = ChartAxis::sizeHint(which, constraint); | |
84 | QStringList ticksList = createValueLabels(m_tickCount); |
|
87 | QStringList ticksList = createValueLabels(m_tickCount); | |
85 | qreal width=0; |
|
88 | qreal width = 0; | |
86 | qreal height=0; |
|
89 | qreal height = 0; | |
87 |
|
90 | |||
88 | switch (which) { |
|
91 | switch (which) { | |
89 | case Qt::MinimumSize: { |
|
92 | case Qt::MinimumSize: { | |
90 | int count = qMax(ticksList.first().count() , ticksList.last().count()); |
|
93 | int count = qMax(ticksList.first().count() , ticksList.last().count()); | |
91 | width=fn.averageCharWidth()*count+labelPadding(); |
|
94 | width = fn.averageCharWidth() * count + labelPadding(); | |
92 | height=fn.height(); |
|
95 | height = fn.height(); | |
93 | height=qMax(height,base.height()); |
|
96 | height = qMax(height, base.height()); | |
94 | width+=base.width(); |
|
97 | width += base.width(); | |
95 | sh = QSizeF(width,height); |
|
98 | sh = QSizeF(width, height); | |
96 | break; |
|
99 | break; | |
97 | } |
|
100 | } | |
98 | case Qt::PreferredSize: |
|
101 | case Qt::PreferredSize: { | |
99 | { |
|
102 | for (int i = 0; i < ticksList.size(); ++i) { | |
100 | for (int i = 0; i < ticksList.size(); ++i) |
|
103 | width = qMax(qreal(fn.averageCharWidth() * ticksList.at(i).count()) + labelPadding(), width); | |
101 | { |
|
104 | height += fn.height(); | |
102 | width=qMax(qreal(fn.averageCharWidth()*ticksList.at(i).count())+labelPadding(),width); |
|
|||
103 | height+=fn.height(); |
|
|||
104 | } |
|
105 | } | |
105 | height=qMax(height,base.height()); |
|
106 | height = qMax(height, base.height()); | |
106 | width+=base.width(); |
|
107 | width += base.width(); | |
107 | sh = QSizeF(width,height); |
|
108 | sh = QSizeF(width, height); | |
108 | break; |
|
109 | break; | |
109 | } |
|
110 | } | |
110 | default: |
|
111 | default: |
@@ -50,7 +50,7 protected: | |||||
50 | void handleAxisUpdated(); |
|
50 | void handleAxisUpdated(); | |
51 | private: |
|
51 | private: | |
52 | int m_tickCount; |
|
52 | int m_tickCount; | |
53 |
QValueAxis* |
|
53 | QValueAxis *m_axis; | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -24,7 +24,8 | |||||
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 |
VerticalAxis::VerticalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis) |
|
27 | VerticalAxis::VerticalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis) | |
|
28 | : ChartAxis(axis, presenter, intervalAxis) | |||
28 | { |
|
29 | { | |
29 |
|
30 | |||
30 | } |
|
31 | } | |
@@ -38,7 +39,8 void VerticalAxis::updateGeometry() | |||||
38 | { |
|
39 | { | |
39 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
40 | const QVector<qreal> &layout = ChartAxis::layout(); | |
40 |
|
41 | |||
41 |
if(layout.isEmpty()) |
|
42 | if (layout.isEmpty()) | |
|
43 | return; | |||
42 |
|
44 | |||
43 | QStringList labelList = labels(); |
|
45 | QStringList labelList = labels(); | |
44 |
|
46 | |||
@@ -50,77 +52,73 void VerticalAxis::updateGeometry() | |||||
50 | Q_ASSERT(labels.size() == labelList.size()); |
|
52 | Q_ASSERT(labels.size() == labelList.size()); | |
51 | Q_ASSERT(layout.size() == labelList.size()); |
|
53 | Q_ASSERT(layout.size() == labelList.size()); | |
52 |
|
54 | |||
53 |
const QRectF& |
|
55 | const QRectF &axisRect = axisGeometry(); | |
54 |
const QRectF& |
|
56 | const QRectF &gridRect = gridGeometry(); | |
55 |
|
57 | |||
56 | qreal height = axisRect.bottom(); |
|
58 | qreal height = axisRect.bottom(); | |
57 |
|
59 | |||
58 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
60 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem *>(axis.at(0)); | |
59 |
|
61 | |||
60 | if (alignment()==Qt::AlignLeft) |
|
62 | if (alignment() == Qt::AlignLeft) | |
61 |
lineItem->setLine( |
|
63 | lineItem->setLine(axisRect.right() , gridRect.top(), axisRect.right(), gridRect.bottom()); | |
62 | else if(alignment()==Qt::AlignRight) |
|
64 | else if (alignment() == Qt::AlignRight) | |
63 |
lineItem->setLine( |
|
65 | lineItem->setLine(axisRect.left() , gridRect.top(), axisRect.left(), gridRect.bottom()); | |
64 |
|
66 | |||
65 | QFontMetrics fn(font()); |
|
67 | QFontMetrics fn(font()); | |
66 |
|
68 | |||
67 | for (int i = 0; i < layout.size(); ++i) { |
|
69 | for (int i = 0; i < layout.size(); ++i) { | |
68 |
|
70 | |||
69 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
71 | QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i)); | |
70 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
72 | QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(axis.at(i + 1)); | |
71 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
73 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i)); | |
72 |
|
74 | |||
73 | //grid line |
|
75 | //grid line | |
74 |
gridItem->setLine( |
|
76 | gridItem->setLine(gridRect.left() , layout[i], gridRect.right(), layout[i]); | |
75 |
|
77 | |||
76 | //label text |
|
78 | //label text | |
77 | QString text = labelList.at(i); |
|
79 | QString text = labelList.at(i); | |
78 |
if (fn.boundingRect(text).width() > axisRect.right() - axisRect.left() - labelPadding() |
|
80 | if (fn.boundingRect(text).width() > axisRect.right() - axisRect.left() - labelPadding()) { | |
79 | { |
|
|||
80 | QString label = text + "..."; |
|
81 | QString label = text + "..."; | |
81 | while (fn.boundingRect(label).width() > axisRect.right() - axisRect.left() - labelPadding() && label.length() > 3) |
|
82 | while (fn.boundingRect(label).width() > axisRect.right() - axisRect.left() - labelPadding() && label.length() > 3) | |
82 | label.remove(label.length() - 4, 1); |
|
83 | label.remove(label.length() - 4, 1); | |
83 | labelItem->setText(label); |
|
84 | labelItem->setText(label); | |
84 | } |
|
85 | } else { | |
85 | else { |
|
|||
86 | labelItem->setText(text); |
|
86 | labelItem->setText(text); | |
87 | } |
|
87 | } | |
88 |
const QRectF& |
|
88 | const QRectF &rect = labelItem->boundingRect(); | |
89 | QPointF center = rect.center(); |
|
89 | QPointF center = rect.center(); | |
90 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
90 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
91 |
|
91 | |||
92 | //ticks and label position |
|
92 | //ticks and label position | |
93 | if (alignment()==Qt::AlignLeft) { |
|
93 | if (alignment() == Qt::AlignLeft) { | |
94 |
labelItem->setPos( |
|
94 | labelItem->setPos(axisRect.right() - rect.width() - labelPadding() , layout[i] - center.y()); | |
95 |
tickItem->setLine( |
|
95 | tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]); | |
96 | } |
|
96 | } else if (alignment() == Qt::AlignRight) { | |
97 | else if(alignment()==Qt::AlignRight) { |
|
97 | labelItem->setPos(axisRect.left() + labelPadding() , layout[i] - center.y()); | |
98 |
|
|
98 | tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]); | |
99 | tickItem->setLine( axisRect.left(),layout[i], axisRect.left()+ labelPadding(),layout[i]); |
|
|||
100 | } |
|
99 | } | |
101 | if(intervalAxis()&& i+1!=layout.size()) { |
|
100 | if (intervalAxis() && i + 1 != layout.size()) { | |
102 | const qreal delta = (layout[i+1] - layout[i])/2; |
|
101 | const qreal delta = (layout[i + 1] - layout[i]) / 2; | |
103 | labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y()); |
|
102 | labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y()); | |
104 | } |
|
103 | } | |
105 |
|
104 | |||
106 | //overlap detection |
|
105 | //overlap detection | |
107 | if(labelItem->pos().y() + rect.height() > height || |
|
106 | if (labelItem->pos().y() + rect.height() > height || | |
108 | labelItem->pos().y() + rect.height() > axisRect.bottom() || |
|
107 | labelItem->pos().y() + rect.height() > axisRect.bottom() || | |
109 | labelItem->pos().y() < axisRect.top()) { |
|
108 | labelItem->pos().y() < axisRect.top()) { | |
110 | labelItem->setVisible(false); |
|
109 | labelItem->setVisible(false); | |
111 | gridItem->setVisible(false); |
|
110 | gridItem->setVisible(false); | |
112 | tickItem->setVisible(false); |
|
111 | tickItem->setVisible(false); | |
113 | } |
|
112 | } else { | |
114 | else { |
|
|||
115 | labelItem->setVisible(true); |
|
113 | labelItem->setVisible(true); | |
116 | gridItem->setVisible(true); |
|
114 | gridItem->setVisible(true); | |
117 | height=labelItem->pos().y(); |
|
115 | height = labelItem->pos().y(); | |
118 | } |
|
116 | } | |
119 |
|
117 | |||
120 | //shades |
|
118 | //shades | |
121 | if ((i+1)%2 && i>1) { |
|
119 | if ((i + 1) % 2 && i > 1) { | |
122 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
120 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1)); | |
123 |
rectItem->setRect( |
|
121 | rectItem->setRect(gridRect.left(), layout[i], gridRect.width(), layout[i - 1] - layout[i]); | |
124 | } |
|
122 | } | |
125 |
|
123 | |||
126 | // check if the grid line and the axis tick should be shown |
|
124 | // check if the grid line and the axis tick should be shown | |
@@ -128,17 +126,17 void VerticalAxis::updateGeometry() | |||||
128 | if (y < gridRect.top() || y > gridRect.bottom()) { |
|
126 | if (y < gridRect.top() || y > gridRect.bottom()) { | |
129 | gridItem->setVisible(false); |
|
127 | gridItem->setVisible(false); | |
130 | tickItem->setVisible(false); |
|
128 | tickItem->setVisible(false); | |
131 |
if( |
|
129 | if (intervalAxis() && (labelItem->pos().y() < gridRect.top() || labelItem->pos().y() + rect.height() > gridRect.bottom())) | |
132 | labelItem->setVisible(false); |
|
130 | labelItem->setVisible(false); | |
133 | } |
|
131 | } | |
134 |
|
132 | |||
135 | } |
|
133 | } | |
136 | //begin/end grid line in case labels between |
|
134 | //begin/end grid line in case labels between | |
137 | if(intervalAxis()) { |
|
135 | if (intervalAxis()) { | |
138 | QGraphicsLineItem *gridLine; |
|
136 | QGraphicsLineItem *gridLine; | |
139 | gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size())); |
|
137 | gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size())); | |
140 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top()); |
|
138 | gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top()); | |
141 | gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1)); |
|
139 | gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size() + 1)); | |
142 | gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom()); |
|
140 | gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom()); | |
143 | } |
|
141 | } | |
144 | } |
|
142 | } |
@@ -282,7 +282,7 void ChartDataSet::removeAxis(QAbstractAxis *axis) | |||||
282 |
|
282 | |||
283 | void ChartDataSet::removeAllSeries() |
|
283 | void ChartDataSet::removeAllSeries() | |
284 | { |
|
284 | { | |
285 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
285 | QList<QAbstractSeries *> series = m_seriesDomainMap.keys(); | |
286 | foreach (QAbstractSeries *s , series) |
|
286 | foreach (QAbstractSeries *s , series) | |
287 | removeSeries(s); |
|
287 | removeSeries(s); | |
288 |
|
288 |
@@ -31,10 +31,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
31 |
|
31 | |||
32 | static const qreal golden_ratio = 0.25; |
|
32 | static const qreal golden_ratio = 0.25; | |
33 |
|
33 | |||
34 |
ChartLayout::ChartLayout(ChartPresenter* |
|
34 | ChartLayout::ChartLayout(ChartPresenter *presenter) | |
35 | m_presenter(presenter), |
|
35 | : m_presenter(presenter), | |
36 | m_margins(20,20,20,20), |
|
36 | m_margins(20, 20, 20, 20), | |
37 | m_minChartRect(0,0,200,200) |
|
37 | m_minChartRect(0, 0, 200, 200) | |
38 | { |
|
38 | { | |
39 |
|
39 | |||
40 | } |
|
40 | } | |
@@ -44,67 +44,65 ChartLayout::~ChartLayout() | |||||
44 |
|
44 | |||
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 |
void ChartLayout::setGeometry(const QRectF& |
|
47 | void ChartLayout::setGeometry(const QRectF &rect) | |
48 | { |
|
48 | { | |
49 | if (!rect.isValid()) |
|
49 | if (!rect.isValid()) | |
50 | return; |
|
50 | return; | |
51 |
|
51 | |||
52 | QList<ChartAxis*> axes = m_presenter->axisItems(); |
|
52 | QList<ChartAxis *> axes = m_presenter->axisItems(); | |
53 | QList<ChartElement*> charts = m_presenter->chartItems(); |
|
53 | QList<ChartElement *> charts = m_presenter->chartItems(); | |
54 |
ChartTitle* |
|
54 | ChartTitle *title = m_presenter->titleElement(); | |
55 |
QLegend* |
|
55 | QLegend *legend = m_presenter->legend(); | |
56 |
ChartBackground* |
|
56 | ChartBackground *background = m_presenter->backgroundElement(); | |
57 |
|
57 | |||
58 | QRectF contentGeometry = calculateBackgroundGeometry(rect,background); |
|
58 | QRectF contentGeometry = calculateBackgroundGeometry(rect, background); | |
59 |
|
59 | |||
60 | contentGeometry = calculateContentGeometry(contentGeometry); |
|
60 | contentGeometry = calculateContentGeometry(contentGeometry); | |
61 |
|
61 | |||
62 |
if (title && title->isVisible()) |
|
62 | if (title && title->isVisible()) | |
63 | contentGeometry = calculateTitleGeometry(contentGeometry,title); |
|
63 | contentGeometry = calculateTitleGeometry(contentGeometry, title); | |
64 | } |
|
|||
65 |
|
64 | |||
66 |
if (legend->isAttachedToChart() && legend->isVisible()) |
|
65 | if (legend->isAttachedToChart() && legend->isVisible()) | |
67 | contentGeometry = calculateLegendGeometry(contentGeometry,legend); |
|
66 | contentGeometry = calculateLegendGeometry(contentGeometry, legend); | |
68 | } |
|
|||
69 |
|
67 | |||
70 | contentGeometry = calculateAxisGeometry(contentGeometry,axes); |
|
68 | contentGeometry = calculateAxisGeometry(contentGeometry, axes); | |
71 |
|
69 | |||
72 | m_chartsRect = calculateChartsGeometry(contentGeometry,charts); |
|
70 | m_chartsRect = calculateChartsGeometry(contentGeometry, charts); | |
73 |
|
71 | |||
74 | QGraphicsLayout::setGeometry(rect); |
|
72 | QGraphicsLayout::setGeometry(rect); | |
75 | } |
|
73 | } | |
76 |
|
74 | |||
77 |
QRectF ChartLayout::calculateContentGeometry(const QRectF& |
|
75 | QRectF ChartLayout::calculateContentGeometry(const QRectF &geometry) const | |
78 | { |
|
76 | { | |
79 | return geometry.adjusted(m_margins.left(),m_margins.top(),-m_margins.right(),-m_margins.bottom()); |
|
77 | return geometry.adjusted(m_margins.left(), m_margins.top(), -m_margins.right(), -m_margins.bottom()); | |
80 | } |
|
78 | } | |
81 |
|
79 | |||
82 |
QRectF ChartLayout::calculateContentMinimum(const QRectF& |
|
80 | QRectF ChartLayout::calculateContentMinimum(const QRectF &minimum) const | |
83 | { |
|
81 | { | |
84 | return minimum.adjusted(0,0,m_margins.left()+m_margins.right(),m_margins.top() + m_margins.bottom()); |
|
82 | return minimum.adjusted(0, 0, m_margins.left() + m_margins.right(), m_margins.top() + m_margins.bottom()); | |
85 | } |
|
83 | } | |
86 |
|
84 | |||
87 |
|
85 | |||
88 |
QRectF ChartLayout::calculateBackgroundGeometry(const QRectF& |
|
86 | QRectF ChartLayout::calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const | |
89 | { |
|
87 | { | |
90 | qreal left, top, right, bottom; |
|
88 | qreal left, top, right, bottom; | |
91 | getContentsMargins(&left, &top, &right, &bottom); |
|
89 | getContentsMargins(&left, &top, &right, &bottom); | |
92 | QRectF backgroundGeometry = geometry.adjusted(left,top,-right,-bottom); |
|
90 | QRectF backgroundGeometry = geometry.adjusted(left, top, -right, -bottom); | |
93 | if(background) background->setRect(backgroundGeometry); |
|
91 | if (background) | |
|
92 | background->setRect(backgroundGeometry); | |||
94 | return backgroundGeometry; |
|
93 | return backgroundGeometry; | |
95 | } |
|
94 | } | |
96 |
|
95 | |||
97 |
QRectF ChartLayout::calculateBackgroundMinimum(const QRectF& |
|
96 | QRectF ChartLayout::calculateBackgroundMinimum(const QRectF &minimum) const | |
98 | { |
|
97 | { | |
99 | qreal left, top, right, bottom; |
|
98 | qreal left, top, right, bottom; | |
100 | getContentsMargins(&left, &top, &right, &bottom); |
|
99 | getContentsMargins(&left, &top, &right, &bottom); | |
101 | return minimum.adjusted(0,0,left + right,top+bottom); |
|
100 | return minimum.adjusted(0, 0, left + right, top + bottom); | |
102 | } |
|
101 | } | |
103 |
|
102 | |||
104 |
|
103 | |||
105 |
QRectF ChartLayout::calculateAxisGeometry(const QRectF& |
|
104 | QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const | |
106 | { |
|
105 | { | |
107 |
|
||||
108 | QSizeF left; |
|
106 | QSizeF left; | |
109 | QSizeF right; |
|
107 | QSizeF right; | |
110 | QSizeF bottom; |
|
108 | QSizeF bottom; | |
@@ -114,77 +112,78 QRectF ChartLayout::calculateAxisGeometry(const QRectF& geometry, const QList<Ch | |||||
114 | int topCount = 0; |
|
112 | int topCount = 0; | |
115 | int bottomCount = 0; |
|
113 | int bottomCount = 0; | |
116 |
|
114 | |||
117 |
foreach(ChartAxis* |
|
115 | foreach (ChartAxis *axis , axes) { | |
118 |
|
116 | |||
119 |
if(!axis->isVisible()) |
|
117 | if (!axis->isVisible()) | |
|
118 | continue; | |||
120 |
|
119 | |||
121 | QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); |
|
120 | QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); | |
122 |
|
121 | |||
123 | switch(axis->alignment()){ |
|
122 | switch (axis->alignment()) { | |
124 | case Qt::AlignLeft: |
|
123 | case Qt::AlignLeft: | |
125 | left.setWidth(left.width()+size.width()); |
|
124 | left.setWidth(left.width() + size.width()); | |
126 | left.setHeight(qMax(left.height(),size.height())); |
|
125 | left.setHeight(qMax(left.height(), size.height())); | |
127 | leftCount++; |
|
126 | leftCount++; | |
128 | break; |
|
127 | break; | |
129 | case Qt::AlignRight: |
|
128 | case Qt::AlignRight: | |
130 | right.setWidth(right.width()+size.width()); |
|
129 | right.setWidth(right.width() + size.width()); | |
131 | right.setHeight(qMax(right.height(),size.height())); |
|
130 | right.setHeight(qMax(right.height(), size.height())); | |
132 | rightCount++; |
|
131 | rightCount++; | |
133 | break; |
|
132 | break; | |
134 | case Qt::AlignTop: |
|
133 | case Qt::AlignTop: | |
135 | top.setWidth(qMax(top.width(),size.width())); |
|
134 | top.setWidth(qMax(top.width(), size.width())); | |
136 | top.setHeight(top.height()+size.height()); |
|
135 | top.setHeight(top.height() + size.height()); | |
137 | topCount++; |
|
136 | topCount++; | |
138 | break; |
|
137 | break; | |
139 | case Qt::AlignBottom: |
|
138 | case Qt::AlignBottom: | |
140 | bottom.setWidth(qMax(bottom.width(),size.width())); |
|
139 | bottom.setWidth(qMax(bottom.width(), size.width())); | |
141 | bottom.setHeight(bottom.height() + size.height()); |
|
140 | bottom.setHeight(bottom.height() + size.height()); | |
142 | bottomCount++; |
|
141 | bottomCount++; | |
143 | break; |
|
142 | break; | |
144 |
|
||||
145 | } |
|
143 | } | |
146 | } |
|
144 | } | |
147 |
|
145 | |||
148 | left.setWidth(qMax(qMax(top.width()/2,bottom.width()/2),left.width())); |
|
146 | left.setWidth(qMax(qMax(top.width() / 2, bottom.width() / 2), left.width())); | |
149 | left.setWidth(qMin(left.width(),golden_ratio*geometry.width())); |
|
147 | left.setWidth(qMin(left.width(), golden_ratio * geometry.width())); | |
150 | right.setWidth(qMax(qMax(top.width()/2,bottom.width()/2),right.width())); |
|
148 | right.setWidth(qMax(qMax(top.width() / 2, bottom.width() / 2), right.width())); | |
151 | right.setWidth(qMin(right.width(),golden_ratio*geometry.width())); |
|
149 | right.setWidth(qMin(right.width(), golden_ratio * geometry.width())); | |
152 | top.setHeight(qMax(qMax(left.height()/2,right.height()/2),top.height())); |
|
150 | top.setHeight(qMax(qMax(left.height() / 2, right.height() / 2), top.height())); | |
153 | bottom.setHeight(qMax(qMax(left.height()/2,right.height()/2),bottom.height())); |
|
151 | bottom.setHeight(qMax(qMax(left.height() / 2, right.height() / 2), bottom.height())); | |
154 |
|
152 | |||
155 | QRectF chartRect = geometry.adjusted(left.width(),top.height(),-right.width(),-bottom.height()); |
|
153 | QRectF chartRect = geometry.adjusted(left.width(), top.height(), -right.width(), -bottom.height()); | |
156 |
|
154 | |||
157 | qreal leftOffset=0; |
|
155 | qreal leftOffset = 0; | |
158 | qreal rightOffset=0; |
|
156 | qreal rightOffset = 0; | |
159 | qreal topOffset=0; |
|
157 | qreal topOffset = 0; | |
160 | qreal bottomOffset=0; |
|
158 | qreal bottomOffset = 0; | |
161 |
|
159 | |||
162 | foreach(ChartAxis* axis , axes) { |
|
160 | foreach(ChartAxis * axis , axes) { | |
163 |
|
161 | |||
164 |
if(!axis->isVisible()) |
|
162 | if (!axis->isVisible()) | |
|
163 | continue; | |||
165 |
|
164 | |||
166 | QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); |
|
165 | QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); | |
167 |
|
166 | |||
168 | switch(axis->alignment()){ |
|
167 | switch (axis->alignment()) { | |
169 | case Qt::AlignLeft:{ |
|
168 | case Qt::AlignLeft: { | |
170 | qreal width = qMin(size.width(),left.width()/leftCount); |
|
169 | qreal width = qMin(size.width(), left.width() / leftCount); | |
171 | leftOffset+=width; |
|
170 | leftOffset += width; | |
172 | axis->setGeometry(QRect(chartRect.left()-leftOffset,chartRect.top()-(size.height()+1)/2,width,chartRect.height()+size.height()+2),chartRect); |
|
171 | axis->setGeometry(QRect(chartRect.left() - leftOffset, chartRect.top() - (size.height() + 1) / 2, width, chartRect.height() + size.height() + 2), chartRect); | |
173 | break; |
|
172 | break; | |
174 | } |
|
173 | } | |
175 | case Qt::AlignRight:{ |
|
174 | case Qt::AlignRight: { | |
176 | qreal width = qMin(size.width(),right.width()/rightCount); |
|
175 | qreal width = qMin(size.width(), right.width() / rightCount); | |
177 | axis->setGeometry(QRect(chartRect.right()+rightOffset,chartRect.top()-(size.height()+1)/2,width,chartRect.height()+size.height()+2),chartRect); |
|
176 | axis->setGeometry(QRect(chartRect.right() + rightOffset, chartRect.top() - (size.height() + 1) / 2, width, chartRect.height() + size.height() + 2), chartRect); | |
178 | rightOffset+=width; |
|
177 | rightOffset += width; | |
179 | break; |
|
178 | break; | |
180 | } |
|
179 | } | |
181 | case Qt::AlignTop: |
|
180 | case Qt::AlignTop: | |
182 | axis->setGeometry(QRect(geometry.left(),chartRect.top()-topOffset - size.height(),geometry.width(),size.height()),chartRect); |
|
181 | axis->setGeometry(QRect(geometry.left(), chartRect.top() - topOffset - size.height(), geometry.width(), size.height()), chartRect); | |
183 | topOffset+=size.height(); |
|
182 | topOffset += size.height(); | |
184 | break; |
|
183 | break; | |
185 | case Qt::AlignBottom: |
|
184 | case Qt::AlignBottom: | |
186 | axis->setGeometry(QRect(geometry.left(),chartRect.bottom()+bottomOffset,geometry.width(),size.height()),chartRect); |
|
185 | axis->setGeometry(QRect(geometry.left(), chartRect.bottom() + bottomOffset, geometry.width(), size.height()), chartRect); | |
187 | bottomOffset+=size.height(); |
|
186 | bottomOffset += size.height(); | |
188 | break; |
|
187 | break; | |
189 | } |
|
188 | } | |
190 | } |
|
189 | } | |
@@ -192,72 +191,73 QRectF ChartLayout::calculateAxisGeometry(const QRectF& geometry, const QList<Ch | |||||
192 | return chartRect; |
|
191 | return chartRect; | |
193 | } |
|
192 | } | |
194 |
|
193 | |||
195 |
QRectF ChartLayout::calculateAxisMinimum(const QRectF& |
|
194 | QRectF ChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxis *>& axes) const | |
196 | { |
|
195 | { | |
197 | QSizeF left; |
|
196 | QSizeF left; | |
198 | QSizeF right; |
|
197 | QSizeF right; | |
199 | QSizeF bottom; |
|
198 | QSizeF bottom; | |
200 | QSizeF top; |
|
199 | QSizeF top; | |
201 |
|
200 | |||
202 |
foreach(ChartAxis* |
|
201 | foreach (ChartAxis *axis , axes) { | |
203 |
|
202 | |||
204 | QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); |
|
203 | QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); | |
205 |
|
204 | |||
206 |
if(!axis->isVisible()) |
|
205 | if (!axis->isVisible()) | |
|
206 | continue; | |||
207 |
|
207 | |||
208 | switch(axis->alignment()) { |
|
208 | switch (axis->alignment()) { | |
209 |
|
|
209 | case Qt::AlignLeft: | |
210 | left.setWidth(left.width()+size.width()); |
|
210 | left.setWidth(left.width() + size.width()); | |
211 | left.setHeight(qMax(left.height()*2,size.height())); |
|
211 | left.setHeight(qMax(left.height() * 2, size.height())); | |
212 | break; |
|
212 | break; | |
213 |
|
|
213 | case Qt::AlignRight: | |
214 | right.setWidth(right.width()+size.width()); |
|
214 | right.setWidth(right.width() + size.width()); | |
215 | right.setHeight(qMax(right.height()*2,size.height())); |
|
215 | right.setHeight(qMax(right.height() * 2, size.height())); | |
216 | break; |
|
216 | break; | |
217 |
|
|
217 | case Qt::AlignTop: | |
218 | top.setWidth(qMax(top.width(),size.width())); |
|
218 | top.setWidth(qMax(top.width(), size.width())); | |
219 | top.setHeight(top.height()+size.height()); |
|
219 | top.setHeight(top.height() + size.height()); | |
220 | break; |
|
220 | break; | |
221 |
|
|
221 | case Qt::AlignBottom: | |
222 | bottom.setWidth(qMax(bottom.width(),size.width())); |
|
222 | bottom.setWidth(qMax(bottom.width(), size.width())); | |
223 | bottom.setHeight(bottom.height() + size.height()); |
|
223 | bottom.setHeight(bottom.height() + size.height()); | |
224 | break; |
|
224 | break; | |
225 | } |
|
225 | } | |
226 | } |
|
226 | } | |
227 | return minimum.adjusted(0,0,left.width() + right.width() + qMax(top.width(),bottom.width()), top.height() + bottom.height() + qMax(left.height(),right.height())); |
|
227 | return minimum.adjusted(0, 0, left.width() + right.width() + qMax(top.width(), bottom.width()), top.height() + bottom.height() + qMax(left.height(), right.height())); | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 |
QRectF ChartLayout::calculateLegendGeometry(const QRectF& |
|
230 | QRectF ChartLayout::calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const | |
231 | { |
|
231 | { | |
232 | QSizeF size = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,-1)); |
|
232 | QSizeF size = legend->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)); | |
233 | QRectF legendRect; |
|
233 | QRectF legendRect; | |
234 | QRectF result; |
|
234 | QRectF result; | |
235 |
|
235 | |||
236 | switch (legend->alignment()) { |
|
236 | switch (legend->alignment()) { | |
237 | case Qt::AlignTop: { |
|
237 | case Qt::AlignTop: { | |
238 | legendRect = QRectF(geometry.topLeft(),QSizeF(geometry.width(),size.height())); |
|
238 | legendRect = QRectF(geometry.topLeft(), QSizeF(geometry.width(), size.height())); | |
239 | result = geometry.adjusted(0,legendRect.height(),0,0); |
|
239 | result = geometry.adjusted(0, legendRect.height(), 0, 0); | |
240 | break; |
|
240 | break; | |
241 | } |
|
241 | } | |
242 | case Qt::AlignBottom: { |
|
242 | case Qt::AlignBottom: { | |
243 | legendRect = QRectF(QPointF(geometry.left(),geometry.bottom()-size.height()),QSizeF(geometry.width(),size.height())); |
|
243 | legendRect = QRectF(QPointF(geometry.left(), geometry.bottom() - size.height()), QSizeF(geometry.width(), size.height())); | |
244 | result = geometry.adjusted(0,0,0,-legendRect.height()); |
|
244 | result = geometry.adjusted(0, 0, 0, -legendRect.height()); | |
245 | break; |
|
245 | break; | |
246 | } |
|
246 | } | |
247 | case Qt::AlignLeft: { |
|
247 | case Qt::AlignLeft: { | |
248 | qreal width = qMin(size.width(),geometry.width()*golden_ratio); |
|
248 | qreal width = qMin(size.width(), geometry.width() * golden_ratio); | |
249 | legendRect = QRectF(geometry.topLeft(),QSizeF(width,geometry.height())); |
|
249 | legendRect = QRectF(geometry.topLeft(), QSizeF(width, geometry.height())); | |
250 | result = geometry.adjusted(width,0,0,0); |
|
250 | result = geometry.adjusted(width, 0, 0, 0); | |
251 | break; |
|
251 | break; | |
252 | } |
|
252 | } | |
253 | case Qt::AlignRight: { |
|
253 | case Qt::AlignRight: { | |
254 | qreal width = qMin(size.width(),geometry.width()*golden_ratio); |
|
254 | qreal width = qMin(size.width(), geometry.width() * golden_ratio); | |
255 | legendRect = QRectF(QPointF(geometry.right()-width,geometry.top()),QSizeF(width,geometry.height())); |
|
255 | legendRect = QRectF(QPointF(geometry.right() - width, geometry.top()), QSizeF(width, geometry.height())); | |
256 | result = geometry.adjusted(0,0,-width,0); |
|
256 | result = geometry.adjusted(0, 0, -width, 0); | |
257 | break; |
|
257 | break; | |
258 | } |
|
258 | } | |
259 | default: { |
|
259 | default: { | |
260 | legendRect = QRectF(0,0,0,0); |
|
260 | legendRect = QRectF(0, 0, 0, 0); | |
261 | result = geometry; |
|
261 | result = geometry; | |
262 | break; |
|
262 | break; | |
263 | } |
|
263 | } | |
@@ -269,59 +269,55 QRectF ChartLayout::calculateLegendGeometry(const QRectF& geometry,QLegend* lege | |||||
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 |
|
271 | |||
272 |
QRectF ChartLayout::calculateChartsGeometry(const QRectF& |
|
272 | QRectF ChartLayout::calculateChartsGeometry(const QRectF &geometry, const QList<ChartElement *>& charts) const | |
273 | { |
|
273 | { | |
274 | Q_ASSERT(geometry.isValid()); |
|
274 | Q_ASSERT(geometry.isValid()); | |
275 |
|
275 | foreach (ChartElement *chart, charts) | ||
276 | foreach(ChartElement* chart, charts) |
|
|||
277 | { |
|
|||
278 | chart->handleGeometryChanged(geometry); |
|
276 | chart->handleGeometryChanged(geometry); | |
279 | } |
|
|||
280 |
|
||||
281 | return geometry; |
|
277 | return geometry; | |
282 | } |
|
278 | } | |
283 |
|
279 | |||
284 |
QRectF ChartLayout::calculateLegendMinimum(const QRectF& |
|
280 | QRectF ChartLayout::calculateLegendMinimum(const QRectF &geometry, QLegend *legend) const | |
285 | { |
|
281 | { | |
286 | QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize,QSizeF(-1,-1)); |
|
282 | QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)); | |
287 | return geometry.adjusted(0,0,minSize.width(),minSize.height()); |
|
283 | return geometry.adjusted(0, 0, minSize.width(), minSize.height()); | |
288 | } |
|
284 | } | |
289 |
|
285 | |||
290 |
QRectF ChartLayout::calculateTitleGeometry(const QRectF& |
|
286 | QRectF ChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const | |
291 | { |
|
287 | { | |
292 | title->setGeometry(geometry); |
|
288 | title->setGeometry(geometry); | |
293 | QPointF center = geometry.center() - title->boundingRect().center(); |
|
289 | QPointF center = geometry.center() - title->boundingRect().center(); | |
294 | title->setPos(center.x(),title->pos().y()); |
|
290 | title->setPos(center.x(), title->pos().y()); | |
295 | return geometry.adjusted(0,title->boundingRect().height(),0,0); |
|
291 | return geometry.adjusted(0, title->boundingRect().height(), 0, 0); | |
296 | } |
|
292 | } | |
297 |
|
293 | |||
298 |
QRectF ChartLayout::calculateTitleMinimum(const QRectF& |
|
294 | QRectF ChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const | |
299 | { |
|
295 | { | |
300 | QSizeF min = title->sizeHint(Qt::MinimumSize); |
|
296 | QSizeF min = title->sizeHint(Qt::MinimumSize); | |
301 | return minimum.adjusted(0,0,min.width(),min.height()); |
|
297 | return minimum.adjusted(0, 0, min.width(), min.height()); | |
302 | } |
|
298 | } | |
303 |
|
299 | |||
304 |
QSizeF ChartLayout::sizeHint |
|
300 | QSizeF ChartLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
305 | { |
|
301 | { | |
306 | Q_UNUSED(constraint); |
|
302 | Q_UNUSED(constraint); | |
307 | if(which == Qt::MinimumSize){ |
|
303 | if (which == Qt::MinimumSize) { | |
308 | QList<ChartAxis*> axes = m_presenter->axisItems(); |
|
304 | QList<ChartAxis *> axes = m_presenter->axisItems(); | |
309 |
ChartTitle* |
|
305 | ChartTitle *title = m_presenter->titleElement(); | |
310 |
QLegend* |
|
306 | QLegend *legend = m_presenter->legend(); | |
311 | QRectF minimumRect(0,0,0,0); |
|
307 | QRectF minimumRect(0, 0, 0, 0); | |
312 | minimumRect = calculateBackgroundMinimum(minimumRect); |
|
308 | minimumRect = calculateBackgroundMinimum(minimumRect); | |
313 | minimumRect = calculateContentMinimum(minimumRect); |
|
309 | minimumRect = calculateContentMinimum(minimumRect); | |
314 | minimumRect = calculateTitleMinimum(minimumRect,title); |
|
310 | minimumRect = calculateTitleMinimum(minimumRect, title); | |
315 | minimumRect = calculateLegendMinimum(minimumRect,legend); |
|
311 | minimumRect = calculateLegendMinimum(minimumRect, legend); | |
316 | minimumRect = calculateAxisMinimum(minimumRect,axes); |
|
312 | minimumRect = calculateAxisMinimum(minimumRect, axes); | |
317 | return minimumRect.united(m_minChartRect).size().toSize(); |
|
313 | return minimumRect.united(m_minChartRect).size().toSize(); | |
318 |
} |
|
314 | } | |
319 |
|
|
315 | return QSize(-1, -1); | |
320 | } |
|
316 | } | |
321 |
|
317 | |||
322 |
void ChartLayout::setMargins(const QMargins& |
|
318 | void ChartLayout::setMargins(const QMargins &margins) | |
323 | { |
|
319 | { | |
324 | if(m_margins != margins){ |
|
320 | if (m_margins != margins) { | |
325 | m_margins = margins; |
|
321 | m_margins = margins; | |
326 | updateGeometry(); |
|
322 | updateGeometry(); | |
327 | } |
|
323 | } |
@@ -37,37 +37,37 class ChartLayout : public QGraphicsLayout | |||||
37 | { |
|
37 | { | |
38 | public: |
|
38 | public: | |
39 |
|
39 | |||
40 |
ChartLayout(ChartPresenter* |
|
40 | ChartLayout(ChartPresenter *presenter); | |
41 | virtual ~ChartLayout(); |
|
41 | virtual ~ChartLayout(); | |
42 |
|
42 | |||
43 |
void setMargins(const QMargins& |
|
43 | void setMargins(const QMargins &margins); | |
44 | QMargins margins() const; |
|
44 | QMargins margins() const; | |
45 |
|
45 | |||
46 |
void setGeometry(const QRectF& |
|
46 | void setGeometry(const QRectF &rect); | |
47 | QRectF chartsGeometry() const { return m_chartsRect;} |
|
47 | QRectF chartsGeometry() const { return m_chartsRect;} | |
48 |
|
48 | |||
49 | protected: |
|
49 | protected: | |
50 |
QSizeF sizeHint |
|
50 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; | |
51 | int count() const { return 0; } |
|
51 | int count() const { return 0; } | |
52 |
QGraphicsLayoutItem* |
|
52 | QGraphicsLayoutItem *itemAt(int) const { return 0; }; | |
53 | void removeAt(int){}; |
|
53 | void removeAt(int) {}; | |
54 |
|
54 | |||
55 | private: |
|
55 | private: | |
56 |
QRectF calculateBackgroundGeometry(const QRectF& |
|
56 | QRectF calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const; | |
57 |
QRectF calculateContentGeometry(const QRectF& |
|
57 | QRectF calculateContentGeometry(const QRectF &geometry) const; | |
58 |
QRectF calculateTitleGeometry(const QRectF& |
|
58 | QRectF calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const; | |
59 |
QRectF calculateChartGeometry(const QRectF& |
|
59 | QRectF calculateChartGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const; | |
60 |
QRectF calculateLegendGeometry(const QRectF& |
|
60 | QRectF calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const; | |
61 |
QRectF calculateAxisGeometry(const QRectF& |
|
61 | QRectF calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const; | |
62 |
QRectF calculateChartsGeometry(const QRectF& |
|
62 | QRectF calculateChartsGeometry(const QRectF &geometry, const QList<ChartElement *>& charts) const; | |
63 |
QRectF calculateBackgroundMinimum(const QRectF& |
|
63 | QRectF calculateBackgroundMinimum(const QRectF &minimum) const; | |
64 |
QRectF calculateContentMinimum(const QRectF& |
|
64 | QRectF calculateContentMinimum(const QRectF &minimum) const; | |
65 |
QRectF calculateTitleMinimum(const QRectF& |
|
65 | QRectF calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const; | |
66 |
QRectF calculateAxisMinimum(const QRectF& |
|
66 | QRectF calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxis *>& axes) const; | |
67 |
QRectF calculateLegendMinimum(const QRectF& |
|
67 | QRectF calculateLegendMinimum(const QRectF &minimum, QLegend *legend) const; | |
68 |
|
68 | |||
69 | private: |
|
69 | private: | |
70 |
ChartPresenter* |
|
70 | ChartPresenter *m_presenter; | |
71 | QMargins m_margins; |
|
71 | QMargins m_margins; | |
72 | QRectF m_minChartRect; |
|
72 | QRectF m_minChartRect; | |
73 | QRectF m_minAxisRect; |
|
73 | QRectF m_minAxisRect; |
@@ -35,15 +35,16 | |||||
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
ChartPresenter::ChartPresenter(QChart* |
|
38 | ChartPresenter::ChartPresenter(QChart *chart, ChartDataSet *dataset) | |
39 | m_chart(chart), |
|
39 | : QObject(chart), | |
40 | m_dataset(dataset), |
|
40 | m_chart(chart), | |
41 | m_chartTheme(0), |
|
41 | m_dataset(dataset), | |
42 | m_options(QChart::NoAnimation), |
|
42 | m_chartTheme(0), | |
43 | m_state(ShowState), |
|
43 | m_options(QChart::NoAnimation), | |
44 | m_layout(new ChartLayout(this)), |
|
44 | m_state(ShowState), | |
45 | m_background(0), |
|
45 | m_layout(new ChartLayout(this)), | |
46 | m_title(0) |
|
46 | m_background(0), | |
|
47 | m_title(0) | |||
47 | { |
|
48 | { | |
48 |
|
49 | |||
49 | } |
|
50 | } | |
@@ -53,17 +54,16 ChartPresenter::~ChartPresenter() | |||||
53 | delete m_chartTheme; |
|
54 | delete m_chartTheme; | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 |
void ChartPresenter::handleAxisAdded(QAbstractAxis* |
|
57 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis, Domain *domain) | |
57 | { |
|
58 | { | |
58 |
ChartAxis* |
|
59 | ChartAxis *item = axis->d_ptr->createGraphics(this); | |
59 | item->setDomain(domain); |
|
60 | item->setDomain(domain); | |
60 |
|
61 | |||
61 |
if(m_options.testFlag(QChart::GridAxisAnimations)) |
|
62 | if (m_options.testFlag(QChart::GridAxisAnimations)) | |
62 | item->setAnimation(new AxisAnimation(item)); |
|
63 | item->setAnimation(new AxisAnimation(item)); | |
63 | } |
|
|||
64 |
|
64 | |||
65 | QObject::connect(domain,SIGNAL(updated()),item,SLOT(handleDomainUpdated())); |
|
65 | QObject::connect(domain, SIGNAL(updated()), item, SLOT(handleDomainUpdated())); | |
66 | QObject::connect(axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleAxisVisibleChanged(bool))); |
|
66 | QObject::connect(axis, SIGNAL(visibleChanged(bool)), this, SLOT(handleAxisVisibleChanged(bool))); | |
67 |
|
67 | |||
68 | //initialize |
|
68 | //initialize | |
69 | domain->emitUpdated(); |
|
69 | domain->emitUpdated(); | |
@@ -76,42 +76,42 void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) | |||||
76 | m_layout->invalidate(); |
|
76 | m_layout->invalidate(); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 |
void ChartPresenter::handleAxisRemoved(QAbstractAxis* |
|
79 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) | |
80 | { |
|
80 | { | |
81 |
ChartAxis* |
|
81 | ChartAxis *item = m_axisItems.take(axis); | |
82 | Q_ASSERT(item); |
|
82 | Q_ASSERT(item); | |
83 | selectVisibleAxis(); |
|
83 | selectVisibleAxis(); | |
84 | item->hide(); |
|
84 | item->hide(); | |
85 | item->disconnect(); |
|
85 | item->disconnect(); | |
86 | QObject::disconnect(this,0,item,0); |
|
86 | QObject::disconnect(this, 0, item, 0); | |
87 | item->deleteLater(); |
|
87 | item->deleteLater(); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 |
|
90 | |||
91 |
void ChartPresenter::handleSeriesAdded(QAbstractSeries* |
|
91 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |
92 | { |
|
92 | { | |
93 | ChartElement *item = series->d_ptr->createGraphics(this); |
|
93 | ChartElement *item = series->d_ptr->createGraphics(this); | |
94 | Q_ASSERT(item); |
|
94 | Q_ASSERT(item); | |
95 | item->setDomain(domain); |
|
95 | item->setDomain(domain); | |
96 |
|
96 | |||
97 | QObject::connect(domain,SIGNAL(updated()),item,SLOT(handleDomainUpdated())); |
|
97 | QObject::connect(domain, SIGNAL(updated()), item, SLOT(handleDomainUpdated())); | |
98 | //initialize |
|
98 | //initialize | |
99 | item->handleDomainUpdated(); |
|
99 | item->handleDomainUpdated(); | |
100 |
|
100 | |||
101 | m_chartItems.insert(series,item); |
|
101 | m_chartItems.insert(series, item); | |
102 | m_layout->invalidate(); |
|
102 | m_layout->invalidate(); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 |
void ChartPresenter::handleSeriesRemoved(QAbstractSeries* |
|
105 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) | |
106 | { |
|
106 | { | |
107 |
ChartElement* |
|
107 | ChartElement *item = m_chartItems.take(series); | |
108 | Q_ASSERT(item); |
|
108 | Q_ASSERT(item); | |
109 | item->deleteLater(); |
|
109 | item->deleteLater(); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void ChartPresenter::selectVisibleAxis() |
|
112 | void ChartPresenter::selectVisibleAxis() | |
113 | { |
|
113 | { | |
114 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
114 | QMapIterator<QAbstractAxis *, ChartAxis *> i(m_axisItems); | |
115 |
|
115 | |||
116 | while (i.hasNext()) { |
|
116 | while (i.hasNext()) { | |
117 | i.next(); |
|
117 | i.next(); | |
@@ -141,27 +141,26 void ChartPresenter::selectVisibleAxis() | |||||
141 |
|
141 | |||
142 | void ChartPresenter::handleAxisVisibleChanged(bool visible) |
|
142 | void ChartPresenter::handleAxisVisibleChanged(bool visible) | |
143 | { |
|
143 | { | |
144 |
QAbstractAxis* |
|
144 | QAbstractAxis *axis = static_cast<QAbstractAxis *>(sender()); | |
145 | Q_ASSERT(axis); |
|
145 | Q_ASSERT(axis); | |
146 | if(visible){ |
|
146 | if (visible) { | |
147 |
|
147 | |||
148 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
148 | QMapIterator<QAbstractAxis *, ChartAxis *> i(m_axisItems); | |
149 |
|
149 | |||
150 | while (i.hasNext()) { |
|
150 | while (i.hasNext()) { | |
151 | i.next(); |
|
151 | i.next(); | |
152 |
if(i.key()==axis) |
|
152 | if (i.key() == axis) | |
153 | continue; |
|
153 | continue; | |
154 | } |
|
154 | if (i.key()->orientation() == axis->orientation()) | |
155 | if(i.key()->orientation()==axis->orientation()) { |
|
155 | i.key()->setVisible(false); | |
156 | i.key()->setVisible(false); |
|
|||
157 | } |
|
|||
158 | } |
|
156 | } | |
159 | } |
|
157 | } | |
160 | } |
|
158 | } | |
161 |
|
159 | |||
162 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) |
|
160 | void ChartPresenter::setTheme(QChart::ChartTheme theme, bool force) | |
163 | { |
|
161 | { | |
164 |
if(m_chartTheme && m_chartTheme->id() == theme) |
|
162 | if (m_chartTheme && m_chartTheme->id() == theme) | |
|
163 | return; | |||
165 | delete m_chartTheme; |
|
164 | delete m_chartTheme; | |
166 | m_chartTheme = ChartTheme::createTheme(theme); |
|
165 | m_chartTheme = ChartTheme::createTheme(theme); | |
167 | m_chartTheme->setForced(force); |
|
166 | m_chartTheme->setForced(force); | |
@@ -182,8 +181,8 QChart::ChartTheme ChartPresenter::theme() | |||||
182 |
|
181 | |||
183 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
182 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
184 | { |
|
183 | { | |
185 | if(m_options!=options) { |
|
184 | if (m_options != options) { | |
186 | m_options=options; |
|
185 | m_options = options; | |
187 | resetAllElements(); |
|
186 | resetAllElements(); | |
188 | } |
|
187 | } | |
189 |
|
188 | |||
@@ -191,37 +190,37 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |||||
191 |
|
190 | |||
192 | void ChartPresenter::resetAllElements() |
|
191 | void ChartPresenter::resetAllElements() | |
193 | { |
|
192 | { | |
194 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
193 | QMapIterator<QAbstractAxis *, ChartAxis *> i(m_axisItems); | |
195 | while (i.hasNext()) { |
|
194 | while (i.hasNext()) { | |
196 |
|
|
195 | i.next(); | |
197 |
|
|
196 | Domain *domain = i.value()->domain(); | |
198 |
|
|
197 | QAbstractAxis *axis = i.key(); | |
199 |
|
|
198 | handleAxisRemoved(axis); | |
200 |
|
|
199 | handleAxisAdded(axis, domain); | |
201 | } |
|
200 | } | |
202 |
|
201 | |||
203 | QMapIterator<QAbstractSeries*, ChartElement*> j(m_chartItems); |
|
202 | QMapIterator<QAbstractSeries *, ChartElement *> j(m_chartItems); | |
204 |
|
|
203 | while (j.hasNext()) { | |
205 |
|
|
204 | j.next(); | |
206 |
|
|
205 | Domain *domain = j.value()->domain(); | |
207 |
|
|
206 | QAbstractSeries *series = j.key(); | |
208 |
|
|
207 | handleSeriesRemoved(series); | |
209 |
|
|
208 | handleSeriesAdded(series, domain); | |
210 |
|
|
209 | } | |
211 |
|
210 | |||
212 |
|
|
211 | layout()->invalidate(); | |
213 | } |
|
212 | } | |
214 |
|
213 | |||
215 | void ChartPresenter::zoomIn(qreal factor) |
|
214 | void ChartPresenter::zoomIn(qreal factor) | |
216 | { |
|
215 | { | |
217 | QRectF rect = m_layout->chartsGeometry(); |
|
216 | QRectF rect = m_layout->chartsGeometry(); | |
218 | rect.setWidth(rect.width()/factor); |
|
217 | rect.setWidth(rect.width() / factor); | |
219 | rect.setHeight(rect.height()/factor); |
|
218 | rect.setHeight(rect.height() / factor); | |
220 | rect.moveCenter(m_layout->chartsGeometry().center()); |
|
219 | rect.moveCenter(m_layout->chartsGeometry().center()); | |
221 | zoomIn(rect); |
|
220 | zoomIn(rect); | |
222 | } |
|
221 | } | |
223 |
|
222 | |||
224 |
void ChartPresenter::zoomIn(const QRectF& |
|
223 | void ChartPresenter::zoomIn(const QRectF &rect) | |
225 | { |
|
224 | { | |
226 | QRectF r = rect.normalized(); |
|
225 | QRectF r = rect.normalized(); | |
227 | r.translate(-m_layout->chartsGeometry().topLeft()); |
|
226 | r.translate(-m_layout->chartsGeometry().topLeft()); | |
@@ -229,8 +228,8 void ChartPresenter::zoomIn(const QRectF& rect) | |||||
229 | return; |
|
228 | return; | |
230 |
|
229 | |||
231 | m_state = ZoomInState; |
|
230 | m_state = ZoomInState; | |
232 | m_statePoint = QPointF(r.center().x()/m_layout->chartsGeometry().width(),r.center().y()/m_layout->chartsGeometry().height()); |
|
231 | m_statePoint = QPointF(r.center().x() / m_layout->chartsGeometry().width(), r.center().y() / m_layout->chartsGeometry().height()); | |
233 | m_dataset->zoomInDomain(r,m_layout->chartsGeometry().size()); |
|
232 | m_dataset->zoomInDomain(r, m_layout->chartsGeometry().size()); | |
234 | m_state = ShowState; |
|
233 | m_state = ShowState; | |
235 | } |
|
234 | } | |
236 |
|
235 | |||
@@ -242,23 +241,23 void ChartPresenter::zoomOut(qreal factor) | |||||
242 | chartRect.setSize(m_layout->chartsGeometry().size()); |
|
241 | chartRect.setSize(m_layout->chartsGeometry().size()); | |
243 |
|
242 | |||
244 | QRectF rect; |
|
243 | QRectF rect; | |
245 | rect.setSize(chartRect.size()/factor); |
|
244 | rect.setSize(chartRect.size() / factor); | |
246 | rect.moveCenter(chartRect.center()); |
|
245 | rect.moveCenter(chartRect.center()); | |
247 | if (!rect.isValid()) |
|
246 | if (!rect.isValid()) | |
248 | return; |
|
247 | return; | |
249 | m_statePoint = QPointF(rect.center().x()/m_layout->chartsGeometry().width(),rect.center().y()/m_layout->chartsGeometry().height()); |
|
248 | m_statePoint = QPointF(rect.center().x() / m_layout->chartsGeometry().width(), rect.center().y() / m_layout->chartsGeometry().height()); | |
250 | m_dataset->zoomOutDomain(rect, chartRect.size()); |
|
249 | m_dataset->zoomOutDomain(rect, chartRect.size()); | |
251 | m_state = ShowState; |
|
250 | m_state = ShowState; | |
252 | } |
|
251 | } | |
253 |
|
252 | |||
254 | void ChartPresenter::scroll(qreal dx,qreal dy) |
|
253 | void ChartPresenter::scroll(qreal dx, qreal dy) | |
255 | { |
|
254 | { | |
256 | if(dx<0) m_state=ScrollLeftState; |
|
255 | if (dx < 0) m_state = ScrollLeftState; | |
257 | if(dx>0) m_state=ScrollRightState; |
|
256 | if (dx > 0) m_state = ScrollRightState; | |
258 | if(dy<0) m_state=ScrollUpState; |
|
257 | if (dy < 0) m_state = ScrollUpState; | |
259 | if(dy>0) m_state=ScrollDownState; |
|
258 | if (dy > 0) m_state = ScrollDownState; | |
260 |
|
259 | |||
261 | m_dataset->scrollDomain(dx,dy,m_layout->chartsGeometry().size()); |
|
260 | m_dataset->scrollDomain(dx, dy, m_layout->chartsGeometry().size()); | |
262 | m_state = ShowState; |
|
261 | m_state = ShowState; | |
263 | } |
|
262 | } | |
264 |
|
263 | |||
@@ -287,21 +286,21 void ChartPresenter::createTitleItem() | |||||
287 |
|
286 | |||
288 | void ChartPresenter::handleAnimationFinished() |
|
287 | void ChartPresenter::handleAnimationFinished() | |
289 | { |
|
288 | { | |
290 | m_animations.removeAll(qobject_cast<ChartAnimation*>(sender())); |
|
289 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); | |
291 |
if(m_animations.empty()) |
|
290 | if (m_animations.empty()) | |
|
291 | emit animationsFinished(); | |||
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 |
void ChartPresenter::startAnimation(ChartAnimation* |
|
294 | void ChartPresenter::startAnimation(ChartAnimation *animation) | |
295 | { |
|
295 | { | |
296 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
296 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); | |
297 | QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection); |
|
297 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); | |
298 |
if(!m_animations.isEmpty()) |
|
298 | if (!m_animations.isEmpty()) | |
299 | m_animations.append(animation); |
|
299 | m_animations.append(animation); | |
300 | } |
|
|||
301 | QTimer::singleShot(0, animation, SLOT(start())); |
|
300 | QTimer::singleShot(0, animation, SLOT(start())); | |
302 | } |
|
301 | } | |
303 |
|
302 | |||
304 |
void ChartPresenter::setBackgroundBrush(const QBrush& |
|
303 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) | |
305 | { |
|
304 | { | |
306 | createBackgroundItem(); |
|
305 | createBackgroundItem(); | |
307 | m_background->setBrush(brush); |
|
306 | m_background->setBrush(brush); | |
@@ -310,11 +309,12 void ChartPresenter::setBackgroundBrush(const QBrush& brush) | |||||
310 |
|
309 | |||
311 | QBrush ChartPresenter::backgroundBrush() const |
|
310 | QBrush ChartPresenter::backgroundBrush() const | |
312 | { |
|
311 | { | |
313 |
if (!m_background) |
|
312 | if (!m_background) | |
|
313 | return QBrush(); | |||
314 | return m_background->brush(); |
|
314 | return m_background->brush(); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 |
void ChartPresenter::setBackgroundPen(const QPen& |
|
317 | void ChartPresenter::setBackgroundPen(const QPen &pen) | |
318 | { |
|
318 | { | |
319 | createBackgroundItem(); |
|
319 | createBackgroundItem(); | |
320 | m_background->setPen(pen); |
|
320 | m_background->setPen(pen); | |
@@ -323,11 +323,12 void ChartPresenter::setBackgroundPen(const QPen& pen) | |||||
323 |
|
323 | |||
324 | QPen ChartPresenter::backgroundPen() const |
|
324 | QPen ChartPresenter::backgroundPen() const | |
325 | { |
|
325 | { | |
326 |
if (!m_background) |
|
326 | if (!m_background) | |
|
327 | return QPen(); | |||
327 | return m_background->pen(); |
|
328 | return m_background->pen(); | |
328 | } |
|
329 | } | |
329 |
|
330 | |||
330 |
void ChartPresenter::setTitle(const QString& |
|
331 | void ChartPresenter::setTitle(const QString &title) | |
331 | { |
|
332 | { | |
332 | createTitleItem(); |
|
333 | createTitleItem(); | |
333 | m_title->setText(title); |
|
334 | m_title->setText(title); | |
@@ -336,11 +337,12 void ChartPresenter::setTitle(const QString& title) | |||||
336 |
|
337 | |||
337 | QString ChartPresenter::title() const |
|
338 | QString ChartPresenter::title() const | |
338 | { |
|
339 | { | |
339 |
if (!m_title) |
|
340 | if (!m_title) | |
|
341 | return QString(); | |||
340 | return m_title->text(); |
|
342 | return m_title->text(); | |
341 | } |
|
343 | } | |
342 |
|
344 | |||
343 |
void ChartPresenter::setTitleFont(const QFont& |
|
345 | void ChartPresenter::setTitleFont(const QFont &font) | |
344 | { |
|
346 | { | |
345 | createTitleItem(); |
|
347 | createTitleItem(); | |
346 | m_title->setFont(font); |
|
348 | m_title->setFont(font); | |
@@ -349,7 +351,8 void ChartPresenter::setTitleFont(const QFont& font) | |||||
349 |
|
351 | |||
350 | QFont ChartPresenter::titleFont() const |
|
352 | QFont ChartPresenter::titleFont() const | |
351 | { |
|
353 | { | |
352 |
if (!m_title) |
|
354 | if (!m_title) | |
|
355 | return QFont(); | |||
353 | return m_title->font(); |
|
356 | return m_title->font(); | |
354 | } |
|
357 | } | |
355 |
|
358 | |||
@@ -362,7 +365,8 void ChartPresenter::setTitleBrush(const QBrush &brush) | |||||
362 |
|
365 | |||
363 | QBrush ChartPresenter::titleBrush() const |
|
366 | QBrush ChartPresenter::titleBrush() const | |
364 | { |
|
367 | { | |
365 |
if (!m_title) |
|
368 | if (!m_title) | |
|
369 | return QBrush(); | |||
366 | return m_title->brush(); |
|
370 | return m_title->brush(); | |
367 | } |
|
371 | } | |
368 |
|
372 | |||
@@ -375,7 +379,8 void ChartPresenter::setBackgroundVisible(bool visible) | |||||
375 |
|
379 | |||
376 | bool ChartPresenter::isBackgroundVisible() const |
|
380 | bool ChartPresenter::isBackgroundVisible() const | |
377 | { |
|
381 | { | |
378 |
if (!m_background) |
|
382 | if (!m_background) | |
|
383 | return false; | |||
379 | return m_background->isVisible(); |
|
384 | return m_background->isVisible(); | |
380 | } |
|
385 | } | |
381 |
|
386 | |||
@@ -387,17 +392,18 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) | |||||
387 |
|
392 | |||
388 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
393 | bool ChartPresenter::isBackgroundDropShadowEnabled() const | |
389 | { |
|
394 | { | |
390 |
if (!m_background) |
|
395 | if (!m_background) | |
|
396 | return false; | |||
391 | return m_background->isDropShadowEnabled(); |
|
397 | return m_background->isDropShadowEnabled(); | |
392 | } |
|
398 | } | |
393 |
|
399 | |||
394 |
|
400 | |||
395 |
ChartLayout* |
|
401 | ChartLayout *ChartPresenter::layout() | |
396 | { |
|
402 | { | |
397 | return m_layout; |
|
403 | return m_layout; | |
398 | } |
|
404 | } | |
399 |
|
405 | |||
400 |
QLegend* |
|
406 | QLegend *ChartPresenter::legend() | |
401 | { |
|
407 | { | |
402 | return m_chart->legend(); |
|
408 | return m_chart->legend(); | |
403 | } |
|
409 | } | |
@@ -407,22 +413,22 void ChartPresenter::setVisible(bool visible) | |||||
407 | m_chart->setVisible(visible); |
|
413 | m_chart->setVisible(visible); | |
408 | } |
|
414 | } | |
409 |
|
415 | |||
410 |
ChartBackground* |
|
416 | ChartBackground *ChartPresenter::backgroundElement() | |
411 | { |
|
417 | { | |
412 | return m_background; |
|
418 | return m_background; | |
413 | } |
|
419 | } | |
414 |
|
420 | |||
415 | QList<ChartAxis*> ChartPresenter::axisItems() const |
|
421 | QList<ChartAxis *> ChartPresenter::axisItems() const | |
416 | { |
|
422 | { | |
417 | return m_axisItems.values(); |
|
423 | return m_axisItems.values(); | |
418 | } |
|
424 | } | |
419 |
|
425 | |||
420 | QList<ChartElement*> ChartPresenter::chartItems() const |
|
426 | QList<ChartElement *> ChartPresenter::chartItems() const | |
421 | { |
|
427 | { | |
422 | return m_chartItems.values(); |
|
428 | return m_chartItems.values(); | |
423 | } |
|
429 | } | |
424 |
|
430 | |||
425 |
ChartTitle* |
|
431 | ChartTitle *ChartPresenter::titleElement() | |
426 | { |
|
432 | { | |
427 | return m_title; |
|
433 | return m_title; | |
428 | } |
|
434 | } |
@@ -78,29 +78,29 public: | |||||
78 | ZoomOutState |
|
78 | ZoomOutState | |
79 | }; |
|
79 | }; | |
80 |
|
80 | |||
81 |
ChartPresenter(QChart* |
|
81 | ChartPresenter(QChart *chart, ChartDataSet *dataset); | |
82 | virtual ~ChartPresenter(); |
|
82 | virtual ~ChartPresenter(); | |
83 |
|
83 | |||
84 | ChartTheme *chartTheme() const { return m_chartTheme; } |
|
84 | ChartTheme *chartTheme() const { return m_chartTheme; } | |
85 | ChartDataSet *dataSet() const { return m_dataset; } |
|
85 | ChartDataSet *dataSet() const { return m_dataset; } | |
86 |
QGraphicsItem* |
|
86 | QGraphicsItem *rootItem() const { return m_chart; } | |
87 |
ChartBackground* |
|
87 | ChartBackground *backgroundElement(); | |
88 |
ChartTitle* |
|
88 | ChartTitle *titleElement(); | |
89 | QList<ChartAxis*> axisItems() const; |
|
89 | QList<ChartAxis *> axisItems() const; | |
90 | QList<ChartElement*> chartItems() const; |
|
90 | QList<ChartElement *> chartItems() const; | |
91 |
|
91 | |||
92 |
QLegend* |
|
92 | QLegend *legend(); | |
93 |
|
93 | |||
94 |
void setBackgroundBrush(const QBrush& |
|
94 | void setBackgroundBrush(const QBrush &brush); | |
95 | QBrush backgroundBrush() const; |
|
95 | QBrush backgroundBrush() const; | |
96 |
|
96 | |||
97 |
void setBackgroundPen(const QPen& |
|
97 | void setBackgroundPen(const QPen &pen); | |
98 | QPen backgroundPen() const; |
|
98 | QPen backgroundPen() const; | |
99 |
|
99 | |||
100 |
void setTitle(const QString& |
|
100 | void setTitle(const QString &title); | |
101 | QString title() const; |
|
101 | QString title() const; | |
102 |
|
102 | |||
103 |
void setTitleFont(const QFont& |
|
103 | void setTitleFont(const QFont &font); | |
104 | QFont titleFont() const; |
|
104 | QFont titleFont() const; | |
105 |
|
105 | |||
106 | void setTitleBrush(const QBrush &brush); |
|
106 | void setTitleBrush(const QBrush &brush); | |
@@ -114,24 +114,24 public: | |||||
114 |
|
114 | |||
115 | void setVisible(bool visible); |
|
115 | void setVisible(bool visible); | |
116 |
|
116 | |||
117 | void setTheme(QChart::ChartTheme theme,bool force = true); |
|
117 | void setTheme(QChart::ChartTheme theme, bool force = true); | |
118 | QChart::ChartTheme theme(); |
|
118 | QChart::ChartTheme theme(); | |
119 |
|
119 | |||
120 | void setAnimationOptions(QChart::AnimationOptions options); |
|
120 | void setAnimationOptions(QChart::AnimationOptions options); | |
121 | QChart::AnimationOptions animationOptions() const; |
|
121 | QChart::AnimationOptions animationOptions() const; | |
122 |
|
122 | |||
123 | void zoomIn(qreal factor); |
|
123 | void zoomIn(qreal factor); | |
124 |
void zoomIn(const QRectF& |
|
124 | void zoomIn(const QRectF &rect); | |
125 | void zoomOut(qreal factor); |
|
125 | void zoomOut(qreal factor); | |
126 | void scroll(qreal dx,qreal dy); |
|
126 | void scroll(qreal dx, qreal dy); | |
127 |
|
127 | |||
128 |
void startAnimation(ChartAnimation* |
|
128 | void startAnimation(ChartAnimation *animation); | |
129 | State state() const { return m_state; } |
|
129 | State state() const { return m_state; } | |
130 | QPointF statePoint() const { return m_statePoint; } |
|
130 | QPointF statePoint() const { return m_statePoint; } | |
131 |
|
131 | |||
132 | void resetAllElements(); |
|
132 | void resetAllElements(); | |
133 |
|
133 | |||
134 |
ChartLayout* |
|
134 | ChartLayout *layout(); | |
135 |
|
135 | |||
136 | private: |
|
136 | private: | |
137 | void createBackgroundItem(); |
|
137 | void createBackgroundItem(); | |
@@ -139,10 +139,10 private: | |||||
139 | void selectVisibleAxis(); |
|
139 | void selectVisibleAxis(); | |
140 |
|
140 | |||
141 | public Q_SLOTS: |
|
141 | public Q_SLOTS: | |
142 |
void handleSeriesAdded(QAbstractSeries* |
|
142 | void handleSeriesAdded(QAbstractSeries *series, Domain *domain); | |
143 |
void handleSeriesRemoved(QAbstractSeries* |
|
143 | void handleSeriesRemoved(QAbstractSeries *series); | |
144 |
void handleAxisAdded(QAbstractAxis* |
|
144 | void handleAxisAdded(QAbstractAxis *axis, Domain *domain); | |
145 |
void handleAxisRemoved(QAbstractAxis* |
|
145 | void handleAxisRemoved(QAbstractAxis *axis); | |
146 | void handleAxisVisibleChanged(bool visible); |
|
146 | void handleAxisVisibleChanged(bool visible); | |
147 |
|
147 | |||
148 | private Q_SLOTS: |
|
148 | private Q_SLOTS: | |
@@ -152,18 +152,18 Q_SIGNALS: | |||||
152 | void animationsFinished(); |
|
152 | void animationsFinished(); | |
153 |
|
153 | |||
154 | private: |
|
154 | private: | |
155 |
QChart* |
|
155 | QChart *m_chart; | |
156 |
ChartDataSet* |
|
156 | ChartDataSet *m_dataset; | |
157 | ChartTheme *m_chartTheme; |
|
157 | ChartTheme *m_chartTheme; | |
158 | QMap<QAbstractSeries*, ChartElement*> m_chartItems; |
|
158 | QMap<QAbstractSeries *, ChartElement *> m_chartItems; | |
159 | QMap<QAbstractAxis*, ChartAxis*> m_axisItems; |
|
159 | QMap<QAbstractAxis *, ChartAxis *> m_axisItems; | |
160 | QChart::AnimationOptions m_options; |
|
160 | QChart::AnimationOptions m_options; | |
161 | State m_state; |
|
161 | State m_state; | |
162 | QPointF m_statePoint; |
|
162 | QPointF m_statePoint; | |
163 | QList<ChartAnimation*> m_animations; |
|
163 | QList<ChartAnimation *> m_animations; | |
164 |
ChartLayout* |
|
164 | ChartLayout *m_layout; | |
165 |
ChartBackground* |
|
165 | ChartBackground *m_background; | |
166 |
ChartTitle* |
|
166 | ChartTitle *m_title; | |
167 | }; |
|
167 | }; | |
168 |
|
168 | |||
169 | QTCOMMERCIALCHART_END_NAMESPACE |
|
169 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -128,25 +128,25 void LegendLayout::setAttachedGeometry(const QRectF &rect) | |||||
128 | switch (m_legend->alignment()) { |
|
128 | switch (m_legend->alignment()) { | |
129 | case Qt::AlignTop: |
|
129 | case Qt::AlignTop: | |
130 | case Qt::AlignBottom: { |
|
130 | case Qt::AlignBottom: { | |
131 |
|
|
131 | QPointF point(0, 0); | |
132 |
|
|
132 | foreach (LegendMarker *marker, m_legend->d_ptr->markers()) { | |
133 |
|
|
133 | if (marker->isVisible()) { | |
134 |
|
|
134 | marker->setGeometry(geometry); | |
135 |
|
|
135 | marker->setPos(point.x(), geometry.height() / 2 - marker->boundingRect().height() / 2); | |
136 |
|
|
136 | const QRectF &rect = marker->boundingRect(); | |
137 |
|
|
137 | size = size.expandedTo(rect.size()); | |
138 |
|
|
138 | qreal w = rect.width(); | |
139 |
|
|
139 | m_width += w; | |
140 |
|
|
140 | point.setX(point.x() + w); | |
141 | } |
|
|||
142 | } |
|
141 | } | |
143 | if (m_width < geometry.width()) |
|
|||
144 | m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top()); |
|
|||
145 | else |
|
|||
146 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
|||
147 | m_height = size.height(); |
|
|||
148 | } |
|
142 | } | |
149 | break; |
|
143 | if (m_width < geometry.width()) | |
|
144 | m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top()); | |||
|
145 | else | |||
|
146 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |||
|
147 | m_height = size.height(); | |||
|
148 | } | |||
|
149 | break; | |||
150 | case Qt::AlignLeft: |
|
150 | case Qt::AlignLeft: | |
151 | case Qt::AlignRight: { |
|
151 | case Qt::AlignRight: { | |
152 | QPointF point(0, 0); |
|
152 | QPointF point(0, 0); | |
@@ -168,7 +168,7 void LegendLayout::setAttachedGeometry(const QRectF &rect) | |||||
168 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
168 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
169 | m_width = size.width(); |
|
169 | m_width = size.width(); | |
170 | break; |
|
170 | break; | |
171 |
|
|
171 | } | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | m_minOffsetX = -left; |
|
174 | m_minOffsetX = -left; | |
@@ -203,143 +203,143 void LegendLayout::setDettachedGeometry(const QRectF &rect) | |||||
203 |
|
203 | |||
204 | switch (m_legend->alignment()) { |
|
204 | switch (m_legend->alignment()) { | |
205 | case Qt::AlignTop: { |
|
205 | case Qt::AlignTop: { | |
206 |
|
|
206 | QPointF point(0, 0); | |
207 |
|
|
207 | m_width = 0; | |
208 |
|
|
208 | m_height = 0; | |
209 |
|
|
209 | for (int i = 0; i < markers.count(); i++) { | |
210 |
|
|
210 | LegendMarker *marker = markers.at(i); | |
211 |
|
|
211 | if (marker->isVisible()) { | |
212 |
|
|
212 | marker->setGeometry(geometry); | |
213 |
|
|
213 | marker->setPos(point.x(), point.y()); | |
214 |
|
|
214 | const QRectF &boundingRect = marker->boundingRect(); | |
215 |
|
|
215 | qreal w = boundingRect.width(); | |
216 |
|
|
216 | qreal h = boundingRect.height(); | |
217 |
|
|
217 | m_width = qMax(m_width, w); | |
218 |
|
|
218 | m_height = qMax(m_height, h); | |
219 |
|
|
219 | point.setX(point.x() + w); | |
220 |
|
|
220 | if (point.x() + w > geometry.left() + geometry.width() - right) { | |
221 |
|
|
221 | // Next item would go off rect. | |
222 |
|
|
222 | point.setX(0); | |
223 |
|
|
223 | point.setY(point.y() + h); | |
224 |
|
|
224 | if (i + 1 < markers.count()) { | |
225 |
|
|
225 | m_height += h; | |
226 | } |
|
|||
227 | } |
|
226 | } | |
228 | } |
|
227 | } | |
229 | } |
|
228 | } | |
230 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
|||
231 |
|
||||
232 | m_minOffsetX = -left; |
|
|||
233 | m_minOffsetY = -top; |
|
|||
234 | m_maxOffsetX = m_width - geometry.width() - right; |
|
|||
235 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
|||
236 | } |
|
229 | } | |
237 | break; |
|
230 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
|
231 | ||||
|
232 | m_minOffsetX = -left; | |||
|
233 | m_minOffsetY = -top; | |||
|
234 | m_maxOffsetX = m_width - geometry.width() - right; | |||
|
235 | m_maxOffsetY = m_height - geometry.height() - bottom; | |||
|
236 | } | |||
|
237 | break; | |||
238 | case Qt::AlignBottom: { |
|
238 | case Qt::AlignBottom: { | |
239 |
|
|
239 | QPointF point(0, geometry.height()); | |
240 |
|
|
240 | m_width = 0; | |
241 |
|
|
241 | m_height = 0; | |
242 |
|
|
242 | for (int i = 0; i < markers.count(); i++) { | |
243 |
|
|
243 | LegendMarker *marker = markers.at(i); | |
244 |
|
|
244 | if (marker->isVisible()) { | |
245 |
|
|
245 | marker->setGeometry(geometry); | |
246 |
|
|
246 | const QRectF &boundingRect = marker->boundingRect(); | |
247 |
|
|
247 | qreal w = boundingRect.width(); | |
248 |
|
|
248 | qreal h = boundingRect.height(); | |
249 |
|
|
249 | m_width = qMax(m_width, w); | |
250 |
|
|
250 | m_height = qMax(m_height, h); | |
251 |
|
|
251 | marker->setPos(point.x(), point.y() - h); | |
252 |
|
|
252 | point.setX(point.x() + w); | |
253 |
|
|
253 | if (point.x() + w > geometry.left() + geometry.width() - right) { | |
254 |
|
|
254 | // Next item would go off rect. | |
255 |
|
|
255 | point.setX(0); | |
256 |
|
|
256 | point.setY(point.y() - h); | |
257 |
|
|
257 | if (i + 1 < markers.count()) { | |
258 |
|
|
258 | m_height += h; | |
259 | } |
|
|||
260 | } |
|
259 | } | |
261 | } |
|
260 | } | |
262 | } |
|
261 | } | |
263 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
|||
264 |
|
||||
265 | m_minOffsetX = -left; |
|
|||
266 | m_minOffsetY = -m_height + geometry.height() - top; |
|
|||
267 | m_maxOffsetX = m_width - geometry.width() - right; |
|
|||
268 | m_maxOffsetY = -bottom; |
|
|||
269 | } |
|
262 | } | |
270 | break; |
|
263 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |
|
264 | ||||
|
265 | m_minOffsetX = -left; | |||
|
266 | m_minOffsetY = -m_height + geometry.height() - top; | |||
|
267 | m_maxOffsetX = m_width - geometry.width() - right; | |||
|
268 | m_maxOffsetY = -bottom; | |||
|
269 | } | |||
|
270 | break; | |||
271 | case Qt::AlignLeft: { |
|
271 | case Qt::AlignLeft: { | |
272 |
|
|
272 | QPointF point(0, 0); | |
273 |
|
|
273 | m_width = 0; | |
274 |
|
|
274 | m_height = 0; | |
275 |
|
|
275 | qreal maxWidth = 0; | |
276 |
|
|
276 | for (int i = 0; i < markers.count(); i++) { | |
277 |
|
|
277 | LegendMarker *marker = markers.at(i); | |
278 |
|
|
278 | if (marker->isVisible()) { | |
279 |
|
|
279 | marker->setGeometry(geometry); | |
280 |
|
|
280 | const QRectF &boundingRect = marker->boundingRect(); | |
281 |
|
|
281 | qreal w = boundingRect.width(); | |
282 |
|
|
282 | qreal h = boundingRect.height(); | |
283 |
|
|
283 | m_height = qMax(m_height, h); | |
284 |
|
|
284 | maxWidth = qMax(maxWidth, w); | |
285 |
|
|
285 | marker->setPos(point.x(), point.y()); | |
286 |
|
|
286 | point.setY(point.y() + h); | |
287 |
|
|
287 | if (point.y() + h > geometry.bottom() - bottom) { | |
288 |
|
|
288 | // Next item would go off rect. | |
289 |
|
|
289 | point.setX(point.x() + maxWidth); | |
290 |
|
|
290 | point.setY(0); | |
291 |
|
|
291 | if (i + 1 < markers.count()) { | |
292 |
|
|
292 | m_width += maxWidth; | |
293 |
|
|
293 | maxWidth = 0; | |
294 | } |
|
|||
295 | } |
|
294 | } | |
296 | } |
|
295 | } | |
297 | } |
|
296 | } | |
298 | m_width += maxWidth; |
|
|||
299 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
|||
300 |
|
||||
301 | m_minOffsetX = -left; |
|
|||
302 | m_minOffsetY = -top; |
|
|||
303 | m_maxOffsetX = m_width - geometry.width() - right; |
|
|||
304 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
|||
305 | } |
|
297 | } | |
306 | break; |
|
298 | m_width += maxWidth; | |
|
299 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |||
|
300 | ||||
|
301 | m_minOffsetX = -left; | |||
|
302 | m_minOffsetY = -top; | |||
|
303 | m_maxOffsetX = m_width - geometry.width() - right; | |||
|
304 | m_maxOffsetY = m_height - geometry.height() - bottom; | |||
|
305 | } | |||
|
306 | break; | |||
307 | case Qt::AlignRight: { |
|
307 | case Qt::AlignRight: { | |
308 |
|
|
308 | QPointF point(geometry.width(), 0); | |
309 |
|
|
309 | m_width = 0; | |
310 |
|
|
310 | m_height = 0; | |
311 |
|
|
311 | qreal maxWidth = 0; | |
312 |
|
|
312 | for (int i = 0; i < markers.count(); i++) { | |
313 |
|
|
313 | LegendMarker *marker = markers.at(i); | |
314 |
|
|
314 | if (marker->isVisible()) { | |
315 |
|
|
315 | marker->setGeometry(geometry); | |
316 |
|
|
316 | const QRectF &boundingRect = marker->boundingRect(); | |
317 |
|
|
317 | qreal w = boundingRect.width(); | |
318 |
|
|
318 | qreal h = boundingRect.height(); | |
319 |
|
|
319 | m_height = qMax(m_height, h); | |
320 |
|
|
320 | maxWidth = qMax(maxWidth, w); | |
321 |
|
|
321 | marker->setPos(point.x() - w, point.y()); | |
322 |
|
|
322 | point.setY(point.y() + h); | |
323 |
|
|
323 | if (point.y() + h > geometry.bottom() - bottom) { | |
324 |
|
|
324 | // Next item would go off rect. | |
325 |
|
|
325 | point.setX(point.x() - maxWidth); | |
326 |
|
|
326 | point.setY(0); | |
327 |
|
|
327 | if (i + 1 < markers.count()) { | |
328 |
|
|
328 | m_width += maxWidth; | |
329 |
|
|
329 | maxWidth = 0; | |
330 | } |
|
|||
331 | } |
|
330 | } | |
332 | } |
|
331 | } | |
333 | } |
|
332 | } | |
334 | m_width += maxWidth; |
|
|||
335 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
|||
336 |
|
||||
337 | m_minOffsetX = - m_width + geometry.width() - left; |
|
|||
338 | m_minOffsetY = -top; |
|
|||
339 | m_maxOffsetX = - right; |
|
|||
340 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
|||
341 | } |
|
333 | } | |
342 | break; |
|
334 | m_width += maxWidth; | |
|
335 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); | |||
|
336 | ||||
|
337 | m_minOffsetX = - m_width + geometry.width() - left; | |||
|
338 | m_minOffsetY = -top; | |||
|
339 | m_maxOffsetX = - right; | |||
|
340 | m_maxOffsetY = m_height - geometry.height() - bottom; | |||
|
341 | } | |||
|
342 | break; | |||
343 | default: |
|
343 | default: | |
344 | break; |
|
344 | break; | |
345 | } |
|
345 | } |
@@ -173,7 +173,7 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | |||||
173 | setZValue(ChartPresenter::LegendZValue); |
|
173 | setZValue(ChartPresenter::LegendZValue); | |
174 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
174 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
175 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
175 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
176 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
176 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
177 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
177 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); | |
178 | setLayout(d_ptr->m_layout); |
|
178 | setLayout(d_ptr->m_layout); | |
179 | } |
|
179 | } |
@@ -175,7 +175,7 void PieSliceItem::updateGeometry() | |||||
175 | textCenter = m_data.m_center + offset(centerAngle, m_data.m_radius / 2); |
|
175 | textCenter = m_data.m_center + offset(centerAngle, m_data.m_radius / 2); | |
176 | m_labelTextRect.moveCenter(textCenter); |
|
176 | m_labelTextRect.moveCenter(textCenter); | |
177 | break; |
|
177 | break; | |
178 |
|
|
178 | } | |
179 | case QPieSlice::LabelInsideNormal: { |
|
179 | case QPieSlice::LabelInsideNormal: { | |
180 | QPointF textCenter; |
|
180 | QPointF textCenter; | |
181 | if (m_data.m_holeRadius > 0) |
|
181 | if (m_data.m_holeRadius > 0) | |
@@ -184,7 +184,7 void PieSliceItem::updateGeometry() | |||||
184 | textCenter = m_data.m_center + offset(centerAngle, m_data.m_radius / 2); |
|
184 | textCenter = m_data.m_center + offset(centerAngle, m_data.m_radius / 2); | |
185 | m_labelTextRect.moveCenter(textCenter); |
|
185 | m_labelTextRect.moveCenter(textCenter); | |
186 | break; |
|
186 | break; | |
187 |
|
|
187 | } | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | // bounding rect |
|
190 | // bounding rect |
@@ -26,9 +26,9 | |||||
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 |
QPieModelMapper::QPieModelMapper(QObject *parent) |
|
29 | QPieModelMapper::QPieModelMapper(QObject *parent) | |
30 | QObject(parent), |
|
30 | : QObject(parent), | |
31 | d_ptr(new QPieModelMapperPrivate(this)) |
|
31 | d_ptr(new QPieModelMapperPrivate(this)) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 |
@@ -409,7 +409,7 bool QPieSeries::append(QList<QPieSlice *> slices) | |||||
409 |
|
409 | |||
410 | d->updateDerivativeData(); |
|
410 | d->updateDerivativeData(); | |
411 |
|
411 | |||
412 |
foreach |
|
412 | foreach(QPieSlice * s, slices) { | |
413 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
413 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
414 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
414 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
415 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
415 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
@@ -104,11 +104,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
104 | /*! |
|
104 | /*! | |
105 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
105 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
106 | */ |
|
106 | */ | |
107 |
QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
107 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
108 | d_ptr(new QChartPrivate()) |
|
108 | : QGraphicsWidget(parent, wFlags), | |
|
109 | d_ptr(new QChartPrivate()) | |||
109 | { |
|
110 | { | |
110 | d_ptr->m_dataset = new ChartDataSet(this); |
|
111 | d_ptr->m_dataset = new ChartDataSet(this); | |
111 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
112 | d_ptr->m_presenter = new ChartPresenter(this, d_ptr->m_dataset); | |
112 | d_ptr->createConnections(); |
|
113 | d_ptr->createConnections(); | |
113 | d_ptr->m_legend = new LegendScroller(this); |
|
114 | d_ptr->m_legend = new LegendScroller(this); | |
114 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
115 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
@@ -124,7 +125,7 QChart::~QChart() | |||||
124 | //delete first presenter , since this is a root of all the graphical items |
|
125 | //delete first presenter , since this is a root of all the graphical items | |
125 | setLayout(0); |
|
126 | setLayout(0); | |
126 | delete d_ptr->m_presenter; |
|
127 | delete d_ptr->m_presenter; | |
127 | d_ptr->m_presenter=0; |
|
128 | d_ptr->m_presenter = 0; | |
128 | } |
|
129 | } | |
129 |
|
130 | |||
130 | /*! |
|
131 | /*! | |
@@ -165,7 +166,7 void QChart::removeAllSeries() | |||||
165 | /*! |
|
166 | /*! | |
166 | Sets the \a brush that is used for painting the background of the chart area. |
|
167 | Sets the \a brush that is used for painting the background of the chart area. | |
167 | */ |
|
168 | */ | |
168 |
void QChart::setBackgroundBrush(const QBrush& |
|
169 | void QChart::setBackgroundBrush(const QBrush &brush) | |
169 | { |
|
170 | { | |
170 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
171 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
171 | } |
|
172 | } | |
@@ -181,7 +182,7 QBrush QChart::backgroundBrush() const | |||||
181 | /*! |
|
182 | /*! | |
182 | Sets the \a pen that is used for painting the background of the chart area. |
|
183 | Sets the \a pen that is used for painting the background of the chart area. | |
183 | */ |
|
184 | */ | |
184 |
void QChart::setBackgroundPen(const QPen& |
|
185 | void QChart::setBackgroundPen(const QPen &pen) | |
185 | { |
|
186 | { | |
186 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
187 | d_ptr->m_presenter->setBackgroundPen(pen); | |
187 | } |
|
188 | } | |
@@ -197,7 +198,7 QPen QChart::backgroundPen() const | |||||
197 | /*! |
|
198 | /*! | |
198 | Sets the chart \a title. The description text that is drawn above the chart. |
|
199 | Sets the chart \a title. The description text that is drawn above the chart. | |
199 | */ |
|
200 | */ | |
200 |
void QChart::setTitle(const QString& |
|
201 | void QChart::setTitle(const QString &title) | |
201 | { |
|
202 | { | |
202 | d_ptr->m_presenter->setTitle(title); |
|
203 | d_ptr->m_presenter->setTitle(title); | |
203 | } |
|
204 | } | |
@@ -213,7 +214,7 QString QChart::title() const | |||||
213 | /*! |
|
214 | /*! | |
214 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
215 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
215 | */ |
|
216 | */ | |
216 |
void QChart::setTitleFont(const QFont& |
|
217 | void QChart::setTitleFont(const QFont &font) | |
217 | { |
|
218 | { | |
218 | d_ptr->m_presenter->setTitleFont(font); |
|
219 | d_ptr->m_presenter->setTitleFont(font); | |
219 | } |
|
220 | } | |
@@ -263,9 +264,10 void QChart::zoomIn() | |||||
263 | /*! |
|
264 | /*! | |
264 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
265 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
265 | */ |
|
266 | */ | |
266 |
void QChart::zoomIn(const QRectF& |
|
267 | void QChart::zoomIn(const QRectF &rect) | |
267 | { |
|
268 | { | |
268 |
if (!rect.isValid()) |
|
269 | if (!rect.isValid()) | |
|
270 | return; | |||
269 | d_ptr->m_presenter->zoomIn(rect); |
|
271 | d_ptr->m_presenter->zoomIn(rect); | |
270 | } |
|
272 | } | |
271 |
|
273 | |||
@@ -303,7 +305,7 void QChart::zoom(qreal factor) | |||||
303 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
305 | Returns the pointer to the x axis object of the chart asociated with the specified \a series | |
304 | If no series is provided then pointer to currently visible axis is provided |
|
306 | If no series is provided then pointer to currently visible axis is provided | |
305 | */ |
|
307 | */ | |
306 |
QAbstractAxis* |
|
308 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
307 | { |
|
309 | { | |
308 | return d_ptr->m_dataset->axisX(series); |
|
310 | return d_ptr->m_dataset->axisX(series); | |
309 | } |
|
311 | } | |
@@ -312,7 +314,7 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const | |||||
312 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
314 | Returns the pointer to the y axis object of the chart asociated with the specified \a series | |
313 | If no series is provided then pointer to currently visible axis is provided |
|
315 | If no series is provided then pointer to currently visible axis is provided | |
314 | */ |
|
316 | */ | |
315 |
QAbstractAxis* |
|
317 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
316 | { |
|
318 | { | |
317 | return d_ptr->m_dataset->axisY(series); |
|
319 | return d_ptr->m_dataset->axisY(series); | |
318 | } |
|
320 | } | |
@@ -353,13 +355,13 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const | |||||
353 | */ |
|
355 | */ | |
354 | void QChart::createDefaultAxes() |
|
356 | void QChart::createDefaultAxes() | |
355 | { |
|
357 | { | |
356 |
|
|
358 | d_ptr->m_dataset->createDefaultAxes(); | |
357 | } |
|
359 | } | |
358 |
|
360 | |||
359 | /*! |
|
361 | /*! | |
360 | Returns the legend object of the chart. Ownership stays in chart. |
|
362 | Returns the legend object of the chart. Ownership stays in chart. | |
361 | */ |
|
363 | */ | |
362 |
QLegend* |
|
364 | QLegend *QChart::legend() const | |
363 | { |
|
365 | { | |
364 | return d_ptr->m_legend; |
|
366 | return d_ptr->m_legend; | |
365 | } |
|
367 | } | |
@@ -367,7 +369,7 QLegend* QChart::legend() const | |||||
367 | /*! |
|
369 | /*! | |
368 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
370 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
369 | */ |
|
371 | */ | |
370 |
void QChart::setMargins(const QMargins& |
|
372 | void QChart::setMargins(const QMargins &margins) | |
371 | { |
|
373 | { | |
372 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
374 | d_ptr->m_presenter->layout()->setMargins(margins); | |
373 | } |
|
375 | } | |
@@ -445,7 +447,7 bool QChart::isDropShadowEnabled() const | |||||
445 |
|
447 | |||
446 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
448 | \sa addSeries(), removeSeries(), removeAllSeries() | |
447 | */ |
|
449 | */ | |
448 | QList<QAbstractSeries*> QChart::series() const |
|
450 | QList<QAbstractSeries *> QChart::series() const | |
449 | { |
|
451 | { | |
450 | return d_ptr->m_dataset->series(); |
|
452 | return d_ptr->m_dataset->series(); | |
451 | } |
|
453 | } | |
@@ -455,10 +457,11 QList<QAbstractSeries*> QChart::series() const | |||||
455 |
|
457 | |||
456 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
458 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() | |
457 | */ |
|
459 | */ | |
458 |
void QChart::setAxisX(QAbstractAxis* |
|
460 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) | |
459 | { |
|
461 | { | |
460 |
if(axis->alignment()==Qt::AlignLeft || axis->alignment()==Qt::AlignRight) |
|
462 | if (axis->alignment() == Qt::AlignLeft || axis->alignment() == Qt::AlignRight) | |
461 | d_ptr->m_dataset->setAxis(series,axis,Qt::Horizontal); |
|
463 | return; | |
|
464 | d_ptr->m_dataset->setAxis(series, axis, Qt::Horizontal); | |||
462 | } |
|
465 | } | |
463 |
|
466 | |||
464 | /*! |
|
467 | /*! | |
@@ -466,10 +469,11 void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series) | |||||
466 |
|
469 | |||
467 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
470 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() | |
468 | */ |
|
471 | */ | |
469 |
void QChart::setAxisY( |
|
472 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) | |
470 | { |
|
473 | { | |
471 |
if(axis->alignment()==Qt::AlignTop || axis->alignment()==Qt::AlignBottom) |
|
474 | if (axis->alignment() == Qt::AlignTop || axis->alignment() == Qt::AlignBottom) | |
472 | d_ptr->m_dataset->setAxis(series,axis,Qt::Vertical); |
|
475 | return; | |
|
476 | d_ptr->m_dataset->setAxis(series, axis, Qt::Vertical); | |||
473 | } |
|
477 | } | |
474 |
|
478 | |||
475 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
479 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -489,10 +493,10 QChartPrivate::~QChartPrivate() | |||||
489 |
|
493 | |||
490 | void QChartPrivate::createConnections() |
|
494 | void QChartPrivate::createConnections() | |
491 | { |
|
495 | { | |
492 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
496 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
493 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
497 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
494 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); |
|
498 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); | |
495 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
499 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
496 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); |
|
500 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); | |
497 | } |
|
501 | } | |
498 |
|
502 |
@@ -67,7 +67,7 void ScatterChartItem::createPoints(int count) | |||||
67 | const QRectF &rect = item->boundingRect(); |
|
67 | const QRectF &rect = item->boundingRect(); | |
68 | item->setPos(-rect.width() / 2, -rect.height() / 2); |
|
68 | item->setPos(-rect.width() / 2, -rect.height() / 2); | |
69 | break; |
|
69 | break; | |
70 |
|
|
70 | } | |
71 | case QScatterSeries::MarkerShapeRectangle: |
|
71 | case QScatterSeries::MarkerShapeRectangle: | |
72 | item = new RectangleMarker(0, 0, m_size, m_size, this); |
|
72 | item = new RectangleMarker(0, 0, m_size, m_size, this); | |
73 | item->setPos(-m_size / 2, -m_size / 2); |
|
73 | item->setPos(-m_size / 2, -m_size / 2); |
@@ -29,9 +29,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
29 | /*! |
|
29 | /*! | |
30 | Constructs a mapper object which is a child of \a parent. |
|
30 | Constructs a mapper object which is a child of \a parent. | |
31 | */ |
|
31 | */ | |
32 |
QXYModelMapper::QXYModelMapper(QObject *parent) |
|
32 | QXYModelMapper::QXYModelMapper(QObject *parent) | |
33 | QObject(parent), |
|
33 | : QObject(parent), | |
34 | d_ptr(new QXYModelMapperPrivate(this)) |
|
34 | d_ptr(new QXYModelMapperPrivate(this)) | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 |
General Comments 0
You need to be logged in to leave comments.
Login now