##// END OF EJS Templates
Adds charts templates to chartviewer
Michal Klocek -
r1864:011a4bf2614e
parent child
Show More
@@ -1,55 +1,55
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
25
26 class HorizontalBarChart: public Chart
26 class HorizontalBarChart: public Chart
27 {
27 {
28 public:
28 public:
29 QString name() { return QObject::tr("HorizontalBarChart"); }
29 QString name() { return QObject::tr("HorizontalBarChart"); }
30 QString category() { return QObject::tr("BarSeries"); }
30 QString category() { return QObject::tr("BarSeries"); }
31 QString subCategory() { return QObject::tr("Vertical"); }
31 QString subCategory() { return QObject::tr("Horizontal"); }
32
32
33 QChart* createChart(const DataTable& table)
33 QChart* createChart(const DataTable& table)
34 {
34 {
35
35
36 QChart* chart = new QChart();
36 QChart* chart = new QChart();
37
37
38 chart->setTitle("Horizontal bar chart");
38 chart->setTitle("Horizontal bar chart");
39
39
40 QHorizontalBarSeries* series = new QHorizontalBarSeries(chart);
40 QHorizontalBarSeries* series = new QHorizontalBarSeries(chart);
41 for (int i(0); i < table.count(); i++) {
41 for (int i(0); i < table.count(); i++) {
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
43 foreach (Data data, table[i])
43 foreach (Data data, table[i])
44 *set << data.first.y();
44 *set << data.first.y();
45 series->append(set);
45 series->append(set);
46 }
46 }
47 chart->addSeries(series);
47 chart->addSeries(series);
48 chart->createDefaultAxes();
48 chart->createDefaultAxes();
49 return chart;
49 return chart;
50 }
50 }
51
51
52 };
52 };
53
53
54 DECLARE_CHART(HorizontalBarChart)
54 DECLARE_CHART(HorizontalBarChart)
55
55
@@ -1,55 +1,55
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 "qhorizontalstackedbarseries.h"
23 #include "qhorizontalstackedbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25
25
26 class HorizontalStackedBarChart: public Chart
26 class HorizontalStackedBarChart: public Chart
27 {
27 {
28 public:
28 public:
29 QString name() { return QObject::tr("HorizontalStackedBarChart"); }
29 QString name() { return QObject::tr("HorizontalStackedBarChart"); }
30 QString category() { return QObject::tr("BarSeries"); }
30 QString category() { return QObject::tr("BarSeries"); }
31 QString subCategory() { return QObject::tr("Vertical"); }
31 QString subCategory() { return QObject::tr("Horizontal"); }
32
32
33 QChart* createChart(const DataTable& table)
33 QChart* createChart(const DataTable& table)
34 {
34 {
35
35
36 QChart* chart = new QChart();
36 QChart* chart = new QChart();
37
37
38 chart->setTitle("Horizontal stacked chart");
38 chart->setTitle("Horizontal stacked chart");
39
39
40 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries(chart);
40 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries(chart);
41 for (int i(0); i < table.count(); i++) {
41 for (int i(0); i < table.count(); i++) {
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
43 foreach (Data data, table[i])
43 foreach (Data data, table[i])
44 *set << data.first.y();
44 *set << data.first.y();
45 series->append(set);
45 series->append(set);
46 }
46 }
47 chart->addSeries(series);
47 chart->addSeries(series);
48 chart->createDefaultAxes();
48 chart->createDefaultAxes();
49 return chart;
49 return chart;
50 }
50 }
51
51
52 };
52 };
53
53
54 DECLARE_CHART(HorizontalStackedBarChart)
54 DECLARE_CHART(HorizontalStackedBarChart)
55
55
@@ -1,59 +1,59
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 "qpieseries.h"
23 #include "qpieseries.h"
24
24
25 class PieChart: public Chart
25 class PieChart: public Chart
26 {
26 {
27 public:
27 public:
28 QString name() { return QObject::tr("PieChart"); }
28 QString name() { return QObject::tr("PieChart"); }
29 QString category() { return QString::null; }
29 QString category() { return QObject::tr("PieSeries"); }
30 QString subCategory() { return QString::null; }
30 QString subCategory() { return QString::null; }
31
31
32 QChart* createChart(const DataTable& table)
32 QChart* createChart(const DataTable& table)
33 {
33 {
34 QChart* chart = new QChart();
34 QChart* chart = new QChart();
35 chart->setTitle("Pie chart");
35 chart->setTitle("Pie chart");
36
36
37 qreal pieSize = 1.0 / table.count();
37 qreal pieSize = 1.0 / table.count();
38 for (int i = 0; i < table.count(); i++) {
38 for (int i = 0; i < table.count(); i++) {
39 QPieSeries *series = new QPieSeries(chart);
39 QPieSeries *series = new QPieSeries(chart);
40 foreach (Data data, table[i]) {
40 foreach (Data data, table[i]) {
41 QPieSlice *slice = series->append(data.second, data.first.y());
41 QPieSlice *slice = series->append(data.second, data.first.y());
42 if (data == table[i].first()) {
42 if (data == table[i].first()) {
43 slice->setLabelVisible();
43 slice->setLabelVisible();
44 slice->setExploded();
44 slice->setExploded();
45 }
45 }
46 }
46 }
47 qreal hPos = (pieSize / 2) + (i / (qreal) table.count());
47 qreal hPos = (pieSize / 2) + (i / (qreal) table.count());
48 series->setPieSize(pieSize);
48 series->setPieSize(pieSize);
49 series->setHorizontalPosition(hPos);
49 series->setHorizontalPosition(hPos);
50 series->setVerticalPosition(0.5);
50 series->setVerticalPosition(0.5);
51 chart->addSeries(series);
51 chart->addSeries(series);
52 }
52 }
53 return chart;
53 return chart;
54 }
54 }
55
55
56 };
56 };
57
57
58 DECLARE_CHART(PieChart)
58 DECLARE_CHART(PieChart)
59
59
@@ -1,458 +1,581
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 "charts.h"
23 #include "charts.h"
24 #include <QChartView>
24 #include <QChartView>
25 #include <QAreaSeries>
25 #include <QAreaSeries>
26 #include <QLegend>
26 #include <QLegend>
27 #include <QGridLayout>
27 #include <QGridLayout>
28 #include <QFormLayout>
28 #include <QFormLayout>
29 #include <QComboBox>
29 #include <QComboBox>
30 #include <QSpinBox>
30 #include <QSpinBox>
31 #include <QCheckBox>
31 #include <QCheckBox>
32 #include <QGroupBox>
32 #include <QGroupBox>
33 #include <QLabel>
33 #include <QLabel>
34 #include <QGraphicsScene>
34 #include <QGraphicsScene>
35 #include <QGraphicsGridLayout>
35 #include <QGraphicsGridLayout>
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
42
43 Window::Window(QWidget* parent) :
43 Window::Window(QWidget* parent) :
44 QMainWindow(parent),
44 QMainWindow(parent),
45 m_listCount(3),
45 m_listCount(3),
46 m_valueMax(10),
46 m_valueMax(10),
47 m_valueCount(7),
47 m_valueCount(7),
48 m_scene(new QGraphicsScene(this)),
48 m_scene(new QGraphicsScene(this)),
49 m_view(0),
49 m_view(0),
50 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
50 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
51 m_form(0),
51 m_form(0),
52 m_themeComboBox(0),
52 m_themeComboBox(0),
53 m_antialiasCheckBox(0),
53 m_antialiasCheckBox(0),
54 m_animatedComboBox(0),
54 m_animatedComboBox(0),
55 m_legendComboBox(0),
55 m_legendComboBox(0),
56 m_templateComboBox(0),
56 m_openGLCheckBox(0),
57 m_openGLCheckBox(0),
57 m_zoomCheckBox(0),
58 m_zoomCheckBox(0),
58 m_scrollCheckBox(0),
59 m_scrollCheckBox(0),
59 m_rubberBand(new QGraphicsRectItem()),
60 m_rubberBand(new QGraphicsRectItem()),
60 m_baseLayout(new QGraphicsGridLayout()),
61 m_baseLayout(new QGraphicsGridLayout()),
61 m_menu(new QMenu(this)),
62 m_menu(createMenu()),
62 m_state(NoState),
63 m_state(NoState),
63 m_currentState(NoState)
64 m_currentState(NoState),
65 m_template(0)
64 {
66 {
65 createProxyWidgets();
67 createProxyWidgets();
66 connectSignals();
68 connectSignals();
67
69
68 // create layout
70 // create layout
69 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
71 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
70 settingsLayout->setOrientation(Qt::Vertical);
72 settingsLayout->setOrientation(Qt::Vertical);
71 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
73 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
72 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
74 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
73 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
75 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
74 settingsLayout->addItem(m_widgetHash["themeLabel"]);
76 settingsLayout->addItem(m_widgetHash["themeLabel"]);
75 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
77 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
76 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
78 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
77 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
79 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
78 settingsLayout->addItem(m_widgetHash["legendLabel"]);
80 settingsLayout->addItem(m_widgetHash["legendLabel"]);
79 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
81 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
82 settingsLayout->addItem(m_widgetHash["templateLabel"]);
83 settingsLayout->addItem(m_widgetHash["templateComboBox"]);
80 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
84 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
81 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
85 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
82 settingsLayout->addStretch();
86 settingsLayout->addStretch();
83 m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
87 m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
84
88
85 //create charts
89 //create charts
86 Charts::ChartList list = Charts::chartList();
90 Charts::ChartList list = Charts::chartList();
87
91
88 for (int i = 0; i < 9 && i < list.size(); ++i) {
92 for (int i = 0; i < 9; ++i) {
89 QChart* chart = list.at(i)->createChart(m_dataTable);
93 QChart* chart = 0;
94 if(i<list.size()){
95 chart = list.at(i)->createChart(m_dataTable);
96 }else{
97 chart = new QChart();
98 chart->setTitle(tr("Empty"));
99 }
100
90 m_baseLayout->addItem(chart, i / 3, i % 3);
101 m_baseLayout->addItem(chart, i / 3, i % 3);
91 m_chartHash[chart] = i;
102 m_chartHash[chart] = i;
92 }
103 }
93
104
94 foreach(Chart* chart, list) {
95 createMenuAction(m_menu, QIcon(), chart->name(), qVariantFromValue((void *) chart));
96 }
97
98 m_form = new QGraphicsWidget();
105 m_form = new QGraphicsWidget();
99 m_form->setLayout(m_baseLayout);
106 m_form->setLayout(m_baseLayout);
100 m_scene->addItem(m_form);
107 m_scene->addItem(m_form);
101 m_scene->addItem(m_rubberBand);
108 m_scene->addItem(m_rubberBand);
102 m_rubberBand->setVisible(false);
109 m_rubberBand->setVisible(false);
103
110
104 m_view = new View(m_scene, m_form);
111 m_view = new View(m_scene, m_form);
105 m_view->setMinimumSize(m_form->preferredSize().toSize());
112 m_view->setMinimumSize(m_form->preferredSize().toSize());
106
113
107 // Set defaults
114 // Set defaults
108 m_antialiasCheckBox->setChecked(true);
115 m_antialiasCheckBox->setChecked(true);
109 updateUI();
116 updateUI();
110 setCentralWidget(m_view);
117 setCentralWidget(m_view);
111 }
118 }
112
119
113 Window::~Window()
120 Window::~Window()
114 {
121 {
115 }
122 }
116
123
117 void Window::connectSignals()
124 void Window::connectSignals()
118 {
125 {
119 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
126 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
120 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
127 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
121 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
128 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
122 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
129 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
123 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
130 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
124 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
131 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
125 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
132 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
133 QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
126 }
134 }
127
135
128 void Window::createProxyWidgets()
136 void Window::createProxyWidgets()
129 {
137 {
130 m_themeComboBox = createThemeBox();
138 m_themeComboBox = createThemeBox();
131 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
139 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
132 m_animatedComboBox = createAnimationBox();
140 m_animatedComboBox = createAnimationBox();
133 m_legendComboBox = createLegendBox();
141 m_legendComboBox = createLegendBox();
134 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
142 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
135 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
143 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
136 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
144 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
145 m_templateComboBox= createTempleteBox();
137 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
146 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
138 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
147 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
139 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
148 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
140 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
149 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
141 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
150 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
142 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
151 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
143 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
152 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
144 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
153 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
154 m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template"));
155 m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox);
145 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
156 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
146 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
157 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
158
147 }
159 }
148
160
149 QComboBox* Window::createThemeBox()
161 QComboBox* Window::createThemeBox()
150 {
162 {
151 QComboBox* themeComboBox = new ComboBox(this);
163 QComboBox* themeComboBox = new ComboBox(this);
152 themeComboBox->addItem("Light", QChart::ChartThemeLight);
164 themeComboBox->addItem("Light", QChart::ChartThemeLight);
153 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
165 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
154 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
166 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
155 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
167 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
156 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
168 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
157 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
169 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
158 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
170 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
159 return themeComboBox;
171 return themeComboBox;
160 }
172 }
161
173
162 QComboBox* Window::createAnimationBox()
174 QComboBox* Window::createAnimationBox()
163 {
175 {
164 QComboBox* animationComboBox = new ComboBox(this);
176 QComboBox* animationComboBox = new ComboBox(this);
165 animationComboBox->addItem("No Animations", QChart::NoAnimation);
177 animationComboBox->addItem("No Animations", QChart::NoAnimation);
166 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
178 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
167 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
179 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
168 animationComboBox->addItem("All Animations", QChart::AllAnimations);
180 animationComboBox->addItem("All Animations", QChart::AllAnimations);
169 return animationComboBox;
181 return animationComboBox;
170 }
182 }
171
183
172 QComboBox* Window::createLegendBox()
184 QComboBox* Window::createLegendBox()
173 {
185 {
174 QComboBox* legendComboBox = new ComboBox(this);
186 QComboBox* legendComboBox = new ComboBox(this);
175 legendComboBox->addItem("No Legend ", 0);
187 legendComboBox->addItem("No Legend ", 0);
176 legendComboBox->addItem("Legend Top", Qt::AlignTop);
188 legendComboBox->addItem("Legend Top", Qt::AlignTop);
177 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
189 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
178 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
190 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
179 legendComboBox->addItem("Legend Right", Qt::AlignRight);
191 legendComboBox->addItem("Legend Right", Qt::AlignRight);
180 return legendComboBox;
192 return legendComboBox;
181 }
193 }
182
194
195 QComboBox* Window::createTempleteBox()
196 {
197 QComboBox* templateComboBox = new ComboBox(this);
198 templateComboBox->addItem("No Template", 0);
199
200 Charts::ChartList list = Charts::chartList();
201 QMultiMap<QString, Chart*> categoryMap;
202
203 foreach(Chart* chart, list) {
204 categoryMap.insertMulti(chart->category(), chart);
205 }
206 foreach(const QString& category, categoryMap.uniqueKeys()) {
207 templateComboBox->addItem(category, category);
208 }
209 return templateComboBox;
210 }
211
212
183 void Window::updateUI()
213 void Window::updateUI()
184 {
214 {
215 checkTemplate();
185 checkOpenGL();
216 checkOpenGL();
186 checkTheme();
217 checkTheme();
187 checkAnimationOptions();
218 checkAnimationOptions();
188 checkLegend();
219 checkLegend();
189 checkState();
220 checkState();
190 }
221 }
191
222
192 void Window::checkLegend()
223 void Window::checkLegend()
193 {
224 {
194 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
225 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
195
226
196 if (!alignment) {
227 if (!alignment) {
197 foreach (QChart *chart, m_chartHash.keys()) {
228 foreach (QChart *chart, m_chartHash.keys()) {
198 chart->legend()->hide();
229 chart->legend()->hide();
199 }
230 }
200 }
231 }
201 else {
232 else {
202 foreach (QChart *chart, m_chartHash.keys()) {
233 foreach (QChart *chart, m_chartHash.keys()) {
203 chart->legend()->setAlignment(alignment);
234 chart->legend()->setAlignment(alignment);
204 chart->legend()->show();
235 chart->legend()->show();
205 }
236 }
206 }
237 }
207 }
238 }
208
239
209 void Window::checkOpenGL()
240 void Window::checkOpenGL()
210 {
241 {
211 bool opengl = m_openGLCheckBox->isChecked();
242 bool opengl = m_openGLCheckBox->isChecked();
212 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
243 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
213 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
244 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
214 m_view->deleteLater();
245 m_view->deleteLater();
215 m_view = new View(m_scene, m_form);
246 m_view = new View(m_scene, m_form);
216 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
247 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
217 setCentralWidget(m_view);
248 setCentralWidget(m_view);
218 }
249 }
219
250
220 bool antialias = m_antialiasCheckBox->isChecked();
251 bool antialias = m_antialiasCheckBox->isChecked();
221
252
222 if (opengl)
253 if (opengl)
223 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
254 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
224 else
255 else
225 m_view->setRenderHint(QPainter::Antialiasing, antialias);
256 m_view->setRenderHint(QPainter::Antialiasing, antialias);
226 }
257 }
227
258
228 void Window::checkAnimationOptions()
259 void Window::checkAnimationOptions()
229 {
260 {
230 QChart::AnimationOptions options(
261 QChart::AnimationOptions options(
231 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
262 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
232 if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) {
263 if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) {
233 foreach (QChart *chart, m_chartHash.keys())
264 foreach (QChart *chart, m_chartHash.keys())
234 chart->setAnimationOptions(options);
265 chart->setAnimationOptions(options);
235 }
266 }
236 }
267 }
237
268
238 void Window::checkState()
269 void Window::checkState()
239 {
270 {
240 bool scroll = m_scrollCheckBox->isChecked();
271 bool scroll = m_scrollCheckBox->isChecked();
241
272
242 if (m_state != ScrollState && scroll) {
273 if (m_state != ScrollState && scroll) {
243 m_state = ScrollState;
274 m_state = ScrollState;
244 m_zoomCheckBox->setChecked(false);
275 m_zoomCheckBox->setChecked(false);
245 }
276 }
246 else if (!scroll && m_state == ScrollState) {
277 else if (!scroll && m_state == ScrollState) {
247 m_state = NoState;
278 m_state = NoState;
248 }
279 }
249
280
250 bool zoom = m_zoomCheckBox->isChecked();
281 bool zoom = m_zoomCheckBox->isChecked();
251
282
252 if (m_state != ZoomState && zoom) {
283 if (m_state != ZoomState && zoom) {
253 m_state = ZoomState;
284 m_state = ZoomState;
254 m_scrollCheckBox->setChecked(false);
285 m_scrollCheckBox->setChecked(false);
255 }
286 }
256 else if (!zoom && m_state == ZoomState) {
287 else if (!zoom && m_state == ZoomState) {
257 m_state = NoState;
288 m_state = NoState;
258 }
289 }
259 }
290 }
260
291
292 void Window::checkTemplate()
293 {
294
295 int index = m_templateComboBox->currentIndex();
296 if (m_template == index || index == 0)
297 return;
298
299 QString category = m_templateComboBox->itemData(index).toString();
300 Charts::ChartList list = Charts::chartList();
301
302 QList<QChart*> qchartList = m_chartHash.keys();
303
304 foreach(QChart* qchart,qchartList){
305 for(int i = 0 ; i < m_baseLayout->count();++i)
306 {
307 if(m_baseLayout->itemAt(i)==qchart){
308 m_baseLayout->removeAt(i);
309 break;
310 }
311 }
312 }
313
314 m_chartHash.clear();
315 qDeleteAll(qchartList);
316
317 QChart* qchart(0);
318
319 int j=0;
320 for (int i = 0; i < list.size(); ++i) {
321 Chart* chart = list.at(i);
322 if (chart->category() == category && j < 9) {
323 qchart = list.at(i)->createChart(m_dataTable);
324 m_baseLayout->addItem(qchart, j / 3, j % 3);
325 m_chartHash[qchart] = j;
326 j++;
327 }
328 }
329 for (; j < 9; ++j) {
330 qchart = new QChart();
331 qchart->setTitle(tr("Empty"));
332 m_baseLayout->addItem(qchart, j / 3, j % 3);
333 m_chartHash[qchart] = j;
334 }
335 }
336
261 void Window::checkTheme()
337 void Window::checkTheme()
262 {
338 {
263 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
339 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
264 m_themeComboBox->currentIndex()).toInt();
340 m_themeComboBox->currentIndex()).toInt();
265
341
266 foreach (QChart *chart, m_chartHash.keys())
342 foreach (QChart *chart, m_chartHash.keys())
267 chart->setTheme(theme);
343 chart->setTheme(theme);
268
344
269 QPalette pal = window()->palette();
345 QPalette pal = window()->palette();
270 if (theme == QChart::ChartThemeLight) {
346 if (theme == QChart::ChartThemeLight) {
271 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
347 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
272 pal.setColor(QPalette::WindowText, QRgb(0x404044));
348 pal.setColor(QPalette::WindowText, QRgb(0x404044));
273 }
349 }
274 else if (theme == QChart::ChartThemeDark) {
350 else if (theme == QChart::ChartThemeDark) {
275 pal.setColor(QPalette::Window, QRgb(0x121218));
351 pal.setColor(QPalette::Window, QRgb(0x121218));
276 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
352 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
277 }
353 }
278 else if (theme == QChart::ChartThemeBlueCerulean) {
354 else if (theme == QChart::ChartThemeBlueCerulean) {
279 pal.setColor(QPalette::Window, QRgb(0x40434a));
355 pal.setColor(QPalette::Window, QRgb(0x40434a));
280 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
356 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
281 }
357 }
282 else if (theme == QChart::ChartThemeBrownSand) {
358 else if (theme == QChart::ChartThemeBrownSand) {
283 pal.setColor(QPalette::Window, QRgb(0x9e8965));
359 pal.setColor(QPalette::Window, QRgb(0x9e8965));
284 pal.setColor(QPalette::WindowText, QRgb(0x404044));
360 pal.setColor(QPalette::WindowText, QRgb(0x404044));
285 }
361 }
286 else if (theme == QChart::ChartThemeBlueNcs) {
362 else if (theme == QChart::ChartThemeBlueNcs) {
287 pal.setColor(QPalette::Window, QRgb(0x018bba));
363 pal.setColor(QPalette::Window, QRgb(0x018bba));
288 pal.setColor(QPalette::WindowText, QRgb(0x404044));
364 pal.setColor(QPalette::WindowText, QRgb(0x404044));
289 }
365 }
290 else if (theme == QChart::ChartThemeHighContrast) {
366 else if (theme == QChart::ChartThemeHighContrast) {
291 pal.setColor(QPalette::Window, QRgb(0xffab03));
367 pal.setColor(QPalette::Window, QRgb(0xffab03));
292 pal.setColor(QPalette::WindowText, QRgb(0x181818));
368 pal.setColor(QPalette::WindowText, QRgb(0x181818));
293 }
369 }
294 else if (theme == QChart::ChartThemeBlueIcy) {
370 else if (theme == QChart::ChartThemeBlueIcy) {
295 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
371 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
296 pal.setColor(QPalette::WindowText, QRgb(0x404044));
372 pal.setColor(QPalette::WindowText, QRgb(0x404044));
297 }
373 }
298 else {
374 else {
299 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
375 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
300 pal.setColor(QPalette::WindowText, QRgb(0x404044));
376 pal.setColor(QPalette::WindowText, QRgb(0x404044));
301 }
377 }
302 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
378 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
303 widget->setPalette(pal);
379 widget->setPalette(pal);
304 }
380 }
305 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
381 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
306 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
382 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
307 }
383 }
308
384
309 void Window::mousePressEvent(QMouseEvent *event)
385 void Window::mousePressEvent(QMouseEvent *event)
310 {
386 {
311 if (event->button() == Qt::LeftButton) {
387 if (event->button() == Qt::LeftButton) {
312
388
313 m_origin = event->pos();
389 m_origin = event->pos();
314 m_currentState = NoState;
390 m_currentState = NoState;
315
391
316 foreach (QChart *chart, m_chartHash.keys()) {
392 foreach (QChart *chart, m_chartHash.keys()) {
317
393
318 QRectF geometryRect = chart->geometry();
394 QRectF geometryRect = chart->geometry();
319 QRectF plotArea = chart->plotArea();
395 QRectF plotArea = chart->plotArea();
320 plotArea.translate(geometryRect.topLeft());
396 plotArea.translate(geometryRect.topLeft());
321 if (plotArea.contains(m_origin)) {
397 if (plotArea.contains(m_origin)) {
322 m_currentState = m_state;
398 m_currentState = m_state;
323
399
324 if (m_currentState == NoState) {
400 if (m_currentState == NoState && m_templateComboBox->currentIndex()==0) {
325 showMenu(chart);
401 handleMenu(chart);
326 }
402 }
327 break;
403 break;
328 }
404 }
329 }
405 }
330
406
331 if (m_currentState == ZoomState) {
407 if (m_currentState == ZoomState) {
332 m_rubberBand->setRect(QRectF(m_origin, QSize()));
408 m_rubberBand->setRect(QRectF(m_origin, QSize()));
333 m_rubberBand->setVisible(true);
409 m_rubberBand->setVisible(true);
334 }
410 }
335
411
336 event->accept();
412 event->accept();
337 }
413 }
338
414
339 if (event->button() == Qt::RightButton) {
415 if (event->button() == Qt::RightButton) {
340 m_origin = event->pos();
416 m_origin = event->pos();
341 m_currentState = m_state;
417 m_currentState = m_state;
342 }
418 }
343 }
419 }
344
420
345 void Window::mouseMoveEvent(QMouseEvent *event)
421 void Window::mouseMoveEvent(QMouseEvent *event)
346 {
422 {
347 if ( m_currentState != NoState) {
423 if ( m_currentState != NoState) {
348
424
349 foreach (QChart *chart, m_chartHash.keys()) {
425 foreach (QChart *chart, m_chartHash.keys()) {
350
426
351 QRectF geometryRect = chart->geometry();
427 QRectF geometryRect = chart->geometry();
352 QRectF plotArea = chart->plotArea();
428 QRectF plotArea = chart->plotArea();
353 plotArea.translate(geometryRect.topLeft());
429 plotArea.translate(geometryRect.topLeft());
354
430
355 if (plotArea.contains(m_origin)) {
431 if (plotArea.contains(m_origin)) {
356 if (m_currentState == ScrollState) {
432 if (m_currentState == ScrollState) {
357 QPointF delta = m_origin - event->pos();
433 QPointF delta = m_origin - event->pos();
358 chart->scroll(delta.x(), -delta.y());
434 chart->scroll(delta.x(), -delta.y());
359 }
435 }
360 if (m_currentState == ZoomState && plotArea.contains(event->pos())) {
436 if (m_currentState == ZoomState && plotArea.contains(event->pos())) {
361 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
437 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
362 }
438 }
363 break;
439 break;
364 }
440 }
365 }
441 }
366 if(m_currentState == ScrollState) m_origin = event->pos();
442 if(m_currentState == ScrollState) m_origin = event->pos();
367 event->accept();
443 event->accept();
368 }
444 }
369 }
445 }
370
446
371 void Window::mouseReleaseEvent(QMouseEvent *event)
447 void Window::mouseReleaseEvent(QMouseEvent *event)
372 {
448 {
373 if (event->button() == Qt::LeftButton) {
449 if (event->button() == Qt::LeftButton) {
374 if (m_currentState == ZoomState) {
450 if (m_currentState == ZoomState) {
375 m_rubberBand->setVisible(false);
451 m_rubberBand->setVisible(false);
376
452
377 foreach (QChart *chart, m_chartHash.keys()) {
453 foreach (QChart *chart, m_chartHash.keys()) {
378
454
379 QRectF geometryRect = chart->geometry();
455 QRectF geometryRect = chart->geometry();
380 QRectF plotArea = chart->plotArea();
456 QRectF plotArea = chart->plotArea();
381 plotArea.translate(geometryRect.topLeft());
457 plotArea.translate(geometryRect.topLeft());
382
458
383 if (plotArea.contains(m_origin)) {
459 if (plotArea.contains(m_origin)) {
384 QRectF rect = m_rubberBand->rect();
460 QRectF rect = m_rubberBand->rect();
385 rect.translate(-geometryRect.topLeft());
461 rect.translate(-geometryRect.topLeft());
386 chart->zoomIn(rect);
462 chart->zoomIn(rect);
387 break;
463 break;
388 }
464 }
389 }
465 }
390 }
466 }
391
467
392 m_currentState = NoState;
468 m_currentState = NoState;
393 event->accept();
469 event->accept();
394 }
470 }
395
471
396 if (event->button() == Qt::RightButton) {
472 if (event->button() == Qt::RightButton) {
397
473
398 if (m_currentState == ZoomState) {
474 if (m_currentState == ZoomState) {
399 foreach (QChart *chart, m_chartHash.keys()) {
475 foreach (QChart *chart, m_chartHash.keys()) {
400
476
401 QRectF geometryRect = chart->geometry();
477 QRectF geometryRect = chart->geometry();
402 QRectF plotArea = chart->plotArea();
478 QRectF plotArea = chart->plotArea();
403 plotArea.translate(geometryRect.topLeft());
479 plotArea.translate(geometryRect.topLeft());
404
480
405 if (plotArea.contains(m_origin)) {
481 if (plotArea.contains(m_origin)) {
406 QRectF rect = m_rubberBand->rect();
482 QRectF rect = m_rubberBand->rect();
407 chart->zoomOut();
483 chart->zoomOut();
408 break;
484 break;
409 }
485 }
410 }
486 }
411 }
487 }
412 }
488 }
413 }
489 }
414
490
415 void Window::comboBoxFocused(QComboBox *combobox)
491 void Window::comboBoxFocused(QComboBox *combobox)
416 {
492 {
417 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
493 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
418 if(widget->widget()==combobox)
494 if(widget->widget()==combobox)
419 widget->setZValue(2.0);
495 widget->setZValue(2.0);
420 else
496 else
421 widget->setZValue(0.0);
497 widget->setZValue(0.0);
422 }
498 }
423 }
499 }
424
500
425 void Window::showMenu(QChart* qchart)
501 void Window::handleMenu(QChart* qchart)
426 {
502 {
427 QAction *chosen = m_menu->exec(QCursor::pos());
503 QAction *chosen = m_menu->exec(QCursor::pos());
428
504
429 if (chosen) {
505 if (chosen) {
430 Chart* chart = (Chart *) chosen->data().value<void *>();
506 Chart* chart = (Chart *) chosen->data().value<void *>();
431 int index = m_chartHash[qchart];
507 int index = m_chartHash[qchart];
432 //not in 4.7.2 m_baseLayout->removeItem(qchart);
508 //not in 4.7.2 m_baseLayout->removeItem(qchart);
433 for(int i = 0 ; i < m_baseLayout->count();++i)
509 for(int i = 0 ; i < m_baseLayout->count();++i)
434 {
510 {
435 if(m_baseLayout->itemAt(i)==qchart){
511 if(m_baseLayout->itemAt(i)==qchart){
436 m_baseLayout->removeAt(i);
512 m_baseLayout->removeAt(i);
437 break;
513 break;
438 }
514 }
439 }
515 }
440
516
441 m_chartHash.remove(qchart);
517 m_chartHash.remove(qchart);
442 QChart* newChart = chart->createChart(m_dataTable);
518 QChart* newChart = chart->createChart(m_dataTable);
443 m_baseLayout->addItem(newChart, index / 3, index % 3);
519 m_baseLayout->addItem(newChart, index / 3, index % 3);
444 m_chartHash[newChart] = index;
520 m_chartHash[newChart] = index;
445 delete qchart;
521 delete qchart;
446 updateUI();
522 updateUI();
447 }
523 }
448
524
449 }
525 }
450
526
527 QMenu* Window::createMenu()
528 {
529 Charts::ChartList list = Charts::chartList();
530 QMultiMap<QString, Chart*> categoryMap;
531
532 QMenu* result = new QMenu(this);
533
534 foreach(Chart* chart, list) {
535 categoryMap.insertMulti(chart->category(), chart);
536 }
537
538 foreach(const QString& category, categoryMap.uniqueKeys()) {
539 QMenu* menu(0);
540 QMultiMap<QString, Chart*> subCategoryMap;
541 if (category.isEmpty()) {
542 menu = result;
543 }
544 else {
545 menu = new QMenu(category, this);
546 result->addMenu(menu);
547 }
548
549 foreach(Chart* chart , categoryMap.values(category)) {
550 subCategoryMap.insert(chart->subCategory(), chart);
551 }
552
553 foreach(const QString& subCategory, subCategoryMap.uniqueKeys()) {
554 QMenu* subMenu(0);
555 if (subCategory.isEmpty()) {
556 subMenu = menu;
557 }
558 else {
559 subMenu = new QMenu(subCategory, this);
560 menu->addMenu(subMenu);
561 }
562
563 foreach(Chart* chart , subCategoryMap.values(subCategory)) {
564
565 createMenuAction(subMenu, QIcon(), chart->name(),
566 qVariantFromValue((void *) chart));
567 }
568 }
569 }
570
571 return result;
572 }
573
451 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
574 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
452 const QVariant &data)
575 const QVariant &data)
453 {
576 {
454 QAction *action = menu->addAction(icon, text);
577 QAction *action = menu->addAction(icon, text);
455 action->setCheckable(false);
578 action->setCheckable(false);
456 action->setData(data);
579 action->setData(data);
457 return action;
580 return action;
458 }
581 }
@@ -1,118 +1,123
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 "model.h"
23 #include "model.h"
24 #include <QMainWindow>
24 #include <QMainWindow>
25 #include <QChartGlobal>
25 #include <QChartGlobal>
26 #include <QHash>
26 #include <QHash>
27 #include <QComboBox>
27 #include <QComboBox>
28
28
29 class QCheckBox;
29 class QCheckBox;
30 class QGraphicsRectItem;
30 class QGraphicsRectItem;
31 class QGraphicsScene;
31 class QGraphicsScene;
32 class QGraphicsWidget;
32 class QGraphicsWidget;
33 class View;
33 class View;
34 class QGraphicsGridLayout;
34 class QGraphicsGridLayout;
35 class Chart;
35 class Chart;
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 class QChart;
38 class QChart;
39 QTCOMMERCIALCHART_END_NAMESPACE
39 QTCOMMERCIALCHART_END_NAMESPACE
40
40
41 QTCOMMERCIALCHART_USE_NAMESPACE
41 QTCOMMERCIALCHART_USE_NAMESPACE
42
42
43
43
44 class Window: public QMainWindow
44 class Window: public QMainWindow
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 enum State{ NoState = 0, ZoomState, ScrollState};
47 enum State{ NoState = 0, ZoomState, ScrollState};
48 public:
48 public:
49 explicit Window(QWidget *parent = 0);
49 explicit Window(QWidget *parent = 0);
50 ~Window();
50 ~Window();
51
51
52 private Q_SLOTS:
52 private Q_SLOTS:
53 void updateUI();
53 void updateUI();
54 private:
54 private:
55 QComboBox* createThemeBox();
55 QComboBox* createThemeBox();
56 QComboBox* createAnimationBox();
56 QComboBox* createAnimationBox();
57 QComboBox* createLegendBox();
57 QComboBox* createLegendBox();
58 QComboBox* createTempleteBox();
58 void connectSignals();
59 void connectSignals();
59 void createProxyWidgets();
60 void createProxyWidgets();
60 void comboBoxFocused(QComboBox *combox);
61 void comboBoxFocused(QComboBox *combox);
61 inline void checkAnimationOptions();
62 inline void checkAnimationOptions();
62 inline void checkLegend();
63 inline void checkLegend();
63 inline void checkOpenGL();
64 inline void checkOpenGL();
64 inline void checkTheme();
65 inline void checkTheme();
65 inline void checkState();
66 inline void checkState();
66 void showMenu(QChart * chart);
67 inline void checkTemplate();
68 QMenu* createMenu();
69 void handleMenu(QChart * chart);
67 QAction* createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
70 QAction* createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
68
71
69 protected:
72 protected:
70 void mousePressEvent(QMouseEvent *event);
73 void mousePressEvent(QMouseEvent *event);
71 void mouseMoveEvent(QMouseEvent *event);
74 void mouseMoveEvent(QMouseEvent *event);
72 void mouseReleaseEvent(QMouseEvent *event);
75 void mouseReleaseEvent(QMouseEvent *event);
73
76
74 private:
77 private:
75 int m_listCount;
78 int m_listCount;
76 int m_valueMax;
79 int m_valueMax;
77 int m_valueCount;
80 int m_valueCount;
78 QGraphicsScene* m_scene;
81 QGraphicsScene* m_scene;
79 View* m_view;
82 View* m_view;
80 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
83 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
81 QHash<QChart*, int> m_chartHash;
84 QHash<QChart*, int> m_chartHash;
82 DataTable m_dataTable;
85 DataTable m_dataTable;
83
86
84 QGraphicsWidget *m_form;
87 QGraphicsWidget *m_form;
85 QComboBox *m_themeComboBox;
88 QComboBox *m_themeComboBox;
86 QCheckBox *m_antialiasCheckBox;
89 QCheckBox *m_antialiasCheckBox;
87 QComboBox *m_animatedComboBox;
90 QComboBox *m_animatedComboBox;
88 QComboBox *m_legendComboBox;
91 QComboBox *m_legendComboBox;
92 QComboBox *m_templateComboBox;
89 QCheckBox *m_openGLCheckBox;
93 QCheckBox *m_openGLCheckBox;
90 QCheckBox *m_zoomCheckBox;
94 QCheckBox *m_zoomCheckBox;
91 QCheckBox *m_scrollCheckBox;
95 QCheckBox *m_scrollCheckBox;
92 QPoint m_origin;
96 QPoint m_origin;
93 QGraphicsRectItem* m_rubberBand;
97 QGraphicsRectItem* m_rubberBand;
94 QGraphicsGridLayout* m_baseLayout;
98 QGraphicsGridLayout* m_baseLayout;
95 QMenu* m_menu;
99 QMenu* m_menu;
96 State m_state;
100 State m_state;
97 State m_currentState;
101 State m_currentState;
102 int m_template;
98
103
99 friend class ComboBox;
104 friend class ComboBox;
100 };
105 };
101
106
102 class ComboBox: public QComboBox
107 class ComboBox: public QComboBox
103 {
108 {
104 public:
109 public:
105 ComboBox(Window* window,QWidget *parent = 0):QComboBox(parent),m_window(window)
110 ComboBox(Window* window,QWidget *parent = 0):QComboBox(parent),m_window(window)
106 {}
111 {}
107
112
108 protected:
113 protected:
109 void focusInEvent(QFocusEvent *e)
114 void focusInEvent(QFocusEvent *e)
110 {
115 {
111 QComboBox::focusInEvent(e);
116 QComboBox::focusInEvent(e);
112 m_window->comboBoxFocused(this);
117 m_window->comboBoxFocused(this);
113 }
118 }
114 private:
119 private:
115 Window* m_window;
120 Window* m_window;
116 };
121 };
117
122
118 #endif
123 #endif
General Comments 0
You need to be logged in to leave comments. Login now