kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
User-selectable fields displayed for markers.
rodzic
d867c8e726
commit
2539266944
|
@ -33,6 +33,8 @@ class Marker(QtCore.QObject):
|
|||
|
||||
updated = pyqtSignal(object)
|
||||
|
||||
fieldSelection = ["actualfreq", "impedance", "vswr"]
|
||||
|
||||
def __init__(self, name, initialColor, frequency=""):
|
||||
super().__init__()
|
||||
self.name = name
|
||||
|
@ -64,6 +66,20 @@ class Marker(QtCore.QObject):
|
|||
self.s21_phase_label = QtWidgets.QLabel("")
|
||||
self.quality_factor_label = QtWidgets.QLabel("")
|
||||
|
||||
self.fields = {"actualfreq": ("Frequency:", self.frequency_label),
|
||||
"impedance": ("Impedance:", self.impedance_label),
|
||||
"serl": ("Series L:", self.inductance_label),
|
||||
"serc": ("Series C:", self.capacitance_label),
|
||||
"parr": ("Parallel R:", self.parallel_r_label),
|
||||
"parlc": ("Parallel L/C:", self.parallel_x_label),
|
||||
"returnloss": ("Return loss:", self.returnloss_label),
|
||||
"vswr": ("VSWR:", self.vswr_label),
|
||||
"s11q": ("Quality factor:", self.quality_factor_label),
|
||||
"s11phase": ("S11 Phase:", self.s11_phase_label),
|
||||
"s21gain": ("S21 Gain:", self.gain_label),
|
||||
"s21phase": ("S21 Phase:", self.s21_phase_label),
|
||||
}
|
||||
|
||||
################################################################################################################
|
||||
# Marker control layout
|
||||
################################################################################################################
|
||||
|
@ -90,34 +106,75 @@ class Marker(QtCore.QObject):
|
|||
line = QtWidgets.QFrame()
|
||||
line.setFrameShape(QtWidgets.QFrame.VLine)
|
||||
|
||||
left_form = QtWidgets.QFormLayout()
|
||||
right_form = QtWidgets.QFormLayout()
|
||||
box_layout.addLayout(left_form)
|
||||
self.left_form = QtWidgets.QFormLayout()
|
||||
self.right_form = QtWidgets.QFormLayout()
|
||||
box_layout.addLayout(self.left_form)
|
||||
box_layout.addWidget(line)
|
||||
box_layout.addLayout(right_form)
|
||||
box_layout.addLayout(self.right_form)
|
||||
|
||||
self.buildForm()
|
||||
|
||||
def buildForm(self):
|
||||
while self.left_form.count() > 0:
|
||||
old_row = self.left_form.takeRow(0)
|
||||
old_row.fieldItem.widget().hide()
|
||||
old_row.labelItem.widget().hide()
|
||||
|
||||
while self.right_form.count() > 0:
|
||||
old_row = self.right_form.takeRow(0)
|
||||
old_row.fieldItem.widget().hide()
|
||||
old_row.labelItem.widget().hide()
|
||||
|
||||
if len(self.fieldSelection) <= 3:
|
||||
for field in self.fieldSelection:
|
||||
if field in self.fields:
|
||||
label, value = self.fields[field]
|
||||
self.left_form.addRow(label, value)
|
||||
value.show()
|
||||
else:
|
||||
left_half = math.ceil(len(self.fieldSelection)/2)
|
||||
right_half = len(self.fieldSelection)
|
||||
for i in range(left_half):
|
||||
field = self.fieldSelection[i]
|
||||
if field in self.fields:
|
||||
label, value = self.fields[field]
|
||||
self.left_form.addRow(label, value)
|
||||
value.show()
|
||||
for i in range(left_half, right_half):
|
||||
field = self.fieldSelection[i]
|
||||
if field in self.fields:
|
||||
label, value = self.fields[field]
|
||||
self.right_form.addRow(label, value)
|
||||
value.show()
|
||||
|
||||
# Left side
|
||||
left_form.addRow("Frequency:", self.frequency_label)
|
||||
left_form.addRow("Impedance:", self.impedance_label)
|
||||
# left_form.addRow("Admittance:", self.admittance_label)
|
||||
left_form.addRow("Parallel R:", self.parallel_r_label)
|
||||
left_form.addRow("Parallel X:", self.parallel_x_label)
|
||||
left_form.addRow("L equiv.:", self.inductance_label)
|
||||
left_form.addRow("C equiv.:", self.capacitance_label)
|
||||
|
||||
# Right side
|
||||
right_form.addRow("Return loss:", self.returnloss_label)
|
||||
right_form.addRow("VSWR:", self.vswr_label)
|
||||
right_form.addRow("Q:", self.quality_factor_label)
|
||||
right_form.addRow("S11 Phase:", self.s11_phase_label)
|
||||
right_form.addRow("S21 Gain:", self.gain_label)
|
||||
right_form.addRow("S21 Phase:", self.s21_phase_label)
|
||||
# self.left_form.addRow("Frequency:", self.frequency_label)
|
||||
# self.left_form.addRow("Impedance:", self.impedance_label)
|
||||
# # left_form.addRow("Admittance:", self.admittance_label)
|
||||
# self.left_form.addRow("Parallel R:", self.parallel_r_label)
|
||||
# self.left_form.addRow("Parallel X:", self.parallel_x_label)
|
||||
# self.left_form.addRow("L equiv.:", self.inductance_label)
|
||||
# self.left_form.addRow("C equiv.:", self.capacitance_label)
|
||||
#
|
||||
# # Right side
|
||||
# self.right_form.addRow("Return loss:", self.returnloss_label)
|
||||
# if "vswr" in self.fieldSelection:
|
||||
# self.right_form.addRow("VSWR:", self.vswr_label)
|
||||
# self.vswr_label.show()
|
||||
# self.right_form.addRow("Q:", self.quality_factor_label)
|
||||
# self.right_form.addRow("S11 Phase:", self.s11_phase_label)
|
||||
# self.right_form.addRow("S21 Gain:", self.gain_label)
|
||||
# self.right_form.addRow("S21 Phase:", self.s21_phase_label)
|
||||
|
||||
def setFrequency(self, frequency):
|
||||
f = RFTools.parseFrequency(frequency)
|
||||
self.frequency = max(f, 0)
|
||||
self.updated.emit(self)
|
||||
|
||||
def setFieldSelection(self, fields):
|
||||
self.fieldSelection: List[str] = fields.copy()
|
||||
self.buildForm()
|
||||
|
||||
def setColor(self, color):
|
||||
if color.isValid():
|
||||
self.color = color
|
||||
|
|
|
@ -1160,14 +1160,19 @@ class DisplaySettingsWindow(QtWidgets.QWidget):
|
|||
markers_box = QtWidgets.QGroupBox("Markers")
|
||||
markers_layout = QtWidgets.QFormLayout(markers_box)
|
||||
|
||||
self.marker_window = MarkerSettingsWindow(self.app)
|
||||
|
||||
btn_add_marker = QtWidgets.QPushButton("Add")
|
||||
btn_add_marker.clicked.connect(self.addMarker)
|
||||
self.btn_remove_marker = QtWidgets.QPushButton("Remove")
|
||||
self.btn_remove_marker.clicked.connect(self.removeMarker)
|
||||
btn_marker_settings = QtWidgets.QPushButton("Settings ...")
|
||||
btn_marker_settings.clicked.connect(self.displayMarkerWindow)
|
||||
|
||||
marker_btn_layout = QtWidgets.QHBoxLayout()
|
||||
marker_btn_layout.addWidget(btn_add_marker)
|
||||
marker_btn_layout.addWidget(self.btn_remove_marker)
|
||||
marker_btn_layout.addWidget(btn_marker_settings)
|
||||
|
||||
markers_layout.addRow(marker_btn_layout)
|
||||
|
||||
|
@ -1189,7 +1194,7 @@ class DisplaySettingsWindow(QtWidgets.QWidget):
|
|||
selections.append(c.name)
|
||||
|
||||
selections.append("None")
|
||||
|
||||
# TODO: Make this tolerant of non-existant charts
|
||||
chart00_selection = QtWidgets.QComboBox()
|
||||
chart00_selection.addItems(selections)
|
||||
chart00_selection.setCurrentIndex(selections.index(self.app.settings.value("Chart00", "S11 Smith Chart")))
|
||||
|
@ -1473,6 +1478,10 @@ class DisplaySettingsWindow(QtWidgets.QWidget):
|
|||
self.bandsWindow.show()
|
||||
QtWidgets.QApplication.setActiveWindow(self.bandsWindow)
|
||||
|
||||
def displayMarkerWindow(self):
|
||||
self.marker_window.show()
|
||||
QtWidgets.QApplication.setActiveWindow(self.marker_window)
|
||||
|
||||
def addMarker(self):
|
||||
marker_count = len(self.app.markers)
|
||||
if marker_count < 6:
|
||||
|
@ -2151,3 +2160,174 @@ class AnalysisWindow(QtWidgets.QWidget):
|
|||
self.analysis_layout.addWidget(self.analysis.widget())
|
||||
self.analysis.widget().show()
|
||||
self.update()
|
||||
|
||||
|
||||
class MarkerSettingsWindow(QtWidgets.QWidget):
|
||||
exampleData11 = [Datapoint(123000000, 0, 0),
|
||||
Datapoint(123500000, 0.9, -0.1),
|
||||
Datapoint(124000000, 0, 0)]
|
||||
exampleData21 = [Datapoint(123000000, 0, 0),
|
||||
Datapoint(123456000, -0.3, 0.5),
|
||||
Datapoint(124000000, 0, 0)]
|
||||
|
||||
fieldList = {"actualfreq": "Actual frequency",
|
||||
"impedance": "Impedance",
|
||||
"admittance": "Admittance",
|
||||
"serr": "Series R",
|
||||
"serlc": "Series equivalent L/C",
|
||||
"serl": "Series equivalent L",
|
||||
"serc": "Series equivalent C",
|
||||
"parr": "Parallel R",
|
||||
"parlc": "Parallel equivalent L/C",
|
||||
"parl": "Parallel equivalent L",
|
||||
"parc": "Parallel equivalent C",
|
||||
"vswr": "VSWR",
|
||||
"returnloss": "Return loss",
|
||||
"s11q": "S11 Quality factor",
|
||||
"s11phase": "S11 Phase",
|
||||
"s21gain": "S21 Gain",
|
||||
"s21phase": "S21 Phase",
|
||||
}
|
||||
|
||||
defaultValue = ["actualfreq",
|
||||
"impedance",
|
||||
"serl",
|
||||
"serc",
|
||||
"parr",
|
||||
"parlc",
|
||||
"vswr",
|
||||
"returnloss",
|
||||
"s11q",
|
||||
"s11phase",
|
||||
"s21gain",
|
||||
"s21phase"
|
||||
]
|
||||
|
||||
def __init__(self, app: NanoVNASaver):
|
||||
super().__init__()
|
||||
self.app = app
|
||||
|
||||
self.setWindowTitle("Marker settings")
|
||||
self.setWindowIcon(self.app.icon)
|
||||
|
||||
shortcut = QtWidgets.QShortcut(QtCore.Qt.Key_Escape, self, self.cancelButtonClick)
|
||||
|
||||
if len(self.app.markers) > 0:
|
||||
color = self.app.markers[0].color
|
||||
else:
|
||||
color = self.app.default_marker_colors[0]
|
||||
|
||||
self.exampleMarker = Marker("Example marker", initialColor=color, frequency="123456000")
|
||||
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
self.setLayout(layout)
|
||||
|
||||
settings_group_box = QtWidgets.QGroupBox("Settings")
|
||||
settings_group_box_layout = QtWidgets.QFormLayout(settings_group_box)
|
||||
self.checkboxColouredMarker = QtWidgets.QCheckBox("Colored marker name")
|
||||
self.checkboxDataShownInCharts = QtWidgets.QCheckBox("Show data in charts (EXPERIMENTAL)")
|
||||
settings_group_box_layout.addRow(self.checkboxColouredMarker)
|
||||
settings_group_box_layout.addRow(self.checkboxDataShownInCharts)
|
||||
|
||||
fields_group_box = QtWidgets.QGroupBox("Displayed data")
|
||||
fields_group_box_layout = QtWidgets.QFormLayout(fields_group_box)
|
||||
|
||||
self.savedFieldSelection = self.app.settings.value("MarkerFields", defaultValue=self.defaultValue)
|
||||
|
||||
if self.savedFieldSelection == "":
|
||||
self.savedFieldSelection = []
|
||||
|
||||
self.currentFieldSelection = self.savedFieldSelection.copy()
|
||||
|
||||
self.fieldSelectionView = QtWidgets.QListView()
|
||||
self.model = QtGui.QStandardItemModel()
|
||||
for field in self.fieldList:
|
||||
item = QtGui.QStandardItem(self.fieldList[field])
|
||||
item.setData(field)
|
||||
item.setCheckable(True)
|
||||
item.setEditable(False)
|
||||
if field in self.currentFieldSelection:
|
||||
item.setCheckState(QtCore.Qt.Checked)
|
||||
self.model.appendRow(item)
|
||||
self.fieldSelectionView.setModel(self.model)
|
||||
|
||||
self.model.itemChanged.connect(self.updateField)
|
||||
|
||||
fields_group_box_layout.addRow(self.fieldSelectionView)
|
||||
|
||||
layout.addWidget(settings_group_box)
|
||||
layout.addWidget(fields_group_box)
|
||||
layout.addWidget(self.exampleMarker.getGroupBox())
|
||||
|
||||
btn_layout = QtWidgets.QHBoxLayout()
|
||||
layout.addLayout(btn_layout)
|
||||
btn_ok = QtWidgets.QPushButton("OK")
|
||||
btn_apply = QtWidgets.QPushButton("Apply")
|
||||
btn_default = QtWidgets.QPushButton("Defaults")
|
||||
btn_cancel = QtWidgets.QPushButton("Cancel")
|
||||
|
||||
btn_ok.clicked.connect(self.okButtonClick)
|
||||
btn_apply.clicked.connect(self.applyButtonClick)
|
||||
btn_default.clicked.connect(self.defaultButtonClick)
|
||||
btn_cancel.clicked.connect(self.cancelButtonClick)
|
||||
|
||||
btn_layout.addWidget(btn_ok)
|
||||
btn_layout.addWidget(btn_apply)
|
||||
btn_layout.addWidget(btn_default)
|
||||
btn_layout.addWidget(btn_cancel)
|
||||
|
||||
self.updateMarker()
|
||||
for m in self.app.markers:
|
||||
m.setFieldSelection(self.currentFieldSelection)
|
||||
|
||||
def updateMarker(self):
|
||||
self.exampleMarker.setFieldSelection(self.currentFieldSelection)
|
||||
self.exampleMarker.findLocation(self.exampleData11)
|
||||
self.exampleMarker.resetLabels()
|
||||
self.exampleMarker.updateLabels(self.exampleData11, self.exampleData21)
|
||||
|
||||
def updateField(self, field: QtGui.QStandardItem):
|
||||
if field.checkState() == QtCore.Qt.Checked:
|
||||
if not field.data() in self.currentFieldSelection:
|
||||
self.currentFieldSelection = []
|
||||
for i in range(self.model.rowCount()):
|
||||
field = self.model.item(i, 0)
|
||||
if field.checkState() == QtCore.Qt.Checked:
|
||||
self.currentFieldSelection.append(field.data())
|
||||
else:
|
||||
if field.data() in self.currentFieldSelection:
|
||||
self.currentFieldSelection.remove(field.data())
|
||||
self.updateMarker()
|
||||
|
||||
def applyButtonClick(self):
|
||||
self.savedFieldSelection = self.currentFieldSelection.copy()
|
||||
self.app.settings.setValue("MarkerFields", self.savedFieldSelection)
|
||||
for m in self.app.markers:
|
||||
m.setFieldSelection(self.savedFieldSelection)
|
||||
|
||||
def okButtonClick(self):
|
||||
self.applyButtonClick()
|
||||
self.close()
|
||||
|
||||
def cancelButtonClick(self):
|
||||
self.currentFieldSelection = self.savedFieldSelection.copy()
|
||||
self.resetModel()
|
||||
self.updateMarker()
|
||||
self.close()
|
||||
|
||||
def defaultButtonClick(self):
|
||||
self.currentFieldSelection = self.defaultValue.copy()
|
||||
self.resetModel()
|
||||
self.updateMarker()
|
||||
|
||||
def resetModel(self):
|
||||
self.model = QtGui.QStandardItemModel()
|
||||
for field in self.fieldList:
|
||||
item = QtGui.QStandardItem(self.fieldList[field])
|
||||
item.setData(field)
|
||||
item.setCheckable(True)
|
||||
item.setEditable(False)
|
||||
if field in self.currentFieldSelection:
|
||||
item.setCheckState(QtCore.Qt.Checked)
|
||||
self.model.appendRow(item)
|
||||
self.fieldSelectionView.setModel(self.model)
|
||||
|
|
Ładowanie…
Reference in New Issue