##// END OF EJS Templates
Refactored the test app
Refactored the test app

File last commit:

r93:264fcc5c2ce8
r110:d11ac5a26e2a
Show More
qchartwidget.cpp
100 lines | 2.6 KiB | text/x-c | CppLexer
/ src / qchartwidget.cpp
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 #include "qchartwidget.h"
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include "qchartseries.h"
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 #include <QGraphicsView>
#include <QGraphicsScene>
Michal Klocek
Refactor current draft to fit int current design specs...
r21 #include <QResizeEvent>
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19
QChartWidget::QChartWidget(QWidget *parent) :
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 QGraphicsView(parent),
Tero Ahola
QChartWidget now zooms only x axis and zoom is reset with right click
r93 m_rubberBand(QRubberBand::Rectangle, this),
m_originX(0)
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 {
Tero Ahola
Added size hint for the widget
r29 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
Michal Klocek
Adds rubberband for zooming...
r58 m_scene = new QGraphicsScene();
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setScene(m_scene);
Tero Ahola
Refactored series creation with QChart
r61
Michal Klocek
Removes PIMPL for now...
r53 m_chart = new QChart();
m_scene->addItem(m_chart);
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 m_rubberBand.setEnabled(true); // TODO: should zoom be enabled by default?
Tero Ahola
Refactoring: QChartWidget is now a QGraphicsView
r55 show();
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 }
QChartWidget::~QChartWidget()
{
}
Michal Klocek
Refactor current draft to fit int current design specs...
r21 void QChartWidget::resizeEvent(QResizeEvent *event)
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 {
Michal Klocek
Removes PIMPL for now...
r53 m_scene->setSceneRect(0,0,size().width(),size().height());
m_chart->setSize(size());
Michal Klocek
Refactor current draft to fit int current design specs...
r21 QWidget::resizeEvent(event);
}
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19
Tero Ahola
Added size hint for the widget
r29 QSize QChartWidget::sizeHint() const
{
// TODO: calculate size hint based on contents?
return QSize(100, 100);
}
Michal Klocek
Refactor current draft to fit int current design specs...
r21
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 void QChartWidget::mousePressEvent(QMouseEvent *event)
{
if(m_rubberBand.isEnabled() && event->button() == Qt::LeftButton) {
int margin = m_chart->margin();
QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
Tero Ahola
QChartWidget now zooms only x axis and zoom is reset with right click
r93 if (rect.contains(event->pos())) {
m_originX = event->pos().x();
m_rubberBand.setGeometry(QRect(m_originX, 0, 0, height()));
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 m_rubberBand.show();
event->accept();
}
}
}
void QChartWidget::mouseMoveEvent(QMouseEvent *event)
{
if(m_rubberBand.isVisible())
Tero Ahola
QChartWidget now zooms only x axis and zoom is reset with right click
r93 m_rubberBand.setGeometry(QRect(m_originX, 0,
event->pos().x() - m_originX, height()).normalized());
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 }
void QChartWidget::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && m_rubberBand.isVisible()) {
m_rubberBand.hide();
QRect rect = m_rubberBand.geometry();
m_chart->zoomInToRect(rect);
event->accept();
}
Tero Ahola
QChartWidget now zooms only x axis and zoom is reset with right click
r93 if(event->button()==Qt::RightButton)
m_chart->zoomReset();
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 }
Michal Klocek
Refactor current draft to fit int current design specs...
r21 void QChartWidget::addSeries(QChartSeries* series)
{
Michal Klocek
Removes PIMPL for now...
r53 m_chart->addSeries(series);
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 }
Tero Ahola
Refactored series creation with QChart
r61 QChartSeries* QChartWidget::createSeries(QChartSeries::QChartSeriesType type)
Tero Ahola
Integrated scatter type series...
r42 {
Tero Ahola
Refactored series creation with QChart
r61 return m_chart->createSeries(type);
Tero Ahola
Integrated scatter type series...
r42 }
Tero Ahola
Draft implementation for setting color themes for a chart
r64
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 void QChartWidget::setTheme(QChart::ChartThemeId theme)
Tero Ahola
Draft implementation for setting color themes for a chart
r64 {
m_chart->setTheme(theme);
}
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 void QChartWidget::setZoomEnabled(bool enabled)
{
m_rubberBand.setEnabled(enabled);
}
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 #include "moc_qchartwidget.cpp"
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_END_NAMESPACE