Skip to content

Commit a6701d3

Browse files
committed
feat(Qt): remove redundant QLayout
1 parent 44e1b9b commit a6701d3

File tree

10 files changed

+240
-256
lines changed

10 files changed

+240
-256
lines changed

friture/PitchView.qml

Lines changed: 93 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,107 @@
1-
import QtQuick 2.9
1+
import QtQuick 2.15
22
import QtQuick.Window 2.2
33
import QtQuick.Layouts 1.15
4+
import QtQuick.Shapes 1.15
45
import Friture 1.0
6+
import "plotItemColors.js" as PlotItemColors
57

6-
Rectangle {
7-
id: pitch
8-
SystemPalette { id: systemPalette; colorGroup: SystemPalette.Active }
9-
color: systemPalette.window
8+
Item {
9+
id: container
10+
property var stateId
1011

11-
implicitWidth: pitchCol.implicitWidth
12-
implicitHeight: parent ? parent.height : 0
12+
// delay the load of the Plot until stateId has been set
13+
Loader {
14+
id: loader
15+
anchors.fill: parent
16+
}
1317

14-
property var pitch_view_model
18+
onStateIdChanged: {
19+
console.log("stateId changed: " + stateId)
20+
loader.sourceComponent = plotComponent
21+
}
1522

16-
ColumnLayout {
17-
id: pitchCol
18-
spacing: 0
23+
Component {
24+
id: plotComponent
1925

20-
FontMetrics {
21-
id: fontMetrics
22-
font.pointSize: 14
23-
font.bold: true
24-
}
26+
Item {
27+
Plot {
28+
id: plot
29+
scopedata: Store.dock_states[container.stateId]
2530

26-
Text {
27-
id: note
28-
text: pitch_view_model.note
29-
textFormat: Text.PlainText
30-
font.pointSize: 14
31-
font.bold: true
32-
rightPadding: 6
33-
horizontalAlignment: Text.AlignRight
34-
Layout.alignment: Qt.AlignTop | Qt.AlignRight
35-
color: systemPalette.windowText
36-
}
31+
anchors.fill: null // override 'fill: parent' in Plot.qml
32+
anchors.left: parent.left
33+
anchors.right: pitchItem.left
34+
anchors.top: parent.top
35+
anchors.bottom: parent.bottom
3736

38-
Text {
39-
id: pitchHz
40-
text: pitch_view_model.pitch
41-
textFormat: Text.PlainText
42-
font.pointSize: 14
43-
font.bold: true
44-
rightPadding: 6
45-
horizontalAlignment: Text.AlignRight
46-
Layout.preferredWidth: fontMetrics.boundingRect("000.0").width
47-
Layout.alignment: Qt.AlignTop | Qt.AlignRight
48-
color: systemPalette.windowText
49-
}
37+
Repeater {
38+
model: plot.scopedata.plot_items
39+
40+
PlotCurve {
41+
anchors.fill: parent
42+
color: PlotItemColors.color(index)
43+
curve: modelData
44+
}
45+
}
46+
}
47+
48+
Rectangle {
49+
id: pitchItem
50+
51+
implicitWidth: pitchCol.implicitWidth
52+
implicitHeight: parent ? parent.height : 0
53+
54+
anchors.right: parent.right
55+
56+
SystemPalette { id: systemPalette; colorGroup: SystemPalette.Active }
57+
color: systemPalette.window
58+
59+
ColumnLayout {
60+
id: pitchCol
61+
spacing: 0
62+
63+
FontMetrics {
64+
id: fontMetrics
65+
font.pointSize: 14
66+
font.bold: true
67+
}
68+
69+
Text {
70+
id: note
71+
text: plot.scopedata.note
72+
textFormat: Text.PlainText
73+
font.pointSize: 14
74+
font.bold: true
75+
rightPadding: 6
76+
horizontalAlignment: Text.AlignRight
77+
Layout.alignment: Qt.AlignTop | Qt.AlignRight
78+
color: systemPalette.windowText
79+
}
80+
81+
Text {
82+
id: pitchHz
83+
text: plot.scopedata.pitch
84+
textFormat: Text.PlainText
85+
font.pointSize: 14
86+
font.bold: true
87+
rightPadding: 6
88+
horizontalAlignment: Text.AlignRight
89+
Layout.preferredWidth: fontMetrics.boundingRect("000.0").width
90+
Layout.alignment: Qt.AlignTop | Qt.AlignRight
91+
color: systemPalette.windowText
92+
}
5093

51-
Text {
52-
id: pitchUnit
53-
text: pitch_view_model.pitch_unit
54-
textFormat: Text.PlainText
55-
rightPadding: 6
56-
horizontalAlignment: Text.AlignRight
57-
Layout.alignment: Qt.AlignTop | Qt.AlignRight
58-
color: systemPalette.windowText
94+
Text {
95+
id: pitchUnit
96+
text: plot.scopedata.pitch_unit
97+
textFormat: Text.PlainText
98+
rightPadding: 6
99+
horizontalAlignment: Text.AlignRight
100+
Layout.alignment: Qt.AlignTop | Qt.AlignRight
101+
color: systemPalette.windowText
102+
}
103+
}
104+
}
59105
}
60106
}
61107
}

friture/histplot.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
# The peak decay rates (magic goes here :).
3434
PEAK_DECAY_RATE = 1.0 - 3E-6
3535

36-
class HistPlot(QtWidgets.QWidget):
36+
class HistPlot(QQuickWidget):
3737

3838
def __init__(self, parent, engine):
39-
super(HistPlot, self).__init__(parent)
39+
super(HistPlot, self).__init__(engine, parent)
4040

4141
self.logger = logging.getLogger(__name__)
4242

@@ -73,27 +73,18 @@ def __init__(self, parent, engine):
7373
self.normHorizontalScaleTransform.setScale(fscales.Logarithmic)
7474
self._histplot_data.horizontal_axis.setScale(fscales.Logarithmic)
7575

76-
plotLayout = QtWidgets.QGridLayout(self)
77-
plotLayout.setSpacing(0)
78-
plotLayout.setContentsMargins(0, 0, 0, 0)
76+
self.statusChanged.connect(self.on_status_changed)
77+
self.setResizeMode(QQuickWidget.SizeRootObjectToView)
78+
self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
79+
self.setSource(qml_url("HistPlot.qml"))
7980

80-
self.quickWidget = QQuickWidget(engine, self)
81-
self.quickWidget.statusChanged.connect(self.on_status_changed)
82-
self.quickWidget.setResizeMode(QQuickWidget.SizeRootObjectToView)
83-
self.quickWidget.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
84-
self.quickWidget.setSource(qml_url("HistPlot.qml"))
81+
raise_if_error(self)
8582

86-
raise_if_error(self.quickWidget)
87-
88-
self.quickWidget.rootObject().setProperty("stateId", state_id)
89-
90-
plotLayout.addWidget(self.quickWidget)
91-
92-
self.setLayout(plotLayout)
83+
self.rootObject().setProperty("stateId", state_id)
9384

9485
def on_status_changed(self, status):
9586
if status == QQuickWidget.Error:
96-
for error in self.quickWidget.errors():
87+
for error in self.errors():
9788
self.logger.error("QML error: " + error.toString())
9889

9990
def setdata(self, fl, fh, fc, y):

friture/imageplot.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
from friture.store import GetStore
2727
from friture.pitch_tracker import format_frequency
2828

29-
class ImagePlot(QtWidgets.QWidget):
29+
class ImagePlot(QQuickWidget):
3030

3131
def __init__(self, parent, engine):
32-
super(ImagePlot, self).__init__(parent)
32+
super(ImagePlot, self).__init__(engine, parent)
3333

3434
self.logger = logging.getLogger(__name__)
3535

@@ -53,27 +53,18 @@ def __init__(self, parent, engine):
5353
self._spectrogram_data.color_axis.setRange(-140, 0)
5454
self._spectrogram_data.show_color_axis = True
5555

56-
plotLayout = QtWidgets.QGridLayout(self)
57-
plotLayout.setSpacing(0)
58-
plotLayout.setContentsMargins(0, 0, 0, 0)
59-
60-
self.quickWidget = QQuickWidget(engine, self)
61-
self.quickWidget.statusChanged.connect(self.on_status_changed)
62-
self.quickWidget.setResizeMode(QQuickWidget.SizeRootObjectToView)
63-
self.quickWidget.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
64-
self.quickWidget.setSource(qml_url("ImagePlot.qml"))
56+
self.statusChanged.connect(self.on_status_changed)
57+
self.setResizeMode(QQuickWidget.SizeRootObjectToView)
58+
self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
59+
self.setSource(qml_url("ImagePlot.qml"))
6560

66-
raise_if_error(self.quickWidget)
67-
68-
self.quickWidget.rootObject().setProperty("stateId", state_id)
69-
70-
plotLayout.addWidget(self.quickWidget)
61+
raise_if_error(self)
7162

72-
self.setLayout(plotLayout)
63+
self.rootObject().setProperty("stateId", state_id)
7364

7465
def on_status_changed(self, status):
7566
if status == QQuickWidget.Error:
76-
for error in self.quickWidget.errors():
67+
for error in self.errors():
7768
self.logger.error("QML error: " + error.toString())
7869

7970
def push(self, data, last_data_time):

friture/longlevels.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,13 @@ def push(self, x):
9393
return x_dec
9494

9595

96-
class LongLevelWidget(QtWidgets.QWidget):
96+
class LongLevelWidget(QQuickWidget):
9797

9898
def __init__(self, parent, engine):
99-
super().__init__(parent)
99+
super().__init__(engine, parent)
100100

101101
self.logger = logging.getLogger(__name__)
102102

103-
self.setObjectName("LongLevels_Widget")
104-
105103
store = GetStore()
106104
self._long_levels_data = Scope_Data(store)
107105
store._dock_states.append(self._long_levels_data)
@@ -116,22 +114,14 @@ def __init__(self, parent, engine):
116114
self._long_levels_data.horizontal_axis.name = "Time (sec)"
117115
self._long_levels_data.horizontal_axis.setTrackerFormatter(lambda x: "%#.3g sec" % (x))
118116

119-
self.setObjectName("Scope_Widget")
120-
self.gridLayout = QtWidgets.QGridLayout(self)
121-
self.gridLayout.setObjectName("gridLayout")
122-
self.gridLayout.setContentsMargins(2, 2, 2, 2)
123-
124-
self.quickWidget = QQuickWidget(engine, self)
125-
self.quickWidget.statusChanged.connect(self.on_status_changed)
126-
self.quickWidget.setResizeMode(QQuickWidget.SizeRootObjectToView)
127-
self.quickWidget.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
128-
self.quickWidget.setSource(qml_url("Scope.qml"))
117+
self.statusChanged.connect(self.on_status_changed)
118+
self.setResizeMode(QQuickWidget.SizeRootObjectToView)
119+
self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
120+
self.setSource(qml_url("Scope.qml"))
129121

130-
raise_if_error(self.quickWidget)
131-
132-
self.quickWidget.rootObject().setProperty("stateId", state_id)
122+
raise_if_error(self)
133123

134-
self.gridLayout.addWidget(self.quickWidget, 0, 0, 1, 1)
124+
self.rootObject().setProperty("stateId", state_id)
135125

136126
self.level_min = DEFAULT_LEVEL_MIN
137127
self.level_max = DEFAULT_LEVEL_MAX
@@ -214,7 +204,7 @@ def handle_new_data(self, floatdata):
214204

215205
def on_status_changed(self, status):
216206
if status == QQuickWidget.Error:
217-
for error in self.quickWidget.errors():
207+
for error in self.errors():
218208
self.logger.error("QML error: " + error.toString())
219209

220210
# method

0 commit comments

Comments
 (0)