##// END OF EJS Templates
else clause added to QChartView mousePressEvent. Added some more docs to QChart and QChartView
Marek Rosa -
r285:46d1e061b6ff
parent child
Show More
@@ -101,7 +101,7 Widget::~Widget()
101 */
101 */
102 void Widget::refreshChart()
102 void Widget::refreshChart()
103 {
103 {
104 chartArea->removeSeries(series0);
104 chartArea->removeAllSeries();
105
105
106 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
106 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
107 QStringList selectedCountriesStrings;
107 QStringList selectedCountriesStrings;
@@ -141,7 +141,7 void Widget::refreshChart()
141 for (int i = 0; i < selectedYearsInts.size(); i++)
141 for (int i = 0; i < selectedYearsInts.size(); i++)
142 {
142 {
143 query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery);
143 query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery);
144 QBarSet* barSet = new QBarSet;
144 QBarSet* barSet = new QBarSet(QString("GDP_%1").arg(selectedYearsInts[i]));
145 // while (query.next()) {
145 // while (query.next()) {
146 // qDebug() << query.value(0).toString() << " : " << query.value(1).toString();
146 // qDebug() << query.value(0).toString() << " : " << query.value(1).toString();
147 // }
147 // }
@@ -205,9 +205,10 void Widget::refreshChart()
205 qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt();
205 qDebug() << "Putting 0 for Bosnia" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt();
206 }
206 }
207 }
207 }
208 chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1);
208 // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1);
209 chartArea->addSeries(series);
209 chartArea->addSeries(series);
210 }
210 }
211 chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1);
211 }
212 }
212 }
213 }
213
214
@@ -32,7 +32,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 */
32 */
33
33
34 /*!
34 /*!
35 Constructs a chart object which is a child of parent.
35 Constructs a chart object which is a child of a\a parent.
36 */
36 */
37 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
37 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
38 m_backgroundItem(0),
38 m_backgroundItem(0),
@@ -50,7 +50,7 QChart::~QChart()
50 }
50 }
51
51
52 /*!
52 /*!
53 Adds the \a series and optional y axis onto the chart and takes the ownership of the objects.
53 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
54 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
54 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
55 the y axis).
55 the y axis).
56 */
56 */
@@ -60,10 +60,10 void QChart::addSeries(QChartSeries* series, QChartAxis* axisY)
60 }
60 }
61
61
62 /*!
62 /*!
63 Removes the QChartSeries specified in a perameter from the QChartView.
63 Removes the \a series specified in a perameter from the QChartView.
64 It releses its ownership of the specified QChartSeries object.
64 It releses its ownership of the specified QChartSeries object.
65 It does not delete the pointed QChartSeries data object
65 It does not delete the pointed QChartSeries data object
66 \sa removeSeries(), removeAllSeries()
66 \sa addSeries(), removeAllSeries()
67 */
67 */
68 void QChart::removeSeries(QChartSeries* series)
68 void QChart::removeSeries(QChartSeries* series)
69 {
69 {
@@ -148,7 +148,7 void QChart::setMargin(int margin)
148 }
148 }
149
149
150 /*!
150 /*!
151 Sets the \a theme used by the chart for rendering data graphical representation
151 Sets the \a theme used by the chart for rendering the graphical representation of the data
152 \sa ChartTheme, chartTheme()
152 \sa ChartTheme, chartTheme()
153 */
153 */
154 void QChart::setChartTheme(QChart::ChartTheme theme)
154 void QChart::setChartTheme(QChart::ChartTheme theme)
@@ -165,6 +165,9 QChart::ChartTheme QChart::chartTheme() const
165 return m_presenter->chartTheme();
165 return m_presenter->chartTheme();
166 }
166 }
167
167
168 /*!
169 Zooms in the view by a factor of 2
170 */
168 void QChart::zoomIn()
171 void QChart::zoomIn()
169 {
172 {
170 if (!m_dataset->nextDomain()) {
173 if (!m_dataset->nextDomain()) {
@@ -176,6 +179,9 void QChart::zoomIn()
176 }
179 }
177 }
180 }
178
181
182 /*!
183 Zooms in the view to a maximum level at which \a rect is still fully visible.
184 */
179 void QChart::zoomIn(const QRectF& rect)
185 void QChart::zoomIn(const QRectF& rect)
180 {
186 {
181 if(!rect.isValid()) return;
187 if(!rect.isValid()) return;
@@ -185,6 +191,9 void QChart::zoomIn(const QRectF& rect)
185 m_dataset->addDomain(r,m_presenter->geometry());
191 m_dataset->addDomain(r,m_presenter->geometry());
186 }
192 }
187
193
194 /*!
195 Restores the view zoom level to the previous one.
196 */
188 void QChart::zoomOut()
197 void QChart::zoomOut()
189 {
198 {
190 m_dataset->previousDomain();
199 m_dataset->previousDomain();
@@ -25,14 +25,14 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
25 {
25 {
26 Q_OBJECT
26 Q_OBJECT
27 public:
27 public:
28 enum ChartTheme {
28 enum ChartTheme {
29 /*! The default theme follows the GUI style of the Operating System */
30 ChartThemeDefault,
29 ChartThemeDefault,
31 ChartThemeVanilla,
30 ChartThemeVanilla,
32 ChartThemeIcy,
31 ChartThemeIcy,
33 ChartThemeGrayscale,
32 ChartThemeGrayscale,
34 ChartThemeScientific
33 ChartThemeScientific
35 //ChartThemeUnnamed1
34 //ChartThemeUnnamed1
35 /*! The default theme follows the GUI style of the Operating System */
36 };
36 };
37
37
38 public:
38 public:
@@ -20,6 +20,9
20
20
21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
22
22
23 /*!
24 Constructs a chartView object which is a child of a\a parent.
25 */
23 QChartView::QChartView(QWidget *parent) :
26 QChartView::QChartView(QWidget *parent) :
24 QGraphicsView(parent),
27 QGraphicsView(parent),
25 m_scene(new QGraphicsScene(this)),
28 m_scene(new QGraphicsScene(this)),
@@ -52,10 +55,10 void QChartView::resizeEvent(QResizeEvent *event)
52 }
55 }
53
56
54 /*!
57 /*!
55 Adds the series and optional y axis onto the chart and takes the ownership of the objects.
58 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
56 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
59 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
57 the y axis).
60 the y axis).
58 \sa removeSeries, removeAllSeries
61 \sa removeSeries(), removeAllSeries()
59 */
62 */
60 void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
63 void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
61 {
64 {
@@ -63,10 +66,10 void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
63 }
66 }
64
67
65 /*!
68 /*!
66 Removes the QChartSeries specified in a perameter from the QChartView.
69 Removes the \a series specified in a perameter from the QChartView.
67 It releses its ownership of the specified QChartSeries object.
70 It releses its ownership of the specified QChartSeries object.
68 It does not delete the pointed QChartSeries data object
71 It does not delete the pointed QChartSeries data object
69 \sa removeSeries(), removeAllSeries()
72 \sa addSeries(), removeAllSeries()
70 */
73 */
71 void QChartView::removeSeries(QChartSeries* series)
74 void QChartView::removeSeries(QChartSeries* series)
72 {
75 {
@@ -83,16 +86,25 void QChartView::removeAllSeries()
83 m_chart->removeAllSeries();
86 m_chart->removeAllSeries();
84 }
87 }
85
88
89 /*!
90 Zooms in the view by a factor of 2
91 */
86 void QChartView::zoomIn()
92 void QChartView::zoomIn()
87 {
93 {
88 m_chart->zoomIn();
94 m_chart->zoomIn();
89 }
95 }
90
96
97 /*!
98 Zooms in the view to a maximum level at which \a rect is still fully visible.
99 */
91 void QChartView::zoomIn(const QRect& rect)
100 void QChartView::zoomIn(const QRect& rect)
92 {
101 {
93 m_chart->zoomIn(rect);
102 m_chart->zoomIn(rect);
94 }
103 }
95
104
105 /*!
106 Restores the view zoom level to the previous one.
107 */
96 void QChartView::zoomOut()
108 void QChartView::zoomOut()
97 {
109 {
98 m_chart->zoomOut();
110 m_chart->zoomOut();
@@ -107,7 +119,7 int QChartView::margin() const
107 }
119 }
108
120
109 /*!
121 /*!
110 Sets the chart \a tile. A description text that is rendered above the chart.
122 Sets the chart \a title. A description text that is rendered above the chart.
111 */
123 */
112 void QChartView::setChartTitle(const QString& title)
124 void QChartView::setChartTitle(const QString& title)
113 {
125 {
@@ -138,6 +150,9 void QChartView::setChartBackgroundPen(const QPen& pen)
138 m_chart->setChartBackgroundPen(pen);
150 m_chart->setChartBackgroundPen(pen);
139 }
151 }
140
152
153 /*!
154 Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
155 */
141 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
156 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
142 {
157 {
143 switch(policy) {
158 switch(policy) {
@@ -167,6 +182,9 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
167 }
182 }
168 }
183 }
169
184
185 /*!
186 Returns the RubberBandPolicy that is currently being used by the widget.
187 */
170 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
188 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
171 {
189 {
172 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
190 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
@@ -175,6 +193,10 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
175 return NoRubberBand;
193 return NoRubberBand;
176 }
194 }
177
195
196 /*!
197 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.
198 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is not consumed.
199 */
178 void QChartView::mousePressEvent(QMouseEvent *event)
200 void QChartView::mousePressEvent(QMouseEvent *event)
179 {
201 {
180 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
202 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
@@ -189,6 +211,9 void QChartView::mousePressEvent(QMouseEvent *event)
189 event->accept();
211 event->accept();
190 }
212 }
191 }
213 }
214 else {
215 QGraphicsView::mousePressEvent(event);
216 }
192 }
217 }
193
218
194 void QChartView::mouseMoveEvent(QMouseEvent *event)
219 void QChartView::mouseMoveEvent(QMouseEvent *event)
@@ -213,6 +238,10 void QChartView::mouseMoveEvent(QMouseEvent *event)
213 }
238 }
214 }
239 }
215
240
241 /*!
242 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
243 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
244 */
216 void QChartView::mouseReleaseEvent(QMouseEvent *event)
245 void QChartView::mouseReleaseEvent(QMouseEvent *event)
217 {
246 {
218 if(m_rubberBand) {
247 if(m_rubberBand) {
General Comments 0
You need to be logged in to leave comments. Login now