##// END OF EJS Templates
Added size factor property to pie
Tero Ahola -
r60:0be2c26f8dc1
parent child
Show More
@@ -1,15 +1,15
1 1 !include(common.pri) {
2 error('missing common.pri')
2 error('missing common.pri')
3 3 }
4 4
5 5 TEMPLATE = subdirs
6 SUBDIRS += src example test
6 SUBDIRS += src example test
7 7 CONFIG += ordered
8 8 QMAKE_CXXFLAGS += -g -Wall
9 9 unix:QMAKE_DISTCLEAN += -r build bin
10 10 win32:QMAKE_DISTCLEAN += /Q build bin
11 11
12 12 # install feature file
13 13 feature.path = $$[QT_INSTALL_DATA]/mkspecs/features
14 14 feature.files = $$PWD/features/qtcommercialchart.prf
15 15 INSTALLS += feature
@@ -1,32 +1,32
1 1 integrated_build:{
2 2 message('Internal build within charts core source tree')
3 3 INCLUDEPATH += $$CHART_BUILD_HEADER_DIR
4 4 LIBS += -L $$CHART_BUILD_LIB_DIR -Wl,-rpath,$$CHART_BUILD_LIB_DIR
5 5 DESTDIR = $$CHART_BUILD_BIN_DIR
6 6 CONFIG(debug, debug|release) {
7 7 LIBS += -lQtCommercialChartd
8 8
9 9 #this is ugly hack to work around missing rpath, it simply copies lib
10 10 win32:{
11 11 copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll
12 copylib.commands = $$QMAKE_COPY $$CHART_BUILD_LIB_DIR\QtCommercialChartd.dll $$CHART_BUILD_BIN_DIR
12 copylib.commands = $$QMAKE_COPY $$CHART_BUILD_LIB_DIR\\QtCommercialChartd.dll $$CHART_BUILD_BIN_DIR
13 13 copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChartd.dll
14 14 PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll
15 15 QMAKE_EXTRA_TARGETS +=copylib
16 16 }
17 17
18 18 } else {
19 LIBS += -lQtCommercialChart
19 LIBS += -lQtCommercialChart
20 20
21 #this is ugly hack to work around missing rpath, it simply copies lib
22 win32:{
23 copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChart
24 copylib.commands = $$QMAKE_COPY $$CHART_BUILD_LIB_DIR\QtCommercialChart.dll $$CHART_BUILD_BIN_DIR
25 copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChart.dll
26 PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChart
27 QMAKE_EXTRA_TARGETS +=copylib
21 #this is ugly hack to work around missing rpath, it simply copies lib
22 win32: {
23 copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChart
24 copylib.commands = $$QMAKE_COPY $$CHART_BUILD_LIB_DIR\\QtCommercialChart.dll $$CHART_BUILD_BIN_DIR
25 copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChart.dll
26 PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChart
27 QMAKE_EXTRA_TARGETS +=copylib
28 28 }
29 29 }
30 }else{
30 } else {
31 31 CONFIG+=qtcommercialchart
32 32 }
@@ -1,75 +1,76
1 1 #include "pieslice.h"
2 2 #include <QPainter>
3 3 #include <QDebug>
4 4
5 5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 PieSlice::PieSlice(const QColor& color, qreal startAngle, qreal span)
7 PieSlice::PieSlice(const QColor& color, qreal startAngle, qreal span, QRectF rect)
8 8 : m_color(color),
9 9 m_startAngle(startAngle),
10 m_span(span)
10 m_span(span),
11 m_rect(rect)
11 12 {
12 13 setAcceptHoverEvents(true);
13 14 }
14 15
15 16 PieSlice::~PieSlice()
16 17 {
17 18 }
18 19
19 20 QRectF PieSlice::boundingRect() const
20 21 {
21 return parentItem()->boundingRect();
22 return m_rect;
22 23 }
23 24
24 25 QPainterPath PieSlice::shape() const
25 26 {
26 27 qreal angle = (-m_startAngle) + (90);
27 28 qreal span = -m_span;
28 29
29 30 QPainterPath path;
30 31 path.moveTo(boundingRect().center());
31 32 path.arcTo(boundingRect(), angle, span);
32 33
33 34 // TODO: draw the shape so that it might have a hole in the center
34 35 // - Sin & Cos will be needed to find inner/outer arc endpoints
35 36
36 37 // dx, dy are offsets from the center
37 38 //qreal l = boundingRect().height();
38 39 //qreal dx = qSin(angle*(M_PI/180)) * l;
39 40 //qreal dy = qCos(angle*(M_PI/180)) * l;
40 41
41 42 // TODO: exploded slice?
42 43
43 44 return path;
44 45 }
45 46
46 47 void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
47 48 {
48 49 // Setup painter
49 50 painter->setBrush(m_color);
50 51 QPen pen;
51 52 //pen.setColor(m_color.darker());
52 53 pen.setColor(Qt::gray);
53 54 pen.setWidth(1);
54 55 painter->setPen(pen);
55 56
56 57 // From Qt docs:
57 58 // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360).
58 59 // Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction.
59 60 // Zero degrees is at the 3 o'clock position.
60 61 //
61 62 // For sake of simplicity convert this so that zero degrees is at 12 o'clock and full circle is 360.
62 63 //qreal angle = (-m_startAngle*16) + (90*16);
63 64 //qreal span = -m_span*16;
64 65 //painter->drawPie(boundingRect(), angle, span);
65 66
66 67 painter->drawPath(shape());
67 68 }
68 69
69 70 void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event)
70 71 {
71 72 QGraphicsItem::hoverEnterEvent(event);
72 73 qDebug() << "hover" << m_color << m_startAngle << m_span;
73 74 }
74 75
75 76 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,31 +1,32
1 1 #ifndef PIESLICE_H
2 2 #define PIESLICE_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include <QGraphicsItem>
6 6 #include <QRectF>
7 7 #include <QColor>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class PieSlice : public QGraphicsItem
12 12 {
13 13 public:
14 PieSlice(const QColor& color, qreal startAngle, qreal span);
14 PieSlice(const QColor& color, qreal startAngle, qreal span, QRectF rect);
15 15 ~PieSlice();
16 16
17 17 public: // from QGraphicsItem
18 18 QRectF boundingRect() const;
19 19 QPainterPath shape() const;
20 20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
21 21 void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
22 22
23 private:
23 public:
24 24 QColor m_color;
25 25 qreal m_startAngle;
26 26 qreal m_span;
27 QRectF m_rect;
27 28 };
28 29
29 30 QTCOMMERCIALCHART_END_NAMESPACE
30 31
31 32 #endif // PIESLICE_H
@@ -1,54 +1,91
1 1 #include "qpieseries.h"
2 2 #include "pieslice.h"
3 3 #include <QGraphicsObject>
4 4 #include <QDebug>
5 5
6 6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 7
8 8 QPieSeries::QPieSeries(QList<qreal> x, QGraphicsObject *parent) :
9 9 QChartSeries(parent),
10 m_x(x)
10 m_x(x),
11 m_sizeFactor(1.0)
11 12 {
12 13 // Create slices
13 14 qreal fullPie = 360;
14 15 qreal total = 0;
15 16 foreach (qreal value, m_x)
16 17 total += value;
17 18
18 19 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent);
19 20 Q_ASSERT(parentItem);
21 m_chartSize = parentItem->boundingRect();
20 22 qreal angle = 0;
21 23 // TODO: no need to create new slices in case size changed; we should re-use the existing ones
22 24 foreach (qreal value, m_x) {
23 25 qreal span = value / total * fullPie;
24 PieSlice *slice = new PieSlice(randomColor(), angle, span);
26 PieSlice *slice = new PieSlice(randomColor(), angle, span, parentItem->boundingRect());
25 27 slice->setParentItem(parentItem);
26 28 m_slices.append(slice);
27 29 angle += span;
28 30 }
31
32 resizeSlices(m_chartSize);
29 33 }
30 34
31 35 QPieSeries::~QPieSeries()
32 36 {
37 while (m_slices.count())
38 delete m_slices.takeLast();
33 39 }
34 40
35 void QPieSeries::chartSizeChanged(QRectF /*rect*/)
41 void QPieSeries::chartSizeChanged(QRectF chartRect)
36 42 {
43 // TODO: allow user setting the size?
44 // TODO: allow user defining the margins?
45 m_chartSize = chartRect;
46 resizeSlices(m_chartSize);
47 }
48
49 void QPieSeries::resizeSlices(QRectF rect)
50 {
51 QRectF tempRect = rect;
52 if (tempRect.width() < tempRect.height()) {
53 tempRect.setWidth(tempRect.width() * m_sizeFactor);
54 tempRect.setHeight(tempRect.width());
55 tempRect.moveCenter(rect.center());
56 } else {
57 tempRect.setHeight(tempRect.height() * m_sizeFactor);
58 tempRect.setWidth(tempRect.height());
59 tempRect.moveCenter(rect.center());
60 }
61
62 foreach (PieSlice *slice, m_slices)
63 slice->m_rect = tempRect;
64 }
65
66 void QPieSeries::setSizeFactor(qreal factor)
67 {
68 if (factor > 0.0)
69 m_sizeFactor = factor;
70 resizeSlices(m_chartSize);
71
72 // Initiate update via the parent graphics item
73 // TODO: potential issue: what if this function is called from the parent context?
74 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent());
75 Q_ASSERT(parentItem);
76 parentItem->update();
37 77 }
38 78
39 79 QColor QPieSeries::randomColor()
40 80 {
41 81 QColor c;
42 82 c.setRed(qrand() % 255);
43 83 c.setGreen(qrand() % 255);
44 84 c.setBlue(qrand() % 255);
45 85 return c;
46 86 }
47 87
48 void QPieSeries::setData(QList<int> data)
49 {
50 }
51 88
52 89 #include "moc_qpieseries.cpp"
53 90
54 91 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,40 +1,44
1 1 #ifndef PIESERIES_H
2 2 #define PIESERIES_H
3 3
4 4 #include "qchartseries.h"
5 5 #include <QObject>
6 6 #include <QRectF>
7 7 #include <QColor>
8 8
9 9 class QGraphicsObject;
10 10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 11 class PieSlice;
12 12
13 13 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries
14 14 {
15 15 Q_OBJECT
16
16 17 public:
17 18 // TODO: use a generic data class instead of x and y
18 19 QPieSeries(QList<qreal> x, QGraphicsObject *parent = 0);
19 20 ~QPieSeries();
20 21 QColor randomColor();
21 void setData(QList<int> data);
22 void setSizeFactor(qreal sizeFactor);
23 qreal sizeFactor() { return m_sizeFactor; }
22 24
23 25 public: // from QChartSeries
24 26 QChartSeriesType type() const { return QChartSeries::SeriesTypePie; }
25 27
26 28 public Q_SLOTS:
27 29 void chartSizeChanged(QRectF rect);
28 30
29 31 private:
32 void resizeSlices(QRectF rect);
30 33 //Q_DECLARE_PRIVATE(QPieSeries)
31 34 Q_DISABLE_COPY(QPieSeries)
32 35 // TODO: move the followin to internal impl
33 36 QList<qreal> m_x;
34 37 QList<PieSlice*> m_slices;
35 QSizeF m_size;
38 QRectF m_chartSize;
39 qreal m_sizeFactor;
36 40 };
37 41
38 42 QTCOMMERCIALCHART_END_NAMESPACE
39 43
40 44 #endif // PIESERIES_H
@@ -1,27 +1,25
1 include( ../../common.pri )
2 include( ../../integrated.pri )
1 !include( ../../common.pri ) {
2 error( "Couldn't find the common.pri file!" )
3 }
4 !include( ../../integrated.pri ) {
5 error( "Couldn't find the integrated.pri file !")
6 }
3 7
4 8 TARGET = chartwidgettest
5 9 TEMPLATE = app
6 10
7 11 QT += core gui
8 12 contains(QT_MAJOR_VERSION, 5) {
9 13 QT += widgets
10 14 }
11 15
12
13 16 OBJECTS_DIR = tmp
14 17 MOC_DIR = tmp
15 18
16 19 SOURCES += main.cpp \
17 20 mainwidget.cpp \
18 # qscatterseries.cpp \
19 # qseriespointgraphicsitem.cpp \
20 21 dataseriedialog.cpp
21 22
22 23 HEADERS += \
23 24 mainwidget.h \
24 # qscatterseries.h \
25 # qseriespointgraphicsitem.h \
26 25 dataseriedialog.h
27
@@ -1,241 +1,271
1 1 #include "mainwidget.h"
2 2 #include "dataseriedialog.h"
3 #include "qchartseries.h"
4 #include "qpieseries.h"
3 5 #include <qxychartseries.h>
4 6 #include <QPushButton>
5 7 #include <QComboBox>
6 8 #include <QSpinBox>
7 9 #include <QCheckBox>
8 10 #include <QGridLayout>
9 11 #include <QHBoxLayout>
10 12 #include <QLabel>
11 13 #include <QSpacerItem>
12 14 #include <QMessageBox>
13 15 #include <cmath>
14 16 #include <QDebug>
15 17
16 18 QTCOMMERCIALCHART_USE_NAMESPACE
17 19
18 20 MainWidget::MainWidget(QWidget *parent) :
19 21 QWidget(parent)
20 22 {
21 23 QPushButton *addSeriesButton = new QPushButton("Add series");
22 24 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
23 25
24 26 // Chart background
25 27 QComboBox *backgroundCombo = new QComboBox(this);
26 28 backgroundCombo->addItem("None");
27 29 backgroundCombo->addItem("TODO Grid");
28 30 backgroundCombo->addItem("TODO Image");
29 31 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
30 32 this, SLOT(backgroundChanged(int)));
31 33
32 34 // Axis
33 35 // TODO: multiple axes?
34 36 m_autoScaleCheck = new QCheckBox("Automatic scaling");
35 37 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
36 38 // Allow setting also non-sense values (like -2147483648 and 2147483647)
37 39 m_xMinSpin = new QSpinBox();
38 40 m_xMinSpin->setMinimum(INT_MIN);
39 41 m_xMinSpin->setMaximum(INT_MAX);
40 42 m_xMinSpin->setValue(0);
41 43 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
42 44 m_xMaxSpin = new QSpinBox();
43 45 m_xMaxSpin->setMinimum(INT_MIN);
44 46 m_xMaxSpin->setMaximum(INT_MAX);
45 47 m_xMaxSpin->setValue(10);
46 48 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
47 49 m_yMinSpin = new QSpinBox();
48 50 m_yMinSpin->setMinimum(INT_MIN);
49 51 m_yMinSpin->setMaximum(INT_MAX);
50 52 m_yMinSpin->setValue(0);
51 53 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
52 54 m_yMaxSpin = new QSpinBox();
53 55 m_yMaxSpin->setMinimum(INT_MIN);
54 56 m_yMaxSpin->setMaximum(INT_MAX);
55 57 m_yMaxSpin->setValue(10);
56 58 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
57 59
58 60 QGridLayout *grid = new QGridLayout();
59 QHBoxLayout *hbox = new QHBoxLayout();
61 QGridLayout *mainLayout = new QGridLayout();
60 62 //grid->addWidget(new QLabel("Add series:"), 0, 0);
61 63 grid->addWidget(addSeriesButton, 0, 1);
62 64 grid->addWidget(new QLabel("Background:"), 2, 0);
63 65 grid->addWidget(backgroundCombo, 2, 1);
64 66 grid->addWidget(m_autoScaleCheck, 3, 0);
65 67 grid->addWidget(new QLabel("x min:"), 4, 0);
66 68 grid->addWidget(m_xMinSpin, 4, 1);
67 69 grid->addWidget(new QLabel("x max:"), 5, 0);
68 70 grid->addWidget(m_xMaxSpin, 5, 1);
69 71 grid->addWidget(new QLabel("y min:"), 6, 0);
70 72 grid->addWidget(m_yMinSpin, 6, 1);
71 73 grid->addWidget(new QLabel("y max:"), 7, 0);
72 74 grid->addWidget(m_yMaxSpin, 7, 1);
73 75 // add row with empty label to make all the other rows static
74 76 grid->addWidget(new QLabel(""), 8, 0);
75 77 grid->setRowStretch(8, 1);
76 78
77 hbox->addLayout(grid);
79 mainLayout->addLayout(grid, 0, 0);
80
81 // Scatter specific settings
82 m_scatterLayout = new QGridLayout();
83 m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
84 m_scatterLayout->setEnabled(false);
85
86 // Pie specific settings
87 m_pieLayout = new QGridLayout();
88 m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
89 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
90 pieSizeSpin->setMinimum(LONG_MIN);
91 pieSizeSpin->setMaximum(LONG_MAX);
92 pieSizeSpin->setValue(1.0);
93 pieSizeSpin->setSingleStep(0.1);
94 connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
95 m_pieLayout->setEnabled(false);
96 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
97
98 mainLayout->addLayout(m_scatterLayout, 1, 0);
99 mainLayout->addLayout(m_pieLayout, 2, 0);
78 100
79 101 m_chartWidget = new QChartWidget(this);
80 102 //m_chartWidget->setColor(Qt::red);
81 hbox->addWidget(m_chartWidget);
103 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
82 104 // hbox->setStretch(1, 1);
83 105
84 setLayout(hbox);
106 setLayout(mainLayout);
85 107
86 108 m_autoScaleCheck->setChecked(true);
87 chartTypeChanged(4);
88 109 testDataChanged(0);
89 110 }
90 111
91 112 void MainWidget::addSeries()
92 113 {
93 DataSerieDialog dialog(m_defaultSeries, this);
114 DataSerieDialog dialog(m_defaultSeriesName, this);
94 115 connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
95 116 dialog.exec();
96 117 }
97 118
98 119 void MainWidget::addSeries(QString series, QString data)
99 120 {
100 121 qDebug() << "addSeries: " << series << " data: " << data;
101 m_defaultSeries = series;
102
103 QXYChartSeries* series0 = QXYChartSeries::create();
122 m_defaultSeriesName = series;
123 QChartSeries *newSeries = QXYChartSeries::create();
104 124
105 125 // TODO: a dedicated data class for storing x and y values
106 126 QList<qreal> x;
107 127 QList<qreal> y;
108 128
109 129 if (data == "linear") {
110 130 for (int i = 0; i < 20; i++) {
111 131 x.append(i);
112 132 y.append(i);
113 133 }
114 134 for (int i = 0; i < 20; i++)
115 series0->add(i, i);
135 ((QXYChartSeries *)newSeries)->add(i, i);
116 136 } else if (data == "linear, 1M") {
117 137 for (int i = 0; i < 10000; i++) {
118 138 x.append(i);
119 139 y.append(20);
120 140 }
121 141 for (int i = 0; i < 1000000; i++)
122 series0->add(i, 10);
142 ((QXYChartSeries *)newSeries)->add(i, 10);
123 143 } else if (data == "SIN") {
124 144 for (int i = 0; i < 100; i++) {
125 145 x.append(i);
126 146 y.append(abs(sin(3.14159265358979 / 50 * i) * 100));
127 147 }
128 148 for (int i = 0; i < 100; i++)
129 series0->add(i, abs(sin(3.14159265358979 / 50 * i) * 100));
149 ((QXYChartSeries *)newSeries)->add(i, abs(sin(3.14159265358979 / 50 * i) * 100));
130 150 } else if (data == "SIN + random") {
131 151 for (qreal i = 0; i < 100; i += 0.1) {
132 152 x.append(i + (rand() % 5));
133 153 y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
134 154 }
135 155 for (qreal i = 0; i < 100; i += 0.1)
136 series0->add(i + (rand() % 5), abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
156 ((QXYChartSeries *)newSeries)->add(i + (rand() % 5), abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
137 157 } else {
138 158 // TODO: check if data has a valid file name
139 159 }
140 160
141 161 // TODO: color of the series
142 162 if (series == "Scatter") {
143 /*QChartSeries* scatterSeries = */
144 m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypeScatter);
163 newSeries = m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypeScatter);
145 164 } else if (series == "Pie") {
146 m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypePie);
165 newSeries = m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypePie);
147 166 } else if (series == "Line") {
148 m_chartWidget->addSeries(series0);
167 m_chartWidget->addSeries(newSeries);
149 168 } else {
150 169 // TODO
151 170 }
171
172 setCurrentSeries(newSeries);
152 173 }
153 174
154 void MainWidget::chartTypeChanged(int itemIndex)
175 void MainWidget::setCurrentSeries(QChartSeries *series)
155 176 {
156 // TODO: change chart type
157 switch (itemIndex) {
158 case 4:
159 //m_chartWidget->setType(4);
177 m_currentSeries = series;
178 switch (m_currentSeries->type()) {
179 case QChartSeries::SeriesTypeLine:
160 180 break;
161 default: {
162 //m_chartWidget->setType(0);
181 case QChartSeries::SeriesTypeScatter:
182 break;
183 case QChartSeries::SeriesTypePie:
184 break;
185 default:
186 Q_ASSERT(false);
163 187 break;
164 }
165 188 }
166 189 }
167 190
168 191 void MainWidget::testDataChanged(int itemIndex)
169 192 {
170 193 qDebug() << "testDataChanged: " << itemIndex;
171 194
172 195 // switch (itemIndex) {
173 196 // case 0: {
174 197 // QList<QChartDataPoint> data;
175 198 // for (int x = 0; x < 20; x++) {
176 199 // data.append(QChartDataPoint() << x << x / 2);
177 200 // }
178 201 // m_chartWidget->setData(data);
179 202 // break;
180 203 // }
181 204 // case 1: {
182 205 // QList<QChartDataPoint> data;
183 206 // for (int x = 0; x < 100; x++) {
184 207 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
185 208 // }
186 209 // m_chartWidget->setData(data);
187 210 // break;
188 211 // }
189 212 // case 2: {
190 213 // QList<QChartDataPoint> data;
191 214 // for (int x = 0; x < 1000; x++) {
192 215 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
193 216 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
194 217 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
195 218 // }
196 219 // m_chartWidget->setData(data);
197 220 // break;
198 221 // }
199 222 // default:
200 223 // break;
201 224 // }
202 225 }
203 226
204 227 void MainWidget::backgroundChanged(int itemIndex)
205 228 {
206 229 qDebug() << "backgroundChanged: " << itemIndex;
207 230 }
208 231
209 232 void MainWidget::autoScaleChanged(int value)
210 233 {
211 234 if (value) {
212 235 // TODO: enable auto scaling
213 236 } else {
214 237 // TODO: set scaling manually (and disable auto scaling)
215 238 }
216 239
217 240 m_xMinSpin->setEnabled(!value);
218 241 m_xMaxSpin->setEnabled(!value);
219 242 m_yMinSpin->setEnabled(!value);
220 243 m_yMaxSpin->setEnabled(!value);
221 244 }
222 245
223 246 void MainWidget::xMinChanged(int value)
224 247 {
225 248 qDebug() << "xMinChanged: " << value;
226 249 }
227 250
228 251 void MainWidget::xMaxChanged(int value)
229 252 {
230 253 qDebug() << "xMaxChanged: " << value;
231 254 }
232 255
233 256 void MainWidget::yMinChanged(int value)
234 257 {
235 258 qDebug() << "yMinChanged: " << value;
236 259 }
237 260
238 261 void MainWidget::yMaxChanged(int value)
239 262 {
240 263 qDebug() << "yMaxChanged: " << value;
241 264 }
265
266 void MainWidget::setPieSizeFactor(double size)
267 {
268 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
269 Q_ASSERT(pie);
270 pie->setSizeFactor(qreal(size));
271 }
@@ -1,43 +1,48
1 1 #ifndef MAINWIDGET_H
2 2 #define MAINWIDGET_H
3 3
4 4 #include <qchartglobal.h>
5 5 #include <qchartwidget.h>
6 6 #include <QWidget>
7 7
8 8 class QSpinBox;
9 9 class QCheckBox;
10 class QGridLayout;
10 11
11 12 QTCOMMERCIALCHART_USE_NAMESPACE
12 13
13 14 class MainWidget : public QWidget
14 15 {
15 16 Q_OBJECT
16 17 public:
17 18 explicit MainWidget(QWidget *parent = 0);
18 19
19 20 signals:
20 21
21 22 private slots:
22 void chartTypeChanged(int itemIndex);
23 23 void addSeries();
24 24 void addSeries(QString series, QString data);
25 25 void testDataChanged(int itemIndex);
26 26 void backgroundChanged(int itemIndex);
27 27 void autoScaleChanged(int value);
28 28 void xMinChanged(int value);
29 29 void xMaxChanged(int value);
30 30 void yMinChanged(int value);
31 31 void yMaxChanged(int value);
32 void setCurrentSeries(QChartSeries *series);
33 void setPieSizeFactor(double margin);
32 34
33 35 private:
34 36 QChartWidget *m_chartWidget;
35 37 QCheckBox *m_autoScaleCheck;
36 38 QSpinBox *m_xMinSpin;
37 39 QSpinBox *m_xMaxSpin;
38 40 QSpinBox *m_yMinSpin;
39 41 QSpinBox *m_yMaxSpin;
40 QString m_defaultSeries;
42 QString m_defaultSeriesName;
43 QChartSeries *m_currentSeries;
44 QGridLayout *m_scatterLayout;
45 QGridLayout *m_pieLayout;
41 46 };
42 47
43 48 #endif // MAINWIDGET_H
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