qchartwidget.cpp
77 lines
| 1.9 KiB
| text/x-c
|
CppLexer
/ src / qchartwidget.cpp
|
r19 | #include "qchartwidget.h" | ||
|
r21 | #include "qchartseries.h" | ||
|
r19 | #include <QGraphicsView> | ||
#include <QGraphicsScene> | ||||
|
r21 | #include <QResizeEvent> | ||
|
r19 | |||
|
r30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||
|
r19 | |||
class QChartWidgetPrivate | ||||
{ | ||||
public: | ||||
|
r21 | QChartWidgetPrivate(QChartWidget *parent) : | ||
m_view(0), | ||||
m_scene(0), | ||||
|
r28 | m_chart(0) | ||
|
r21 | { | ||
|
r19 | m_scene = new QGraphicsScene(); | ||
|
r21 | m_view = new QGraphicsView(parent); | ||
|
r46 | m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | ||
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | ||||
|
r21 | m_view->setScene(m_scene); | ||
m_chart = new QChart(); | ||||
m_scene->addItem(m_chart); | ||||
|
r42 | m_view->show(); | ||
|
r19 | } | ||
|
r21 | |||
|
r19 | ~QChartWidgetPrivate() { | ||
} | ||||
QGraphicsView *m_view; | ||||
QGraphicsScene *m_scene; | ||||
QChart* m_chart; | ||||
}; | ||||
|
r29 | /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
r28 | |||
|
r19 | QChartWidget::QChartWidget(QWidget *parent) : | ||
QWidget(parent), | ||||
|
r21 | d_ptr(new QChartWidgetPrivate(this)) | ||
|
r19 | { | ||
|
r29 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
|
r19 | } | ||
QChartWidget::~QChartWidget() | ||||
{ | ||||
|
r21 | delete d_ptr; | ||
|
r19 | } | ||
|
r21 | void QChartWidget::resizeEvent(QResizeEvent *event) | ||
|
r19 | { | ||
|
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); | ||||
} | ||||
|
r19 | |||
|
r29 | QSize QChartWidget::sizeHint() const | ||
{ | ||||
// TODO: calculate size hint based on contents? | ||||
return QSize(100, 100); | ||||
} | ||||
|
r21 | |||
void QChartWidget::addSeries(QChartSeries* series) | ||||
{ | ||||
Q_D(QChartWidget); | ||||
d->m_chart->addSeries(series); | ||||
|
r19 | } | ||
|
r42 | QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) | ||
{ | ||||
Q_D(QChartWidget); | ||||
return d->m_chart->createSeries(x, y, type); | ||||
} | ||||
|
r19 | #include "moc_qchartwidget.cpp" | ||
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||