@@ -0,0 +1,15 | |||||
|
1 | !include( ../../common.pri ) { | |||
|
2 | error( "Couldn't find the common.pri file!" ) | |||
|
3 | } | |||
|
4 | ||||
|
5 | !include( ../../integrated.pri ) { | |||
|
6 | error( "Couldn't find the integrated.pri file !") | |||
|
7 | } | |||
|
8 | ||||
|
9 | TARGET = axisChart | |||
|
10 | TEMPLATE = app | |||
|
11 | QT += core gui | |||
|
12 | SOURCES += main.cpp | |||
|
13 | ||||
|
14 | ||||
|
15 |
@@ -0,0 +1,56 | |||||
|
1 | #include <QApplication> | |||
|
2 | #include <QMainWindow> | |||
|
3 | #include <qchartview.h> | |||
|
4 | #include <qlinechartseries.h> | |||
|
5 | #include <qchart.h> | |||
|
6 | #include <qchartaxis.h> | |||
|
7 | #include <cmath> | |||
|
8 | ||||
|
9 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
10 | ||||
|
11 | #define PI 3.14159265358979 | |||
|
12 | ||||
|
13 | int main(int argc, char *argv[]) | |||
|
14 | { | |||
|
15 | QApplication a(argc, argv); | |||
|
16 | ||||
|
17 | QMainWindow window; | |||
|
18 | ||||
|
19 | QLineChartSeries* series0 = new QLineChartSeries(); | |||
|
20 | QPen blue(Qt::blue); | |||
|
21 | blue.setWidth(3); | |||
|
22 | series0->setPen(blue); | |||
|
23 | QLineChartSeries* series1 = new QLineChartSeries(); | |||
|
24 | QPen red(Qt::red); | |||
|
25 | red.setWidth(3); | |||
|
26 | series1->setPen(red); | |||
|
27 | ||||
|
28 | int numPoints = 100; | |||
|
29 | ||||
|
30 | for (int x = 0; x <= numPoints; ++x) { | |||
|
31 | series0->add(x, fabs(sin(PI/50*x)*100)); | |||
|
32 | series1->add(x, fabs(cos(PI/50*x)*100)); | |||
|
33 | } | |||
|
34 | ||||
|
35 | QChartView* chartView = new QChartView(&window); | |||
|
36 | ||||
|
37 | chartView->setRenderHint(QPainter::Antialiasing); | |||
|
38 | chartView->setTitle("Basic line chart example"); | |||
|
39 | chartView->addSeries(series0); | |||
|
40 | chartView->addSeries(series1); | |||
|
41 | chartView->setChartBackgroundBrush(Qt::white); | |||
|
42 | ||||
|
43 | QChartAxis axis = chartView->defaultAxisX(); | |||
|
44 | axis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); | |||
|
45 | axis.setGridPen(Qt::DashLine); | |||
|
46 | ||||
|
47 | chartView->setDefaultAxisX(axis); | |||
|
48 | //axis.setShadesBrush(Qt::gray); | |||
|
49 | chartView->setDefaultAxisY(axis); | |||
|
50 | ||||
|
51 | window.setCentralWidget(chartView); | |||
|
52 | window.resize(400, 300); | |||
|
53 | window.show(); | |||
|
54 | ||||
|
55 | return a.exec(); | |||
|
56 | } |
@@ -1,10 +1,11 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | SUBDIRS += linechart \ |
|
2 | SUBDIRS += linechart \ | |
3 | zoomlinechart \ |
|
3 | zoomlinechart \ | |
4 | colorlinechart \ |
|
4 | colorlinechart \ | |
5 | barchart \ |
|
5 | barchart \ | |
6 | stackedbarchart \ |
|
6 | stackedbarchart \ | |
7 | percentbarchart \ |
|
7 | percentbarchart \ | |
8 | scatter \ |
|
8 | scatter \ | |
9 | piechart \ |
|
9 | piechart \ | |
10 | dynamiclinechart |
|
10 | dynamiclinechart \ | |
|
11 | axischart |
@@ -1,176 +1,289 | |||||
1 | #include "axisitem_p.h" |
|
1 | #include "axisitem_p.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include <QPainter> |
|
3 | #include <QPainter> | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 |
|
5 | |||
6 | #define LABEL_PADDING 5 |
|
6 | static int label_padding = 5; | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
AxisItem::AxisItem( |
|
10 | AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) : | |
11 |
|
|
11 | ChartItem(parent), | |
12 | m_axis(axis), |
|
12 | m_ticks(4), | |
13 | m_ticks(4), |
|
13 | m_type(type), | |
14 | m_type(type) |
|
14 | m_labelsAngle(0), | |
|
15 | m_shadesEnabled(true), | |||
|
16 | m_grid(this), | |||
|
17 | m_shades(this), | |||
|
18 | m_labels(this) | |||
15 | { |
|
19 | { | |
16 | //initial initialization |
|
20 | //initial initialization | |
17 | handleAxisChanged(); |
|
21 | createItems(); | |
18 | } |
|
22 | } | |
19 |
|
23 | |||
20 | AxisItem::~AxisItem() |
|
24 | AxisItem::~AxisItem() | |
21 | { |
|
25 | { | |
22 | } |
|
26 | } | |
23 |
|
27 | |||
24 | QRectF AxisItem::boundingRect() const |
|
28 | QRectF AxisItem::boundingRect() const | |
25 | { |
|
29 | { | |
26 | return m_rect; |
|
30 | return m_rect; | |
27 | } |
|
31 | } | |
28 |
|
32 | |||
|
33 | void AxisItem::createItems() | |||
|
34 | { | |||
|
35 | for (int i = 0; i <= m_ticks; ++i) { | |||
|
36 | m_grid.addToGroup(new QGraphicsLineItem(this)); | |||
|
37 | m_labels.addToGroup(new QGraphicsSimpleTextItem(this)); | |||
|
38 | if(i%2) m_shades.addToGroup(new QGraphicsRectItem(this)); | |||
|
39 | } | |||
|
40 | } | |||
|
41 | ||||
|
42 | void AxisItem::clear() | |||
|
43 | { | |||
|
44 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |||
|
45 | delete item; | |||
|
46 | } | |||
|
47 | ||||
|
48 | foreach(QGraphicsItem* item , m_grid.childItems()) { | |||
|
49 | delete item; | |||
|
50 | } | |||
|
51 | ||||
|
52 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |||
|
53 | delete item; | |||
|
54 | } | |||
|
55 | ||||
|
56 | } | |||
|
57 | ||||
|
58 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |||
|
59 | { | |||
29 |
|
60 | |||
30 | /* |
|
61 | } | |
31 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) |
|
62 | ||
|
63 | void AxisItem::updateDomain() | |||
32 | { |
|
64 | { | |
33 | if (!m_rect.isValid()) |
|
|||
34 | return; |
|
|||
35 |
|
65 | |||
36 | if(m_type==X_AXIS) { |
|
66 | QList<QGraphicsItem *> lines = m_grid.childItems(); | |
|
67 | QList<QGraphicsItem *> labels = m_labels.childItems(); | |||
|
68 | QList<QGraphicsItem *> shades = m_shades.childItems(); | |||
37 |
|
69 | |||
38 | const qreal deltaX = m_rect.width() / m_ticks; |
|
70 | switch (m_type) | |
|
71 | { | |||
|
72 | case X_AXIS: | |||
|
73 | { | |||
|
74 | const qreal deltaX = m_rect.width() / m_ticks; | |||
39 |
|
75 | |||
40 | for (int i = 0; i <= m_ticks; ++i) { |
|
76 | for (int i = 0; i <= m_ticks; ++i) { | |
41 |
|
77 | |||
42 | int x = i * deltaX + m_rect.left(); |
|
78 | int x = i * deltaX + m_rect.left(); | |
43 |
|
79 | |||
44 | if(i==0) x--; |
|
80 | qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks); | |
45 | if(i==m_ticks) x++; |
|
|||
46 |
|
81 | |||
47 | qreal label = m_plotDomain.m_minX + (i * m_plotDomain.spanX() |
|
82 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
48 | / m_ticks); |
|
83 | lineItem->setLine(x, m_rect.top(), x, m_rect.bottom()); | |
49 | painter->drawLine(x, m_rect.top()-1, x, m_rect.bottom()+1); |
|
|||
50 | // painter->drawLine(x, m_rect.bottom()-1, x, m_rect.bottom()-1 + 5); |
|
|||
51 |
|
84 | |||
52 | painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20,Qt::AlignHCenter | Qt::AlignTop, QString::number(label)); |
|
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
53 | } |
|
86 | labelItem->setText(QString::number(label)); | |
54 | } |
|
87 | QPointF center = labelItem->boundingRect().center(); | |
|
88 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |||
|
89 | labelItem->setPos(x - center.x(), m_rect.bottom() + label_padding); | |||
55 |
|
90 | |||
56 | if(m_type==Y_AXIS) { |
|
91 | if(i%2){ | |
|
92 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); | |||
|
93 | rectItem->setRect(x,m_rect.top(),deltaX,m_rect.height()); | |||
|
94 | } | |||
|
95 | } | |||
|
96 | } | |||
|
97 | break; | |||
57 |
|
98 | |||
58 | const qreal deltaY = (m_rect.height()) / m_ticks; |
|
99 | case Y_AXIS: | |
|
100 | { | |||
|
101 | const qreal deltaY = m_rect.height()/ m_ticks; | |||
59 |
|
102 | |||
60 |
for (int |
|
103 | for (int i = 0; i <= m_ticks; ++i) { | |
61 |
|
104 | |||
62 |
int y = |
|
105 | int y = i * -deltaY + m_rect.bottom(); | |
63 |
|
106 | |||
64 | if(j==0) y++; |
|
107 | qreal label = m_domain.m_minY + (i * m_domain.spanY()/ m_ticks); | |
65 | if(j==m_ticks) y--; |
|
|||
66 |
|
108 | |||
67 | qreal label = m_plotDomain.m_minY + (j * m_plotDomain.spanY() |
|
109 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
68 | / m_ticks); |
|
110 | lineItem->setLine(m_rect.left() , y, m_rect.right(), y); | |
69 |
|
111 | |||
70 | painter->drawLine(m_rect.left()-1, y, m_rect.right()+1, y); |
|
112 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
71 | //painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y); |
|
113 | labelItem->setText(QString::number(label)); | |
72 | //TODO : margin = 50 ; |
|
114 | QPointF center = labelItem->boundingRect().center(); | |
73 | painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20, |
|
115 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
74 | Qt::AlignRight | Qt::AlignVCenter, |
|
116 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , y-center.y()); | |
75 | QString::number(label)); |
|
|||
76 | } |
|
|||
77 | } |
|
|||
78 |
|
117 | |||
79 | //painter->drawRect(m_rect.adjusted(0, 0, -1, -1)); |
|
118 | ||
|
119 | if(i%2){ | |||
|
120 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); | |||
|
121 | rectItem->setRect(m_rect.left(),y,m_rect.width(),deltaY); | |||
|
122 | } | |||
|
123 | } | |||
|
124 | } | |||
|
125 | break; | |||
|
126 | default: | |||
|
127 | qDebug()<<"Unknown axis type"; | |||
|
128 | break; | |||
|
129 | } | |||
80 | } |
|
130 | } | |
81 | */ |
|
131 | ||
82 | void AxisItem::createItems() |
|
132 | void AxisItem::handleAxisChanged(const QChartAxis& axis) | |
83 | { |
|
133 | { | |
|
134 | if(axis.isGridVisible()) { | |||
|
135 | setGridOpacity(100); | |||
|
136 | } | |||
|
137 | else { | |||
|
138 | setGridOpacity(0); | |||
|
139 | } | |||
84 |
|
140 | |||
85 | if(!m_rect.isValid()) return; |
|
141 | if(axis.isLabelsVisible()) | |
|
142 | { | |||
|
143 | setLabelsOpacity(100); | |||
|
144 | } | |||
|
145 | else { | |||
|
146 | setLabelsOpacity(0); | |||
|
147 | } | |||
86 |
|
148 | |||
87 | switch (m_type) |
|
149 | if(axis.isShadesVisible()) { | |
|
150 | setShadesOpacity(100); | |||
|
151 | } | |||
|
152 | else { | |||
|
153 | setShadesOpacity(0); | |||
|
154 | } | |||
|
155 | ||||
|
156 | switch(axis.labelsOrientation()) | |||
88 | { |
|
157 | { | |
89 | case X_AXIS: |
|
158 | case QChartAxis::LabelsOrientationHorizontal: | |
90 | { |
|
159 | setLabelsAngle(0); | |
91 | const qreal deltaX = m_rect.width() / m_ticks; |
|
160 | break; | |
|
161 | case QChartAxis::LabelsOrientationVertical: | |||
|
162 | setLabelsAngle(90); | |||
|
163 | break; | |||
|
164 | case QChartAxis::LabelsOrientationSlide: | |||
|
165 | setLabelsAngle(-45); | |||
|
166 | break; | |||
|
167 | default: | |||
|
168 | break; | |||
|
169 | } | |||
92 |
|
170 | |||
93 | for (int i = 0; i <= m_ticks; ++i) { |
|
171 | setLabelsPen(axis.labelsPen()); | |
|
172 | setLabelsBrush(axis.labelsBrush()); | |||
|
173 | setLabelsFont(axis.labelFont()); | |||
|
174 | setGridPen(axis.gridPen()); | |||
|
175 | setShadesPen(axis.shadesPen()); | |||
|
176 | setShadesBrush(axis.shadesBrush()); | |||
94 |
|
177 | |||
95 | int x = i * deltaX + m_rect.left(); |
|
178 | } | |
96 |
|
179 | |||
97 | qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks); |
|
180 | void AxisItem::handleDomainChanged(const Domain& domain) | |
|
181 | { | |||
|
182 | m_domain = domain; | |||
|
183 | updateDomain(); | |||
|
184 | update(); | |||
|
185 | } | |||
98 |
|
186 | |||
99 | m_grid<<new QGraphicsLineItem(x, m_rect.top(), x, m_rect.bottom(),this); |
|
187 | void AxisItem::handleGeometryChanged(const QRectF& rect) | |
|
188 | { | |||
|
189 | m_rect = rect; | |||
|
190 | updateDomain(); | |||
|
191 | update(); | |||
|
192 | } | |||
100 |
|
193 | |||
101 | QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this); |
|
194 | void AxisItem::setGridOpacity(qreal opacity) | |
102 | QPointF center = text->boundingRect().center(); |
|
195 | { | |
103 | text->setPos(x - center.x(), m_rect.bottom() + LABEL_PADDING); |
|
196 | m_grid.setOpacity(opacity); | |
104 | //text->rotate(-45); |
|
197 | } | |
105 | m_labels<<text; |
|
|||
106 | } |
|
|||
107 | } |
|
|||
108 | break; |
|
|||
109 |
|
198 | |||
110 | case Y_AXIS: |
|
|||
111 | { |
|
|||
112 | const qreal deltaY = m_rect.height()/ m_ticks; |
|
|||
113 |
|
199 | |||
114 | for (int j = 0; j <= m_ticks; ++j) { |
|
200 | qreal AxisItem::gridOpacity() const | |
|
201 | { | |||
|
202 | return m_grid.opacity(); | |||
|
203 | } | |||
115 |
|
204 | |||
116 | int y = j * -deltaY + m_rect.bottom(); |
|
205 | void AxisItem::setLabelsOpacity(qreal opacity) | |
|
206 | { | |||
|
207 | m_labels.setOpacity(opacity); | |||
|
208 | } | |||
117 |
|
209 | |||
118 | qreal label = m_domain.m_minY + (j * m_domain.spanY() |
|
210 | qreal AxisItem::labelsOpacity() const | |
119 | / m_ticks); |
|
211 | { | |
|
212 | return m_labels.opacity(); | |||
|
213 | } | |||
120 |
|
214 | |||
121 | m_grid<<new QGraphicsLineItem(m_rect.left() , y, m_rect.right(), y,this); |
|
215 | void AxisItem::setShadesOpacity(qreal opacity) | |
122 | QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this); |
|
216 | { | |
123 | QPointF center = text->boundingRect().center(); |
|
217 | m_shades.setOpacity(opacity); | |
124 | text->setPos(m_rect.left() - text->boundingRect().width() - LABEL_PADDING , y-center.y()); |
|
218 | } | |
125 |
|
219 | |||
126 | m_labels<<text; |
|
220 | qreal AxisItem::shadesOpacity() const | |
|
221 | { | |||
|
222 | return m_shades.opacity(); | |||
|
223 | } | |||
127 |
|
224 | |||
128 | } |
|
225 | void AxisItem::setLabelsAngle(int angle) | |
129 | } |
|
226 | { | |
130 | break; |
|
227 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
131 | default: |
|
228 | QPointF center = item->boundingRect().center(); | |
132 | qDebug()<<"Unknown axis type"; |
|
229 | item->setRotation(angle); | |
133 | break; |
|
|||
134 | } |
|
230 | } | |
|
231 | ||||
|
232 | m_labelsAngle=angle; | |||
135 | } |
|
233 | } | |
136 |
|
234 | |||
137 | void AxisItem::clear() |
|
235 | void AxisItem::setLabelsPen(const QPen& pen) | |
138 | { |
|
236 | { | |
139 | qDeleteAll(m_shades); |
|
237 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
140 | m_shades.clear(); |
|
238 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
141 | qDeleteAll(m_grid); |
|
239 | } | |
142 | m_grid.clear(); |
|
|||
143 | qDeleteAll(m_labels); |
|
|||
144 | m_labels.clear(); |
|
|||
145 | } |
|
240 | } | |
146 |
|
241 | |||
147 | void AxisItem::updateDomain() |
|
242 | void AxisItem::setLabelsBrush(const QBrush& brush) | |
148 | { |
|
243 | { | |
149 | clear(); |
|
244 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
150 | createItems(); |
|
245 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
|
246 | } | |||
151 | } |
|
247 | } | |
152 |
|
248 | |||
153 | void AxisItem::handleAxisChanged() |
|
249 | void AxisItem::setLabelsFont(const QFont& font) | |
154 | { |
|
250 | { | |
155 | //m_axis-> |
|
251 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
|
252 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |||
|
253 | } | |||
156 | } |
|
254 | } | |
157 |
|
255 | |||
158 | void AxisItem::handleDomainChanged(const Domain& domain) |
|
256 | void AxisItem::setShadesBrush(const QBrush& brush) | |
159 | { |
|
257 | { | |
160 | m_domain = domain; |
|
258 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
161 | clear(); |
|
259 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
162 | createItems(); |
|
260 | } | |
163 | } |
|
261 | } | |
164 |
|
262 | |||
165 |
void AxisItem:: |
|
263 | void AxisItem::setShadesPen(const QPen& pen) | |
166 | { |
|
264 | { | |
167 | Q_ASSERT(rect.isValid()); |
|
265 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
168 | m_rect = rect; |
|
266 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
|
267 | } | |||
|
268 | } | |||
|
269 | ||||
|
270 | void AxisItem::setGridPen(const QPen& pen) | |||
|
271 | { | |||
|
272 | foreach(QGraphicsItem* item , m_grid.childItems()) { | |||
|
273 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |||
|
274 | } | |||
|
275 | } | |||
|
276 | ||||
|
277 | void AxisItem::setTicks(int count) | |||
|
278 | { | |||
|
279 | if(count!=m_ticks){ | |||
169 | clear(); |
|
280 | clear(); | |
|
281 | m_ticks=count; | |||
170 | createItems(); |
|
282 | createItems(); | |
|
283 | } | |||
171 | } |
|
284 | } | |
172 |
|
285 | |||
173 | //TODO "nice numbers algorithm" |
|
286 | //TODO "nice numbers algorithm" | |
174 | #include "moc_axisitem_p.cpp" |
|
287 | #include "moc_axisitem_p.cpp" | |
175 |
|
288 | |||
176 | QTCOMMERCIALCHART_END_NAMESPACE |
|
289 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,63 +1,75 | |||||
1 | #ifndef AXISITEM_H_ |
|
1 | #ifndef AXISITEM_H_ | |
2 | #define AXISITEM_H_ |
|
2 | #define AXISITEM_H_ | |
3 |
|
3 | |||
4 | #include "domain_p.h" |
|
4 | #include "domain_p.h" | |
5 | #include "chartitem_p.h" |
|
5 | #include "chartitem_p.h" | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QChartAxis; |
|
10 | class QChartAxis; | |
11 |
|
11 | |||
12 | class AxisItem : public QObject, public ChartItem |
|
12 | class AxisItem : public QObject, public ChartItem | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | enum AxisType{X_AXIS,Y_AXIS}; |
|
16 | enum AxisType{X_AXIS,Y_AXIS}; | |
17 |
|
17 | |||
18 |
AxisItem( |
|
18 | AxisItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0); | |
19 | ~AxisItem(); |
|
19 | ~AxisItem(); | |
20 |
|
20 | |||
21 | //from QGraphicsItem |
|
21 | //from QGraphicsItem | |
22 | QRectF boundingRect() const; |
|
22 | QRectF boundingRect() const; | |
23 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
24 |
|
24 | |||
25 | protected slots: |
|
25 | AxisType axisType() const {return m_type;}; | |
26 | void handleAxisChanged(); |
|
|||
27 | void handleDomainChanged(const Domain& domain); |
|
|||
28 | void handleGeometryChanged(const QRectF& size); |
|
|||
29 |
|
26 | |||
30 | protected: |
|
27 | void setGridOpacity(qreal opacity); | |
31 | void updateDomain(); |
|
28 | qreal gridOpacity() const; | |
32 |
|
29 | |||
33 | private: |
|
30 | void setLabelsOpacity(qreal opacity); | |
34 | void clear(); |
|
31 | qreal labelsOpacity() const; | |
35 |
|
32 | |||
36 | public: |
|
33 | void setShadesOpacity(qreal opacity); | |
37 | AxisType axisType() const {return m_type;}; |
|
34 | qreal shadesOpacity() const; | |
38 |
|
35 | |||
39 | protected: |
|
36 | void setLabelsAngle(int angle); | |
|
37 | int labelsAngle()const { return m_labelsAngle; } | |||
|
38 | ||||
|
39 | void setTicks(int count); | |||
|
40 | int ticks() const { return m_ticks;} | |||
40 |
|
41 | |||
|
42 | void setShadesBrush(const QBrush& brush); | |||
|
43 | void setShadesPen(const QPen& pen); | |||
41 |
|
44 | |||
|
45 | void setGridPen(const QPen& pen); | |||
|
46 | ||||
|
47 | void setLabelsPen(const QPen& pen); | |||
|
48 | void setLabelsBrush(const QBrush& brush); | |||
|
49 | void setLabelsFont(const QFont& font); | |||
|
50 | ||||
|
51 | public slots: | |||
|
52 | void handleAxisChanged(const QChartAxis& axis); | |||
|
53 | void handleDomainChanged(const Domain& domain); | |||
|
54 | void handleGeometryChanged(const QRectF& size); | |||
|
55 | protected: | |||
|
56 | void updateDomain(); | |||
42 | private: |
|
57 | private: | |
|
58 | void clear(); | |||
43 | void createItems(); |
|
59 | void createItems(); | |
44 | private: |
|
60 | private: | |
45 |
|
||||
46 | QChartAxis* m_axis; |
|
|||
47 | AxisType m_type; |
|
61 | AxisType m_type; | |
48 | int m_ticks; |
|
62 | int m_ticks; | |
49 | Domain m_domain; |
|
63 | Domain m_domain; | |
50 | QRectF m_rect; |
|
64 | QRectF m_rect; | |
51 |
|
65 | int m_labelsAngle; | ||
52 | QPainterPath m_path; |
|
66 | bool m_shadesEnabled; | |
53 |
|
67 | QGraphicsItemGroup m_grid; | ||
54 |
|
68 | QGraphicsItemGroup m_shades; | ||
55 |
|
|
69 | QGraphicsItemGroup m_labels; | |
56 | QList<QGraphicsRectItem*> m_shades; |
|
|||
57 | QList<QGraphicsSimpleTextItem*> m_labels; |
|
|||
58 |
|
70 | |||
59 | }; |
|
71 | }; | |
60 |
|
72 | |||
61 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | QTCOMMERCIALCHART_END_NAMESPACE | |
62 |
|
74 | |||
63 | #endif /* AXISITEM_H_ */ |
|
75 | #endif /* AXISITEM_H_ */ |
@@ -1,265 +1,271 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | //series |
|
6 | //series | |
7 | #include "barchartseries.h" |
|
7 | #include "barchartseries.h" | |
8 | #include "stackedbarchartseries.h" |
|
8 | #include "stackedbarchartseries.h" | |
9 | #include "percentbarchartseries.h" |
|
9 | #include "percentbarchartseries.h" | |
10 | #include "qlinechartseries.h" |
|
10 | #include "qlinechartseries.h" | |
11 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
12 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | //items |
|
13 | //items | |
14 | #include "axisitem_p.h" |
|
14 | #include "axisitem_p.h" | |
15 | #include "bargroup.h" |
|
15 | #include "bargroup.h" | |
16 | #include "stackedbargroup.h" |
|
16 | #include "stackedbargroup.h" | |
17 | #include "linechartitem_p.h" |
|
17 | #include "linechartitem_p.h" | |
18 | #include "percentbargroup.h" |
|
18 | #include "percentbargroup.h" | |
19 | #include "linechartanimationitem_p.h" |
|
19 | #include "linechartanimationitem_p.h" | |
20 | #include "piepresenter.h" |
|
20 | #include "piepresenter.h" | |
21 | #include "scatterpresenter.h" |
|
21 | #include "scatterpresenter.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
26 | m_chart(chart), |
|
26 | m_chart(chart), | |
27 | m_dataset(dataset), |
|
27 | m_dataset(dataset), | |
28 | m_chartTheme(0), |
|
28 | m_chartTheme(0), | |
|
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)), | |||
|
30 | m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)), | |||
29 | m_domainIndex(0), |
|
31 | m_domainIndex(0), | |
30 | m_marginSize(0), |
|
32 | m_marginSize(0), | |
31 | m_axisX(new QChartAxis(this)), |
|
|||
32 | m_axisY(new QChartAxis(this)), |
|
|||
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
34 | { |
|
34 | { | |
35 | setChartTheme(QChart::ChartThemeDefault); |
|
35 | setChartTheme(QChart::ChartThemeDefault); | |
36 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); |
|
|||
37 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); |
|
|||
38 | createConnections(); |
|
36 | createConnections(); | |
39 | } |
|
37 | } | |
40 |
|
38 | |||
41 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
42 | { |
|
40 | { | |
43 | } |
|
41 | } | |
44 |
|
42 | |||
45 | void ChartPresenter::createConnections() |
|
43 | void ChartPresenter::createConnections() | |
46 | { |
|
44 | { | |
47 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
48 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
49 |
|
47 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&))); | ||
50 | QMapIterator<QChartAxis*,AxisItem*> i(m_axisItems); |
|
48 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&))); | |
51 |
|
49 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&))); | ||
52 | while (i.hasNext()) { |
|
50 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&))); | |
53 | i.next(); |
|
|||
54 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),i.value(),SLOT(handleGeometryChanged(const QRectF&))); |
|
|||
55 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),i.value(),SLOT(handleDomainChanged(const Domain&))); |
|
|||
56 | } |
|
|||
57 | } |
|
51 | } | |
58 |
|
52 | |||
59 | void ChartPresenter::handleGeometryChanged() |
|
53 | void ChartPresenter::handleGeometryChanged() | |
60 | { |
|
54 | { | |
61 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
55 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
62 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
56 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
63 | Q_ASSERT(m_rect.isValid()); |
|
57 | Q_ASSERT(m_rect.isValid()); | |
64 | emit geometryChanged(m_rect); |
|
58 | emit geometryChanged(m_rect); | |
65 | } |
|
59 | } | |
66 |
|
60 | |||
67 | int ChartPresenter::margin() const |
|
61 | int ChartPresenter::margin() const | |
68 | { |
|
62 | { | |
69 | return m_marginSize; |
|
63 | return m_marginSize; | |
70 | } |
|
64 | } | |
71 |
|
65 | |||
72 | void ChartPresenter::setMargin(int margin) |
|
66 | void ChartPresenter::setMargin(int margin) | |
73 | { |
|
67 | { | |
74 | m_marginSize = margin; |
|
68 | m_marginSize = margin; | |
75 | } |
|
69 | } | |
76 |
|
70 | |||
77 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
71 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
78 | { |
|
72 | { | |
79 | qDebug() << " ChartPresenter::handleSeriesAdded"; |
|
73 | qDebug() << " ChartPresenter::handleSeriesAdded"; | |
80 | switch(series->type()) |
|
74 | switch(series->type()) | |
81 | { |
|
75 | { | |
82 | case QChartSeries::SeriesTypeLine: { |
|
76 | case QChartSeries::SeriesTypeLine: { | |
83 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); |
|
77 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); | |
84 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
78 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
85 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
79 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
86 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
80 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
87 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
81 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
88 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
82 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
89 | m_chartItems.insert(series,item); |
|
83 | m_chartItems.insert(series,item); | |
90 | break; |
|
84 | break; | |
91 | } |
|
85 | } | |
92 |
|
86 | |||
93 | case QChartSeries::SeriesTypeBar: { |
|
87 | case QChartSeries::SeriesTypeBar: { | |
94 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
88 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
95 | BarGroup* item = new BarGroup(barSeries->model(),m_chart); |
|
89 | BarGroup* item = new BarGroup(barSeries->model(),m_chart); | |
96 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
90 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
97 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
91 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
98 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
92 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
99 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
93 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
100 | m_chartItems.insert(series,item); |
|
94 | m_chartItems.insert(series,item); | |
101 | // m_axisXItem->setVisible(false); |
|
95 | // m_axisXItem->setVisible(false); | |
102 | break; |
|
96 | break; | |
103 | } |
|
97 | } | |
104 |
|
98 | |||
105 | case QChartSeries::SeriesTypeStackedBar: { |
|
99 | case QChartSeries::SeriesTypeStackedBar: { | |
106 |
|
100 | |||
107 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
101 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
108 | StackedBarGroup* item = new StackedBarGroup(stackedBarSeries->model(),m_chart); |
|
102 | StackedBarGroup* item = new StackedBarGroup(stackedBarSeries->model(),m_chart); | |
109 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
103 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
110 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
104 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
111 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
112 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
106 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
113 | m_chartItems.insert(series,item); |
|
107 | m_chartItems.insert(series,item); | |
114 | break; |
|
108 | break; | |
115 | } |
|
109 | } | |
116 |
|
110 | |||
117 | case QChartSeries::SeriesTypePercentBar: { |
|
111 | case QChartSeries::SeriesTypePercentBar: { | |
118 |
|
112 | |||
119 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
113 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
120 | PercentBarGroup* item = new PercentBarGroup(percentBarSeries->model(),m_chart); |
|
114 | PercentBarGroup* item = new PercentBarGroup(percentBarSeries->model(),m_chart); | |
121 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
115 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
122 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
116 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
123 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
117 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
124 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
118 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
125 | m_chartItems.insert(series,item); |
|
119 | m_chartItems.insert(series,item); | |
126 | break; |
|
120 | break; | |
127 | } |
|
121 | } | |
128 | case QChartSeries::SeriesTypeScatter: { |
|
122 | case QChartSeries::SeriesTypeScatter: { | |
129 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
123 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
130 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
124 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); | |
131 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
125 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
132 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
126 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
133 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), |
|
127 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), | |
134 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); |
|
128 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); | |
135 | // scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
129 | // scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
136 | // scatterSeries->d->setParentItem(this); |
|
130 | // scatterSeries->d->setParentItem(this); | |
137 | // scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
131 | // scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
138 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
132 | m_chartItems.insert(scatterSeries, scatterPresenter); | |
139 | break; |
|
133 | break; | |
140 | } |
|
134 | } | |
141 | case QChartSeries::SeriesTypePie: { |
|
135 | case QChartSeries::SeriesTypePie: { | |
142 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
136 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
143 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
137 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
144 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
138 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
145 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
139 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
146 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); |
|
140 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); | |
147 | m_chartItems.insert(series, pie); |
|
141 | m_chartItems.insert(series, pie); | |
148 | break; |
|
142 | break; | |
149 | } |
|
143 | } | |
150 | default: { |
|
144 | default: { | |
151 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
145 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
152 | break; |
|
146 | break; | |
153 | } |
|
147 | } | |
154 | } |
|
148 | } | |
155 |
|
149 | |||
156 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
150 | if(m_rect.isValid()) emit geometryChanged(m_rect); | |
157 | } |
|
151 | } | |
158 |
|
152 | |||
159 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
153 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
160 | { |
|
154 | { | |
161 | //TODO: |
|
155 | //TODO: | |
162 | } |
|
156 | } | |
163 |
|
157 | |||
164 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
|
158 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |
165 | { |
|
159 | { | |
166 | if(!rect.isValid()) return; |
|
160 | if(!rect.isValid()) return; | |
167 | QRectF r = rect.normalized(); |
|
161 | QRectF r = rect.normalized(); | |
168 | r.translate(-m_marginSize, -m_marginSize); |
|
162 | r.translate(-m_marginSize, -m_marginSize); | |
169 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); |
|
163 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); | |
170 | m_dataset->addDomain(domain); |
|
164 | m_dataset->addDomain(domain); | |
171 | } |
|
165 | } | |
172 |
|
166 | |||
173 | void ChartPresenter::zoomIn() |
|
167 | void ChartPresenter::zoomIn() | |
174 | { |
|
168 | { | |
175 | if (!m_dataset->nextDomain()) { |
|
169 | if (!m_dataset->nextDomain()) { | |
176 | QRectF rect = m_rect; |
|
170 | QRectF rect = m_rect; | |
177 | rect.setWidth(rect.width()/2); |
|
171 | rect.setWidth(rect.width()/2); | |
178 | rect.setHeight(rect.height()/2); |
|
172 | rect.setHeight(rect.height()/2); | |
179 | rect.moveCenter(m_rect.center()); |
|
173 | rect.moveCenter(m_rect.center()); | |
180 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
174 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
181 | m_dataset->addDomain(domain); |
|
175 | m_dataset->addDomain(domain); | |
182 | } |
|
176 | } | |
183 | } |
|
177 | } | |
184 |
|
178 | |||
185 | void ChartPresenter::zoomOut() |
|
179 | void ChartPresenter::zoomOut() | |
186 | { |
|
180 | { | |
187 | m_dataset->previousDomain(); |
|
181 | m_dataset->previousDomain(); | |
188 | } |
|
182 | } | |
189 |
|
183 | |||
190 | void ChartPresenter::zoomReset() |
|
184 | void ChartPresenter::zoomReset() | |
191 | { |
|
185 | { | |
192 | m_dataset->clearDomains(); |
|
186 | m_dataset->clearDomains(); | |
193 | } |
|
187 | } | |
194 |
|
188 | |||
195 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
189 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
196 | { |
|
190 | { | |
197 | delete m_chartTheme; |
|
191 | delete m_chartTheme; | |
198 |
|
192 | |||
199 | m_chartTheme = ChartTheme::createTheme(theme); |
|
193 | m_chartTheme = ChartTheme::createTheme(theme); | |
200 |
|
194 | |||
201 | m_chartTheme->decorate(m_chart); |
|
195 | m_chartTheme->decorate(m_chart); | |
202 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); |
|
196 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); | |
203 |
|
197 | |||
204 | int index=0; |
|
198 | int index=0; | |
205 | while (i.hasNext()) { |
|
199 | while (i.hasNext()) { | |
206 | i.next(); |
|
200 | i.next(); | |
207 | index++; |
|
201 | index++; | |
208 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
202 | m_chartTheme->decorate(i.value(),i.key(),index); | |
209 | } |
|
|||
210 | } |
|
203 | } | |
211 |
|
204 | |||
|
205 | m_chartTheme->decorate(m_axisX, m_axisXItem); | |||
|
206 | m_chartTheme->decorate(m_axisY, m_axisYItem); | |||
|
207 | ||||
|
208 | } | |||
|
209 | ||||
212 |
|
210 | |||
213 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
211 | QChart::ChartTheme ChartPresenter::chartTheme() | |
214 | { |
|
212 | { | |
215 | return m_chartTheme->id(); |
|
213 | return m_chartTheme->id(); | |
216 | } |
|
214 | } | |
217 |
|
215 | |||
218 | QChartAxis* ChartPresenter::axisX() |
|
216 | void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) | |
219 | { |
|
217 | { | |
220 | return m_axisX; |
|
218 | //if(m_axisX != axis) { | |
|
219 | m_axisX = axis; | |||
|
220 | m_axisXItem->handleAxisChanged(m_axisX); | |||
|
221 | //} | |||
221 | } |
|
222 | } | |
222 |
|
223 | |||
223 | QChartAxis* ChartPresenter::axisY() |
|
224 | void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) | |
224 | { |
|
225 | { | |
225 | return m_axisY; |
|
226 | // if(m_axisY != axis) { | |
|
227 | m_axisY = axis; | |||
|
228 | m_axisYItem->handleAxisChanged(m_axisY); | |||
|
229 | //} | |||
226 | } |
|
230 | } | |
227 |
|
231 | |||
228 |
QChartAxis |
|
232 | QChartAxis ChartPresenter::defaultAxisX() const | |
229 | { |
|
233 | { | |
230 | //only one axis |
|
234 | return m_axisX; | |
231 | if(m_axisX==0){ |
|
|||
232 | m_axisX = new QChartAxis(this); |
|
|||
233 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); |
|
|||
234 | } |
|
|||
235 | return m_axisX; |
|
|||
236 | } |
|
235 | } | |
237 |
|
236 | |||
238 |
QChartAxis |
|
237 | QChartAxis ChartPresenter::defaultAxisY() const | |
239 | { |
|
238 | { | |
240 | if(m_axisY==0){ |
|
239 | return m_axisY; | |
241 | m_axisY = new QChartAxis(this); |
|
240 | } | |
242 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); |
|
|||
243 | return m_axisY; |
|
|||
244 | } |
|
|||
245 |
|
241 | |||
246 | QChartAxis* axis = new QChartAxis(this); |
|
242 | QChartAxis ChartPresenter::axisY(int id) const | |
247 | m_axisItems[axis] = new AxisItem(axis,AxisItem::Y_AXIS,m_chart); |
|
243 | { | |
248 | return axis; |
|
244 | return m_axis.value(id); | |
249 | } |
|
245 | } | |
250 |
|
246 | |||
251 |
|
|
247 | int ChartPresenter::addAxisY(const QChartAxis& axis) | |
252 | { |
|
248 | { | |
253 | AxisItem* item = m_axisItems.take(axis); |
|
249 | int key =0 ; | |
254 | if(item){ |
|
250 | ||
255 | delete item; |
|
251 | while(m_axis.contains(key)){ | |
256 | delete axis; |
|
252 | key++; | |
|
253 | //TODO overflow | |||
257 | } |
|
254 | } | |
258 | //reset pointers to default ones |
|
255 | ||
259 | if(axis == m_axisX) m_axisX=0; |
|
256 | m_axis.insert(key,axis); | |
260 | else if(axis == m_axisY) m_axisY=0; |
|
257 | m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); | |
|
258 | ||||
|
259 | return key; | |||
|
260 | } | |||
|
261 | ||||
|
262 | ||||
|
263 | void ChartPresenter::removeAxisY(int id) | |||
|
264 | { | |||
|
265 | m_axis.remove(id); | |||
|
266 | delete m_axisItems.take(id); | |||
261 | } |
|
267 | } | |
262 |
|
268 | |||
263 | #include "moc_chartpresenter_p.cpp" |
|
269 | #include "moc_chartpresenter_p.cpp" | |
264 |
|
270 | |||
265 | QTCOMMERCIALCHART_END_NAMESPACE |
|
271 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,72 +1,76 | |||||
1 | #ifndef CHARTPRESENTER_H_ |
|
1 | #ifndef CHARTPRESENTER_H_ | |
2 | #define CHARTPRESENTER_H_ |
|
2 | #define CHARTPRESENTER_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO |
|
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |
|
6 | #include "qchartaxis.h" | |||
6 | #include <QRectF> |
|
7 | #include <QRectF> | |
7 |
|
8 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
10 | |||
10 | class ChartItem; |
|
11 | class ChartItem; | |
11 | class QChartSeries; |
|
12 | class QChartSeries; | |
12 | class ChartDataSet; |
|
13 | class ChartDataSet; | |
13 | //class QChart; |
|
14 | //class QChart; | |
14 | class Domain; |
|
15 | class Domain; | |
15 | class AxisItem; |
|
16 | class AxisItem; | |
16 | class ChartTheme; |
|
17 | class ChartTheme; | |
17 |
|
18 | |||
18 | class ChartPresenter: public QObject |
|
19 | class ChartPresenter: public QObject | |
19 | { |
|
20 | { | |
20 | Q_OBJECT |
|
21 | Q_OBJECT | |
21 | public: |
|
22 | public: | |
22 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
23 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
23 | virtual ~ChartPresenter(); |
|
24 | virtual ~ChartPresenter(); | |
24 |
|
25 | |||
25 | void setMargin(int margin); |
|
26 | void setMargin(int margin); | |
26 | int margin() const; |
|
27 | int margin() const; | |
27 |
|
28 | |||
28 | void zoomInToRect(const QRectF& rectangle); |
|
29 | void zoomInToRect(const QRectF& rectangle); | |
29 | void zoomIn(); |
|
30 | void zoomIn(); | |
30 | void zoomOut(); |
|
31 | void zoomOut(); | |
31 | void zoomReset(); |
|
32 | void zoomReset(); | |
32 |
|
33 | |||
33 | void setChartTheme(QChart::ChartTheme theme); |
|
34 | void setChartTheme(QChart::ChartTheme theme); | |
34 | QChart::ChartTheme chartTheme(); |
|
35 | QChart::ChartTheme chartTheme(); | |
35 |
|
36 | |||
36 | QChartAxis* axisX(); |
|
37 | void setDefaultAxisX(const QChartAxis& axis); | |
37 | QChartAxis* axisY(); |
|
38 | void setDefaultAxisY(const QChartAxis& axis); | |
38 |
QChartAxis |
|
39 | QChartAxis defaultAxisX() const; | |
39 |
QChartAxis |
|
40 | QChartAxis defaultAxisY() const; | |
40 | void removeAxis(QChartAxis* axis); |
|
41 | QChartAxis axisY(int id) const; | |
|
42 | int addAxisY(const QChartAxis& axis); | |||
|
43 | void removeAxisY(int id); | |||
41 |
|
44 | |||
42 | private: |
|
45 | private: | |
43 | void createConnections(); |
|
46 | void createConnections(); | |
44 |
|
47 | |||
45 | public slots: |
|
48 | public slots: | |
46 | void handleSeriesAdded(QChartSeries* series); |
|
49 | void handleSeriesAdded(QChartSeries* series); | |
47 | void handleSeriesRemoved(QChartSeries* series){}; |
|
50 | void handleSeriesRemoved(QChartSeries* series){}; | |
48 | void handleSeriesChanged(QChartSeries* series); |
|
51 | void handleSeriesChanged(QChartSeries* series); | |
49 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); |
|
52 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); | |
50 | void handleGeometryChanged(); |
|
53 | void handleGeometryChanged(); | |
51 |
|
||||
52 | signals: |
|
54 | signals: | |
53 | void geometryChanged(const QRectF& rect); |
|
55 | void geometryChanged(const QRectF& rect); | |
54 |
|
||||
55 | private: |
|
56 | private: | |
56 | QMap<QChartSeries*,ChartItem*> m_chartItems; |
|
57 | QMap<QChartSeries*,ChartItem*> m_chartItems; | |
57 |
QMap< |
|
58 | QMap<int,AxisItem*> m_axisItems; | |
|
59 | QMap<int,QChartAxis> m_axis; | |||
58 | QChart* m_chart; |
|
60 | QChart* m_chart; | |
59 | ChartDataSet* m_dataset; |
|
61 | ChartDataSet* m_dataset; | |
60 | QVector<Domain> m_domains; |
|
62 | QVector<Domain> m_domains; | |
61 | ChartTheme *m_chartTheme; |
|
63 | ChartTheme *m_chartTheme; | |
62 |
QChartAxis |
|
64 | QChartAxis m_axisX; | |
63 |
|
|
65 | AxisItem* m_axisXItem; | |
|
66 | QChartAxis m_axisY; | |||
|
67 | AxisItem* m_axisYItem; | |||
64 | int m_domainIndex; |
|
68 | int m_domainIndex; | |
65 | int m_marginSize; |
|
69 | int m_marginSize; | |
66 | QRectF m_rect; |
|
70 | QRectF m_rect; | |
67 |
|
71 | |||
68 | }; |
|
72 | }; | |
69 |
|
73 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
74 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
75 | |||
72 | #endif /* CHARTPRESENTER_H_ */ |
|
76 | #endif /* CHARTPRESENTER_H_ */ |
@@ -1,210 +1,220 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
|
3 | #include "qchartaxis.h" | |||
3 |
|
4 | |||
4 |
|
5 | |||
5 | //series |
|
6 | //series | |
6 | #include "barchartseries.h" |
|
7 | #include "barchartseries.h" | |
7 | #include "stackedbarchartseries.h" |
|
8 | #include "stackedbarchartseries.h" | |
8 | #include "percentbarchartseries.h" |
|
9 | #include "percentbarchartseries.h" | |
9 | #include "qlinechartseries.h" |
|
10 | #include "qlinechartseries.h" | |
10 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
11 |
|
12 | |||
12 | //items |
|
13 | //items | |
13 | #include "axisitem_p.h" |
|
14 | #include "axisitem_p.h" | |
14 | #include "bargroup.h" |
|
15 | #include "bargroup.h" | |
15 | #include "stackedbargroup.h" |
|
16 | #include "stackedbargroup.h" | |
16 | #include "linechartitem_p.h" |
|
17 | #include "linechartitem_p.h" | |
17 | #include "percentbargroup.h" |
|
18 | #include "percentbargroup.h" | |
18 | #include "piepresenter.h" |
|
19 | #include "piepresenter.h" | |
19 |
|
20 | |||
20 | //themes |
|
21 | //themes | |
21 | #include "chartthemevanilla_p.h" |
|
22 | #include "chartthemevanilla_p.h" | |
22 | #include "chartthemeicy_p.h" |
|
23 | #include "chartthemeicy_p.h" | |
23 | #include "chartthemegrayscale_p.h" |
|
24 | #include "chartthemegrayscale_p.h" | |
24 | #include "chartthemescientific_p.h" |
|
25 | #include "chartthemescientific_p.h" | |
25 |
|
26 | |||
26 |
|
27 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
29 | |||
29 | /* TODO |
|
30 | /* TODO | |
30 | case QChart::ChartThemeUnnamed1: |
|
31 | case QChart::ChartThemeUnnamed1: | |
31 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
32 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); | |
32 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
|
33 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); | |
33 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); |
|
34 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); | |
34 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); |
|
35 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); | |
35 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); |
|
36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); | |
36 |
|
37 | |||
37 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
38 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); | |
38 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
39 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
39 | */ |
|
40 | */ | |
40 |
|
41 | |||
41 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
42 | ChartTheme::ChartTheme(QChart::ChartTheme id) | |
42 | { |
|
43 | { | |
43 | m_id = id; |
|
44 | m_id = id; | |
44 | m_seriesColor.append(QRgb(0xff000000)); |
|
45 | m_seriesColor.append(QRgb(0xff000000)); | |
45 | m_seriesColor.append(QRgb(0xff707070)); |
|
46 | m_seriesColor.append(QRgb(0xff707070)); | |
46 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
47 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
47 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
48 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
48 | } |
|
49 | } | |
49 |
|
50 | |||
50 |
|
51 | |||
51 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
52 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
52 | { |
|
53 | { | |
53 | switch(theme) { |
|
54 | switch(theme) { | |
54 | case QChart::ChartThemeDefault: |
|
55 | case QChart::ChartThemeDefault: | |
55 | return new ChartTheme(); |
|
56 | return new ChartTheme(); | |
56 | case QChart::ChartThemeVanilla: |
|
57 | case QChart::ChartThemeVanilla: | |
57 | return new ChartThemeVanilla(); |
|
58 | return new ChartThemeVanilla(); | |
58 | case QChart::ChartThemeIcy: |
|
59 | case QChart::ChartThemeIcy: | |
59 | return new ChartThemeIcy(); |
|
60 | return new ChartThemeIcy(); | |
60 | case QChart::ChartThemeGrayscale: |
|
61 | case QChart::ChartThemeGrayscale: | |
61 | return new ChartThemeGrayscale(); |
|
62 | return new ChartThemeGrayscale(); | |
62 | case QChart::ChartThemeScientific: |
|
63 | case QChart::ChartThemeScientific: | |
63 | return new ChartThemeScientific(); |
|
64 | return new ChartThemeScientific(); | |
64 | } |
|
65 | } | |
65 | } |
|
66 | } | |
66 |
|
67 | |||
67 | void ChartTheme::decorate(QChart* chart) |
|
68 | void ChartTheme::decorate(QChart* chart) | |
68 | { |
|
69 | { | |
69 | QLinearGradient backgroundGradient; |
|
70 | QLinearGradient backgroundGradient; | |
70 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); |
|
71 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); | |
71 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); |
|
72 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); | |
72 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
73 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
73 | chart->setChartBackgroundBrush(backgroundGradient); |
|
74 | chart->setChartBackgroundBrush(backgroundGradient); | |
74 | } |
|
75 | } | |
75 | //TODO helper to by removed later |
|
76 | //TODO helper to by removed later | |
76 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) |
|
77 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) | |
77 | { |
|
78 | { | |
78 | switch(series->type()) |
|
79 | switch(series->type()) | |
79 | { |
|
80 | { | |
80 | case QChartSeries::SeriesTypeLine: { |
|
81 | case QChartSeries::SeriesTypeLine: { | |
81 | QLineChartSeries* s = static_cast<QLineChartSeries*>(series); |
|
82 | QLineChartSeries* s = static_cast<QLineChartSeries*>(series); | |
82 | LineChartItem* i = static_cast<LineChartItem*>(item); |
|
83 | LineChartItem* i = static_cast<LineChartItem*>(item); | |
83 | decorate(i,s,count); |
|
84 | decorate(i,s,count); | |
84 | break; |
|
85 | break; | |
85 | } |
|
86 | } | |
86 | case QChartSeries::SeriesTypeBar: { |
|
87 | case QChartSeries::SeriesTypeBar: { | |
87 | BarChartSeries* b = static_cast<BarChartSeries*>(series); |
|
88 | BarChartSeries* b = static_cast<BarChartSeries*>(series); | |
88 | BarGroup* i = static_cast<BarGroup*>(item); |
|
89 | BarGroup* i = static_cast<BarGroup*>(item); | |
89 | decorate(i,b,count); |
|
90 | decorate(i,b,count); | |
90 | break; |
|
91 | break; | |
91 | } |
|
92 | } | |
92 | case QChartSeries::SeriesTypeStackedBar: { |
|
93 | case QChartSeries::SeriesTypeStackedBar: { | |
93 | StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series); |
|
94 | StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series); | |
94 | StackedBarGroup* i = static_cast<StackedBarGroup*>(item); |
|
95 | StackedBarGroup* i = static_cast<StackedBarGroup*>(item); | |
95 | decorate(i,s,count); |
|
96 | decorate(i,s,count); | |
96 | break; |
|
97 | break; | |
97 | } |
|
98 | } | |
98 | case QChartSeries::SeriesTypePercentBar: { |
|
99 | case QChartSeries::SeriesTypePercentBar: { | |
99 | PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series); |
|
100 | PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series); | |
100 | PercentBarGroup* i = static_cast<PercentBarGroup*>(item); |
|
101 | PercentBarGroup* i = static_cast<PercentBarGroup*>(item); | |
101 | decorate(i,s,count); |
|
102 | decorate(i,s,count); | |
102 | break; |
|
103 | break; | |
103 | } |
|
104 | } | |
104 | case QChartSeries::SeriesTypePie: { |
|
105 | case QChartSeries::SeriesTypePie: { | |
105 | QPieSeries* s = static_cast<QPieSeries*>(series); |
|
106 | QPieSeries* s = static_cast<QPieSeries*>(series); | |
106 | PiePresenter* i = static_cast<PiePresenter*>(item); |
|
107 | PiePresenter* i = static_cast<PiePresenter*>(item); | |
107 | decorate(i,s,count); |
|
108 | decorate(i,s,count); | |
108 | break; |
|
109 | break; | |
109 | } |
|
110 | } | |
110 | default: |
|
111 | default: | |
111 | qDebug()<<"Wrong item to be decorated by theme"; |
|
112 | qDebug()<<"Wrong item to be decorated by theme"; | |
112 | break; |
|
113 | break; | |
113 | } |
|
114 | } | |
114 |
|
115 | |||
115 | } |
|
116 | } | |
116 |
|
117 | |||
117 | void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count) |
|
118 | void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count) | |
118 | { |
|
119 | { | |
119 | QPen pen; |
|
120 | QPen pen; | |
120 | if(pen != series->pen()){ |
|
121 | if(pen != series->pen()){ | |
121 | item->setPen(series->pen()); |
|
122 | item->setPen(series->pen()); | |
122 | return; |
|
123 | return; | |
123 | } |
|
124 | } | |
124 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
125 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
125 | pen.setWidthF(2); |
|
126 | pen.setWidthF(2); | |
126 | item->setPen(pen); |
|
127 | item->setPen(pen); | |
127 | } |
|
128 | } | |
128 |
|
129 | |||
129 | void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) |
|
130 | void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) | |
130 | { |
|
131 | { | |
131 | item->resetColors(); |
|
132 | item->resetColors(); | |
132 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
133 | for (int i=0; i<m_seriesColor.count(); i++) { | |
133 | item->addColor(m_seriesColor.at(i)); |
|
134 | item->addColor(m_seriesColor.at(i)); | |
134 | } |
|
135 | } | |
135 | item->addColor(QColor(255,0,0,128)); |
|
136 | item->addColor(QColor(255,0,0,128)); | |
136 | item->addColor(QColor(255,255,0,128)); |
|
137 | item->addColor(QColor(255,255,0,128)); | |
137 | item->addColor(QColor(0,255,0,128)); |
|
138 | item->addColor(QColor(0,255,0,128)); | |
138 | item->addColor(QColor(0,0,255,128)); |
|
139 | item->addColor(QColor(0,0,255,128)); | |
139 | item->addColor(QColor(255,128,0,128)); |
|
140 | item->addColor(QColor(255,128,0,128)); | |
140 | } |
|
141 | } | |
141 |
|
142 | |||
142 | void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) |
|
143 | void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) | |
143 | { |
|
144 | { | |
144 | item->resetColors(); |
|
145 | item->resetColors(); | |
145 | for (int i=0; i< m_seriesColor.count(); i++) { |
|
146 | for (int i=0; i< m_seriesColor.count(); i++) { | |
146 | item->addColor(m_seriesColor.at(i)); |
|
147 | item->addColor(m_seriesColor.at(i)); | |
147 | } |
|
148 | } | |
148 | item->addColor(QColor(255,0,0,128)); |
|
149 | item->addColor(QColor(255,0,0,128)); | |
149 | item->addColor(QColor(255,255,0,128)); |
|
150 | item->addColor(QColor(255,255,0,128)); | |
150 | item->addColor(QColor(0,255,0,128)); |
|
151 | item->addColor(QColor(0,255,0,128)); | |
151 | item->addColor(QColor(0,0,255,128)); |
|
152 | item->addColor(QColor(0,0,255,128)); | |
152 | item->addColor(QColor(255,128,0,128)); |
|
153 | item->addColor(QColor(255,128,0,128)); | |
153 | } |
|
154 | } | |
154 |
|
155 | |||
155 | void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) |
|
156 | void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) | |
156 | { |
|
157 | { | |
157 | item->resetColors(); |
|
158 | item->resetColors(); | |
158 | for (int i=0; i< m_seriesColor.count(); i++) { |
|
159 | for (int i=0; i< m_seriesColor.count(); i++) { | |
159 | item->addColor(m_seriesColor.at(i)); |
|
160 | item->addColor(m_seriesColor.at(i)); | |
160 | } |
|
161 | } | |
161 | item->addColor(QColor(255,0,0,128)); |
|
162 | item->addColor(QColor(255,0,0,128)); | |
162 | item->addColor(QColor(255,255,0,128)); |
|
163 | item->addColor(QColor(255,255,0,128)); | |
163 | item->addColor(QColor(0,255,0,128)); |
|
164 | item->addColor(QColor(0,255,0,128)); | |
164 | item->addColor(QColor(0,0,255,128)); |
|
165 | item->addColor(QColor(0,0,255,128)); | |
165 | item->addColor(QColor(255,128,0,128)); |
|
166 | item->addColor(QColor(255,128,0,128)); | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) |
|
169 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) | |
169 | { |
|
170 | { | |
170 | // create a list of slice colors based on current theme |
|
171 | // create a list of slice colors based on current theme | |
171 | int i = 0; |
|
172 | int i = 0; | |
172 | QList<QColor> colors; |
|
173 | QList<QColor> colors; | |
173 | while (colors.count() < series->count()) { |
|
174 | while (colors.count() < series->count()) { | |
174 |
|
175 | |||
175 | // get base color |
|
176 | // get base color | |
176 | QColor c = m_seriesColor[i++]; |
|
177 | QColor c = m_seriesColor[i++]; | |
177 | i = i % m_seriesColor.count(); |
|
178 | i = i % m_seriesColor.count(); | |
178 |
|
179 | |||
179 | // -1 means achromatic color -> cannot manipulate lightness |
|
180 | // -1 means achromatic color -> cannot manipulate lightness | |
180 | // TODO: find a better way to randomize lightness |
|
181 | // TODO: find a better way to randomize lightness | |
181 | if (c.toHsv().hue() == -1) |
|
182 | if (c.toHsv().hue() == -1) | |
182 | qWarning() << "ChartTheme::decorate() warning: achromatic theme color"; |
|
183 | qWarning() << "ChartTheme::decorate() warning: achromatic theme color"; | |
183 |
|
184 | |||
184 | // randomize lightness |
|
185 | // randomize lightness | |
185 | qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter |
|
186 | qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter | |
186 | c = c.lighter(f); |
|
187 | c = c.lighter(f); | |
187 |
|
188 | |||
188 | // find duplicates |
|
189 | // find duplicates | |
189 | bool isUnique = true; |
|
190 | bool isUnique = true; | |
190 | foreach (QColor color, colors) { |
|
191 | foreach (QColor color, colors) { | |
191 | if (c == color) |
|
192 | if (c == color) | |
192 | isUnique = false; |
|
193 | isUnique = false; | |
193 | } |
|
194 | } | |
194 |
|
195 | |||
195 | // add to array if unique |
|
196 | // add to array if unique | |
196 | //if (isUnique) |
|
197 | //if (isUnique) | |
197 | colors << c; |
|
198 | colors << c; | |
198 | } |
|
199 | } | |
199 |
|
200 | |||
200 | // finally update colors |
|
201 | // finally update colors | |
201 | foreach (QPieSliceId id, series->ids()) { |
|
202 | foreach (QPieSliceId id, series->ids()) { | |
202 | QPieSlice s = series->slice(id); |
|
203 | QPieSlice s = series->slice(id); | |
203 | s.setPen(QPen(Qt::black)); // TODO: get from theme |
|
204 | s.setPen(QPen(Qt::black)); // TODO: get from theme | |
204 | s.setBrush(colors.takeFirst()); |
|
205 | s.setBrush(colors.takeFirst()); | |
205 | series->update(s); |
|
206 | series->update(s); | |
206 | } |
|
207 | } | |
207 | } |
|
208 | } | |
208 |
|
209 | |||
209 |
|
210 | |||
|
211 | void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) | |||
|
212 | { | |||
|
213 | //TODO: dummy defults for now | |||
|
214 | ||||
|
215 | axis.setLabelsBrush(Qt::black); | |||
|
216 | axis.setLabelsPen(Qt::NoPen); | |||
|
217 | item->handleAxisChanged(axis); | |||
|
218 | } | |||
|
219 | ||||
210 | QTCOMMERCIALCHART_END_NAMESPACE |
|
220 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,48 +1,49 | |||||
1 | #ifndef CHARTTHEME_H |
|
1 | #ifndef CHARTTHEME_H | |
2 | #define CHARTTHEME_H |
|
2 | #define CHARTTHEME_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" |
|
5 | #include "qchart.h" | |
6 | #include <QColor> |
|
6 | #include <QColor> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class ChartItem; |
|
10 | class ChartItem; | |
11 | class QChartSeries; |
|
11 | class QChartSeries; | |
12 | class LineChartItem; |
|
12 | class LineChartItem; | |
13 | class QLineChartSeries; |
|
13 | class QLineChartSeries; | |
14 | class BarGroup; |
|
14 | class BarGroup; | |
15 | class BarChartSeries; |
|
15 | class BarChartSeries; | |
16 | class StackedBarGroup; |
|
16 | class StackedBarGroup; | |
17 | class StackedBarChartSeries; |
|
17 | class StackedBarChartSeries; | |
18 | class PercentBarChartSeries; |
|
18 | class PercentBarChartSeries; | |
19 | class PercentBarGroup; |
|
19 | class PercentBarGroup; | |
20 | class PiePresenter; |
|
20 | class PiePresenter; | |
21 | class QPieSeries; |
|
21 | class QPieSeries; | |
22 |
|
22 | |||
23 | class ChartTheme |
|
23 | class ChartTheme | |
24 | { |
|
24 | { | |
25 | protected: |
|
25 | protected: | |
26 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); |
|
26 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); | |
27 | public: |
|
27 | public: | |
28 | static ChartTheme* createTheme(QChart::ChartTheme theme); |
|
28 | static ChartTheme* createTheme(QChart::ChartTheme theme); | |
29 | QChart::ChartTheme id() const {return m_id;} |
|
29 | QChart::ChartTheme id() const {return m_id;} | |
30 | void decorate(QChart* chart); |
|
30 | void decorate(QChart* chart); | |
31 | void decorate(ChartItem* item, QChartSeries* series,int count); |
|
31 | void decorate(ChartItem* item, QChartSeries* series,int count); | |
32 | void decorate(LineChartItem* item, QLineChartSeries*, int count); |
|
32 | void decorate(LineChartItem* item, QLineChartSeries*, int count); | |
33 | void decorate(BarGroup* item, BarChartSeries* series,int count); |
|
33 | void decorate(BarGroup* item, BarChartSeries* series,int count); | |
34 | void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count); |
|
34 | void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count); | |
35 | void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count); |
|
35 | void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count); | |
36 | void decorate(PiePresenter* item, QPieSeries* series, int count); |
|
36 | void decorate(PiePresenter* item, QPieSeries* series, int count); | |
|
37 | void decorate(QChartAxis& axis,AxisItem* item); | |||
37 |
|
38 | |||
38 | protected: |
|
39 | protected: | |
39 | QChart::ChartTheme m_id; |
|
40 | QChart::ChartTheme m_id; | |
40 | QColor m_gradientStartColor; |
|
41 | QColor m_gradientStartColor; | |
41 | QColor m_gradientEndColor; |
|
42 | QColor m_gradientEndColor; | |
42 | QList<QColor> m_seriesColor; |
|
43 | QList<QColor> m_seriesColor; | |
43 |
|
44 | |||
44 | }; |
|
45 | }; | |
45 |
|
46 | |||
46 | QTCOMMERCIALCHART_END_NAMESPACE |
|
47 | QTCOMMERCIALCHART_END_NAMESPACE | |
47 |
|
48 | |||
48 | #endif // CHARTTHEME_H |
|
49 | #endif // CHARTTHEME_H |
@@ -1,194 +1,204 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qscatterseries.h" |
|
2 | #include "qscatterseries.h" | |
3 | #include "qscatterseries_p.h" |
|
3 | #include "qscatterseries_p.h" | |
4 | #include "qpieseries.h" |
|
4 | #include "qpieseries.h" | |
5 | #include "qchartaxis.h" |
|
5 | #include "qchartaxis.h" | |
6 | #include "chartpresenter_p.h" |
|
6 | #include "chartpresenter_p.h" | |
7 | #include "chartdataset_p.h" |
|
7 | #include "chartdataset_p.h" | |
8 |
|
8 | |||
9 | //series |
|
9 | //series | |
10 | #include "barchartseries.h" |
|
10 | #include "barchartseries.h" | |
11 | #include "stackedbarchartseries.h" |
|
11 | #include "stackedbarchartseries.h" | |
12 | #include "percentbarchartseries.h" |
|
12 | #include "percentbarchartseries.h" | |
13 | #include "qlinechartseries.h" |
|
13 | #include "qlinechartseries.h" | |
14 |
|
14 | |||
15 | #include <QGraphicsScene> |
|
15 | #include <QGraphicsScene> | |
16 | #include <QGraphicsSceneResizeEvent> |
|
16 | #include <QGraphicsSceneResizeEvent> | |
17 | #include <QDebug> |
|
17 | #include <QDebug> | |
18 |
|
18 | |||
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
20 |
|
20 | |||
21 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
21 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
22 | m_backgroundItem(0), |
|
22 | m_backgroundItem(0), | |
23 | m_titleItem(0), |
|
23 | m_titleItem(0), | |
24 | m_dataset(new ChartDataSet(this)), |
|
24 | m_dataset(new ChartDataSet(this)), | |
25 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
25 | m_presenter(new ChartPresenter(this,m_dataset)) | |
26 | { |
|
26 | { | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | QChart::~QChart() {} |
|
29 | QChart::~QChart() {} | |
30 |
|
30 | |||
31 | void QChart::addSeries(QChartSeries* series) |
|
31 | void QChart::addSeries(QChartSeries* series) | |
32 | { |
|
32 | { | |
33 | m_dataset->addSeries(series); |
|
33 | m_dataset->addSeries(series); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | //TODO on review, is it really needed ?? |
|
36 | //TODO on review, is it really needed ?? | |
37 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
37 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
38 | { |
|
38 | { | |
39 | QChartSeries *series(0); |
|
39 | QChartSeries *series(0); | |
40 |
|
40 | |||
41 | switch (type) { |
|
41 | switch (type) { | |
42 | case QChartSeries::SeriesTypeLine: { |
|
42 | case QChartSeries::SeriesTypeLine: { | |
43 | series = new QLineChartSeries(this); |
|
43 | series = new QLineChartSeries(this); | |
44 | break; |
|
44 | break; | |
45 | } |
|
45 | } | |
46 | case QChartSeries::SeriesTypeBar: { |
|
46 | case QChartSeries::SeriesTypeBar: { | |
47 | //series = new BarChartSeries(this); |
|
47 | //series = new BarChartSeries(this); | |
48 | break; |
|
48 | break; | |
49 | } |
|
49 | } | |
50 | case QChartSeries::SeriesTypeStackedBar: { |
|
50 | case QChartSeries::SeriesTypeStackedBar: { | |
51 | //series = new StackedBarChartSeries(this); |
|
51 | //series = new StackedBarChartSeries(this); | |
52 | break; |
|
52 | break; | |
53 | } |
|
53 | } | |
54 | case QChartSeries::SeriesTypePercentBar: { |
|
54 | case QChartSeries::SeriesTypePercentBar: { | |
55 | //series = new PercentBarChartSeries(this); |
|
55 | //series = new PercentBarChartSeries(this); | |
56 | break; |
|
56 | break; | |
57 | } |
|
57 | } | |
58 | case QChartSeries::SeriesTypeScatter: { |
|
58 | case QChartSeries::SeriesTypeScatter: { | |
59 | series = new QScatterSeries(this); |
|
59 | series = new QScatterSeries(this); | |
60 | break; |
|
60 | break; | |
61 | } |
|
61 | } | |
62 | case QChartSeries::SeriesTypePie: { |
|
62 | case QChartSeries::SeriesTypePie: { | |
63 | series = new QPieSeries(this); |
|
63 | series = new QPieSeries(this); | |
64 | break; |
|
64 | break; | |
65 | } |
|
65 | } | |
66 | default: |
|
66 | default: | |
67 | Q_ASSERT(false); |
|
67 | Q_ASSERT(false); | |
68 | break; |
|
68 | break; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | addSeries(series); |
|
71 | addSeries(series); | |
72 | return series; |
|
72 | return series; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
75 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
76 | { |
|
76 | { | |
77 |
|
77 | |||
78 | if(!m_backgroundItem) { |
|
78 | if(!m_backgroundItem) { | |
79 | m_backgroundItem = new QGraphicsRectItem(this); |
|
79 | m_backgroundItem = new QGraphicsRectItem(this); | |
80 | m_backgroundItem->setZValue(-1); |
|
80 | m_backgroundItem->setZValue(-1); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | m_backgroundItem->setBrush(brush); |
|
83 | m_backgroundItem->setBrush(brush); | |
84 | m_backgroundItem->update(); |
|
84 | m_backgroundItem->update(); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
87 | void QChart::setChartBackgroundPen(const QPen& pen) | |
88 | { |
|
88 | { | |
89 |
|
89 | |||
90 | if(!m_backgroundItem) { |
|
90 | if(!m_backgroundItem) { | |
91 | m_backgroundItem = new QGraphicsRectItem(this); |
|
91 | m_backgroundItem = new QGraphicsRectItem(this); | |
92 | m_backgroundItem->setZValue(-1); |
|
92 | m_backgroundItem->setZValue(-1); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | m_backgroundItem->setPen(pen); |
|
95 | m_backgroundItem->setPen(pen); | |
96 | m_backgroundItem->update(); |
|
96 | m_backgroundItem->update(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void QChart::setTitle(const QString& title,const QFont& font) |
|
99 | void QChart::setTitle(const QString& title,const QFont& font) | |
100 | { |
|
100 | { | |
101 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
101 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
102 | m_titleItem->setPlainText(title); |
|
102 | m_titleItem->setPlainText(title); | |
103 | m_titleItem->setFont(font); |
|
103 | m_titleItem->setFont(font); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | int QChart::margin() const |
|
106 | int QChart::margin() const | |
107 | { |
|
107 | { | |
108 | return m_presenter->margin(); |
|
108 | return m_presenter->margin(); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void QChart::setMargin(int margin) |
|
111 | void QChart::setMargin(int margin) | |
112 | { |
|
112 | { | |
113 | m_presenter->setMargin(margin); |
|
113 | m_presenter->setMargin(margin); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
116 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
117 | { |
|
117 | { | |
118 | m_presenter->setChartTheme(theme); |
|
118 | m_presenter->setChartTheme(theme); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | QChart::ChartTheme QChart::chartTheme() const |
|
121 | QChart::ChartTheme QChart::chartTheme() const | |
122 | { |
|
122 | { | |
123 | return m_presenter->chartTheme(); |
|
123 | return m_presenter->chartTheme(); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
126 | void QChart::zoomInToRect(const QRectF& rectangle) | |
127 | { |
|
127 | { | |
128 | m_presenter->zoomInToRect(rectangle); |
|
128 | m_presenter->zoomInToRect(rectangle); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void QChart::zoomIn() |
|
131 | void QChart::zoomIn() | |
132 | { |
|
132 | { | |
133 | m_presenter->zoomIn(); |
|
133 | m_presenter->zoomIn(); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void QChart::zoomOut() |
|
136 | void QChart::zoomOut() | |
137 | { |
|
137 | { | |
138 | m_presenter->zoomOut(); |
|
138 | m_presenter->zoomOut(); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void QChart::zoomReset() |
|
141 | void QChart::zoomReset() | |
142 | { |
|
142 | { | |
143 | m_presenter->zoomReset(); |
|
143 | m_presenter->zoomReset(); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | QChartAxis* QChart::axisX() |
|
146 | void QChart::setDefaultAxisX(const QChartAxis& axis) | |
147 | { |
|
147 | { | |
148 |
|
|
148 | m_presenter->setDefaultAxisX(axis); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | QChartAxis* QChart::axisY() |
|
151 | void QChart::setDefaultAxisY(const QChartAxis& axis) | |
152 | { |
|
152 | { | |
153 |
|
|
153 | m_presenter->setDefaultAxisY(axis); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 |
QChartAxis |
|
156 | QChartAxis QChart::defaultAxisX() const | |
157 | { |
|
157 | { | |
158 |
return m_presenter-> |
|
158 | return m_presenter->defaultAxisX(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 |
QChartAxis |
|
161 | QChartAxis QChart::defaultAxisY() const | |
162 | { |
|
162 | { | |
163 |
return m_presenter-> |
|
163 | return m_presenter->defaultAxisY(); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 |
|
|
166 | int QChart::addAxisY(const QChartAxis& axis) | |
167 | { |
|
167 | { | |
168 |
m_presenter-> |
|
168 | return m_presenter->addAxisY(axis); | |
|
169 | } | |||
|
170 | ||||
|
171 | QChartAxis QChart::axisY(int id) const | |||
|
172 | { | |||
|
173 | return m_presenter->axisY(id); | |||
|
174 | } | |||
|
175 | ||||
|
176 | void QChart::removeAxisY(int id) | |||
|
177 | { | |||
|
178 | m_presenter->removeAxisY(id); | |||
169 | } |
|
179 | } | |
170 |
|
180 | |||
171 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
181 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
172 | { |
|
182 | { | |
173 |
|
183 | |||
174 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
184 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
175 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
185 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
176 |
|
186 | |||
177 | // recalculate title position |
|
187 | // recalculate title position | |
178 | if (m_titleItem) { |
|
188 | if (m_titleItem) { | |
179 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
189 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
180 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
190 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
181 | } |
|
191 | } | |
182 |
|
192 | |||
183 | //recalculate background gradient |
|
193 | //recalculate background gradient | |
184 | if (m_backgroundItem) { |
|
194 | if (m_backgroundItem) { | |
185 | m_backgroundItem->setRect(rect); |
|
195 | m_backgroundItem->setRect(rect); | |
186 | } |
|
196 | } | |
187 |
|
197 | |||
188 | QGraphicsWidget::resizeEvent(event); |
|
198 | QGraphicsWidget::resizeEvent(event); | |
189 | update(); |
|
199 | update(); | |
190 | } |
|
200 | } | |
191 |
|
201 | |||
192 | #include "moc_qchart.cpp" |
|
202 | #include "moc_qchart.cpp" | |
193 |
|
203 | |||
194 | QTCOMMERCIALCHART_END_NAMESPACE |
|
204 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,90 +1,92 | |||||
1 | #ifndef CHART_H |
|
1 | #ifndef CHART_H | |
2 | #define CHART_H |
|
2 | #define CHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QChartSeries; |
|
15 | class QChartSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarGroup; |
|
17 | class BarGroup; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 |
|
23 | |||
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: |
|
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
25 | //class QTCOMMERCIALCHART_EXPORT QChart |
|
25 | //class QTCOMMERCIALCHART_EXPORT QChart | |
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { |
|
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
27 | // public: QChartGraphicsItem(QChart &chart); |
|
27 | // public: QChartGraphicsItem(QChart &chart); | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | * TODO: define the responsibilities |
|
30 | * TODO: define the responsibilities | |
31 | */ |
|
31 | */ | |
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | enum ChartTheme { |
|
36 | enum ChartTheme { | |
37 | /*! The default theme follows the GUI style of the Operating System */ |
|
37 | /*! The default theme follows the GUI style of the Operating System */ | |
38 | ChartThemeDefault, |
|
38 | ChartThemeDefault, | |
39 | ChartThemeVanilla, |
|
39 | ChartThemeVanilla, | |
40 | ChartThemeIcy, |
|
40 | ChartThemeIcy, | |
41 | ChartThemeGrayscale, |
|
41 | ChartThemeGrayscale, | |
42 | ChartThemeScientific, |
|
42 | ChartThemeScientific, | |
43 | //ChartThemeUnnamed1 |
|
43 | //ChartThemeUnnamed1 | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
48 | ~QChart(); |
|
48 | ~QChart(); | |
49 |
|
49 | |||
50 | void addSeries(QChartSeries* series); |
|
50 | void addSeries(QChartSeries* series); | |
51 |
|
51 | |||
52 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); |
|
52 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
53 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... |
|
53 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
54 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
54 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
55 |
|
55 | |||
56 | void setMargin(int margin); |
|
56 | void setMargin(int margin); | |
57 | int margin() const; |
|
57 | int margin() const; | |
58 | void setChartTheme(QChart::ChartTheme theme); |
|
58 | void setChartTheme(QChart::ChartTheme theme); | |
59 | QChart::ChartTheme chartTheme() const; |
|
59 | QChart::ChartTheme chartTheme() const; | |
60 |
|
60 | |||
61 | void setTitle(const QString& title,const QFont& font = QFont()); |
|
61 | void setTitle(const QString& title,const QFont& font = QFont()); | |
62 | void setChartBackgroundBrush(const QBrush& brush); |
|
62 | void setChartBackgroundBrush(const QBrush& brush); | |
63 | void setChartBackgroundPen(const QPen& pen); |
|
63 | void setChartBackgroundPen(const QPen& pen); | |
64 |
|
64 | |||
65 | void zoomInToRect(const QRectF& rectangle); |
|
65 | void zoomInToRect(const QRectF& rectangle); | |
66 | void zoomIn(); |
|
66 | void zoomIn(); | |
67 | void zoomOut(); |
|
67 | void zoomOut(); | |
68 | void zoomReset(); |
|
68 | void zoomReset(); | |
69 |
|
69 | |||
70 | QChartAxis* axisX(); |
|
70 | void setDefaultAxisX(const QChartAxis& axis); | |
71 | QChartAxis* axisY(); |
|
71 | void setDefaultAxisY(const QChartAxis& axis); | |
72 |
QChartAxis |
|
72 | QChartAxis defaultAxisX() const; | |
73 |
QChartAxis |
|
73 | QChartAxis defaultAxisY() const; | |
74 | void removeAxis(QChartAxis* axis); |
|
74 | QChartAxis axisY(int id) const; | |
|
75 | int addAxisY(const QChartAxis& axis); | |||
|
76 | void removeAxisY(int id); | |||
75 |
|
77 | |||
76 | protected: |
|
78 | protected: | |
77 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
79 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
78 |
|
80 | |||
79 | private: |
|
81 | private: | |
80 | Q_DISABLE_COPY(QChart) |
|
82 | Q_DISABLE_COPY(QChart) | |
81 | QGraphicsRectItem* m_backgroundItem; |
|
83 | QGraphicsRectItem* m_backgroundItem; | |
82 | QGraphicsTextItem* m_titleItem; |
|
84 | QGraphicsTextItem* m_titleItem; | |
83 | QRectF m_rect; |
|
85 | QRectF m_rect; | |
84 | ChartDataSet *m_dataset; |
|
86 | ChartDataSet *m_dataset; | |
85 | ChartPresenter *m_presenter; |
|
87 | ChartPresenter *m_presenter; | |
86 | }; |
|
88 | }; | |
87 |
|
89 | |||
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | QTCOMMERCIALCHART_END_NAMESPACE | |
89 |
|
91 | |||
90 | #endif |
|
92 | #endif |
@@ -1,53 +1,86 | |||||
1 |
|
||||
2 |
|
|
1 | #include "qchartaxis.h" | |
3 |
|
2 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
4 | |||
6 |
QChartAxis::QChartAxis( |
|
5 | QChartAxis::QChartAxis(): | |
7 | m_axisVisible(true), |
|
6 | m_axisVisible(true), | |
8 |
m_g |
|
7 | m_gridVisible(true), | |
9 | m_labelsVisible(true), |
|
8 | m_labelsVisible(true), | |
10 |
m_ |
|
9 | m_shadesVisible(true) | |
11 | { |
|
10 | { | |
12 | // TODO Auto-generated constructor stub |
|
11 | // TODO Auto-generated constructor stub | |
13 |
|
12 | |||
14 | } |
|
13 | } | |
15 |
|
14 | |||
16 | QChartAxis::~QChartAxis() |
|
15 | QChartAxis::~QChartAxis() | |
17 | { |
|
16 | { | |
18 | // TODO Auto-generated destructor stub |
|
17 | // TODO Auto-generated destructor stub | |
19 | } |
|
18 | } | |
20 |
|
19 | |||
21 | void QChartAxis::setAxisPen(const QPen& pen) |
|
20 | void QChartAxis::setAxisPen(const QPen& pen) | |
22 | { |
|
21 | { | |
23 |
m_axisPen |
|
22 | m_axisPen=pen; | |
24 | } |
|
23 | } | |
25 |
|
24 | |||
26 | void QChartAxis::setAxisBrush(const QBrush& brush) |
|
25 | void QChartAxis::setAxisBrush(const QBrush& brush) | |
27 | { |
|
26 | { | |
28 |
m_axisBrush |
|
27 | m_axisBrush=brush; | |
29 | } |
|
28 | } | |
30 |
|
29 | |||
31 | void QChartAxis::setAxisVisible(bool visible) |
|
30 | void QChartAxis::setAxisVisible(bool visible) | |
32 | { |
|
31 | { | |
33 | m_axisVisible=visible; |
|
32 | m_axisVisible=visible; | |
34 | } |
|
33 | } | |
35 |
|
34 | |||
36 | void QChartAxis::setGridVisible(bool visible) |
|
35 | void QChartAxis::setGridVisible(bool visible) | |
37 | { |
|
36 | { | |
38 |
m_g |
|
37 | m_gridVisible=visible; | |
|
38 | } | |||
|
39 | ||||
|
40 | void QChartAxis::setGridPen(const QPen& pen) | |||
|
41 | { | |||
|
42 | m_gridPen=pen; | |||
39 | } |
|
43 | } | |
40 |
|
44 | |||
41 | void QChartAxis::setLabelsVisible(bool visible) |
|
45 | void QChartAxis::setLabelsVisible(bool visible) | |
42 | { |
|
46 | { | |
43 | m_labelsVisible=visible; |
|
47 | m_labelsVisible=visible; | |
44 | } |
|
48 | } | |
45 |
|
49 | |||
46 | void QChartAxis::setRowShadesVisible(bool visible) |
|
50 | void QChartAxis::setLabelsPen(const QPen& pen) | |
|
51 | { | |||
|
52 | m_labelsPen=pen; | |||
|
53 | } | |||
|
54 | ||||
|
55 | void QChartAxis::setLabelsBrush(const QBrush& brush) | |||
|
56 | { | |||
|
57 | m_labelsBrush=brush; | |||
|
58 | } | |||
|
59 | ||||
|
60 | void QChartAxis::setLabelsFont(const QFont& font) | |||
|
61 | { | |||
|
62 | m_labelsFont=font; | |||
|
63 | } | |||
|
64 | ||||
|
65 | void QChartAxis::setLabelsOrientation(LabelsOrientation orientation) | |||
|
66 | { | |||
|
67 | m_labelsOrientation=orientation; | |||
|
68 | } | |||
|
69 | ||||
|
70 | void QChartAxis::setShadesVisible(bool visible) | |||
|
71 | { | |||
|
72 | m_shadesVisible=visible; | |||
|
73 | } | |||
|
74 | ||||
|
75 | void QChartAxis::setShadesPen(const QPen& pen) | |||
|
76 | { | |||
|
77 | m_shadesPen=pen; | |||
|
78 | } | |||
|
79 | ||||
|
80 | void QChartAxis::setShadesBrush(const QBrush& brush) | |||
47 | { |
|
81 | { | |
48 | m_rowShadesVisible=visible; |
|
82 | m_shadesBrush=brush; | |
49 | } |
|
83 | } | |
50 |
|
84 | |||
51 | #include "moc_qchartaxis.cpp" |
|
|||
52 |
|
85 | |||
53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,76 +1,76 | |||||
1 | #ifndef QCHARTAXIS_H_ |
|
1 | #ifndef QCHARTAXIS_H_ | |
2 | #define QCHARTAXIS_H_ |
|
2 | #define QCHARTAXIS_H_ | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <QPen> |
|
5 | #include <QPen> | |
|
6 | #include <QFont> | |||
6 |
|
7 | |||
7 |
|
8 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
10 | |||
10 |
class QChartAxis |
|
11 | class QChartAxis | |
11 | { |
|
12 | { | |
12 | Q_OBJECT |
|
|||
13 |
|
||||
14 | Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY axisVisibilityChanged); |
|
|||
15 | Q_PROPERTY(QPen axisPen READ axisPen WRITE setAxisPen NOTIFY axisPenChanged); |
|
|||
16 | Q_PROPERTY(QBrush axisBrush READ axisBrush WRITE setAxisBrush NOTIFY axisBurshChanged); |
|
|||
17 |
|
||||
18 | // Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY axisVisibilityChanged); |
|
|||
19 | public: |
|
13 | public: | |
20 | enum LabelOrientation{ HORIZONTAL, VERTICAL , SLIDE }; |
|
14 | enum LabelsOrientation{ LabelsOrientationHorizontal, LabelsOrientationVertical , LabelsOrientationSlide }; | |
21 |
|
15 | |||
22 |
QChartAxis( |
|
16 | QChartAxis(); | |
23 | virtual ~QChartAxis(); |
|
17 | virtual ~QChartAxis(); | |
24 |
|
18 | |||
25 | //axis |
|
19 | //axis | |
26 | bool isAxisVisible() const { return m_axisVisible;}; |
|
20 | bool isAxisVisible() const { return m_axisVisible;}; | |
27 | void setAxisVisible(bool visible); |
|
21 | void setAxisVisible(bool visible); | |
28 | void setAxisPen(const QPen& pen); |
|
22 | void setAxisPen(const QPen& pen); | |
29 |
|
|
23 | QPen axisPen() const { return m_axisPen;}; | |
30 | void setAxisBrush(const QBrush& brush); |
|
24 | void setAxisBrush(const QBrush& brush); | |
31 |
|
|
25 | QBrush axisBrush() const { return m_axisBrush;}; | |
32 |
|
26 | |||
33 | //grid |
|
27 | //grid | |
34 |
bool isGridVisible() const { return m_g |
|
28 | bool isGridVisible() const { return m_gridVisible;}; | |
35 | void setGridVisible(bool visible); |
|
29 | void setGridVisible(bool visible); | |
|
30 | void setGridPen(const QPen& pen); | |||
|
31 | QPen gridPen() const {return m_gridPen;} | |||
36 |
|
32 | |||
|
33 | //labels | |||
37 | bool isLabelsVisible() const { return m_labelsVisible;}; |
|
34 | bool isLabelsVisible() const { return m_labelsVisible;}; | |
38 | void setLabelsVisible(bool visible); |
|
35 | void setLabelsVisible(bool visible); | |
39 |
|
36 | void setLabelsPen(const QPen& pen); | ||
40 | bool isRowShadesVisible() const { return m_rowShadesVisible;}; |
|
37 | QPen labelsPen() const { return m_labelsPen;} | |
41 | void setRowShadesVisible(bool visible); |
|
38 | void setLabelsBrush(const QBrush& brush); | |
42 |
|
39 | QBrush labelsBrush() const { return m_labelsBrush;} | ||
43 | /* |
|
40 | void setLabelsFont(const QFont& font); | |
44 | void setLabelFont(const QFont& font); |
|
41 | QFont labelFont() const { return m_labelsFont;} | |
45 | const QFont& labelFont(); |
|
42 | void setLabelsOrientation(LabelsOrientation orientation); | |
46 |
|
43 | LabelsOrientation labelsOrientation() const { return m_labelsOrientation;}; | ||
47 | void setLabelPen(const QPen& pen); |
|
44 | ||
48 | const QPen& labelPen(); |
|
45 | //shades | |
49 |
|
46 | bool isShadesVisible() const { return m_shadesVisible;}; | ||
50 | void setGridPen(const QPen& pen); |
|
47 | void setShadesVisible(bool visible); | |
51 |
const QPen& |
|
48 | void setShadesPen(const QPen& pen); | |
52 |
|
49 | QPen shadesPen() const { return m_shadesPen;} | ||
53 |
void set |
|
50 | void setShadesBrush(const QBrush& brush); | |
54 | const QBrush& gridBrush(); |
|
51 | QBrush shadesBrush() const { return m_shadesBrush;} | |
55 | */ |
|
|||
56 |
|
||||
57 |
|
||||
58 | signals: |
|
|||
59 | void axisVisibilityChanged(); |
|
|||
60 | void axisPenChanged(); |
|
|||
61 | void axisBurshChanged(); |
|
|||
62 |
|
52 | |||
63 |
|
53 | |||
64 | private: |
|
54 | private: | |
65 |
|
55 | |||
66 | bool m_axisVisible; |
|
56 | bool m_axisVisible; | |
67 | QPen m_axisPen; |
|
57 | QPen m_axisPen; | |
68 | QBrush m_axisBrush; |
|
58 | QBrush m_axisBrush; | |
69 |
|
59 | |||
70 |
bool m_g |
|
60 | bool m_gridVisible; | |
|
61 | QPen m_gridPen; | |||
|
62 | ||||
71 | bool m_labelsVisible; |
|
63 | bool m_labelsVisible; | |
72 | bool m_rowShadesVisible; |
|
64 | QPen m_labelsPen; | |
|
65 | QBrush m_labelsBrush; | |||
|
66 | QFont m_labelsFont; | |||
|
67 | ||||
|
68 | bool m_shadesVisible; | |||
|
69 | QPen m_shadesPen; | |||
|
70 | QBrush m_shadesBrush; | |||
|
71 | ||||
|
72 | LabelsOrientation m_labelsOrientation; | |||
73 | }; |
|
73 | }; | |
74 |
|
74 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE | |
76 | #endif /* QCHARTAXIS_H_ */ |
|
76 | #endif /* QCHARTAXIS_H_ */ |
@@ -1,227 +1,236 | |||||
1 | #include "qchartview.h" |
|
1 | #include "qchartview.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
|
3 | #include "qchartaxis.h" | |||
3 | #include <QGraphicsView> |
|
4 | #include <QGraphicsView> | |
4 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
5 | #include <QRubberBand> |
|
6 | #include <QRubberBand> | |
6 | #include <QResizeEvent> |
|
7 | #include <QResizeEvent> | |
7 | #include <QDebug> |
|
8 | #include <QDebug> | |
8 |
|
9 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
11 | |||
11 | QChartView::QChartView(QWidget *parent) : |
|
12 | QChartView::QChartView(QWidget *parent) : | |
12 |
|
|
13 | QGraphicsView(parent), | |
13 |
|
|
14 | m_scene(new QGraphicsScene()), | |
14 |
|
|
15 | m_chart(new QChart()), | |
15 |
|
|
16 | m_rubberBand(0), | |
16 |
|
|
17 | m_verticalRubberBand(false), | |
17 |
|
|
18 | m_horizonalRubberBand(false) | |
18 | { |
|
19 | { | |
19 |
|
|
20 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
20 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
21 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
21 | setScene(m_scene); |
|
22 | setScene(m_scene); | |
22 | m_chart->setMargin(50); |
|
23 | m_chart->setMargin(50); | |
23 | m_scene->addItem(m_chart); |
|
24 | m_scene->addItem(m_chart); | |
24 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
25 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
25 | } |
|
26 | } | |
26 |
|
27 | |||
27 | QChartView::~QChartView() |
|
28 | QChartView::~QChartView() | |
28 | { |
|
29 | { | |
29 | } |
|
30 | } | |
30 |
|
31 | |||
31 | void QChartView::resizeEvent(QResizeEvent *event) |
|
32 | void QChartView::resizeEvent(QResizeEvent *event) | |
32 | { |
|
33 | { | |
33 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
34 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
34 | m_chart->resize(size()); |
|
35 | m_chart->resize(size()); | |
35 | QWidget::resizeEvent(event); |
|
36 | QWidget::resizeEvent(event); | |
36 | } |
|
37 | } | |
37 |
|
38 | |||
38 |
|
||||
39 | void QChartView::addSeries(QChartSeries* series) |
|
39 | void QChartView::addSeries(QChartSeries* series) | |
40 | { |
|
40 | { | |
41 | m_chart->addSeries(series); |
|
41 | m_chart->addSeries(series); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) |
|
44 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) | |
45 | { |
|
45 | { | |
46 |
|
46 | |||
47 | return m_chart->createSeries(type); |
|
47 | return m_chart->createSeries(type); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | void QChartView::zoomInToRect(const QRect& rectangle) |
|
50 | void QChartView::zoomInToRect(const QRect& rectangle) | |
51 | { |
|
51 | { | |
52 | m_chart->zoomInToRect(rectangle); |
|
52 | m_chart->zoomInToRect(rectangle); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void QChartView::zoomIn() |
|
55 | void QChartView::zoomIn() | |
56 | { |
|
56 | { | |
57 | m_chart->zoomIn(); |
|
57 | m_chart->zoomIn(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void QChartView::zoomOut() |
|
60 | void QChartView::zoomOut() | |
61 | { |
|
61 | { | |
62 | m_chart->zoomOut(); |
|
62 | m_chart->zoomOut(); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | int QChartView::margin() const |
|
65 | int QChartView::margin() const | |
66 | { |
|
66 | { | |
67 | return m_chart->margin(); |
|
67 | return m_chart->margin(); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void QChartView::setTitle(const QString& title) |
|
70 | void QChartView::setTitle(const QString& title) | |
71 | { |
|
71 | { | |
72 | m_chart->setTitle(title); |
|
72 | m_chart->setTitle(title); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void QChartView::setChartBackgroundBrush(const QBrush& brush) |
|
75 | void QChartView::setChartBackgroundBrush(const QBrush& brush) | |
76 | { |
|
76 | { | |
77 |
|
|
77 | m_chart->setChartBackgroundBrush(brush); | |
78 | } |
|
78 | } | |
79 | void QChartView::setChartBackgroundPen(const QPen& pen) |
|
79 | void QChartView::setChartBackgroundPen(const QPen& pen) | |
80 | { |
|
80 | { | |
81 |
|
|
81 | m_chart->setChartBackgroundPen(pen); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 |
|
||||
85 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) |
|
84 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) | |
86 | { |
|
85 | { | |
87 | switch(policy){ |
|
86 | switch(policy) { | |
88 | case VerticalRubberBand: |
|
87 | case VerticalRubberBand: | |
89 |
|
|
88 | m_verticalRubberBand = true; | |
90 |
|
|
89 | m_horizonalRubberBand = false; | |
91 |
|
|
90 | break; | |
92 | case HorizonalRubberBand: |
|
91 | case HorizonalRubberBand: | |
93 |
|
|
92 | m_verticalRubberBand = false; | |
94 |
|
|
93 | m_horizonalRubberBand = true; | |
95 |
|
|
94 | break; | |
96 | case RectangleRubberBand: |
|
95 | case RectangleRubberBand: | |
97 |
|
|
96 | m_verticalRubberBand = true; | |
98 |
|
|
97 | m_horizonalRubberBand = true; | |
99 |
|
|
98 | break; | |
100 | case NoRubberBand: |
|
99 | case NoRubberBand: | |
101 | default: |
|
100 | default: | |
102 |
|
|
101 | delete m_rubberBand; | |
103 |
|
|
102 | m_rubberBand=0; | |
104 |
|
|
103 | m_horizonalRubberBand = false; | |
105 |
|
|
104 | m_verticalRubberBand = false; | |
106 |
|
|
105 | return; | |
107 | } |
|
106 | } | |
108 | if(!m_rubberBand){ |
|
107 | if(!m_rubberBand) { | |
109 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
108 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
110 | m_rubberBand->setEnabled(true); |
|
109 | m_rubberBand->setEnabled(true); | |
111 | } |
|
110 | } | |
112 | } |
|
111 | } | |
113 |
|
112 | |||
114 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const |
|
113 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const | |
115 | { |
|
114 | { | |
116 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; |
|
115 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; | |
117 | if(m_horizonalRubberBand) return HorizonalRubberBand; |
|
116 | if(m_horizonalRubberBand) return HorizonalRubberBand; | |
118 | if(m_verticalRubberBand) return VerticalRubberBand; |
|
117 | if(m_verticalRubberBand) return VerticalRubberBand; | |
119 | return NoRubberBand; |
|
118 | return NoRubberBand; | |
120 | } |
|
119 | } | |
121 |
|
120 | |||
122 |
|
||||
123 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
121 | void QChartView::mousePressEvent(QMouseEvent *event) | |
124 | { |
|
122 | { | |
125 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
123 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
126 |
|
124 | |||
127 | int margin = m_chart->margin(); |
|
125 | int margin = m_chart->margin(); | |
128 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
126 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
129 |
|
127 | |||
130 | if (rect.contains(event->pos())) { |
|
128 | if (rect.contains(event->pos())) { | |
131 | m_rubberBandOrigin = event->pos(); |
|
129 | m_rubberBandOrigin = event->pos(); | |
132 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); |
|
130 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); | |
133 | m_rubberBand->show(); |
|
131 | m_rubberBand->show(); | |
134 | event->accept(); |
|
132 | event->accept(); | |
135 | } |
|
133 | } | |
136 | } |
|
134 | } | |
137 | } |
|
135 | } | |
138 |
|
136 | |||
139 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
137 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
140 | { |
|
138 | { | |
141 | if(m_rubberBand && m_rubberBand->isVisible()){ |
|
139 | if(m_rubberBand && m_rubberBand->isVisible()) { | |
142 | int margin = m_chart->margin(); |
|
140 | int margin = m_chart->margin(); | |
143 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
141 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
144 | int width = event->pos().x() - m_rubberBandOrigin.x(); |
|
142 | int width = event->pos().x() - m_rubberBandOrigin.x(); | |
145 | int height = event->pos().y() - m_rubberBandOrigin.y(); |
|
143 | int height = event->pos().y() - m_rubberBandOrigin.y(); | |
146 | if(!m_verticalRubberBand) { |
|
144 | if(!m_verticalRubberBand) { | |
147 | m_rubberBandOrigin.setY(rect.top()); |
|
145 | m_rubberBandOrigin.setY(rect.top()); | |
148 | height = rect.height(); |
|
146 | height = rect.height(); | |
149 | } |
|
147 | } | |
150 | if(!m_horizonalRubberBand) { |
|
148 | if(!m_horizonalRubberBand) { | |
151 | m_rubberBandOrigin.setX(rect.left()); |
|
149 | m_rubberBandOrigin.setX(rect.left()); | |
152 | width= rect.width(); |
|
150 | width= rect.width(); | |
153 | } |
|
151 | } | |
154 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); |
|
152 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); | |
155 | } else { |
|
153 | } | |
|
154 | else { | |||
156 | QGraphicsView::mouseMoveEvent(event); |
|
155 | QGraphicsView::mouseMoveEvent(event); | |
157 | } |
|
156 | } | |
158 | } |
|
157 | } | |
159 |
|
158 | |||
160 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
159 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
161 | { |
|
160 | { | |
162 | if(m_rubberBand){ |
|
161 | if(m_rubberBand) { | |
163 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { |
|
162 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { | |
164 | m_rubberBand->hide(); |
|
163 | m_rubberBand->hide(); | |
165 | QRect rect = m_rubberBand->geometry(); |
|
164 | QRect rect = m_rubberBand->geometry(); | |
166 | m_chart->zoomInToRect(rect); |
|
165 | m_chart->zoomInToRect(rect); | |
167 | event->accept(); |
|
166 | event->accept(); | |
168 | } |
|
167 | } | |
169 |
|
168 | |||
170 | if(event->button()==Qt::RightButton) |
|
169 | if(event->button()==Qt::RightButton) | |
171 | m_chart->zoomReset(); |
|
170 | m_chart->zoomReset(); | |
172 |
} |
|
171 | } | |
|
172 | else { | |||
173 | QGraphicsView::mouseReleaseEvent(event); |
|
173 | QGraphicsView::mouseReleaseEvent(event); | |
174 | } |
|
174 | } | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
177 | void QChartView::keyPressEvent(QKeyEvent *event) | |
178 | { |
|
178 | { | |
179 | switch (event->key()) { |
|
179 | switch (event->key()) { | |
180 | case Qt::Key_Plus: |
|
180 | case Qt::Key_Plus: | |
181 | zoomIn(); |
|
181 | zoomIn(); | |
182 | break; |
|
182 | break; | |
183 | case Qt::Key_Minus: |
|
183 | case Qt::Key_Minus: | |
184 | zoomOut(); |
|
184 | zoomOut(); | |
185 | break; |
|
185 | break; | |
186 | default: |
|
186 | default: | |
187 | QGraphicsView::keyPressEvent(event); |
|
187 | QGraphicsView::keyPressEvent(event); | |
188 | break; |
|
188 | break; | |
189 | } |
|
189 | } | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | void QChartView::setChartTheme(QChart::ChartTheme theme) |
|
192 | void QChartView::setChartTheme(QChart::ChartTheme theme) | |
193 | { |
|
193 | { | |
194 | m_chart->setChartTheme(theme); |
|
194 | m_chart->setChartTheme(theme); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | QChart::ChartTheme QChartView::chartTheme() const |
|
197 | QChart::ChartTheme QChartView::chartTheme() const | |
198 | { |
|
198 | { | |
199 | return m_chart->chartTheme(); |
|
199 | return m_chart->chartTheme(); | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | QChartAxis* QChartView::axisX() |
|
202 | void QChartView::setDefaultAxisX(const QChartAxis& axis) | |
|
203 | { | |||
|
204 | m_chart->setDefaultAxisX(axis); | |||
|
205 | } | |||
|
206 | ||||
|
207 | void QChartView::setDefaultAxisY(const QChartAxis& axis) | |||
203 | { |
|
208 | { | |
204 |
|
|
209 | m_chart->setDefaultAxisY(axis); | |
205 | } |
|
210 | } | |
206 |
|
211 | |||
207 |
QChartAxis |
|
212 | QChartAxis QChartView::defaultAxisX() const | |
208 | { |
|
213 | { | |
209 |
return m_chart-> |
|
214 | return m_chart->defaultAxisX(); | |
210 | } |
|
215 | } | |
211 |
|
216 | |||
212 |
QChartAxis |
|
217 | QChartAxis QChartView::defaultAxisY() const | |
213 | { |
|
218 | { | |
214 |
return m_chart-> |
|
219 | return m_chart->defaultAxisY(); | |
215 | } |
|
220 | } | |
216 |
|
221 | |||
217 | QChartAxis* QChartView::addAxisY() |
|
222 | int QChartView::addAxisY(const QChartAxis& axis) | |
218 | { |
|
223 | { | |
219 | return m_chart->addAxisY(); |
|
224 | return m_chart->addAxisY(axis); | |
220 | } |
|
225 | } | |
221 |
|
226 | |||
222 | void QChartView::removeAxis(QChartAxis* axis) |
|
227 | QChartAxis QChartView::axisY(int id) const | |
223 | { |
|
228 | { | |
224 |
m_chart-> |
|
229 | return m_chart->axisY(id); | |
225 | } |
|
230 | } | |
226 |
|
231 | |||
|
232 | void QChartView::removeAxisY(int id) | |||
|
233 | { | |||
|
234 | m_chart->removeAxisY(id); | |||
|
235 | } | |||
227 | QTCOMMERCIALCHART_END_NAMESPACE |
|
236 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,75 +1,77 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartseries.h" |
|
5 | #include "qchartseries.h" | |
6 | #include "qchart.h" |
|
6 | #include "qchart.h" | |
7 | #include <QGraphicsView> |
|
7 | #include <QGraphicsView> | |
8 |
|
8 | |||
9 | class QGraphicsScene; |
|
9 | class QGraphicsScene; | |
10 | class QRubberBand; |
|
10 | class QRubberBand; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class QChart; |
|
14 | class QChart; | |
15 |
|
15 | |||
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
17 | { |
|
17 | { | |
18 | public: |
|
18 | public: | |
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; |
|
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; | |
20 |
|
20 | |||
21 | explicit QChartView(QWidget *parent = 0); |
|
21 | explicit QChartView(QWidget *parent = 0); | |
22 | ~QChartView(); |
|
22 | ~QChartView(); | |
23 |
|
23 | |||
24 | //implement from QWidget |
|
24 | //implement from QWidget | |
25 | void resizeEvent(QResizeEvent *event); |
|
25 | void resizeEvent(QResizeEvent *event); | |
26 |
|
26 | |||
27 | void addSeries(QChartSeries* series); |
|
27 | void addSeries(QChartSeries* series); | |
28 |
|
28 | |||
29 | // Convenience function |
|
29 | // Convenience function | |
30 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
30 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
31 |
|
31 | |||
32 | int margin() const; |
|
32 | int margin() const; | |
33 |
|
33 | |||
34 | void setTitle(const QString& title); |
|
34 | void setTitle(const QString& title); | |
35 | void setChartBackgroundBrush(const QBrush& brush); |
|
35 | void setChartBackgroundBrush(const QBrush& brush); | |
36 | void setChartBackgroundPen(const QPen& pen); |
|
36 | void setChartBackgroundPen(const QPen& pen); | |
37 |
|
37 | |||
38 | void zoomInToRect(const QRect& rectangle); |
|
38 | void zoomInToRect(const QRect& rectangle); | |
39 | void zoomIn(); |
|
39 | void zoomIn(); | |
40 | void zoomOut(); |
|
40 | void zoomOut(); | |
41 |
|
41 | |||
42 | void setRubberBandPolicy(const RubberBandPolicy ); |
|
42 | void setRubberBandPolicy(const RubberBandPolicy ); | |
43 | RubberBandPolicy rubberBandPolicy() const; |
|
43 | RubberBandPolicy rubberBandPolicy() const; | |
44 |
|
44 | |||
45 | void setChartTheme(QChart::ChartTheme theme); |
|
45 | void setChartTheme(QChart::ChartTheme theme); | |
46 | QChart::ChartTheme chartTheme() const; |
|
46 | QChart::ChartTheme chartTheme() const; | |
47 |
|
47 | |||
48 | QChartAxis* axisX(); |
|
48 | void setDefaultAxisX(const QChartAxis& axis); | |
49 | QChartAxis* axisY(); |
|
49 | void setDefaultAxisY(const QChartAxis& axis); | |
50 |
QChartAxis |
|
50 | QChartAxis defaultAxisX() const; | |
51 |
QChartAxis |
|
51 | QChartAxis defaultAxisY() const; | |
52 | void removeAxis(QChartAxis* axis); |
|
52 | QChartAxis axisY(int id) const; | |
|
53 | int addAxisY(const QChartAxis& axis); | |||
|
54 | void removeAxisY(int id); | |||
53 |
|
55 | |||
54 | protected: |
|
56 | protected: | |
55 | void mousePressEvent(QMouseEvent *event); |
|
57 | void mousePressEvent(QMouseEvent *event); | |
56 | void mouseMoveEvent(QMouseEvent *event); |
|
58 | void mouseMoveEvent(QMouseEvent *event); | |
57 | void mouseReleaseEvent(QMouseEvent *event); |
|
59 | void mouseReleaseEvent(QMouseEvent *event); | |
58 | void keyPressEvent(QKeyEvent *event); |
|
60 | void keyPressEvent(QKeyEvent *event); | |
59 |
|
61 | |||
60 |
|
62 | |||
61 | private: |
|
63 | private: | |
62 | QGraphicsScene *m_scene; |
|
64 | QGraphicsScene *m_scene; | |
63 | QChart* m_chart; |
|
65 | QChart* m_chart; | |
64 | QPoint m_rubberBandOrigin; |
|
66 | QPoint m_rubberBandOrigin; | |
65 | QRubberBand* m_rubberBand; |
|
67 | QRubberBand* m_rubberBand; | |
66 | bool m_verticalRubberBand; |
|
68 | bool m_verticalRubberBand; | |
67 | bool m_horizonalRubberBand; |
|
69 | bool m_horizonalRubberBand; | |
68 | Q_DISABLE_COPY(QChartView) |
|
70 | Q_DISABLE_COPY(QChartView) | |
69 |
|
71 | |||
70 |
|
72 | |||
71 | }; |
|
73 | }; | |
72 |
|
74 | |||
73 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE | |
74 |
|
76 | |||
75 | #endif // QCHARTWIDGET_H |
|
77 | #endif // QCHARTWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now