diff --git a/example/gdpbarchart/widget.cpp b/example/gdpbarchart/widget.cpp index 8514984..0193a9c 100644 --- a/example/gdpbarchart/widget.cpp +++ b/example/gdpbarchart/widget.cpp @@ -101,7 +101,7 @@ Widget::~Widget() */ void Widget::refreshChart() { - chartArea->removeSeries(series0); + chartArea->removeAllSeries(); // selected countries items list is not sorted. copy the values to QStringlist and sort them. QStringList selectedCountriesStrings; @@ -141,7 +141,7 @@ void Widget::refreshChart() for (int i = 0; i < selectedYearsInts.size(); i++) { query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); - QBarSet* barSet = new QBarSet; + QBarSet* barSet = new QBarSet(QString("GDP_%1").arg(selectedYearsInts[i])); // while (query.next()) { // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); // } @@ -205,9 +205,10 @@ void Widget::refreshChart() qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt(); } } - chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1); +// chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1); chartArea->addSeries(series); } + chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1); } } diff --git a/src/qchart.cpp b/src/qchart.cpp index 479b130..2d60157 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -32,7 +32,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - Constructs a chart object which is a child of parent. + Constructs a chart object which is a child of a\a parent. */ QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), m_backgroundItem(0), @@ -50,7 +50,7 @@ QChart::~QChart() } /*! - Adds the \a series and optional y axis onto the chart and takes the ownership of the objects. + Adds the \a series and optional \a axisY 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). */ @@ -60,10 +60,10 @@ void QChart::addSeries(QChartSeries* series, QChartAxis* axisY) } /*! - Removes the QChartSeries specified in a perameter from the QChartView. + Removes the \a series 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() + \sa addSeries(), removeAllSeries() */ void QChart::removeSeries(QChartSeries* series) { @@ -148,7 +148,7 @@ void QChart::setMargin(int margin) } /*! - Sets the \a theme used by the chart for rendering data graphical representation + Sets the \a theme used by the chart for rendering the graphical representation of the data \sa ChartTheme, chartTheme() */ void QChart::setChartTheme(QChart::ChartTheme theme) @@ -165,6 +165,9 @@ QChart::ChartTheme QChart::chartTheme() const return m_presenter->chartTheme(); } +/*! + Zooms in the view by a factor of 2 +*/ void QChart::zoomIn() { if (!m_dataset->nextDomain()) { @@ -176,6 +179,9 @@ void QChart::zoomIn() } } +/*! + Zooms in the view to a maximum level at which \a rect is still fully visible. +*/ void QChart::zoomIn(const QRectF& rect) { if(!rect.isValid()) return; @@ -185,6 +191,9 @@ void QChart::zoomIn(const QRectF& rect) m_dataset->addDomain(r,m_presenter->geometry()); } +/*! + Restores the view zoom level to the previous one. +*/ void QChart::zoomOut() { m_dataset->previousDomain(); diff --git a/src/qchart.h b/src/qchart.h index 0fa31ca..15b068f 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -25,14 +25,14 @@ class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget { Q_OBJECT public: - enum ChartTheme { - /*! The default theme follows the GUI style of the Operating System */ + enum ChartTheme { ChartThemeDefault, ChartThemeVanilla, ChartThemeIcy, ChartThemeGrayscale, ChartThemeScientific //ChartThemeUnnamed1 + /*! The default theme follows the GUI style of the Operating System */ }; public: diff --git a/src/qchartview.cpp b/src/qchartview.cpp index ddb825a..ed9e204 100644 --- a/src/qchartview.cpp +++ b/src/qchartview.cpp @@ -20,6 +20,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE +/*! + Constructs a chartView object which is a child of a\a parent. +*/ QChartView::QChartView(QWidget *parent) : QGraphicsView(parent), m_scene(new QGraphicsScene(this)), @@ -52,10 +55,10 @@ void QChartView::resizeEvent(QResizeEvent *event) } /*! - Adds the series and optional y axis onto the chart and takes the ownership of the objects. + Adds the \a series and optional \a axisY 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 + \sa removeSeries(), removeAllSeries() */ void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY) { @@ -63,10 +66,10 @@ void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY) } /*! - Removes the QChartSeries specified in a perameter from the QChartView. + Removes the \a series 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() + \sa addSeries(), removeAllSeries() */ void QChartView::removeSeries(QChartSeries* series) { @@ -83,16 +86,25 @@ void QChartView::removeAllSeries() m_chart->removeAllSeries(); } +/*! + Zooms in the view by a factor of 2 +*/ void QChartView::zoomIn() { m_chart->zoomIn(); } +/*! + Zooms in the view to a maximum level at which \a rect is still fully visible. +*/ void QChartView::zoomIn(const QRect& rect) { m_chart->zoomIn(rect); } +/*! + Restores the view zoom level to the previous one. +*/ void QChartView::zoomOut() { m_chart->zoomOut(); @@ -107,7 +119,7 @@ int QChartView::margin() const } /*! - Sets the chart \a tile. A description text that is rendered above the chart. + Sets the chart \a title. A description text that is rendered above the chart. */ void QChartView::setChartTitle(const QString& title) { @@ -138,6 +150,9 @@ void QChartView::setChartBackgroundPen(const QPen& pen) m_chart->setChartBackgroundPen(pen); } +/*! + Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. +*/ void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) { switch(policy) { @@ -167,6 +182,9 @@ void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) } } +/*! + Returns the RubberBandPolicy that is currently being used by the widget. +*/ QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const { if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; @@ -175,6 +193,10 @@ QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const return NoRubberBand; } +/*! + 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. + If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is not consumed. +*/ void QChartView::mousePressEvent(QMouseEvent *event) { if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { @@ -189,6 +211,9 @@ void QChartView::mousePressEvent(QMouseEvent *event) event->accept(); } } + else { + QGraphicsView::mousePressEvent(event); + } } void QChartView::mouseMoveEvent(QMouseEvent *event) @@ -213,6 +238,10 @@ void QChartView::mouseMoveEvent(QMouseEvent *event) } } +/*! + 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. +*/ void QChartView::mouseReleaseEvent(QMouseEvent *event) { if(m_rubberBand) {