@@ -1,9 +1,9 | |||||
1 | !include(common.pri) { |
|
1 | !include(common.pri) { | |
2 | error('missing common.pri') |
|
2 | error('missing common.pri') | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TEMPLATE = subdirs |
|
5 | TEMPLATE = subdirs | |
6 |
SUBDIRS += |
|
6 | SUBDIRS += src example test | |
7 | CONFIG += ordered |
|
7 | CONFIG += ordered | |
8 | QMAKE_CXXFLAGS += -g -Wall |
|
8 | QMAKE_CXXFLAGS += -g -Wall | |
9 | unix:QMAKE_DISTCLEAN += -r build bin |
|
9 | unix:QMAKE_DISTCLEAN += -r build bin |
@@ -9,24 +9,24 integrated_build:{ | |||||
9 | #this is ugly hack to work around missing rpath, it simply copies lib |
|
9 | #this is ugly hack to work around missing rpath, it simply copies lib | |
10 | win32:{ |
|
10 | win32:{ | |
11 | copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll |
|
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 | copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChartd.dll |
|
13 | copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChartd.dll | |
14 | PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll |
|
14 | PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll | |
15 | QMAKE_EXTRA_TARGETS +=copylib |
|
15 | QMAKE_EXTRA_TARGETS +=copylib | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | } else { |
|
18 | } else { | |
19 | LIBS += -lQtCommercialChart |
|
19 | LIBS += -lQtCommercialChart | |
20 |
|
20 | |||
21 | #this is ugly hack to work around missing rpath, it simply copies lib |
|
21 | #this is ugly hack to work around missing rpath, it simply copies lib | |
22 | win32:{ |
|
22 | win32: { | |
23 | copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChart |
|
23 | copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChart | |
24 | copylib.commands = $$QMAKE_COPY $$CHART_BUILD_LIB_DIR\QtCommercialChart.dll $$CHART_BUILD_BIN_DIR |
|
24 | copylib.commands = $$QMAKE_COPY $$CHART_BUILD_LIB_DIR\\QtCommercialChart.dll $$CHART_BUILD_BIN_DIR | |
25 | copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChart.dll |
|
25 | copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChart.dll | |
26 | PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChart |
|
26 | PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChart | |
27 | QMAKE_EXTRA_TARGETS +=copylib |
|
27 | QMAKE_EXTRA_TARGETS +=copylib | |
28 | } |
|
28 | } | |
29 | } |
|
29 | } | |
30 | }else{ |
|
30 | } else { | |
31 | CONFIG+=qtcommercialchart |
|
31 | CONFIG+=qtcommercialchart | |
32 | } |
|
32 | } |
@@ -4,10 +4,11 | |||||
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
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 | : m_color(color), |
|
8 | : m_color(color), | |
9 | m_startAngle(startAngle), |
|
9 | m_startAngle(startAngle), | |
10 | m_span(span) |
|
10 | m_span(span), | |
|
11 | m_rect(rect) | |||
11 | { |
|
12 | { | |
12 | setAcceptHoverEvents(true); |
|
13 | setAcceptHoverEvents(true); | |
13 | } |
|
14 | } | |
@@ -18,7 +19,7 PieSlice::~PieSlice() | |||||
18 |
|
19 | |||
19 | QRectF PieSlice::boundingRect() const |
|
20 | QRectF PieSlice::boundingRect() const | |
20 | { |
|
21 | { | |
21 | return parentItem()->boundingRect(); |
|
22 | return m_rect; | |
22 | } |
|
23 | } | |
23 |
|
24 | |||
24 | QPainterPath PieSlice::shape() const |
|
25 | QPainterPath PieSlice::shape() const |
@@ -11,7 +11,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
11 | class PieSlice : public QGraphicsItem |
|
11 | class PieSlice : public QGraphicsItem | |
12 | { |
|
12 | { | |
13 | public: |
|
13 | public: | |
14 | PieSlice(const QColor& color, qreal startAngle, qreal span); |
|
14 | PieSlice(const QColor& color, qreal startAngle, qreal span, QRectF rect); | |
15 | ~PieSlice(); |
|
15 | ~PieSlice(); | |
16 |
|
16 | |||
17 | public: // from QGraphicsItem |
|
17 | public: // from QGraphicsItem | |
@@ -20,10 +20,11 public: // from QGraphicsItem | |||||
20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
21 | void hoverEnterEvent(QGraphicsSceneHoverEvent * event); |
|
21 | void hoverEnterEvent(QGraphicsSceneHoverEvent * event); | |
22 |
|
22 | |||
23 | private: |
|
23 | public: | |
24 | QColor m_color; |
|
24 | QColor m_color; | |
25 | qreal m_startAngle; |
|
25 | qreal m_startAngle; | |
26 | qreal m_span; |
|
26 | qreal m_span; | |
|
27 | QRectF m_rect; | |||
27 | }; |
|
28 | }; | |
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_END_NAMESPACE |
|
30 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -7,7 +7,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
7 |
|
7 | |||
8 | QPieSeries::QPieSeries(QList<qreal> x, QGraphicsObject *parent) : |
|
8 | QPieSeries::QPieSeries(QList<qreal> x, QGraphicsObject *parent) : | |
9 | QChartSeries(parent), |
|
9 | QChartSeries(parent), | |
10 | m_x(x) |
|
10 | m_x(x), | |
|
11 | m_sizeFactor(1.0) | |||
11 | { |
|
12 | { | |
12 | // Create slices |
|
13 | // Create slices | |
13 | qreal fullPie = 360; |
|
14 | qreal fullPie = 360; | |
@@ -17,23 +18,62 QPieSeries::QPieSeries(QList<qreal> x, QGraphicsObject *parent) : | |||||
17 |
|
18 | |||
18 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent); |
|
19 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent); | |
19 | Q_ASSERT(parentItem); |
|
20 | Q_ASSERT(parentItem); | |
|
21 | m_chartSize = parentItem->boundingRect(); | |||
20 | qreal angle = 0; |
|
22 | qreal angle = 0; | |
21 | // TODO: no need to create new slices in case size changed; we should re-use the existing ones |
|
23 | // TODO: no need to create new slices in case size changed; we should re-use the existing ones | |
22 | foreach (qreal value, m_x) { |
|
24 | foreach (qreal value, m_x) { | |
23 | qreal span = value / total * fullPie; |
|
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 | slice->setParentItem(parentItem); |
|
27 | slice->setParentItem(parentItem); | |
26 | m_slices.append(slice); |
|
28 | m_slices.append(slice); | |
27 | angle += span; |
|
29 | angle += span; | |
28 | } |
|
30 | } | |
|
31 | ||||
|
32 | resizeSlices(m_chartSize); | |||
29 | } |
|
33 | } | |
30 |
|
34 | |||
31 | QPieSeries::~QPieSeries() |
|
35 | QPieSeries::~QPieSeries() | |
32 | { |
|
36 | { | |
|
37 | while (m_slices.count()) | |||
|
38 | delete m_slices.takeLast(); | |||
33 | } |
|
39 | } | |
34 |
|
40 | |||
35 |
void QPieSeries::chartSizeChanged(QRectF |
|
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 | QColor QPieSeries::randomColor() |
|
79 | QColor QPieSeries::randomColor() | |
@@ -45,9 +85,6 QColor QPieSeries::randomColor() | |||||
45 | return c; |
|
85 | return c; | |
46 | } |
|
86 | } | |
47 |
|
87 | |||
48 | void QPieSeries::setData(QList<int> data) |
|
|||
49 | { |
|
|||
50 | } |
|
|||
51 |
|
88 | |||
52 | #include "moc_qpieseries.cpp" |
|
89 | #include "moc_qpieseries.cpp" | |
53 |
|
90 |
@@ -13,12 +13,14 class PieSlice; | |||||
13 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries |
|
13 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
|
16 | ||||
16 | public: |
|
17 | public: | |
17 | // TODO: use a generic data class instead of x and y |
|
18 | // TODO: use a generic data class instead of x and y | |
18 | QPieSeries(QList<qreal> x, QGraphicsObject *parent = 0); |
|
19 | QPieSeries(QList<qreal> x, QGraphicsObject *parent = 0); | |
19 | ~QPieSeries(); |
|
20 | ~QPieSeries(); | |
20 | QColor randomColor(); |
|
21 | QColor randomColor(); | |
21 | void setData(QList<int> data); |
|
22 | void setSizeFactor(qreal sizeFactor); | |
|
23 | qreal sizeFactor() { return m_sizeFactor; } | |||
22 |
|
24 | |||
23 | public: // from QChartSeries |
|
25 | public: // from QChartSeries | |
24 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } |
|
26 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } | |
@@ -27,12 +29,14 public Q_SLOTS: | |||||
27 | void chartSizeChanged(QRectF rect); |
|
29 | void chartSizeChanged(QRectF rect); | |
28 |
|
30 | |||
29 | private: |
|
31 | private: | |
|
32 | void resizeSlices(QRectF rect); | |||
30 | //Q_DECLARE_PRIVATE(QPieSeries) |
|
33 | //Q_DECLARE_PRIVATE(QPieSeries) | |
31 | Q_DISABLE_COPY(QPieSeries) |
|
34 | Q_DISABLE_COPY(QPieSeries) | |
32 | // TODO: move the followin to internal impl |
|
35 | // TODO: move the followin to internal impl | |
33 | QList<qreal> m_x; |
|
36 | QList<qreal> m_x; | |
34 | QList<PieSlice*> m_slices; |
|
37 | QList<PieSlice*> m_slices; | |
35 | QSizeF m_size; |
|
38 | QRectF m_chartSize; | |
|
39 | qreal m_sizeFactor; | |||
36 | }; |
|
40 | }; | |
37 |
|
41 | |||
38 | QTCOMMERCIALCHART_END_NAMESPACE |
|
42 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,5 +1,9 | |||||
1 | include( ../../common.pri ) |
|
1 | !include( ../../common.pri ) { | |
2 | include( ../../integrated.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 | TARGET = chartwidgettest |
|
8 | TARGET = chartwidgettest | |
5 | TEMPLATE = app |
|
9 | TEMPLATE = app | |
@@ -9,19 +13,13 contains(QT_MAJOR_VERSION, 5) { | |||||
9 | QT += widgets |
|
13 | QT += widgets | |
10 | } |
|
14 | } | |
11 |
|
15 | |||
12 |
|
||||
13 | OBJECTS_DIR = tmp |
|
16 | OBJECTS_DIR = tmp | |
14 | MOC_DIR = tmp |
|
17 | MOC_DIR = tmp | |
15 |
|
18 | |||
16 | SOURCES += main.cpp \ |
|
19 | SOURCES += main.cpp \ | |
17 | mainwidget.cpp \ |
|
20 | mainwidget.cpp \ | |
18 | # qscatterseries.cpp \ |
|
|||
19 | # qseriespointgraphicsitem.cpp \ |
|
|||
20 | dataseriedialog.cpp |
|
21 | dataseriedialog.cpp | |
21 |
|
22 | |||
22 | HEADERS += \ |
|
23 | HEADERS += \ | |
23 | mainwidget.h \ |
|
24 | mainwidget.h \ | |
24 | # qscatterseries.h \ |
|
|||
25 | # qseriespointgraphicsitem.h \ |
|
|||
26 | dataseriedialog.h |
|
25 | dataseriedialog.h | |
27 |
|
@@ -1,5 +1,7 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "dataseriedialog.h" |
|
2 | #include "dataseriedialog.h" | |
|
3 | #include "qchartseries.h" | |||
|
4 | #include "qpieseries.h" | |||
3 | #include <qxychartseries.h> |
|
5 | #include <qxychartseries.h> | |
4 | #include <QPushButton> |
|
6 | #include <QPushButton> | |
5 | #include <QComboBox> |
|
7 | #include <QComboBox> | |
@@ -56,7 +58,7 MainWidget::MainWidget(QWidget *parent) : | |||||
56 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
58 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
57 |
|
59 | |||
58 | QGridLayout *grid = new QGridLayout(); |
|
60 | QGridLayout *grid = new QGridLayout(); | |
59 |
Q |
|
61 | QGridLayout *mainLayout = new QGridLayout(); | |
60 | //grid->addWidget(new QLabel("Add series:"), 0, 0); |
|
62 | //grid->addWidget(new QLabel("Add series:"), 0, 0); | |
61 | grid->addWidget(addSeriesButton, 0, 1); |
|
63 | grid->addWidget(addSeriesButton, 0, 1); | |
62 | grid->addWidget(new QLabel("Background:"), 2, 0); |
|
64 | grid->addWidget(new QLabel("Background:"), 2, 0); | |
@@ -74,23 +76,42 MainWidget::MainWidget(QWidget *parent) : | |||||
74 | grid->addWidget(new QLabel(""), 8, 0); |
|
76 | grid->addWidget(new QLabel(""), 8, 0); | |
75 | grid->setRowStretch(8, 1); |
|
77 | grid->setRowStretch(8, 1); | |
76 |
|
78 | |||
77 |
|
|
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 | m_chartWidget = new QChartWidget(this); |
|
101 | m_chartWidget = new QChartWidget(this); | |
80 | //m_chartWidget->setColor(Qt::red); |
|
102 | //m_chartWidget->setColor(Qt::red); | |
81 |
|
|
103 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); | |
82 | // hbox->setStretch(1, 1); |
|
104 | // hbox->setStretch(1, 1); | |
83 |
|
105 | |||
84 |
setLayout( |
|
106 | setLayout(mainLayout); | |
85 |
|
107 | |||
86 | m_autoScaleCheck->setChecked(true); |
|
108 | m_autoScaleCheck->setChecked(true); | |
87 | chartTypeChanged(4); |
|
|||
88 | testDataChanged(0); |
|
109 | testDataChanged(0); | |
89 | } |
|
110 | } | |
90 |
|
111 | |||
91 | void MainWidget::addSeries() |
|
112 | void MainWidget::addSeries() | |
92 | { |
|
113 | { | |
93 | DataSerieDialog dialog(m_defaultSeries, this); |
|
114 | DataSerieDialog dialog(m_defaultSeriesName, this); | |
94 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
115 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
95 | dialog.exec(); |
|
116 | dialog.exec(); | |
96 | } |
|
117 | } | |
@@ -98,9 +119,8 void MainWidget::addSeries() | |||||
98 | void MainWidget::addSeries(QString series, QString data) |
|
119 | void MainWidget::addSeries(QString series, QString data) | |
99 | { |
|
120 | { | |
100 | qDebug() << "addSeries: " << series << " data: " << data; |
|
121 | qDebug() << "addSeries: " << series << " data: " << data; | |
101 | m_defaultSeries = series; |
|
122 | m_defaultSeriesName = series; | |
102 |
|
123 | QChartSeries *newSeries = QXYChartSeries::create(); | ||
103 | QXYChartSeries* series0 = QXYChartSeries::create(); |
|
|||
104 |
|
124 | |||
105 | // TODO: a dedicated data class for storing x and y values |
|
125 | // TODO: a dedicated data class for storing x and y values | |
106 | QList<qreal> x; |
|
126 | QList<qreal> x; | |
@@ -112,56 +132,59 void MainWidget::addSeries(QString series, QString data) | |||||
112 | y.append(i); |
|
132 | y.append(i); | |
113 | } |
|
133 | } | |
114 | for (int i = 0; i < 20; i++) |
|
134 | for (int i = 0; i < 20; i++) | |
115 |
|
|
135 | ((QXYChartSeries *)newSeries)->add(i, i); | |
116 | } else if (data == "linear, 1M") { |
|
136 | } else if (data == "linear, 1M") { | |
117 | for (int i = 0; i < 10000; i++) { |
|
137 | for (int i = 0; i < 10000; i++) { | |
118 | x.append(i); |
|
138 | x.append(i); | |
119 | y.append(20); |
|
139 | y.append(20); | |
120 | } |
|
140 | } | |
121 | for (int i = 0; i < 1000000; i++) |
|
141 | for (int i = 0; i < 1000000; i++) | |
122 |
|
|
142 | ((QXYChartSeries *)newSeries)->add(i, 10); | |
123 | } else if (data == "SIN") { |
|
143 | } else if (data == "SIN") { | |
124 | for (int i = 0; i < 100; i++) { |
|
144 | for (int i = 0; i < 100; i++) { | |
125 | x.append(i); |
|
145 | x.append(i); | |
126 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
146 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
127 | } |
|
147 | } | |
128 | for (int i = 0; i < 100; i++) |
|
148 | for (int i = 0; i < 100; i++) | |
129 |
|
|
149 | ((QXYChartSeries *)newSeries)->add(i, abs(sin(3.14159265358979 / 50 * i) * 100)); | |
130 | } else if (data == "SIN + random") { |
|
150 | } else if (data == "SIN + random") { | |
131 | for (qreal i = 0; i < 100; i += 0.1) { |
|
151 | for (qreal i = 0; i < 100; i += 0.1) { | |
132 | x.append(i + (rand() % 5)); |
|
152 | x.append(i + (rand() % 5)); | |
133 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
153 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
134 | } |
|
154 | } | |
135 | for (qreal i = 0; i < 100; i += 0.1) |
|
155 | for (qreal i = 0; i < 100; i += 0.1) | |
136 |
|
|
156 | ((QXYChartSeries *)newSeries)->add(i + (rand() % 5), abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
137 | } else { |
|
157 | } else { | |
138 | // TODO: check if data has a valid file name |
|
158 | // TODO: check if data has a valid file name | |
139 | } |
|
159 | } | |
140 |
|
160 | |||
141 | // TODO: color of the series |
|
161 | // TODO: color of the series | |
142 | if (series == "Scatter") { |
|
162 | if (series == "Scatter") { | |
143 | /*QChartSeries* scatterSeries = */ |
|
163 | newSeries = m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypeScatter); | |
144 | m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypeScatter); |
|
|||
145 | } else if (series == "Pie") { |
|
164 | } else if (series == "Pie") { | |
146 | m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypePie); |
|
165 | newSeries = m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypePie); | |
147 | } else if (series == "Line") { |
|
166 | } else if (series == "Line") { | |
148 |
m_chartWidget->addSeries( |
|
167 | m_chartWidget->addSeries(newSeries); | |
149 | } else { |
|
168 | } else { | |
150 | // TODO |
|
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 |
|
177 | m_currentSeries = series; | |
157 | switch (itemIndex) { |
|
178 | switch (m_currentSeries->type()) { | |
158 | case 4: |
|
179 | case QChartSeries::SeriesTypeLine: | |
159 | //m_chartWidget->setType(4); |
|
|||
160 | break; |
|
180 | break; | |
161 | default: { |
|
181 | case QChartSeries::SeriesTypeScatter: | |
162 | //m_chartWidget->setType(0); |
|
182 | break; | |
|
183 | case QChartSeries::SeriesTypePie: | |||
|
184 | break; | |||
|
185 | default: | |||
|
186 | Q_ASSERT(false); | |||
163 | break; |
|
187 | break; | |
164 | } |
|
|||
165 | } |
|
188 | } | |
166 | } |
|
189 | } | |
167 |
|
190 | |||
@@ -239,3 +262,10 void MainWidget::yMaxChanged(int value) | |||||
239 | { |
|
262 | { | |
240 | qDebug() << "yMaxChanged: " << value; |
|
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 | } |
@@ -7,6 +7,7 | |||||
7 |
|
7 | |||
8 | class QSpinBox; |
|
8 | class QSpinBox; | |
9 | class QCheckBox; |
|
9 | class QCheckBox; | |
|
10 | class QGridLayout; | |||
10 |
|
11 | |||
11 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
12 | QTCOMMERCIALCHART_USE_NAMESPACE | |
12 |
|
13 | |||
@@ -19,7 +20,6 public: | |||||
19 | signals: |
|
20 | signals: | |
20 |
|
21 | |||
21 | private slots: |
|
22 | private slots: | |
22 | void chartTypeChanged(int itemIndex); |
|
|||
23 | void addSeries(); |
|
23 | void addSeries(); | |
24 | void addSeries(QString series, QString data); |
|
24 | void addSeries(QString series, QString data); | |
25 | void testDataChanged(int itemIndex); |
|
25 | void testDataChanged(int itemIndex); | |
@@ -29,6 +29,8 private slots: | |||||
29 | void xMaxChanged(int value); |
|
29 | void xMaxChanged(int value); | |
30 | void yMinChanged(int value); |
|
30 | void yMinChanged(int value); | |
31 | void yMaxChanged(int value); |
|
31 | void yMaxChanged(int value); | |
|
32 | void setCurrentSeries(QChartSeries *series); | |||
|
33 | void setPieSizeFactor(double margin); | |||
32 |
|
34 | |||
33 | private: |
|
35 | private: | |
34 | QChartWidget *m_chartWidget; |
|
36 | QChartWidget *m_chartWidget; | |
@@ -37,7 +39,10 private: | |||||
37 | QSpinBox *m_xMaxSpin; |
|
39 | QSpinBox *m_xMaxSpin; | |
38 | QSpinBox *m_yMinSpin; |
|
40 | QSpinBox *m_yMinSpin; | |
39 | QSpinBox *m_yMaxSpin; |
|
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 | #endif // MAINWIDGET_H |
|
48 | #endif // MAINWIDGET_H |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now