qchartwidget.cpp
69 lines
| 1.5 KiB
| text/x-c
|
CppLexer
/ src / qchartwidget.cpp
Tero Ahola
|
r19 | #include "qchartwidget.h" | ||
Michal Klocek
|
r21 | #include "qchartseries.h" | ||
Tero Ahola
|
r19 | #include <QGraphicsView> | ||
#include <QGraphicsScene> | ||||
Michal Klocek
|
r21 | #include <QResizeEvent> | ||
Tero Ahola
|
r19 | |||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
Tero Ahola
|
r19 | |||
class QChartWidgetPrivate | ||||
{ | ||||
public: | ||||
Michal Klocek
|
r21 | QChartWidgetPrivate(QChartWidget *parent) : | ||
m_view(0), | ||||
m_scene(0), | ||||
Michal Klocek
|
r28 | m_chart(0) | ||
Michal Klocek
|
r21 | { | ||
Tero Ahola
|
r19 | m_scene = new QGraphicsScene(); | ||
Michal Klocek
|
r21 | m_view = new QGraphicsView(parent); | ||
m_view->setScene(m_scene); | ||||
m_chart = new QChart(); | ||||
m_scene->addItem(m_chart); | ||||
Tero Ahola
|
r19 | } | ||
Michal Klocek
|
r21 | |||
Tero Ahola
|
r19 | ~QChartWidgetPrivate() { | ||
} | ||||
QGraphicsView *m_view; | ||||
QGraphicsScene *m_scene; | ||||
QChart* m_chart; | ||||
}; | ||||
Tero Ahola
|
r29 | /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
Michal Klocek
|
r28 | |||
Tero Ahola
|
r19 | QChartWidget::QChartWidget(QWidget *parent) : | ||
QWidget(parent), | ||||
Michal Klocek
|
r21 | d_ptr(new QChartWidgetPrivate(this)) | ||
Tero Ahola
|
r19 | { | ||
Tero Ahola
|
r29 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
Tero Ahola
|
r19 | } | ||
QChartWidget::~QChartWidget() | ||||
{ | ||||
Michal Klocek
|
r21 | delete d_ptr; | ||
Tero Ahola
|
r19 | } | ||
Michal Klocek
|
r21 | void QChartWidget::resizeEvent(QResizeEvent *event) | ||
Tero Ahola
|
r19 | { | ||
Michal Klocek
|
r21 | Q_D(QChartWidget); | ||
d->m_view->resize(size().width(),size().height()); | ||||
d->m_scene->setSceneRect(0,0,size().width(),size().height()); | ||||
d->m_chart->setSize(size()); | ||||
QWidget::resizeEvent(event); | ||||
} | ||||
Tero Ahola
|
r19 | |||
Tero Ahola
|
r29 | QSize QChartWidget::sizeHint() const | ||
{ | ||||
// TODO: calculate size hint based on contents? | ||||
return QSize(100, 100); | ||||
} | ||||
Michal Klocek
|
r21 | |||
void QChartWidget::addSeries(QChartSeries* series) | ||||
{ | ||||
Q_D(QChartWidget); | ||||
d->m_chart->addSeries(series); | ||||
Tero Ahola
|
r19 | } | ||
#include "moc_qchartwidget.cpp" | ||||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||