##// END OF EJS Templates
Refactored chartwidgettest test data impl
Refactored chartwidgettest test data impl

File last commit:

r277:704deaf5754b
r278:1d8f8b316dca
Show More
qchartview.cpp
283 lines | 7.6 KiB | text/x-c | CppLexer
Michal Klocek
Adds rubberband for zooming...
r58 #include "qchartview.h"
#include "qchart.h"
Michal Klocek
Adds more axis handling...
r176 #include "qchartaxis.h"
Michal Klocek
Adds rubberband for zooming...
r58 #include <QGraphicsView>
#include <QGraphicsScene>
#include <QRubberBand>
#include <QResizeEvent>
#include <QDebug>
Marek Rosa
Small fixes and QDoc comment in qchartview.cpp added
r233 /*!
\class QChartView
Marek Rosa
Added some documentation to QChart and QChartView
r274 \brief Chart widget
QChartView is a standalone widget that can display charts. It does not require QGraphicsScene to work. It manages the graphical
representation of different types of QChartSeries and other chart related objects like
QChartAxis and QChartLegend. If you want to display a chart in your existing QGraphicsScene, you can use the QChart class instead.
\sa QChart
Marek Rosa
Small fixes and QDoc comment in qchartview.cpp added
r233 */
Michal Klocek
Adds rubberband for zooming...
r58 QTCOMMERCIALCHART_BEGIN_NAMESPACE
QChartView::QChartView(QWidget *parent) :
Michal Klocek
Adds more axis handling...
r176 QGraphicsView(parent),
Jani Honkonen
Fix a major memory leak
r204 m_scene(new QGraphicsScene(this)),
Michal Klocek
Adds more axis handling...
r176 m_chart(new QChart()),
m_rubberBand(0),
m_verticalRubberBand(false),
m_horizonalRubberBand(false)
{
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Michal Klocek
Adds rubberband for zooming...
r58 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setScene(m_scene);
m_chart->setMargin(50);
m_scene->addItem(m_chart);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
Marek Rosa
Added some more documentation to QChart and QChartView
r277
/*!
Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
*/
Michal Klocek
Adds rubberband for zooming...
r58 QChartView::~QChartView()
{
}
void QChartView::resizeEvent(QResizeEvent *event)
{
m_scene->setSceneRect(0,0,size().width(),size().height());
Michal Klocek
Adds layout support for charts....
r115 m_chart->resize(size());
Michal Klocek
Adds rubberband for zooming...
r58 QWidget::resizeEvent(event);
}
Marek Rosa
Added some documentation to QChart and QChartView
r274 /*!
Adds the series and optional y axis onto the chart and takes the ownership of the objects.
If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
the y axis).
\sa removeSeries, removeAllSeries
*/
Michal Klocek
Refactors axis handling...
r223 void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
Michal Klocek
Adds rubberband for zooming...
r58 {
Michal Klocek
Refactors axis handling...
r223 m_chart->addSeries(series,axisY);
Michal Klocek
Adds rubberband for zooming...
r58 }
Marek Rosa
Added some documentation to QChart and QChartView
r274 /*!
Removes the QChartSeries specified in a perameter from the QChartView.
It releses its ownership of the specified QChartSeries object.
It does not delete the pointed QChartSeries data object
\sa removeSeries(), removeAllSeries()
*/
Michal Klocek
Adds missing removeSeries call to chartview
r245 void QChartView::removeSeries(QChartSeries* series)
{
m_chart->removeSeries(series);
}
Marek Rosa
Added some documentation to QChart and QChartView
r274 /*!
Removes all the QChartSeries that have been added to the QChartView
It also deletes the pointed QChartSeries data objects
\sa addSeries(), removeSeries()
*/
Michal Klocek
Adds RemoveAllSeries method to API
r258 void QChartView::removeAllSeries()
{
m_chart->removeAllSeries();
}
Michal Klocek
Refactors axis handling...
r223 void QChartView::zoomIn()
Michal Klocek
Adds rubberband for zooming...
r58 {
Michal Klocek
Refactors axis handling...
r223 m_chart->zoomIn();
Michal Klocek
Adds rubberband for zooming...
r58 }
Michal Klocek
Refactors axis handling...
r223 void QChartView::zoomIn(const QRect& rect)
Michal Klocek
Adds rubberband for zooming...
r58 {
Michal Klocek
Refactors axis handling...
r223 m_chart->zoomIn(rect);
Michal Klocek
Adds rubberband for zooming...
r58 }
Michal Klocek
Add zoom support...
r67 void QChartView::zoomOut()
Michal Klocek
Adds rubberband for zooming...
r58 {
Michal Klocek
Add zoom support...
r67 m_chart->zoomOut();
Michal Klocek
Adds rubberband for zooming...
r58 }
Marek Rosa
Added some documentation to QChart and QChartView
r274 /*!
Marek Rosa
Added some more documentation to QChart and QChartView
r277 Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
Marek Rosa
Added some documentation to QChart and QChartView
r274 */
Michal Klocek
Add zoom support...
r67 int QChartView::margin() const
{
return m_chart->margin();
}
Michal Klocek
Add background to chart...
r69
Marek Rosa
Added some documentation to QChart and QChartView
r274 /*!
Marek Rosa
Added some more documentation to QChart and QChartView
r277 Sets the chart \a tile. A description text that is rendered above the chart.
Marek Rosa
Added some documentation to QChart and QChartView
r274 */
Michal Klocek
Adds font handling for chart's titile...
r192 void QChartView::setChartTitle(const QString& title)
Michal Klocek
Add background to chart...
r69 {
Michal Klocek
Adds font handling for chart's titile...
r192 m_chart->setChartTitle(title);
}
Marek Rosa
Added some documentation to QChart and QChartView
r274 /*!
Marek Rosa
Added some more documentation to QChart and QChartView
r277 Sets the \a font that is used for rendering the description text that is rendered above the chart.
Marek Rosa
Added some documentation to QChart and QChartView
r274 */
Michal Klocek
Adds font handling for chart's titile...
r192 void QChartView::setChartTitleFont(const QFont& font)
{
m_chart->setChartTitleFont(font);
Michal Klocek
Add background to chart...
r69 }
Marek Rosa
Added some more documentation to QChart and QChartView
r277 /*!
Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
*/
Michal Klocek
Change background gradient to use ObjectBoundingMode...
r122 void QChartView::setChartBackgroundBrush(const QBrush& brush)
{
Michal Klocek
Adds more axis handling...
r176 m_chart->setChartBackgroundBrush(brush);
Michal Klocek
Change background gradient to use ObjectBoundingMode...
r122 }
Marek Rosa
Added some more documentation to QChart and QChartView
r277
/*!
Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
*/
Michal Klocek
Change background gradient to use ObjectBoundingMode...
r122 void QChartView::setChartBackgroundPen(const QPen& pen)
{
Michal Klocek
Adds more axis handling...
r176 m_chart->setChartBackgroundPen(pen);
Michal Klocek
Change background gradient to use ObjectBoundingMode...
r122 }
Michal Klocek
Removes QChartWidget...
r136
void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
{
Michal Klocek
Adds more axis handling...
r176 switch(policy) {
Michal Klocek
Removes QChartWidget...
r136 case VerticalRubberBand:
Michal Klocek
Adds more axis handling...
r176 m_verticalRubberBand = true;
m_horizonalRubberBand = false;
break;
Michal Klocek
Removes QChartWidget...
r136 case HorizonalRubberBand:
Michal Klocek
Adds more axis handling...
r176 m_verticalRubberBand = false;
m_horizonalRubberBand = true;
break;
Michal Klocek
Removes QChartWidget...
r136 case RectangleRubberBand:
Michal Klocek
Adds more axis handling...
r176 m_verticalRubberBand = true;
m_horizonalRubberBand = true;
break;
Michal Klocek
Removes QChartWidget...
r136 case NoRubberBand:
default:
Michal Klocek
Adds more axis handling...
r176 delete m_rubberBand;
m_rubberBand=0;
m_horizonalRubberBand = false;
m_verticalRubberBand = false;
return;
Michal Klocek
Removes QChartWidget...
r136 }
Michal Klocek
Adds more axis handling...
r176 if(!m_rubberBand) {
m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
m_rubberBand->setEnabled(true);
Michal Klocek
minor. memoryleak fix
r138 }
Michal Klocek
Removes QChartWidget...
r136 }
QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
{
if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
if(m_horizonalRubberBand) return HorizonalRubberBand;
if(m_verticalRubberBand) return VerticalRubberBand;
return NoRubberBand;
}
void QChartView::mousePressEvent(QMouseEvent *event)
{
if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
int margin = m_chart->margin();
QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
if (rect.contains(event->pos())) {
m_rubberBandOrigin = event->pos();
m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
m_rubberBand->show();
event->accept();
}
}
}
void QChartView::mouseMoveEvent(QMouseEvent *event)
{
Michal Klocek
Adds more axis handling...
r176 if(m_rubberBand && m_rubberBand->isVisible()) {
Michal Klocek
Removes QChartWidget...
r136 int margin = m_chart->margin();
QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
int width = event->pos().x() - m_rubberBandOrigin.x();
int height = event->pos().y() - m_rubberBandOrigin.y();
if(!m_verticalRubberBand) {
m_rubberBandOrigin.setY(rect.top());
height = rect.height();
}
if(!m_horizonalRubberBand) {
m_rubberBandOrigin.setX(rect.left());
width= rect.width();
}
m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
Michal Klocek
Adds more axis handling...
r176 }
else {
Michal Klocek
Removes QChartWidget...
r136 QGraphicsView::mouseMoveEvent(event);
}
}
void QChartView::mouseReleaseEvent(QMouseEvent *event)
{
Michal Klocek
Adds more axis handling...
r176 if(m_rubberBand) {
if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
m_rubberBand->hide();
QRect rect = m_rubberBand->geometry();
Michal Klocek
Refactors axis handling...
r223 m_chart->zoomIn(rect);
Michal Klocek
Adds more axis handling...
r176 event->accept();
}
Michal Klocek
Removes QChartWidget...
r136
Michal Klocek
Adds more axis handling...
r176 if(event->button()==Qt::RightButton)
Michal Klocek
Removes QChartWidget...
r136 m_chart->zoomReset();
Michal Klocek
Adds more axis handling...
r176 }
else {
Michal Klocek
Removes QChartWidget...
r136 QGraphicsView::mouseReleaseEvent(event);
}
}
void QChartView::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
Michal Klocek
Adds more axis handling...
r176 case Qt::Key_Plus:
Michal Klocek
Removes QChartWidget...
r136 zoomIn();
break;
Michal Klocek
Adds more axis handling...
r176 case Qt::Key_Minus:
Michal Klocek
Removes QChartWidget...
r136 zoomOut();
break;
Michal Klocek
Adds more axis handling...
r176 default:
Michal Klocek
Removes QChartWidget...
r136 QGraphicsView::keyPressEvent(event);
break;
}
}
Marek Rosa
Added some more documentation to QChart and QChartView
r277 /*!
Sets the \a theme used by the chart for rendering the graphical representation of the data
\sa QChart::ChartTheme, chartTheme()
*/
Michal Klocek
Adds missing ids to theme classes
r153 void QChartView::setChartTheme(QChart::ChartTheme theme)
Michal Klocek
Removes QChartWidget...
r136 {
Michal Klocek
Adds missing ids to theme classes
r153 m_chart->setChartTheme(theme);
Michal Klocek
Removes QChartWidget...
r136 }
Marek Rosa
Added some more documentation to QChart and QChartView
r277 /*!
Returns the theme enum used by the chart.
\sa setChartTheme()
*/
Michal Klocek
Adds missing ids to theme classes
r153 QChart::ChartTheme QChartView::chartTheme() const
{
return m_chart->chartTheme();
}
Michal Klocek
Removes QChartWidget...
r136
Marek Rosa
Added some documentation to QChart and QChartView
r274 /*!
Returns the pointer to the x axis object of the chart
*/
Michal Klocek
Refactors axis handling...
r223 QChartAxis* QChartView::axisX() const
Michal Klocek
Add public function for axis hadnling to qchart
r155 {
Michal Klocek
Refactors axis handling...
r223 return m_chart->axisX();
Michal Klocek
Add public function for axis hadnling to qchart
r155 }
Marek Rosa
Added some documentation to QChart and QChartView
r274 /*!
Returns the pointer to the y axis object of the chart
*/
Michal Klocek
Refactors axis handling...
r223 QChartAxis* QChartView::axisY() const
Michal Klocek
Add public function for axis hadnling to qchart
r155 {
Michal Klocek
Refactors axis handling...
r223 return m_chart->axisY();
Michal Klocek
Add public function for axis hadnling to qchart
r155 }
Michal Klocek
Adds rubberband for zooming...
r58 QTCOMMERCIALCHART_END_NAMESPACE