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