mirror of https://gitlab.com/pamhyr/pamhyr2
Scenario: Add duplicate command.
parent
0608b9175e
commit
9043b6e2a3
|
|
@ -57,14 +57,23 @@ class DefaultMenu(AbstractMenu):
|
|||
class ScenarioMenu(AbstractMenu):
|
||||
def run(self):
|
||||
item = self._items[0]
|
||||
current_scenario = item.graph._study.status.scenario.id
|
||||
|
||||
select = self._menu.addAction(self._trad["menu_select_scenario"])
|
||||
duplicate = None
|
||||
delete = None
|
||||
|
||||
if item.scenario.id != 0:
|
||||
delete = self._menu.addAction(self._trad["menu_del_scenario"])
|
||||
if item.scenario.id == current_scenario:
|
||||
duplicate = self._menu.addAction(
|
||||
self._trad["menu_dup_scenario"]
|
||||
)
|
||||
|
||||
action = self._exec()
|
||||
if action == select:
|
||||
self._parent.select_scenario(item)
|
||||
elif item.scenario.id != 0:
|
||||
if action == delete:
|
||||
self._parent.delete_scenario(item)
|
||||
elif action == delete:
|
||||
self._parent.delete_scenario(item)
|
||||
elif action == duplicate:
|
||||
self._parent.duplicate_scenario(item)
|
||||
|
|
|
|||
|
|
@ -459,6 +459,19 @@ class GraphWidget(QGraphicsView):
|
|||
self.exec_with_waiting_window(fn, "delete_scenario")
|
||||
self.changeScenario.emit(self.sender())
|
||||
|
||||
def duplicate_scenario(self, item):
|
||||
def fn():
|
||||
self._close_other_window()
|
||||
# self._study.save()
|
||||
self._undo.push(
|
||||
DuplicateScenariosCommand(
|
||||
self._study,
|
||||
)
|
||||
)
|
||||
|
||||
self.exec_with_waiting_window(fn, "duplicate_scenario")
|
||||
self.changeScenario.emit(self.sender())
|
||||
|
||||
def _close_other_window(self):
|
||||
self.parent\
|
||||
.parent\
|
||||
|
|
|
|||
|
|
@ -80,6 +80,25 @@ class DeleteScenariosCommand(QUndoCommand):
|
|||
self._scenario.set_as_deleted()
|
||||
|
||||
|
||||
class DuplicateScenariosCommand(QUndoCommand):
|
||||
def __init__(self, study):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._study = study
|
||||
self._new = None
|
||||
|
||||
def undo(self):
|
||||
self._study.scenarios.delete(self._new.id)
|
||||
self._study.reload_from_scenario(self._new.parent)
|
||||
|
||||
def redo(self):
|
||||
if self._new is None:
|
||||
self._new = self._study.duplicate_current_scenario()
|
||||
else:
|
||||
self._new.set_as_not_deleted()
|
||||
self._study.reload_from_scenario(self._new)
|
||||
|
||||
|
||||
class SetCommand(QUndoCommand):
|
||||
def __init__(self, scenario, column, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ class ScenariosTranslate(MainTranslate):
|
|||
self._dict["menu_del_scenario"] = _translate(
|
||||
"Scenarios", "Delete this scenario"
|
||||
)
|
||||
self._dict["menu_dup_scenario"] = _translate(
|
||||
"Scenarios", "Duplicate this scenario"
|
||||
)
|
||||
|
||||
self._sub_dict["table_headers_scenarios"] = {
|
||||
# "id": self._dict['id'],
|
||||
|
|
|
|||
Loading…
Reference in New Issue