From 9b6f702368602f6b0b8245d9121eed52dc3cd79c 2012-05-30 09:07:27 From: Tero Ahola Date: 2012-05-30 09:07:27 Subject: [PATCH] Added test app for testing QML properties --- diff --git a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml index fe79e06..31b32a4 100644 --- a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml +++ b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml @@ -37,7 +37,7 @@ Rectangle { // For dynamic data we use a custom data model derived from QAbstractiItemModel CustomModel { id: customModel - CustomModelElement { values: [index, "Manufacturer", 1, 2] } + CustomModelElement { values: [0, "Manufacturer", 1, 2] } CustomModelElement { values: [1, "Volkswagen", 13.5, 12.5] } CustomModelElement { values: [2, "Toyota", 10.9, 9.9] } CustomModelElement { values: [3, "Ford", 8.6, 7.6] } diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index 5a31684..0916f26 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -69,13 +69,12 @@ void DeclarativeChart::componentComplete() void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); - Q_UNUSED(oldGeometry) - if (newGeometry.isValid()) { if (newGeometry.width() > 0 && newGeometry.height() > 0) { m_chart->resize(newGeometry.width(), newGeometry.height()); } } + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); } void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) diff --git a/plugins/declarative/declarativepieseries.cpp b/plugins/declarative/declarativepieseries.cpp index 9744c6e..d929f14 100644 --- a/plugins/declarative/declarativepieseries.cpp +++ b/plugins/declarative/declarativepieseries.cpp @@ -68,6 +68,18 @@ void DeclarativePieSlice::setBorderWidth(int width) setPen(p); } +QColor DeclarativePieSlice::labelColor() +{ + return labelPen().color(); +} + +void DeclarativePieSlice::setLabelColor(QColor color) +{ + QPen p = labelPen(); + p.setColor(color); + setLabelPen(p); +} + DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : QPieSeries(parent) { diff --git a/plugins/declarative/declarativepieseries.h b/plugins/declarative/declarativepieseries.h index 5ee9831..9a2fe65 100644 --- a/plugins/declarative/declarativepieseries.h +++ b/plugins/declarative/declarativepieseries.h @@ -38,6 +38,7 @@ class DeclarativePieSlice: public QPieSlice Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor) Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth) + Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor) public: explicit DeclarativePieSlice(QObject *parent = 0); @@ -47,6 +48,8 @@ public: void setBorderColor(QColor color); int borderWidth(); void setBorderWidth(int width); + QColor labelColor(); + void setLabelColor(QColor color); }; class DeclarativePieSeries : public QPieSeries, public QDeclarativeParserStatus diff --git a/src/xychart/qxyseries.h b/src/xychart/qxyseries.h index c4c7460..e50551a 100644 --- a/src/xychart/qxyseries.h +++ b/src/xychart/qxyseries.h @@ -36,6 +36,7 @@ class QXYModelMapper; class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries { Q_OBJECT + Q_PROPERTY(bool pointsVisible READ pointsVisible WRITE setPointsVisible) protected: explicit QXYSeries(QXYSeriesPrivate &d,QObject *parent = 0); diff --git a/tests/qmlchartproperties/main.cpp b/tests/qmlchartproperties/main.cpp new file mode 100644 index 0000000..dab33c8 --- /dev/null +++ b/tests/qmlchartproperties/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/qmlchartproperties/loader.qml")); + viewer->showExpanded(); + + return app->exec(); +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.qml new file mode 100644 index 0000000..b11e89f --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/AreaChart.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: "area series" + anchors.fill: parent + axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005", + "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"] + + property variant series: daSeries + + AreaSeries { + id: daSeries + name: "area 1" + upperSeries: LineSeries { + XyPoint { x: 0; y: 1 } + XyPoint { x: 1; y: 1 } + XyPoint { x: 2; y: 3 } + XyPoint { x: 3; y: 3 } + XyPoint { x: 4; y: 2 } + XyPoint { x: 5; y: 0 } + XyPoint { x: 6; y: 2 } + XyPoint { x: 7; y: 1 } + XyPoint { x: 8; y: 2 } + XyPoint { x: 9; y: 1 } + 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 } + } + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml new file mode 100644 index 0000000..4e57e78 --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** 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: "Bar series" + anchors.fill: parent + theme: ChartView.ChartThemeLight + legend: ChartView.LegendBottom + // TODO: labels defined by x-axis, not by bar series + axisXLabels: ["0", "2008", "1", "2009", "2", "2010", "3", "2012"] + + property variant series: daSeries + + GroupedBarSeries { + id: daSeries + barCategories: [ "2008", "2009", "2010", "2011", "2012" ] + BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { name: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { name: "James"; values: [3, 5, 8, 13, 5, 8] } + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml new file mode 100644 index 0000000..014a2e2 --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** 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 + +Flow { + id: flow + spacing: 5 + property variant series + + Button { + text: "color" + onClicked: series.color = main.nextColor(); + } + Button { + text: "points visible" + onClicked: series.pointsVisible = !series.pointsVisible + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/Button.qml b/tests/qmlchartproperties/qml/qmlchartproperties/Button.qml new file mode 100644 index 0000000..6666d32 --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/Button.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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: 45 + width: 165 + color: "#afafaf" + radius: 5 + + 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 = "#afafaf"; + } + } + onPressAndHold: { + repeatTimer.start(); + } + onReleased: { + repeatTimer.stop(); + } + } + + Timer { + id: repeatTimer + interval: 200 + repeat: true + triggeredOnStart: false + running: false + onTriggered: { + button.clicked(); + } + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml new file mode 100644 index 0000000..dfcd966 --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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: "line series" + anchors.fill: parent + + property variant series: daSeries + + LineSeries { + id: daSeries + name: "line 1" + 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 } + } + + LineSeries { + name: "line 2" + XyPoint { x: 1.1; y: 1.1 } + XyPoint { x: 1.9; y: 2.3 } + XyPoint { x: 2.1; y: 1.1 } + XyPoint { x: 2.9; y: 3.9 } + XyPoint { x: 3.4; y: 2.0 } + XyPoint { x: 4.1; y: 2.3 } + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml new file mode 100644 index 0000000..6648a95 --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** 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 + + +Flow { + id: flow + spacing: 5 + property variant series + + Button { + text: "color" + onClicked: series.color = main.nextColor(); + } + Button { + text: "points visible" + onClicked: series.pointsVisible = !series.pointsVisible + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/PieChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/PieChart.qml new file mode 100644 index 0000000..e6f15fc --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/PieChart.qml @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** 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: chart + title: "pie series" + animationOptions: ChartView.SeriesAnimations + + property variant series: pieSeries + + PieSeries { + id: pieSeries + PieSlice { id: daSlice; label: "slice1"; value: 11 } + PieSlice { label: "slice2"; value: 22 } + PieSlice { label: "slice3"; value: 33 } + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/PieEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/PieEditor.qml new file mode 100644 index 0000000..bb3274d --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/PieEditor.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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 + +Flow { + id: flow + spacing: 5 + property variant series + + Button { + text: "slice color" + onClicked: series.at(0).color = main.nextColor(); + } + Button { + text: "slice border color" + onClicked: series.at(0).borderColor = main.nextColor(); + } + Button { + text: "slice border width +" + onClicked: series.at(0).borderWidth++; + } + Button { + text: "slice border width -" + onClicked: series.at(0).borderWidth--; + } + Button { + text: "slice label visible" + onClicked: series.at(0).labelVisible = !series.at(0).labelVisible; + } + Button { + text: "slice label color" + onClicked: series.at(0).labelColor = main.nextColor(); + } + Button { + text: "slice exploded" + onClicked: series.at(0).exploded = !series.at(0).exploded; + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml new file mode 100644 index 0000000..d5251dc --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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: "scatter series" + axisX.max: 4 + axisY.max: 4 + property variant series: daSeries + + ScatterSeries { + id: daSeries + name: "scatter 1" + XyPoint { x: 1.5; y: 1.5 } + XyPoint { x: 1.5; y: 1.6 } + XyPoint { x: 1.57; y: 1.55 } + XyPoint { x: 1.8; y: 1.8 } + XyPoint { x: 1.9; y: 1.6 } + XyPoint { x: 2.1; y: 1.3 } + XyPoint { x: 2.5; y: 2.1 } + } + + ScatterSeries { + name: "scatter2" + XyPoint { x: 2.0; y: 2.0 } + XyPoint { x: 2.0; y: 2.1 } + XyPoint { x: 2.07; y: 2.05 } + XyPoint { x: 2.2; y: 2.9 } + XyPoint { x: 2.4; y: 2.7 } + XyPoint { x: 2.67; y: 2.65 } + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml new file mode 100644 index 0000000..07881b1 --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** 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: "spline series" + anchors.fill: parent + property variant series: daSeries + + SplineSeries { + id: daSeries + name: "spline 1" + 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 } + } + + SplineSeries { + name: "spline 2" + XyPoint { x: 1.1; y: 1.1 } + XyPoint { x: 1.9; y: 2.3 } + XyPoint { x: 2.1; y: 1.1 } + XyPoint { x: 2.9; y: 3.9 } + XyPoint { x: 3.4; y: 2.0 } + XyPoint { x: 4.1; y: 2.3 } + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/View1.qml b/tests/qmlchartproperties/qml/qmlchartproperties/View1.qml new file mode 100644 index 0000000..6b878fb --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/View1.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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 + +Rectangle { + anchors.fill: parent + + ChartView { + title: "spline series" + anchors.fill: parent + + SplineSeries { + id: daSeries + name: "spline 1" + 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 } + } + + SplineSeries { + name: "spline 2" + XyPoint { x: 1.1; y: 1.1 } + XyPoint { x: 1.9; y: 2.3 } + XyPoint { x: 2.1; y: 1.1 } + XyPoint { x: 2.9; y: 3.9 } + XyPoint { x: 3.4; y: 2.0 } + XyPoint { x: 4.1; y: 2.3 } + } + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/loader.qml b/tests/qmlchartproperties/qml/qmlchartproperties/loader.qml new file mode 100644 index 0000000..77df7be --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/loader.qml @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** 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 + +Item { + id: container + width: 640 + height: 500 + Component.onCompleted: { + var co = Qt.createComponent("main.qml") + if (co.status == Component.Ready) { + var o = co.createObject(container) + } else { + console.log(co.errorString()) + console.log("QtCommercial.Chart 1.1 not available") + console.log("Please use correct QML_IMPORT_PATH export") + } + } +} diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/main.qml b/tests/qmlchartproperties/qml/qmlchartproperties/main.qml new file mode 100644 index 0000000..7f4ed85 --- /dev/null +++ b/tests/qmlchartproperties/qml/qmlchartproperties/main.qml @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** 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 + +Rectangle { + id: main + width: parent.width + height: parent.height + property int viewNumber: 0 + property int viewCount: 6 + property variant colors: ["#637D74", "#403D3A", "#8C3B3B", "#AB6937", "#D4A960"] + property int colorIndex: 0 + + function nextColor() { + colorIndex++; + console.log("color: " + colors[colorIndex % colors.length]); + return colors[colorIndex % colors.length]; + } + + onViewNumberChanged: { + if (viewNumber == 0) { + chartLoader.source = "PieChart.qml"; + editorLoader.source = "PieEditor.qml"; + } else if (viewNumber == 1) { + chartLoader.source = "LineChart.qml"; + editorLoader.source = "LineEditor.qml"; + } else if (viewNumber == 2) { + chartLoader.source = "SplineChart.qml"; + editorLoader.source = "LineEditor.qml"; + } else if (viewNumber == 3) { + chartLoader.source = "ScatterChart.qml"; + editorLoader.source = "LineEditor.qml"; // TODO: scatter specific properties + } else if (viewNumber == 4) { + chartLoader.source = "AreaChart.qml"; + editorLoader.source = "LineEditor.qml"; // TODO: area specific properties + } else if (viewNumber == 5) { + chartLoader.source = "BarChart.qml"; + editorLoader.source = "BarEditor.qml"; + } else { + console.log("Illegal view number"); + } + } + + Row { + anchors.top: parent.top + anchors.bottom: buttonRow.top + anchors.left: parent.left + anchors.right: parent.right + + Loader { + id: chartLoader + width: main.width - editorLoader.width + height: parent.height + source: "PieChart.qml" + onStatusChanged: { + console.log("chartLoader.status: " + status + " " + source); + if (status == Loader.Ready && editorLoader.status == Loader.Ready) + editorLoader.item.series = chartLoader.item.series; + } + } + + Loader { + id: editorLoader + width: 150 + height: parent.height + source: "PieEditor.qml" + onStatusChanged: { + console.log("editorLoader.status: " + status + " " + source); + if (status == Loader.Ready && chartLoader.status == Loader.Ready) + editorLoader.item.series = chartLoader.item.series; + } + } + } + +// Loader { +// id: loader +// anchors.top: parent.top +// anchors.bottom: buttonRow.top +// anchors.left: parent.left +// anchors.right: parent.right +// source: "View" + viewNumber + ".qml"; +// } + + Row { + id: buttonRow + height: 100 + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 + anchors.horizontalCenter: parent.horizontalCenter + spacing: 10 + + Rectangle { + height: buttonRow.height + width: 100 + color: "#afafaf" + radius: 5 + Text { + anchors.centerIn: parent + text: "previous" + } + MouseArea { + anchors.fill: parent + onClicked: { + viewNumber = (viewNumber + viewCount - 1) % viewCount; + } + } + } + + Rectangle { + height: buttonRow.height + width: 100 + color: "#afafaf" + radius: 5 + Text { + anchors.centerIn: parent + text: "next" + } + MouseArea { + anchors.fill: parent + onClicked: { + viewNumber = (viewNumber + 1) % viewCount; + } + } + } + } +} diff --git a/tests/qmlchartproperties/qmlapplicationviewer/qmlapplicationviewer.cpp b/tests/qmlchartproperties/qmlapplicationviewer/qmlapplicationviewer.cpp new file mode 100644 index 0000000..8ba6e88 --- /dev/null +++ b/tests/qmlchartproperties/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/qmlchartproperties/qmlapplicationviewer/qmlapplicationviewer.h b/tests/qmlchartproperties/qmlapplicationviewer/qmlapplicationviewer.h new file mode 100644 index 0000000..f8008f5 --- /dev/null +++ b/tests/qmlchartproperties/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/qmlchartproperties/qmlapplicationviewer/qmlapplicationviewer.pri b/tests/qmlchartproperties/qmlapplicationviewer/qmlapplicationviewer.pri new file mode 100644 index 0000000..567c6dc --- /dev/null +++ b/tests/qmlchartproperties/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/qmlchartproperties/qmlchartproperties.pro b/tests/qmlchartproperties/qmlchartproperties.pro new file mode 100644 index 0000000..d7871c6 --- /dev/null +++ b/tests/qmlchartproperties/qmlchartproperties.pro @@ -0,0 +1,10 @@ +!include( ../tests.pri ) { + error( "Couldn't find the test.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp + +include(qmlapplicationviewer/qmlapplicationviewer.pri) + +!system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_DEMOS_BIN_DIR" diff --git a/tests/qmlchartproperties/resources.qrc b/tests/qmlchartproperties/resources.qrc new file mode 100644 index 0000000..9d68b9b --- /dev/null +++ b/tests/qmlchartproperties/resources.qrc @@ -0,0 +1,16 @@ + + + qml/qmlchartproperties/loader.qml + qml/qmlchartproperties/main.qml + qml/qmlchartproperties/Button.qml + qml/qmlchartproperties/PieChart.qml + qml/qmlchartproperties/PieEditor.qml + qml/qmlchartproperties/LineChart.qml + qml/qmlchartproperties/LineEditor.qml + qml/qmlchartproperties/SplineChart.qml + qml/qmlchartproperties/ScatterChart.qml + qml/qmlchartproperties/AreaChart.qml + qml/qmlchartproperties/BarChart.qml + qml/qmlchartproperties/BarEditor.qml + + diff --git a/tests/tests.pro b/tests/tests.pro index 799bc3b..4277bfe 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -8,4 +8,5 @@ SUBDIRS += \ chartwidgettest \ wavechart \ gdpbarchart \ - tablemodelchart + tablemodelchart \ + qmlchartproperties