##// END OF EJS Templates
Fixes missing update barcategory...
Michal Klocek -
r1643:d11966383060
parent child
Show More
@@ -37,28 +37,44 Rectangle {
37 37 legend.alignment: Qt.AlignTop
38 38
39 39 //![2]
40 BarSeries {
41 axisX: CategoriesAxis {
42 id: categoriesAxis
43 categories: ["Mo", "Tu", "We", "Th", "Fr", "Sa" ]
40 BarCategoriesAxis {
41 id: myBarCategoryAxis
42 categories: ["Mo", "Tu", "We", "Th", "Fr"]
44 43 }
45 44
45 BarSeries {
46 id: myBarSeries
46 47 BarSet {
47 48 id: rainfallSet
48 49 label: "Rainfall"
49 50 }
50 51 }
51 52
52 ScatterSeries {
53 ValuesAxis{
54 id: myValuesAxisY
55 min: 0
56 max: 10
57 }
58
59 LineSeries {
53 60 id: maxTempSeries
54 61 name: "Max. temperature"
55 62 }
56 63
57 ScatterSeries {
64 LineSeries {
58 65 id: minTempSeries
59 66 name: "Min. temperature"
60 67 }
61 68 //![2]
69
70 Component.onCompleted: {
71 setAxisX(myBarCategoryAxis,myBarSeries)
72 setAxisX(myBarCategoryAxis,maxTempSeries)
73 setAxisX(myBarCategoryAxis,minTempSeries)
74 setAxisY(myValuesAxisY,maxTempSeries)
75 setAxisY(myValuesAxisY,minTempSeries)
76 setAxisY(myValuesAxisY,myBarSeries)
77 }
62 78 }
63 79
64 80 // A timer to refresh the forecast every 5 minutes
@@ -128,10 +144,6 Rectangle {
128 144
129 145 function parseWeatherData(weatherData) {
130 146 // Clear previous values
131 chartView.axisX.min = 0;
132 chartView.axisX.max = 5;
133 chartView.axisY.min = 0;
134 chartView.axisY.max = 5;
135 147 maxTempSeries.clear();
136 148 minTempSeries.clear();
137 149 weatherImageModel.clear();
@@ -147,23 +159,23 Rectangle {
147 159 maxTempSeries.append(i, weatherObj.tempMaxC);
148 160 minTempSeries.append(i, weatherObj.tempMinC);
149 161 rainfallSet.append(i, weatherObj.precipMM);
150
151 162 weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value});
152 163 //![5]
153 164
154 165 // Update scale of the chart
155 chartView.axisX.min = 0;
156 chartView.axisX.max = i;
157 while (chartView.axisY.min >= Number(weatherObj.tempMinC))
158 chartView.axisY.min = chartView.axisY.min - 10;
159 while (chartView.axisY.max <= Number(weatherObj.tempMaxC))
160 chartView.axisY.max = chartView.axisY.max + 10;
166 chartView.axisY().max = Math.max(chartView.axisY().max,weatherObj.tempMaxC)
167 chartView.axisY().max = Math.max(chartView.axisY().max,weatherObj.tempMinC)
168 chartView.axisX().min = 0;
169 chartView.axisX().max = i+1;
161 170
162 171 // Set the x-axis labels to the dates of the forecast
163 var xLabels = categoriesAxis.categories;
164 xLabels[Number(i) * 2] = i;
165 xLabels[(Number(i) * 2) + 1] = weatherObj.date.substring(5, 10);
166 categoriesAxis.categories = xLabels;
172 var xLabels = myBarCategoryAxis.categories;
173 xLabels[Number(i)] = weatherObj.date.substring(5, 10);
174 myBarCategoryAxis.categories = xLabels;
175 myBarCategoryAxis.visible = true;
167 176 }
177
178
168 179 }
180
169 181 }
@@ -38,8 +38,6 class DeclarativeChart : public QDeclarativeItem
38 38 Q_PROPERTY(QString title READ title WRITE setTitle)
39 39 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
40 40 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
41 Q_PROPERTY(QAbstractAxis *axisX READ axisX)
42 Q_PROPERTY(QAbstractAxis *axisY READ axisY)
43 41 Q_PROPERTY(QLegend *legend READ legend)
44 42 Q_PROPERTY(int count READ count)
45 43 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
@@ -114,8 +112,7 public:
114 112 qreal leftMargin();
115 113 qreal rightMargin();
116 114
117 QAbstractAxis *axisX(QAbstractSeries *series = 0);
118 QAbstractAxis *axisY(QAbstractSeries *series = 0);
115
119 116
120 117 public:
121 118 Q_INVOKABLE QAbstractSeries *series(int index);
@@ -124,6 +121,8 public:
124 121 Q_INVOKABLE void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0);
125 122 Q_INVOKABLE void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0);
126 123 Q_INVOKABLE void createDefaultAxes();
124 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
125 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
127 126
128 127 Q_INVOKABLE void zoom(qreal factor);
129 128 Q_INVOKABLE void scrollLeft(qreal pixels);
@@ -95,7 +95,7 protected:
95 95 void createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const;
96 96
97 97 public Q_SLOTS:
98 void handleAxisUpdated();
98 virtual void handleAxisUpdated();
99 99 void handleAxisCategoriesUpdated();
100 100 void handleRangeChanged(qreal min , qreal max,int tickCount);
101 101 void handleGeometryChanged(const QRectF &size);
@@ -106,4 +106,14 void ChartCategoriesAxisX::updateGeometry()
106 106 }
107 107 }
108 108
109 void ChartCategoriesAxisX::handleAxisUpdated()
110 {
111 if(m_categoriesAxis->categories()!=m_categories)
112 {
113 m_categories=m_categoriesAxis->categories();
114 if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry();
115 }
116 ChartAxis::handleAxisUpdated();
117 }
118
109 119 QTCOMMERCIALCHART_END_NAMESPACE
@@ -49,8 +49,11 public:
49 49 protected:
50 50 QVector<qreal> calculateLayout() const;
51 51 void updateGeometry();
52 Q_SLOTS
53 void handleAxisUpdated();
52 54
53 55 private:
56 QStringList m_categories;
54 57 QBarCategoriesAxis *m_categoriesAxis;
55 58 };
56 59
@@ -105,4 +105,16 void ChartCategoriesAxisY::updateGeometry()
105 105 }
106 106 }
107 107
108
109 void ChartCategoriesAxisY::handleAxisUpdated()
110 {
111
112 if(m_categoriesAxis->categories()!=m_categories)
113 {
114 m_categories=m_categoriesAxis->categories();
115 if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry();
116 }
117 ChartAxis::handleAxisUpdated();
118 }
119
108 120 QTCOMMERCIALCHART_END_NAMESPACE
@@ -49,8 +49,10 public:
49 49 protected:
50 50 QVector<qreal> calculateLayout() const;
51 51 void updateGeometry();
52
52 Q_SLOTS
53 void handleAxisUpdated();
53 54 private:
55 QStringList m_categories;
54 56 QBarCategoriesAxis *m_categoriesAxis;
55 57 };
56 58
@@ -133,7 +133,7 void QBarCategoriesAxis::append(const QStringList &categories)
133 133 }else{
134 134 d->m_categories.append(categories);
135 135 }
136
136 emit d->updated();
137 137 emit categoriesChanged();
138 138 }
139 139
@@ -149,6 +149,7 void QBarCategoriesAxis::append(const QString &category)
149 149 }else{
150 150 d->m_categories.append(category);
151 151 }
152 emit d->updated();
152 153 emit categoriesChanged();
153 154 }
154 155
@@ -161,6 +162,7 void QBarCategoriesAxis::remove(const QString &category)
161 162 if (d->m_categories.contains(category)) {
162 163 d->m_categories.removeAt(d->m_categories.indexOf(category));
163 164 setRange(d->m_categories.first(),d->m_categories.last());
165 emit d->updated();
164 166 emit categoriesChanged();
165 167 }
166 168 }
@@ -177,6 +179,7 void QBarCategoriesAxis::insert(int index, const QString &category)
177 179 }else{
178 180 d->m_categories.insert(index,category);
179 181 }
182 emit d->updated();
180 183 emit categoriesChanged();
181 184 }
182 185
@@ -188,6 +191,7 void QBarCategoriesAxis::clear()
188 191 Q_D(QBarCategoriesAxis);
189 192 d->m_categories.clear();
190 193 setRange(QString::null,QString::null);
194 emit d->updated();
191 195 emit categoriesChanged();
192 196 }
193 197
@@ -197,6 +201,7 void QBarCategoriesAxis::setCategories(const QStringList &categories)
197 201 if(d->m_categories!=categories){
198 202 d->m_categories = categories;
199 203 setRange(categories.first(),categories.last());
204 emit d->updated();
200 205 emit categoriesChanged();
201 206 }
202 207 }
@@ -283,14 +288,14 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& max
283 288 }
284 289
285 290 bool changed = false;
286 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
291 if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) {
287 292 d->m_minCategory = minCategory;
288 293 d->m_min = minIndex;
289 294 emit minChanged(minCategory);
290 295 changed = true;
291 296 }
292 297
293 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
298 if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) {
294 299 d->m_max = maxIndex;
295 300 d->m_maxCategory = maxCategory;
296 301 emit maxChanged(maxCategory);
@@ -299,7 +304,6 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& max
299 304
300 305 if (changed) {
301 306 d->emitRange();
302 emit categoriesChanged();
303 307 }
304 308 }
305 309
General Comments 0
You need to be logged in to leave comments. Login now