aboutsummaryrefslogtreecommitdiffstats
path: root/examples/graphs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/graphs')
-rw-r--r--examples/graphs/2d/hellographs/HelloGraphs/Main.qml85
-rw-r--r--examples/graphs/3d/minimalsurfacegraph/main.py20
-rw-r--r--examples/graphs/3d/widgetgraphgallery/axesinputhandler.py101
-rw-r--r--examples/graphs/3d/widgetgraphgallery/bargraph.py138
-rw-r--r--examples/graphs/3d/widgetgraphgallery/custominputhandler.py178
-rw-r--r--examples/graphs/3d/widgetgraphgallery/graphmodifier.py74
-rw-r--r--examples/graphs/3d/widgetgraphgallery/highlightseries.py12
-rw-r--r--examples/graphs/3d/widgetgraphgallery/main.py48
-rw-r--r--examples/graphs/3d/widgetgraphgallery/scatterdatamodifier.py116
-rw-r--r--examples/graphs/3d/widgetgraphgallery/scattergraph.py49
-rw-r--r--examples/graphs/3d/widgetgraphgallery/surfacegraph.py21
-rw-r--r--examples/graphs/3d/widgetgraphgallery/surfacegraphmodifier.py218
-rw-r--r--examples/graphs/3d/widgetgraphgallery/topographicseries.py2
-rw-r--r--examples/graphs/3d/widgetgraphgallery/widgetgraphgallery.pyproject2
14 files changed, 482 insertions, 582 deletions
diff --git a/examples/graphs/2d/hellographs/HelloGraphs/Main.qml b/examples/graphs/2d/hellographs/HelloGraphs/Main.qml
index b1844aec4..815e365ee 100644
--- a/examples/graphs/2d/hellographs/HelloGraphs/Main.qml
+++ b/examples/graphs/2d/hellographs/HelloGraphs/Main.qml
@@ -30,23 +30,24 @@ Item {
GraphsView {
anchors.fill: parent
anchors.margins: 16
- theme: GraphTheme {
- colorTheme: GraphTheme.ColorThemeDark
+ axisX: BarCategoryAxis {
+ categories: [2024, 2025, 2026]
+ gridVisible: false
+ subGridVisible: false
+ }
+ axisY: ValueAxis {
+ min: 20
+ max: 100
+ tickInterval: 10
+ subTickCount: 9
+ }
+ theme: GraphsTheme {
+ colorScheme: Qt.Dark
+ theme: GraphsTheme.Theme.QtGreen
}
//! [bargraph]
//! [barseries]
BarSeries {
- axisX: BarCategoryAxis {
- categories: [2024, 2025, 2026]
- gridVisible: false
- minorGridVisible: false
- }
- axisY: ValueAxis {
- min: 20
- max: 100
- tickInterval: 10
- minorTickCount: 9
- }
//! [barseries]
//! [barset]
BarSet {
@@ -72,19 +73,32 @@ Item {
GraphsView {
anchors.fill: parent
anchors.margins: 16
- theme: GraphTheme {
+ theme: GraphsTheme {
readonly property color c1: "#DBEB00"
readonly property color c2: "#373F26"
readonly property color c3: Qt.lighter(c2, 1.5)
- colorTheme: GraphTheme.ColorThemeDark
- gridMajorBarsColor: c3
- gridMinorBarsColor: c2
- axisXMajorColor: c3
- axisYMajorColor: c3
- axisXMinorColor: c2
- axisYMinorColor: c2
- axisXLabelsColor: c1
- axisYLabelsColor: c1
+ colorScheme: Qt.Dark
+ seriesColors: ["#2CDE85", "#DBEB00"]
+ grid.mainColor: c3
+ grid.subColor: c2
+ axisX.mainColor: c3
+ axisY.mainColor: c3
+ axisX.subColor: c2
+ axisY.subColor: c2
+ axisX.labelTextColor: c1
+ axisY.labelTextColor: c1
+ }
+ axisX: ValueAxis {
+ max: 5
+ tickInterval: 1
+ subTickCount: 9
+ labelDecimals: 1
+ }
+ axisY: ValueAxis {
+ max: 10
+ tickInterval: 1
+ subTickCount: 4
+ labelDecimals: 1
}
//! [linegraph]
@@ -99,31 +113,11 @@ Item {
}
//! [linemarker]
- //! [lineseriestheme]
- SeriesTheme {
- id: seriesTheme
- colors: ["#2CDE85", "#DBEB00"]
- }
- //! [lineseriestheme]
-
//! [lineseries1]
LineSeries {
id: lineSeries1
- theme: seriesTheme
- axisX: ValueAxis {
- max: 5
- tickInterval: 1
- minorTickCount: 9
- labelDecimals: 1
- }
- axisY: ValueAxis {
- max: 10
- tickInterval: 1
- minorTickCount: 4
- labelDecimals: 1
- }
width: 4
- pointMarker: Marker { }
+ pointDelegate: Marker { }
XYPoint { x: 0; y: 0 }
XYPoint { x: 1; y: 2.1 }
XYPoint { x: 2; y: 3.3 }
@@ -136,9 +130,8 @@ Item {
//! [lineseries2]
LineSeries {
id: lineSeries2
- theme: seriesTheme
width: 4
- pointMarker: Marker { }
+ pointDelegate: Marker { }
XYPoint { x: 0; y: 5.0 }
XYPoint { x: 1; y: 3.3 }
XYPoint { x: 2; y: 7.1 }
diff --git a/examples/graphs/3d/minimalsurfacegraph/main.py b/examples/graphs/3d/minimalsurfacegraph/main.py
index 6ef940b52..efdb7d550 100644
--- a/examples/graphs/3d/minimalsurfacegraph/main.py
+++ b/examples/graphs/3d/minimalsurfacegraph/main.py
@@ -6,10 +6,10 @@ import sys
from PySide6.QtCore import QSize
from PySide6.QtGui import QVector3D
-from PySide6.QtGraphs import (Q3DSurface, QSurfaceDataItem,
- QSurface3DSeries)
-from PySide6.QtWidgets import QApplication
+from PySide6.QtGraphs import (QSurfaceDataItem, QSurface3DSeries)
+from PySide6.QtGraphsWidgets import (Q3DSurfaceWidgetItem)
from PySide6.QtQuickWidgets import QQuickWidget
+from PySide6.QtWidgets import QApplication
DESCRIPTION = """Minimal Qt Graphs Surface Example
@@ -23,7 +23,9 @@ if __name__ == '__main__':
print(DESCRIPTION)
- surface = Q3DSurface()
+ window = QQuickWidget()
+ surface = Q3DSurfaceWidgetItem()
+ surface.setWidget(window)
axis = surface.axisX()
axis.setTitle("X")
axis.setTitleVisible(True)
@@ -48,8 +50,10 @@ if __name__ == '__main__':
available_height = app.primaryScreen().availableGeometry().height()
width = available_height * 4 / 5
- surface.resize(QSize(width, width))
- surface.setResizeMode(QQuickWidget.SizeRootObjectToView)
- surface.show()
+ window.resize(QSize(width, width))
+ window.show()
- sys.exit(app.exec())
+ exit_code = app.exec()
+ surface = None
+ del window
+ sys.exit(exit_code)
diff --git a/examples/graphs/3d/widgetgraphgallery/axesinputhandler.py b/examples/graphs/3d/widgetgraphgallery/axesinputhandler.py
deleted file mode 100644
index 2323d62e1..000000000
--- a/examples/graphs/3d/widgetgraphgallery/axesinputhandler.py
+++ /dev/null
@@ -1,101 +0,0 @@
-# Copyright (C) 2023 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from __future__ import annotations
-
-from enum import Enum
-from math import sin, cos, degrees
-
-from PySide6.QtCore import Qt
-from PySide6.QtGraphs import QAbstract3DGraph, Q3DInputHandler
-
-
-class InputState(Enum):
- StateNormal = 0
- StateDraggingX = 1
- StateDraggingZ = 2
- StateDraggingY = 3
-
-
-class AxesInputHandler(Q3DInputHandler):
-
- def __init__(self, graph, parent=None):
- super().__init__(parent)
- self._mousePressed = False
- self._state = InputState.StateNormal
- self._axisX = None
- self._axisZ = None
- self._axisY = None
- self._speedModifier = 15.0
-
- # Connect to the item selection signal from graph
- graph.selectedElementChanged.connect(self.handleElementSelected)
-
- def setAxes(self, axisX, axisZ, axisY):
- self._axisX = axisX
- self._axisZ = axisZ
- self._axisY = axisY
-
- def setDragSpeedModifier(self, modifier):
- self._speedModifier = modifier
-
- def mousePressEvent(self, event, mousePos):
- super().mousePressEvent(event, mousePos)
- if Qt.LeftButton == event.button():
- self._mousePressed = True
-
- def mouseMoveEvent(self, event, mousePos):
- # Check if we're trying to drag axis label
- if self._mousePressed and self._state != InputState.StateNormal:
- self.setPreviousInputPos(self.inputPosition())
- self.setInputPosition(mousePos)
- self.handleAxisDragging()
- else:
- super().mouseMoveEvent(event, mousePos)
-
- def mouseReleaseEvent(self, event, mousePos):
- super().mouseReleaseEvent(event, mousePos)
- self._mousePressed = False
- self._state = InputState.StateNormal
-
- def handleElementSelected(self, type):
- if type == QAbstract3DGraph.ElementAxisXLabel:
- self._state = InputState.StateDraggingX
- elif type == QAbstract3DGraph.ElementAxisYLabel:
- self._state = InputState.StateDraggingY
- elif type == QAbstract3DGraph.ElementAxisZLabel:
- self._state = InputState.StateDraggingZ
- else:
- self._state = InputState.StateNormal
-
- def handleAxisDragging(self):
- distance = 0.0
- # Get scene orientation from active camera
- xRotation = self.cameraXRotation()
- yRotation = self.cameraYRotation()
-
- # Calculate directional drag multipliers based on rotation
- xMulX = cos(degrees(xRotation))
- xMulY = sin(degrees(xRotation))
- zMulX = sin(degrees(xRotation))
- zMulY = cos(degrees(xRotation))
-
- # Get the drag amount
- move = self.inputPosition() - self.previousInputPos()
-
- # Flip the effect of y movement if we're viewing from below
- yMove = -move.y() if yRotation < 0 else move.y()
-
- # Adjust axes
- if self._state == InputState.StateDraggingX:
- distance = (move.x() * xMulX - yMove * xMulY) / self._speedModifier
- self._axisX.setRange(self._axisX.min() - distance,
- self._axisX.max() - distance)
- elif self._state == InputState.StateDraggingZ:
- distance = (move.x() * zMulX + yMove * zMulY) / self._speedModifier
- self._axisZ.setRange(self._axisZ.min() + distance,
- self._axisZ.max() + distance)
- elif self._state == InputState.StateDraggingY:
- # No need to use adjusted y move here
- distance = move.y() / self._speedModifier
- self._axisY.setRange(self._axisY.min() + distance,
- self._axisY.max() + distance)
diff --git a/examples/graphs/3d/widgetgraphgallery/bargraph.py b/examples/graphs/3d/widgetgraphgallery/bargraph.py
index 497916068..11ee67d4d 100644
--- a/examples/graphs/3d/widgetgraphgallery/bargraph.py
+++ b/examples/graphs/3d/widgetgraphgallery/bargraph.py
@@ -10,35 +10,38 @@ from PySide6.QtWidgets import (QButtonGroup, QCheckBox, QComboBox, QFontComboBox
QLabel, QPushButton, QHBoxLayout, QSizePolicy,
QRadioButton, QSlider, QVBoxLayout, QWidget)
from PySide6.QtQuickWidgets import QQuickWidget
-from PySide6.QtGraphs import (QAbstract3DGraph, QAbstract3DSeries, Q3DBars)
+from PySide6.QtGraphs import QAbstract3DSeries, QtGraphs3D
+from PySide6.QtGraphsWidgets import Q3DBarsWidgetItem
class BarGraph(QObject):
def __init__(self, minimum_graph_size, maximum_graph_size):
super().__init__()
- self._barsGraph = Q3DBars()
+
+ barsGraph = Q3DBarsWidgetItem()
+ barsGraphWidget = QQuickWidget()
+ barsGraph.setWidget(barsGraphWidget)
self._barsWidget = QWidget()
hLayout = QHBoxLayout(self._barsWidget)
- self._barsGraph.setMinimumSize(minimum_graph_size)
- self._barsGraph.setMaximumSize(maximum_graph_size)
- self._barsGraph.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
- self._barsGraph.setFocusPolicy(Qt.StrongFocus)
- self._barsGraph.setResizeMode(QQuickWidget.SizeRootObjectToView)
- hLayout.addWidget(self._barsGraph, 1)
+ barsGraphWidget.setMinimumSize(minimum_graph_size)
+ barsGraphWidget.setMaximumSize(maximum_graph_size)
+ barsGraphWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
+ barsGraphWidget.setFocusPolicy(Qt.StrongFocus)
+ hLayout.addWidget(barsGraphWidget, 1)
vLayout = QVBoxLayout()
hLayout.addLayout(vLayout)
themeList = QComboBox(self._barsWidget)
- themeList.addItem("Qt")
- themeList.addItem("Primary Colors")
- themeList.addItem("Digia")
- themeList.addItem("Stone Moss")
- themeList.addItem("Army Blue")
- themeList.addItem("Retro")
- themeList.addItem("Ebony")
- themeList.addItem("Isabelle")
+ themeList.addItem("QtGreen")
+ themeList.addItem("QtGreenNeon")
+ themeList.addItem("MixSeries")
+ themeList.addItem("OrangeSeries")
+ themeList.addItem("YellowSeries")
+ themeList.addItem("BlueSeries")
+ themeList.addItem("PurpleSeries")
+ themeList.addItem("GreySeries")
themeList.setCurrentIndex(0)
labelButton = QPushButton(self._barsWidget)
@@ -64,37 +67,37 @@ class BarGraph(QObject):
zoomToSelectedButton.setText("Zoom to selected bar")
selectionModeList = QComboBox(self._barsWidget)
- selectionModeList.addItem("None", QAbstract3DGraph.SelectionNone)
- selectionModeList.addItem("Bar", QAbstract3DGraph.SelectionItem)
- selectionModeList.addItem("Row", QAbstract3DGraph.SelectionRow)
- sel = QAbstract3DGraph.SelectionItemAndRow
+ selectionModeList.addItem("None", QtGraphs3D.SelectionFlag.None_)
+ selectionModeList.addItem("Bar", QtGraphs3D.SelectionFlag.Item)
+ selectionModeList.addItem("Row", QtGraphs3D.SelectionFlag.Row)
+ sel = QtGraphs3D.SelectionFlag.ItemAndRow
selectionModeList.addItem("Bar and Row", sel)
- selectionModeList.addItem("Column", QAbstract3DGraph.SelectionColumn)
- sel = QAbstract3DGraph.SelectionItemAndColumn
+ selectionModeList.addItem("Column", QtGraphs3D.SelectionFlag.Column)
+ sel = QtGraphs3D.SelectionFlag.ItemAndColumn
selectionModeList.addItem("Bar and Column", sel)
- sel = QAbstract3DGraph.SelectionRowAndColumn
+ sel = QtGraphs3D.SelectionFlag.RowAndColumn
selectionModeList.addItem("Row and Column", sel)
- sel = QAbstract3DGraph.SelectionItemRowAndColumn
+ sel = QtGraphs3D.SelectionFlag.RowAndColumn
selectionModeList.addItem("Bar, Row and Column", sel)
- sel = QAbstract3DGraph.SelectionSlice | QAbstract3DGraph.SelectionRow
+ sel = QtGraphs3D.SelectionFlag.Slice | QtGraphs3D.SelectionFlag.Row
selectionModeList.addItem("Slice into Row", sel)
- sel = QAbstract3DGraph.SelectionSlice | QAbstract3DGraph.SelectionItemAndRow
+ sel = QtGraphs3D.SelectionFlag.Slice | QtGraphs3D.SelectionFlag.ItemAndRow
selectionModeList.addItem("Slice into Row and Item", sel)
- sel = QAbstract3DGraph.SelectionSlice | QAbstract3DGraph.SelectionColumn
+ sel = QtGraphs3D.SelectionFlag.Slice | QtGraphs3D.SelectionFlag.Column
selectionModeList.addItem("Slice into Column", sel)
- sel = (QAbstract3DGraph.SelectionSlice
- | QAbstract3DGraph.SelectionItemAndColumn)
+ sel = (QtGraphs3D.SelectionFlag.Slice
+ | QtGraphs3D.SelectionFlag.ItemAndColumn)
selectionModeList.addItem("Slice into Column and Item", sel)
- sel = (QAbstract3DGraph.SelectionItemRowAndColumn
- | QAbstract3DGraph.SelectionMultiSeries)
+ sel = (QtGraphs3D.SelectionFlag.ItemRowAndColumn
+ | QtGraphs3D.SelectionFlag.MultiSeries)
selectionModeList.addItem("Multi: Bar, Row, Col", sel)
- sel = (QAbstract3DGraph.SelectionSlice
- | QAbstract3DGraph.SelectionItemAndRow
- | QAbstract3DGraph.SelectionMultiSeries)
+ sel = (QtGraphs3D.SelectionFlag.Slice
+ | QtGraphs3D.SelectionFlag.ItemAndRow
+ | QtGraphs3D.SelectionFlag.MultiSeries)
selectionModeList.addItem("Multi, Slice: Row, Item", sel)
- sel = (QAbstract3DGraph.SelectionSlice
- | QAbstract3DGraph.SelectionItemAndColumn
- | QAbstract3DGraph.SelectionMultiSeries)
+ sel = (QtGraphs3D.SelectionFlag.Slice
+ | QtGraphs3D.SelectionFlag.ItemAndColumn
+ | QtGraphs3D.SelectionFlag.MultiSeries)
selectionModeList.addItem("Multi, Slice: Col, Item", sel)
selectionModeList.setCurrentIndex(1)
@@ -219,50 +222,51 @@ class BarGraph(QObject):
vLayout.addWidget(modeWeather, 0, Qt.AlignTop)
vLayout.addWidget(modeCustomProxy, 1, Qt.AlignTop)
- self._modifier = GraphModifier(self._barsGraph, self)
+ modifier = GraphModifier(barsGraph, self)
+ modifier.changeTheme(themeList.currentIndex())
- rotationSliderX.valueChanged.connect(self._modifier.rotateX)
- rotationSliderY.valueChanged.connect(self._modifier.rotateY)
+ rotationSliderX.valueChanged.connect(modifier.rotateX)
+ rotationSliderY.valueChanged.connect(modifier.rotateY)
- labelButton.clicked.connect(self._modifier.changeLabelBackground)
- cameraButton.clicked.connect(self._modifier.changePresetCamera)
- zoomToSelectedButton.clicked.connect(self._modifier.zoomToSelectedBar)
+ labelButton.clicked.connect(modifier.changeLabelBackground)
+ cameraButton.clicked.connect(modifier.changePresetCamera)
+ zoomToSelectedButton.clicked.connect(modifier.zoomToSelectedBar)
- backgroundCheckBox.stateChanged.connect(self._modifier.setBackgroundEnabled)
- gridCheckBox.stateChanged.connect(self._modifier.setGridEnabled)
- smoothCheckBox.stateChanged.connect(self._modifier.setSmoothBars)
- seriesCheckBox.stateChanged.connect(self._modifier.setSeriesVisibility)
- reverseValueAxisCheckBox.stateChanged.connect(self._modifier.setReverseValueAxis)
- reflectionCheckBox.stateChanged.connect(self._modifier.setReflection)
+ backgroundCheckBox.stateChanged.connect(modifier.setPlotAreaBackgroundVisible)
+ gridCheckBox.stateChanged.connect(modifier.setGridVisible)
+ smoothCheckBox.stateChanged.connect(modifier.setSmoothBars)
+ seriesCheckBox.stateChanged.connect(modifier.setSeriesVisibility)
+ reverseValueAxisCheckBox.stateChanged.connect(modifier.setReverseValueAxis)
+ reflectionCheckBox.stateChanged.connect(modifier.setReflection)
- self._modifier.backgroundEnabledChanged.connect(backgroundCheckBox.setChecked)
- self._modifier.gridEnabledChanged.connect(gridCheckBox.setChecked)
+ modifier.backgroundVisibleChanged.connect(backgroundCheckBox.setChecked)
+ modifier.gridVisibleChanged.connect(gridCheckBox.setChecked)
- rangeList.currentIndexChanged.connect(self._modifier.changeRange)
+ rangeList.currentIndexChanged.connect(modifier.changeRange)
- barStyleList.currentIndexChanged.connect(self._modifier.changeStyle)
+ barStyleList.currentIndexChanged.connect(modifier.changeStyle)
- selectionModeList.currentIndexChanged.connect(self._modifier.changeSelectionMode)
+ selectionModeList.currentIndexChanged.connect(modifier.changeSelectionMode)
- themeList.currentIndexChanged.connect(self._modifier.changeTheme)
+ themeList.currentIndexChanged.connect(modifier.changeTheme)
- shadowQuality.currentIndexChanged.connect(self._modifier.changeShadowQuality)
+ shadowQuality.currentIndexChanged.connect(modifier.changeShadowQuality)
- self._modifier.shadowQualityChanged.connect(shadowQuality.setCurrentIndex)
- self._barsGraph.shadowQualityChanged.connect(self._modifier.shadowQualityUpdatedByVisual)
+ modifier.shadowQualityChanged.connect(shadowQuality.setCurrentIndex)
+ barsGraph.shadowQualityChanged.connect(modifier.shadowQualityUpdatedByVisual)
- fontSizeSlider.valueChanged.connect(self._modifier.changeFontSize)
- fontList.currentFontChanged.connect(self._modifier.changeFont)
+ fontSizeSlider.valueChanged.connect(modifier.changeFontSize)
+ fontList.currentFontChanged.connect(modifier.changeFont)
- self._modifier.fontSizeChanged.connect(fontSizeSlider.setValue)
- self._modifier.fontChanged.connect(fontList.setCurrentFont)
+ modifier.fontSizeChanged.connect(fontSizeSlider.setValue)
+ modifier.fontChanged.connect(fontList.setCurrentFont)
- axisTitlesVisibleCB.stateChanged.connect(self._modifier.setAxisTitleVisibility)
- axisTitlesFixedCB.stateChanged.connect(self._modifier.setAxisTitleFixed)
- axisLabelRotationSlider.valueChanged.connect(self._modifier.changeLabelRotation)
+ axisTitlesVisibleCB.stateChanged.connect(modifier.setAxisTitleVisibility)
+ axisTitlesFixedCB.stateChanged.connect(modifier.setAxisTitleFixed)
+ axisLabelRotationSlider.valueChanged.connect(modifier.changeLabelRotation)
- modeWeather.toggled.connect(self._modifier.setDataModeToWeather)
- modeCustomProxy.toggled.connect(self._modifier.setDataModeToCustom)
+ modeWeather.toggled.connect(modifier.setDataModeToWeather)
+ modeCustomProxy.toggled.connect(modifier.setDataModeToCustom)
modeWeather.toggled.connect(seriesCheckBox.setEnabled)
modeWeather.toggled.connect(rangeList.setEnabled)
modeWeather.toggled.connect(axisTitlesVisibleCB.setEnabled)
diff --git a/examples/graphs/3d/widgetgraphgallery/custominputhandler.py b/examples/graphs/3d/widgetgraphgallery/custominputhandler.py
deleted file mode 100644
index a33968091..000000000
--- a/examples/graphs/3d/widgetgraphgallery/custominputhandler.py
+++ /dev/null
@@ -1,178 +0,0 @@
-# Copyright (C) 2023 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from __future__ import annotations
-
-from enum import Enum
-from math import sin, cos, degrees
-
-from PySide6.QtCore import Qt
-from PySide6.QtGraphs import (QAbstract3DGraph, Q3DInputHandler)
-
-
-class InputState(Enum):
- StateNormal = 0
- StateDraggingX = 1
- StateDraggingZ = 2
- StateDraggingY = 3
-
-
-class CustomInputHandler(Q3DInputHandler):
-
- def __init__(self, graph, parent=None):
- super().__init__(parent)
- self._highlight = None
- self._mousePressed = False
- self._state = InputState.StateNormal
- self._axisX = None
- self._axisY = None
- self._axisZ = None
- self._speedModifier = 20.0
- self._aspectRatio = 0.0
- self._axisXMinValue = 0.0
- self._axisXMaxValue = 0.0
- self._axisXMinRange = 0.0
- self._axisZMinValue = 0.0
- self._axisZMaxValue = 0.0
- self._axisZMinRange = 0.0
- self._areaMinValue = 0.0
- self._areaMaxValue = 0.0
-
- # Connect to the item selection signal from graph
- graph.selectedElementChanged.connect(self.handleElementSelected)
-
- def setAspectRatio(self, ratio):
- self._aspectRatio = ratio
-
- def setHighlightSeries(self, series):
- self._highlight = series
-
- def setDragSpeedModifier(self, modifier):
- self._speedModifier = modifier
-
- def setLimits(self, min, max, minRange):
- self._areaMinValue = min
- self._areaMaxValue = max
- self._axisXMinValue = self._areaMinValue
- self._axisXMaxValue = self._areaMaxValue
- self._axisZMinValue = self._areaMinValue
- self._axisZMaxValue = self._areaMaxValue
- self._axisXMinRange = minRange
- self._axisZMinRange = minRange
-
- def setAxes(self, axisX, axisY, axisZ):
- self._axisX = axisX
- self._axisY = axisY
- self._axisZ = axisZ
-
- def mousePressEvent(self, event, mousePos):
- if Qt.LeftButton == event.button():
- self._highlight.setVisible(False)
- self._mousePressed = True
- super().mousePressEvent(event, mousePos)
-
- def wheelEvent(self, event):
- delta = float(event.angleDelta().y())
-
- self._axisXMinValue += delta
- self._axisXMaxValue -= delta
- self._axisZMinValue += delta
- self._axisZMaxValue -= delta
- self.checkConstraints()
-
- y = (self._axisXMaxValue - self._axisXMinValue) * self._aspectRatio
-
- self._axisX.setRange(self._axisXMinValue, self._axisXMaxValue)
- self._axisY.setRange(100.0, y)
- self._axisZ.setRange(self._axisZMinValue, self._axisZMaxValue)
-
- def mouseMoveEvent(self, event, mousePos):
- # Check if we're trying to drag axis label
- if self._mousePressed and self._state != InputState.StateNormal:
- self.setPreviousInputPos(self.inputPosition())
- self.setInputPosition(mousePos)
- self.handleAxisDragging()
- else:
- super().mouseMoveEvent(event, mousePos)
-
- def mouseReleaseEvent(self, event, mousePos):
- super().mouseReleaseEvent(event, mousePos)
- self._mousePressed = False
- self._state = InputState.StateNormal
-
- def handleElementSelected(self, type):
- if type == QAbstract3DGraph.ElementAxisXLabel:
- self._state = InputState.StateDraggingX
- elif type == QAbstract3DGraph.ElementAxisZLabel:
- self._state = InputState.StateDraggingZ
- else:
- self._state = InputState.StateNormal
-
- def handleAxisDragging(self):
- distance = 0.0
-
- # Get scene orientation from active camera
- xRotation = self.scene().cameraXRotation()
-
- # Calculate directional drag multipliers based on rotation
- xMulX = cos(degrees(xRotation))
- xMulY = sin(degrees(xRotation))
- zMulX = xMulY
- zMulY = xMulX
-
- # Get the drag amount
- move = self.inputPosition() - self.previousInputPos()
-
- # Adjust axes
- if self._state == InputState.StateDraggingX:
- distance = (move.x() * xMulX - move.y() * xMulY) * self._speedModifier
- self._axisXMinValue -= distance
- self._axisXMaxValue -= distance
- if self._axisXMinValue < self._areaMinValue:
- dist = self._axisXMaxValue - self._axisXMinValue
- self._axisXMinValue = self._areaMinValue
- self._axisXMaxValue = self._axisXMinValue + dist
-
- if self._axisXMaxValue > self._areaMaxValue:
- dist = self._axisXMaxValue - self._axisXMinValue
- self._axisXMaxValue = self._areaMaxValue
- self._axisXMinValue = self._axisXMaxValue - dist
-
- self._axisX.setRange(self._axisXMinValue, self._axisXMaxValue)
- elif self._state == InputState.StateDraggingZ:
- distance = (move.x() * zMulX + move.y() * zMulY) * self._speedModifier
- self._axisZMinValue += distance
- self._axisZMaxValue += distance
- if self._axisZMinValue < self._areaMinValue:
- dist = self._axisZMaxValue - self._axisZMinValue
- self._axisZMinValue = self._areaMinValue
- self._axisZMaxValue = self._axisZMinValue + dist
-
- if self._axisZMaxValue > self._areaMaxValue:
- dist = self._axisZMaxValue - self._axisZMinValue
- self._axisZMaxValue = self._areaMaxValue
- self._axisZMinValue = self._axisZMaxValue - dist
-
- self._axisZ.setRange(self._axisZMinValue, self._axisZMaxValue)
-
- def checkConstraints(self):
- if self._axisXMinValue < self._areaMinValue:
- self._axisXMinValue = self._areaMinValue
- if self._axisXMaxValue > self._areaMaxValue:
- self._axisXMaxValue = self._areaMaxValue
- # Don't allow too much zoom in
- range = self._axisXMaxValue - self._axisXMinValue
- if range < self._axisXMinRange:
- adjust = (self._axisXMinRange - range) / 2.0
- self._axisXMinValue -= adjust
- self._axisXMaxValue += adjust
-
- if self._axisZMinValue < self._areaMinValue:
- self._axisZMinValue = self._areaMinValue
- if self._axisZMaxValue > self._areaMaxValue:
- self._axisZMaxValue = self._areaMaxValue
- # Don't allow too much zoom in
- range = self._axisZMaxValue - self._axisZMinValue
- if range < self._axisZMinRange:
- adjust = (self._axisZMinRange - range) / 2.0
- self._axisZMinValue -= adjust
- self._axisZMaxValue += adjust
diff --git a/examples/graphs/3d/widgetgraphgallery/graphmodifier.py b/examples/graphs/3d/widgetgraphgallery/graphmodifier.py
index 678864ac3..8c66cab10 100644
--- a/examples/graphs/3d/widgetgraphgallery/graphmodifier.py
+++ b/examples/graphs/3d/widgetgraphgallery/graphmodifier.py
@@ -8,9 +8,9 @@ import numpy as np
from PySide6.QtCore import QObject, QPropertyAnimation, Signal, Slot
from PySide6.QtGui import QFont, QVector3D
-from PySide6.QtGraphs import (QAbstract3DGraph, QAbstract3DSeries,
+from PySide6.QtGraphs import (QAbstract3DSeries,
QBarDataItem, QBar3DSeries, QCategory3DAxis,
- QValue3DAxis, Q3DTheme)
+ QValue3DAxis, QtGraphs3D, QGraphsTheme)
from rainfalldata import RainfallData
@@ -42,8 +42,8 @@ TEMP_HELSINKI = np.array([
class GraphModifier(QObject):
shadowQualityChanged = Signal(int)
- backgroundEnabledChanged = Signal(bool)
- gridEnabledChanged = Signal(bool)
+ backgroundVisibleChanged = Signal(bool)
+ gridVisibleChanged = Signal(bool)
fontChanged = Signal(QFont)
fontSizeChanged = Signal(int)
@@ -76,11 +76,11 @@ class GraphModifier(QObject):
self._defaultTarget = []
self._customData = None
- self._graph.setShadowQuality(QAbstract3DGraph.ShadowQuality.SoftMedium)
+ self._graph.setShadowQuality(QtGraphs3D.ShadowQuality.SoftMedium)
theme = self._graph.activeTheme()
- theme.setBackgroundEnabled(False)
- theme.setFont(QFont("Times New Roman", self._fontSize))
- theme.setLabelBackgroundEnabled(True)
+ theme.setPlotAreaBackgroundVisible(False)
+ theme.setLabelFont(QFont("Times New Roman", self._fontSize))
+ theme.setLabelBackgroundVisible(True)
self._graph.setMultiSeriesUniform(True)
self._months = ["January", "February", "March", "April", "May", "June",
@@ -94,14 +94,14 @@ class GraphModifier(QObject):
self._temperatureAxis.setSubSegmentCount(self._subSegments)
self._temperatureAxis.setRange(self._minval, self._maxval)
self._temperatureAxis.setLabelFormat("%.1f " + self._celsiusString)
- self._temperatureAxis.setLabelAutoRotation(30.0)
+ self._temperatureAxis.setLabelAutoAngle(30.0)
self._temperatureAxis.setTitleVisible(True)
self._yearAxis.setTitle("Year")
- self._yearAxis.setLabelAutoRotation(30.0)
+ self._yearAxis.setLabelAutoAngle(30.0)
self._yearAxis.setTitleVisible(True)
self._monthAxis.setTitle("Month")
- self._monthAxis.setLabelAutoRotation(30.0)
+ self._monthAxis.setLabelAutoAngle(30.0)
self._monthAxis.setTitleVisible(True)
self._graph.setValueAxis(self._temperatureAxis)
@@ -208,54 +208,54 @@ class GraphModifier(QObject):
# Restore camera target in case animation has changed it
self._graph.setCameraTargetPosition(QVector3D(0.0, 0.0, 0.0))
- self._preset = QAbstract3DGraph.CameraPreset.Front.value
+ self._preset = QtGraphs3D.CameraPreset.Front.value
- self._graph.setCameraPreset(QAbstract3DGraph.CameraPreset(self._preset))
+ self._graph.setCameraPreset(QtGraphs3D.CameraPreset(self._preset))
self._preset += 1
- if self._preset > QAbstract3DGraph.CameraPreset.DirectlyBelow.value:
- self._preset = QAbstract3DGraph.CameraPreset.FrontLow.value
+ if self._preset > QtGraphs3D.CameraPreset.DirectlyBelow.value:
+ self._preset = QtGraphs3D.CameraPreset.FrontLow.value
@Slot(int)
def changeTheme(self, theme):
currentTheme = self._graph.activeTheme()
- currentTheme.setType(Q3DTheme.Theme(theme))
- self.backgroundEnabledChanged.emit(currentTheme.isBackgroundEnabled())
- self.gridEnabledChanged.emit(currentTheme.isGridEnabled())
- self.fontChanged.emit(currentTheme.font())
- self.fontSizeChanged.emit(currentTheme.font().pointSize())
+ currentTheme.setTheme(QGraphsTheme.Theme(theme))
+ self.backgroundVisibleChanged.emit(currentTheme.isBackgroundVisible())
+ self.gridVisibleChanged.emit(currentTheme.isGridVisible())
+ self.fontChanged.emit(currentTheme.labelFont())
+ self.fontSizeChanged.emit(currentTheme.labelFont().pointSize())
def changeLabelBackground(self):
theme = self._graph.activeTheme()
- theme.setLabelBackgroundEnabled(not theme.isLabelBackgroundEnabled())
+ theme.setLabelBackgroundVisible(not theme.isLabelBackgroundVisible())
@Slot(int)
def changeSelectionMode(self, selectionMode):
comboBox = self.sender()
if comboBox:
flags = comboBox.itemData(selectionMode)
- self._graph.setSelectionMode(QAbstract3DGraph.SelectionFlags(flags))
+ self._graph.setSelectionMode(QtGraphs3D.SelectionFlags(flags))
def changeFont(self, font):
newFont = font
- self._graph.activeTheme().setFont(newFont)
+ self._graph.activeTheme().setLabelFont(newFont)
def changeFontSize(self, fontsize):
self._fontSize = fontsize
- font = self._graph.activeTheme().font()
+ font = self._graph.activeTheme().labelFont()
font.setPointSize(self._fontSize)
- self._graph.activeTheme().setFont(font)
+ self._graph.activeTheme().setLabelFont(font)
- @Slot(QAbstract3DGraph.ShadowQuality)
+ @Slot(QtGraphs3D.ShadowQuality)
def shadowQualityUpdatedByVisual(self, sq):
# Updates the UI component to show correct shadow quality
self.shadowQualityChanged.emit(sq.value)
@Slot(int)
def changeLabelRotation(self, rotation):
- self._temperatureAxis.setLabelAutoRotation(float(rotation))
- self._monthAxis.setLabelAutoRotation(float(rotation))
- self._yearAxis.setLabelAutoRotation(float(rotation))
+ self._temperatureAxis.setLabelAutoAngle(float(rotation))
+ self._monthAxis.setLabelAutoAngle(float(rotation))
+ self._yearAxis.setLabelAutoAngle(float(rotation))
@Slot(bool)
def setAxisTitleVisibility(self, enabled):
@@ -339,25 +339,23 @@ class GraphModifier(QObject):
self.changeDataMode(True)
def changeShadowQuality(self, quality):
- sq = QAbstract3DGraph.ShadowQuality(quality)
+ sq = QtGraphs3D.ShadowQuality(quality)
self._graph.setShadowQuality(sq)
self.shadowQualityChanged.emit(quality)
def rotateX(self, rotation):
self._xRotation = rotation
- camera = self._graph.scene().activeCamera()
- camera.setCameraPosition(self._xRotation, self._yRotation)
+ self._graph.setCameraPosition(self._xRotation, self._yRotation)
def rotateY(self, rotation):
self._yRotation = rotation
- camera = self._graph.scene().activeCamera()
- camera.setCameraPosition(self._xRotation, self._yRotation)
+ self._graph.setCameraPosition(self._xRotation, self._yRotation)
- def setBackgroundEnabled(self, enabled):
- self._graph.activeTheme().setBackgroundEnabled(bool(enabled))
+ def setPlotAreaBackgroundVisible(self, enabled):
+ self._graph.activeTheme().setPlotAreaBackgroundVisible(bool(enabled))
- def setGridEnabled(self, enabled):
- self._graph.activeTheme().setGridEnabled(bool(enabled))
+ def setGridVisible(self, enabled):
+ self._graph.activeTheme().setGridVisible(bool(enabled))
def setSmoothBars(self, smooth):
self._smooth = bool(smooth)
diff --git a/examples/graphs/3d/widgetgraphgallery/highlightseries.py b/examples/graphs/3d/widgetgraphgallery/highlightseries.py
index fce1bd0ac..e6e1af3df 100644
--- a/examples/graphs/3d/widgetgraphgallery/highlightseries.py
+++ b/examples/graphs/3d/widgetgraphgallery/highlightseries.py
@@ -4,7 +4,8 @@ from __future__ import annotations
from PySide6.QtCore import QPoint, Qt, Slot
from PySide6.QtGui import QLinearGradient, QVector3D
-from PySide6.QtGraphs import (QSurface3DSeries, QSurfaceDataItem, Q3DTheme)
+from PySide6.QtGraphs import (QSurface3DSeries, QSurfaceDataItem,
+ QGraphsTheme)
DARK_RED_POS = 1.0
@@ -26,12 +27,12 @@ class HighlightSeries(QSurface3DSeries):
self._topographicSeries = None
self._minHeight = 0.0
self.setDrawMode(QSurface3DSeries.DrawSurface)
- self.setFlatShadingEnabled(True)
+ self.setShading(QSurface3DSeries.Shading.Flat)
self.setVisible(False)
def setTopographicSeries(self, series):
self._topographicSeries = series
- array = self._topographicSeries.dataProxy().array()
+ array = self._topographicSeries.dataArray()
self._srcWidth = len(array[0])
self._srcHeight = len(array)
self._topographicSeries.selectedPointChanged.connect(self.handlePositionChange)
@@ -63,8 +64,7 @@ class HighlightSeries(QSurface3DSeries):
if endZ > (self._srcHeight - 1):
endZ = self._srcHeight - 1
- srcProxy = self._topographicSeries.dataProxy()
- srcArray = srcProxy.array()
+ srcArray = self._topographicSeries.dataArray()
dataArray = []
for i in range(int(startZ), int(endZ)):
@@ -92,4 +92,4 @@ class HighlightSeries(QSurface3DSeries):
gr.setColorAt(DARK_RED_POS * ratio, Qt.darkRed)
self.setBaseGradient(gr)
- self.setColorStyle(Q3DTheme.ColorStyle.RangeGradient)
+ self.setColorStyle(QGraphsTheme.ColorStyle.RangeGradient)
diff --git a/examples/graphs/3d/widgetgraphgallery/main.py b/examples/graphs/3d/widgetgraphgallery/main.py
index d8380486b..7a5bfe458 100644
--- a/examples/graphs/3d/widgetgraphgallery/main.py
+++ b/examples/graphs/3d/widgetgraphgallery/main.py
@@ -14,29 +14,37 @@ from scattergraph import ScatterGraph
from surfacegraph import SurfaceGraph
-if __name__ == "__main__":
- app = QApplication(sys.argv)
+class MainWidget(QTabWidget):
+ """Tab widget for creating own tabs for Q3DBars, Q3DScatter, and Q3DSurface"""
- # Create a tab widget for creating own tabs for Q3DBars, Q3DScatter, and Q3DSurface
- tabWidget = QTabWidget()
- tabWidget.setWindowTitle("Widget Gallery")
+ def __init__(self, p=None):
+ super().__init__(p)
+
+ screen_size = self.screen().size()
+ minimum_graph_size = QSize(screen_size.width() / 2, screen_size.height() / 1.75)
+
+ # Create bar graph
+ self._bars = BarGraph(minimum_graph_size, screen_size)
+ # Create scatter graph
+ self._scatter = ScatterGraph(minimum_graph_size, screen_size)
+ # Create surface graph
+ self._surface = SurfaceGraph(minimum_graph_size, screen_size)
- screen_size = tabWidget.screen().size()
- minimum_graph_size = QSize(screen_size.width() / 2, screen_size.height() / 1.75)
+ # Add bars widget
+ self.addTab(self._bars.barsWidget(), "Bar Graph")
+ # Add scatter widget
+ self.addTab(self._scatter.scatterWidget(), "Scatter Graph")
+ # Add surface widget
+ self.addTab(self._surface.surfaceWidget(), "Surface Graph")
- # Create bar graph
- bars = BarGraph(minimum_graph_size, screen_size)
- # Create scatter graph
- scatter = ScatterGraph(minimum_graph_size, screen_size)
- # Create surface graph
- surface = SurfaceGraph(minimum_graph_size, screen_size)
- # Add bars widget
- tabWidget.addTab(bars.barsWidget(), "Bar Graph")
- # Add scatter widget
- tabWidget.addTab(scatter.scatterWidget(), "Scatter Graph")
- # Add surface widget
- tabWidget.addTab(surface.surfaceWidget(), "Surface Graph")
+if __name__ == "__main__":
+ app = QApplication(sys.argv)
+
+ tabWidget = MainWidget()
+ tabWidget.setWindowTitle("Widget Gallery")
tabWidget.show()
- sys.exit(app.exec())
+ exit_code = app.exec()
+ del tabWidget
+ sys.exit(exit_code)
diff --git a/examples/graphs/3d/widgetgraphgallery/scatterdatamodifier.py b/examples/graphs/3d/widgetgraphgallery/scatterdatamodifier.py
index 8d6cde59f..f66a295e8 100644
--- a/examples/graphs/3d/widgetgraphgallery/scatterdatamodifier.py
+++ b/examples/graphs/3d/widgetgraphgallery/scatterdatamodifier.py
@@ -2,15 +2,14 @@
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
from __future__ import annotations
-from math import cos, degrees, sqrt
+from enum import Enum
+from math import sin, cos, degrees, sqrt
from PySide6.QtCore import QObject, Signal, Slot, Qt
-from PySide6.QtGui import QVector3D
-from PySide6.QtGraphs import (QAbstract3DGraph, QAbstract3DSeries,
+from PySide6.QtGui import QVector2D, QVector3D
+from PySide6.QtGraphs import (QAbstract3DSeries,
QScatterDataItem, QScatterDataProxy,
- QScatter3DSeries, Q3DTheme)
-
-from axesinputhandler import AxesInputHandler
+ QScatter3DSeries, QtGraphs3D, QGraphsTheme)
NUMBER_OF_ITEMS = 10000
@@ -19,10 +18,17 @@ LOWER_NUMBER_OF_ITEMS = 900
LOWER_CURVE_DIVIDER = 0.75
+class InputState(Enum):
+ StateNormal = 0
+ StateDraggingX = 1
+ StateDraggingZ = 2
+ StateDraggingY = 3
+
+
class ScatterDataModifier(QObject):
backgroundEnabledChanged = Signal(bool)
- gridEnabledChanged = Signal(bool)
+ gridVisibleChanged = Signal(bool)
shadowQualityChanged = Signal(int)
def __init__(self, scatter, parent):
@@ -32,15 +38,14 @@ class ScatterDataModifier(QObject):
self._style = QAbstract3DSeries.Mesh.Sphere
self._smooth = True
- self._inputHandler = AxesInputHandler(scatter)
self._autoAdjust = True
self._itemCount = LOWER_NUMBER_OF_ITEMS
self._CURVE_DIVIDER = LOWER_CURVE_DIVIDER
- self._inputHandler = AxesInputHandler(scatter)
- self._graph.activeTheme().setType(Q3DTheme.Theme.StoneMoss)
- self._graph.setShadowQuality(QAbstract3DGraph.ShadowQuality.SoftHigh)
- self._graph.setCameraPreset(QAbstract3DGraph.CameraPreset.Front)
+ self._graph.activeTheme().setTheme(QGraphsTheme.Theme.MixSeries)
+ self._graph.activeTheme().setColorScheme(QGraphsTheme.ColorScheme.Dark)
+ self._graph.setShadowQuality(QtGraphs3D.ShadowQuality.SoftHigh)
+ self._graph.setCameraPreset(QtGraphs3D.CameraPreset.Front)
self._graph.setCameraZoomLevel(80.0)
self._proxy = QScatterDataProxy()
@@ -48,15 +53,14 @@ class ScatterDataModifier(QObject):
self._series.setItemLabelFormat("@xTitle: @xLabel @yTitle: @yLabel @zTitle: @zLabel")
self._series.setMeshSmooth(self._smooth)
self._graph.addSeries(self._series)
- self._preset = QAbstract3DGraph.CameraPreset.FrontLow.value
+ self._preset = QtGraphs3D.CameraPreset.FrontLow.value
- # Give ownership of the handler to the graph and make it the active
- # handler
- self._graph.setActiveInputHandler(self._inputHandler)
+ self._state = InputState.StateNormal
+ self._dragSpeedModifier = float(15)
- # Give our axes to the input handler
- self._inputHandler.setAxes(self._graph.axisX(), self._graph.axisZ(),
- self._graph.axisY())
+ self._graph.selectedElementChanged.connect(self.handleElementSelected)
+ self._graph.dragged.connect(self.handleAxisDragging)
+ self._graph.setDragButton(Qt.LeftButton)
self.addData()
@@ -94,35 +98,34 @@ class ScatterDataModifier(QObject):
@Slot(int)
def changeTheme(self, theme):
currentTheme = self._graph.activeTheme()
- currentTheme.setType(Q3DTheme.Theme(theme))
- self.backgroundEnabledChanged.emit(currentTheme.isBackgroundEnabled())
- self.gridEnabledChanged.emit(currentTheme.isGridEnabled())
+ currentTheme.setTheme(QGraphsTheme.Theme(theme))
+ self.backgroundEnabledChanged.emit(currentTheme.isPlotAreaBackgroundVisible())
+ self.gridVisibleChanged.emit(currentTheme.isGridVisible())
@Slot()
def changePresetCamera(self):
- camera = self._graph.scene().activeCamera()
- camera.setCameraPreset(QAbstract3DGraph.CameraPreset(self._preset))
+ self._graph.setCameraPreset(QtGraphs3D.CameraPreset(self._preset))
self._preset += 1
- if self._preset > QAbstract3DGraph.CameraPreset.DirectlyBelow.value:
- self._preset = QAbstract3DGraph.CameraPreset.FrontLow.value
+ if self._preset > QtGraphs3D.CameraPreset.DirectlyBelow.value:
+ self._preset = QtGraphs3D.CameraPreset.FrontLow.value
- @Slot(QAbstract3DGraph.ShadowQuality)
+ @Slot(QtGraphs3D.ShadowQuality)
def shadowQualityUpdatedByVisual(self, sq):
self.shadowQualityChanged.emit(sq.value)
@Slot(int)
def changeShadowQuality(self, quality):
- sq = QAbstract3DGraph.ShadowQuality(quality)
+ sq = QtGraphs3D.ShadowQuality(quality)
self._graph.setShadowQuality(sq)
@Slot(int)
- def setBackgroundEnabled(self, enabled):
- self._graph.activeTheme().setBackgroundEnabled(enabled == Qt.Checked.value)
+ def setPlotAreaBackgroundVisible(self, enabled):
+ self._graph.activeTheme().setPlotAreaBackgroundVisible(enabled == Qt.Checked.value)
@Slot(int)
- def setGridEnabled(self, enabled):
- self._graph.activeTheme().setGridEnabled(enabled == Qt.Checked.value)
+ def setGridVisible(self, enabled):
+ self._graph.activeTheme().setGridVisible(enabled == Qt.Checked.value)
@Slot()
def toggleItemCount(self):
@@ -141,10 +144,55 @@ class ScatterDataModifier(QObject):
if not self._autoAdjust:
self._graph.axisX().setAutoAdjustRange(True)
self._graph.axisZ().setAutoAdjustRange(True)
- self._inputHandler.setDragSpeedModifier(1.5)
+ self._dragSpeedModifier = 1.5
self._autoAdjust = True
else:
self._graph.axisX().setRange(-10.0, 10.0)
self._graph.axisZ().setRange(-10.0, 10.0)
- self._inputHandler.setDragSpeedModifier(15.0)
+ self._dragSpeedModifier = float(15)
self._autoAdjust = False
+
+ @Slot(QtGraphs3D.ElementType)
+ def handleElementSelected(self, type):
+ if type == QtGraphs3D.ElementType.AxisXLabel:
+ self._state = InputState.StateDraggingX
+ elif type == QtGraphs3D.ElementType.AxisYLabel:
+ self._state = InputState.StateDraggingY
+ elif type == QtGraphs3D.ElementType.AxisZLabel:
+ self._state = InputState.StateDraggingZ
+ else:
+ self._state = InputState.StateNormal
+
+ @Slot(QVector2D)
+ def handleAxisDragging(self, delta):
+ distance = 0.0
+ # Get scene orientation from active camera
+ xRotation = self._graph.cameraXRotation()
+ yRotation = self._graph.cameraYRotation()
+
+ # Calculate directional drag multipliers based on rotation
+ xMulX = cos(degrees(xRotation))
+ xMulY = sin(degrees(xRotation))
+ zMulX = sin(degrees(xRotation))
+ zMulY = cos(degrees(xRotation))
+
+ # Get the drag amount
+ move = delta.toPoint()
+
+ # Flip the effect of y movement if we're viewing from below
+ yMove = -move.y() if yRotation < 0 else move.y()
+
+ # Adjust axes
+ if self._state == InputState.StateDraggingX:
+ axis = self._graph.axisX()
+ distance = (move.x() * xMulX - yMove * xMulY) / self._dragSpeedModifier
+ axis.setRange(axis.min() - distance, axis.max() - distance)
+ elif self._state == InputState.StateDraggingZ:
+ axis = self._graph.axisZ()
+ distance = (move.x() * zMulX + yMove * zMulY) / self._dragSpeedModifier
+ axis.setRange(axis.min() + distance, axis.max() + distance)
+ elif self._state == InputState.StateDraggingY:
+ axis = self._graph.axisY()
+ # No need to use adjusted y move here
+ distance = move.y() / self._dragSpeedModifier
+ axis.setRange(axis.min() + distance, axis.max() + distance)
diff --git a/examples/graphs/3d/widgetgraphgallery/scattergraph.py b/examples/graphs/3d/widgetgraphgallery/scattergraph.py
index 9cf5ff33a..5c8d01e37 100644
--- a/examples/graphs/3d/widgetgraphgallery/scattergraph.py
+++ b/examples/graphs/3d/widgetgraphgallery/scattergraph.py
@@ -7,7 +7,8 @@ from PySide6.QtWidgets import (QCheckBox, QComboBox, QCommandLinkButton,
QLabel, QHBoxLayout, QSizePolicy,
QVBoxLayout, QWidget, )
from PySide6.QtQuickWidgets import QQuickWidget
-from PySide6.QtGraphs import (QAbstract3DSeries, Q3DScatter)
+from PySide6.QtGraphs import QAbstract3DSeries
+from PySide6.QtGraphsWidgets import Q3DScatterWidgetItem
from scatterdatamodifier import ScatterDataModifier
@@ -16,15 +17,17 @@ class ScatterGraph(QObject):
def __init__(self, minimum_graph_size, maximum_graph_size):
super().__init__()
- self._scatterGraph = Q3DScatter()
+
+ scatterGraph = Q3DScatterWidgetItem()
+ scatterGraphWidget = QQuickWidget()
+ scatterGraph.setWidget(scatterGraphWidget)
self._scatterWidget = QWidget()
hLayout = QHBoxLayout(self._scatterWidget)
- self._scatterGraph.setMinimumSize(minimum_graph_size)
- self._scatterGraph.setMaximumSize(maximum_graph_size)
- self._scatterGraph.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
- self._scatterGraph.setFocusPolicy(Qt.StrongFocus)
- self._scatterGraph.setResizeMode(QQuickWidget.SizeRootObjectToView)
- hLayout.addWidget(self._scatterGraph, 1)
+ scatterGraphWidget.setMinimumSize(minimum_graph_size)
+ scatterGraphWidget.setMaximumSize(maximum_graph_size)
+ scatterGraphWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
+ scatterGraphWidget.setFocusPolicy(Qt.StrongFocus)
+ hLayout.addWidget(scatterGraphWidget, 1)
vLayout = QVBoxLayout()
hLayout.addLayout(vLayout)
@@ -45,7 +48,7 @@ class ScatterGraph(QObject):
rangeButton.setIconSize(QSize(0, 0))
backgroundCheckBox = QCheckBox(self._scatterWidget)
- backgroundCheckBox.setText("Show background")
+ backgroundCheckBox.setText("Show graph background")
backgroundCheckBox.setChecked(True)
gridCheckBox = QCheckBox(self._scatterWidget)
@@ -97,26 +100,26 @@ class ScatterGraph(QObject):
vLayout.addWidget(QLabel("Adjust shadow quality"))
vLayout.addWidget(shadowQuality, 1, Qt.AlignTop)
- self._modifier = ScatterDataModifier(self._scatterGraph, self)
+ modifier = ScatterDataModifier(scatterGraph, self)
- cameraButton.clicked.connect(self._modifier.changePresetCamera)
- itemCountButton.clicked.connect(self._modifier.toggleItemCount)
- rangeButton.clicked.connect(self._modifier.toggleRanges)
+ cameraButton.clicked.connect(modifier.changePresetCamera)
+ itemCountButton.clicked.connect(modifier.toggleItemCount)
+ rangeButton.clicked.connect(modifier.toggleRanges)
- backgroundCheckBox.stateChanged.connect(self._modifier.setBackgroundEnabled)
- gridCheckBox.stateChanged.connect(self._modifier.setGridEnabled)
- smoothCheckBox.stateChanged.connect(self._modifier.setSmoothDots)
+ backgroundCheckBox.stateChanged.connect(modifier.setPlotAreaBackgroundVisible)
+ gridCheckBox.stateChanged.connect(modifier.setGridVisible)
+ smoothCheckBox.stateChanged.connect(modifier.setSmoothDots)
- self._modifier.backgroundEnabledChanged.connect(backgroundCheckBox.setChecked)
- self._modifier.gridEnabledChanged.connect(gridCheckBox.setChecked)
- itemStyleList.currentIndexChanged.connect(self._modifier.changeStyle)
+ modifier.backgroundEnabledChanged.connect(backgroundCheckBox.setChecked)
+ modifier.gridVisibleChanged.connect(gridCheckBox.setChecked)
+ itemStyleList.currentIndexChanged.connect(modifier.changeStyle)
- themeList.currentIndexChanged.connect(self._modifier.changeTheme)
+ themeList.currentIndexChanged.connect(modifier.changeTheme)
- shadowQuality.currentIndexChanged.connect(self._modifier.changeShadowQuality)
+ shadowQuality.currentIndexChanged.connect(modifier.changeShadowQuality)
- self._modifier.shadowQualityChanged.connect(shadowQuality.setCurrentIndex)
- self._scatterGraph.shadowQualityChanged.connect(self._modifier.shadowQualityUpdatedByVisual)
+ modifier.shadowQualityChanged.connect(shadowQuality.setCurrentIndex)
+ scatterGraph.shadowQualityChanged.connect(modifier.shadowQualityUpdatedByVisual)
def scatterWidget(self):
return self._scatterWidget
diff --git a/examples/graphs/3d/widgetgraphgallery/surfacegraph.py b/examples/graphs/3d/widgetgraphgallery/surfacegraph.py
index 5c0bc61c8..db57090e4 100644
--- a/examples/graphs/3d/widgetgraphgallery/surfacegraph.py
+++ b/examples/graphs/3d/widgetgraphgallery/surfacegraph.py
@@ -10,7 +10,7 @@ from PySide6.QtWidgets import (QGroupBox, QCheckBox, QLabel, QHBoxLayout,
QPushButton, QRadioButton, QSizePolicy, QSlider,
QVBoxLayout, QWidget)
from PySide6.QtQuickWidgets import QQuickWidget
-from PySide6.QtGraphs import Q3DSurface
+from PySide6.QtGraphsWidgets import Q3DSurfaceWidgetItem
def gradientBtoYPB_Pixmap():
@@ -72,15 +72,18 @@ class SurfaceGraph(QObject):
def __init__(self, minimum_graph_size, maximum_graph_size):
super().__init__()
- self._surfaceGraph = Q3DSurface()
+
+ surfaceGraphWidget = QQuickWidget()
+ surfaceGraph = Q3DSurfaceWidgetItem()
+ surfaceGraph.setWidget(surfaceGraphWidget)
self._surfaceWidget = QWidget()
hLayout = QHBoxLayout(self._surfaceWidget)
- self._surfaceGraph.setMinimumSize(minimum_graph_size)
- self._surfaceGraph.setMaximumSize(maximum_graph_size)
- self._surfaceGraph.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
- self._surfaceGraph.setFocusPolicy(Qt.StrongFocus)
- self._surfaceGraph.setResizeMode(QQuickWidget.SizeRootObjectToView)
- hLayout.addWidget(self._surfaceGraph, 1)
+ surfaceGraphWidget.setMinimumSize(minimum_graph_size)
+ surfaceGraphWidget.setMaximumSize(maximum_graph_size)
+ surfaceGraphWidget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
+ surfaceGraphWidget.setFocusPolicy(Qt.StrongFocus)
+ surfaceGraphWidget.setResizeMode(QQuickWidget.SizeRootObjectToView)
+ hLayout.addWidget(surfaceGraphWidget, 1)
vLayout = QVBoxLayout()
hLayout.addLayout(vLayout)
vLayout.setAlignment(Qt.AlignTop)
@@ -214,7 +217,7 @@ class SurfaceGraph(QObject):
vLayout.addWidget(heightMapGroupBox)
vLayout.addWidget(enableTexture)
# Create the controller
- modifier = SurfaceGraphModifier(self._surfaceGraph, labelSelectedItem, self)
+ modifier = SurfaceGraphModifier(surfaceGraph, labelSelectedItem, self)
# Connect widget controls to controller
heightMapModelRB.toggled.connect(modifier.enableHeightMapModel)
sqrtSinModelRB.toggled.connect(modifier.enableSqrtSinModel)
diff --git a/examples/graphs/3d/widgetgraphgallery/surfacegraphmodifier.py b/examples/graphs/3d/widgetgraphgallery/surfacegraphmodifier.py
index bcac7c3ea..c45265082 100644
--- a/examples/graphs/3d/widgetgraphgallery/surfacegraphmodifier.py
+++ b/examples/graphs/3d/widgetgraphgallery/surfacegraphmodifier.py
@@ -3,22 +3,29 @@
from __future__ import annotations
import os
-from math import sqrt, sin
+from enum import Enum
+from math import sqrt, sin, cos, degrees
from pathlib import Path
from PySide6.QtCore import QObject, QPropertyAnimation, Qt, Slot
from PySide6.QtGui import (QColor, QFont, QImage, QLinearGradient,
- QQuaternion, QVector3D)
-from PySide6.QtGraphs import (QAbstract3DGraph, QCustom3DItem,
+ QQuaternion, QVector2D, QVector3D, QWheelEvent)
+from PySide6.QtGraphs import (QCustom3DItem,
QCustom3DLabel, QHeightMapSurfaceDataProxy,
QValue3DAxis, QSurfaceDataItem,
QSurfaceDataProxy, QSurface3DSeries,
- Q3DInputHandler, Q3DTheme)
+ QtGraphs3D, QGraphsTheme)
from highlightseries import HighlightSeries
from topographicseries import TopographicSeries
-from custominputhandler import CustomInputHandler
+
+
+class InputState(Enum):
+ StateNormal = 0
+ StateDraggingX = 1
+ StateDraggingZ = 2
+ StateDraggingY = 3
SAMPLE_COUNT_X = 150
@@ -27,6 +34,7 @@ HEIGHTMAP_GRID_STEP_X = 6
HEIGHTMAP_GRID_STEP_Z = 6
SAMPLE_MIN = -8.0
SAMPLE_MAX = 8.0
+SPEED_MODIFIER = 20.0
AREA_WIDTH = 8000.0
AREA_HEIGHT = 8000.0
@@ -38,6 +46,7 @@ class SurfaceGraphModifier(QObject):
def __init__(self, surface, label, parent):
super().__init__(parent)
+ self._state = InputState.StateNormal
self._data_path = Path(__file__).resolve().parent / "data"
self._graph = surface
self._textField = label
@@ -61,6 +70,15 @@ class SurfaceGraphModifier(QObject):
self._heightMapWidth = 0
self._heightMapHeight = 0
+ self._axisXMinValue = 0.0
+ self._axisXMaxValue = 0.0
+ self._axisXMinRange = 0.0
+ self._axisZMinValue = 0.0
+ self._axisZMaxValue = 0.0
+ self._axisZMinRange = 0.0
+ self._areaMinValue = 0.0
+ self._areaMaxValue = 0.0
+
self._selectionAnimation = None
self._titleLabel = None
self._previouslyAnimatedItem = None
@@ -71,12 +89,12 @@ class SurfaceGraphModifier(QObject):
self._highlightWidth = 0
self._highlightHeight = 0
- self._customInputHandler = None
- self._defaultInputHandler = Q3DInputHandler()
-
self._graph.setCameraZoomLevel(85.0)
- self._graph.setCameraPreset(QAbstract3DGraph.CameraPreset.IsometricRight)
- self._graph.activeTheme().setType(Q3DTheme.Theme.Retro)
+ self._graph.setCameraPreset(QtGraphs3D.CameraPreset.IsometricRight)
+ theme = self._graph.activeTheme()
+ theme.setTheme(QGraphsTheme.Theme.MixSeries)
+ theme.setLabelBackgroundVisible(False)
+ theme.setLabelBorderVisible(False)
self._x_axis = QValue3DAxis()
self._y_axis = QValue3DAxis()
@@ -128,19 +146,19 @@ class SurfaceGraphModifier(QObject):
grOne.setColorAt(0.5, Qt.darkGray)
grOne.setColorAt(1.0, Qt.gray)
self._heightMapSeriesOne.setBaseGradient(grOne)
- self._heightMapSeriesOne.setColorStyle(Q3DTheme.ColorStyle.RangeGradient)
+ self._heightMapSeriesOne.setColorStyle(QGraphsTheme.ColorStyle.RangeGradient)
grTwo = QLinearGradient()
grTwo.setColorAt(0.39, Qt.blue)
grTwo.setColorAt(0.4, Qt.white)
self._heightMapSeriesTwo.setBaseGradient(grTwo)
- self._heightMapSeriesTwo.setColorStyle(Q3DTheme.ColorStyle.RangeGradient)
+ self._heightMapSeriesTwo.setColorStyle(QGraphsTheme.ColorStyle.RangeGradient)
grThree = QLinearGradient()
grThree.setColorAt(0.0, Qt.white)
grThree.setColorAt(0.05, Qt.black)
self._heightMapSeriesThree.setBaseGradient(grThree)
- self._heightMapSeriesThree.setColorStyle(Q3DTheme.ColorStyle.RangeGradient)
+ self._heightMapSeriesThree.setColorStyle(QGraphsTheme.ColorStyle.RangeGradient)
# Custom items and label
self._graph.selectedElementChanged.connect(self.handleElementSelected)
@@ -180,11 +198,8 @@ class SurfaceGraphModifier(QObject):
self._highlight.handleGradientChange(AREA_WIDTH * ASPECT_RATIO)
self._graph.axisY().maxChanged.connect(self._highlight.handleGradientChange)
- self._customInputHandler = CustomInputHandler(self._graph)
- self._customInputHandler.setHighlightSeries(self._highlight)
- self._customInputHandler.setAxes(self._x_axis, self._y_axis, self._z_axis)
- self._customInputHandler.setLimits(0.0, AREA_WIDTH, MIN_RANGE)
- self._customInputHandler.setAspectRatio(ASPECT_RATIO)
+ self._graph.wheel.connect(self.onWheel)
+ self._graph.dragged.connect(self.handleAxisDragging)
def fillSqrtSinProxy(self):
stepX = (SAMPLE_MAX - SAMPLE_MIN) / float(SAMPLE_COUNT_X - 1)
@@ -209,16 +224,16 @@ class SurfaceGraphModifier(QObject):
def enableSqrtSinModel(self, enable):
if enable:
self._sqrtSinSeries.setDrawMode(QSurface3DSeries.DrawSurfaceAndWireframe)
- self._sqrtSinSeries.setFlatShadingEnabled(True)
+ self._sqrtSinSeries.setShading(QSurface3DSeries.Shading.Flat)
self._graph.axisX().setLabelFormat("%.2f")
self._graph.axisZ().setLabelFormat("%.2f")
self._graph.axisX().setRange(SAMPLE_MIN, SAMPLE_MAX)
self._graph.axisY().setRange(0.0, 2.0)
self._graph.axisZ().setRange(SAMPLE_MIN, SAMPLE_MAX)
- self._graph.axisX().setLabelAutoRotation(30.0)
- self._graph.axisY().setLabelAutoRotation(90.0)
- self._graph.axisZ().setLabelAutoRotation(30.0)
+ self._graph.axisX().setLabelAutoAngle(30.0)
+ self._graph.axisY().setLabelAutoAngle(90.0)
+ self._graph.axisZ().setLabelAutoAngle(30.0)
self._graph.removeSeries(self._heightMapSeriesOne)
self._graph.removeSeries(self._heightMapSeriesTwo)
@@ -237,8 +252,6 @@ class SurfaceGraphModifier(QObject):
self._graph.axisY().setTitle("")
self._graph.axisZ().setTitle("")
- self._graph.setActiveInputHandler(self._defaultInputHandler)
-
# Reset range sliders for Sqrt & Sin
self._rangeMinX = SAMPLE_MIN
self._rangeMinZ = SAMPLE_MIN
@@ -257,6 +270,8 @@ class SurfaceGraphModifier(QObject):
self._axisMaxSliderZ.setMaximum(SAMPLE_COUNT_Z - 1)
self._axisMaxSliderZ.setValue(SAMPLE_COUNT_Z - 1)
+ self._graph.setZoomEnabled(True)
+
@Slot(bool)
def enableHeightMapModel(self, enable):
if enable:
@@ -284,8 +299,6 @@ class SurfaceGraphModifier(QObject):
self._graph.addSeries(self._heightMapSeriesTwo)
self._graph.addSeries(self._heightMapSeriesThree)
- self._graph.setActiveInputHandler(self._defaultInputHandler)
-
self._titleLabel.setVisible(True)
self._graph.axisX().setTitleVisible(True)
self._graph.axisY().setTitleVisible(True)
@@ -311,6 +324,11 @@ class SurfaceGraphModifier(QObject):
self._axisMaxSliderZ.setMaximum(mapGridCountZ - 1)
self._axisMaxSliderZ.setValue(mapGridCountZ - 1)
+ self._graph.wheel.disconnect(self.onWheel)
+ self._graph.dragged.disconnect(self.handleAxisDragging)
+ self._graph.setDefaultInputHandler()
+ self._graph.setZoomEnabled(True)
+
@Slot(bool)
def enableTopographyModel(self, enable):
if enable:
@@ -319,9 +337,9 @@ class SurfaceGraphModifier(QObject):
self._graph.axisX().setRange(0.0, AREA_WIDTH)
self._graph.axisY().setRange(100.0, AREA_WIDTH * ASPECT_RATIO)
self._graph.axisZ().setRange(0.0, AREA_HEIGHT)
- self._graph.axisX().setLabelAutoRotation(30.0)
- self._graph.axisY().setLabelAutoRotation(90.0)
- self._graph.axisZ().setLabelAutoRotation(30.0)
+ self._graph.axisX().setLabelAutoAngle(30.0)
+ self._graph.axisY().setLabelAutoAngle(90.0)
+ self._graph.axisZ().setLabelAutoAngle(30.0)
self._graph.removeSeries(self._heightMapSeriesOne)
self._graph.removeSeries(self._heightMapSeriesTwo)
@@ -338,8 +356,6 @@ class SurfaceGraphModifier(QObject):
self._graph.axisY().setTitle("")
self._graph.axisZ().setTitle("")
- self._graph.setActiveInputHandler(self._customInputHandler)
-
# Reset range sliders for topography map
self._rangeMinX = 0.0
self._rangeMinZ = 0.0
@@ -358,6 +374,19 @@ class SurfaceGraphModifier(QObject):
self._axisMaxSliderZ.setMaximum(AREA_HEIGHT)
self._axisMaxSliderZ.setValue(AREA_HEIGHT)
+ self._areaMinValue = 0
+ self._areaMaxValue = AREA_WIDTH
+ self._axisXMinValue = self._areaMinValue
+ self._axisXMaxValue = self._areaMaxValue
+ self._axisZMinValue = self._areaMinValue
+ self._axisZMaxValue = self._areaMaxValue
+ self._axisXMinRange = MIN_RANGE
+ self._axisZMinRange = MIN_RANGE
+
+ self._graph.wheel.connect(self.onWheel)
+ self._graph.dragged.connect(self.handleAxisDragging)
+ self._graph.setZoomEnabled(False)
+
def adjustXMin(self, min):
minX = self._stepX * float(min) + self._rangeMinX
@@ -420,7 +449,7 @@ class SurfaceGraphModifier(QObject):
gr.setColorAt(1.0, Qt.yellow)
self._sqrtSinSeries.setBaseGradient(gr)
- self._sqrtSinSeries.setColorStyle(Q3DTheme.ColorStyle.RangeGradient)
+ self._sqrtSinSeries.setColorStyle(QGraphsTheme.ColorStyle.RangeGradient)
def setGreenToRedGradient(self):
gr = QLinearGradient()
@@ -430,7 +459,7 @@ class SurfaceGraphModifier(QObject):
gr.setColorAt(1.0, Qt.darkRed)
self._sqrtSinSeries.setBaseGradient(gr)
- self._sqrtSinSeries.setColorStyle(Q3DTheme.ColorStyle.RangeGradient)
+ self._sqrtSinSeries.setColorStyle(QGraphsTheme.ColorStyle.RangeGradient)
@Slot(bool)
def toggleItemOne(self, show):
@@ -551,8 +580,8 @@ class SurfaceGraphModifier(QObject):
@Slot(bool)
def toggleShadows(self, shadows):
- sq = (QAbstract3DGraph.ShadowQualityMedium
- if shadows else QAbstract3DGraph.ShadowQualityNone)
+ sq = (QtGraphs3D.ShadowQualityMedium
+ if shadows else QtGraphs3D.ShadowQualityNone)
self._graph.setShadowQuality(sq)
@Slot(bool)
@@ -565,7 +594,7 @@ class SurfaceGraphModifier(QObject):
def handleElementSelected(self, type):
self.resetSelection()
- if type == QAbstract3DGraph.ElementCustomItem:
+ if type == QtGraphs3D.ElementType.CustomItem:
item = self._graph.selectedCustomItem()
text = ""
if isinstance(item, QCustom3DItem):
@@ -582,7 +611,7 @@ class SurfaceGraphModifier(QObject):
self._selectionAnimation.setStartValue(item.scaling())
self._selectionAnimation.setEndValue(item.scaling() * 1.5)
self._selectionAnimation.start()
- elif type == QAbstract3DGraph.ElementSeries:
+ elif type == QtGraphs3D.ElementType.Series:
text = "Surface ("
series = self._graph.selectedSeries()
if series:
@@ -590,16 +619,19 @@ class SurfaceGraphModifier(QObject):
text += f"{point.x()}, {point.y()}"
text += ")"
self._textField.setText(text)
- elif (type.value > QAbstract3DGraph.ElementSeries.value
- and type < QAbstract3DGraph.ElementCustomItem.value):
+ elif (type.value > QtGraphs3D.ElementType.Series.value
+ and type.value < QtGraphs3D.ElementType.CustomItem.value):
index = self._graph.selectedLabelIndex()
text = ""
- if type == QAbstract3DGraph.ElementAxisXLabel:
+ if type == QtGraphs3D.ElementType.AxisXLabel:
text += "Axis X label: "
- elif type == QAbstract3DGraph.ElementAxisYLabel:
+ self._state = InputState.StateDraggingX
+ elif type == QtGraphs3D.ElementType.AxisYLabel:
text += "Axis Y label: "
+ self._state = InputState.StateDraggingY
else:
text += "Axis Z label: "
+ self._state = InputState.StateDraggingZ
text += str(index)
self._textField.setText(text)
else:
@@ -612,21 +644,21 @@ class SurfaceGraphModifier(QObject):
self._previouslyAnimatedItem = None
def toggleModeNone(self):
- self._graph.setSelectionMode(QAbstract3DGraph.SelectionNone)
+ self._graph.setSelectionMode(QtGraphs3D.SelectionFlag.None_)
def toggleModeItem(self):
- self._graph.setSelectionMode(QAbstract3DGraph.SelectionItem)
+ self._graph.setSelectionMode(QtGraphs3D.SelectionFlag.Item)
def toggleModeSliceRow(self):
- sm = (QAbstract3DGraph.SelectionItemAndRow
- | QAbstract3DGraph.SelectionSlice
- | QAbstract3DGraph.SelectionMultiSeries)
+ sm = (QtGraphs3D.SelectionFlag.ItemAndRow
+ | QtGraphs3D.SelectionFlag.Slice
+ | QtGraphs3D.SelectionFlag.MultiSeries)
self._graph.setSelectionMode(sm)
def toggleModeSliceColumn(self):
- sm = (QAbstract3DGraph.SelectionItemAndColumn
- | QAbstract3DGraph.SelectionSlice
- | QAbstract3DGraph.SelectionMultiSeries)
+ sm = (QtGraphs3D.SelectionFlag.ItemAndColumn
+ | QtGraphs3D.SelectionFlag.Slice
+ | QtGraphs3D.SelectionFlag.MultiSeries)
self._graph.setSelectionMode(sm)
def setAxisMinSliderX(self, slider):
@@ -640,3 +672,91 @@ class SurfaceGraphModifier(QObject):
def setAxisMaxSliderZ(self, slider):
self._axisMaxSliderZ = slider
+
+ def checkConstraints(self):
+ if self._axisXMinValue < self._areaMinValue:
+ self._axisXMinValue = self._areaMinValue
+ if self._axisXMaxValue > self._areaMaxValue:
+ self._axisXMaxValue = self._areaMaxValue
+ # Don't allow too much zoom in
+ range = self._axisXMaxValue - self._axisXMinValue
+ if range < self._axisXMinRange:
+ adjust = (self._axisXMinRange - range) / 2.0
+ self._axisXMinValue -= adjust
+ self._axisXMaxValue += adjust
+
+ if self._axisZMinValue < self._areaMinValue:
+ self._axisZMinValue = self._areaMinValue
+ if self._axisZMaxValue > self._areaMaxValue:
+ self._axisZMaxValue = self._areaMaxValue
+ # Don't allow too much zoom in
+ range = self._axisZMaxValue - self._axisZMinValue
+ if range < self._axisZMinRange:
+ adjust = (self._axisZMinRange - range) / 2.0
+ self._axisZMinValue -= adjust
+ self._axisZMaxValue += adjust
+
+ @Slot(QVector2D)
+ def handleAxisDragging(self, delta):
+
+ distance = float(0)
+
+ # Get scene orientation from active camera
+ xRotation = self._graph.cameraXRotation()
+
+ # Calculate directional drag multipliers based on rotation
+ xMulX = cos(degrees(xRotation))
+ xMulY = sin(degrees(xRotation))
+ zMulX = sin(degrees(xRotation))
+ zMulY = cos(degrees(xRotation))
+
+ # Get the drag amount
+ move = delta.toPoint()
+
+ # Adjust axes
+ if self._state == InputState.StateDraggingX:
+ distance = (move.x() * xMulX - move.y() * xMulY) * SPEED_MODIFIER
+ self._axisXMinValue -= distance
+ self._axisXMaxValue -= distance
+ if self._axisXMinValue < self._areaMinValue:
+ dist = self._axisXMaxValue - self._axisXMinValue
+ self._axisXMinValue = self._areaMinValue
+ self._axisXMaxValue = self._axisXMinValue + dist
+
+ if self._axisXMaxValue > self._areaMaxValue:
+ dist = self._axisXMaxValue - self._axisXMinValue
+ self._axisXMaxValue = self._areaMaxValue
+ self._axisXMinValue = self._axisXMaxValue - dist
+
+ self._graph.axisX().setRange(self._axisXMinValue, self._axisXMaxValue)
+ elif self._state == InputState.StateDraggingZ:
+ distance = (move.x() * zMulX + move.y() * zMulY) * SPEED_MODIFIER
+ self._axisZMinValue += distance
+ self._axisZMaxValue += distance
+ if self._axisZMinValue < self._areaMinValue:
+ dist = self._axisZMaxValue - self._axisZMinValue
+ self._axisZMinValue = self._areaMinValue
+ self._axisZMaxValue = self._axisZMinValue + dist
+
+ if self._axisZMaxValue > self._areaMaxValue:
+ dist = self._axisZMaxValue - self._axisZMinValue
+ self._axisZMaxValue = self._areaMaxValue
+ self._axisZMinValue = self._axisZMaxValue - dist
+
+ self._graph.axisZ().setRange(self._axisZMinValue, self._axisZMaxValue)
+
+ @Slot(QWheelEvent)
+ def onWheel(self, event):
+ delta = float(event.angleDelta().y())
+
+ self._axisXMinValue += delta
+ self._axisXMaxValue -= delta
+ self._axisZMinValue += delta
+ self._axisZMaxValue -= delta
+ self.checkConstraints()
+
+ y = (self._axisXMaxValue - self._axisXMinValue) * ASPECT_RATIO
+
+ self._graph.axisX().setRange(self._axisXMinValue, self._axisXMaxValue)
+ self._graph.axisY().setRange(100.0, y)
+ self._graph.axisZ().setRange(self._axisZMinValue, self._axisZMaxValue)
diff --git a/examples/graphs/3d/widgetgraphgallery/topographicseries.py b/examples/graphs/3d/widgetgraphgallery/topographicseries.py
index 30805d66f..69a58c6b5 100644
--- a/examples/graphs/3d/widgetgraphgallery/topographicseries.py
+++ b/examples/graphs/3d/widgetgraphgallery/topographicseries.py
@@ -18,7 +18,7 @@ class TopographicSeries(QSurface3DSeries):
self._sampleCountX = 0.0
self._sampleCountZ = 0.0
self.setDrawMode(QSurface3DSeries.DrawSurface)
- self.setFlatShadingEnabled(True)
+ self.setShading(QSurface3DSeries.Shading.Flat)
self.setBaseColor(Qt.white)
def sampleCountX(self):
diff --git a/examples/graphs/3d/widgetgraphgallery/widgetgraphgallery.pyproject b/examples/graphs/3d/widgetgraphgallery/widgetgraphgallery.pyproject
index 581b21483..ebc680f66 100644
--- a/examples/graphs/3d/widgetgraphgallery/widgetgraphgallery.pyproject
+++ b/examples/graphs/3d/widgetgraphgallery/widgetgraphgallery.pyproject
@@ -1,8 +1,6 @@
{
"files": ["main.py",
- "axesinputhandler.py",
"bargraph.py",
- "custominputhandler.py",
"graphmodifier.py",
"highlightseries.py",
"rainfalldata.py",