From d1196638306064bd1e79bec7604b941c163b82aa 2012-07-04 12:10:38 From: Michal Klocek Date: 2012-07-04 12:10:38 Subject: [PATCH] Fixes missing update barcategory * fixes qmlweather * qml axis returns as INVOCABLE --- diff --git a/demos/qmlweather/qml/qmlweather/main.qml b/demos/qmlweather/qml/qmlweather/main.qml index 6d11c0b..adba41c 100644 --- a/demos/qmlweather/qml/qmlweather/main.qml +++ b/demos/qmlweather/qml/qmlweather/main.qml @@ -37,28 +37,44 @@ Rectangle { legend.alignment: Qt.AlignTop //![2] + BarCategoriesAxis { + id: myBarCategoryAxis + categories: ["Mo", "Tu", "We", "Th", "Fr"] + } + BarSeries { - axisX: CategoriesAxis { - id: categoriesAxis - categories: ["Mo", "Tu", "We", "Th", "Fr", "Sa" ] - } - + id: myBarSeries BarSet { id: rainfallSet label: "Rainfall" } } + + ValuesAxis{ + id: myValuesAxisY + min: 0 + max: 10 + } - ScatterSeries { + LineSeries { id: maxTempSeries name: "Max. temperature" } - ScatterSeries { + LineSeries { id: minTempSeries name: "Min. temperature" } //![2] + + Component.onCompleted: { + setAxisX(myBarCategoryAxis,myBarSeries) + setAxisX(myBarCategoryAxis,maxTempSeries) + setAxisX(myBarCategoryAxis,minTempSeries) + setAxisY(myValuesAxisY,maxTempSeries) + setAxisY(myValuesAxisY,minTempSeries) + setAxisY(myValuesAxisY,myBarSeries) + } } // A timer to refresh the forecast every 5 minutes @@ -128,10 +144,6 @@ Rectangle { function parseWeatherData(weatherData) { // Clear previous values - chartView.axisX.min = 0; - chartView.axisX.max = 5; - chartView.axisY.min = 0; - chartView.axisY.max = 5; maxTempSeries.clear(); minTempSeries.clear(); weatherImageModel.clear(); @@ -147,23 +159,23 @@ Rectangle { maxTempSeries.append(i, weatherObj.tempMaxC); minTempSeries.append(i, weatherObj.tempMinC); rainfallSet.append(i, weatherObj.precipMM); - weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value}); //![5] // Update scale of the chart - chartView.axisX.min = 0; - chartView.axisX.max = i; - while (chartView.axisY.min >= Number(weatherObj.tempMinC)) - chartView.axisY.min = chartView.axisY.min - 10; - while (chartView.axisY.max <= Number(weatherObj.tempMaxC)) - chartView.axisY.max = chartView.axisY.max + 10; + chartView.axisY().max = Math.max(chartView.axisY().max,weatherObj.tempMaxC) + chartView.axisY().max = Math.max(chartView.axisY().max,weatherObj.tempMinC) + chartView.axisX().min = 0; + chartView.axisX().max = i+1; // Set the x-axis labels to the dates of the forecast - var xLabels = categoriesAxis.categories; - xLabels[Number(i) * 2] = i; - xLabels[(Number(i) * 2) + 1] = weatherObj.date.substring(5, 10); - categoriesAxis.categories = xLabels; + var xLabels = myBarCategoryAxis.categories; + xLabels[Number(i)] = weatherObj.date.substring(5, 10); + myBarCategoryAxis.categories = xLabels; + myBarCategoryAxis.visible = true; } + + } + } diff --git a/plugins/declarative/declarativechart.h b/plugins/declarative/declarativechart.h index 7ae0a1a..c8481b8 100644 --- a/plugins/declarative/declarativechart.h +++ b/plugins/declarative/declarativechart.h @@ -38,8 +38,6 @@ class DeclarativeChart : public QDeclarativeItem Q_PROPERTY(QString title READ title WRITE setTitle) Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) - Q_PROPERTY(QAbstractAxis *axisX READ axisX) - Q_PROPERTY(QAbstractAxis *axisY READ axisY) Q_PROPERTY(QLegend *legend READ legend) Q_PROPERTY(int count READ count) Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) @@ -114,8 +112,7 @@ public: qreal leftMargin(); qreal rightMargin(); - QAbstractAxis *axisX(QAbstractSeries *series = 0); - QAbstractAxis *axisY(QAbstractSeries *series = 0); + public: Q_INVOKABLE QAbstractSeries *series(int index); @@ -124,6 +121,8 @@ public: Q_INVOKABLE void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0); Q_INVOKABLE void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0); Q_INVOKABLE void createDefaultAxes(); + Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); + Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); Q_INVOKABLE void zoom(qreal factor); Q_INVOKABLE void scrollLeft(qreal pixels); diff --git a/src/axis/chartaxis_p.h b/src/axis/chartaxis_p.h index b312b62..e0bd406 100644 --- a/src/axis/chartaxis_p.h +++ b/src/axis/chartaxis_p.h @@ -95,7 +95,7 @@ protected: void createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const; public Q_SLOTS: - void handleAxisUpdated(); + virtual void handleAxisUpdated(); void handleAxisCategoriesUpdated(); void handleRangeChanged(qreal min , qreal max,int tickCount); void handleGeometryChanged(const QRectF &size); diff --git a/src/axis/chartcategoriesaxisx.cpp b/src/axis/chartcategoriesaxisx.cpp index afcf0b8..26d387d 100644 --- a/src/axis/chartcategoriesaxisx.cpp +++ b/src/axis/chartcategoriesaxisx.cpp @@ -106,4 +106,14 @@ void ChartCategoriesAxisX::updateGeometry() } } +void ChartCategoriesAxisX::handleAxisUpdated() +{ + if(m_categoriesAxis->categories()!=m_categories) + { + m_categories=m_categoriesAxis->categories(); + if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); + } + ChartAxis::handleAxisUpdated(); +} + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/chartcategoriesaxisx_p.h b/src/axis/chartcategoriesaxisx_p.h index f206a19..730e5b6 100644 --- a/src/axis/chartcategoriesaxisx_p.h +++ b/src/axis/chartcategoriesaxisx_p.h @@ -49,8 +49,11 @@ public: protected: QVector calculateLayout() const; void updateGeometry(); +Q_SLOTS + void handleAxisUpdated(); private: + QStringList m_categories; QBarCategoriesAxis *m_categoriesAxis; }; diff --git a/src/axis/chartcategoriesaxisy.cpp b/src/axis/chartcategoriesaxisy.cpp index cbdb448..b8f7593 100644 --- a/src/axis/chartcategoriesaxisy.cpp +++ b/src/axis/chartcategoriesaxisy.cpp @@ -105,4 +105,16 @@ void ChartCategoriesAxisY::updateGeometry() } } + +void ChartCategoriesAxisY::handleAxisUpdated() +{ + + if(m_categoriesAxis->categories()!=m_categories) + { + m_categories=m_categoriesAxis->categories(); + if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); + } + ChartAxis::handleAxisUpdated(); +} + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/chartcategoriesaxisy_p.h b/src/axis/chartcategoriesaxisy_p.h index 278afec..d93efc9 100644 --- a/src/axis/chartcategoriesaxisy_p.h +++ b/src/axis/chartcategoriesaxisy_p.h @@ -49,8 +49,10 @@ public: protected: QVector calculateLayout() const; void updateGeometry(); - +Q_SLOTS + void handleAxisUpdated(); private: + QStringList m_categories; QBarCategoriesAxis *m_categoriesAxis; }; diff --git a/src/axis/qbarcategoriesaxis.cpp b/src/axis/qbarcategoriesaxis.cpp index 77f6c0d..aa9bba7 100644 --- a/src/axis/qbarcategoriesaxis.cpp +++ b/src/axis/qbarcategoriesaxis.cpp @@ -133,7 +133,7 @@ void QBarCategoriesAxis::append(const QStringList &categories) }else{ d->m_categories.append(categories); } - + emit d->updated(); emit categoriesChanged(); } @@ -149,6 +149,7 @@ void QBarCategoriesAxis::append(const QString &category) }else{ d->m_categories.append(category); } + emit d->updated(); emit categoriesChanged(); } @@ -161,6 +162,7 @@ void QBarCategoriesAxis::remove(const QString &category) if (d->m_categories.contains(category)) { d->m_categories.removeAt(d->m_categories.indexOf(category)); setRange(d->m_categories.first(),d->m_categories.last()); + emit d->updated(); emit categoriesChanged(); } } @@ -177,6 +179,7 @@ void QBarCategoriesAxis::insert(int index, const QString &category) }else{ d->m_categories.insert(index,category); } + emit d->updated(); emit categoriesChanged(); } @@ -188,6 +191,7 @@ void QBarCategoriesAxis::clear() Q_D(QBarCategoriesAxis); d->m_categories.clear(); setRange(QString::null,QString::null); + emit d->updated(); emit categoriesChanged(); } @@ -197,6 +201,7 @@ void QBarCategoriesAxis::setCategories(const QStringList &categories) if(d->m_categories!=categories){ d->m_categories = categories; setRange(categories.first(),categories.last()); + emit d->updated(); emit categoriesChanged(); } } @@ -283,14 +288,14 @@ void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& max } bool changed = false; - if (!qFuzzyIsNull(d->m_min - (minIndex))) { + if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) { d->m_minCategory = minCategory; d->m_min = minIndex; emit minChanged(minCategory); changed = true; } - if (!qFuzzyIsNull(d->m_max - (maxIndex))) { + if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) { d->m_max = maxIndex; d->m_maxCategory = maxCategory; emit maxChanged(maxCategory); @@ -299,7 +304,6 @@ void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& max if (changed) { d->emitRange(); - emit categoriesChanged(); } }