From 1044476b0aa76a1f730b0d4bf452d46e60c6f4e8 Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Fri, 15 May 2020 14:32:53 +0200 Subject: Add example contributions from Hacktoberfest 2019 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding examples contributed from Github. Thanks to the contributors: - María José Molina-Contreras https://github.com/mjmolina - Sabine Wolf https://github.com/Lythi45 - Meili Triantafyllidi https://github.com/mei-li - Elena Hirjoaba https://github.com/puskini33 Change-Id: I7abfc6149af2e02c947ab9f088af1d09492de5df Reviewed-by: Christian Tismer --- examples/charts/charts.pyproject | 4 +- examples/charts/linechart.py | 84 ++++++++++++++++++ examples/charts/logvalueaxis.py | 94 ++++++++++++++++++++ examples/charts/piechart.py | 87 +++++++++++++++++++ examples/charts/qmlpolarchart/View1.qml | 78 +++++++++++++++++ examples/charts/qmlpolarchart/View2.qml | 99 ++++++++++++++++++++++ examples/charts/qmlpolarchart/View3.qml | 86 +++++++++++++++++++ examples/charts/qmlpolarchart/main.qml | 89 +++++++++++++++++++ examples/charts/qmlpolarchart/qmlpolarchart.py | 63 ++++++++++++++ .../charts/qmlpolarchart/qmlpolarchart.pyproject | 3 + examples/charts/temperaturerecords.py | 95 +++++++++++++++++++++ 11 files changed, 781 insertions(+), 1 deletion(-) create mode 100644 examples/charts/linechart.py create mode 100644 examples/charts/logvalueaxis.py create mode 100644 examples/charts/piechart.py create mode 100644 examples/charts/qmlpolarchart/View1.qml create mode 100644 examples/charts/qmlpolarchart/View2.qml create mode 100644 examples/charts/qmlpolarchart/View3.qml create mode 100644 examples/charts/qmlpolarchart/main.qml create mode 100644 examples/charts/qmlpolarchart/qmlpolarchart.py create mode 100644 examples/charts/qmlpolarchart/qmlpolarchart.pyproject create mode 100644 examples/charts/temperaturerecords.py diff --git a/examples/charts/charts.pyproject b/examples/charts/charts.pyproject index a4e6c01c1..15a48a3a1 100644 --- a/examples/charts/charts.pyproject +++ b/examples/charts/charts.pyproject @@ -1,3 +1,5 @@ { - "files": ["percentbarchart.py", "donutbreakdown.py", "legend.py", "nesteddonuts.py", "modeldata.py", "lineandbar.py", "memoryusage.py", "callout.py", "audio.py"] + "files": ["percentbarchart.py", "donutbreakdown.py", "legend.py", "nesteddonuts.py", + "modeldata.py", "lineandbar.py", "memoryusage.py", "callout.py", "audio.py", + "linechart.py", "logvalueaxis.py", "piechart.py", "temperaturerecords.py"] } diff --git a/examples/charts/linechart.py b/examples/charts/linechart.py new file mode 100644 index 000000000..98d17b35c --- /dev/null +++ b/examples/charts/linechart.py @@ -0,0 +1,84 @@ +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the Qt for Python examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## You may use this file under the terms of the BSD license as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################# + +"""PySide2 port of the linechart example from Qt v5.x""" + +import sys +from PySide2.QtCore import QPointF +from PySide2.QtGui import QPainter +from PySide2.QtWidgets import QMainWindow, QApplication +from PySide2.QtCharts import QtCharts + + +class TestChart(QMainWindow): + def __init__(self): + QMainWindow.__init__(self) + + self.series = QtCharts.QLineSeries() + self.series.append(0, 6) + self.series.append(2, 4) + self.series.append(3, 8) + self.series.append(7, 4) + self.series.append(10, 5) + self.series.append(QPointF(11, 1)) + self.series.append(QPointF(13, 3)) + self.series.append(QPointF(17, 6)) + self.series.append(QPointF(18, 3)) + self.series.append(QPointF(20, 2)) + + self.chart = QtCharts.QChart() + self.chart.legend().hide() + self.chart.addSeries(self.series) + self.chart.createDefaultAxes() + self.chart.setTitle("Simple line chart example") + + self.chartView = QtCharts.QChartView(self.chart) + self.chartView.setRenderHint(QPainter.Antialiasing) + + self.setCentralWidget(self.chartView) + + +if __name__ == "__main__": + app = QApplication(sys.argv) + + window = TestChart() + window.show() + window.resize(440, 300) + sys.exit(app.exec_()) diff --git a/examples/charts/logvalueaxis.py b/examples/charts/logvalueaxis.py new file mode 100644 index 000000000..7fb5604cd --- /dev/null +++ b/examples/charts/logvalueaxis.py @@ -0,0 +1,94 @@ +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the Qt for Python examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## You may use this file under the terms of the BSD license as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################# + +"""PySide2 port of the Logarithmic Axis Example from Qt v5.x""" + + + +import sys +from PySide2.QtCore import Qt, QPointF +from PySide2.QtGui import QPainter +from PySide2.QtWidgets import QMainWindow, QApplication +from PySide2.QtCharts import QtCharts + + +class TestChart(QMainWindow): + def __init__(self): + QMainWindow.__init__(self) + + self.series = QtCharts.QLineSeries() + self.series.append([ + QPointF(1.0, 1.0), QPointF(2.0, 73.0), QPointF(3.0, 268.0), + QPointF(4.0, 17.0), QPointF(5.0, 4325.0), QPointF(6.0, 723.0)]) + + self.chart = QtCharts.QChart() + self.chart.addSeries(self.series) + self.chart.legend().hide() + self.chart.setTitle("Logarithmic axis example") + + self.axisX = QtCharts.QValueAxis() + self.axisX.setTitleText("Data point") + self.axisX.setLabelFormat("%i") + self.axisX.setTickCount(self.series.count()) + self.chart.addAxis(self.axisX, Qt.AlignBottom) + self.series.attachAxis(self.axisX) + + self.axisY = QtCharts.QLogValueAxis() + self.axisY.setTitleText("Values") + self.axisY.setLabelFormat("%g") + self.axisY.setBase(8.0) + self.axisY.setMinorTickCount(-1) + self.chart.addAxis(self.axisY, Qt.AlignLeft) + self.series.attachAxis(self.axisY) + + self.chartView = QtCharts.QChartView(self.chart) + self.chartView.setRenderHint(QPainter.Antialiasing) + + self.setCentralWidget(self.chartView) + + +if __name__ == "__main__": + app = QApplication(sys.argv) + + window = TestChart() + window.show() + window.resize(800, 600) + + sys.exit(app.exec_()) diff --git a/examples/charts/piechart.py b/examples/charts/piechart.py new file mode 100644 index 000000000..820da8b91 --- /dev/null +++ b/examples/charts/piechart.py @@ -0,0 +1,87 @@ +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the Qt for Python examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## You may use this file under the terms of the BSD license as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################# + +"""PySide2 port of the Pie Chart Example from Qt v5.x""" + +import sys +from PySide2.QtCore import Qt +from PySide2.QtGui import QPainter, QPen +from PySide2.QtWidgets import QMainWindow, QApplication +from PySide2.QtCharts import QtCharts + + +class TestChart(QMainWindow): + + def __init__(self): + QMainWindow.__init__(self) + + self.series = QtCharts.QPieSeries() + + self.series.append('Jane', 1) + self.series.append('Joe', 2) + self.series.append('Andy', 3) + self.series.append('Barbara', 4) + self.series.append('Axel', 5) + + self.slice = self.series.slices()[1] + self.slice.setExploded() + self.slice.setLabelVisible() + self.slice.setPen(QPen(Qt.darkGreen, 2)) + self.slice.setBrush(Qt.green) + + self.chart = QtCharts.QChart() + self.chart.addSeries(self.series) + self.chart.setTitle('Simple piechart example') + self.chart.legend().hide() + + self.chartView = QtCharts.QChartView(self.chart) + self.chartView.setRenderHint(QPainter.Antialiasing) + + self.setCentralWidget(self.chartView) + + +if __name__ == "__main__": + app = QApplication(sys.argv) + + window = TestChart() + window.show() + window.resize(440, 300) + + sys.exit(app.exec_()) diff --git a/examples/charts/qmlpolarchart/View1.qml b/examples/charts/qmlpolarchart/View1.qml new file mode 100644 index 000000000..ad17fec6b --- /dev/null +++ b/examples/charts/qmlpolarchart/View1.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtCharts 2.0 + +Item { + anchors.fill: parent + //![1] + PolarChartView { + title: "Two Series, Common Axes" + anchors.fill: parent + legend.visible: false + antialiasing: true + + ValueAxis { + id: axisAngular + min: 0 + max: 20 + tickCount: 9 + } + + ValueAxis { + id: axisRadial + min: -0.5 + max: 1.5 + } + + SplineSeries { + id: series1 + axisAngular: axisAngular + axisRadial: axisRadial + pointsVisible: true + } + + ScatterSeries { + id: series2 + axisAngular: axisAngular + axisRadial: axisRadial + markerSize: 10 + } + } + + // Add data dynamically to the series + Component.onCompleted: { + for (var i = 0; i <= 20; i++) { + series1.append(i, Math.random()); + series2.append(i, Math.random()); + } + } + //![1] +} diff --git a/examples/charts/qmlpolarchart/View2.qml b/examples/charts/qmlpolarchart/View2.qml new file mode 100644 index 000000000..7f241c3e7 --- /dev/null +++ b/examples/charts/qmlpolarchart/View2.qml @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtCharts 2.0 + +Item { + anchors.fill: parent + + //![1] + PolarChartView { + title: "Historical Area Series" + anchors.fill: parent + legend.visible: false + antialiasing: true + + DateTimeAxis { + id: axis1 + format: "yyyy MMM" + tickCount: 13 + } + ValueAxis { + id: axis2 + } + LineSeries { + id: lowerLine + axisAngular: axis1 + axisRadial: axis2 + + // Please note that month in JavaScript months are zero based, so 2 means March + XYPoint { x: toMsecsSinceEpoch(new Date(1950, 0, 1)); y: 15 } + XYPoint { x: toMsecsSinceEpoch(new Date(1962, 4, 1)); y: 35 } + XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 } + XYPoint { x: toMsecsSinceEpoch(new Date(1978, 2, 1)); y: 75 } + XYPoint { x: toMsecsSinceEpoch(new Date(1987, 11, 1)); y: 102 } + XYPoint { x: toMsecsSinceEpoch(new Date(1992, 1, 1)); y: 132 } + XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 } + XYPoint { x: toMsecsSinceEpoch(new Date(2002, 4, 1)); y: 120 } + XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 1)); y: 140 } + XYPoint { x: toMsecsSinceEpoch(new Date(2013, 5, 1)); y: 150 } + } + LineSeries { + id: upperLine + axisAngular: axis1 + axisRadial: axis2 + + // Please note that month in JavaScript months are zero based, so 2 means March + XYPoint { x: toMsecsSinceEpoch(new Date(1950, 0, 1)); y: 30 } + XYPoint { x: toMsecsSinceEpoch(new Date(1962, 4, 1)); y: 55 } + XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 80 } + XYPoint { x: toMsecsSinceEpoch(new Date(1978, 2, 1)); y: 105 } + XYPoint { x: toMsecsSinceEpoch(new Date(1987, 11, 1)); y: 125 } + XYPoint { x: toMsecsSinceEpoch(new Date(1992, 1, 1)); y: 160 } + XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 140 } + XYPoint { x: toMsecsSinceEpoch(new Date(2002, 4, 1)); y: 140 } + XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 1)); y: 170 } + XYPoint { x: toMsecsSinceEpoch(new Date(2013, 5, 1)); y: 200 } + } + AreaSeries { + axisAngular: axis1 + axisRadial: axis2 + lowerSeries: lowerLine + upperSeries: upperLine + } + } + // DateTimeAxis is based on QDateTimes so we must convert our JavaScript dates to + // milliseconds since epoch to make them match the DateTimeAxis values + function toMsecsSinceEpoch(date) { + var msecs = date.getTime(); + return msecs; + } + //![1] +} diff --git a/examples/charts/qmlpolarchart/View3.qml b/examples/charts/qmlpolarchart/View3.qml new file mode 100644 index 000000000..5695a891f --- /dev/null +++ b/examples/charts/qmlpolarchart/View3.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtCharts 2.0 + +Item { + anchors.fill: parent + + //![1] + PolarChartView { + title: "Numerical Data for Dummies" + anchors.fill: parent + legend.visible: false + antialiasing: true + + LineSeries { + axisRadial: CategoryAxis { + min: 0 + max: 30 + CategoryRange { + label: "critical" + endValue: 2 + } + CategoryRange { + label: "low" + endValue: 7 + } + CategoryRange { + label: "normal" + endValue: 12 + } + CategoryRange { + label: "high" + endValue: 18 + } + CategoryRange { + label: "extremely high" + endValue: 30 + } + } + + axisAngular: ValueAxis { + tickCount: 13 + } + + XYPoint { x: 0; y: 4.3 } + XYPoint { x: 1; y: 4.1 } + XYPoint { x: 2; y: 4.7 } + XYPoint { x: 3; y: 3.9 } + XYPoint { x: 4; y: 5.2 } + XYPoint { x: 5; y: 5.3 } + XYPoint { x: 6; y: 6.1 } + XYPoint { x: 7; y: 7.7 } + XYPoint { x: 8; y: 12.9 } + XYPoint { x: 9; y: 19.2 } + } + } + //![1] +} diff --git a/examples/charts/qmlpolarchart/main.qml b/examples/charts/qmlpolarchart/main.qml new file mode 100644 index 000000000..ed7a810c6 --- /dev/null +++ b/examples/charts/qmlpolarchart/main.qml @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + width: 800 + height: 600 + property bool sourceLoaded: false + + ListView { + id: root + focus: true + anchors.fill: parent + snapMode: ListView.SnapOneItem + highlightRangeMode: ListView.StrictlyEnforceRange + highlightMoveDuration: 250 + orientation: ListView.Horizontal + boundsBehavior: Flickable.StopAtBounds + + onCurrentIndexChanged: { + if (infoText.opacity > 0.0) { + if (sourceLoaded) + infoText.opacity = 0.0; + else if (currentIndex != 0) + currentIndex = 0; + } + } + + model: ListModel { + ListElement {component: "View1.qml"} + ListElement {component: "View2.qml"} + ListElement {component: "View3.qml"} + } + + delegate: Loader { + width: root.width + height: root.height + + source: component + asynchronous: true + + onLoaded: sourceLoaded = true + } + } + + Rectangle { + id: infoText + anchors.centerIn: parent + width: parent.width + height: 40 + color: "black" + Text { + color: "white" + anchors.centerIn: parent + text: "You can navigate between views using swipe or arrow keys" + } + + Behavior on opacity { + NumberAnimation { duration: 400 } + } + } +} diff --git a/examples/charts/qmlpolarchart/qmlpolarchart.py b/examples/charts/qmlpolarchart/qmlpolarchart.py new file mode 100644 index 000000000..4398169b0 --- /dev/null +++ b/examples/charts/qmlpolarchart/qmlpolarchart.py @@ -0,0 +1,63 @@ +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the Qt for Python examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## You may use this file under the terms of the BSD license as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################# + +"""PySide2 port of the QML Polar Chart Example from Qt v5.x""" + +import sys +import os +from PySide2.QtQuick import QQuickView +from PySide2.QtCore import Qt, QUrl +from PySide2.QtWidgets import QApplication, QMainWindow + + +if __name__ == '__main__': + app = QApplication(sys.argv) + viewer = QQuickView() + + viewer.engine().addImportPath(os.path.dirname(__file__)) + viewer.engine().quit.connect(viewer.close) + + viewer.setTitle = "QML Polar Chart" + qmlFile = os.path.join(os.path.dirname(__file__), 'main.qml') + viewer.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) + viewer.setResizeMode(QQuickView.SizeRootObjectToView) + viewer.show() + + sys.exit(app.exec_()) diff --git a/examples/charts/qmlpolarchart/qmlpolarchart.pyproject b/examples/charts/qmlpolarchart/qmlpolarchart.pyproject new file mode 100644 index 000000000..6c18b1f43 --- /dev/null +++ b/examples/charts/qmlpolarchart/qmlpolarchart.pyproject @@ -0,0 +1,3 @@ +{ + "files": ["View1.qml", "View1.qml", "View2.qml", "View3.qml", "main.qml", "qmlpolarchart.py"] +} diff --git a/examples/charts/temperaturerecords.py b/examples/charts/temperaturerecords.py new file mode 100644 index 000000000..dfd4dd67c --- /dev/null +++ b/examples/charts/temperaturerecords.py @@ -0,0 +1,95 @@ +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the Qt for Python examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## You may use this file under the terms of the BSD license as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +## +## $QT_END_LICENSE$ +## +############################################################################# + +"""PySide2 port of the Temperature Records example from Qt v5.x""" + +import sys +from PySide2.QtCore import Qt +from PySide2.QtGui import QPainter +from PySide2.QtWidgets import QMainWindow, QApplication +from PySide2.QtCharts import QtCharts + + +class MainWindow(QMainWindow): + def __init__(self): + QMainWindow.__init__(self) + low = QtCharts.QBarSet("Min") + high = QtCharts.QBarSet("Max") + low.append([-52, -50, -45.3, -37.0, -25.6, -8.0, + -6.0, -11.8, -19.7, -32.8, -43.0, -48.0]) + high.append([11.9, 12.8, 18.5, 26.5, 32.0, 34.8, + 38.2, 34.8, 29.8, 20.4, 15.1, 11.8]) + + series = QtCharts.QStackedBarSeries() + series.append(low) + series.append(high) + + chart = QtCharts.QChart() + chart.addSeries(series) + chart.setTitle("Temperature records in celcius") + chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations) + + categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", + "Aug", "Sep", "Oct", "Nov", "Dec"] + axisX = QtCharts.QBarCategoryAxis() + axisX.append(categories) + axisX.setTitleText("Month") + chart.addAxis(axisX, Qt.AlignBottom) + axisY = QtCharts.QValueAxis() + axisY.setRange(-52, 52) + axisY.setTitleText("Temperature [°C]") + chart.addAxis(axisY, Qt.AlignLeft) + series.attachAxis(axisX) + series.attachAxis(axisY) + + chart.legend().setVisible(True) + chart.legend().setAlignment(Qt.AlignBottom) + + chart_view = QtCharts.QChartView(chart) + chart_view.setRenderHint(QPainter.Antialiasing) + + self.setCentralWidget(chart_view) + +if __name__ == "__main__": + app = QApplication(sys.argv) + w = MainWindow() + w.resize(600, 300) + w.show() + sys.exit(app.exec_()) -- cgit v1.2.3