##// END OF EJS Templates
QML ChartView scrolling, zooming, drop shadow
Tero Ahola -
r1461:bf7c8a356b51
parent child
Show More
@@ -220,6 +220,71 int DeclarativeChart::count()
220 return m_chart->series().count();
220 return m_chart->series().count();
221 }
221 }
222
222
223 void DeclarativeChart::setDropShadowEnabled(bool enabled)
224 {
225 if (enabled != m_chart->isBackgroundDropShadowEnabled()) {
226 m_chart->setBackgroundDropShadowEnabled(enabled);
227 dropShadowEnabledChanged(enabled);
228 }
229 }
230
231 bool DeclarativeChart::dropShadowEnabled()
232 {
233 return m_chart->isBackgroundDropShadowEnabled();
234 }
235
236 void DeclarativeChart::zoom(qreal factor)
237 {
238 m_chart->zoom(factor);
239 }
240
241 void DeclarativeChart::scrollLeft(qreal pixels)
242 {
243 m_chart->scroll(QPointF(pixels, 0));
244 }
245
246 void DeclarativeChart::scrollRight(qreal pixels)
247 {
248 m_chart->scroll(QPointF(-pixels, 0));
249 }
250
251 void DeclarativeChart::scrollUp(qreal pixels)
252 {
253 m_chart->scroll(QPointF(0, pixels));
254 }
255
256 void DeclarativeChart::scrollDown(qreal pixels)
257 {
258 m_chart->scroll(QPointF(0, -pixels));
259 }
260
261 //void DeclarativeChart::scrollLeft(qreal ticks)
262 //{
263 // m_chart->scroll(QPointF(ticksToPixels(m_chart->axisX(), ticks), 0));
264 //}
265
266 //void DeclarativeChart::scrollRight(qreal ticks)
267 //{
268 // m_chart->scroll(QPointF(-ticksToPixels(m_chart->axisX(), ticks), 0));
269 //}
270
271 //void DeclarativeChart::scrollUp(qreal ticks)
272 //{
273 // m_chart->scroll(QPointF(0, ticksToPixels(m_chart->axisY(), ticks)));
274 //}
275
276 //void DeclarativeChart::scrollDown(qreal ticks)
277 //{
278 // m_chart->scroll(QPointF(0, -ticksToPixels(m_chart->axisY(), ticks)));
279 //}
280
281 //qreal DeclarativeChart::ticksToPixels(QAxis *axis, qreal ticks)
282 //{
283 // qreal tickCount = axis->max() - axis->min();
284 // qreal tickPixels = (m_chart->size().width() - m_chart->margins().width() * 2) / tickCount;
285 // return tickPixels * ticks;
286 //}
287
223 QAbstractSeries *DeclarativeChart::series(int index)
288 QAbstractSeries *DeclarativeChart::series(int index)
224 {
289 {
225 if (index < m_chart->series().count()) {
290 if (index < m_chart->series().count()) {
@@ -37,14 +37,15 class DeclarativeChart : public QDeclarativeItem
37 Q_PROPERTY(Theme theme READ theme WRITE setTheme NOTIFY themeChanged)
37 Q_PROPERTY(Theme theme READ theme WRITE setTheme NOTIFY themeChanged)
38 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions NOTIFY animationOptionsChanged)
38 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions NOTIFY animationOptionsChanged)
39 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
39 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
40 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
40 Q_PROPERTY(QAxis *axisX READ axisX)
41 Q_PROPERTY(QAxis *axisX READ axisX)
41 Q_PROPERTY(QAxis *axisY READ axisY)
42 Q_PROPERTY(QAxis *axisY READ axisY)
42 Q_PROPERTY(QLegend *legend READ legend)
43 Q_PROPERTY(QLegend *legend READ legend)
43 // TODO: how to define axis labels? This is not very convenient
44 // TODO: how to define axis labels? This is not very convenient
44 Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged)
45 Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged)
45 Q_PROPERTY(int count READ count)
46 Q_PROPERTY(int count READ count)
46 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
47 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
47 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
48 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
48 Q_ENUMS(Animation)
49 Q_ENUMS(Animation)
49 Q_ENUMS(Theme)
50 Q_ENUMS(Theme)
50 Q_ENUMS(SeriesType)
51 Q_ENUMS(SeriesType)
@@ -107,6 +108,13 public:
107 void setBackgroundColor(QColor color);
108 void setBackgroundColor(QColor color);
108 QColor backgroundColor();
109 QColor backgroundColor();
109 int count();
110 int count();
111 void setDropShadowEnabled(bool enabled);
112 bool dropShadowEnabled();
113 Q_INVOKABLE void zoom(qreal factor);
114 Q_INVOKABLE void scrollLeft(qreal pixels);
115 Q_INVOKABLE void scrollRight(qreal pixels);
116 Q_INVOKABLE void scrollUp(qreal pixels);
117 Q_INVOKABLE void scrollDown(qreal pixels);
110 Q_INVOKABLE QAbstractSeries *series(int index);
118 Q_INVOKABLE QAbstractSeries *series(int index);
111 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
119 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
112 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
120 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
@@ -118,6 +126,7 Q_SIGNALS:
118 void axisLabelsChanged();
126 void axisLabelsChanged();
119 void titleColorChanged();
127 void titleColorChanged();
120 void backgroundColorChanged();
128 void backgroundColorChanged();
129 void dropShadowEnabledChanged(bool enabled);
121
130
122 public:
131 public:
123 // Extending QChart with DeclarativeChart is not possible because QObject does not support
132 // Extending QChart with DeclarativeChart is not possible because QObject does not support
@@ -43,6 +43,7 Flow {
43 onAnimationOptionsChanged: console.log("chart.onAnimationOptionsChanged: " + series.animationOptions);
43 onAnimationOptionsChanged: console.log("chart.onAnimationOptionsChanged: " + series.animationOptions);
44 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + series.titleColor);
44 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + series.titleColor);
45 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor);
45 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor);
46 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
46 }
47 }
47
48
48 Connections {
49 Connections {
@@ -116,6 +117,34 Flow {
116 onClicked: series.backgroundColor = main.nextColor();
117 onClicked: series.backgroundColor = main.nextColor();
117 }
118 }
118 Button {
119 Button {
120 text: "drop shadow enabled"
121 onClicked: series.dropShadowEnabled = !series.dropShadowEnabled;
122 }
123 Button {
124 text: "zoom +"
125 onClicked: series.zoom(2);
126 }
127 Button {
128 text: "zoom -"
129 onClicked: series.zoom(0.5);
130 }
131 Button {
132 text: "scroll left"
133 onClicked: series.scrollLeft(10);
134 }
135 Button {
136 text: "scroll right"
137 onClicked: series.scrollRight(10);
138 }
139 Button {
140 text: "scroll up"
141 onClicked: series.scrollUp(10);
142 }
143 Button {
144 text: "scroll down"
145 onClicked: series.scrollDown(10);
146 }
147 Button {
119 text: "legend visible"
148 text: "legend visible"
120 onClicked: series.legend.visible = !series.legend.visible;
149 onClicked: series.legend.visible = !series.legend.visible;
121 }
150 }
General Comments 0
You need to be logged in to leave comments. Login now