##// END OF EJS Templates
Fix previous broken commit
Michal Klocek -
r145:251cad7c49ee
parent child
Show More
@@ -1,51 +1,51
1 1 #include <QApplication>
2 2 #include <QMainWindow>
3 3 #include <qchartview.h>
4 #include <qxychartseries.h>
4 #include <qlinechartseries.h>
5 5 #include <qchart.h>
6 6 #include <cmath>
7 7
8 8 QTCOMMERCIALCHART_USE_NAMESPACE
9 9
10 10 #define PI 3.14159265358979
11 11
12 12 int main(int argc, char *argv[])
13 13 {
14 14 QApplication a(argc, argv);
15 15
16 16 QMainWindow window;
17 17
18 QXYChartSeries* series0 = QXYChartSeries::create();
18 QLineChartSeries* series0 = QLineChartSeries::create();
19 19 QPen blue(Qt::blue);
20 20 blue.setWidth(3);
21 21 series0->setPen(blue);
22 QXYChartSeries* series1 = QXYChartSeries::create();
22 QLineChartSeries* series1 = QLineChartSeries::create();
23 23 QPen red(Qt::red);
24 24 red.setWidth(3);
25 25 series1->setPen(red);
26 26
27 27 int numPoints = 100;
28 28
29 29 for (int x = 0; x <= numPoints; ++x) {
30 30 series0->add(x, fabs(sin(PI/50*x)*100));
31 31 series1->add(x, fabs(cos(PI/50*x)*100));
32 32 }
33 33
34 34 QChartView* chartView = new QChartView(&window);
35 35 chartView->setRenderHint(QPainter::Antialiasing);
36 36 chartView->setTitle("Custom color line chart example");
37 37 chartView->addSeries(series0);
38 38 chartView->addSeries(series1);
39 39
40 40 QLinearGradient backgroundGradient;
41 41 backgroundGradient.setColorAt(0.0, Qt::blue);
42 42 backgroundGradient.setColorAt(1.0, Qt::yellow);
43 43 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
44 44 chartView->setChartBackgroundBrush(backgroundGradient);
45 45
46 46 window.setCentralWidget(chartView);
47 47 window.resize(400, 300);
48 48 window.show();
49 49
50 50 return a.exec();
51 51 }
@@ -1,16 +1,16
1 1 !include( ../../common.pri ) {
2 2 error( "Couldn't find the common.pri file!" )
3 3 }
4 4
5 5 !include( ../../integrated.pri ) {
6 6 error( "Couldn't find the integrated.pri file !")
7 7 }
8 8
9 9 TARGET = dynamicLineChart
10 10 TEMPLATE = app
11 QT += core gui
11 QT += core gui opengl
12 12 SOURCES += main.cpp
13 13 HEADERS += wavegenerator.h
14 14
15 15
16 16
@@ -1,38 +1,40
1 1 #include <QApplication>
2 2 #include <QMainWindow>
3 3 #include <qchartview.h>
4 #include <qxychartseries.h>
4 #include <qlinechartseries.h>
5 5 #include <qchart.h>
6 6 #include <cmath>
7 7 #include "wavegenerator.h"
8 #include <QGLWidget>
8 9
9 10 int main(int argc, char *argv[])
10 11 {
11 12 QApplication a(argc, argv);
12 13
13 14 QMainWindow window;
14 15
15 QXYChartSeries* series0 = QXYChartSeries::create();
16 QLineChartSeries* series0 = QLineChartSeries::create();
16 17 QPen blue(Qt::blue);
17 18 blue.setWidth(3);
18 19 series0->setPen(blue);
19 QXYChartSeries* series1 = QXYChartSeries::create();
20 QLineChartSeries* series1 = QLineChartSeries::create();
20 21 QPen red(Qt::red);
21 22 red.setWidth(3);
22 23 series1->setPen(red);
23 24
24 25 WaveGenerator generator(series0,series1);
25 26
26 27 QChartView* chartView = new QChartView(&window);
27 28
29 chartView->setViewport( new QGLWidget() );
28 30 chartView->setRenderHint(QPainter::Antialiasing);
29 31 chartView->setTitle("This is wave generator buahha.");
30 32 chartView->addSeries(series0);
31 33 chartView->addSeries(series1);
32 34
33 35 window.setCentralWidget(chartView);
34 36 window.resize(400, 300);
35 37 window.show();
36 38
37 39 return a.exec();
38 40 }
@@ -1,60 +1,60
1 1 #include <QTimer>
2 2 #include <QTime>
3 3 #include <QObject>
4 4 #include <cmath>
5 #include <qxychartseries.h>
5 #include <qlinechartseries.h>
6 6
7 7 QTCOMMERCIALCHART_USE_NAMESPACE
8 8
9 9 #define PI 3.14159265358979
10 10 static const int numPoints =100;
11 11
12 12 class WaveGenerator: public QObject
13 13 {
14 14 Q_OBJECT
15 15
16 16 public:
17 WaveGenerator(QXYChartSeries* series1, QXYChartSeries* series2) :
17 WaveGenerator(QLineChartSeries* series1, QLineChartSeries* series2) :
18 18 m_series1(series1),
19 19 m_series2(series2),
20 20 m_wave(0),
21 21 m_step(2*PI/numPoints)
22 22 {
23 23
24 24 QTime now = QTime::currentTime();
25 25 qsrand((uint)now.msec());
26 26
27 27 int fluctuate = 100;
28 28
29 29 for (qreal x = 0; x <= 2*PI; x+=m_step) {
30 30 series1->add(x, fabs(sin(x)*fluctuate));
31 31 series2->add(x, fabs(cos(x)*fluctuate));
32 32 }
33 33
34 34 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(update()));
35 35 m_timer.setInterval(5000);
36 36 m_timer.start();
37 37
38 38 };
39 39
40 40 public slots:
41 41 void update()
42 42 {
43 43 int fluctuate;
44 44
45 45 for (qreal i = 0, x = 0; x <= 2*PI; x+=m_step, i++) {
46 46 fluctuate = qrand() % 100;
47 47 m_series1->set(i, x, fabs(sin(x)*fluctuate));
48 48 fluctuate = qrand() % 100;
49 49 m_series2->set(i, x, fabs(cos(x)*fluctuate));
50 50 }
51 51
52 52 }
53 53
54 54 private:
55 QXYChartSeries* m_series1;
56 QXYChartSeries* m_series2;
55 QLineChartSeries* m_series1;
56 QLineChartSeries* m_series2;
57 57 int m_wave;
58 58 qreal m_step;
59 59 QTimer m_timer;
60 60 };
@@ -1,46 +1,46
1 1 #include <QApplication>
2 2 #include <QMainWindow>
3 3 #include <qchartview.h>
4 #include <qxychartseries.h>
4 #include <qlinechartseries.h>
5 5 #include <qchart.h>
6 6 #include <cmath>
7 7
8 8 QTCOMMERCIALCHART_USE_NAMESPACE
9 9
10 10 #define PI 3.14159265358979
11 11
12 12 int main(int argc, char *argv[])
13 13 {
14 14 QApplication a(argc, argv);
15 15
16 16 QMainWindow window;
17 17
18 QXYChartSeries* series0 = QXYChartSeries::create();
18 QLineChartSeries* series0 = QLineChartSeries::create();
19 19 QPen blue(Qt::blue);
20 20 blue.setWidth(3);
21 21 series0->setPen(blue);
22 QXYChartSeries* series1 = QXYChartSeries::create();
22 QLineChartSeries* series1 = QLineChartSeries::create();
23 23 QPen red(Qt::red);
24 24 red.setWidth(3);
25 25 series1->setPen(red);
26 26
27 27 int numPoints = 100;
28 28
29 29 for (int x = 0; x <= numPoints; ++x) {
30 30 series0->add(x, fabs(sin(PI/50*x)*100));
31 31 series1->add(x, fabs(cos(PI/50*x)*100));
32 32 }
33 33
34 34 QChartView* chartView = new QChartView(&window);
35 35
36 36 chartView->setRenderHint(QPainter::Antialiasing);
37 37 chartView->setTitle("Basic line chart example");
38 38 chartView->addSeries(series0);
39 39 chartView->addSeries(series1);
40 40
41 41 window.setCentralWidget(chartView);
42 42 window.resize(400, 300);
43 43 window.show();
44 44
45 45 return a.exec();
46 46 }
@@ -1,44 +1,44
1 1 #include "chartwidget.h"
2 2 #include <QApplication>
3 3 #include <QMainWindow>
4 #include <qxychartseries.h>
4 #include <qlinechartseries.h>
5 5 #include <cmath>
6 6
7 7 QTCOMMERCIALCHART_USE_NAMESPACE
8 8
9 9 #define PI 3.14159265358979
10 10
11 11 int main(int argc, char *argv[])
12 12 {
13 13 QApplication a(argc, argv);
14 14
15 15 QMainWindow window;
16 16
17 QXYChartSeries* series0 = QXYChartSeries::create();
17 QLineChartSeries* series0 = QLineChartSeries::create();
18 18 QPen blue(Qt::blue);
19 19 blue.setWidth(3);
20 20 series0->setPen(blue);
21 QXYChartSeries* series1 = QXYChartSeries::create();
21 QLineChartSeries* series1 = QLineChartSeries::create();
22 22 QPen red(Qt::red);
23 23 red.setWidth(3);
24 24 series1->setPen(red);
25 25
26 26 int numPoints = 100;
27 27
28 28 for (int x = 0; x <= numPoints; ++x) {
29 29 series0->add(x, fabs(sin(PI/50*x)*100));
30 30 series1->add(x, fabs(cos(PI/50*x)*100));
31 31 }
32 32
33 33 ChartWidget* chartWidget = new ChartWidget(&window);
34 34 chartWidget->setRenderHint(QPainter::Antialiasing);
35 35 chartWidget->setTitle("Zoom in/out line chart example");
36 36 chartWidget->addSeries(series0);
37 37 chartWidget->addSeries(series1);
38 38
39 39 window.setCentralWidget(chartWidget);
40 40 window.resize(400, 300);
41 41 window.show();
42 42
43 43 return a.exec();
44 44 }
@@ -1,96 +1,96
1 1 #include "declarativeseries.h"
2 2 #include "declarativechart.h"
3 #include <qxychartseries.h>
3 #include <qlinechartseries.h>
4 4 #include <cmath>
5 5 #include <QDebug>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 DeclarativeSeries::DeclarativeSeries(QDeclarativeItem *parent) :
10 10 QDeclarativeItem(parent),
11 11 m_seriesType(SeriesTypeInvalid), // TODO: default type?
12 12 m_chart(0),
13 13 m_series(0)
14 14 {
15 15 setFlag(QGraphicsItem::ItemHasNoContents, false);
16 16 connect(this, SIGNAL(parentChanged()),
17 17 this, SLOT(setParentForSeries()));
18 18 }
19 19
20 20 void DeclarativeSeries::setSeriesType(SeriesType type)
21 21 {
22 22 if (!m_series || type != m_seriesType) {
23 23 m_seriesType = type;
24 24 initSeries();
25 25 }
26 26 }
27 27
28 28 void DeclarativeSeries::setParentForSeries()
29 29 {
30 30 initSeries();
31 31 }
32 32
33 33 void DeclarativeSeries::initSeries()
34 34 {
35 35 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
36 36
37 37 if (declarativeChart && m_seriesType != SeriesTypeInvalid) {
38 38 delete m_series;
39 39 m_series = 0;
40 40
41 41 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
42 42 qDebug() << "creating series for chart: " << chart;
43 43 Q_ASSERT(chart);
44 44
45 45 switch (m_seriesType) {
46 46 case SeriesTypeLine: {
47 m_series = QXYChartSeries::create(this);
47 m_series = QLineChartSeries::create(this);
48 48 for (qreal i(0.0); i < 100.0; i += 1.0)
49 ((QXYChartSeries *)m_series)->add(i, i);
49 ((QLineChartSeries *)m_series)->add(i, i);
50 50 chart->addSeries(m_series);
51 51 break;
52 52 }
53 53 case SeriesTypeBar:
54 54 // fallthrough; bar and scatter use the same test data
55 55 case SeriesTypeScatter: {
56 56 m_series = chart->createSeries((QChartSeries::QChartSeriesType) m_seriesType);
57 57 QList<qreal> datax;
58 58 QList<qreal> datay;
59 59 for (qreal i = 0; i < 100; i += 0.1) {
60 60 datax.append(i + (rand() % 5));
61 61 datay.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
62 62 }
63 63 Q_ASSERT(m_series->setData(datax, datay));
64 64 break;
65 65 }
66 66 case SeriesTypeStackedBar:
67 67 break;
68 68 case SeriesTypePercentBar:
69 69 break;
70 70 case SeriesTypePie: {
71 71 m_series = chart->createSeries((QChartSeries::QChartSeriesType) m_seriesType);
72 72 QList<qreal> data;
73 73 data << 1.0;
74 74 data << 12.0;
75 75 data << 4.0;
76 76 Q_ASSERT(m_series->setData(data));
77 77 break;
78 78 }
79 79 default:
80 80 break;
81 81 }
82 82 }
83 83 }
84 84
85 85 QVariant DeclarativeSeries::itemChange(GraphicsItemChange change,
86 86 const QVariant &value)
87 87 {
88 88 // For debugging purposes only:
89 89 // qDebug() << QString::number(change) << " : " << value.toString();
90 90 return QGraphicsItem::itemChange(change, value);
91 91 }
92 92
93 93
94 94 #include "moc_declarativeseries.cpp"
95 95
96 96 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,184 +1,176
1 1 #include "axisitem_p.h"
2 2 #include "qchartaxis.h"
3 3 #include <QPainter>
4 4 #include <QDebug>
5 5
6 6 #define LABEL_PADDING 5
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 AxisItem::AxisItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) :
11 11 ChartItem(parent),
12 12 m_axis(axis),
13 13 m_ticks(4),
14 14 m_type(type)
15 15 {
16 //initial initialization
17 handleAxisChanged();
16 18 }
17 19
18 20 AxisItem::~AxisItem()
19 21 {
20 22 }
21 23
22 void AxisItem::setLength(int length)
23 {
24 QPainterPath path;
25 path.moveTo(QPointF(0,0));
26 path.lineTo(length,0);
27 // path.lineTo(length-4,0);
28 // path.lineTo(length,3);
29 // path.lineTo(length-4,6);
30 // path.lineTo(length-4,4);
31 // path.lineTo(0,4);
32 // path.lineTo(0,2);
33 m_path=path;
34 update();
35 }
36
37 24 QRectF AxisItem::boundingRect() const
38 25 {
39 26 return m_rect;
40 27 }
41 28
42 29
43 30 /*
44 31 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
45 32 {
46 33 if (!m_rect.isValid())
47 34 return;
48 35
49 36 if(m_type==X_AXIS) {
50 37
51 38 const qreal deltaX = m_rect.width() / m_ticks;
52 39
53 40 for (int i = 0; i <= m_ticks; ++i) {
54 41
55 42 int x = i * deltaX + m_rect.left();
56 43
57 44 if(i==0) x--;
58 45 if(i==m_ticks) x++;
59 46
60 47 qreal label = m_plotDomain.m_minX + (i * m_plotDomain.spanX()
61 48 / m_ticks);
62 49 painter->drawLine(x, m_rect.top()-1, x, m_rect.bottom()+1);
63 50 // painter->drawLine(x, m_rect.bottom()-1, x, m_rect.bottom()-1 + 5);
64 51
65 52 painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20,Qt::AlignHCenter | Qt::AlignTop, QString::number(label));
66 53 }
67 54 }
68 55
69 56 if(m_type==Y_AXIS) {
70 57
71 58 const qreal deltaY = (m_rect.height()) / m_ticks;
72 59
73 60 for (int j = 0; j <= m_ticks; ++j) {
74 61
75 62 int y = j * -deltaY + m_rect.bottom();
76 63
77 64 if(j==0) y++;
78 65 if(j==m_ticks) y--;
79 66
80 67 qreal label = m_plotDomain.m_minY + (j * m_plotDomain.spanY()
81 68 / m_ticks);
82 69
83 70 painter->drawLine(m_rect.left()-1, y, m_rect.right()+1, y);
84 71 //painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y);
85 72 //TODO : margin = 50 ;
86 73 painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20,
87 74 Qt::AlignRight | Qt::AlignVCenter,
88 75 QString::number(label));
89 76 }
90 77 }
91 78
92 79 //painter->drawRect(m_rect.adjusted(0, 0, -1, -1));
93 80 }
94 81 */
95 82 void AxisItem::createItems()
96 83 {
97 84
98 85 if(!m_rect.isValid()) return;
99 86
100 if(m_type==X_AXIS) {
101
102 const qreal deltaX = m_rect.width() / m_ticks;
103
104 for (int i = 0; i <= m_ticks; ++i) {
87 switch (m_type)
88 {
89 case X_AXIS:
90 {
91 const qreal deltaX = m_rect.width() / m_ticks;
105 92
106 int x = i * deltaX + m_rect.left();
93 for (int i = 0; i <= m_ticks; ++i) {
107 94
108 qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks);
95 int x = i * deltaX + m_rect.left();
109 96
110 m_grid<<new QGraphicsLineItem(x, m_rect.top(), x, m_rect.bottom(),this);
97 qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks);
111 98
112 QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this);
113 QPointF center = text->boundingRect().center();
114 text->setPos(x - center.x(), m_rect.bottom() + LABEL_PADDING);
115 //text->rotate(-45);
116 m_labels<<text;
117 }
118 }
99 m_grid<<new QGraphicsLineItem(x, m_rect.top(), x, m_rect.bottom(),this);
119 100
120 if(m_type==Y_AXIS) {
121
122 const qreal deltaY = m_rect.height()/ m_ticks;
101 QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this);
102 QPointF center = text->boundingRect().center();
103 text->setPos(x - center.x(), m_rect.bottom() + LABEL_PADDING);
104 //text->rotate(-45);
105 m_labels<<text;
106 }
107 }
108 break;
123 109
124 for (int j = 0; j <= m_ticks; ++j) {
110 case Y_AXIS:
111 {
112 const qreal deltaY = m_rect.height()/ m_ticks;
125 113
126 int y = j * -deltaY + m_rect.bottom();
114 for (int j = 0; j <= m_ticks; ++j) {
127 115
128 qreal label = m_domain.m_minY + (j * m_domain.spanY()
129 / m_ticks);
116 int y = j * -deltaY + m_rect.bottom();
130 117
131 m_grid<<new QGraphicsLineItem(m_rect.left() , y, m_rect.right(), y,this);
132 QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this);
133 QPointF center = text->boundingRect().center();
118 qreal label = m_domain.m_minY + (j * m_domain.spanY()
119 / m_ticks);
134 120
135 text->setPos(m_rect.left() - text->boundingRect().width() - LABEL_PADDING , y-center.y());
136 //text->rotate(-45);
137 m_labels<<text;
121 m_grid<<new QGraphicsLineItem(m_rect.left() , y, m_rect.right(), y,this);
122 QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this);
123 QPointF center = text->boundingRect().center();
124 text->setPos(m_rect.left() - text->boundingRect().width() - LABEL_PADDING , y-center.y());
138 125
139 }
140 }
126 m_labels<<text;
141 127
142 //painter->drawRect(m_rect.adjusted(0, 0, -1, -1));
128 }
129 }
130 break;
131 default:
132 qDebug()<<"Unknown axis type";
133 break;
134 }
143 135 }
144 136
145 137 void AxisItem::clear()
146 138 {
147 139 qDeleteAll(m_shades);
148 140 m_shades.clear();
149 141 qDeleteAll(m_grid);
150 142 m_grid.clear();
151 143 qDeleteAll(m_labels);
152 144 m_labels.clear();
153 145 }
154 146
155 147 void AxisItem::updateDomain()
156 148 {
157 149 clear();
158 150 createItems();
159 151 }
160 152
161 153 void AxisItem::handleAxisChanged()
162 154 {
163 155 //m_axis->
164 156 }
165 157
166 158 void AxisItem::handleDomainChanged(const Domain& domain)
167 159 {
168 160 m_domain = domain;
169 161 clear();
170 162 createItems();
171 163 }
172 164
173 165 void AxisItem::handleGeometryChanged(const QRectF& rect)
174 166 {
175 167 Q_ASSERT(rect.isValid());
176 168 m_rect = rect;
177 169 clear();
178 170 createItems();
179 171 }
180 172
181 173 //TODO "nice numbers algorithm"
182 174 #include "moc_axisitem_p.cpp"
183 175
184 176 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,68 +1,63
1 1 #ifndef AXISITEM_H_
2 2 #define AXISITEM_H_
3 3
4 4 #include "domain_p.h"
5 5 #include "chartitem_p.h"
6 6 #include <QGraphicsItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QChartAxis;
11 11
12 12 class AxisItem : public QObject, public ChartItem
13 13 {
14 14 Q_OBJECT
15 15 public:
16 16 enum AxisType{X_AXIS,Y_AXIS};
17 17
18 18 AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0);
19 19 ~AxisItem();
20 20
21 21 //from QGraphicsItem
22 22 QRectF boundingRect() const;
23 23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
24 24
25 25 protected slots:
26 26 void handleAxisChanged();
27 27 void handleDomainChanged(const Domain& domain);
28 28 void handleGeometryChanged(const QRectF& size);
29 29
30 30 protected:
31 31 void updateDomain();
32 32
33 33 private:
34 34 void clear();
35 35
36 36 public:
37 void setLength(int length);
38 void setWidth(int width);
39 37 AxisType axisType() const {return m_type;};
40 38
41 39 protected:
42 40
43 41
44 42 private:
45 43 void createItems();
46 44 private:
47 45
48 46 QChartAxis* m_axis;
49 47 AxisType m_type;
50 48 int m_ticks;
51 49 Domain m_domain;
52
53
54
55 50 QRectF m_rect;
56 51
57 52 QPainterPath m_path;
58 53
59 54
60 55 QList<QGraphicsLineItem*> m_grid;
61 56 QList<QGraphicsRectItem*> m_shades;
62 57 QList<QGraphicsSimpleTextItem*> m_labels;
63 58
64 59 };
65 60
66 61 QTCOMMERCIALCHART_END_NAMESPACE
67 62
68 63 #endif /* AXISITEM_H_ */
@@ -1,148 +1,148
1 1 #include "chartdataset_p.h"
2 2 //series
3 #include "qxychartseries.h"
3 #include "qlinechartseries.h"
4 4 #include "barchartseries.h"
5 5 #include "stackedbarchartseries.h"
6 6 #include "percentbarchartseries.h"
7 7 #include "piechart/qpieseries.h"
8 8 #include "piechart/piepresentation.h"
9 9
10 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 11
12 12 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent)
13 13 {
14 14 Domain domain;
15 15 m_domains<<domain;
16 16 }
17 17
18 18 ChartDataSet::~ChartDataSet()
19 19 {
20 20 // TODO Auto-generated destructor stub
21 21 }
22 22
23 23 const Domain& ChartDataSet::domain() const
24 24 {
25 25 return m_domains[m_domainIndex];
26 26 }
27 27
28 28 void ChartDataSet::addSeries(QChartSeries* series)
29 29 {
30 30 // TODO: we should check the series not already added
31 31 m_chartSeries << series;
32 32 m_domainIndex = 0;
33 33 m_domains.resize(1);
34 34
35 35 Domain& domain = m_domains[m_domainIndex];
36 36
37 37 switch(series->type())
38 38 {
39 39 case QChartSeries::SeriesTypeLine: {
40 40
41 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
41 QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series);
42 42
43 43 for (int i = 0; i < xyseries->count(); i++)
44 44 {
45 45 qreal x = xyseries->x(i);
46 46 qreal y = xyseries->y(i);
47 47 domain.m_minX = qMin(domain.m_minX,x);
48 48 domain.m_minY = qMin(domain.m_minY,y);
49 49 domain.m_maxX = qMax(domain.m_maxX,x);
50 50 domain.m_maxY = qMax(domain.m_maxY,y);
51 51 }
52 52 break;
53 53 }
54 54 case QChartSeries::SeriesTypeBar: {
55 55
56 56 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
57 57 qreal x = barSeries->countColumns();
58 58 qreal y = barSeries->max();
59 59 domain.m_minX = qMin(domain.m_minX,x);
60 60 domain.m_minY = qMin(domain.m_minY,y);
61 61 domain.m_maxX = qMax(domain.m_maxX,x);
62 62 domain.m_maxY = qMax(domain.m_maxY,y);
63 63 }
64 64 break;
65 65 case QChartSeries::SeriesTypeStackedBar: {
66 66
67 67 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
68 68 qreal x = stackedBarSeries->countColumns();
69 69 qreal y = stackedBarSeries->maxColumnSum();
70 70 domain.m_minX = qMin(domain.m_minX,x);
71 71 domain.m_minY = qMin(domain.m_minY,y);
72 72 domain.m_maxX = qMax(domain.m_maxX,x);
73 73 domain.m_maxY = qMax(domain.m_maxY,y);
74 74 }
75 75 break;
76 76 case QChartSeries::SeriesTypePercentBar: {
77 77
78 78 PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
79 79 qreal x = percentBarSeries->countColumns();
80 80 domain.m_minX = qMin(domain.m_minX,x);
81 81 domain.m_minY = 0;
82 82 domain.m_maxX = qMax(domain.m_maxX,x);
83 83 domain.m_maxY = 100;
84 84 }
85 85 break;
86 86
87 87 case QChartSeries::SeriesTypePie: {
88 88 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
89 89 // TODO: domain stuff
90 90 break;
91 91 }
92 92
93 93 default: {
94 94 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
95 95 return;
96 96 break;
97 97 }
98 98
99 99 }
100 100
101 101 emit seriesAdded(series);
102 102 emit domainChanged(domain);
103 103 }
104 104
105 105 bool ChartDataSet::nextDomain()
106 106 {
107 107 if (m_domainIndex < m_domains.count() - 1) {
108 108 m_domainIndex++;
109 109 emit domainChanged(m_domains[m_domainIndex]);
110 110 return true;
111 111 }
112 112 else {
113 113 return false;
114 114 }
115 115 }
116 116
117 117 bool ChartDataSet::previousDomain()
118 118 {
119 119 if (m_domainIndex > 0) {
120 120 m_domainIndex--;
121 121 emit domainChanged(m_domains[m_domainIndex]);
122 122 return true;
123 123 }
124 124 else {
125 125 return false;
126 126 }
127 127 }
128 128
129 129 void ChartDataSet::clearDomains()
130 130 {
131 131 if (m_domainIndex > 0) {
132 132 m_domainIndex = 0;
133 133 emit domainChanged(m_domains[m_domainIndex]);
134 134 }
135 135 }
136 136
137 137 void ChartDataSet::addDomain(const Domain& domain)
138 138 {
139 139 m_domains.resize(m_domainIndex + 1);
140 140 m_domains << domain;
141 141 m_domainIndex++;
142 142
143 143 emit domainChanged(domain);
144 144 }
145 145
146 146 #include "moc_chartdataset_p.cpp"
147 147
148 148 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,251 +1,248
1 1 #include "qchart.h"
2 2 #include "qchartaxis.h"
3 3 #include "chartpresenter_p.h"
4 4 #include "chartdataset_p.h"
5 5 #include "charttheme_p.h"
6 6 //series
7 7 #include "barchartseries.h"
8 8 #include "stackedbarchartseries.h"
9 9 #include "percentbarchartseries.h"
10 #include "qxychartseries.h"
10 #include "qlinechartseries.h"
11 11 #include "qpieseries.h"
12 12 //items
13 13 #include "axisitem_p.h"
14 14 #include "bargroup.h"
15 15 #include "stackedbargroup.h"
16 #include "xylinechartitem_p.h"
16 #include "linechartitem_p.h"
17 17 #include "percentbargroup.h"
18 18 #include "linechartanimationitem_p.h"
19 19 #include "piepresentation.h"
20 20
21 #include <QAbstractAnimation>
22 #include <QPropertyAnimation>
23
24 21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 22
26 23 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
27 24 m_chart(chart),
28 25 m_dataset(dataset),
29 26 m_chartTheme(0),
30 27 m_domainIndex(0),
31 28 m_marginSize(0),
32 29 m_rect(QRectF(QPoint(0,0),m_chart->size()))
33 30 {
34 31 setTheme(QChart::ChartThemeDefault);
35 32 createConnections();
36 33 createDeafultAxis();
37 34 }
38 35
39 36 ChartPresenter::~ChartPresenter()
40 37 {
41 38 }
42 39
43 40 void ChartPresenter::createDeafultAxis()
44 41 {
45 42 //default axis
46 43 QChartAxis* axisX = new QChartAxis(this);
47 44 QChartAxis* axisY = new QChartAxis(this);
48 45
49 46 m_axis << new AxisItem(axisX,AxisItem::X_AXIS,m_chart);
50 47 m_axis << new AxisItem(axisY,AxisItem::Y_AXIS,m_chart);
51 48
52 49 foreach(AxisItem* item, m_axis) {
53 50 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
54 51 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
55 52 }
56 53 }
57 54
58 55 void ChartPresenter::createConnections()
59 56 {
60 57 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
61 58 QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*)));
62 59 }
63 60
64 61 void ChartPresenter::handleGeometryChanged()
65 62 {
66 63 m_rect = QRectF(QPoint(0,0),m_chart->size());
67 64 m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
68 65 emit geometryChanged(m_rect);
69 66 }
70 67
71 68 int ChartPresenter::margin() const
72 69 {
73 70 return m_marginSize;
74 71 }
75 72
76 73 void ChartPresenter::setMargin(int margin)
77 74 {
78 75 m_marginSize = margin;
79 76 }
80 77
81 78 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
82 79 {
83 80 switch(series->type())
84 81 {
85 82 case QChartSeries::SeriesTypeLine: {
86 QXYChartSeries* lineSeries = static_cast<QXYChartSeries*>(series);
87 XYLineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart);
83 QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series);
84 LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart);
88 85 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
89 86 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
90 87 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
91 88 QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
92 89 m_chartItems.insert(series,item);
93 90 break;
94 91 }
95 92
96 93 case QChartSeries::SeriesTypeBar: {
97 94 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
98 95 BarGroup* item = new BarGroup(*barSeries,m_chart);
99 96 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
100 97 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
101 98 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
102 99 QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
103 100 m_chartItems.insert(series,item);
104 101 // m_axisXItem->setVisible(false);
105 102 break;
106 103 }
107 104
108 105 case QChartSeries::SeriesTypeStackedBar: {
109 106
110 107 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
111 108 StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart);
112 109 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
113 110 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
114 111 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
115 112 QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
116 113 m_chartItems.insert(series,item);
117 114 break;
118 115 }
119 116
120 117 case QChartSeries::SeriesTypePercentBar: {
121 118
122 119 PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
123 120 PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart);
124 121 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
125 122 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
126 123 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
127 124 QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
128 125 m_chartItems.insert(series,item);
129 126 break;
130 127 }
131 128 /*
132 129 case QChartSeries::SeriesTypeScatter: {
133 130 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
134 131 scatterSeries->d->m_theme = m_chartTheme->themeForSeries();
135 132 scatterSeries->d->setParentItem(this);
136 133 scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
137 134 m_chartItems << scatterSeries->d;
138 135 m_chartTheme->addObserver(scatterSeries->d);
139 136
140 137 foreach (qreal x, scatterSeries->d->m_x) {
141 138 domain.m_minX = qMin(domain.m_minX, x);
142 139 domain.m_maxX = qMax(domain.m_maxX, x);
143 140 }
144 141 foreach (qreal y, scatterSeries->d->m_y) {
145 142 domain.m_minY = qMin(domain.m_minY, y);
146 143 domain.m_maxY = qMax(domain.m_maxY, y);
147 144 }
148 145
149 146 break;
150 147 }
151 148 */
152 149
153 150 case QChartSeries::SeriesTypePie: {
154 151 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
155 152 PiePresentation* pieChart = new PiePresentation(m_chart, pieSeries);
156 153 pieSeries->m_piePresentation = pieChart; // TODO: remove this pointer passing use signals&slots
157 154 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pieChart, SLOT(handleGeometryChanged(const QRectF&)));
158 155 QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pieChart, SLOT(handleDomainChanged(const Domain&)));
159 156 m_chartItems.insert(series, pieChart);
160 157 break;
161 158 }
162 159
163 160 default: {
164 161 qDebug()<< "Series type" << series->type() << "not implemented.";
165 162 break;
166 163 }
167 164 }
168 165 }
169 166
170 167 void ChartPresenter::handleSeriesChanged(QChartSeries* series)
171 168 {
172 169 //TODO:
173 170 }
174 171
175 172 void ChartPresenter::zoomInToRect(const QRectF& rect)
176 173 {
177 174 if(!rect.isValid()) return;
178 175 QRectF r = rect.normalized();
179 176 r.translate(-m_marginSize, -m_marginSize);
180 177 Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height()));
181 178 m_dataset->addDomain(domain);
182 179 }
183 180
184 181 void ChartPresenter::zoomIn()
185 182 {
186 183 if (!m_dataset->nextDomain()) {
187 184 QRectF rect = m_rect;
188 185 rect.setWidth(rect.width()/2);
189 186 rect.setHeight(rect.height()/2);
190 187 rect.moveCenter(m_rect.center());
191 188 Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height()));
192 189 m_dataset->addDomain(domain);
193 190 }
194 191 }
195 192
196 193 void ChartPresenter::zoomOut()
197 194 {
198 195 m_dataset->previousDomain();
199 196 }
200 197
201 198 void ChartPresenter::zoomReset()
202 199 {
203 200 m_dataset->clearDomains();
204 201 }
205 202
206 203 void ChartPresenter::setTheme(QChart::ChartThemeId theme)
207 204 {
208 205 delete m_chartTheme;
209 206
210 207 m_chartTheme = ChartTheme::createTheme(theme);
211 208
212 209 m_chartTheme->decorate(m_chart);
213 210 QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems);
214 211
215 212 int index=0;
216 213 while (i.hasNext()) {
217 214 i.next();
218 215 index++;
219 216 m_chartTheme->decorate(i.value(),i.key(),index);
220 217 }
221 218 }
222 219
223 220
224 221 QChart::ChartThemeId ChartPresenter::theme()
225 222 {
226 223 return (QChart::ChartThemeId) 0;
227 224 }
228 225
229 226 /*
230 227 void ChartPresenter::setAxisX(const QChartAxis& axis)
231 228 {
232 229 setAxis(m_axisXItem,axis);
233 230 }
234 231 void ChartPresenter::setAxisY(const QChartAxis& axis)
235 232 {
236 233 setAxis(m_axisYItem.at(0),axis);
237 234 }
238 235
239 236 void ChartPresenter::setAxisY(const QList<QChartAxis>& axis)
240 237 {
241 238 //TODO not implemented
242 239 }
243 240
244 241 void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis)
245 242 {
246 243 item->setVisible(axis.isAxisVisible());
247 244 }
248 245 */
249 246 #include "moc_chartpresenter_p.cpp"
250 247
251 248 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,142 +1,142
1 1 #include "charttheme_p.h"
2 2 #include "qchart.h"
3 3
4 4
5 5 //series
6 6 #include "barchartseries.h"
7 7 #include "stackedbarchartseries.h"
8 8 #include "percentbarchartseries.h"
9 #include "qxychartseries.h"
9 #include "qlinechartseries.h"
10 10 //items
11 11 #include "axisitem_p.h"
12 12 #include "bargroup.h"
13 13 #include "stackedbargroup.h"
14 #include "xylinechartitem_p.h"
14 #include "linechartitem_p.h"
15 15 #include "percentbargroup.h"
16 16
17 17 //themes
18 18 #include "chartthemevanilla_p.h"
19 19 #include "chartthemeicy_p.h"
20 20 #include "chartthemegrayscale_p.h"
21 21 #include "chartthemescientific_p.h"
22 22
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 /* TODO
27 27 case QChart::ChartThemeUnnamed1:
28 28 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
29 29 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
30 30 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
31 31 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
32 32 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
33 33
34 34 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
35 35 m_gradientEndColor = QColor(QRgb(0xffafafaf));
36 36 */
37 37
38 38 ChartTheme::ChartTheme()
39 39 {
40 40 m_seriesColor.append(QRgb(0xff000000));
41 41 m_seriesColor.append(QRgb(0xff707070));
42 42 m_gradientStartColor = QColor(QRgb(0xffffffff));
43 43 m_gradientEndColor = QColor(QRgb(0xffafafaf));
44 44 }
45 45
46 46
47 47 ChartTheme* ChartTheme::createTheme(QChart::ChartThemeId theme)
48 48 {
49 49 switch(theme) {
50 50 case QChart::ChartThemeDefault:
51 51 return new ChartTheme();
52 52 case QChart::ChartThemeVanilla:
53 53 return new ChartThemeVanilla();
54 54 case QChart::ChartThemeIcy:
55 55 return new ChartThemeIcy();
56 56 case QChart::ChartThemeGrayscale:
57 57 return new ChartThemeGrayscale();
58 58 case QChart::ChartThemeScientific:
59 59 return new ChartThemeScientific();
60 60 }
61 61 }
62 62
63 63 void ChartTheme::decorate(QChart* chart)
64 64 {
65 65 QLinearGradient backgroundGradient;
66 66 backgroundGradient.setColorAt(0.0, m_gradientStartColor);
67 67 backgroundGradient.setColorAt(1.0, m_gradientEndColor);
68 68 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
69 69 chart->setChartBackgroundBrush(backgroundGradient);
70 70 }
71 71 //TODO helper to by removed later
72 72 void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count)
73 73 {
74 74 switch(series->type())
75 75 {
76 76 case QChartSeries::SeriesTypeLine: {
77 QXYChartSeries* s = static_cast<QXYChartSeries*>(series);
78 XYLineChartItem* i = static_cast<XYLineChartItem*>(item);
77 QLineChartSeries* s = static_cast<QLineChartSeries*>(series);
78 LineChartItem* i = static_cast<LineChartItem*>(item);
79 79 decorate(i,s,count);
80 80 break;
81 81 }
82 82 case QChartSeries::SeriesTypeBar: {
83 83 BarChartSeries* b = static_cast<BarChartSeries*>(series);
84 84 BarGroup* i = static_cast<BarGroup*>(item);
85 85 decorate(i,b,count);
86 86 break;
87 87 }
88 88 case QChartSeries::SeriesTypeStackedBar: {
89 89 StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series);
90 90 StackedBarGroup* i = static_cast<StackedBarGroup*>(item);
91 91 decorate(i,s,count);
92 92 break;
93 93 }
94 94 case QChartSeries::SeriesTypePercentBar: {
95 95 PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series);
96 96 PercentBarGroup* i = static_cast<PercentBarGroup*>(item);
97 97 decorate(i,s,count);
98 98 break;
99 99 }
100 100 default:
101 101 qDebug()<<"Wrong item to be decorated by theme";
102 102 break;
103 103 }
104 104
105 105 }
106 106
107 void ChartTheme::decorate(XYLineChartItem* item, QXYChartSeries* series,int count)
107 void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count)
108 108 {
109 109 item->setPen(series->pen());
110 110 }
111 111
112 112 void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count)
113 113 {
114 114 item->addColor(QColor(255,0,0,128));
115 115 item->addColor(QColor(255,255,0,128));
116 116 item->addColor(QColor(0,255,0,128));
117 117 item->addColor(QColor(0,0,255,128));
118 118 item->addColor(QColor(255,128,0,128));
119 119 }
120 120
121 121 void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count)
122 122 {
123 123 // Add some fugly colors for 5 fist series...
124 124 item->addColor(QColor(255,0,0,128));
125 125 item->addColor(QColor(255,255,0,128));
126 126 item->addColor(QColor(0,255,0,128));
127 127 item->addColor(QColor(0,0,255,128));
128 128 item->addColor(QColor(255,128,0,128));
129 129 }
130 130
131 131 void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count)
132 132 {
133 133 // Add some fugly colors for 5 fist series...
134 134 item->addColor(QColor(255,0,0,128));
135 135 item->addColor(QColor(255,255,0,128));
136 136 item->addColor(QColor(0,255,0,128));
137 137 item->addColor(QColor(0,0,255,128));
138 138 item->addColor(QColor(255,128,0,128));
139 139 }
140 140
141 141
142 142 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,43 +1,43
1 1 #ifndef CHARTTHEME_H
2 2 #define CHARTTHEME_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "qchart.h"
6 6 #include <QColor>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class ChartItem;
11 11 class QChartSeries;
12 class XYLineChartItem;
13 class QXYChartSeries;
12 class LineChartItem;
13 class QLineChartSeries;
14 14 class BarGroup;
15 15 class BarChartSeries;
16 16 class StackedBarGroup;
17 17 class StackedBarChartSeries;
18 18 class PercentBarChartSeries;
19 19 class PercentBarGroup;
20 20
21 21 class ChartTheme
22 22 {
23 23 protected:
24 24 explicit ChartTheme();
25 25 public:
26 26 static ChartTheme* createTheme(QChart::ChartThemeId theme);
27 27 void decorate(QChart* chart);
28 28 void decorate(ChartItem* item, QChartSeries* series,int count);
29 void decorate(XYLineChartItem* item, QXYChartSeries*, int count);
29 void decorate(LineChartItem* item, QLineChartSeries*, int count);
30 30 void decorate(BarGroup* item, BarChartSeries* series,int count);
31 31 void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count);
32 32 void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count);
33 33
34 34 protected:
35 35 QColor m_gradientStartColor;
36 36 QColor m_gradientEndColor;
37 37 QList<QColor> m_seriesColor;
38 38
39 39 };
40 40
41 41 QTCOMMERCIALCHART_END_NAMESPACE
42 42
43 43 #endif // CHARTTHEME_H
@@ -1,63 +1,63
1 1 #include "linechartanimationitem_p.h"
2 #include "xylinechartitem_p.h"
2 #include "linechartitem_p.h"
3 3 #include <QPropertyAnimation>
4 4
5 5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 7 const static int duration = 500;
8 8
9 9
10 LineChartAnimationItem::LineChartAnimationItem(ChartPresenter* presenter, QXYChartSeries* series,QGraphicsItem *parent):
11 XYLineChartItem(presenter,series,parent)
10 LineChartAnimationItem::LineChartAnimationItem(ChartPresenter* presenter, QLineChartSeries* series,QGraphicsItem *parent):
11 LineChartItem(presenter,series,parent)
12 12 {
13 13
14 14 }
15 15
16 16 LineChartAnimationItem::~LineChartAnimationItem()
17 17 {
18 18 }
19 19
20 20 void LineChartAnimationItem::addPoints(const QVector<QPointF>& points)
21 21 {
22 22 m_data=points;
23 23 clearView();
24 24 QPropertyAnimation *animation = new QPropertyAnimation(this, "a_addPoints", parent());
25 25 animation->setDuration(duration);
26 26 //animation->setEasingCurve(QEasingCurve::InOutBack);
27 27 animation->setKeyValueAt(0.0, 0);
28 28 animation->setKeyValueAt(1.0, m_data.size());
29 29 animation->start(QAbstractAnimation::DeleteWhenStopped);
30 30 }
31 31
32 32 void LineChartAnimationItem::setPoint(int index,const QPointF& point)
33 33 {
34 34 AnimationHelper* helper = new AnimationHelper(this,index);
35 35 QPropertyAnimation *animation = new QPropertyAnimation(helper, "point", parent());
36 36 animation->setDuration(duration);
37 37 //animation->setEasingCurve(QEasingCurve::InOutBack);
38 38 animation->setKeyValueAt(0.0, points().value(index));
39 39 animation->setKeyValueAt(1.0, point);
40 40 animation->start(QAbstractAnimation::DeleteWhenStopped);
41 41 }
42 42
43 43 void LineChartAnimationItem::aw_addPoints(int points)
44 44 {
45 45 int index = count();
46 46 for(int i = index;i< points ;i++){
47 XYLineChartItem::addPoint(m_data.at(i));
47 LineChartItem::addPoint(m_data.at(i));
48 48 }
49 49 updateGeometry();
50 50 update();
51 51 }
52 52
53 53 void LineChartAnimationItem::aw_setPoint(int index,const QPointF& point)
54 54 {
55 XYLineChartItem::setPoint(index,point);
55 LineChartItem::setPoint(index,point);
56 56 updateGeometry();
57 57 update();
58 58 }
59 59
60 60
61 61 #include "moc_linechartanimationitem_p.cpp"
62 62
63 63 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,55 +1,55
1 #ifndef XYLINEPRESENTER_P_H_
2 #define XYLINEPRESENTER_P_H_
1 #ifndef LINECHARTANIMATIONITEM_P_H_
2 #define LINECHARTANIMATIONITEM_P_H_
3 3
4 4 #include "qchartglobal.h"
5 #include "xylinechartitem_p.h"
5 #include "linechartitem_p.h"
6 6 #include "domain_p.h"
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 class XYLineChartItem;
10 class LineChartItem;
11 11
12 class LineChartAnimationItem : public XYLineChartItem {
12 class LineChartAnimationItem : public LineChartItem {
13 13 Q_OBJECT
14 14 Q_PROPERTY(int a_addPoints READ ar_addPoints WRITE aw_addPoints);
15 15 // Q_PROPERTY(QPointF a_setPoint READ ar_setPoint WRITE aw_setPoint);
16 16 public:
17 LineChartAnimationItem(ChartPresenter* presenter, QXYChartSeries *series, QGraphicsItem *parent = 0);
17 LineChartAnimationItem(ChartPresenter* presenter, QLineChartSeries *series, QGraphicsItem *parent = 0);
18 18 virtual ~LineChartAnimationItem();
19 19
20 20 void addPoints(const QVector<QPointF>& points);
21 21 void setPoint(int index,const QPointF& point);
22 22 //void removePoint(const QPointF& point){};
23 23 //void setPoint(const QPointF& oldPoint, const QPointF& newPoint){};
24 24
25 25 int ar_addPoints() const { return m_addPoints;}
26 26 void aw_addPoints(int points);
27 27 const QPointF& ar_setPoint() const { return m_setPoint;}
28 28 void aw_setPoint(int index,const QPointF& point);
29 29
30 30 private:
31 31 QVector<QPointF> m_data;
32 32 Domain m_domain;
33 33 int m_addPoints;
34 34 QPointF m_setPoint;
35 35 int m_setPoint_index;
36 36 };
37 37
38 38 class AnimationHelper: public QObject
39 39 {
40 40 Q_OBJECT
41 41 Q_PROPERTY(QPointF point READ point WRITE setPoint);
42 42 public:
43 43 AnimationHelper(LineChartAnimationItem* item,int index):m_item(item),m_index(index){};
44 44 void setPoint(const QPointF& point){
45 45 m_item->aw_setPoint(m_index,point);
46 46 }
47 47 QPointF point(){return m_point;}
48 48 QPointF m_point;
49 49 LineChartAnimationItem* m_item;
50 50 int m_index;
51 51 };
52 52
53 53 QTCOMMERCIALCHART_END_NAMESPACE
54 54
55 #endif /* XYLINEPRESENTER_P_H_ */
55 #endif
@@ -1,195 +1,195
1 1 #include "qchart.h"
2 2 #include "qchartseries.h"
3 3 #include "qscatterseries.h"
4 4 #include "qscatterseries_p.h"
5 5 #include "qpieseries.h"
6 6 #include "qchartaxis.h"
7 7 #include "charttheme_p.h"
8 8 #include "chartitem_p.h"
9 9 #include "plotdomain_p.h"
10 10 #include "axisitem_p.h"
11 11 #include "chartpresenter_p.h"
12 12 #include "chartdataset_p.h"
13 13
14 14 //series
15 15 #include "barchartseries.h"
16 16 #include "stackedbarchartseries.h"
17 17 #include "percentbarchartseries.h"
18 #include "qxychartseries.h"
18 #include "qlinechartseries.h"
19 19
20 20 #include <QGraphicsScene>
21 21 #include <QGraphicsSceneResizeEvent>
22 22 #include <QDebug>
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
27 27 m_backgroundItem(0),
28 28 m_titleItem(0),
29 29 m_dataset(new ChartDataSet(this)),
30 30 m_presenter(new ChartPresenter(this,m_dataset))
31 31 {
32 32 }
33 33
34 34 QChart::~QChart() {}
35 35
36 36 void QChart::addSeries(QChartSeries* series)
37 37 {
38 38 m_dataset->addSeries(series);
39 39 }
40 40
41 41 //TODO on review, is it really needed ??
42 42 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
43 43 {
44 44 // TODO: support also other types; not only scatter and pie
45 45
46 46 QChartSeries *series(0);
47 47
48 48 switch (type) {
49 49 case QChartSeries::SeriesTypeLine: {
50 series = QXYChartSeries::create();
50 series = QLineChartSeries::create();
51 51 break;
52 52 }
53 53 case QChartSeries::SeriesTypeBar: {
54 54 series = new BarChartSeries(this);
55 55 break;
56 56 }
57 57 case QChartSeries::SeriesTypeStackedBar: {
58 58 series = new StackedBarChartSeries(this);
59 59 break;
60 60 }
61 61 case QChartSeries::SeriesTypePercentBar: {
62 62 series = new PercentBarChartSeries(this);
63 63 break;
64 64 }
65 65 case QChartSeries::SeriesTypeScatter: {
66 66 series = new QScatterSeries(this);
67 67 break;
68 68 }
69 69 case QChartSeries::SeriesTypePie: {
70 70 series = new QPieSeries(this);
71 71 break;
72 72 }
73 73 default:
74 74 Q_ASSERT(false);
75 75 break;
76 76 }
77 77
78 78 addSeries(series);
79 79 return series;
80 80 }
81 81
82 82 void QChart::setChartBackgroundBrush(const QBrush& brush)
83 83 {
84 84
85 85 if(!m_backgroundItem) {
86 86 m_backgroundItem = new QGraphicsRectItem(this);
87 87 m_backgroundItem->setZValue(-1);
88 88 }
89 89
90 90 m_backgroundItem->setBrush(brush);
91 91 m_backgroundItem->update();
92 92 }
93 93
94 94 void QChart::setChartBackgroundPen(const QPen& pen)
95 95 {
96 96
97 97 if(!m_backgroundItem) {
98 98 m_backgroundItem = new QGraphicsRectItem(this);
99 99 m_backgroundItem->setZValue(-1);
100 100 }
101 101
102 102 m_backgroundItem->setPen(pen);
103 103 m_backgroundItem->update();
104 104 }
105 105
106 106 void QChart::setTitle(const QString& title,const QFont& font)
107 107 {
108 108 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
109 109 m_titleItem->setPlainText(title);
110 110 m_titleItem->setFont(font);
111 111 }
112 112
113 113 int QChart::margin() const
114 114 {
115 115 return m_presenter->margin();
116 116 }
117 117
118 118 void QChart::setMargin(int margin)
119 119 {
120 120 m_presenter->setMargin(margin);
121 121 }
122 122
123 123 void QChart::setTheme(QChart::ChartThemeId theme)
124 124 {
125 125 m_presenter->setTheme(theme);
126 126 }
127 127
128 128 QChart::ChartThemeId QChart::theme()
129 129 {
130 130 return (QChart::ChartThemeId) m_presenter->theme();
131 131 }
132 132
133 133 void QChart::zoomInToRect(const QRectF& rectangle)
134 134 {
135 135 m_presenter->zoomInToRect(rectangle);
136 136 }
137 137
138 138 void QChart::zoomIn()
139 139 {
140 140 m_presenter->zoomIn();
141 141 }
142 142
143 143 void QChart::zoomOut()
144 144 {
145 145 m_presenter->zoomOut();
146 146 }
147 147
148 148 void QChart::zoomReset()
149 149 {
150 150 m_presenter->zoomReset();
151 151 }
152 152
153 153 void QChart::setAxisX(const QChartAxis& axis)
154 154 {
155 155
156 156 }
157 157 void QChart::setAxisY(const QChartAxis& axis)
158 158 {
159 159
160 160 }
161 161
162 162 void QChart::setAxisY(const QList<QChartAxis>& axis)
163 163 {
164 164 //TODO not implemented
165 165 }
166 166
167 167 void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
168 168 {
169 169
170 170 }
171 171
172 172 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
173 173 {
174 174
175 175 m_rect = QRectF(QPoint(0,0),event->newSize());
176 176 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
177 177
178 178 // recalculate title position
179 179 if (m_titleItem) {
180 180 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
181 181 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
182 182 }
183 183
184 184 //recalculate background gradient
185 185 if (m_backgroundItem) {
186 186 m_backgroundItem->setRect(rect);
187 187 }
188 188
189 189 QGraphicsWidget::resizeEvent(event);
190 190 update();
191 191 }
192 192
193 193 #include "moc_qchart.cpp"
194 194
195 195 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,34 +1,34
1 1 #include "qchartglobal.h"
2 2 #include "qchartseries.h"
3 3
4 4 #include "barchartseries.h"
5 #include "qxychartseries.h"
5 #include "qlinechartseries.h"
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 QChartSeries* QChartSeries::create(QChartSeriesType type, QObject* parent)
10 10 {
11 11 qDebug() << "QChartSeries::create";
12 12 // TODO: Other types
13 13 switch (type) {
14 14 case QChartSeries::SeriesTypeLine: {
15 QXYChartSeries* s = QXYChartSeries::create(parent); // TODO: do we need create method for derived implementations?
15 QLineChartSeries* s = QLineChartSeries::create(parent); // TODO: do we need create method for derived implementations?
16 16 return s;
17 17 }
18 18 case QChartSeries::SeriesTypePie: {
19 19 return 0;
20 20 }
21 21 case QChartSeries::SeriesTypeScatter: {
22 22 return 0;
23 23 }
24 24 case QChartSeries::SeriesTypeBar: {
25 25 BarChartSeries* s = new BarChartSeries(parent);
26 26 return s;
27 27 }
28 28 default:
29 29 return 0;
30 30 }
31 31 }
32 32
33 33 #include "moc_qchartseries.cpp"
34 34 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,141 +1,114
1 !include( ../common.pri ) {
2 error( Couldn't find the common.pri file! )
3 }
4
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
5 2 TARGET = QtCommercialChart
6 3 DESTDIR = $$CHART_BUILD_LIB_DIR
7 4 TEMPLATE = lib
8 5 QT += core \
9 6 gui
10
11 7 CONFIG += debug_and_release
12 8 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
13
14 SOURCES += \
15 barchart/barchartseries.cpp \
9 SOURCES += barchart/barchartseries.cpp \
16 10 barchart/bargroup.cpp \
17 11 barchart/bar.cpp \
18 12 barchart/stackedbarchartseries.cpp \
19 13 barchart/stackedbargroup.cpp \
20 14 barchart/percentbarchartseries.cpp \
21 15 barchart/percentbargroup.cpp \
22 16 barchart/barlabel.cpp \
23 xylinechart/qxychartseries.cpp \
24 xylinechart/xylinechartitem.cpp \
25 xylinechart/linechartanimationitem.cpp \
17 linechart/linechartanimationitem.cpp \
18 linechart/linechartitem.cpp \
19 linechart/qlinechartseries.cpp \
26 20 piechart/qpieseries.cpp \
27 21 piechart/pieslice.cpp \
28 22 piechart/piepresentation.cpp \
23 barchart/separator.cpp \
24 barchart/bargroupbase.cpp \
25 barchart/barchartseriesbase.cpp \
29 26 plotdomain.cpp \
30 27 qscatterseries.cpp \
31 28 qchart.cpp \
32 29 axisitem.cpp \
33 30 qchartview.cpp \
34 31 qchartseries.cpp \
35 32 qchartaxis.cpp \
36 33 charttheme.cpp \
37 barchart/separator.cpp \
38 barchart/bargroupbase.cpp \
39 barchart/barchartseriesbase.cpp \
40 34 chartdataset.cpp \
41 35 chartpresenter.cpp \
42 domain.cpp
43
44
45
46 PRIVATE_HEADERS += \
47 xylinechart/xylinechartitem_p.h \
48 xylinechart/linechartanimationitem_p.h \
36 domain.cpp
37 PRIVATE_HEADERS += linechart/linechartitem_p.h \
38 linechart/linechartanimationitem_p.h \
49 39 barchart/barlabel_p.h \
50 40 barchart/bar_p.h \
51 41 barchart/separator_p.h \
52 42 piechart/piepresentation.h \
53 43 piechart/pieslice.h \
54 44 plotdomain_p.h \
55 45 qscatterseries_p.h \
56 46 axisitem_p.h \
57 47 chartitem_p.h \
58 48 charttheme_p.h \
59 49 chartdataset_p.h \
60 50 chartpresenter_p.h \
61 domain_p.h
62
63 PUBLIC_HEADERS += \
64 qchartseries.h \
65 qscatterseries.h \
66 qchart.h \
67 qchartglobal.h \
68 xylinechart/qxychartseries.h \
51 domain_p.h
52 PUBLIC_HEADERS += linechart/qlinechartseries.h \
69 53 barchart/barchartseries.h \
70 54 barchart/bargroup.h \
71 55 barchart/stackedbarchartseries.h \
72 56 barchart/stackedbargroup.h \
73 57 barchart/percentbarchartseries.h \
74 58 barchart/percentbargroup.h \
75 59 barchart/barchartseriesbase.h \
76 60 barchart/bargroupbase.h \
77 61 piechart/qpieseries.h \
62 qchartseries.h \
63 qscatterseries.h \
64 qchart.h \
65 qchartglobal.h \
78 66 qchartview.h \
79 qchartaxis.h
80
81 THEMES += \
82 themes/chartthemeicy_p.h \
67 qchartaxis.h
68 THEMES += themes/chartthemeicy_p.h \
83 69 themes/chartthemegrayscale_p.h \
84 70 themes/chartthemescientific_p.h \
85 themes/chartthemevanilla_p.h \
86
87
71 themes/chartthemevanilla_p.h
88 72 HEADERS += $$PUBLIC_HEADERS
89 73 HEADERS += $$PRIVATE_HEADERS
90 74 HEADERS += $$THEMES
91
92 INCLUDEPATH += xylinechart \
93 barchart \
94 piechart \
95 themes \
96 .
97
75 INCLUDEPATH += linechart \
76 barchart \
77 piechart \
78 themes \
79 .
98 80 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
99 81 MOC_DIR = $$CHART_BUILD_DIR/lib
100 82 UI_DIR = $$CHART_BUILD_DIR/lib
101 83 RCC_DIR = $$CHART_BUILD_DIR/lib
102
103
104 84 DEFINES += QTCOMMERCIALCHART_LIBRARY
105
106 85 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
107 86 public_headers.files = $$PUBLIC_HEADERS
108 87 target.path = $$[QT_INSTALL_LIBS]
109 88 INSTALLS += target \
110 89 public_headers
111
112
113 90 install_build_headers.name = bild_headers
114 91 install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h
115 92 install_build_headers.input = PUBLIC_HEADERS
116 install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR
117 install_build_headers.CONFIG += target_predeps no_link
93 install_build_headers.commands = $$QMAKE_COPY \
94 ${QMAKE_FILE_NAME} \
95 $$CHART_BUILD_HEADER_DIR
96 install_build_headers.CONFIG += target_predeps \
97 no_link
118 98 QMAKE_EXTRA_COMPILERS += install_build_headers
119
120 99 chartversion.target = qchartversion_p.h
121 chartversion.commands = @echo "build_time" > $$chartversion.target;
122 chartversion.depends = $$HEADERS $$SOURCES
100 chartversion.commands = @echo \
101 "build_time" \
102 > \
103 $$chartversion.target;
104 chartversion.depends = $$HEADERS \
105 $$SOURCES
123 106 PRE_TARGETDEPS += qchartversion_p.h
124 QMAKE_CLEAN+= qchartversion_p.h
107 QMAKE_CLEAN += qchartversion_p.h
125 108 QMAKE_EXTRA_TARGETS += chartversion
126
127 unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
128 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
129
130
131
132
133
134
135
136
137
138
139
140
141
109 unix:QMAKE_DISTCLEAN += -r \
110 $$CHART_BUILD_HEADER_DIR \
111 $$CHART_BUILD_LIB_DIR
112 win32:QMAKE_DISTCLEAN += /Q \
113 $$CHART_BUILD_HEADER_DIR \
114 $$CHART_BUILD_LIB_DIR
@@ -1,381 +1,381
1 1 #include "mainwidget.h"
2 2 #include "dataseriedialog.h"
3 3 #include "qchartseries.h"
4 4 #include "qpieseries.h"
5 #include <qxychartseries.h>
5 #include <qlinechartseries.h>
6 6 #include <barchartseries.h>
7 7 #include <QPushButton>
8 8 #include <QComboBox>
9 9 #include <QSpinBox>
10 10 #include <QCheckBox>
11 11 #include <QGridLayout>
12 12 #include <QHBoxLayout>
13 13 #include <QLabel>
14 14 #include <QSpacerItem>
15 15 #include <QMessageBox>
16 16 #include <cmath>
17 17 #include <QDebug>
18 18 #include <QStandardItemModel>
19 19
20 20
21 21 QTCOMMERCIALCHART_USE_NAMESPACE
22 22
23 23 MainWidget::MainWidget(QWidget *parent) :
24 24 QWidget(parent)
25 25 {
26 26 m_chartWidget = new QChartView(this);
27 27 m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand);
28 28
29 29 // Grid layout for the controls for configuring the chart widget
30 30 QGridLayout *grid = new QGridLayout();
31 31 QPushButton *addSeriesButton = new QPushButton("Add series");
32 32 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
33 33 grid->addWidget(addSeriesButton, 0, 1);
34 34 initBackroundCombo(grid);
35 35 initScaleControls(grid);
36 36 initThemeCombo(grid);
37 37 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
38 38 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool)));
39 39 zoomCheckBox->setChecked(true);
40 40 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
41 41 // add row with empty label to make all the other rows static
42 42 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
43 43 grid->setRowStretch(grid->rowCount() - 1, 1);
44 44
45 45 // Another grid layout as a main layout
46 46 QGridLayout *mainLayout = new QGridLayout();
47 47 mainLayout->addLayout(grid, 0, 0);
48 48
49 49 // Init series type specific controls
50 50 initPieControls();
51 51 mainLayout->addLayout(m_pieLayout, 2, 0);
52 52 // Scatter series specific settings
53 53 // m_scatterLayout = new QGridLayout();
54 54 // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
55 55 // m_scatterLayout->setEnabled(false);
56 56 // mainLayout->addLayout(m_scatterLayout, 1, 0);
57 57
58 58 // Add layouts and the chart widget to the main layout
59 59 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
60 60 setLayout(mainLayout);
61 61
62 62 // force an update to test data
63 63 testDataChanged(0);
64 64 }
65 65
66 66 // Combo box for selecting the chart's background
67 67 void MainWidget::initBackroundCombo(QGridLayout *grid)
68 68 {
69 69 QComboBox *backgroundCombo = new QComboBox(this);
70 70 backgroundCombo->addItem("Color");
71 71 backgroundCombo->addItem("Gradient");
72 72 backgroundCombo->addItem("Image");
73 73 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
74 74 this, SLOT(backgroundChanged(int)));
75 75
76 76 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
77 77 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
78 78 }
79 79
80 80 // Scale related controls (auto-scale vs. manual min-max values)
81 81 void MainWidget::initScaleControls(QGridLayout *grid)
82 82 {
83 83 m_autoScaleCheck = new QCheckBox("Automatic scaling");
84 84 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
85 85 // Allow setting also non-sense values (like -2147483648 and 2147483647)
86 86 m_xMinSpin = new QSpinBox();
87 87 m_xMinSpin->setMinimum(INT_MIN);
88 88 m_xMinSpin->setMaximum(INT_MAX);
89 89 m_xMinSpin->setValue(0);
90 90 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
91 91 m_xMaxSpin = new QSpinBox();
92 92 m_xMaxSpin->setMinimum(INT_MIN);
93 93 m_xMaxSpin->setMaximum(INT_MAX);
94 94 m_xMaxSpin->setValue(10);
95 95 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
96 96 m_yMinSpin = new QSpinBox();
97 97 m_yMinSpin->setMinimum(INT_MIN);
98 98 m_yMinSpin->setMaximum(INT_MAX);
99 99 m_yMinSpin->setValue(0);
100 100 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
101 101 m_yMaxSpin = new QSpinBox();
102 102 m_yMaxSpin->setMinimum(INT_MIN);
103 103 m_yMaxSpin->setMaximum(INT_MAX);
104 104 m_yMaxSpin->setValue(10);
105 105 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
106 106
107 107 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
108 108 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
109 109 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
110 110 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
111 111 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
112 112 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
113 113 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
114 114 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
115 115 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
116 116
117 117 m_autoScaleCheck->setChecked(true);
118 118 }
119 119
120 120 // Combo box for selecting theme
121 121 void MainWidget::initThemeCombo(QGridLayout *grid)
122 122 {
123 123 QComboBox *chartTheme = new QComboBox();
124 124 chartTheme->addItem("Default");
125 125 chartTheme->addItem("Vanilla");
126 126 chartTheme->addItem("Icy");
127 127 chartTheme->addItem("Grayscale");
128 128 chartTheme->addItem("Scientific");
129 129 chartTheme->addItem("Unnamed1");
130 130 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
131 131 this, SLOT(changeChartTheme(int)));
132 132 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
133 133 grid->addWidget(chartTheme, 8, 1);
134 134 }
135 135
136 136 void MainWidget::initPieControls()
137 137 {
138 138 // Pie series specific settings
139 139 // Pie size factory
140 140 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
141 141 pieSizeSpin->setMinimum(LONG_MIN);
142 142 pieSizeSpin->setMaximum(LONG_MAX);
143 143 pieSizeSpin->setValue(1.0);
144 144 pieSizeSpin->setSingleStep(0.1);
145 145 connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
146 146 // Pie position
147 147 QComboBox *piePosCombo = new QComboBox(this);
148 148 piePosCombo->addItem("Maximized");
149 149 piePosCombo->addItem("Top left");
150 150 piePosCombo->addItem("Top right");
151 151 piePosCombo->addItem("Bottom left");
152 152 piePosCombo->addItem("Bottom right");
153 153 connect(piePosCombo, SIGNAL(currentIndexChanged(int)),
154 154 this, SLOT(setPiePosition(int)));
155 155 m_pieLayout = new QGridLayout();
156 156 m_pieLayout->setEnabled(false);
157 157 m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
158 158 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
159 159 m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0);
160 160 m_pieLayout->addWidget(piePosCombo, 1, 1);
161 161 }
162 162
163 163 void MainWidget::addSeries()
164 164 {
165 165 DataSerieDialog dialog(m_defaultSeriesName, this);
166 166 connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
167 167 dialog.exec();
168 168 }
169 169
170 170 void MainWidget::addSeries(QString series, QString data)
171 171 {
172 172 qDebug() << "addSeries: " << series << " data: " << data;
173 173 m_defaultSeriesName = series;
174 174
175 175 // TODO: a dedicated data class for storing x and y values
176 176 QList<qreal> x;
177 177 QList<qreal> y;
178 178
179 179 if (data == "linear") {
180 180 for (int i = 0; i < 20; i++) {
181 181 x.append(i);
182 182 y.append(i);
183 183 }
184 184 } else if (data == "linear, 1M") {
185 185 // 1 million data points from 0.0001 to 100
186 186 // TODO: What is the requirement? Should we be able to show this kind of data with
187 187 // reasonable performance, or can we expect the application developer to do "data mining"
188 188 // for us, so that the count of data points given to QtCommercial Chart is always
189 189 // reasonable?
190 190 for (qreal i = 0; i < 100; i += 0.0001) {
191 191 x.append(i);
192 192 y.append(20);
193 193 }
194 194 } else if (data == "SIN") {
195 195 for (int i = 0; i < 100; i++) {
196 196 x.append(i);
197 197 y.append(abs(sin(3.14159265358979 / 50 * i) * 100));
198 198 }
199 199 } else if (data == "SIN + random") {
200 200 for (qreal i = 0; i < 100; i += 0.1) {
201 201 x.append(i + (rand() % 5));
202 202 y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
203 203 }
204 204 } else {
205 205 // TODO: check if data has a valid file name
206 206 Q_ASSERT(false);
207 207 }
208 208
209 209 // TODO: color of the series
210 210 QChartSeries *newSeries = 0;
211 211 if (series == "Scatter") {
212 212 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter);
213 213 Q_ASSERT(newSeries->setData(x, y));
214 214 } else if (series == "Pie") {
215 215 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
216 216 Q_ASSERT(newSeries->setData(y));
217 217 } else if (series == "Line") {
218 218 // TODO: adding data to an existing line series does not give any visuals for some reason
219 219 // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine);
220 220 // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries);
221 221 // lineSeries->setColor(Qt::blue);
222 222 // for (int i(0); i < x.count() && i < y.count(); i++) {
223 223 // lineSeries->add(x.at(i), y.at(i));
224 224 // }
225 225 //Q_ASSERT(newSeries->setData(x, y));
226 QXYChartSeries* series0 = QXYChartSeries::create();
226 QLineChartSeries* series0 = QLineChartSeries::create();
227 227 for (int i(0); i < x.count() && i < y.count(); i++)
228 228 series0->add(x.at(i), y.at(i));
229 229 m_chartWidget->addSeries(series0);
230 230 newSeries = series0;
231 231 } else {
232 232 // TODO
233 233 }
234 234
235 235 // BarChart
236 236 if (series == "Bar") {
237 237 // This is the another way of creating series. Should we create test cases for both ways, if we support them?
238 238 qDebug() << "Bar chart series";
239 239 newSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this);
240 240
241 241 // Create some test data to chart
242 242 QStandardItemModel dataModel(2,10,this);
243 243 QModelIndex index;
244 244 index = dataModel.index(0,0);
245 245 // Series 1, items 6 to 9 missing.
246 246 dataModel.setData(dataModel.index(0,0),1);
247 247 dataModel.setData(dataModel.index(0,1),12);
248 248 dataModel.setData(dataModel.index(0,2),5);
249 249 dataModel.setData(dataModel.index(0,3),8);
250 250 dataModel.setData(dataModel.index(0,4),17);
251 251 dataModel.setData(dataModel.index(0,5),9);
252 252
253 253 // Series 2, some other items missing
254 254 dataModel.setData(dataModel.index(1,0),5);
255 255 dataModel.setData(dataModel.index(1,3),4);
256 256 dataModel.setData(dataModel.index(1,5),7);
257 257 dataModel.setData(dataModel.index(1,6),8);
258 258 dataModel.setData(dataModel.index(1,8),9);
259 259 dataModel.setData(dataModel.index(1,9),9);
260 260
261 261 newSeries->setData(&dataModel);
262 262
263 263 m_chartWidget->addSeries(newSeries);
264 264 }
265 265
266 266 setCurrentSeries(newSeries);
267 267 }
268 268
269 269 void MainWidget::setCurrentSeries(QChartSeries *series)
270 270 {
271 271 m_currentSeries = series;
272 272 switch (m_currentSeries->type()) {
273 273 case QChartSeries::SeriesTypeLine:
274 274 break;
275 275 case QChartSeries::SeriesTypeScatter:
276 276 break;
277 277 case QChartSeries::SeriesTypePie:
278 278 break;
279 279 case QChartSeries::SeriesTypeBar:
280 280 qDebug() << "setCurrentSeries (bar)";
281 281 break;
282 282 default:
283 283 Q_ASSERT(false);
284 284 break;
285 285 }
286 286 }
287 287
288 288 void MainWidget::testDataChanged(int itemIndex)
289 289 {
290 290 qDebug() << "testDataChanged: " << itemIndex;
291 291
292 292 // switch (itemIndex) {
293 293 // case 0: {
294 294 // QList<QChartDataPoint> data;
295 295 // for (int x = 0; x < 20; x++) {
296 296 // data.append(QChartDataPoint() << x << x / 2);
297 297 // }
298 298 // m_chartWidget->setData(data);
299 299 // break;
300 300 // }
301 301 // case 1: {
302 302 // QList<QChartDataPoint> data;
303 303 // for (int x = 0; x < 100; x++) {
304 304 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
305 305 // }
306 306 // m_chartWidget->setData(data);
307 307 // break;
308 308 // }
309 309 // case 2: {
310 310 // QList<QChartDataPoint> data;
311 311 // for (int x = 0; x < 1000; x++) {
312 312 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
313 313 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
314 314 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
315 315 // }
316 316 // m_chartWidget->setData(data);
317 317 // break;
318 318 // }
319 319 // default:
320 320 // break;
321 321 // }
322 322 }
323 323
324 324 void MainWidget::backgroundChanged(int itemIndex)
325 325 {
326 326 qDebug() << "backgroundChanged: " << itemIndex;
327 327 }
328 328
329 329 void MainWidget::autoScaleChanged(int value)
330 330 {
331 331 if (value) {
332 332 // TODO: enable auto scaling
333 333 } else {
334 334 // TODO: set scaling manually (and disable auto scaling)
335 335 }
336 336
337 337 m_xMinSpin->setEnabled(!value);
338 338 m_xMaxSpin->setEnabled(!value);
339 339 m_yMinSpin->setEnabled(!value);
340 340 m_yMaxSpin->setEnabled(!value);
341 341 }
342 342
343 343 void MainWidget::xMinChanged(int value)
344 344 {
345 345 qDebug() << "xMinChanged: " << value;
346 346 }
347 347
348 348 void MainWidget::xMaxChanged(int value)
349 349 {
350 350 qDebug() << "xMaxChanged: " << value;
351 351 }
352 352
353 353 void MainWidget::yMinChanged(int value)
354 354 {
355 355 qDebug() << "yMinChanged: " << value;
356 356 }
357 357
358 358 void MainWidget::yMaxChanged(int value)
359 359 {
360 360 qDebug() << "yMaxChanged: " << value;
361 361 }
362 362
363 363 void MainWidget::changeChartTheme(int themeIndex)
364 364 {
365 365 qDebug() << "changeChartTheme: " << themeIndex;
366 366 m_chartWidget->setTheme((QChart::ChartThemeId) themeIndex);
367 367 }
368 368
369 369 void MainWidget::setPieSizeFactor(double size)
370 370 {
371 371 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
372 372 if (pie)
373 373 pie->setSizeFactor(qreal(size));
374 374 }
375 375
376 376 void MainWidget::setPiePosition(int position)
377 377 {
378 378 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
379 379 if (pie)
380 380 pie->setPosition((QPieSeries::PiePosition) position);
381 381 }
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now