@@ -0,0 +1,75 | |||||
|
1 | #include "pieslice.h" | |||
|
2 | #include <QPainter> | |||
|
3 | #include <QDebug> | |||
|
4 | ||||
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
6 | ||||
|
7 | PieSlice::PieSlice(const QColor& color, qreal startAngle, qreal span) | |||
|
8 | : m_color(color), | |||
|
9 | m_startAngle(startAngle), | |||
|
10 | m_span(span) | |||
|
11 | { | |||
|
12 | setAcceptHoverEvents(true); | |||
|
13 | } | |||
|
14 | ||||
|
15 | PieSlice::~PieSlice() | |||
|
16 | { | |||
|
17 | } | |||
|
18 | ||||
|
19 | QRectF PieSlice::boundingRect() const | |||
|
20 | { | |||
|
21 | return parentItem()->boundingRect(); | |||
|
22 | } | |||
|
23 | ||||
|
24 | QPainterPath PieSlice::shape() const | |||
|
25 | { | |||
|
26 | qreal angle = (-m_startAngle) + (90); | |||
|
27 | qreal span = -m_span; | |||
|
28 | ||||
|
29 | QPainterPath path; | |||
|
30 | path.moveTo(boundingRect().center()); | |||
|
31 | path.arcTo(boundingRect(), angle, span); | |||
|
32 | ||||
|
33 | // TODO: draw the shape so that it might have a hole in the center | |||
|
34 | // - Sin & Cos will be needed to find inner/outer arc endpoints | |||
|
35 | ||||
|
36 | // dx, dy are offsets from the center | |||
|
37 | //qreal l = boundingRect().height(); | |||
|
38 | //qreal dx = qSin(angle*(M_PI/180)) * l; | |||
|
39 | //qreal dy = qCos(angle*(M_PI/180)) * l; | |||
|
40 | ||||
|
41 | // TODO: exploded slice? | |||
|
42 | ||||
|
43 | return path; | |||
|
44 | } | |||
|
45 | ||||
|
46 | void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |||
|
47 | { | |||
|
48 | // Setup painter | |||
|
49 | painter->setBrush(m_color); | |||
|
50 | QPen pen; | |||
|
51 | //pen.setColor(m_color.darker()); | |||
|
52 | pen.setColor(Qt::gray); | |||
|
53 | pen.setWidth(1); | |||
|
54 | painter->setPen(pen); | |||
|
55 | ||||
|
56 | // From Qt docs: | |||
|
57 | // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). | |||
|
58 | // Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. | |||
|
59 | // Zero degrees is at the 3 o'clock position. | |||
|
60 | // | |||
|
61 | // For sake of simplicity convert this so that zero degrees is at 12 o'clock and full circle is 360. | |||
|
62 | //qreal angle = (-m_startAngle*16) + (90*16); | |||
|
63 | //qreal span = -m_span*16; | |||
|
64 | //painter->drawPie(boundingRect(), angle, span); | |||
|
65 | ||||
|
66 | painter->drawPath(shape()); | |||
|
67 | } | |||
|
68 | ||||
|
69 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event) | |||
|
70 | { | |||
|
71 | QGraphicsItem::hoverEnterEvent(event); | |||
|
72 | qDebug() << "hover" << m_color << m_startAngle << m_span; | |||
|
73 | } | |||
|
74 | ||||
|
75 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,31 | |||||
|
1 | #ifndef PIESLICE_H | |||
|
2 | #define PIESLICE_H | |||
|
3 | ||||
|
4 | #include "qchartglobal.h" | |||
|
5 | #include <QGraphicsItem> | |||
|
6 | #include <QRectF> | |||
|
7 | #include <QColor> | |||
|
8 | ||||
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
10 | ||||
|
11 | class PieSlice : public QGraphicsItem | |||
|
12 | { | |||
|
13 | public: | |||
|
14 | PieSlice(const QColor& color, qreal startAngle, qreal span); | |||
|
15 | ~PieSlice(); | |||
|
16 | ||||
|
17 | public: // from QGraphicsItem | |||
|
18 | QRectF boundingRect() const; | |||
|
19 | QPainterPath shape() const; | |||
|
20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |||
|
21 | void hoverEnterEvent(QGraphicsSceneHoverEvent * event); | |||
|
22 | ||||
|
23 | private: | |||
|
24 | QColor m_color; | |||
|
25 | qreal m_startAngle; | |||
|
26 | qreal m_span; | |||
|
27 | }; | |||
|
28 | ||||
|
29 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
30 | ||||
|
31 | #endif // PIESLICE_H |
@@ -0,0 +1,54 | |||||
|
1 | #include "qpieseries.h" | |||
|
2 | #include "pieslice.h" | |||
|
3 | #include <QGraphicsObject> | |||
|
4 | #include <QDebug> | |||
|
5 | ||||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
7 | ||||
|
8 | QPieSeries::QPieSeries(QList<qreal> x, QGraphicsObject *parent) : | |||
|
9 | QChartSeries(parent), | |||
|
10 | m_x(x) | |||
|
11 | { | |||
|
12 | } | |||
|
13 | ||||
|
14 | QPieSeries::~QPieSeries() | |||
|
15 | { | |||
|
16 | } | |||
|
17 | ||||
|
18 | void QPieSeries::chartSizeChanged(QRectF rect, qreal xscale, qreal yscale) | |||
|
19 | { | |||
|
20 | qreal fullPie = 360; | |||
|
21 | qreal total = 0; | |||
|
22 | foreach (qreal value, m_x) | |||
|
23 | total += value; | |||
|
24 | ||||
|
25 | // We must have a parent for the graphics items we create | |||
|
26 | // TODO: maybe QChartSeries needs to be a QGraphicsObject to make this clear for the users? | |||
|
27 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent()); | |||
|
28 | Q_ASSERT(parentItem); | |||
|
29 | qreal angle = 0; | |||
|
30 | foreach (qreal value, m_x) { | |||
|
31 | qreal span = value / total * fullPie; | |||
|
32 | PieSlice *slice = new PieSlice(randomColor(), angle, span); | |||
|
33 | slice->setParentItem(parentItem); | |||
|
34 | m_slices.append(slice); | |||
|
35 | angle += span; | |||
|
36 | } | |||
|
37 | } | |||
|
38 | ||||
|
39 | QColor QPieSeries::randomColor() | |||
|
40 | { | |||
|
41 | QColor c; | |||
|
42 | c.setRed(qrand() % 255); | |||
|
43 | c.setGreen(qrand() % 255); | |||
|
44 | c.setBlue(qrand() % 255); | |||
|
45 | return c; | |||
|
46 | } | |||
|
47 | ||||
|
48 | void QPieSeries::setData(QList<int> data) | |||
|
49 | { | |||
|
50 | } | |||
|
51 | ||||
|
52 | #include "moc_qpieseries.cpp" | |||
|
53 | ||||
|
54 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,40 | |||||
|
1 | #ifndef PIESERIES_H | |||
|
2 | #define PIESERIES_H | |||
|
3 | ||||
|
4 | #include "qchartseries.h" | |||
|
5 | #include <QObject> | |||
|
6 | #include <QRectF> | |||
|
7 | #include <QColor> | |||
|
8 | ||||
|
9 | class QGraphicsObject; | |||
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
11 | class PieSlice; | |||
|
12 | ||||
|
13 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries | |||
|
14 | { | |||
|
15 | Q_OBJECT | |||
|
16 | public: | |||
|
17 | // TODO: use a generic data class instead of x and y | |||
|
18 | QPieSeries(QList<qreal> x, QGraphicsObject *parent = 0); | |||
|
19 | ~QPieSeries(); | |||
|
20 | QColor randomColor(); | |||
|
21 | void setData(QList<int> data); | |||
|
22 | ||||
|
23 | public: // from QChartSeries | |||
|
24 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } | |||
|
25 | ||||
|
26 | public Q_SLOTS: | |||
|
27 | void chartSizeChanged(QRectF rect, qreal xscale, qreal yscale); | |||
|
28 | ||||
|
29 | private: | |||
|
30 | //Q_DECLARE_PRIVATE(QPieSeries) | |||
|
31 | Q_DISABLE_COPY(QPieSeries) | |||
|
32 | // TODO: move the followin to internal impl | |||
|
33 | QList<qreal> m_x; | |||
|
34 | QList<PieSlice*> m_slices; | |||
|
35 | QSizeF m_size; | |||
|
36 | }; | |||
|
37 | ||||
|
38 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
39 | ||||
|
40 | #endif // PIESERIES_H |
@@ -1,16 +1,16 | |||||
1 | CONFIG+=integrated_build #remove if you want to build against installed libs |
|
1 | #CONFIG+=integrated_build #remove if you want to build against installed libs | |
2 |
|
2 | |||
3 | CHART_BUILD_HEADER_DIR = $$PWD/include |
|
3 | CHART_BUILD_HEADER_DIR = $$PWD/include | |
4 | CHART_BUILD_LIB_DIR = $$PWD/lib |
|
4 | CHART_BUILD_LIB_DIR = $$PWD/lib | |
5 | CHART_BUILD_DIR = $$PWD/build |
|
5 | CHART_BUILD_DIR = $$PWD/build | |
6 | CHART_BUILD_BIN_DIR = $$PWD/bin |
|
6 | CHART_BUILD_BIN_DIR = $$PWD/bin | |
7 |
|
7 | |||
8 | # hack to fix windows builds |
|
8 | # hack to fix windows builds | |
9 |
|
9 | |||
10 | win32:{ |
|
10 | win32:{ | |
11 | CHART_BUILD_HEADER_DIR = $$replace(CHART_BUILD_HEADER_DIR, "/","\\") |
|
11 | CHART_BUILD_HEADER_DIR = $$replace(CHART_BUILD_HEADER_DIR, "/","\\") | |
12 | CHART_BUILD_LIB_DIR = $$replace(CHART_BUILD_LIB_DIR, "/","\\") |
|
12 | CHART_BUILD_LIB_DIR = $$replace(CHART_BUILD_LIB_DIR, "/","\\") | |
13 | CHART_BUILD_BUILD_DIR = $$replace(CHART_BUILD_BUILD_DIR, "/","\\") |
|
13 | CHART_BUILD_BUILD_DIR = $$replace(CHART_BUILD_BUILD_DIR, "/","\\") | |
14 | CHART_BUILD_BIN_DIR = $$replace(CHART_BUILD_BIN_DIR, "/","\\") |
|
14 | CHART_BUILD_BIN_DIR = $$replace(CHART_BUILD_BIN_DIR, "/","\\") | |
15 | } |
|
15 | } | |
16 |
|
16 |
@@ -1,159 +1,171 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartseries.h" |
|
2 | #include "qchartseries.h" | |
3 | #include "qscatterseries.h" |
|
3 | #include "qscatterseries.h" | |
4 | #include "qscatterseries_p.h" |
|
4 | #include "qscatterseries_p.h" | |
|
5 | #include "qpieseries.h" | |||
5 | #include "qxychartseries.h" |
|
6 | #include "qxychartseries.h" | |
6 | #include "xylinechartitem_p.h" |
|
7 | #include "xylinechartitem_p.h" | |
7 | #include "xyplotdomain_p.h" |
|
8 | #include "xyplotdomain_p.h" | |
8 | #include "axis_p.h" |
|
9 | #include "axis_p.h" | |
9 | #include "xygrid_p.h" |
|
10 | #include "xygrid_p.h" | |
10 | #include <QGraphicsScene> |
|
11 | #include <QGraphicsScene> | |
11 | #include <QDebug> |
|
12 | #include <QDebug> | |
12 |
|
13 | |||
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
14 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
14 |
|
15 | |||
15 | class QChartPrivate |
|
16 | class QChartPrivate | |
16 | { |
|
17 | { | |
17 | public: |
|
18 | public: | |
18 |
|
19 | |||
19 | QChartPrivate(QChart* parent): |
|
20 | QChartPrivate(QChart* parent): | |
20 | m_axisX(new Axis(parent)), |
|
21 | m_axisX(new Axis(parent)), | |
21 | m_axisY(new Axis(parent)), |
|
22 | m_axisY(new Axis(parent)), | |
22 | m_grid(new XYGrid(parent)), |
|
23 | m_grid(new XYGrid(parent)), | |
23 | m_plotDataIndex(0), |
|
24 | m_plotDataIndex(0), | |
24 | m_marginSize(0){} |
|
25 | m_marginSize(0){} | |
25 |
|
26 | |||
26 | Axis* m_axisX; |
|
27 | Axis* m_axisX; | |
27 | Axis* m_axisY; |
|
28 | Axis* m_axisY; | |
28 | XYGrid* m_grid; |
|
29 | XYGrid* m_grid; | |
29 | QRect m_rect; |
|
30 | QRect m_rect; | |
30 | QList<const QChartSeries*> m_series; |
|
31 | QList<const QChartSeries*> m_series; | |
31 | QList<XYPlotDomain> m_plotDomainList; |
|
32 | QList<XYPlotDomain> m_plotDomainList; | |
32 | QList<XYLineChartItem*> m_xyLineChartItems; |
|
33 | QList<XYLineChartItem*> m_xyLineChartItems; | |
33 | QList<QGraphicsItem*> m_items; |
|
34 | QList<QGraphicsItem*> m_items; | |
34 | int m_plotDataIndex; |
|
35 | int m_plotDataIndex; | |
35 | int m_marginSize; |
|
36 | int m_marginSize; | |
36 |
|
37 | |||
37 | }; |
|
38 | }; | |
38 |
|
39 | |||
39 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
40 |
|
41 | |||
41 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), |
|
42 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), | |
42 | d(new QChartPrivate(this)) |
|
43 | d(new QChartPrivate(this)) | |
43 | { |
|
44 | { | |
44 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
45 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
45 | // set axis |
|
46 | // set axis | |
46 | d->m_axisY->rotate(90); |
|
47 | d->m_axisY->rotate(90); | |
47 | } |
|
48 | } | |
48 |
|
49 | |||
49 | QChart::~QChart(){} |
|
50 | QChart::~QChart(){} | |
50 |
|
51 | |||
51 | QRectF QChart::boundingRect() const |
|
52 | QRectF QChart::boundingRect() const | |
52 | { |
|
53 | { | |
53 | return d->m_rect; |
|
54 | return d->m_rect; | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 | void QChart::addSeries(QChartSeries* series) |
|
57 | void QChart::addSeries(QChartSeries* series) | |
57 | { |
|
58 | { | |
58 | // TODO: we should check the series not already added |
|
59 | // TODO: we should check the series not already added | |
59 |
|
60 | |||
60 | d->m_series<<series; |
|
61 | d->m_series<<series; | |
61 |
|
62 | |||
62 | switch(series->type()) |
|
63 | switch(series->type()) | |
63 | { |
|
64 | { | |
64 | case QChartSeries::SeriesTypeLine: { |
|
65 | case QChartSeries::SeriesTypeLine: { | |
65 |
|
66 | |||
66 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
67 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
67 |
|
68 | |||
68 | XYPlotDomain domain; |
|
69 | XYPlotDomain domain; | |
69 | //TODO "nice numbers algorithm" |
|
70 | //TODO "nice numbers algorithm" | |
70 | domain.m_ticksX=4; |
|
71 | domain.m_ticksX=4; | |
71 | domain.m_ticksY=4; |
|
72 | domain.m_ticksY=4; | |
72 |
|
73 | |||
73 | for (int i = 0 ; i < xyseries->count() ; i++) |
|
74 | for (int i = 0 ; i < xyseries->count() ; i++) | |
74 | { |
|
75 | { | |
75 | qreal x = xyseries->x(i); |
|
76 | qreal x = xyseries->x(i); | |
76 | qreal y = xyseries->y(i); |
|
77 | qreal y = xyseries->y(i); | |
77 | domain.m_minX = qMin(domain.m_minX,x); |
|
78 | domain.m_minX = qMin(domain.m_minX,x); | |
78 | domain.m_minY = qMin(domain.m_minY,y); |
|
79 | domain.m_minY = qMin(domain.m_minY,y); | |
79 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
80 | domain.m_maxX = qMax(domain.m_maxX,x); | |
80 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
81 | domain.m_maxY = qMax(domain.m_maxY,y); | |
81 | } |
|
82 | } | |
82 |
|
83 | |||
83 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); |
|
84 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); | |
84 | item->updateXYPlotDomain(domain); |
|
85 | item->updateXYPlotDomain(domain); | |
85 | d->m_plotDomainList<<domain; |
|
86 | d->m_plotDomainList<<domain; | |
86 | d->m_xyLineChartItems<<item; |
|
87 | d->m_xyLineChartItems<<item; | |
87 | break; |
|
88 | break; | |
88 | } |
|
89 | } | |
89 | case QChartSeries::SeriesTypeScatter: { |
|
90 | // TODO: Not tested: | |
90 | QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series); |
|
91 | // case QChartSeries::SeriesTypeScatter: { | |
91 | if (scatter) { |
|
92 | // QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series); | |
92 | scatter->d->setParentItem(this); |
|
93 | // if (scatter) { | |
93 | scene()->addItem(scatter->d); |
|
94 | // scatter->d->setParentItem(this); | |
94 | } |
|
95 | // scene()->addItem(scatter->d); | |
95 |
|
|
96 | // } | |
96 | } |
|
97 | // break; | |
|
98 | // } | |||
97 | } |
|
99 | } | |
98 | } |
|
100 | } | |
99 |
|
101 | |||
100 | QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) |
|
102 | QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) | |
101 | { |
|
103 | { | |
102 |
// TODO: support also other types |
|
104 | // TODO: support also other types; not only scatter and pie | |
103 |
Q_ASSERT(type == QChartSeries::SeriesTypeScatter |
|
105 | Q_ASSERT(type == QChartSeries::SeriesTypeScatter | |
104 | QChartSeries *series = 0; |
|
106 | || type == QChartSeries::SeriesTypePie); | |
105 |
|
107 | |||
106 | switch (type) { |
|
108 | switch (type) { | |
107 | case QChartSeries::SeriesTypeScatter: { |
|
109 | case QChartSeries::SeriesTypeScatter: { | |
108 | QScatterSeries *scatterSeries = new QScatterSeries(x, y, this); |
|
110 | QScatterSeries *scatterSeries = new QScatterSeries(x, y, this); | |
|
111 | connect(this, SIGNAL(sizeChanged(QRectF, qreal, qreal)), | |||
|
112 | scatterSeries, SLOT(chartSizeChanged(QRectF, qreal, qreal))); | |||
109 | scatterSeries->d->setParentItem(this); |
|
113 | scatterSeries->d->setParentItem(this); | |
110 | break; |
|
114 | return scatterSeries; | |
|
115 | } | |||
|
116 | case QChartSeries::SeriesTypePie: { | |||
|
117 | // TODO: we now have also a list of y values as a parameter, it is ignored | |||
|
118 | // we should use a generic data class instead of list of x and y values | |||
|
119 | QPieSeries *pieSeries = new QPieSeries(x, this); | |||
|
120 | connect(this, SIGNAL(sizeChanged(QRectF, qreal, qreal)), | |||
|
121 | pieSeries, SLOT(chartSizeChanged(QRectF, qreal, qreal))); | |||
|
122 | return pieSeries; | |||
111 | } |
|
123 | } | |
112 | default: |
|
124 | default: | |
113 | break; |
|
125 | break; | |
114 | } |
|
126 | } | |
115 |
|
127 | |||
116 |
return |
|
128 | return 0; | |
117 | } |
|
129 | } | |
118 |
|
130 | |||
119 | void QChart::setSize(const QSizeF& size) |
|
131 | void QChart::setSize(const QSizeF& size) | |
120 | { |
|
132 | { | |
121 | d->m_rect = QRect(QPoint(0,0),size.toSize()); |
|
133 | d->m_rect = QRect(QPoint(0,0),size.toSize()); | |
122 | d->m_rect.adjust(margin(),margin(), -margin(), -margin()); |
|
134 | d->m_rect.adjust(margin(),margin(), -margin(), -margin()); | |
123 | d->m_grid->setPos(d->m_rect.topLeft()); |
|
135 | d->m_grid->setPos(d->m_rect.topLeft()); | |
124 | d->m_grid->setSize(d->m_rect.size()); |
|
136 | d->m_grid->setSize(d->m_rect.size()); | |
125 |
|
137 | |||
126 | // TODO: calculate the scale |
|
138 | // TODO: calculate the scale | |
127 | // TODO: calculate the origo |
|
139 | // TODO: calculate the origo | |
128 | // TODO: not sure if emitting a signal here is the best from performance point of view |
|
140 | // TODO: not sure if emitting a signal here is the best from performance point of view | |
129 | const qreal xscale = size.width() / 100; |
|
141 | const qreal xscale = size.width() / 100; | |
130 | const qreal yscale = size.height() / 100; |
|
142 | const qreal yscale = size.height() / 100; | |
131 | emit sizeChanged(QRectF(0, 0, size.width(), size.height()), xscale, yscale); |
|
143 | emit sizeChanged(QRectF(0, 0, size.width(), size.height()), xscale, yscale); | |
132 |
|
144 | |||
133 | for (int i(0); i < d->m_plotDomainList.size(); i++) |
|
145 | for (int i(0); i < d->m_plotDomainList.size(); i++) | |
134 | d->m_plotDomainList[i].m_viewportRect = d->m_rect; |
|
146 | d->m_plotDomainList[i].m_viewportRect = d->m_rect; | |
135 |
|
147 | |||
136 | // TODO: line chart items are updated separately as they don't support update |
|
148 | // TODO: line chart items are updated separately as they don't support update | |
137 | // via sizeChanged signal |
|
149 | // via sizeChanged signal | |
138 | foreach(XYLineChartItem* item , d->m_xyLineChartItems) |
|
150 | foreach(XYLineChartItem* item , d->m_xyLineChartItems) | |
139 | item->updateXYPlotDomain(d->m_plotDomainList.at(d->m_plotDataIndex)); |
|
151 | item->updateXYPlotDomain(d->m_plotDomainList.at(d->m_plotDataIndex)); | |
140 |
|
152 | |||
141 | if (d->m_plotDomainList.count()) |
|
153 | if (d->m_plotDomainList.count()) | |
142 | d->m_grid->setXYPlotData(d->m_plotDomainList.at(d->m_plotDataIndex)); |
|
154 | d->m_grid->setXYPlotData(d->m_plotDomainList.at(d->m_plotDataIndex)); | |
143 | update(); |
|
155 | update(); | |
144 | } |
|
156 | } | |
145 |
|
157 | |||
146 | int QChart::margin() const |
|
158 | int QChart::margin() const | |
147 | { |
|
159 | { | |
148 | return d->m_marginSize; |
|
160 | return d->m_marginSize; | |
149 | } |
|
161 | } | |
150 |
|
162 | |||
151 | void QChart::setMargin(int margin) |
|
163 | void QChart::setMargin(int margin) | |
152 | { |
|
164 | { | |
153 | d->m_marginSize = margin; |
|
165 | d->m_marginSize = margin; | |
154 | } |
|
166 | } | |
155 |
|
167 | |||
156 | #include "moc_qchart.cpp" |
|
168 | #include "moc_qchart.cpp" | |
157 |
|
169 | |||
158 |
|
170 | |||
159 | QTCOMMERCIALCHART_END_NAMESPACE |
|
171 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,38 +1,38 | |||||
1 | #ifndef QCHARTSERIES_H |
|
1 | #ifndef QCHARTSERIES_H | |
2 | #define QCHARTSERIES_H |
|
2 | #define QCHARTSERIES_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject |
|
9 | class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject | |
10 | { |
|
10 | { | |
11 |
|
11 | |||
12 | public: |
|
12 | public: | |
13 | enum QChartSeriesType { |
|
13 | enum QChartSeriesType { | |
14 | SeriesTypeLine = 0, |
|
14 | SeriesTypeLine = 0, | |
15 | // SeriesTypeArea, |
|
15 | // SeriesTypeArea, | |
16 | // SeriesTypeBar, |
|
16 | // SeriesTypeBar, | |
17 |
|
|
17 | SeriesTypePie, | |
18 | SeriesTypeScatter |
|
18 | SeriesTypeScatter | |
19 | // SeriesTypeSpline |
|
19 | // SeriesTypeSpline | |
20 | }; |
|
20 | }; | |
21 |
|
21 | |||
22 | protected: |
|
22 | protected: | |
23 | QChartSeries(QObject *parent = 0):QObject(parent){}; |
|
23 | QChartSeries(QObject *parent = 0):QObject(parent){}; | |
24 |
|
24 | |||
25 | public: |
|
25 | public: | |
26 | virtual ~QChartSeries(){}; |
|
26 | virtual ~QChartSeries(){}; | |
27 |
|
27 | |||
28 | //factory method |
|
28 | //factory method | |
29 | static QChartSeries* create(QObject* parent = 0 ){ return 0;} |
|
29 | static QChartSeries* create(QObject* parent = 0 ){ return 0;} | |
30 | //pure virtual |
|
30 | //pure virtual | |
31 | virtual QChartSeriesType type() const = 0; |
|
31 | virtual QChartSeriesType type() const = 0; | |
32 |
|
32 | |||
33 | }; |
|
33 | }; | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_END_NAMESPACE |
|
35 | QTCOMMERCIALCHART_END_NAMESPACE | |
36 |
|
36 | |||
37 | #endif |
|
37 | #endif | |
38 |
|
38 |
@@ -1,77 +1,76 | |||||
1 | #include "qscatterseries.h" |
|
1 | #include "qscatterseries.h" | |
2 | #include "qscatterseries_p.h" |
|
2 | #include "qscatterseries_p.h" | |
3 | #include "qchart.h" |
|
3 | #include "qchart.h" | |
4 | #include <QPainter> |
|
4 | #include <QPainter> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | //#define QSeriesData QList<qreal> |
|
10 | //#define QSeriesData QList<qreal> | |
11 |
|
11 | |||
12 | QScatterSeriesPrivate::QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent) : |
|
12 | QScatterSeriesPrivate::QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent) : | |
13 | QGraphicsItem(parent), |
|
13 | QGraphicsItem(parent), | |
14 | m_x(x), |
|
14 | m_x(x), | |
15 | m_y(y) |
|
15 | m_y(y) | |
16 | { |
|
16 | { | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | void QScatterSeriesPrivate::resize(QRectF rect, qreal xscale, qreal yscale) |
|
19 | void QScatterSeriesPrivate::resize(QRectF rect, qreal xscale, qreal yscale) | |
20 | { |
|
20 | { | |
21 | m_scenex.clear(); |
|
21 | m_scenex.clear(); | |
22 | m_sceney.clear(); |
|
22 | m_sceney.clear(); | |
23 |
|
23 | |||
24 | foreach(qreal x, m_x) |
|
24 | foreach(qreal x, m_x) | |
25 | m_scenex.append(rect.left() + x * xscale); |
|
25 | m_scenex.append(rect.left() + x * xscale); | |
26 |
|
26 | |||
27 | foreach(qreal y, m_y) |
|
27 | foreach(qreal y, m_y) | |
28 | m_sceney.append(rect.bottom() - y * yscale); |
|
28 | m_sceney.append(rect.bottom() - y * yscale); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | QRectF QScatterSeriesPrivate::boundingRect() const |
|
31 | QRectF QScatterSeriesPrivate::boundingRect() const | |
32 | { |
|
32 | { | |
33 | return QRectF(0, 0, 55, 100); |
|
33 | return QRectF(0, 0, 55, 100); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
36 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
37 | { |
|
37 | { | |
38 | QPen pen = painter->pen(); |
|
38 | QPen pen = painter->pen(); | |
39 | QBrush brush = pen.brush(); |
|
39 | QBrush brush = pen.brush(); | |
40 | // TODO: The opacity should be user definable... |
|
40 | // TODO: The opacity should be user definable... | |
41 | brush.setColor(QColor(255, 82, 0, 50)); |
|
41 | brush.setColor(QColor(255, 82, 0, 50)); | |
42 | pen.setBrush(brush); |
|
42 | pen.setBrush(brush); | |
43 | pen.setWidth(4); |
|
43 | pen.setWidth(4); | |
44 | painter->setPen(pen); |
|
44 | painter->setPen(pen); | |
45 |
|
45 | |||
46 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize |
|
46 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize | |
47 | // event right after construction or maybe given a size during initialization |
|
47 | // event right after construction or maybe given a size during initialization | |
48 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
48 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | |
49 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
49 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | |
50 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); |
|
50 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); | |
51 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); |
|
51 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | QScatterSeries::QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent) : |
|
55 | QScatterSeries::QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent) : | |
56 | QChartSeries(parent), |
|
56 | QChartSeries(parent), | |
57 | d(new QScatterSeriesPrivate(x, y, qobject_cast<QGraphicsItem *> (parent))) |
|
57 | d(new QScatterSeriesPrivate(x, y, qobject_cast<QGraphicsItem *> (parent))) | |
58 | { |
|
58 | { | |
59 | connect(parent, SIGNAL(sizeChanged(QRectF, qreal, qreal)), this, SLOT(chartSizeChanged(QRectF, qreal, qreal))); |
|
|||
60 | } |
|
59 | } | |
61 |
|
60 | |||
62 | void QScatterSeries::chartSizeChanged(QRectF rect, qreal xscale, qreal yscale) |
|
61 | void QScatterSeries::chartSizeChanged(QRectF rect, qreal xscale, qreal yscale) | |
63 | { |
|
62 | { | |
64 | // Recalculate scatter data point locations on the scene |
|
63 | // Recalculate scatter data point locations on the scene | |
65 | // d->transform().reset(); |
|
64 | // d->transform().reset(); | |
66 | // d->transform().translate(); |
|
65 | // d->transform().translate(); | |
67 | d->resize(rect, xscale, yscale); |
|
66 | d->resize(rect, xscale, yscale); | |
68 | } |
|
67 | } | |
69 |
|
68 | |||
70 | QScatterSeries::~QScatterSeries() |
|
69 | QScatterSeries::~QScatterSeries() | |
71 | { |
|
70 | { | |
72 | delete d; |
|
71 | delete d; | |
73 | } |
|
72 | } | |
74 |
|
73 | |||
75 | #include "moc_qscatterseries.cpp" |
|
74 | #include "moc_qscatterseries.cpp" | |
76 |
|
75 | |||
77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
76 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,33 +1,33 | |||||
1 | #ifndef QSCATTERSERIES_H |
|
1 | #ifndef QSCATTERSERIES_H | |
2 | #define QSCATTERSERIES_H |
|
2 | #define QSCATTERSERIES_H | |
3 |
|
3 | |||
4 | #include "qchartseries.h" |
|
4 | #include "qchartseries.h" | |
5 | #include <QRectF> |
|
5 | #include <QRectF> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 | class QScatterSeriesPrivate; |
|
8 | class QScatterSeriesPrivate; | |
9 |
|
9 | |||
10 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries |
|
10 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 | //QScatterSeries(QSeriesData *data, QObject *chart); |
|
14 | //QScatterSeries(QSeriesData *data, QObject *chart); | |
15 |
QScatterSeries(QList<qreal> x, QList<qreal> y, QObject * |
|
15 | QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent = 0); | |
16 | ~QScatterSeries(); |
|
16 | ~QScatterSeries(); | |
17 |
|
17 | |||
18 | public: // from QChartSeries |
|
18 | public: // from QChartSeries | |
19 |
|
|
19 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } | |
20 |
|
20 | |||
21 | public Q_SLOTS: |
|
21 | public Q_SLOTS: | |
22 | void chartSizeChanged(QRectF rect, qreal xscale, qreal yscale); |
|
22 | void chartSizeChanged(QRectF rect, qreal xscale, qreal yscale); | |
23 |
|
23 | |||
24 | private: |
|
24 | private: | |
25 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
25 | Q_DECLARE_PRIVATE(QScatterSeries) | |
26 | Q_DISABLE_COPY(QScatterSeries) |
|
26 | Q_DISABLE_COPY(QScatterSeries) | |
27 | friend class QChart; |
|
27 | friend class QChart; | |
28 | QScatterSeriesPrivate *const d; |
|
28 | QScatterSeriesPrivate *const d; | |
29 | }; |
|
29 | }; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_END_NAMESPACE |
|
31 | QTCOMMERCIALCHART_END_NAMESPACE | |
32 |
|
32 | |||
33 | #endif // QSCATTERSERIES_H |
|
33 | #endif // QSCATTERSERIES_H |
@@ -1,75 +1,81 | |||||
1 | !include( ../common.pri ) { |
|
1 | !include( ../common.pri ) { | |
2 | error( Couldn't find the common.pri file! ) |
|
2 | error( Couldn't find the common.pri file! ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TARGET = QtCommercialChart |
|
5 | TARGET = QtCommercialChart | |
6 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
6 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
7 | TEMPLATE = lib |
|
7 | TEMPLATE = lib | |
8 | QT += core \ |
|
8 | QT += core \ | |
9 | gui |
|
9 | gui | |
10 |
|
10 | |||
11 | CONFIG += debug_and_release |
|
11 | CONFIG += debug_and_release | |
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
13 |
|
13 | |||
14 | SOURCES += \ |
|
14 | SOURCES += \ | |
15 | xylinechart/qxychartseries.cpp \ |
|
15 | xylinechart/qxychartseries.cpp \ | |
16 | xylinechart/xylinechartitem.cpp \ |
|
16 | xylinechart/xylinechartitem.cpp \ | |
17 | xylinechart/xygrid.cpp \ |
|
17 | xylinechart/xygrid.cpp \ | |
18 | xylinechart/xyplotdomain.cpp \ |
|
18 | xylinechart/xyplotdomain.cpp \ | |
19 | qscatterseries.cpp \ |
|
19 | qscatterseries.cpp \ | |
|
20 | qpieseries.cpp \ | |||
20 | qchart.cpp \ |
|
21 | qchart.cpp \ | |
21 | axis.cpp \ |
|
22 | axis.cpp \ | |
22 | qchartwidget.cpp |
|
23 | qchartwidget.cpp \ | |
|
24 | pieslice.cpp | |||
23 |
|
25 | |||
24 | PRIVATE_HEADERS += \ |
|
26 | PRIVATE_HEADERS += \ | |
25 | xylinechart/xylinechartitem_p.h \ |
|
27 | xylinechart/xylinechartitem_p.h \ | |
26 | xylinechart/xyplotdomain_p.h \ |
|
28 | xylinechart/xyplotdomain_p.h \ | |
27 | xylinechart/xygrid_p.h \ |
|
29 | xylinechart/xygrid_p.h \ | |
28 | qscatterseries_p.h \ |
|
30 | qscatterseries_p.h \ | |
|
31 | pieslice.h \ | |||
29 | axis_p.h |
|
32 | axis_p.h | |
30 |
|
33 | |||
31 | PUBLIC_HEADERS += \ |
|
34 | PUBLIC_HEADERS += \ | |
32 | qchartseries.h \ |
|
35 | qchartseries.h \ | |
33 | qscatterseries.h \ |
|
36 | qscatterseries.h \ | |
|
37 | qpieseries.h \ | |||
34 | qchart.h \ |
|
38 | qchart.h \ | |
35 | qchartwidget.h \ |
|
39 | qchartwidget.h \ | |
36 | qchartglobal.h \ |
|
40 | qchartglobal.h \ | |
37 | xylinechart/qxychartseries.h |
|
41 | xylinechart/qxychartseries.h | |
38 |
|
42 | |||
39 | HEADERS += $$PUBLIC_HEADERS |
|
43 | HEADERS += $$PUBLIC_HEADERS | |
40 | HEADERS += $$PRIVATE_HEADERS |
|
44 | HEADERS += $$PRIVATE_HEADERS | |
41 |
|
45 | |||
42 | INCLUDEPATH += xylinechart \ |
|
46 | INCLUDEPATH += xylinechart \ | |
43 | . |
|
47 | . | |
44 |
|
48 | |||
45 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
49 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
46 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
50 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
47 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
51 | UI_DIR = $$CHART_BUILD_DIR/lib | |
48 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
52 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
49 |
|
53 | |||
50 |
|
54 | |||
51 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
55 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
52 |
|
56 | |||
53 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
57 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
54 | public_headers.files = $$PUBLIC_HEADERS |
|
58 | public_headers.files = $$PUBLIC_HEADERS | |
55 | target.path = $$[QT_INSTALL_LIBS] |
|
59 | target.path = $$[QT_INSTALL_LIBS] | |
56 | INSTALLS += target \ |
|
60 | INSTALLS += target \ | |
57 | public_headers |
|
61 | public_headers | |
58 |
|
62 | |||
59 |
|
63 | |||
60 | install_build_headers.name = bild_headers |
|
64 | install_build_headers.name = bild_headers | |
61 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
65 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
62 | install_build_headers.input = PUBLIC_HEADERS |
|
66 | install_build_headers.input = PUBLIC_HEADERS | |
63 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR |
|
67 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR | |
64 | install_build_headers.CONFIG += target_predeps no_link |
|
68 | install_build_headers.CONFIG += target_predeps no_link | |
65 | QMAKE_EXTRA_COMPILERS += install_build_headers |
|
69 | QMAKE_EXTRA_COMPILERS += install_build_headers | |
66 |
|
70 | |||
67 | chartversion.target = qchartversion_p.h |
|
71 | chartversion.target = qchartversion_p.h | |
68 | chartversion.commands = @echo "build_time" > $$chartversion.target; |
|
72 | chartversion.commands = @echo "build_time" > $$chartversion.target; | |
69 | chartversion.depends = $$HEADERS $$SOURCES |
|
73 | chartversion.depends = $$HEADERS $$SOURCES | |
70 | PRE_TARGETDEPS += qchartversion_p.h |
|
74 | PRE_TARGETDEPS += qchartversion_p.h | |
71 | QMAKE_CLEAN+= qchartversion_p.h |
|
75 | QMAKE_CLEAN+= qchartversion_p.h | |
72 | QMAKE_EXTRA_TARGETS += chartversion |
|
76 | QMAKE_EXTRA_TARGETS += chartversion | |
73 |
|
77 | |||
74 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
78 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
75 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
79 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
|
80 | ||||
|
81 |
@@ -1,239 +1,241 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "dataseriedialog.h" |
|
2 | #include "dataseriedialog.h" | |
3 | #include <qxychartseries.h> |
|
3 | #include <qxychartseries.h> | |
4 | #include <QPushButton> |
|
4 | #include <QPushButton> | |
5 | #include <QComboBox> |
|
5 | #include <QComboBox> | |
6 | #include <QSpinBox> |
|
6 | #include <QSpinBox> | |
7 | #include <QCheckBox> |
|
7 | #include <QCheckBox> | |
8 | #include <QGridLayout> |
|
8 | #include <QGridLayout> | |
9 | #include <QHBoxLayout> |
|
9 | #include <QHBoxLayout> | |
10 | #include <QLabel> |
|
10 | #include <QLabel> | |
11 | #include <QSpacerItem> |
|
11 | #include <QSpacerItem> | |
12 | #include <QMessageBox> |
|
12 | #include <QMessageBox> | |
13 | #include <cmath> |
|
13 | #include <cmath> | |
14 | #include <QDebug> |
|
14 | #include <QDebug> | |
15 |
|
15 | |||
16 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
16 | QTCOMMERCIALCHART_USE_NAMESPACE | |
17 |
|
17 | |||
18 | MainWidget::MainWidget(QWidget *parent) : |
|
18 | MainWidget::MainWidget(QWidget *parent) : | |
19 | QWidget(parent) |
|
19 | QWidget(parent) | |
20 | { |
|
20 | { | |
21 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
21 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
22 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
22 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
23 |
|
23 | |||
24 | // Chart background |
|
24 | // Chart background | |
25 | QComboBox *backgroundCombo = new QComboBox(this); |
|
25 | QComboBox *backgroundCombo = new QComboBox(this); | |
26 | backgroundCombo->addItem("None"); |
|
26 | backgroundCombo->addItem("None"); | |
27 | backgroundCombo->addItem("TODO Grid"); |
|
27 | backgroundCombo->addItem("TODO Grid"); | |
28 | backgroundCombo->addItem("TODO Image"); |
|
28 | backgroundCombo->addItem("TODO Image"); | |
29 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
29 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
30 | this, SLOT(backgroundChanged(int))); |
|
30 | this, SLOT(backgroundChanged(int))); | |
31 |
|
31 | |||
32 | // Axis |
|
32 | // Axis | |
33 | // TODO: multiple axes? |
|
33 | // TODO: multiple axes? | |
34 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
34 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
35 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
35 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
36 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
36 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
37 | m_xMinSpin = new QSpinBox(); |
|
37 | m_xMinSpin = new QSpinBox(); | |
38 | m_xMinSpin->setMinimum(INT_MIN); |
|
38 | m_xMinSpin->setMinimum(INT_MIN); | |
39 | m_xMinSpin->setMaximum(INT_MAX); |
|
39 | m_xMinSpin->setMaximum(INT_MAX); | |
40 | m_xMinSpin->setValue(0); |
|
40 | m_xMinSpin->setValue(0); | |
41 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
41 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
42 | m_xMaxSpin = new QSpinBox(); |
|
42 | m_xMaxSpin = new QSpinBox(); | |
43 | m_xMaxSpin->setMinimum(INT_MIN); |
|
43 | m_xMaxSpin->setMinimum(INT_MIN); | |
44 | m_xMaxSpin->setMaximum(INT_MAX); |
|
44 | m_xMaxSpin->setMaximum(INT_MAX); | |
45 | m_xMaxSpin->setValue(10); |
|
45 | m_xMaxSpin->setValue(10); | |
46 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
46 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
47 | m_yMinSpin = new QSpinBox(); |
|
47 | m_yMinSpin = new QSpinBox(); | |
48 | m_yMinSpin->setMinimum(INT_MIN); |
|
48 | m_yMinSpin->setMinimum(INT_MIN); | |
49 | m_yMinSpin->setMaximum(INT_MAX); |
|
49 | m_yMinSpin->setMaximum(INT_MAX); | |
50 | m_yMinSpin->setValue(0); |
|
50 | m_yMinSpin->setValue(0); | |
51 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
51 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
52 | m_yMaxSpin = new QSpinBox(); |
|
52 | m_yMaxSpin = new QSpinBox(); | |
53 | m_yMaxSpin->setMinimum(INT_MIN); |
|
53 | m_yMaxSpin->setMinimum(INT_MIN); | |
54 | m_yMaxSpin->setMaximum(INT_MAX); |
|
54 | m_yMaxSpin->setMaximum(INT_MAX); | |
55 | m_yMaxSpin->setValue(10); |
|
55 | m_yMaxSpin->setValue(10); | |
56 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
56 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
57 |
|
57 | |||
58 | QGridLayout *grid = new QGridLayout(); |
|
58 | QGridLayout *grid = new QGridLayout(); | |
59 | QHBoxLayout *hbox = new QHBoxLayout(); |
|
59 | QHBoxLayout *hbox = new QHBoxLayout(); | |
60 | //grid->addWidget(new QLabel("Add series:"), 0, 0); |
|
60 | //grid->addWidget(new QLabel("Add series:"), 0, 0); | |
61 | grid->addWidget(addSeriesButton, 0, 1); |
|
61 | grid->addWidget(addSeriesButton, 0, 1); | |
62 | grid->addWidget(new QLabel("Background:"), 2, 0); |
|
62 | grid->addWidget(new QLabel("Background:"), 2, 0); | |
63 | grid->addWidget(backgroundCombo, 2, 1); |
|
63 | grid->addWidget(backgroundCombo, 2, 1); | |
64 | grid->addWidget(m_autoScaleCheck, 3, 0); |
|
64 | grid->addWidget(m_autoScaleCheck, 3, 0); | |
65 | grid->addWidget(new QLabel("x min:"), 4, 0); |
|
65 | grid->addWidget(new QLabel("x min:"), 4, 0); | |
66 | grid->addWidget(m_xMinSpin, 4, 1); |
|
66 | grid->addWidget(m_xMinSpin, 4, 1); | |
67 | grid->addWidget(new QLabel("x max:"), 5, 0); |
|
67 | grid->addWidget(new QLabel("x max:"), 5, 0); | |
68 | grid->addWidget(m_xMaxSpin, 5, 1); |
|
68 | grid->addWidget(m_xMaxSpin, 5, 1); | |
69 | grid->addWidget(new QLabel("y min:"), 6, 0); |
|
69 | grid->addWidget(new QLabel("y min:"), 6, 0); | |
70 | grid->addWidget(m_yMinSpin, 6, 1); |
|
70 | grid->addWidget(m_yMinSpin, 6, 1); | |
71 | grid->addWidget(new QLabel("y max:"), 7, 0); |
|
71 | grid->addWidget(new QLabel("y max:"), 7, 0); | |
72 | grid->addWidget(m_yMaxSpin, 7, 1); |
|
72 | grid->addWidget(m_yMaxSpin, 7, 1); | |
73 | // add row with empty label to make all the other rows static |
|
73 | // add row with empty label to make all the other rows static | |
74 | grid->addWidget(new QLabel(""), 8, 0); |
|
74 | grid->addWidget(new QLabel(""), 8, 0); | |
75 | grid->setRowStretch(8, 1); |
|
75 | grid->setRowStretch(8, 1); | |
76 |
|
76 | |||
77 | hbox->addLayout(grid); |
|
77 | hbox->addLayout(grid); | |
78 |
|
78 | |||
79 | m_chartWidget = new QChartWidget(this); |
|
79 | m_chartWidget = new QChartWidget(this); | |
80 | //m_chartWidget->setColor(Qt::red); |
|
80 | //m_chartWidget->setColor(Qt::red); | |
81 | hbox->addWidget(m_chartWidget); |
|
81 | hbox->addWidget(m_chartWidget); | |
82 | // hbox->setStretch(1, 1); |
|
82 | // hbox->setStretch(1, 1); | |
83 |
|
83 | |||
84 | setLayout(hbox); |
|
84 | setLayout(hbox); | |
85 |
|
85 | |||
86 | m_autoScaleCheck->setChecked(true); |
|
86 | m_autoScaleCheck->setChecked(true); | |
87 | chartTypeChanged(4); |
|
87 | chartTypeChanged(4); | |
88 | testDataChanged(0); |
|
88 | testDataChanged(0); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void MainWidget::addSeries() |
|
91 | void MainWidget::addSeries() | |
92 | { |
|
92 | { | |
93 | DataSerieDialog dialog(m_defaultSeries, this); |
|
93 | DataSerieDialog dialog(m_defaultSeries, this); | |
94 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
94 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
95 | dialog.exec(); |
|
95 | dialog.exec(); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void MainWidget::addSeries(QString series, QString data) |
|
98 | void MainWidget::addSeries(QString series, QString data) | |
99 | { |
|
99 | { | |
100 | qDebug() << "addSeries: " << series << " data: " << data; |
|
100 | qDebug() << "addSeries: " << series << " data: " << data; | |
101 | m_defaultSeries = series; |
|
101 | m_defaultSeries = series; | |
102 |
|
102 | |||
103 | QXYChartSeries* series0 = QXYChartSeries::create(); |
|
103 | QXYChartSeries* series0 = QXYChartSeries::create(); | |
104 |
|
104 | |||
105 | // TODO: a dedicated data class for storing x and y values |
|
105 | // TODO: a dedicated data class for storing x and y values | |
106 | QList<qreal> x; |
|
106 | QList<qreal> x; | |
107 | QList<qreal> y; |
|
107 | QList<qreal> y; | |
108 |
|
108 | |||
109 | if (data == "linear") { |
|
109 | if (data == "linear") { | |
110 | for (int i = 0; i < 20; i++) { |
|
110 | for (int i = 0; i < 20; i++) { | |
111 | x.append(i); |
|
111 | x.append(i); | |
112 | y.append(i); |
|
112 | y.append(i); | |
113 | } |
|
113 | } | |
114 | for (int i = 0; i < 20; i++) |
|
114 | for (int i = 0; i < 20; i++) | |
115 | series0->add(i, i); |
|
115 | series0->add(i, i); | |
116 | } else if (data == "linear, 1M") { |
|
116 | } else if (data == "linear, 1M") { | |
117 | for (int i = 0; i < 10000; i++) { |
|
117 | for (int i = 0; i < 10000; i++) { | |
118 | x.append(i); |
|
118 | x.append(i); | |
119 | y.append(20); |
|
119 | y.append(20); | |
120 | } |
|
120 | } | |
121 | for (int i = 0; i < 1000000; i++) |
|
121 | for (int i = 0; i < 1000000; i++) | |
122 | series0->add(i, 10); |
|
122 | series0->add(i, 10); | |
123 | } else if (data == "SIN") { |
|
123 | } else if (data == "SIN") { | |
124 | for (int i = 0; i < 100; i++) { |
|
124 | for (int i = 0; i < 100; i++) { | |
125 | x.append(i); |
|
125 | x.append(i); | |
126 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
126 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
127 | } |
|
127 | } | |
128 | for (int i = 0; i < 100; i++) |
|
128 | for (int i = 0; i < 100; i++) | |
129 | series0->add(i, abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
129 | series0->add(i, abs(sin(3.14159265358979 / 50 * i) * 100)); | |
130 | } else if (data == "SIN + random") { |
|
130 | } else if (data == "SIN + random") { | |
131 | for (qreal i = 0; i < 100; i += 0.1) { |
|
131 | for (qreal i = 0; i < 100; i += 0.1) { | |
132 | x.append(i + (rand() % 5)); |
|
132 | x.append(i + (rand() % 5)); | |
133 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
133 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
134 | } |
|
134 | } | |
135 | for (qreal i = 0; i < 100; i += 0.1) |
|
135 | for (qreal i = 0; i < 100; i += 0.1) | |
136 | series0->add(i + (rand() % 5), abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
136 | series0->add(i + (rand() % 5), abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
137 | } else { |
|
137 | } else { | |
138 | // TODO: check if data has a valid file name |
|
138 | // TODO: check if data has a valid file name | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | // TODO: color of the series |
|
141 | // TODO: color of the series | |
142 | if (series == "Scatter") { |
|
142 | if (series == "Scatter") { | |
143 | /*QChartSeries* scatterSeries = */ |
|
143 | /*QChartSeries* scatterSeries = */ | |
144 | m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypeScatter); |
|
144 | m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypeScatter); | |
|
145 | } else if (series == "Pie") { | |||
|
146 | m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypePie); | |||
145 | } else if (series == "Line") { |
|
147 | } else if (series == "Line") { | |
146 | m_chartWidget->addSeries(series0); |
|
148 | m_chartWidget->addSeries(series0); | |
147 | } else { |
|
149 | } else { | |
148 | // TODO |
|
150 | // TODO | |
149 | } |
|
151 | } | |
150 | } |
|
152 | } | |
151 |
|
153 | |||
152 | void MainWidget::chartTypeChanged(int itemIndex) |
|
154 | void MainWidget::chartTypeChanged(int itemIndex) | |
153 | { |
|
155 | { | |
154 | // TODO: change chart type |
|
156 | // TODO: change chart type | |
155 | switch (itemIndex) { |
|
157 | switch (itemIndex) { | |
156 | case 4: |
|
158 | case 4: | |
157 | //m_chartWidget->setType(4); |
|
159 | //m_chartWidget->setType(4); | |
158 | break; |
|
160 | break; | |
159 | default: { |
|
161 | default: { | |
160 | //m_chartWidget->setType(0); |
|
162 | //m_chartWidget->setType(0); | |
161 | break; |
|
163 | break; | |
162 | } |
|
164 | } | |
163 | } |
|
165 | } | |
164 | } |
|
166 | } | |
165 |
|
167 | |||
166 | void MainWidget::testDataChanged(int itemIndex) |
|
168 | void MainWidget::testDataChanged(int itemIndex) | |
167 | { |
|
169 | { | |
168 | qDebug() << "testDataChanged: " << itemIndex; |
|
170 | qDebug() << "testDataChanged: " << itemIndex; | |
169 |
|
171 | |||
170 | // switch (itemIndex) { |
|
172 | // switch (itemIndex) { | |
171 | // case 0: { |
|
173 | // case 0: { | |
172 | // QList<QChartDataPoint> data; |
|
174 | // QList<QChartDataPoint> data; | |
173 | // for (int x = 0; x < 20; x++) { |
|
175 | // for (int x = 0; x < 20; x++) { | |
174 | // data.append(QChartDataPoint() << x << x / 2); |
|
176 | // data.append(QChartDataPoint() << x << x / 2); | |
175 | // } |
|
177 | // } | |
176 | // m_chartWidget->setData(data); |
|
178 | // m_chartWidget->setData(data); | |
177 | // break; |
|
179 | // break; | |
178 | // } |
|
180 | // } | |
179 | // case 1: { |
|
181 | // case 1: { | |
180 | // QList<QChartDataPoint> data; |
|
182 | // QList<QChartDataPoint> data; | |
181 | // for (int x = 0; x < 100; x++) { |
|
183 | // for (int x = 0; x < 100; x++) { | |
182 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
184 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
183 | // } |
|
185 | // } | |
184 | // m_chartWidget->setData(data); |
|
186 | // m_chartWidget->setData(data); | |
185 | // break; |
|
187 | // break; | |
186 | // } |
|
188 | // } | |
187 | // case 2: { |
|
189 | // case 2: { | |
188 | // QList<QChartDataPoint> data; |
|
190 | // QList<QChartDataPoint> data; | |
189 | // for (int x = 0; x < 1000; x++) { |
|
191 | // for (int x = 0; x < 1000; x++) { | |
190 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
192 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
191 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
193 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
192 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
194 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
193 | // } |
|
195 | // } | |
194 | // m_chartWidget->setData(data); |
|
196 | // m_chartWidget->setData(data); | |
195 | // break; |
|
197 | // break; | |
196 | // } |
|
198 | // } | |
197 | // default: |
|
199 | // default: | |
198 | // break; |
|
200 | // break; | |
199 | // } |
|
201 | // } | |
200 | } |
|
202 | } | |
201 |
|
203 | |||
202 | void MainWidget::backgroundChanged(int itemIndex) |
|
204 | void MainWidget::backgroundChanged(int itemIndex) | |
203 | { |
|
205 | { | |
204 | qDebug() << "backgroundChanged: " << itemIndex; |
|
206 | qDebug() << "backgroundChanged: " << itemIndex; | |
205 | } |
|
207 | } | |
206 |
|
208 | |||
207 | void MainWidget::autoScaleChanged(int value) |
|
209 | void MainWidget::autoScaleChanged(int value) | |
208 | { |
|
210 | { | |
209 | if (value) { |
|
211 | if (value) { | |
210 | // TODO: enable auto scaling |
|
212 | // TODO: enable auto scaling | |
211 | } else { |
|
213 | } else { | |
212 | // TODO: set scaling manually (and disable auto scaling) |
|
214 | // TODO: set scaling manually (and disable auto scaling) | |
213 | } |
|
215 | } | |
214 |
|
216 | |||
215 | m_xMinSpin->setEnabled(!value); |
|
217 | m_xMinSpin->setEnabled(!value); | |
216 | m_xMaxSpin->setEnabled(!value); |
|
218 | m_xMaxSpin->setEnabled(!value); | |
217 | m_yMinSpin->setEnabled(!value); |
|
219 | m_yMinSpin->setEnabled(!value); | |
218 | m_yMaxSpin->setEnabled(!value); |
|
220 | m_yMaxSpin->setEnabled(!value); | |
219 | } |
|
221 | } | |
220 |
|
222 | |||
221 | void MainWidget::xMinChanged(int value) |
|
223 | void MainWidget::xMinChanged(int value) | |
222 | { |
|
224 | { | |
223 | qDebug() << "xMinChanged: " << value; |
|
225 | qDebug() << "xMinChanged: " << value; | |
224 | } |
|
226 | } | |
225 |
|
227 | |||
226 | void MainWidget::xMaxChanged(int value) |
|
228 | void MainWidget::xMaxChanged(int value) | |
227 | { |
|
229 | { | |
228 | qDebug() << "xMaxChanged: " << value; |
|
230 | qDebug() << "xMaxChanged: " << value; | |
229 | } |
|
231 | } | |
230 |
|
232 | |||
231 | void MainWidget::yMinChanged(int value) |
|
233 | void MainWidget::yMinChanged(int value) | |
232 | { |
|
234 | { | |
233 | qDebug() << "yMinChanged: " << value; |
|
235 | qDebug() << "yMinChanged: " << value; | |
234 | } |
|
236 | } | |
235 |
|
237 | |||
236 | void MainWidget::yMaxChanged(int value) |
|
238 | void MainWidget::yMaxChanged(int value) | |
237 | { |
|
239 | { | |
238 | qDebug() << "yMaxChanged: " << value; |
|
240 | qDebug() << "yMaxChanged: " << value; | |
239 | } |
|
241 | } |
General Comments 0
You need to be logged in to leave comments.
Login now