##// END OF EJS Templates
Add horizontal charts to chartviewer
Michal Klocek -
r1755:1a6e0b1256e1
parent child
Show More
@@ -0,0 +1,60
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "charts.h"
22 #include "qchart.h"
23 #include "qhorizontalbarseries.h"
24 #include "qbarset.h"
25
26 class HorizontalBarChart: public Chart
27 {
28 public:
29
30 HorizontalBarChart(){
31 initialize();
32 }
33
34 QString name() { return QObject::tr("HorizontalBarChart"); }
35 QString category() { return QObject::tr("BarSeries"); }
36 QString subCategory() { return QObject::tr("Vertical"); }
37
38 QChart* createChart(const DataTable& table)
39 {
40
41 QChart* chart = new QChart();
42
43 chart->setTitle("Horizontal bar chart");
44
45 QHorizontalBarSeries* series = new QHorizontalBarSeries(chart);
46 for (int i(0); i < table.count(); i++) {
47 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
48 foreach (Data data, table[i])
49 *set << data.first.y();
50 series->append(set);
51 }
52 chart->addSeries(series);
53 chart->createDefaultAxes();
54 return chart;
55 }
56
57 };
58
59 DECLARE_CHART(HorizontalBarChart)
60
@@ -0,0 +1,60
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "charts.h"
22 #include "qchart.h"
23 #include "qhorizontalstackedbarseries.h"
24 #include "qbarset.h"
25
26 class HorizontalStackedBarChart: public Chart
27 {
28 public:
29
30 HorizontalStackedBarChart(){
31 initialize();
32 }
33
34 QString name() { return QObject::tr("HorizontalStackedBarChart"); }
35 QString category() { return QObject::tr("BarSeries"); }
36 QString subCategory() { return QObject::tr("Vertical"); }
37
38 QChart* createChart(const DataTable& table)
39 {
40
41 QChart* chart = new QChart();
42
43 chart->setTitle("Horizontal stacked chart");
44
45 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries(chart);
46 for (int i(0); i < table.count(); i++) {
47 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
48 foreach (Data data, table[i])
49 *set << data.first.y();
50 series->append(set);
51 }
52 chart->addSeries(series);
53 chart->createDefaultAxes();
54 return chart;
55 }
56
57 };
58
59 DECLARE_CHART(HorizontalStackedBarChart)
60
@@ -0,0 +1,60
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "charts.h"
22 #include "qchart.h"
23 #include "qbarseries.h"
24 #include "qbarset.h"
25
26 class VerticalBarChart: public Chart
27 {
28 public:
29
30 VerticalBarChart(){
31 initialize();
32 }
33
34 QString name() { return QObject::tr("VerticalBarChart"); }
35 QString category() { return QObject::tr("BarSeries"); }
36 QString subCategory() { return QObject::tr("Vertical"); }
37
38 QChart* createChart(const DataTable& table)
39 {
40
41 QChart* chart = new QChart();
42
43 chart->setTitle("Vertical bar chart");
44
45 QBarSeries* series = new QBarSeries(chart);
46 for (int i(0); i < table.count(); i++) {
47 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
48 foreach (Data data, table[i])
49 *set << data.first.y();
50 series->append(set);
51 }
52 chart->addSeries(series);
53 chart->createDefaultAxes();
54 return chart;
55 }
56
57 };
58
59 DECLARE_CHART(VerticalBarChart)
60
@@ -0,0 +1,67
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef MODEL_H_
22 #define MODEL_H_
23
24 #include <QList>
25 #include <QPair>
26 #include <QPointF>
27 #include <QTime>
28
29 typedef QPair<QPointF, QString> Data;
30 typedef QList<Data> DataList;
31 typedef QList<DataList> DataTable;
32
33
34 class Model
35 {
36 private:
37 Model(){}
38
39 public:
40 static DataTable generateRandomData(int listCount, int valueMax, int valueCount)
41 {
42 DataTable dataTable;
43
44 // set seed for random stuff
45 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
46
47 // generate random data
48 for (int i(0); i < listCount; i++) {
49 DataList dataList;
50 qreal yValue(0);
51 for (int j(0); j < valueCount; j++) {
52 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
53 QPointF value(
54 (j + (qreal) qrand() / (qreal) RAND_MAX)
55 * ((qreal) valueMax / (qreal) valueCount), yValue);
56 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
57 dataList << Data(value, label);
58 }
59 dataTable << dataList;
60 }
61
62 return dataTable;
63 }
64
65 };
66
67 #endif
@@ -1,86 +1,86
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
21
22 #ifndef CHARTS_H
22 #ifndef CHARTS_H
23 #define CHARTS_H
23 #define CHARTS_H
24 #include "window.h"
24 #include "model.h"
25 #include <QList>
25 #include <QList>
26 #include <QString>
26 #include <QString>
27 #include <qchartglobal.h>
27 #include <qchartglobal.h>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QChart;
30 class QChart;
31 QTCOMMERCIALCHART_END_NAMESPACE
31 QTCOMMERCIALCHART_END_NAMESPACE
32
32
33 QTCOMMERCIALCHART_USE_NAMESPACE
33 QTCOMMERCIALCHART_USE_NAMESPACE
34
34
35 class Chart
35 class Chart
36 {
36 {
37 public:
37 public:
38 Chart();
38 Chart();
39
39
40 virtual ~Chart();
40 virtual ~Chart();
41
41
42 virtual void initialize();
42 virtual void initialize();
43 virtual QChart* createChart(const DataTable& table) = 0;
43 virtual QChart* createChart(const DataTable& table) = 0;
44 virtual QString name() = 0;
44 virtual QString name() = 0;
45 virtual QString category() = 0;
45 virtual QString category() = 0;
46 virtual QString subCategory() = 0;
46 virtual QString subCategory() = 0;
47
47
48 };
48 };
49
49
50 namespace Charts
50 namespace Charts
51 {
51 {
52
52
53 typedef QList<Chart*> ChartList;
53 typedef QList<Chart*> ChartList;
54
54
55 inline ChartList& chartList()
55 inline ChartList& chartList()
56 {
56 {
57 static ChartList list;
57 static ChartList list;
58 return list;
58 return list;
59 }
59 }
60
60
61 inline bool findChart(Chart* chart)
61 inline bool findChart(Chart* chart)
62 {
62 {
63 ChartList& list = chartList();
63 ChartList& list = chartList();
64 if (list.contains(chart)) {
64 if (list.contains(chart)) {
65 return true;
65 return true;
66 }
66 }
67 foreach (Chart* item, list) {
67 foreach (Chart* item, list) {
68 if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) {
68 if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) {
69 return true;
69 return true;
70 }
70 }
71 }
71 }
72 return false;
72 return false;
73 }
73 }
74
74
75 inline void addChart(Chart* chart)
75 inline void addChart(Chart* chart)
76 {
76 {
77 ChartList& list = chartList();
77 ChartList& list = chartList();
78 if (!findChart(chart)) {
78 if (!findChart(chart)) {
79 list.append(chart);
79 list.append(chart);
80 }
80 }
81 }
81 }
82 }
82 }
83
83
84 #define DECLARE_CHART(chartName) static chartName t;
84 #define DECLARE_CHART(chartName) static chartName t;
85
85
86 #endif
86 #endif
@@ -1,4 +1,13
1 INCLUDEPATH += $$PWD
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3
4 SOURCES+= linechart.cpp scatterchart.cpp splinechart.cpp piechart.cpp barchart.cpp areachart.cpp No newline at end of file
4 SOURCES+= \
5 linechart.cpp \
6 scatterchart.cpp \
7 splinechart.cpp \
8 piechart.cpp \
9 verticalstackedbarchart.cpp \
10 horizontalstackedbarchart.cpp \
11 verticalbarchart.cpp \
12 horizontalbarchart.cpp \
13 areachart.cpp No newline at end of file
@@ -1,60 +1,60
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 "qstackedbarseries.h"
23 #include "qstackedbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25
25
26 class BarChart: public Chart
26 class VerticalStackedBarChart: public Chart
27 {
27 {
28 public:
28 public:
29
29
30 BarChart(){
30 VerticalStackedBarChart(){
31 initialize();
31 initialize();
32 }
32 }
33
33
34 QString name() { return QObject::tr("VerticalStackedBarChart"); }
34 QString name() { return QObject::tr("VerticalStackedBarChart"); }
35 QString category() { return QObject::tr("BarSeries"); }
35 QString category() { return QObject::tr("BarSeries"); }
36 QString subCategory() { return QObject::tr("Vertical"); }
36 QString subCategory() { return QObject::tr("Vertical"); }
37
37
38 QChart* createChart(const DataTable& table)
38 QChart* createChart(const DataTable& table)
39 {
39 {
40
40
41 QChart* chart = new QChart();
41 QChart* chart = new QChart();
42
42
43 chart->setTitle("Bar chart");
43 chart->setTitle("Stacked bar chart");
44
44
45 QStackedBarSeries* series = new QStackedBarSeries(chart);
45 QStackedBarSeries* series = new QStackedBarSeries(chart);
46 for (int i(0); i < table.count(); i++) {
46 for (int i(0); i < table.count(); i++) {
47 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
47 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
48 foreach (Data data, table[i])
48 foreach (Data data, table[i])
49 *set << data.first.y();
49 *set << data.first.y();
50 series->append(set);
50 series->append(set);
51 }
51 }
52 chart->addSeries(series);
52 chart->addSeries(series);
53 chart->createDefaultAxes();
53 chart->createDefaultAxes();
54 return chart;
54 return chart;
55 }
55 }
56
56
57 };
57 };
58
58
59 DECLARE_CHART(BarChart)
59 DECLARE_CHART(VerticalStackedBarChart)
60
60
@@ -1,7 +1,7
1 !include( ../demos.pri ):error( "Couldn't find the demos.pri file!" )
1 !include( ../demos.pri ):error( "Couldn't find the demos.pri file!" )
2 include(charts/charts.pri)
2 include(charts/charts.pri)
3 TARGET = chartviewer
3 TARGET = chartviewer
4 QT += opengl
4 QT += opengl
5 SOURCES += main.cpp window.cpp view.cpp charts.cpp
5 SOURCES += main.cpp window.cpp view.cpp charts.cpp
6 HEADERS += window.h view.h charts.h
6 HEADERS += window.h view.h charts.h model.h
7
7
@@ -1,433 +1,395
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
25 #include <QChartView>
24 #include <QChartView>
26 #include <QPieSeries>
27 #include <QPieSlice>
28 #include <QPercentBarSeries>
29 #include <QStackedBarSeries>
30 #include <QBarSeries>
31 #include <QBarSet>
32 #include <QLineSeries>
33 #include <QSplineSeries>
34 #include <QScatterSeries>
35 #include <QAreaSeries>
25 #include <QAreaSeries>
36 #include <QLegend>
26 #include <QLegend>
37 #include <QGridLayout>
27 #include <QGridLayout>
38 #include <QFormLayout>
28 #include <QFormLayout>
39 #include <QComboBox>
29 #include <QComboBox>
40 #include <QSpinBox>
30 #include <QSpinBox>
41 #include <QCheckBox>
31 #include <QCheckBox>
42 #include <QGroupBox>
32 #include <QGroupBox>
43 #include <QLabel>
33 #include <QLabel>
44 #include <QTime>
45 #include <QBarCategoriesAxis>
46 #include <QGraphicsScene>
34 #include <QGraphicsScene>
47 #include <QGraphicsGridLayout>
35 #include <QGraphicsGridLayout>
48 #include <QGraphicsLinearLayout>
36 #include <QGraphicsLinearLayout>
49 #include <QGraphicsProxyWidget>
37 #include <QGraphicsProxyWidget>
50 #include <QGLWidget>
38 #include <QGLWidget>
51 #include <QApplication>
39 #include <QApplication>
52 #include <QDebug>
40 #include <QDebug>
53
41
54 Window::Window(QWidget* parent) :
42 Window::Window(QWidget* parent) :
55 QMainWindow(parent),
43 QMainWindow(parent),
56 m_listCount(3),
44 m_listCount(3),
57 m_valueMax(10),
45 m_valueMax(10),
58 m_valueCount(7),
46 m_valueCount(7),
59 m_scene(new QGraphicsScene(this)),
47 m_scene(new QGraphicsScene(this)),
60 m_view(0),
48 m_view(0),
61 m_dataTable(generateRandomData(m_listCount, m_valueMax, m_valueCount)),
49 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
62 m_form(0),
50 m_form(0),
63 m_themeComboBox(0),
51 m_themeComboBox(0),
64 m_antialiasCheckBox(0),
52 m_antialiasCheckBox(0),
65 m_animatedComboBox(0),
53 m_animatedComboBox(0),
66 m_legendComboBox(0),
54 m_legendComboBox(0),
67 m_openGLCheckBox(0),
55 m_openGLCheckBox(0),
68 m_zoomCheckBox(0),
56 m_zoomCheckBox(0),
69 m_scrollCheckBox(0),
57 m_scrollCheckBox(0),
70 m_rubberBand(new QGraphicsRectItem()),
58 m_rubberBand(new QGraphicsRectItem()),
71 m_isScrolling(false),
59 m_isScrolling(false),
72 m_isZooming(false),
60 m_isZooming(false),
73 m_scroll(false),
61 m_scroll(false),
74 m_zoom(false)
62 m_zoom(false)
75 {
63 {
76 createProxyWidgets();
64 createProxyWidgets();
77 connectSignals();
65 connectSignals();
78
66
79 // create layout
67 // create layout
80 QGraphicsGridLayout* baseLayout = new QGraphicsGridLayout();
68 QGraphicsGridLayout* baseLayout = new QGraphicsGridLayout();
81 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
69 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
82 settingsLayout->setOrientation(Qt::Vertical);
70 settingsLayout->setOrientation(Qt::Vertical);
83 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
71 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
84 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
72 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
85 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
73 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
86 settingsLayout->addItem(m_widgetHash["themeLabel"]);
74 settingsLayout->addItem(m_widgetHash["themeLabel"]);
87 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
75 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
88 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
76 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
89 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
77 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
90 settingsLayout->addItem(m_widgetHash["legendLabel"]);
78 settingsLayout->addItem(m_widgetHash["legendLabel"]);
91 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
79 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
92 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
80 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
93 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
81 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
94 settingsLayout->addStretch();
82 settingsLayout->addStretch();
95 baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
83 baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
96 //create charts
84 //create charts
97
85
98 Charts::ChartList list = Charts::chartList();
86 Charts::ChartList list = Charts::chartList();
99
87
100 for(int i = 0 ; i < 6 ; ++i)
88 for(int i = 0 ; i < 9 && i<list.size() ; ++i)
101 {
89 {
102 if(!(i<list.size()) || list.isEmpty()) break;
103 QChart* chart = list.at(i)->createChart(m_dataTable);
90 QChart* chart = list.at(i)->createChart(m_dataTable);
104 baseLayout->addItem(chart, i/3, i%3);
91 baseLayout->addItem(chart, i/3, i%3);
105 m_chartList << chart;
92 m_chartList << chart;
106 }
93 }
107
94
108 m_form = new QGraphicsWidget();
95 m_form = new QGraphicsWidget();
109 m_form->setLayout(baseLayout);
96 m_form->setLayout(baseLayout);
110 m_scene->addItem(m_form);
97 m_scene->addItem(m_form);
111 m_scene->addItem(m_rubberBand);
98 m_scene->addItem(m_rubberBand);
112 m_rubberBand->setVisible(false);
99 m_rubberBand->setVisible(false);
113
100
114 m_view = new View(m_scene, m_form);
101 m_view = new View(m_scene, m_form);
115 m_view->setMinimumSize(m_form->preferredSize().toSize());
102 m_view->setMinimumSize(m_form->preferredSize().toSize());
116
103
117 // Set defaults
104 // Set defaults
118 m_antialiasCheckBox->setChecked(true);
105 m_antialiasCheckBox->setChecked(true);
119 updateUI();
106 updateUI();
120 setCentralWidget(m_view);
107 setCentralWidget(m_view);
121 }
108 }
122
109
123 Window::~Window()
110 Window::~Window()
124 {
111 {
125 }
112 }
126
113
127 void Window::connectSignals()
114 void Window::connectSignals()
128 {
115 {
129 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
130 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
117 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
131 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
118 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
132 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
119 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
133 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
120 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
134 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
121 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
135 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
122 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
136 }
123 }
137
124
138 DataTable Window::generateRandomData(int listCount, int valueMax, int valueCount) const
139 {
140 DataTable dataTable;
141
142 // set seed for random stuff
143 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
144
145 // generate random data
146 for (int i(0); i < listCount; i++) {
147 DataList dataList;
148 qreal yValue(0);
149 for (int j(0); j < valueCount; j++) {
150 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
151 QPointF value(
152 (j + (qreal) qrand() / (qreal) RAND_MAX)
153 * ((qreal) m_valueMax / (qreal) valueCount), yValue);
154 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
155 dataList << Data(value, label);
156 }
157 dataTable << dataList;
158 }
159
160 return dataTable;
161 }
162
163 void Window::createProxyWidgets()
125 void Window::createProxyWidgets()
164 {
126 {
165 m_themeComboBox = createThemeBox();
127 m_themeComboBox = createThemeBox();
166 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
128 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
167 m_animatedComboBox = createAnimationBox();
129 m_animatedComboBox = createAnimationBox();
168 m_legendComboBox = createLegendBox();
130 m_legendComboBox = createLegendBox();
169 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
131 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
170 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
132 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
171 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
133 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
172 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
134 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
173 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
135 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
174 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
136 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
175 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
137 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
176 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
138 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
177 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
139 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
178 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
140 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
179 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
141 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
180 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
142 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
181 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
143 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
182 }
144 }
183
145
184 QComboBox* Window::createThemeBox()
146 QComboBox* Window::createThemeBox()
185 {
147 {
186 // settings layoutQGLWidget’
148 // settings layoutQGLWidget’
187 QComboBox* themeComboBox = new ComboBox(this);
149 QComboBox* themeComboBox = new ComboBox(this);
188 themeComboBox->addItem("Light", QChart::ChartThemeLight);
150 themeComboBox->addItem("Light", QChart::ChartThemeLight);
189 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
151 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
190 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
152 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
191 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
153 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
192 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
154 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
193 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
155 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
194 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
156 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
195 return themeComboBox;
157 return themeComboBox;
196 }
158 }
197
159
198 QComboBox* Window::createAnimationBox()
160 QComboBox* Window::createAnimationBox()
199 {
161 {
200 // settings layout
162 // settings layout
201 QComboBox* animationComboBox = new ComboBox(this);
163 QComboBox* animationComboBox = new ComboBox(this);
202 animationComboBox->addItem("No Animations", QChart::NoAnimation);
164 animationComboBox->addItem("No Animations", QChart::NoAnimation);
203 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
165 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
204 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
166 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
205 animationComboBox->addItem("All Animations", QChart::AllAnimations);
167 animationComboBox->addItem("All Animations", QChart::AllAnimations);
206 return animationComboBox;
168 return animationComboBox;
207 }
169 }
208
170
209 QComboBox* Window::createLegendBox()
171 QComboBox* Window::createLegendBox()
210 {
172 {
211 QComboBox* legendComboBox = new ComboBox(this);
173 QComboBox* legendComboBox = new ComboBox(this);
212 legendComboBox->addItem("No Legend ", 0);
174 legendComboBox->addItem("No Legend ", 0);
213 legendComboBox->addItem("Legend Top", Qt::AlignTop);
175 legendComboBox->addItem("Legend Top", Qt::AlignTop);
214 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
176 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
215 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
177 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
216 legendComboBox->addItem("Legend Right", Qt::AlignRight);
178 legendComboBox->addItem("Legend Right", Qt::AlignRight);
217 return legendComboBox;
179 return legendComboBox;
218 }
180 }
219
181
220 void Window::updateUI()
182 void Window::updateUI()
221 {
183 {
222 bool opengl = m_openGLCheckBox->isChecked();
184 bool opengl = m_openGLCheckBox->isChecked();
223 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
185 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
224 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
186 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
225 m_view->deleteLater();
187 m_view->deleteLater();
226 m_view = new View(m_scene, m_form);
188 m_view = new View(m_scene, m_form);
227 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
189 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
228 setCentralWidget(m_view);
190 setCentralWidget(m_view);
229 }
191 }
230
192
231 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
193 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
232 m_themeComboBox->currentIndex()).toInt();
194 m_themeComboBox->currentIndex()).toInt();
233
195
234 foreach (QChart *chart, m_chartList)
196 foreach (QChart *chart, m_chartList)
235 chart->setTheme(theme);
197 chart->setTheme(theme);
236
198
237 QPalette pal = window()->palette();
199 QPalette pal = window()->palette();
238 if (theme == QChart::ChartThemeLight) {
200 if (theme == QChart::ChartThemeLight) {
239 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
201 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
240 pal.setColor(QPalette::WindowText, QRgb(0x404044));
202 pal.setColor(QPalette::WindowText, QRgb(0x404044));
241 }
203 }
242 else if (theme == QChart::ChartThemeDark) {
204 else if (theme == QChart::ChartThemeDark) {
243 pal.setColor(QPalette::Window, QRgb(0x121218));
205 pal.setColor(QPalette::Window, QRgb(0x121218));
244 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
206 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
245 }
207 }
246 else if (theme == QChart::ChartThemeBlueCerulean) {
208 else if (theme == QChart::ChartThemeBlueCerulean) {
247 pal.setColor(QPalette::Window, QRgb(0x40434a));
209 pal.setColor(QPalette::Window, QRgb(0x40434a));
248 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
210 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
249 }
211 }
250 else if (theme == QChart::ChartThemeBrownSand) {
212 else if (theme == QChart::ChartThemeBrownSand) {
251 pal.setColor(QPalette::Window, QRgb(0x9e8965));
213 pal.setColor(QPalette::Window, QRgb(0x9e8965));
252 pal.setColor(QPalette::WindowText, QRgb(0x404044));
214 pal.setColor(QPalette::WindowText, QRgb(0x404044));
253 }
215 }
254 else if (theme == QChart::ChartThemeBlueNcs) {
216 else if (theme == QChart::ChartThemeBlueNcs) {
255 pal.setColor(QPalette::Window, QRgb(0x018bba));
217 pal.setColor(QPalette::Window, QRgb(0x018bba));
256 pal.setColor(QPalette::WindowText, QRgb(0x404044));
218 pal.setColor(QPalette::WindowText, QRgb(0x404044));
257 }
219 }
258 else if (theme == QChart::ChartThemeHighContrast) {
220 else if (theme == QChart::ChartThemeHighContrast) {
259 pal.setColor(QPalette::Window, QRgb(0xffab03));
221 pal.setColor(QPalette::Window, QRgb(0xffab03));
260 pal.setColor(QPalette::WindowText, QRgb(0x181818));
222 pal.setColor(QPalette::WindowText, QRgb(0x181818));
261 }
223 }
262 else if (theme == QChart::ChartThemeBlueIcy) {
224 else if (theme == QChart::ChartThemeBlueIcy) {
263 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
225 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
264 pal.setColor(QPalette::WindowText, QRgb(0x404044));
226 pal.setColor(QPalette::WindowText, QRgb(0x404044));
265 }
227 }
266 else {
228 else {
267 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
229 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
268 pal.setColor(QPalette::WindowText, QRgb(0x404044));
230 pal.setColor(QPalette::WindowText, QRgb(0x404044));
269 }
231 }
270 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
232 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
271 widget->setPalette(pal);
233 widget->setPalette(pal);
272 }
234 }
273 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
235 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
274 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
236 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
275
237
276 QChart::AnimationOptions options(
238 QChart::AnimationOptions options(
277 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
239 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
278 if (!m_chartList.isEmpty() && m_chartList.at(0)->animationOptions() != options) {
240 if (!m_chartList.isEmpty() && m_chartList.at(0)->animationOptions() != options) {
279 foreach (QChart *chart, m_chartList)
241 foreach (QChart *chart, m_chartList)
280 chart->setAnimationOptions(options);
242 chart->setAnimationOptions(options);
281 }
243 }
282
244
283 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
245 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
284
246
285 if (!alignment) {
247 if (!alignment) {
286 foreach (QChart *chart, m_chartList) {
248 foreach (QChart *chart, m_chartList) {
287 chart->legend()->hide();
249 chart->legend()->hide();
288 }
250 }
289 }
251 }
290 else {
252 else {
291 foreach (QChart *chart, m_chartList) {
253 foreach (QChart *chart, m_chartList) {
292 chart->legend()->setAlignment(alignment);
254 chart->legend()->setAlignment(alignment);
293 chart->legend()->show();
255 chart->legend()->show();
294 }
256 }
295 }
257 }
296
258
297 bool antialias = m_antialiasCheckBox->isChecked();
259 bool antialias = m_antialiasCheckBox->isChecked();
298
260
299 if (opengl)
261 if (opengl)
300 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
262 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
301 else
263 else
302 m_view->setRenderHint(QPainter::Antialiasing, antialias);
264 m_view->setRenderHint(QPainter::Antialiasing, antialias);
303
265
304 bool scroll = m_scrollCheckBox->isChecked();
266 bool scroll = m_scrollCheckBox->isChecked();
305
267
306 if(!m_scroll & scroll){
268 if(!m_scroll & scroll){
307 m_scroll=true;
269 m_scroll=true;
308 m_zoom=false;
270 m_zoom=false;
309 m_zoomCheckBox->setChecked(false);
271 m_zoomCheckBox->setChecked(false);
310 }
272 }
311
273
312 bool zoom = m_zoomCheckBox->isChecked();
274 bool zoom = m_zoomCheckBox->isChecked();
313
275
314 if(!m_zoom & zoom){
276 if(!m_zoom & zoom){
315 m_scroll=false;
277 m_scroll=false;
316 m_zoom=true;
278 m_zoom=true;
317 m_scrollCheckBox->setChecked(false);
279 m_scrollCheckBox->setChecked(false);
318 }
280 }
319
281
320 }
282 }
321
283
322 void Window::mousePressEvent(QMouseEvent *event)
284 void Window::mousePressEvent(QMouseEvent *event)
323 {
285 {
324 if (event->button() == Qt::LeftButton) {
286 if (event->button() == Qt::LeftButton) {
325
287
326 m_origin = event->pos();
288 m_origin = event->pos();
327 m_isScrolling = false;
289 m_isScrolling = false;
328 m_isZooming = false;
290 m_isZooming = false;
329
291
330 foreach (QChart *chart, m_chartList) {
292 foreach (QChart *chart, m_chartList) {
331
293
332 QRectF geometryRect = chart->geometry();
294 QRectF geometryRect = chart->geometry();
333 QRectF plotArea = chart->plotArea();
295 QRectF plotArea = chart->plotArea();
334 plotArea.translate(geometryRect.topLeft());
296 plotArea.translate(geometryRect.topLeft());
335 if (plotArea.contains(m_origin)) {
297 if (plotArea.contains(m_origin)) {
336 m_isScrolling = m_scroll;
298 m_isScrolling = m_scroll;
337 m_isZooming = m_zoom;
299 m_isZooming = m_zoom;
338 break;
300 break;
339 }
301 }
340 }
302 }
341
303
342 if (m_isZooming) {
304 if (m_isZooming) {
343 m_rubberBand->setRect(QRectF(m_origin, QSize()));
305 m_rubberBand->setRect(QRectF(m_origin, QSize()));
344 m_rubberBand->setVisible(true);
306 m_rubberBand->setVisible(true);
345 }
307 }
346 event->accept();
308 event->accept();
347 }
309 }
348
310
349 if (event->button() == Qt::RightButton) {
311 if (event->button() == Qt::RightButton) {
350 m_origin = event->pos();
312 m_origin = event->pos();
351 m_isZooming = m_zoom;
313 m_isZooming = m_zoom;
352 }
314 }
353 }
315 }
354
316
355 void Window::mouseMoveEvent(QMouseEvent *event)
317 void Window::mouseMoveEvent(QMouseEvent *event)
356 {
318 {
357 if (m_isScrolling || m_isZooming) {
319 if (m_isScrolling || m_isZooming) {
358
320
359 foreach (QChart *chart, m_chartList) {
321 foreach (QChart *chart, m_chartList) {
360
322
361 QRectF geometryRect = chart->geometry();
323 QRectF geometryRect = chart->geometry();
362 QRectF plotArea = chart->plotArea();
324 QRectF plotArea = chart->plotArea();
363 plotArea.translate(geometryRect.topLeft());
325 plotArea.translate(geometryRect.topLeft());
364
326
365 if (plotArea.contains(m_origin)) {
327 if (plotArea.contains(m_origin)) {
366 if (m_isScrolling) {
328 if (m_isScrolling) {
367 QPointF delta = m_origin - event->pos();
329 QPointF delta = m_origin - event->pos();
368 chart->scroll(delta.x(), -delta.y());
330 chart->scroll(delta.x(), -delta.y());
369 }
331 }
370 if (m_isZooming && plotArea.contains(event->pos())) {
332 if (m_isZooming && plotArea.contains(event->pos())) {
371 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
333 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
372 }
334 }
373 break;
335 break;
374 }
336 }
375 }
337 }
376 if(m_isScrolling) m_origin = event->pos();
338 if(m_isScrolling) m_origin = event->pos();
377 event->accept();
339 event->accept();
378 }
340 }
379 }
341 }
380
342
381 void Window::mouseReleaseEvent(QMouseEvent *event)
343 void Window::mouseReleaseEvent(QMouseEvent *event)
382 {
344 {
383 if (event->button() == Qt::LeftButton) {
345 if (event->button() == Qt::LeftButton) {
384 m_isScrolling = false;
346 m_isScrolling = false;
385 if (m_isZooming) {
347 if (m_isZooming) {
386 m_isZooming = false;
348 m_isZooming = false;
387 m_rubberBand->setVisible(false);
349 m_rubberBand->setVisible(false);
388
350
389 foreach (QChart *chart, m_chartList) {
351 foreach (QChart *chart, m_chartList) {
390
352
391 QRectF geometryRect = chart->geometry();
353 QRectF geometryRect = chart->geometry();
392 QRectF plotArea = chart->plotArea();
354 QRectF plotArea = chart->plotArea();
393 plotArea.translate(geometryRect.topLeft());
355 plotArea.translate(geometryRect.topLeft());
394
356
395 if (plotArea.contains(m_origin)) {
357 if (plotArea.contains(m_origin)) {
396 QRectF rect = m_rubberBand->rect();
358 QRectF rect = m_rubberBand->rect();
397 rect.translate(-geometryRect.topLeft());
359 rect.translate(-geometryRect.topLeft());
398 chart->zoomIn(rect);
360 chart->zoomIn(rect);
399 break;
361 break;
400 }
362 }
401 }
363 }
402 }
364 }
403 event->accept();
365 event->accept();
404 }
366 }
405
367
406 if (event->button() == Qt::RightButton) {
368 if (event->button() == Qt::RightButton) {
407
369
408 if (m_isZooming) {
370 if (m_isZooming) {
409 foreach (QChart *chart, m_chartList) {
371 foreach (QChart *chart, m_chartList) {
410
372
411 QRectF geometryRect = chart->geometry();
373 QRectF geometryRect = chart->geometry();
412 QRectF plotArea = chart->plotArea();
374 QRectF plotArea = chart->plotArea();
413 plotArea.translate(geometryRect.topLeft());
375 plotArea.translate(geometryRect.topLeft());
414
376
415 if (plotArea.contains(m_origin)) {
377 if (plotArea.contains(m_origin)) {
416 QRectF rect = m_rubberBand->rect();
378 QRectF rect = m_rubberBand->rect();
417 chart->zoomOut();
379 chart->zoomOut();
418 break;
380 break;
419 }
381 }
420 }
382 }
421 }
383 }
422 }
384 }
423 }
385 }
424
386
425 void Window::comboBoxFocused(QComboBox *combobox)
387 void Window::comboBoxFocused(QComboBox *combobox)
426 {
388 {
427 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
389 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
428 if(widget->widget()==combobox)
390 if(widget->widget()==combobox)
429 widget->setZValue(2.0);
391 widget->setZValue(2.0);
430 else
392 else
431 widget->setZValue(0.0);
393 widget->setZValue(0.0);
432 }
394 }
433 }
395 }
@@ -1,116 +1,110
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 <QMainWindow>
24 #include <QMainWindow>
24 #include <QChartGlobal>
25 #include <QChartGlobal>
25 #include <QHash>
26 #include <QHash>
26 #include <QComboBox>
27 #include <QComboBox>
27
28
28 class QCheckBox;
29 class QCheckBox;
29 class QGraphicsRectItem;
30 class QGraphicsRectItem;
30 class QGraphicsScene;
31 class QGraphicsScene;
31 class QGraphicsWidget;
32 class QGraphicsWidget;
32 class View;
33 class View;
33
34
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 class QChart;
36 class QChart;
36 QTCOMMERCIALCHART_END_NAMESPACE
37 QTCOMMERCIALCHART_END_NAMESPACE
37
38
38 typedef QPair<QPointF, QString> Data;
39 typedef QList<Data> DataList;
40 typedef QList<DataList> DataTable;
41
42 QTCOMMERCIALCHART_USE_NAMESPACE
39 QTCOMMERCIALCHART_USE_NAMESPACE
43
40
44
41
45 class Window: public QMainWindow
42 class Window: public QMainWindow
46 {
43 {
47 Q_OBJECT
44 Q_OBJECT
48 public:
45 public:
49 explicit Window(QWidget *parent = 0);
46 explicit Window(QWidget *parent = 0);
50 ~Window();
47 ~Window();
51
48
52 private Q_SLOTS:
49 private Q_SLOTS:
53 void updateUI();
50 void updateUI();
54
55
56 private:
51 private:
57 DataTable generateRandomData(int listCount,int valueMax,int valueCount) const;
58 QComboBox* createThemeBox();
52 QComboBox* createThemeBox();
59 QComboBox* createAnimationBox();
53 QComboBox* createAnimationBox();
60 QComboBox* createLegendBox();
54 QComboBox* createLegendBox();
61 void connectSignals();
55 void connectSignals();
62 void createProxyWidgets();
56 void createProxyWidgets();
63 void comboBoxFocused(QComboBox *combox);
57 void comboBoxFocused(QComboBox *combox);
64
58
65 protected:
59 protected:
66 void mousePressEvent(QMouseEvent *event);
60 void mousePressEvent(QMouseEvent *event);
67 void mouseMoveEvent(QMouseEvent *event);
61 void mouseMoveEvent(QMouseEvent *event);
68 void mouseReleaseEvent(QMouseEvent *event);
62 void mouseReleaseEvent(QMouseEvent *event);
69
63
70
64
71 private:
65 private:
72 int m_listCount;
66 int m_listCount;
73 int m_valueMax;
67 int m_valueMax;
74 int m_valueCount;
68 int m_valueCount;
75 QGraphicsScene* m_scene;
69 QGraphicsScene* m_scene;
76 View* m_view;
70 View* m_view;
77 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
71 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
78 QList<QChart*> m_chartList;
72 QList<QChart*> m_chartList;
79 DataTable m_dataTable;
73 DataTable m_dataTable;
80
74
81 QGraphicsWidget *m_form;
75 QGraphicsWidget *m_form;
82 QComboBox *m_themeComboBox;
76 QComboBox *m_themeComboBox;
83 QCheckBox *m_antialiasCheckBox;
77 QCheckBox *m_antialiasCheckBox;
84 QComboBox *m_animatedComboBox;
78 QComboBox *m_animatedComboBox;
85 QComboBox *m_legendComboBox;
79 QComboBox *m_legendComboBox;
86 QCheckBox *m_openGLCheckBox;
80 QCheckBox *m_openGLCheckBox;
87 QCheckBox *m_zoomCheckBox;
81 QCheckBox *m_zoomCheckBox;
88 QCheckBox *m_scrollCheckBox;
82 QCheckBox *m_scrollCheckBox;
89 QPoint m_origin;
83 QPoint m_origin;
90 QGraphicsRectItem* m_rubberBand;
84 QGraphicsRectItem* m_rubberBand;
91
85
92 bool m_isScrolling;
86 bool m_isScrolling;
93 bool m_isZooming;
87 bool m_isZooming;
94 bool m_scroll;
88 bool m_scroll;
95 bool m_zoom;
89 bool m_zoom;
96
90
97 friend class ComboBox;
91 friend class ComboBox;
98 };
92 };
99
93
100 class ComboBox: public QComboBox
94 class ComboBox: public QComboBox
101 {
95 {
102 public:
96 public:
103 ComboBox(Window* window,QWidget *parent = 0):QComboBox(parent),m_window(window)
97 ComboBox(Window* window,QWidget *parent = 0):QComboBox(parent),m_window(window)
104 {}
98 {}
105
99
106 protected:
100 protected:
107 void focusInEvent(QFocusEvent *e)
101 void focusInEvent(QFocusEvent *e)
108 {
102 {
109 QComboBox::focusInEvent(e);
103 QComboBox::focusInEvent(e);
110 m_window->comboBoxFocused(this);
104 m_window->comboBoxFocused(this);
111 }
105 }
112 private:
106 private:
113 Window* m_window;
107 Window* m_window;
114 };
108 };
115
109
116 #endif
110 #endif
General Comments 0
You need to be logged in to leave comments. Login now