From c3705e59ed4078422b2ea28ea95135bdf12e49c5 2012-08-22 12:03:24 From: Tero Ahola Date: 2012-08-22 12:03:24 Subject: [PATCH] Refactored QML axis handling --- diff --git a/demos/qmlchart/qml/qmlchart/View1.qml b/demos/qmlchart/qml/qmlchart/View1.qml index c07f0e1..9a0cdca 100644 --- a/demos/qmlchart/qml/qmlchart/View1.qml +++ b/demos/qmlchart/qml/qmlchart/View1.qml @@ -35,9 +35,6 @@ Rectangle { PieSeries { id: pieSeries - onClicked: { - slice.exploded = !slice.exploded; - } PieSlice { label: "Volkswagen"; value: 13.5 } PieSlice { label: "Toyota"; value: 10.9 } PieSlice { label: "Ford"; value: 8.6 } @@ -45,11 +42,11 @@ Rectangle { PieSlice { label: "Volvo"; value: 6.8 } } } - //![1] Component.onCompleted: { - // You can also add slices dynamically + // You can also manipulate slices dynamically otherSlice = pieSeries.append("Others", 52.0); pieSeries.find("Volkswagen").exploded = true; } + //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View10.qml b/demos/qmlchart/qml/qmlchart/View10.qml index 4e23106..15912cb 100644 --- a/demos/qmlchart/qml/qmlchart/View10.qml +++ b/demos/qmlchart/qml/qmlchart/View10.qml @@ -29,20 +29,13 @@ Rectangle { title: "Horizontal Stacked Bar series" anchors.fill: parent legend.alignment: Qt.AlignBottom - BarCategoriesAxis { - id: myAxis; - categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] - } + HorizontalStackedBarSeries { - id: mySeries; + axisY: BarCategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } } - Component.onCompleted: { - createDefaultAxes(); - setAxisY(myAxis,mySeries); - } } //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View11.qml b/demos/qmlchart/qml/qmlchart/View11.qml index 63d1e41..fdf27ac 100644 --- a/demos/qmlchart/qml/qmlchart/View11.qml +++ b/demos/qmlchart/qml/qmlchart/View11.qml @@ -29,20 +29,13 @@ Rectangle { title: "Horizontal Percent Bar series" anchors.fill: parent legend.alignment: Qt.AlignBottom - BarCategoriesAxis { - id: myAxis - categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] - } + HorizontalPercentBarSeries { - id: mySeries + axisY: BarCategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } } - Component.onCompleted: { - createDefaultAxes(); - setAxisY(myAxis,mySeries); - } } //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View2.qml b/demos/qmlchart/qml/qmlchart/View2.qml index 22a0056..057027a 100644 --- a/demos/qmlchart/qml/qmlchart/View2.qml +++ b/demos/qmlchart/qml/qmlchart/View2.qml @@ -39,10 +39,6 @@ Rectangle { XYPoint { x: 3.4; y: 3.0 } XYPoint { x: 4.1; y: 3.3 } } - - Component.onCompleted: { - createDefaultAxes(); - } } //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View3.qml b/demos/qmlchart/qml/qmlchart/View3.qml index 68590f0..1df7b6e 100644 --- a/demos/qmlchart/qml/qmlchart/View3.qml +++ b/demos/qmlchart/qml/qmlchart/View3.qml @@ -31,7 +31,7 @@ Rectangle { SplineSeries { name: "SplineSeries" - XYPoint { x: 0; y: 0.3 } + XYPoint { x: 0; y: 0.0 } XYPoint { x: 1.1; y: 3.2 } XYPoint { x: 1.9; y: 2.4 } XYPoint { x: 2.1; y: 2.1 } @@ -39,10 +39,6 @@ Rectangle { XYPoint { x: 3.4; y: 2.3 } XYPoint { x: 4.1; y: 3.1 } } - - Component.onCompleted: { - createDefaultAxes(); - } } //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View4.qml b/demos/qmlchart/qml/qmlchart/View4.qml index e34c899..02101e5 100644 --- a/demos/qmlchart/qml/qmlchart/View4.qml +++ b/demos/qmlchart/qml/qmlchart/View4.qml @@ -29,15 +29,15 @@ Rectangle { title: "NHL All-Star Team Players" anchors.fill: parent - AreaSeries { - //TODO: obsolate - //axisX: CategoriesAxis { - // id: categoriesAxis - // categories: ["2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", - // "2008", "2009", "2010", "2011" ] - //} + BarCategoriesAxis { + id: catergoriesAxis + categories: ["2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", + "2009", "2010", "2011" ] + } + AreaSeries { name: "Russian" + axisX: catergoriesAxis upperSeries: LineSeries { XYPoint { x: 0; y: 1 } XYPoint { x: 1; y: 1 } @@ -52,27 +52,13 @@ Rectangle { XYPoint { x: 10; y: 2 } XYPoint { x: 11; y: 1 } } - lowerSeries: LineSeries { - XYPoint { x: 0; y: 0 } - XYPoint { x: 1; y: 0 } - XYPoint { x: 2; y: 0 } - XYPoint { x: 3; y: 0 } - XYPoint { x: 4; y: 0 } - XYPoint { x: 5; y: 0 } - XYPoint { x: 6; y: 0 } - XYPoint { x: 7; y: 0 } - XYPoint { x: 8; y: 0 } - XYPoint { x: 9; y: 0 } - XYPoint { x: 10; y: 0 } - XYPoint { x: 11; y: 0 } - } } // ... //![1] AreaSeries { - id: swedish name: "Swedish" + axisX: catergoriesAxis upperSeries: LineSeries { XYPoint { x: 0; y: 1 } XYPoint { x: 1; y: 1 } @@ -87,28 +73,11 @@ Rectangle { XYPoint { x: 10; y: 3 } XYPoint { x: 11; y: 3 } } - lowerSeries: LineSeries { - XYPoint { x: 0; y: 0 } - XYPoint { x: 1; y: 0 } - XYPoint { x: 2; y: 0 } - XYPoint { x: 3; y: 0 } - XYPoint { x: 4; y: 0 } - XYPoint { x: 5; y: 0 } - XYPoint { x: 6; y: 0 } - XYPoint { x: 7; y: 0 } - XYPoint { x: 8; y: 0 } - XYPoint { x: 9; y: 0 } - XYPoint { x: 10; y: 0 } - XYPoint { x: 11; y: 0 } - } - onClicked: { - color = "yellow"; - borderColor = "blue"; - } } AreaSeries { name: "Finnish" + axisX: catergoriesAxis upperSeries: LineSeries { XYPoint { x: 0; y: 0 } XYPoint { x: 1; y: 0 } @@ -123,27 +92,10 @@ Rectangle { XYPoint { x: 10; y: 0 } XYPoint { x: 11; y: 1 } } - lowerSeries: LineSeries { - XYPoint { x: 0; y: 0 } - XYPoint { x: 1; y: 0 } - XYPoint { x: 2; y: 0 } - XYPoint { x: 3; y: 0 } - XYPoint { x: 4; y: 0 } - XYPoint { x: 5; y: 0 } - XYPoint { x: 6; y: 0 } - XYPoint { x: 7; y: 0 } - XYPoint { x: 8; y: 0 } - XYPoint { x: 9; y: 0 } - XYPoint { x: 10; y: 0 } - XYPoint { x: 11; y: 0 } - } onClicked: { color = "white"; borderColor = "blue"; } } - Component.onCompleted: { - createDefaultAxes(); - } } } diff --git a/demos/qmlchart/qml/qmlchart/View5.qml b/demos/qmlchart/qml/qmlchart/View5.qml index ee438f8..c10599c 100644 --- a/demos/qmlchart/qml/qmlchart/View5.qml +++ b/demos/qmlchart/qml/qmlchart/View5.qml @@ -51,13 +51,6 @@ Rectangle { XYPoint { x: 2.2; y: 2.9 } XYPoint { x: 2.4; y: 2.7 } XYPoint { x: 2.67; y: 2.65 } - //![2] } - - Component.onCompleted: { - createDefaultAxes(); - } - } - //![2] } diff --git a/demos/qmlchart/qml/qmlchart/View6.qml b/demos/qmlchart/qml/qmlchart/View6.qml index b8c604a..b4c02b0 100644 --- a/demos/qmlchart/qml/qmlchart/View6.qml +++ b/demos/qmlchart/qml/qmlchart/View6.qml @@ -29,20 +29,14 @@ Rectangle { title: "Bar series" anchors.fill: parent legend.alignment: Qt.AlignBottom - BarCategoriesAxis { - id:myAxis - categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] - } + BarSeries { - id: mySeries + id: mySeries + axisX: BarCategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } } - Component.onCompleted: { - createDefaultAxes(); - setAxisX(myAxis,mySeries); - } } //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View7.qml b/demos/qmlchart/qml/qmlchart/View7.qml index 9f9585d..c3dc8ca 100644 --- a/demos/qmlchart/qml/qmlchart/View7.qml +++ b/demos/qmlchart/qml/qmlchart/View7.qml @@ -29,20 +29,14 @@ Rectangle { title: "Stacked Bar series" anchors.fill: parent legend.alignment: Qt.AlignBottom - BarCategoriesAxis { - id: myAxis; - categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] - } + StackedBarSeries { - id: mySeries; + id: mySeries + axisX: BarCategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } } - Component.onCompleted: { - createDefaultAxes(); - setAxisX(myAxis,mySeries); - } } //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View8.qml b/demos/qmlchart/qml/qmlchart/View8.qml index f679e06..a507208 100644 --- a/demos/qmlchart/qml/qmlchart/View8.qml +++ b/demos/qmlchart/qml/qmlchart/View8.qml @@ -29,21 +29,13 @@ Rectangle { title: "Percent Bar series" anchors.fill: parent legend.alignment: Qt.AlignBottom - BarCategoriesAxis { - id: myAxis - categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] - } + PercentBarSeries { - id: mySeries + axisX: BarCategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } } - Component.onCompleted: { - createDefaultAxes(); - setAxisX(myAxis,mySeries); - } } //![1] } - diff --git a/demos/qmlchart/qml/qmlchart/View9.qml b/demos/qmlchart/qml/qmlchart/View9.qml index 2c350b8..cf94d98 100644 --- a/demos/qmlchart/qml/qmlchart/View9.qml +++ b/demos/qmlchart/qml/qmlchart/View9.qml @@ -29,20 +29,13 @@ Rectangle { title: "Horizontal Bar series" anchors.fill: parent legend.alignment: Qt.AlignBottom - BarCategoriesAxis { - id: myAxis - categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] - } + HorizontalBarSeries { - id: mySeries + axisY: BarCategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } } - Component.onCompleted: { - createDefaultAxes(); - setAxisY(myAxis,mySeries); - } } //![1] } diff --git a/demos/qmlcustomizations/qml/qmlcustomizations/main.qml b/demos/qmlcustomizations/qml/qmlcustomizations/main.qml index 21dbc51..4d4a05c 100644 --- a/demos/qmlcustomizations/qml/qmlcustomizations/main.qml +++ b/demos/qmlcustomizations/qml/qmlcustomizations/main.qml @@ -27,7 +27,6 @@ Rectangle { property int __activeIndex: 1 property real __intervalCoefficient: 0 - //![1] ChartView { id: chartView @@ -62,7 +61,6 @@ Rectangle { interval = __intervalCoefficient * j * j; splineSeries.append(j, interval); } - chartView.createDefaultAxes() chartView.axisX(scatterSeries).max = j; chartView.axisY(scatterSeries).max = 1000; } diff --git a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml index 72a6cee..f1069eb 100644 --- a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml +++ b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml @@ -33,12 +33,14 @@ Rectangle { animationOptions: ChartView.SeriesAnimations BarCategoriesAxis { - id: categoryAxis + id: categoriesAxis categories: ["2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" ] + min: "2007" + max: "2014" } ValuesAxis { - id: yAxis + id: valuesAxis min: 0 max: 60 } @@ -63,6 +65,8 @@ Rectangle { BarSeries { id: myBarSeries name: "Others" + axisX: categoriesAxis + axisY: valuesAxis barWidth: 0.9 visible: false HBarModelMapper { @@ -78,6 +82,8 @@ Rectangle { LineSeries { id: lineSeries1 name: "Volkswagen" + axisX: categoriesAxis + axisY: valuesAxis visible: false HXYModelMapper { model: customModel @@ -91,6 +97,8 @@ Rectangle { LineSeries { id: lineSeries2 name: "Toyota" + axisX: categoriesAxis + axisY: valuesAxis visible: false HXYModelMapper { model: customModel @@ -103,6 +111,8 @@ Rectangle { LineSeries { id: lineSeries3 name: "Ford" + axisX: categoriesAxis + axisY: valuesAxis visible: false HXYModelMapper { model: customModel @@ -115,6 +125,8 @@ Rectangle { LineSeries { id: lineSeries4 name: "Skoda" + axisX: categoriesAxis + axisY: valuesAxis visible: false HXYModelMapper { model: customModel @@ -127,6 +139,8 @@ Rectangle { LineSeries { id: lineSeries5 name: "Volvo" + axisX: categoriesAxis + axisY: valuesAxis visible: false HXYModelMapper { model: customModel @@ -162,23 +176,5 @@ Rectangle { } } //![3] - - Component.onCompleted: { - setAxisX(categoryAxis,myBarSeries) - setAxisX(categoryAxis,lineSeries1) - setAxisX(categoryAxis,lineSeries2) - setAxisX(categoryAxis,lineSeries3) - setAxisX(categoryAxis,lineSeries4) - setAxisX(categoryAxis,lineSeries5) - setAxisY(yAxis,myBarSeries) - setAxisY(yAxis,lineSeries1) - setAxisY(yAxis,lineSeries2) - setAxisY(yAxis,lineSeries3) - setAxisY(yAxis,lineSeries4) - setAxisY(yAxis,lineSeries5) - categoryAxis.min = "2007" - categoryAxis.max = "2014" - categoryAxis.visible = true; - } } } diff --git a/demos/qmlf1legends/qml/qmlf1legends/main.qml b/demos/qmlf1legends/qml/qmlf1legends/main.qml index 5da557a..7bb8827 100644 --- a/demos/qmlf1legends/qml/qmlf1legends/main.qml +++ b/demos/qmlf1legends/qml/qmlf1legends/main.qml @@ -61,28 +61,26 @@ Rectangle { if (currentIndex < speedsXml.count) { // Check if there is a series for the data already (we are using driver name to identify series) var lineSeries = chartView.series(speedsXml.get(currentIndex).driver); - if (!lineSeries){ + if (!lineSeries) { lineSeries = chartView.createSeries(ChartView.SeriesTypeLine, speedsXml.get(currentIndex).driver); - chartView.createDefaultAxes(); - chartView.axisY(lineSeries).min = 0; - chartView.axisY(lineSeries).max = 250 + chartView.axisY().min = 0; + chartView.axisY().max = 250 } - lineSeries.append(currentIndex, speedsXml.get(currentIndex).speed); // Make the x-axis range dynamic if (currentIndex > 9) - chartView.axisX(lineSeries).min = currentIndex - 10; + chartView.axisX().min = currentIndex - 10; else - chartView.axisX(lineSeries).min = 0; + chartView.axisX().min = 0; - chartView.axisX(lineSeries).max = currentIndex + 1; + chartView.axisX().max = currentIndex + 1; } else { // No more data, change x-axis range to show all the data timer.stop(); chartView.animationOptions = ChartView.AllAnimations; - chartView.axisX(lineSeries).min = 0; - chartView.axisX(lineSeries).max = currentIndex + 1; + chartView.axisX().min = 0; + chartView.axisX().max = currentIndex + 1; } } } diff --git a/demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml b/demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml index a84708f..cc7b3c6 100644 --- a/demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml +++ b/demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml @@ -40,17 +40,14 @@ ChartView { LineSeries { id: lineSeries1 name: "signal 1" + axisX: axisX + axisY: axisY } LineSeries { id: lineSeries2 name: "signal 2" - } - - Component.onCompleted: { - chartView.setAxisX(axisX, lineSeries1); - chartView.setAxisY(axisY, lineSeries1); - chartView.setAxisX(axisX, lineSeries2); - chartView.setAxisY(axisY, lineSeries2); + axisX: axisX + axisY: axisY } Timer { @@ -79,8 +76,8 @@ ChartView { series.markerSize = 3; series.borderColor = "transparent"; } - chartView.setAxisX(axisX, series); - chartView.setAxisY(axisY, series); +// chartView.setAxisX(axisX, series); +// chartView.setAxisY(axisY, series); } } @@ -92,7 +89,6 @@ ChartView { } function changeRefreshRate(rate) { - console.log("rate " + rate); refreshTimer.interval = 1 / Number(rate) * 1000; } } diff --git a/demos/qmlweather/qml/qmlweather/main.qml b/demos/qmlweather/qml/qmlweather/main.qml index adba41c..93ab3e1 100644 --- a/demos/qmlweather/qml/qmlweather/main.qml +++ b/demos/qmlweather/qml/qmlweather/main.qml @@ -38,43 +38,45 @@ Rectangle { //![2] BarCategoriesAxis { - id: myBarCategoryAxis - categories: ["Mo", "Tu", "We", "Th", "Fr"] + id: barCategoriesAxis } BarSeries { id: myBarSeries + axisX: barCategoriesAxis + axisY: valuesAxisY BarSet { id: rainfallSet label: "Rainfall" } } + ValuesAxis { + id: valuesAxisX + min: 0 + max: 5 + } + ValuesAxis{ - id: myValuesAxisY + id: valuesAxisY min: 0 max: 10 } LineSeries { id: maxTempSeries + axisX: valuesAxisX + axisY: valuesAxisY name: "Max. temperature" } LineSeries { id: minTempSeries + axisX: valuesAxisX + axisY: valuesAxisY 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 @@ -100,7 +102,7 @@ Rectangle { xhr.send(); //![3] } else { - // No app key for worldweatheronline.com given by the user -> use static data + // No app key for worldweatheronline.com given by the user -> use dummy static data var responseText = "{ \"data\": { \"current_condition\": [ {\"cloudcover\": \"10\", \"humidity\": \"61\", \"observation_time\": \"06:26 AM\", \"precipMM\": \"0.0\", \"pressure\": \"1022\", \"temp_C\": \"6\", \"temp_F\": \"43\", \"visibility\": \"10\", \"weatherCode\": \"113\", \"weatherDesc\": [ {\"value\": \"Sunny\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png\" } ], \"winddir16Point\": \"SE\", \"winddirDegree\": \"140\", \"windspeedKmph\": \"7\", \"windspeedMiles\": \"4\" } ], \"request\": [ {\"query\": \"Jyvaskyla, Finland\", \"type\": \"City\" } ], \"weather\": [ {\"date\": \"2012-05-09\", \"precipMM\": \"0.4\", \"tempMaxC\": \"14\", \"tempMaxF\": \"57\", \"tempMinC\": \"7\", \"tempMinF\": \"45\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"S\", \"winddirDegree\": \"179\", \"winddirection\": \"S\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-10\", \"precipMM\": \"2.4\", \"tempMaxC\": \"13\", \"tempMaxF\": \"55\", \"tempMinC\": \"8\", \"tempMinF\": \"46\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SW\", \"winddirDegree\": \"219\", \"winddirection\": \"SW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" }, {\"date\": \"2012-05-11\", \"precipMM\": \"11.1\", \"tempMaxC\": \"15\", \"tempMaxF\": \"59\", \"tempMinC\": \"7\", \"tempMinF\": \"44\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SSW\", \"winddirDegree\": \"200\", \"winddirection\": \"SSW\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-12\", \"precipMM\": \"2.8\", \"tempMaxC\": \"7\", \"tempMaxF\": \"44\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"317\", \"weatherDesc\": [ {\"value\": \"Light sleet\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0021_cloudy_with_sleet.png\" } ], \"winddir16Point\": \"NW\", \"winddirDegree\": \"311\", \"winddirection\": \"NW\", \"windspeedKmph\": \"24\", \"windspeedMiles\": \"15\" }, {\"date\": \"2012-05-13\", \"precipMM\": \"0.4\", \"tempMaxC\": \"6\", \"tempMaxF\": \"42\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"WNW\", \"winddirDegree\": \"281\", \"winddirection\": \"WNW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" } ] }}"; var a = JSON.parse(responseText); parseWeatherData(a); @@ -156,26 +158,25 @@ Rectangle { //![5] // Store temperature values, rainfall and weather icon - maxTempSeries.append(i, weatherObj.tempMaxC); - minTempSeries.append(i, weatherObj.tempMinC); + maxTempSeries.append(Number(i) + 0.5, weatherObj.tempMaxC); + minTempSeries.append(Number(i) + 0.5, weatherObj.tempMinC); rainfallSet.append(i, weatherObj.precipMM); weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value}); //![5] // Update scale of the chart - 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; + valuesAxisY.max = Math.max(chartView.axisY().max,weatherObj.tempMaxC); + valuesAxisX.min = 0; + valuesAxisX.max = Number(i) + 1; // Set the x-axis labels to the dates of the forecast - var xLabels = myBarCategoryAxis.categories; + var xLabels = barCategoriesAxis.categories; xLabels[Number(i)] = weatherObj.date.substring(5, 10); - myBarCategoryAxis.categories = xLabels; - myBarCategoryAxis.visible = true; + barCategoriesAxis.categories = xLabels; + barCategoriesAxis.visible = true; + barCategoriesAxis.min = 0; + barCategoriesAxis.max = xLabels.length - 1; } - - } } diff --git a/plugins/declarative/declarative.pro b/plugins/declarative/declarative.pro index d3fa59f..b0f9577 100644 --- a/plugins/declarative/declarative.pro +++ b/plugins/declarative/declarative.pro @@ -4,6 +4,7 @@ QT += declarative !include( ../plugins.pri ) { error( "Couldn't find the plugins.pri file!" ) } +INCLUDEPATH += $$CHART_BUILD_PRIVATE_HEADER_DIR contains(QT_MAJOR_VERSION, 5) { # TODO: QtQuick2 not supported by the implementation currently diff --git a/plugins/declarative/declarativeareaseries.cpp b/plugins/declarative/declarativeareaseries.cpp index a621d5f..c9cd855 100644 --- a/plugins/declarative/declarativeareaseries.cpp +++ b/plugins/declarative/declarativeareaseries.cpp @@ -23,11 +23,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : - QAreaSeries(parent) + QAreaSeries(parent), + m_axisX(0), + m_axisY(0) { } - void DeclarativeAreaSeries::setUpperSeries(DeclarativeLineSeries* series) { QAreaSeries::setUpperSeries(series); diff --git a/plugins/declarative/declarativeareaseries.h b/plugins/declarative/declarativeareaseries.h index 659a8ff..0bf359b 100644 --- a/plugins/declarative/declarativeareaseries.h +++ b/plugins/declarative/declarativeareaseries.h @@ -31,6 +31,8 @@ class DeclarativeAreaSeries : public QAreaSeries Q_OBJECT Q_PROPERTY(DeclarativeLineSeries *upperSeries READ upperSeries WRITE setUpperSeries) Q_PROPERTY(DeclarativeLineSeries *lowerSeries READ lowerSeries WRITE setLowerSeries) + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) public: explicit DeclarativeAreaSeries(QObject *parent = 0); @@ -38,6 +40,18 @@ public: DeclarativeLineSeries* upperSeries() const; void setLowerSeries(DeclarativeLineSeries* series); DeclarativeLineSeries* lowerSeries() const; + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + +Q_SIGNALS: + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); + +private: + QAbstractAxis *m_axisX; + QAbstractAxis *m_axisY; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index 897d0bd..47ea227 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -60,7 +60,9 @@ void DeclarativeBarSet::setValues(QVariantList values) // Declarative bar series ====================================================================================== DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : - QBarSeries(parent) + QBarSeries(parent), + m_axisX(0), + m_axisY(0) { } @@ -117,7 +119,9 @@ DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVaria // Declarative stacked bar series ============================================================================== DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : - QStackedBarSeries(parent) + QStackedBarSeries(parent), + m_axisX(0), + m_axisY(0) { } @@ -175,7 +179,9 @@ DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, // Declarative percent bar series ============================================================================== DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : - QPercentBarSeries(parent) + QPercentBarSeries(parent), + m_axisX(0), + m_axisY(0) { } @@ -232,7 +238,9 @@ DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, // Declarative horizontal bar series =========================================================================== DeclarativeHorizontalBarSeries::DeclarativeHorizontalBarSeries(QDeclarativeItem *parent) : - QHorizontalBarSeries(parent) + QHorizontalBarSeries(parent), + m_axisX(0), + m_axisY(0) { } @@ -289,7 +297,9 @@ DeclarativeBarSet *DeclarativeHorizontalBarSeries::insert(int index, QString lab // Declarative horizontal stacked bar series =================================================================== DeclarativeHorizontalStackedBarSeries::DeclarativeHorizontalStackedBarSeries(QDeclarativeItem *parent) : - QHorizontalStackedBarSeries(parent) + QHorizontalStackedBarSeries(parent), + m_axisX(0), + m_axisY(0) { } @@ -346,7 +356,9 @@ DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::insert(int index, QStr // Declarative horizontal percent bar series =================================================================== DeclarativeHorizontalPercentBarSeries::DeclarativeHorizontalPercentBarSeries(QDeclarativeItem *parent) : - QHorizontalPercentBarSeries(parent) + QHorizontalPercentBarSeries(parent), + m_axisX(0), + m_axisY(0) { } diff --git a/plugins/declarative/declarativebarseries.h b/plugins/declarative/declarativebarseries.h index 03fb584..5185930 100644 --- a/plugins/declarative/declarativebarseries.h +++ b/plugins/declarative/declarativebarseries.h @@ -63,12 +63,20 @@ class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } QDeclarativeListProperty seriesChildren(); + +public: Q_INVOKABLE DeclarativeBarSet *at(int index); Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); @@ -79,6 +87,10 @@ public: // from QDeclarativeParserStatus void classBegin(); void componentComplete(); +Q_SIGNALS: + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); + public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); @@ -91,12 +103,20 @@ class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativ { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0); + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } QDeclarativeListProperty seriesChildren(); + +public: Q_INVOKABLE DeclarativeBarSet *at(int index); Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); @@ -107,21 +127,36 @@ public: // from QDeclarativeParserStatus void classBegin(); void componentComplete(); +Q_SIGNALS: + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); + public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); +private: + QAbstractAxis* m_axisX; + QAbstractAxis* m_axisY; }; class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0); + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } QDeclarativeListProperty seriesChildren(); + +public: Q_INVOKABLE DeclarativeBarSet *at(int index); Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); @@ -132,20 +167,36 @@ public: // from QDeclarativeParserStatus void classBegin(); void componentComplete(); +Q_SIGNALS: + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); + public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); + +private: + QAbstractAxis* m_axisX; + QAbstractAxis* m_axisY; }; class DeclarativeHorizontalBarSeries : public QHorizontalBarSeries, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeHorizontalBarSeries(QDeclarativeItem *parent = 0); + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } QDeclarativeListProperty seriesChildren(); + +public: Q_INVOKABLE DeclarativeBarSet *at(int index); Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); @@ -156,20 +207,36 @@ public: // from QDeclarativeParserStatus void classBegin(); void componentComplete(); +Q_SIGNALS: + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); + public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); + +private: + QAbstractAxis* m_axisX; + QAbstractAxis* m_axisY; }; class DeclarativeHorizontalStackedBarSeries : public QHorizontalStackedBarSeries, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeHorizontalStackedBarSeries(QDeclarativeItem *parent = 0); + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } QDeclarativeListProperty seriesChildren(); + +public: Q_INVOKABLE DeclarativeBarSet *at(int index); Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); @@ -180,20 +247,36 @@ public: // from QDeclarativeParserStatus void classBegin(); void componentComplete(); +Q_SIGNALS: + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); + public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); + +private: + QAbstractAxis* m_axisX; + QAbstractAxis* m_axisY; }; class DeclarativeHorizontalPercentBarSeries : public QHorizontalPercentBarSeries, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeHorizontalPercentBarSeries(QDeclarativeItem *parent = 0); + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } QDeclarativeListProperty seriesChildren(); + +public: Q_INVOKABLE DeclarativeBarSet *at(int index); Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); @@ -204,8 +287,16 @@ public: // from QDeclarativeParserStatus void classBegin(); void componentComplete(); +Q_SIGNALS: + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); + public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); + +private: + QAbstractAxis* m_axisX; + QAbstractAxis* m_axisY; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index 10787a5..877c8ac 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -20,6 +20,7 @@ #include "declarativechart.h" #include +#include #include "declarativelineseries.h" #include "declarativeareaseries.h" #include "declarativebarseries.h" @@ -27,6 +28,10 @@ #include "declarativesplineseries.h" #include "declarativescatterseries.h" #include "qbarcategoryaxis.h" +#include "qvalueaxis.h" +#include "qdatetimeaxis.h" +#include "qintervalsaxis.h" +#include "qabstractseries_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -165,25 +170,25 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! \qmlmethod ChartView::scrollLeft(real pixels) Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. - \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max + \sa ValueAxis::min, ValueAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max */ /*! \qmlmethod ChartView::scrollRight(real pixels) Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. - \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max + \sa ValueAxis::min, ValueAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max */ /*! \qmlmethod ChartView::scrollUp(real pixels) Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. - \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max + \sa ValueAxis::min, ValueAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max */ /*! \qmlmethod ChartView::scrollDown(real pixels) Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. - \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max + \sa ValueAxis::min, ValueAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max */ /*! @@ -252,16 +257,96 @@ void DeclarativeChart::componentComplete() { foreach(QObject *child, children()) { if (qobject_cast(child)) { -// qDebug() << "DeclarativeChart::componentComplete(), add: " << child; - // TODO: how about optional y-axis? m_chart->addSeries(qobject_cast(child)); - }else if(qobject_cast(child)){ - + if (qobject_cast(child)) { + DeclarativeLineSeries *s = qobject_cast(child); + connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); + connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); + setAxisX(s->axisX(), s); + setAxisY(s->axisY(), s); + } else if (qobject_cast(child)) { + DeclarativeSplineSeries *s = qobject_cast(child); + connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); + connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); + setAxisX(s->axisX(), s); + setAxisY(s->axisY(), s); + } else if (qobject_cast(child)) { + DeclarativeScatterSeries *s = qobject_cast(child); + connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); + connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); + setAxisX(s->axisX(), s); + setAxisY(s->axisY(), s); + } else if (qobject_cast(child)) { + DeclarativeAreaSeries *s = qobject_cast(child); + connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); + connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); + setAxisX(s->axisX(), s); + setAxisY(s->axisY(), s); + } else if (qobject_cast(child)) { + DeclarativeBarSeries *s = qobject_cast(child); + connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); + connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); + setAxisX(s->axisX(), s); + setAxisY(s->axisY(), s); + } else if (qobject_cast(child)) { + DeclarativeStackedBarSeries *s = qobject_cast(child); + connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); + connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); + setAxisX(s->axisX(), s); + setAxisY(s->axisY(), s); + } else if (qobject_cast(child)) { + DeclarativePercentBarSeries *s = qobject_cast(child); + connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); + connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); + setAxisX(s->axisX(), s); + setAxisY(s->axisY(), s); + } else if (qobject_cast(child)) { + DeclarativeHorizontalBarSeries *s = qobject_cast(child); + connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); + connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); + setAxisX(s->axisX(), s); + setAxisY(s->axisY(), s); + } else if (qobject_cast(child)) { + DeclarativeHorizontalStackedBarSeries *s = qobject_cast(child); + connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); + connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); + setAxisX(s->axisX(), s); + setAxisY(s->axisY(), s); + } else if (qobject_cast(child)) { + DeclarativeHorizontalPercentBarSeries *s = qobject_cast(child); + connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *))); + connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *))); + setAxisX(s->axisX(), s); + setAxisY(s->axisY(), s); + } + } else if(qobject_cast(child)) { + // Do nothing, axes are set for the chart in the context of series } } + + // Create the missing axes for the series that cannot be painted without axes + foreach(QAbstractSeries *series, m_chart->series()) + createDefaultAxes(series); + QDeclarativeItem::componentComplete(); } +void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis) +{ +// qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; + if (axis && qobject_cast(sender())) { + m_chart->setAxisX(axis, qobject_cast(sender())); + } +} + +void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis) +{ +// qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; + if (axis && qobject_cast(sender())) { + m_chart->setAxisY(axis, qobject_cast(sender())); + } +} + void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); @@ -462,6 +547,7 @@ QAbstractSeries *DeclarativeChart::series(QString seriesName) QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) { QAbstractSeries *series = 0; + switch (type) { case DeclarativeChart::SeriesTypeLine: series = new DeclarativeLineSeries(); @@ -499,24 +585,90 @@ QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType typ default: qWarning() << "Illegal series type"; } - series->setName(name); - m_chart->addSeries(series); + + if (series) { + series->setName(name); + m_chart->addSeries(series); + createDefaultAxes(series); + } + return series; } -void DeclarativeChart::setAxisX(QAbstractAxis* axis, QAbstractSeries *series) +void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) { - m_chart->setAxisX(axis,series); + if (axis) + m_chart->setAxisX(axis, series); } -void DeclarativeChart::setAxisY(QAbstractAxis* axis, QAbstractSeries *series) +void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) { - m_chart->setAxisY(axis,series); + if (axis) + m_chart->setAxisY(axis, series); } void DeclarativeChart::createDefaultAxes() { - m_chart->createDefaultAxes(); + qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; +} + +void DeclarativeChart::createDefaultAxes(QAbstractSeries* series) +{ + foreach (QAbstractSeries *s, m_chart->series()) { + // If there is already an x axis of the correct type, re-use it + if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) + && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) + m_chart->setAxisX(m_chart->axisX(s), series); + + // If there is already a y axis of the correct type, re-use it + if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) + && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) + m_chart->setAxisY(m_chart->axisY(s), series); + } + + // If no x axis of correct type was found, create a new x axis based of default axis type + if (!m_chart->axisX(series)) { + switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { + case QAbstractAxis::AxisTypeValues: + m_chart->setAxisX(new QValueAxis(this), series); + break; + case QAbstractAxis::AxisTypeCategories: + m_chart->setAxisX(new QBarCategoryAxis(this), series); + break; + case QAbstractAxis::AxisTypeIntervals: + m_chart->setAxisX(new QIntervalsAxis(this), series); + break; + case QAbstractAxis::AxisTypeDateTime: + m_chart->setAxisX(new QDateTimeAxis(this), series); + break; + default: + // Do nothing, assume AxisTypeNoAxis + break; + } + } + + // If no y axis of correct type was found, create a new y axis based of default axis type + if (!m_chart->axisY(series)) { + switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { + case QAbstractAxis::AxisTypeValues: + m_chart->setAxisY(new QValueAxis(this), series); + break; + case QAbstractAxis::AxisTypeCategories: + m_chart->setAxisY(new QBarCategoryAxis(this), series); + break; + case QAbstractAxis::AxisTypeIntervals: + m_chart->setAxisY(new QIntervalsAxis(this), series); + break; + case QAbstractAxis::AxisTypeDateTime: + m_chart->setAxisY(new QDateTimeAxis(this), series); + break; + default: + // Do nothing, assume AxisTypeNoAxis + break; + } + } + + //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); } #include "moc_declarativechart.cpp" diff --git a/plugins/declarative/declarativechart.h b/plugins/declarative/declarativechart.h index 4af7a57..28c42ad 100644 --- a/plugins/declarative/declarativechart.h +++ b/plugins/declarative/declarativechart.h @@ -27,7 +27,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -// TODO: Derive from QChart for easier definition of properties? class DeclarativeChart : public QDeclarativeItem // TODO: for QTQUICK2: extend QQuickPainterItem instead //class DeclarativeChart : public QQuickPaintedItem, public Chart @@ -49,6 +48,7 @@ class DeclarativeChart : public QDeclarativeItem Q_ENUMS(Animation) Q_ENUMS(Theme) Q_ENUMS(SeriesType) +// Q_ENUMS(AxisType) public: // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api @@ -114,15 +114,14 @@ public: qreal bottomMargin(); qreal leftMargin(); qreal rightMargin(); - - + void createDefaultAxes(QAbstractSeries* series); public: Q_INVOKABLE QAbstractSeries *series(int index); Q_INVOKABLE QAbstractSeries *series(QString seriesName); Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); - Q_INVOKABLE void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0); - Q_INVOKABLE void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0); + 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); @@ -145,6 +144,8 @@ Q_SIGNALS: public Q_SLOTS: void handleMarginsChanged(QRectF newMargins); + void handleAxisXSet(QAbstractAxis *axis); + void handleAxisYSet(QAbstractAxis *axis); private: // Extending QChart with DeclarativeChart is not possible because QObject does not support diff --git a/plugins/declarative/declarativelineseries.cpp b/plugins/declarative/declarativelineseries.cpp index 6a9a8e2..cfca1f0 100644 --- a/plugins/declarative/declarativelineseries.cpp +++ b/plugins/declarative/declarativelineseries.cpp @@ -23,17 +23,14 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : - QLineSeries(parent) + QLineSeries(parent), + m_axisX(0), + m_axisY(0) { connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int))); } -QXYSeries *DeclarativeLineSeries::xySeries() -{ - return this; -} - void DeclarativeLineSeries::handleCountChanged(int index) { Q_UNUSED(index) diff --git a/plugins/declarative/declarativelineseries.h b/plugins/declarative/declarativelineseries.h index a46fc0c..baed87a 100644 --- a/plugins/declarative/declarativelineseries.h +++ b/plugins/declarative/declarativelineseries.h @@ -33,12 +33,18 @@ class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries, pu Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) Q_CLASSINFO("DefaultProperty", "declarativeChildren") public: explicit DeclarativeLineSeries(QObject *parent = 0); - QXYSeries *xySeries(); + QXYSeries *xySeries() { return this; } + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } QDeclarativeListProperty declarativeChildren(); public: // from QDeclarativeParserStatus @@ -55,10 +61,16 @@ public: Q_SIGNALS: void countChanged(int count); + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); public Q_SLOTS: static void appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element); void handleCountChanged(int index); + +private: + QAbstractAxis *m_axisX; + QAbstractAxis *m_axisY; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativescatterseries.cpp b/plugins/declarative/declarativescatterseries.cpp index c362777..c8ed47d 100644 --- a/plugins/declarative/declarativescatterseries.cpp +++ b/plugins/declarative/declarativescatterseries.cpp @@ -23,17 +23,14 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) : - QScatterSeries(parent) + QScatterSeries(parent), + m_axisX(0), + m_axisY(0) { connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int))); } -QXYSeries *DeclarativeScatterSeries::xySeries() -{ - return this; -} - void DeclarativeScatterSeries::handleCountChanged(int index) { Q_UNUSED(index) diff --git a/plugins/declarative/declarativescatterseries.h b/plugins/declarative/declarativescatterseries.h index 2d3a0c2..f002539 100644 --- a/plugins/declarative/declarativescatterseries.h +++ b/plugins/declarative/declarativescatterseries.h @@ -33,12 +33,18 @@ class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeri Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) Q_CLASSINFO("DefaultProperty", "declarativeChildren") public: explicit DeclarativeScatterSeries(QObject *parent = 0); - QXYSeries *xySeries(); + QXYSeries *xySeries() { return this; } + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } QDeclarativeListProperty declarativeChildren(); public: // from QDeclarativeParserStatus @@ -55,10 +61,16 @@ public: Q_SIGNALS: void countChanged(int count); + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); public Q_SLOTS: static void appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element); void handleCountChanged(int index); + +private: + QAbstractAxis *m_axisX; + QAbstractAxis *m_axisY; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativesplineseries.cpp b/plugins/declarative/declarativesplineseries.cpp index 53f4a03..8ff8834 100644 --- a/plugins/declarative/declarativesplineseries.cpp +++ b/plugins/declarative/declarativesplineseries.cpp @@ -23,17 +23,14 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : - QSplineSeries(parent) + QSplineSeries(parent), + m_axisX(0), + m_axisY(0) { connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int))); } -QXYSeries *DeclarativeSplineSeries::xySeries() -{ - return this; -} - void DeclarativeSplineSeries::handleCountChanged(int index) { Q_UNUSED(index) diff --git a/plugins/declarative/declarativesplineseries.h b/plugins/declarative/declarativesplineseries.h index 1c278d7..4f5f545 100644 --- a/plugins/declarative/declarativesplineseries.h +++ b/plugins/declarative/declarativesplineseries.h @@ -33,12 +33,18 @@ class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) Q_CLASSINFO("DefaultProperty", "declarativeChildren") public: explicit DeclarativeSplineSeries(QObject *parent = 0); - QXYSeries *xySeries(); + QXYSeries *xySeries() { return this; } + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } QDeclarativeListProperty declarativeChildren(); public: // from QDeclarativeParserStatus @@ -55,10 +61,16 @@ public: Q_SIGNALS: void countChanged(int count); + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); public Q_SLOTS: static void appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element); void handleCountChanged(int index); + +public: + QAbstractAxis *m_axisX; + QAbstractAxis *m_axisY; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index dedf835..20ef0f7 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -91,7 +91,7 @@ public: qmlRegisterUncreatableType(uri, 1, 0, "AbstractBarSeries", QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); qmlRegisterUncreatableType(uri, 1, 0, "AbstractAxis", - QLatin1String("Trying to create uncreatable: AbstractAxis.")); + QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); } }; diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 1ec61ff..12b7f1d 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -116,12 +116,13 @@ void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) void ChartDataSet::createDefaultAxes() { - - if(m_seriesDomainMap.isEmpty()) return; + if (m_seriesDomainMap.isEmpty()) + return; QAbstractAxis::AxisTypes typeX(0); QAbstractAxis::AxisTypes typeY(0); + // Remove possibly existing axes QMapIterator i(m_seriesDomainMap); while (i.hasNext()) { i.next(); @@ -130,8 +131,10 @@ void ChartDataSet::createDefaultAxes() i.toFront(); + // Select the required axis x and axis y types based on the types of the current series while (i.hasNext()) { i.next(); + QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); if(axisX) typeX&=axisX->type(); @@ -140,27 +143,27 @@ void ChartDataSet::createDefaultAxes() else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); } - createAxes(typeX,Qt::Horizontal); - createAxes(typeY,Qt::Vertical); + // Create the axes of the types selected + createAxes(typeX, Qt::Horizontal); + createAxes(typeY, Qt::Vertical); } -void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation) +void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) { QMapIterator i(m_seriesDomainMap); - if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) - { + // TODO: Add a descriptive comment of what happens here + if (type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) { while (i.hasNext()) { i.next(); - QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation); - if(!axis) continue; - initializeAxis(axis,i.key()); - emit axisAdded(axis,i.value()); + QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation), orientation); + if (axis) { + initializeAxis(axis, i.key()); + emit axisAdded(axis, i.value()); + } } - - } - else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { - QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation); + } else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { + QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)), orientation); i.toFront(); while (i.hasNext()) { i.next(); @@ -170,10 +173,9 @@ void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orie } } - -QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation) +QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation) { - QAbstractAxis* axis =0; + QAbstractAxis* axis = 0; switch(type) { case QAbstractAxis::AxisTypeValues: @@ -433,6 +435,11 @@ void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Ori seriesAxisMap= &m_seriesAxisXMap; } + if (seriesAxisMap->value(series) == axis) { + qWarning() << "The axis already set for the series"; + return; + } + QAbstractAxis *oldAxis = seriesAxisMap->take(series); QList axes = seriesAxisMap->values(); if(oldAxis) { diff --git a/src/qabstractseries.h b/src/qabstractseries.h index 1bb0cc5..734fe30 100644 --- a/src/qabstractseries.h +++ b/src/qabstractseries.h @@ -79,6 +79,7 @@ protected: friend class ChartDataSet; friend class ChartPresenter; friend class QLegendPrivate; + friend class DeclarativeChart; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/scatterchart/qscatterseries.cpp b/src/scatterchart/qscatterseries.cpp index 7a056ac..9d1469f 100644 --- a/src/scatterchart/qscatterseries.cpp +++ b/src/scatterchart/qscatterseries.cpp @@ -50,7 +50,6 @@ The following QML shows how to create a chart with two simple scatter series: \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1 - \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 2 \beginfloatleft \image demos_qmlchart5.png diff --git a/tests/qmlchartaxis/main.cpp b/tests/qmlchartaxis/main.cpp new file mode 100644 index 0000000..da1873a --- /dev/null +++ b/tests/qmlchartaxis/main.cpp @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "qmlapplicationviewer.h" + +Q_DECL_EXPORT int main(int argc, char *argv[]) +{ + QScopedPointer app(createApplication(argc, argv)); + QScopedPointer viewer(QmlApplicationViewer::create()); + + viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); + viewer->setSource(QUrl("qrc:/qml/qmlchartaxis/main.qml")); + viewer->showExpanded(); + + return app->exec(); +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Button.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Button.qml new file mode 100644 index 0000000..9186740 --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Button.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 + +Rectangle { + id: button + height: 25 + width: 140 + color: unpressedColor + radius: 5 + property color unpressedColor: "#afafaf" + + property string text: "button" + signal clicked + + Text { + id: buttonText + anchors.centerIn: parent + text: button.text + } + + MouseArea { + anchors.fill: parent + onClicked: { + button.clicked(); + } + onPressedChanged: { + if (pressed) { + button.color = "#efefef"; + } else { + button.color = unpressedColor; + } + } + onPressAndHold: { + repeatTimer.start(); + } + onReleased: { + repeatTimer.stop(); + } + } + + Timer { + id: repeatTimer + interval: 140 + repeat: true + triggeredOnStart: false + running: false + onTriggered: { + button.clicked(); + } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart.qml new file mode 100644 index 0000000..82109ed --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart.qml @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + id: chartView + title: "Chart Title" + anchors.fill: parent + property variant series: chartView + + LineSeries { + name: "line" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } + + onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); + onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); + onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); + onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); + onTopMarginChanged: { + console.log("chart.onTopMarginChanged: " + margin); + marginVisualizer.opacity = 1.0; + } + onBottomMarginChanged: { + console.log("chart.onBottomMarginChanged: " + margin); + marginVisualizer.opacity = 1.0; + } + onLeftMarginChanged: { + console.log("chart.onLeftMarginChanged: " + margin); + marginVisualizer.opacity = 1.0; + } + onRightMarginChanged: { + console.log("chart.onRightMarginChanged: " + margin); + marginVisualizer.opacity = 1.0; + } + + legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); + legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); + legend.onColorChanged: console.log("legend.onColorChanged: " + color); + legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); + legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color); + + + ValuesAxis{ + onColorChanged: console.log("axisX.onColorChanged: " + color); + onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible); + onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color); + onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible); + onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible); + onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible); + onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color); + onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color); + onMinChanged: console.log("axisX.onMinChanged: " + min); + onMaxChanged: console.log("axisX.onMaxChanged: " + max); + } + + ValuesAxis{ + onColorChanged: console.log("axisY.onColorChanged: " + color); + onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible); + onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color); + onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible); + onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible); + onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible); + onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color); + onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); + onMinChanged: console.log("axisY.onMinChanged: " + min); + onMaxChanged: console.log("axisY.onMaxChanged: " + max); + } + + Rectangle { + id: marginVisualizer + color: "transparent" + border.color: "red" + anchors.fill: parent + anchors.topMargin: parent.topMargin + anchors.bottomMargin: parent.bottomMargin + anchors.leftMargin: parent.leftMargin + anchors.rightMargin: parent.rightMargin + opacity: 0.0 + onOpacityChanged: if (opacity > 0.9) opacity = 0.0; + Behavior on opacity { + NumberAnimation { duration: 800 } + } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart0.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart0.qml new file mode 100644 index 0000000..35ef313 --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart0.qml @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + id: chartView + title: "default axes" + + LineSeries { + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } + + ScatterSeries { + name: "scatter series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart1.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart1.qml new file mode 100644 index 0000000..03266a2 --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart1.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + title: "user defined axes" + + ValuesAxis { + id: axisX + min: 0 + max: 10 + } + + ValuesAxis { + id: axisY + min: 0 + max: 6 + } + + LineSeries { + name: "line series" + axisX: axisX + axisY: axisY + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } + + ScatterSeries { + name: "scatter series" + axisX: axisX + axisY: axisY + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart2.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart2.qml new file mode 100644 index 0000000..4fa43e6 --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart2.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + id: chartView + title: "user defined axes" + + ValuesAxis { + id: axisX + min: 0 + max: 10 + // TODO: property to fix orientation to "X" to make this the X default axis for all series + // that don't have user defined X axis + } + + ValuesAxis { + id: axisY + min: 0 + max: 5 + // TODO: property to fix orientation to "Y" to make this the Y default axis for all series + // that don't have user defined Y axis + } + + LineSeries { + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } + + ScatterSeries { + name: "scatter series" + id: scatter + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } + + Component.onCompleted: { + // You can also set the axes dynamically + chartView.setAxisX(axisX, scatter); + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart3.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart3.qml new file mode 100644 index 0000000..4145d6a --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart3.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + title: "configuring dynamically" + id: chartView + property int index: 0 + + Timer { + interval: 1000 + repeat: true + running: true + onTriggered: { + switch (index) { + case 0: + chartView.axisX(lineSeries).max = 5; + chartView.axisY(lineSeries).max = 5; + break; + case 1: + chartView.axisX(scatterSeries).max = 10; + chartView.axisY(scatterSeries).max = 10; + break; + default: + chartView.axisX().max = 15; + chartView.axisY().max = 15; + } + index = (index + 1) % 3; + } + } + + LineSeries { + id: lineSeries + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } + + ScatterSeries { + id: scatterSeries + name: "scatter series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart4.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart4.qml new file mode 100644 index 0000000..bff025c --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart4.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + title: "series specific dynamic axes" + id: chartView + property int index: 0 + + Timer { + interval: 1000 + repeat: true + running: true + onTriggered: { + switch (index) { + case 0: + lineAxisX.max = 5; + lineAxisY.max = 5; + scatterAxisX.max = 10; + scatterAxisY.max = 10; + break; + case 1: + lineAxisX.max = 10; + lineAxisY.max = 10; + scatterAxisX.max = 5; + scatterAxisY.max = 5; + break; + default: + chartView.axisX().max = 2; + chartView.axisY().max = 2; + } + index = (index + 1) % 3; + } + } + + LineSeries { + id: lineSeries + name: "line series" + axisX: ValuesAxis { id: lineAxisX } + axisY: ValuesAxis { id: lineAxisY } + + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } + + ScatterSeries { + id: scatterSeries + name: "scatter series" + axisX: ValuesAxis { id: scatterAxisX } + axisY: ValuesAxis { id: scatterAxisY } + + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart5.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart5.qml new file mode 100644 index 0000000..3735dc2 --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart5.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + id: chartView + title: "dynamically created series" + property int index: 0 + + Timer { + interval: 1000 + repeat: true + running: true + onTriggered: { + switch (index) { + case 0: + while (chartView.count) + chartView.series(0).destroy(); + var line = chartView.createSeries(ChartView.SeriesTypeLine, "line"); + line.append(0, 0); + line.append(1.1, 2.1); + line.append(1.9, 3.3); + line.append(2.1, 2.1); + line.append(2.9, 4.9); + line.append(3.4, 3.0); + line.append(4.1, 3.3); + break; + case 1: + chartView.axisX().min = 0; + chartView.axisX().max = 4.5; + chartView.axisY().min = 0; + chartView.axisY().max = 4.5; + break; + default: + var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter"); + scatter.append(0, 0); + scatter.append(1.1, 2.1); + scatter.append(1.9, 3.3); + scatter.append(2.1, 2.1); + scatter.append(2.9, 4.9); + scatter.append(3.4, 3.0); + scatter.append(4.1, 3.3); + } + index = (index + 1) % 3; + } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart6.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart6.qml new file mode 100644 index 0000000..c4eed18 --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart6.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + id: chartView + title: "switching axes dynamically" + + Timer { + interval: 1000 + repeat: true + running: true + onTriggered: { + if (lineSeries.axisX == valuesAxis1) + lineSeries.axisX = valuesAxis2; + else + lineSeries.axisX = valuesAxis1; + } + } + + ValuesAxis { + id: valuesAxis1 + min: 0 + max: 5 + } + + ValuesAxis { + id: valuesAxis2 + min: 1 + max: 6 + } + + LineSeries { + id: lineSeries + name: "line series" + axisX: valuesAxis1 + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart7.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart7.qml new file mode 100644 index 0000000..5582048 --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart7.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + id: chartView + title: "axis scale; different series" + + LineSeries { + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + } + + ScatterSeries { + name: "scatter series" + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart8.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart8.qml new file mode 100644 index 0000000..9e2950d --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart8.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + id: chartView + title: "Deprecated code" + property int index: 0 + + Component.onCompleted: { + // Calling createDefaultAxes in onCompleted is now deprecated. It needs to be tested, + // though, because some application may still use it + chartView.createDefaultAxes(); + } + + LineSeries { + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } + + ScatterSeries { + name: "scatter series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/Chart9.qml b/tests/qmlchartaxis/qml/qmlchartaxis/Chart9.qml new file mode 100644 index 0000000..9e2950d --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/Chart9.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +ChartView { + id: chartView + title: "Deprecated code" + property int index: 0 + + Component.onCompleted: { + // Calling createDefaultAxes in onCompleted is now deprecated. It needs to be tested, + // though, because some application may still use it + chartView.createDefaultAxes(); + } + + LineSeries { + name: "line series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } + + ScatterSeries { + name: "scatter series" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } +} diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/main.qml b/tests/qmlchartaxis/qml/qmlchartaxis/main.qml new file mode 100644 index 0000000..311dc18 --- /dev/null +++ b/tests/qmlchartaxis/qml/qmlchartaxis/main.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 + +Rectangle { + id: main + width: 400 + height: 300 + property int viewNumber: 0 + + Row { + anchors.fill: parent + anchors.topMargin: 10 + + Loader { + id: chartLoader + width: parent.width - buttonColumn.width + height: parent.height + source: "Chart" + viewNumber + ".qml" + } + + Column { + id: buttonColumn + width: 150 + height: parent.height + spacing: 5 + + Button { + text: "Default" + onClicked: viewNumber = 0; + } + Button { + text: "User defined" + onClicked: viewNumber = 1; + } + Button { + text: "Chart axes" + onClicked: viewNumber = 2; + } + Button { + text: "Configuring dynamically" + onClicked: viewNumber = 3; + } + Button { + text: "Series specific dynamic" + onClicked: viewNumber = 4; + } + Button { + text: "Creating dynamically" + onClicked: viewNumber = 5; + } + Button { + text: "Switching dynamically" + onClicked: viewNumber = 6; + } + Button { + text: "Axis scale" + onClicked: viewNumber = 7; + } + Button { + text: "Legacy" + onClicked: viewNumber = 8; + } + } + } +} diff --git a/tests/qmlchartaxis/qmlapplicationviewer/qmlapplicationviewer.cpp b/tests/qmlchartaxis/qmlapplicationviewer/qmlapplicationviewer.cpp new file mode 100644 index 0000000..8ba6e88 --- /dev/null +++ b/tests/qmlchartaxis/qmlapplicationviewer/qmlapplicationviewer.cpp @@ -0,0 +1,200 @@ +// checksum 0x78c version 0x60010 +/* + This file was generated by the Qt Quick Application wizard of Qt Creator. + QmlApplicationViewer is a convenience class containing mobile device specific + code such as screen orientation handling. Also QML paths and debugging are + handled here. + It is recommended not to modify this file, since newer versions of Qt Creator + may offer an updated version of it. +*/ + +#include "qmlapplicationviewer.h" + +#include +#include +#include +#include +#include +#include + +#include // MEEGO_EDITION_HARMATTAN + +#ifdef HARMATTAN_BOOSTER +#include +#endif + +#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 + +#include + +#if !defined(NO_JSDEBUGGER) +#include +#endif +#if !defined(NO_QMLOBSERVER) +#include +#endif + +// Enable debugging before any QDeclarativeEngine is created +struct QmlJsDebuggingEnabler +{ + QmlJsDebuggingEnabler() + { + QDeclarativeDebugHelper::enableDebugging(); + } +}; + +// Execute code in constructor before first QDeclarativeEngine is instantiated +static QmlJsDebuggingEnabler enableDebuggingHelper; + +#endif // QMLJSDEBUGGER + +class QmlApplicationViewerPrivate +{ + QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {} + + QString mainQmlFile; + QDeclarativeView *view; + friend class QmlApplicationViewer; + QString adjustPath(const QString &path); +}; + +QString QmlApplicationViewerPrivate::adjustPath(const QString &path) +{ +#ifdef Q_OS_UNIX +#ifdef Q_OS_MAC + if (!QDir::isAbsolutePath(path)) + return QCoreApplication::applicationDirPath() + + QLatin1String("/../Resources/") + path; +#else + QString pathInInstallDir; + const QString applicationDirPath = QCoreApplication::applicationDirPath(); + pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path); + + if (QFileInfo(pathInInstallDir).exists()) + return pathInInstallDir; +#endif +#endif + return path; +} + +QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) + : QDeclarativeView(parent) + , d(new QmlApplicationViewerPrivate(this)) +{ + connect(engine(), SIGNAL(quit()), SLOT(close())); + setResizeMode(QDeclarativeView::SizeRootObjectToView); + // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in +#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 +#if !defined(NO_JSDEBUGGER) + new QmlJSDebugger::JSDebuggerAgent(d->view->engine()); +#endif +#if !defined(NO_QMLOBSERVER) + new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view); +#endif +#endif +} + +QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent) + : QDeclarativeView(parent) + , d(new QmlApplicationViewerPrivate(view)) +{ + connect(view->engine(), SIGNAL(quit()), view, SLOT(close())); + view->setResizeMode(QDeclarativeView::SizeRootObjectToView); + // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in +#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 +#if !defined(NO_JSDEBUGGER) + new QmlJSDebugger::JSDebuggerAgent(d->view->engine()); +#endif +#if !defined(NO_QMLOBSERVER) + new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view); +#endif +#endif +} + +QmlApplicationViewer::~QmlApplicationViewer() +{ + delete d; +} + +QmlApplicationViewer *QmlApplicationViewer::create() +{ +#ifdef HARMATTAN_BOOSTER + return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0); +#else + return new QmlApplicationViewer(); +#endif +} + +void QmlApplicationViewer::setMainQmlFile(const QString &file) +{ + d->mainQmlFile = d->adjustPath(file); + d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile)); +} + +void QmlApplicationViewer::addImportPath(const QString &path) +{ + d->view->engine()->addImportPath(d->adjustPath(path)); +} + +void QmlApplicationViewer::setOrientation(ScreenOrientation orientation) +{ +#if defined(Q_OS_SYMBIAN) + // If the version of Qt on the device is < 4.7.2, that attribute won't work + if (orientation != ScreenOrientationAuto) { + const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.')); + if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) { + qWarning("Screen orientation locking only supported with Qt 4.7.2 and above"); + return; + } + } +#endif // Q_OS_SYMBIAN + + Qt::WidgetAttribute attribute; + switch (orientation) { +#if QT_VERSION < 0x040702 + // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes + case ScreenOrientationLockPortrait: + attribute = static_cast(128); + break; + case ScreenOrientationLockLandscape: + attribute = static_cast(129); + break; + default: + case ScreenOrientationAuto: + attribute = static_cast(130); + break; +#else // QT_VERSION < 0x040702 + case ScreenOrientationLockPortrait: + attribute = Qt::WA_LockPortraitOrientation; + break; + case ScreenOrientationLockLandscape: + attribute = Qt::WA_LockLandscapeOrientation; + break; + default: + case ScreenOrientationAuto: + attribute = Qt::WA_AutoOrientation; + break; +#endif // QT_VERSION < 0x040702 + }; + setAttribute(attribute, true); +} + +void QmlApplicationViewer::showExpanded() +{ +#if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR) + d->view->showFullScreen(); +#elif defined(Q_WS_MAEMO_5) + d->view->showMaximized(); +#else + d->view->show(); +#endif +} + +QApplication *createApplication(int &argc, char **argv) +{ +#ifdef HARMATTAN_BOOSTER + return MDeclarativeCache::qApplication(argc, argv); +#else + return new QApplication(argc, argv); +#endif +} diff --git a/tests/qmlchartaxis/qmlapplicationviewer/qmlapplicationviewer.h b/tests/qmlchartaxis/qmlapplicationviewer/qmlapplicationviewer.h new file mode 100644 index 0000000..f8008f5 --- /dev/null +++ b/tests/qmlchartaxis/qmlapplicationviewer/qmlapplicationviewer.h @@ -0,0 +1,47 @@ +// checksum 0x82ed version 0x60010 +/* + This file was generated by the Qt Quick Application wizard of Qt Creator. + QmlApplicationViewer is a convenience class containing mobile device specific + code such as screen orientation handling. Also QML paths and debugging are + handled here. + It is recommended not to modify this file, since newer versions of Qt Creator + may offer an updated version of it. +*/ + +#ifndef QMLAPPLICATIONVIEWER_H +#define QMLAPPLICATIONVIEWER_H + +#include + +class QmlApplicationViewer : public QDeclarativeView +{ + Q_OBJECT + +public: + enum ScreenOrientation { + ScreenOrientationLockPortrait, + ScreenOrientationLockLandscape, + ScreenOrientationAuto + }; + + explicit QmlApplicationViewer(QWidget *parent = 0); + virtual ~QmlApplicationViewer(); + + static QmlApplicationViewer *create(); + + void setMainQmlFile(const QString &file); + void addImportPath(const QString &path); + + // Note that this will only have an effect on Symbian and Fremantle. + void setOrientation(ScreenOrientation orientation); + + void showExpanded(); + +private: + explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent); + class QmlApplicationViewerPrivate *d; +}; + +QApplication *createApplication(int &argc, char **argv); + +#endif // QMLAPPLICATIONVIEWER_H diff --git a/tests/qmlchartaxis/qmlapplicationviewer/qmlapplicationviewer.pri b/tests/qmlchartaxis/qmlapplicationviewer/qmlapplicationviewer.pri new file mode 100644 index 0000000..567c6dc --- /dev/null +++ b/tests/qmlchartaxis/qmlapplicationviewer/qmlapplicationviewer.pri @@ -0,0 +1,13 @@ +QT += declarative + +SOURCES += $$PWD/qmlapplicationviewer.cpp +HEADERS += $$PWD/qmlapplicationviewer.h +INCLUDEPATH += $$PWD + +# Include JS debugger library if QMLJSDEBUGGER_PATH is set +!isEmpty(QMLJSDEBUGGER_PATH) { + include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri) +} else { + DEFINES -= QMLJSDEBUGGER +} + diff --git a/tests/qmlchartaxis/qmlchartaxis.pro b/tests/qmlchartaxis/qmlchartaxis.pro new file mode 100644 index 0000000..fccb2d4 --- /dev/null +++ b/tests/qmlchartaxis/qmlchartaxis.pro @@ -0,0 +1,8 @@ +!include( ../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp + +include(qmlapplicationviewer/qmlapplicationviewer.pri) diff --git a/tests/qmlchartaxis/resources.qrc b/tests/qmlchartaxis/resources.qrc new file mode 100644 index 0000000..82a79ac --- /dev/null +++ b/tests/qmlchartaxis/resources.qrc @@ -0,0 +1,15 @@ + + + qml/qmlchartaxis/main.qml + qml/qmlchartaxis/Button.qml + qml/qmlchartaxis/Chart0.qml + qml/qmlchartaxis/Chart1.qml + qml/qmlchartaxis/Chart2.qml + qml/qmlchartaxis/Chart3.qml + qml/qmlchartaxis/Chart4.qml + qml/qmlchartaxis/Chart5.qml + qml/qmlchartaxis/Chart6.qml + qml/qmlchartaxis/Chart7.qml + qml/qmlchartaxis/Chart8.qml + + diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml index 264352b..2c2ee87 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml @@ -68,10 +68,6 @@ ChartView { onColorChanged: console.log(name + ".onColorChanged: " + color); onBorderColorChanged: console.log(name + ".onBorderColorChanged: " + borderColor); // onCountChanged: console.log(name + ".onCountChanged: " + count); - - Component.onCompleted: { - createDefaultAxes(); - } } AreaSeries { diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml index 242fd15..ad1243b 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml @@ -30,14 +30,11 @@ ChartView { property variant series: mySeries - BarCategoriesAxis { - id:myAxis; - categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSeries { id: mySeries name: "bar" - + axisX: BarCategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); onHovered: console.log("barset.onHovered: " + status); @@ -64,10 +61,4 @@ ChartView { onLabelsVisibleChanged: console.log("groupedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("groupedBarSeries.onCountChanged: " + count); } - - Component.onCompleted: { - createDefaultAxes(); - setAxisX(myAxis,mySeries); - } - } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml index bedfc7a..82109ed 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml @@ -107,8 +107,4 @@ ChartView { NumberAnimation { duration: 800 } } } - - Component.onCompleted: { - createDefaultAxes(); - } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml index 68b5f49..279f443 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml @@ -59,8 +59,4 @@ ChartView { XYPoint { x: 4.1; y: 2.3 } onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); } - - Component.onCompleted: { - createDefaultAxes(); - } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml index 7d5af23..f8c5ed3 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml @@ -30,14 +30,11 @@ ChartView { property variant series: mySeries - BarCategoriesAxis { - id: myAxis - categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] - } - PercentBarSeries { id: mySeries name: "bar" + axisX: BarCategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); onHovered: console.log("barset.onHovered: " + status); @@ -64,9 +61,4 @@ ChartView { onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("percentBarSeries.onCountChanged: " + count); } - - Component.onCompleted: { - createDefaultAxes(); - setAxisX(myAxis,mySeries); - } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml index 4a4a1cb..e3765fb 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml @@ -58,8 +58,4 @@ ChartView { XYPoint { x: 2.67; y: 2.65 } onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); } - - Component.onCompleted: { - createDefaultAxes(); - } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml index 0dbf65f..7b12519 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml @@ -58,8 +58,4 @@ ChartView { XYPoint { x: 4.1; y: 2.3 } onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); } - - Component.onCompleted: { - createDefaultAxes(); - } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml index 950ee11..9df3fa3 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml @@ -30,14 +30,10 @@ ChartView { property variant series: mySeries - BarCategoriesAxis { - id: myAxis - categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] - } - StackedBarSeries { id: mySeries name: "bar" + axisX: BarCategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); onHovered: console.log("barset.onHovered: " + status); @@ -64,9 +60,4 @@ ChartView { onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("stackedBarSeries.onCountChanged: " + count); } - - Component.onCompleted: { - createDefaultAxes(); - setAxisX(myAxis,mySeries); - } } diff --git a/tests/tests.pro b/tests/tests.pro index 11b1f33..5ad9635 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -6,7 +6,8 @@ TEMPLATE = subdirs SUBDIRS += \ auto \ chartwidgettest \ - qmlchartproperties + qmlchartproperties \ + qmlchartaxis !linux-arm*: { SUBDIRS += \