##// END OF EJS Templates
QML bar series categories
QML bar series categories

File last commit:

r700:4707806c8913
r726:5bffcd7b4ba5
Show More
qchartview.cpp
403 lines | 10.8 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
QChart and QChartView now has some description for all the functions
r287 /*!
\enum QChartView::RubberBandPolicy
This enum describes the different types of rubber bands that can be used for zoom rect selection
\value NoRubberBand
\value VerticalRubberBand
\value HorizonalRubberBand
\value RectangleRubberBand
*/
Marek Rosa
Small fixes and QDoc comment in qchartview.cpp added
r233 /*!
\class QChartView
Marek Rosa
QChart and QChartView now has some description for all the functions
r287 \brief Standalone charting widget.
Marek Rosa
Added some documentation to QChart and QChartView
r274
Tero Ahola
More examples on QChartView qdoc
r321 QChartView is a standalone widget that can display charts. It does not require separate
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.
Marek Rosa
Added some documentation to QChart and QChartView
r274
\sa QChart
Marek Rosa
Small fixes and QDoc comment in qchartview.cpp added
r233 */
Michal Klocek
Adds rubberband for zooming...
r58 QTCOMMERCIALCHART_BEGIN_NAMESPACE
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 /*!
Constructs a chartView object which is a child of a\a parent.
*/
Michal Klocek
Adds rubberband for zooming...
r58 QChartView::QChartView(QWidget *parent) :
Tero Ahola
New theme with light colors, chartview background
r584 QGraphicsView(parent),
m_scene(new QGraphicsScene(this)),
m_chart(new QChart()),
m_rubberBand(0),
m_verticalRubberBand(false),
m_horizonalRubberBand(false)
Michal Klocek
Adds more axis handling...
r176 {
Tero Ahola
Removed the visible frame around chart view
r700 setFrameShape(QFrame::NoFrame);
Tero Ahola
Use window's palette for chart view by default
r664 setBackgroundRole(QPalette::Window);
Michal Klocek
Adds more axis handling...
r176 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Michal Klocek
Adds rubberband for zooming...
r58 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setScene(m_scene);
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()
{
}
Marek Rosa
QChart and QChartView now has some description for all the functions
r287 /*!
Resizes and updates the chart area using the \a event data
*/
Michal Klocek
Adds rubberband for zooming...
r58 void QChartView::resizeEvent(QResizeEvent *event)
{
Tero Ahola
Bugfix: chart scrolling effect on OSX
r665 // If the scene rect is the size of the view, you will get scrolling effect at least on OSX;
// i.e. you are able to move the chart inside the view a couple of pixels by mouse flicking
m_scene->setSceneRect(0, 0, size().width() - 2, size().height() - 2);
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 /*!
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
Marek Rosa
Added some documentation to QChart and QChartView
r274 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
the y axis).
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 \sa removeSeries(), removeAllSeries()
Marek Rosa
Added some documentation to QChart and QChartView
r274 */
Michal Klocek
Rename QChartSeries to QSeries
r360 void QChartView::addSeries(QSeries* 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 /*!
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 Removes the \a series specified in a perameter from the QChartView.
Marek Rosa
Added some documentation to QChart and QChartView
r274 It releses its ownership of the specified QChartSeries object.
It does not delete the pointed QChartSeries data object
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 \sa addSeries(), removeAllSeries()
Marek Rosa
Added some documentation to QChart and QChartView
r274 */
Michal Klocek
Rename QChartSeries to QSeries
r360 void QChartView::removeSeries(QSeries* series)
Michal Klocek
Adds missing removeSeries call to chartview
r245 {
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();
}
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 /*!
Zooms in the view by a factor of 2
*/
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 }
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 /*!
Zooms in the view to a maximum level at which \a rect is still fully visible.
*/
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 }
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 /*!
Restores the view zoom level to the previous one.
*/
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 /*!
Michal Klocek
Fixes for docs , adds xyseries docs
r481 Sets the chart \a title. A description text that is drawn 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 force option to chartTheme...
r645 m_chart->setTitle(title);
Michal Klocek
Adds font handling for chart's titile...
r192 }
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 /*!
Michal Klocek
Fixes for docs , adds xyseries docs
r481 Returns the chart's title. A description text that is drawn above the chart.
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 */
QString QChartView::chartTitle() const
{
Michal Klocek
Adds force option to chartTheme...
r645 return m_chart->title();
Michal Klocek
Refactor animation to fit line,spline,scatter...
r476 }
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)
{
Michal Klocek
Adds force option to chartTheme...
r645 m_chart->setTitleFont(font);
Michal Klocek
Add background to chart...
r69 }
Tero Ahola
Chart title font color
r495 /*!
Sets the \a brush used for rendering the title text.
*/
void QChartView::setChartTitleBrush(const QBrush &brush)
{
Michal Klocek
Adds force option to chartTheme...
r645 m_chart->setTitleBrush(brush);
Tero Ahola
Chart title font color
r495 }
/*!
Returns the brush used for rendering the title text.
*/
QBrush QChartView::chartTitleBrush()
{
Michal Klocek
Adds force option to chartTheme...
r645 return m_chart->titleBrush();
Tero Ahola
Chart title font color
r495 }
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 force option to chartTheme...
r645 m_chart->setBackgroundBrush(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 force option to chartTheme...
r645 m_chart->setBackgroundPen(pen);
Michal Klocek
Change background gradient to use ObjectBoundingMode...
r122 }
Michal Klocek
Removes QChartWidget...
r136
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 /*!
Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
*/
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 }
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 /*!
Returns the RubberBandPolicy that is currently being used by the widget.
*/
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;
}
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 /*!
If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
Marek Rosa
Small description update
r328 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 */
Michal Klocek
Removes QChartWidget...
r136 void QChartView::mousePressEvent(QMouseEvent *event)
{
if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
Michal Klocek
Changes background item...
r639 int padding = m_chart->padding();
QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
Michal Klocek
Removes QChartWidget...
r136
if (rect.contains(event->pos())) {
m_rubberBandOrigin = event->pos();
m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
m_rubberBand->show();
event->accept();
}
}
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 else {
QGraphicsView::mousePressEvent(event);
}
Michal Klocek
Removes QChartWidget...
r136 }
Marek Rosa
QChart and QChartView now has some description for all the functions
r287 /*!
If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
*/
Michal Klocek
Removes QChartWidget...
r136 void QChartView::mouseMoveEvent(QMouseEvent *event)
{
Michal Klocek
Adds more axis handling...
r176 if(m_rubberBand && m_rubberBand->isVisible()) {
Michal Klocek
Changes background item...
r639 int padding = m_chart->padding();
QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
Michal Klocek
Removes QChartWidget...
r136 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);
}
}
Marek Rosa
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
r285 /*!
If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
*/
Michal Klocek
Removes QChartWidget...
r136 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 loosenumber algorithm...
r678 if(event->button()==Qt::RightButton){
m_chart->zoomOut();
event->accept();
}
Michal Klocek
Adds more axis handling...
r176 }
else {
Michal Klocek
Removes QChartWidget...
r136 QGraphicsView::mouseReleaseEvent(event);
}
}
Marek Rosa
QChart and QChartView now has some description for all the functions
r287 /*!
Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
*/
Michal Klocek
Removes QChartWidget...
r136 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 }
sauimone
First version of legend. Simple markers and serie names. Using drilldown as example for now.
r529 /*!
Returns the pointer to legend object of the chart
*/
QLegend* QChartView::legend() const
{
return m_chart->legend();
}
Michal Klocek
Adds animation settings handling
r298 /*!
Tero Ahola
QDoc for animation options in QChart
r302 Sets animation \a options for the chart
Michal Klocek
Adds animation settings handling
r298 */
void QChartView::setAnimationOptions(QChart::AnimationOptions options)
{
m_chart->setAnimationOptions(options);
}
/*!
Returns animation options for the chart
*/
QChart::AnimationOptions QChartView::animationOptions() const
{
return m_chart->animationOptions();
}
Michal Klocek
Refcator scrol() to scrollLeft,Right,Up,Down
r600 void QChartView::scrollLeft()
Michal Klocek
Adds scroll support...
r531 {
Michal Klocek
Refcator scrol() to scrollLeft,Right,Up,Down
r600 m_chart->scrollLeft();
Michal Klocek
Adds scroll support...
r531 }
Michal Klocek
Refcator scrol() to scrollLeft,Right,Up,Down
r600 void QChartView::scrollRight()
{
m_chart->scrollRight();
}
void QChartView::scrollUp()
{
m_chart->scrollUp();
}
void QChartView::scrollDown()
{
m_chart->scrollDown();
}
Tero Ahola
New theme with light colors, chartview background
r584 #include "moc_qchartview.cpp"
Michal Klocek
Adds rubberband for zooming...
r58 QTCOMMERCIALCHART_END_NAMESPACE