@@ -1,178 +1,204 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "abstractbarchartitem_p.h" |
|
21 | #include "abstractbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "qabstractbarseries.h" |
|
25 | #include "qabstractbarseries.h" | |
26 | #include "qabstractbarseries_p.h" |
|
26 | #include "qabstractbarseries_p.h" | |
27 | #include "qchart.h" |
|
27 | #include "qchart.h" | |
28 | #include "chartpresenter_p.h" |
|
28 | #include "chartpresenter_p.h" | |
29 | #include "charttheme_p.h" |
|
29 | #include "charttheme_p.h" | |
30 | #include "abstractbaranimation_p.h" |
|
30 | #include "abstractbaranimation_p.h" | |
31 | #include "chartdataset_p.h" |
|
31 | #include "chartdataset_p.h" | |
32 | #include <QPainter> |
|
32 | #include <QPainter> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
36 | AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : | |
37 | ChartItem(presenter), |
|
37 | ChartItem(presenter), | |
38 | m_animation(0), |
|
38 | m_animation(0), | |
39 | m_series(series) |
|
39 | m_series(series) | |
40 | { |
|
40 | { | |
|
41 | ||||
41 | setFlag(ItemClipsChildrenToShape); |
|
42 | setFlag(ItemClipsChildrenToShape); | |
42 |
connect(series->d_func(), SIGNAL(updated |
|
43 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); | |
|
44 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); | |||
43 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); |
|
45 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); | |
44 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); |
|
46 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); | |
45 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); |
|
47 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); | |
46 | setZValue(ChartPresenter::BarSeriesZValue); |
|
48 | setZValue(ChartPresenter::BarSeriesZValue); | |
47 | handleDataStructureChanged(); |
|
49 | handleDataStructureChanged(); | |
48 | } |
|
50 | } | |
49 |
|
51 | |||
50 | AbstractBarChartItem::~AbstractBarChartItem() |
|
52 | AbstractBarChartItem::~AbstractBarChartItem() | |
51 | { |
|
53 | { | |
52 | } |
|
54 | } | |
53 |
|
55 | |||
54 | void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
56 | void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
55 | { |
|
57 | { | |
56 | Q_UNUSED(painter); |
|
58 | Q_UNUSED(painter); | |
57 | Q_UNUSED(option); |
|
59 | Q_UNUSED(option); | |
58 | Q_UNUSED(widget); |
|
60 | Q_UNUSED(widget); | |
59 | } |
|
61 | } | |
60 |
|
62 | |||
61 | QRectF AbstractBarChartItem::boundingRect() const |
|
63 | QRectF AbstractBarChartItem::boundingRect() const | |
62 | { |
|
64 | { | |
63 | return m_rect; |
|
65 | return m_rect; | |
64 | } |
|
66 | } | |
65 |
|
67 | |||
66 | void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
68 | void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout) | |
67 | { |
|
69 | { | |
68 | if (m_animation) { |
|
70 | if (m_animation) { | |
69 | m_animation->setup(m_layout,layout); |
|
71 | m_animation->setup(m_layout,layout); | |
70 | presenter()->startAnimation(m_animation); |
|
72 | presenter()->startAnimation(m_animation); | |
71 |
|
73 | |||
72 | } else { |
|
74 | } else { | |
73 | setLayout(layout); |
|
75 | setLayout(layout); | |
74 | update(); |
|
76 | update(); | |
75 | } |
|
77 | } | |
76 | } |
|
78 | } | |
77 |
|
79 | |||
78 | void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation) |
|
80 | void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation) | |
79 | { |
|
81 | { | |
80 | m_animation = animation; |
|
82 | m_animation = animation; | |
81 | } |
|
83 | } | |
82 |
|
84 | |||
83 | void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout) |
|
85 | void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout) | |
84 | { |
|
86 | { | |
85 | if (layout.count() != m_bars.count()) |
|
87 | if (layout.count() != m_bars.count()) | |
86 | return; |
|
88 | return; | |
87 |
|
89 | |||
88 | m_layout = layout; |
|
90 | m_layout = layout; | |
89 |
|
91 | |||
90 | for (int i=0; i < m_bars.count(); i++) { |
|
92 | for (int i=0; i < m_bars.count(); i++) { | |
91 | m_bars.at(i)->setRect(layout.at(i)); |
|
93 | m_bars.at(i)->setRect(layout.at(i)); | |
92 | } |
|
94 | } | |
93 | } |
|
95 | } | |
94 | //handlers |
|
96 | //handlers | |
95 |
|
97 | |||
96 | void AbstractBarChartItem::handleDomainUpdated() |
|
98 | void AbstractBarChartItem::handleDomainUpdated() | |
97 | { |
|
99 | { | |
98 | m_domainMinX = domain()->minX(); |
|
100 | m_domainMinX = domain()->minX(); | |
99 | m_domainMaxX = domain()->maxX(); |
|
101 | m_domainMaxX = domain()->maxX(); | |
100 | m_domainMinY = domain()->minY(); |
|
102 | m_domainMinY = domain()->minY(); | |
101 | m_domainMaxY = domain()->maxY(); |
|
103 | m_domainMaxY = domain()->maxY(); | |
102 | handleLayoutChanged(); |
|
104 | handleLayoutChanged(); | |
103 | } |
|
105 | } | |
104 |
|
106 | |||
105 | void AbstractBarChartItem::handleGeometryChanged(const QRectF &rect) |
|
107 | void AbstractBarChartItem::handleGeometryChanged(const QRectF &rect) | |
106 | { |
|
108 | { | |
107 | prepareGeometryChange(); |
|
109 | prepareGeometryChange(); | |
108 | m_rect = rect; |
|
110 | m_rect = rect; | |
109 | handleLayoutChanged(); |
|
111 | handleLayoutChanged(); | |
110 | } |
|
112 | } | |
111 |
|
113 | |||
112 | void AbstractBarChartItem::handleLayoutChanged() |
|
114 | void AbstractBarChartItem::handleLayoutChanged() | |
113 | { |
|
115 | { | |
114 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { |
|
116 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { | |
115 | // rect size zero. |
|
117 | // rect size zero. | |
116 | return; |
|
118 | return; | |
117 | } |
|
119 | } | |
118 | QVector<QRectF> layout = calculateLayout(); |
|
120 | QVector<QRectF> layout = calculateLayout(); | |
119 | applyLayout(layout); |
|
121 | applyLayout(layout); | |
120 | } |
|
122 | } | |
121 |
|
123 | |||
122 | void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible) |
|
124 | void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible) | |
123 | { |
|
125 | { | |
124 | foreach (QGraphicsSimpleTextItem* label, m_labels) { |
|
126 | foreach (QGraphicsSimpleTextItem* label, m_labels) { | |
125 | label->setVisible(visible); |
|
127 | label->setVisible(visible); | |
126 | } |
|
128 | } | |
127 | update(); |
|
129 | update(); | |
128 | } |
|
130 | } | |
129 |
|
131 | |||
130 | void AbstractBarChartItem::handleDataStructureChanged() |
|
132 | void AbstractBarChartItem::handleDataStructureChanged() | |
131 | { |
|
133 | { | |
132 | foreach(QGraphicsItem *item, childItems()) { |
|
134 | foreach(QGraphicsItem *item, childItems()) { | |
133 | delete item; |
|
135 | delete item; | |
134 | } |
|
136 | } | |
135 |
|
137 | |||
136 | m_bars.clear(); |
|
138 | m_bars.clear(); | |
137 | m_labels.clear(); |
|
139 | m_labels.clear(); | |
138 | m_layout.clear(); |
|
140 | m_layout.clear(); | |
139 |
|
141 | |||
140 | bool labelsVisible = m_series->isLabelsVisible(); |
|
142 | bool labelsVisible = m_series->isLabelsVisible(); | |
141 |
|
143 | |||
142 | // Create new graphic items for bars |
|
144 | // Create new graphic items for bars | |
143 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { |
|
145 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { | |
144 | for (int s = 0; s < m_series->count(); s++) { |
|
146 | for (int s = 0; s < m_series->count(); s++) { | |
145 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
147 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
146 |
|
148 | |||
147 | // Bars |
|
149 | // Bars | |
148 | Bar *bar = new Bar(set,c,this); |
|
150 | Bar *bar = new Bar(set,c,this); | |
149 | m_bars.append(bar); |
|
151 | m_bars.append(bar); | |
150 | connect(bar, SIGNAL(clicked(int, QBarSet*)), m_series, SIGNAL(clicked(int, QBarSet*))); |
|
152 | connect(bar, SIGNAL(clicked(int, QBarSet*)), m_series, SIGNAL(clicked(int, QBarSet*))); | |
151 | connect(bar, SIGNAL(hovered(bool, QBarSet*)), m_series, SIGNAL(hovered(bool, QBarSet*))); |
|
153 | connect(bar, SIGNAL(hovered(bool, QBarSet*)), m_series, SIGNAL(hovered(bool, QBarSet*))); | |
152 | connect(bar, SIGNAL(clicked(int, QBarSet*)), set, SIGNAL(clicked(int))); |
|
154 | connect(bar, SIGNAL(clicked(int, QBarSet*)), set, SIGNAL(clicked(int))); | |
153 | connect(bar, SIGNAL(hovered(bool, QBarSet*)), set, SIGNAL(hovered(bool))); |
|
155 | connect(bar, SIGNAL(hovered(bool, QBarSet*)), set, SIGNAL(hovered(bool))); | |
154 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
156 | m_layout.append(QRectF(0, 0, 0, 0)); | |
155 |
|
157 | |||
156 | // Labels |
|
158 | // Labels | |
157 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); |
|
159 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); | |
158 | label->setVisible(labelsVisible); |
|
160 | label->setVisible(labelsVisible); | |
159 | m_labels.append(label); |
|
161 | m_labels.append(label); | |
160 | } |
|
162 | } | |
161 | } |
|
163 | } | |
162 |
|
164 | |||
163 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
165 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
164 | handleLayoutChanged(); |
|
166 | handleLayoutChanged(); | |
165 | } |
|
167 | } | |
166 |
|
168 | |||
167 | void AbstractBarChartItem::handleVisibleChanged() |
|
169 | void AbstractBarChartItem::handleVisibleChanged() | |
168 | { |
|
170 | { | |
169 | bool visible = m_series->isVisible(); |
|
171 | bool visible = m_series->isVisible(); | |
170 | handleLabelsVisibleChanged(visible); |
|
172 | handleLabelsVisibleChanged(visible); | |
171 | foreach(QGraphicsItem *item, childItems()) { |
|
173 | foreach(QGraphicsItem *item, childItems()) { | |
172 | item->setVisible(visible); |
|
174 | item->setVisible(visible); | |
173 | } |
|
175 | } | |
174 | } |
|
176 | } | |
175 |
|
177 | |||
|
178 | void AbstractBarChartItem::handleUpdatedBars() | |||
|
179 | { | |||
|
180 | // Handle changes in pen, brush, labels etc. | |||
|
181 | int categoryCount = m_series->d_func()->categoryCount(); | |||
|
182 | int setCount = m_series->count(); | |||
|
183 | int itemIndex(0); | |||
|
184 | ||||
|
185 | for (int category = 0; category < categoryCount; category++) { | |||
|
186 | for (int set = 0; set < setCount; set++) { | |||
|
187 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |||
|
188 | Bar* bar = m_bars.at(itemIndex); | |||
|
189 | bar->setPen(barSet->m_pen); | |||
|
190 | bar->setBrush(barSet->m_brush); | |||
|
191 | bar->update(); | |||
|
192 | ||||
|
193 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |||
|
194 | label->setFont(barSet->m_labelFont); | |||
|
195 | label->setBrush(barSet->m_labelBrush); | |||
|
196 | label->update(); | |||
|
197 | itemIndex++; | |||
|
198 | } | |||
|
199 | } | |||
|
200 | } | |||
|
201 | ||||
176 | #include "moc_abstractbarchartitem_p.cpp" |
|
202 | #include "moc_abstractbarchartitem_p.cpp" | |
177 |
|
203 | |||
178 | QTCOMMERCIALCHART_END_NAMESPACE |
|
204 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,91 +1,92 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | #ifndef ABSTRACTBARCHARTITEM_H |
|
31 | #ifndef ABSTRACTBARCHARTITEM_H | |
32 | #define ABSTRACTBARCHARTITEM_H |
|
32 | #define ABSTRACTBARCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "qabstractbarseries.h" |
|
35 | #include "qabstractbarseries.h" | |
36 | #include <QPen> |
|
36 | #include <QPen> | |
37 | #include <QBrush> |
|
37 | #include <QBrush> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class Bar; |
|
41 | class Bar; | |
42 | class QAxisCategories; |
|
42 | class QAxisCategories; | |
43 | class QChart; |
|
43 | class QChart; | |
44 | class AbstractBarAnimation; |
|
44 | class AbstractBarAnimation; | |
45 |
|
45 | |||
46 | class AbstractBarChartItem : public ChartItem |
|
46 | class AbstractBarChartItem : public ChartItem | |
47 | { |
|
47 | { | |
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 | public: |
|
49 | public: | |
50 | AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter); |
|
50 | AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter); | |
51 | virtual ~AbstractBarChartItem(); |
|
51 | virtual ~AbstractBarChartItem(); | |
52 |
|
52 | |||
53 | public: |
|
53 | public: | |
54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
55 | QRectF boundingRect() const; |
|
55 | QRectF boundingRect() const; | |
56 |
|
56 | |||
57 | virtual QVector<QRectF> calculateLayout() = 0; |
|
57 | virtual QVector<QRectF> calculateLayout() = 0; | |
58 | virtual void applyLayout(const QVector<QRectF> &layout); |
|
58 | virtual void applyLayout(const QVector<QRectF> &layout); | |
59 | virtual void setAnimation(AbstractBarAnimation* animation); |
|
59 | virtual void setAnimation(AbstractBarAnimation* animation); | |
60 | void setLayout(const QVector<QRectF> &layout); |
|
60 | void setLayout(const QVector<QRectF> &layout); | |
61 | void updateLayout(const QVector<QRectF> &layout); |
|
61 | void updateLayout(const QVector<QRectF> &layout); | |
62 | QRectF geometry() const { return m_rect;} |
|
62 | QRectF geometry() const { return m_rect;} | |
63 |
|
63 | |||
64 | public Q_SLOTS: |
|
64 | public Q_SLOTS: | |
65 | void handleDomainUpdated(); |
|
65 | void handleDomainUpdated(); | |
66 | void handleGeometryChanged(const QRectF &size); |
|
66 | void handleGeometryChanged(const QRectF &size); | |
67 | void handleLayoutChanged(); |
|
67 | void handleLayoutChanged(); | |
68 | void handleLabelsVisibleChanged(bool visible); |
|
68 | void handleLabelsVisibleChanged(bool visible); | |
69 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items |
|
69 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items | |
70 | void handleVisibleChanged(); |
|
70 | void handleVisibleChanged(); | |
|
71 | void handleUpdatedBars(); | |||
71 |
|
72 | |||
72 | protected: |
|
73 | protected: | |
73 |
|
74 | |||
74 | qreal m_domainMinX; |
|
75 | qreal m_domainMinX; | |
75 | qreal m_domainMaxX; |
|
76 | qreal m_domainMaxX; | |
76 | qreal m_domainMinY; |
|
77 | qreal m_domainMinY; | |
77 | qreal m_domainMaxY; |
|
78 | qreal m_domainMaxY; | |
78 |
|
79 | |||
79 | QRectF m_rect; |
|
80 | QRectF m_rect; | |
80 | QVector<QRectF> m_layout; |
|
81 | QVector<QRectF> m_layout; | |
81 |
|
82 | |||
82 | AbstractBarAnimation *m_animation; |
|
83 | AbstractBarAnimation *m_animation; | |
83 |
|
84 | |||
84 | QAbstractBarSeries *m_series; // Not owned. |
|
85 | QAbstractBarSeries *m_series; // Not owned. | |
85 | QList<Bar *> m_bars; |
|
86 | QList<Bar *> m_bars; | |
86 | QList<QGraphicsSimpleTextItem *> m_labels; |
|
87 | QList<QGraphicsSimpleTextItem *> m_labels; | |
87 | }; |
|
88 | }; | |
88 |
|
89 | |||
89 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | QTCOMMERCIALCHART_END_NAMESPACE | |
90 |
|
91 | |||
91 | #endif // ABSTRACTBARCHARTITEM_H |
|
92 | #endif // ABSTRACTBARCHARTITEM_H |
@@ -1,865 +1,870 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qabstractbarseries.h" |
|
21 | #include "qabstractbarseries.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "qvalueaxis.h" |
|
29 | #include "qvalueaxis.h" | |
30 | #include "qbarcategoryaxis.h" |
|
30 | #include "qbarcategoryaxis.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAbstractBarSeries |
|
35 | \class QAbstractBarSeries | |
36 | \brief Series for creating a bar chart |
|
36 | \brief Series for creating a bar chart | |
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
42 | shows the x-values. |
|
42 | shows the x-values. | |
43 |
|
43 | |||
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
45 | \image examples_barchart.png |
|
45 | \image examples_barchart.png | |
46 |
|
46 | |||
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
48 | */ |
|
48 | */ | |
49 | /*! |
|
49 | /*! | |
50 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
50 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
51 | \inherits QAbstractSeries |
|
51 | \inherits QAbstractSeries | |
52 |
|
52 | |||
53 | The following QML shows how to create a simple bar chart: |
|
53 | The following QML shows how to create a simple bar chart: | |
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
55 |
|
55 | |||
56 | \beginfloatleft |
|
56 | \beginfloatleft | |
57 | \image demos_qmlchart6.png |
|
57 | \image demos_qmlchart6.png | |
58 | \endfloat |
|
58 | \endfloat | |
59 | \clearfloat |
|
59 | \clearfloat | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QAbstractBarSeries::barWidth |
|
63 | \property QAbstractBarSeries::barWidth | |
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
68 | \sa QBarSeries |
|
68 | \sa QBarSeries | |
69 | */ |
|
69 | */ | |
70 | /*! |
|
70 | /*! | |
71 | \qmlproperty real AbstractBarSeries::barWidth |
|
71 | \qmlproperty real AbstractBarSeries::barWidth | |
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \property QAbstractBarSeries::count |
|
79 | \property QAbstractBarSeries::count | |
80 | Holds the number of sets in series. |
|
80 | Holds the number of sets in series. | |
81 | */ |
|
81 | */ | |
82 | /*! |
|
82 | /*! | |
83 | \qmlproperty int AbstractBarSeries::count |
|
83 | \qmlproperty int AbstractBarSeries::count | |
84 | Holds the number of sets in series. |
|
84 | Holds the number of sets in series. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QAbstractBarSeries::labelsVisible |
|
88 | \property QAbstractBarSeries::labelsVisible | |
89 | Defines the visibility of the labels in series |
|
89 | Defines the visibility of the labels in series | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
92 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
93 | Defines the visibility of the labels in series |
|
93 | Defines the visibility of the labels in series | |
94 | */ |
|
94 | */ | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
99 | Clicked bar inside set is indexed by \a index |
|
99 | Clicked bar inside set is indexed by \a index | |
100 | */ |
|
100 | */ | |
101 | /*! |
|
101 | /*! | |
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
104 | Clicked bar inside set is indexed by \a index |
|
104 | Clicked bar inside set is indexed by \a index | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
109 |
|
109 | |||
110 | The signal is emitted if mouse is hovered on top of series. |
|
110 | The signal is emitted if mouse is hovered on top of series. | |
111 | Parameter \a barset is the pointer of barset, where hover happened. |
|
111 | Parameter \a barset is the pointer of barset, where hover happened. | |
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
116 |
|
116 | |||
117 | The signal is emitted if mouse is hovered on top of series. |
|
117 | The signal is emitted if mouse is hovered on top of series. | |
118 | Parameter \a barset is the pointer of barset, where hover happened. |
|
118 | Parameter \a barset is the pointer of barset, where hover happened. | |
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn void QAbstractBarSeries::countChanged() |
|
123 | \fn void QAbstractBarSeries::countChanged() | |
124 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
124 | This signal is emitted when barset count has been changed, for example by append or remove. | |
125 | */ |
|
125 | */ | |
126 | /*! |
|
126 | /*! | |
127 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
127 | \qmlsignal AbstractBarSeries::onCountChanged() | |
128 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
128 | This signal is emitted when barset count has been changed, for example by append or remove. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
132 | \fn void QAbstractBarSeries::labelsVisibleChanged() | |
133 | This signal is emitted when labels visibility have changed. |
|
133 | This signal is emitted when labels visibility have changed. | |
134 | \sa isLabelsVisible(), setLabelsVisible() |
|
134 | \sa isLabelsVisible(), setLabelsVisible() | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
139 | This signal is emitted when \a sets have been added to the series. |
|
139 | This signal is emitted when \a sets have been added to the series. | |
140 | \sa append(), insert() |
|
140 | \sa append(), insert() | |
141 | */ |
|
141 | */ | |
142 | /*! |
|
142 | /*! | |
143 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) |
|
143 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) | |
144 | Emitted when \a barset has been added to the series. |
|
144 | Emitted when \a barset has been added to the series. | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
149 | This signal is emitted when \a sets have been removed from the series. |
|
149 | This signal is emitted when \a sets have been removed from the series. | |
150 | \sa remove() |
|
150 | \sa remove() | |
151 | */ |
|
151 | */ | |
152 | /*! |
|
152 | /*! | |
153 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) |
|
153 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) | |
154 | Emitted when \a barset has been removed from the series. |
|
154 | Emitted when \a barset has been removed from the series. | |
155 | */ |
|
155 | */ | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
159 | Returns bar set at \a index. Returns null if the index is not valid. |
|
159 | Returns bar set at \a index. Returns null if the index is not valid. | |
160 | */ |
|
160 | */ | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
164 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
164 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
165 | For example: |
|
165 | For example: | |
166 | \code |
|
166 | \code | |
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
168 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
168 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); | |
169 | \endcode |
|
169 | \endcode | |
170 | */ |
|
170 | */ | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
173 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
174 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
174 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
175 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
175 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
176 | appended. |
|
176 | appended. | |
177 | \sa AbstractBarSeries::append() |
|
177 | \sa AbstractBarSeries::append() | |
178 | */ |
|
178 | */ | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
181 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
182 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
182 | Removes the barset from the series. Returns true if successfull, false otherwise. | |
183 | */ |
|
183 | */ | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | \qmlmethod AbstractBarSeries::clear() |
|
186 | \qmlmethod AbstractBarSeries::clear() | |
187 | Removes all barsets from the series. |
|
187 | Removes all barsets from the series. | |
188 | */ |
|
188 | */ | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | Destructs abstractbarseries and owned barsets. |
|
191 | Destructs abstractbarseries and owned barsets. | |
192 | */ |
|
192 | */ | |
193 | QAbstractBarSeries::~QAbstractBarSeries() |
|
193 | QAbstractBarSeries::~QAbstractBarSeries() | |
194 | { |
|
194 | { | |
195 |
|
195 | |||
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | \internal |
|
199 | \internal | |
200 | */ |
|
200 | */ | |
201 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
201 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : | |
202 | QAbstractSeries(d,parent) |
|
202 | QAbstractSeries(d,parent) | |
203 | { |
|
203 | { | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
207 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
208 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
208 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
209 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
209 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
210 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
210 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
211 | */ |
|
211 | */ | |
212 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
212 | void QAbstractBarSeries::setBarWidth(qreal width) | |
213 | { |
|
213 | { | |
214 | Q_D(QAbstractBarSeries); |
|
214 | Q_D(QAbstractBarSeries); | |
215 | d->setBarWidth(width); |
|
215 | d->setBarWidth(width); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | Returns the width of the bars of the series. |
|
219 | Returns the width of the bars of the series. | |
220 | \sa setBarWidth() |
|
220 | \sa setBarWidth() | |
221 | */ |
|
221 | */ | |
222 | qreal QAbstractBarSeries::barWidth() const |
|
222 | qreal QAbstractBarSeries::barWidth() const | |
223 | { |
|
223 | { | |
224 | Q_D(const QAbstractBarSeries); |
|
224 | Q_D(const QAbstractBarSeries); | |
225 | return d->barWidth(); |
|
225 | return d->barWidth(); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | /*! |
|
228 | /*! | |
229 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
229 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
230 | Returns true, if appending succeeded. |
|
230 | Returns true, if appending succeeded. | |
231 | */ |
|
231 | */ | |
232 | bool QAbstractBarSeries::append(QBarSet *set) |
|
232 | bool QAbstractBarSeries::append(QBarSet *set) | |
233 | { |
|
233 | { | |
234 | Q_D(QAbstractBarSeries); |
|
234 | Q_D(QAbstractBarSeries); | |
235 | bool success = d->append(set); |
|
235 | bool success = d->append(set); | |
236 | if (success) { |
|
236 | if (success) { | |
237 | QList<QBarSet*> sets; |
|
237 | QList<QBarSet*> sets; | |
238 | sets.append(set); |
|
238 | sets.append(set); | |
239 | set->setParent(this); |
|
239 | set->setParent(this); | |
240 | emit barsetsAdded(sets); |
|
240 | emit barsetsAdded(sets); | |
241 | emit countChanged(); |
|
241 | emit countChanged(); | |
242 | } |
|
242 | } | |
243 | return success; |
|
243 | return success; | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | /*! |
|
246 | /*! | |
247 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove |
|
247 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove | |
248 | was successful. |
|
248 | was successful. | |
249 | Returns true, if set was removed. |
|
249 | Returns true, if set was removed. | |
250 | */ |
|
250 | */ | |
251 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
251 | bool QAbstractBarSeries::remove(QBarSet *set) | |
252 | { |
|
252 | { | |
253 | Q_D(QAbstractBarSeries); |
|
253 | Q_D(QAbstractBarSeries); | |
254 | bool success = d->remove(set); |
|
254 | bool success = d->remove(set); | |
255 | if (success) { |
|
255 | if (success) { | |
256 | QList<QBarSet*> sets; |
|
256 | QList<QBarSet*> sets; | |
257 | sets.append(set); |
|
257 | sets.append(set); | |
258 | set->setParent(0); |
|
258 | set->setParent(0); | |
259 | emit barsetsRemoved(sets); |
|
259 | emit barsetsRemoved(sets); | |
260 | emit countChanged(); |
|
260 | emit countChanged(); | |
261 | delete set; |
|
261 | delete set; | |
262 | set = 0; |
|
262 | set = 0; | |
263 | } |
|
263 | } | |
264 | return success; |
|
264 | return success; | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | /*! |
|
267 | /*! | |
268 | Takes a single \a set from the series. Does not delete the barset object. |
|
268 | Takes a single \a set from the series. Does not delete the barset object. | |
269 |
|
269 | |||
270 | NOTE: The series remains as the barset's parent object. You must set the |
|
270 | NOTE: The series remains as the barset's parent object. You must set the | |
271 | parent object to take full ownership. |
|
271 | parent object to take full ownership. | |
272 |
|
272 | |||
273 | Returns true if take was successfull. |
|
273 | Returns true if take was successfull. | |
274 | */ |
|
274 | */ | |
275 | bool QAbstractBarSeries::take(QBarSet *set) |
|
275 | bool QAbstractBarSeries::take(QBarSet *set) | |
276 | { |
|
276 | { | |
277 | Q_D(QAbstractBarSeries); |
|
277 | Q_D(QAbstractBarSeries); | |
278 | bool success = d->remove(set); |
|
278 | bool success = d->remove(set); | |
279 | if (success) { |
|
279 | if (success) { | |
280 | QList<QBarSet*> sets; |
|
280 | QList<QBarSet*> sets; | |
281 | sets.append(set); |
|
281 | sets.append(set); | |
282 | emit barsetsRemoved(sets); |
|
282 | emit barsetsRemoved(sets); | |
283 | emit countChanged(); |
|
283 | emit countChanged(); | |
284 | } |
|
284 | } | |
285 | return success; |
|
285 | return success; | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | /*! |
|
288 | /*! | |
289 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
289 | Adds a list of barsets to series. Takes ownership of \a sets. | |
290 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
290 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
291 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
291 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
292 | and function returns false. |
|
292 | and function returns false. | |
293 | */ |
|
293 | */ | |
294 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
294 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) | |
295 | { |
|
295 | { | |
296 | Q_D(QAbstractBarSeries); |
|
296 | Q_D(QAbstractBarSeries); | |
297 | bool success = d->append(sets); |
|
297 | bool success = d->append(sets); | |
298 | if (success) { |
|
298 | if (success) { | |
299 | emit barsetsAdded(sets); |
|
299 | emit barsetsAdded(sets); | |
300 | emit countChanged(); |
|
300 | emit countChanged(); | |
301 | } |
|
301 | } | |
302 | return success; |
|
302 | return success; | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | /*! |
|
305 | /*! | |
306 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
306 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
307 | Returns true, if inserting succeeded. |
|
307 | Returns true, if inserting succeeded. | |
308 |
|
308 | |||
309 | */ |
|
309 | */ | |
310 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
310 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
311 | { |
|
311 | { | |
312 | Q_D(QAbstractBarSeries); |
|
312 | Q_D(QAbstractBarSeries); | |
313 | bool success = d->insert(index, set); |
|
313 | bool success = d->insert(index, set); | |
314 | if (success) { |
|
314 | if (success) { | |
315 | QList<QBarSet*> sets; |
|
315 | QList<QBarSet*> sets; | |
316 | sets.append(set); |
|
316 | sets.append(set); | |
317 | emit barsetsAdded(sets); |
|
317 | emit barsetsAdded(sets); | |
318 | emit countChanged(); |
|
318 | emit countChanged(); | |
319 | } |
|
319 | } | |
320 | return success; |
|
320 | return success; | |
321 | } |
|
321 | } | |
322 |
|
322 | |||
323 | /*! |
|
323 | /*! | |
324 | Removes all barsets from the series. Deletes removed sets. |
|
324 | Removes all barsets from the series. Deletes removed sets. | |
325 | */ |
|
325 | */ | |
326 | void QAbstractBarSeries::clear() |
|
326 | void QAbstractBarSeries::clear() | |
327 | { |
|
327 | { | |
328 | Q_D(QAbstractBarSeries); |
|
328 | Q_D(QAbstractBarSeries); | |
329 | QList<QBarSet *> sets = barSets(); |
|
329 | QList<QBarSet *> sets = barSets(); | |
330 | bool success = d->remove(sets); |
|
330 | bool success = d->remove(sets); | |
331 | if (success) { |
|
331 | if (success) { | |
332 | emit barsetsRemoved(sets); |
|
332 | emit barsetsRemoved(sets); | |
333 | emit countChanged(); |
|
333 | emit countChanged(); | |
334 | foreach (QBarSet* set, sets) { |
|
334 | foreach (QBarSet* set, sets) { | |
335 | delete set; |
|
335 | delete set; | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | /*! |
|
340 | /*! | |
341 | Returns number of sets in series. |
|
341 | Returns number of sets in series. | |
342 | */ |
|
342 | */ | |
343 | int QAbstractBarSeries::count() const |
|
343 | int QAbstractBarSeries::count() const | |
344 | { |
|
344 | { | |
345 | Q_D(const QAbstractBarSeries); |
|
345 | Q_D(const QAbstractBarSeries); | |
346 | return d->m_barSets.count(); |
|
346 | return d->m_barSets.count(); | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | /*! |
|
349 | /*! | |
350 | Returns a list of sets in series. Keeps ownership of sets. |
|
350 | Returns a list of sets in series. Keeps ownership of sets. | |
351 | */ |
|
351 | */ | |
352 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
352 | QList<QBarSet*> QAbstractBarSeries::barSets() const | |
353 | { |
|
353 | { | |
354 | Q_D(const QAbstractBarSeries); |
|
354 | Q_D(const QAbstractBarSeries); | |
355 | return d->m_barSets; |
|
355 | return d->m_barSets; | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | /*! |
|
358 | /*! | |
359 | Sets the visibility of labels in series to \a visible |
|
359 | Sets the visibility of labels in series to \a visible | |
360 | */ |
|
360 | */ | |
361 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
361 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
362 | { |
|
362 | { | |
363 | Q_D(QAbstractBarSeries); |
|
363 | Q_D(QAbstractBarSeries); | |
364 | if (d->m_labelsVisible != visible) { |
|
364 | if (d->m_labelsVisible != visible) { | |
365 | d->setLabelsVisible(visible); |
|
365 | d->setLabelsVisible(visible); | |
366 | emit labelsVisibleChanged(); |
|
366 | emit labelsVisibleChanged(); | |
367 | } |
|
367 | } | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | /*! |
|
370 | /*! | |
371 | Returns the visibility of labels |
|
371 | Returns the visibility of labels | |
372 | */ |
|
372 | */ | |
373 | bool QAbstractBarSeries::isLabelsVisible() const |
|
373 | bool QAbstractBarSeries::isLabelsVisible() const | |
374 | { |
|
374 | { | |
375 | Q_D(const QAbstractBarSeries); |
|
375 | Q_D(const QAbstractBarSeries); | |
376 | return d->m_labelsVisible; |
|
376 | return d->m_labelsVisible; | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
379 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
380 |
|
380 | |||
381 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
381 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
382 | QAbstractSeriesPrivate(q), |
|
382 | QAbstractSeriesPrivate(q), | |
383 | m_barWidth(0.5), // Default value is 50% of category width |
|
383 | m_barWidth(0.5), // Default value is 50% of category width | |
384 | m_labelsVisible(false), |
|
384 | m_labelsVisible(false), | |
385 | m_visible(true) |
|
385 | m_visible(true) | |
386 | { |
|
386 | { | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
389 | int QAbstractBarSeriesPrivate::categoryCount() const | |
390 | { |
|
390 | { | |
391 | // No categories defined. return count of longest set. |
|
391 | // No categories defined. return count of longest set. | |
392 | int count = 0; |
|
392 | int count = 0; | |
393 | for (int i=0; i<m_barSets.count(); i++) { |
|
393 | for (int i=0; i<m_barSets.count(); i++) { | |
394 | if (m_barSets.at(i)->count() > count) { |
|
394 | if (m_barSets.at(i)->count() > count) { | |
395 | count = m_barSets.at(i)->count(); |
|
395 | count = m_barSets.at(i)->count(); | |
396 | } |
|
396 | } | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | return count; |
|
399 | return count; | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
402 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
403 | { |
|
403 | { | |
404 | if (width < 0.0) { |
|
404 | if (width < 0.0) { | |
405 | width = 0.0; |
|
405 | width = 0.0; | |
406 | } |
|
406 | } | |
407 | m_barWidth = width; |
|
407 | m_barWidth = width; | |
408 |
emit updated |
|
408 | emit updatedLayout(); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
411 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
412 | { |
|
412 | { | |
413 | return m_barWidth; |
|
413 | return m_barWidth; | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
416 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) | |
417 | { |
|
417 | { | |
418 | return m_barSets.at(index); |
|
418 | return m_barSets.at(index); | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
421 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
422 | { |
|
422 | { | |
423 | m_visible = visible; |
|
423 | m_visible = visible; | |
424 |
emit |
|
424 | emit visibleChanged(); | |
425 | } |
|
425 | } | |
426 |
|
426 | |||
427 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
427 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
428 | { |
|
428 | { | |
429 | m_labelsVisible = visible; |
|
429 | m_labelsVisible = visible; | |
430 | emit labelsVisibleChanged(visible); |
|
430 | emit labelsVisibleChanged(visible); | |
431 | } |
|
431 | } | |
432 |
|
432 | |||
433 | qreal QAbstractBarSeriesPrivate::min() |
|
433 | qreal QAbstractBarSeriesPrivate::min() | |
434 | { |
|
434 | { | |
435 | if (m_barSets.count() <= 0) { |
|
435 | if (m_barSets.count() <= 0) { | |
436 | return 0; |
|
436 | return 0; | |
437 | } |
|
437 | } | |
438 | qreal min = INT_MAX; |
|
438 | qreal min = INT_MAX; | |
439 |
|
439 | |||
440 | for (int i = 0; i < m_barSets.count(); i++) { |
|
440 | for (int i = 0; i < m_barSets.count(); i++) { | |
441 | int categoryCount = m_barSets.at(i)->count(); |
|
441 | int categoryCount = m_barSets.at(i)->count(); | |
442 | for (int j = 0; j < categoryCount; j++) { |
|
442 | for (int j = 0; j < categoryCount; j++) { | |
443 | qreal temp = m_barSets.at(i)->at(j); |
|
443 | qreal temp = m_barSets.at(i)->at(j); | |
444 | if (temp < min) |
|
444 | if (temp < min) | |
445 | min = temp; |
|
445 | min = temp; | |
446 | } |
|
446 | } | |
447 | } |
|
447 | } | |
448 | return min; |
|
448 | return min; | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | qreal QAbstractBarSeriesPrivate::max() |
|
451 | qreal QAbstractBarSeriesPrivate::max() | |
452 | { |
|
452 | { | |
453 | if (m_barSets.count() <= 0) { |
|
453 | if (m_barSets.count() <= 0) { | |
454 | return 0; |
|
454 | return 0; | |
455 | } |
|
455 | } | |
456 | qreal max = INT_MIN; |
|
456 | qreal max = INT_MIN; | |
457 |
|
457 | |||
458 | for (int i = 0; i < m_barSets.count(); i++) { |
|
458 | for (int i = 0; i < m_barSets.count(); i++) { | |
459 | int categoryCount = m_barSets.at(i)->count(); |
|
459 | int categoryCount = m_barSets.at(i)->count(); | |
460 | for (int j = 0; j < categoryCount; j++) { |
|
460 | for (int j = 0; j < categoryCount; j++) { | |
461 | qreal temp = m_barSets.at(i)->at(j); |
|
461 | qreal temp = m_barSets.at(i)->at(j); | |
462 | if (temp > max) |
|
462 | if (temp > max) | |
463 | max = temp; |
|
463 | max = temp; | |
464 | } |
|
464 | } | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | return max; |
|
467 | return max; | |
468 | } |
|
468 | } | |
469 |
|
469 | |||
470 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
470 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
471 | { |
|
471 | { | |
472 | if ((set < 0) || (set >= m_barSets.count())) { |
|
472 | if ((set < 0) || (set >= m_barSets.count())) { | |
473 | // No set, no value. |
|
473 | // No set, no value. | |
474 | return 0; |
|
474 | return 0; | |
475 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
475 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
476 | // No category, no value. |
|
476 | // No category, no value. | |
477 | return 0; |
|
477 | return 0; | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | return m_barSets.at(set)->at(category); |
|
480 | return m_barSets.at(set)->at(category); | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
483 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
484 | { |
|
484 | { | |
485 | if ((set < 0) || (set >= m_barSets.count())) { |
|
485 | if ((set < 0) || (set >= m_barSets.count())) { | |
486 | // No set, no value. |
|
486 | // No set, no value. | |
487 | return 0; |
|
487 | return 0; | |
488 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
488 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
489 | // No category, no value. |
|
489 | // No category, no value. | |
490 | return 0; |
|
490 | return 0; | |
491 | } |
|
491 | } | |
492 |
|
492 | |||
493 | qreal value = m_barSets.at(set)->at(category); |
|
493 | qreal value = m_barSets.at(set)->at(category); | |
494 | qreal sum = categorySum(category); |
|
494 | qreal sum = categorySum(category); | |
495 | if ( qFuzzyIsNull(sum) ) { |
|
495 | if ( qFuzzyIsNull(sum) ) { | |
496 | return 0; |
|
496 | return 0; | |
497 | } |
|
497 | } | |
498 |
|
498 | |||
499 | return value / sum; |
|
499 | return value / sum; | |
500 | } |
|
500 | } | |
501 |
|
501 | |||
502 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
502 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
503 | { |
|
503 | { | |
504 | qreal sum(0); |
|
504 | qreal sum(0); | |
505 | int count = m_barSets.count(); // Count sets |
|
505 | int count = m_barSets.count(); // Count sets | |
506 | for (int set = 0; set < count; set++) { |
|
506 | for (int set = 0; set < count; set++) { | |
507 | if (category < m_barSets.at(set)->count()) |
|
507 | if (category < m_barSets.at(set)->count()) | |
508 | sum += m_barSets.at(set)->at(category); |
|
508 | sum += m_barSets.at(set)->at(category); | |
509 | } |
|
509 | } | |
510 | return sum; |
|
510 | return sum; | |
511 | } |
|
511 | } | |
512 |
|
512 | |||
513 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
513 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
514 | { |
|
514 | { | |
515 | qreal sum(0); |
|
515 | qreal sum(0); | |
516 | int count = m_barSets.count(); // Count sets |
|
516 | int count = m_barSets.count(); // Count sets | |
517 | for (int set = 0; set < count; set++) { |
|
517 | for (int set = 0; set < count; set++) { | |
518 | if (category < m_barSets.at(set)->count()) |
|
518 | if (category < m_barSets.at(set)->count()) | |
519 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
519 | sum += qAbs(m_barSets.at(set)->at(category)); | |
520 | } |
|
520 | } | |
521 | return sum; |
|
521 | return sum; | |
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
524 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
525 | { |
|
525 | { | |
526 | qreal max = INT_MIN; |
|
526 | qreal max = INT_MIN; | |
527 | int count = categoryCount(); |
|
527 | int count = categoryCount(); | |
528 | for (int i = 0; i < count; i++) { |
|
528 | for (int i = 0; i < count; i++) { | |
529 | qreal sum = categorySum(i); |
|
529 | qreal sum = categorySum(i); | |
530 | if (sum > max) |
|
530 | if (sum > max) | |
531 | max = sum; |
|
531 | max = sum; | |
532 | } |
|
532 | } | |
533 | return max; |
|
533 | return max; | |
534 | } |
|
534 | } | |
535 |
|
535 | |||
536 | qreal QAbstractBarSeriesPrivate::minX() |
|
536 | qreal QAbstractBarSeriesPrivate::minX() | |
537 | { |
|
537 | { | |
538 | if (m_barSets.count() <= 0) { |
|
538 | if (m_barSets.count() <= 0) { | |
539 | return 0; |
|
539 | return 0; | |
540 | } |
|
540 | } | |
541 | qreal min = INT_MAX; |
|
541 | qreal min = INT_MAX; | |
542 |
|
542 | |||
543 | for (int i = 0; i < m_barSets.count(); i++) { |
|
543 | for (int i = 0; i < m_barSets.count(); i++) { | |
544 | int categoryCount = m_barSets.at(i)->count(); |
|
544 | int categoryCount = m_barSets.at(i)->count(); | |
545 | for (int j = 0; j < categoryCount; j++) { |
|
545 | for (int j = 0; j < categoryCount; j++) { | |
546 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
546 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
547 | if (temp < min) |
|
547 | if (temp < min) | |
548 | min = temp; |
|
548 | min = temp; | |
549 | } |
|
549 | } | |
550 | } |
|
550 | } | |
551 | return min; |
|
551 | return min; | |
552 | } |
|
552 | } | |
553 |
|
553 | |||
554 | qreal QAbstractBarSeriesPrivate::maxX() |
|
554 | qreal QAbstractBarSeriesPrivate::maxX() | |
555 | { |
|
555 | { | |
556 | if (m_barSets.count() <= 0) { |
|
556 | if (m_barSets.count() <= 0) { | |
557 | return 0; |
|
557 | return 0; | |
558 | } |
|
558 | } | |
559 | qreal max = INT_MIN; |
|
559 | qreal max = INT_MIN; | |
560 |
|
560 | |||
561 | for (int i = 0; i < m_barSets.count(); i++) { |
|
561 | for (int i = 0; i < m_barSets.count(); i++) { | |
562 | int categoryCount = m_barSets.at(i)->count(); |
|
562 | int categoryCount = m_barSets.at(i)->count(); | |
563 | for (int j = 0; j < categoryCount; j++) { |
|
563 | for (int j = 0; j < categoryCount; j++) { | |
564 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
564 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
565 | if (temp > max) |
|
565 | if (temp > max) | |
566 | max = temp; |
|
566 | max = temp; | |
567 | } |
|
567 | } | |
568 | } |
|
568 | } | |
569 |
|
569 | |||
570 | return max; |
|
570 | return max; | |
571 | } |
|
571 | } | |
572 |
|
572 | |||
573 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) |
|
573 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) | |
574 | { |
|
574 | { | |
575 | // Returns top (sum of all positive values) of category. |
|
575 | // Returns top (sum of all positive values) of category. | |
576 | // Returns 0, if all values are negative |
|
576 | // Returns 0, if all values are negative | |
577 | qreal top(0); |
|
577 | qreal top(0); | |
578 | int count = m_barSets.count(); |
|
578 | int count = m_barSets.count(); | |
579 | for (int set = 0; set < count; set++) { |
|
579 | for (int set = 0; set < count; set++) { | |
580 | if (category < m_barSets.at(set)->count()) { |
|
580 | if (category < m_barSets.at(set)->count()) { | |
581 | qreal temp = m_barSets.at(set)->at(category); |
|
581 | qreal temp = m_barSets.at(set)->at(category); | |
582 | if (temp > 0) { |
|
582 | if (temp > 0) { | |
583 | top += temp; |
|
583 | top += temp; | |
584 | } |
|
584 | } | |
585 | } |
|
585 | } | |
586 | } |
|
586 | } | |
587 | return top; |
|
587 | return top; | |
588 | } |
|
588 | } | |
589 |
|
589 | |||
590 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) |
|
590 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) | |
591 | { |
|
591 | { | |
592 | // Returns bottom (sum of all negative values) of category |
|
592 | // Returns bottom (sum of all negative values) of category | |
593 | // Returns 0, if all values are positive |
|
593 | // Returns 0, if all values are positive | |
594 | qreal bottom(0); |
|
594 | qreal bottom(0); | |
595 | int count = m_barSets.count(); |
|
595 | int count = m_barSets.count(); | |
596 | for (int set = 0; set < count; set++) { |
|
596 | for (int set = 0; set < count; set++) { | |
597 | if (category < m_barSets.at(set)->count()) { |
|
597 | if (category < m_barSets.at(set)->count()) { | |
598 | qreal temp = m_barSets.at(set)->at(category); |
|
598 | qreal temp = m_barSets.at(set)->at(category); | |
599 | if (temp < 0) { |
|
599 | if (temp < 0) { | |
600 | bottom += temp; |
|
600 | bottom += temp; | |
601 | } |
|
601 | } | |
602 | } |
|
602 | } | |
603 | } |
|
603 | } | |
604 | return bottom; |
|
604 | return bottom; | |
605 | } |
|
605 | } | |
606 |
|
606 | |||
607 | qreal QAbstractBarSeriesPrivate::top() |
|
607 | qreal QAbstractBarSeriesPrivate::top() | |
608 | { |
|
608 | { | |
609 | // Returns top of all categories |
|
609 | // Returns top of all categories | |
610 | qreal top(0); |
|
610 | qreal top(0); | |
611 | int count = categoryCount(); |
|
611 | int count = categoryCount(); | |
612 | for (int i=0; i<count; i++) { |
|
612 | for (int i=0; i<count; i++) { | |
613 | qreal temp = categoryTop(i); |
|
613 | qreal temp = categoryTop(i); | |
614 | if (temp > top) { |
|
614 | if (temp > top) { | |
615 | top = temp; |
|
615 | top = temp; | |
616 | } |
|
616 | } | |
617 | } |
|
617 | } | |
618 | return top; |
|
618 | return top; | |
619 | } |
|
619 | } | |
620 |
|
620 | |||
621 | qreal QAbstractBarSeriesPrivate::bottom() |
|
621 | qreal QAbstractBarSeriesPrivate::bottom() | |
622 | { |
|
622 | { | |
623 | // Returns bottom of all categories |
|
623 | // Returns bottom of all categories | |
624 | qreal bottom(0); |
|
624 | qreal bottom(0); | |
625 | int count = categoryCount(); |
|
625 | int count = categoryCount(); | |
626 | for (int i=0; i<count; i++) { |
|
626 | for (int i=0; i<count; i++) { | |
627 | qreal temp = categoryBottom(i); |
|
627 | qreal temp = categoryBottom(i); | |
628 | if (temp < bottom) { |
|
628 | if (temp < bottom) { | |
629 | bottom = temp; |
|
629 | bottom = temp; | |
630 | } |
|
630 | } | |
631 | } |
|
631 | } | |
632 | return bottom; |
|
632 | return bottom; | |
633 | } |
|
633 | } | |
634 |
|
634 | |||
635 |
|
635 | |||
636 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
636 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) | |
637 | { |
|
637 | { | |
638 | qreal minX(domain.minX()); |
|
638 | qreal minX(domain.minX()); | |
639 | qreal minY(domain.minY()); |
|
639 | qreal minY(domain.minY()); | |
640 | qreal maxX(domain.maxX()); |
|
640 | qreal maxX(domain.maxX()); | |
641 | qreal maxY(domain.maxY()); |
|
641 | qreal maxY(domain.maxY()); | |
642 |
|
642 | |||
643 | qreal seriesMinX = this->minX(); |
|
643 | qreal seriesMinX = this->minX(); | |
644 | qreal seriesMaxX = this->maxX(); |
|
644 | qreal seriesMaxX = this->maxX(); | |
645 | qreal y = max(); |
|
645 | qreal y = max(); | |
646 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
646 | minX = qMin(minX, seriesMinX - (qreal)0.5); | |
647 | minY = qMin(minY, y); |
|
647 | minY = qMin(minY, y); | |
648 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
648 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); | |
649 | maxY = qMax(maxY, y); |
|
649 | maxY = qMax(maxY, y); | |
650 |
|
650 | |||
651 | domain.setRange(minX,maxX,minY,maxY); |
|
651 | domain.setRange(minX,maxX,minY,maxY); | |
652 | } |
|
652 | } | |
653 |
|
653 | |||
654 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
654 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
655 | { |
|
655 | { | |
656 | Q_UNUSED(presenter); |
|
656 | Q_UNUSED(presenter); | |
657 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
657 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; | |
658 | return 0; |
|
658 | return 0; | |
659 | } |
|
659 | } | |
660 |
|
660 | |||
661 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
661 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
662 | { |
|
662 | { | |
663 | Q_Q(QAbstractBarSeries); |
|
663 | Q_Q(QAbstractBarSeries); | |
664 | QList<LegendMarker*> markers; |
|
664 | QList<LegendMarker*> markers; | |
665 | foreach(QBarSet* set, q->barSets()) { |
|
665 | foreach(QBarSet* set, q->barSets()) { | |
666 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
666 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
667 | markers << marker; |
|
667 | markers << marker; | |
668 | } |
|
668 | } | |
669 |
|
669 | |||
670 | return markers; |
|
670 | return markers; | |
671 | } |
|
671 | } | |
672 |
|
672 | |||
673 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
673 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
674 | { |
|
674 | { | |
675 | Q_Q(QAbstractBarSeries); |
|
675 | Q_Q(QAbstractBarSeries); | |
676 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
676 | if ((m_barSets.contains(set)) || (set == 0)) { | |
677 | // Fail if set is already in list or set is null. |
|
677 | // Fail if set is already in list or set is null. | |
678 | return false; |
|
678 | return false; | |
679 | } |
|
679 | } | |
680 | m_barSets.append(set); |
|
680 | m_barSets.append(set); | |
|
681 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |||
681 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
682 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
682 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
683 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
683 | emit restructuredBars(); // this notifies barchartitem |
|
684 | emit restructuredBars(); // this notifies barchartitem | |
684 | if (m_dataset) { |
|
685 | if (m_dataset) { | |
685 | m_dataset->updateSeries(q); // this notifies legend |
|
686 | m_dataset->updateSeries(q); // this notifies legend | |
686 | } |
|
687 | } | |
687 | return true; |
|
688 | return true; | |
688 | } |
|
689 | } | |
689 |
|
690 | |||
690 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
691 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
691 | { |
|
692 | { | |
692 | Q_Q(QAbstractBarSeries); |
|
693 | Q_Q(QAbstractBarSeries); | |
693 | if (!m_barSets.contains(set)) { |
|
694 | if (!m_barSets.contains(set)) { | |
694 | // Fail if set is not in list |
|
695 | // Fail if set is not in list | |
695 | return false; |
|
696 | return false; | |
696 | } |
|
697 | } | |
697 | m_barSets.removeOne(set); |
|
698 | m_barSets.removeOne(set); | |
|
699 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |||
698 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
700 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
699 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
701 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
700 | emit restructuredBars(); // this notifies barchartitem |
|
702 | emit restructuredBars(); // this notifies barchartitem | |
701 | if (m_dataset) { |
|
703 | if (m_dataset) { | |
702 | m_dataset->updateSeries(q); // this notifies legend |
|
704 | m_dataset->updateSeries(q); // this notifies legend | |
703 | } |
|
705 | } | |
704 | return true; |
|
706 | return true; | |
705 | } |
|
707 | } | |
706 |
|
708 | |||
707 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
709 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) | |
708 | { |
|
710 | { | |
709 | Q_Q(QAbstractBarSeries); |
|
711 | Q_Q(QAbstractBarSeries); | |
710 | foreach (QBarSet* set, sets) { |
|
712 | foreach (QBarSet* set, sets) { | |
711 | if ((set == 0) || (m_barSets.contains(set))) { |
|
713 | if ((set == 0) || (m_barSets.contains(set))) { | |
712 | // Fail if any of the sets is null or is already appended. |
|
714 | // Fail if any of the sets is null or is already appended. | |
713 | return false; |
|
715 | return false; | |
714 | } |
|
716 | } | |
715 | if (sets.count(set) != 1) { |
|
717 | if (sets.count(set) != 1) { | |
716 | // Also fail if same set is more than once in given list. |
|
718 | // Also fail if same set is more than once in given list. | |
717 | return false; |
|
719 | return false; | |
718 | } |
|
720 | } | |
719 | } |
|
721 | } | |
720 |
|
722 | |||
721 | foreach (QBarSet* set, sets) { |
|
723 | foreach (QBarSet* set, sets) { | |
722 | m_barSets.append(set); |
|
724 | m_barSets.append(set); | |
|
725 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |||
723 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
726 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
724 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
727 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
725 | } |
|
728 | } | |
726 | emit restructuredBars(); // this notifies barchartitem |
|
729 | emit restructuredBars(); // this notifies barchartitem | |
727 | if (m_dataset) { |
|
730 | if (m_dataset) { | |
728 | m_dataset->updateSeries(q); // this notifies legend |
|
731 | m_dataset->updateSeries(q); // this notifies legend | |
729 | } |
|
732 | } | |
730 | return true; |
|
733 | return true; | |
731 | } |
|
734 | } | |
732 |
|
735 | |||
733 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
736 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
734 | { |
|
737 | { | |
735 | Q_Q(QAbstractBarSeries); |
|
738 | Q_Q(QAbstractBarSeries); | |
736 | if (sets.count() == 0) { |
|
739 | if (sets.count() == 0) { | |
737 | return false; |
|
740 | return false; | |
738 | } |
|
741 | } | |
739 | foreach (QBarSet* set, sets) { |
|
742 | foreach (QBarSet* set, sets) { | |
740 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
743 | if ((set == 0) || (!m_barSets.contains(set))) { | |
741 | // Fail if any of the sets is null or is not in series |
|
744 | // Fail if any of the sets is null or is not in series | |
742 | return false; |
|
745 | return false; | |
743 | } |
|
746 | } | |
744 | if (sets.count(set) != 1) { |
|
747 | if (sets.count(set) != 1) { | |
745 | // Also fail if same set is more than once in given list. |
|
748 | // Also fail if same set is more than once in given list. | |
746 | return false; |
|
749 | return false; | |
747 | } |
|
750 | } | |
748 | } |
|
751 | } | |
749 |
|
752 | |||
750 | foreach (QBarSet* set, sets) { |
|
753 | foreach (QBarSet* set, sets) { | |
751 | m_barSets.removeOne(set); |
|
754 | m_barSets.removeOne(set); | |
|
755 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |||
752 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
756 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
753 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
757 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
754 | } |
|
758 | } | |
755 |
|
759 | |||
756 | emit restructuredBars(); // this notifies barchartitem |
|
760 | emit restructuredBars(); // this notifies barchartitem | |
757 | if (m_dataset) { |
|
761 | if (m_dataset) { | |
758 | m_dataset->updateSeries(q); // this notifies legend |
|
762 | m_dataset->updateSeries(q); // this notifies legend | |
759 | } |
|
763 | } | |
760 | return true; |
|
764 | return true; | |
761 | } |
|
765 | } | |
762 |
|
766 | |||
763 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
767 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
764 | { |
|
768 | { | |
765 | Q_Q(QAbstractBarSeries); |
|
769 | Q_Q(QAbstractBarSeries); | |
766 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
770 | if ((m_barSets.contains(set)) || (set == 0)) { | |
767 | // Fail if set is already in list or set is null. |
|
771 | // Fail if set is already in list or set is null. | |
768 | return false; |
|
772 | return false; | |
769 | } |
|
773 | } | |
770 | m_barSets.insert(index, set); |
|
774 | m_barSets.insert(index, set); | |
|
775 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |||
771 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
776 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
772 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
777 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
773 | emit restructuredBars(); // this notifies barchartitem |
|
778 | emit restructuredBars(); // this notifies barchartitem | |
774 | if (m_dataset) { |
|
779 | if (m_dataset) { | |
775 | m_dataset->updateSeries(q); // this notifies legend |
|
780 | m_dataset->updateSeries(q); // this notifies legend | |
776 | } |
|
781 | } | |
777 | return true; |
|
782 | return true; | |
778 | } |
|
783 | } | |
779 |
|
784 | |||
780 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
785 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
781 | { |
|
786 | { | |
782 | Q_Q(QAbstractBarSeries); |
|
787 | Q_Q(QAbstractBarSeries); | |
783 |
|
788 | |||
784 | if(axis->type()==QAbstractAxis::AxisTypeBarCategory) { |
|
789 | if(axis->type()==QAbstractAxis::AxisTypeBarCategory) { | |
785 |
|
790 | |||
786 | switch(q->type()) { |
|
791 | switch(q->type()) { | |
787 |
|
792 | |||
788 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
793 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
789 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
794 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
790 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
795 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { | |
791 |
|
796 | |||
792 | if(axis->orientation()==Qt::Vertical) |
|
797 | if(axis->orientation()==Qt::Vertical) | |
793 | { |
|
798 | { | |
794 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); |
|
799 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); | |
795 | } |
|
800 | } | |
796 | break; |
|
801 | break; | |
797 | } |
|
802 | } | |
798 | case QAbstractSeries::SeriesTypeBar: |
|
803 | case QAbstractSeries::SeriesTypeBar: | |
799 | case QAbstractSeries::SeriesTypePercentBar: |
|
804 | case QAbstractSeries::SeriesTypePercentBar: | |
800 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
805 | case QAbstractSeries::SeriesTypeStackedBar: { | |
801 |
|
806 | |||
802 | if(axis->orientation()==Qt::Horizontal) |
|
807 | if(axis->orientation()==Qt::Horizontal) | |
803 | { |
|
808 | { | |
804 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); |
|
809 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); | |
805 | } |
|
810 | } | |
806 | break; |
|
811 | break; | |
807 | } |
|
812 | } | |
808 | default: |
|
813 | default: | |
809 | qWarning()<<"Unexpected series type"; |
|
814 | qWarning()<<"Unexpected series type"; | |
810 | break; |
|
815 | break; | |
811 |
|
816 | |||
812 | } |
|
817 | } | |
813 | } |
|
818 | } | |
814 | } |
|
819 | } | |
815 |
|
820 | |||
816 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
821 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
817 | { |
|
822 | { | |
818 | Q_Q(const QAbstractBarSeries); |
|
823 | Q_Q(const QAbstractBarSeries); | |
819 |
|
824 | |||
820 | switch(q->type()) { |
|
825 | switch(q->type()) { | |
821 |
|
826 | |||
822 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
827 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
823 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
828 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
824 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
829 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { | |
825 |
|
830 | |||
826 | if(orientation==Qt::Vertical) |
|
831 | if(orientation==Qt::Vertical) | |
827 | { |
|
832 | { | |
828 | return QAbstractAxis::AxisTypeBarCategory; |
|
833 | return QAbstractAxis::AxisTypeBarCategory; | |
829 | } |
|
834 | } | |
830 | break; |
|
835 | break; | |
831 | } |
|
836 | } | |
832 | case QAbstractSeries::SeriesTypeBar: |
|
837 | case QAbstractSeries::SeriesTypeBar: | |
833 | case QAbstractSeries::SeriesTypePercentBar: |
|
838 | case QAbstractSeries::SeriesTypePercentBar: | |
834 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
839 | case QAbstractSeries::SeriesTypeStackedBar: { | |
835 |
|
840 | |||
836 | if(orientation==Qt::Horizontal) |
|
841 | if(orientation==Qt::Horizontal) | |
837 | { |
|
842 | { | |
838 | return QAbstractAxis::AxisTypeBarCategory; |
|
843 | return QAbstractAxis::AxisTypeBarCategory; | |
839 | } |
|
844 | } | |
840 | break; |
|
845 | break; | |
841 | } |
|
846 | } | |
842 | default: |
|
847 | default: | |
843 | qWarning()<<"Unexpected series type"; |
|
848 | qWarning()<<"Unexpected series type"; | |
844 | break; |
|
849 | break; | |
845 |
|
850 | |||
846 | } |
|
851 | } | |
847 | return QAbstractAxis::AxisTypeValue; |
|
852 | return QAbstractAxis::AxisTypeValue; | |
848 |
|
853 | |||
849 | } |
|
854 | } | |
850 |
|
855 | |||
851 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis) |
|
856 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis) | |
852 | { |
|
857 | { | |
853 | QStringList categories; |
|
858 | QStringList categories; | |
854 | if(axis->categories().isEmpty()) { |
|
859 | if(axis->categories().isEmpty()) { | |
855 | for (int i(1); i < categoryCount()+1; i++) |
|
860 | for (int i(1); i < categoryCount()+1; i++) | |
856 | categories << QString::number(i); |
|
861 | categories << QString::number(i); | |
857 | axis->append(categories); |
|
862 | axis->append(categories); | |
858 | } |
|
863 | } | |
859 | } |
|
864 | } | |
860 |
|
865 | |||
861 | #include "moc_qabstractbarseries.cpp" |
|
866 | #include "moc_qabstractbarseries.cpp" | |
862 | #include "moc_qabstractbarseries_p.cpp" |
|
867 | #include "moc_qabstractbarseries_p.cpp" | |
863 |
|
868 | |||
864 |
|
869 | |||
865 | QTCOMMERCIALCHART_END_NAMESPACE |
|
870 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,107 +1,109 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QABSTRACTBARSERIES_P_H |
|
30 | #ifndef QABSTRACTBARSERIES_P_H | |
31 | #define QABSTRACTBARSERIES_P_H |
|
31 | #define QABSTRACTBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractbarseries.h" |
|
33 | #include "qabstractbarseries.h" | |
34 | #include "qabstractseries_p.h" |
|
34 | #include "qabstractseries_p.h" | |
35 | #include <QStringList> |
|
35 | #include <QStringList> | |
36 | #include <QAbstractSeries> |
|
36 | #include <QAbstractSeries> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class QBarModelMapper; |
|
40 | class QBarModelMapper; | |
41 | class QBarCategoryAxis; |
|
41 | class QBarCategoryAxis; | |
42 |
|
42 | |||
43 | class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate |
|
43 | class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate | |
44 | { |
|
44 | { | |
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 | public: |
|
46 | public: | |
47 | QAbstractBarSeriesPrivate(QAbstractBarSeries *parent); |
|
47 | QAbstractBarSeriesPrivate(QAbstractBarSeries *parent); | |
48 | int categoryCount() const; |
|
48 | int categoryCount() const; | |
49 |
|
49 | |||
50 | void setBarWidth(qreal width); |
|
50 | void setBarWidth(qreal width); | |
51 | qreal barWidth() const; |
|
51 | qreal barWidth() const; | |
52 |
|
52 | |||
53 | void setVisible(bool visible); |
|
53 | void setVisible(bool visible); | |
54 | void setLabelsVisible(bool visible); |
|
54 | void setLabelsVisible(bool visible); | |
55 |
|
55 | |||
56 | void scaleDomain(Domain& domain); |
|
56 | void scaleDomain(Domain& domain); | |
57 | ChartElement* createGraphics(ChartPresenter* presenter); |
|
57 | ChartElement* createGraphics(ChartPresenter* presenter); | |
58 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
58 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
59 |
|
59 | |||
60 | void initializeAxis(QAbstractAxis* axis); |
|
60 | void initializeAxis(QAbstractAxis* axis); | |
61 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
61 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
62 |
|
62 | |||
63 | bool append(QBarSet *set); |
|
63 | bool append(QBarSet *set); | |
64 | bool remove(QBarSet *set); |
|
64 | bool remove(QBarSet *set); | |
65 | bool append(QList<QBarSet* > sets); |
|
65 | bool append(QList<QBarSet* > sets); | |
66 | bool remove(QList<QBarSet* > sets); |
|
66 | bool remove(QList<QBarSet* > sets); | |
67 | bool insert(int index, QBarSet *set); |
|
67 | bool insert(int index, QBarSet *set); | |
68 |
|
68 | |||
69 | QBarSet* barsetAt(int index); |
|
69 | QBarSet* barsetAt(int index); | |
70 | qreal min(); |
|
70 | qreal min(); | |
71 | qreal max(); |
|
71 | qreal max(); | |
72 | qreal valueAt(int set, int category); |
|
72 | qreal valueAt(int set, int category); | |
73 | qreal percentageAt(int set, int category); |
|
73 | qreal percentageAt(int set, int category); | |
74 | qreal categorySum(int category); |
|
74 | qreal categorySum(int category); | |
75 | qreal absoluteCategorySum(int category); |
|
75 | qreal absoluteCategorySum(int category); | |
76 | qreal maxCategorySum(); |
|
76 | qreal maxCategorySum(); | |
77 | qreal minX(); |
|
77 | qreal minX(); | |
78 | qreal maxX(); |
|
78 | qreal maxX(); | |
79 | qreal categoryTop(int category); |
|
79 | qreal categoryTop(int category); | |
80 | qreal categoryBottom(int category); |
|
80 | qreal categoryBottom(int category); | |
81 | qreal top(); |
|
81 | qreal top(); | |
82 | qreal bottom(); |
|
82 | qreal bottom(); | |
83 |
|
83 | |||
84 | Q_SIGNALS: |
|
84 | Q_SIGNALS: | |
85 | void clicked(int index, QBarSet *barset); |
|
85 | void clicked(int index, QBarSet *barset); | |
86 | void updatedBars(); |
|
86 | void updatedBars(); | |
|
87 | void updatedLayout(); | |||
87 | void restructuredBars(); |
|
88 | void restructuredBars(); | |
88 | void labelsVisibleChanged(bool visible); |
|
89 | void labelsVisibleChanged(bool visible); | |
|
90 | void visibleChanged(); | |||
89 |
|
91 | |||
90 | private: |
|
92 | private: | |
91 | void populateCategories(QBarCategoryAxis* axis); |
|
93 | void populateCategories(QBarCategoryAxis* axis); | |
92 |
|
94 | |||
93 | protected: |
|
95 | protected: | |
94 | QList<QBarSet *> m_barSets; |
|
96 | QList<QBarSet *> m_barSets; | |
95 | qreal m_barWidth; |
|
97 | qreal m_barWidth; | |
96 | bool m_labelsVisible; |
|
98 | bool m_labelsVisible; | |
97 | bool m_visible; |
|
99 | bool m_visible; | |
98 |
|
100 | |||
99 | private: |
|
101 | private: | |
100 | Q_DECLARE_PUBLIC(QAbstractBarSeries) |
|
102 | Q_DECLARE_PUBLIC(QAbstractBarSeries) | |
101 | friend class HorizontalBarChartItem; |
|
103 | friend class HorizontalBarChartItem; | |
102 | friend class BarChartItem; |
|
104 | friend class BarChartItem; | |
103 | }; |
|
105 | }; | |
104 |
|
106 | |||
105 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |
106 |
|
108 | |||
107 | #endif // QABSTRACTBARSERIES_P_H |
|
109 | #endif // QABSTRACTBARSERIES_P_H |
@@ -1,650 +1,650 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include "qbarset_p.h" |
|
22 | #include "qbarset_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QBarSet |
|
27 | \class QBarSet | |
28 | \brief Building block for different bar charts |
|
28 | \brief Building block for different bar charts | |
29 |
|
29 | |||
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
31 | First value of set is assumed to belong to first category, second to second category and so on. | |
32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
32 | If set has fewer values than there are categories, then the missing values are assumed to be | |
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
34 |
|
34 | |||
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
37 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 | /*! |
|
39 | /*! | |
40 | \qmlclass BarSet QBarSet |
|
40 | \qmlclass BarSet QBarSet | |
41 |
|
41 | |||
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. | |
43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
43 | First value of set is assumed to belong to first category, second to second category and so on. | |
44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
44 | If set has fewer values than there are categories, then the missing values are assumed to be | |
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
46 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries |
|
46 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \property QBarSet::label |
|
50 | \property QBarSet::label | |
51 | Defines the label of the barSet. |
|
51 | Defines the label of the barSet. | |
52 | */ |
|
52 | */ | |
53 | /*! |
|
53 | /*! | |
54 | \qmlproperty string BarSet::label |
|
54 | \qmlproperty string BarSet::label | |
55 | Defines the label of the barSet. |
|
55 | Defines the label of the barSet. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QBarSet::pen |
|
59 | \property QBarSet::pen | |
60 | \brief Defines the pen used by the barSet. |
|
60 | \brief Defines the pen used by the barSet. | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QBarSet::brush |
|
64 | \property QBarSet::brush | |
65 | \brief Defines the brush used by the barSet. |
|
65 | \brief Defines the brush used by the barSet. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QBarSet::labelBrush |
|
69 | \property QBarSet::labelBrush | |
70 | \brief Defines the brush used by the barSet's label. |
|
70 | \brief Defines the brush used by the barSet's label. | |
71 | */ |
|
71 | */ | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | \property QBarSet::labelFont |
|
74 | \property QBarSet::labelFont | |
75 | \brief Defines the font used by the barSet's label. |
|
75 | \brief Defines the font used by the barSet's label. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \qmlproperty Font BarSet::labelFont |
|
79 | \qmlproperty Font BarSet::labelFont | |
80 | Defines the font used by the barSet's label. |
|
80 | Defines the font used by the barSet's label. | |
81 |
|
81 | |||
82 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
82 | See the \l {Font} {QML Font Element} for detailed documentation. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QBarSet::color |
|
86 | \property QBarSet::color | |
87 | The fill (brush) color of the bar set. |
|
87 | The fill (brush) color of the bar set. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty color BarSet::color |
|
90 | \qmlproperty color BarSet::color | |
91 | The fill (brush) color of the bar set. |
|
91 | The fill (brush) color of the bar set. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QBarSet::borderColor |
|
95 | \property QBarSet::borderColor | |
96 | The line (pen) color of the bar set. |
|
96 | The line (pen) color of the bar set. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty color BarSet::borderColor |
|
99 | \qmlproperty color BarSet::borderColor | |
100 | The line (pen) color of the bar set. |
|
100 | The line (pen) color of the bar set. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \qmlproperty real BarSet::borderWidth |
|
104 | \qmlproperty real BarSet::borderWidth | |
105 | The width of the border line. By default the width is 2.0. |
|
105 | The width of the border line. By default the width is 2.0. | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \property QBarSet::labelColor |
|
109 | \property QBarSet::labelColor | |
110 | The text (label) color of the bar set. |
|
110 | The text (label) color of the bar set. | |
111 | */ |
|
111 | */ | |
112 | /*! |
|
112 | /*! | |
113 | \qmlproperty color BarSet::labelColor |
|
113 | \qmlproperty color BarSet::labelColor | |
114 | The text (label) color of the bar set. |
|
114 | The text (label) color of the bar set. | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \fn void QBarSet::clicked(int index) |
|
118 | \fn void QBarSet::clicked(int index) | |
119 |
|
119 | |||
120 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
120 | The signal is emitted if the user clicks with a mouse on top of barset. | |
121 | Clicked bar inside set is indexed by \a index |
|
121 | Clicked bar inside set is indexed by \a index | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \fn void QBarSet::hovered(bool status) |
|
125 | \fn void QBarSet::hovered(bool status) | |
126 |
|
126 | |||
127 | The signal is emitted if mouse is hovered on top of barset. |
|
127 | The signal is emitted if mouse is hovered on top of barset. | |
128 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
128 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QBarSet::labelChanged() |
|
133 | \fn void QBarSet::labelChanged() | |
134 | This signal is emitted when the label of the barSet has changed. |
|
134 | This signal is emitted when the label of the barSet has changed. | |
135 | \sa label |
|
135 | \sa label | |
136 | */ |
|
136 | */ | |
137 | /*! |
|
137 | /*! | |
138 | \qmlsignal BarSet::onLabelChanged() |
|
138 | \qmlsignal BarSet::onLabelChanged() | |
139 | This signal is emitted when the label of the barSet has changed. |
|
139 | This signal is emitted when the label of the barSet has changed. | |
140 | */ |
|
140 | */ | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | \fn void QBarSet::penChanged() |
|
143 | \fn void QBarSet::penChanged() | |
144 | This signal is emitted when the pen of the barSet has changed. |
|
144 | This signal is emitted when the pen of the barSet has changed. | |
145 | \sa pen |
|
145 | \sa pen | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \fn void QBarSet::brushChanged() |
|
149 | \fn void QBarSet::brushChanged() | |
150 | This signal is emitted when the brush of the barSet has changed. |
|
150 | This signal is emitted when the brush of the barSet has changed. | |
151 | \sa brush |
|
151 | \sa brush | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \fn void QBarSet::labelBrushChanged() |
|
155 | \fn void QBarSet::labelBrushChanged() | |
156 | This signal is emitted when the brush of the barSet's label has changed. |
|
156 | This signal is emitted when the brush of the barSet's label has changed. | |
157 | \sa labelBrush |
|
157 | \sa labelBrush | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | \fn void QBarSet::labelFontChanged() |
|
161 | \fn void QBarSet::labelFontChanged() | |
162 | This signal is emitted when the font of the barSet's label has changed. |
|
162 | This signal is emitted when the font of the barSet's label has changed. | |
163 | \sa labelBrush |
|
163 | \sa labelBrush | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | \fn void QBarSet::colorChanged(QColor) |
|
167 | \fn void QBarSet::colorChanged(QColor) | |
168 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
168 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
169 | */ |
|
169 | */ | |
170 | /*! |
|
170 | /*! | |
171 | \qmlsignal BarSet::onColorChanged(color color) |
|
171 | \qmlsignal BarSet::onColorChanged(color color) | |
172 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
172 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
173 | */ |
|
173 | */ | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
176 | \fn void QBarSet::borderColorChanged(QColor) |
|
176 | \fn void QBarSet::borderColorChanged(QColor) | |
177 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
177 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
178 | */ |
|
178 | */ | |
179 | /*! |
|
179 | /*! | |
180 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
180 | \qmlsignal BarSet::onBorderColorChanged(color color) | |
181 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
181 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
182 | */ |
|
182 | */ | |
183 |
|
183 | |||
184 | /*! |
|
184 | /*! | |
185 | \fn void QBarSet::labelColorChanged(QColor) |
|
185 | \fn void QBarSet::labelColorChanged(QColor) | |
186 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
186 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
187 | */ |
|
187 | */ | |
188 | /*! |
|
188 | /*! | |
189 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
189 | \qmlsignal BarSet::onLabelColorChanged(color color) | |
190 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
190 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
191 | */ |
|
191 | */ | |
192 |
|
192 | |||
193 | /*! |
|
193 | /*! | |
194 | \fn void QBarSet::valuesAdded(int index, int count) |
|
194 | \fn void QBarSet::valuesAdded(int index, int count) | |
195 | This signal is emitted when new values have been added to the set. |
|
195 | This signal is emitted when new values have been added to the set. | |
196 | Parameter \a index indicates the position of the first inserted value. |
|
196 | Parameter \a index indicates the position of the first inserted value. | |
197 | Parameter \a count is the number of iserted values. |
|
197 | Parameter \a count is the number of iserted values. | |
198 | \sa append(), insert() |
|
198 | \sa append(), insert() | |
199 | */ |
|
199 | */ | |
200 | /*! |
|
200 | /*! | |
201 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
201 | \qmlsignal BarSet::onValuesAdded(int index, int count) | |
202 | This signal is emitted when new values have been added to the set. |
|
202 | This signal is emitted when new values have been added to the set. | |
203 | Parameter \a index indicates the position of the first inserted value. |
|
203 | Parameter \a index indicates the position of the first inserted value. | |
204 | Parameter \a count is the number of iserted values. |
|
204 | Parameter \a count is the number of iserted values. | |
205 | */ |
|
205 | */ | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
208 | \fn void QBarSet::valuesRemoved(int index, int count) | |
209 | This signal is emitted values have been removed from the set. |
|
209 | This signal is emitted values have been removed from the set. | |
210 | Parameter \a index indicates the position of the first removed value. |
|
210 | Parameter \a index indicates the position of the first removed value. | |
211 | Parameter \a count is the number of removed values. |
|
211 | Parameter \a count is the number of removed values. | |
212 | \sa remove() |
|
212 | \sa remove() | |
213 | */ |
|
213 | */ | |
214 | /*! |
|
214 | /*! | |
215 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
215 | \qmlsignal BarSet::onValuesRemoved(int index, int count) | |
216 | This signal is emitted values have been removed from the set. |
|
216 | This signal is emitted values have been removed from the set. | |
217 | Parameter \a index indicates the position of the first removed value. |
|
217 | Parameter \a index indicates the position of the first removed value. | |
218 | Parameter \a count is the number of removed values. |
|
218 | Parameter \a count is the number of removed values. | |
219 | */ |
|
219 | */ | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \fn void QBarSet::valueChanged(int index) |
|
222 | \fn void QBarSet::valueChanged(int index) | |
223 | This signal is emitted values the value in the set has been modified. |
|
223 | This signal is emitted values the value in the set has been modified. | |
224 | Parameter \a index indicates the position of the modified value. |
|
224 | Parameter \a index indicates the position of the modified value. | |
225 | \sa at() |
|
225 | \sa at() | |
226 | */ |
|
226 | */ | |
227 | /*! |
|
227 | /*! | |
228 | \qmlsignal BarSet::onValueChanged(int index) |
|
228 | \qmlsignal BarSet::onValueChanged(int index) | |
229 | This signal is emitted values the value in the set has been modified. |
|
229 | This signal is emitted values the value in the set has been modified. | |
230 | Parameter \a index indicates the position of the modified value. |
|
230 | Parameter \a index indicates the position of the modified value. | |
231 | */ |
|
231 | */ | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | \qmlproperty int BarSet::count |
|
234 | \qmlproperty int BarSet::count | |
235 | The count of values on the barset |
|
235 | The count of values on the barset | |
236 | */ |
|
236 | */ | |
237 |
|
237 | |||
238 | /*! |
|
238 | /*! | |
239 | \qmlproperty QVariantList BarSet::values |
|
239 | \qmlproperty QVariantList BarSet::values | |
240 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of |
|
240 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of | |
241 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
241 | reals as values, the values are automatically completed to points by using the index of a value as it's | |
242 | x-coordinate. For example: |
|
242 | x-coordinate. For example: | |
243 | \code |
|
243 | \code | |
244 | myBarSet1.values = [0, 5, 1, 5]; |
|
244 | myBarSet1.values = [0, 5, 1, 5]; | |
245 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
245 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; | |
246 | \endcode |
|
246 | \endcode | |
247 | */ |
|
247 | */ | |
248 |
|
248 | |||
249 | /*! |
|
249 | /*! | |
250 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
250 | Constructs QBarSet with a label of \a label and with parent of \a parent | |
251 | */ |
|
251 | */ | |
252 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
252 | QBarSet::QBarSet(const QString label, QObject *parent) | |
253 | : QObject(parent) |
|
253 | : QObject(parent) | |
254 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
254 | ,d_ptr(new QBarSetPrivate(label,this)) | |
255 | { |
|
255 | { | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | Destroys the barset |
|
259 | Destroys the barset | |
260 | */ |
|
260 | */ | |
261 | QBarSet::~QBarSet() |
|
261 | QBarSet::~QBarSet() | |
262 | { |
|
262 | { | |
263 | // NOTE: d_ptr destroyed by QObject |
|
263 | // NOTE: d_ptr destroyed by QObject | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | /*! |
|
266 | /*! | |
267 | Sets new \a label for set. |
|
267 | Sets new \a label for set. | |
268 | */ |
|
268 | */ | |
269 | void QBarSet::setLabel(const QString label) |
|
269 | void QBarSet::setLabel(const QString label) | |
270 | { |
|
270 | { | |
271 | d_ptr->m_label = label; |
|
271 | d_ptr->m_label = label; | |
272 | emit labelChanged(); |
|
272 | emit labelChanged(); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Returns label of the set. |
|
276 | Returns label of the set. | |
277 | */ |
|
277 | */ | |
278 | QString QBarSet::label() const |
|
278 | QString QBarSet::label() const | |
279 | { |
|
279 | { | |
280 | return d_ptr->m_label; |
|
280 | return d_ptr->m_label; | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | /*! |
|
283 | /*! | |
284 | Appends new value \a value to the end of set. |
|
284 | Appends new value \a value to the end of set. | |
285 | */ |
|
285 | */ | |
286 | void QBarSet::append(const qreal value) |
|
286 | void QBarSet::append(const qreal value) | |
287 | { |
|
287 | { | |
288 | // Convert to QPointF |
|
288 | // Convert to QPointF | |
289 | int index = d_ptr->m_values.count(); |
|
289 | int index = d_ptr->m_values.count(); | |
290 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
290 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
291 | emit valuesAdded(index, 1); |
|
291 | emit valuesAdded(index, 1); | |
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 | /*! |
|
294 | /*! | |
295 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
295 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |
296 | are appended to end of barset |
|
296 | are appended to end of barset | |
297 | \sa append() |
|
297 | \sa append() | |
298 | */ |
|
298 | */ | |
299 | void QBarSet::append(const QList<qreal> &values) |
|
299 | void QBarSet::append(const QList<qreal> &values) | |
300 | { |
|
300 | { | |
301 | int index = d_ptr->m_values.count(); |
|
301 | int index = d_ptr->m_values.count(); | |
302 | d_ptr->append(values); |
|
302 | d_ptr->append(values); | |
303 | emit valuesAdded(index, values.count()); |
|
303 | emit valuesAdded(index, values.count()); | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | /*! |
|
306 | /*! | |
307 | Convinience operator. Same as append, with real \a value. |
|
307 | Convinience operator. Same as append, with real \a value. | |
308 | \sa append() |
|
308 | \sa append() | |
309 | */ |
|
309 | */ | |
310 | QBarSet& QBarSet::operator << (const qreal &value) |
|
310 | QBarSet& QBarSet::operator << (const qreal &value) | |
311 | { |
|
311 | { | |
312 | append(value); |
|
312 | append(value); | |
313 | return *this; |
|
313 | return *this; | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | /*! |
|
316 | /*! | |
317 | Inserts new \a value on the \a index position. |
|
317 | Inserts new \a value on the \a index position. | |
318 | The value that is currently at this postion is moved to postion index + 1 |
|
318 | The value that is currently at this postion is moved to postion index + 1 | |
319 | \sa remove() |
|
319 | \sa remove() | |
320 | */ |
|
320 | */ | |
321 | void QBarSet::insert(const int index, const qreal value) |
|
321 | void QBarSet::insert(const int index, const qreal value) | |
322 | { |
|
322 | { | |
323 | d_ptr->insert(index, value); |
|
323 | d_ptr->insert(index, value); | |
324 | emit valuesAdded(index,1); |
|
324 | emit valuesAdded(index,1); | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | /*! |
|
327 | /*! | |
328 | Removes \a count number of values from the set starting at \a index. |
|
328 | Removes \a count number of values from the set starting at \a index. | |
329 | \sa insert() |
|
329 | \sa insert() | |
330 | */ |
|
330 | */ | |
331 | void QBarSet::remove(const int index, const int count) |
|
331 | void QBarSet::remove(const int index, const int count) | |
332 | { |
|
332 | { | |
333 | int removedCount = d_ptr->remove(index,count); |
|
333 | int removedCount = d_ptr->remove(index,count); | |
334 | if (removedCount > 0) { |
|
334 | if (removedCount > 0) { | |
335 | emit valuesRemoved(index,removedCount); |
|
335 | emit valuesRemoved(index,removedCount); | |
336 | } |
|
336 | } | |
337 | return; |
|
337 | return; | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | /*! |
|
340 | /*! | |
341 | Sets a new value \a value to set, indexed by \a index |
|
341 | Sets a new value \a value to set, indexed by \a index | |
342 | */ |
|
342 | */ | |
343 | void QBarSet::replace(const int index, const qreal value) |
|
343 | void QBarSet::replace(const int index, const qreal value) | |
344 | { |
|
344 | { | |
345 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
345 | if (index >= 0 && index < d_ptr->m_values.count()) { | |
346 | d_ptr->replace(index,value); |
|
346 | d_ptr->replace(index,value); | |
347 | emit valueChanged(index); |
|
347 | emit valueChanged(index); | |
348 | } |
|
348 | } | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 |
|
351 | |||
352 | /*! |
|
352 | /*! | |
353 | Returns value of set indexed by \a index. |
|
353 | Returns value of set indexed by \a index. | |
354 | If the index is out of bounds 0.0 is returned. |
|
354 | If the index is out of bounds 0.0 is returned. | |
355 | */ |
|
355 | */ | |
356 | qreal QBarSet::at(const int index) const |
|
356 | qreal QBarSet::at(const int index) const | |
357 | { |
|
357 | { | |
358 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
358 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
359 | return 0; |
|
359 | return 0; | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | return d_ptr->m_values.at(index).y(); |
|
362 | return d_ptr->m_values.at(index).y(); | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | /*! |
|
365 | /*! | |
366 | Returns value of set indexed by \a index. |
|
366 | Returns value of set indexed by \a index. | |
367 | If the index is out of bounds 0.0 is returned. |
|
367 | If the index is out of bounds 0.0 is returned. | |
368 | */ |
|
368 | */ | |
369 | qreal QBarSet::operator [](const int index) const |
|
369 | qreal QBarSet::operator [](const int index) const | |
370 | { |
|
370 | { | |
371 | return at(index); |
|
371 | return at(index); | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | /*! |
|
374 | /*! | |
375 | Returns count of values in set. |
|
375 | Returns count of values in set. | |
376 | */ |
|
376 | */ | |
377 | int QBarSet::count() const |
|
377 | int QBarSet::count() const | |
378 | { |
|
378 | { | |
379 | return d_ptr->m_values.count(); |
|
379 | return d_ptr->m_values.count(); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | /*! |
|
382 | /*! | |
383 | Returns sum of all values in barset. |
|
383 | Returns sum of all values in barset. | |
384 | */ |
|
384 | */ | |
385 | qreal QBarSet::sum() const |
|
385 | qreal QBarSet::sum() const | |
386 | { |
|
386 | { | |
387 | qreal total(0); |
|
387 | qreal total(0); | |
388 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
388 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
389 | total += d_ptr->m_values.at(i).y(); |
|
389 | total += d_ptr->m_values.at(i).y(); | |
390 | } |
|
390 | } | |
391 | return total; |
|
391 | return total; | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 | /*! |
|
394 | /*! | |
395 | Sets pen for set. Bars of this set are drawn using \a pen |
|
395 | Sets pen for set. Bars of this set are drawn using \a pen | |
396 | */ |
|
396 | */ | |
397 | void QBarSet::setPen(const QPen &pen) |
|
397 | void QBarSet::setPen(const QPen &pen) | |
398 | { |
|
398 | { | |
399 | if(d_ptr->m_pen!=pen){ |
|
399 | if(d_ptr->m_pen!=pen){ | |
400 | d_ptr->m_pen = pen; |
|
400 | d_ptr->m_pen = pen; | |
401 | emit d_ptr->updatedBars(); |
|
401 | emit d_ptr->updatedBars(); | |
402 | emit penChanged(); |
|
402 | emit penChanged(); | |
403 | } |
|
403 | } | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | /*! |
|
406 | /*! | |
407 | Returns pen of the set. |
|
407 | Returns pen of the set. | |
408 | */ |
|
408 | */ | |
409 | QPen QBarSet::pen() const |
|
409 | QPen QBarSet::pen() const | |
410 | { |
|
410 | { | |
411 | return d_ptr->m_pen; |
|
411 | return d_ptr->m_pen; | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | /*! |
|
414 | /*! | |
415 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
415 | Sets brush for the set. Bars of this set are drawn using \a brush | |
416 | */ |
|
416 | */ | |
417 | void QBarSet::setBrush(const QBrush &brush) |
|
417 | void QBarSet::setBrush(const QBrush &brush) | |
418 | { |
|
418 | { | |
419 | if(d_ptr->m_brush!=brush){ |
|
419 | if(d_ptr->m_brush!=brush){ | |
420 | d_ptr->m_brush = brush; |
|
420 | d_ptr->m_brush = brush; | |
421 | emit d_ptr->updatedBars(); |
|
421 | emit d_ptr->updatedBars(); | |
422 | emit brushChanged(); |
|
422 | emit brushChanged(); | |
423 | } |
|
423 | } | |
424 | } |
|
424 | } | |
425 |
|
425 | |||
426 | /*! |
|
426 | /*! | |
427 | Returns brush of the set. |
|
427 | Returns brush of the set. | |
428 | */ |
|
428 | */ | |
429 | QBrush QBarSet::brush() const |
|
429 | QBrush QBarSet::brush() const | |
430 | { |
|
430 | { | |
431 | return d_ptr->m_brush; |
|
431 | return d_ptr->m_brush; | |
432 | } |
|
432 | } | |
433 |
|
433 | |||
434 | /*! |
|
434 | /*! | |
435 | Sets \a brush of the values that are drawn on top of this barset |
|
435 | Sets \a brush of the values that are drawn on top of this barset | |
436 | */ |
|
436 | */ | |
437 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
437 | void QBarSet::setLabelBrush(const QBrush &brush) | |
438 | { |
|
438 | { | |
439 | if(d_ptr->m_labelBrush!=brush){ |
|
439 | if(d_ptr->m_labelBrush!=brush){ | |
440 | d_ptr->m_labelBrush = brush; |
|
440 | d_ptr->m_labelBrush = brush; | |
441 | emit d_ptr->updatedBars(); |
|
441 | emit d_ptr->updatedBars(); | |
442 | emit labelBrushChanged(); |
|
442 | emit labelBrushChanged(); | |
443 | } |
|
443 | } | |
444 | } |
|
444 | } | |
445 |
|
445 | |||
446 | /*! |
|
446 | /*! | |
447 | Returns brush of the values that are drawn on top of this barset |
|
447 | Returns brush of the values that are drawn on top of this barset | |
448 | */ |
|
448 | */ | |
449 | QBrush QBarSet::labelBrush() const |
|
449 | QBrush QBarSet::labelBrush() const | |
450 | { |
|
450 | { | |
451 | return d_ptr->m_labelBrush; |
|
451 | return d_ptr->m_labelBrush; | |
452 | } |
|
452 | } | |
453 |
|
453 | |||
454 | /*! |
|
454 | /*! | |
455 | Sets the \a font for values that are drawn on top of this barset |
|
455 | Sets the \a font for values that are drawn on top of this barset | |
456 | */ |
|
456 | */ | |
457 | void QBarSet::setLabelFont(const QFont &font) |
|
457 | void QBarSet::setLabelFont(const QFont &font) | |
458 | { |
|
458 | { | |
459 | if(d_ptr->m_labelFont!=font) { |
|
459 | if(d_ptr->m_labelFont!=font) { | |
460 | d_ptr->m_labelFont = font; |
|
460 | d_ptr->m_labelFont = font; | |
461 | emit d_ptr->updatedBars(); |
|
461 | emit d_ptr->updatedBars(); | |
462 | emit labelFontChanged(); |
|
462 | emit labelFontChanged(); | |
463 | } |
|
463 | } | |
464 |
|
464 | |||
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | /*! |
|
467 | /*! | |
468 | Returns the pen for values that are drawn on top of this barset |
|
468 | Returns the pen for values that are drawn on top of this barset | |
469 | */ |
|
469 | */ | |
470 | QFont QBarSet::labelFont() const |
|
470 | QFont QBarSet::labelFont() const | |
471 | { |
|
471 | { | |
472 | return d_ptr->m_labelFont; |
|
472 | return d_ptr->m_labelFont; | |
473 | } |
|
473 | } | |
474 |
|
474 | |||
475 | /*! |
|
475 | /*! | |
476 | Returns the color of the brush of barset. |
|
476 | Returns the color of the brush of barset. | |
477 | */ |
|
477 | */ | |
478 | QColor QBarSet::color() |
|
478 | QColor QBarSet::color() | |
479 | { |
|
479 | { | |
480 | return brush().color(); |
|
480 | return brush().color(); | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | /*! |
|
483 | /*! | |
484 | Sets the \a color of brush for this barset |
|
484 | Sets the \a color of brush for this barset | |
485 | */ |
|
485 | */ | |
486 | void QBarSet::setColor(QColor color) |
|
486 | void QBarSet::setColor(QColor color) | |
487 | { |
|
487 | { | |
488 | QBrush b = brush(); |
|
488 | QBrush b = brush(); | |
489 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { |
|
489 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { | |
490 | b.setColor(color); |
|
490 | b.setColor(color); | |
491 | if (b.style() == Qt::NoBrush) { |
|
491 | if (b.style() == Qt::NoBrush) { | |
492 | // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) |
|
492 | // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) | |
493 | // This prevents theme to override color defined in QML side: |
|
493 | // This prevents theme to override color defined in QML side: | |
494 | // BarSet { label: "Bob"; color:"red"; values: [1,2,3] } |
|
494 | // BarSet { label: "Bob"; color:"red"; values: [1,2,3] } | |
495 | // The color must be obeyed, since user wanted it. |
|
495 | // The color must be obeyed, since user wanted it. | |
496 | b.setStyle(Qt::SolidPattern); |
|
496 | b.setStyle(Qt::SolidPattern); | |
497 | } |
|
497 | } | |
498 | setBrush(b); |
|
498 | setBrush(b); | |
499 | emit colorChanged(color); |
|
499 | emit colorChanged(color); | |
500 | } |
|
500 | } | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | /*! |
|
503 | /*! | |
504 | Returns the color of pen of this barset |
|
504 | Returns the color of pen of this barset | |
505 | */ |
|
505 | */ | |
506 | QColor QBarSet::borderColor() |
|
506 | QColor QBarSet::borderColor() | |
507 | { |
|
507 | { | |
508 | return pen().color(); |
|
508 | return pen().color(); | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | /*! |
|
511 | /*! | |
512 | Sets the color of pen for this barset |
|
512 | Sets the color of pen for this barset | |
513 | */ |
|
513 | */ | |
514 | void QBarSet::setBorderColor(QColor color) |
|
514 | void QBarSet::setBorderColor(QColor color) | |
515 | { |
|
515 | { | |
516 | QPen p = pen(); |
|
516 | QPen p = pen(); | |
517 | if (p.color() != color) { |
|
517 | if (p.color() != color) { | |
518 | p.setColor(color); |
|
518 | p.setColor(color); | |
519 | setPen(p); |
|
519 | setPen(p); | |
520 | emit borderColorChanged(color); |
|
520 | emit borderColorChanged(color); | |
521 | } |
|
521 | } | |
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | /*! |
|
524 | /*! | |
525 | Returns the color of labels of this barset |
|
525 | Returns the color of labels of this barset | |
526 | */ |
|
526 | */ | |
527 | QColor QBarSet::labelColor() |
|
527 | QColor QBarSet::labelColor() | |
528 | { |
|
528 | { | |
529 | return labelBrush().color(); |
|
529 | return labelBrush().color(); | |
530 | } |
|
530 | } | |
531 |
|
531 | |||
532 | /*! |
|
532 | /*! | |
533 | Sets the color of labels for this barset |
|
533 | Sets the color of labels for this barset | |
534 | */ |
|
534 | */ | |
535 | void QBarSet::setLabelColor(QColor color) |
|
535 | void QBarSet::setLabelColor(QColor color) | |
536 | { |
|
536 | { | |
537 | QBrush b = labelBrush(); |
|
537 | QBrush b = labelBrush(); | |
538 | if (b == QBrush()) |
|
538 | if (b == QBrush()) | |
539 | b.setStyle(Qt::SolidPattern); |
|
539 | b.setStyle(Qt::SolidPattern); | |
540 |
|
540 | |||
541 | if (b.color() != color) { |
|
541 | if (b.color() != color) { | |
542 | b.setColor(color); |
|
542 | b.setColor(color); | |
543 | setLabelBrush(b); |
|
543 | setLabelBrush(b); | |
544 | emit labelColorChanged(color); |
|
544 | emit labelColorChanged(color); | |
545 | } |
|
545 | } | |
546 | } |
|
546 | } | |
547 |
|
547 | |||
548 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
548 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
549 |
|
549 | |||
550 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
550 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | |
551 | q_ptr(parent), |
|
551 | q_ptr(parent), | |
552 | m_label(label) |
|
552 | m_label(label) | |
553 | { |
|
553 | { | |
554 | } |
|
554 | } | |
555 |
|
555 | |||
556 | QBarSetPrivate::~QBarSetPrivate() |
|
556 | QBarSetPrivate::~QBarSetPrivate() | |
557 | { |
|
557 | { | |
558 | } |
|
558 | } | |
559 |
|
559 | |||
560 | void QBarSetPrivate::append(QPointF value) |
|
560 | void QBarSetPrivate::append(QPointF value) | |
561 | { |
|
561 | { | |
562 | m_values.append(value); |
|
562 | m_values.append(value); | |
563 | emit restructuredBars(); |
|
563 | emit restructuredBars(); | |
564 | } |
|
564 | } | |
565 |
|
565 | |||
566 | void QBarSetPrivate::append(QList<QPointF> values) |
|
566 | void QBarSetPrivate::append(QList<QPointF> values) | |
567 | { |
|
567 | { | |
568 | for (int i=0; i<values.count(); i++) { |
|
568 | for (int i=0; i<values.count(); i++) { | |
569 | m_values.append(values.at(i)); |
|
569 | m_values.append(values.at(i)); | |
570 | } |
|
570 | } | |
571 | emit restructuredBars(); |
|
571 | emit restructuredBars(); | |
572 | } |
|
572 | } | |
573 |
|
573 | |||
574 | void QBarSetPrivate::append(QList<qreal> values) |
|
574 | void QBarSetPrivate::append(QList<qreal> values) | |
575 | { |
|
575 | { | |
576 | int index = m_values.count(); |
|
576 | int index = m_values.count(); | |
577 | for (int i=0; i<values.count(); i++) { |
|
577 | for (int i=0; i<values.count(); i++) { | |
578 | m_values.append(QPointF(index,values.at(i))); |
|
578 | m_values.append(QPointF(index,values.at(i))); | |
579 | index++; |
|
579 | index++; | |
580 | } |
|
580 | } | |
581 | emit restructuredBars(); |
|
581 | emit restructuredBars(); | |
582 | } |
|
582 | } | |
583 |
|
583 | |||
584 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
584 | void QBarSetPrivate::insert(const int index, const qreal value) | |
585 | { |
|
585 | { | |
586 | m_values.insert(index, QPointF(index, value)); |
|
586 | m_values.insert(index, QPointF(index, value)); | |
587 | emit restructuredBars(); |
|
587 | emit restructuredBars(); | |
588 | } |
|
588 | } | |
589 |
|
589 | |||
590 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
590 | void QBarSetPrivate::insert(const int index, const QPointF value) | |
591 | { |
|
591 | { | |
592 | m_values.insert(index, value); |
|
592 | m_values.insert(index, value); | |
593 | emit restructuredBars(); |
|
593 | emit restructuredBars(); | |
594 | } |
|
594 | } | |
595 |
|
595 | |||
596 | int QBarSetPrivate::remove(const int index, const int count) |
|
596 | int QBarSetPrivate::remove(const int index, const int count) | |
597 | { |
|
597 | { | |
598 | int removeCount = count; |
|
598 | int removeCount = count; | |
599 |
|
599 | |||
600 | if ((index <0) || (m_values.count() == 0)) { |
|
600 | if ((index <0) || (m_values.count() == 0)) { | |
601 | // Invalid index or not values in list, remove nothing. |
|
601 | // Invalid index or not values in list, remove nothing. | |
602 | return 0; |
|
602 | return 0; | |
603 | } else if ((index + count) > m_values.count()) { |
|
603 | } else if ((index + count) > m_values.count()) { | |
604 | // Trying to remove more items than list has. Limit amount to be removed. |
|
604 | // Trying to remove more items than list has. Limit amount to be removed. | |
605 | removeCount = m_values.count() - index; |
|
605 | removeCount = m_values.count() - index; | |
606 | } |
|
606 | } | |
607 |
|
607 | |||
608 | int c = 0; |
|
608 | int c = 0; | |
609 | while (c < removeCount) { |
|
609 | while (c < removeCount) { | |
610 | m_values.removeAt(index); |
|
610 | m_values.removeAt(index); | |
611 | c++; |
|
611 | c++; | |
612 | } |
|
612 | } | |
613 | emit restructuredBars(); |
|
613 | emit restructuredBars(); | |
614 | return removeCount; |
|
614 | return removeCount; | |
615 | } |
|
615 | } | |
616 |
|
616 | |||
617 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
617 | void QBarSetPrivate::replace(const int index, const qreal value) | |
618 | { |
|
618 | { | |
619 | m_values.replace(index,QPointF(index,value)); |
|
619 | m_values.replace(index,QPointF(index,value)); | |
620 |
emit updated |
|
620 | emit updatedLayout(); | |
621 | } |
|
621 | } | |
622 |
|
622 | |||
623 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
623 | void QBarSetPrivate::replace(const int index, const QPointF value) | |
624 | { |
|
624 | { | |
625 | m_values.replace(index,value); |
|
625 | m_values.replace(index,value); | |
626 |
emit updated |
|
626 | emit updatedLayout(); | |
627 | } |
|
627 | } | |
628 |
|
628 | |||
629 | qreal QBarSetPrivate::pos(const int index) |
|
629 | qreal QBarSetPrivate::pos(const int index) | |
630 | { |
|
630 | { | |
631 | if (index < 0 || index >= m_values.count()) { |
|
631 | if (index < 0 || index >= m_values.count()) { | |
632 | return 0; |
|
632 | return 0; | |
633 | } |
|
633 | } | |
634 |
|
634 | |||
635 | return m_values.at(index).x(); |
|
635 | return m_values.at(index).x(); | |
636 | } |
|
636 | } | |
637 |
|
637 | |||
638 | qreal QBarSetPrivate::value(const int index) |
|
638 | qreal QBarSetPrivate::value(const int index) | |
639 | { |
|
639 | { | |
640 | if (index < 0 || index >= m_values.count()) { |
|
640 | if (index < 0 || index >= m_values.count()) { | |
641 | return 0; |
|
641 | return 0; | |
642 | } |
|
642 | } | |
643 |
|
643 | |||
644 | return m_values.at(index).y(); |
|
644 | return m_values.at(index).y(); | |
645 | } |
|
645 | } | |
646 |
|
646 | |||
647 | #include "moc_qbarset.cpp" |
|
647 | #include "moc_qbarset.cpp" | |
648 | #include "moc_qbarset_p.cpp" |
|
648 | #include "moc_qbarset_p.cpp" | |
649 |
|
649 | |||
650 | QTCOMMERCIALCHART_END_NAMESPACE |
|
650 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,81 +1,82 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QBARSET_P_H |
|
30 | #ifndef QBARSET_P_H | |
31 | #define QBARSET_P_H |
|
31 | #define QBARSET_P_H | |
32 |
|
32 | |||
33 | #include "qbarset.h" |
|
33 | #include "qbarset.h" | |
34 | #include <QMap> |
|
34 | #include <QMap> | |
35 | #include <QPen> |
|
35 | #include <QPen> | |
36 | #include <QBrush> |
|
36 | #include <QBrush> | |
37 | #include <QFont> |
|
37 | #include <QFont> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class QBarSetPrivate : public QObject |
|
41 | class QBarSetPrivate : public QObject | |
42 | { |
|
42 | { | |
43 | Q_OBJECT |
|
43 | Q_OBJECT | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | QBarSetPrivate(const QString label, QBarSet *parent); |
|
46 | QBarSetPrivate(const QString label, QBarSet *parent); | |
47 | ~QBarSetPrivate(); |
|
47 | ~QBarSetPrivate(); | |
48 |
|
48 | |||
49 | void append(QPointF value); |
|
49 | void append(QPointF value); | |
50 | void append(QList<QPointF> values); |
|
50 | void append(QList<QPointF> values); | |
51 | void append(QList<qreal> values); |
|
51 | void append(QList<qreal> values); | |
52 |
|
52 | |||
53 | void insert(const int index, const qreal value); |
|
53 | void insert(const int index, const qreal value); | |
54 | void insert(const int index, const QPointF value); |
|
54 | void insert(const int index, const QPointF value); | |
55 | int remove(const int index, const int count); |
|
55 | int remove(const int index, const int count); | |
56 |
|
56 | |||
57 | void replace(const int index, const qreal value); |
|
57 | void replace(const int index, const qreal value); | |
58 | void replace(const int index, const QPointF value); |
|
58 | void replace(const int index, const QPointF value); | |
59 |
|
59 | |||
60 | qreal pos(const int index); |
|
60 | qreal pos(const int index); | |
61 | qreal value(const int index); |
|
61 | qreal value(const int index); | |
62 |
|
62 | |||
63 | Q_SIGNALS: |
|
63 | Q_SIGNALS: | |
64 | void restructuredBars(); |
|
64 | void restructuredBars(); | |
65 | void updatedBars(); |
|
65 | void updatedBars(); | |
|
66 | void updatedLayout(); | |||
66 |
|
67 | |||
67 | public: |
|
68 | public: | |
68 | QBarSet * const q_ptr; |
|
69 | QBarSet * const q_ptr; | |
69 | QString m_label; |
|
70 | QString m_label; | |
70 | QList<QPointF> m_values; |
|
71 | QList<QPointF> m_values; | |
71 | QPen m_pen; |
|
72 | QPen m_pen; | |
72 | QBrush m_brush; |
|
73 | QBrush m_brush; | |
73 | QBrush m_labelBrush; |
|
74 | QBrush m_labelBrush; | |
74 | QFont m_labelFont; |
|
75 | QFont m_labelFont; | |
75 |
|
76 | |||
76 | friend class QBarSet; |
|
77 | friend class QBarSet; | |
77 | }; |
|
78 | }; | |
78 |
|
79 | |||
79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
80 | QTCOMMERCIALCHART_END_NAMESPACE | |
80 |
|
81 | |||
81 | #endif // QBARSETPRIVATE_P_H |
|
82 | #endif // QBARSETPRIVATE_P_H |
General Comments 0
You need to be logged in to leave comments.
Login now