##// END OF EJS Templates
coding style fixes for demos
Jani Honkonen -
r2099:dacd8b696e6b
parent child
Show More
@@ -1,101 +1,101
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 "chart.h"
21 #include "chart.h"
22 #include <QValueAxis>
22 #include <QValueAxis>
23 #include <QAbstractAxis>
23 #include <QAbstractAxis>
24 #include <cmath>
24 #include <cmath>
25
25
26 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series)
26 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series)
27 : QChart(parent, wFlags), m_series(series)
27 : QChart(parent, wFlags), m_series(series)
28 {
28 {
29 m_clicked = false;
29 m_clicked = false;
30 }
30 }
31
31
32 Chart::~Chart()
32 Chart::~Chart()
33 {
33 {
34 }
34 }
35
35
36 void Chart::clickPoint(const QPointF &point)
36 void Chart::clickPoint(const QPointF &point)
37 {
37 {
38 // Find the closes data point
38 // Find the closes data point
39 m_movingPoint = QPoint();
39 m_movingPoint = QPoint();
40 m_clicked = false;
40 m_clicked = false;
41 foreach (QPointF p, m_series->points()) {
41 foreach (QPointF p, m_series->points()) {
42 if (distance(p, point) < distance(m_movingPoint, point)) {
42 if (distance(p, point) < distance(m_movingPoint, point)) {
43 m_movingPoint = p;
43 m_movingPoint = p;
44 m_clicked = true;
44 m_clicked = true;
45 }
45 }
46 }
46 }
47 }
47 }
48
48
49 qreal Chart::distance(const QPointF &p1, const QPointF &p2)
49 qreal Chart::distance(const QPointF &p1, const QPointF &p2)
50 {
50 {
51 return sqrt((p1.x() - p2.x()) * (p1.x() - p2.x())
51 return sqrt((p1.x() - p2.x()) * (p1.x() - p2.x())
52 + (p1.y() - p2.y()) * (p1.y() - p2.y()));
52 + (p1.y() - p2.y()) * (p1.y() - p2.y()));
53 }
53 }
54
54
55 void Chart::setPointClicked(bool clicked)
55 void Chart::setPointClicked(bool clicked)
56 {
56 {
57 m_clicked = clicked;
57 m_clicked = clicked;
58 }
58 }
59
59
60 void Chart::handlePointMove(const QPoint &point)
60 void Chart::handlePointMove(const QPoint &point)
61 {
61 {
62 if (m_clicked) {
62 if (m_clicked) {
63 //Map the point clicked from the ChartView
63 //Map the point clicked from the ChartView
64 //to the area occupied by the chart.
64 //to the area occupied by the chart.
65 QPoint mappedPoint = point;
65 QPoint mappedPoint = point;
66 mappedPoint.setX(point.x()-this->plotArea().x());
66 mappedPoint.setX(point.x() - this->plotArea().x());
67 mappedPoint.setY(point.y()-this->plotArea().y());
67 mappedPoint.setY(point.y() - this->plotArea().y());
68
68
69 //Get the x- and y axis to be able to convert the mapped
69 //Get the x- and y axis to be able to convert the mapped
70 //coordinate point to the charts scale.
70 //coordinate point to the charts scale.
71 QAbstractAxis * axisx = this->axisX();
71 QAbstractAxis *axisx = this->axisX();
72 QValueAxis* haxis = 0;
72 QValueAxis *haxis = 0;
73 if (axisx->type() == QAbstractAxis::AxisTypeValue)
73 if (axisx->type() == QAbstractAxis::AxisTypeValue)
74 haxis = qobject_cast<QValueAxis*>(axisx);
74 haxis = qobject_cast<QValueAxis *>(axisx);
75
75
76 QAbstractAxis * axisy = this->axisY();
76 QAbstractAxis *axisy = this->axisY();
77 QValueAxis* vaxis = 0;
77 QValueAxis *vaxis = 0;
78 if (axisy->type() == QAbstractAxis::AxisTypeValue)
78 if (axisy->type() == QAbstractAxis::AxisTypeValue)
79 vaxis = qobject_cast<QValueAxis*>(axisy);
79 vaxis = qobject_cast<QValueAxis *>(axisy);
80
80
81 if (haxis && vaxis) {
81 if (haxis && vaxis) {
82 //Calculate the "unit" between points on the x
82 //Calculate the "unit" between points on the x
83 //y axis.
83 //y axis.
84 double xUnit = this->plotArea().width()/haxis->max();
84 double xUnit = this->plotArea().width() / haxis->max();
85 double yUnit = this->plotArea().height()/vaxis->max();
85 double yUnit = this->plotArea().height() / vaxis->max();
86
86
87 //Convert the mappedPoint to the actual chart scale.
87 //Convert the mappedPoint to the actual chart scale.
88 double x = mappedPoint.x()/xUnit;
88 double x = mappedPoint.x() / xUnit;
89 double y = vaxis->max() - mappedPoint.y()/yUnit;
89 double y = vaxis->max() - mappedPoint.y() / yUnit;
90
90
91 //Replace the old point with the new one.
91 //Replace the old point with the new one.
92 m_series->replace(m_movingPoint, QPointF(x, y));
92 m_series->replace(m_movingPoint, QPointF(x, y));
93
93
94 //Update the m_movingPoint so we are able to
94 //Update the m_movingPoint so we are able to
95 //do the replace also during mousemoveEvent.
95 //do the replace also during mousemoveEvent.
96 m_movingPoint.setX(x);
96 m_movingPoint.setX(x);
97 m_movingPoint.setY(y);
97 m_movingPoint.setY(y);
98 }
98 }
99 }
99 }
100 }
100 }
101
101
@@ -1,74 +1,74
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 <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QLineSeries>
23 #include <QLineSeries>
24
24
25 #include <QValueAxis>
25 #include <QValueAxis>
26
26
27 #include "chart.h"
27 #include "chart.h"
28 #include "chartview.h"
28 #include "chartview.h"
29
29
30 QTCOMMERCIALCHART_USE_NAMESPACE
30 QTCOMMERCIALCHART_USE_NAMESPACE
31
31
32 int main(int argc, char *argv[])
32 int main(int argc, char *argv[])
33 {
33 {
34 QApplication a(argc, argv);
34 QApplication a(argc, argv);
35
35
36 QLineSeries* series = new QLineSeries();
36 QLineSeries *series = new QLineSeries();
37
37
38 series->append(0, 6);
38 series->append(0, 6);
39 series->append(1, 3);
39 series->append(1, 3);
40 series->append(2, 4);
40 series->append(2, 4);
41 series->append(3, 8);
41 series->append(3, 8);
42 series->append(7, 13);
42 series->append(7, 13);
43 series->append(10, 5);
43 series->append(10, 5);
44 *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
44 *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
45
45
46 Chart* chart = new Chart(0, 0, series);
46 Chart *chart = new Chart(0, 0, series);
47 chart->legend()->hide();
47 chart->legend()->hide();
48 chart->addSeries(series);
48 chart->addSeries(series);
49 QPen p = series->pen();
49 QPen p = series->pen();
50 p.setWidth(5);
50 p.setWidth(5);
51 series->setPen(p);
51 series->setPen(p);
52 chart->createDefaultAxes();
52 chart->createDefaultAxes();
53 chart->setTitle("Drag'n drop to move data points");
53 chart->setTitle("Drag'n drop to move data points");
54
54
55 QValueAxis *axisX = new QValueAxis();
55 QValueAxis *axisX = new QValueAxis();
56 chart->setAxisX(axisX, series);
56 chart->setAxisX(axisX, series);
57 axisX->setRange(0, 20);
57 axisX->setRange(0, 20);
58
58
59 QValueAxis *axisY = new QValueAxis();
59 QValueAxis *axisY = new QValueAxis();
60 chart->setAxisY(axisY, series);
60 chart->setAxisY(axisY, series);
61 axisY->setRange(0, 13);
61 axisY->setRange(0, 13);
62
62
63 QObject::connect(series, SIGNAL(clicked(QPointF)), chart, SLOT(clickPoint(QPointF)));
63 QObject::connect(series, SIGNAL(clicked(QPointF)), chart, SLOT(clickPoint(QPointF)));
64
64
65 ChartView* chartView = new ChartView(chart);
65 ChartView *chartView = new ChartView(chart);
66 chartView->setRenderHint(QPainter::Antialiasing);
66 chartView->setRenderHint(QPainter::Antialiasing);
67
67
68 QMainWindow window;
68 QMainWindow window;
69 window.setCentralWidget(chartView);
69 window.setCentralWidget(chartView);
70 window.resize(400, 300);
70 window.resize(400, 300);
71 window.show();
71 window.show();
72
72
73 return a.exec();
73 return a.exec();
74 }
74 }
@@ -1,35 +1,35
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 "themewidget.h"
21 #include "themewidget.h"
22 #include <QApplication>
22 #include <QApplication>
23 #include <QMainWindow>
23 #include <QMainWindow>
24
24
25 int main(int argc, char *argv[])
25 int main(int argc, char *argv[])
26 {
26 {
27 QApplication a(argc, argv);
27 QApplication a(argc, argv);
28 QMainWindow window;
28 QMainWindow window;
29 ThemeWidget* widget = new ThemeWidget();
29 ThemeWidget *widget = new ThemeWidget();
30 window.setCentralWidget(widget);
30 window.setCentralWidget(widget);
31 window.resize(900, 600);
31 window.resize(900, 600);
32 window.show();
32 window.show();
33 return a.exec();
33 return a.exec();
34 }
34 }
35
35
@@ -1,371 +1,373
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 "themewidget.h"
21 #include "themewidget.h"
22
22
23 #include <QChartView>
23 #include <QChartView>
24 #include <QPieSeries>
24 #include <QPieSeries>
25 #include <QPieSlice>
25 #include <QPieSlice>
26 #include <QAbstractBarSeries>
26 #include <QAbstractBarSeries>
27 #include <QPercentBarSeries>
27 #include <QPercentBarSeries>
28 #include <QStackedBarSeries>
28 #include <QStackedBarSeries>
29 #include <QBarSeries>
29 #include <QBarSeries>
30 #include <QBarSet>
30 #include <QBarSet>
31 #include <QLineSeries>
31 #include <QLineSeries>
32 #include <QSplineSeries>
32 #include <QSplineSeries>
33 #include <QScatterSeries>
33 #include <QScatterSeries>
34 #include <QAreaSeries>
34 #include <QAreaSeries>
35 #include <QLegend>
35 #include <QLegend>
36 #include <QGridLayout>
36 #include <QGridLayout>
37 #include <QFormLayout>
37 #include <QFormLayout>
38 #include <QComboBox>
38 #include <QComboBox>
39 #include <QSpinBox>
39 #include <QSpinBox>
40 #include <QCheckBox>
40 #include <QCheckBox>
41 #include <QGroupBox>
41 #include <QGroupBox>
42 #include <QLabel>
42 #include <QLabel>
43 #include <QTime>
43 #include <QTime>
44 #include <QBarCategoryAxis>
44 #include <QBarCategoryAxis>
45
45
46 ThemeWidget::ThemeWidget(QWidget* parent) :
46 ThemeWidget::ThemeWidget(QWidget *parent) :
47 QWidget(parent),
47 QWidget(parent),
48 m_listCount(3),
48 m_listCount(3),
49 m_valueMax(10),
49 m_valueMax(10),
50 m_valueCount(7),
50 m_valueCount(7),
51 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
51 m_dataTable(generateRandomData(m_listCount, m_valueMax, m_valueCount)),
52 m_themeComboBox(createThemeBox()),
52 m_themeComboBox(createThemeBox()),
53 m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
53 m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
54 m_animatedComboBox(createAnimationBox()),
54 m_animatedComboBox(createAnimationBox()),
55 m_legendComboBox(createLegendBox())
55 m_legendComboBox(createLegendBox())
56 {
56 {
57 connectSignals();
57 connectSignals();
58 // create layout
58 // create layout
59 QGridLayout* baseLayout = new QGridLayout();
59 QGridLayout *baseLayout = new QGridLayout();
60 QHBoxLayout *settingsLayout = new QHBoxLayout();
60 QHBoxLayout *settingsLayout = new QHBoxLayout();
61 settingsLayout->addWidget(new QLabel("Theme:"));
61 settingsLayout->addWidget(new QLabel("Theme:"));
62 settingsLayout->addWidget(m_themeComboBox);
62 settingsLayout->addWidget(m_themeComboBox);
63 settingsLayout->addWidget(new QLabel("Animation:"));
63 settingsLayout->addWidget(new QLabel("Animation:"));
64 settingsLayout->addWidget(m_animatedComboBox);
64 settingsLayout->addWidget(m_animatedComboBox);
65 settingsLayout->addWidget(new QLabel("Legend:"));
65 settingsLayout->addWidget(new QLabel("Legend:"));
66 settingsLayout->addWidget(m_legendComboBox);
66 settingsLayout->addWidget(m_legendComboBox);
67 settingsLayout->addWidget(m_antialiasCheckBox);
67 settingsLayout->addWidget(m_antialiasCheckBox);
68 settingsLayout->addStretch();
68 settingsLayout->addStretch();
69 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
69 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
70
70
71 //create charts
71 //create charts
72
72
73 QChartView *chartView;
73 QChartView *chartView;
74
74
75 chartView = new QChartView(createAreaChart());
75 chartView = new QChartView(createAreaChart());
76 baseLayout->addWidget(chartView, 1, 0);
76 baseLayout->addWidget(chartView, 1, 0);
77 m_charts << chartView;
77 m_charts << chartView;
78
78
79 chartView = new QChartView(createBarChart(m_valueCount));
79 chartView = new QChartView(createBarChart(m_valueCount));
80 baseLayout->addWidget(chartView, 1, 1);
80 baseLayout->addWidget(chartView, 1, 1);
81 m_charts << chartView;
81 m_charts << chartView;
82
82
83 chartView = new QChartView(createLineChart());
83 chartView = new QChartView(createLineChart());
84 baseLayout->addWidget(chartView, 1, 2);
84 baseLayout->addWidget(chartView, 1, 2);
85 m_charts << chartView;
85 m_charts << chartView;
86
86
87 chartView = new QChartView(createPieChart());
87 chartView = new QChartView(createPieChart());
88 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
88 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
89 baseLayout->addWidget(chartView, 2, 0);
89 baseLayout->addWidget(chartView, 2, 0);
90 m_charts << chartView;
90 m_charts << chartView;
91
91
92 chartView = new QChartView(createSplineChart());
92 chartView = new QChartView(createSplineChart());
93 baseLayout->addWidget(chartView, 2, 1);
93 baseLayout->addWidget(chartView, 2, 1);
94 m_charts << chartView;
94 m_charts << chartView;
95
95
96 chartView = new QChartView(createScatterChart());
96 chartView = new QChartView(createScatterChart());
97 baseLayout->addWidget(chartView, 2, 2);
97 baseLayout->addWidget(chartView, 2, 2);
98 m_charts << chartView;
98 m_charts << chartView;
99
99
100 setLayout(baseLayout);
100 setLayout(baseLayout);
101
101
102 // Set defaults
102 // Set defaults
103 m_antialiasCheckBox->setChecked(true);
103 m_antialiasCheckBox->setChecked(true);
104 updateUI();
104 updateUI();
105 }
105 }
106
106
107 ThemeWidget::~ThemeWidget()
107 ThemeWidget::~ThemeWidget()
108 {
108 {
109 }
109 }
110
110
111 void ThemeWidget::connectSignals()
111 void ThemeWidget::connectSignals()
112 {
112 {
113 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
113 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
114 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
114 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
115 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
115 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
117 }
117 }
118
118
119 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
119 DataTable ThemeWidget::generateRandomData(int listCount, int valueMax, int valueCount) const
120 {
120 {
121 DataTable dataTable;
121 DataTable dataTable;
122
122
123 // set seed for random stuff
123 // set seed for random stuff
124 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
124 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
125
125
126 // generate random data
126 // generate random data
127 for (int i(0); i < listCount; i++) {
127 for (int i(0); i < listCount; i++) {
128 DataList dataList;
128 DataList dataList;
129 qreal yValue(0);
129 qreal yValue(0);
130 for (int j(0); j < valueCount; j++) {
130 for (int j(0); j < valueCount; j++) {
131 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
131 yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount;
132 QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
132 QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
133 yValue);
133 yValue);
134 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
134 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
135 dataList << Data(value, label);
135 dataList << Data(value, label);
136 }
136 }
137 dataTable << dataList;
137 dataTable << dataList;
138 }
138 }
139
139
140 return dataTable;
140 return dataTable;
141 }
141 }
142
142
143 QComboBox* ThemeWidget::createThemeBox() const
143 QComboBox *ThemeWidget::createThemeBox() const
144 {
144 {
145 // settings layout
145 // settings layout
146 QComboBox* themeComboBox = new QComboBox();
146 QComboBox *themeComboBox = new QComboBox();
147 themeComboBox->addItem("Light", QChart::ChartThemeLight);
147 themeComboBox->addItem("Light", QChart::ChartThemeLight);
148 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
148 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
149 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
149 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
150 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
150 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
151 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
151 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
152 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
152 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
153 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
153 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
154 return themeComboBox;
154 return themeComboBox;
155 }
155 }
156
156
157 QComboBox* ThemeWidget::createAnimationBox() const
157 QComboBox *ThemeWidget::createAnimationBox() const
158 {
158 {
159 // settings layout
159 // settings layout
160 QComboBox* animationComboBox = new QComboBox();
160 QComboBox *animationComboBox = new QComboBox();
161 animationComboBox->addItem("No Animations", QChart::NoAnimation);
161 animationComboBox->addItem("No Animations", QChart::NoAnimation);
162 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
162 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
163 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
163 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
164 animationComboBox->addItem("All Animations", QChart::AllAnimations);
164 animationComboBox->addItem("All Animations", QChart::AllAnimations);
165 return animationComboBox;
165 return animationComboBox;
166 }
166 }
167
167
168 QComboBox* ThemeWidget::createLegendBox() const
168 QComboBox *ThemeWidget::createLegendBox() const
169 {
169 {
170 QComboBox* legendComboBox = new QComboBox();
170 QComboBox *legendComboBox = new QComboBox();
171 legendComboBox->addItem("No Legend ", 0);
171 legendComboBox->addItem("No Legend ", 0);
172 legendComboBox->addItem("Legend Top", Qt::AlignTop);
172 legendComboBox->addItem("Legend Top", Qt::AlignTop);
173 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
173 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
174 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
174 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
175 legendComboBox->addItem("Legend Right", Qt::AlignRight);
175 legendComboBox->addItem("Legend Right", Qt::AlignRight);
176 return legendComboBox;
176 return legendComboBox;
177 }
177 }
178
178
179 QChart* ThemeWidget::createAreaChart() const
179 QChart *ThemeWidget::createAreaChart() const
180 {
180 {
181 QChart *chart = new QChart();
181 QChart *chart = new QChart();
182 // chart->axisX()->setNiceNumbersEnabled(true);
182 // chart->axisX()->setNiceNumbersEnabled(true);
183 // chart->axisY()->setNiceNumbersEnabled(true);
183 // chart->axisY()->setNiceNumbersEnabled(true);
184 chart->setTitle("Area chart");
184 chart->setTitle("Area chart");
185
185
186 // The lower series initialized to zero values
186 // The lower series initialized to zero values
187 QLineSeries *lowerSeries = 0;
187 QLineSeries *lowerSeries = 0;
188 QString name("Series ");
188 QString name("Series ");
189 int nameIndex = 0;
189 int nameIndex = 0;
190 for (int i(0); i < m_dataTable.count(); i++) {
190 for (int i(0); i < m_dataTable.count(); i++) {
191 QLineSeries *upperSeries = new QLineSeries(chart);
191 QLineSeries *upperSeries = new QLineSeries(chart);
192 for (int j(0); j < m_dataTable[i].count(); j++) {
192 for (int j(0); j < m_dataTable[i].count(); j++) {
193 Data data = m_dataTable[i].at(j);
193 Data data = m_dataTable[i].at(j);
194 if (lowerSeries){
194 if (lowerSeries) {
195 const QList<QPointF>& points = lowerSeries->points();
195 const QList<QPointF>& points = lowerSeries->points();
196 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
196 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
197 }else
197 } else {
198 upperSeries->append(QPointF(j, data.first.y()));
198 upperSeries->append(QPointF(j, data.first.y()));
199 }
199 }
200 }
200 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
201 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
201 area->setName(name + QString::number(nameIndex));
202 area->setName(name + QString::number(nameIndex));
202 nameIndex++;
203 nameIndex++;
203 chart->addSeries(area);
204 chart->addSeries(area);
204 chart->createDefaultAxes();
205 chart->createDefaultAxes();
205 lowerSeries = upperSeries;
206 lowerSeries = upperSeries;
206 }
207 }
207
208
208 return chart;
209 return chart;
209 }
210 }
210
211
211 QChart* ThemeWidget::createBarChart(int valueCount) const
212 QChart *ThemeWidget::createBarChart(int valueCount) const
212 {
213 {
213 Q_UNUSED(valueCount);
214 Q_UNUSED(valueCount);
214 QChart* chart = new QChart();
215 QChart *chart = new QChart();
215 chart->setTitle("Bar chart");
216 chart->setTitle("Bar chart");
216
217
217 QStackedBarSeries* series = new QStackedBarSeries(chart);
218 QStackedBarSeries *series = new QStackedBarSeries(chart);
218 for (int i(0); i < m_dataTable.count(); i++) {
219 for (int i(0); i < m_dataTable.count(); i++) {
219 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
220 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
220 foreach (Data data, m_dataTable[i])
221 foreach (Data data, m_dataTable[i])
221 *set << data.first.y();
222 *set << data.first.y();
222 series->append(set);
223 series->append(set);
223 }
224 }
224 chart->addSeries(series);
225 chart->addSeries(series);
225 chart->createDefaultAxes();
226 chart->createDefaultAxes();
226
227
227 return chart;
228 return chart;
228 }
229 }
229
230
230 QChart* ThemeWidget::createLineChart() const
231 QChart *ThemeWidget::createLineChart() const
231 {
232 {
232 QChart* chart = new QChart();
233 QChart *chart = new QChart();
233 chart->setTitle("Line chart");
234 chart->setTitle("Line chart");
234
235
235 QString name("Series ");
236 QString name("Series ");
236 int nameIndex = 0;
237 int nameIndex = 0;
237 foreach (DataList list, m_dataTable) {
238 foreach (DataList list, m_dataTable) {
238 QLineSeries *series = new QLineSeries(chart);
239 QLineSeries *series = new QLineSeries(chart);
239 foreach (Data data, list)
240 foreach (Data data, list)
240 series->append(data.first);
241 series->append(data.first);
241 series->setName(name + QString::number(nameIndex));
242 series->setName(name + QString::number(nameIndex));
242 nameIndex++;
243 nameIndex++;
243 chart->addSeries(series);
244 chart->addSeries(series);
244 }
245 }
245 chart->createDefaultAxes();
246 chart->createDefaultAxes();
246
247
247 return chart;
248 return chart;
248 }
249 }
249
250
250 QChart* ThemeWidget::createPieChart() const
251 QChart *ThemeWidget::createPieChart() const
251 {
252 {
252 QChart* chart = new QChart();
253 QChart *chart = new QChart();
253 chart->setTitle("Pie chart");
254 chart->setTitle("Pie chart");
254
255
255 qreal pieSize = 1.0 / m_dataTable.count();
256 qreal pieSize = 1.0 / m_dataTable.count();
256 for (int i = 0; i < m_dataTable.count(); i++) {
257 for (int i = 0; i < m_dataTable.count(); i++) {
257 QPieSeries *series = new QPieSeries(chart);
258 QPieSeries *series = new QPieSeries(chart);
258 foreach (Data data, m_dataTable[i]) {
259 foreach (Data data, m_dataTable[i]) {
259 QPieSlice *slice = series->append(data.second, data.first.y());
260 QPieSlice *slice = series->append(data.second, data.first.y());
260 if (data == m_dataTable[i].first()) {
261 if (data == m_dataTable[i].first()) {
261 slice->setLabelVisible();
262 slice->setLabelVisible();
262 slice->setExploded();
263 slice->setExploded();
263 }
264 }
264 }
265 }
265 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
266 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
266 series->setPieSize(pieSize);
267 series->setPieSize(pieSize);
267 series->setHorizontalPosition(hPos);
268 series->setHorizontalPosition(hPos);
268 series->setVerticalPosition(0.5);
269 series->setVerticalPosition(0.5);
269 chart->addSeries(series);
270 chart->addSeries(series);
270 }
271 }
271
272
272 return chart;
273 return chart;
273 }
274 }
274
275
275 QChart* ThemeWidget::createSplineChart() const
276 QChart *ThemeWidget::createSplineChart() const
276 { // spine chart
277 {
277 QChart* chart = new QChart();
278 // spine chart
279 QChart *chart = new QChart();
278 chart->setTitle("Spline chart");
280 chart->setTitle("Spline chart");
279 QString name("Series ");
281 QString name("Series ");
280 int nameIndex = 0;
282 int nameIndex = 0;
281 foreach (DataList list, m_dataTable) {
283 foreach (DataList list, m_dataTable) {
282 QSplineSeries *series = new QSplineSeries(chart);
284 QSplineSeries *series = new QSplineSeries(chart);
283 foreach (Data data, list)
285 foreach (Data data, list)
284 series->append(data.first);
286 series->append(data.first);
285 series->setName(name + QString::number(nameIndex));
287 series->setName(name + QString::number(nameIndex));
286 nameIndex++;
288 nameIndex++;
287 chart->addSeries(series);
289 chart->addSeries(series);
288 }
290 }
289 chart->createDefaultAxes();
291 chart->createDefaultAxes();
290 return chart;
292 return chart;
291 }
293 }
292
294
293 QChart* ThemeWidget::createScatterChart() const
295 QChart *ThemeWidget::createScatterChart() const
294 { // scatter chart
296 {
295 QChart* chart = new QChart();
297 // scatter chart
298 QChart *chart = new QChart();
296 chart->setTitle("Scatter chart");
299 chart->setTitle("Scatter chart");
297 QString name("Series ");
300 QString name("Series ");
298 int nameIndex = 0;
301 int nameIndex = 0;
299 foreach (DataList list, m_dataTable) {
302 foreach (DataList list, m_dataTable) {
300 QScatterSeries *series = new QScatterSeries(chart);
303 QScatterSeries *series = new QScatterSeries(chart);
301 foreach (Data data, list)
304 foreach (Data data, list)
302 series->append(data.first);
305 series->append(data.first);
303 series->setName(name + QString::number(nameIndex));
306 series->setName(name + QString::number(nameIndex));
304 nameIndex++;
307 nameIndex++;
305 chart->addSeries(series);
308 chart->addSeries(series);
306 }
309 }
307 chart->createDefaultAxes();
310 chart->createDefaultAxes();
308 return chart;
311 return chart;
309 }
312 }
310
313
311 void ThemeWidget::updateUI()
314 void ThemeWidget::updateUI()
312 {
315 {
313 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
316 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
314
317
315 if (m_charts.at(0)->chart()->theme() != theme) {
318 if (m_charts.at(0)->chart()->theme() != theme) {
316 foreach (QChartView *chartView, m_charts)
319 foreach (QChartView *chartView, m_charts)
317 chartView->chart()->setTheme(theme);
320 chartView->chart()->setTheme(theme);
318
321
319 QPalette pal = window()->palette();
322 QPalette pal = window()->palette();
320 if (theme == QChart::ChartThemeLight) {
323 if (theme == QChart::ChartThemeLight) {
321 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
324 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
322 pal.setColor(QPalette::WindowText, QRgb(0x404044));
325 pal.setColor(QPalette::WindowText, QRgb(0x404044));
323 } else if (theme == QChart::ChartThemeDark) {
326 } else if (theme == QChart::ChartThemeDark) {
324 pal.setColor(QPalette::Window, QRgb(0x121218));
327 pal.setColor(QPalette::Window, QRgb(0x121218));
325 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
328 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
326 } else if (theme == QChart::ChartThemeBlueCerulean) {
329 } else if (theme == QChart::ChartThemeBlueCerulean) {
327 pal.setColor(QPalette::Window, QRgb(0x40434a));
330 pal.setColor(QPalette::Window, QRgb(0x40434a));
328 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
331 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
329 } else if (theme == QChart::ChartThemeBrownSand) {
332 } else if (theme == QChart::ChartThemeBrownSand) {
330 pal.setColor(QPalette::Window, QRgb(0x9e8965));
333 pal.setColor(QPalette::Window, QRgb(0x9e8965));
331 pal.setColor(QPalette::WindowText, QRgb(0x404044));
334 pal.setColor(QPalette::WindowText, QRgb(0x404044));
332 } else if (theme == QChart::ChartThemeBlueNcs) {
335 } else if (theme == QChart::ChartThemeBlueNcs) {
333 pal.setColor(QPalette::Window, QRgb(0x018bba));
336 pal.setColor(QPalette::Window, QRgb(0x018bba));
334 pal.setColor(QPalette::WindowText, QRgb(0x404044));
337 pal.setColor(QPalette::WindowText, QRgb(0x404044));
335 } else if (theme == QChart::ChartThemeHighContrast) {
338 } else if (theme == QChart::ChartThemeHighContrast) {
336 pal.setColor(QPalette::Window, QRgb(0xffab03));
339 pal.setColor(QPalette::Window, QRgb(0xffab03));
337 pal.setColor(QPalette::WindowText, QRgb(0x181818));
340 pal.setColor(QPalette::WindowText, QRgb(0x181818));
338 } else if (theme == QChart::ChartThemeBlueIcy) {
341 } else if (theme == QChart::ChartThemeBlueIcy) {
339 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
342 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
340 pal.setColor(QPalette::WindowText, QRgb(0x404044));
343 pal.setColor(QPalette::WindowText, QRgb(0x404044));
341 } else {
344 } else {
342 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
345 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
343 pal.setColor(QPalette::WindowText, QRgb(0x404044));
346 pal.setColor(QPalette::WindowText, QRgb(0x404044));
344 }
347 }
345 window()->setPalette(pal);
348 window()->setPalette(pal);
346 }
349 }
347
350
348 bool checked = m_antialiasCheckBox->isChecked();
351 bool checked = m_antialiasCheckBox->isChecked();
349 foreach (QChartView *chart, m_charts)
352 foreach (QChartView *chart, m_charts)
350 chart->setRenderHint(QPainter::Antialiasing, checked);
353 chart->setRenderHint(QPainter::Antialiasing, checked);
351
354
352 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
355 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
353 if (m_charts.at(0)->chart()->animationOptions() != options) {
356 if (m_charts.at(0)->chart()->animationOptions() != options) {
354 foreach (QChartView *chartView, m_charts)
357 foreach (QChartView *chartView, m_charts)
355 chartView->chart()->setAnimationOptions(options);
358 chartView->chart()->setAnimationOptions(options);
356 }
359 }
357
360
358 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
361 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
359
362
360 if (!alignment) {
363 if (!alignment) {
361 foreach (QChartView *chartView, m_charts) {
364 foreach (QChartView *chartView, m_charts)
362 chartView->chart()->legend()->hide();
365 chartView->chart()->legend()->hide();
363 }
364 } else {
366 } else {
365 foreach (QChartView *chartView, m_charts) {
367 foreach (QChartView *chartView, m_charts) {
366 chartView->chart()->legend()->setAlignment(alignment);
368 chartView->chart()->legend()->setAlignment(alignment);
367 chartView->chart()->legend()->show();
369 chartView->chart()->legend()->show();
368 }
370 }
369 }
371 }
370 }
372 }
371
373
@@ -1,77 +1,77
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 THEMEWIDGET_H
21 #ifndef THEMEWIDGET_H
22 #define THEMEWIDGET_H
22 #define THEMEWIDGET_H
23
23
24 #include <QWidget>
24 #include <QWidget>
25 #include <QChartGlobal>
25 #include <QChartGlobal>
26
26
27 class QComboBox;
27 class QComboBox;
28 class QCheckBox;
28 class QCheckBox;
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 class QChartView;
31 class QChartView;
32 class QChart;
32 class QChart;
33 QTCOMMERCIALCHART_END_NAMESPACE
33 QTCOMMERCIALCHART_END_NAMESPACE
34
34
35 typedef QPair<QPointF, QString> Data;
35 typedef QPair<QPointF, QString> Data;
36 typedef QList<Data> DataList;
36 typedef QList<Data> DataList;
37 typedef QList<DataList> DataTable;
37 typedef QList<DataList> DataTable;
38
38
39 QTCOMMERCIALCHART_USE_NAMESPACE
39 QTCOMMERCIALCHART_USE_NAMESPACE
40
40
41 class ThemeWidget: public QWidget
41 class ThemeWidget: public QWidget
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44 public:
44 public:
45 explicit ThemeWidget(QWidget *parent = 0);
45 explicit ThemeWidget(QWidget *parent = 0);
46 ~ThemeWidget();
46 ~ThemeWidget();
47
47
48 private Q_SLOTS:
48 private Q_SLOTS:
49 void updateUI();
49 void updateUI();
50
50
51 private:
51 private:
52 DataTable generateRandomData(int listCount,int valueMax,int valueCount) const;
52 DataTable generateRandomData(int listCount, int valueMax, int valueCount) const;
53 QComboBox* createThemeBox() const;
53 QComboBox *createThemeBox() const;
54 QComboBox* createAnimationBox() const;
54 QComboBox *createAnimationBox() const;
55 QComboBox* createLegendBox() const;
55 QComboBox *createLegendBox() const;
56 void connectSignals();
56 void connectSignals();
57 QChart* createAreaChart() const;
57 QChart *createAreaChart() const;
58 QChart* createBarChart(int valueCount) const;
58 QChart *createBarChart(int valueCount) const;
59 QChart* createPieChart() const;
59 QChart *createPieChart() const;
60 QChart* createLineChart() const;
60 QChart *createLineChart() const;
61 QChart* createSplineChart() const;
61 QChart *createSplineChart() const;
62 QChart* createScatterChart() const;
62 QChart *createScatterChart() const;
63
63
64 private:
64 private:
65 int m_listCount;
65 int m_listCount;
66 int m_valueMax;
66 int m_valueMax;
67 int m_valueCount;
67 int m_valueCount;
68 QList<QChartView*> m_charts;
68 QList<QChartView *> m_charts;
69 DataTable m_dataTable;
69 DataTable m_dataTable;
70
70
71 QComboBox *m_themeComboBox;
71 QComboBox *m_themeComboBox;
72 QCheckBox *m_antialiasCheckBox;
72 QCheckBox *m_antialiasCheckBox;
73 QComboBox *m_animatedComboBox;
73 QComboBox *m_animatedComboBox;
74 QComboBox *m_legendComboBox;
74 QComboBox *m_legendComboBox;
75 };
75 };
76
76
77 #endif /* THEMEWIDGET_H */
77 #endif /* THEMEWIDGET_H */
@@ -1,94 +1,89
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 "model.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 virtual ~Chart(){};
38 virtual ~Chart() {};
39 virtual QChart* createChart(const DataTable& table) = 0;
39 virtual QChart *createChart(const DataTable &table) = 0;
40 virtual QString name() = 0;
40 virtual QString name() = 0;
41 virtual QString category() = 0;
41 virtual QString category() = 0;
42 virtual QString subCategory() = 0;
42 virtual QString subCategory() = 0;
43
43
44 };
44 };
45
45
46 namespace Charts
46 namespace Charts
47 {
47 {
48
48
49 typedef QList<Chart*> ChartList;
49 typedef QList<Chart *> ChartList;
50
50
51 inline ChartList& chartList()
51 inline ChartList &chartList()
52 {
52 {
53 static ChartList list;
53 static ChartList list;
54 return list;
54 return list;
55 }
56
57 inline bool findChart(Chart* chart)
58 {
59 ChartList& list = chartList();
60 if (list.contains(chart)) {
61 return true;
62 }
55 }
63 foreach (Chart* item, list) {
56
64 if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) {
57 inline bool findChart(Chart *chart)
58 {
59 ChartList &list = chartList();
60 if (list.contains(chart))
65 return true;
61 return true;
62
63 foreach (Chart *item, list) {
64 if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory())
65 return true;
66 }
66 }
67 return false;
67 }
68 }
68 return false;
69 }
70
69
71 inline void addChart(Chart* chart)
70 inline void addChart(Chart *chart)
72 {
71 {
73 ChartList& list = chartList();
72 ChartList &list = chartList();
74 if (!findChart(chart)) {
73 if (!findChart(chart))
75 list.append(chart);
74 list.append(chart);
76 }
75 }
77 }
76 }
78 }
79
77
80 template <class T>
78 template <class T>
81 class ChartWrapper
79 class ChartWrapper
82 {
80 {
83 public:
81 public:
84 QSharedPointer<T> chart;
82 QSharedPointer<T> chart;
85 ChartWrapper() : chart(new T)
83 ChartWrapper() : chart(new T) { Charts::addChart(chart.data()); }
86 {
87 Charts::addChart(chart.data());
88 }
89 };
84 };
90
85
91 #define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType;
86 #define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType;
92 #define DECLARE_CHART_TEMPLATE(chartType,chartName) static ChartWrapper<chartType> chartName;
87 #define DECLARE_CHART_TEMPLATE(chartType,chartName) static ChartWrapper<chartType> chartName;
93
88
94 #endif
89 #endif
@@ -1,69 +1,68
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 "qlineseries.h"
23 #include "qlineseries.h"
24 #include <QCategoryAxis>
24 #include <QCategoryAxis>
25
25
26 class CategoryLineChart: public Chart
26 class CategoryLineChart: public Chart
27 {
27 {
28 public:
28 public:
29 QString name() { return QObject::tr("CategoryAxis"); }
29 QString name() { return QObject::tr("CategoryAxis"); }
30 QString category() { return QObject::tr("Axis"); }
30 QString category() { return QObject::tr("Axis"); }
31 QString subCategory() { return QString::null; }
31 QString subCategory() { return QString::null; }
32
32
33 QChart* createChart(const DataTable& table) {
33 QChart *createChart(const DataTable &table)
34 {
35 QChart *chart = new QChart();
36 chart->setTitle("Category X , Category Y ");
34
37
35 QChart* chart = new QChart();
38 QString name("Series ");
36 chart->setTitle("Category X , Category Y ");
39 int nameIndex = 0;
40 foreach (DataList list, table) {
41 QLineSeries *series = new QLineSeries(chart);
42 foreach(Data data, list)
43 series->append(data.first);
44 series->setName(name + QString::number(nameIndex));
45 nameIndex++;
46 chart->addSeries(series);
47 }
37
48
38 QString name("Series ");
49 QCategoryAxis *axisX = new QCategoryAxis;
39 int nameIndex = 0;
50 axisX->append("low", 5);
40 foreach (DataList list, table) {
51 axisX->append("avg.", 12);
41 QLineSeries *series = new QLineSeries(chart);
52 axisX->append("high", 19);
42 foreach (Data data, list)
53 axisX->setRange(0, 20);
43 series->append(data.first);
54 chart->setAxisX(axisX, chart->series().at(0));
44 series->setName(name + QString::number(nameIndex));
45 nameIndex++;
46 chart->addSeries(series);
47 }
48
55
49 QCategoryAxis *axisX = new QCategoryAxis;
56 QCategoryAxis *axisY = new QCategoryAxis;
50 axisX->append("low", 5);
57 axisY->append("cheap", 5);
51 axisX->append("avg.", 12);
58 axisY->append("fair", 12);
52 axisX->append("high", 19);
59 axisY->append("pricy", 20);
53 axisX->setRange(0, 20);
60 axisY->setRange(0, 20);
54 chart->setAxisX(axisX, chart->series().at(0));
61 chart->setAxisY(axisY, chart->series().at(0));
55
62
56 QCategoryAxis *axisY = new QCategoryAxis;
63 return chart;
57 axisY->append("cheap", 5);
58 axisY->append("fair", 12);
59 axisY->append("pricy", 20);
60 axisY->setRange(0, 20);
61 chart->setAxisY(axisY, chart->series().at(0));
62
63 return chart;
64 }
64 }
65
66 };
65 };
67
66
68 DECLARE_CHART(CategoryLineChart)
67 DECLARE_CHART(CategoryLineChart)
69
68
@@ -1,60 +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 "qlineseries.h"
23 #include "qlineseries.h"
24 #include "qvalueaxis.h"
24 #include "qvalueaxis.h"
25 #include "qcategoryaxis.h"
25 #include "qcategoryaxis.h"
26
26
27 class ValueAxis: public Chart
27 class ValueAxis: public Chart
28 {
28 {
29 public:
29 public:
30 QString name() { return "ValueAxis"; }
30 QString name() { return "ValueAxis"; }
31 QString category() { return QObject::tr("Axis"); }
31 QString category() { return QObject::tr("Axis"); }
32 QString subCategory() { return QString::null; }
32 QString subCategory() { return QString::null; }
33
33
34 QChart* createChart(const DataTable& table) {
34 QChart *createChart(const DataTable &table)
35
35 {
36 QChart* chart = new QChart();
36 QChart *chart = new QChart();
37 chart->setTitle("Value X , Value Y");
37 chart->setTitle("Value X , Value Y");
38
38
39 QString name("Series ");
39 QString name("Series ");
40 int nameIndex = 0;
40 int nameIndex = 0;
41 foreach (DataList list, table) {
41 foreach (DataList list, table) {
42 QLineSeries *series = new QLineSeries(chart);
42 QLineSeries *series = new QLineSeries(chart);
43 foreach (Data data, list)
43 foreach (Data data, list)
44 series->append(data.first);
44 series->append(data.first);
45 series->setName(name + QString::number(nameIndex));
45 series->setName(name + QString::number(nameIndex));
46 nameIndex++;
46 nameIndex++;
47 chart->addSeries(series);
47 chart->addSeries(series);
48 }
48 }
49
49
50 chart->createDefaultAxes();
50 chart->createDefaultAxes();
51 QValueAxis* axis = new QValueAxis();
51 QValueAxis *axis = new QValueAxis();
52 foreach (QAbstractSeries* series,chart->series())
52 foreach (QAbstractSeries *series, chart->series())
53 chart->setAxisX(axis,series);
53 chart->setAxisX(axis, series);
54
54
55 return chart;
55 return chart;
56 }
56 }
57
58 };
57 };
59
58
60 DECLARE_CHART(ValueAxis);
59 DECLARE_CHART(ValueAxis);
@@ -1,55 +1,51
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("Horizontal"); }
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 QChart *chart = new QChart();
36 QChart* chart = new QChart();
37
38 chart->setTitle("Horizontal bar chart");
36 chart->setTitle("Horizontal bar chart");
39
37 QHorizontalBarSeries *series = new QHorizontalBarSeries(chart);
40 QHorizontalBarSeries* series = new QHorizontalBarSeries(chart);
41 for (int i(0); i < table.count(); i++) {
38 for (int i(0); i < table.count(); i++) {
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
39 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
43 foreach (Data data, table[i])
40 foreach (Data data, table[i])
44 *set << data.first.y();
41 *set << data.first.y();
45 series->append(set);
42 series->append(set);
46 }
43 }
47 chart->addSeries(series);
44 chart->addSeries(series);
48 chart->createDefaultAxes();
45 chart->createDefaultAxes();
49 return chart;
46 return chart;
50 }
47 }
51
52 };
48 };
53
49
54 DECLARE_CHART(HorizontalBarChart)
50 DECLARE_CHART(HorizontalBarChart)
55
51
@@ -1,55 +1,51
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 "qhorizontalpercentbarseries.h"
23 #include "qhorizontalpercentbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25
25
26 class HorizontalPercentBarChart: public Chart
26 class HorizontalPercentBarChart: public Chart
27 {
27 {
28 public:
28 public:
29 QString name() { return QObject::tr("HorizontalPercentBarChart"); }
29 QString name() { return QObject::tr("HorizontalPercentBarChart"); }
30 QString category() { return QObject::tr("BarSeries"); }
30 QString category() { return QObject::tr("BarSeries"); }
31 QString subCategory() { return QObject::tr("Horizontal"); }
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 QChart *chart = new QChart();
36 QChart* chart = new QChart();
37
38 chart->setTitle("Horizontal percent chart");
36 chart->setTitle("Horizontal percent chart");
39
37 QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries(chart);
40 QHorizontalPercentBarSeries* series = new QHorizontalPercentBarSeries(chart);
41 for (int i(0); i < table.count(); i++) {
38 for (int i(0); i < table.count(); i++) {
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
39 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
43 foreach (Data data, table[i])
40 foreach (Data data, table[i])
44 *set << data.first.y();
41 *set << data.first.y();
45 series->append(set);
42 series->append(set);
46 }
43 }
47 chart->addSeries(series);
44 chart->addSeries(series);
48 chart->createDefaultAxes();
45 chart->createDefaultAxes();
49 return chart;
46 return chart;
50 }
47 }
51
52 };
48 };
53
49
54 DECLARE_CHART(HorizontalPercentBarChart)
50 DECLARE_CHART(HorizontalPercentBarChart)
55
51
@@ -1,55 +1,51
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("Horizontal"); }
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 QChart *chart = new QChart();
36 QChart* chart = new QChart();
37
38 chart->setTitle("Horizontal stacked chart");
36 chart->setTitle("Horizontal stacked chart");
39
37 QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries(chart);
40 QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries(chart);
41 for (int i(0); i < table.count(); i++) {
38 for (int i(0); i < table.count(); i++) {
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
39 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
43 foreach (Data data, table[i])
40 foreach (Data data, table[i])
44 *set << data.first.y();
41 *set << data.first.y();
45 series->append(set);
42 series->append(set);
46 }
43 }
47 chart->addSeries(series);
44 chart->addSeries(series);
48 chart->createDefaultAxes();
45 chart->createDefaultAxes();
49 return chart;
46 return chart;
50 }
47 }
51
52 };
48 };
53
49
54 DECLARE_CHART(HorizontalStackedBarChart)
50 DECLARE_CHART(HorizontalStackedBarChart)
55
51
@@ -1,55 +1,51
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qbarseries.h"
23 #include "qbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25
25
26 class VerticalBarChart: public Chart
26 class VerticalBarChart: public Chart
27 {
27 {
28 public:
28 public:
29 QString name() { return QObject::tr("VerticalBarChart"); }
29 QString name() { return QObject::tr("VerticalBarChart"); }
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("Vertical"); }
32
32
33 QChart* createChart(const DataTable& table)
33 QChart *createChart(const DataTable &table)
34 {
34 {
35
35 QChart *chart = new QChart();
36 QChart* chart = new QChart();
37
38 chart->setTitle("Vertical bar chart");
36 chart->setTitle("Vertical bar chart");
39
37 QBarSeries *series = new QBarSeries(chart);
40 QBarSeries* series = new QBarSeries(chart);
41 for (int i(0); i < table.count(); i++) {
38 for (int i(0); i < table.count(); i++) {
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
39 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
43 foreach (Data data, table[i])
40 foreach (Data data, table[i])
44 *set << data.first.y();
41 *set << data.first.y();
45 series->append(set);
42 series->append(set);
46 }
43 }
47 chart->addSeries(series);
44 chart->addSeries(series);
48 chart->createDefaultAxes();
45 chart->createDefaultAxes();
49 return chart;
46 return chart;
50 }
47 }
51
52 };
48 };
53
49
54 DECLARE_CHART(VerticalBarChart)
50 DECLARE_CHART(VerticalBarChart)
55
51
@@ -1,55 +1,51
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 "qpercentbarseries.h"
23 #include "qpercentbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25
25
26 class VerticalPercentBarChart: public Chart
26 class VerticalPercentBarChart: public Chart
27 {
27 {
28 public:
28 public:
29 QString name() { return QObject::tr("VerticalPercentBarChart"); }
29 QString name() { return QObject::tr("VerticalPercentBarChart"); }
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("Vertical"); }
32
32
33 QChart* createChart(const DataTable& table)
33 QChart *createChart(const DataTable &table)
34 {
34 {
35
35 QChart *chart = new QChart();
36 QChart* chart = new QChart();
37
38 chart->setTitle("Stacked bar chart");
36 chart->setTitle("Stacked bar chart");
39
37 QPercentBarSeries *series = new QPercentBarSeries(chart);
40 QPercentBarSeries* series = new QPercentBarSeries(chart);
41 for (int i(0); i < table.count(); i++) {
38 for (int i(0); i < table.count(); i++) {
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
39 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
43 foreach (Data data, table[i])
40 foreach (Data data, table[i])
44 *set << data.first.y();
41 *set << data.first.y();
45 series->append(set);
42 series->append(set);
46 }
43 }
47 chart->addSeries(series);
44 chart->addSeries(series);
48 chart->createDefaultAxes();
45 chart->createDefaultAxes();
49 return chart;
46 return chart;
50 }
47 }
51
52 };
48 };
53
49
54 DECLARE_CHART(VerticalPercentBarChart)
50 DECLARE_CHART(VerticalPercentBarChart)
55
51
@@ -1,55 +1,51
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 VerticalStackedBarChart: public Chart
26 class VerticalStackedBarChart: public Chart
27 {
27 {
28 public:
28 public:
29 QString name() { return QObject::tr("VerticalStackedBarChart"); }
29 QString name() { return QObject::tr("VerticalStackedBarChart"); }
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("Vertical"); }
32
32
33 QChart* createChart(const DataTable& table)
33 QChart *createChart(const DataTable &table)
34 {
34 {
35
35 QChart *chart = new QChart();
36 QChart* chart = new QChart();
37
38 chart->setTitle("Stacked bar chart");
36 chart->setTitle("Stacked bar chart");
39
37 QStackedBarSeries *series = new QStackedBarSeries(chart);
40 QStackedBarSeries* series = new QStackedBarSeries(chart);
41 for (int i(0); i < table.count(); i++) {
38 for (int i(0); i < table.count(); i++) {
42 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
39 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
43 foreach (Data data, table[i])
40 foreach (Data data, table[i])
44 *set << data.first.y();
41 *set << data.first.y();
45 series->append(set);
42 series->append(set);
46 }
43 }
47 chart->addSeries(series);
44 chart->addSeries(series);
48 chart->createDefaultAxes();
45 chart->createDefaultAxes();
49 return chart;
46 return chart;
50 }
47 }
51
52 };
48 };
53
49
54 DECLARE_CHART(VerticalStackedBarChart)
50 DECLARE_CHART(VerticalStackedBarChart)
55
51
@@ -1,118 +1,122
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 "qlineseries.h"
23 #include "qlineseries.h"
24
24
25 class FontChart: public Chart
25 class FontChart: public Chart
26 {
26 {
27 public:
27 public:
28 FontChart(int fontSize):m_fontSize(fontSize){};
28 FontChart(int fontSize): m_fontSize(fontSize) {};
29 QString name() { return QObject::tr("Font") + " " + QString::number(m_fontSize); }
29 QString name() { return QObject::tr("Font") + " " + QString::number(m_fontSize); }
30 QString category() { return QObject::tr("Font"); }
30 QString category() { return QObject::tr("Font"); }
31 QString subCategory() { return QString::null; }
31 QString subCategory() { return QString::null; }
32
32
33 QChart* createChart(const DataTable& table) {
33 QChart *createChart(const DataTable &table)
34
34 {
35 QChart* chart = new QChart();
35 QChart *chart = new QChart();
36 chart->setTitle("Font size " + QString::number(m_fontSize));
36 chart->setTitle("Font size " + QString::number(m_fontSize));
37
37 QString name("Series ");
38 QString name("Series ");
38 int nameIndex = 0;
39 int nameIndex = 0;
39 foreach (DataList list, table) {
40 foreach (DataList list, table) {
40 QLineSeries *series = new QLineSeries(chart);
41 QLineSeries *series = new QLineSeries(chart);
41 foreach (Data data, list)
42 foreach (Data data, list)
42 series->append(data.first);
43 series->append(data.first);
43 series->setName(name + QString::number(nameIndex));
44 series->setName(name + QString::number(nameIndex));
44 nameIndex++;
45 nameIndex++;
45 chart->addSeries(series);
46 chart->addSeries(series);
46 }
47 }
47 chart->createDefaultAxes();
48
48 QFont font;
49 chart->createDefaultAxes();
49 font.setPixelSize(m_fontSize);
50 QFont font;
50 chart->setTitleFont(font);
51 font.setPixelSize(m_fontSize);
51 chart->axisX()->setLabelsFont(font);
52 chart->setTitleFont(font);
52 chart->axisY()->setLabelsFont(font);
53 chart->axisX()->setLabelsFont(font);
53 return chart;
54 chart->axisY()->setLabelsFont(font);
55
56 return chart;
57 }
54 }
58
55
59 private:
56 private:
60 int m_fontSize;
57 int m_fontSize;
61
62 };
58 };
63
59
64 class FontChart6:public FontChart{
60 class FontChart6: public FontChart
61 {
65 public:
62 public:
66 FontChart6():FontChart(6){};
63 FontChart6(): FontChart(6) {};
67 };
64 };
68
65
69 class FontChart8:public FontChart{
66 class FontChart8: public FontChart
67 {
70 public:
68 public:
71 FontChart8():FontChart(8){};
69 FontChart8(): FontChart(8) {};
72 };
70 };
73
71
74 class FontChart10:public FontChart{
72 class FontChart10: public FontChart
73 {
75 public:
74 public:
76 FontChart10():FontChart(10){};
75 FontChart10(): FontChart(10) {};
77 };
76 };
78
77
79 class FontChart14:public FontChart{
78 class FontChart14: public FontChart
79 {
80 public:
80 public:
81 FontChart14():FontChart(14){};
81 FontChart14(): FontChart(14) {};
82 };
82 };
83
83
84
84 class FontChart18: public FontChart
85 class FontChart18:public FontChart{
85 {
86 public:
86 public:
87 FontChart18():FontChart(18){};
87 FontChart18(): FontChart(18) {};
88 };
88 };
89
89
90 class FontChart20:public FontChart{
90 class FontChart20: public FontChart
91 {
91 public:
92 public:
92 FontChart20():FontChart(20){};
93 FontChart20(): FontChart(20) {};
93 };
94 };
94
95
95 class FontChart24:public FontChart{
96 class FontChart24: public FontChart
97 {
96 public:
98 public:
97 FontChart24():FontChart(24){};
99 FontChart24(): FontChart(24) {};
98 };
100 };
99
101
100 class FontChart28:public FontChart{
102 class FontChart28: public FontChart
103 {
101 public:
104 public:
102 FontChart28():FontChart(28){};
105 FontChart28(): FontChart(28) {};
103 };
106 };
104
107
105 class FontChart32:public FontChart{
108 class FontChart32: public FontChart
109 {
106 public:
110 public:
107 FontChart32():FontChart(32){};
111 FontChart32(): FontChart(32) {};
108 };
112 };
109
113
110 DECLARE_CHART(FontChart6);
114 DECLARE_CHART(FontChart6);
111 DECLARE_CHART(FontChart8);
115 DECLARE_CHART(FontChart8);
112 DECLARE_CHART(FontChart10);
116 DECLARE_CHART(FontChart10);
113 DECLARE_CHART(FontChart14);
117 DECLARE_CHART(FontChart14);
114 DECLARE_CHART(FontChart18);
118 DECLARE_CHART(FontChart18);
115 DECLARE_CHART(FontChart20);
119 DECLARE_CHART(FontChart20);
116 DECLARE_CHART(FontChart24);
120 DECLARE_CHART(FontChart24);
117 DECLARE_CHART(FontChart28);
121 DECLARE_CHART(FontChart28);
118 DECLARE_CHART(FontChart32);
122 DECLARE_CHART(FontChart32);
@@ -1,57 +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 "qpieseries.h"
23 #include "qpieseries.h"
24
24
25 class DonutChart: public Chart
25 class DonutChart: public Chart
26 {
26 {
27 public:
27 public:
28 QString name() { return QObject::tr("DonutChart"); }
28 QString name() { return QObject::tr("DonutChart"); }
29 QString category() { return QObject::tr("PieSeries"); }
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("Donut chart");
35 chart->setTitle("Donut chart");
36
36 for (int i = 0, j = table.count(); i < table.count(); i++, j--) {
37 for (int i = 0, j = table.count(); i < table.count(); i++,j--) {
38 QPieSeries *series = new QPieSeries(chart);
37 QPieSeries *series = new QPieSeries(chart);
39 foreach (Data data, table[i]) {
38 foreach (Data data, table[i]) {
40 QPieSlice *slice = series->append(data.second, data.first.y());
39 QPieSlice *slice = series->append(data.second, data.first.y());
41 if (data == table[i].first()) {
40 if (data == table[i].first())
42 slice->setLabelVisible();
41 slice->setLabelVisible();
43 }
44 }
42 }
45 series->setPieSize( j / (qreal) table.count());
43 series->setPieSize(j / (qreal) table.count());
46 if(j>1) series->setHoleSize( (j-1)/ (qreal) table.count()+0.1);
44 if (j > 1)
45 series->setHoleSize((j - 1) / (qreal) table.count() + 0.1);
47 series->setHorizontalPosition(0.5);
46 series->setHorizontalPosition(0.5);
48 series->setVerticalPosition(0.5);
47 series->setVerticalPosition(0.5);
49 chart->addSeries(series);
48 chart->addSeries(series);
50 }
49 }
51 return chart;
50 return chart;
52 }
51 }
53
54 };
52 };
55
53
56 DECLARE_CHART(DonutChart)
54 DECLARE_CHART(DonutChart)
57
55
@@ -1,59 +1,57
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 QObject::tr("PieSeries"); }
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
37 qreal pieSize = 1.0 / table.count();
36 qreal pieSize = 1.0 / table.count();
38 for (int i = 0; i < table.count(); i++) {
37 for (int i = 0; i < table.count(); i++) {
39 QPieSeries *series = new QPieSeries(chart);
38 QPieSeries *series = new QPieSeries(chart);
40 foreach (Data data, table[i]) {
39 foreach (Data data, table[i]) {
41 QPieSlice *slice = series->append(data.second, data.first.y());
40 QPieSlice *slice = series->append(data.second, data.first.y());
42 if (data == table[i].first()) {
41 if (data == table[i].first()) {
43 slice->setLabelVisible();
42 slice->setLabelVisible();
44 slice->setExploded();
43 slice->setExploded();
45 }
44 }
46 }
45 }
47 qreal hPos = (pieSize / 2) + (i / (qreal) table.count());
46 qreal hPos = (pieSize / 2) + (i / (qreal) table.count());
48 series->setPieSize(pieSize);
47 series->setPieSize(pieSize);
49 series->setHorizontalPosition(hPos);
48 series->setHorizontalPosition(hPos);
50 series->setVerticalPosition(0.5);
49 series->setVerticalPosition(0.5);
51 chart->addSeries(series);
50 chart->addSeries(series);
52 }
51 }
53 return chart;
52 return chart;
54 }
53 }
55
56 };
54 };
57
55
58 DECLARE_CHART(PieChart)
56 DECLARE_CHART(PieChart)
59
57
@@ -1,69 +1,65
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qareaseries.h"
23 #include "qareaseries.h"
24 #include "qlineseries.h"
24 #include "qlineseries.h"
25
25
26 class AreaChart: public Chart
26 class AreaChart: public Chart
27 {
27 {
28 public:
28 public:
29 QString name() { return QObject::tr("AreaChart"); }
29 QString name() { return QObject::tr("AreaChart"); }
30 QString category() { return QObject::tr("XYSeries"); }
30 QString category() { return QObject::tr("XYSeries"); }
31 QString subCategory() { return QString::null; }
31 QString subCategory() { return QString::null; }
32
32
33 QChart* createChart(const DataTable& table)
33 QChart *createChart(const DataTable &table)
34 {
34 {
35
36 QChart *chart = new QChart();
35 QChart *chart = new QChart();
37 chart->setTitle("Area chart");
36 chart->setTitle("Area chart");
38
37
39 // The lower series initialized to zero values
38 // The lower series initialized to zero values
40 QLineSeries *lowerSeries = 0;
39 QLineSeries *lowerSeries = 0;
41 QString name("Series ");
40 QString name("Series ");
42 int nameIndex = 0;
41 int nameIndex = 0;
43 for (int i(0); i < table.count(); i++) {
42 for (int i(0); i < table.count(); i++) {
44 QLineSeries *upperSeries = new QLineSeries(chart);
43 QLineSeries *upperSeries = new QLineSeries(chart);
45 for (int j(0); j < table[i].count(); j++) {
44 for (int j(0); j < table[i].count(); j++) {
46 Data data = table[i].at(j);
45 Data data = table[i].at(j);
47 if (lowerSeries) {
46 if (lowerSeries) {
48 const QList<QPointF>& points = lowerSeries->points();
47 const QList<QPointF>& points = lowerSeries->points();
49 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
48 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
50 }
49 } else {
51 else
52 upperSeries->append(QPointF(j, data.first.y()));
50 upperSeries->append(QPointF(j, data.first.y()));
51 }
53 }
52 }
54 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
53 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
55 area->setName(name + QString::number(nameIndex));
54 area->setName(name + QString::number(nameIndex));
56 nameIndex++;
55 nameIndex++;
57 chart->addSeries(area);
56 chart->addSeries(area);
58 chart->createDefaultAxes();
57 chart->createDefaultAxes();
59 lowerSeries = upperSeries;
58 lowerSeries = upperSeries;
60 }
59 }
61
62 return chart;
60 return chart;
63
64 }
61 }
65
66 };
62 };
67
63
68 DECLARE_CHART(AreaChart)
64 DECLARE_CHART(AreaChart)
69
65
@@ -1,56 +1,52
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 "qlineseries.h"
23 #include "qlineseries.h"
24
24
25 class LineChart: public Chart
25 class LineChart: public Chart
26 {
26 {
27 public:
27 public:
28 QString name() { return QObject::tr("LineChart"); }
28 QString name() { return QObject::tr("LineChart"); }
29 QString category() { return QObject::tr("XYSeries"); }
29 QString category() { return QObject::tr("XYSeries"); }
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("Line chart");
35 chart->setTitle("Line chart");
36
36 QString name("Series ");
37 QString name("Series ");
37 int nameIndex = 0;
38 int nameIndex = 0;
38 foreach (DataList list, table) {
39 foreach (DataList list, table) {
39 QLineSeries *series = new QLineSeries(chart);
40 QLineSeries *series = new QLineSeries(chart);
40 foreach (Data data, list)
41 foreach (Data data, list)
41 series->append(data.first);
42 series->append(data.first);
42 series->setName(name + QString::number(nameIndex));
43 series->setName(name + QString::number(nameIndex));
43 nameIndex++;
44 nameIndex++;
44 chart->addSeries(series);
45 chart->addSeries(series);
45 }
46 }
46 chart->createDefaultAxes();
47
47 return chart;
48 chart->createDefaultAxes();
49
50 return chart;
51 }
48 }
52
53 };
49 };
54
50
55 DECLARE_CHART(LineChart)
51 DECLARE_CHART(LineChart)
56
52
@@ -1,54 +1,51
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 "qscatterseries.h"
23 #include "qscatterseries.h"
24
24
25 class ScatterChart: public Chart
25 class ScatterChart: public Chart
26 {
26 {
27 public:
27 public:
28 QString name() { return QObject::tr("ScatterChart"); }
28 QString name() { return QObject::tr("ScatterChart"); }
29 QString category() { return QObject::tr("XYSeries"); }
29 QString category() { return QObject::tr("XYSeries"); }
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
34 QChart *chart = new QChart();
35 QChart* chart = new QChart();
36 chart->setTitle("Scatter chart");
35 chart->setTitle("Scatter chart");
37 QString name("Series ");
36 QString name("Series ");
38 int nameIndex = 0;
37 int nameIndex = 0;
39 foreach (DataList list, table) {
38 foreach (DataList list, table) {
40 QScatterSeries *series = new QScatterSeries(chart);
39 QScatterSeries *series = new QScatterSeries(chart);
41 foreach (Data data, list)
40 foreach (Data data, list)
42 series->append(data.first);
41 series->append(data.first);
43 series->setName(name + QString::number(nameIndex));
42 series->setName(name + QString::number(nameIndex));
44 nameIndex++;
43 nameIndex++;
45 chart->addSeries(series);
44 chart->addSeries(series);
46 }
45 }
47 chart->createDefaultAxes();
46 chart->createDefaultAxes();
48
49 return chart;
47 return chart;
50 }
48 }
51
52 };
49 };
53
50
54 DECLARE_CHART(ScatterChart)
51 DECLARE_CHART(ScatterChart)
@@ -1,55 +1,52
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 "qsplineseries.h"
23 #include "qsplineseries.h"
24
24
25 class SplineChart: public Chart
25 class SplineChart: public Chart
26 {
26 {
27 public:
27 public:
28 QString name() { return QObject::tr("SplineChart"); }
28 QString name() { return QObject::tr("SplineChart"); }
29 QString category() { return QObject::tr("XYSeries"); }
29 QString category() { return QObject::tr("XYSeries"); }
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
34 QChart *chart = new QChart();
35 QChart* chart = new QChart();
36
37 chart->setTitle("Spline chart");
35 chart->setTitle("Spline chart");
38 QString name("Series ");
36 QString name("Series ");
39 int nameIndex = 0;
37 int nameIndex = 0;
40 foreach (DataList list, table) {
38 foreach (DataList list, table) {
41 QSplineSeries *series = new QSplineSeries(chart);
39 QSplineSeries *series = new QSplineSeries(chart);
42 foreach (Data data, list)
40 foreach (Data data, list)
43 series->append(data.first);
41 series->append(data.first);
44 series->setName(name + QString::number(nameIndex));
42 series->setName(name + QString::number(nameIndex));
45 nameIndex++;
43 nameIndex++;
46 chart->addSeries(series);
44 chart->addSeries(series);
47 }
45 }
48 chart->createDefaultAxes();
46 chart->createDefaultAxes();
49 return chart;
47 return chart;
50 }
48 }
51
52 };
49 };
53
50
54 DECLARE_CHART(SplineChart)
51 DECLARE_CHART(SplineChart)
55
52
@@ -1,68 +1,66
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 MODEL_H
21 #ifndef MODEL_H
22 #define MODEL_H
22 #define MODEL_H
23
23
24 #include <QList>
24 #include <QList>
25 #include <QPair>
25 #include <QPair>
26 #include <QPointF>
26 #include <QPointF>
27 #include <QTime>
27 #include <QTime>
28 #include <stdlib.h>
28 #include <stdlib.h>
29
29
30 typedef QPair<QPointF, QString> Data;
30 typedef QPair<QPointF, QString> Data;
31 typedef QList<Data> DataList;
31 typedef QList<Data> DataList;
32 typedef QList<DataList> DataTable;
32 typedef QList<DataList> DataTable;
33
33
34
34
35 class Model
35 class Model
36 {
36 {
37 private:
37 private:
38 Model(){}
38 Model() {}
39
39
40 public:
40 public:
41 static DataTable generateRandomData(int listCount, int valueMax, int valueCount)
41 static DataTable generateRandomData(int listCount, int valueMax, int valueCount)
42 {
42 {
43 DataTable dataTable;
43 DataTable dataTable;
44
44
45 // set seed for random stuff
45 // set seed for random stuff
46 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
46 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
47
47
48 // generate random data
48 // generate random data
49 for (int i(0); i < listCount; i++) {
49 for (int i(0); i < listCount; i++) {
50 DataList dataList;
50 DataList dataList;
51 qreal yValue(0);
51 qreal yValue(0);
52 for (int j(0); j < valueCount; j++) {
52 for (int j(0); j < valueCount; j++) {
53 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
53 yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount;
54 QPointF value(
54 QPointF value(
55 (j + (qreal) qrand() / (qreal) RAND_MAX)
55 (j + (qreal) qrand() / (qreal) RAND_MAX)
56 * ((qreal) valueMax / (qreal) valueCount), yValue);
56 * ((qreal) valueMax / (qreal) valueCount), yValue);
57 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
57 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
58 dataList << Data(value, label);
58 dataList << Data(value, label);
59 }
59 }
60 dataTable << dataList;
60 dataTable << dataList;
61 }
61 }
62
63 return dataTable;
62 return dataTable;
64 }
63 }
65
66 };
64 };
67
65
68 #endif
66 #endif
@@ -1,56 +1,56
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 "view.h"
21 #include "view.h"
22 #include <QGraphicsWidget>
22 #include <QGraphicsWidget>
23 #include <QResizeEvent>
23 #include <QResizeEvent>
24 #include <QDebug>
24 #include <QDebug>
25
25
26 View::View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent):QGraphicsView(scene,parent),
26 View::View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent)
27 m_form(form)
27 : QGraphicsView(scene, parent),
28 m_form(form)
28 {
29 {
29 setDragMode(QGraphicsView::NoDrag);
30 setDragMode(QGraphicsView::NoDrag);
30 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
31 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
31 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
32 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
32 }
33 }
33
34
34 void View::resizeEvent(QResizeEvent *event)
35 void View::resizeEvent(QResizeEvent *event)
35 {
36 {
36 if (scene())
37 if (scene())
37 scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
38 scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
38 if (m_form)
39 if (m_form)
39 m_form->resize(QSizeF(event->size()));
40 m_form->resize(QSizeF(event->size()));
40 QGraphicsView::resizeEvent(event);
41 QGraphicsView::resizeEvent(event);
41 }
42 }
42
43
43 void View::mouseMoveEvent(QMouseEvent *event)
44 void View::mouseMoveEvent(QMouseEvent *event)
44 {
45 {
45 //BugFix somehow view always eats the mouse move event;
46 //BugFix somehow view always eats the mouse move event;
46 QGraphicsView::mouseMoveEvent(event);
47 QGraphicsView::mouseMoveEvent(event);
47 event->setAccepted(false);
48 event->setAccepted(false);
48 }
49 }
49
50
50 void View::mouseReleaseEvent(QMouseEvent *event)
51 void View::mouseReleaseEvent(QMouseEvent *event)
51 {
52 {
52
53 QGraphicsView::mouseReleaseEvent(event);
53 QGraphicsView::mouseReleaseEvent(event);
54 //BugFix somehow view always eats the mouse release event;
54 //BugFix somehow view always eats the mouse release event;
55 event->setAccepted(false);
55 event->setAccepted(false);
56 }
56 }
@@ -1,591 +1,571
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_templateComboBox(0),
57 m_openGLCheckBox(0),
57 m_openGLCheckBox(0),
58 m_zoomCheckBox(0),
58 m_zoomCheckBox(0),
59 m_scrollCheckBox(0),
59 m_scrollCheckBox(0),
60 m_rubberBand(new QGraphicsRectItem()),
60 m_rubberBand(new QGraphicsRectItem()),
61 m_baseLayout(new QGraphicsGridLayout()),
61 m_baseLayout(new QGraphicsGridLayout()),
62 m_menu(createMenu()),
62 m_menu(createMenu()),
63 m_state(NoState),
63 m_state(NoState),
64 m_currentState(NoState),
64 m_currentState(NoState),
65 m_template(0)
65 m_template(0)
66 {
66 {
67 createProxyWidgets();
67 createProxyWidgets();
68 // create layout
68 // create layout
69 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
69 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
70 settingsLayout->setOrientation(Qt::Vertical);
70 settingsLayout->setOrientation(Qt::Vertical);
71 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
71 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
72 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
72 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
73 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
73 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
74 settingsLayout->addItem(m_widgetHash["themeLabel"]);
74 settingsLayout->addItem(m_widgetHash["themeLabel"]);
75 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
75 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
76 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
76 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
77 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
77 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
78 settingsLayout->addItem(m_widgetHash["legendLabel"]);
78 settingsLayout->addItem(m_widgetHash["legendLabel"]);
79 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
79 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
80 settingsLayout->addItem(m_widgetHash["templateLabel"]);
80 settingsLayout->addItem(m_widgetHash["templateLabel"]);
81 settingsLayout->addItem(m_widgetHash["templateComboBox"]);
81 settingsLayout->addItem(m_widgetHash["templateComboBox"]);
82 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
82 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
83 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
83 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
84 settingsLayout->addStretch();
84 settingsLayout->addStretch();
85 m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
85 m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
86
86
87 //create charts
87 //create charts
88 Charts::ChartList list = Charts::chartList();
88 Charts::ChartList list = Charts::chartList();
89
89
90 for (int i = 0; i < 9; ++i) {
90 for (int i = 0; i < 9; ++i) {
91 QChart* chart = 0;
91 QChart *chart = 0;
92 if(i<list.size()){
92 if (i < list.size()) {
93 chart = list.at(i)->createChart(m_dataTable);
93 chart = list.at(i)->createChart(m_dataTable);
94 }else{
94 } else {
95 chart = new QChart();
95 chart = new QChart();
96 chart->setTitle(tr("Empty"));
96 chart->setTitle(tr("Empty"));
97 }
97 }
98
98
99 m_baseLayout->addItem(chart, i / 3, i % 3);
99 m_baseLayout->addItem(chart, i / 3, i % 3);
100 m_chartHash[chart] = i;
100 m_chartHash[chart] = i;
101 }
101 }
102
102
103 m_form = new QGraphicsWidget();
103 m_form = new QGraphicsWidget();
104 m_form->setLayout(m_baseLayout);
104 m_form->setLayout(m_baseLayout);
105 m_scene->addItem(m_form);
105 m_scene->addItem(m_form);
106 m_scene->addItem(m_rubberBand);
106 m_scene->addItem(m_rubberBand);
107 m_rubberBand->setVisible(false);
107 m_rubberBand->setVisible(false);
108
108
109 m_view = new View(m_scene, m_form);
109 m_view = new View(m_scene, m_form);
110 m_view->setMinimumSize(m_form->minimumSize().toSize());
110 m_view->setMinimumSize(m_form->minimumSize().toSize());
111
111
112 // Set defaults
112 // Set defaults
113 m_antialiasCheckBox->setChecked(true);
113 m_antialiasCheckBox->setChecked(true);
114 updateUI();
114 updateUI();
115 setCentralWidget(m_view);
115 setCentralWidget(m_view);
116
116
117 connectSignals();
117 connectSignals();
118 }
118 }
119
119
120 Window::~Window()
120 Window::~Window()
121 {
121 {
122 }
122 }
123
123
124 void Window::connectSignals()
124 void Window::connectSignals()
125 {
125 {
126 QObject::connect(m_form, SIGNAL(geometryChanged()),this ,SLOT(handleGeometryChanged()));
126 QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged()));
127 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
127 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
128 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
128 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
129 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
129 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
130 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
130 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
131 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
131 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
132 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
132 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
133 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
133 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
134 QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
134 QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
135 }
135 }
136
136
137 void Window::createProxyWidgets()
137 void Window::createProxyWidgets()
138 {
138 {
139 m_themeComboBox = createThemeBox();
139 m_themeComboBox = createThemeBox();
140 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
140 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
141 m_animatedComboBox = createAnimationBox();
141 m_animatedComboBox = createAnimationBox();
142 m_legendComboBox = createLegendBox();
142 m_legendComboBox = createLegendBox();
143 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
143 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
144 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
144 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
145 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
145 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
146 m_templateComboBox= createTempleteBox();
146 m_templateComboBox = createTempleteBox();
147 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
147 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
148 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
148 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
149 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
149 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
150 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
150 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
151 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
151 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
152 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
152 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
153 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
153 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
154 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
154 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
155 m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template"));
155 m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template"));
156 m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox);
156 m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox);
157 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
157 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
158 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
158 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
159
159
160 }
160 }
161
161
162 QComboBox* Window::createThemeBox()
162 QComboBox *Window::createThemeBox()
163 {
163 {
164 QComboBox* themeComboBox = new ComboBox(this);
164 QComboBox *themeComboBox = new ComboBox(this);
165 themeComboBox->addItem("Light", QChart::ChartThemeLight);
165 themeComboBox->addItem("Light", QChart::ChartThemeLight);
166 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
166 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
167 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
167 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
168 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
168 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
169 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
169 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
170 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
170 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
171 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
171 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
172 return themeComboBox;
172 return themeComboBox;
173 }
173 }
174
174
175 QComboBox* Window::createAnimationBox()
175 QComboBox *Window::createAnimationBox()
176 {
176 {
177 QComboBox* animationComboBox = new ComboBox(this);
177 QComboBox *animationComboBox = new ComboBox(this);
178 animationComboBox->addItem("No Animations", QChart::NoAnimation);
178 animationComboBox->addItem("No Animations", QChart::NoAnimation);
179 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
179 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
180 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
180 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
181 animationComboBox->addItem("All Animations", QChart::AllAnimations);
181 animationComboBox->addItem("All Animations", QChart::AllAnimations);
182 return animationComboBox;
182 return animationComboBox;
183 }
183 }
184
184
185 QComboBox* Window::createLegendBox()
185 QComboBox *Window::createLegendBox()
186 {
186 {
187 QComboBox* legendComboBox = new ComboBox(this);
187 QComboBox *legendComboBox = new ComboBox(this);
188 legendComboBox->addItem("No Legend ", 0);
188 legendComboBox->addItem("No Legend ", 0);
189 legendComboBox->addItem("Legend Top", Qt::AlignTop);
189 legendComboBox->addItem("Legend Top", Qt::AlignTop);
190 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
190 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
191 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
191 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
192 legendComboBox->addItem("Legend Right", Qt::AlignRight);
192 legendComboBox->addItem("Legend Right", Qt::AlignRight);
193 return legendComboBox;
193 return legendComboBox;
194 }
194 }
195
195
196 QComboBox* Window::createTempleteBox()
196 QComboBox *Window::createTempleteBox()
197 {
197 {
198 QComboBox* templateComboBox = new ComboBox(this);
198 QComboBox *templateComboBox = new ComboBox(this);
199 templateComboBox->addItem("No Template", 0);
199 templateComboBox->addItem("No Template", 0);
200
200
201 Charts::ChartList list = Charts::chartList();
201 Charts::ChartList list = Charts::chartList();
202 QMultiMap<QString, Chart*> categoryMap;
202 QMultiMap<QString, Chart *> categoryMap;
203
203
204 foreach(Chart* chart, list) {
204 foreach (Chart *chart, list)
205 categoryMap.insertMulti(chart->category(), chart);
205 categoryMap.insertMulti(chart->category(), chart);
206 }
206
207 foreach(const QString& category, categoryMap.uniqueKeys()) {
207 foreach (const QString &category, categoryMap.uniqueKeys())
208 templateComboBox->addItem(category, category);
208 templateComboBox->addItem(category, category);
209 }
209
210 return templateComboBox;
210 return templateComboBox;
211 }
211 }
212
212
213
213
214 void Window::updateUI()
214 void Window::updateUI()
215 {
215 {
216 checkTemplate();
216 checkTemplate();
217 checkOpenGL();
217 checkOpenGL();
218 checkTheme();
218 checkTheme();
219 checkAnimationOptions();
219 checkAnimationOptions();
220 checkLegend();
220 checkLegend();
221 checkState();
221 checkState();
222 }
222 }
223
223
224 void Window::checkLegend()
224 void Window::checkLegend()
225 {
225 {
226 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
226 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
227
227
228 if (!alignment) {
228 if (!alignment) {
229 foreach (QChart *chart, m_chartHash.keys()) {
229 foreach (QChart *chart, m_chartHash.keys())
230 chart->legend()->hide();
230 chart->legend()->hide();
231 }
231 } else {
232 }
233 else {
234 foreach (QChart *chart, m_chartHash.keys()) {
232 foreach (QChart *chart, m_chartHash.keys()) {
235 chart->legend()->setAlignment(alignment);
233 chart->legend()->setAlignment(alignment);
236 chart->legend()->show();
234 chart->legend()->show();
237 }
235 }
238 }
236 }
239 }
237 }
240
238
241 void Window::checkOpenGL()
239 void Window::checkOpenGL()
242 {
240 {
243 bool opengl = m_openGLCheckBox->isChecked();
241 bool opengl = m_openGLCheckBox->isChecked();
244 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
242 bool isOpengl = qobject_cast<QGLWidget *>(m_view->viewport());
245 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
243 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
246 m_view->deleteLater();
244 m_view->deleteLater();
247 m_view = new View(m_scene, m_form);
245 m_view = new View(m_scene, m_form);
248 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
246 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
249 setCentralWidget(m_view);
247 setCentralWidget(m_view);
250 }
248 }
251
249
252 bool antialias = m_antialiasCheckBox->isChecked();
250 bool antialias = m_antialiasCheckBox->isChecked();
253
251
254 if (opengl)
252 if (opengl)
255 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
253 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
256 else
254 else
257 m_view->setRenderHint(QPainter::Antialiasing, antialias);
255 m_view->setRenderHint(QPainter::Antialiasing, antialias);
258 }
256 }
259
257
260 void Window::checkAnimationOptions()
258 void Window::checkAnimationOptions()
261 {
259 {
262 QChart::AnimationOptions options(
260 QChart::AnimationOptions options(
263 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
261 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
264 if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) {
262
265 foreach (QChart *chart, m_chartHash.keys())
263 if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) {
266 chart->setAnimationOptions(options);
264 foreach (QChart *chart, m_chartHash.keys())
267 }
265 chart->setAnimationOptions(options);
266 }
268 }
267 }
269
268
270 void Window::checkState()
269 void Window::checkState()
271 {
270 {
272 bool scroll = m_scrollCheckBox->isChecked();
271 bool scroll = m_scrollCheckBox->isChecked();
273
272
274 if (m_state != ScrollState && scroll) {
273 if (m_state != ScrollState && scroll) {
275 m_state = ScrollState;
274 m_state = ScrollState;
276 m_zoomCheckBox->setChecked(false);
275 m_zoomCheckBox->setChecked(false);
277 }
276 } else if (!scroll && m_state == ScrollState) {
278 else if (!scroll && m_state == ScrollState) {
279 m_state = NoState;
277 m_state = NoState;
280 }
278 }
281
279
282 bool zoom = m_zoomCheckBox->isChecked();
280 bool zoom = m_zoomCheckBox->isChecked();
283
281
284 if (m_state != ZoomState && zoom) {
282 if (m_state != ZoomState && zoom) {
285 m_state = ZoomState;
283 m_state = ZoomState;
286 m_scrollCheckBox->setChecked(false);
284 m_scrollCheckBox->setChecked(false);
287 }
285 } else if (!zoom && m_state == ZoomState) {
288 else if (!zoom && m_state == ZoomState) {
289 m_state = NoState;
286 m_state = NoState;
290 }
287 }
291 }
288 }
292
289
293 void Window::checkTemplate()
290 void Window::checkTemplate()
294 {
291 {
295
292
296 int index = m_templateComboBox->currentIndex();
293 int index = m_templateComboBox->currentIndex();
297 if (m_template == index || index == 0)
294 if (m_template == index || index == 0)
298 return;
295 return;
299
296
300 m_template = index;
297 m_template = index;
301
298
302 QString category = m_templateComboBox->itemData(index).toString();
299 QString category = m_templateComboBox->itemData(index).toString();
303 Charts::ChartList list = Charts::chartList();
300 Charts::ChartList list = Charts::chartList();
304
301
305 QList<QChart*> qchartList = m_chartHash.keys();
302 QList<QChart *> qchartList = m_chartHash.keys();
306
303
307 foreach(QChart* qchart,qchartList){
304 foreach (QChart *qchart, qchartList) {
308 for(int i = 0 ; i < m_baseLayout->count();++i)
305 for (int i = 0 ; i < m_baseLayout->count(); ++i) {
309 {
306 if (m_baseLayout->itemAt(i) == qchart) {
310 if(m_baseLayout->itemAt(i)==qchart){
307 m_baseLayout->removeAt(i);
311 m_baseLayout->removeAt(i);
308 break;
312 break;
309 }
313 }
310 }
314 }
315 }
311 }
316
312
317 m_chartHash.clear();
313 m_chartHash.clear();
318 qDeleteAll(qchartList);
314 qDeleteAll(qchartList);
319
315
320 QChart* qchart(0);
316 QChart *qchart(0);
321
317
322 int j=0;
318 int j = 0;
323 for (int i = 0; i < list.size(); ++i) {
319 for (int i = 0; i < list.size(); ++i) {
324 Chart* chart = list.at(i);
320 Chart *chart = list.at(i);
325 if (chart->category() == category && j < 9) {
321 if (chart->category() == category && j < 9) {
326 qchart = list.at(i)->createChart(m_dataTable);
322 qchart = list.at(i)->createChart(m_dataTable);
327 m_baseLayout->addItem(qchart, j / 3, j % 3);
323 m_baseLayout->addItem(qchart, j / 3, j % 3);
328 m_chartHash[qchart] = j;
324 m_chartHash[qchart] = j;
329 j++;
325 j++;
330 }
326 }
331 }
327 }
332 for (; j < 9; ++j) {
328 for (; j < 9; ++j) {
333 qchart = new QChart();
329 qchart = new QChart();
334 qchart->setTitle(tr("Empty"));
330 qchart->setTitle(tr("Empty"));
335 m_baseLayout->addItem(qchart, j / 3, j % 3);
331 m_baseLayout->addItem(qchart, j / 3, j % 3);
336 m_chartHash[qchart] = j;
332 m_chartHash[qchart] = j;
337 }
333 }
338 m_baseLayout->activate();
334 m_baseLayout->activate();
339 }
335 }
340
336
341 void Window::checkTheme()
337 void Window::checkTheme()
342 {
338 {
343 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
339 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
344 m_themeComboBox->currentIndex()).toInt();
340 m_themeComboBox->currentIndex()).toInt();
345
341
346 foreach (QChart *chart, m_chartHash.keys())
342 foreach (QChart *chart, m_chartHash.keys())
347 chart->setTheme(theme);
343 chart->setTheme(theme);
348
344
349 QPalette pal = window()->palette();
345 QPalette pal = window()->palette();
350 if (theme == QChart::ChartThemeLight) {
346 if (theme == QChart::ChartThemeLight) {
351 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
347 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
352 pal.setColor(QPalette::WindowText, QRgb(0x404044));
348 pal.setColor(QPalette::WindowText, QRgb(0x404044));
353 }
349 } else if (theme == QChart::ChartThemeDark) {
354 else if (theme == QChart::ChartThemeDark) {
355 pal.setColor(QPalette::Window, QRgb(0x121218));
350 pal.setColor(QPalette::Window, QRgb(0x121218));
356 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
351 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
357 }
352 } else if (theme == QChart::ChartThemeBlueCerulean) {
358 else if (theme == QChart::ChartThemeBlueCerulean) {
359 pal.setColor(QPalette::Window, QRgb(0x40434a));
353 pal.setColor(QPalette::Window, QRgb(0x40434a));
360 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
354 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
361 }
355 } else if (theme == QChart::ChartThemeBrownSand) {
362 else if (theme == QChart::ChartThemeBrownSand) {
363 pal.setColor(QPalette::Window, QRgb(0x9e8965));
356 pal.setColor(QPalette::Window, QRgb(0x9e8965));
364 pal.setColor(QPalette::WindowText, QRgb(0x404044));
357 pal.setColor(QPalette::WindowText, QRgb(0x404044));
365 }
358 } else if (theme == QChart::ChartThemeBlueNcs) {
366 else if (theme == QChart::ChartThemeBlueNcs) {
367 pal.setColor(QPalette::Window, QRgb(0x018bba));
359 pal.setColor(QPalette::Window, QRgb(0x018bba));
368 pal.setColor(QPalette::WindowText, QRgb(0x404044));
360 pal.setColor(QPalette::WindowText, QRgb(0x404044));
369 }
361 } else if (theme == QChart::ChartThemeHighContrast) {
370 else if (theme == QChart::ChartThemeHighContrast) {
371 pal.setColor(QPalette::Window, QRgb(0xffab03));
362 pal.setColor(QPalette::Window, QRgb(0xffab03));
372 pal.setColor(QPalette::WindowText, QRgb(0x181818));
363 pal.setColor(QPalette::WindowText, QRgb(0x181818));
373 }
364 } else if (theme == QChart::ChartThemeBlueIcy) {
374 else if (theme == QChart::ChartThemeBlueIcy) {
375 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
365 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
376 pal.setColor(QPalette::WindowText, QRgb(0x404044));
366 pal.setColor(QPalette::WindowText, QRgb(0x404044));
377 }
367 } else {
378 else {
379 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
368 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
380 pal.setColor(QPalette::WindowText, QRgb(0x404044));
369 pal.setColor(QPalette::WindowText, QRgb(0x404044));
381 }
370 }
382 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
371 foreach (QGraphicsProxyWidget *widget, m_widgetHash)
383 widget->setPalette(pal);
372 widget->setPalette(pal);
384 }
385 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
373 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
386 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
374 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
387 }
375 }
388
376
389 void Window::mousePressEvent(QMouseEvent *event)
377 void Window::mousePressEvent(QMouseEvent *event)
390 {
378 {
391 if (event->button() == Qt::LeftButton) {
379 if (event->button() == Qt::LeftButton) {
392
380
393 m_origin = event->pos();
381 m_origin = event->pos();
394 m_currentState = NoState;
382 m_currentState = NoState;
395
383
396 foreach (QChart *chart, m_chartHash.keys()) {
384 foreach (QChart *chart, m_chartHash.keys()) {
397
385
398 QRectF geometryRect = chart->geometry();
386 QRectF geometryRect = chart->geometry();
399 QRectF plotArea = chart->plotArea();
387 QRectF plotArea = chart->plotArea();
400 plotArea.translate(geometryRect.topLeft());
388 plotArea.translate(geometryRect.topLeft());
401 if (plotArea.contains(m_origin)) {
389 if (plotArea.contains(m_origin)) {
402 m_currentState = m_state;
390 m_currentState = m_state;
403
391 if (m_currentState == NoState && m_templateComboBox->currentIndex() == 0)
404 if (m_currentState == NoState && m_templateComboBox->currentIndex()==0) {
405 handleMenu(chart);
392 handleMenu(chart);
406 }
407 break;
393 break;
408 }
394 }
409 }
395 }
410
396
411 if (m_currentState == ZoomState) {
397 if (m_currentState == ZoomState) {
412 m_rubberBand->setRect(QRectF(m_origin, QSize()));
398 m_rubberBand->setRect(QRectF(m_origin, QSize()));
413 m_rubberBand->setVisible(true);
399 m_rubberBand->setVisible(true);
414 }
400 }
415
401
416 event->accept();
402 event->accept();
417 }
403 }
418
404
419 if (event->button() == Qt::RightButton) {
405 if (event->button() == Qt::RightButton) {
420 m_origin = event->pos();
406 m_origin = event->pos();
421 m_currentState = m_state;
407 m_currentState = m_state;
422 }
408 }
423 }
409 }
424
410
425 void Window::mouseMoveEvent(QMouseEvent *event)
411 void Window::mouseMoveEvent(QMouseEvent *event)
426 {
412 {
427 if ( m_currentState != NoState) {
413 if (m_currentState != NoState) {
428
414
429 foreach (QChart *chart, m_chartHash.keys()) {
415 foreach (QChart *chart, m_chartHash.keys()) {
430
416
431 QRectF geometryRect = chart->geometry();
417 QRectF geometryRect = chart->geometry();
432 QRectF plotArea = chart->plotArea();
418 QRectF plotArea = chart->plotArea();
433 plotArea.translate(geometryRect.topLeft());
419 plotArea.translate(geometryRect.topLeft());
434
420
435 if (plotArea.contains(m_origin)) {
421 if (plotArea.contains(m_origin)) {
436 if (m_currentState == ScrollState) {
422 if (m_currentState == ScrollState) {
437 QPointF delta = m_origin - event->pos();
423 QPointF delta = m_origin - event->pos();
438 chart->scroll(delta.x(), -delta.y());
424 chart->scroll(delta.x(), -delta.y());
439 }
425 }
440 if (m_currentState == ZoomState && plotArea.contains(event->pos())) {
426 if (m_currentState == ZoomState && plotArea.contains(event->pos()))
441 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
427 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
442 }
443 break;
428 break;
444 }
429 }
445 }
430 }
446 if(m_currentState == ScrollState) m_origin = event->pos();
431 if (m_currentState == ScrollState)
432 m_origin = event->pos();
447 event->accept();
433 event->accept();
448 }
434 }
449 }
435 }
450
436
451 void Window::mouseReleaseEvent(QMouseEvent *event)
437 void Window::mouseReleaseEvent(QMouseEvent *event)
452 {
438 {
453 if (event->button() == Qt::LeftButton) {
439 if (event->button() == Qt::LeftButton) {
454 if (m_currentState == ZoomState) {
440 if (m_currentState == ZoomState) {
455 m_rubberBand->setVisible(false);
441 m_rubberBand->setVisible(false);
456
442
457 foreach (QChart *chart, m_chartHash.keys()) {
443 foreach (QChart *chart, m_chartHash.keys()) {
458
444
459 QRectF geometryRect = chart->geometry();
445 QRectF geometryRect = chart->geometry();
460 QRectF plotArea = chart->plotArea();
446 QRectF plotArea = chart->plotArea();
461 plotArea.translate(geometryRect.topLeft());
447 plotArea.translate(geometryRect.topLeft());
462
448
463 if (plotArea.contains(m_origin)) {
449 if (plotArea.contains(m_origin)) {
464 QRectF rect = m_rubberBand->rect();
450 QRectF rect = m_rubberBand->rect();
465 rect.translate(-geometryRect.topLeft());
451 rect.translate(-geometryRect.topLeft());
466 chart->zoomIn(rect);
452 chart->zoomIn(rect);
467 break;
453 break;
468 }
454 }
469 }
455 }
470 }
456 }
471
457
472 m_currentState = NoState;
458 m_currentState = NoState;
473 event->accept();
459 event->accept();
474 }
460 }
475
461
476 if (event->button() == Qt::RightButton) {
462 if (event->button() == Qt::RightButton) {
477
463
478 if (m_currentState == ZoomState) {
464 if (m_currentState == ZoomState) {
479 foreach (QChart *chart, m_chartHash.keys()) {
465 foreach (QChart *chart, m_chartHash.keys()) {
480
466
481 QRectF geometryRect = chart->geometry();
467 QRectF geometryRect = chart->geometry();
482 QRectF plotArea = chart->plotArea();
468 QRectF plotArea = chart->plotArea();
483 plotArea.translate(geometryRect.topLeft());
469 plotArea.translate(geometryRect.topLeft());
484
470
485 if (plotArea.contains(m_origin)) {
471 if (plotArea.contains(m_origin)) {
486 chart->zoomOut();
472 chart->zoomOut();
487 break;
473 break;
488 }
474 }
489 }
475 }
490 }
476 }
491 }
477 }
492 }
478 }
493
479
494 void Window::comboBoxFocused(QComboBox *combobox)
480 void Window::comboBoxFocused(QComboBox *combobox)
495 {
481 {
496 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
482 foreach (QGraphicsProxyWidget *widget , m_widgetHash) {
497 if(widget->widget()==combobox)
483 if (widget->widget() == combobox)
498 widget->setZValue(2.0);
484 widget->setZValue(2.0);
499 else
485 else
500 widget->setZValue(0.0);
486 widget->setZValue(0.0);
501 }
487 }
502 }
488 }
503
489
504 void Window::handleMenu(QChart* qchart)
490 void Window::handleMenu(QChart *qchart)
505 {
491 {
506 QAction *chosen = m_menu->exec(QCursor::pos());
492 QAction *chosen = m_menu->exec(QCursor::pos());
507
493
508 if (chosen) {
494 if (chosen) {
509 Chart* chart = (Chart *) chosen->data().value<void *>();
495 Chart *chart = (Chart *) chosen->data().value<void *>();
510 int index = m_chartHash[qchart];
496 int index = m_chartHash[qchart];
511 //not in 4.7.2 m_baseLayout->removeItem(qchart);
497 //not in 4.7.2 m_baseLayout->removeItem(qchart);
512 for(int i = 0 ; i < m_baseLayout->count();++i)
498 for (int i = 0 ; i < m_baseLayout->count(); ++i) {
513 {
499 if (m_baseLayout->itemAt(i) == qchart) {
514 if(m_baseLayout->itemAt(i)==qchart){
515 m_baseLayout->removeAt(i);
500 m_baseLayout->removeAt(i);
516 break;
501 break;
517 }
502 }
518 }
503 }
519
504
520 m_chartHash.remove(qchart);
505 m_chartHash.remove(qchart);
521 QChart* newChart = chart->createChart(m_dataTable);
506 QChart *newChart = chart->createChart(m_dataTable);
522 m_baseLayout->addItem(newChart, index / 3, index % 3);
507 m_baseLayout->addItem(newChart, index / 3, index % 3);
523 m_chartHash[newChart] = index;
508 m_chartHash[newChart] = index;
524 delete qchart;
509 delete qchart;
525 updateUI();
510 updateUI();
526 }
511 }
527
512
528 }
513 }
529
514
530 QMenu* Window::createMenu()
515 QMenu *Window::createMenu()
531 {
516 {
532 Charts::ChartList list = Charts::chartList();
517 Charts::ChartList list = Charts::chartList();
533 QMultiMap<QString, Chart*> categoryMap;
518 QMultiMap<QString, Chart *> categoryMap;
534
519
535 QMenu* result = new QMenu(this);
520 QMenu *result = new QMenu(this);
536
521
537 foreach(Chart* chart, list) {
522 foreach (Chart *chart, list)
538 categoryMap.insertMulti(chart->category(), chart);
523 categoryMap.insertMulti(chart->category(), chart);
539 }
540
524
541 foreach(const QString& category, categoryMap.uniqueKeys()) {
525 foreach (const QString &category, categoryMap.uniqueKeys()) {
542 QMenu* menu(0);
526 QMenu *menu(0);
543 QMultiMap<QString, Chart*> subCategoryMap;
527 QMultiMap<QString, Chart *> subCategoryMap;
544 if (category.isEmpty()) {
528 if (category.isEmpty()) {
545 menu = result;
529 menu = result;
546 }
530 } else {
547 else {
548 menu = new QMenu(category, this);
531 menu = new QMenu(category, this);
549 result->addMenu(menu);
532 result->addMenu(menu);
550 }
533 }
551
534
552 foreach(Chart* chart , categoryMap.values(category)) {
535 foreach (Chart *chart, categoryMap.values(category))
553 subCategoryMap.insert(chart->subCategory(), chart);
536 subCategoryMap.insert(chart->subCategory(), chart);
554 }
555
537
556 foreach(const QString& subCategory, subCategoryMap.uniqueKeys()) {
538 foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) {
557 QMenu* subMenu(0);
539 QMenu *subMenu(0);
558 if (subCategory.isEmpty()) {
540 if (subCategory.isEmpty()) {
559 subMenu = menu;
541 subMenu = menu;
560 }
542 } else {
561 else {
562 subMenu = new QMenu(subCategory, this);
543 subMenu = new QMenu(subCategory, this);
563 menu->addMenu(subMenu);
544 menu->addMenu(subMenu);
564 }
545 }
565
546
566 foreach(Chart* chart , subCategoryMap.values(subCategory)) {
547 foreach(Chart *chart, subCategoryMap.values(subCategory)) {
567
568 createMenuAction(subMenu, QIcon(), chart->name(),
548 createMenuAction(subMenu, QIcon(), chart->name(),
569 qVariantFromValue((void *) chart));
549 qVariantFromValue((void *) chart));
570 }
550 }
571 }
551 }
572 }
552 }
573
553
574 return result;
554 return result;
575 }
555 }
576
556
577 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
557 QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
578 const QVariant &data)
558 const QVariant &data)
579 {
559 {
580 QAction *action = menu->addAction(icon, text);
560 QAction *action = menu->addAction(icon, text);
581 action->setCheckable(false);
561 action->setCheckable(false);
582 action->setData(data);
562 action->setData(data);
583 return action;
563 return action;
584 }
564 }
585
565
586 void Window::handleGeometryChanged()
566 void Window::handleGeometryChanged()
587 {
567 {
588 QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize);
568 QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize);
589 m_view->scene()->setSceneRect(0, 0, this->width(), this->height());
569 m_view->scene()->setSceneRect(0, 0, this->width(), this->height());
590 m_view->setMinimumSize(size.toSize());
570 m_view->setMinimumSize(size.toSize());
591 }
571 }
@@ -1,124 +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 void handleGeometryChanged();
54 void handleGeometryChanged();
55 private:
55 private:
56 QComboBox* createThemeBox();
56 QComboBox *createThemeBox();
57 QComboBox* createAnimationBox();
57 QComboBox *createAnimationBox();
58 QComboBox* createLegendBox();
58 QComboBox *createLegendBox();
59 QComboBox* createTempleteBox();
59 QComboBox *createTempleteBox();
60 void connectSignals();
60 void connectSignals();
61 void createProxyWidgets();
61 void createProxyWidgets();
62 void comboBoxFocused(QComboBox *combox);
62 void comboBoxFocused(QComboBox *combox);
63 inline void checkAnimationOptions();
63 inline void checkAnimationOptions();
64 inline void checkLegend();
64 inline void checkLegend();
65 inline void checkOpenGL();
65 inline void checkOpenGL();
66 inline void checkTheme();
66 inline void checkTheme();
67 inline void checkState();
67 inline void checkState();
68 inline void checkTemplate();
68 inline void checkTemplate();
69 QMenu* createMenu();
69 QMenu *createMenu();
70 void handleMenu(QChart * chart);
70 void handleMenu(QChart *chart);
71 QAction* createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
71 QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
72
72
73 protected:
73 protected:
74 void mousePressEvent(QMouseEvent *event);
74 void mousePressEvent(QMouseEvent *event);
75 void mouseMoveEvent(QMouseEvent *event);
75 void mouseMoveEvent(QMouseEvent *event);
76 void mouseReleaseEvent(QMouseEvent *event);
76 void mouseReleaseEvent(QMouseEvent *event);
77
77
78 private:
78 private:
79 int m_listCount;
79 int m_listCount;
80 int m_valueMax;
80 int m_valueMax;
81 int m_valueCount;
81 int m_valueCount;
82 QGraphicsScene* m_scene;
82 QGraphicsScene *m_scene;
83 View* m_view;
83 View *m_view;
84 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
84 QHash<QString, QGraphicsProxyWidget *> m_widgetHash;
85 QHash<QChart*, int> m_chartHash;
85 QHash<QChart *, int> m_chartHash;
86 DataTable m_dataTable;
86 DataTable m_dataTable;
87
87
88 QGraphicsWidget *m_form;
88 QGraphicsWidget *m_form;
89 QComboBox *m_themeComboBox;
89 QComboBox *m_themeComboBox;
90 QCheckBox *m_antialiasCheckBox;
90 QCheckBox *m_antialiasCheckBox;
91 QComboBox *m_animatedComboBox;
91 QComboBox *m_animatedComboBox;
92 QComboBox *m_legendComboBox;
92 QComboBox *m_legendComboBox;
93 QComboBox *m_templateComboBox;
93 QComboBox *m_templateComboBox;
94 QCheckBox *m_openGLCheckBox;
94 QCheckBox *m_openGLCheckBox;
95 QCheckBox *m_zoomCheckBox;
95 QCheckBox *m_zoomCheckBox;
96 QCheckBox *m_scrollCheckBox;
96 QCheckBox *m_scrollCheckBox;
97 QPoint m_origin;
97 QPoint m_origin;
98 QGraphicsRectItem* m_rubberBand;
98 QGraphicsRectItem *m_rubberBand;
99 QGraphicsGridLayout* m_baseLayout;
99 QGraphicsGridLayout *m_baseLayout;
100 QMenu* m_menu;
100 QMenu *m_menu;
101 State m_state;
101 State m_state;
102 State m_currentState;
102 State m_currentState;
103 int m_template;
103 int m_template;
104
104
105 friend class ComboBox;
105 friend class ComboBox;
106 };
106 };
107
107
108 class ComboBox: public QComboBox
108 class ComboBox: public QComboBox
109 {
109 {
110 public:
110 public:
111 ComboBox(Window* window,QWidget *parent = 0):QComboBox(parent),m_window(window)
111 ComboBox(Window *window, QWidget *parent = 0): QComboBox(parent), m_window(window)
112 {}
112 {}
113
113
114 protected:
114 protected:
115 void focusInEvent(QFocusEvent *e)
115 void focusInEvent(QFocusEvent *e) {
116 {
117 QComboBox::focusInEvent(e);
116 QComboBox::focusInEvent(e);
118 m_window->comboBoxFocused(this);
117 m_window->comboBoxFocused(this);
119 }
118 }
120 private:
119 private:
121 Window* m_window;
120 Window *m_window;
122 };
121 };
123
122
124 #endif
123 #endif
@@ -1,71 +1,72
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 "chart.h"
21 #include "chart.h"
22 #include <QAbstractAxis>
22 #include <QAbstractAxis>
23 #include <QSplineSeries>
23 #include <QSplineSeries>
24 #include <QValueAxis>
24 #include <QValueAxis>
25 #include <QTime>
25 #include <QTime>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags):
28 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags):
29 QChart(parent, wFlags),
29 QChart(parent, wFlags),
30 m_series(0),
30 m_series(0),
31 m_axis(new QValueAxis),
31 m_axis(new QValueAxis),
32 m_step(0),
32 m_step(0),
33 m_x(5),
33 m_x(5),
34 m_y(1)
34 m_y(1)
35 {
35 {
36 qsrand((uint) QTime::currentTime().msec());
36 qsrand((uint) QTime::currentTime().msec());
37
37
38 QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
38 QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
39 m_timer.setInterval(1000);
39 m_timer.setInterval(1000);
40
40
41 m_series = new QSplineSeries(this);
41 m_series = new QSplineSeries(this);
42 QPen green(Qt::red);
42 QPen green(Qt::red);
43 green.setWidth(3);
43 green.setWidth(3);
44 m_series->setPen(green);
44 m_series->setPen(green);
45 m_series->append(m_x, m_y);
45 m_series->append(m_x, m_y);
46
46
47 addSeries(m_series);
47 addSeries(m_series);
48 createDefaultAxes();
48 createDefaultAxes();
49 setAxisX(m_axis,m_series);
49 setAxisX(m_axis, m_series);
50 m_axis->setTickCount(5);
50 m_axis->setTickCount(5);
51 axisX()->setRange(0, 10);
51 axisX()->setRange(0, 10);
52 axisY()->setRange(-5, 10);
52 axisY()->setRange(-5, 10);
53
53
54 m_timer.start();
54 m_timer.start();
55 }
55 }
56
56
57 Chart::~Chart()
57 Chart::~Chart()
58 {
58 {
59
59
60 }
60 }
61
61
62 void Chart::handleTimeout()
62 void Chart::handleTimeout()
63 {
63 {
64 qreal x = plotArea().width()/m_axis->tickCount();
64 qreal x = plotArea().width() / m_axis->tickCount();
65 qreal y =(m_axis->max() - m_axis->min())/m_axis->tickCount();
65 qreal y = (m_axis->max() - m_axis->min()) / m_axis->tickCount();
66 m_x += y;
66 m_x += y;
67 m_y = qrand() % 5 - 2.5;
67 m_y = qrand() % 5 - 2.5;
68 m_series->append(m_x, m_y);
68 m_series->append(m_x, m_y);
69 scroll(x,0);
69 scroll(x, 0);
70 if(m_x==100) m_timer.stop();
70 if (m_x == 100)
71 m_timer.stop();
71 }
72 }
@@ -1,56 +1,56
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 CHART_H
21 #ifndef CHART_H
22 #define CHART_H
22 #define CHART_H
23
23
24 #include <QChart>
24 #include <QChart>
25 #include <QTimer>
25 #include <QTimer>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 class QSplineSeries;
28 class QSplineSeries;
29 class QValueAxis;
29 class QValueAxis;
30 QTCOMMERCIALCHART_END_NAMESPACE
30 QTCOMMERCIALCHART_END_NAMESPACE
31
31
32 QTCOMMERCIALCHART_USE_NAMESPACE
32 QTCOMMERCIALCHART_USE_NAMESPACE
33
33
34 //![1]
34 //![1]
35 class Chart: public QChart
35 class Chart: public QChart
36 {
36 {
37 Q_OBJECT
37 Q_OBJECT
38 public:
38 public:
39 Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
39 Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
40 virtual ~Chart();
40 virtual ~Chart();
41
41
42 public slots:
42 public slots:
43 void handleTimeout();
43 void handleTimeout();
44
44
45 private:
45 private:
46 QTimer m_timer;
46 QTimer m_timer;
47 QSplineSeries* m_series;
47 QSplineSeries *m_series;
48 QStringList m_titles;
48 QStringList m_titles;
49 QValueAxis* m_axis;
49 QValueAxis *m_axis;
50 qreal m_step;
50 qreal m_step;
51 qreal m_x;
51 qreal m_x;
52 qreal m_y;
52 qreal m_y;
53 };
53 };
54 //![1]
54 //![1]
55
55
56 #endif /* CHART_H */
56 #endif /* CHART_H */
@@ -1,30 +1,29
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 #include <QApplication>
20 #include <QApplication>
21 #include "widget.h"
21 #include "widget.h"
22
22
23 int main(int argc, char *argv[])
23 int main(int argc, char *argv[])
24 {
24 {
25 QApplication a(argc, argv);
25 QApplication a(argc, argv);
26 Widget w;
26 Widget w;
27 w.show();
27 w.show();
28
29 return a.exec();
28 return a.exec();
30 }
29 }
@@ -1,128 +1,128
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 #include "widget.h"
20 #include "widget.h"
21 #include <QChartView>
21 #include <QChartView>
22 #include <QChart>
22 #include <QChart>
23 #include <QLegend>
23 #include <QLegend>
24 #include <QPieSeries>
24 #include <QPieSeries>
25 #include <QPieSlice>
25 #include <QPieSlice>
26 #include <QTime>
26 #include <QTime>
27 #include <QGridLayout>
27 #include <QGridLayout>
28 #include <QTimer>
28 #include <QTimer>
29
29
30 QTCOMMERCIALCHART_USE_NAMESPACE
30 QTCOMMERCIALCHART_USE_NAMESPACE
31
31
32 Widget::Widget(QWidget *parent)
32 Widget::Widget(QWidget *parent)
33 : QWidget(parent)
33 : QWidget(parent)
34 {
34 {
35 setMinimumSize(800, 600);
35 setMinimumSize(800, 600);
36 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
36 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
37
37
38 //! [1]
38 //! [1]
39 QChartView *chartView = new QChartView;
39 QChartView *chartView = new QChartView;
40 chartView->setRenderHint(QPainter::Antialiasing);
40 chartView->setRenderHint(QPainter::Antialiasing);
41 QChart *chart = chartView->chart();
41 QChart *chart = chartView->chart();
42 chart->legend()->setVisible(false);
42 chart->legend()->setVisible(false);
43 chart->setTitle("Nested donuts demo");
43 chart->setTitle("Nested donuts demo");
44 chart->setAnimationOptions(QChart::AllAnimations);
44 chart->setAnimationOptions(QChart::AllAnimations);
45 //! [1]
45 //! [1]
46
46
47 //! [2]
47 //! [2]
48 qreal minSize = 0.1;
48 qreal minSize = 0.1;
49 qreal maxSize = 0.9;
49 qreal maxSize = 0.9;
50 int donutCount = 5;
50 int donutCount = 5;
51 //! [2]
51 //! [2]
52
52
53 //! [3]
53 //! [3]
54 for (int i = 0; i < donutCount; i++) {
54 for (int i = 0; i < donutCount; i++) {
55 QPieSeries *donut = new QPieSeries;
55 QPieSeries *donut = new QPieSeries;
56 int sliceCount = 3 + qrand() % 3;
56 int sliceCount = 3 + qrand() % 3;
57 for (int j = 0; j < sliceCount; j++) {
57 for (int j = 0; j < sliceCount; j++) {
58 qreal value = 100 + qrand() % 100;
58 qreal value = 100 + qrand() % 100;
59 QPieSlice *slice = new QPieSlice(QString("%1").arg(value), value);
59 QPieSlice *slice = new QPieSlice(QString("%1").arg(value), value);
60 slice->setLabelVisible(true);
60 slice->setLabelVisible(true);
61 slice->setLabelColor(Qt::white);
61 slice->setLabelColor(Qt::white);
62 slice->setLabelPosition(QPieSlice::LabelInsideTangential);
62 slice->setLabelPosition(QPieSlice::LabelInsideTangential);
63 connect(slice, SIGNAL(hovered(bool)), this, SLOT(explodeSlice(bool)));
63 connect(slice, SIGNAL(hovered(bool)), this, SLOT(explodeSlice(bool)));
64 donut->append(slice);
64 donut->append(slice);
65 donut->setHoleSize(minSize + i * (maxSize - minSize) / donutCount);
65 donut->setHoleSize(minSize + i * (maxSize - minSize) / donutCount);
66 donut->setPieSize(minSize + (i + 1) * (maxSize - minSize) / donutCount);
66 donut->setPieSize(minSize + (i + 1) * (maxSize - minSize) / donutCount);
67 }
67 }
68 m_donuts.append(donut);
68 m_donuts.append(donut);
69 chartView->chart()->addSeries(donut);
69 chartView->chart()->addSeries(donut);
70 }
70 }
71 //! [3]
71 //! [3]
72
72
73 // create main layout
73 // create main layout
74 //! [4]
74 //! [4]
75 QGridLayout* mainLayout = new QGridLayout;
75 QGridLayout *mainLayout = new QGridLayout;
76 mainLayout->addWidget(chartView, 1, 1);
76 mainLayout->addWidget(chartView, 1, 1);
77 setLayout(mainLayout);
77 setLayout(mainLayout);
78 //! [4]
78 //! [4]
79
79
80 //! [5]
80 //! [5]
81 updateTimer = new QTimer(this);
81 updateTimer = new QTimer(this);
82 connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateRotation()));
82 connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateRotation()));
83 updateTimer->start(1250);
83 updateTimer->start(1250);
84 //! [5]
84 //! [5]
85 }
85 }
86
86
87 Widget::~Widget()
87 Widget::~Widget()
88 {
88 {
89
89
90 }
90 }
91
91
92 //! [6]
92 //! [6]
93 void Widget::updateRotation()
93 void Widget::updateRotation()
94 {
94 {
95 for (int i = 0; i < m_donuts.count(); i++) {
95 for (int i = 0; i < m_donuts.count(); i++) {
96 QPieSeries *donut = m_donuts.at(i);
96 QPieSeries *donut = m_donuts.at(i);
97 qreal phaseShift = -50 + qrand() % 100;
97 qreal phaseShift = -50 + qrand() % 100;
98 donut->setPieStartAngle(donut->pieStartAngle() + phaseShift);
98 donut->setPieStartAngle(donut->pieStartAngle() + phaseShift);
99 donut->setPieEndAngle(donut->pieEndAngle() + phaseShift);
99 donut->setPieEndAngle(donut->pieEndAngle() + phaseShift);
100 }
100 }
101 }
101 }
102 //! [6]
102 //! [6]
103
103
104 //! [7]
104 //! [7]
105 void Widget::explodeSlice(bool exploded)
105 void Widget::explodeSlice(bool exploded)
106 {
106 {
107 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
107 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
108 if (exploded) {
108 if (exploded) {
109 updateTimer->stop();
109 updateTimer->stop();
110 qreal sliceStartAngle = slice->startAngle();
110 qreal sliceStartAngle = slice->startAngle();
111 qreal sliceEndAngle = slice->startAngle() + slice->angleSpan();
111 qreal sliceEndAngle = slice->startAngle() + slice->angleSpan();
112
112
113 QPieSeries *donut = slice->series();
113 QPieSeries *donut = slice->series();
114 qreal seriesIndex = m_donuts.indexOf(donut);
114 qreal seriesIndex = m_donuts.indexOf(donut);
115 for (int i = seriesIndex + 1; i < m_donuts.count(); i++) {
115 for (int i = seriesIndex + 1; i < m_donuts.count(); i++) {
116 m_donuts.at(i)->setPieStartAngle(sliceEndAngle);
116 m_donuts.at(i)->setPieStartAngle(sliceEndAngle);
117 m_donuts.at(i)->setPieEndAngle(360 + sliceStartAngle);
117 m_donuts.at(i)->setPieEndAngle(360 + sliceStartAngle);
118 }
118 }
119 } else {
119 } else {
120 for (int i = 0; i < m_donuts.count(); i++) {
120 for (int i = 0; i < m_donuts.count(); i++) {
121 m_donuts.at(i)->setPieStartAngle(0);
121 m_donuts.at(i)->setPieStartAngle(0);
122 m_donuts.at(i)->setPieEndAngle(360);
122 m_donuts.at(i)->setPieEndAngle(360);
123 }
123 }
124 updateTimer->start();
124 updateTimer->start();
125 }
125 }
126 slice->setExploded(exploded);
126 slice->setExploded(exploded);
127 }
127 }
128 //! [7]
128 //! [7]
@@ -1,47 +1,47
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 #ifndef WIDGET_H
20 #ifndef WIDGET_H
21 #define WIDGET_H
21 #define WIDGET_H
22
22
23 #include <QWidget>
23 #include <QWidget>
24 #include <QPieSeries>
24 #include <QPieSeries>
25
25
26 class QTimer;
26 class QTimer;
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 class Widget : public QWidget
30 class Widget : public QWidget
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33
33
34 public:
34 public:
35 Widget(QWidget *parent = 0);
35 Widget(QWidget *parent = 0);
36 ~Widget();
36 ~Widget();
37
37
38 public slots:
38 public slots:
39 void updateRotation();
39 void updateRotation();
40 void explodeSlice(bool exploded);
40 void explodeSlice(bool exploded);
41
41
42 private:
42 private:
43 QList<QPieSeries *> m_donuts;
43 QList<QPieSeries *> m_donuts;
44 QTimer *updateTimer;
44 QTimer *updateTimer;
45 };
45 };
46
46
47 #endif // WIDGET_H
47 #endif // WIDGET_H
@@ -1,100 +1,100
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 #include "brushtool.h"
20 #include "brushtool.h"
21 #include <QPushButton>
21 #include <QPushButton>
22 #include <QFormLayout>
22 #include <QFormLayout>
23 #include <QComboBox>
23 #include <QComboBox>
24 #include <QColorDialog>
24 #include <QColorDialog>
25
25
26 BrushTool::BrushTool(QString title, QWidget *parent)
26 BrushTool::BrushTool(QString title, QWidget *parent)
27 :QWidget(parent)
27 : QWidget(parent)
28 {
28 {
29 setWindowTitle(title);
29 setWindowTitle(title);
30 setWindowFlags(Qt::Tool);
30 setWindowFlags(Qt::Tool);
31
31
32 m_colorButton = new QPushButton();
32 m_colorButton = new QPushButton();
33 m_styleCombo = new QComboBox();
33 m_styleCombo = new QComboBox();
34 m_styleCombo->addItem("Nobrush", Qt::NoBrush);
34 m_styleCombo->addItem("Nobrush", Qt::NoBrush);
35 m_styleCombo->addItem("Solidpattern", Qt::SolidPattern);
35 m_styleCombo->addItem("Solidpattern", Qt::SolidPattern);
36 m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern);
36 m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern);
37 m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern);
37 m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern);
38 m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern);
38 m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern);
39 m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern);
39 m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern);
40 m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern);
40 m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern);
41 m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern);
41 m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern);
42 m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern);
42 m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern);
43 m_styleCombo->addItem("HorPattern", Qt::HorPattern);
43 m_styleCombo->addItem("HorPattern", Qt::HorPattern);
44 m_styleCombo->addItem("VerPattern", Qt::VerPattern);
44 m_styleCombo->addItem("VerPattern", Qt::VerPattern);
45 m_styleCombo->addItem("CrossPattern", Qt::CrossPattern);
45 m_styleCombo->addItem("CrossPattern", Qt::CrossPattern);
46 m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern);
46 m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern);
47 m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern);
47 m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern);
48 m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern);
48 m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern);
49
49
50 QFormLayout *layout = new QFormLayout();
50 QFormLayout *layout = new QFormLayout();
51 layout->addRow("Color", m_colorButton);
51 layout->addRow("Color", m_colorButton);
52 layout->addRow("Style", m_styleCombo);
52 layout->addRow("Style", m_styleCombo);
53 setLayout(layout);
53 setLayout(layout);
54
54
55 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
55 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
56 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle()));
56 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle()));
57 }
57 }
58
58
59 void BrushTool::setBrush(QBrush brush)
59 void BrushTool::setBrush(QBrush brush)
60 {
60 {
61 m_brush = brush;
61 m_brush = brush;
62 m_colorButton->setText(m_brush.color().name());
62 m_colorButton->setText(m_brush.color().name());
63 m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum
63 m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum
64 }
64 }
65
65
66 QBrush BrushTool::brush() const
66 QBrush BrushTool::brush() const
67 {
67 {
68 return m_brush;
68 return m_brush;
69 }
69 }
70
70
71 QString BrushTool::name()
71 QString BrushTool::name()
72 {
72 {
73 return name(m_brush);
73 return name(m_brush);
74 }
74 }
75
75
76 QString BrushTool::name(const QBrush &brush)
76 QString BrushTool::name(const QBrush &brush)
77 {
77 {
78 return brush.color().name();
78 return brush.color().name();
79 }
79 }
80
80
81 void BrushTool::showColorDialog()
81 void BrushTool::showColorDialog()
82 {
82 {
83 QColorDialog dialog(m_brush.color());
83 QColorDialog dialog(m_brush.color());
84 dialog.show();
84 dialog.show();
85 dialog.exec();
85 dialog.exec();
86 m_brush.setColor(dialog.selectedColor());
86 m_brush.setColor(dialog.selectedColor());
87 m_colorButton->setText(m_brush.color().name());
87 m_colorButton->setText(m_brush.color().name());
88 emit changed();
88 emit changed();
89 }
89 }
90
90
91 void BrushTool::updateStyle()
91 void BrushTool::updateStyle()
92 {
92 {
93 Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt();
93 Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt();
94 if (m_brush.style() != style) {
94 if (m_brush.style() != style) {
95 m_brush.setStyle(style);
95 m_brush.setStyle(style);
96 emit changed();
96 emit changed();
97 }
97 }
98 }
98 }
99
99
100 #include "moc_brushtool.cpp"
100 #include "moc_brushtool.cpp"
@@ -1,48 +1,48
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 "customslice.h"
21 #include "customslice.h"
22
22
23 QTCOMMERCIALCHART_USE_NAMESPACE
23 QTCOMMERCIALCHART_USE_NAMESPACE
24
24
25 CustomSlice::CustomSlice(QString label, qreal value)
25 CustomSlice::CustomSlice(QString label, qreal value)
26 :QPieSlice(label, value)
26 : QPieSlice(label, value)
27 {
27 {
28 connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool)));
28 connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool)));
29 }
29 }
30
30
31 QBrush CustomSlice::originalBrush()
31 QBrush CustomSlice::originalBrush()
32 {
32 {
33 return m_originalBrush;
33 return m_originalBrush;
34 }
34 }
35
35
36 void CustomSlice::showHighlight(bool show)
36 void CustomSlice::showHighlight(bool show)
37 {
37 {
38 if (show) {
38 if (show) {
39 QBrush brush = this->brush();
39 QBrush brush = this->brush();
40 m_originalBrush = brush;
40 m_originalBrush = brush;
41 brush.setColor(brush.color().lighter());
41 brush.setColor(brush.color().lighter());
42 setBrush(brush);
42 setBrush(brush);
43 } else {
43 } else {
44 setBrush(m_originalBrush);
44 setBrush(m_originalBrush);
45 }
45 }
46 }
46 }
47
47
48 #include "moc_customslice.cpp"
48 #include "moc_customslice.cpp"
@@ -1,359 +1,359
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 #include "mainwidget.h"
20 #include "mainwidget.h"
21 #include "customslice.h"
21 #include "customslice.h"
22 #include "pentool.h"
22 #include "pentool.h"
23 #include "brushtool.h"
23 #include "brushtool.h"
24 #include <QPushButton>
24 #include <QPushButton>
25 #include <QComboBox>
25 #include <QComboBox>
26 #include <QCheckBox>
26 #include <QCheckBox>
27 #include <QLineEdit>
27 #include <QLineEdit>
28 #include <QGroupBox>
28 #include <QGroupBox>
29 #include <QDoubleSpinBox>
29 #include <QDoubleSpinBox>
30 #include <QFormLayout>
30 #include <QFormLayout>
31 #include <QFontDialog>
31 #include <QFontDialog>
32 #include <QChartView>
32 #include <QChartView>
33 #include <QPieSeries>
33 #include <QPieSeries>
34
34
35 QTCOMMERCIALCHART_USE_NAMESPACE
35 QTCOMMERCIALCHART_USE_NAMESPACE
36
36
37 MainWidget::MainWidget(QWidget* parent)
37 MainWidget::MainWidget(QWidget *parent)
38 :QWidget(parent),
38 : QWidget(parent),
39 m_slice(0)
39 m_slice(0)
40 {
40 {
41 // create chart
41 // create chart
42 QChart *chart = new QChart;
42 QChart *chart = new QChart;
43 chart->setTitle("Piechart customization");
43 chart->setTitle("Piechart customization");
44 chart->setAnimationOptions(QChart::AllAnimations);
44 chart->setAnimationOptions(QChart::AllAnimations);
45
45
46 // create series
46 // create series
47 m_series = new QPieSeries();
47 m_series = new QPieSeries();
48 *m_series << new CustomSlice("Slice 1", 10.0);
48 *m_series << new CustomSlice("Slice 1", 10.0);
49 *m_series << new CustomSlice("Slice 2", 20.0);
49 *m_series << new CustomSlice("Slice 2", 20.0);
50 *m_series << new CustomSlice("Slice 3", 30.0);
50 *m_series << new CustomSlice("Slice 3", 30.0);
51 *m_series << new CustomSlice("Slice 4", 40.0);
51 *m_series << new CustomSlice("Slice 4", 40.0);
52 *m_series << new CustomSlice("Slice 5", 50.0);
52 *m_series << new CustomSlice("Slice 5", 50.0);
53 m_series->setLabelsVisible();
53 m_series->setLabelsVisible();
54 chart->addSeries(m_series);
54 chart->addSeries(m_series);
55
55
56 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
56 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
57
57
58 // chart settings
58 // chart settings
59 m_themeComboBox = new QComboBox();
59 m_themeComboBox = new QComboBox();
60 m_themeComboBox->addItem("Light", QChart::ChartThemeLight);
60 m_themeComboBox->addItem("Light", QChart::ChartThemeLight);
61 m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean);
61 m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean);
62 m_themeComboBox->addItem("Dark", QChart::ChartThemeDark);
62 m_themeComboBox->addItem("Dark", QChart::ChartThemeDark);
63 m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand);
63 m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand);
64 m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs);
64 m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs);
65 m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
65 m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
66 m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
66 m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
67
67
68 m_aaCheckBox = new QCheckBox();
68 m_aaCheckBox = new QCheckBox();
69 m_animationsCheckBox = new QCheckBox();
69 m_animationsCheckBox = new QCheckBox();
70 m_animationsCheckBox->setCheckState(Qt::Checked);
70 m_animationsCheckBox->setCheckState(Qt::Checked);
71
71
72 m_legendCheckBox = new QCheckBox();
72 m_legendCheckBox = new QCheckBox();
73
73
74 QFormLayout* chartSettingsLayout = new QFormLayout();
74 QFormLayout *chartSettingsLayout = new QFormLayout();
75 chartSettingsLayout->addRow("Theme", m_themeComboBox);
75 chartSettingsLayout->addRow("Theme", m_themeComboBox);
76 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
76 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
77 chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
77 chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
78 chartSettingsLayout->addRow("Legend", m_legendCheckBox);
78 chartSettingsLayout->addRow("Legend", m_legendCheckBox);
79 QGroupBox* chartSettings = new QGroupBox("Chart");
79 QGroupBox *chartSettings = new QGroupBox("Chart");
80 chartSettings->setLayout(chartSettingsLayout);
80 chartSettings->setLayout(chartSettingsLayout);
81
81
82 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
82 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateChartSettings()));
83 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
83 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateChartSettings()));
84 connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
84 connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateChartSettings()));
85 connect(m_legendCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
85 connect(m_legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateChartSettings()));
86
86
87 // series settings
87 // series settings
88 m_hPosition = new QDoubleSpinBox();
88 m_hPosition = new QDoubleSpinBox();
89 m_hPosition->setMinimum(0.0);
89 m_hPosition->setMinimum(0.0);
90 m_hPosition->setMaximum(1.0);
90 m_hPosition->setMaximum(1.0);
91 m_hPosition->setSingleStep(0.1);
91 m_hPosition->setSingleStep(0.1);
92 m_hPosition->setValue(m_series->horizontalPosition());
92 m_hPosition->setValue(m_series->horizontalPosition());
93
93
94 m_vPosition = new QDoubleSpinBox();
94 m_vPosition = new QDoubleSpinBox();
95 m_vPosition->setMinimum(0.0);
95 m_vPosition->setMinimum(0.0);
96 m_vPosition->setMaximum(1.0);
96 m_vPosition->setMaximum(1.0);
97 m_vPosition->setSingleStep(0.1);
97 m_vPosition->setSingleStep(0.1);
98 m_vPosition->setValue(m_series->verticalPosition());
98 m_vPosition->setValue(m_series->verticalPosition());
99
99
100 m_sizeFactor = new QDoubleSpinBox();
100 m_sizeFactor = new QDoubleSpinBox();
101 m_sizeFactor->setMinimum(0.0);
101 m_sizeFactor->setMinimum(0.0);
102 m_sizeFactor->setMaximum(1.0);
102 m_sizeFactor->setMaximum(1.0);
103 m_sizeFactor->setSingleStep(0.1);
103 m_sizeFactor->setSingleStep(0.1);
104 m_sizeFactor->setValue(m_series->pieSize());
104 m_sizeFactor->setValue(m_series->pieSize());
105
105
106 m_startAngle = new QDoubleSpinBox();
106 m_startAngle = new QDoubleSpinBox();
107 m_startAngle->setMinimum(-720);
107 m_startAngle->setMinimum(-720);
108 m_startAngle->setMaximum(720);
108 m_startAngle->setMaximum(720);
109 m_startAngle->setValue(m_series->pieStartAngle());
109 m_startAngle->setValue(m_series->pieStartAngle());
110 m_startAngle->setSingleStep(1);
110 m_startAngle->setSingleStep(1);
111
111
112 m_endAngle = new QDoubleSpinBox();
112 m_endAngle = new QDoubleSpinBox();
113 m_endAngle->setMinimum(-720);
113 m_endAngle->setMinimum(-720);
114 m_endAngle->setMaximum(720);
114 m_endAngle->setMaximum(720);
115 m_endAngle->setValue(m_series->pieEndAngle());
115 m_endAngle->setValue(m_series->pieEndAngle());
116 m_endAngle->setSingleStep(1);
116 m_endAngle->setSingleStep(1);
117
117
118 m_holeSize = new QDoubleSpinBox();
118 m_holeSize = new QDoubleSpinBox();
119 m_holeSize->setMinimum(0.0);
119 m_holeSize->setMinimum(0.0);
120 m_holeSize->setMaximum(1.0);
120 m_holeSize->setMaximum(1.0);
121 m_holeSize->setSingleStep(0.1);
121 m_holeSize->setSingleStep(0.1);
122 m_holeSize->setValue(m_series->holeSize());
122 m_holeSize->setValue(m_series->holeSize());
123
123
124 QPushButton *appendSlice = new QPushButton("Append slice");
124 QPushButton *appendSlice = new QPushButton("Append slice");
125 QPushButton *insertSlice = new QPushButton("Insert slice");
125 QPushButton *insertSlice = new QPushButton("Insert slice");
126 QPushButton *removeSlice = new QPushButton("Remove selected slice");
126 QPushButton *removeSlice = new QPushButton("Remove selected slice");
127
127
128 QFormLayout* seriesSettingsLayout = new QFormLayout();
128 QFormLayout *seriesSettingsLayout = new QFormLayout();
129 seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
129 seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
130 seriesSettingsLayout->addRow("Vertical position", m_vPosition);
130 seriesSettingsLayout->addRow("Vertical position", m_vPosition);
131 seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
131 seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
132 seriesSettingsLayout->addRow("Start angle", m_startAngle);
132 seriesSettingsLayout->addRow("Start angle", m_startAngle);
133 seriesSettingsLayout->addRow("End angle", m_endAngle);
133 seriesSettingsLayout->addRow("End angle", m_endAngle);
134 seriesSettingsLayout->addRow("Hole size", m_holeSize);
134 seriesSettingsLayout->addRow("Hole size", m_holeSize);
135 seriesSettingsLayout->addRow(appendSlice);
135 seriesSettingsLayout->addRow(appendSlice);
136 seriesSettingsLayout->addRow(insertSlice);
136 seriesSettingsLayout->addRow(insertSlice);
137 seriesSettingsLayout->addRow(removeSlice);
137 seriesSettingsLayout->addRow(removeSlice);
138 QGroupBox* seriesSettings = new QGroupBox("Series");
138 QGroupBox *seriesSettings = new QGroupBox("Series");
139 seriesSettings->setLayout(seriesSettingsLayout);
139 seriesSettings->setLayout(seriesSettingsLayout);
140
140
141 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
141 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
142 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
142 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
143 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
143 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
144 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
144 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
145 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
145 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
146 connect(m_holeSize, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
146 connect(m_holeSize, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
147 connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice()));
147 connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice()));
148 connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice()));
148 connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice()));
149 connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice()));
149 connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice()));
150
150
151 // slice settings
151 // slice settings
152 m_sliceName = new QLineEdit("<click a slice>");
152 m_sliceName = new QLineEdit("<click a slice>");
153 m_sliceName->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
153 m_sliceName->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
154 m_sliceValue = new QDoubleSpinBox();
154 m_sliceValue = new QDoubleSpinBox();
155 m_sliceValue->setMaximum(1000);
155 m_sliceValue->setMaximum(1000);
156 m_sliceLabelVisible = new QCheckBox();
156 m_sliceLabelVisible = new QCheckBox();
157 m_sliceLabelArmFactor = new QDoubleSpinBox();
157 m_sliceLabelArmFactor = new QDoubleSpinBox();
158 m_sliceLabelArmFactor->setSingleStep(0.01);
158 m_sliceLabelArmFactor->setSingleStep(0.01);
159 m_sliceExploded = new QCheckBox();
159 m_sliceExploded = new QCheckBox();
160 m_sliceExplodedFactor = new QDoubleSpinBox();
160 m_sliceExplodedFactor = new QDoubleSpinBox();
161 m_sliceExplodedFactor->setSingleStep(0.01);
161 m_sliceExplodedFactor->setSingleStep(0.01);
162 m_pen = new QPushButton();
162 m_pen = new QPushButton();
163 m_penTool = new PenTool("Slice pen", this);
163 m_penTool = new PenTool("Slice pen", this);
164 m_brush = new QPushButton();
164 m_brush = new QPushButton();
165 m_brushTool = new BrushTool("Slice brush", this);
165 m_brushTool = new BrushTool("Slice brush", this);
166 m_font = new QPushButton();
166 m_font = new QPushButton();
167 m_labelBrush = new QPushButton();
167 m_labelBrush = new QPushButton();
168 m_labelBrushTool = new BrushTool("Label brush", this);
168 m_labelBrushTool = new BrushTool("Label brush", this);
169 m_labelPosition = new QComboBox(this);
169 m_labelPosition = new QComboBox(this);
170 m_labelPosition->addItem("Outside", QPieSlice::LabelOutside);
170 m_labelPosition->addItem("Outside", QPieSlice::LabelOutside);
171 m_labelPosition->addItem("Inside horizontal", QPieSlice::LabelInsideHorizontal);
171 m_labelPosition->addItem("Inside horizontal", QPieSlice::LabelInsideHorizontal);
172 m_labelPosition->addItem("Inside tangential", QPieSlice::LabelInsideTangential);
172 m_labelPosition->addItem("Inside tangential", QPieSlice::LabelInsideTangential);
173 m_labelPosition->addItem("Inside normal", QPieSlice::LabelInsideNormal);
173 m_labelPosition->addItem("Inside normal", QPieSlice::LabelInsideNormal);
174
174
175 QFormLayout* sliceSettingsLayout = new QFormLayout();
175 QFormLayout *sliceSettingsLayout = new QFormLayout();
176 sliceSettingsLayout->addRow("Label", m_sliceName);
176 sliceSettingsLayout->addRow("Label", m_sliceName);
177 sliceSettingsLayout->addRow("Value", m_sliceValue);
177 sliceSettingsLayout->addRow("Value", m_sliceValue);
178 sliceSettingsLayout->addRow("Pen", m_pen);
178 sliceSettingsLayout->addRow("Pen", m_pen);
179 sliceSettingsLayout->addRow("Brush", m_brush);
179 sliceSettingsLayout->addRow("Brush", m_brush);
180 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
180 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
181 sliceSettingsLayout->addRow("Label font", m_font);
181 sliceSettingsLayout->addRow("Label font", m_font);
182 sliceSettingsLayout->addRow("Label brush", m_labelBrush);
182 sliceSettingsLayout->addRow("Label brush", m_labelBrush);
183 sliceSettingsLayout->addRow("Label position", m_labelPosition);
183 sliceSettingsLayout->addRow("Label position", m_labelPosition);
184 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
184 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
185 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
185 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
186 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
186 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
187 QGroupBox* sliceSettings = new QGroupBox("Selected slice");
187 QGroupBox *sliceSettings = new QGroupBox("Selected slice");
188 sliceSettings->setLayout(sliceSettingsLayout);
188 sliceSettings->setLayout(sliceSettingsLayout);
189
189
190 connect(m_sliceName, SIGNAL(textChanged(QString)), this, SLOT(updateSliceSettings()));
190 connect(m_sliceName, SIGNAL(textChanged(QString)), this, SLOT(updateSliceSettings()));
191 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
191 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
192 connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show()));
192 connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show()));
193 connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
193 connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
194 connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
194 connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
195 connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
195 connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
196 connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
196 connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
197 connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show()));
197 connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show()));
198 connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
198 connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
199 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
199 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
200 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
200 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
201 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
201 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
202 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
202 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
203 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
203 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
204 connect(m_labelPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSliceSettings()));
204 connect(m_labelPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSliceSettings()));
205
205
206 // create chart view
206 // create chart view
207 m_chartView = new QChartView(chart);
207 m_chartView = new QChartView(chart);
208
208
209 // create main layout
209 // create main layout
210 QVBoxLayout *settingsLayout = new QVBoxLayout();
210 QVBoxLayout *settingsLayout = new QVBoxLayout();
211 settingsLayout->addWidget(chartSettings);
211 settingsLayout->addWidget(chartSettings);
212 settingsLayout->addWidget(seriesSettings);
212 settingsLayout->addWidget(seriesSettings);
213 settingsLayout->addWidget(sliceSettings);
213 settingsLayout->addWidget(sliceSettings);
214 settingsLayout->addStretch();
214 settingsLayout->addStretch();
215
215
216 QGridLayout* baseLayout = new QGridLayout();
216 QGridLayout *baseLayout = new QGridLayout();
217 baseLayout->addLayout(settingsLayout, 0, 0);
217 baseLayout->addLayout(settingsLayout, 0, 0);
218 baseLayout->addWidget(m_chartView, 0, 1);
218 baseLayout->addWidget(m_chartView, 0, 1);
219 setLayout(baseLayout);
219 setLayout(baseLayout);
220
220
221 updateSerieSettings();
221 updateSerieSettings();
222 updateChartSettings();
222 updateChartSettings();
223 }
223 }
224
224
225
225
226 void MainWidget::updateChartSettings()
226 void MainWidget::updateChartSettings()
227 {
227 {
228 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
228 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
229 m_chartView->chart()->setTheme(theme);
229 m_chartView->chart()->setTheme(theme);
230 m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked());
230 m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked());
231
231
232 if (m_animationsCheckBox->checkState() == Qt::Checked)
232 if (m_animationsCheckBox->checkState() == Qt::Checked)
233 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
233 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
234 else
234 else
235 m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
235 m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
236
236
237 if (m_legendCheckBox->checkState() == Qt::Checked)
237 if (m_legendCheckBox->checkState() == Qt::Checked)
238 m_chartView->chart()->legend()->show();
238 m_chartView->chart()->legend()->show();
239 else
239 else
240 m_chartView->chart()->legend()->hide();
240 m_chartView->chart()->legend()->hide();
241 }
241 }
242
242
243 void MainWidget::updateSerieSettings()
243 void MainWidget::updateSerieSettings()
244 {
244 {
245 m_series->setHorizontalPosition(m_hPosition->value());
245 m_series->setHorizontalPosition(m_hPosition->value());
246 m_series->setVerticalPosition(m_vPosition->value());
246 m_series->setVerticalPosition(m_vPosition->value());
247 m_series->setPieSize(m_sizeFactor->value());
247 m_series->setPieSize(m_sizeFactor->value());
248 m_holeSize->setMaximum(m_sizeFactor->value());
248 m_holeSize->setMaximum(m_sizeFactor->value());
249 m_series->setPieStartAngle(m_startAngle->value());
249 m_series->setPieStartAngle(m_startAngle->value());
250 m_series->setPieEndAngle(m_endAngle->value());
250 m_series->setPieEndAngle(m_endAngle->value());
251 m_series->setHoleSize(m_holeSize->value());
251 m_series->setHoleSize(m_holeSize->value());
252 }
252 }
253
253
254 void MainWidget::updateSliceSettings()
254 void MainWidget::updateSliceSettings()
255 {
255 {
256 if (!m_slice)
256 if (!m_slice)
257 return;
257 return;
258
258
259 m_slice->setLabel(m_sliceName->text());
259 m_slice->setLabel(m_sliceName->text());
260
260
261 m_slice->setValue(m_sliceValue->value());
261 m_slice->setValue(m_sliceValue->value());
262
262
263 m_slice->setPen(m_penTool->pen());
263 m_slice->setPen(m_penTool->pen());
264 m_slice->setBrush(m_brushTool->brush());
264 m_slice->setBrush(m_brushTool->brush());
265
265
266 m_slice->setLabelBrush(m_labelBrushTool->brush());
266 m_slice->setLabelBrush(m_labelBrushTool->brush());
267 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
267 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
268 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
268 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
269 m_slice->setLabelPosition((QPieSlice::LabelPosition)m_labelPosition->currentIndex()); // assumes that index is in sync with the enum
269 m_slice->setLabelPosition((QPieSlice::LabelPosition)m_labelPosition->currentIndex()); // assumes that index is in sync with the enum
270
270
271 m_slice->setExploded(m_sliceExploded->isChecked());
271 m_slice->setExploded(m_sliceExploded->isChecked());
272 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
272 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
273 }
273 }
274
274
275 void MainWidget::handleSliceClicked(QPieSlice* slice)
275 void MainWidget::handleSliceClicked(QPieSlice *slice)
276 {
276 {
277 m_slice = static_cast<CustomSlice*>(slice);
277 m_slice = static_cast<CustomSlice *>(slice);
278
278
279 // name
279 // name
280 m_sliceName->blockSignals(true);
280 m_sliceName->blockSignals(true);
281 m_sliceName->setText(slice->label());
281 m_sliceName->setText(slice->label());
282 m_sliceName->blockSignals(false);
282 m_sliceName->blockSignals(false);
283
283
284 // value
284 // value
285 m_sliceValue->blockSignals(true);
285 m_sliceValue->blockSignals(true);
286 m_sliceValue->setValue(slice->value());
286 m_sliceValue->setValue(slice->value());
287 m_sliceValue->blockSignals(false);
287 m_sliceValue->blockSignals(false);
288
288
289 // pen
289 // pen
290 m_pen->setText(PenTool::name(m_slice->pen()));
290 m_pen->setText(PenTool::name(m_slice->pen()));
291 m_penTool->setPen(m_slice->pen());
291 m_penTool->setPen(m_slice->pen());
292
292
293 // brush
293 // brush
294 m_brush->setText(m_slice->originalBrush().color().name());
294 m_brush->setText(m_slice->originalBrush().color().name());
295 m_brushTool->setBrush(m_slice->originalBrush());
295 m_brushTool->setBrush(m_slice->originalBrush());
296
296
297 // label
297 // label
298 m_labelBrush->setText(BrushTool::name(m_slice->labelBrush()));
298 m_labelBrush->setText(BrushTool::name(m_slice->labelBrush()));
299 m_labelBrushTool->setBrush(m_slice->labelBrush());
299 m_labelBrushTool->setBrush(m_slice->labelBrush());
300 m_font->setText(slice->labelFont().toString());
300 m_font->setText(slice->labelFont().toString());
301 m_sliceLabelVisible->blockSignals(true);
301 m_sliceLabelVisible->blockSignals(true);
302 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
302 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
303 m_sliceLabelVisible->blockSignals(false);
303 m_sliceLabelVisible->blockSignals(false);
304 m_sliceLabelArmFactor->blockSignals(true);
304 m_sliceLabelArmFactor->blockSignals(true);
305 m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
305 m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
306 m_sliceLabelArmFactor->blockSignals(false);
306 m_sliceLabelArmFactor->blockSignals(false);
307 m_labelPosition->blockSignals(true);
307 m_labelPosition->blockSignals(true);
308 m_labelPosition->setCurrentIndex(slice->labelPosition()); // assumes that index is in sync with the enum
308 m_labelPosition->setCurrentIndex(slice->labelPosition()); // assumes that index is in sync with the enum
309 m_labelPosition->blockSignals(false);
309 m_labelPosition->blockSignals(false);
310
310
311 // exploded
311 // exploded
312 m_sliceExploded->blockSignals(true);
312 m_sliceExploded->blockSignals(true);
313 m_sliceExploded->setChecked(slice->isExploded());
313 m_sliceExploded->setChecked(slice->isExploded());
314 m_sliceExploded->blockSignals(false);
314 m_sliceExploded->blockSignals(false);
315 m_sliceExplodedFactor->blockSignals(true);
315 m_sliceExplodedFactor->blockSignals(true);
316 m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
316 m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
317 m_sliceExplodedFactor->blockSignals(false);
317 m_sliceExplodedFactor->blockSignals(false);
318 }
318 }
319
319
320 void MainWidget::showFontDialog()
320 void MainWidget::showFontDialog()
321 {
321 {
322 if (!m_slice)
322 if (!m_slice)
323 return;
323 return;
324
324
325 QFontDialog dialog(m_slice->labelFont());
325 QFontDialog dialog(m_slice->labelFont());
326 dialog.show();
326 dialog.show();
327 dialog.exec();
327 dialog.exec();
328
328
329 m_slice->setLabelFont(dialog.currentFont());
329 m_slice->setLabelFont(dialog.currentFont());
330 m_font->setText(dialog.currentFont().toString());
330 m_font->setText(dialog.currentFont().toString());
331 }
331 }
332
332
333 void MainWidget::appendSlice()
333 void MainWidget::appendSlice()
334 {
334 {
335 *m_series << new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0);
335 *m_series << new CustomSlice("Slice " + QString::number(m_series->count() + 1), 10.0);
336 }
336 }
337
337
338 void MainWidget::insertSlice()
338 void MainWidget::insertSlice()
339 {
339 {
340 if (!m_slice)
340 if (!m_slice)
341 return;
341 return;
342
342
343 int i = m_series->slices().indexOf(m_slice);
343 int i = m_series->slices().indexOf(m_slice);
344
344
345 m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0));
345 m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count() + 1), 10.0));
346 }
346 }
347
347
348 void MainWidget::removeSlice()
348 void MainWidget::removeSlice()
349 {
349 {
350 if (!m_slice)
350 if (!m_slice)
351 return;
351 return;
352
352
353 m_sliceName->setText("<click a slice>");
353 m_sliceName->setText("<click a slice>");
354
354
355 m_series->remove(m_slice);
355 m_series->remove(m_slice);
356 m_slice = 0;
356 m_slice = 0;
357 }
357 }
358
358
359 #include "moc_mainwidget.cpp"
359 #include "moc_mainwidget.cpp"
@@ -1,93 +1,93
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 #ifndef MAINWIDGET_H
20 #ifndef MAINWIDGET_H
21 #define MAINWIDGET_H
21 #define MAINWIDGET_H
22
22
23 #include <QWidget>
23 #include <QWidget>
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25
25
26 class QLineEdit;
26 class QLineEdit;
27 class QPushButton;
27 class QPushButton;
28 class QCheckBox;
28 class QCheckBox;
29 class QComboBox;
29 class QComboBox;
30 class QDoubleSpinBox;
30 class QDoubleSpinBox;
31 class PenTool;
31 class PenTool;
32 class BrushTool;
32 class BrushTool;
33 class CustomSlice;
33 class CustomSlice;
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 class QChartView;
36 class QChartView;
37 class QPieSeries;
37 class QPieSeries;
38 class QPieSlice;
38 class QPieSlice;
39 QTCOMMERCIALCHART_END_NAMESPACE
39 QTCOMMERCIALCHART_END_NAMESPACE
40
40
41 QTCOMMERCIALCHART_USE_NAMESPACE
41 QTCOMMERCIALCHART_USE_NAMESPACE
42
42
43 class MainWidget : public QWidget
43 class MainWidget : public QWidget
44 {
44 {
45 Q_OBJECT
45 Q_OBJECT
46
46
47 public:
47 public:
48 explicit MainWidget(QWidget* parent = 0);
48 explicit MainWidget(QWidget *parent = 0);
49
49
50 public Q_SLOTS:
50 public Q_SLOTS:
51 void updateChartSettings();
51 void updateChartSettings();
52 void updateSerieSettings();
52 void updateSerieSettings();
53 void updateSliceSettings();
53 void updateSliceSettings();
54 void handleSliceClicked(QPieSlice* slice);
54 void handleSliceClicked(QPieSlice *slice);
55 void showFontDialog();
55 void showFontDialog();
56 void appendSlice();
56 void appendSlice();
57 void insertSlice();
57 void insertSlice();
58 void removeSlice();
58 void removeSlice();
59
59
60 private:
60 private:
61 QComboBox *m_themeComboBox;
61 QComboBox *m_themeComboBox;
62 QCheckBox *m_aaCheckBox;
62 QCheckBox *m_aaCheckBox;
63 QCheckBox *m_animationsCheckBox;
63 QCheckBox *m_animationsCheckBox;
64 QCheckBox *m_legendCheckBox;
64 QCheckBox *m_legendCheckBox;
65
65
66 QChartView* m_chartView;
66 QChartView *m_chartView;
67 QPieSeries* m_series;
67 QPieSeries *m_series;
68 CustomSlice* m_slice;
68 CustomSlice *m_slice;
69
69
70 QDoubleSpinBox* m_hPosition;
70 QDoubleSpinBox *m_hPosition;
71 QDoubleSpinBox* m_vPosition;
71 QDoubleSpinBox *m_vPosition;
72 QDoubleSpinBox* m_sizeFactor;
72 QDoubleSpinBox *m_sizeFactor;
73 QDoubleSpinBox* m_startAngle;
73 QDoubleSpinBox *m_startAngle;
74 QDoubleSpinBox* m_endAngle;
74 QDoubleSpinBox *m_endAngle;
75 QDoubleSpinBox* m_holeSize;
75 QDoubleSpinBox *m_holeSize;
76
76
77 QLineEdit* m_sliceName;
77 QLineEdit *m_sliceName;
78 QDoubleSpinBox* m_sliceValue;
78 QDoubleSpinBox *m_sliceValue;
79 QCheckBox* m_sliceLabelVisible;
79 QCheckBox *m_sliceLabelVisible;
80 QDoubleSpinBox* m_sliceLabelArmFactor;
80 QDoubleSpinBox *m_sliceLabelArmFactor;
81 QCheckBox* m_sliceExploded;
81 QCheckBox *m_sliceExploded;
82 QDoubleSpinBox* m_sliceExplodedFactor;
82 QDoubleSpinBox *m_sliceExplodedFactor;
83 QPushButton *m_brush;
83 QPushButton *m_brush;
84 BrushTool *m_brushTool;
84 BrushTool *m_brushTool;
85 QPushButton *m_pen;
85 QPushButton *m_pen;
86 PenTool *m_penTool;
86 PenTool *m_penTool;
87 QPushButton *m_font;
87 QPushButton *m_font;
88 QPushButton *m_labelBrush;
88 QPushButton *m_labelBrush;
89 QComboBox *m_labelPosition;
89 QComboBox *m_labelPosition;
90 BrushTool *m_labelBrushTool;
90 BrushTool *m_labelBrushTool;
91 };
91 };
92
92
93 #endif // MAINWIDGET_H
93 #endif // MAINWIDGET_H
@@ -1,141 +1,141
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 "pentool.h"
21 #include "pentool.h"
22 #include <QPushButton>
22 #include <QPushButton>
23 #include <QDoubleSpinBox>
23 #include <QDoubleSpinBox>
24 #include <QComboBox>
24 #include <QComboBox>
25 #include <QFormLayout>
25 #include <QFormLayout>
26 #include <QColorDialog>
26 #include <QColorDialog>
27
27
28 PenTool::PenTool(QString title, QWidget *parent)
28 PenTool::PenTool(QString title, QWidget *parent)
29 :QWidget(parent)
29 : QWidget(parent)
30 {
30 {
31 setWindowTitle(title);
31 setWindowTitle(title);
32 setWindowFlags(Qt::Tool);
32 setWindowFlags(Qt::Tool);
33
33
34 m_colorButton = new QPushButton();
34 m_colorButton = new QPushButton();
35
35
36 m_widthSpinBox = new QDoubleSpinBox();
36 m_widthSpinBox = new QDoubleSpinBox();
37
37
38 m_styleCombo = new QComboBox();
38 m_styleCombo = new QComboBox();
39 m_styleCombo->addItem("NoPen");
39 m_styleCombo->addItem("NoPen");
40 m_styleCombo->addItem("SolidLine");
40 m_styleCombo->addItem("SolidLine");
41 m_styleCombo->addItem("DashLine");
41 m_styleCombo->addItem("DashLine");
42 m_styleCombo->addItem("DotLine");
42 m_styleCombo->addItem("DotLine");
43 m_styleCombo->addItem("DashDotLine");
43 m_styleCombo->addItem("DashDotLine");
44 m_styleCombo->addItem("DashDotDotLine");
44 m_styleCombo->addItem("DashDotDotLine");
45
45
46 m_capStyleCombo = new QComboBox();
46 m_capStyleCombo = new QComboBox();
47 m_capStyleCombo->addItem("FlatCap", Qt::FlatCap);
47 m_capStyleCombo->addItem("FlatCap", Qt::FlatCap);
48 m_capStyleCombo->addItem("SquareCap", Qt::SquareCap);
48 m_capStyleCombo->addItem("SquareCap", Qt::SquareCap);
49 m_capStyleCombo->addItem("RoundCap", Qt::RoundCap);
49 m_capStyleCombo->addItem("RoundCap", Qt::RoundCap);
50
50
51 m_joinStyleCombo = new QComboBox();
51 m_joinStyleCombo = new QComboBox();
52 m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin);
52 m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin);
53 m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin);
53 m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin);
54 m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin);
54 m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin);
55 m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin);
55 m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin);
56
56
57 QFormLayout *layout = new QFormLayout();
57 QFormLayout *layout = new QFormLayout();
58 layout->addRow("Color", m_colorButton);
58 layout->addRow("Color", m_colorButton);
59 layout->addRow("Width", m_widthSpinBox);
59 layout->addRow("Width", m_widthSpinBox);
60 layout->addRow("Style", m_styleCombo);
60 layout->addRow("Style", m_styleCombo);
61 layout->addRow("Cap style", m_capStyleCombo);
61 layout->addRow("Cap style", m_capStyleCombo);
62 layout->addRow("Join style", m_joinStyleCombo);
62 layout->addRow("Join style", m_joinStyleCombo);
63 setLayout(layout);
63 setLayout(layout);
64
64
65 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
65 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
66 connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double)));
66 connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double)));
67 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int)));
67 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int)));
68 connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int)));
68 connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int)));
69 connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int)));
69 connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int)));
70 }
70 }
71
71
72 void PenTool::setPen(const QPen &pen)
72 void PenTool::setPen(const QPen &pen)
73 {
73 {
74 m_pen = pen;
74 m_pen = pen;
75 m_colorButton->setText(m_pen.color().name());
75 m_colorButton->setText(m_pen.color().name());
76 m_widthSpinBox->setValue(m_pen.widthF());
76 m_widthSpinBox->setValue(m_pen.widthF());
77 m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum
77 m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum
78 m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle()));
78 m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle()));
79 m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle()));
79 m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle()));
80 }
80 }
81
81
82 QPen PenTool::pen() const
82 QPen PenTool::pen() const
83 {
83 {
84 return m_pen;
84 return m_pen;
85 }
85 }
86
86
87 QString PenTool::name()
87 QString PenTool::name()
88 {
88 {
89 return name(m_pen);
89 return name(m_pen);
90 }
90 }
91
91
92 QString PenTool::name(const QPen &pen)
92 QString PenTool::name(const QPen &pen)
93 {
93 {
94 return pen.color().name() + ":" + QString::number(pen.widthF());
94 return pen.color().name() + ":" + QString::number(pen.widthF());
95 }
95 }
96
96
97 void PenTool::showColorDialog()
97 void PenTool::showColorDialog()
98 {
98 {
99 QColorDialog dialog(m_pen.color());
99 QColorDialog dialog(m_pen.color());
100 dialog.show();
100 dialog.show();
101 dialog.exec();
101 dialog.exec();
102 m_pen.setColor(dialog.selectedColor());
102 m_pen.setColor(dialog.selectedColor());
103 m_colorButton->setText(m_pen.color().name());
103 m_colorButton->setText(m_pen.color().name());
104 emit changed();
104 emit changed();
105 }
105 }
106
106
107 void PenTool::updateWidth(double width)
107 void PenTool::updateWidth(double width)
108 {
108 {
109 if (!qFuzzyIsNull(width - m_pen.widthF())) {
109 if (!qFuzzyIsNull(width - m_pen.widthF())) {
110 m_pen.setWidthF(width);
110 m_pen.setWidthF(width);
111 emit changed();
111 emit changed();
112 }
112 }
113 }
113 }
114
114
115 void PenTool::updateStyle(int style)
115 void PenTool::updateStyle(int style)
116 {
116 {
117 if (m_pen.style() != style) {
117 if (m_pen.style() != style) {
118 m_pen.setStyle((Qt::PenStyle) style);
118 m_pen.setStyle((Qt::PenStyle) style);
119 emit changed();
119 emit changed();
120 }
120 }
121 }
121 }
122
122
123 void PenTool::updateCapStyle(int index)
123 void PenTool::updateCapStyle(int index)
124 {
124 {
125 Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt();
125 Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt();
126 if (m_pen.capStyle() != capStyle) {
126 if (m_pen.capStyle() != capStyle) {
127 m_pen.setCapStyle(capStyle);
127 m_pen.setCapStyle(capStyle);
128 emit changed();
128 emit changed();
129 }
129 }
130 }
130 }
131
131
132 void PenTool::updateJoinStyle(int index)
132 void PenTool::updateJoinStyle(int index)
133 {
133 {
134 Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt();
134 Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt();
135 if (m_pen.joinStyle() != joinStyle) {
135 if (m_pen.joinStyle() != joinStyle) {
136 m_pen.setJoinStyle(joinStyle);
136 m_pen.setJoinStyle(joinStyle);
137 emit changed();
137 emit changed();
138 }
138 }
139 }
139 }
140
140
141 #include "moc_pentool.cpp"
141 #include "moc_pentool.cpp"
@@ -1,40 +1,40
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 <QApplication>
21 #include <QApplication>
22 #ifdef QT5_QUICK_1
22 #ifdef QT5_QUICK_1
23 #include <QtQuick1/QDeclarativeEngine>
23 #include <QtQuick1/QDeclarativeEngine>
24 #else
24 #else
25 #include <QtDeclarative/QDeclarativeEngine>
25 #include <QtDeclarative/QDeclarativeEngine>
26 #endif
26 #endif
27 #include "qmlapplicationviewer.h"
27 #include "qmlapplicationviewer.h"
28
28
29 Q_DECL_EXPORT int main(int argc, char *argv[])
29 Q_DECL_EXPORT int main(int argc, char *argv[])
30 {
30 {
31 QScopedPointer<QApplication> app(createApplication(argc, argv));
31 QScopedPointer<QApplication> app(createApplication(argc, argv));
32 QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
32 QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
33
33
34 //viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
34 //viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
35 viewer->setSource(QUrl("qrc:/qml/qmlcustomlegend/loader.qml"));
35 viewer->setSource(QUrl("qrc:/qml/qmlcustomlegend/loader.qml"));
36 viewer->setRenderHint(QPainter::Antialiasing, true);
36 viewer->setRenderHint(QPainter::Antialiasing, true);
37 viewer->showExpanded();
37 viewer->showExpanded();
38
38
39 return app->exec();
39 return app->exec();
40 }
40 }
1 NO CONTENT: modified file chmod 100755 => 100644
NO CONTENT: modified file chmod 100755 => 100644
1 NO CONTENT: modified file chmod 100755 => 100644
NO CONTENT: modified file chmod 100755 => 100644
@@ -1,136 +1,136
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 "customtablemodel.h"
21 #include "customtablemodel.h"
22 #include <QVector>
22 #include <QVector>
23 #include <QRect>
23 #include <QRect>
24 #include <QColor>
24 #include <QColor>
25 #include <QDebug>
25 #include <QDebug>
26
26
27 CustomTableModel::CustomTableModel(QObject *parent) :
27 CustomTableModel::CustomTableModel(QObject *parent) :
28 QAbstractTableModel(parent),
28 QAbstractTableModel(parent),
29 m_columnCount(0),
29 m_columnCount(0),
30 m_rowCount(0)
30 m_rowCount(0)
31 {
31 {
32 }
32 }
33
33
34 int CustomTableModel::rowCount(const QModelIndex & parent) const
34 int CustomTableModel::rowCount(const QModelIndex &parent) const
35 {
35 {
36 Q_UNUSED(parent)
36 Q_UNUSED(parent)
37 return m_data.count();
37 return m_data.count();
38 }
38 }
39
39
40 int CustomTableModel::columnCount(const QModelIndex & parent) const
40 int CustomTableModel::columnCount(const QModelIndex &parent) const
41 {
41 {
42 Q_UNUSED(parent)
42 Q_UNUSED(parent)
43 return m_columnCount;
43 return m_columnCount;
44 }
44 }
45
45
46 QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, int role) const
46 QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, int role) const
47 {
47 {
48 if (role != Qt::DisplayRole)
48 if (role != Qt::DisplayRole)
49 return QVariant();
49 return QVariant();
50
50
51 if (orientation == Qt::Vertical) {
51 if (orientation == Qt::Vertical) {
52 if (m_verticalHeaders.count() > section)
52 if (m_verticalHeaders.count() > section)
53 return m_verticalHeaders[section];
53 return m_verticalHeaders[section];
54 else
54 else
55 return QAbstractTableModel::headerData(section, orientation, role);
55 return QAbstractTableModel::headerData(section, orientation, role);
56 } else {
56 } else {
57 return QAbstractTableModel::headerData(section, orientation, role);
57 return QAbstractTableModel::headerData(section, orientation, role);
58 }
58 }
59 }
59 }
60
60
61 bool CustomTableModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
61 bool CustomTableModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
62 {
62 {
63 if (orientation == Qt::Vertical) {
63 if (orientation == Qt::Vertical) {
64 while (m_verticalHeaders.count() <= section)
64 while (m_verticalHeaders.count() <= section)
65 m_verticalHeaders.append(QVariant());
65 m_verticalHeaders.append(QVariant());
66 m_verticalHeaders.replace(section, value);
66 m_verticalHeaders.replace(section, value);
67 } else {
67 } else {
68 return QAbstractTableModel::setHeaderData(section, orientation, value, role);
68 return QAbstractTableModel::setHeaderData(section, orientation, value, role);
69 }
69 }
70 emit headerDataChanged(orientation, section, section);
70 emit headerDataChanged(orientation, section, section);
71 return true;
71 return true;
72 }
72 }
73
73
74 QVariant CustomTableModel::data(const QModelIndex &index, int role) const
74 QVariant CustomTableModel::data(const QModelIndex &index, int role) const
75 {
75 {
76 if (role == Qt::DisplayRole) {
76 if (role == Qt::DisplayRole) {
77 return m_data[index.row()]->at(index.column());
77 return m_data[index.row()]->at(index.column());
78 } else if (role == Qt::EditRole) {
78 } else if (role == Qt::EditRole) {
79 return m_data[index.row()]->at(index.column());
79 return m_data[index.row()]->at(index.column());
80 }
80 }
81 return QVariant();
81 return QVariant();
82 }
82 }
83
83
84 bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
84 bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
85 {
85 {
86 if (index.isValid() && role == Qt::EditRole) {
86 if (index.isValid() && role == Qt::EditRole) {
87 m_data[index.row()]->replace(index.column(), value);
87 m_data[index.row()]->replace(index.column(), value);
88 emit dataChanged(index, index);
88 emit dataChanged(index, index);
89 return true;
89 return true;
90 }
90 }
91 return false;
91 return false;
92 }
92 }
93
93
94 QVariant CustomTableModel::at(int row, int column)
94 QVariant CustomTableModel::at(int row, int column)
95 {
95 {
96 return data(index(row, column));
96 return data(index(row, column));
97 }
97 }
98
98
99 void CustomTableModel::insertColumn(int column, const QModelIndex &parent)
99 void CustomTableModel::insertColumn(int column, const QModelIndex &parent)
100 {
100 {
101 beginInsertColumns(parent, column, column);
101 beginInsertColumns(parent, column, column);
102 m_columnCount++;
102 m_columnCount++;
103 endInsertColumns();
103 endInsertColumns();
104 }
104 }
105
105
106 void CustomTableModel::insertRow(int row, const QModelIndex &parent)
106 void CustomTableModel::insertRow(int row, const QModelIndex &parent)
107 {
107 {
108 beginInsertRows(parent, row, row);
108 beginInsertRows(parent, row, row);
109 QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount);
109 QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount);
110 m_data.insert(row, dataVec);
110 m_data.insert(row, dataVec);
111 endInsertRows();
111 endInsertRows();
112 }
112 }
113
113
114 bool CustomTableModel::removeRow(int row, const QModelIndex &parent)
114 bool CustomTableModel::removeRow(int row, const QModelIndex &parent)
115 {
115 {
116 return QAbstractTableModel::removeRow(row, parent);
116 return QAbstractTableModel::removeRow(row, parent);
117 }
117 }
118
118
119 bool CustomTableModel::removeRows(int row, int count, const QModelIndex &parent)
119 bool CustomTableModel::removeRows(int row, int count, const QModelIndex &parent)
120 {
120 {
121 beginRemoveRows(parent, row, row + count - 1);
121 beginRemoveRows(parent, row, row + count - 1);
122 bool removed(false);
122 bool removed(false);
123 for (int i(row); i < (row + count); i++) {
123 for (int i(row); i < (row + count); i++) {
124 m_data.removeAt(i);
124 m_data.removeAt(i);
125 removed = true;
125 removed = true;
126 }
126 }
127 endRemoveRows();
127 endRemoveRows();
128 return removed;
128 return removed;
129 }
129 }
130
130
131 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
131 Qt::ItemFlags CustomTableModel::flags(const QModelIndex &index) const
132 {
132 {
133 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
133 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
134 }
134 }
135
135
136 #include "moc_customtablemodel.cpp"
136 #include "moc_customtablemodel.cpp"
@@ -1,56 +1,56
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 CUSTOMTABLEMODEL_H
21 #ifndef CUSTOMTABLEMODEL_H
22 #define CUSTOMTABLEMODEL_H
22 #define CUSTOMTABLEMODEL_H
23
23
24 #include <QAbstractTableModel>
24 #include <QAbstractTableModel>
25 #include <QHash>
25 #include <QHash>
26
26
27 class CustomTableModel : public QAbstractTableModel
27 class CustomTableModel : public QAbstractTableModel
28 {
28 {
29 Q_OBJECT
29 Q_OBJECT
30 Q_PROPERTY(int rowCount READ rowCount)
30 Q_PROPERTY(int rowCount READ rowCount)
31 Q_PROPERTY(int columnCount READ columnCount)
31 Q_PROPERTY(int columnCount READ columnCount)
32
32
33 public:
33 public:
34 explicit CustomTableModel(QObject *parent = 0);
34 explicit CustomTableModel(QObject *parent = 0);
35
35
36 int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
36 int rowCount(const QModelIndex &parent = QModelIndex()) const;
37 int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
37 int columnCount(const QModelIndex &parent = QModelIndex()) const;
38 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
38 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
39 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
39 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
40 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
40 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
41 bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
41 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
42 Qt::ItemFlags flags ( const QModelIndex & index ) const;
42 Qt::ItemFlags flags(const QModelIndex &index) const;
43 void insertColumn(int column, const QModelIndex &parent = QModelIndex());
43 void insertColumn(int column, const QModelIndex &parent = QModelIndex());
44 void insertRow(int row, const QModelIndex &parent = QModelIndex());
44 void insertRow(int row, const QModelIndex &parent = QModelIndex());
45 Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
45 Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
46 Q_INVOKABLE bool removeRow (int row, const QModelIndex &parent = QModelIndex());
46 Q_INVOKABLE bool removeRow(int row, const QModelIndex &parent = QModelIndex());
47 Q_INVOKABLE QVariant at(int row, int column);
47 Q_INVOKABLE QVariant at(int row, int column);
48
48
49 private:
49 private:
50 QList<QVector<QVariant> * > m_data;
50 QList<QVector<QVariant> * > m_data;
51 QList<QVariant> m_verticalHeaders;
51 QList<QVariant> m_verticalHeaders;
52 int m_columnCount;
52 int m_columnCount;
53 int m_rowCount;
53 int m_rowCount;
54 };
54 };
55
55
56 #endif // CUSTOMTABLEMODEL_H
56 #endif // CUSTOMTABLEMODEL_H
@@ -1,51 +1,51
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 DATASOURCE_H
21 #ifndef DATASOURCE_H
22 #define DATASOURCE_H
22 #define DATASOURCE_H
23
23
24 #include <QObject>
24 #include <QObject>
25 #include <QAbstractSeries>
25 #include <QAbstractSeries>
26
26
27 class QDeclarativeView;
27 class QDeclarativeView;
28
28
29 QTCOMMERCIALCHART_USE_NAMESPACE
29 QTCOMMERCIALCHART_USE_NAMESPACE
30
30
31 class DataSource : public QObject
31 class DataSource : public QObject
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 public:
34 public:
35 explicit DataSource(QDeclarativeView *appViewer, QObject *parent = 0);
35 explicit DataSource(QDeclarativeView *appViewer, QObject *parent = 0);
36
36
37 signals:
37 signals:
38
38
39 public slots:
39 public slots:
40 void generateData(int type, int rowCount, int colCount);
40 void generateData(int type, int rowCount, int colCount);
41 void update(QAbstractSeries *series);
41 void update(QAbstractSeries *series);
42 void setOpenGL(bool enabled);
42 void setOpenGL(bool enabled);
43 void setAntialiasing(bool enabled);
43 void setAntialiasing(bool enabled);
44
44
45 private:
45 private:
46 QDeclarativeView *m_appViewer;
46 QDeclarativeView *m_appViewer;
47 QList<QList<QPointF> > m_data;
47 QList<QList<QPointF> > m_data;
48 int m_index;
48 int m_index;
49 };
49 };
50
50
51 #endif // DATASOURCE_H
51 #endif // DATASOURCE_H
General Comments 0
You need to be logged in to leave comments. Login now