@@ -1,238 +1,246 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "grid.h" |
|
21 | #include "grid.h" | |
22 | #include "charts.h" |
|
22 | #include "charts.h" | |
23 | #include <qchart.h> |
|
23 | #include <qchart.h> | |
24 | #include <QGraphicsGridLayout> |
|
24 | #include <QGraphicsGridLayout> | |
25 | #include <QGraphicsSceneMouseEvent> |
|
25 | #include <QGraphicsSceneMouseEvent> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | Grid::Grid(int size,QGraphicsItem *parent):QGraphicsWidget(parent), |
|
28 | Grid::Grid(int size,QGraphicsItem *parent):QGraphicsWidget(parent), | |
29 | m_listCount(3), |
|
29 | m_listCount(3), | |
30 | m_valueMax(10), |
|
30 | m_valueMax(10), | |
31 | m_valueCount(7), |
|
31 | m_valueCount(7), | |
32 | m_size(size), |
|
32 | m_size(size), | |
33 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), |
|
33 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), | |
|
34 | m_state(NoState), | |||
|
35 | m_currentState(NoState), | |||
34 | m_rubberBand(new QGraphicsRectItem()), |
|
36 | m_rubberBand(new QGraphicsRectItem()), | |
35 | m_gridLayout(new QGraphicsGridLayout()) |
|
37 | m_gridLayout(new QGraphicsGridLayout()) | |
36 | { |
|
38 | { | |
37 | setLayout(m_gridLayout); |
|
39 | setLayout(m_gridLayout); | |
38 | m_rubberBand->setParentItem(this); |
|
40 | m_rubberBand->setParentItem(this); | |
39 | m_rubberBand->setVisible(false); |
|
41 | m_rubberBand->setVisible(false); | |
40 | m_rubberBand->setZValue(2); |
|
42 | m_rubberBand->setZValue(2); | |
41 | } |
|
43 | } | |
42 |
|
44 | |||
43 | Grid::~Grid() |
|
45 | Grid::~Grid() | |
44 | { |
|
46 | { | |
45 |
|
47 | |||
46 | } |
|
48 | } | |
47 |
|
49 | |||
48 | void Grid::createCharts() |
|
|||
49 | { |
|
|||
50 | clear(); |
|
|||
51 |
|
||||
52 | Charts::ChartList list = Charts::chartList(); |
|
|||
53 |
|
||||
54 | for (int i = 0; i < m_size * m_size; ++i) { |
|
|||
55 | QChart *chart = 0; |
|
|||
56 | if (i < list.size()) { |
|
|||
57 | chart = list.at(i)->createChart(m_dataTable); |
|
|||
58 | } |
|
|||
59 | else { |
|
|||
60 | chart = new QChart(); |
|
|||
61 | chart->setTitle(QObject::tr("Empty")); |
|
|||
62 | } |
|
|||
63 |
|
||||
64 | m_gridLayout->addItem(chart, i / m_size, i % m_size); |
|
|||
65 | m_chartHash[chart] = i; |
|
|||
66 | } |
|
|||
67 |
|
||||
68 | } |
|
|||
69 |
|
||||
70 | void Grid::createCharts(const QString& category) |
|
50 | void Grid::createCharts(const QString& category) | |
71 | { |
|
51 | { | |
72 | clear(); |
|
52 | clear(); | |
73 |
|
53 | |||
74 | QChart *qchart(0); |
|
54 | QChart *qchart(0); | |
75 | Charts::ChartList list = Charts::chartList(); |
|
55 | Charts::ChartList list = Charts::chartList(); | |
76 |
|
56 | |||
77 | int j = 0; |
|
57 | if (category.isEmpty()) { | |
78 | for (int i = 0; i < list.size(); ++i) { |
|
58 | ||
79 | Chart *chart = list.at(i); |
|
59 | for (int i = 0; i < m_size * m_size; ++i) { | |
80 | if (chart->category() == category && j < m_size * m_size) { |
|
60 | QChart *chart = 0; | |
81 | qchart = list.at(i)->createChart(m_dataTable); |
|
61 | if (i < list.size()) { | |
|
62 | chart = list.at(i)->createChart(m_dataTable); | |||
|
63 | } | |||
|
64 | else { | |||
|
65 | chart = new QChart(); | |||
|
66 | chart->setTitle(QObject::tr("Empty")); | |||
|
67 | } | |||
|
68 | ||||
|
69 | m_gridLayout->addItem(chart, i / m_size, i % m_size); | |||
|
70 | m_chartHash[chart] = i; | |||
|
71 | } | |||
|
72 | } | |||
|
73 | else { | |||
|
74 | ||||
|
75 | int j = 0; | |||
|
76 | for (int i = 0; i < list.size(); ++i) { | |||
|
77 | Chart *chart = list.at(i); | |||
|
78 | if (chart->category() == category && j < m_size * m_size) { | |||
|
79 | qchart = list.at(i)->createChart(m_dataTable); | |||
|
80 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); | |||
|
81 | m_chartHash[qchart] = j; | |||
|
82 | j++; | |||
|
83 | } | |||
|
84 | } | |||
|
85 | for (; j < m_size * m_size; ++j) { | |||
|
86 | qchart = new QChart(); | |||
|
87 | qchart->setTitle(QObject::tr("Empty")); | |||
82 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); |
|
88 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); | |
83 | m_chartHash[qchart] = j; |
|
89 | m_chartHash[qchart] = j; | |
84 | j++; |
|
|||
85 | } |
|
90 | } | |
86 | } |
|
91 | } | |
87 | for (; j < m_size * m_size; ++j) { |
|
92 | m_category = category; | |
88 | qchart = new QChart(); |
|
|||
89 | qchart->setTitle(QObject::tr("Empty")); |
|
|||
90 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); |
|
|||
91 | m_chartHash[qchart] = j; |
|
|||
92 | } |
|
|||
93 |
|
||||
94 | m_gridLayout->activate(); |
|
93 | m_gridLayout->activate(); | |
95 | } |
|
94 | } | |
96 |
|
95 | |||
97 | void Grid::clear() |
|
96 | void Grid::clear() | |
98 | { |
|
97 | { | |
99 | for (int i = 0; i < m_gridLayout->count(); ++i) { |
|
98 | for (int i = 0; i < m_gridLayout->count(); ++i) { | |
100 | m_gridLayout->removeAt(i); |
|
99 | m_gridLayout->removeAt(i); | |
101 | } |
|
100 | } | |
102 |
|
101 | |||
103 | qDeleteAll(m_chartHash.keys()); |
|
102 | qDeleteAll(m_chartHash.keys()); | |
104 | m_chartHash.clear(); |
|
103 | m_chartHash.clear(); | |
105 | } |
|
104 | } | |
106 |
|
105 | |||
107 | QList<QChart*> Grid::charts() |
|
106 | QList<QChart*> Grid::charts() | |
108 | { |
|
107 | { | |
109 | return m_chartHash.keys(); |
|
108 | return m_chartHash.keys(); | |
110 | } |
|
109 | } | |
111 |
|
110 | |||
112 | void Grid::setState(State state) |
|
111 | void Grid::setState(State state) | |
113 | { |
|
112 | { | |
114 | m_state = state; |
|
113 | m_state = state; | |
115 | } |
|
114 | } | |
116 |
|
115 | |||
|
116 | void Grid::setSize(int size) | |||
|
117 | { | |||
|
118 | if(m_size !=size) | |||
|
119 | { | |||
|
120 | m_size = size; | |||
|
121 | createCharts(m_category); | |||
|
122 | } | |||
|
123 | } | |||
|
124 | ||||
117 | void Grid::setRubberPen(const QPen& pen) |
|
125 | void Grid::setRubberPen(const QPen& pen) | |
118 | { |
|
126 | { | |
119 | m_rubberBand->setPen(pen); |
|
127 | m_rubberBand->setPen(pen); | |
120 | } |
|
128 | } | |
121 |
|
129 | |||
122 | void Grid::replaceChart(QChart* oldChart, Chart* newChart) |
|
130 | void Grid::replaceChart(QChart* oldChart, Chart* newChart) | |
123 | { |
|
131 | { | |
124 | int index = m_chartHash[oldChart]; |
|
132 | int index = m_chartHash[oldChart]; | |
125 | //not in 4.7.2 m_baseLayout->removeItem(qchart); |
|
133 | //not in 4.7.2 m_baseLayout->removeItem(qchart); | |
126 | for (int i = 0; i < m_gridLayout->count(); ++i) { |
|
134 | for (int i = 0; i < m_gridLayout->count(); ++i) { | |
127 | if (m_gridLayout->itemAt(i) == oldChart) { |
|
135 | if (m_gridLayout->itemAt(i) == oldChart) { | |
128 | m_gridLayout->removeAt(i); |
|
136 | m_gridLayout->removeAt(i); | |
129 | break; |
|
137 | break; | |
130 | } |
|
138 | } | |
131 | } |
|
139 | } | |
132 | m_chartHash.remove(oldChart); |
|
140 | m_chartHash.remove(oldChart); | |
133 | QChart *chart = newChart->createChart(m_dataTable); |
|
141 | QChart *chart = newChart->createChart(m_dataTable); | |
134 | m_gridLayout->addItem(chart, index / m_size, index % m_size); |
|
142 | m_gridLayout->addItem(chart, index / m_size, index % m_size); | |
135 | m_chartHash[chart] = index; |
|
143 | m_chartHash[chart] = index; | |
136 | delete oldChart; |
|
144 | delete oldChart; | |
137 | } |
|
145 | } | |
138 |
|
146 | |||
139 | void Grid::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
147 | void Grid::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
140 | { |
|
148 | { | |
141 | if (event->button() == Qt::LeftButton) { |
|
149 | if (event->button() == Qt::LeftButton) { | |
142 |
|
150 | |||
143 | m_origin = event->pos(); |
|
151 | m_origin = event->pos(); | |
144 | m_currentState = NoState; |
|
152 | m_currentState = NoState; | |
145 |
|
153 | |||
146 | foreach (QChart *chart, charts()) { |
|
154 | foreach (QChart *chart, charts()) { | |
147 |
|
155 | |||
148 | QRectF geometryRect = chart->geometry(); |
|
156 | QRectF geometryRect = chart->geometry(); | |
149 | QRectF plotArea = chart->plotArea(); |
|
157 | QRectF plotArea = chart->plotArea(); | |
150 | plotArea.translate(geometryRect.topLeft()); |
|
158 | plotArea.translate(geometryRect.topLeft()); | |
151 | if (plotArea.contains(m_origin)) { |
|
159 | if (plotArea.contains(m_origin)) { | |
152 | m_currentState = m_state; |
|
160 | m_currentState = m_state; | |
153 | if (m_currentState == NoState) emit chartSelected(chart); |
|
161 | if (m_currentState == NoState) emit chartSelected(chart); | |
154 | break; |
|
162 | break; | |
155 | } |
|
163 | } | |
156 | } |
|
164 | } | |
157 | if (m_currentState == ZoomState) { |
|
165 | if (m_currentState == ZoomState) { | |
158 | m_rubberBand->setRect(QRectF(m_origin, QSize())); |
|
166 | m_rubberBand->setRect(QRectF(m_origin, QSize())); | |
159 | m_rubberBand->setVisible(true); |
|
167 | m_rubberBand->setVisible(true); | |
160 | } |
|
168 | } | |
161 |
|
169 | |||
162 | event->accept(); |
|
170 | event->accept(); | |
163 | } |
|
171 | } | |
164 |
|
172 | |||
165 | if (event->button() == Qt::RightButton) { |
|
173 | if (event->button() == Qt::RightButton) { | |
166 | m_origin = event->pos(); |
|
174 | m_origin = event->pos(); | |
167 | m_currentState = m_state; |
|
175 | m_currentState = m_state; | |
168 | } |
|
176 | } | |
169 | } |
|
177 | } | |
170 |
|
178 | |||
171 | void Grid::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
179 | void Grid::mouseMoveEvent(QGraphicsSceneMouseEvent *event) | |
172 | { |
|
180 | { | |
173 | if (m_currentState != NoState) { |
|
181 | if (m_currentState != NoState) { | |
174 |
|
182 | |||
175 | foreach (QChart *chart, charts()) { |
|
183 | foreach (QChart *chart, charts()) { | |
176 |
|
184 | |||
177 | QRectF geometryRect = chart->geometry(); |
|
185 | QRectF geometryRect = chart->geometry(); | |
178 | QRectF plotArea = chart->plotArea(); |
|
186 | QRectF plotArea = chart->plotArea(); | |
179 | plotArea.translate(geometryRect.topLeft()); |
|
187 | plotArea.translate(geometryRect.topLeft()); | |
180 |
|
188 | |||
181 | if (plotArea.contains(m_origin)) { |
|
189 | if (plotArea.contains(m_origin)) { | |
182 | if (m_currentState == ScrollState) { |
|
190 | if (m_currentState == ScrollState) { | |
183 | QPointF delta = m_origin - event->pos(); |
|
191 | QPointF delta = m_origin - event->pos(); | |
184 | chart->scroll(delta.x(), -delta.y()); |
|
192 | chart->scroll(delta.x(), -delta.y()); | |
185 | } |
|
193 | } | |
186 | if (m_currentState == ZoomState && plotArea.contains(event->pos())) |
|
194 | if (m_currentState == ZoomState && plotArea.contains(event->pos())) | |
187 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); |
|
195 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); | |
188 | break; |
|
196 | break; | |
189 | } |
|
197 | } | |
190 | } |
|
198 | } | |
191 | if (m_currentState == ScrollState) |
|
199 | if (m_currentState == ScrollState) | |
192 | m_origin = event->pos(); |
|
200 | m_origin = event->pos(); | |
193 | event->accept(); |
|
201 | event->accept(); | |
194 | } |
|
202 | } | |
195 | } |
|
203 | } | |
196 |
|
204 | |||
197 | void Grid::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
205 | void Grid::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |
198 | { |
|
206 | { | |
199 | if (event->button() == Qt::LeftButton) { |
|
207 | if (event->button() == Qt::LeftButton) { | |
200 | if (m_currentState == ZoomState) { |
|
208 | if (m_currentState == ZoomState) { | |
201 | m_rubberBand->setVisible(false); |
|
209 | m_rubberBand->setVisible(false); | |
202 |
|
210 | |||
203 | foreach (QChart *chart, charts()) { |
|
211 | foreach (QChart *chart, charts()) { | |
204 |
|
212 | |||
205 | QRectF geometryRect = chart->geometry(); |
|
213 | QRectF geometryRect = chart->geometry(); | |
206 | QRectF plotArea = chart->plotArea(); |
|
214 | QRectF plotArea = chart->plotArea(); | |
207 | plotArea.translate(geometryRect.topLeft()); |
|
215 | plotArea.translate(geometryRect.topLeft()); | |
208 |
|
216 | |||
209 | if (plotArea.contains(m_origin)) { |
|
217 | if (plotArea.contains(m_origin)) { | |
210 | QRectF rect = m_rubberBand->rect(); |
|
218 | QRectF rect = m_rubberBand->rect(); | |
211 | rect.translate(-geometryRect.topLeft()); |
|
219 | rect.translate(-geometryRect.topLeft()); | |
212 | chart->zoomIn(rect); |
|
220 | chart->zoomIn(rect); | |
213 | break; |
|
221 | break; | |
214 | } |
|
222 | } | |
215 | } |
|
223 | } | |
216 | } |
|
224 | } | |
217 |
|
225 | |||
218 | m_currentState = NoState; |
|
226 | m_currentState = NoState; | |
219 | event->accept(); |
|
227 | event->accept(); | |
220 | } |
|
228 | } | |
221 |
|
229 | |||
222 | if (event->button() == Qt::RightButton) { |
|
230 | if (event->button() == Qt::RightButton) { | |
223 |
|
231 | |||
224 | if (m_currentState == ZoomState) { |
|
232 | if (m_currentState == ZoomState) { | |
225 | foreach (QChart *chart, charts()) { |
|
233 | foreach (QChart *chart, charts()) { | |
226 |
|
234 | |||
227 | QRectF geometryRect = chart->geometry(); |
|
235 | QRectF geometryRect = chart->geometry(); | |
228 | QRectF plotArea = chart->plotArea(); |
|
236 | QRectF plotArea = chart->plotArea(); | |
229 | plotArea.translate(geometryRect.topLeft()); |
|
237 | plotArea.translate(geometryRect.topLeft()); | |
230 |
|
238 | |||
231 | if (plotArea.contains(m_origin)) { |
|
239 | if (plotArea.contains(m_origin)) { | |
232 | chart->zoomOut(); |
|
240 | chart->zoomOut(); | |
233 | break; |
|
241 | break; | |
234 | } |
|
242 | } | |
235 | } |
|
243 | } | |
236 | } |
|
244 | } | |
237 | } |
|
245 | } | |
238 | } |
|
246 | } |
@@ -1,75 +1,75 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef GRID_H_ |
|
21 | #ifndef GRID_H_ | |
22 | #define GRID_H_ |
|
22 | #define GRID_H_ | |
23 |
|
23 | |||
24 | #include "model.h" |
|
24 | #include "model.h" | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 | #include <QChartGlobal> |
|
26 | #include <QChartGlobal> | |
27 |
|
27 | |||
28 | class QGraphicsGridLayout; |
|
28 | class QGraphicsGridLayout; | |
29 | class GridControl; |
|
|||
30 | class Chart; |
|
29 | class Chart; | |
31 |
|
30 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 | class QChart; |
|
32 | class QChart; | |
34 | QTCOMMERCIALCHART_END_NAMESPACE |
|
33 | QTCOMMERCIALCHART_END_NAMESPACE | |
35 |
|
34 | |||
36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
35 | QTCOMMERCIALCHART_USE_NAMESPACE | |
37 |
|
36 | |||
38 | class Grid : public QGraphicsWidget |
|
37 | class Grid : public QGraphicsWidget | |
39 | { |
|
38 | { | |
40 | Q_OBJECT |
|
39 | Q_OBJECT | |
41 | public: |
|
40 | public: | |
42 | enum State { NoState = 0, ZoomState, ScrollState}; |
|
41 | enum State { NoState = 0, ZoomState, ScrollState}; | |
43 | Grid(int size , QGraphicsItem *parent = 0 ); |
|
42 | Grid(int size , QGraphicsItem *parent = 0 ); | |
44 | ~Grid(); |
|
43 | ~Grid(); | |
45 | QList<QChart*> charts(); |
|
44 | QList<QChart*> charts(); | |
46 | void createCharts(); |
|
45 | void createCharts(const QString& category = QString()); | |
47 | void createCharts(const QString& category); |
|
|||
48 | void replaceChart(QChart* oldChart, Chart* newChart); |
|
46 | void replaceChart(QChart* oldChart, Chart* newChart); | |
49 | void setState(State state); |
|
47 | void setState(State state); | |
50 | State state(){ return m_state; }; |
|
48 | State state() const { return m_state; }; | |
51 | void setRubberPen(const QPen& pen); |
|
49 | void setRubberPen(const QPen& pen); | |
|
50 | void setSize(int size); | |||
|
51 | int size() const {return m_size;} | |||
52 | Q_SIGNAL |
|
52 | Q_SIGNAL | |
53 | void chartSelected(QChart* chart); |
|
53 | void chartSelected(QChart* chart); | |
54 | protected: |
|
54 | protected: | |
55 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
55 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
56 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
|
56 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event); | |
57 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
|
57 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); | |
58 | private: |
|
58 | private: | |
59 | void clear(); |
|
59 | void clear(); | |
60 | private: |
|
60 | private: | |
61 | int m_listCount; |
|
61 | int m_listCount; | |
62 | int m_valueMax; |
|
62 | int m_valueMax; | |
63 | int m_valueCount; |
|
63 | int m_valueCount; | |
64 | int m_size; |
|
64 | int m_size; | |
65 | DataTable m_dataTable; |
|
65 | DataTable m_dataTable; | |
66 | QHash<QChart *, int> m_chartHash; |
|
66 | QHash<QChart *, int> m_chartHash; | |
67 | GridControl* m_control; |
|
|||
68 | State m_state; |
|
67 | State m_state; | |
69 | State m_currentState; |
|
68 | State m_currentState; | |
70 | QPointF m_origin; |
|
69 | QPointF m_origin; | |
71 | QGraphicsRectItem *m_rubberBand; |
|
70 | QGraphicsRectItem *m_rubberBand; | |
72 | QGraphicsGridLayout* m_gridLayout; |
|
71 | QGraphicsGridLayout* m_gridLayout; | |
|
72 | QString m_category; | |||
73 | }; |
|
73 | }; | |
74 |
|
74 | |||
75 | #endif /* GRID_H_ */ |
|
75 | #endif /* GRID_H_ */ |
@@ -1,448 +1,484 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "window.h" |
|
21 | #include "window.h" | |
22 | #include "view.h" |
|
22 | #include "view.h" | |
23 | #include "grid.h" |
|
23 | #include "grid.h" | |
24 | #include "charts.h" |
|
24 | #include "charts.h" | |
25 | #include <QChartView> |
|
25 | #include <QChartView> | |
26 | #include <QAreaSeries> |
|
26 | #include <QAreaSeries> | |
27 | #include <QLegend> |
|
27 | #include <QLegend> | |
28 | #include <QGridLayout> |
|
28 | #include <QGridLayout> | |
29 | #include <QFormLayout> |
|
29 | #include <QFormLayout> | |
30 | #include <QComboBox> |
|
30 | #include <QComboBox> | |
31 | #include <QSpinBox> |
|
31 | #include <QSpinBox> | |
32 | #include <QCheckBox> |
|
32 | #include <QCheckBox> | |
33 | #include <QGroupBox> |
|
33 | #include <QGroupBox> | |
34 | #include <QLabel> |
|
34 | #include <QLabel> | |
35 | #include <QGraphicsScene> |
|
35 | #include <QGraphicsScene> | |
36 | #include <QGraphicsLinearLayout> |
|
36 | #include <QGraphicsLinearLayout> | |
37 | #include <QGraphicsProxyWidget> |
|
37 | #include <QGraphicsProxyWidget> | |
38 | #include <QGLWidget> |
|
38 | #include <QGLWidget> | |
39 | #include <QApplication> |
|
39 | #include <QApplication> | |
40 | #include <QDebug> |
|
40 | #include <QDebug> | |
41 | #include <QMenu> |
|
41 | #include <QMenu> | |
|
42 | #include <QPushButton> | |||
42 |
|
43 | |||
43 | Window::Window(const QVariantHash& parameters,QWidget *parent) : |
|
44 | Window::Window(const QVariantHash& parameters,QWidget *parent) : | |
44 | QMainWindow(parent), |
|
45 | QMainWindow(parent), | |
45 | m_scene(new QGraphicsScene(this)), |
|
46 | m_scene(new QGraphicsScene(this)), | |
46 | m_view(0), |
|
47 | m_view(0), | |
47 | m_form(0), |
|
48 | m_form(0), | |
48 | m_themeComboBox(0), |
|
49 | m_themeComboBox(0), | |
49 | m_antialiasCheckBox(0), |
|
50 | m_antialiasCheckBox(0), | |
50 | m_animatedComboBox(0), |
|
51 | m_animatedComboBox(0), | |
51 | m_legendComboBox(0), |
|
52 | m_legendComboBox(0), | |
52 | m_templateComboBox(0), |
|
53 | m_templateComboBox(0), | |
|
54 | m_viewComboBox(0), | |||
53 | m_openGLCheckBox(0), |
|
55 | m_openGLCheckBox(0), | |
54 | m_zoomCheckBox(0), |
|
56 | m_zoomCheckBox(0), | |
55 | m_scrollCheckBox(0), |
|
57 | m_scrollCheckBox(0), | |
56 | m_baseLayout(new QGraphicsLinearLayout()), |
|
58 | m_baseLayout(new QGraphicsLinearLayout()), | |
57 | m_menu(createMenu()), |
|
59 | m_menu(createMenu()), | |
58 | m_template(0), |
|
60 | m_template(0), | |
59 |
m_grid(new Grid( |
|
61 | m_grid(new Grid(1)) | |
60 | { |
|
62 | { | |
61 | createProxyWidgets(); |
|
63 | createProxyWidgets(); | |
62 | // create layout |
|
64 | // create layout | |
63 | QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); |
|
65 | QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); | |
|
66 | ||||
64 | settingsLayout->setOrientation(Qt::Vertical); |
|
67 | settingsLayout->setOrientation(Qt::Vertical); | |
65 | settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
68 | settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
66 | settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); |
|
69 | settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); | |
67 | settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); |
|
70 | settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); | |
|
71 | settingsLayout->addItem(m_widgetHash["viewLabel"]); | |||
|
72 | settingsLayout->addItem(m_widgetHash["viewComboBox"]); | |||
68 | settingsLayout->addItem(m_widgetHash["themeLabel"]); |
|
73 | settingsLayout->addItem(m_widgetHash["themeLabel"]); | |
69 | settingsLayout->addItem(m_widgetHash["themeComboBox"]); |
|
74 | settingsLayout->addItem(m_widgetHash["themeComboBox"]); | |
70 | settingsLayout->addItem(m_widgetHash["animationsLabel"]); |
|
75 | settingsLayout->addItem(m_widgetHash["animationsLabel"]); | |
71 | settingsLayout->addItem(m_widgetHash["animatedComboBox"]); |
|
76 | settingsLayout->addItem(m_widgetHash["animatedComboBox"]); | |
72 | settingsLayout->addItem(m_widgetHash["legendLabel"]); |
|
77 | settingsLayout->addItem(m_widgetHash["legendLabel"]); | |
73 | settingsLayout->addItem(m_widgetHash["legendComboBox"]); |
|
78 | settingsLayout->addItem(m_widgetHash["legendComboBox"]); | |
74 | settingsLayout->addItem(m_widgetHash["templateLabel"]); |
|
79 | settingsLayout->addItem(m_widgetHash["templateLabel"]); | |
75 | settingsLayout->addItem(m_widgetHash["templateComboBox"]); |
|
80 | settingsLayout->addItem(m_widgetHash["templateComboBox"]); | |
76 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); |
|
81 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); | |
77 | settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); |
|
82 | settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); | |
78 | settingsLayout->addStretch(); |
|
83 | settingsLayout->addStretch(); | |
79 |
|
84 | |||
80 | m_grid->createCharts(); |
|
85 | m_grid->createCharts(); | |
81 |
|
86 | |||
82 | m_baseLayout->setOrientation(Qt::Horizontal); |
|
87 | m_baseLayout->setOrientation(Qt::Horizontal); | |
83 | m_baseLayout->addItem(m_grid); |
|
88 | m_baseLayout->addItem(m_grid); | |
84 | m_baseLayout->addItem(settingsLayout); |
|
89 | m_baseLayout->addItem(settingsLayout); | |
85 |
|
90 | |||
86 | m_form = new QGraphicsWidget(); |
|
91 | m_form = new QGraphicsWidget(); | |
87 | m_form->setLayout(m_baseLayout); |
|
92 | m_form->setLayout(m_baseLayout); | |
88 | m_scene->addItem(m_form); |
|
93 | m_scene->addItem(m_form); | |
89 |
|
94 | |||
90 | m_view = new View(m_scene, m_form); |
|
95 | m_view = new View(m_scene, m_form); | |
91 | m_view->setMinimumSize(m_form->minimumSize().toSize()); |
|
96 | m_view->setMinimumSize(m_form->minimumSize().toSize()); | |
92 |
|
97 | |||
93 | // Set defaults |
|
98 | // Set defaults | |
94 | m_antialiasCheckBox->setChecked(true); |
|
99 | m_antialiasCheckBox->setChecked(true); | |
95 | initializeFromParamaters(parameters); |
|
100 | initializeFromParamaters(parameters); | |
96 | updateUI(); |
|
101 | updateUI(); | |
|
102 | handleGeometryChanged(); | |||
97 | setCentralWidget(m_view); |
|
103 | setCentralWidget(m_view); | |
98 |
|
104 | |||
99 | connectSignals(); |
|
105 | connectSignals(); | |
100 | } |
|
106 | } | |
101 |
|
107 | |||
102 | Window::~Window() |
|
108 | Window::~Window() | |
103 | { |
|
109 | { | |
104 | } |
|
110 | } | |
105 |
|
111 | |||
106 | void Window::connectSignals() |
|
112 | void Window::connectSignals() | |
107 | { |
|
113 | { | |
108 | QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); |
|
114 | QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); | |
|
115 | QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |||
109 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
116 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
110 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
117 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
111 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
118 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
112 | QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
119 | QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
113 | QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
120 | QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
114 | QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
121 | QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
115 | QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
122 | QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
116 | QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
123 | QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
117 | QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)),this,SLOT(handleChartSelected(QChart*))); |
|
124 | QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)),this,SLOT(handleChartSelected(QChart*))); | |
118 | } |
|
125 | } | |
119 |
|
126 | |||
120 | void Window::createProxyWidgets() |
|
127 | void Window::createProxyWidgets() | |
121 | { |
|
128 | { | |
122 | m_themeComboBox = createThemeBox(); |
|
129 | m_themeComboBox = createThemeBox(); | |
|
130 | m_viewComboBox = createViewBox(); | |||
123 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); |
|
131 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); | |
124 | m_animatedComboBox = createAnimationBox(); |
|
132 | m_animatedComboBox = createAnimationBox(); | |
125 | m_legendComboBox = createLegendBox(); |
|
133 | m_legendComboBox = createLegendBox(); | |
126 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); |
|
134 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); | |
127 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); |
|
135 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); | |
128 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); |
|
136 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); | |
129 | m_templateComboBox = createTempleteBox(); |
|
137 | m_templateComboBox = createTempleteBox(); | |
|
138 | m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View")); | |||
|
139 | m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox); | |||
130 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); |
|
140 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); | |
131 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); |
|
141 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); | |
132 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); |
|
142 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); | |
133 | m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); |
|
143 | m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); | |
134 | m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); |
|
144 | m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); | |
135 | m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); |
|
145 | m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); | |
136 | m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); |
|
146 | m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); | |
137 | m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); |
|
147 | m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); | |
138 | m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template")); |
|
148 | m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template")); | |
139 | m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); |
|
149 | m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); | |
140 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); |
|
150 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); | |
141 | m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); |
|
151 | m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); | |
142 |
|
||||
143 | } |
|
152 | } | |
144 |
|
153 | |||
145 | QComboBox *Window::createThemeBox() |
|
154 | QComboBox *Window::createThemeBox() | |
146 | { |
|
155 | { | |
147 | QComboBox *themeComboBox = new ComboBox(this); |
|
156 | QComboBox *themeComboBox = new ComboBox(this); | |
148 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
157 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
149 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
158 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
150 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
159 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
151 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
160 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
152 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
161 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
153 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
162 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
154 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
163 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
155 | return themeComboBox; |
|
164 | return themeComboBox; | |
156 | } |
|
165 | } | |
157 |
|
166 | |||
|
167 | QComboBox *Window::createViewBox() | |||
|
168 | { | |||
|
169 | QComboBox *viewComboBox = new ComboBox(this); | |||
|
170 | viewComboBox->addItem("1 chart", 1); | |||
|
171 | viewComboBox->addItem("4 charts", 2); | |||
|
172 | viewComboBox->addItem("9 charts", 3); | |||
|
173 | viewComboBox->addItem("16 charts", 4); | |||
|
174 | return viewComboBox; | |||
|
175 | } | |||
|
176 | ||||
158 | QComboBox *Window::createAnimationBox() |
|
177 | QComboBox *Window::createAnimationBox() | |
159 | { |
|
178 | { | |
160 | QComboBox *animationComboBox = new ComboBox(this); |
|
179 | QComboBox *animationComboBox = new ComboBox(this); | |
161 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
180 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
162 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
181 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
163 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
182 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
164 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
183 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
165 | return animationComboBox; |
|
184 | return animationComboBox; | |
166 | } |
|
185 | } | |
167 |
|
186 | |||
168 | QComboBox *Window::createLegendBox() |
|
187 | QComboBox *Window::createLegendBox() | |
169 | { |
|
188 | { | |
170 | QComboBox *legendComboBox = new ComboBox(this); |
|
189 | QComboBox *legendComboBox = new ComboBox(this); | |
171 | legendComboBox->addItem("No Legend ", 0); |
|
190 | legendComboBox->addItem("No Legend ", 0); | |
172 | legendComboBox->addItem("Legend Top", Qt::AlignTop); |
|
191 | legendComboBox->addItem("Legend Top", Qt::AlignTop); | |
173 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
|
192 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); | |
174 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); |
|
193 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); | |
175 | legendComboBox->addItem("Legend Right", Qt::AlignRight); |
|
194 | legendComboBox->addItem("Legend Right", Qt::AlignRight); | |
176 | return legendComboBox; |
|
195 | return legendComboBox; | |
177 | } |
|
196 | } | |
178 |
|
197 | |||
179 | QComboBox *Window::createTempleteBox() |
|
198 | QComboBox *Window::createTempleteBox() | |
180 | { |
|
199 | { | |
181 | QComboBox *templateComboBox = new ComboBox(this); |
|
200 | QComboBox *templateComboBox = new ComboBox(this); | |
182 | templateComboBox->addItem("No Template", 0); |
|
201 | templateComboBox->addItem("No Template", 0); | |
183 |
|
202 | |||
184 | Charts::ChartList list = Charts::chartList(); |
|
203 | Charts::ChartList list = Charts::chartList(); | |
185 | QMultiMap<QString, Chart *> categoryMap; |
|
204 | QMultiMap<QString, Chart *> categoryMap; | |
186 |
|
205 | |||
187 | foreach (Chart *chart, list) |
|
206 | foreach (Chart *chart, list) | |
188 | categoryMap.insertMulti(chart->category(), chart); |
|
207 | categoryMap.insertMulti(chart->category(), chart); | |
189 |
|
208 | |||
190 | foreach (const QString &category, categoryMap.uniqueKeys()) |
|
209 | foreach (const QString &category, categoryMap.uniqueKeys()) | |
191 | templateComboBox->addItem(category, category); |
|
210 | templateComboBox->addItem(category, category); | |
192 |
|
211 | |||
193 | return templateComboBox; |
|
212 | return templateComboBox; | |
194 | } |
|
213 | } | |
195 |
|
214 | |||
196 | void Window::initializeFromParamaters(const QVariantHash& parameters) |
|
215 | void Window::initializeFromParamaters(const QVariantHash& parameters) | |
197 | { |
|
216 | { | |
198 | if (parameters.contains("template")) { |
|
217 | if (parameters.contains("template")) { | |
199 | QString t = parameters["template"].toString(); |
|
218 | QString t = parameters["template"].toString(); | |
200 | for (int i = 0; i < m_templateComboBox->count(); ++i) { |
|
219 | for (int i = 0; i < m_templateComboBox->count(); ++i) { | |
201 | if (m_templateComboBox->itemText(i) == t) { |
|
220 | if (m_templateComboBox->itemText(i) == t) { | |
202 | m_templateComboBox->setCurrentIndex(i); |
|
221 | m_templateComboBox->setCurrentIndex(i); | |
203 | break; |
|
222 | break; | |
204 | } |
|
223 | } | |
205 | } |
|
224 | } | |
206 | } |
|
225 | } | |
207 | if (parameters.contains("opengl")) { |
|
226 | if (parameters.contains("opengl")) { | |
208 | bool checked = parameters["opengl"].toBool(); |
|
227 | bool checked = parameters["opengl"].toBool(); | |
209 | m_openGLCheckBox->setChecked(checked); |
|
228 | m_openGLCheckBox->setChecked(checked); | |
210 | } |
|
229 | } | |
211 | if (parameters.contains("theme")) { |
|
230 | if (parameters.contains("theme")) { | |
212 | QString t = parameters["theme"].toString(); |
|
231 | QString t = parameters["theme"].toString(); | |
213 | for (int i = 0; i < m_themeComboBox->count(); ++i) { |
|
232 | for (int i = 0; i < m_themeComboBox->count(); ++i) { | |
214 | if (m_themeComboBox->itemText(i) == t) { |
|
233 | if (m_themeComboBox->itemText(i) == t) { | |
215 | m_themeComboBox->setCurrentIndex(i); |
|
234 | m_themeComboBox->setCurrentIndex(i); | |
216 | break; |
|
235 | break; | |
217 | } |
|
236 | } | |
218 | } |
|
237 | } | |
219 | } |
|
238 | } | |
220 | if (parameters.contains("animation")) { |
|
239 | if (parameters.contains("animation")) { | |
221 | QString t = parameters["animation"].toString(); |
|
240 | QString t = parameters["animation"].toString(); | |
222 | for (int i = 0; i < m_animatedComboBox->count(); ++i) { |
|
241 | for (int i = 0; i < m_animatedComboBox->count(); ++i) { | |
223 | if (m_animatedComboBox->itemText(i) == t) { |
|
242 | if (m_animatedComboBox->itemText(i) == t) { | |
224 | m_animatedComboBox->setCurrentIndex(i); |
|
243 | m_animatedComboBox->setCurrentIndex(i); | |
225 | break; |
|
244 | break; | |
226 | } |
|
245 | } | |
227 | } |
|
246 | } | |
228 | } |
|
247 | } | |
229 | if (parameters.contains("legend")) { |
|
248 | if (parameters.contains("legend")) { | |
230 | QString t = parameters["legend"].toString(); |
|
249 | QString t = parameters["legend"].toString(); | |
231 | for (int i = 0; i < m_legendComboBox->count(); ++i) { |
|
250 | for (int i = 0; i < m_legendComboBox->count(); ++i) { | |
232 | if (m_legendComboBox->itemText(i) == t) { |
|
251 | if (m_legendComboBox->itemText(i) == t) { | |
233 | m_legendComboBox->setCurrentIndex(i); |
|
252 | m_legendComboBox->setCurrentIndex(i); | |
234 | break; |
|
253 | break; | |
235 | } |
|
254 | } | |
236 | } |
|
255 | } | |
237 | } |
|
256 | } | |
|
257 | if (parameters.contains("view")) { | |||
|
258 | int t = parameters["view"].toInt(); | |||
|
259 | for (int i = 0; i < m_viewComboBox->count(); ++i) { | |||
|
260 | if (m_viewComboBox->itemData(i).toInt() == t) { | |||
|
261 | ||||
|
262 | m_viewComboBox->setCurrentIndex(i); | |||
|
263 | break; | |||
|
264 | } | |||
|
265 | } | |||
|
266 | } | |||
238 | } |
|
267 | } | |
239 |
|
268 | |||
240 | void Window::updateUI() |
|
269 | void Window::updateUI() | |
241 | { |
|
270 | { | |
242 | checkTemplate(); |
|
271 | checkTemplate(); | |
|
272 | checkView(); | |||
243 | checkOpenGL(); |
|
273 | checkOpenGL(); | |
244 | checkTheme(); |
|
274 | checkTheme(); | |
245 | checkAnimationOptions(); |
|
275 | checkAnimationOptions(); | |
246 | checkLegend(); |
|
276 | checkLegend(); | |
247 | checkState(); |
|
277 | checkState(); | |
248 | } |
|
278 | } | |
249 |
|
279 | |||
|
280 | void Window::checkView() | |||
|
281 | { | |||
|
282 | int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt()); | |||
|
283 | m_grid->setSize(count); | |||
|
284 | } | |||
|
285 | ||||
250 | void Window::checkLegend() |
|
286 | void Window::checkLegend() | |
251 | { |
|
287 | { | |
252 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
288 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
253 |
|
289 | |||
254 | if (!alignment) { |
|
290 | if (!alignment) { | |
255 | foreach (QChart *chart, m_grid->charts()) |
|
291 | foreach (QChart *chart, m_grid->charts()) | |
256 | chart->legend()->hide(); |
|
292 | chart->legend()->hide(); | |
257 | } else { |
|
293 | } else { | |
258 | foreach (QChart *chart, m_grid->charts()) { |
|
294 | foreach (QChart *chart, m_grid->charts()) { | |
259 | chart->legend()->setAlignment(alignment); |
|
295 | chart->legend()->setAlignment(alignment); | |
260 | chart->legend()->show(); |
|
296 | chart->legend()->show(); | |
261 | } |
|
297 | } | |
262 | } |
|
298 | } | |
263 | } |
|
299 | } | |
264 |
|
300 | |||
265 | void Window::checkOpenGL() |
|
301 | void Window::checkOpenGL() | |
266 | { |
|
302 | { | |
267 | bool opengl = m_openGLCheckBox->isChecked(); |
|
303 | bool opengl = m_openGLCheckBox->isChecked(); | |
268 | bool isOpengl = qobject_cast<QGLWidget *>(m_view->viewport()); |
|
304 | bool isOpengl = qobject_cast<QGLWidget *>(m_view->viewport()); | |
269 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { |
|
305 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { | |
270 | m_view->deleteLater(); |
|
306 | m_view->deleteLater(); | |
271 | m_view = new View(m_scene, m_form); |
|
307 | m_view = new View(m_scene, m_form); | |
272 | m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); |
|
308 | m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); | |
273 | setCentralWidget(m_view); |
|
309 | setCentralWidget(m_view); | |
274 | } |
|
310 | } | |
275 |
|
311 | |||
276 | bool antialias = m_antialiasCheckBox->isChecked(); |
|
312 | bool antialias = m_antialiasCheckBox->isChecked(); | |
277 |
|
313 | |||
278 | if (opengl) |
|
314 | if (opengl) | |
279 | m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); |
|
315 | m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); | |
280 | else |
|
316 | else | |
281 | m_view->setRenderHint(QPainter::Antialiasing, antialias); |
|
317 | m_view->setRenderHint(QPainter::Antialiasing, antialias); | |
282 | } |
|
318 | } | |
283 |
|
319 | |||
284 | void Window::checkAnimationOptions() |
|
320 | void Window::checkAnimationOptions() | |
285 | { |
|
321 | { | |
286 | QChart::AnimationOptions options( |
|
322 | QChart::AnimationOptions options( | |
287 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
323 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
288 |
|
324 | |||
289 | QList<QChart*> charts = m_grid->charts(); |
|
325 | QList<QChart*> charts = m_grid->charts(); | |
290 |
|
326 | |||
291 | if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) { |
|
327 | if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) { | |
292 | foreach (QChart *chart, charts) |
|
328 | foreach (QChart *chart, charts) | |
293 | chart->setAnimationOptions(options); |
|
329 | chart->setAnimationOptions(options); | |
294 | } |
|
330 | } | |
295 | } |
|
331 | } | |
296 |
|
332 | |||
297 | void Window::checkState() |
|
333 | void Window::checkState() | |
298 | { |
|
334 | { | |
299 | bool scroll = m_scrollCheckBox->isChecked(); |
|
335 | bool scroll = m_scrollCheckBox->isChecked(); | |
300 |
|
336 | |||
301 |
|
337 | |||
302 | if (m_grid->state() != Grid::ScrollState && scroll) { |
|
338 | if (m_grid->state() != Grid::ScrollState && scroll) { | |
303 | m_grid->setState(Grid::ScrollState); |
|
339 | m_grid->setState(Grid::ScrollState); | |
304 | m_zoomCheckBox->setChecked(false); |
|
340 | m_zoomCheckBox->setChecked(false); | |
305 | } else if (!scroll && m_grid->state() == Grid::ScrollState) { |
|
341 | } else if (!scroll && m_grid->state() == Grid::ScrollState) { | |
306 | m_grid->setState(Grid::NoState); |
|
342 | m_grid->setState(Grid::NoState); | |
307 | } |
|
343 | } | |
308 |
|
344 | |||
309 | bool zoom = m_zoomCheckBox->isChecked(); |
|
345 | bool zoom = m_zoomCheckBox->isChecked(); | |
310 |
|
346 | |||
311 | if (m_grid->state() != Grid::ZoomState && zoom) { |
|
347 | if (m_grid->state() != Grid::ZoomState && zoom) { | |
312 | m_grid->setState(Grid::ZoomState); |
|
348 | m_grid->setState(Grid::ZoomState); | |
313 | m_scrollCheckBox->setChecked(false); |
|
349 | m_scrollCheckBox->setChecked(false); | |
314 | } else if (!zoom && m_grid->state() == Grid::ZoomState) { |
|
350 | } else if (!zoom && m_grid->state() == Grid::ZoomState) { | |
315 | m_grid->setState(Grid::NoState); |
|
351 | m_grid->setState(Grid::NoState); | |
316 | } |
|
352 | } | |
317 | } |
|
353 | } | |
318 |
|
354 | |||
319 | void Window::checkTemplate() |
|
355 | void Window::checkTemplate() | |
320 | { |
|
356 | { | |
321 | int index = m_templateComboBox->currentIndex(); |
|
357 | int index = m_templateComboBox->currentIndex(); | |
322 | if (m_template == index || index == 0) |
|
358 | if (m_template == index || index == 0) | |
323 | return; |
|
359 | return; | |
324 |
|
360 | |||
325 | m_template = index; |
|
361 | m_template = index; | |
326 | QString category = m_templateComboBox->itemData(index).toString(); |
|
362 | QString category = m_templateComboBox->itemData(index).toString(); | |
327 | m_grid->createCharts(category); |
|
363 | m_grid->createCharts(category); | |
328 | } |
|
364 | } | |
329 |
|
365 | |||
330 | void Window::checkTheme() |
|
366 | void Window::checkTheme() | |
331 | { |
|
367 | { | |
332 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( |
|
368 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( | |
333 | m_themeComboBox->currentIndex()).toInt(); |
|
369 | m_themeComboBox->currentIndex()).toInt(); | |
334 |
|
370 | |||
335 | foreach (QChart *chart, m_grid->charts()) |
|
371 | foreach (QChart *chart, m_grid->charts()) | |
336 | chart->setTheme(theme); |
|
372 | chart->setTheme(theme); | |
337 |
|
373 | |||
338 | QPalette pal = window()->palette(); |
|
374 | QPalette pal = window()->palette(); | |
339 | if (theme == QChart::ChartThemeLight) { |
|
375 | if (theme == QChart::ChartThemeLight) { | |
340 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
376 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
341 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
377 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
342 | } else if (theme == QChart::ChartThemeDark) { |
|
378 | } else if (theme == QChart::ChartThemeDark) { | |
343 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
379 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
344 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
380 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
345 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
381 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
346 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
382 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
347 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
383 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
348 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
384 | } else if (theme == QChart::ChartThemeBrownSand) { | |
349 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
385 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
350 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
386 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
351 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
387 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
352 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
388 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
353 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
389 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
354 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
390 | } else if (theme == QChart::ChartThemeHighContrast) { | |
355 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
391 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
356 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
392 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
357 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
393 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
358 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
394 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
359 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
395 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
360 | } else { |
|
396 | } else { | |
361 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
397 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
362 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
398 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
363 | } |
|
399 | } | |
364 | foreach (QGraphicsProxyWidget *widget, m_widgetHash) |
|
400 | foreach (QGraphicsProxyWidget *widget, m_widgetHash) | |
365 | widget->setPalette(pal); |
|
401 | widget->setPalette(pal); | |
366 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); |
|
402 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); | |
367 | m_grid->setRubberPen(pal.color((QPalette::WindowText))); |
|
403 | m_grid->setRubberPen(pal.color((QPalette::WindowText))); | |
368 | } |
|
404 | } | |
369 |
|
405 | |||
370 | void Window::comboBoxFocused(QComboBox *combobox) |
|
406 | void Window::comboBoxFocused(QComboBox *combobox) | |
371 | { |
|
407 | { | |
372 | foreach (QGraphicsProxyWidget *widget , m_widgetHash) { |
|
408 | foreach (QGraphicsProxyWidget *widget , m_widgetHash) { | |
373 | if (widget->widget() == combobox) |
|
409 | if (widget->widget() == combobox) | |
374 | widget->setZValue(2.0); |
|
410 | widget->setZValue(2.0); | |
375 | else |
|
411 | else | |
376 | widget->setZValue(0.0); |
|
412 | widget->setZValue(0.0); | |
377 | } |
|
413 | } | |
378 | } |
|
414 | } | |
379 |
|
415 | |||
380 | void Window::handleChartSelected(QChart *qchart) |
|
416 | void Window::handleChartSelected(QChart *qchart) | |
381 | { |
|
417 | { | |
382 | if(m_templateComboBox->currentIndex() != 0) return; |
|
418 | if(m_templateComboBox->currentIndex() != 0) return; | |
383 |
|
419 | |||
384 | QAction *chosen = m_menu->exec(QCursor::pos()); |
|
420 | QAction *chosen = m_menu->exec(QCursor::pos()); | |
385 |
|
421 | |||
386 | if (chosen) { |
|
422 | if (chosen) { | |
387 | Chart *chart = (Chart *) chosen->data().value<void *>(); |
|
423 | Chart *chart = (Chart *) chosen->data().value<void *>(); | |
388 | m_grid->replaceChart(qchart,chart); |
|
424 | m_grid->replaceChart(qchart,chart); | |
389 | updateUI(); |
|
425 | updateUI(); | |
390 | } |
|
426 | } | |
391 | } |
|
427 | } | |
392 |
|
428 | |||
393 | QMenu *Window::createMenu() |
|
429 | QMenu *Window::createMenu() | |
394 | { |
|
430 | { | |
395 | Charts::ChartList list = Charts::chartList(); |
|
431 | Charts::ChartList list = Charts::chartList(); | |
396 | QMultiMap<QString, Chart *> categoryMap; |
|
432 | QMultiMap<QString, Chart *> categoryMap; | |
397 |
|
433 | |||
398 | QMenu *result = new QMenu(this); |
|
434 | QMenu *result = new QMenu(this); | |
399 |
|
435 | |||
400 | foreach (Chart *chart, list) |
|
436 | foreach (Chart *chart, list) | |
401 | categoryMap.insertMulti(chart->category(), chart); |
|
437 | categoryMap.insertMulti(chart->category(), chart); | |
402 |
|
438 | |||
403 | foreach (const QString &category, categoryMap.uniqueKeys()) { |
|
439 | foreach (const QString &category, categoryMap.uniqueKeys()) { | |
404 | QMenu *menu(0); |
|
440 | QMenu *menu(0); | |
405 | QMultiMap<QString, Chart *> subCategoryMap; |
|
441 | QMultiMap<QString, Chart *> subCategoryMap; | |
406 | if (category.isEmpty()) { |
|
442 | if (category.isEmpty()) { | |
407 | menu = result; |
|
443 | menu = result; | |
408 | } else { |
|
444 | } else { | |
409 | menu = new QMenu(category, this); |
|
445 | menu = new QMenu(category, this); | |
410 | result->addMenu(menu); |
|
446 | result->addMenu(menu); | |
411 | } |
|
447 | } | |
412 |
|
448 | |||
413 | foreach (Chart *chart, categoryMap.values(category)) |
|
449 | foreach (Chart *chart, categoryMap.values(category)) | |
414 | subCategoryMap.insert(chart->subCategory(), chart); |
|
450 | subCategoryMap.insert(chart->subCategory(), chart); | |
415 |
|
451 | |||
416 | foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) { |
|
452 | foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) { | |
417 | QMenu *subMenu(0); |
|
453 | QMenu *subMenu(0); | |
418 | if (subCategory.isEmpty()) { |
|
454 | if (subCategory.isEmpty()) { | |
419 | subMenu = menu; |
|
455 | subMenu = menu; | |
420 | } else { |
|
456 | } else { | |
421 | subMenu = new QMenu(subCategory, this); |
|
457 | subMenu = new QMenu(subCategory, this); | |
422 | menu->addMenu(subMenu); |
|
458 | menu->addMenu(subMenu); | |
423 | } |
|
459 | } | |
424 |
|
460 | |||
425 | foreach (Chart *chart, subCategoryMap.values(subCategory)) { |
|
461 | foreach (Chart *chart, subCategoryMap.values(subCategory)) { | |
426 | createMenuAction(subMenu, QIcon(), chart->name(), |
|
462 | createMenuAction(subMenu, QIcon(), chart->name(), | |
427 | qVariantFromValue((void *) chart)); |
|
463 | qVariantFromValue((void *) chart)); | |
428 | } |
|
464 | } | |
429 | } |
|
465 | } | |
430 | } |
|
466 | } | |
431 | return result; |
|
467 | return result; | |
432 | } |
|
468 | } | |
433 |
|
469 | |||
434 | QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, |
|
470 | QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, | |
435 | const QVariant &data) |
|
471 | const QVariant &data) | |
436 | { |
|
472 | { | |
437 | QAction *action = menu->addAction(icon, text); |
|
473 | QAction *action = menu->addAction(icon, text); | |
438 | action->setCheckable(false); |
|
474 | action->setCheckable(false); | |
439 | action->setData(data); |
|
475 | action->setData(data); | |
440 | return action; |
|
476 | return action; | |
441 | } |
|
477 | } | |
442 |
|
478 | |||
443 | void Window::handleGeometryChanged() |
|
479 | void Window::handleGeometryChanged() | |
444 | { |
|
480 | { | |
445 | QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize); |
|
481 | QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize); | |
446 | m_view->scene()->setSceneRect(0, 0, this->width(), this->height()); |
|
482 | m_view->scene()->setSceneRect(0, 0, this->width(), this->height()); | |
447 | m_view->setMinimumSize(size.toSize()); |
|
483 | m_view->setMinimumSize(size.toSize()); | |
448 | } |
|
484 | } |
@@ -1,115 +1,114 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef WINDOW_H |
|
21 | #ifndef WINDOW_H | |
22 | #define WINDOW_H |
|
22 | #define WINDOW_H | |
23 | #include <QMainWindow> |
|
23 | #include <QMainWindow> | |
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QHash> |
|
25 | #include <QHash> | |
26 | #include <QComboBox> |
|
26 | #include <QComboBox> | |
27 |
|
27 | |||
28 | class QCheckBox; |
|
28 | class QCheckBox; | |
29 | class QGraphicsRectItem; |
|
29 | class QGraphicsRectItem; | |
30 | class QGraphicsScene; |
|
30 | class QGraphicsScene; | |
31 | class QGraphicsWidget; |
|
31 | class QGraphicsWidget; | |
32 | class View; |
|
32 | class View; | |
33 | class QGraphicsLinearLayout; |
|
33 | class QGraphicsLinearLayout; | |
34 | class Chart; |
|
34 | class Chart; | |
35 | class Grid; |
|
35 | class Grid; | |
|
36 | class QPushButton; | |||
36 |
|
37 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 | class QChart; |
|
39 | class QChart; | |
39 | QTCOMMERCIALCHART_END_NAMESPACE |
|
40 | QTCOMMERCIALCHART_END_NAMESPACE | |
40 |
|
41 | |||
41 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
42 | QTCOMMERCIALCHART_USE_NAMESPACE | |
42 |
|
43 | |||
43 |
|
44 | |||
44 | class Window: public QMainWindow |
|
45 | class Window: public QMainWindow | |
45 | { |
|
46 | { | |
46 | Q_OBJECT |
|
47 | Q_OBJECT | |
47 | public: |
|
48 | public: | |
48 | explicit Window(const QVariantHash& parameters, QWidget *parent = 0); |
|
49 | explicit Window(const QVariantHash& parameters, QWidget *parent = 0); | |
49 | ~Window(); |
|
50 | ~Window(); | |
50 |
|
51 | |||
51 | private Q_SLOTS: |
|
52 | private Q_SLOTS: | |
52 | void updateUI(); |
|
53 | void updateUI(); | |
53 | void handleGeometryChanged(); |
|
54 | void handleGeometryChanged(); | |
54 | void handleChartSelected(QChart *chart); |
|
55 | void handleChartSelected(QChart *chart); | |
55 | private: |
|
56 | private: | |
|
57 | QComboBox *createViewBox(); | |||
56 | QComboBox *createThemeBox(); |
|
58 | QComboBox *createThemeBox(); | |
57 | QComboBox *createAnimationBox(); |
|
59 | QComboBox *createAnimationBox(); | |
58 | QComboBox *createLegendBox(); |
|
60 | QComboBox *createLegendBox(); | |
59 | QComboBox *createTempleteBox(); |
|
61 | QComboBox *createTempleteBox(); | |
60 | void connectSignals(); |
|
62 | void connectSignals(); | |
61 | void createProxyWidgets(); |
|
63 | void createProxyWidgets(); | |
62 | void comboBoxFocused(QComboBox *combox); |
|
64 | void comboBoxFocused(QComboBox *combox); | |
63 | inline void checkAnimationOptions(); |
|
65 | inline void checkAnimationOptions(); | |
|
66 | inline void checkView(); | |||
64 | inline void checkLegend(); |
|
67 | inline void checkLegend(); | |
65 | inline void checkOpenGL(); |
|
68 | inline void checkOpenGL(); | |
66 | inline void checkTheme(); |
|
69 | inline void checkTheme(); | |
67 | inline void checkState(); |
|
70 | inline void checkState(); | |
68 | inline void checkTemplate(); |
|
71 | inline void checkTemplate(); | |
69 | QMenu *createMenu(); |
|
72 | QMenu *createMenu(); | |
70 | QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); |
|
73 | QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); | |
71 | void initializeFromParamaters(const QVariantHash& parameters); |
|
74 | void initializeFromParamaters(const QVariantHash& parameters); | |
72 |
|
75 | |||
73 | protected: |
|
|||
74 | //void mousePressEvent(QMouseEvent *event); |
|
|||
75 | //void mouseMoveEvent(QMouseEvent *event); |
|
|||
76 | //void mouseReleaseEvent(QMouseEvent *event); |
|
|||
77 |
|
||||
78 | private: |
|
76 | private: | |
79 | QGraphicsScene *m_scene; |
|
77 | QGraphicsScene *m_scene; | |
80 | View *m_view; |
|
78 | View *m_view; | |
81 | QHash<QString, QGraphicsProxyWidget *> m_widgetHash; |
|
79 | QHash<QString, QGraphicsProxyWidget *> m_widgetHash; | |
82 |
|
80 | |||
83 | QGraphicsWidget *m_form; |
|
81 | QGraphicsWidget *m_form; | |
84 | QComboBox *m_themeComboBox; |
|
82 | QComboBox *m_themeComboBox; | |
85 | QCheckBox *m_antialiasCheckBox; |
|
83 | QCheckBox *m_antialiasCheckBox; | |
86 | QComboBox *m_animatedComboBox; |
|
84 | QComboBox *m_animatedComboBox; | |
87 | QComboBox *m_legendComboBox; |
|
85 | QComboBox *m_legendComboBox; | |
88 | QComboBox *m_templateComboBox; |
|
86 | QComboBox *m_templateComboBox; | |
|
87 | QComboBox *m_viewComboBox; | |||
89 | QCheckBox *m_openGLCheckBox; |
|
88 | QCheckBox *m_openGLCheckBox; | |
90 | QCheckBox *m_zoomCheckBox; |
|
89 | QCheckBox *m_zoomCheckBox; | |
91 | QCheckBox *m_scrollCheckBox; |
|
90 | QCheckBox *m_scrollCheckBox; | |
92 | QGraphicsLinearLayout *m_baseLayout; |
|
91 | QGraphicsLinearLayout *m_baseLayout; | |
93 | QMenu *m_menu; |
|
92 | QMenu *m_menu; | |
94 | int m_template; |
|
93 | int m_template; | |
95 | Grid* m_grid; |
|
94 | Grid* m_grid; | |
96 |
|
95 | |||
97 | friend class ComboBox; |
|
96 | friend class ComboBox; | |
98 | }; |
|
97 | }; | |
99 |
|
98 | |||
100 | class ComboBox: public QComboBox |
|
99 | class ComboBox: public QComboBox | |
101 | { |
|
100 | { | |
102 | public: |
|
101 | public: | |
103 | ComboBox(Window *window, QWidget *parent = 0): QComboBox(parent), m_window(window) |
|
102 | ComboBox(Window *window, QWidget *parent = 0): QComboBox(parent), m_window(window) | |
104 | {} |
|
103 | {} | |
105 |
|
104 | |||
106 | protected: |
|
105 | protected: | |
107 | void focusInEvent(QFocusEvent *e) { |
|
106 | void focusInEvent(QFocusEvent *e) { | |
108 | QComboBox::focusInEvent(e); |
|
107 | QComboBox::focusInEvent(e); | |
109 | m_window->comboBoxFocused(this); |
|
108 | m_window->comboBoxFocused(this); | |
110 | } |
|
109 | } | |
111 | private: |
|
110 | private: | |
112 | Window *m_window; |
|
111 | Window *m_window; | |
113 | }; |
|
112 | }; | |
114 |
|
113 | |||
115 | #endif |
|
114 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now