From 7f47f3c844a495a1cc47706b23a2505eac914572 2012-06-01 06:15:16 From: Tero Ahola Date: 2012-06-01 06:15:16 Subject: [PATCH] Tuning qml chart demo pie and area charts --- diff --git a/demos/qmlchart/qml/qmlchart/View1.qml b/demos/qmlchart/qml/qmlchart/View1.qml index dc7a155..3469ddf 100644 --- a/demos/qmlchart/qml/qmlchart/View1.qml +++ b/demos/qmlchart/qml/qmlchart/View1.qml @@ -29,10 +29,7 @@ Rectangle { ChartView { id: chart title: "Top-5 car brand shares in Finland" - anchors.top: parent.top - anchors.bottom: button.top - anchors.left: parent.left - anchors.right: parent.right + anchors.fill: parent theme: ChartView.ChartThemeLight legend: ChartView.LegendBottom animationOptions: ChartView.SeriesAnimations @@ -40,7 +37,10 @@ Rectangle { // If you have static data, you can simply use the PieSlice API PieSeries { id: pieSeries - PieSlice { id: volkswagenSlice; label: "Volkswagen"; value: 13.5 } + onClicked: { + slice.exploded = !slice.exploded; + } + PieSlice { label: "Volkswagen"; value: 13.5 } PieSlice { label: "Toyota"; value: 10.9 } PieSlice { label: "Ford"; value: 8.6 } PieSlice { label: "Skoda"; value: 8.2 } @@ -49,56 +49,8 @@ Rectangle { } Component.onCompleted: { - volkswagenSlice.exploded = true; // You can also add slices dynamically otherSlice = pieSeries.append("Others", 52.0); - } - - Timer { - repeat: true - interval: 2000 - running: true - onTriggered: { - // Set all slices as not exploded - for (var i = 0; i < pieSeries.count; i++) - pieSeries.at(i).exploded = false; - - // Explode one of the slices - __explodedIndex = (__explodedIndex + 1) % pieSeries.count; - pieSeries.at(__explodedIndex).exploded = true; - - pieSeries.find("Volkswagen").exploded = true; - // TODO: implement for convenience -// pieSeries.removeAll("Ford"); - } - } - - Rectangle { - id: button - anchors.bottom: parent.bottom - anchors.bottomMargin: 10 - anchors.horizontalCenter: parent.horizontalCenter - height: 40 - width: 100 - color: "orange" - radius: 5 - Text { - id: buttonText - anchors.centerIn: parent - text: "Hide others" - } - MouseArea { - anchors.fill: parent - onClicked: { - if (buttonText.text == "Show others") { - buttonText.text = "Hide others"; - // TODO: ? - otherSlice.visible = true; - } else { - buttonText.text = "Show others"; - otherSlice.visible = false; - } - } - } + pieSeries.find("Volkswagen").exploded = true; } } diff --git a/demos/qmlchart/qml/qmlchart/View3.qml b/demos/qmlchart/qml/qmlchart/View3.qml index 2065b4a..4b7c918 100644 --- a/demos/qmlchart/qml/qmlchart/View3.qml +++ b/demos/qmlchart/qml/qmlchart/View3.qml @@ -61,9 +61,14 @@ Rectangle { XyPoint { x: 10; y: 0 } XyPoint { x: 11; y: 0 } } + onClicked: { + color = "red"; + borderColor = "black"; + } } AreaSeries { + id: swedish name: "Swedish" upperSeries: LineSeries { XyPoint { x: 0; y: 1 } @@ -93,6 +98,10 @@ Rectangle { XyPoint { x: 10; y: 0 } XyPoint { x: 11; y: 0 } } + onClicked: { + color = "yellow"; + borderColor = "blue"; + } } AreaSeries { @@ -125,6 +134,10 @@ Rectangle { XyPoint { x: 10; y: 0 } XyPoint { x: 11; y: 0 } } + onClicked: { + color = "white"; + borderColor = "blue"; + } } } } diff --git a/demos/qmlchart/qml/qmlchart/main.qml b/demos/qmlchart/qml/qmlchart/main.qml index 01b35fd..2072df2 100644 --- a/demos/qmlchart/qml/qmlchart/main.qml +++ b/demos/qmlchart/qml/qmlchart/main.qml @@ -24,18 +24,63 @@ import QtCommercial.Chart 1.0 Rectangle { width: parent.width height: parent.height - property int __viewNumber: 0 - - MouseArea { - anchors.fill: parent - onClicked: { - __viewNumber++; - } - } + property int viewNumber: 1 Loader { id: loader - anchors.fill: parent - source: "View" + (__viewNumber % 5 + 1) + ".qml"; + anchors.top: parent.top + anchors.bottom: buttons.top + anchors.left: parent.left + anchors.right: parent.right + source: "View" + viewNumber + ".qml"; + } + + Row { + id: buttons + anchors.bottom: parent.bottom + anchors.bottomMargin: 5 + anchors.horizontalCenter: parent.horizontalCenter + spacing: 10 + + Rectangle { + height: 35 + width: 55 + color: "grey" + radius: 5 + Text { + anchors.centerIn: parent + text: "previous" + } + MouseArea { + anchors.fill: parent + onClicked: { + var i = viewNumber - 1; + if (i <= 0) + viewNumber = 5; + else + viewNumber = i; + } + } + } + Rectangle { + height: 35 + width: 55 + color: "grey" + radius: 5 + Text { + anchors.centerIn: parent + text: "next" + } + MouseArea { + anchors.fill: parent + onClicked: { + var i = viewNumber + 1; + if (i > 5) + viewNumber = 1; + else + viewNumber = i; + } + } + } } } diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index 2788967..1f7dd62 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -67,11 +67,12 @@ public: qmlRegisterType(uri, 1, 0, "HBarModelMapper"); qmlRegisterType(uri, 1, 0, "VBarModelMapper"); - qmlRegisterUncreatableType(uri, 1, 0, "QScatterSeries", QLatin1String("Trying to create uncreatable: QScatterSeries.")); qmlRegisterUncreatableType(uri, 1, 0, "QPieSeries", QLatin1String("Trying to create uncreatable: QPieSeries.")); + qmlRegisterUncreatableType(uri, 1, 0, "QPieSlice", + QLatin1String("Trying to create uncreatable: QPieSlice.")); qmlRegisterUncreatableType(uri, 1, 0, "AbstractItemModel", QLatin1String("Trying to create uncreatable: AbstractItemModel.")); qmlRegisterUncreatableType(uri, 1, 0, "XYModelMapper",