@@ -0,0 +1,84 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include <QApplication> | |
|
22 | #include <QMainWindow> | |
|
23 | #include <QChartView> | |
|
24 | #include <QLineSeries> | |
|
25 | #include <QValueAxis> | |
|
26 | #include <QTime> | |
|
27 | #include <QValueAxis> | |
|
28 | ||
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
30 | ||
|
31 | int main(int argc, char *argv[]) | |
|
32 | { | |
|
33 | QApplication a(argc, argv); | |
|
34 | ||
|
35 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
|
36 | ||
|
37 | //![1] | |
|
38 | QLineSeries* series; | |
|
39 | QValueAxis *axisX; | |
|
40 | QValueAxis *axisY; | |
|
41 | QChart* chart = new QChart(); | |
|
42 | for (int i = 0; i < 5; i++) { | |
|
43 | series = new QLineSeries; | |
|
44 | for (int k(0); k < 8; k++) | |
|
45 | series->append(i + k, qrand()%20); | |
|
46 | chart->addSeries(series); | |
|
47 | ||
|
48 | axisX = new QValueAxis; | |
|
49 | axisX->setTickCount(7 + i); | |
|
50 | axisX->setLinePenColor(series->pen().color()); | |
|
51 | if (i%2) | |
|
52 | axisX->setAlternativePlacement(true); | |
|
53 | axisY = new QValueAxis; | |
|
54 | axisY->setTickCount(7 + i); | |
|
55 | axisY->setLinePenColor(series->pen().color()); | |
|
56 | if (i%2) | |
|
57 | axisY->setAlternativePlacement(true); | |
|
58 | ||
|
59 | chart->setAxisX(axisX, series); | |
|
60 | chart->setAxisY(axisY, series); | |
|
61 | } | |
|
62 | //![2] | |
|
63 | ||
|
64 | //![3] | |
|
65 | chart->legend()->hide(); | |
|
66 | ||
|
67 | chart->setTitle("Simple line chart example"); | |
|
68 | //![3] | |
|
69 | ||
|
70 | //![4] | |
|
71 | QChartView* chartView = new QChartView(chart); | |
|
72 | chartView->setRenderHint(QPainter::Antialiasing); | |
|
73 | //![4] | |
|
74 | ||
|
75 | ||
|
76 | //![5] | |
|
77 | QMainWindow window; | |
|
78 | window.setCentralWidget(chartView); | |
|
79 | window.resize(800, 600); | |
|
80 | window.show(); | |
|
81 | //![5] | |
|
82 | ||
|
83 | return a.exec(); | |
|
84 | } |
@@ -0,0 +1,5 | |||
|
1 | !include( ../examples.pri ) { | |
|
2 | error( "Couldn't find the examples.pri file!" ) | |
|
3 | } | |
|
4 | TARGET = multiaxis | |
|
5 | SOURCES += main.cpp |
@@ -30,7 +30,8 SUBDIRS += \ | |||
|
30 | 30 | donutbreakdown \ |
|
31 | 31 | scrollchart \ |
|
32 | 32 | temperaturerecords \ |
|
33 | donutchart | |
|
33 | donutchart \ | |
|
34 | multiaxis | |
|
34 | 35 | |
|
35 | 36 | !linux-arm*: { |
|
36 | 37 | SUBDIRS += \ |
@@ -399,6 +399,11 void ChartAxis::setGeometry(const QRectF &rect) | |||
|
399 | 399 | |
|
400 | 400 | } |
|
401 | 401 | |
|
402 | void ChartAxis::setInternalRect(const QRectF &size) | |
|
403 | { | |
|
404 | m_internalRect = size; | |
|
405 | } | |
|
406 | ||
|
402 | 407 | void ChartAxis::axisSelected() |
|
403 | 408 | { |
|
404 | 409 | //TODO: axis clicked; |
@@ -441,6 +446,11 Qt::Orientation ChartAxis::orientation() const | |||
|
441 | 446 | return m_chartAxis->orientation(); |
|
442 | 447 | } |
|
443 | 448 | |
|
449 | bool ChartAxis::alternativePlacement() const | |
|
450 | { | |
|
451 | return m_chartAxis->alternativePlacement(); | |
|
452 | } | |
|
453 | ||
|
444 | 454 | bool ChartAxis::isVisible() |
|
445 | 455 | { |
|
446 | 456 | return m_chartAxis->isVisible(); |
@@ -96,6 +96,7 public: | |||
|
96 | 96 | ChartAnimation* animation() const { return m_animation; }; |
|
97 | 97 | |
|
98 | 98 | Qt::Orientation orientation() const; |
|
99 | bool alternativePlacement() const; | |
|
99 | 100 | |
|
100 | 101 | bool isVisible(); |
|
101 | 102 | void hide(); |
@@ -103,6 +104,8 public: | |||
|
103 | 104 | void setGeometry(const QRectF &size); |
|
104 | 105 | QRectF geometry() const { return m_rect; } |
|
105 | 106 | |
|
107 | void setInternalRect(const QRectF &size); | |
|
108 | ||
|
106 | 109 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint = QSizeF()) const; |
|
107 | 110 | |
|
108 | 111 | protected: |
@@ -128,6 +131,7 protected: | |||
|
128 | 131 | int m_labelsAngle; |
|
129 | 132 | //TODO: to be removed |
|
130 | 133 | QRectF m_rect; |
|
134 | QRectF m_internalRect; | |
|
131 | 135 | QScopedPointer<QGraphicsItemGroup> m_grid; |
|
132 | 136 | QScopedPointer<QGraphicsItemGroup> m_shades; |
|
133 | 137 | QScopedPointer<QGraphicsItemGroup> m_labels; |
@@ -693,13 +693,23 Qt::Orientation QAbstractAxis::orientation() | |||
|
693 | 693 | return d_ptr->m_orientation; |
|
694 | 694 | } |
|
695 | 695 | |
|
696 | bool QAbstractAxis::alternativePlacement() const | |
|
697 | { | |
|
698 | return d_ptr->m_alternativePlacement; | |
|
699 | } | |
|
700 | ||
|
701 | void QAbstractAxis::setAlternativePlacement(bool placement) | |
|
702 | { | |
|
703 | d_ptr->m_alternativePlacement = placement; | |
|
704 | } | |
|
705 | ||
|
696 | 706 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
697 | 707 | |
|
698 | 708 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): |
|
699 | 709 | q_ptr(q), |
|
700 | 710 | m_orientation(Qt::Orientation(0)), |
|
701 | 711 | m_dataset(0), |
|
702 |
m_visible( |
|
|
712 | m_visible(true), | |
|
703 | 713 | m_arrowVisible(true), |
|
704 | 714 | m_gridLineVisible(true), |
|
705 | 715 | m_labelsVisible(true), |
@@ -707,7 +717,8 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): | |||
|
707 | 717 | m_shadesVisible(false), |
|
708 | 718 | m_shadesBrush(Qt::SolidPattern), |
|
709 | 719 | m_shadesOpacity(1.0), |
|
710 | m_dirty(false) | |
|
720 | m_dirty(false), | |
|
721 | m_alternativePlacement(false) | |
|
711 | 722 | { |
|
712 | 723 | |
|
713 | 724 | } |
@@ -32,8 +32,8 class QAbstractAxisPrivate; | |||
|
32 | 32 | |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
34 | 34 | { |
|
35 |
|
|
|
36 |
|
|
|
35 | Q_OBJECT | |
|
36 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) | |
|
37 | 37 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) |
|
38 | 38 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) |
|
39 | 39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
@@ -124,6 +124,8 public: | |||
|
124 | 124 | QColor shadesBorderColor() const; |
|
125 | 125 | |
|
126 | 126 | Qt::Orientation orientation(); |
|
127 | bool alternativePlacement() const; | |
|
128 | void setAlternativePlacement(bool placement); | |
|
127 | 129 | |
|
128 | 130 | //range handling |
|
129 | 131 | void setMin(const QVariant &min); |
@@ -145,7 +147,7 Q_SIGNALS: | |||
|
145 | 147 | void shadesBorderColorChanged(QColor color); |
|
146 | 148 | |
|
147 | 149 | protected: |
|
148 |
|
|
|
150 | QScopedPointer<QAbstractAxisPrivate> d_ptr; | |
|
149 | 151 | Q_DISABLE_COPY(QAbstractAxis) |
|
150 | 152 | friend class ChartDataSet; |
|
151 | 153 | friend class ChartAxis; |
@@ -107,6 +107,8 private: | |||
|
107 | 107 | |
|
108 | 108 | bool m_dirty; |
|
109 | 109 | |
|
110 | bool m_alternativePlacement; | |
|
111 | ||
|
110 | 112 | friend class QAbstractAxis; |
|
111 | 113 | friend class ChartDataSet; |
|
112 | 114 | }; |
@@ -32,7 +32,7 static int label_padding = 5; | |||
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | ChartValueAxisX::ChartValueAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
35 | m_tickCount(0) | |
|
35 | m_tickCount(0) | |
|
36 | 36 | { |
|
37 | 37 | } |
|
38 | 38 | |
@@ -76,35 +76,47 void ChartValueAxisX::updateGeometry() | |||
|
76 | 76 | QRectF chartRrect = presenter()->chartsGeometry(); |
|
77 | 77 | |
|
78 | 78 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
79 | lineItem->setLine(chartRrect.left(), chartRrect.bottom(), chartRrect.right(), chartRrect.bottom()); | |
|
79 | // lineItem->setLine(chartRrect.left(), chartRrect.bottom(), chartRrect.right(), chartRrect.bottom()); | |
|
80 | if (m_chartAxis->alternativePlacement()) | |
|
81 | lineItem->setLine(chartRrect.left(), m_internalRect.top(), chartRrect.right(), m_internalRect.top()); | |
|
82 | else | |
|
83 | lineItem->setLine(chartRrect.left(), m_internalRect.bottom(), chartRrect.right(), m_internalRect.bottom()); | |
|
80 | 84 | |
|
81 | 85 | qreal width = 0; |
|
82 | 86 | for (int i = 0; i < layout.size(); ++i) { |
|
83 | 87 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
84 | 88 | lineItem->setLine(layout[i], chartRrect.top(), layout[i], chartRrect.bottom()); |
|
85 | 89 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 | labelItem->setPos(layout[i] - center.x(), chartRrect.bottom() + label_padding); | |
|
91 | if(labelItem->pos().x() <= width || | |
|
92 | labelItem->pos().x() < m_rect.left() || | |
|
93 | labelItem->pos().x() + rect.width() > m_rect.right()){ | |
|
94 | labelItem->setVisible(false); | |
|
95 | lineItem->setVisible(false); | |
|
96 | }else{ | |
|
97 | labelItem->setVisible(true); | |
|
98 |
|
|
|
99 | width=rect.width()+labelItem->pos().x(); | |
|
100 |
|
|
|
90 | labelItem->setText(ticksList.at(i)); | |
|
91 | const QRectF& rect = labelItem->boundingRect(); | |
|
92 | QPointF center = rect.center(); | |
|
93 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
94 | // labelItem->setPos(layout[i] - center.x(), chartRrect.bottom() + label_padding); | |
|
95 | if (m_chartAxis->alternativePlacement()) | |
|
96 | labelItem->setPos(layout[i] - center.x(), m_internalRect.top() - rect.height() - label_padding); | |
|
97 | else | |
|
98 | labelItem->setPos(layout[i] - center.x(), m_internalRect.bottom() + label_padding); | |
|
99 | if(labelItem->pos().x() <= width || | |
|
100 | labelItem->pos().x() < m_rect.left() || | |
|
101 | labelItem->pos().x() + rect.width() > m_rect.right()){ | |
|
102 | labelItem->setVisible(false); | |
|
103 | lineItem->setVisible(false); | |
|
104 | }else{ | |
|
105 | labelItem->setVisible(true); | |
|
106 | lineItem->setVisible(true); | |
|
107 | width=rect.width()+labelItem->pos().x(); | |
|
108 | } | |
|
101 | 109 | |
|
102 | 110 | if ((i+1)%2 && i>1) { |
|
103 | 111 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
104 | 112 | rectItem->setRect(layout[i-1],chartRrect.top(),layout[i]-layout[i-1],chartRrect.height()); |
|
105 | 113 | } |
|
106 | 114 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
107 | lineItem->setLine(layout[i],chartRrect.bottom(),layout[i],chartRrect.bottom()+5); | |
|
115 | // lineItem->setLine(layout[i],chartRrect.bottom(),layout[i],chartRrect.bottom()+5); | |
|
116 | if (m_chartAxis->alternativePlacement()) | |
|
117 | lineItem->setLine(layout[i],m_internalRect.top(),layout[i],m_internalRect.top()-5); | |
|
118 | else | |
|
119 | lineItem->setLine(layout[i],m_internalRect.bottom(),layout[i],m_internalRect.bottom()+5); | |
|
108 | 120 | } |
|
109 | 121 | } |
|
110 | 122 | |
@@ -128,33 +140,33 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF& constraint) c | |||
|
128 | 140 | qreal width=0; |
|
129 | 141 | qreal height=0; |
|
130 | 142 | |
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 | ||
|
146 | } | |
|
147 | height=fn.height()+label_padding; | |
|
148 | width=qMax(width,base.width()); | |
|
149 | height+=base.height(); | |
|
150 | sh = QSizeF(width,height); | |
|
151 | break; | |
|
143 | switch (which) { | |
|
144 | case Qt::MinimumSize:{ | |
|
145 | int count = qMax(ticksList.last().count(),ticksList.first().count()); | |
|
146 | width=fn.averageCharWidth()*count; | |
|
147 | height=fn.height()+label_padding; | |
|
148 | width=qMax(width,base.width()); | |
|
149 | height+=base.height(); | |
|
150 | sh = QSizeF(width,height); | |
|
151 | break; | |
|
152 | } | |
|
153 | case Qt::PreferredSize:{ | |
|
154 | for (int i = 0; i < ticksList.size(); ++i) | |
|
155 | { | |
|
156 | width+=fn.averageCharWidth()*ticksList.at(i).count(); | |
|
157 | ||
|
152 | 158 | } |
|
153 | default: | |
|
154 | break; | |
|
155 | } | |
|
159 | height=fn.height()+label_padding; | |
|
160 | width=qMax(width,base.width()); | |
|
161 | height+=base.height(); | |
|
162 | sh = QSizeF(width,height); | |
|
163 | break; | |
|
164 | } | |
|
165 | default: | |
|
166 | break; | |
|
167 | } | |
|
156 | 168 | |
|
157 |
|
|
|
169 | return sh; | |
|
158 | 170 | } |
|
159 | 171 | |
|
160 | 172 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -32,7 +32,7 static int label_padding = 5; | |||
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | ChartValueAxisY::ChartValueAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter), |
|
35 | m_tickCount(0) | |
|
35 | m_tickCount(0) | |
|
36 | 36 | { |
|
37 | 37 | } |
|
38 | 38 | |
@@ -79,7 +79,11 void ChartValueAxisY::updateGeometry() | |||
|
79 | 79 | qreal height = m_rect.bottom(); |
|
80 | 80 | |
|
81 | 81 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
82 | lineItem->setLine( chartRect.left() , chartRect.top(), chartRect.left(), chartRect.bottom()); | |
|
82 | // lineItem->setLine( chartRect.left() , chartRect.top(), chartRect.left(), chartRect.bottom()); | |
|
83 | if (m_chartAxis->alternativePlacement()) | |
|
84 | lineItem->setLine( m_internalRect.right() , chartRect.top(), m_internalRect.right(), chartRect.bottom()); | |
|
85 | else | |
|
86 | lineItem->setLine( m_internalRect.left() , chartRect.top(), m_internalRect.left(), chartRect.bottom()); | |
|
83 | 87 | |
|
84 | 88 | QFontMetrics fn(m_font); |
|
85 | 89 | |
@@ -88,40 +92,48 void ChartValueAxisY::updateGeometry() | |||
|
88 | 92 | lineItem->setLine( chartRect.left() , layout[i], chartRect.right(), layout[i]); |
|
89 | 93 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
90 | 94 | |
|
91 |
|
|
|
95 | QString text = ticksList.at(i); | |
|
92 | 96 | |
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
97 | if (fn.boundingRect(text).width() > chartRect.left() - m_rect.left() - label_padding ) | |
|
98 | { | |
|
99 | QString label = text + "..."; | |
|
100 | while (fn.boundingRect(label).width() > chartRect.left() - m_rect.left() - label_padding && label.length() > 3) | |
|
101 | label.remove(label.length() - 4, 1); | |
|
102 | labelItem->setText(label); | |
|
103 | }else{ | |
|
104 | labelItem->setText(text); | |
|
105 | } | |
|
102 | 106 | |
|
103 |
|
|
|
107 | const QRectF& rect = labelItem->boundingRect(); | |
|
104 | 108 | |
|
105 |
|
|
|
106 |
|
|
|
107 | labelItem->setPos( chartRect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
|
109 | QPointF center = rect.center(); | |
|
110 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
111 | // labelItem->setPos( chartRect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
|
112 | if (m_chartAxis->alternativePlacement()) | |
|
113 | labelItem->setPos( m_internalRect.right() + label_padding , layout[i]-center.y()); | |
|
114 | else | |
|
115 | labelItem->setPos( m_internalRect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
|
108 | 116 | |
|
109 |
|
|
|
117 | if(labelItem->pos().y() + rect.height() > height || | |
|
110 | 118 | labelItem->pos().y() < m_rect.top()) { |
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
119 | labelItem->setVisible(false); | |
|
120 | lineItem->setVisible(false); | |
|
121 | }else{ | |
|
122 | labelItem->setVisible(true); | |
|
123 | lineItem->setVisible(true); | |
|
124 | height=labelItem->pos().y(); | |
|
125 | } | |
|
118 | 126 | |
|
119 | 127 | if ((i+1)%2 && i>1) { |
|
120 | 128 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
121 | 129 | rectItem->setRect( chartRect.left(),layout[i], chartRect.width(),layout[i-1]-layout[i]); |
|
122 | 130 | } |
|
123 | 131 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
124 | lineItem->setLine( chartRect.left()-5,layout[i], chartRect.left(),layout[i]); | |
|
132 | // lineItem->setLine( chartRect.left()-5,layout[i], chartRect.left(),layout[i]); | |
|
133 | if (m_chartAxis->alternativePlacement()) | |
|
134 | lineItem->setLine( m_internalRect.right()+5,layout[i], m_internalRect.right(),layout[i]); | |
|
135 | else | |
|
136 | lineItem->setLine( m_internalRect.left()-5,layout[i], m_internalRect.left(),layout[i]); | |
|
125 | 137 | } |
|
126 | 138 | } |
|
127 | 139 | |
@@ -145,28 +157,28 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF& constraint) c | |||
|
145 | 157 | qreal height=0; |
|
146 | 158 | |
|
147 | 159 | switch (which) { |
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
160 | case Qt::MinimumSize: { | |
|
161 | int count = qMax(ticksList.first().count() , ticksList.last().count()); | |
|
162 | width=fn.averageCharWidth()*count+label_padding; | |
|
163 | height=fn.height(); | |
|
164 | height=qMax(height,base.height()); | |
|
165 | width+=base.width(); | |
|
166 | sh = QSizeF(width,height); | |
|
167 | break; | |
|
168 | } | |
|
169 | case Qt::PreferredSize: | |
|
170 | { | |
|
171 | for (int i = 0; i < ticksList.size(); ++i) | |
|
158 | 172 | { |
|
159 | for (int i = 0; i < ticksList.size(); ++i) | |
|
160 | { | |
|
161 | width=qMax(qreal(fn.averageCharWidth()*ticksList.at(i).count())+label_padding,width); | |
|
162 | height+=fn.height(); | |
|
163 | } | |
|
164 | height=qMax(height,base.height()); | |
|
165 | width+=base.width(); | |
|
166 | sh = QSizeF(width,height); | |
|
167 | break; | |
|
173 | width=qMax(qreal(fn.averageCharWidth()*ticksList.at(i).count())+label_padding,width); | |
|
174 | height+=fn.height(); | |
|
168 | 175 | } |
|
169 | default: | |
|
176 | height=qMax(height,base.height()); | |
|
177 | width+=base.width(); | |
|
178 | sh = QSizeF(width,height); | |
|
179 | break; | |
|
180 | } | |
|
181 | default: | |
|
170 | 182 | break; |
|
171 | 183 | } |
|
172 | 184 | return sh; |
@@ -31,9 +31,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
31 | 31 | static const qreal golden_ratio = 0.25; |
|
32 | 32 | |
|
33 | 33 | ChartLayout::ChartLayout(ChartPresenter* presenter): |
|
34 | m_presenter(presenter), | |
|
35 | m_margins(20,20,20,20), | |
|
36 | m_minChartRect(0,0,200,200) | |
|
34 | m_presenter(presenter), | |
|
35 | m_margins(20,20,20,20), | |
|
36 | m_minChartRect(0,0,200,200) | |
|
37 | 37 | { |
|
38 | 38 | |
|
39 | 39 | } |
@@ -87,7 +87,7 void ChartLayout::setGeometry(const QRectF& rect) | |||
|
87 | 87 | |
|
88 | 88 | QRectF ChartLayout::calculateContentGeometry(const QRectF& geometry) const |
|
89 | 89 | { |
|
90 |
|
|
|
90 | return geometry.adjusted(m_margins.left(),m_margins.top(),-m_margins.right(),-m_margins.bottom()); | |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | QRectF ChartLayout::calculateContentMinimum(const QRectF& minimum) const |
@@ -118,13 +118,26 QRectF ChartLayout::calculateChartGeometry(const QRectF& geometry, const QList<C | |||
|
118 | 118 | QSizeF vertical(0,0); |
|
119 | 119 | QSizeF horizontal(0,0); |
|
120 | 120 | |
|
121 | int topAxisCount = 0; | |
|
122 | int bottomAxisCount = 0; | |
|
123 | int leftAxisCount = 0; | |
|
124 | int rightAxisCount = 0; | |
|
125 | ||
|
121 | 126 | // check axis size |
|
122 | 127 | foreach(ChartAxis* axis , axes) { |
|
123 | 128 | if(axis->orientation()==Qt::Vertical && axis->isVisible()) { |
|
124 | 129 | vertical = vertical.expandedTo(axis->effectiveSizeHint(Qt::MinimumSize)); |
|
130 | if (axis->alternativePlacement()) | |
|
131 | rightAxisCount++; | |
|
132 | else | |
|
133 | leftAxisCount++; | |
|
125 | 134 | } |
|
126 | 135 | else if(axis->orientation()==Qt::Horizontal && axis->isVisible()) { |
|
127 | 136 | horizontal = horizontal.expandedTo(axis->effectiveSizeHint(Qt::MinimumSize)); |
|
137 | if (axis->alternativePlacement()) | |
|
138 | topAxisCount++; | |
|
139 | else | |
|
140 | bottomAxisCount++; | |
|
128 | 141 | } |
|
129 | 142 | |
|
130 | 143 | } |
@@ -133,10 +146,37 QRectF ChartLayout::calculateChartGeometry(const QRectF& geometry, const QList<C | |||
|
133 | 146 | |
|
134 | 147 | QRectF rect = geometry.adjusted(width,vertical.height()/2,-horizontal.width()/2,-horizontal.height()); |
|
135 | 148 | |
|
149 | // axis area width | |
|
150 | // TODO: replase with dynamic size code | |
|
151 | int axisWidth = 35; | |
|
152 | ||
|
153 | // get the final size of the plot rect | |
|
154 | rect.adjust(leftAxisCount * axisWidth, topAxisCount * axisWidth, -rightAxisCount * axisWidth, -bottomAxisCount * axisWidth); | |
|
136 | 155 | m_presenter->setChartsGeometry(rect); |
|
137 | 156 | |
|
157 | leftAxisCount = 0; | |
|
158 | rightAxisCount = 0; | |
|
159 | bottomAxisCount = 0; | |
|
160 | topAxisCount = 0; | |
|
161 | ||
|
162 | // adjust the axes internal and external rects | |
|
138 | 163 | foreach(ChartAxis* axis , axes) { |
|
139 | axis->setGeometry(geometry); | |
|
164 | if(axis->orientation()==Qt::Vertical) { | |
|
165 | axis->setInternalRect(rect.adjusted(-leftAxisCount * axisWidth, 0, rightAxisCount * axisWidth, 0)); | |
|
166 | axis->setGeometry(rect.adjusted(-(leftAxisCount + 1) * axisWidth, 0, (rightAxisCount + 1) * axisWidth, 0)); | |
|
167 | if (axis->alternativePlacement()) | |
|
168 | rightAxisCount++; | |
|
169 | else | |
|
170 | leftAxisCount++; | |
|
171 | } | |
|
172 | else if(axis->orientation()==Qt::Horizontal) { | |
|
173 | axis->setInternalRect(rect.adjusted(0, -topAxisCount * axisWidth, 0, bottomAxisCount * axisWidth)); | |
|
174 | axis->setGeometry(rect.adjusted(0, -(topAxisCount + 1) * axisWidth, 0, (bottomAxisCount + 1) * axisWidth)); | |
|
175 | if (axis->alternativePlacement()) | |
|
176 | topAxisCount++; | |
|
177 | else | |
|
178 | bottomAxisCount++; | |
|
179 | } | |
|
140 | 180 | } |
|
141 | 181 | |
|
142 | 182 | return rect; |
@@ -165,34 +205,33 QRectF ChartLayout::calculateLegendGeometry(const QRectF& geometry,QLegend* lege | |||
|
165 | 205 | QRectF result; |
|
166 | 206 | |
|
167 | 207 | switch (legend->alignment()) { |
|
168 | ||
|
169 | case Qt::AlignTop: { | |
|
170 | legendRect = QRectF(geometry.topLeft(),QSizeF(geometry.width(),size.height())); | |
|
171 | result = geometry.adjusted(0,legendRect.height(),0,0); | |
|
172 | break; | |
|
173 | } | |
|
174 | case Qt::AlignBottom: { | |
|
175 | legendRect = QRectF(QPointF(geometry.left(),geometry.bottom()-size.height()),QSizeF(geometry.width(),size.height())); | |
|
176 | result = geometry.adjusted(0,0,0,-legendRect.height()); | |
|
177 | break; | |
|
178 | } | |
|
179 | case Qt::AlignLeft: { | |
|
180 | qreal width = qMin(size.width(),geometry.width()*golden_ratio); | |
|
181 | legendRect = QRectF(geometry.topLeft(),QSizeF(width,geometry.height())); | |
|
182 | result = geometry.adjusted(width,0,0,0); | |
|
183 | break; | |
|
184 | } | |
|
185 | case Qt::AlignRight: { | |
|
186 | qreal width = qMin(size.width(),geometry.width()*golden_ratio); | |
|
187 | legendRect = QRectF(QPointF(geometry.right()-width,geometry.top()),QSizeF(width,geometry.height())); | |
|
188 | result = geometry.adjusted(0,0,-width,0); | |
|
189 | break; | |
|
190 | } | |
|
191 | default: { | |
|
192 | legendRect = QRectF(0,0,0,0); | |
|
193 | result = geometry; | |
|
194 | break; | |
|
195 | } | |
|
208 | case Qt::AlignTop: { | |
|
209 | legendRect = QRectF(geometry.topLeft(),QSizeF(geometry.width(),size.height())); | |
|
210 | result = geometry.adjusted(0,legendRect.height(),0,0); | |
|
211 | break; | |
|
212 | } | |
|
213 | case Qt::AlignBottom: { | |
|
214 | legendRect = QRectF(QPointF(geometry.left(),geometry.bottom()-size.height()),QSizeF(geometry.width(),size.height())); | |
|
215 | result = geometry.adjusted(0,0,0,-legendRect.height()); | |
|
216 | break; | |
|
217 | } | |
|
218 | case Qt::AlignLeft: { | |
|
219 | qreal width = qMin(size.width(),geometry.width()*golden_ratio); | |
|
220 | legendRect = QRectF(geometry.topLeft(),QSizeF(width,geometry.height())); | |
|
221 | result = geometry.adjusted(width,0,0,0); | |
|
222 | break; | |
|
223 | } | |
|
224 | case Qt::AlignRight: { | |
|
225 | qreal width = qMin(size.width(),geometry.width()*golden_ratio); | |
|
226 | legendRect = QRectF(QPointF(geometry.right()-width,geometry.top()),QSizeF(width,geometry.height())); | |
|
227 | result = geometry.adjusted(0,0,-width,0); | |
|
228 | break; | |
|
229 | } | |
|
230 | default: { | |
|
231 | legendRect = QRectF(0,0,0,0); | |
|
232 | result = geometry; | |
|
233 | break; | |
|
234 | } | |
|
196 | 235 | } |
|
197 | 236 | |
|
198 | 237 | legend->setGeometry(legendRect); |
@@ -202,22 +241,22 QRectF ChartLayout::calculateLegendGeometry(const QRectF& geometry,QLegend* lege | |||
|
202 | 241 | |
|
203 | 242 | QRectF ChartLayout::calculateLegendMinimum(const QRectF& geometry,QLegend* legend) const |
|
204 | 243 | { |
|
205 |
|
|
|
206 |
|
|
|
244 | QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize,QSizeF(-1,-1)); | |
|
245 | return geometry.adjusted(0,0,minSize.width(),minSize.height()); | |
|
207 | 246 | } |
|
208 | 247 | |
|
209 | 248 | QRectF ChartLayout::calculateTitleGeometry(const QRectF& geometry,ChartTitle* title) const |
|
210 | 249 | { |
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
250 | title->setGeometry(geometry); | |
|
251 | QPointF center = geometry.center() - title->boundingRect().center(); | |
|
252 | title->setPos(center.x(),title->pos().y()); | |
|
253 | return geometry.adjusted(0,title->boundingRect().height(),0,0); | |
|
215 | 254 | } |
|
216 | 255 | |
|
217 | 256 | QRectF ChartLayout::calculateTitleMinimum(const QRectF& minimum,ChartTitle* title) const |
|
218 | 257 | { |
|
219 |
|
|
|
220 |
|
|
|
258 | QSizeF min = title->sizeHint(Qt::MinimumSize); | |
|
259 | return minimum.adjusted(0,0,min.width(),min.height()); | |
|
221 | 260 | } |
|
222 | 261 | |
|
223 | 262 | QSizeF ChartLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const |
@@ -135,26 +135,27 void ChartPresenter::selectVisibleAxis() | |||
|
135 | 135 | |
|
136 | 136 | while (i.hasNext()) { |
|
137 | 137 | i.next(); |
|
138 | i.key()->hide(); | |
|
138 | // i.key()->hide(); | |
|
139 | i.key()->show(); | |
|
139 | 140 | } |
|
140 | 141 | |
|
141 | i.toFront(); | |
|
142 | // i.toFront(); | |
|
142 | 143 | |
|
143 | bool axisX=false; | |
|
144 | bool axisY=false; | |
|
144 | // bool axisX=false; | |
|
145 | // bool axisY=false; | |
|
145 | 146 | |
|
146 | while (i.hasNext()) { | |
|
147 | i.next(); | |
|
148 | if(i.key()->orientation()==Qt::Vertical && !axisY) { | |
|
149 | axisY=true; | |
|
150 | i.key()->show(); | |
|
151 | } | |
|
152 | if(i.key()->orientation()==Qt::Horizontal && !axisX) { | |
|
153 | axisX=true; | |
|
154 | i.key()->show(); | |
|
155 | } | |
|
147 | // while (i.hasNext()) { | |
|
148 | // i.next(); | |
|
149 | // if(i.key()->orientation()==Qt::Vertical && !axisY) { | |
|
150 | // axisY=true; | |
|
151 | // i.key()->show(); | |
|
152 | // } | |
|
153 | // if(i.key()->orientation()==Qt::Horizontal && !axisX) { | |
|
154 | // axisX=true; | |
|
155 | // i.key()->show(); | |
|
156 | // } | |
|
156 | 157 | |
|
157 | } | |
|
158 | // } | |
|
158 | 159 | } |
|
159 | 160 | |
|
160 | 161 |
General Comments 0
You need to be logged in to leave comments.
Login now