@@ -220,6 +220,71 int DeclarativeChart::count() | |||
|
220 | 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 | 288 | QAbstractSeries *DeclarativeChart::series(int index) |
|
224 | 289 | { |
|
225 | 290 | if (index < m_chart->series().count()) { |
@@ -37,14 +37,15 class DeclarativeChart : public QDeclarativeItem | |||
|
37 | 37 | Q_PROPERTY(Theme theme READ theme WRITE setTheme NOTIFY themeChanged) |
|
38 | 38 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions NOTIFY animationOptionsChanged) |
|
39 | 39 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) |
|
40 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) | |
|
40 | 41 | Q_PROPERTY(QAxis *axisX READ axisX) |
|
41 | 42 | Q_PROPERTY(QAxis *axisY READ axisY) |
|
42 | 43 | Q_PROPERTY(QLegend *legend READ legend) |
|
43 | 44 | // TODO: how to define axis labels? This is not very convenient |
|
44 | 45 | Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged) |
|
45 | 46 | Q_PROPERTY(int count READ count) |
|
46 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) | |
|
47 | 47 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
48 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) | |
|
48 | 49 | Q_ENUMS(Animation) |
|
49 | 50 | Q_ENUMS(Theme) |
|
50 | 51 | Q_ENUMS(SeriesType) |
@@ -107,6 +108,13 public: | |||
|
107 | 108 | void setBackgroundColor(QColor color); |
|
108 | 109 | QColor backgroundColor(); |
|
109 | 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 | 118 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
111 | 119 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
112 | 120 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); |
@@ -118,6 +126,7 Q_SIGNALS: | |||
|
118 | 126 | void axisLabelsChanged(); |
|
119 | 127 | void titleColorChanged(); |
|
120 | 128 | void backgroundColorChanged(); |
|
129 | void dropShadowEnabledChanged(bool enabled); | |
|
121 | 130 | |
|
122 | 131 | public: |
|
123 | 132 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
@@ -43,6 +43,7 Flow { | |||
|
43 | 43 | onAnimationOptionsChanged: console.log("chart.onAnimationOptionsChanged: " + series.animationOptions); |
|
44 | 44 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + series.titleColor); |
|
45 | 45 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); |
|
46 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); | |
|
46 | 47 | } |
|
47 | 48 | |
|
48 | 49 | Connections { |
@@ -116,6 +117,34 Flow { | |||
|
116 | 117 | onClicked: series.backgroundColor = main.nextColor(); |
|
117 | 118 | } |
|
118 | 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 | 148 | text: "legend visible" |
|
120 | 149 | onClicked: series.legend.visible = !series.legend.visible; |
|
121 | 150 | } |
General Comments 0
You need to be logged in to leave comments.
Login now