@@ -0,0 +1,63 | |||||
|
1 | #include "chartwidget.h" | |||
|
2 | #include <QMouseEvent> | |||
|
3 | ||||
|
4 | ChartWidget::ChartWidget(QWidget *parent) | |||
|
5 | : QChartView(parent), | |||
|
6 | m_rubberBand(QRubberBand::Rectangle,this) | |||
|
7 | { | |||
|
8 | } | |||
|
9 | ||||
|
10 | void ChartWidget::mousePressEvent(QMouseEvent *event) | |||
|
11 | { | |||
|
12 | if(event->button()!=Qt::LeftButton) return; | |||
|
13 | ||||
|
14 | int margin = this->margin(); | |||
|
15 | ||||
|
16 | QRect rect(margin,margin,width()-2*margin,height()-2*margin); | |||
|
17 | ||||
|
18 | m_origin = event->pos(); | |||
|
19 | ||||
|
20 | if (!rect.contains(m_origin)) return; | |||
|
21 | ||||
|
22 | m_rubberBand.setGeometry(QRect(m_origin, QSize())); | |||
|
23 | m_rubberBand.show(); | |||
|
24 | ||||
|
25 | event->accept(); | |||
|
26 | } | |||
|
27 | ||||
|
28 | void ChartWidget::mouseMoveEvent(QMouseEvent *event) | |||
|
29 | { | |||
|
30 | if(m_rubberBand.isVisible()) | |||
|
31 | m_rubberBand.setGeometry(QRect(m_origin, event->pos()).normalized()); | |||
|
32 | } | |||
|
33 | ||||
|
34 | void ChartWidget::mouseReleaseEvent(QMouseEvent *event) | |||
|
35 | { | |||
|
36 | if( event->button()==Qt::LeftButton && m_rubberBand.isVisible()) { | |||
|
37 | m_rubberBand.hide(); | |||
|
38 | ||||
|
39 | QRect rect = m_rubberBand.geometry(); | |||
|
40 | zoomInToRect(rect); | |||
|
41 | event->accept(); | |||
|
42 | } | |||
|
43 | ||||
|
44 | if(event->button()==Qt::RightButton) { | |||
|
45 | zoomOut(); | |||
|
46 | } | |||
|
47 | } | |||
|
48 | ||||
|
49 | ||||
|
50 | void ChartWidget::keyPressEvent(QKeyEvent *event) | |||
|
51 | { | |||
|
52 | switch (event->key()) { | |||
|
53 | case Qt::Key_Plus: | |||
|
54 | zoomIn(); | |||
|
55 | break; | |||
|
56 | case Qt::Key_Minus: | |||
|
57 | zoomOut(); | |||
|
58 | break; | |||
|
59 | default: | |||
|
60 | QGraphicsView::keyPressEvent(event); | |||
|
61 | break; | |||
|
62 | } | |||
|
63 | } |
@@ -0,0 +1,28 | |||||
|
1 | #ifndef CHARTWIDGET_H | |||
|
2 | #define CHARTWIDGET_H | |||
|
3 | #include <qchartview.h> | |||
|
4 | #include <QRubberBand> | |||
|
5 | ||||
|
6 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
7 | ||||
|
8 | class ChartWidget : public QChartView | |||
|
9 | { | |||
|
10 | Q_OBJECT | |||
|
11 | ||||
|
12 | public: | |||
|
13 | ChartWidget(QWidget *parent = 0); | |||
|
14 | ||||
|
15 | protected: | |||
|
16 | void mousePressEvent(QMouseEvent *event); | |||
|
17 | void mouseMoveEvent(QMouseEvent *event); | |||
|
18 | void mouseReleaseEvent(QMouseEvent *event); | |||
|
19 | void keyPressEvent(QKeyEvent *event); | |||
|
20 | ||||
|
21 | private: | |||
|
22 | bool rubberBandIsShown; | |||
|
23 | QRubberBand m_rubberBand; | |||
|
24 | QPoint m_origin; | |||
|
25 | ||||
|
26 | }; | |||
|
27 | ||||
|
28 | #endif |
@@ -0,0 +1,38 | |||||
|
1 | #include "chartwidget.h" | |||
|
2 | #include <QApplication> | |||
|
3 | #include <QMainWindow> | |||
|
4 | #include <qxychartseries.h> | |||
|
5 | #include <cmath> | |||
|
6 | ||||
|
7 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
8 | ||||
|
9 | #define PI 3.14159265358979 | |||
|
10 | ||||
|
11 | int main(int argc, char *argv[]) | |||
|
12 | { | |||
|
13 | QApplication a(argc, argv); | |||
|
14 | ||||
|
15 | QMainWindow window; | |||
|
16 | ||||
|
17 | QXYChartSeries* series0 = QXYChartSeries::create(); | |||
|
18 | series0->setColor(Qt::blue); | |||
|
19 | QXYChartSeries* series1 = QXYChartSeries::create(); | |||
|
20 | series1->setColor(Qt::red); | |||
|
21 | ||||
|
22 | int numPoints = 100; | |||
|
23 | ||||
|
24 | for (int x = 0; x <= numPoints; ++x) { | |||
|
25 | series0->add(x, abs(sin(PI/50*x)*100)); | |||
|
26 | series1->add(x, abs(cos(PI/50*x)*100)); | |||
|
27 | } | |||
|
28 | ||||
|
29 | ChartWidget* chartWidget = new ChartWidget(&window); | |||
|
30 | chartWidget->addSeries(series0); | |||
|
31 | chartWidget->addSeries(series1); | |||
|
32 | ||||
|
33 | window.setCentralWidget(chartWidget); | |||
|
34 | window.resize(400, 300); | |||
|
35 | window.show(); | |||
|
36 | ||||
|
37 | return a.exec(); | |||
|
38 | } |
@@ -0,0 +1,17 | |||||
|
1 | !include( ../../common.pri ) { | |||
|
2 | error( "Couldn't find the common.pri file!" ) | |||
|
3 | } | |||
|
4 | ||||
|
5 | !include( ../../integrated.pri ) { | |||
|
6 | error( "Couldn't find the integrated.pri file !") | |||
|
7 | } | |||
|
8 | ||||
|
9 | TARGET = zoomLineChart | |||
|
10 | TEMPLATE = app | |||
|
11 | QT += core gui | |||
|
12 | HEADERS += chartwidget.h | |||
|
13 | SOURCES += main.cpp chartwidget.cpp | |||
|
14 | ||||
|
15 | ||||
|
16 | ||||
|
17 |
@@ -0,0 +1,95 | |||||
|
1 | #include "axisitem_p.h" | |||
|
2 | #include <QPainter> | |||
|
3 | #include <QDebug> | |||
|
4 | ||||
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
6 | ||||
|
7 | AxisItem::AxisItem(AxisType type,QGraphicsItem* parent): ChartItem(parent), | |||
|
8 | m_ticks(4), | |||
|
9 | m_type(type) | |||
|
10 | { | |||
|
11 | } | |||
|
12 | ||||
|
13 | AxisItem::~AxisItem() | |||
|
14 | { | |||
|
15 | } | |||
|
16 | ||||
|
17 | void AxisItem::setSize(const QSize& size) | |||
|
18 | { | |||
|
19 | m_rect = QRectF(QPoint(0,0),size); | |||
|
20 | } | |||
|
21 | ||||
|
22 | void AxisItem::setLength(int length) | |||
|
23 | { | |||
|
24 | QPainterPath path; | |||
|
25 | path.moveTo(QPointF(0,0)); | |||
|
26 | path.lineTo(length,0); | |||
|
27 | // path.lineTo(length-4,0); | |||
|
28 | // path.lineTo(length,3); | |||
|
29 | // path.lineTo(length-4,6); | |||
|
30 | // path.lineTo(length-4,4); | |||
|
31 | // path.lineTo(0,4); | |||
|
32 | // path.lineTo(0,2); | |||
|
33 | m_path=path; | |||
|
34 | update(); | |||
|
35 | } | |||
|
36 | ||||
|
37 | QRectF AxisItem::boundingRect() const | |||
|
38 | { | |||
|
39 | return m_rect; | |||
|
40 | } | |||
|
41 | ||||
|
42 | void AxisItem::setPlotDomain(const PlotDomain& plotDomain) | |||
|
43 | { | |||
|
44 | m_plotDomain = plotDomain; | |||
|
45 | } | |||
|
46 | ||||
|
47 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) | |||
|
48 | { | |||
|
49 | if (!m_rect.isValid()) | |||
|
50 | return; | |||
|
51 | ||||
|
52 | if(m_type==X_AXIS) { | |||
|
53 | ||||
|
54 | const qreal deltaX = (m_rect.width() -1) / m_ticks; | |||
|
55 | ||||
|
56 | for (int i = 0; i <= m_ticks; ++i) { | |||
|
57 | ||||
|
58 | int x = i * deltaX + m_rect.left(); | |||
|
59 | qreal label = m_plotDomain.m_minX + (i * m_plotDomain.spanX() | |||
|
60 | / m_ticks); | |||
|
61 | painter->drawLine(x, m_rect.top()+1, x, m_rect.bottom()); | |||
|
62 | //painter->drawLine(x, m_rect.bottom(), x, m_rect.bottom() + 5); | |||
|
63 | ||||
|
64 | painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20, | |||
|
65 | Qt::AlignHCenter | Qt::AlignTop, | |||
|
66 | QString::number(label)); | |||
|
67 | } | |||
|
68 | } | |||
|
69 | ||||
|
70 | if(m_type==Y_AXIS) { | |||
|
71 | ||||
|
72 | const qreal deltaY = (m_rect.height() - 1) / m_ticks; | |||
|
73 | ||||
|
74 | for (int j = 0; j <= m_ticks; ++j) { | |||
|
75 | ||||
|
76 | int y = j * -deltaY + m_rect.bottom(); | |||
|
77 | qreal label = m_plotDomain.m_minY + (j * m_plotDomain.spanY() | |||
|
78 | / m_ticks); | |||
|
79 | ||||
|
80 | painter->drawLine(m_rect.left(), y, m_rect.right()-1, y); | |||
|
81 | //painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y); | |||
|
82 | //TODO : margin = 50 ; | |||
|
83 | painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20, | |||
|
84 | Qt::AlignRight | Qt::AlignVCenter, | |||
|
85 | QString::number(label)); | |||
|
86 | } | |||
|
87 | } | |||
|
88 | ||||
|
89 | //painter->drawRect(m_rect.adjusted(0, 0, -1, -1)); | |||
|
90 | ||||
|
91 | } | |||
|
92 | ||||
|
93 | //TODO "nice numbers algorithm" | |||
|
94 | ||||
|
95 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,40 | |||||
|
1 | #ifndef AXISITEM_H_ | |||
|
2 | #define AXISITEM_H_ | |||
|
3 | ||||
|
4 | #include "chartitem_p.h" | |||
|
5 | #include "plotdomain_p.h" | |||
|
6 | #include <QGraphicsItem> | |||
|
7 | ||||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
9 | ||||
|
10 | class AxisItem: public ChartItem | |||
|
11 | { | |||
|
12 | public: | |||
|
13 | enum AxisType{X_AXIS,Y_AXIS}; | |||
|
14 | ||||
|
15 | AxisItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0); | |||
|
16 | ~AxisItem(); | |||
|
17 | ||||
|
18 | //from QGraphicsItem | |||
|
19 | QRectF boundingRect() const; | |||
|
20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |||
|
21 | ||||
|
22 | //from ChartItem | |||
|
23 | void setSize(const QSize& size); | |||
|
24 | void setPlotDomain(const PlotDomain& data); | |||
|
25 | ||||
|
26 | void setLength(int length); | |||
|
27 | void setWidth(int width); | |||
|
28 | AxisType axisType() const {return m_type;}; | |||
|
29 | ||||
|
30 | private: | |||
|
31 | QRectF m_rect; | |||
|
32 | int m_ticks; | |||
|
33 | PlotDomain m_plotDomain; | |||
|
34 | QPainterPath m_path; | |||
|
35 | AxisType m_type; | |||
|
36 | }; | |||
|
37 | ||||
|
38 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
39 | ||||
|
40 | #endif /* AXISITEM_H_ */ |
@@ -0,0 +1,22 | |||||
|
1 | #ifndef CHARTITEM_H_ | |||
|
2 | #define CHARTITEM_H_ | |||
|
3 | ||||
|
4 | #include "plotdomain_p.h" | |||
|
5 | #include <QGraphicsItem> | |||
|
6 | ||||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
8 | ||||
|
9 | class ChartItem : public QGraphicsItem | |||
|
10 | { | |||
|
11 | enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM}; | |||
|
12 | public: | |||
|
13 | ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){}; | |||
|
14 | virtual ~ChartItem(){}; | |||
|
15 | ||||
|
16 | virtual void setSize(const QSize& size) = 0; | |||
|
17 | virtual void setPlotDomain(const PlotDomain& data) = 0; | |||
|
18 | }; | |||
|
19 | ||||
|
20 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
21 | ||||
|
22 | #endif /* CHARTITEM_H_ */ |
@@ -1,2 +1,3 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | SUBDIRS += linechart |
|
2 | SUBDIRS += linechart \ | |
|
3 | zoomlinechart |
@@ -1,55 +1,39 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qxychartseries.h> |
|
4 | #include <qxychartseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
9 |
|
9 | |||
10 | #define PI 3.14159265358979 |
|
10 | #define PI 3.14159265358979 | |
11 |
|
11 | |||
12 | int main(int argc, char *argv[]) |
|
12 | int main(int argc, char *argv[]) | |
13 | { |
|
13 | { | |
14 | QApplication a(argc, argv); |
|
14 | QApplication a(argc, argv); | |
15 |
|
15 | |||
16 | QMainWindow window; |
|
16 | QMainWindow window; | |
17 |
|
17 | |||
18 | QXYChartSeries* series0 = QXYChartSeries::create(); |
|
18 | QXYChartSeries* series0 = QXYChartSeries::create(); | |
19 | series0->setColor(Qt::blue); |
|
19 | series0->setColor(Qt::blue); | |
20 | QXYChartSeries* series1 = QXYChartSeries::create(); |
|
20 | QXYChartSeries* series1 = QXYChartSeries::create(); | |
21 | series1->setColor(Qt::red); |
|
21 | series1->setColor(Qt::red); | |
22 | QXYChartSeries* series2 = QXYChartSeries::create(); |
|
|||
23 | series2->setColor(Qt::gray); |
|
|||
24 | QXYChartSeries* series3 = QXYChartSeries::create(); |
|
|||
25 | series3->setColor(Qt::green); |
|
|||
26 |
|
22 | |||
27 | int numPoints = 100; |
|
23 | int numPoints = 100; | |
28 |
|
24 | |||
29 | for (int x = 0; x < numPoints; ++x) { |
|
25 | for (int x = 0; x <= numPoints; ++x) { | |
30 | series0->add(x,0); |
|
26 | series0->add(x, abs(sin(PI/50*x)*100)); | |
31 |
series1->add(x, abs(s |
|
27 | series1->add(x, abs(cos(PI/50*x)*100)); | |
32 | series2->add(x, abs(cos(PI/50*x)*100)); |
|
28 | } | |
33 | series3->add(x,100); |
|
|||
34 | } |
|
|||
35 |
|
||||
36 | QList<QXYChartSeries*> dataset; |
|
|||
37 |
|
||||
38 | //qDebug()<<"Series 1:" << *series1; |
|
|||
39 | //qDebug()<<"Series 2:" << *series2; |
|
|||
40 |
|
||||
41 | dataset << series0; |
|
|||
42 | dataset << series1; |
|
|||
43 | dataset << series2; |
|
|||
44 | dataset << series3; |
|
|||
45 |
|
29 | |||
46 | QChartView* chartView = new QChartView(&window); |
|
30 | QChartView* chartView = new QChartView(&window); | |
|
31 | chartView->addSeries(series0); | |||
47 | chartView->addSeries(series1); |
|
32 | chartView->addSeries(series1); | |
48 | chartView->addSeries(series2); |
|
|||
49 |
|
33 | |||
50 | window.setCentralWidget(chartView); |
|
34 | window.setCentralWidget(chartView); | |
51 | window.resize(400, 300); |
|
35 | window.resize(400, 300); | |
52 | window.show(); |
|
36 | window.show(); | |
53 |
|
37 | |||
54 | return a.exec(); |
|
38 | return a.exec(); | |
55 | } |
|
39 | } |
@@ -1,33 +1,31 | |||||
1 |
#include " |
|
1 | #include "plotdomain_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 |
|
|
5 | PlotDomain::PlotDomain(): | |
6 | m_ticksX(0), |
|
|||
7 | m_ticksY(0), |
|
|||
8 | m_minX(0), |
|
6 | m_minX(0), | |
9 | m_maxX(0), |
|
7 | m_maxX(0), | |
10 | m_minY(0), |
|
8 | m_minY(0), | |
11 | m_maxY(0) |
|
9 | m_maxY(0) | |
12 | { |
|
10 | { | |
13 |
|
11 | |||
14 | } |
|
12 | } | |
15 |
|
13 | |||
16 |
|
|
14 | PlotDomain::~PlotDomain() | |
17 | { |
|
15 | { | |
18 | // TODO Auto-generated destructor stub |
|
16 | // TODO Auto-generated destructor stub | |
19 | } |
|
17 | } | |
20 |
|
18 | |||
21 |
qreal |
|
19 | qreal PlotDomain::spanX() const | |
22 | { |
|
20 | { | |
23 | Q_ASSERT(m_maxX >= m_minX); |
|
21 | Q_ASSERT(m_maxX >= m_minX); | |
24 | return m_maxX - m_minX; |
|
22 | return m_maxX - m_minX; | |
25 | } |
|
23 | } | |
26 |
|
24 | |||
27 |
qreal |
|
25 | qreal PlotDomain::spanY() const | |
28 | { |
|
26 | { | |
29 | Q_ASSERT(m_maxY >= m_minY); |
|
27 | Q_ASSERT(m_maxY >= m_minY); | |
30 | return m_maxY - m_minY; |
|
28 | return m_maxY - m_minY; | |
31 | } |
|
29 | } | |
32 |
|
30 | |||
33 | QTCOMMERCIALCHART_END_NAMESPACE |
|
31 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,30 +1,25 | |||||
1 | #ifndef PLOTDOMAIN_H_ |
|
1 | #ifndef PLOTDOMAIN_H_ | |
2 | #define PLOTDOMAIN_H_ |
|
2 | #define PLOTDOMAIN_H_ | |
3 | #include "qchartglobal.h" |
|
3 | #include "qchartglobal.h" | |
4 | #include <QRect> |
|
4 | #include <QRect> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 |
class |
|
8 | class PlotDomain { | |
9 | public: |
|
9 | public: | |
10 |
|
|
10 | PlotDomain(); | |
11 |
virtual ~ |
|
11 | virtual ~PlotDomain(); | |
12 |
|
12 | |||
13 | qreal spanX() const; |
|
13 | qreal spanX() const; | |
14 | qreal spanY() const; |
|
14 | qreal spanY() const; | |
15 | int ticksX() const { return m_ticksX; } |
|
|||
16 | int ticksY() const { return m_ticksY; } |
|
|||
17 |
|
15 | |||
18 | public: |
|
16 | public: | |
19 | int m_ticksX; |
|
|||
20 | int m_ticksY; |
|
|||
21 | qreal m_minX; |
|
17 | qreal m_minX; | |
22 | qreal m_maxX; |
|
18 | qreal m_maxX; | |
23 | qreal m_minY; |
|
19 | qreal m_minY; | |
24 | qreal m_maxY; |
|
20 | qreal m_maxY; | |
25 | QRect m_viewportRect; |
|
|||
26 | }; |
|
21 | }; | |
27 |
|
22 | |||
28 | QTCOMMERCIALCHART_END_NAMESPACE |
|
23 | QTCOMMERCIALCHART_END_NAMESPACE | |
29 |
|
24 | |||
30 | #endif /* PLOTTER_H_ */ |
|
25 | #endif /* PLOTTER_H_ */ |
@@ -1,213 +1,264 | |||||
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 "qpieseries.h" | |
6 | #include "qxychartseries.h" |
|
6 | #include "qxychartseries.h" | |
7 |
|
7 | |||
8 | #include "barchartseries.h" |
|
8 | #include "barchartseries.h" | |
9 | #include "bargroup.h" |
|
9 | #include "bargroup.h" | |
10 |
|
10 | |||
11 | #include "xylinechartitem_p.h" |
|
11 | #include "xylinechartitem_p.h" | |
12 |
#include " |
|
12 | #include "plotdomain_p.h" | |
13 | #include "axis_p.h" |
|
13 | #include "axisitem_p.h" | |
14 | #include "xygrid_p.h" |
|
|||
15 | #include <QGraphicsScene> |
|
14 | #include <QGraphicsScene> | |
16 | #include <QDebug> |
|
15 | #include <QDebug> | |
17 |
|
16 | |||
18 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
17 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
19 |
|
18 | |||
20 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), |
|
19 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), | |
21 | m_axisX(new Axis(this)), |
|
20 | m_axisX(new AxisItem(AxisItem::X_AXIS,this)), | |
22 | m_axisY(new Axis(this)), |
|
21 | m_axisY(new AxisItem(AxisItem::Y_AXIS,this)), | |
23 | m_grid(new XYGrid(this)), |
|
|||
24 | m_plotDataIndex(0), |
|
22 | m_plotDataIndex(0), | |
25 | m_marginSize(0) |
|
23 | m_marginSize(0) | |
26 | { |
|
24 | { | |
27 | // TODO: the default theme? |
|
25 | // TODO: the default theme? | |
28 | setTheme(QChart::ChartThemeVanilla); |
|
26 | setTheme(QChart::ChartThemeVanilla); | |
29 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
27 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
30 | // set axis |
|
28 | PlotDomain domain; | |
31 | m_axisY->rotate(90); |
|
29 | m_plotDomainList<<domain; | |
|
30 | ||||
|
31 | m_chartItems<<m_axisX; | |||
|
32 | m_chartItems<<m_axisY; | |||
32 | } |
|
33 | } | |
33 |
|
34 | |||
34 | QChart::~QChart(){} |
|
35 | QChart::~QChart(){} | |
35 |
|
36 | |||
36 | QRectF QChart::boundingRect() const |
|
37 | QRectF QChart::boundingRect() const | |
37 | { |
|
38 | { | |
38 | return m_rect; |
|
39 | return m_rect; | |
39 | } |
|
40 | } | |
40 |
|
41 | |||
41 | void QChart::addSeries(QChartSeries* series) |
|
42 | void QChart::addSeries(QChartSeries* series) | |
42 | { |
|
43 | { | |
43 | // TODO: we should check the series not already added |
|
44 | // TODO: we should check the series not already added | |
44 |
|
45 | |||
45 | m_series<<series; |
|
46 | m_series<<series; | |
46 |
|
47 | |||
47 | switch(series->type()) |
|
48 | switch(series->type()) | |
48 | { |
|
49 | { | |
49 | case QChartSeries::SeriesTypeLine: { |
|
50 | case QChartSeries::SeriesTypeLine: { | |
50 |
|
51 | |||
51 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
52 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
52 | // Use color defined by theme in case the series does not define a custom color |
|
53 | // Use color defined by theme in case the series does not define a custom color | |
53 | if (!xyseries->color().isValid() && m_themeColors.count()) |
|
54 | if (!xyseries->color().isValid() && m_themeColors.count()) | |
54 | xyseries->setColor(m_themeColors.takeFirst()); |
|
55 | xyseries->setColor(m_themeColors.takeFirst()); | |
55 |
|
56 | |||
56 | XYPlotDomain domain; |
|
57 | m_plotDataIndex = 0 ; | |
57 | //TODO "nice numbers algorithm" |
|
58 | m_plotDomainList.resize(1); | |
58 | domain.m_ticksX=4; |
|
59 | ||
59 | domain.m_ticksY=4; |
|
60 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
60 |
|
61 | |||
61 | for (int i = 0 ; i < xyseries->count() ; i++) |
|
62 | for (int i = 0 ; i < xyseries->count() ; i++) | |
62 | { |
|
63 | { | |
63 | qreal x = xyseries->x(i); |
|
64 | qreal x = xyseries->x(i); | |
64 | qreal y = xyseries->y(i); |
|
65 | qreal y = xyseries->y(i); | |
65 | domain.m_minX = qMin(domain.m_minX,x); |
|
66 | domain.m_minX = qMin(domain.m_minX,x); | |
66 | domain.m_minY = qMin(domain.m_minY,y); |
|
67 | domain.m_minY = qMin(domain.m_minY,y); | |
67 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
68 | domain.m_maxX = qMax(domain.m_maxX,x); | |
68 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
69 | domain.m_maxY = qMax(domain.m_maxY,y); | |
69 | } |
|
70 | } | |
70 |
|
71 | |||
71 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); |
|
72 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); | |
72 | item->updateXYPlotDomain(domain); |
|
73 | ||
73 | m_plotDomainList<<domain; |
|
74 | m_chartItems<<item; | |
74 | m_xyLineChartItems<<item; |
|
75 | ||
|
76 | foreach(ChartItem* i ,m_chartItems) | |||
|
77 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |||
|
78 | ||||
75 | break; |
|
79 | break; | |
76 | } |
|
80 | } | |
77 | case QChartSeries::SeriesTypeBar: { |
|
81 | case QChartSeries::SeriesTypeBar: { | |
78 |
|
82 | |||
79 | qDebug() << "barSeries added"; |
|
83 | qDebug() << "barSeries added"; | |
80 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
84 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
81 |
|
85 | |||
82 | // Who owns the series? |
|
86 | // Who owns the series? | |
83 | BarGroup* group = new BarGroup(*barSeries, this); |
|
87 | BarGroup* group = new BarGroup(*barSeries, this); | |
84 | scene()->addItem(group); |
|
88 | scene()->addItem(group); | |
85 | m_BarGroupItems.append(group); // If we need to access group later |
|
89 | m_BarGroupItems.append(group); // If we need to access group later | |
86 | break; |
|
90 | break; | |
87 | } |
|
91 | } | |
88 | case QChartSeries::SeriesTypeScatter: { |
|
92 | case QChartSeries::SeriesTypeScatter: { | |
89 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
93 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
90 | connect(this, SIGNAL(sizeChanged(QRectF)), |
|
94 | connect(this, SIGNAL(sizeChanged(QRectF)), | |
91 | scatterSeries, SLOT(chartSizeChanged(QRectF))); |
|
95 | scatterSeries, SLOT(chartSizeChanged(QRectF))); | |
92 | scatterSeries->d->setParentItem(this); |
|
96 | scatterSeries->d->setParentItem(this); | |
93 | QColor nextColor = m_themeColors.takeFirst(); |
|
97 | QColor nextColor = m_themeColors.takeFirst(); | |
94 | nextColor.setAlpha(150); // TODO: default opacity? |
|
98 | nextColor.setAlpha(150); // TODO: default opacity? | |
95 | scatterSeries->setMarkerColor(nextColor); |
|
99 | scatterSeries->setMarkerColor(nextColor); | |
96 | } |
|
100 | } | |
97 | case QChartSeries::SeriesTypePie: { |
|
101 | case QChartSeries::SeriesTypePie: { | |
98 | // TODO: we now have also a list of y values as a parameter, it is ignored |
|
102 | // TODO: we now have also a list of y values as a parameter, it is ignored | |
99 | // we should use a generic data class instead of list of x and y values |
|
103 | // we should use a generic data class instead of list of x and y values | |
100 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
104 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
101 | connect(this, SIGNAL(sizeChanged(QRectF)), |
|
105 | connect(this, SIGNAL(sizeChanged(QRectF)), | |
102 | pieSeries, SLOT(chartSizeChanged(QRectF))); |
|
106 | pieSeries, SLOT(chartSizeChanged(QRectF))); | |
103 | // TODO: how to define the color for all the slices of a pie? |
|
107 | // TODO: how to define the color for all the slices of a pie? | |
104 | } |
|
108 | } | |
105 | } |
|
109 | } | |
106 | } |
|
110 | } | |
107 |
|
111 | |||
108 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
112 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
109 | { |
|
113 | { | |
110 | // TODO: support also other types; not only scatter and pie |
|
114 | // TODO: support also other types; not only scatter and pie | |
111 |
|
115 | |||
112 | QChartSeries *series(0); |
|
116 | QChartSeries *series(0); | |
113 |
|
117 | |||
114 | switch (type) { |
|
118 | switch (type) { | |
115 | case QChartSeries::SeriesTypeLine: { |
|
119 | case QChartSeries::SeriesTypeLine: { | |
116 | series = QXYChartSeries::create(); |
|
120 | series = QXYChartSeries::create(); | |
117 | break; |
|
121 | break; | |
118 | } |
|
122 | } | |
119 | case QChartSeries::SeriesTypeBar: { |
|
123 | case QChartSeries::SeriesTypeBar: { | |
120 | series = new BarChartSeries(this); |
|
124 | series = new BarChartSeries(this); | |
121 | break; |
|
125 | break; | |
122 | } |
|
126 | } | |
123 | case QChartSeries::SeriesTypeScatter: { |
|
127 | case QChartSeries::SeriesTypeScatter: { | |
124 | series = new QScatterSeries(this); |
|
128 | series = new QScatterSeries(this); | |
125 | break; |
|
129 | break; | |
126 | } |
|
130 | } | |
127 | case QChartSeries::SeriesTypePie: { |
|
131 | case QChartSeries::SeriesTypePie: { | |
128 | series = new QPieSeries(this); |
|
132 | series = new QPieSeries(this); | |
129 | break; |
|
133 | break; | |
130 | } |
|
134 | } | |
131 | default: |
|
135 | default: | |
132 | Q_ASSERT(false); |
|
136 | Q_ASSERT(false); | |
133 | break; |
|
137 | break; | |
134 | } |
|
138 | } | |
135 |
|
139 | |||
136 | addSeries(series); |
|
140 | addSeries(series); | |
137 | return series; |
|
141 | return series; | |
138 | } |
|
142 | } | |
139 |
|
143 | |||
140 |
void QChart::setSize(const QSize |
|
144 | void QChart::setSize(const QSize& size) | |
141 | { |
|
145 | { | |
142 |
m_rect = QRect(QPoint(0,0),size |
|
146 | m_rect = QRect(QPoint(0,0),size); | |
143 | m_rect.adjust(margin(),margin(), -margin(), -margin()); |
|
147 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
144 | m_grid->setPos(m_rect.topLeft()); |
|
148 | ||
145 | m_grid->setSize(m_rect.size()); |
|
149 | foreach (ChartItem* item ,m_chartItems) { | |
|
150 | item->setPos(rect.topLeft()); | |||
|
151 | item->setSize(rect.size()); | |||
146 |
|
152 | |||
|
153 | } | |||
147 | // TODO: TTD for setting scale |
|
154 | // TODO: TTD for setting scale | |
148 | //emit scaleChanged(100, 100); |
|
155 | //emit scaleChanged(100, 100); | |
149 | // TODO: calculate the origo |
|
156 | // TODO: calculate the origo | |
150 | // TODO: not sure if emitting a signal here is the best from performance point of view |
|
157 | // TODO: not sure if emitting a signal here is the best from performance point of view | |
151 | emit sizeChanged(QRectF(0, 0, size.width(), size.height())); |
|
158 | emit sizeChanged(QRectF(0, 0, size.width(), size.height())); | |
152 |
|
159 | |||
153 | for (int i(0); i < m_plotDomainList.size(); i++) |
|
|||
154 | m_plotDomainList[i].m_viewportRect = m_rect; |
|
|||
155 |
|
||||
156 | // TODO: line chart items are updated separately as they don't support update |
|
|||
157 | // via sizeChanged signal |
|
|||
158 | foreach(XYLineChartItem* item ,m_xyLineChartItems) |
|
|||
159 | item->updateXYPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
|||
160 |
|
||||
161 |
|
||||
162 | if (m_plotDomainList.count()) |
|
|||
163 | m_grid->setXYPlotData(m_plotDomainList.at(m_plotDataIndex)); |
|
|||
164 |
|
||||
165 | update(); |
|
160 | update(); | |
166 | } |
|
161 | } | |
167 |
|
162 | |||
168 | int QChart::margin() const |
|
163 | int QChart::margin() const | |
169 | { |
|
164 | { | |
170 | return m_marginSize; |
|
165 | return m_marginSize; | |
171 | } |
|
166 | } | |
172 |
|
167 | |||
173 | void QChart::setMargin(int margin) |
|
168 | void QChart::setMargin(int margin) | |
174 | { |
|
169 | { | |
175 | m_marginSize = margin; |
|
170 | m_marginSize = margin; | |
176 | } |
|
171 | } | |
177 |
|
172 | |||
178 | void QChart::setTheme(QChart::ChartTheme theme) |
|
173 | void QChart::setTheme(QChart::ChartTheme theme) | |
179 | { |
|
174 | { | |
180 | // TODO: define color themes |
|
175 | // TODO: define color themes | |
181 | switch (theme) { |
|
176 | switch (theme) { | |
182 | case ChartThemeVanilla: |
|
177 | case ChartThemeVanilla: | |
183 | m_themeColors.append(QColor(255, 238, 174)); |
|
178 | m_themeColors.append(QColor(255, 238, 174)); | |
184 | m_themeColors.append(QColor(228, 228, 160)); |
|
179 | m_themeColors.append(QColor(228, 228, 160)); | |
185 | m_themeColors.append(QColor(228, 179, 160)); |
|
180 | m_themeColors.append(QColor(228, 179, 160)); | |
186 | m_themeColors.append(QColor(180, 151, 18)); |
|
181 | m_themeColors.append(QColor(180, 151, 18)); | |
187 | m_themeColors.append(QColor(252, 252, 37)); |
|
182 | m_themeColors.append(QColor(252, 252, 37)); | |
188 | break; |
|
183 | break; | |
189 | case ChartThemeIcy: |
|
184 | case ChartThemeIcy: | |
190 | m_themeColors.append(QColor(255, 238, 174)); |
|
185 | m_themeColors.append(QColor(255, 238, 174)); | |
191 | m_themeColors.append(QColor(228, 228, 160)); |
|
186 | m_themeColors.append(QColor(228, 228, 160)); | |
192 | m_themeColors.append(QColor(228, 179, 160)); |
|
187 | m_themeColors.append(QColor(228, 179, 160)); | |
193 | m_themeColors.append(QColor(180, 151, 18)); |
|
188 | m_themeColors.append(QColor(180, 151, 18)); | |
194 | m_themeColors.append(QColor(252, 252, 37)); |
|
189 | m_themeColors.append(QColor(252, 252, 37)); | |
195 | break; |
|
190 | break; | |
196 | case ChartThemeGrayscale: |
|
191 | case ChartThemeGrayscale: | |
197 | m_themeColors.append(QColor(255, 238, 174)); |
|
192 | m_themeColors.append(QColor(255, 238, 174)); | |
198 | m_themeColors.append(QColor(228, 228, 160)); |
|
193 | m_themeColors.append(QColor(228, 228, 160)); | |
199 | m_themeColors.append(QColor(228, 179, 160)); |
|
194 | m_themeColors.append(QColor(228, 179, 160)); | |
200 | m_themeColors.append(QColor(180, 151, 18)); |
|
195 | m_themeColors.append(QColor(180, 151, 18)); | |
201 | m_themeColors.append(QColor(252, 252, 37)); |
|
196 | m_themeColors.append(QColor(252, 252, 37)); | |
202 | break; |
|
197 | break; | |
203 | default: |
|
198 | default: | |
204 | Q_ASSERT(false); |
|
199 | Q_ASSERT(false); | |
205 | break; |
|
200 | break; | |
206 | } |
|
201 | } | |
207 |
|
202 | |||
208 | // TODO: update coloring of different elements to match the selected theme |
|
203 | // TODO: update coloring of different elements to match the selected theme | |
209 | } |
|
204 | } | |
210 |
|
205 | |||
|
206 | void QChart::zoomInToRect(const QRect& rectangle) | |||
|
207 | { | |||
|
208 | ||||
|
209 | if(!rectangle.isValid()) return; | |||
|
210 | ||||
|
211 | qreal margin = this->margin(); | |||
|
212 | ||||
|
213 | QRect rect = rectangle.normalized(); | |||
|
214 | rect.translate(-margin, -margin); | |||
|
215 | ||||
|
216 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; | |||
|
217 | PlotDomain newDomain; | |||
|
218 | ||||
|
219 | qreal dx = oldDomain.spanX() / (m_rect.width() - 2 * margin); | |||
|
220 | qreal dy = oldDomain.spanY() / (m_rect.height() - 2 * margin); | |||
|
221 | ||||
|
222 | newDomain.m_minX = oldDomain.m_minX + dx * rect.left(); | |||
|
223 | newDomain.m_maxX = oldDomain.m_minX + dx * rect.right(); | |||
|
224 | newDomain.m_minY = oldDomain.m_maxY - dy * rect.bottom(); | |||
|
225 | newDomain.m_maxY = oldDomain.m_maxY - dy * rect.top(); | |||
|
226 | ||||
|
227 | m_plotDomainList.resize(m_plotDataIndex + 1); | |||
|
228 | m_plotDomainList<<newDomain; | |||
|
229 | m_plotDataIndex++; | |||
|
230 | ||||
|
231 | foreach (ChartItem* item ,m_chartItems) | |||
|
232 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |||
|
233 | update(); | |||
|
234 | } | |||
|
235 | ||||
|
236 | void QChart::zoomIn() | |||
|
237 | { | |||
|
238 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { | |||
|
239 | m_plotDataIndex++; | |||
|
240 | foreach (ChartItem* item ,m_chartItems) | |||
|
241 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |||
|
242 | update(); | |||
|
243 | }else{ | |||
|
244 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |||
|
245 | rect.setWidth(rect.width()/2); | |||
|
246 | rect.setHeight(rect.height()/2); | |||
|
247 | rect.moveCenter(m_rect.center()); | |||
|
248 | zoomInToRect(rect); | |||
|
249 | } | |||
|
250 | } | |||
|
251 | ||||
|
252 | void QChart::zoomOut() | |||
|
253 | { | |||
|
254 | if (m_plotDataIndex > 0) { | |||
|
255 | m_plotDataIndex--; | |||
|
256 | foreach (ChartItem* item ,m_chartItems) | |||
|
257 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |||
|
258 | update(); | |||
|
259 | } | |||
|
260 | } | |||
|
261 | ||||
211 | #include "moc_qchart.cpp" |
|
262 | #include "moc_qchart.cpp" | |
212 |
|
263 | |||
213 | QTCOMMERCIALCHART_END_NAMESPACE |
|
264 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,76 +1,80 | |||||
1 | #ifndef CHART_H |
|
1 | #ifndef CHART_H | |
2 | #define CHART_H |
|
2 | #define CHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsObject> |
|
6 | #include <QGraphicsObject> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class Axis; |
|
10 | class AxisItem; | |
11 | class XYGrid; |
|
|||
12 | class QChartSeries; |
|
11 | class QChartSeries; | |
13 |
class |
|
12 | class PlotDomain; | |
14 |
class |
|
13 | class ChartItem; | |
15 | class BarGroup; |
|
14 | class BarGroup; | |
16 |
|
15 | |||
17 | // TODO: We don't need to have QChart tied to QGraphicsItem: |
|
16 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
18 | //class QTCOMMERCIALCHART_EXPORT QChart |
|
17 | //class QTCOMMERCIALCHART_EXPORT QChart | |
19 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { |
|
18 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
20 | // public: QChartGraphicsItem(QChart &chart); |
|
19 | // public: QChartGraphicsItem(QChart &chart); | |
21 |
|
20 | |||
22 | /*! |
|
21 | /*! | |
23 | * TODO: define the responsibilities |
|
22 | * TODO: define the responsibilities | |
24 | */ |
|
23 | */ | |
25 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject |
|
24 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject | |
26 | { |
|
25 | { | |
27 | Q_OBJECT |
|
26 | Q_OBJECT | |
28 | public: |
|
27 | public: | |
29 | enum ChartTheme { |
|
28 | enum ChartTheme { | |
30 | ChartThemeVanilla = 0, |
|
29 | ChartThemeVanilla = 0, | |
31 | ChartThemeIcy, |
|
30 | ChartThemeIcy, | |
32 | ChartThemeGrayscale |
|
31 | ChartThemeGrayscale | |
33 | }; |
|
32 | }; | |
34 |
|
33 | |||
35 | public: |
|
34 | public: | |
36 | QChart(QGraphicsObject* parent = 0); |
|
35 | QChart(QGraphicsObject* parent = 0); | |
37 | ~QChart(); |
|
36 | ~QChart(); | |
38 |
|
37 | |||
39 | //from QGraphicsItem |
|
38 | //from QGraphicsItem | |
40 | QRectF boundingRect() const; |
|
39 | QRectF boundingRect() const; | |
41 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; |
|
40 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; | |
42 |
|
41 | |||
43 | void addSeries(QChartSeries* series); |
|
42 | void addSeries(QChartSeries* series); | |
44 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); |
|
43 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
45 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... |
|
44 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
46 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
45 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
47 |
|
46 | |||
48 |
|
|
47 | void setSize(const QSize& size); | |
49 | void setMargin(int margin); |
|
48 | void setMargin(int margin); | |
50 | int margin() const; |
|
49 | int margin() const; | |
51 | void setTheme(QChart::ChartTheme theme); |
|
50 | void setTheme(QChart::ChartTheme theme); | |
52 |
|
51 | |||
|
52 | void zoomInToRect(const QRect& rectangle); | |||
|
53 | void zoomIn(); | |||
|
54 | void zoomOut(); | |||
|
55 | ||||
53 | signals: |
|
56 | signals: | |
|
57 | //TODO chage to const QSize& size | |||
54 | void sizeChanged(QRectF rect); |
|
58 | void sizeChanged(QRectF rect); | |
55 | void scaleChanged(qreal xscale, qreal yscale); |
|
59 | void scaleChanged(qreal xscale, qreal yscale); | |
56 |
|
60 | |||
57 | private: |
|
61 | private: | |
58 | Q_DISABLE_COPY(QChart) |
|
62 | Q_DISABLE_COPY(QChart) | |
59 | Axis* m_axisX; |
|
63 | AxisItem* m_axisX; | |
60 | Axis* m_axisY; |
|
64 | AxisItem* m_axisY; | |
61 | XYGrid* m_grid; |
|
|||
62 | QRect m_rect; |
|
65 | QRect m_rect; | |
63 | QList<const QChartSeries*> m_series; |
|
66 | QList<const QChartSeries*> m_series; | |
64 |
Q |
|
67 | QVector<PlotDomain> m_plotDomainList; | |
65 |
QList< |
|
68 | QList<ChartItem*> m_chartItems; | |
|
69 | //TODO: remove | |||
66 | QList<QGraphicsItem*> m_items; |
|
70 | QList<QGraphicsItem*> m_items; | |
67 | int m_plotDataIndex; |
|
71 | int m_plotDataIndex; | |
68 | int m_marginSize; |
|
72 | int m_marginSize; | |
69 | QList<QColor> m_themeColors; |
|
73 | QList<QColor> m_themeColors; | |
70 |
|
74 | |||
71 | QList<BarGroup*> m_BarGroupItems; |
|
75 | QList<BarGroup*> m_BarGroupItems; | |
72 | }; |
|
76 | }; | |
73 |
|
77 | |||
74 | QTCOMMERCIALCHART_END_NAMESPACE |
|
78 | QTCOMMERCIALCHART_END_NAMESPACE | |
75 |
|
79 | |||
76 | #endif |
|
80 | #endif |
@@ -1,81 +1,66 | |||||
1 | #include "qchartview.h" |
|
1 | #include "qchartview.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include <QGraphicsView> |
|
3 | #include <QGraphicsView> | |
4 | #include <QGraphicsScene> |
|
4 | #include <QGraphicsScene> | |
5 | #include <QRubberBand> |
|
5 | #include <QRubberBand> | |
6 | #include <QResizeEvent> |
|
6 | #include <QResizeEvent> | |
7 | #include <QDebug> |
|
7 | #include <QDebug> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | QChartView::QChartView(QWidget *parent) : |
|
11 | QChartView::QChartView(QWidget *parent) : | |
12 | QGraphicsView(parent), |
|
12 | QGraphicsView(parent), | |
13 | m_scene(new QGraphicsScene()), |
|
13 | m_scene(new QGraphicsScene()), | |
14 |
m_chart(new QChart()) |
|
14 | m_chart(new QChart()) | |
15 | m_rubberBand(0), |
|
|||
16 | m_showRubberBand(false) |
|
|||
17 | { |
|
15 | { | |
18 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
16 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
19 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
17 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
20 | setScene(m_scene); |
|
18 | setScene(m_scene); | |
21 | m_chart->setMargin(50); |
|
19 | m_chart->setMargin(50); | |
22 | m_scene->addItem(m_chart); |
|
20 | m_scene->addItem(m_chart); | |
23 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
21 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
24 | } |
|
22 | } | |
25 |
|
23 | |||
26 | QChartView::~QChartView() |
|
24 | QChartView::~QChartView() | |
27 | { |
|
25 | { | |
28 | } |
|
26 | } | |
29 |
|
27 | |||
30 | void QChartView::resizeEvent(QResizeEvent *event) |
|
28 | void QChartView::resizeEvent(QResizeEvent *event) | |
31 | { |
|
29 | { | |
32 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
30 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
33 | m_chart->setSize(size()); |
|
31 | m_chart->setSize(size()); | |
34 | QWidget::resizeEvent(event); |
|
32 | QWidget::resizeEvent(event); | |
35 | } |
|
33 | } | |
36 |
|
34 | |||
37 |
|
35 | |||
38 | void QChartView::addSeries(QChartSeries* series) |
|
36 | void QChartView::addSeries(QChartSeries* series) | |
39 | { |
|
37 | { | |
40 | m_chart->addSeries(series); |
|
38 | m_chart->addSeries(series); | |
41 | } |
|
39 | } | |
42 |
|
40 | |||
43 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) |
|
41 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) | |
44 | { |
|
42 | { | |
45 |
|
43 | |||
46 | return m_chart->createSeries(type); |
|
44 | return m_chart->createSeries(type); | |
47 | } |
|
45 | } | |
48 |
|
46 | |||
49 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
47 | void QChartView::zoomInToRect(const QRect& rectangle) | |
50 | { |
|
48 | { | |
51 | int margin = m_chart->margin(); |
|
49 | m_chart->zoomInToRect(rectangle); | |
52 |
|
||||
53 | QRect rect(margin,margin,width()-2*margin,height()-2*margin); |
|
|||
54 |
|
||||
55 | m_origin = event->pos(); |
|
|||
56 |
|
||||
57 | if (!rect.contains(m_origin)) return; |
|
|||
58 |
|
||||
59 | if (!m_rubberBand) |
|
|||
60 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
|||
61 | m_rubberBand->setGeometry(QRect(m_origin, QSize())); |
|
|||
62 | m_showRubberBand=true; |
|
|||
63 | m_rubberBand->show(); |
|
|||
64 |
|
||||
65 | } |
|
50 | } | |
66 |
|
51 | |||
67 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
52 | void QChartView::zoomIn() | |
68 | { |
|
53 | { | |
69 | if(m_showRubberBand) |
|
54 | m_chart->zoomIn(); | |
70 | m_rubberBand->setGeometry(QRect(m_origin, event->pos()).normalized()); |
|
|||
71 | } |
|
55 | } | |
72 |
|
56 | |||
73 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
57 | void QChartView::zoomOut() | |
74 | { |
|
58 | { | |
75 | if(m_showRubberBand) { |
|
59 | m_chart->zoomOut(); | |
76 | m_rubberBand->hide(); |
|
|||
77 | m_showRubberBand=false; |
|
|||
78 | } |
|
|||
79 | } |
|
60 | } | |
80 |
|
61 | |||
|
62 | int QChartView::margin() const | |||
|
63 | { | |||
|
64 | return m_chart->margin(); | |||
|
65 | } | |||
81 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,43 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartseries.h" |
|
5 | #include "qchartseries.h" | |
6 | #include <QGraphicsView> |
|
6 | #include <QGraphicsView> | |
7 |
|
7 | |||
8 | class QGraphicsScene; |
|
8 | class QGraphicsScene; | |
9 | class QRubberBand; |
|
|||
10 |
|
9 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
11 | |||
13 | class QChart; |
|
12 | class QChart; | |
14 |
|
13 | |||
15 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
14 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
16 | { |
|
15 | { | |
17 | public: |
|
16 | public: | |
18 | explicit QChartView(QWidget *parent = 0); |
|
17 | explicit QChartView(QWidget *parent = 0); | |
19 | ~QChartView(); |
|
18 | ~QChartView(); | |
20 |
|
19 | |||
21 | //implement from QWidget |
|
20 | //implement from QWidget | |
22 | void resizeEvent(QResizeEvent *event); |
|
21 | void resizeEvent(QResizeEvent *event); | |
23 |
|
22 | |||
24 | void addSeries(QChartSeries* series); |
|
23 | void addSeries(QChartSeries* series); | |
25 | // Convenience function |
|
24 | // Convenience function | |
26 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
25 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
27 |
|
26 | |||
28 | protected: |
|
27 | int margin() const; | |
29 | void mouseMoveEvent (QMouseEvent *event); |
|
28 | void zoomInToRect(const QRect& rectangle); | |
30 | void mousePressEvent (QMouseEvent *event); |
|
29 | void zoomIn(); | |
31 | void mouseReleaseEvent (QMouseEvent *event); |
|
30 | void zoomOut(); | |
32 |
|
31 | |||
33 | private: |
|
32 | private: | |
34 | QGraphicsScene *m_scene; |
|
33 | QGraphicsScene *m_scene; | |
35 | QChart* m_chart; |
|
34 | QChart* m_chart; | |
36 | QRubberBand *m_rubberBand; |
|
|||
37 | QPoint m_origin; |
|
35 | QPoint m_origin; | |
38 | bool m_showRubberBand; |
|
|||
39 | Q_DISABLE_COPY(QChartView) |
|
36 | Q_DISABLE_COPY(QChartView) | |
40 |
|
37 | |||
41 |
|
38 | |||
42 | }; |
|
39 | }; | |
43 |
|
40 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
41 | QTCOMMERCIALCHART_END_NAMESPACE | |
45 |
|
42 | |||
46 | #endif // QCHARTWIDGET_H |
|
43 | #endif // QCHARTWIDGET_H |
@@ -1,90 +1,89 | |||||
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 | barchart/barchartseries.cpp \ |
|
15 | barchart/barchartseries.cpp \ | |
16 | barchart/bargroup.cpp \ |
|
16 | barchart/bargroup.cpp \ | |
17 | barchart/bar.cpp \ |
|
17 | barchart/bar.cpp \ | |
18 | xylinechart/qxychartseries.cpp \ |
|
18 | xylinechart/qxychartseries.cpp \ | |
19 | xylinechart/xylinechartitem.cpp \ |
|
19 | xylinechart/xylinechartitem.cpp \ | |
20 | xylinechart/xygrid.cpp \ |
|
20 | plotdomain.cpp \ | |
21 | xylinechart/xyplotdomain.cpp \ |
|
|||
22 | qscatterseries.cpp \ |
|
21 | qscatterseries.cpp \ | |
23 | qpieseries.cpp \ |
|
22 | qpieseries.cpp \ | |
24 | qchart.cpp \ |
|
23 | qchart.cpp \ | |
25 | axis.cpp \ |
|
24 | axisitem.cpp \ | |
26 | qchartwidget.cpp \ |
|
25 | qchartwidget.cpp \ | |
27 | pieslice.cpp \ |
|
26 | pieslice.cpp \ | |
28 | qchartview.cpp \ |
|
27 | qchartview.cpp \ | |
29 | qchartseries.cpp |
|
28 | qchartseries.cpp | |
30 |
|
29 | |||
31 | PRIVATE_HEADERS += \ |
|
30 | PRIVATE_HEADERS += \ | |
32 | xylinechart/xylinechartitem_p.h \ |
|
31 | xylinechart/xylinechartitem_p.h \ | |
33 |
|
|
32 | plotdomain_p.h \ | |
34 | xylinechart/xygrid_p.h \ |
|
|||
35 | qscatterseries_p.h \ |
|
33 | qscatterseries_p.h \ | |
36 | pieslice.h \ |
|
34 | pieslice.h \ | |
37 | axis_p.h |
|
35 | axisitem_p.h \ | |
|
36 | chartitem_p.h | |||
38 |
|
37 | |||
39 | PUBLIC_HEADERS += \ |
|
38 | PUBLIC_HEADERS += \ | |
40 | qchartseries.h \ |
|
39 | qchartseries.h \ | |
41 | qscatterseries.h \ |
|
40 | qscatterseries.h \ | |
42 | qpieseries.h \ |
|
41 | qpieseries.h \ | |
43 | qchart.h \ |
|
42 | qchart.h \ | |
44 | qchartwidget.h \ |
|
43 | qchartwidget.h \ | |
45 | qchartglobal.h \ |
|
44 | qchartglobal.h \ | |
46 | xylinechart/qxychartseries.h \ |
|
45 | xylinechart/qxychartseries.h \ | |
47 | barchart/barchartseries.h \ |
|
46 | barchart/barchartseries.h \ | |
48 | barchart/bargroup.h \ |
|
47 | barchart/bargroup.h \ | |
49 | qchartview.h |
|
48 | qchartview.h | |
50 |
|
49 | |||
51 | HEADERS += $$PUBLIC_HEADERS |
|
50 | HEADERS += $$PUBLIC_HEADERS | |
52 | HEADERS += $$PRIVATE_HEADERS |
|
51 | HEADERS += $$PRIVATE_HEADERS | |
53 |
|
52 | |||
54 | INCLUDEPATH += xylinechart \ |
|
53 | INCLUDEPATH += xylinechart \ | |
55 | barchart \ |
|
54 | barchart \ | |
56 | . |
|
55 | . | |
57 |
|
56 | |||
58 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
57 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
59 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
58 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
60 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
59 | UI_DIR = $$CHART_BUILD_DIR/lib | |
61 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
60 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
62 |
|
61 | |||
63 |
|
62 | |||
64 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
63 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
65 |
|
64 | |||
66 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
65 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
67 | public_headers.files = $$PUBLIC_HEADERS |
|
66 | public_headers.files = $$PUBLIC_HEADERS | |
68 | target.path = $$[QT_INSTALL_LIBS] |
|
67 | target.path = $$[QT_INSTALL_LIBS] | |
69 | INSTALLS += target \ |
|
68 | INSTALLS += target \ | |
70 | public_headers |
|
69 | public_headers | |
71 |
|
70 | |||
72 |
|
71 | |||
73 | install_build_headers.name = bild_headers |
|
72 | install_build_headers.name = bild_headers | |
74 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
73 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
75 | install_build_headers.input = PUBLIC_HEADERS |
|
74 | install_build_headers.input = PUBLIC_HEADERS | |
76 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR |
|
75 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR | |
77 | install_build_headers.CONFIG += target_predeps no_link |
|
76 | install_build_headers.CONFIG += target_predeps no_link | |
78 | QMAKE_EXTRA_COMPILERS += install_build_headers |
|
77 | QMAKE_EXTRA_COMPILERS += install_build_headers | |
79 |
|
78 | |||
80 | chartversion.target = qchartversion_p.h |
|
79 | chartversion.target = qchartversion_p.h | |
81 | chartversion.commands = @echo "build_time" > $$chartversion.target; |
|
80 | chartversion.commands = @echo "build_time" > $$chartversion.target; | |
82 | chartversion.depends = $$HEADERS $$SOURCES |
|
81 | chartversion.depends = $$HEADERS $$SOURCES | |
83 | PRE_TARGETDEPS += qchartversion_p.h |
|
82 | PRE_TARGETDEPS += qchartversion_p.h | |
84 | QMAKE_CLEAN+= qchartversion_p.h |
|
83 | QMAKE_CLEAN+= qchartversion_p.h | |
85 | QMAKE_EXTRA_TARGETS += chartversion |
|
84 | QMAKE_EXTRA_TARGETS += chartversion | |
86 |
|
85 | |||
87 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
86 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
88 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
87 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
89 |
|
88 | |||
90 |
|
89 |
@@ -1,70 +1,70 | |||||
1 | #include "xygrid_p.h" |
|
1 | #include "xygrid_p.h" | |
2 | #include <QPainter> |
|
2 | #include <QPainter> | |
3 | #include <QDebug> |
|
3 | #include <QDebug> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | XYGrid::XYGrid(QGraphicsItem* parent):QGraphicsItem(parent) |
|
7 | XYGrid::XYGrid(QGraphicsItem* parent):QGraphicsItem(parent) | |
8 | { |
|
8 | { | |
9 | } |
|
9 | } | |
10 |
|
10 | |||
11 | XYGrid::~XYGrid() |
|
11 | XYGrid::~XYGrid() | |
12 | { |
|
12 | { | |
13 | // TODO Auto-generated destructor stub |
|
13 | // TODO Auto-generated destructor stub | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | void XYGrid::setSize(const QSizeF& size) |
|
16 | void XYGrid::setSize(const QSizeF& size) | |
17 | { |
|
17 | { | |
18 | m_rect.setSize(size.toSize()); |
|
18 | m_rect.setSize(size.toSize()); | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 |
void XYGrid::setXYPlotData(const |
|
21 | void XYGrid::setXYPlotData(const PlotDomain& xyPlotData) | |
22 | { |
|
22 | { | |
23 | m_xyPlotData = xyPlotData; |
|
23 | m_xyPlotData = xyPlotData; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | QRectF XYGrid::boundingRect() const |
|
26 | QRectF XYGrid::boundingRect() const | |
27 | { |
|
27 | { | |
28 | return m_rect; |
|
28 | return m_rect; | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | void XYGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) |
|
31 | void XYGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) | |
32 | { |
|
32 | { | |
33 |
|
33 | |||
34 | if (!m_rect.isValid()) |
|
34 | if (!m_rect.isValid()) | |
35 | return; |
|
35 | return; | |
36 |
|
36 | |||
37 | const qreal deltaX = (m_rect.width() -1) / m_xyPlotData.ticksX(); |
|
37 | const qreal deltaX = (m_rect.width() -1) / m_xyPlotData.ticksX(); | |
38 | const qreal deltaY = (m_rect.height() - 1) / m_xyPlotData.ticksY(); |
|
38 | const qreal deltaY = (m_rect.height() - 1) / m_xyPlotData.ticksY(); | |
39 |
|
39 | |||
40 | for (int i = 0; i <= m_xyPlotData.ticksX(); ++i) { |
|
40 | for (int i = 0; i <= m_xyPlotData.ticksX(); ++i) { | |
41 |
|
41 | |||
42 | int x = i * deltaX + m_rect.left(); |
|
42 | int x = i * deltaX + m_rect.left(); | |
43 | qreal label = m_xyPlotData.m_minX + (i * m_xyPlotData.spanX() |
|
43 | qreal label = m_xyPlotData.m_minX + (i * m_xyPlotData.spanX() | |
44 | / m_xyPlotData.ticksX()); |
|
44 | / m_xyPlotData.ticksX()); | |
45 | painter->drawLine(x, m_rect.top()+1, x, m_rect.bottom()); |
|
45 | painter->drawLine(x, m_rect.top()+1, x, m_rect.bottom()); | |
46 | //painter->drawLine(x, m_rect.bottom(), x, m_rect.bottom() + 5); |
|
46 | //painter->drawLine(x, m_rect.bottom(), x, m_rect.bottom() + 5); | |
47 |
|
47 | |||
48 | painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20, |
|
48 | painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20, | |
49 | Qt::AlignHCenter | Qt::AlignTop, |
|
49 | Qt::AlignHCenter | Qt::AlignTop, | |
50 | QString::number(label)); |
|
50 | QString::number(label)); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | for (int j = 0; j <= m_xyPlotData.ticksY(); ++j) { |
|
53 | for (int j = 0; j <= m_xyPlotData.ticksY(); ++j) { | |
54 |
|
54 | |||
55 | int y = j * -deltaY + m_rect.bottom(); |
|
55 | int y = j * -deltaY + m_rect.bottom(); | |
56 | qreal label = m_xyPlotData.m_minY + (j * m_xyPlotData.spanY() |
|
56 | qreal label = m_xyPlotData.m_minY + (j * m_xyPlotData.spanY() | |
57 | / m_xyPlotData.ticksY()); |
|
57 | / m_xyPlotData.ticksY()); | |
58 |
|
58 | |||
59 | painter->drawLine(m_rect.left(), y, m_rect.right()-1, y); |
|
59 | painter->drawLine(m_rect.left(), y, m_rect.right()-1, y); | |
60 | //painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y); |
|
60 | //painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y); | |
61 | //TODO : margin = 50 ; |
|
61 | //TODO : margin = 50 ; | |
62 | painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20, |
|
62 | painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20, | |
63 | Qt::AlignRight | Qt::AlignVCenter, |
|
63 | Qt::AlignRight | Qt::AlignVCenter, | |
64 | QString::number(label)); |
|
64 | QString::number(label)); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | //painter->drawRect(m_rect.adjusted(0, 0, -1, -1)); |
|
67 | //painter->drawRect(m_rect.adjusted(0, 0, -1, -1)); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,31 +1,31 | |||||
1 | #ifndef XYGRID_H_ |
|
1 | #ifndef XYGRID_H_ | |
2 | #define XYGRID_H_ |
|
2 | #define XYGRID_H_ | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <xyplotdomain_p.h> |
|
5 | #include <xyplotdomain_p.h> | |
6 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class XYGrid : public QGraphicsItem |
|
10 | class XYGrid : public QGraphicsItem | |
11 | { |
|
11 | { | |
12 | public: |
|
12 | public: | |
13 | XYGrid(QGraphicsItem* parent = 0); |
|
13 | XYGrid(QGraphicsItem* parent = 0); | |
14 | virtual ~XYGrid(); |
|
14 | virtual ~XYGrid(); | |
15 |
|
15 | |||
16 | //from QGraphicsItem |
|
16 | //from QGraphicsItem | |
17 | virtual QRectF boundingRect() const; |
|
17 | virtual QRectF boundingRect() const; | |
18 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
18 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
19 |
|
19 | |||
20 | //TODO: this is just temporary interface |
|
20 | //TODO: this is just temporary interface | |
21 |
void setXYPlotData(const |
|
21 | void setXYPlotData(const PlotDomain& xyPlotData); | |
22 | void setSize(const QSizeF& rect); |
|
22 | void setSize(const QSizeF& rect); | |
23 |
|
23 | |||
24 | private: |
|
24 | private: | |
25 | QRectF m_rect; |
|
25 | QRectF m_rect; | |
26 |
|
|
26 | PlotDomain m_xyPlotData; | |
27 | }; |
|
27 | }; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_END_NAMESPACE |
|
29 | QTCOMMERCIALCHART_END_NAMESPACE | |
30 |
|
30 | |||
31 | #endif /* XYGRID_H_ */ |
|
31 | #endif /* XYGRID_H_ */ |
@@ -1,56 +1,67 | |||||
1 | #include "xylinechartitem_p.h" |
|
1 | #include "xylinechartitem_p.h" | |
2 | #include "axis_p.h" |
|
2 | #include "axisitem_p.h" | |
3 | #include "xygrid_p.h" |
|
|||
4 | #include "qxychartseries.h" |
|
3 | #include "qxychartseries.h" | |
5 | #include <QPainter> |
|
4 | #include <QPainter> | |
6 | #include <QStyleOptionGraphicsItem> |
|
5 | #include <QStyleOptionGraphicsItem> | |
7 | #include <QDebug> |
|
6 | #include <QDebug> | |
8 |
|
7 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
9 | |||
11 |
XYLineChartItem::XYLineChartItem(QXYChartSeries* series,QGraphicsItem *parent): |
|
10 | XYLineChartItem::XYLineChartItem(QXYChartSeries* series,QGraphicsItem *parent):ChartItem(parent), | |
12 | m_series(series) |
|
11 | m_series(series), | |
|
12 | m_dirty(false) | |||
13 | { |
|
13 | { | |
14 |
|
14 | |||
15 | } |
|
15 | } | |
16 |
|
16 | |||
17 |
void XYLineChartItem:: |
|
17 | void XYLineChartItem::setSize(const QSize& size) | |
18 | { |
|
18 | { | |
19 | m_xyPlotData=data; |
|
19 | m_rect=QRect(0,0,size.width(),size.height()); | |
|
20 | m_dirty=true; | |||
|
21 | } | |||
20 |
|
22 | |||
21 | if (!m_xyPlotData.m_viewportRect.isValid()) |
|
23 | void XYLineChartItem::setPlotDomain(const PlotDomain& data) | |
22 | return; |
|
24 | { | |
|
25 | m_plotDomain=data; | |||
|
26 | m_dirty=true; | |||
|
27 | } | |||
23 |
|
28 | |||
24 | const QRect& rect = m_xyPlotData.m_viewportRect; |
|
29 | QRectF XYLineChartItem::boundingRect() const | |
|
30 | { | |||
|
31 | return m_polyline.boundingRect(); | |||
|
32 | } | |||
25 |
|
33 | |||
26 | const qreal deltaX = (rect.width()-1)/m_xyPlotData.spanX(); |
|
34 | void XYLineChartItem::updateGeometry() | |
27 | const qreal deltaY = (rect.height()-1)/m_xyPlotData.spanY(); |
|
35 | { | |
|
36 | if (!m_rect.isValid()) return; | |||
28 |
|
37 | |||
29 | m_polyline.clear(); |
|
38 | const qreal deltaX = (m_rect.width()-1)/m_plotDomain.spanX(); | |
30 | m_polyline.resize(m_series->count()); |
|
39 | const qreal deltaY = (m_rect.height()-1)/m_plotDomain.spanY(); | |
31 |
|
40 | |||
32 | for (int j = 0; j < m_series->count(); ++j) { |
|
41 | m_polyline.clear(); | |
33 | qreal dx = m_series->x(j) - m_xyPlotData.m_minX; |
|
42 | m_polyline.resize(m_series->count()); | |
34 | qreal dy = m_series->y(j) - m_xyPlotData.m_minY; |
|
|||
35 | qreal x = (dx * deltaX) + rect.left(); |
|
|||
36 | qreal y = - (dy * deltaY) + rect.bottom(); |
|
|||
37 | m_polyline[j] = QPointF(x, y); |
|
|||
38 | } |
|
|||
39 |
|
43 | |||
40 | } |
|
44 | for (int j = 0; j < m_series->count(); ++j) { | |
|
45 | qreal dx = m_series->x(j) - m_plotDomain.m_minX; | |||
|
46 | qreal dy = m_series->y(j) - m_plotDomain.m_minY; | |||
|
47 | qreal x = (dx * deltaX) + m_rect.left(); | |||
|
48 | qreal y = - (dy * deltaY) + m_rect.bottom(); | |||
|
49 | m_polyline[j] = QPointF(x, y); | |||
|
50 | } | |||
41 |
|
51 | |||
42 | QRectF XYLineChartItem::boundingRect() const |
|
|||
43 | { |
|
|||
44 | return m_polyline.boundingRect(); |
|
|||
45 | } |
|
52 | } | |
46 |
|
53 | |||
47 |
|
54 | |||
48 | void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) |
|
55 | void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) | |
49 | { |
|
56 | { | |
50 | painter->setClipRect(m_xyPlotData.m_viewportRect.adjusted(+1, +1, -1, -1)); |
|
57 | //TODO: remove it | |
|
58 | if (m_dirty) { | |||
|
59 | updateGeometry(); | |||
|
60 | m_dirty=false; | |||
|
61 | } | |||
|
62 | painter->setClipRect(m_rect.adjusted(+1, +1, -1, -1)); | |||
51 | painter->setPen(m_series->color()); |
|
63 | painter->setPen(m_series->color()); | |
52 | painter->drawPolyline(m_polyline); |
|
64 | painter->drawPolyline(m_polyline); | |
53 |
|
||||
54 | } |
|
65 | } | |
55 |
|
66 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,33 +1,38 | |||||
1 | #ifndef XYLINECHARTITEM_H |
|
1 | #ifndef XYLINECHARTITEM_H | |
2 | #define XYLINECHARTITEM_H |
|
2 | #define XYLINECHARTITEM_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QGraphicsItem> |
|
5 | #include "chartitem_p.h" | |
6 | #include "xyplotdomain_p.h" |
|
|||
7 |
|
6 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
8 | |||
10 | class QXYChartSeries; |
|
9 | class QXYChartSeries; | |
11 |
|
10 | |||
12 |
class XYLineChartItem : public |
|
11 | class XYLineChartItem : public ChartItem | |
13 | { |
|
12 | { | |
14 |
|
13 | |||
15 | public: |
|
14 | public: | |
16 | XYLineChartItem(QXYChartSeries* m_series,QGraphicsItem *parent = 0); |
|
15 | XYLineChartItem(QXYChartSeries* m_series,QGraphicsItem *parent = 0); | |
17 |
|
|
16 | ~ XYLineChartItem(){}; | |
18 |
|
17 | |||
19 | //from QGraphicsItem |
|
18 | //from QGraphicsItem | |
20 |
|
|
19 | QRectF boundingRect() const; | |
21 |
|
|
20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
21 | //from ChartItem | |||
|
22 | void setSize(const QSize& size); | |||
|
23 | void setPlotDomain(const PlotDomain& data); | |||
22 |
|
24 | |||
23 | void updateXYPlotDomain(const XYPlotDomain& data); |
|
25 | private: | |
|
26 | void updateGeometry(); | |||
24 |
|
27 | |||
25 | private: |
|
28 | private: | |
|
29 | QRect m_rect; | |||
26 | QPolygonF m_polyline; |
|
30 | QPolygonF m_polyline; | |
27 | QXYChartSeries* m_series; |
|
31 | QXYChartSeries* m_series; | |
28 |
|
|
32 | PlotDomain m_plotDomain; | |
|
33 | bool m_dirty; | |||
29 | }; |
|
34 | }; | |
30 |
|
35 | |||
31 | QTCOMMERCIALCHART_END_NAMESPACE |
|
36 | QTCOMMERCIALCHART_END_NAMESPACE | |
32 |
|
37 | |||
33 | #endif |
|
38 | #endif |
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