qchartwidget.cpp
57 lines
| 1.3 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 | |||
QChartWidget::QChartWidget(QWidget *parent) : | ||||
Tero Ahola
|
r55 | QGraphicsView(parent) | ||
Tero Ahola
|
r19 | { | ||
Tero Ahola
|
r29 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
Michal Klocek
|
r58 | m_scene = new QGraphicsScene(); | ||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | ||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | ||||
setScene(m_scene); | ||||
Tero Ahola
|
r61 | |||
Michal Klocek
|
r53 | m_chart = new QChart(); | ||
m_scene->addItem(m_chart); | ||||
Tero Ahola
|
r55 | show(); | ||
Tero Ahola
|
r19 | } | ||
QChartWidget::~QChartWidget() | ||||
{ | ||||
} | ||||
Michal Klocek
|
r21 | void QChartWidget::resizeEvent(QResizeEvent *event) | ||
Tero Ahola
|
r19 | { | ||
Michal Klocek
|
r53 | m_scene->setSceneRect(0,0,size().width(),size().height()); | ||
m_chart->setSize(size()); | ||||
Michal Klocek
|
r21 | 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) | ||||
{ | ||||
Michal Klocek
|
r53 | m_chart->addSeries(series); | ||
Tero Ahola
|
r19 | } | ||
Tero Ahola
|
r61 | QChartSeries* QChartWidget::createSeries(QChartSeries::QChartSeriesType type) | ||
Tero Ahola
|
r42 | { | ||
Tero Ahola
|
r61 | return m_chart->createSeries(type); | ||
Tero Ahola
|
r42 | } | ||
Tero Ahola
|
r64 | |||
Tero Ahola
|
r75 | void QChartWidget::setTheme(QChart::ChartThemeId theme) | ||
Tero Ahola
|
r64 | { | ||
m_chart->setTheme(theme); | ||||
} | ||||
Tero Ahola
|
r19 | #include "moc_qchartwidget.cpp" | ||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_END_NAMESPACE | ||