@@ -1,37 +1,35 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/bar.cpp \ |
|
5 | $$PWD/bar.cpp \ | |
6 | $$PWD/barchartitem.cpp \ |
|
6 | $$PWD/barchartitem.cpp \ | |
7 | $$PWD/percentbarchartitem.cpp \ |
|
7 | $$PWD/percentbarchartitem.cpp \ | |
8 | $$PWD/groupedbarchartitem.cpp \ |
|
8 | $$PWD/groupedbarchartitem.cpp \ | |
9 | $$PWD/qbarseries.cpp \ |
|
9 | $$PWD/qbarseries.cpp \ | |
10 | $$PWD/qbarset.cpp \ |
|
10 | $$PWD/qbarset.cpp \ | |
11 | $$PWD/qpercentbarseries.cpp \ |
|
11 | $$PWD/qpercentbarseries.cpp \ | |
12 | $$PWD/qstackedbarseries.cpp \ |
|
12 | $$PWD/qstackedbarseries.cpp \ | |
13 | $$PWD/qgroupedbarseries.cpp \ |
|
13 | $$PWD/qgroupedbarseries.cpp \ | |
14 | $$PWD/stackedbarchartitem.cpp \ |
|
14 | $$PWD/stackedbarchartitem.cpp \ | |
15 | $$PWD/barlabel.cpp \ |
|
|||
16 | $$PWD/qbarmodelmapper.cpp |
|
15 | $$PWD/qbarmodelmapper.cpp | |
17 |
|
16 | |||
18 | PRIVATE_HEADERS += \ |
|
17 | PRIVATE_HEADERS += \ | |
19 | $$PWD/bar_p.h \ |
|
18 | $$PWD/bar_p.h \ | |
20 | $$PWD/barchartitem_p.h \ |
|
19 | $$PWD/barchartitem_p.h \ | |
21 | $$PWD/percentbarchartitem_p.h \ |
|
20 | $$PWD/percentbarchartitem_p.h \ | |
22 | $$PWD/stackedbarchartitem_p.h \ |
|
21 | $$PWD/stackedbarchartitem_p.h \ | |
23 | $$PWD/groupedbarchartitem_p.h \ |
|
22 | $$PWD/groupedbarchartitem_p.h \ | |
24 | $$PWD/barlabel_p.h \ |
|
|||
25 | $$PWD/qbarset_p.h \ |
|
23 | $$PWD/qbarset_p.h \ | |
26 | $$PWD/qbarseries_p.h \ |
|
24 | $$PWD/qbarseries_p.h \ | |
27 | $$PWD/qstackedbarseries_p.h\ |
|
25 | $$PWD/qstackedbarseries_p.h\ | |
28 | $$PWD/qpercentbarseries_p.h \ |
|
26 | $$PWD/qpercentbarseries_p.h \ | |
29 | $$PWD/qgroupedbarseries_p.h \ |
|
27 | $$PWD/qgroupedbarseries_p.h \ | |
30 |
|
28 | |||
31 | PUBLIC_HEADERS += \ |
|
29 | PUBLIC_HEADERS += \ | |
32 | $$PWD/qbarseries.h \ |
|
30 | $$PWD/qbarseries.h \ | |
33 | $$PWD/qbarset.h \ |
|
31 | $$PWD/qbarset.h \ | |
34 | $$PWD/qpercentbarseries.h \ |
|
32 | $$PWD/qpercentbarseries.h \ | |
35 | $$PWD/qstackedbarseries.h \ |
|
33 | $$PWD/qstackedbarseries.h \ | |
36 | $$PWD/qgroupedbarseries.h \ |
|
34 | $$PWD/qgroupedbarseries.h \ | |
37 | $$PWD/qbarmodelmapper.h |
|
35 | $$PWD/qbarmodelmapper.h |
@@ -1,210 +1,217 | |||||
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 "barchartitem_p.h" |
|
21 | #include "barchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "barlabel_p.h" |
|
|||
24 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
25 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
26 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
27 | #include "qbarseries_p.h" |
|
26 | #include "qbarseries_p.h" | |
28 | #include "qchart.h" |
|
27 | #include "qchart.h" | |
29 | #include "chartpresenter_p.h" |
|
28 | #include "chartpresenter_p.h" | |
30 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
31 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
32 | #include <QPainter> |
|
31 | #include <QPainter> | |
33 |
|
32 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
34 | |||
36 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
35 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
37 | ChartItem(presenter), |
|
36 | ChartItem(presenter), | |
38 | m_layoutSet(false), |
|
37 | m_layoutSet(false), | |
39 | m_series(series) |
|
38 | m_series(series) | |
40 | { |
|
39 | { | |
41 | setFlag(ItemClipsChildrenToShape); |
|
40 | setFlag(ItemClipsChildrenToShape); | |
42 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
41 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
43 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); |
|
42 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); | |
|
43 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(labelsVisibleChanged(bool))); | |||
44 | setZValue(ChartPresenter::BarSeriesZValue); |
|
44 | setZValue(ChartPresenter::BarSeriesZValue); | |
45 | dataChanged(); |
|
45 | dataChanged(); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | BarChartItem::~BarChartItem() |
|
48 | BarChartItem::~BarChartItem() | |
49 | { |
|
49 | { | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
52 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
53 | { |
|
53 | { | |
54 | Q_UNUSED(painter); |
|
54 | Q_UNUSED(painter); | |
55 | Q_UNUSED(option); |
|
55 | Q_UNUSED(option); | |
56 | Q_UNUSED(widget); |
|
56 | Q_UNUSED(widget); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | QRectF BarChartItem::boundingRect() const |
|
59 | QRectF BarChartItem::boundingRect() const | |
60 | { |
|
60 | { | |
61 | return m_rect; |
|
61 | return m_rect; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void BarChartItem::dataChanged() |
|
64 | void BarChartItem::dataChanged() | |
65 | { |
|
65 | { | |
66 | foreach(QGraphicsItem *item, childItems()) { |
|
66 | foreach(QGraphicsItem *item, childItems()) { | |
67 | delete item; |
|
67 | delete item; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | m_bars.clear(); |
|
70 | m_bars.clear(); | |
71 | m_labels.clear(); |
|
71 | m_labels.clear(); | |
72 | m_layout.clear(); |
|
72 | m_layout.clear(); | |
73 |
|
73 | |||
|
74 | bool labelsVisible = m_series->isLabelsVisible(); | |||
|
75 | ||||
74 | // Create new graphic items for bars |
|
76 | // Create new graphic items for bars | |
75 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
77 | for (int c = 0; c < m_series->categoryCount(); c++) { | |
76 | QString category = m_series->d_func()->categoryName(c); |
|
78 | QString category = m_series->d_func()->categoryName(c); | |
77 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
79 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
78 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
80 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
|
81 | ||||
|
82 | // Bars | |||
79 | Bar *bar = new Bar(set,category,this); |
|
83 | Bar *bar = new Bar(set,category,this); | |
80 | m_bars.append(bar); |
|
84 | m_bars.append(bar); | |
81 | connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString))); |
|
85 | connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString))); | |
82 | connect(bar, SIGNAL(clicked(QBarSet*,QString)), m_series, SIGNAL(clicked(QBarSet*,QString))); |
|
86 | connect(bar, SIGNAL(clicked(QBarSet*,QString)), m_series, SIGNAL(clicked(QBarSet*,QString))); | |
83 | connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool))); |
|
87 | connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool))); | |
84 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); |
|
88 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); | |
85 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
89 | m_layout.append(QRectF(0, 0, 0, 0)); | |
86 | } |
|
|||
87 | } |
|
|||
88 |
|
90 | |||
89 | // Create labels |
|
91 | // Labels | |
90 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
92 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); | |
91 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
93 | label->setVisible(labelsVisible); | |
92 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
94 | m_labels.append(label); | |
93 | BarLabel *value = new BarLabel(*set, this); |
|
|||
94 | m_labels.append(value); |
|
|||
95 | connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); |
|
|||
96 | } |
|
95 | } | |
97 |
} |
|
96 | } | |
98 |
|
97 | |||
99 | // TODO: Is this the right place to call it? |
|
98 | // TODO: Is this the right place to call it? | |
100 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
99 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
101 | } |
|
100 | } | |
102 |
|
101 | |||
103 | QVector<QRectF> BarChartItem::calculateLayout() |
|
102 | QVector<QRectF> BarChartItem::calculateLayout() | |
104 | { |
|
103 | { | |
105 | QVector<QRectF> layout; |
|
104 | QVector<QRectF> layout; | |
106 |
|
105 | |||
107 | // Use temporary qreals for accurancy |
|
106 | // Use temporary qreals for accurancy | |
108 | qreal categoryCount = m_series->categoryCount(); |
|
107 | qreal categoryCount = m_series->categoryCount(); | |
109 | qreal setCount = m_series->barsetCount(); |
|
108 | qreal setCount = m_series->barsetCount(); | |
110 |
|
109 | |||
111 | // Domain: |
|
110 | // Domain: | |
112 | qreal width = geometry().width(); |
|
111 | qreal width = geometry().width(); | |
113 | qreal height = geometry().height(); |
|
112 | qreal height = geometry().height(); | |
114 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
113 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
115 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
114 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
116 | qreal scaleY = (height / rangeY); |
|
115 | qreal scaleY = (height / rangeY); | |
117 | qreal scaleX = (width / rangeX); |
|
116 | qreal scaleX = (width / rangeX); | |
118 | qreal categoryWidth = width / categoryCount; |
|
117 | qreal categoryWidth = width / categoryCount; | |
119 | qreal barWidth = categoryWidth / setCount - categoryWidth * m_series->d_func()->barMargin(); |
|
118 | qreal barWidth = categoryWidth / setCount - categoryWidth * m_series->d_func()->barMargin(); | |
120 |
|
119 | |||
121 | int itemIndex(0); |
|
120 | int itemIndex(0); | |
122 | for (int category = 0; category < categoryCount; category++) { |
|
121 | for (int category = 0; category < categoryCount; category++) { | |
123 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
122 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
124 | for (int set = 0; set < setCount; set++) { |
|
123 | for (int set = 0; set < setCount; set++) { | |
125 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
124 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
126 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
125 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
127 | qreal barHeight = barSet->at(category).y() * scaleY; |
|
126 | qreal barHeight = barSet->at(category).y() * scaleY; | |
128 |
|
127 | |||
129 | Bar* bar = m_bars.at(itemIndex); |
|
128 | Bar* bar = m_bars.at(itemIndex); | |
130 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
129 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
131 |
|
130 | |||
132 | layout.append(rect); |
|
131 | layout.append(rect); | |
133 | bar->setPen(barSet->pen()); |
|
132 | bar->setPen(barSet->pen()); | |
134 | bar->setBrush(barSet->brush()); |
|
133 | bar->setBrush(barSet->brush()); | |
135 |
|
134 | |||
136 |
|
|
135 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
137 |
|
136 | |||
138 | if (!qFuzzyIsNull(barSet->at(category).y())) { |
|
137 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
139 | label->setText(QString::number(barSet->at(category).y())); |
|
138 | label->setText(QString::number(barSet->at(category).y())); | |
140 | } else { |
|
139 | } else { | |
141 | label->setText(QString("")); |
|
140 | label->setText(QString("")); | |
142 | } |
|
141 | } | |
143 |
|
142 | |||
144 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
143 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
145 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
144 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
146 | label->setFont(barSet->labelFont()); |
|
145 | label->setFont(barSet->labelFont()); | |
147 |
|
146 | |||
148 | itemIndex++; |
|
147 | itemIndex++; | |
149 | } |
|
148 | } | |
150 | } |
|
149 | } | |
151 |
|
150 | |||
152 | return layout; |
|
151 | return layout; | |
153 | } |
|
152 | } | |
154 |
|
153 | |||
155 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
154 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
156 | { |
|
155 | { | |
157 | if (animator()) |
|
156 | if (animator()) | |
158 | animator()->updateLayout(this, m_layout, layout); |
|
157 | animator()->updateLayout(this, m_layout, layout); | |
159 | else |
|
158 | else | |
160 | setLayout(layout); |
|
159 | setLayout(layout); | |
161 | } |
|
160 | } | |
162 |
|
161 | |||
163 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
162 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
164 | { |
|
163 | { | |
165 | m_layout = layout; |
|
164 | m_layout = layout; | |
166 |
|
165 | |||
167 | for (int i=0; i < m_bars.count(); i++) |
|
166 | for (int i=0; i < m_bars.count(); i++) | |
168 | m_bars.at(i)->setRect(layout.at(i)); |
|
167 | m_bars.at(i)->setRect(layout.at(i)); | |
169 |
|
168 | |||
170 | update(); |
|
169 | update(); | |
171 | } |
|
170 | } | |
172 | //handlers |
|
171 | //handlers | |
173 |
|
172 | |||
174 | void BarChartItem::handleModelChanged() |
|
173 | void BarChartItem::handleModelChanged() | |
175 | { |
|
174 | { | |
176 | // dataChanged(); |
|
175 | // dataChanged(); | |
177 | presenter()->resetAllElements(); |
|
176 | presenter()->resetAllElements(); | |
178 | } |
|
177 | } | |
179 |
|
178 | |||
180 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
179 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
181 | { |
|
180 | { | |
182 | m_domainMinX = minX; |
|
181 | m_domainMinX = minX; | |
183 | m_domainMaxX = maxX; |
|
182 | m_domainMaxX = maxX; | |
184 | m_domainMinY = minY; |
|
183 | m_domainMinY = minY; | |
185 | m_domainMaxY = maxY; |
|
184 | m_domainMaxY = maxY; | |
186 | handleLayoutChanged(); |
|
185 | handleLayoutChanged(); | |
187 | } |
|
186 | } | |
188 |
|
187 | |||
189 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
188 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
190 | { |
|
189 | { | |
191 | prepareGeometryChange(); |
|
190 | prepareGeometryChange(); | |
192 | m_rect = rect; |
|
191 | m_rect = rect; | |
193 | handleLayoutChanged(); |
|
192 | handleLayoutChanged(); | |
194 | m_layoutSet = true; |
|
193 | m_layoutSet = true; | |
195 | } |
|
194 | } | |
196 |
|
195 | |||
197 | void BarChartItem::handleLayoutChanged() |
|
196 | void BarChartItem::handleLayoutChanged() | |
198 | { |
|
197 | { | |
199 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { |
|
198 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { | |
200 | // rect size zero. |
|
199 | // rect size zero. | |
201 | return; |
|
200 | return; | |
202 | } |
|
201 | } | |
203 | QVector<QRectF> layout = calculateLayout(); |
|
202 | QVector<QRectF> layout = calculateLayout(); | |
204 | applyLayout(layout); |
|
203 | applyLayout(layout); | |
205 | update(); |
|
204 | update(); | |
206 | } |
|
205 | } | |
207 |
|
206 | |||
|
207 | void BarChartItem::labelsVisibleChanged(bool visible) | |||
|
208 | { | |||
|
209 | foreach (QGraphicsSimpleTextItem* label, m_labels) { | |||
|
210 | label->setVisible(visible); | |||
|
211 | } | |||
|
212 | update(); | |||
|
213 | } | |||
|
214 | ||||
208 | #include "moc_barchartitem_p.cpp" |
|
215 | #include "moc_barchartitem_p.cpp" | |
209 |
|
216 | |||
210 | QTCOMMERCIALCHART_END_NAMESPACE |
|
217 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,84 +1,84 | |||||
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 | #ifndef BARCHARTITEM_H |
|
21 | #ifndef BARCHARTITEM_H | |
22 | #define BARCHARTITEM_H |
|
22 | #define BARCHARTITEM_H | |
23 |
|
23 | |||
24 | #include "chartitem_p.h" |
|
24 | #include "chartitem_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class Bar; |
|
31 | class Bar; | |
32 | class BarLabel; |
|
|||
33 | class QAxisCategories; |
|
32 | class QAxisCategories; | |
34 | class QChart; |
|
33 | class QChart; | |
35 |
|
34 | |||
36 | //typedef QVector<QRectF> BarLayout; |
|
35 | //typedef QVector<QRectF> BarLayout; | |
37 |
|
36 | |||
38 | class BarChartItem : public ChartItem |
|
37 | class BarChartItem : public ChartItem | |
39 | { |
|
38 | { | |
40 | Q_OBJECT |
|
39 | Q_OBJECT | |
41 | public: |
|
40 | public: | |
42 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
41 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
43 | virtual ~BarChartItem(); |
|
42 | virtual ~BarChartItem(); | |
44 |
|
43 | |||
45 | public: |
|
44 | public: | |
46 | // From QGraphicsItem |
|
45 | // From QGraphicsItem | |
47 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
46 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
48 | QRectF boundingRect() const; |
|
47 | QRectF boundingRect() const; | |
49 |
|
48 | |||
50 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
49 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
51 |
|
50 | |||
52 | virtual QVector<QRectF> calculateLayout(); |
|
51 | virtual QVector<QRectF> calculateLayout(); | |
53 | void applyLayout(const QVector<QRectF> &layout); |
|
52 | void applyLayout(const QVector<QRectF> &layout); | |
54 | void setLayout(const QVector<QRectF> &layout); |
|
53 | void setLayout(const QVector<QRectF> &layout); | |
55 | void updateLayout(const QVector<QRectF> &layout); |
|
54 | void updateLayout(const QVector<QRectF> &layout); | |
56 |
|
55 | |||
57 | QRectF geometry() const { return m_rect;} |
|
56 | QRectF geometry() const { return m_rect;} | |
58 |
|
57 | |||
59 | public Q_SLOTS: |
|
58 | public Q_SLOTS: | |
60 | void handleModelChanged(); |
|
59 | void handleModelChanged(); | |
61 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
60 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
62 | void handleGeometryChanged(const QRectF &size); |
|
61 | void handleGeometryChanged(const QRectF &size); | |
63 | void handleLayoutChanged(); |
|
62 | void handleLayoutChanged(); | |
|
63 | void labelsVisibleChanged(bool visible); | |||
64 |
|
64 | |||
65 | protected: |
|
65 | protected: | |
66 |
|
66 | |||
67 | qreal m_domainMinX; |
|
67 | qreal m_domainMinX; | |
68 | qreal m_domainMaxX; |
|
68 | qreal m_domainMaxX; | |
69 | qreal m_domainMinY; |
|
69 | qreal m_domainMinY; | |
70 | qreal m_domainMaxY; |
|
70 | qreal m_domainMaxY; | |
71 |
|
71 | |||
72 | QRectF m_rect; |
|
72 | QRectF m_rect; | |
73 | bool m_layoutSet; // True, if component has been laid out. |
|
73 | bool m_layoutSet; // True, if component has been laid out. | |
74 | QVector<QRectF> m_layout; |
|
74 | QVector<QRectF> m_layout; | |
75 |
|
75 | |||
76 | // Not owned. |
|
76 | // Not owned. | |
77 | QBarSeries *m_series; |
|
77 | QBarSeries *m_series; | |
78 | QList<Bar *> m_bars; |
|
78 | QList<Bar *> m_bars; | |
79 |
QList< |
|
79 | QList<QGraphicsSimpleTextItem *> m_labels; | |
80 | }; |
|
80 | }; | |
81 |
|
81 | |||
82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
82 | QTCOMMERCIALCHART_END_NAMESPACE | |
83 |
|
83 | |||
84 | #endif // BARCHARTITEM_H |
|
84 | #endif // BARCHARTITEM_H |
@@ -1,90 +1,89 | |||||
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 "groupedbarchartitem_p.h" |
|
21 | #include "groupedbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "barlabel_p.h" |
|
|||
24 | #include "qbarset_p.h" |
|
23 | #include "qbarset_p.h" | |
25 | #include "qbarseries_p.h" |
|
24 | #include "qbarseries_p.h" | |
26 | #include "qbarset.h" |
|
25 | #include "qbarset.h" | |
27 |
|
26 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
28 | |||
30 | GroupedBarChartItem::GroupedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | GroupedBarChartItem::GroupedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
31 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
32 | { |
|
31 | { | |
33 | } |
|
32 | } | |
34 |
|
33 | |||
35 | QVector<QRectF> GroupedBarChartItem::calculateLayout() |
|
34 | QVector<QRectF> GroupedBarChartItem::calculateLayout() | |
36 | { |
|
35 | { | |
37 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
38 |
|
37 | |||
39 | // Use temporary qreals for accurancy |
|
38 | // Use temporary qreals for accurancy | |
40 | qreal categoryCount = m_series->categoryCount(); |
|
39 | qreal categoryCount = m_series->categoryCount(); | |
41 | qreal setCount = m_series->barsetCount(); |
|
40 | qreal setCount = m_series->barsetCount(); | |
42 |
|
41 | |||
43 | // Domain: |
|
42 | // Domain: | |
44 | qreal width = geometry().width(); |
|
43 | qreal width = geometry().width(); | |
45 | qreal height = geometry().height(); |
|
44 | qreal height = geometry().height(); | |
46 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
45 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
47 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
46 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
48 | qreal scaleY = (height / rangeY); |
|
47 | qreal scaleY = (height / rangeY); | |
49 | qreal scaleX = (width / rangeX); |
|
48 | qreal scaleX = (width / rangeX); | |
50 | qreal categoryWidth = width / categoryCount; |
|
49 | qreal categoryWidth = width / categoryCount; | |
51 | qreal barWidth = categoryWidth / setCount - categoryWidth * m_series->d_func()->barMargin(); |
|
50 | qreal barWidth = categoryWidth / setCount - categoryWidth * m_series->d_func()->barMargin(); | |
52 |
|
51 | |||
53 | int itemIndex(0); |
|
52 | int itemIndex(0); | |
54 | for (int category = 0; category < categoryCount; category++) { |
|
53 | for (int category = 0; category < categoryCount; category++) { | |
55 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
54 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
56 | for (int set = 0; set < setCount; set++) { |
|
55 | for (int set = 0; set < setCount; set++) { | |
57 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
56 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
58 |
|
57 | |||
59 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left(); |
|
58 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left(); | |
60 | xPos -= setCount*barWidth/2; |
|
59 | xPos -= setCount*barWidth/2; | |
61 | xPos += set*barWidth; |
|
60 | xPos += set*barWidth; | |
62 | qreal barHeight = barSet->at(category).y() * scaleY; |
|
61 | qreal barHeight = barSet->at(category).y() * scaleY; | |
63 | Bar* bar = m_bars.at(itemIndex); |
|
62 | Bar* bar = m_bars.at(itemIndex); | |
64 |
|
63 | |||
65 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
64 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
66 | layout.append(rect); |
|
65 | layout.append(rect); | |
67 | bar->setPen(barSet->pen()); |
|
66 | bar->setPen(barSet->pen()); | |
68 | bar->setBrush(barSet->brush()); |
|
67 | bar->setBrush(barSet->brush()); | |
69 |
|
68 | |||
70 |
|
|
69 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
71 |
|
70 | |||
72 | if (!qFuzzyIsNull(barSet->at(category).y())) { |
|
71 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
73 | label->setText(QString::number(barSet->at(category).y())); |
|
72 | label->setText(QString::number(barSet->at(category).y())); | |
74 | } else { |
|
73 | } else { | |
75 | label->setText(QString("")); |
|
74 | label->setText(QString("")); | |
76 | } |
|
75 | } | |
77 |
|
76 | |||
78 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
77 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
79 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
78 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
80 | label->setFont(barSet->labelFont()); |
|
79 | label->setFont(barSet->labelFont()); | |
81 |
|
80 | |||
82 | itemIndex++; |
|
81 | itemIndex++; | |
83 | } |
|
82 | } | |
84 | } |
|
83 | } | |
85 | return layout; |
|
84 | return layout; | |
86 | } |
|
85 | } | |
87 |
|
86 | |||
88 | #include "moc_groupedbarchartitem_p.cpp" |
|
87 | #include "moc_groupedbarchartitem_p.cpp" | |
89 |
|
88 | |||
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
89 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,94 +1,93 | |||||
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 "percentbarchartitem_p.h" |
|
21 | #include "percentbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "barlabel_p.h" |
|
|||
24 | #include "qbarseries_p.h" |
|
23 | #include "qbarseries_p.h" | |
25 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
26 | #include <QDebug> |
|
25 | #include <QDebug> | |
27 |
|
26 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
28 | |||
30 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
31 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
32 | { |
|
31 | { | |
33 | } |
|
32 | } | |
34 |
|
33 | |||
35 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
34 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
36 | { |
|
35 | { | |
37 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
38 |
|
37 | |||
39 | // Use temporary qreals for accurancy |
|
38 | // Use temporary qreals for accurancy | |
40 | qreal categoryCount = m_series->categoryCount(); |
|
39 | qreal categoryCount = m_series->categoryCount(); | |
41 | qreal setCount = m_series->barsetCount(); |
|
40 | qreal setCount = m_series->barsetCount(); | |
42 |
|
41 | |||
43 | // Domain: |
|
42 | // Domain: | |
44 | qreal width = geometry().width(); |
|
43 | qreal width = geometry().width(); | |
45 | qreal height = geometry().height(); |
|
44 | qreal height = geometry().height(); | |
46 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
45 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
47 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
46 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
48 | qreal scaleY = (height / rangeY); |
|
47 | qreal scaleY = (height / rangeY); | |
49 | qreal scaleX = (width / rangeX); |
|
48 | qreal scaleX = (width / rangeX); | |
50 | qreal categoryWidth = width / categoryCount; |
|
49 | qreal categoryWidth = width / categoryCount; | |
51 | qreal barWidth = categoryWidth / setCount - categoryWidth * m_series->d_func()->barMargin(); |
|
50 | qreal barWidth = categoryWidth / setCount - categoryWidth * m_series->d_func()->barMargin(); | |
52 |
|
51 | |||
53 | int itemIndex(0); |
|
52 | int itemIndex(0); | |
54 | for (int category = 0; category < categoryCount; category++) { |
|
53 | for (int category = 0; category < categoryCount; category++) { | |
55 | qreal colSum = m_series->d_func()->categorySum(category); |
|
54 | qreal colSum = m_series->d_func()->categorySum(category); | |
56 | qreal percentage = (100 / colSum); |
|
55 | qreal percentage = (100 / colSum); | |
57 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
56 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
58 | for (int set=0; set < setCount; set++) { |
|
57 | for (int set=0; set < setCount; set++) { | |
59 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
58 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
60 |
|
59 | |||
61 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
60 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
62 |
|
61 | |||
63 | qreal barHeight = barSet->at(category).y() * percentage * scaleY; |
|
62 | qreal barHeight = barSet->at(category).y() * percentage * scaleY; | |
64 | Bar* bar = m_bars.at(itemIndex); |
|
63 | Bar* bar = m_bars.at(itemIndex); | |
65 | bar->setPen(barSet->pen()); |
|
64 | bar->setPen(barSet->pen()); | |
66 | bar->setBrush(barSet->brush()); |
|
65 | bar->setBrush(barSet->brush()); | |
67 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
66 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
68 | layout.append(rect); |
|
67 | layout.append(rect); | |
69 |
|
68 | |||
70 |
|
|
69 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
71 |
|
70 | |||
72 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { |
|
71 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { | |
73 | int p = m_series->d_func()->percentageAt(set,category) * 100; |
|
72 | int p = m_series->d_func()->percentageAt(set,category) * 100; | |
74 | QString vString(QString::number(p)); |
|
73 | QString vString(QString::number(p)); | |
75 | vString.truncate(3); |
|
74 | vString.truncate(3); | |
76 | vString.append("%"); |
|
75 | vString.append("%"); | |
77 | label->setText(vString); |
|
76 | label->setText(vString); | |
78 | } else { |
|
77 | } else { | |
79 | label->setText(QString("")); |
|
78 | label->setText(QString("")); | |
80 | } |
|
79 | } | |
81 |
|
80 | |||
82 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
81 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
83 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
82 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
84 | label->setFont(barSet->labelFont()); |
|
83 | label->setFont(barSet->labelFont()); | |
85 | itemIndex++; |
|
84 | itemIndex++; | |
86 | yPos -= barHeight; |
|
85 | yPos -= barHeight; | |
87 | } |
|
86 | } | |
88 | } |
|
87 | } | |
89 | return layout; |
|
88 | return layout; | |
90 | } |
|
89 | } | |
91 |
|
90 | |||
92 | #include "moc_percentbarchartitem_p.cpp" |
|
91 | #include "moc_percentbarchartitem_p.cpp" | |
93 |
|
92 | |||
94 | QTCOMMERCIALCHART_END_NAMESPACE |
|
93 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,483 +1,492 | |||||
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 "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_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 "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \class QBarSeries |
|
34 | \class QBarSeries | |
35 | \brief part of QtCommercial chart API. |
|
35 | \brief part of QtCommercial chart API. | |
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
41 | shows the x-values. |
|
41 | shows the x-values. | |
42 |
|
42 | |||
43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
44 | \image examples_barchart.png |
|
44 | \image examples_barchart.png | |
45 |
|
45 | |||
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) |
|
50 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) | |
51 |
|
51 | |||
52 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category |
|
52 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category | |
53 | contained by the series. |
|
53 | contained by the series. | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
57 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
58 |
|
58 | |||
59 | The signal is emitted if mouse is hovered on top of series. |
|
59 | The signal is emitted if mouse is hovered on top of series. | |
60 | Parameter \a barset is the pointer of barset, where hover happened. |
|
60 | Parameter \a barset is the pointer of barset, where hover happened. | |
61 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
61 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | Constructs empty QBarSeries. |
|
65 | Constructs empty QBarSeries. | |
66 | QBarSeries is QObject which is a child of a \a parent. |
|
66 | QBarSeries is QObject which is a child of a \a parent. | |
67 | */ |
|
67 | */ | |
68 | QBarSeries::QBarSeries(QObject *parent) : |
|
68 | QBarSeries::QBarSeries(QObject *parent) : | |
69 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) |
|
69 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) | |
70 | { |
|
70 | { | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | Destructs barseries and owned barsets. |
|
74 | Destructs barseries and owned barsets. | |
75 | */ |
|
75 | */ | |
76 | QBarSeries::~QBarSeries() |
|
76 | QBarSeries::~QBarSeries() | |
77 | { |
|
77 | { | |
78 | // NOTE: d_ptr destroyed by QObject |
|
78 | // NOTE: d_ptr destroyed by QObject | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | \internal |
|
82 | \internal | |
83 | */ |
|
83 | */ | |
84 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
84 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
85 | QAbstractSeries(d,parent) |
|
85 | QAbstractSeries(d,parent) | |
86 | { |
|
86 | { | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | Returns the type of series. Derived classes override this. |
|
90 | Returns the type of series. Derived classes override this. | |
91 | */ |
|
91 | */ | |
92 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
92 | QAbstractSeries::SeriesType QBarSeries::type() const | |
93 | { |
|
93 | { | |
94 | return QAbstractSeries::SeriesTypeBar; |
|
94 | return QAbstractSeries::SeriesTypeBar; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | Sets the \a categories, which are used to to group the data. |
|
98 | Sets the \a categories, which are used to to group the data. | |
99 | */ |
|
99 | */ | |
100 | void QBarSeries::setCategories(QBarCategories categories) |
|
100 | void QBarSeries::setCategories(QBarCategories categories) | |
101 | { |
|
101 | { | |
102 | Q_D(QBarSeries); |
|
102 | Q_D(QBarSeries); | |
103 | d->setCategories(categories); |
|
103 | d->setCategories(categories); | |
104 | emit d->categoriesUpdated(); |
|
104 | emit d->categoriesUpdated(); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | 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. |
|
108 | 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. | |
109 | Returns true, if appending succeeded. |
|
109 | Returns true, if appending succeeded. | |
110 |
|
110 | |||
111 | */ |
|
111 | */ | |
112 | bool QBarSeries::append(QBarSet *set) |
|
112 | bool QBarSeries::append(QBarSet *set) | |
113 | { |
|
113 | { | |
114 | Q_D(QBarSeries); |
|
114 | Q_D(QBarSeries); | |
115 | if ((d->m_barSets.contains(set)) || (set == 0)) { |
|
115 | if ((d->m_barSets.contains(set)) || (set == 0)) { | |
116 | // Fail if set is already in list or set is null. |
|
116 | // Fail if set is already in list or set is null. | |
117 | return false; |
|
117 | return false; | |
118 | } |
|
118 | } | |
119 | d->m_barSets.append(set); |
|
119 | d->m_barSets.append(set); | |
120 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
120 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
121 | emit d->restructuredBars(); |
|
121 | emit d->restructuredBars(); | |
122 | return true; |
|
122 | return true; | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
126 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
127 | Returns true, if set was removed. |
|
127 | Returns true, if set was removed. | |
128 | */ |
|
128 | */ | |
129 | bool QBarSeries::remove(QBarSet *set) |
|
129 | bool QBarSeries::remove(QBarSet *set) | |
130 | { |
|
130 | { | |
131 | Q_D(QBarSeries); |
|
131 | Q_D(QBarSeries); | |
132 | if (!d->m_barSets.contains(set)) { |
|
132 | if (!d->m_barSets.contains(set)) { | |
133 | // Fail if set is not in list |
|
133 | // Fail if set is not in list | |
134 | return false; |
|
134 | return false; | |
135 | } |
|
135 | } | |
136 | d->m_barSets.removeOne(set); |
|
136 | d->m_barSets.removeOne(set); | |
137 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
137 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
138 | emit d->restructuredBars(); |
|
138 | emit d->restructuredBars(); | |
139 | return true; |
|
139 | return true; | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
143 | Adds a list of barsets to series. Takes ownership of \a sets. | |
144 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
144 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
145 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
145 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
146 | and function returns false. |
|
146 | and function returns false. | |
147 | */ |
|
147 | */ | |
148 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
148 | bool QBarSeries::append(QList<QBarSet* > sets) | |
149 | { |
|
149 | { | |
150 | Q_D(QBarSeries); |
|
150 | Q_D(QBarSeries); | |
151 | foreach (QBarSet* set, sets) { |
|
151 | foreach (QBarSet* set, sets) { | |
152 | if ((set == 0) || (d->m_barSets.contains(set))) { |
|
152 | if ((set == 0) || (d->m_barSets.contains(set))) { | |
153 | // Fail if any of the sets is null or is already appended. |
|
153 | // Fail if any of the sets is null or is already appended. | |
154 | return false; |
|
154 | return false; | |
155 | } |
|
155 | } | |
156 | if (sets.count(set) != 1) { |
|
156 | if (sets.count(set) != 1) { | |
157 | // Also fail if same set is more than once in given list. |
|
157 | // Also fail if same set is more than once in given list. | |
158 | return false; |
|
158 | return false; | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | foreach (QBarSet* set, sets) { |
|
162 | foreach (QBarSet* set, sets) { | |
163 | d->m_barSets.append(set); |
|
163 | d->m_barSets.append(set); | |
164 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
164 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
165 | } |
|
165 | } | |
166 | emit d->restructuredBars(); |
|
166 | emit d->restructuredBars(); | |
167 | return true; |
|
167 | return true; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
171 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. | |
172 | */ |
|
172 | */ | |
173 | bool QBarSeries::remove(QList<QBarSet* > sets) |
|
173 | bool QBarSeries::remove(QList<QBarSet* > sets) | |
174 | { |
|
174 | { | |
175 | Q_D(QBarSeries); |
|
175 | Q_D(QBarSeries); | |
176 |
|
176 | |||
177 | bool setsRemoved = false; |
|
177 | bool setsRemoved = false; | |
178 | foreach (QBarSet* set, sets) { |
|
178 | foreach (QBarSet* set, sets) { | |
179 | if (d->m_barSets.contains(set)) { |
|
179 | if (d->m_barSets.contains(set)) { | |
180 | d->m_barSets.removeOne(set); |
|
180 | d->m_barSets.removeOne(set); | |
181 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
181 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
182 | setsRemoved = true; |
|
182 | setsRemoved = true; | |
183 | } |
|
183 | } | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | if (setsRemoved) { |
|
186 | if (setsRemoved) { | |
187 | emit d->restructuredBars(); |
|
187 | emit d->restructuredBars(); | |
188 | } |
|
188 | } | |
189 | return setsRemoved; |
|
189 | return setsRemoved; | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | Returns number of sets in series. |
|
193 | Returns number of sets in series. | |
194 | */ |
|
194 | */ | |
195 | int QBarSeries::barsetCount() const |
|
195 | int QBarSeries::barsetCount() const | |
196 | { |
|
196 | { | |
197 | Q_D(const QBarSeries); |
|
197 | Q_D(const QBarSeries); | |
198 | return d->m_barSets.count(); |
|
198 | return d->m_barSets.count(); | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | Returns number of categories in series |
|
202 | Returns number of categories in series | |
203 | */ |
|
203 | */ | |
204 | int QBarSeries::categoryCount() const |
|
204 | int QBarSeries::categoryCount() const | |
205 | { |
|
205 | { | |
206 | Q_D(const QBarSeries); |
|
206 | Q_D(const QBarSeries); | |
207 | return d->categoryCount(); |
|
207 | return d->categoryCount(); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Returns a list of sets in series. Keeps ownership of sets. |
|
211 | Returns a list of sets in series. Keeps ownership of sets. | |
212 | */ |
|
212 | */ | |
213 | QList<QBarSet*> QBarSeries::barSets() const |
|
213 | QList<QBarSet*> QBarSeries::barSets() const | |
214 | { |
|
214 | { | |
215 | Q_D(const QBarSeries); |
|
215 | Q_D(const QBarSeries); | |
216 | return d->m_barSets; |
|
216 | return d->m_barSets; | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Returns the bar categories of the series. |
|
220 | Returns the bar categories of the series. | |
221 | */ |
|
221 | */ | |
222 | QBarCategories QBarSeries::categories() const |
|
222 | QBarCategories QBarSeries::categories() const | |
223 | { |
|
223 | { | |
224 | Q_D(const QBarSeries); |
|
224 | Q_D(const QBarSeries); | |
225 | return d->categories(); |
|
225 | return d->categories(); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | /*! |
|
228 | /*! | |
229 | Sets the visibility of labels in series to \a visible |
|
229 | Sets the visibility of labels in series to \a visible | |
230 | */ |
|
230 | */ | |
231 | void QBarSeries::setLabelsVisible(bool visible) |
|
231 | void QBarSeries::setLabelsVisible(bool visible) | |
232 | { |
|
232 | { | |
233 | foreach (QBarSet* s, barSets()) { |
|
233 | Q_D(QBarSeries); | |
234 |
|
|
234 | if (d->m_labelsVisible != visible) { | |
|
235 | d->m_labelsVisible = visible; | |||
|
236 | emit d->updatedBars(); | |||
235 | } |
|
237 | } | |
236 | } |
|
238 | } | |
237 |
|
239 | |||
|
240 | bool QBarSeries::isLabelsVisible() const | |||
|
241 | { | |||
|
242 | Q_D(const QBarSeries); | |||
|
243 | return d->m_labelsVisible; | |||
|
244 | } | |||
|
245 | ||||
238 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
246 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
239 |
|
247 | |||
240 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
248 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : | |
241 | QAbstractSeriesPrivate(q), |
|
249 | QAbstractSeriesPrivate(q), | |
242 | m_barMargin(0.05) // Default value is 5% of category width |
|
250 | m_barMargin(0.05), // Default value is 5% of category width | |
|
251 | m_labelsVisible(false) | |||
243 | { |
|
252 | { | |
244 | } |
|
253 | } | |
245 |
|
254 | |||
246 | void QBarSeriesPrivate::setCategories(QBarCategories categories) |
|
255 | void QBarSeriesPrivate::setCategories(QBarCategories categories) | |
247 | { |
|
256 | { | |
248 | m_categories = categories; |
|
257 | m_categories = categories; | |
249 | } |
|
258 | } | |
250 |
|
259 | |||
251 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
260 | void QBarSeriesPrivate::insertCategory(int index, const QString category) | |
252 | { |
|
261 | { | |
253 | m_categories.insert(index, category); |
|
262 | m_categories.insert(index, category); | |
254 | emit categoriesUpdated(); |
|
263 | emit categoriesUpdated(); | |
255 | } |
|
264 | } | |
256 |
|
265 | |||
257 | void QBarSeriesPrivate::removeCategory(int index) |
|
266 | void QBarSeriesPrivate::removeCategory(int index) | |
258 | { |
|
267 | { | |
259 | m_categories.removeAt(index); |
|
268 | m_categories.removeAt(index); | |
260 | emit categoriesUpdated(); |
|
269 | emit categoriesUpdated(); | |
261 | } |
|
270 | } | |
262 |
|
271 | |||
263 | int QBarSeriesPrivate::categoryCount() const |
|
272 | int QBarSeriesPrivate::categoryCount() const | |
264 | { |
|
273 | { | |
265 | if (m_categories.count() > 0) { |
|
274 | if (m_categories.count() > 0) { | |
266 | return m_categories.count(); |
|
275 | return m_categories.count(); | |
267 | } |
|
276 | } | |
268 |
|
277 | |||
269 | // No categories defined. return count of longest set. |
|
278 | // No categories defined. return count of longest set. | |
270 | int count = 0; |
|
279 | int count = 0; | |
271 | for (int i=0; i<m_barSets.count(); i++) { |
|
280 | for (int i=0; i<m_barSets.count(); i++) { | |
272 | if (m_barSets.at(i)->count() > count) { |
|
281 | if (m_barSets.at(i)->count() > count) { | |
273 | count = m_barSets.at(i)->count(); |
|
282 | count = m_barSets.at(i)->count(); | |
274 | } |
|
283 | } | |
275 | } |
|
284 | } | |
276 |
|
285 | |||
277 | return count; |
|
286 | return count; | |
278 | } |
|
287 | } | |
279 |
|
288 | |||
280 | QBarCategories QBarSeriesPrivate::categories() const |
|
289 | QBarCategories QBarSeriesPrivate::categories() const | |
281 | { |
|
290 | { | |
282 | if (m_categories.count() > 0) { |
|
291 | if (m_categories.count() > 0) { | |
283 | return m_categories; |
|
292 | return m_categories; | |
284 | } |
|
293 | } | |
285 |
|
294 | |||
286 | // No categories defined. retun list of indices. |
|
295 | // No categories defined. retun list of indices. | |
287 | QBarCategories categories; |
|
296 | QBarCategories categories; | |
288 |
|
297 | |||
289 | int count = categoryCount(); |
|
298 | int count = categoryCount(); | |
290 | for (int i = 0; i < count; i++) { |
|
299 | for (int i = 0; i < count; i++) { | |
291 | categories.append(QString::number(i)); |
|
300 | categories.append(QString::number(i)); | |
292 | } |
|
301 | } | |
293 | return categories; |
|
302 | return categories; | |
294 | } |
|
303 | } | |
295 |
|
304 | |||
296 | void QBarSeriesPrivate::setBarMargin(qreal margin) |
|
305 | void QBarSeriesPrivate::setBarMargin(qreal margin) | |
297 | { |
|
306 | { | |
298 | if (margin > 1.0) { |
|
307 | if (margin > 1.0) { | |
299 | margin = 1.0; |
|
308 | margin = 1.0; | |
300 | } else if (margin < 0.0) { |
|
309 | } else if (margin < 0.0) { | |
301 | margin = 0.0; |
|
310 | margin = 0.0; | |
302 | } |
|
311 | } | |
303 |
|
312 | |||
304 | m_barMargin = margin; |
|
313 | m_barMargin = margin; | |
305 | emit updatedBars(); |
|
314 | emit updatedBars(); | |
306 | } |
|
315 | } | |
307 |
|
316 | |||
308 | qreal QBarSeriesPrivate::barMargin() |
|
317 | qreal QBarSeriesPrivate::barMargin() | |
309 | { |
|
318 | { | |
310 | return m_barMargin; |
|
319 | return m_barMargin; | |
311 | } |
|
320 | } | |
312 |
|
321 | |||
313 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
322 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
314 | { |
|
323 | { | |
315 | return m_barSets.at(index); |
|
324 | return m_barSets.at(index); | |
316 | } |
|
325 | } | |
317 |
|
326 | |||
318 | QString QBarSeriesPrivate::categoryName(int category) |
|
327 | QString QBarSeriesPrivate::categoryName(int category) | |
319 | { |
|
328 | { | |
320 | if ((category >= 0) && (category < m_categories.count())) { |
|
329 | if ((category >= 0) && (category < m_categories.count())) { | |
321 | return m_categories.at(category); |
|
330 | return m_categories.at(category); | |
322 | } |
|
331 | } | |
323 |
|
332 | |||
324 | return QString::number(category); |
|
333 | return QString::number(category); | |
325 | } |
|
334 | } | |
326 |
|
335 | |||
327 | qreal QBarSeriesPrivate::min() |
|
336 | qreal QBarSeriesPrivate::min() | |
328 | { |
|
337 | { | |
329 | if (m_barSets.count() <= 0) { |
|
338 | if (m_barSets.count() <= 0) { | |
330 | return 0; |
|
339 | return 0; | |
331 | } |
|
340 | } | |
332 | qreal min = INT_MAX; |
|
341 | qreal min = INT_MAX; | |
333 |
|
342 | |||
334 | for (int i = 0; i < m_barSets.count(); i++) { |
|
343 | for (int i = 0; i < m_barSets.count(); i++) { | |
335 | int categoryCount = m_barSets.at(i)->count(); |
|
344 | int categoryCount = m_barSets.at(i)->count(); | |
336 | for (int j = 0; j < categoryCount; j++) { |
|
345 | for (int j = 0; j < categoryCount; j++) { | |
337 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
346 | qreal temp = m_barSets.at(i)->at(j).y(); | |
338 | if (temp < min) |
|
347 | if (temp < min) | |
339 | min = temp; |
|
348 | min = temp; | |
340 | } |
|
349 | } | |
341 | } |
|
350 | } | |
342 | return min; |
|
351 | return min; | |
343 | } |
|
352 | } | |
344 |
|
353 | |||
345 | qreal QBarSeriesPrivate::max() |
|
354 | qreal QBarSeriesPrivate::max() | |
346 | { |
|
355 | { | |
347 | if (m_barSets.count() <= 0) { |
|
356 | if (m_barSets.count() <= 0) { | |
348 | return 0; |
|
357 | return 0; | |
349 | } |
|
358 | } | |
350 | qreal max = INT_MIN; |
|
359 | qreal max = INT_MIN; | |
351 |
|
360 | |||
352 | for (int i = 0; i < m_barSets.count(); i++) { |
|
361 | for (int i = 0; i < m_barSets.count(); i++) { | |
353 | int categoryCount = m_barSets.at(i)->count(); |
|
362 | int categoryCount = m_barSets.at(i)->count(); | |
354 | for (int j = 0; j < categoryCount; j++) { |
|
363 | for (int j = 0; j < categoryCount; j++) { | |
355 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
364 | qreal temp = m_barSets.at(i)->at(j).y(); | |
356 | if (temp > max) |
|
365 | if (temp > max) | |
357 | max = temp; |
|
366 | max = temp; | |
358 | } |
|
367 | } | |
359 | } |
|
368 | } | |
360 |
|
369 | |||
361 | return max; |
|
370 | return max; | |
362 | } |
|
371 | } | |
363 |
|
372 | |||
364 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
373 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
365 | { |
|
374 | { | |
366 | if ((set < 0) || (set >= m_barSets.count())) { |
|
375 | if ((set < 0) || (set >= m_barSets.count())) { | |
367 | // No set, no value. |
|
376 | // No set, no value. | |
368 | return 0; |
|
377 | return 0; | |
369 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
378 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
370 | // No category, no value. |
|
379 | // No category, no value. | |
371 | return 0; |
|
380 | return 0; | |
372 | } |
|
381 | } | |
373 |
|
382 | |||
374 | return m_barSets.at(set)->at(category).y(); |
|
383 | return m_barSets.at(set)->at(category).y(); | |
375 | } |
|
384 | } | |
376 |
|
385 | |||
377 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
386 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
378 | { |
|
387 | { | |
379 | if ((set < 0) || (set >= m_barSets.count())) { |
|
388 | if ((set < 0) || (set >= m_barSets.count())) { | |
380 | // No set, no value. |
|
389 | // No set, no value. | |
381 | return 0; |
|
390 | return 0; | |
382 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
391 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
383 | // No category, no value. |
|
392 | // No category, no value. | |
384 | return 0; |
|
393 | return 0; | |
385 | } |
|
394 | } | |
386 |
|
395 | |||
387 | qreal value = m_barSets.at(set)->at(category).y(); |
|
396 | qreal value = m_barSets.at(set)->at(category).y(); | |
388 | qreal sum = categorySum(category); |
|
397 | qreal sum = categorySum(category); | |
389 | if ( qFuzzyIsNull(sum) ) { |
|
398 | if ( qFuzzyIsNull(sum) ) { | |
390 | return 0; |
|
399 | return 0; | |
391 | } |
|
400 | } | |
392 |
|
401 | |||
393 | return value / sum; |
|
402 | return value / sum; | |
394 | } |
|
403 | } | |
395 |
|
404 | |||
396 | qreal QBarSeriesPrivate::categorySum(int category) |
|
405 | qreal QBarSeriesPrivate::categorySum(int category) | |
397 | { |
|
406 | { | |
398 | qreal sum(0); |
|
407 | qreal sum(0); | |
399 | int count = m_barSets.count(); // Count sets |
|
408 | int count = m_barSets.count(); // Count sets | |
400 | for (int set = 0; set < count; set++) { |
|
409 | for (int set = 0; set < count; set++) { | |
401 | if (category < m_barSets.at(set)->count()) |
|
410 | if (category < m_barSets.at(set)->count()) | |
402 | sum += m_barSets.at(set)->at(category).y(); |
|
411 | sum += m_barSets.at(set)->at(category).y(); | |
403 | } |
|
412 | } | |
404 | return sum; |
|
413 | return sum; | |
405 | } |
|
414 | } | |
406 |
|
415 | |||
407 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
416 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
408 | { |
|
417 | { | |
409 | qreal sum(0); |
|
418 | qreal sum(0); | |
410 | int count = m_barSets.count(); // Count sets |
|
419 | int count = m_barSets.count(); // Count sets | |
411 | for (int set = 0; set < count; set++) { |
|
420 | for (int set = 0; set < count; set++) { | |
412 | if (category < m_barSets.at(set)->count()) |
|
421 | if (category < m_barSets.at(set)->count()) | |
413 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
422 | sum += qAbs(m_barSets.at(set)->at(category).y()); | |
414 | } |
|
423 | } | |
415 | return sum; |
|
424 | return sum; | |
416 | } |
|
425 | } | |
417 |
|
426 | |||
418 | qreal QBarSeriesPrivate::maxCategorySum() |
|
427 | qreal QBarSeriesPrivate::maxCategorySum() | |
419 | { |
|
428 | { | |
420 | qreal max = INT_MIN; |
|
429 | qreal max = INT_MIN; | |
421 | int count = categoryCount(); |
|
430 | int count = categoryCount(); | |
422 | for (int i = 0; i < count; i++) { |
|
431 | for (int i = 0; i < count; i++) { | |
423 | qreal sum = categorySum(i); |
|
432 | qreal sum = categorySum(i); | |
424 | if (sum > max) |
|
433 | if (sum > max) | |
425 | max = sum; |
|
434 | max = sum; | |
426 | } |
|
435 | } | |
427 | return max; |
|
436 | return max; | |
428 | } |
|
437 | } | |
429 |
|
438 | |||
430 | void QBarSeriesPrivate::barsetChanged() |
|
439 | void QBarSeriesPrivate::barsetChanged() | |
431 | { |
|
440 | { | |
432 | emit updatedBars(); |
|
441 | emit updatedBars(); | |
433 | } |
|
442 | } | |
434 |
|
443 | |||
435 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
444 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
436 | { |
|
445 | { | |
437 | qreal minX(domain.minX()); |
|
446 | qreal minX(domain.minX()); | |
438 | qreal minY(domain.minY()); |
|
447 | qreal minY(domain.minY()); | |
439 | qreal maxX(domain.maxX()); |
|
448 | qreal maxX(domain.maxX()); | |
440 | qreal maxY(domain.maxY()); |
|
449 | qreal maxY(domain.maxY()); | |
441 | int tickXCount(domain.tickXCount()); |
|
450 | int tickXCount(domain.tickXCount()); | |
442 | int tickYCount(domain.tickYCount()); |
|
451 | int tickYCount(domain.tickYCount()); | |
443 |
|
452 | |||
444 | qreal x = categoryCount(); |
|
453 | qreal x = categoryCount(); | |
445 | qreal y = max(); |
|
454 | qreal y = max(); | |
446 | minX = qMin(minX, x) - 0.5; |
|
455 | minX = qMin(minX, x) - 0.5; | |
447 | minY = qMin(minY, y); |
|
456 | minY = qMin(minY, y); | |
448 | maxX = qMax(maxX, x) - 0.5; |
|
457 | maxX = qMax(maxX, x) - 0.5; | |
449 | maxY = qMax(maxY, y); |
|
458 | maxY = qMax(maxY, y); | |
450 | tickXCount = x+1; |
|
459 | tickXCount = x+1; | |
451 |
|
460 | |||
452 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
461 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
453 | } |
|
462 | } | |
454 |
|
463 | |||
455 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
464 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
456 | { |
|
465 | { | |
457 | Q_Q(QBarSeries); |
|
466 | Q_Q(QBarSeries); | |
458 |
|
467 | |||
459 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
468 | BarChartItem* bar = new BarChartItem(q,presenter); | |
460 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
469 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
461 | presenter->animator()->addAnimation(bar); |
|
470 | presenter->animator()->addAnimation(bar); | |
462 | } |
|
471 | } | |
463 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
472 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
464 | return bar; |
|
473 | return bar; | |
465 |
|
474 | |||
466 | } |
|
475 | } | |
467 |
|
476 | |||
468 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
477 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
469 | { |
|
478 | { | |
470 | Q_Q(QBarSeries); |
|
479 | Q_Q(QBarSeries); | |
471 | QList<LegendMarker*> markers; |
|
480 | QList<LegendMarker*> markers; | |
472 | foreach(QBarSet* set, q->barSets()) { |
|
481 | foreach(QBarSet* set, q->barSets()) { | |
473 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
482 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
474 | markers << marker; |
|
483 | markers << marker; | |
475 | } |
|
484 | } | |
476 |
|
485 | |||
477 | return markers; |
|
486 | return markers; | |
478 | } |
|
487 | } | |
479 |
|
488 | |||
480 | #include "moc_qbarseries.cpp" |
|
489 | #include "moc_qbarseries.cpp" | |
481 | #include "moc_qbarseries_p.cpp" |
|
490 | #include "moc_qbarseries_p.cpp" | |
482 |
|
491 | |||
483 | QTCOMMERCIALCHART_END_NAMESPACE |
|
492 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,74 +1,75 | |||||
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 | #ifndef BARSERIES_H |
|
21 | #ifndef BARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define BARSERIES_H | |
23 |
|
23 | |||
24 | #include <qabstractseries.h> |
|
24 | #include <qabstractseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | typedef QStringList QBarCategories; |
|
29 | typedef QStringList QBarCategories; | |
30 |
|
30 | |||
31 | class QBarSet; |
|
31 | class QBarSet; | |
32 | class BarCategory; |
|
32 | class BarCategory; | |
33 | class QBarSeriesPrivate; |
|
33 | class QBarSeriesPrivate; | |
34 |
|
34 | |||
35 | // Container for series |
|
35 | // Container for series | |
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries |
|
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | public: |
|
39 | public: | |
40 | explicit QBarSeries(QObject *parent = 0); |
|
40 | explicit QBarSeries(QObject *parent = 0); | |
41 | virtual ~QBarSeries(); |
|
41 | virtual ~QBarSeries(); | |
42 |
|
42 | |||
43 | QAbstractSeries::SeriesType type() const; |
|
43 | QAbstractSeries::SeriesType type() const; | |
44 | void setCategories(QBarCategories categories); |
|
44 | void setCategories(QBarCategories categories); | |
45 |
|
45 | |||
46 | bool append(QBarSet *set); |
|
46 | bool append(QBarSet *set); | |
47 | bool remove(QBarSet *set); |
|
47 | bool remove(QBarSet *set); | |
48 | bool append(QList<QBarSet* > sets); |
|
48 | bool append(QList<QBarSet* > sets); | |
49 | bool remove(QList<QBarSet* > sets); |
|
49 | bool remove(QList<QBarSet* > sets); | |
50 | int barsetCount() const; |
|
50 | int barsetCount() const; | |
51 | int categoryCount() const; |
|
51 | int categoryCount() const; | |
52 | QList<QBarSet*> barSets() const; |
|
52 | QList<QBarSet*> barSets() const; | |
53 | QBarCategories categories() const; |
|
53 | QBarCategories categories() const; | |
54 |
|
54 | |||
55 | void setLabelsVisible(bool visible = true); |
|
55 | void setLabelsVisible(bool visible = true); | |
|
56 | bool isLabelsVisible() const; | |||
56 |
|
57 | |||
57 | protected: |
|
58 | protected: | |
58 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); |
|
59 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); | |
59 |
|
60 | |||
60 | Q_SIGNALS: |
|
61 | Q_SIGNALS: | |
61 | void clicked(QBarSet *barset, QString category); |
|
62 | void clicked(QBarSet *barset, QString category); | |
62 | void hovered(QBarSet* barset, bool status); |
|
63 | void hovered(QBarSet* barset, bool status); | |
63 |
|
64 | |||
64 | protected: |
|
65 | protected: | |
65 | Q_DECLARE_PRIVATE(QBarSeries) |
|
66 | Q_DECLARE_PRIVATE(QBarSeries) | |
66 | friend class BarChartItem; |
|
67 | friend class BarChartItem; | |
67 | friend class PercentBarChartItem; |
|
68 | friend class PercentBarChartItem; | |
68 | friend class StackedBarChartItem; |
|
69 | friend class StackedBarChartItem; | |
69 | friend class GroupedBarChartItem; |
|
70 | friend class GroupedBarChartItem; | |
70 | }; |
|
71 | }; | |
71 |
|
72 | |||
72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | QTCOMMERCIALCHART_END_NAMESPACE | |
73 |
|
74 | |||
74 | #endif // BARSERIES_H |
|
75 | #endif // BARSERIES_H |
@@ -1,61 +1,64 | |||||
1 | #ifndef QBARSERIES_P_H |
|
1 | #ifndef QBARSERIES_P_H | |
2 | #define QBARSERIES_P_H |
|
2 | #define QBARSERIES_P_H | |
3 |
|
3 | |||
4 | #include "qbarseries.h" |
|
4 | #include "qbarseries.h" | |
5 | #include "qabstractseries_p.h" |
|
5 | #include "qabstractseries_p.h" | |
6 | #include <QStringList> |
|
6 | #include <QStringList> | |
7 | #include <QAbstractSeries> |
|
7 | #include <QAbstractSeries> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class QBarModelMapper; |
|
11 | class QBarModelMapper; | |
12 |
|
12 | |||
13 | // Container for series |
|
13 | // Container for series | |
14 | class QBarSeriesPrivate : public QAbstractSeriesPrivate |
|
14 | class QBarSeriesPrivate : public QAbstractSeriesPrivate | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 | QBarSeriesPrivate(QBarSeries *parent); |
|
18 | QBarSeriesPrivate(QBarSeries *parent); | |
19 | void setCategories(QBarCategories categories); |
|
19 | void setCategories(QBarCategories categories); | |
20 | void insertCategory(int index, const QString category); |
|
20 | void insertCategory(int index, const QString category); | |
21 | void removeCategory(int index); |
|
21 | void removeCategory(int index); | |
22 | int categoryCount() const; |
|
22 | int categoryCount() const; | |
23 | QBarCategories categories() const; |
|
23 | QBarCategories categories() const; | |
24 |
|
24 | |||
25 | void setBarMargin(qreal margin); |
|
25 | void setBarMargin(qreal margin); | |
26 | qreal barMargin(); |
|
26 | qreal barMargin(); | |
27 |
|
27 | |||
28 | void scaleDomain(Domain& domain); |
|
28 | void scaleDomain(Domain& domain); | |
29 | Chart* createGraphics(ChartPresenter* presenter); |
|
29 | Chart* createGraphics(ChartPresenter* presenter); | |
30 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
30 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
31 |
|
31 | |||
32 | QBarSet* barsetAt(int index); |
|
32 | QBarSet* barsetAt(int index); | |
33 | QString categoryName(int category); |
|
33 | QString categoryName(int category); | |
34 | qreal min(); |
|
34 | qreal min(); | |
35 | qreal max(); |
|
35 | qreal max(); | |
36 | qreal valueAt(int set, int category); |
|
36 | qreal valueAt(int set, int category); | |
37 | qreal percentageAt(int set, int category); |
|
37 | qreal percentageAt(int set, int category); | |
38 | qreal categorySum(int category); |
|
38 | qreal categorySum(int category); | |
39 | qreal absoluteCategorySum(int category); |
|
39 | qreal absoluteCategorySum(int category); | |
40 | qreal maxCategorySum(); |
|
40 | qreal maxCategorySum(); | |
41 |
|
41 | |||
42 | Q_SIGNALS: |
|
42 | Q_SIGNALS: | |
43 | void clicked(QBarSet *barset, QString category); |
|
43 | void clicked(QBarSet *barset, QString category); | |
44 | void updatedBars(); |
|
44 | void updatedBars(); | |
45 | void restructuredBars(); |
|
45 | void restructuredBars(); | |
46 | void categoriesUpdated(); |
|
46 | void categoriesUpdated(); | |
|
47 | void labelsVisibleChanged(bool visible); | |||
47 |
|
48 | |||
48 | private Q_SLOTS: |
|
49 | private Q_SLOTS: | |
49 | void barsetChanged(); |
|
50 | void barsetChanged(); | |
50 |
|
51 | |||
51 | protected: |
|
52 | protected: | |
52 | QList<QBarSet *> m_barSets; |
|
53 | QList<QBarSet *> m_barSets; | |
53 | QBarCategories m_categories; |
|
54 | QBarCategories m_categories; | |
54 | qreal m_barMargin; |
|
55 | qreal m_barMargin; | |
|
56 | bool m_labelsVisible; | |||
|
57 | ||||
55 | private: |
|
58 | private: | |
56 | Q_DECLARE_PUBLIC(QBarSeries) |
|
59 | Q_DECLARE_PUBLIC(QBarSeries) | |
57 | }; |
|
60 | }; | |
58 |
|
61 | |||
59 | QTCOMMERCIALCHART_END_NAMESPACE |
|
62 | QTCOMMERCIALCHART_END_NAMESPACE | |
60 |
|
63 | |||
61 | #endif // QBARSERIESPRIVATE_P_H |
|
64 | #endif // QBARSERIESPRIVATE_P_H |
@@ -1,363 +1,342 | |||||
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 part of QtCommercial chart API. |
|
28 | \brief part of QtCommercial chart API. | |
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 QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries |
|
37 | \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \fn void QBarSet::clicked(QString category) |
|
41 | \fn void QBarSet::clicked(QString category) | |
42 | \brief signals that set has been clicked |
|
42 | \brief signals that set has been clicked | |
43 | Parameter \a category describes on which category was clicked |
|
43 | Parameter \a category describes on which category was clicked | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | \fn void QBarSet::hovered(bool status) |
|
47 | \fn void QBarSet::hovered(bool status) | |
48 | \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left. |
|
48 | \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left. | |
49 |
|
49 | |||
50 | The signal is emitted if mouse is hovered on top of set |
|
50 | The signal is emitted if mouse is hovered on top of set | |
51 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
51 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
55 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
56 | */ |
|
56 | */ | |
57 | QBarSet::QBarSet(const QString name, QObject *parent) |
|
57 | QBarSet::QBarSet(const QString name, QObject *parent) | |
58 | : QObject(parent) |
|
58 | : QObject(parent) | |
59 | ,d_ptr(new QBarSetPrivate(name,this)) |
|
59 | ,d_ptr(new QBarSetPrivate(name,this)) | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | Destroys the barset |
|
64 | Destroys the barset | |
65 | */ |
|
65 | */ | |
66 | QBarSet::~QBarSet() |
|
66 | QBarSet::~QBarSet() | |
67 | { |
|
67 | { | |
68 | // NOTE: d_ptr destroyed by QObject |
|
68 | // NOTE: d_ptr destroyed by QObject | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | Sets new \a name for set. |
|
72 | Sets new \a name for set. | |
73 | */ |
|
73 | */ | |
74 | void QBarSet::setName(const QString name) |
|
74 | void QBarSet::setName(const QString name) | |
75 | { |
|
75 | { | |
76 | d_ptr->m_name = name; |
|
76 | d_ptr->m_name = name; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | Returns name of the set. |
|
80 | Returns name of the set. | |
81 | */ |
|
81 | */ | |
82 | QString QBarSet::name() const |
|
82 | QString QBarSet::name() const | |
83 | { |
|
83 | { | |
84 | return d_ptr->m_name; |
|
84 | return d_ptr->m_name; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | Appends a point to set. Parameter \a value x coordinate defines the |
|
88 | Appends a point to set. Parameter \a value x coordinate defines the | |
89 | position in x-axis and y coordinate defines the height of bar. |
|
89 | position in x-axis and y coordinate defines the height of bar. | |
90 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) |
|
90 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) | |
91 | the x values are used or ignored. |
|
91 | the x values are used or ignored. | |
92 | */ |
|
92 | */ | |
93 | void QBarSet::append(const QPointF value) |
|
93 | void QBarSet::append(const QPointF value) | |
94 | { |
|
94 | { | |
95 | d_ptr->m_values.append(value); |
|
95 | d_ptr->m_values.append(value); | |
96 | emit d_ptr->restructuredBars(); |
|
96 | emit d_ptr->restructuredBars(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | Appends a list of \a values to set. Works like append with single point. |
|
100 | Appends a list of \a values to set. Works like append with single point. | |
101 | \sa append() |
|
101 | \sa append() | |
102 | */ |
|
102 | */ | |
103 | void QBarSet::append(const QList<QPointF> values) |
|
103 | void QBarSet::append(const QList<QPointF> values) | |
104 | { |
|
104 | { | |
105 | for (int i=0; i<values.count(); i++) { |
|
105 | for (int i=0; i<values.count(); i++) { | |
106 | d_ptr->m_values.append(values.at(i)); |
|
106 | d_ptr->m_values.append(values.at(i)); | |
107 | } |
|
107 | } | |
108 | emit d_ptr->restructuredBars(); |
|
108 | emit d_ptr->restructuredBars(); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, |
|
112 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, | |
113 | with x coordinate being the index of appended value and y coordinate is the value. |
|
113 | with x coordinate being the index of appended value and y coordinate is the value. | |
114 | */ |
|
114 | */ | |
115 | void QBarSet::append(const qreal value) |
|
115 | void QBarSet::append(const qreal value) | |
116 | { |
|
116 | { | |
117 | append(QPointF(d_ptr->m_values.count(), value)); |
|
117 | append(QPointF(d_ptr->m_values.count(), value)); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Appends a list of reals to set. Works like append with single real value. The values in list |
|
121 | Appends a list of reals to set. Works like append with single real value. The values in list | |
122 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. |
|
122 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. | |
123 | \sa append() |
|
123 | \sa append() | |
124 | */ |
|
124 | */ | |
125 | void QBarSet::append(const QList<qreal> values) |
|
125 | void QBarSet::append(const QList<qreal> values) | |
126 | { |
|
126 | { | |
127 | int index = d_ptr->m_values.count(); |
|
127 | int index = d_ptr->m_values.count(); | |
128 | for (int i=0; i<values.count(); i++) { |
|
128 | for (int i=0; i<values.count(); i++) { | |
129 | d_ptr->m_values.append(QPointF(index,values.at(i))); |
|
129 | d_ptr->m_values.append(QPointF(index,values.at(i))); | |
130 | index++; |
|
130 | index++; | |
131 | } |
|
131 | } | |
132 | emit d_ptr->restructuredBars(); |
|
132 | emit d_ptr->restructuredBars(); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | Convinience operator. Same as append, with real \a value. |
|
136 | Convinience operator. Same as append, with real \a value. | |
137 | \sa append() |
|
137 | \sa append() | |
138 | */ |
|
138 | */ | |
139 | QBarSet& QBarSet::operator << (const qreal &value) |
|
139 | QBarSet& QBarSet::operator << (const qreal &value) | |
140 | { |
|
140 | { | |
141 | append(value); |
|
141 | append(value); | |
142 | return *this; |
|
142 | return *this; | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | Convinience operator. Same as append, with QPointF \a value. |
|
146 | Convinience operator. Same as append, with QPointF \a value. | |
147 | \sa append() |
|
147 | \sa append() | |
148 | */ |
|
148 | */ | |
149 | QBarSet& QBarSet::operator << (const QPointF &value) |
|
149 | QBarSet& QBarSet::operator << (const QPointF &value) | |
150 | { |
|
150 | { | |
151 | append(value); |
|
151 | append(value); | |
152 | return *this; |
|
152 | return *this; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | Inserts new \a value on the \a index position. |
|
156 | Inserts new \a value on the \a index position. | |
157 | The value that is currently at this postion is moved to postion index + 1 |
|
157 | The value that is currently at this postion is moved to postion index + 1 | |
158 | \sa remove() |
|
158 | \sa remove() | |
159 | */ |
|
159 | */ | |
160 | void QBarSet::insert(const int index, const qreal value) |
|
160 | void QBarSet::insert(const int index, const qreal value) | |
161 | { |
|
161 | { | |
162 | d_ptr->m_values.insert(index, QPointF(index, value)); |
|
162 | d_ptr->m_values.insert(index, QPointF(index, value)); | |
163 | // emit d_ptr->updatedBars(); |
|
163 | // emit d_ptr->updatedBars(); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | Removes the value specified by \a index |
|
167 | Removes the value specified by \a index | |
168 | \sa insert() |
|
168 | \sa insert() | |
169 | */ |
|
169 | */ | |
170 | void QBarSet::remove(const int index) |
|
170 | void QBarSet::remove(const int index) | |
171 | { |
|
171 | { | |
172 | d_ptr->m_values.removeAt(index); |
|
172 | d_ptr->m_values.removeAt(index); | |
173 | // emit d_ptr->updatedBars(); |
|
173 | // emit d_ptr->updatedBars(); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | Sets a new value \a value to set, indexed by \a index |
|
177 | Sets a new value \a value to set, indexed by \a index | |
178 | */ |
|
178 | */ | |
179 | void QBarSet::replace(const int index, const qreal value) |
|
179 | void QBarSet::replace(const int index, const qreal value) | |
180 | { |
|
180 | { | |
181 | d_ptr->m_values.replace(index,QPointF(index,value)); |
|
181 | d_ptr->m_values.replace(index,QPointF(index,value)); | |
182 | emit d_ptr->updatedBars(); |
|
182 | emit d_ptr->updatedBars(); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. |
|
186 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. | |
187 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
187 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value | |
188 | of the QPointF (if appended with QPointF append). |
|
188 | of the QPointF (if appended with QPointF append). | |
189 | If the index is out of bounds QPointF(0, 0.0) is returned. |
|
189 | If the index is out of bounds QPointF(0, 0.0) is returned. | |
190 | */ |
|
190 | */ | |
191 | QPointF QBarSet::at(const int index) const |
|
191 | QPointF QBarSet::at(const int index) const | |
192 | { |
|
192 | { | |
193 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
193 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
194 | return QPointF(index, 0.0); |
|
194 | return QPointF(index, 0.0); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | return d_ptr->m_values.at(index); |
|
197 | return d_ptr->m_values.at(index); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. |
|
201 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. | |
202 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
202 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value | |
203 | of the QPointF (if appended with QPointF append). |
|
203 | of the QPointF (if appended with QPointF append). | |
204 | */ |
|
204 | */ | |
205 | QPointF QBarSet::operator [](const int index) const |
|
205 | QPointF QBarSet::operator [](const int index) const | |
206 | { |
|
206 | { | |
207 | return d_ptr->m_values.at(index); |
|
207 | return d_ptr->m_values.at(index); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Returns count of values in set. |
|
211 | Returns count of values in set. | |
212 | */ |
|
212 | */ | |
213 | int QBarSet::count() const |
|
213 | int QBarSet::count() const | |
214 | { |
|
214 | { | |
215 | return d_ptr->m_values.count(); |
|
215 | return d_ptr->m_values.count(); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. |
|
219 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. | |
220 | */ |
|
220 | */ | |
221 | qreal QBarSet::sum() const |
|
221 | qreal QBarSet::sum() const | |
222 | { |
|
222 | { | |
223 | qreal total(0); |
|
223 | qreal total(0); | |
224 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
224 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
225 | //total += d_ptr->m_values.at(i); |
|
225 | //total += d_ptr->m_values.at(i); | |
226 | total += d_ptr->m_values.at(i).y(); |
|
226 | total += d_ptr->m_values.at(i).y(); | |
227 | } |
|
227 | } | |
228 | return total; |
|
228 | return total; | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | Sets pen for set. Bars of this set are drawn using \a pen |
|
232 | Sets pen for set. Bars of this set are drawn using \a pen | |
233 | */ |
|
233 | */ | |
234 | void QBarSet::setPen(const QPen &pen) |
|
234 | void QBarSet::setPen(const QPen &pen) | |
235 | { |
|
235 | { | |
236 | if(d_ptr->m_pen!=pen){ |
|
236 | if(d_ptr->m_pen!=pen){ | |
237 | d_ptr->m_pen = pen; |
|
237 | d_ptr->m_pen = pen; | |
238 | emit d_ptr->updatedBars(); |
|
238 | emit d_ptr->updatedBars(); | |
239 | } |
|
239 | } | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | /*! |
|
242 | /*! | |
243 | Returns pen of the set. |
|
243 | Returns pen of the set. | |
244 | */ |
|
244 | */ | |
245 | QPen QBarSet::pen() const |
|
245 | QPen QBarSet::pen() const | |
246 | { |
|
246 | { | |
247 | return d_ptr->m_pen; |
|
247 | return d_ptr->m_pen; | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | /*! |
|
250 | /*! | |
251 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
251 | Sets brush for the set. Bars of this set are drawn using \a brush | |
252 | */ |
|
252 | */ | |
253 | void QBarSet::setBrush(const QBrush &brush) |
|
253 | void QBarSet::setBrush(const QBrush &brush) | |
254 | { |
|
254 | { | |
255 | if(d_ptr->m_brush!=brush){ |
|
255 | if(d_ptr->m_brush!=brush){ | |
256 | d_ptr->m_brush = brush; |
|
256 | d_ptr->m_brush = brush; | |
257 | emit d_ptr->updatedBars(); |
|
257 | emit d_ptr->updatedBars(); | |
258 | } |
|
258 | } | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Returns brush of the set. |
|
262 | Returns brush of the set. | |
263 | */ |
|
263 | */ | |
264 | QBrush QBarSet::brush() const |
|
264 | QBrush QBarSet::brush() const | |
265 | { |
|
265 | { | |
266 | return d_ptr->m_brush; |
|
266 | return d_ptr->m_brush; | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | /*! |
|
269 | /*! | |
270 | Sets \a pen of the values that are drawn on top of this barset |
|
270 | Sets \a pen of the values that are drawn on top of this barset | |
271 | */ |
|
271 | */ | |
272 | void QBarSet::setLabelPen(const QPen &pen) |
|
272 | void QBarSet::setLabelPen(const QPen &pen) | |
273 | { |
|
273 | { | |
274 | if(d_ptr->m_labelPen!=pen){ |
|
274 | if(d_ptr->m_labelPen!=pen){ | |
275 | d_ptr->m_labelPen = pen; |
|
275 | d_ptr->m_labelPen = pen; | |
276 | emit d_ptr->updatedBars(); |
|
276 | emit d_ptr->updatedBars(); | |
277 | } |
|
277 | } | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 | /*! |
|
280 | /*! | |
281 | Returns pen of the values that are drawn on top of this barset |
|
281 | Returns pen of the values that are drawn on top of this barset | |
282 | */ |
|
282 | */ | |
283 | QPen QBarSet::labelPen() const |
|
283 | QPen QBarSet::labelPen() const | |
284 | { |
|
284 | { | |
285 | return d_ptr->m_labelPen; |
|
285 | return d_ptr->m_labelPen; | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | /*! |
|
288 | /*! | |
289 | Sets \a brush of the values that are drawn on top of this barset |
|
289 | Sets \a brush of the values that are drawn on top of this barset | |
290 | */ |
|
290 | */ | |
291 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
291 | void QBarSet::setLabelBrush(const QBrush &brush) | |
292 | { |
|
292 | { | |
293 | if(d_ptr->m_labelBrush!=brush){ |
|
293 | if(d_ptr->m_labelBrush!=brush){ | |
294 | d_ptr->m_labelBrush = brush; |
|
294 | d_ptr->m_labelBrush = brush; | |
295 | emit d_ptr->updatedBars(); |
|
295 | emit d_ptr->updatedBars(); | |
296 | } |
|
296 | } | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | /*! |
|
299 | /*! | |
300 | Returns brush of the values that are drawn on top of this barset |
|
300 | Returns brush of the values that are drawn on top of this barset | |
301 | */ |
|
301 | */ | |
302 | QBrush QBarSet::labelBrush() const |
|
302 | QBrush QBarSet::labelBrush() const | |
303 | { |
|
303 | { | |
304 | return d_ptr->m_labelBrush; |
|
304 | return d_ptr->m_labelBrush; | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | /*! |
|
307 | /*! | |
308 | Sets the \a font for values that are drawn on top of this barset |
|
308 | Sets the \a font for values that are drawn on top of this barset | |
309 | */ |
|
309 | */ | |
310 | void QBarSet::setLabelFont(const QFont &font) |
|
310 | void QBarSet::setLabelFont(const QFont &font) | |
311 | { |
|
311 | { | |
312 | if(d_ptr->m_labelFont!=font) { |
|
312 | if(d_ptr->m_labelFont!=font) { | |
313 | d_ptr->m_labelFont = font; |
|
313 | d_ptr->m_labelFont = font; | |
314 | emit d_ptr->updatedBars(); |
|
314 | emit d_ptr->updatedBars(); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | /*! |
|
319 | /*! | |
320 | Returns the pen for values that are drawn on top of this set |
|
320 | Returns the pen for values that are drawn on top of this set | |
321 | */ |
|
321 | */ | |
322 | QFont QBarSet::labelFont() const |
|
322 | QFont QBarSet::labelFont() const | |
323 | { |
|
323 | { | |
324 | return d_ptr->m_labelFont; |
|
324 | return d_ptr->m_labelFont; | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | /*! |
|
|||
328 | Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. |
|
|||
329 | */ |
|
|||
330 |
|
||||
331 | void QBarSet::setLabelsVisible(bool visible) |
|
|||
332 | { |
|
|||
333 | if(d_ptr->m_labelsVisible!=visible) { |
|
|||
334 | d_ptr->m_labelsVisible = visible; |
|
|||
335 | emit d_ptr->labelsVisibleChanged(visible); |
|
|||
336 | } |
|
|||
337 | } |
|
|||
338 |
|
||||
339 | /*! |
|
|||
340 | Returns the visibility of values |
|
|||
341 | */ |
|
|||
342 | bool QBarSet::labelsVisible() const |
|
|||
343 | { |
|
|||
344 | return d_ptr->m_labelsVisible; |
|
|||
345 | } |
|
|||
346 |
|
||||
347 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
327 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
348 |
|
328 | |||
349 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), |
|
329 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), | |
350 | q_ptr(parent), |
|
330 | q_ptr(parent), | |
351 |
m_name(name) |
|
331 | m_name(name) | |
352 | m_labelsVisible(false) |
|
|||
353 | { |
|
332 | { | |
354 | } |
|
333 | } | |
355 |
|
334 | |||
356 | QBarSetPrivate::~QBarSetPrivate() |
|
335 | QBarSetPrivate::~QBarSetPrivate() | |
357 | { |
|
336 | { | |
358 | } |
|
337 | } | |
359 |
|
338 | |||
360 | #include "moc_qbarset.cpp" |
|
339 | #include "moc_qbarset.cpp" | |
361 | #include "moc_qbarset_p.cpp" |
|
340 | #include "moc_qbarset_p.cpp" | |
362 |
|
341 | |||
363 | QTCOMMERCIALCHART_END_NAMESPACE |
|
342 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,93 +1,90 | |||||
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 | #ifndef QBARSET_H |
|
21 | #ifndef QBARSET_H | |
22 | #define QBARSET_H |
|
22 | #define QBARSET_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QBrush> |
|
26 | #include <QBrush> | |
27 | #include <QFont> |
|
27 | #include <QFont> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | class QBarSetPrivate; |
|
30 | class QBarSetPrivate; | |
31 |
|
31 | |||
32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | Q_PROPERTY(QString name READ name WRITE setName) |
|
35 | Q_PROPERTY(QString name READ name WRITE setName) | |
36 |
|
36 | |||
37 | public: |
|
37 | public: | |
38 | explicit QBarSet(const QString name, QObject *parent = 0); |
|
38 | explicit QBarSet(const QString name, QObject *parent = 0); | |
39 | virtual ~QBarSet(); |
|
39 | virtual ~QBarSet(); | |
40 |
|
40 | |||
41 | void setName(const QString name); |
|
41 | void setName(const QString name); | |
42 | QString name() const; |
|
42 | QString name() const; | |
43 |
|
43 | |||
44 |
void append(const QPointF value); |
|
44 | void append(const QPointF value); | |
45 |
void append(const QList<QPointF> values); |
|
45 | void append(const QList<QPointF> values); | |
46 | void append(const qreal value); // TODO: change so, that count becomes x-value |
|
46 | void append(const qreal value); | |
47 |
void append(const QList<qreal> values); |
|
47 | void append(const QList<qreal> values); | |
48 |
|
48 | |||
49 | QBarSet& operator << (const qreal &value); // TODO: change implementations so, that count becomes x-value |
|
49 | QBarSet& operator << (const qreal &value); | |
50 |
QBarSet& operator << (const QPointF &value); |
|
50 | QBarSet& operator << (const QPointF &value); | |
51 |
|
51 | |||
52 | void insert(const int index, const qreal value); // TODO: internal reindexing (what happens, if there are points with real x values?) |
|
52 | void insert(const int index, const qreal value); | |
53 | void remove(const int index); // TODO: internal reindexing (what happens, if there are points with real x values?) |
|
53 | void remove(const int index); | |
54 | void replace(const int index, const qreal value); |
|
54 | void replace(const int index, const qreal value); | |
55 | QPointF at(const int index) const; |
|
55 | QPointF at(const int index) const; | |
56 | QPointF operator [] (const int index) const; |
|
56 | QPointF operator [] (const int index) const; | |
57 | int count() const; |
|
57 | int count() const; | |
58 | qreal sum() const; |
|
58 | qreal sum() const; | |
59 |
|
59 | |||
60 | void setPen(const QPen &pen); |
|
60 | void setPen(const QPen &pen); | |
61 | QPen pen() const; |
|
61 | QPen pen() const; | |
62 |
|
62 | |||
63 | void setBrush(const QBrush &brush); |
|
63 | void setBrush(const QBrush &brush); | |
64 | QBrush brush() const; |
|
64 | QBrush brush() const; | |
65 |
|
65 | |||
66 | void setLabelPen(const QPen &pen); |
|
66 | void setLabelPen(const QPen &pen); | |
67 | QPen labelPen() const; |
|
67 | QPen labelPen() const; | |
68 |
|
68 | |||
69 | void setLabelBrush(const QBrush &brush); |
|
69 | void setLabelBrush(const QBrush &brush); | |
70 | QBrush labelBrush() const; |
|
70 | QBrush labelBrush() const; | |
71 |
|
71 | |||
72 | void setLabelFont(const QFont &font); |
|
72 | void setLabelFont(const QFont &font); | |
73 | QFont labelFont() const; |
|
73 | QFont labelFont() const; | |
74 |
|
74 | |||
75 | void setLabelsVisible(bool visible = true); |
|
|||
76 | bool labelsVisible() const; |
|
|||
77 |
|
||||
78 | Q_SIGNALS: |
|
75 | Q_SIGNALS: | |
79 | void clicked(QString category); |
|
76 | void clicked(QString category); | |
80 | void hovered(bool status); |
|
77 | void hovered(bool status); | |
81 |
|
78 | |||
82 | private: |
|
79 | private: | |
83 | QScopedPointer<QBarSetPrivate> d_ptr; |
|
80 | QScopedPointer<QBarSetPrivate> d_ptr; | |
84 | Q_DISABLE_COPY(QBarSet) |
|
81 | Q_DISABLE_COPY(QBarSet) | |
85 | friend class QBarSeries; |
|
82 | friend class QBarSeries; | |
86 | friend class BarLegendMarker; |
|
83 | friend class BarLegendMarker; | |
87 | friend class BarChartItem; |
|
84 | friend class BarChartItem; | |
88 | friend class QBarSeriesPrivate; |
|
85 | friend class QBarSeriesPrivate; | |
89 | }; |
|
86 | }; | |
90 |
|
87 | |||
91 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | QTCOMMERCIALCHART_END_NAMESPACE | |
92 |
|
89 | |||
93 | #endif // QBARSET_H |
|
90 | #endif // QBARSET_H |
@@ -1,39 +1,40 | |||||
1 | #ifndef QBARSET_P_H |
|
1 | #ifndef QBARSET_P_H | |
2 | #define QBARSET_P_H |
|
2 | #define QBARSET_P_H | |
3 |
|
3 | |||
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include <QMap> |
|
5 | #include <QMap> | |
|
6 | #include <QPen> | |||
|
7 | #include <QBrush> | |||
|
8 | #include <QFont> | |||
6 |
|
9 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
11 | |||
9 | class QBarSetPrivate : public QObject |
|
12 | class QBarSetPrivate : public QObject | |
10 | { |
|
13 | { | |
11 | Q_OBJECT |
|
14 | Q_OBJECT | |
12 |
|
15 | |||
13 | public: |
|
16 | public: | |
14 | QBarSetPrivate(const QString name, QBarSet *parent); |
|
17 | QBarSetPrivate(const QString name, QBarSet *parent); | |
15 | ~QBarSetPrivate(); |
|
18 | ~QBarSetPrivate(); | |
16 |
|
19 | |||
17 | Q_SIGNALS: |
|
20 | Q_SIGNALS: | |
18 | void clicked(QString category); |
|
21 | void clicked(QString category); | |
19 | void restructuredBars(); |
|
22 | void restructuredBars(); | |
20 | void updatedBars(); |
|
23 | void updatedBars(); | |
21 | void labelsVisibleChanged(bool visible); |
|
|||
22 |
|
24 | |||
23 | public: |
|
25 | public: | |
24 | QBarSet * const q_ptr; |
|
26 | QBarSet * const q_ptr; | |
25 | QString m_name; |
|
27 | QString m_name; | |
26 | QList<QPointF> m_values; |
|
28 | QList<QPointF> m_values; | |
27 | QPen m_pen; |
|
29 | QPen m_pen; | |
28 | QBrush m_brush; |
|
30 | QBrush m_brush; | |
29 | QPen m_labelPen; |
|
31 | QPen m_labelPen; | |
30 | QBrush m_labelBrush; |
|
32 | QBrush m_labelBrush; | |
31 | QFont m_labelFont; |
|
33 | QFont m_labelFont; | |
32 | bool m_labelsVisible; |
|
|||
33 |
|
34 | |||
34 | friend class QBarSet; |
|
35 | friend class QBarSet; | |
35 | }; |
|
36 | }; | |
36 |
|
37 | |||
37 | QTCOMMERCIALCHART_END_NAMESPACE |
|
38 | QTCOMMERCIALCHART_END_NAMESPACE | |
38 |
|
39 | |||
39 | #endif // QBARSETPRIVATE_P_H |
|
40 | #endif // QBARSETPRIVATE_P_H |
@@ -1,88 +1,87 | |||||
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 "stackedbarchartitem_p.h" |
|
21 | #include "stackedbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "barlabel_p.h" |
|
|||
24 | #include "qbarset_p.h" |
|
23 | #include "qbarset_p.h" | |
25 | #include "qbarseries_p.h" |
|
24 | #include "qbarseries_p.h" | |
26 | #include "qbarset.h" |
|
25 | #include "qbarset.h" | |
27 |
|
26 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
28 | |||
30 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
31 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
32 | { |
|
31 | { | |
33 | } |
|
32 | } | |
34 |
|
33 | |||
35 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
34 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
36 | { |
|
35 | { | |
37 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
38 | // Use temporary qreals for accurancy |
|
37 | // Use temporary qreals for accurancy | |
39 | qreal categoryCount = m_series->categoryCount(); |
|
38 | qreal categoryCount = m_series->categoryCount(); | |
40 | qreal setCount = m_series->barsetCount(); |
|
39 | qreal setCount = m_series->barsetCount(); | |
41 |
|
40 | |||
42 | // Domain: |
|
41 | // Domain: | |
43 | qreal width = geometry().width(); |
|
42 | qreal width = geometry().width(); | |
44 | qreal height = geometry().height(); |
|
43 | qreal height = geometry().height(); | |
45 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
44 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
46 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
45 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
47 | qreal scaleY = (height / rangeY); |
|
46 | qreal scaleY = (height / rangeY); | |
48 | qreal scaleX = (width / rangeX); |
|
47 | qreal scaleX = (width / rangeX); | |
49 | qreal categoryWidth = width / categoryCount; |
|
48 | qreal categoryWidth = width / categoryCount; | |
50 | qreal barWidth = categoryWidth / setCount - categoryWidth * m_series->d_func()->barMargin(); |
|
49 | qreal barWidth = categoryWidth / setCount - categoryWidth * m_series->d_func()->barMargin(); | |
51 |
|
50 | |||
52 | int itemIndex(0); |
|
51 | int itemIndex(0); | |
53 | for (int category = 0; category < categoryCount; category++) { |
|
52 | for (int category = 0; category < categoryCount; category++) { | |
54 | qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y(); |
|
53 | qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y(); | |
55 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
54 | for (int set=0; set < m_series->barsetCount(); set++) { | |
56 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
55 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
57 |
|
56 | |||
58 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
57 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
59 |
|
58 | |||
60 | qreal barHeight = barSet->at(category).y() * scaleY; |
|
59 | qreal barHeight = barSet->at(category).y() * scaleY; | |
61 | Bar* bar = m_bars.at(itemIndex); |
|
60 | Bar* bar = m_bars.at(itemIndex); | |
62 | bar->setPen(barSet->pen()); |
|
61 | bar->setPen(barSet->pen()); | |
63 | bar->setBrush(barSet->brush()); |
|
62 | bar->setBrush(barSet->brush()); | |
64 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
63 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
65 | layout.append(rect); |
|
64 | layout.append(rect); | |
66 |
|
65 | |||
67 |
|
|
66 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
68 |
|
67 | |||
69 | if (!qFuzzyIsNull(barSet->at(category).y())) { |
|
68 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
70 | label->setText(QString::number(barSet->at(category).y())); |
|
69 | label->setText(QString::number(barSet->at(category).y())); | |
71 | } else { |
|
70 | } else { | |
72 | label->setText(QString("")); |
|
71 | label->setText(QString("")); | |
73 | } |
|
72 | } | |
74 |
|
73 | |||
75 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
74 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
76 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
75 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
77 | label->setFont(barSet->labelFont()); |
|
76 | label->setFont(barSet->labelFont()); | |
78 | itemIndex++; |
|
77 | itemIndex++; | |
79 | yPos -= barHeight; |
|
78 | yPos -= barHeight; | |
80 | } |
|
79 | } | |
81 | } |
|
80 | } | |
82 |
|
81 | |||
83 | return layout; |
|
82 | return layout; | |
84 | } |
|
83 | } | |
85 |
|
84 | |||
86 | #include "moc_stackedbarchartitem_p.cpp" |
|
85 | #include "moc_stackedbarchartitem_p.cpp" | |
87 |
|
86 | |||
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,677 +1,673 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qbarseries.h> |
|
22 | #include <qbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 | #include <qchart.h> |
|
25 | #include <qchart.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 | Q_DECLARE_METATYPE(QBarSet*) |
|
29 | Q_DECLARE_METATYPE(QBarSet*) | |
30 |
|
30 | |||
31 | class tst_QBarSeries : public QObject |
|
31 | class tst_QBarSeries : public QObject | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public slots: |
|
35 | public slots: | |
36 | void initTestCase(); |
|
36 | void initTestCase(); | |
37 | void cleanupTestCase(); |
|
37 | void cleanupTestCase(); | |
38 | void init(); |
|
38 | void init(); | |
39 | void cleanup(); |
|
39 | void cleanup(); | |
40 |
|
40 | |||
41 | private slots: |
|
41 | private slots: | |
42 | void qbarseries_data(); |
|
42 | void qbarseries_data(); | |
43 | void qbarseries(); |
|
43 | void qbarseries(); | |
44 | void type_data(); |
|
44 | void type_data(); | |
45 | void type(); |
|
45 | void type(); | |
46 | void setCategories_data(); |
|
46 | void setCategories_data(); | |
47 | void setCategories(); |
|
47 | void setCategories(); | |
48 | void append_data(); |
|
48 | void append_data(); | |
49 | void append(); |
|
49 | void append(); | |
50 | void remove_data(); |
|
50 | void remove_data(); | |
51 | void remove(); |
|
51 | void remove(); | |
52 | void appendList_data(); |
|
52 | void appendList_data(); | |
53 | void appendList(); |
|
53 | void appendList(); | |
54 | void removeList_data(); |
|
54 | void removeList_data(); | |
55 | void removeList(); |
|
55 | void removeList(); | |
56 | void barsetCount_data(); |
|
56 | void barsetCount_data(); | |
57 | void barsetCount(); |
|
57 | void barsetCount(); | |
58 | void categoryCount_data(); |
|
58 | void categoryCount_data(); | |
59 | void categoryCount(); |
|
59 | void categoryCount(); | |
60 | void barSets_data(); |
|
60 | void barSets_data(); | |
61 | void barSets(); |
|
61 | void barSets(); | |
62 | void categories_data(); |
|
62 | void categories_data(); | |
63 | void categories(); |
|
63 | void categories(); | |
64 | void setLabelsVisible_data(); |
|
64 | void setLabelsVisible_data(); | |
65 | void setLabelsVisible(); |
|
65 | void setLabelsVisible(); | |
66 | void mouseclicked_data(); |
|
66 | void mouseclicked_data(); | |
67 | void mouseclicked(); |
|
67 | void mouseclicked(); | |
68 | void mousehovered_data(); |
|
68 | void mousehovered_data(); | |
69 | void mousehovered(); |
|
69 | void mousehovered(); | |
70 |
|
70 | |||
71 | private: |
|
71 | private: | |
72 | QBarSeries* m_barseries; |
|
72 | QBarSeries* m_barseries; | |
73 | QBarSeries* m_barseries_with_sets; |
|
73 | QBarSeries* m_barseries_with_sets; | |
74 |
|
74 | |||
75 | QList<QBarSet*> m_testSets; |
|
75 | QList<QBarSet*> m_testSets; | |
76 |
|
76 | |||
77 | QBarCategories m_categories; |
|
77 | QBarCategories m_categories; | |
78 | }; |
|
78 | }; | |
79 |
|
79 | |||
80 | void tst_QBarSeries::initTestCase() |
|
80 | void tst_QBarSeries::initTestCase() | |
81 | { |
|
81 | { | |
82 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
82 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void tst_QBarSeries::cleanupTestCase() |
|
85 | void tst_QBarSeries::cleanupTestCase() | |
86 | { |
|
86 | { | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void tst_QBarSeries::init() |
|
89 | void tst_QBarSeries::init() | |
90 | { |
|
90 | { | |
91 | m_categories << "category0" << "category1" << "category2"; |
|
91 | m_categories << "category0" << "category1" << "category2"; | |
92 | m_barseries = new QBarSeries(); |
|
92 | m_barseries = new QBarSeries(); | |
93 | m_barseries->setCategories(m_categories); |
|
93 | m_barseries->setCategories(m_categories); | |
94 | m_barseries_with_sets = new QBarSeries(); |
|
94 | m_barseries_with_sets = new QBarSeries(); | |
95 | m_barseries_with_sets->setCategories(m_categories); |
|
95 | m_barseries_with_sets->setCategories(m_categories); | |
96 |
|
96 | |||
97 | for (int i=0; i<5; i++) { |
|
97 | for (int i=0; i<5; i++) { | |
98 | m_testSets.append(new QBarSet("testset")); |
|
98 | m_testSets.append(new QBarSet("testset")); | |
99 | m_barseries_with_sets->append(m_testSets.at(i)); |
|
99 | m_barseries_with_sets->append(m_testSets.at(i)); | |
100 | } |
|
100 | } | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | void tst_QBarSeries::cleanup() |
|
103 | void tst_QBarSeries::cleanup() | |
104 | { |
|
104 | { | |
105 | foreach(QBarSet* s, m_testSets) { |
|
105 | foreach(QBarSet* s, m_testSets) { | |
106 | m_barseries_with_sets->remove(s); |
|
106 | m_barseries_with_sets->remove(s); | |
107 | delete s; |
|
107 | delete s; | |
108 | } |
|
108 | } | |
109 | m_testSets.clear(); |
|
109 | m_testSets.clear(); | |
110 |
|
110 | |||
111 | delete m_barseries; |
|
111 | delete m_barseries; | |
112 | m_barseries = 0; |
|
112 | m_barseries = 0; | |
113 | delete m_barseries_with_sets; |
|
113 | delete m_barseries_with_sets; | |
114 | m_barseries_with_sets = 0; |
|
114 | m_barseries_with_sets = 0; | |
115 | m_categories.clear(); |
|
115 | m_categories.clear(); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void tst_QBarSeries::qbarseries_data() |
|
118 | void tst_QBarSeries::qbarseries_data() | |
119 | { |
|
119 | { | |
120 | QTest::addColumn<QBarCategories> ("categories"); |
|
120 | QTest::addColumn<QBarCategories> ("categories"); | |
121 | QBarCategories c; |
|
121 | QBarCategories c; | |
122 | c << "category0" << "category1" << "category2"; |
|
122 | c << "category0" << "category1" << "category2"; | |
123 | QTest::newRow("categories") << c; |
|
123 | QTest::newRow("categories") << c; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void tst_QBarSeries::qbarseries() |
|
126 | void tst_QBarSeries::qbarseries() | |
127 | { |
|
127 | { | |
128 | QFETCH(QBarCategories, categories); |
|
128 | QFETCH(QBarCategories, categories); | |
129 | QBarSeries *barseries = new QBarSeries(); |
|
129 | QBarSeries *barseries = new QBarSeries(); | |
130 | QVERIFY(barseries != 0); |
|
130 | QVERIFY(barseries != 0); | |
131 | barseries->setCategories(categories); |
|
131 | barseries->setCategories(categories); | |
132 | QBarCategories verifyCategories = barseries->categories(); |
|
132 | QBarCategories verifyCategories = barseries->categories(); | |
133 |
|
133 | |||
134 | QVERIFY(verifyCategories.count() == categories.count()); |
|
134 | QVERIFY(verifyCategories.count() == categories.count()); | |
135 | for (int i=0; i<categories.count(); i++) { |
|
135 | for (int i=0; i<categories.count(); i++) { | |
136 | QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0); |
|
136 | QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0); | |
137 | } |
|
137 | } | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | void tst_QBarSeries::type_data() |
|
140 | void tst_QBarSeries::type_data() | |
141 | { |
|
141 | { | |
142 |
|
142 | |||
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | void tst_QBarSeries::type() |
|
145 | void tst_QBarSeries::type() | |
146 | { |
|
146 | { | |
147 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
147 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | void tst_QBarSeries::setCategories_data() |
|
150 | void tst_QBarSeries::setCategories_data() | |
151 | { |
|
151 | { | |
152 | QTest::addColumn<QBarCategories> ("categories"); |
|
152 | QTest::addColumn<QBarCategories> ("categories"); | |
153 | QBarCategories categories; |
|
153 | QBarCategories categories; | |
154 | categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6"; |
|
154 | categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6"; | |
155 | QTest::newRow("cat") << categories; |
|
155 | QTest::newRow("cat") << categories; | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | void tst_QBarSeries::setCategories() |
|
158 | void tst_QBarSeries::setCategories() | |
159 | { |
|
159 | { | |
160 | QVERIFY(m_barseries->categories().count() == m_categories.count()); |
|
160 | QVERIFY(m_barseries->categories().count() == m_categories.count()); | |
161 |
|
161 | |||
162 | QFETCH(QBarCategories, categories); |
|
162 | QFETCH(QBarCategories, categories); | |
163 | m_barseries->setCategories(categories); |
|
163 | m_barseries->setCategories(categories); | |
164 |
|
164 | |||
165 | QVERIFY(m_barseries->categories().count() == categories.count()); |
|
165 | QVERIFY(m_barseries->categories().count() == categories.count()); | |
166 | for (int i=0; i<categories.count(); i++) { |
|
166 | for (int i=0; i<categories.count(); i++) { | |
167 | QVERIFY(m_barseries->categories().at(i).compare(categories.at(i)) == 0); |
|
167 | QVERIFY(m_barseries->categories().at(i).compare(categories.at(i)) == 0); | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void tst_QBarSeries::append_data() |
|
171 | void tst_QBarSeries::append_data() | |
172 | { |
|
172 | { | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void tst_QBarSeries::append() |
|
175 | void tst_QBarSeries::append() | |
176 | { |
|
176 | { | |
177 | QVERIFY(m_barseries->barsetCount() == 0); |
|
177 | QVERIFY(m_barseries->barsetCount() == 0); | |
178 |
|
178 | |||
179 | bool ret = false; |
|
179 | bool ret = false; | |
180 |
|
180 | |||
181 | // Try adding barset |
|
181 | // Try adding barset | |
182 | QBarSet *barset = new QBarSet("testset"); |
|
182 | QBarSet *barset = new QBarSet("testset"); | |
183 | ret = m_barseries->append(barset); |
|
183 | ret = m_barseries->append(barset); | |
184 |
|
184 | |||
185 | QVERIFY(ret == true); |
|
185 | QVERIFY(ret == true); | |
186 | QVERIFY(m_barseries->barsetCount() == 1); |
|
186 | QVERIFY(m_barseries->barsetCount() == 1); | |
187 |
|
187 | |||
188 | // Try adding another set |
|
188 | // Try adding another set | |
189 | QBarSet *barset2 = new QBarSet("testset2"); |
|
189 | QBarSet *barset2 = new QBarSet("testset2"); | |
190 | ret = m_barseries->append(barset2); |
|
190 | ret = m_barseries->append(barset2); | |
191 |
|
191 | |||
192 | QVERIFY(ret == true); |
|
192 | QVERIFY(ret == true); | |
193 | QVERIFY(m_barseries->barsetCount() == 2); |
|
193 | QVERIFY(m_barseries->barsetCount() == 2); | |
194 |
|
194 | |||
195 | // Try adding same set again |
|
195 | // Try adding same set again | |
196 | ret = m_barseries->append(barset2); |
|
196 | ret = m_barseries->append(barset2); | |
197 | QVERIFY(ret == false); |
|
197 | QVERIFY(ret == false); | |
198 | QVERIFY(m_barseries->barsetCount() == 2); |
|
198 | QVERIFY(m_barseries->barsetCount() == 2); | |
199 |
|
199 | |||
200 | // Try adding null set |
|
200 | // Try adding null set | |
201 | ret = m_barseries->append(0); |
|
201 | ret = m_barseries->append(0); | |
202 | QVERIFY(ret == false); |
|
202 | QVERIFY(ret == false); | |
203 | QVERIFY(m_barseries->barsetCount() == 2); |
|
203 | QVERIFY(m_barseries->barsetCount() == 2); | |
204 |
|
204 | |||
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void tst_QBarSeries::remove_data() |
|
207 | void tst_QBarSeries::remove_data() | |
208 | { |
|
208 | { | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | void tst_QBarSeries::remove() |
|
211 | void tst_QBarSeries::remove() | |
212 | { |
|
212 | { | |
213 | int count = m_testSets.count(); |
|
213 | int count = m_testSets.count(); | |
214 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
214 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
215 |
|
215 | |||
216 | // Try to remove null pointer (should not remove, should not crash) |
|
216 | // Try to remove null pointer (should not remove, should not crash) | |
217 | bool ret = false; |
|
217 | bool ret = false; | |
218 | ret = m_barseries_with_sets->remove(0); |
|
218 | ret = m_barseries_with_sets->remove(0); | |
219 | QVERIFY(ret == false); |
|
219 | QVERIFY(ret == false); | |
220 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
220 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
221 |
|
221 | |||
222 | // Try to remove invalid pointer (should not remove, should not crash) |
|
222 | // Try to remove invalid pointer (should not remove, should not crash) | |
223 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); |
|
223 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); | |
224 | QVERIFY(ret == false); |
|
224 | QVERIFY(ret == false); | |
225 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
225 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
226 |
|
226 | |||
227 | // remove some sets |
|
227 | // remove some sets | |
228 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); |
|
228 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); | |
229 | QVERIFY(ret == true); |
|
229 | QVERIFY(ret == true); | |
230 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); |
|
230 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); | |
231 | QVERIFY(ret == true); |
|
231 | QVERIFY(ret == true); | |
232 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); |
|
232 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); | |
233 | QVERIFY(ret == true); |
|
233 | QVERIFY(ret == true); | |
234 |
|
234 | |||
235 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); |
|
235 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); | |
236 |
|
236 | |||
237 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
237 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); | |
238 |
|
238 | |||
239 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
239 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); | |
240 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
240 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); | |
241 |
|
241 | |||
242 | // Try removing all sets again (should be ok, even if some sets have already been removed) |
|
242 | // Try removing all sets again (should be ok, even if some sets have already been removed) | |
243 | ret = false; |
|
243 | ret = false; | |
244 | for (int i=0; i<count; i++) { |
|
244 | for (int i=0; i<count; i++) { | |
245 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); |
|
245 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | QVERIFY(ret == true); |
|
248 | QVERIFY(ret == true); | |
249 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
249 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | void tst_QBarSeries::appendList_data() |
|
252 | void tst_QBarSeries::appendList_data() | |
253 | { |
|
253 | { | |
254 |
|
254 | |||
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | void tst_QBarSeries::appendList() |
|
257 | void tst_QBarSeries::appendList() | |
258 | { |
|
258 | { | |
259 | int count = 5; |
|
259 | int count = 5; | |
260 | QVERIFY(m_barseries->barsetCount() == 0); |
|
260 | QVERIFY(m_barseries->barsetCount() == 0); | |
261 |
|
261 | |||
262 | QList<QBarSet*> sets; |
|
262 | QList<QBarSet*> sets; | |
263 | for (int i=0; i<count; i++) { |
|
263 | for (int i=0; i<count; i++) { | |
264 | sets.append(new QBarSet("testset")); |
|
264 | sets.append(new QBarSet("testset")); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | // Append new sets (should succeed, count should match the count of sets) |
|
267 | // Append new sets (should succeed, count should match the count of sets) | |
268 | bool ret = false; |
|
268 | bool ret = false; | |
269 | ret = m_barseries->append(sets); |
|
269 | ret = m_barseries->append(sets); | |
270 | QVERIFY(ret == true); |
|
270 | QVERIFY(ret == true); | |
271 | QVERIFY(m_barseries->barsetCount() == count); |
|
271 | QVERIFY(m_barseries->barsetCount() == count); | |
272 |
|
272 | |||
273 | // Append same sets again (should fail, count should remain same) |
|
273 | // Append same sets again (should fail, count should remain same) | |
274 | ret = m_barseries->append(sets); |
|
274 | ret = m_barseries->append(sets); | |
275 | QVERIFY(ret == false); |
|
275 | QVERIFY(ret == false); | |
276 | QVERIFY(m_barseries->barsetCount() == count); |
|
276 | QVERIFY(m_barseries->barsetCount() == count); | |
277 |
|
277 | |||
278 | // Try append empty list (should succeed, but count should remain same) |
|
278 | // Try append empty list (should succeed, but count should remain same) | |
279 | QList<QBarSet*> invalidList; |
|
279 | QList<QBarSet*> invalidList; | |
280 | ret = m_barseries->append(invalidList); |
|
280 | ret = m_barseries->append(invalidList); | |
281 | QVERIFY(ret == true); |
|
281 | QVERIFY(ret == true); | |
282 | QVERIFY(m_barseries->barsetCount() == count); |
|
282 | QVERIFY(m_barseries->barsetCount() == count); | |
283 |
|
283 | |||
284 | // Try append list with one new and one existing set (should fail, count remains same) |
|
284 | // Try append list with one new and one existing set (should fail, count remains same) | |
285 | invalidList.append(new QBarSet("ok set")); |
|
285 | invalidList.append(new QBarSet("ok set")); | |
286 | invalidList.append(sets.at(0)); |
|
286 | invalidList.append(sets.at(0)); | |
287 | ret = m_barseries->append(invalidList); |
|
287 | ret = m_barseries->append(invalidList); | |
288 | QVERIFY(ret == false); |
|
288 | QVERIFY(ret == false); | |
289 | QVERIFY(m_barseries->barsetCount() == count); |
|
289 | QVERIFY(m_barseries->barsetCount() == count); | |
290 |
|
290 | |||
291 | // Try append list with null pointers (should fail, count remains same) |
|
291 | // Try append list with null pointers (should fail, count remains same) | |
292 | QList<QBarSet*> invalidList2; |
|
292 | QList<QBarSet*> invalidList2; | |
293 | invalidList2.append(0); |
|
293 | invalidList2.append(0); | |
294 | invalidList2.append(0); |
|
294 | invalidList2.append(0); | |
295 | invalidList2.append(0); |
|
295 | invalidList2.append(0); | |
296 | ret = m_barseries->append(invalidList2); |
|
296 | ret = m_barseries->append(invalidList2); | |
297 | QVERIFY(ret == false); |
|
297 | QVERIFY(ret == false); | |
298 | QVERIFY(m_barseries->barsetCount() == count); |
|
298 | QVERIFY(m_barseries->barsetCount() == count); | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | void tst_QBarSeries::removeList_data() |
|
301 | void tst_QBarSeries::removeList_data() | |
302 | { |
|
302 | { | |
303 |
|
303 | |||
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | void tst_QBarSeries::removeList() |
|
306 | void tst_QBarSeries::removeList() | |
307 | { |
|
307 | { | |
308 | int count = m_testSets.count(); |
|
308 | int count = m_testSets.count(); | |
309 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
309 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
310 |
|
310 | |||
311 | // Try removing empty list of sets (should return false, since no barsets were removed) |
|
311 | // Try removing empty list of sets (should return false, since no barsets were removed) | |
312 | bool ret = false; |
|
312 | bool ret = false; | |
313 | QList<QBarSet*> invalidList; |
|
313 | QList<QBarSet*> invalidList; | |
314 | ret = m_barseries_with_sets->remove(invalidList); |
|
314 | ret = m_barseries_with_sets->remove(invalidList); | |
315 | QVERIFY(ret == false); |
|
315 | QVERIFY(ret == false); | |
316 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
316 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
317 |
|
317 | |||
318 | // Add some null pointers to list |
|
318 | // Add some null pointers to list | |
319 | invalidList.append(0); |
|
319 | invalidList.append(0); | |
320 | invalidList.append(0); |
|
320 | invalidList.append(0); | |
321 | invalidList.append(0); |
|
321 | invalidList.append(0); | |
322 |
|
322 | |||
323 | // Try removing null pointers from list (should return false, should not crash, should not remove anything) |
|
323 | // Try removing null pointers from list (should return false, should not crash, should not remove anything) | |
324 | ret = m_barseries_with_sets->remove(invalidList); |
|
324 | ret = m_barseries_with_sets->remove(invalidList); | |
325 | QVERIFY(ret == false); |
|
325 | QVERIFY(ret == false); | |
326 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
326 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
327 |
|
327 | |||
328 | // remove all sets (should return true, since sets were removed) |
|
328 | // remove all sets (should return true, since sets were removed) | |
329 | ret = m_barseries_with_sets->remove(m_testSets); |
|
329 | ret = m_barseries_with_sets->remove(m_testSets); | |
330 | QVERIFY(ret == true); |
|
330 | QVERIFY(ret == true); | |
331 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
331 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
332 |
|
332 | |||
333 | // Try removing invalid list again (should return false, since no barsets were removed) |
|
333 | // Try removing invalid list again (should return false, since no barsets were removed) | |
334 | ret = m_barseries_with_sets->remove(invalidList); |
|
334 | ret = m_barseries_with_sets->remove(invalidList); | |
335 | QVERIFY(ret == false); |
|
335 | QVERIFY(ret == false); | |
336 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
336 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
337 |
|
337 | |||
338 | // remove all sets again (should return false, since barsets were already removed) |
|
338 | // remove all sets again (should return false, since barsets were already removed) | |
339 | ret = m_barseries_with_sets->remove(m_testSets); |
|
339 | ret = m_barseries_with_sets->remove(m_testSets); | |
340 | QVERIFY(ret == false); |
|
340 | QVERIFY(ret == false); | |
341 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
341 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | void tst_QBarSeries::barsetCount_data() |
|
344 | void tst_QBarSeries::barsetCount_data() | |
345 | { |
|
345 | { | |
346 |
|
346 | |||
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | void tst_QBarSeries::barsetCount() |
|
349 | void tst_QBarSeries::barsetCount() | |
350 | { |
|
350 | { | |
351 | QVERIFY(m_barseries->barsetCount() == 0); |
|
351 | QVERIFY(m_barseries->barsetCount() == 0); | |
352 | QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); |
|
352 | QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | void tst_QBarSeries::categoryCount_data() |
|
355 | void tst_QBarSeries::categoryCount_data() | |
356 | { |
|
356 | { | |
357 |
|
357 | |||
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | void tst_QBarSeries::categoryCount() |
|
360 | void tst_QBarSeries::categoryCount() | |
361 | { |
|
361 | { | |
362 | QVERIFY(m_barseries->categoryCount() == m_categories.count()); |
|
362 | QVERIFY(m_barseries->categoryCount() == m_categories.count()); | |
363 | QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count()); |
|
363 | QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count()); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | void tst_QBarSeries::barSets_data() |
|
366 | void tst_QBarSeries::barSets_data() | |
367 | { |
|
367 | { | |
368 |
|
368 | |||
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | void tst_QBarSeries::barSets() |
|
371 | void tst_QBarSeries::barSets() | |
372 | { |
|
372 | { | |
373 | QVERIFY(m_barseries->barSets().count() == 0); |
|
373 | QVERIFY(m_barseries->barSets().count() == 0); | |
374 |
|
374 | |||
375 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
375 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); | |
376 | QVERIFY(sets.count() == m_testSets.count()); |
|
376 | QVERIFY(sets.count() == m_testSets.count()); | |
377 |
|
377 | |||
378 | for (int i=0; i<m_testSets.count(); i++) { |
|
378 | for (int i=0; i<m_testSets.count(); i++) { | |
379 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
379 | QVERIFY(sets.at(i) == m_testSets.at(i)); | |
380 | } |
|
380 | } | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | void tst_QBarSeries::categories_data() |
|
383 | void tst_QBarSeries::categories_data() | |
384 | { |
|
384 | { | |
385 |
|
385 | |||
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | void tst_QBarSeries::categories() |
|
388 | void tst_QBarSeries::categories() | |
389 | { |
|
389 | { | |
390 | QBarCategories categories = m_barseries->categories(); |
|
390 | QBarCategories categories = m_barseries->categories(); | |
391 |
|
391 | |||
392 | QVERIFY(categories.count() == m_categories.count()); |
|
392 | QVERIFY(categories.count() == m_categories.count()); | |
393 | for (int i=0; i<m_categories.count(); i++) { |
|
393 | for (int i=0; i<m_categories.count(); i++) { | |
394 | QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0); |
|
394 | QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0); | |
395 | } |
|
395 | } | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 | void tst_QBarSeries::setLabelsVisible_data() |
|
398 | void tst_QBarSeries::setLabelsVisible_data() | |
399 | { |
|
399 | { | |
400 |
|
400 | |||
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | void tst_QBarSeries::setLabelsVisible() |
|
403 | void tst_QBarSeries::setLabelsVisible() | |
404 | { |
|
404 | { | |
405 | // labels should be invisible by default |
|
405 | // labels should be invisible by default | |
406 | foreach (QBarSet* s, m_testSets) { |
|
406 | QVERIFY(m_barseries->isLabelsVisible() == false); | |
407 |
|
|
407 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
408 | } |
|
|||
409 |
|
408 | |||
410 | // turn labels to visible |
|
409 | // turn labels to visible | |
411 | m_barseries_with_sets->setLabelsVisible(true); |
|
410 | m_barseries_with_sets->setLabelsVisible(true); | |
412 | foreach (QBarSet* s, m_testSets) { |
|
411 | // TODO: test the signal | |
413 |
|
|
412 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
414 | } |
|
|||
415 |
|
413 | |||
416 | // turn labels to invisible |
|
414 | // turn labels to invisible | |
417 | m_barseries_with_sets->setLabelsVisible(false); |
|
415 | m_barseries_with_sets->setLabelsVisible(false); | |
418 | foreach (QBarSet* s, m_testSets) { |
|
416 | // TODO: test the signal | |
419 |
|
|
417 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
420 | } |
|
|||
421 |
|
418 | |||
422 | // without parameter, should turn labels to visible |
|
419 | // without parameter, should turn labels to visible | |
423 | m_barseries_with_sets->setLabelsVisible(); |
|
420 | m_barseries_with_sets->setLabelsVisible(); | |
424 | foreach (QBarSet* s, m_testSets) { |
|
421 | // TODO: test the signal | |
425 |
|
|
422 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
426 | } |
|
|||
427 | } |
|
423 | } | |
428 |
|
424 | |||
429 | void tst_QBarSeries::mouseclicked_data() |
|
425 | void tst_QBarSeries::mouseclicked_data() | |
430 | { |
|
426 | { | |
431 |
|
427 | |||
432 | } |
|
428 | } | |
433 |
|
429 | |||
434 | void tst_QBarSeries::mouseclicked() |
|
430 | void tst_QBarSeries::mouseclicked() | |
435 | { |
|
431 | { | |
436 | QBarSeries* series = new QBarSeries(); |
|
432 | QBarSeries* series = new QBarSeries(); | |
437 | QBarCategories categories; |
|
433 | QBarCategories categories; | |
438 | categories << "test1" << "test2" << "test3"; |
|
434 | categories << "test1" << "test2" << "test3"; | |
439 | series->setCategories(categories); |
|
435 | series->setCategories(categories); | |
440 |
|
436 | |||
441 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
437 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
442 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); |
|
438 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
443 | series->append(set1); |
|
439 | series->append(set1); | |
444 |
|
440 | |||
445 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
441 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
446 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); |
|
442 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
447 | series->append(set2); |
|
443 | series->append(set2); | |
448 |
|
444 | |||
449 | QSignalSpy setSpy1(set1, SIGNAL(clicked(QString))); |
|
445 | QSignalSpy setSpy1(set1, SIGNAL(clicked(QString))); | |
450 | QSignalSpy setSpy2(set2, SIGNAL(clicked(QString))); |
|
446 | QSignalSpy setSpy2(set2, SIGNAL(clicked(QString))); | |
451 | QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,QString))); |
|
447 | QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,QString))); | |
452 |
|
448 | |||
453 | QChartView view(new QChart()); |
|
449 | QChartView view(new QChart()); | |
454 | view.resize(400,300); |
|
450 | view.resize(400,300); | |
455 | view.chart()->addSeries(series); |
|
451 | view.chart()->addSeries(series); | |
456 | view.show(); |
|
452 | view.show(); | |
457 | QTest::qWaitForWindowShown(&view); |
|
453 | QTest::qWaitForWindowShown(&view); | |
458 |
|
454 | |||
459 | //==================================================================================== |
|
455 | //==================================================================================== | |
460 | // barset 1, category test1 |
|
456 | // barset 1, category test1 | |
461 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(105,180)); |
|
457 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(105,180)); | |
462 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
458 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
463 |
|
459 | |||
464 | QCOMPARE(setSpy1.count(), 1); |
|
460 | QCOMPARE(setSpy1.count(), 1); | |
465 | QCOMPARE(setSpy2.count(), 0); |
|
461 | QCOMPARE(setSpy2.count(), 0); | |
466 | QCOMPARE(seriesSpy.count(), 1); |
|
462 | QCOMPARE(seriesSpy.count(), 1); | |
467 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
463 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); | |
468 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); |
|
464 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); | |
469 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test1")) == 0); |
|
465 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test1")) == 0); | |
470 |
|
466 | |||
471 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
467 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
472 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
468 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
473 |
|
469 | |||
474 | //==================================================================================== |
|
470 | //==================================================================================== | |
475 | // barset 1, category test2 |
|
471 | // barset 1, category test2 | |
476 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(200,180)); |
|
472 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(200,180)); | |
477 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
473 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
478 |
|
474 | |||
479 | QCOMPARE(setSpy1.count(), 1); |
|
475 | QCOMPARE(setSpy1.count(), 1); | |
480 | QCOMPARE(setSpy2.count(), 0); |
|
476 | QCOMPARE(setSpy2.count(), 0); | |
481 | QCOMPARE(seriesSpy.count(), 1); |
|
477 | QCOMPARE(seriesSpy.count(), 1); | |
482 | setSpyArg = setSpy1.takeFirst(); |
|
478 | setSpyArg = setSpy1.takeFirst(); | |
483 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); |
|
479 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); | |
484 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test2")) == 0); |
|
480 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test2")) == 0); | |
485 |
|
481 | |||
486 | seriesSpyArg = seriesSpy.takeFirst(); |
|
482 | seriesSpyArg = seriesSpy.takeFirst(); | |
487 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
483 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
488 |
|
484 | |||
489 | //==================================================================================== |
|
485 | //==================================================================================== | |
490 | // barset 1, category test3 |
|
486 | // barset 1, category test3 | |
491 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(295,180)); |
|
487 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(295,180)); | |
492 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
488 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
493 |
|
489 | |||
494 | QCOMPARE(setSpy1.count(), 1); |
|
490 | QCOMPARE(setSpy1.count(), 1); | |
495 | QCOMPARE(setSpy2.count(), 0); |
|
491 | QCOMPARE(setSpy2.count(), 0); | |
496 | QCOMPARE(seriesSpy.count(), 1); |
|
492 | QCOMPARE(seriesSpy.count(), 1); | |
497 | setSpyArg = setSpy1.takeFirst(); |
|
493 | setSpyArg = setSpy1.takeFirst(); | |
498 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); |
|
494 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); | |
499 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test3")) == 0); |
|
495 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test3")) == 0); | |
500 |
|
496 | |||
501 | seriesSpyArg = seriesSpy.takeFirst(); |
|
497 | seriesSpyArg = seriesSpy.takeFirst(); | |
502 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
498 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
503 |
|
499 | |||
504 | //==================================================================================== |
|
500 | //==================================================================================== | |
505 | // barset 2, category test1 |
|
501 | // barset 2, category test1 | |
506 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(145,180)); |
|
502 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(145,180)); | |
507 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
503 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
508 |
|
504 | |||
509 | QCOMPARE(setSpy1.count(), 0); |
|
505 | QCOMPARE(setSpy1.count(), 0); | |
510 | QCOMPARE(setSpy2.count(), 1); |
|
506 | QCOMPARE(setSpy2.count(), 1); | |
511 | QCOMPARE(seriesSpy.count(), 1); |
|
507 | QCOMPARE(seriesSpy.count(), 1); | |
512 | setSpyArg = setSpy2.takeFirst(); |
|
508 | setSpyArg = setSpy2.takeFirst(); | |
513 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); |
|
509 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); | |
514 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test1")) == 0); |
|
510 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test1")) == 0); | |
515 |
|
511 | |||
516 | seriesSpyArg = seriesSpy.takeFirst(); |
|
512 | seriesSpyArg = seriesSpy.takeFirst(); | |
517 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
513 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
518 |
|
514 | |||
519 | //==================================================================================== |
|
515 | //==================================================================================== | |
520 | // barset 2, category test2 |
|
516 | // barset 2, category test2 | |
521 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(240,180)); |
|
517 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(240,180)); | |
522 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
518 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
523 |
|
519 | |||
524 | QCOMPARE(setSpy1.count(), 0); |
|
520 | QCOMPARE(setSpy1.count(), 0); | |
525 | QCOMPARE(setSpy2.count(), 1); |
|
521 | QCOMPARE(setSpy2.count(), 1); | |
526 | QCOMPARE(seriesSpy.count(), 1); |
|
522 | QCOMPARE(seriesSpy.count(), 1); | |
527 | setSpyArg = setSpy2.takeFirst(); |
|
523 | setSpyArg = setSpy2.takeFirst(); | |
528 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); |
|
524 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); | |
529 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test2")) == 0); |
|
525 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test2")) == 0); | |
530 |
|
526 | |||
531 | seriesSpyArg = seriesSpy.takeFirst(); |
|
527 | seriesSpyArg = seriesSpy.takeFirst(); | |
532 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
528 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
533 |
|
529 | |||
534 | //==================================================================================== |
|
530 | //==================================================================================== | |
535 | // barset 2, category test3 |
|
531 | // barset 2, category test3 | |
536 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(335,180)); |
|
532 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(335,180)); | |
537 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
533 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
538 |
|
534 | |||
539 | QCOMPARE(setSpy1.count(), 0); |
|
535 | QCOMPARE(setSpy1.count(), 0); | |
540 | QCOMPARE(setSpy2.count(), 1); |
|
536 | QCOMPARE(setSpy2.count(), 1); | |
541 | QCOMPARE(seriesSpy.count(), 1); |
|
537 | QCOMPARE(seriesSpy.count(), 1); | |
542 | setSpyArg = setSpy2.takeFirst(); |
|
538 | setSpyArg = setSpy2.takeFirst(); | |
543 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); |
|
539 | QVERIFY(setSpyArg.at(0).type() == QVariant::String); | |
544 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test3")) == 0); |
|
540 | QVERIFY(setSpyArg.at(0).toString().compare(QString("test3")) == 0); | |
545 |
|
541 | |||
546 | seriesSpyArg = seriesSpy.takeFirst(); |
|
542 | seriesSpyArg = seriesSpy.takeFirst(); | |
547 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
543 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
548 |
|
544 | |||
549 | //==================================================================================== |
|
545 | //==================================================================================== | |
550 | // no event cases |
|
546 | // no event cases | |
551 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(1,1)); // Outside of both sets |
|
547 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(1,1)); // Outside of both sets | |
552 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(1,1)); // Right mouse button outside and inside sets |
|
548 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(1,1)); // Right mouse button outside and inside sets | |
553 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(105,180)); // barset 1, category test1 |
|
549 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(105,180)); // barset 1, category test1 | |
554 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(200,180)); // barset 1, category test2 |
|
550 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(200,180)); // barset 1, category test2 | |
555 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(295,180)); // barset 1, category test3 |
|
551 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(295,180)); // barset 1, category test3 | |
556 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(145,180)); // barset 2, category test1 |
|
552 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(145,180)); // barset 2, category test1 | |
557 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(240,180)); // barset 2, category test2 |
|
553 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(240,180)); // barset 2, category test2 | |
558 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(335,180)); // barset 2, category test3 |
|
554 | QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(335,180)); // barset 2, category test3 | |
559 |
|
555 | |||
560 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
556 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
561 | QCOMPARE(setSpy1.count(), 0); |
|
557 | QCOMPARE(setSpy1.count(), 0); | |
562 | QCOMPARE(setSpy2.count(), 0); |
|
558 | QCOMPARE(setSpy2.count(), 0); | |
563 | QCOMPARE(seriesSpy.count(), 0); |
|
559 | QCOMPARE(seriesSpy.count(), 0); | |
564 | } |
|
560 | } | |
565 |
|
561 | |||
566 | void tst_QBarSeries::mousehovered_data() |
|
562 | void tst_QBarSeries::mousehovered_data() | |
567 | { |
|
563 | { | |
568 |
|
564 | |||
569 | } |
|
565 | } | |
570 |
|
566 | |||
571 | void tst_QBarSeries::mousehovered() |
|
567 | void tst_QBarSeries::mousehovered() | |
572 | { |
|
568 | { | |
573 | QBarSeries* series = new QBarSeries(); |
|
569 | QBarSeries* series = new QBarSeries(); | |
574 | QBarCategories categories; |
|
570 | QBarCategories categories; | |
575 | categories << "test1" << "test2" << "test3"; |
|
571 | categories << "test1" << "test2" << "test3"; | |
576 | series->setCategories(categories); |
|
572 | series->setCategories(categories); | |
577 |
|
573 | |||
578 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
574 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
579 | *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10); |
|
575 | *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10); | |
580 | series->append(set1); |
|
576 | series->append(set1); | |
581 |
|
577 | |||
582 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
578 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
583 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); |
|
579 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
584 | series->append(set2); |
|
580 | series->append(set2); | |
585 |
|
581 | |||
586 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); |
|
582 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); | |
587 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); |
|
583 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); | |
588 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); |
|
584 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); | |
589 |
|
585 | |||
590 | QChartView view(new QChart()); |
|
586 | QChartView view(new QChart()); | |
591 | view.resize(400,300); |
|
587 | view.resize(400,300); | |
592 | view.chart()->addSeries(series); |
|
588 | view.chart()->addSeries(series); | |
593 | view.show(); |
|
589 | view.show(); | |
594 | QTest::qWaitForWindowShown(&view); |
|
590 | QTest::qWaitForWindowShown(&view); | |
595 |
|
591 | |||
596 | //======================================================================= |
|
592 | //======================================================================= | |
597 | // move mouse to left border |
|
593 | // move mouse to left border | |
598 | QTest::mouseMove(view.viewport(), QPoint(0, 180)); |
|
594 | QTest::mouseMove(view.viewport(), QPoint(0, 180)); | |
599 |
|
595 | |||
600 | QVERIFY(setSpy1.count() == 0); |
|
596 | QVERIFY(setSpy1.count() == 0); | |
601 | QVERIFY(setSpy2.count() == 0); |
|
597 | QVERIFY(setSpy2.count() == 0); | |
602 | QVERIFY(seriesSpy.count() == 0); |
|
598 | QVERIFY(seriesSpy.count() == 0); | |
603 |
|
599 | |||
604 | //======================================================================= |
|
600 | //======================================================================= | |
605 | // move mouse on top of set1 |
|
601 | // move mouse on top of set1 | |
606 | QTest::mouseMove(view.viewport(), QPoint(105,180)); |
|
602 | QTest::mouseMove(view.viewport(), QPoint(105,180)); | |
607 |
|
603 | |||
608 | QVERIFY(setSpy1.count() == 1); |
|
604 | QVERIFY(setSpy1.count() == 1); | |
609 | QVERIFY(setSpy2.count() == 0); |
|
605 | QVERIFY(setSpy2.count() == 0); | |
610 | QVERIFY(seriesSpy.count() == 1); |
|
606 | QVERIFY(seriesSpy.count() == 1); | |
611 |
|
607 | |||
612 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
608 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); | |
613 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
609 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
614 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
610 | QVERIFY(setSpyArg.at(0).toBool() == true); | |
615 |
|
611 | |||
616 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
612 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
617 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
613 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
618 |
|
614 | |||
619 | //======================================================================= |
|
615 | //======================================================================= | |
620 | // move mouse from top of set1 to top of set2 |
|
616 | // move mouse from top of set1 to top of set2 | |
621 | QTest::mouseMove(view.viewport(), QPoint(145,180)); |
|
617 | QTest::mouseMove(view.viewport(), QPoint(145,180)); | |
622 |
|
618 | |||
623 | QVERIFY(setSpy1.count() == 1); |
|
619 | QVERIFY(setSpy1.count() == 1); | |
624 | QVERIFY(setSpy2.count() == 1); |
|
620 | QVERIFY(setSpy2.count() == 1); | |
625 | QVERIFY(seriesSpy.count() == 2); |
|
621 | QVERIFY(seriesSpy.count() == 2); | |
626 |
|
622 | |||
627 | // should leave set1 |
|
623 | // should leave set1 | |
628 | setSpyArg = setSpy1.takeFirst(); |
|
624 | setSpyArg = setSpy1.takeFirst(); | |
629 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
625 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
630 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
626 | QVERIFY(setSpyArg.at(0).toBool() == false); | |
631 |
|
627 | |||
632 | // should enter set2 |
|
628 | // should enter set2 | |
633 | setSpyArg = setSpy2.takeFirst(); |
|
629 | setSpyArg = setSpy2.takeFirst(); | |
634 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
630 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
635 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
631 | QVERIFY(setSpyArg.at(0).toBool() == true); | |
636 |
|
632 | |||
637 | // should leave set1 |
|
633 | // should leave set1 | |
638 | seriesSpyArg = seriesSpy.takeFirst(); |
|
634 | seriesSpyArg = seriesSpy.takeFirst(); | |
639 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
635 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
640 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
636 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
641 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
637 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
642 |
|
638 | |||
643 | // should enter set2 |
|
639 | // should enter set2 | |
644 | seriesSpyArg = seriesSpy.takeFirst(); |
|
640 | seriesSpyArg = seriesSpy.takeFirst(); | |
645 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
641 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
646 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
642 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
647 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
643 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
648 |
|
644 | |||
649 | //======================================================================= |
|
645 | //======================================================================= | |
650 | // move mouse from top of set2 to background |
|
646 | // move mouse from top of set2 to background | |
651 | QTest::mouseMove(view.viewport(), QPoint(175,180)); |
|
647 | QTest::mouseMove(view.viewport(), QPoint(175,180)); | |
652 |
|
648 | |||
653 | QVERIFY(setSpy1.count() == 0); |
|
649 | QVERIFY(setSpy1.count() == 0); | |
654 | QVERIFY(setSpy2.count() == 1); |
|
650 | QVERIFY(setSpy2.count() == 1); | |
655 | QVERIFY(seriesSpy.count() == 1); |
|
651 | QVERIFY(seriesSpy.count() == 1); | |
656 |
|
652 | |||
657 | // should leave set2 (event via set) |
|
653 | // should leave set2 (event via set) | |
658 | setSpyArg = setSpy2.takeFirst(); |
|
654 | setSpyArg = setSpy2.takeFirst(); | |
659 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
655 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
660 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
656 | QVERIFY(setSpyArg.at(0).toBool() == false); | |
661 |
|
657 | |||
662 | // should leave set2 (event via series) |
|
658 | // should leave set2 (event via series) | |
663 | seriesSpyArg = seriesSpy.takeFirst(); |
|
659 | seriesSpyArg = seriesSpy.takeFirst(); | |
664 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
660 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
665 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
661 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
666 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
662 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
667 | } |
|
663 | } | |
668 |
|
664 | |||
669 | /* |
|
665 | /* | |
670 | bool setModel(QAbstractItemModel *model); |
|
666 | bool setModel(QAbstractItemModel *model); | |
671 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
667 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
672 | void setModelMappingRange(int first, int count = -1); |
|
668 | void setModelMappingRange(int first, int count = -1); | |
673 | */ |
|
669 | */ | |
674 | QTEST_MAIN(tst_QBarSeries) |
|
670 | QTEST_MAIN(tst_QBarSeries) | |
675 |
|
671 | |||
676 | #include "tst_qbarseries.moc" |
|
672 | #include "tst_qbarseries.moc" | |
677 |
|
673 |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now