@@ -1,58 +1,54 | |||||
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 "bar_p.h" |
|
21 | #include "bar_p.h" | |
22 | #include <QDebug> |
|
22 | #include <QDebug> | |
23 | #include <QPainter> |
|
23 | #include <QPainter> | |
24 | #include <QGraphicsSceneEvent> |
|
24 | #include <QGraphicsSceneEvent> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | Bar::Bar(QString category, QGraphicsItem *parent) |
|
28 | Bar::Bar(QString category, QGraphicsItem *parent) | |
29 | : QGraphicsRectItem(parent), |
|
29 | : QGraphicsRectItem(parent), | |
30 | m_category(category) |
|
30 | m_category(category) | |
31 | { |
|
31 | { | |
32 | setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); |
|
32 | setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); | |
33 | setAcceptHoverEvents(true); |
|
33 | setAcceptHoverEvents(true); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
36 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
37 | { |
|
37 | { | |
38 | if (event->button() == Qt::LeftButton) { |
|
38 | emit clicked(m_category, event->button()); | |
39 | emit clicked(m_category); |
|
|||
40 | } else if (event->button() == Qt::RightButton) { |
|
|||
41 | emit rightClicked(m_category); |
|
|||
42 | } |
|
|||
43 | } |
|
39 | } | |
44 |
|
40 | |||
45 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
41 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
46 | { |
|
42 | { | |
47 | emit hoverEntered(event->lastScreenPos()); |
|
43 | emit hoverEntered(event->lastScreenPos()); | |
48 | } |
|
44 | } | |
49 |
|
45 | |||
50 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
46 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
51 | { |
|
47 | { | |
52 | Q_UNUSED(event) |
|
48 | Q_UNUSED(event) | |
53 | emit hoverLeaved(); |
|
49 | emit hoverLeaved(); | |
54 | } |
|
50 | } | |
55 |
|
51 | |||
56 | #include "moc_bar_p.cpp" |
|
52 | #include "moc_bar_p.cpp" | |
57 |
|
53 | |||
58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
54 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,52 | |||||
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 BAR_H |
|
21 | #ifndef BAR_H | |
22 | #define BAR_H |
|
22 | #define BAR_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include <QGraphicsRectItem> |
|
25 | #include <QGraphicsRectItem> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | // Single visual bar item of chart |
|
29 | // Single visual bar item of chart | |
30 | class Bar : public QObject, public QGraphicsRectItem |
|
30 | class Bar : public QObject, public QGraphicsRectItem | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | public: |
|
33 | public: | |
34 | Bar(QString category, QGraphicsItem *parent = 0); |
|
34 | Bar(QString category, QGraphicsItem *parent = 0); | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
37 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
38 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
38 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
39 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
|
39 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); | |
40 |
|
40 | |||
41 | Q_SIGNALS: |
|
41 | Q_SIGNALS: | |
42 | void clicked(QString category); |
|
42 | void clicked(QString category, Qt::MouseButtons button); | |
43 | void rightClicked(QString category); |
|
|||
44 | void hoverEntered(QPoint pos); |
|
43 | void hoverEntered(QPoint pos); | |
45 | void hoverLeaved(); |
|
44 | void hoverLeaved(); | |
46 |
|
45 | |||
47 | private: |
|
46 | private: | |
48 | QString m_category; |
|
47 | QString m_category; | |
49 | }; |
|
48 | }; | |
50 |
|
49 | |||
51 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
52 |
|
51 | |||
53 | #endif // BAR_H |
|
52 | #endif // BAR_H |
@@ -1,235 +1,234 | |||||
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 "barvalue_p.h" |
|
23 | #include "barvalue_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qchart.h" |
|
26 | #include "qchart.h" | |
27 | #include "qchartaxis.h" |
|
27 | #include "qchartaxis.h" | |
28 | #include "qchartaxiscategories.h" |
|
28 | #include "qchartaxiscategories.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartanimator_p.h" |
|
30 | #include "chartanimator_p.h" | |
31 | #include "chartdataset_p.h" |
|
31 | #include "chartdataset_p.h" | |
32 | #include <QDebug> |
|
32 | #include <QDebug> | |
33 | #include <QToolTip> |
|
33 | #include <QToolTip> | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
37 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
38 | ChartItem(presenter), |
|
38 | ChartItem(presenter), | |
39 | m_layoutSet(false), |
|
39 | m_layoutSet(false), | |
40 | m_series(series) |
|
40 | m_series(series) | |
41 | { |
|
41 | { | |
42 | connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString))); |
|
42 | connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString))); | |
43 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
43 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
44 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); |
|
44 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); | |
45 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); |
|
45 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); | |
46 | setZValue(ChartPresenter::BarSeriesZValue); |
|
46 | setZValue(ChartPresenter::BarSeriesZValue); | |
47 | dataChanged(); |
|
47 | dataChanged(); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | BarChartItem::~BarChartItem() |
|
50 | BarChartItem::~BarChartItem() | |
51 | { |
|
51 | { | |
52 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
52 | disconnect(this,SLOT(showToolTip(QPoint,QString))); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
55 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
56 | { |
|
56 | { | |
57 | if (!m_layoutSet) { |
|
57 | if (!m_layoutSet) { | |
58 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; |
|
58 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; | |
59 | return; |
|
59 | return; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | foreach(QGraphicsItem* i, childItems()) |
|
62 | foreach(QGraphicsItem* i, childItems()) | |
63 | i->paint(painter,option,widget); |
|
63 | i->paint(painter,option,widget); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QRectF BarChartItem::boundingRect() const |
|
66 | QRectF BarChartItem::boundingRect() const | |
67 | { |
|
67 | { | |
68 | return m_rect; |
|
68 | return m_rect; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void BarChartItem::dataChanged() |
|
71 | void BarChartItem::dataChanged() | |
72 | { |
|
72 | { | |
73 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
73 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
74 | // Delete old bars |
|
74 | // Delete old bars | |
75 | foreach (QGraphicsItem *item, childItems()) |
|
75 | foreach (QGraphicsItem *item, childItems()) | |
76 | delete item; |
|
76 | delete item; | |
77 |
|
77 | |||
78 | m_bars.clear(); |
|
78 | m_bars.clear(); | |
79 | m_floatingValues.clear(); |
|
79 | m_floatingValues.clear(); | |
80 | m_layout.clear(); |
|
80 | m_layout.clear(); | |
81 |
|
81 | |||
82 | // Create new graphic items for bars |
|
82 | // Create new graphic items for bars | |
83 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
83 | for (int c = 0; c < m_series->categoryCount(); c++) { | |
84 | QString category = m_series->categoryName(c); |
|
84 | QString category = m_series->categoryName(c); | |
85 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
85 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
86 | QBarSet *set = m_series->barsetAt(s); |
|
86 | QBarSet *set = m_series->barsetAt(s); | |
87 | Bar *bar = new Bar(category,this); |
|
87 | Bar *bar = new Bar(category,this); | |
88 | childItems().append(bar); |
|
88 | childItems().append(bar); | |
89 | m_bars.append(bar); |
|
89 | m_bars.append(bar); | |
90 | connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString))); |
|
90 | connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); | |
91 | connect(bar, SIGNAL(rightClicked(QString)), set, SIGNAL(rightClicked(QString))); |
|
|||
92 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); |
|
91 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); | |
93 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); |
|
92 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); | |
94 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
93 | m_layout.append(QRectF(0, 0, 0, 0)); | |
95 | } |
|
94 | } | |
96 | } |
|
95 | } | |
97 |
|
96 | |||
98 | // Create floating values |
|
97 | // Create floating values | |
99 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
98 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
100 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
99 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
101 | QBarSet *set = m_series->barsetAt(s); |
|
100 | QBarSet *set = m_series->barsetAt(s); | |
102 | BarValue *value = new BarValue(*set, this); |
|
101 | BarValue *value = new BarValue(*set, this); | |
103 | childItems().append(value); |
|
102 | childItems().append(value); | |
104 | m_floatingValues.append(value); |
|
103 | m_floatingValues.append(value); | |
105 | connect(set, SIGNAL(toggleFloatingValues()), value, SLOT(toggleVisible())); |
|
104 | connect(set, SIGNAL(toggleFloatingValues()), value, SLOT(toggleVisible())); | |
106 | } |
|
105 | } | |
107 | } |
|
106 | } | |
108 | } |
|
107 | } | |
109 |
|
108 | |||
110 | QVector<QRectF> BarChartItem::calculateLayout() |
|
109 | QVector<QRectF> BarChartItem::calculateLayout() | |
111 | { |
|
110 | { | |
112 | QVector<QRectF> layout; |
|
111 | QVector<QRectF> layout; | |
113 |
|
112 | |||
114 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
113 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
115 | qreal categoryCount = m_series->categoryCount(); |
|
114 | qreal categoryCount = m_series->categoryCount(); | |
116 | qreal setCount = m_series->barsetCount(); |
|
115 | qreal setCount = m_series->barsetCount(); | |
117 |
|
116 | |||
118 | qreal width = geometry().width(); |
|
117 | qreal width = geometry().width(); | |
119 | qreal height = geometry().height(); |
|
118 | qreal height = geometry().height(); | |
120 |
|
119 | |||
121 | qreal max = m_series->max(); |
|
120 | qreal max = m_series->max(); | |
122 |
|
121 | |||
123 | // Domain: |
|
122 | // Domain: | |
124 | if (m_domainMaxY > max) { |
|
123 | if (m_domainMaxY > max) { | |
125 | max = m_domainMaxY; |
|
124 | max = m_domainMaxY; | |
126 | } |
|
125 | } | |
127 |
|
126 | |||
128 | qreal scale = (height / max); |
|
127 | qreal scale = (height / max); | |
129 | qreal categoryWidth = width / categoryCount; |
|
128 | qreal categoryWidth = width / categoryCount; | |
130 | qreal barWidth = categoryWidth / (setCount+1); |
|
129 | qreal barWidth = categoryWidth / (setCount+1); | |
131 |
|
130 | |||
132 | int itemIndex(0); |
|
131 | int itemIndex(0); | |
133 | for (int category = 0; category < categoryCount; category++) { |
|
132 | for (int category = 0; category < categoryCount; category++) { | |
134 | qreal xPos = categoryWidth * category + barWidth / 2; |
|
133 | qreal xPos = categoryWidth * category + barWidth / 2; | |
135 | qreal yPos = height; |
|
134 | qreal yPos = height; | |
136 | for (int set = 0; set < setCount; set++) { |
|
135 | for (int set = 0; set < setCount; set++) { | |
137 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
136 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
138 | Bar* bar = m_bars.at(itemIndex); |
|
137 | Bar* bar = m_bars.at(itemIndex); | |
139 |
|
138 | |||
140 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
139 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
141 | layout.append(rect); |
|
140 | layout.append(rect); | |
142 | bar->setPen(m_series->barsetAt(set)->pen()); |
|
141 | bar->setPen(m_series->barsetAt(set)->pen()); | |
143 | bar->setBrush(m_series->barsetAt(set)->brush()); |
|
142 | bar->setBrush(m_series->barsetAt(set)->brush()); | |
144 | itemIndex++; |
|
143 | itemIndex++; | |
145 | xPos += barWidth; |
|
144 | xPos += barWidth; | |
146 | } |
|
145 | } | |
147 | } |
|
146 | } | |
148 |
|
147 | |||
149 | // Position floating values |
|
148 | // Position floating values | |
150 | itemIndex = 0; |
|
149 | itemIndex = 0; | |
151 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
150 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
152 | qreal xPos = categoryWidth * category + barWidth; |
|
151 | qreal xPos = categoryWidth * category + barWidth; | |
153 | qreal yPos = height; |
|
152 | qreal yPos = height; | |
154 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
153 | for (int set=0; set < m_series->barsetCount(); set++) { | |
155 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
154 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
156 | BarValue* value = m_floatingValues.at(itemIndex); |
|
155 | BarValue* value = m_floatingValues.at(itemIndex); | |
157 |
|
156 | |||
158 | QBarSet* barSet = m_series->barsetAt(set); |
|
157 | QBarSet* barSet = m_series->barsetAt(set); | |
159 |
|
158 | |||
160 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { |
|
159 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { | |
161 | value->setText(QString::number(m_series->valueAt(set, category))); |
|
160 | value->setText(QString::number(m_series->valueAt(set, category))); | |
162 | } else { |
|
161 | } else { | |
163 | value->setText(QString("")); |
|
162 | value->setText(QString("")); | |
164 | } |
|
163 | } | |
165 |
|
164 | |||
166 | value->setPos(xPos, yPos-barHeight / 2); |
|
165 | value->setPos(xPos, yPos-barHeight / 2); | |
167 | value->setPen(barSet->floatingValuePen()); |
|
166 | value->setPen(barSet->floatingValuePen()); | |
168 |
|
167 | |||
169 | itemIndex++; |
|
168 | itemIndex++; | |
170 | xPos += barWidth; |
|
169 | xPos += barWidth; | |
171 | } |
|
170 | } | |
172 | } |
|
171 | } | |
173 |
|
172 | |||
174 | return layout; |
|
173 | return layout; | |
175 | } |
|
174 | } | |
176 |
|
175 | |||
177 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
176 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
178 | { |
|
177 | { | |
179 | if (animator()) |
|
178 | if (animator()) | |
180 | animator()->updateLayout(this, m_layout, layout); |
|
179 | animator()->updateLayout(this, m_layout, layout); | |
181 | else |
|
180 | else | |
182 | setLayout(layout); |
|
181 | setLayout(layout); | |
183 | } |
|
182 | } | |
184 |
|
183 | |||
185 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
184 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
186 | { |
|
185 | { | |
187 | m_layout = layout; |
|
186 | m_layout = layout; | |
188 |
|
187 | |||
189 | for (int i=0; i < m_bars.count(); i++) |
|
188 | for (int i=0; i < m_bars.count(); i++) | |
190 | m_bars.at(i)->setRect(layout.at(i)); |
|
189 | m_bars.at(i)->setRect(layout.at(i)); | |
191 |
|
190 | |||
192 | update(); |
|
191 | update(); | |
193 | } |
|
192 | } | |
194 |
|
193 | |||
195 | //handlers |
|
194 | //handlers | |
196 |
|
195 | |||
197 | void BarChartItem::handleModelChanged(int index) |
|
196 | void BarChartItem::handleModelChanged(int index) | |
198 | { |
|
197 | { | |
199 | Q_UNUSED(index) |
|
198 | Q_UNUSED(index) | |
200 | dataChanged(); |
|
199 | dataChanged(); | |
201 | } |
|
200 | } | |
202 |
|
201 | |||
203 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
202 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
204 | { |
|
203 | { | |
205 | m_domainMinX = minX; |
|
204 | m_domainMinX = minX; | |
206 | m_domainMaxX = maxX; |
|
205 | m_domainMaxX = maxX; | |
207 | m_domainMinY = minY; |
|
206 | m_domainMinY = minY; | |
208 | m_domainMaxY = maxY; |
|
207 | m_domainMaxY = maxY; | |
209 | handleLayoutChanged(); |
|
208 | handleLayoutChanged(); | |
210 | } |
|
209 | } | |
211 |
|
210 | |||
212 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
211 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
213 | { |
|
212 | { | |
214 | m_rect = rect; |
|
213 | m_rect = rect; | |
215 | handleLayoutChanged(); |
|
214 | handleLayoutChanged(); | |
216 | m_layoutSet = true; |
|
215 | m_layoutSet = true; | |
217 | setPos(rect.topLeft()); |
|
216 | setPos(rect.topLeft()); | |
218 | } |
|
217 | } | |
219 |
|
218 | |||
220 | void BarChartItem::handleLayoutChanged() |
|
219 | void BarChartItem::handleLayoutChanged() | |
221 | { |
|
220 | { | |
222 | QVector<QRectF> layout = calculateLayout(); |
|
221 | QVector<QRectF> layout = calculateLayout(); | |
223 | applyLayout(layout); |
|
222 | applyLayout(layout); | |
224 | update(); |
|
223 | update(); | |
225 | } |
|
224 | } | |
226 |
|
225 | |||
227 | void BarChartItem::showToolTip(QPoint pos, QString tip) |
|
226 | void BarChartItem::showToolTip(QPoint pos, QString tip) | |
228 | { |
|
227 | { | |
229 | // TODO: cool tooltip instead of default |
|
228 | // TODO: cool tooltip instead of default | |
230 | QToolTip::showText(pos, tip); |
|
229 | QToolTip::showText(pos, tip); | |
231 | } |
|
230 | } | |
232 |
|
231 | |||
233 | #include "moc_barchartitem_p.cpp" |
|
232 | #include "moc_barchartitem_p.cpp" | |
234 |
|
233 | |||
235 | QTCOMMERCIALCHART_END_NAMESPACE |
|
234 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,407 +1,396 | |||||
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 <QDebug> |
|
21 | #include <QDebug> | |
22 | #include "qbarseries.h" |
|
22 | #include "qbarseries.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "barchartmodel_p.h" |
|
24 | #include "barchartmodel_p.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \class QBarSeries |
|
29 | \class QBarSeries | |
30 | \brief part of QtCommercial chart API. |
|
30 | \brief part of QtCommercial chart API. | |
31 |
|
31 | |||
32 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
32 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
33 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
33 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
34 | by QStringList. |
|
34 | by QStringList. | |
35 |
|
35 | |||
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
38 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \fn virtual QSeriesType QBarSeries::type() const |
|
42 | \fn virtual QSeriesType QBarSeries::type() const | |
43 | \brief Returns type of series. |
|
43 | \brief Returns type of series. | |
44 | \sa QSeries, QSeriesType |
|
44 | \sa QSeries, QSeriesType | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
48 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
49 | \brief \internal \a pos \a tip |
|
49 | \brief \internal \a pos \a tip | |
50 | */ |
|
50 | */ | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
53 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
53 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
54 | QBarSeries is QObject which is a child of a \a parent. |
|
54 | QBarSeries is QObject which is a child of a \a parent. | |
55 | */ |
|
55 | */ | |
56 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), |
|
56 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), | |
57 | m_internalModel(new BarChartModel(categories, this)) |
|
57 | m_internalModel(new BarChartModel(categories, this)) | |
58 | { |
|
58 | { | |
59 | m_model = 0; |
|
59 | m_model = 0; | |
60 | m_mapCategories = -1; |
|
60 | m_mapCategories = -1; | |
61 | m_mapBarBottom = -1; |
|
61 | m_mapBarBottom = -1; | |
62 | m_mapBarTop = -1; |
|
62 | m_mapBarTop = -1; | |
63 | m_mapFirst = 0; |
|
63 | m_mapFirst = 0; | |
64 | m_mapCount = 0; |
|
64 | m_mapCount = 0; | |
65 | m_mapOrientation = Qt::Vertical; |
|
65 | m_mapOrientation = Qt::Vertical; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | Adds a set of bars to series. Takes ownership of \a set. |
|
69 | Adds a set of bars to series. Takes ownership of \a set. | |
70 |
Connects the clicked(QString |
|
70 | Connects the clicked(QString, Qt::MouseButtons) signal | |
71 | of \a set to this series |
|
71 | of \a set to this series | |
72 | */ |
|
72 | */ | |
73 | void QBarSeries::appendBarSet(QBarSet *set) |
|
73 | void QBarSeries::appendBarSet(QBarSet *set) | |
74 | { |
|
74 | { | |
75 | m_internalModel->appendBarSet(set); |
|
75 | m_internalModel->appendBarSet(set); | |
76 | connect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); |
|
76 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
77 | connect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); |
|
|||
78 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
77 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
79 | emit updatedBars(); |
|
78 | emit updatedBars(); | |
80 | } |
|
79 | } | |
81 |
|
80 | |||
82 | /*! |
|
81 | /*! | |
83 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
82 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
84 |
Disconnects the clicked(QString |
|
83 | Disconnects the clicked(QString, Qt::MouseButtons) signal | |
85 | of \a set from this series |
|
84 | of \a set from this series | |
86 | */ |
|
85 | */ | |
87 | void QBarSeries::removeBarSet(QBarSet *set) |
|
86 | void QBarSeries::removeBarSet(QBarSet *set) | |
88 | { |
|
87 | { | |
89 | disconnect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); |
|
88 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
90 | disconnect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); |
|
|||
91 | m_internalModel->removeBarSet(set); |
|
89 | m_internalModel->removeBarSet(set); | |
92 | emit updatedBars(); |
|
90 | emit updatedBars(); | |
93 | } |
|
91 | } | |
94 |
|
92 | |||
95 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
93 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
96 | { |
|
94 | { | |
97 | m_internalModel->insertBarSet(i, set); |
|
95 | m_internalModel->insertBarSet(i, set); | |
98 | // emit barsetChanged(); |
|
96 | // emit barsetChanged(); | |
99 | } |
|
97 | } | |
100 |
|
98 | |||
101 | void QBarSeries::insertCategory(int i, QString category) |
|
99 | void QBarSeries::insertCategory(int i, QString category) | |
102 | { |
|
100 | { | |
103 | m_internalModel->insertCategory(i, category); |
|
101 | m_internalModel->insertCategory(i, category); | |
104 | } |
|
102 | } | |
105 |
|
103 | |||
106 | void QBarSeries::removeCategory(int i) |
|
104 | void QBarSeries::removeCategory(int i) | |
107 | { |
|
105 | { | |
108 | m_internalModel->removeCategory(i); |
|
106 | m_internalModel->removeCategory(i); | |
109 | } |
|
107 | } | |
110 |
|
108 | |||
111 | /*! |
|
109 | /*! | |
112 | Returns number of sets in series. |
|
110 | Returns number of sets in series. | |
113 | */ |
|
111 | */ | |
114 | int QBarSeries::barsetCount() const |
|
112 | int QBarSeries::barsetCount() const | |
115 | { |
|
113 | { | |
116 | // if(m_model) |
|
114 | // if(m_model) | |
117 | // return m_mapBarTop - m_mapBarBottom; |
|
115 | // return m_mapBarTop - m_mapBarBottom; | |
118 | // else |
|
116 | // else | |
119 | return m_internalModel->barsetCount(); |
|
117 | return m_internalModel->barsetCount(); | |
120 | } |
|
118 | } | |
121 |
|
119 | |||
122 | /*! |
|
120 | /*! | |
123 | Returns number of categories in series |
|
121 | Returns number of categories in series | |
124 | */ |
|
122 | */ | |
125 | int QBarSeries::categoryCount() const |
|
123 | int QBarSeries::categoryCount() const | |
126 | { |
|
124 | { | |
127 | return m_internalModel->categoryCount(); |
|
125 | return m_internalModel->categoryCount(); | |
128 | } |
|
126 | } | |
129 |
|
127 | |||
130 | /*! |
|
128 | /*! | |
131 | Returns a list of sets in series. Keeps ownership of sets. |
|
129 | Returns a list of sets in series. Keeps ownership of sets. | |
132 | */ |
|
130 | */ | |
133 | QList<QBarSet*> QBarSeries::barSets() const |
|
131 | QList<QBarSet*> QBarSeries::barSets() const | |
134 | { |
|
132 | { | |
135 | return m_internalModel->barSets(); |
|
133 | return m_internalModel->barSets(); | |
136 | } |
|
134 | } | |
137 |
|
135 | |||
138 | /*! |
|
136 | /*! | |
139 | \internal \a index |
|
137 | \internal \a index | |
140 | */ |
|
138 | */ | |
141 | QBarSet* QBarSeries::barsetAt(int index) |
|
139 | QBarSet* QBarSeries::barsetAt(int index) | |
142 | { |
|
140 | { | |
143 | return m_internalModel->barsetAt(index); |
|
141 | return m_internalModel->barsetAt(index); | |
144 | } |
|
142 | } | |
145 |
|
143 | |||
146 | /*! |
|
144 | /*! | |
147 | \internal \a category |
|
145 | \internal \a category | |
148 | */ |
|
146 | */ | |
149 | QString QBarSeries::categoryName(int category) |
|
147 | QString QBarSeries::categoryName(int category) | |
150 | { |
|
148 | { | |
151 | return m_internalModel->categoryName(category); |
|
149 | return m_internalModel->categoryName(category); | |
152 | } |
|
150 | } | |
153 |
|
151 | |||
154 | /*! |
|
152 | /*! | |
155 | Enables or disables tooltip depending on parameter \a enabled. |
|
153 | Enables or disables tooltip depending on parameter \a enabled. | |
156 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
154 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
157 | Calling without parameter \a enabled, enables the tooltip |
|
155 | Calling without parameter \a enabled, enables the tooltip | |
158 | */ |
|
156 | */ | |
159 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
157 | void QBarSeries::setToolTipEnabled(bool enabled) | |
160 | { |
|
158 | { | |
161 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
159 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
162 | if (enabled) { |
|
160 | if (enabled) { | |
163 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
161 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
164 | QBarSet *set = m_internalModel->barsetAt(i); |
|
162 | QBarSet *set = m_internalModel->barsetAt(i); | |
165 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
163 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
166 | } |
|
164 | } | |
167 | } else { |
|
165 | } else { | |
168 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
166 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
169 | QBarSet *set = m_internalModel->barsetAt(i); |
|
167 | QBarSet *set = m_internalModel->barsetAt(i); | |
170 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
168 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
171 | } |
|
169 | } | |
172 | } |
|
170 | } | |
173 | } |
|
171 | } | |
174 |
|
172 | |||
175 |
|
173 | |||
176 | /*! |
|
174 | /*! | |
177 | \internal \a category |
|
175 | \internal \a category | |
178 | */ |
|
176 | */ | |
179 | void QBarSeries::barsetClicked(QString category) |
|
177 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) | |
180 | { |
|
178 | { | |
181 | emit clicked(qobject_cast<QBarSet*>(sender()), category); |
|
179 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
182 | } |
|
180 | } | |
183 |
|
181 | |||
184 | /*! |
|
182 | /*! | |
185 | \internal \a category |
|
|||
186 | */ |
|
|||
187 | void QBarSeries::barsetRightClicked(QString category) |
|
|||
188 | { |
|
|||
189 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); |
|
|||
190 | } |
|
|||
191 |
|
||||
192 |
|
||||
193 | /*! |
|
|||
194 | \internal |
|
183 | \internal | |
195 | */ |
|
184 | */ | |
196 | qreal QBarSeries::min() |
|
185 | qreal QBarSeries::min() | |
197 | { |
|
186 | { | |
198 | return m_internalModel->min(); |
|
187 | return m_internalModel->min(); | |
199 | } |
|
188 | } | |
200 |
|
189 | |||
201 | /*! |
|
190 | /*! | |
202 | \internal |
|
191 | \internal | |
203 | */ |
|
192 | */ | |
204 | qreal QBarSeries::max() |
|
193 | qreal QBarSeries::max() | |
205 | { |
|
194 | { | |
206 | return m_internalModel->max(); |
|
195 | return m_internalModel->max(); | |
207 | } |
|
196 | } | |
208 |
|
197 | |||
209 | /*! |
|
198 | /*! | |
210 | \internal \a set \a category |
|
199 | \internal \a set \a category | |
211 | */ |
|
200 | */ | |
212 | qreal QBarSeries::valueAt(int set, int category) |
|
201 | qreal QBarSeries::valueAt(int set, int category) | |
213 | { |
|
202 | { | |
214 | return m_internalModel->valueAt(set, category); |
|
203 | return m_internalModel->valueAt(set, category); | |
215 | } |
|
204 | } | |
216 |
|
205 | |||
217 | /*! |
|
206 | /*! | |
218 | \internal \a set \a category |
|
207 | \internal \a set \a category | |
219 | */ |
|
208 | */ | |
220 | qreal QBarSeries::percentageAt(int set, int category) |
|
209 | qreal QBarSeries::percentageAt(int set, int category) | |
221 | { |
|
210 | { | |
222 | return m_internalModel->percentageAt(set, category); |
|
211 | return m_internalModel->percentageAt(set, category); | |
223 | } |
|
212 | } | |
224 |
|
213 | |||
225 | /*! |
|
214 | /*! | |
226 | \internal \a category |
|
215 | \internal \a category | |
227 | */ |
|
216 | */ | |
228 | qreal QBarSeries::categorySum(int category) |
|
217 | qreal QBarSeries::categorySum(int category) | |
229 | { |
|
218 | { | |
230 | return m_internalModel->categorySum(category); |
|
219 | return m_internalModel->categorySum(category); | |
231 | } |
|
220 | } | |
232 |
|
221 | |||
233 | /*! |
|
222 | /*! | |
234 | \internal |
|
223 | \internal | |
235 | */ |
|
224 | */ | |
236 | qreal QBarSeries::maxCategorySum() |
|
225 | qreal QBarSeries::maxCategorySum() | |
237 | { |
|
226 | { | |
238 | return m_internalModel->maxCategorySum(); |
|
227 | return m_internalModel->maxCategorySum(); | |
239 | } |
|
228 | } | |
240 |
|
229 | |||
241 | /*! |
|
230 | /*! | |
242 | \internal |
|
231 | \internal | |
243 | */ |
|
232 | */ | |
244 | BarChartModel& QBarSeries::model() |
|
233 | BarChartModel& QBarSeries::model() | |
245 | { |
|
234 | { | |
246 | return *m_internalModel; |
|
235 | return *m_internalModel; | |
247 | } |
|
236 | } | |
248 |
|
237 | |||
249 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
238 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
250 | { |
|
239 | { | |
251 | // disconnect signals from old model |
|
240 | // disconnect signals from old model | |
252 | if(m_model) |
|
241 | if(m_model) | |
253 | { |
|
242 | { | |
254 | disconnect(m_model, 0, this, 0); |
|
243 | disconnect(m_model, 0, this, 0); | |
255 | m_mapCategories = -1; |
|
244 | m_mapCategories = -1; | |
256 | m_mapBarBottom = -1; |
|
245 | m_mapBarBottom = -1; | |
257 | m_mapBarTop = -1; |
|
246 | m_mapBarTop = -1; | |
258 | m_mapFirst = 0; |
|
247 | m_mapFirst = 0; | |
259 | m_mapCount = 0; |
|
248 | m_mapCount = 0; | |
260 | m_mapOrientation = Qt::Vertical; |
|
249 | m_mapOrientation = Qt::Vertical; | |
261 | } |
|
250 | } | |
262 |
|
251 | |||
263 | // set new model |
|
252 | // set new model | |
264 | if(model) |
|
253 | if(model) | |
265 | { |
|
254 | { | |
266 | m_model = model; |
|
255 | m_model = model; | |
267 | return true; |
|
256 | return true; | |
268 | } |
|
257 | } | |
269 | else |
|
258 | else | |
270 | { |
|
259 | { | |
271 | m_model = 0; |
|
260 | m_model = 0; | |
272 | return false; |
|
261 | return false; | |
273 | } |
|
262 | } | |
274 | } |
|
263 | } | |
275 |
|
264 | |||
276 | // TODO |
|
265 | // TODO | |
277 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
266 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
278 | { |
|
267 | { | |
279 | if (!m_model) |
|
268 | if (!m_model) | |
280 | return; |
|
269 | return; | |
281 |
|
270 | |||
282 | m_mapCategories = categories; |
|
271 | m_mapCategories = categories; | |
283 | m_mapBarBottom = bottomBoundry; |
|
272 | m_mapBarBottom = bottomBoundry; | |
284 | m_mapBarTop = topBoundry; |
|
273 | m_mapBarTop = topBoundry; | |
285 | // m_mapFirst = 1; |
|
274 | // m_mapFirst = 1; | |
286 | m_mapOrientation = orientation; |
|
275 | m_mapOrientation = orientation; | |
287 |
|
276 | |||
288 | // connect the signals |
|
277 | // connect the signals | |
289 | if (m_mapOrientation == Qt::Vertical) { |
|
278 | if (m_mapOrientation == Qt::Vertical) { | |
290 | m_mapCount = m_model->rowCount() - m_mapFirst; |
|
279 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
291 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
280 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
292 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
281 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
293 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), |
|
282 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
294 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
283 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
295 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), |
|
284 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
296 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
285 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
297 | } else { |
|
286 | } else { | |
298 | m_mapCount = m_model->columnCount() - m_mapFirst; |
|
287 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
299 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
288 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
300 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
289 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
301 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), |
|
290 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
302 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
291 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
303 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), |
|
292 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
304 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
293 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
305 | } |
|
294 | } | |
306 |
|
295 | |||
307 |
|
296 | |||
308 | // create the initial bars |
|
297 | // create the initial bars | |
309 | delete m_internalModel; |
|
298 | delete m_internalModel; | |
310 | if (m_mapOrientation == Qt::Vertical) { |
|
299 | if (m_mapOrientation == Qt::Vertical) { | |
311 | QStringList categories; |
|
300 | QStringList categories; | |
312 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
301 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
313 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
302 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
314 | m_internalModel = new BarChartModel(categories, this); |
|
303 | m_internalModel = new BarChartModel(categories, this); | |
315 |
|
304 | |||
316 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
305 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
317 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
306 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
318 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
307 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
319 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
308 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
320 | appendBarSet(barSet); |
|
309 | appendBarSet(barSet); | |
321 | } |
|
310 | } | |
322 | } else { |
|
311 | } else { | |
323 | QStringList categories; |
|
312 | QStringList categories; | |
324 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
313 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
325 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
314 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
326 | m_internalModel = new BarChartModel(categories, this); |
|
315 | m_internalModel = new BarChartModel(categories, this); | |
327 |
|
316 | |||
328 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
317 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
329 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
318 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
330 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
319 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
331 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
320 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
332 | appendBarSet(barSet); |
|
321 | appendBarSet(barSet); | |
333 | } |
|
322 | } | |
334 | } |
|
323 | } | |
335 | } |
|
324 | } | |
336 |
|
325 | |||
337 | void QBarSeries::setModelMappingShift(int first, int count) |
|
326 | void QBarSeries::setModelMappingShift(int first, int count) | |
338 | { |
|
327 | { | |
339 | m_mapFirst = first; |
|
328 | m_mapFirst = first; | |
340 | m_mapCount = count; |
|
329 | m_mapCount = count; | |
341 | } |
|
330 | } | |
342 |
|
331 | |||
343 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
332 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
344 | { |
|
333 | { | |
345 | Q_UNUSED(bottomRight) |
|
334 | Q_UNUSED(bottomRight) | |
346 |
|
335 | |||
347 | if (m_mapOrientation == Qt::Vertical) |
|
336 | if (m_mapOrientation == Qt::Vertical) | |
348 | { |
|
337 | { | |
349 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
338 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
350 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) |
|
339 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
351 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
340 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
352 | } |
|
341 | } | |
353 | else |
|
342 | else | |
354 | { |
|
343 | { | |
355 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
344 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
356 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) |
|
345 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
357 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
346 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
358 | } |
|
347 | } | |
359 | } |
|
348 | } | |
360 |
|
349 | |||
361 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) |
|
350 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
362 | { |
|
351 | { | |
363 | if (m_mapOrientation == Qt::Vertical) { |
|
352 | if (m_mapOrientation == Qt::Vertical) { | |
364 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); |
|
353 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
365 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
354 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
366 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
355 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
367 | } |
|
356 | } | |
368 | } else { |
|
357 | } else { | |
369 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); |
|
358 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
370 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
359 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
371 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
360 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
372 | } |
|
361 | } | |
373 | } |
|
362 | } | |
374 | emit restructuredBar(1); |
|
363 | emit restructuredBar(1); | |
375 | } |
|
364 | } | |
376 |
|
365 | |||
377 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
366 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
378 | { |
|
367 | { | |
379 | Q_UNUSED(parent) |
|
368 | Q_UNUSED(parent) | |
380 | Q_UNUSED(end) |
|
369 | Q_UNUSED(end) | |
381 |
|
370 | |||
382 | removeCategory(start - m_mapFirst); |
|
371 | removeCategory(start - m_mapFirst); | |
383 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
372 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
384 | { |
|
373 | { | |
385 | barsetAt(i)->removeValue(start - m_mapFirst); |
|
374 | barsetAt(i)->removeValue(start - m_mapFirst); | |
386 | } |
|
375 | } | |
387 | emit restructuredBar(1); |
|
376 | emit restructuredBar(1); | |
388 | } |
|
377 | } | |
389 |
|
378 | |||
390 | void QBarSeries::barsetChanged() |
|
379 | void QBarSeries::barsetChanged() | |
391 | { |
|
380 | { | |
392 | emit updatedBars(); |
|
381 | emit updatedBars(); | |
393 | } |
|
382 | } | |
394 |
|
383 | |||
395 | QBarCategories QBarSeries::categories() const |
|
384 | QBarCategories QBarSeries::categories() const | |
396 | { |
|
385 | { | |
397 | QBarCategories categories; |
|
386 | QBarCategories categories; | |
398 | int count = m_internalModel->categoryCount(); |
|
387 | int count = m_internalModel->categoryCount(); | |
399 | for (int i=1; i <= count; i++) { |
|
388 | for (int i=1; i <= count; i++) { | |
400 | categories.insert(i, m_internalModel->categoryName(i - 1)); |
|
389 | categories.insert(i, m_internalModel->categoryName(i - 1)); | |
401 | } |
|
390 | } | |
402 | return categories; |
|
391 | return categories; | |
403 | } |
|
392 | } | |
404 |
|
393 | |||
405 | #include "moc_qbarseries.cpp" |
|
394 | #include "moc_qbarseries.cpp" | |
406 |
|
395 | |||
407 | QTCOMMERCIALCHART_END_NAMESPACE |
|
396 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,117 +1,114 | |||||
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 <qseries.h> |
|
24 | #include <qseries.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 BarChartModel; |
|
32 | class BarChartModel; | |
33 | class BarCategory; |
|
33 | class BarCategory; | |
34 |
|
34 | |||
35 | // Container for series |
|
35 | // Container for series | |
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries |
|
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | public: |
|
39 | public: | |
40 | QBarSeries(QStringList categories, QObject *parent = 0); |
|
40 | QBarSeries(QStringList categories, QObject *parent = 0); | |
41 |
|
41 | |||
42 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } |
|
42 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
43 |
|
43 | |||
44 | void appendBarSet(QBarSet *set); // Takes ownership of set |
|
44 | void appendBarSet(QBarSet *set); // Takes ownership of set | |
45 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
45 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
46 | void insertBarSet(int i, QBarSet *set); |
|
46 | void insertBarSet(int i, QBarSet *set); | |
47 | void insertCategory(int i, QString category); |
|
47 | void insertCategory(int i, QString category); | |
48 | void removeCategory(int i); |
|
48 | void removeCategory(int i); | |
49 | int barsetCount() const; |
|
49 | int barsetCount() const; | |
50 | int categoryCount() const; |
|
50 | int categoryCount() const; | |
51 | QList<QBarSet*> barSets() const; |
|
51 | QList<QBarSet*> barSets() const; | |
52 | QBarCategories categories() const; |
|
52 | QBarCategories categories() const; | |
53 |
|
53 | |||
54 | bool setModel(QAbstractItemModel *model); |
|
54 | bool setModel(QAbstractItemModel *model); | |
55 | QAbstractItemModel *modelExt() { return m_model; } |
|
55 | QAbstractItemModel *modelExt() { return m_model; } | |
56 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
56 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
57 | void setModelMappingShift(int first, int count); |
|
57 | void setModelMappingShift(int first, int count); | |
58 |
|
58 | |||
59 | public: |
|
59 | public: | |
60 | // TODO: Functions below this are not part of api and will be moved |
|
60 | // TODO: Functions below this are not part of api and will be moved | |
61 | // to private implementation, when we start using it |
|
61 | // to private implementation, when we start using it | |
62 | // TODO: TO PIMPL ---> |
|
62 | // TODO: TO PIMPL ---> | |
63 | QBarSet* barsetAt(int index); |
|
63 | QBarSet* barsetAt(int index); | |
64 | QString categoryName(int category); |
|
64 | QString categoryName(int category); | |
65 | qreal min(); |
|
65 | qreal min(); | |
66 | qreal max(); |
|
66 | qreal max(); | |
67 | qreal valueAt(int set, int category); |
|
67 | qreal valueAt(int set, int category); | |
68 | qreal percentageAt(int set, int category); |
|
68 | qreal percentageAt(int set, int category); | |
69 | qreal categorySum(int category); |
|
69 | qreal categorySum(int category); | |
70 | qreal maxCategorySum(); |
|
70 | qreal maxCategorySum(); | |
71 | BarChartModel& model(); |
|
71 | BarChartModel& model(); | |
72 | // <--- TO PIMPL |
|
72 | // <--- TO PIMPL | |
73 |
|
73 | |||
74 | Q_SIGNALS: |
|
74 | Q_SIGNALS: | |
75 | //void changed(int index); |
|
75 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals | |
76 | void clicked(QBarSet *barset, QString category); // Up to user of api, what to do with these signals |
|
|||
77 | void rightClicked(QBarSet *barset, QString category); |
|
|||
78 |
|
76 | |||
79 | // |
|
77 | // | |
80 | void updatedBars(); |
|
78 | void updatedBars(); | |
81 | void restructuredBar(int); |
|
79 | void restructuredBar(int); | |
82 |
|
80 | |||
83 | // TODO: internal signals, these to private implementation. |
|
81 | // TODO: internal signals, these to private implementation. | |
84 | // TODO: TO PIMPL ---> |
|
82 | // TODO: TO PIMPL ---> | |
85 | void showToolTip(QPoint pos, QString tip); |
|
83 | void showToolTip(QPoint pos, QString tip); | |
86 | // <--- TO PIMPL |
|
84 | // <--- TO PIMPL | |
87 |
|
85 | |||
88 | public Q_SLOTS: |
|
86 | public Q_SLOTS: | |
89 | void setToolTipEnabled(bool enabled = true); // enables tooltips |
|
87 | void setToolTipEnabled(bool enabled = true); // enables tooltips | |
90 |
|
88 | |||
91 | // TODO: TO PIMPL ---> |
|
89 | // TODO: TO PIMPL ---> | |
92 | void barsetClicked(QString category); |
|
90 | void barsetClicked(QString category, Qt::MouseButtons button); | |
93 | void barsetRightClicked(QString category); |
|
|||
94 | // <--- TO PIMPL |
|
91 | // <--- TO PIMPL | |
95 |
|
92 | |||
96 | private Q_SLOTS: |
|
93 | private Q_SLOTS: | |
97 | // slots for updating bars when data in model changes |
|
94 | // slots for updating bars when data in model changes | |
98 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
95 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
99 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
96 | void modelDataAdded(QModelIndex parent, int start, int end); | |
100 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
97 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
101 | void barsetChanged(); |
|
98 | void barsetChanged(); | |
102 |
|
99 | |||
103 | protected: |
|
100 | protected: | |
104 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. |
|
101 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |
105 |
|
102 | |||
106 | QAbstractItemModel* m_model; |
|
103 | QAbstractItemModel* m_model; | |
107 | int m_mapCategories; |
|
104 | int m_mapCategories; | |
108 | int m_mapBarBottom; |
|
105 | int m_mapBarBottom; | |
109 | int m_mapBarTop; |
|
106 | int m_mapBarTop; | |
110 | int m_mapFirst; |
|
107 | int m_mapFirst; | |
111 | int m_mapCount; |
|
108 | int m_mapCount; | |
112 | Qt::Orientation m_mapOrientation; |
|
109 | Qt::Orientation m_mapOrientation; | |
113 | }; |
|
110 | }; | |
114 |
|
111 | |||
115 | QTCOMMERCIALCHART_END_NAMESPACE |
|
112 | QTCOMMERCIALCHART_END_NAMESPACE | |
116 |
|
113 | |||
117 | #endif // BARSERIES_H |
|
114 | #endif // BARSERIES_H |
@@ -1,226 +1,221 | |||||
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 <QDebug> |
|
22 | #include <QDebug> | |
23 | #include <QToolTip> |
|
23 | #include <QToolTip> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QBarSet |
|
28 | \class QBarSet | |
29 | \brief part of QtCommercial chart API. |
|
29 | \brief part of QtCommercial chart API. | |
30 |
|
30 | |||
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
32 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | First value of set is assumed to belong to first category, second to second category and so on. | |
33 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | If set has fewer values than there are categories, then the missing values are assumed to be | |
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
35 |
|
35 | |||
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
38 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \fn void QBarSet::clicked(QString category) |
|
42 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) | |
43 | \brief signals that set has been clicked |
|
43 | \brief signals that set has been clicked | |
44 | Parameter \a category describes on which category was clicked |
|
44 | Parameter \a category describes on which category was clicked | |
45 | */ |
|
45 | Parameter \a button mouse button | |
46 |
|
||||
47 | /*! |
|
|||
48 | \fn void QBarSet::rightClicked(QString category) |
|
|||
49 | \brief signals that set has been clicked with right mouse button |
|
|||
50 | Parameter \a category describes on which category was clicked |
|
|||
51 | */ |
|
46 | */ | |
52 |
|
47 | |||
53 | /*! |
|
48 | /*! | |
54 | \fn void QBarSet::hoverEnter(QPoint pos) |
|
49 | \fn void QBarSet::hoverEnter(QPoint pos) | |
55 | \brief signals that mouse has entered over the set at position \a pos. |
|
50 | \brief signals that mouse has entered over the set at position \a pos. | |
56 | */ |
|
51 | */ | |
57 |
|
52 | |||
58 | /*! |
|
53 | /*! | |
59 | \fn void QBarSet::hoverLeave() |
|
54 | \fn void QBarSet::hoverLeave() | |
60 | \brief signals that mouse has left from the set. |
|
55 | \brief signals that mouse has left from the set. | |
61 | */ |
|
56 | */ | |
62 |
|
57 | |||
63 | /*! |
|
58 | /*! | |
64 | \fn void QBarSet::toggleFloatingValues() |
|
59 | \fn void QBarSet::toggleFloatingValues() | |
65 | \brief \internal |
|
60 | \brief \internal | |
66 | */ |
|
61 | */ | |
67 |
|
62 | |||
68 | /*! |
|
63 | /*! | |
69 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) |
|
64 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) | |
70 | \brief \internal \a pos \a tip |
|
65 | \brief \internal \a pos \a tip | |
71 | */ |
|
66 | */ | |
72 |
|
67 | |||
73 |
|
68 | |||
74 | /*! |
|
69 | /*! | |
75 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
70 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
76 | */ |
|
71 | */ | |
77 | QBarSet::QBarSet(QString name, QObject *parent) |
|
72 | QBarSet::QBarSet(QString name, QObject *parent) | |
78 | : QObject(parent) |
|
73 | : QObject(parent) | |
79 | ,m_name(name) |
|
74 | ,m_name(name) | |
80 | { |
|
75 | { | |
81 | } |
|
76 | } | |
82 |
|
77 | |||
83 | /*! |
|
78 | /*! | |
84 | Sets new \a name for set. |
|
79 | Sets new \a name for set. | |
85 | */ |
|
80 | */ | |
86 | void QBarSet::setName(QString name) |
|
81 | void QBarSet::setName(QString name) | |
87 | { |
|
82 | { | |
88 | m_name = name; |
|
83 | m_name = name; | |
89 | } |
|
84 | } | |
90 |
|
85 | |||
91 | /*! |
|
86 | /*! | |
92 | Returns name of the set. |
|
87 | Returns name of the set. | |
93 | */ |
|
88 | */ | |
94 | QString QBarSet::name() const |
|
89 | QString QBarSet::name() const | |
95 | { |
|
90 | { | |
96 | return m_name; |
|
91 | return m_name; | |
97 | } |
|
92 | } | |
98 |
|
93 | |||
99 | /*! |
|
94 | /*! | |
100 | Appends new value \a value to the end of set. |
|
95 | Appends new value \a value to the end of set. | |
101 | */ |
|
96 | */ | |
102 | QBarSet& QBarSet::operator << (const qreal &value) |
|
97 | QBarSet& QBarSet::operator << (const qreal &value) | |
103 | { |
|
98 | { | |
104 | m_values.append(value); |
|
99 | m_values.append(value); | |
105 | emit structureChanged(); |
|
100 | emit structureChanged(); | |
106 | return *this; |
|
101 | return *this; | |
107 | } |
|
102 | } | |
108 |
|
103 | |||
109 | void QBarSet::insertValue(int i, qreal value) |
|
104 | void QBarSet::insertValue(int i, qreal value) | |
110 | { |
|
105 | { | |
111 | m_values.insert(i, value); |
|
106 | m_values.insert(i, value); | |
112 | } |
|
107 | } | |
113 |
|
108 | |||
114 | void QBarSet::removeValue(int i) |
|
109 | void QBarSet::removeValue(int i) | |
115 | { |
|
110 | { | |
116 | m_values.removeAt(i); |
|
111 | m_values.removeAt(i); | |
117 | } |
|
112 | } | |
118 |
|
113 | |||
119 | /*! |
|
114 | /*! | |
120 | Returns count of values in set. |
|
115 | Returns count of values in set. | |
121 | */ |
|
116 | */ | |
122 | int QBarSet::count() const |
|
117 | int QBarSet::count() const | |
123 | { |
|
118 | { | |
124 | return m_values.count(); |
|
119 | return m_values.count(); | |
125 | } |
|
120 | } | |
126 |
|
121 | |||
127 | /*! |
|
122 | /*! | |
128 | Returns value of set indexed by \a index |
|
123 | Returns value of set indexed by \a index | |
129 | */ |
|
124 | */ | |
130 | qreal QBarSet::valueAt(int index) const |
|
125 | qreal QBarSet::valueAt(int index) const | |
131 | { |
|
126 | { | |
132 | return m_values.at(index); |
|
127 | return m_values.at(index); | |
133 | } |
|
128 | } | |
134 |
|
129 | |||
135 | /*! |
|
130 | /*! | |
136 | Sets a new value \a value to set, indexed by \a index |
|
131 | Sets a new value \a value to set, indexed by \a index | |
137 | */ |
|
132 | */ | |
138 | void QBarSet::setValue(int index, qreal value) |
|
133 | void QBarSet::setValue(int index, qreal value) | |
139 | { |
|
134 | { | |
140 | m_values.replace(index,value); |
|
135 | m_values.replace(index,value); | |
141 | emit valueChanged(); |
|
136 | emit valueChanged(); | |
142 | } |
|
137 | } | |
143 |
|
138 | |||
144 | /*! |
|
139 | /*! | |
145 | Returns total sum of all values in barset. |
|
140 | Returns total sum of all values in barset. | |
146 | */ |
|
141 | */ | |
147 | qreal QBarSet::total() const |
|
142 | qreal QBarSet::total() const | |
148 | { |
|
143 | { | |
149 | qreal total(0); |
|
144 | qreal total(0); | |
150 | for (int i=0; i < m_values.count(); i++) { |
|
145 | for (int i=0; i < m_values.count(); i++) { | |
151 | total += m_values.at(i); |
|
146 | total += m_values.at(i); | |
152 | } |
|
147 | } | |
153 | return total; |
|
148 | return total; | |
154 | } |
|
149 | } | |
155 |
|
150 | |||
156 | /*! |
|
151 | /*! | |
157 | Sets pen for set. Bars of this set are drawn using \a pen |
|
152 | Sets pen for set. Bars of this set are drawn using \a pen | |
158 | */ |
|
153 | */ | |
159 | void QBarSet::setPen(const QPen &pen) |
|
154 | void QBarSet::setPen(const QPen &pen) | |
160 | { |
|
155 | { | |
161 | m_pen = pen; |
|
156 | m_pen = pen; | |
162 | emit valueChanged(); |
|
157 | emit valueChanged(); | |
163 | } |
|
158 | } | |
164 |
|
159 | |||
165 | /*! |
|
160 | /*! | |
166 | Returns pen of the set. |
|
161 | Returns pen of the set. | |
167 | */ |
|
162 | */ | |
168 | QPen QBarSet::pen() const |
|
163 | QPen QBarSet::pen() const | |
169 | { |
|
164 | { | |
170 | return m_pen; |
|
165 | return m_pen; | |
171 | } |
|
166 | } | |
172 |
|
167 | |||
173 | /*! |
|
168 | /*! | |
174 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
169 | Sets brush for the set. Bars of this set are drawn using \a brush | |
175 | */ |
|
170 | */ | |
176 | void QBarSet::setBrush(const QBrush &brush) |
|
171 | void QBarSet::setBrush(const QBrush &brush) | |
177 | { |
|
172 | { | |
178 | m_brush = brush; |
|
173 | m_brush = brush; | |
179 | emit valueChanged(); |
|
174 | emit valueChanged(); | |
180 | } |
|
175 | } | |
181 |
|
176 | |||
182 | /*! |
|
177 | /*! | |
183 | Returns brush of the set. |
|
178 | Returns brush of the set. | |
184 | */ |
|
179 | */ | |
185 | QBrush QBarSet::brush() const |
|
180 | QBrush QBarSet::brush() const | |
186 | { |
|
181 | { | |
187 | return m_brush; |
|
182 | return m_brush; | |
188 | } |
|
183 | } | |
189 |
|
184 | |||
190 | /*! |
|
185 | /*! | |
191 | Sets the pen for floating values that are drawn on top of this set |
|
186 | Sets the pen for floating values that are drawn on top of this set | |
192 | */ |
|
187 | */ | |
193 | void QBarSet::setFloatingValuePen(const QPen &pen) |
|
188 | void QBarSet::setFloatingValuePen(const QPen &pen) | |
194 | { |
|
189 | { | |
195 | m_floatingValuePen = pen; |
|
190 | m_floatingValuePen = pen; | |
196 | } |
|
191 | } | |
197 |
|
192 | |||
198 | /*! |
|
193 | /*! | |
199 | Returns the pen for floating values that are drawn on top of this set |
|
194 | Returns the pen for floating values that are drawn on top of this set | |
200 | */ |
|
195 | */ | |
201 | QPen QBarSet::floatingValuePen() const |
|
196 | QPen QBarSet::floatingValuePen() const | |
202 | { |
|
197 | { | |
203 | return m_floatingValuePen; |
|
198 | return m_floatingValuePen; | |
204 | } |
|
199 | } | |
205 |
|
200 | |||
206 | /*! |
|
201 | /*! | |
207 | \internal \a pos |
|
202 | \internal \a pos | |
208 | */ |
|
203 | */ | |
209 | void QBarSet::barHoverEnterEvent(QPoint pos) |
|
204 | void QBarSet::barHoverEnterEvent(QPoint pos) | |
210 | { |
|
205 | { | |
211 | emit showToolTip(pos, m_name); |
|
206 | emit showToolTip(pos, m_name); | |
212 | emit hoverEnter(pos); |
|
207 | emit hoverEnter(pos); | |
213 | } |
|
208 | } | |
214 |
|
209 | |||
215 | /*! |
|
210 | /*! | |
216 | \internal |
|
211 | \internal | |
217 | */ |
|
212 | */ | |
218 | void QBarSet::barHoverLeaveEvent() |
|
213 | void QBarSet::barHoverLeaveEvent() | |
219 | { |
|
214 | { | |
220 | // Emit signal to user of charts |
|
215 | // Emit signal to user of charts | |
221 | emit hoverLeave(); |
|
216 | emit hoverLeave(); | |
222 | } |
|
217 | } | |
223 |
|
218 | |||
224 | #include "moc_qbarset.cpp" |
|
219 | #include "moc_qbarset.cpp" | |
225 |
|
220 | |||
226 | QTCOMMERCIALCHART_END_NAMESPACE |
|
221 | 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 | #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 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
30 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | public: |
|
33 | public: | |
34 | QBarSet(QString name, QObject *parent = 0); |
|
34 | QBarSet(QString name, QObject *parent = 0); | |
35 |
|
35 | |||
36 | void setName(QString name); |
|
36 | void setName(QString name); | |
37 | QString name() const; |
|
37 | QString name() const; | |
38 | QBarSet& operator << (const qreal &value); // appends new value to set |
|
38 | QBarSet& operator << (const qreal &value); // appends new value to set | |
39 | void insertValue(int i, qreal value); |
|
39 | void insertValue(int i, qreal value); | |
40 | void removeValue(int i); |
|
40 | void removeValue(int i); | |
41 |
|
41 | |||
42 | // TODO: remove indices eventually. Use as internal? |
|
42 | // TODO: remove indices eventually. Use as internal? | |
43 | int count() const; // count of values in set |
|
43 | int count() const; // count of values in set | |
44 | qreal valueAt(int index) const; // for modifying individual values |
|
44 | qreal valueAt(int index) const; // for modifying individual values | |
45 | void setValue(int index, qreal value); // setter for individual value |
|
45 | void setValue(int index, qreal value); // setter for individual value | |
46 | qreal total() const; // total values in the set |
|
46 | qreal total() const; // total values in the set | |
47 |
|
47 | |||
48 | // TODO: |
|
48 | // TODO: | |
49 | //qreal value(QString category); |
|
49 | //qreal value(QString category); | |
50 | //void setValue(QString category, qreal value); |
|
50 | //void setValue(QString category, qreal value); | |
51 |
|
51 | |||
52 | void setPen(const QPen &pen); |
|
52 | void setPen(const QPen &pen); | |
53 | QPen pen() const; |
|
53 | QPen pen() const; | |
54 |
|
54 | |||
55 | void setBrush(const QBrush &brush); |
|
55 | void setBrush(const QBrush &brush); | |
56 | QBrush brush() const; |
|
56 | QBrush brush() const; | |
57 |
|
57 | |||
58 | void setFloatingValuePen(const QPen &pen); |
|
58 | void setFloatingValuePen(const QPen &pen); | |
59 | QPen floatingValuePen() const; |
|
59 | QPen floatingValuePen() const; | |
60 |
|
60 | |||
61 | Q_SIGNALS: |
|
61 | Q_SIGNALS: | |
62 | void clicked(QString category); // Clicked and hover signals exposed to user |
|
62 | void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user | |
63 | void rightClicked(QString category); |
|
|||
64 | void toggleFloatingValues(); |
|
63 | void toggleFloatingValues(); | |
65 |
|
64 | |||
66 | // TODO: Expose this to user or not? |
|
65 | // TODO: Expose this to user or not? | |
67 | // TODO: TO PIMPL ---> |
|
66 | // TODO: TO PIMPL ---> | |
68 | void structureChanged(); |
|
67 | void structureChanged(); | |
69 | void valueChanged(); |
|
68 | void valueChanged(); | |
70 | void hoverEnter(QPoint pos); |
|
69 | void hoverEnter(QPoint pos); | |
71 | void hoverLeave(); |
|
70 | void hoverLeave(); | |
72 | void showToolTip(QPoint pos, QString tip); // Private signal |
|
71 | void showToolTip(QPoint pos, QString tip); // Private signal | |
73 | // <--- TO PIMPL |
|
72 | // <--- TO PIMPL | |
74 |
|
73 | |||
75 | public Q_SLOTS: |
|
74 | public Q_SLOTS: | |
76 | // These are for internal communication |
|
75 | // These are for internal communication | |
77 | // TODO: TO PIMPL ---> |
|
76 | // TODO: TO PIMPL ---> | |
78 | void barHoverEnterEvent(QPoint pos); |
|
77 | void barHoverEnterEvent(QPoint pos); | |
79 | void barHoverLeaveEvent(); |
|
78 | void barHoverLeaveEvent(); | |
80 | // <--- TO PIMPL |
|
79 | // <--- TO PIMPL | |
81 |
|
80 | |||
82 | private: |
|
81 | private: | |
83 |
|
82 | |||
84 | QString m_name; |
|
83 | QString m_name; | |
85 | QList<qreal> m_values; // TODO: replace with map (category, value) |
|
84 | QList<qreal> m_values; // TODO: replace with map (category, value) | |
86 | QMap<QString, qreal> m_mappedValues; |
|
85 | QMap<QString, qreal> m_mappedValues; | |
87 | QPen m_pen; |
|
86 | QPen m_pen; | |
88 | QBrush m_brush; |
|
87 | QBrush m_brush; | |
89 | QPen m_floatingValuePen; |
|
88 | QPen m_floatingValuePen; | |
90 | }; |
|
89 | }; | |
91 |
|
90 | |||
92 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE | |
93 |
|
92 | |||
94 | #endif // QBARSET_H |
|
93 | #endif // QBARSET_H |
General Comments 0
You need to be logged in to leave comments.
Login now