@@ -1,49 +1,52 | |||||
1 | #include "qchartwidget.h" |
|
1 | #include "qchartwidget.h" | |
2 | #include "qchartseries.h" |
|
2 | #include "qchartseries.h" | |
3 | #include <QGraphicsView> |
|
3 | #include <QGraphicsView> | |
4 | #include <QGraphicsScene> |
|
4 | #include <QGraphicsScene> | |
5 | #include <QResizeEvent> |
|
5 | #include <QResizeEvent> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | QChartWidget::QChartWidget(QWidget *parent) : |
|
9 | QChartWidget::QChartWidget(QWidget *parent) : | |
10 | QGraphicsView(parent) |
|
10 | QGraphicsView(parent) | |
11 | { |
|
11 | { | |
12 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
12 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
13 | m_scene = new QGraphicsScene(); |
|
13 | m_scene = new QGraphicsScene(); | |
14 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
14 | m_view = new QGraphicsView(parent); | |
15 | setScene(m_scene); |
|
15 | m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
|
16 | m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |||
|
17 | m_view->setScene(m_scene); | |||
|
18 | ||||
16 | m_chart = new QChart(); |
|
19 | m_chart = new QChart(); | |
17 | m_scene->addItem(m_chart); |
|
20 | m_scene->addItem(m_chart); | |
18 | show(); |
|
21 | show(); | |
19 | } |
|
22 | } | |
20 |
|
23 | |||
21 | QChartWidget::~QChartWidget() |
|
24 | QChartWidget::~QChartWidget() | |
22 | { |
|
25 | { | |
23 | } |
|
26 | } | |
24 |
|
27 | |||
25 | void QChartWidget::resizeEvent(QResizeEvent *event) |
|
28 | void QChartWidget::resizeEvent(QResizeEvent *event) | |
26 | { |
|
29 | { | |
27 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
30 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
28 | m_chart->setSize(size()); |
|
31 | m_chart->setSize(size()); | |
29 | QWidget::resizeEvent(event); |
|
32 | QWidget::resizeEvent(event); | |
30 | } |
|
33 | } | |
31 |
|
34 | |||
32 | QSize QChartWidget::sizeHint() const |
|
35 | QSize QChartWidget::sizeHint() const | |
33 | { |
|
36 | { | |
34 | // TODO: calculate size hint based on contents? |
|
37 | // TODO: calculate size hint based on contents? | |
35 | return QSize(100, 100); |
|
38 | return QSize(100, 100); | |
36 | } |
|
39 | } | |
37 |
|
40 | |||
38 | void QChartWidget::addSeries(QChartSeries* series) |
|
41 | void QChartWidget::addSeries(QChartSeries* series) | |
39 | { |
|
42 | { | |
40 | m_chart->addSeries(series); |
|
43 | m_chart->addSeries(series); | |
41 | } |
|
44 | } | |
42 |
|
45 | |||
43 | QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) |
|
46 | QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) | |
44 | { |
|
47 | { | |
45 | return m_chart->createSeries(x, y, type); |
|
48 | return m_chart->createSeries(x, y, type); | |
46 | } |
|
49 | } | |
47 | #include "moc_qchartwidget.cpp" |
|
50 | #include "moc_qchartwidget.cpp" | |
48 |
|
51 | |||
49 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now