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