##// END OF EJS Templates
Added size hint for the widget
Tero Ahola -
r29:1f6ecd9d10e9
parent child
Show More
@@ -1,64 +1,69
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 QCHART_BEGIN_NAMESPACE
7 QCHART_BEGIN_NAMESPACE
8
8
9 class QChartWidgetPrivate
9 class QChartWidgetPrivate
10 {
10 {
11 public:
11 public:
12 QChartWidgetPrivate(QChartWidget *parent) :
12 QChartWidgetPrivate(QChartWidget *parent) :
13 m_view(0),
13 m_view(0),
14 m_scene(0),
14 m_scene(0),
15 m_chart(0)
15 m_chart(0)
16 {
16 {
17 m_scene = new QGraphicsScene();
17 m_scene = new QGraphicsScene();
18 m_view = new QGraphicsView(parent);
18 m_view = new QGraphicsView(parent);
19 m_view->setScene(m_scene);
19 m_view->setScene(m_scene);
20 m_chart = new QChart();
20 m_chart = new QChart();
21 m_scene->addItem(m_chart);
21 m_scene->addItem(m_chart);
22 }
22 }
23
23
24 ~QChartWidgetPrivate() {
24 ~QChartWidgetPrivate() {
25 }
25 }
26
26
27 QGraphicsView *m_view;
27 QGraphicsView *m_view;
28 QGraphicsScene *m_scene;
28 QGraphicsScene *m_scene;
29 QChart* m_chart;
29 QChart* m_chart;
30 };
30 };
31
31
32 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////////////////////////////////////
33
33
34 QChartWidget::QChartWidget(QWidget *parent) :
34 QChartWidget::QChartWidget(QWidget *parent) :
35 QWidget(parent),
35 QWidget(parent),
36 d_ptr(new QChartWidgetPrivate(this))
36 d_ptr(new QChartWidgetPrivate(this))
37 {
37 {
38
38 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
39 }
39 }
40
40
41 QChartWidget::~QChartWidget()
41 QChartWidget::~QChartWidget()
42 {
42 {
43 delete d_ptr;
43 delete d_ptr;
44 }
44 }
45
45
46 void QChartWidget::resizeEvent(QResizeEvent *event)
46 void QChartWidget::resizeEvent(QResizeEvent *event)
47 {
47 {
48 Q_D(QChartWidget);
48 Q_D(QChartWidget);
49 d->m_view->resize(size().width(),size().height());
49 d->m_view->resize(size().width(),size().height());
50 d->m_scene->setSceneRect(0,0,size().width(),size().height());
50 d->m_scene->setSceneRect(0,0,size().width(),size().height());
51 d->m_chart->setSize(size());
51 d->m_chart->setSize(size());
52 QWidget::resizeEvent(event);
52 QWidget::resizeEvent(event);
53 }
53 }
54
54
55 QSize QChartWidget::sizeHint() const
56 {
57 // TODO: calculate size hint based on contents?
58 return QSize(100, 100);
59 }
55
60
56 void QChartWidget::addSeries(QChartSeries* series)
61 void QChartWidget::addSeries(QChartSeries* series)
57 {
62 {
58 Q_D(QChartWidget);
63 Q_D(QChartWidget);
59 d->m_chart->addSeries(series);
64 d->m_chart->addSeries(series);
60 }
65 }
61
66
62 #include "moc_qchartwidget.cpp"
67 #include "moc_qchartwidget.cpp"
63
68
64 QCHART_END_NAMESPACE
69 QCHART_END_NAMESPACE
@@ -1,35 +1,36
1 #ifndef QCHARTWIDGET_H
1 #ifndef QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
3
3
4 #include "qchartconfig.h"
4 #include "qchartconfig.h"
5 #include "qchart.h"
5 #include "qchart.h"
6 #include <QWidget>
6 #include <QWidget>
7
7
8 QCHART_BEGIN_NAMESPACE
8 QCHART_BEGIN_NAMESPACE
9
9
10 class QChartSeries;
10 class QChartSeries;
11 class QChartWidgetPrivate;
11 class QChartWidgetPrivate;
12
12
13 class QCHART_EXPORT QChartWidget : public QWidget
13 class QCHART_EXPORT QChartWidget : public QWidget
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16 public:
16 public:
17 explicit QChartWidget(QWidget *parent = 0);
17 explicit QChartWidget(QWidget *parent = 0);
18 ~QChartWidget();
18 ~QChartWidget();
19
19
20 //implement from QWidget
20 //implement from QWidget
21 void resizeEvent(QResizeEvent *event);
21 void resizeEvent(QResizeEvent *event);
22 QSize sizeHint() const;
22
23
23 void addSeries(QChartSeries* series);
24 void addSeries(QChartSeries* series);
24 protected:
25 protected:
25 QChartWidgetPrivate * const d_ptr;
26 QChartWidgetPrivate * const d_ptr;
26
27
27 private:
28 private:
28 Q_DISABLE_COPY(QChartWidget)
29 Q_DISABLE_COPY(QChartWidget)
29 Q_DECLARE_PRIVATE(QChartWidget)
30 Q_DECLARE_PRIVATE(QChartWidget)
30
31
31 };
32 };
32
33
33 QCHART_END_NAMESPACE
34 QCHART_END_NAMESPACE
34
35
35 #endif // QCHARTWIDGET_H
36 #endif // QCHARTWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now