x axis change
This commit is contained in:
@@ -4,7 +4,7 @@ from PySide6.QtCore import QObject, QPoint, Qt
|
||||
from PySide6.QtGui import QUndoStack
|
||||
from PySide6.QtWidgets import QInputDialog, QMenu, QTreeWidgetItem, QWidget
|
||||
|
||||
from bedit_gui.commands.simulation_plot_commands import AddSimulationPlotTabCommand, ChangeSimulationPlotSignalsCommand, RemoveSimulationPlotTabCommand, RenameSimulationPlotTabCommand
|
||||
from bedit_gui.commands.simulation_plot_commands import AddSimulationPlotTabCommand, ChangeSimulationPlotSignalsCommand, ChangeSimulationPlotXAxisCommand, RemoveSimulationPlotTabCommand, RenameSimulationPlotTabCommand
|
||||
from bedit_gui.controllers.simulation_file_controller import SimulationFileController
|
||||
from bedit_gui.services.application_logging import get_logger
|
||||
from bedit_gui.simulation_models import SimulationPlotTab
|
||||
@@ -29,6 +29,8 @@ class SimulationPlotController(QObject):
|
||||
tabs.tabBar().setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
tabs.tabBar().customContextMenuRequested.connect(self._show_tab_menu)
|
||||
tree.itemChanged.connect(self._signal_changed)
|
||||
tree.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
tree.customContextMenuRequested.connect(self._show_signal_menu)
|
||||
files.runtime_changed.connect(self.load_root)
|
||||
|
||||
window.ui.actionUndo.triggered.connect(self.undo)
|
||||
@@ -201,6 +203,25 @@ class SimulationPlotController(QObject):
|
||||
elif selected is remove_action:
|
||||
self.remove_tab(index)
|
||||
|
||||
def _show_signal_menu(self, position: QPoint) -> None:
|
||||
root = self.files.root
|
||||
tree = self.window.ui.simulationTree
|
||||
item = tree.itemAt(position)
|
||||
signal = item.data(0, Qt.ItemDataRole.UserRole) if item is not None else None
|
||||
if root is None or signal is None or not 0 <= self._active_tab < len(root.plot_tabs):
|
||||
return
|
||||
tab = root.plot_tabs[self._active_tab]
|
||||
menu = QMenu(tree)
|
||||
use_signal = menu.addAction("Use as x axis")
|
||||
use_signal.setEnabled(tab.x_axis != signal)
|
||||
use_time = menu.addAction("Use time as x axis")
|
||||
use_time.setEnabled(tab.x_axis is not None)
|
||||
selected = menu.exec(tree.viewport().mapToGlobal(position))
|
||||
if selected is use_signal:
|
||||
self.undo_stack.push(ChangeSimulationPlotXAxisCommand(root, self._active_tab, signal, self._selection_changed))
|
||||
elif selected is use_time:
|
||||
self.undo_stack.push(ChangeSimulationPlotXAxisCommand(root, self._active_tab, None, self._selection_changed))
|
||||
|
||||
def _available_signals(self) -> list[str]:
|
||||
root = self.files.root
|
||||
if root is None:
|
||||
@@ -220,7 +241,8 @@ class SimulationPlotController(QObject):
|
||||
return
|
||||
widget = self.window.ui.resultsTabWidget.widget(index)
|
||||
if isinstance(widget, SimulationPlotWidget):
|
||||
widget.set_plot(root.results, root.plot_tabs[index].signals)
|
||||
tab = root.plot_tabs[index]
|
||||
widget.set_plot(root.results, tab.signals, tab.x_axis)
|
||||
|
||||
def _set_undo_text(self, command: str) -> None:
|
||||
self.window.ui.actionUndo.setText(f"Undo {command}" if command else "Undo")
|
||||
|
||||
Reference in New Issue
Block a user