mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-30 17:36:33 +02:00
[commands] expose and use more UndoStack properties
This commit is contained in:
parent
2fcdc586a6
commit
e17d0ea240
2 changed files with 28 additions and 3 deletions
|
@ -1,8 +1,9 @@
|
||||||
from PySide2 import QtWidgets
|
from PySide2.QtWidgets import QUndoCommand, QUndoStack
|
||||||
|
from PySide2.QtCore import Property, Signal
|
||||||
from meshroom.processGraph.graph import Node
|
from meshroom.processGraph.graph import Node
|
||||||
|
|
||||||
|
|
||||||
class UndoCommand(QtWidgets.QUndoCommand):
|
class UndoCommand(QUndoCommand):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(UndoCommand, self).__init__(parent)
|
super(UndoCommand, self).__init__(parent)
|
||||||
self._enabled = True
|
self._enabled = True
|
||||||
|
@ -27,9 +28,15 @@ class UndoCommand(QtWidgets.QUndoCommand):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class UndoStack(QtWidgets.QUndoStack):
|
class UndoStack(QUndoStack):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(UndoStack, self).__init__(parent)
|
super(UndoStack, self).__init__(parent)
|
||||||
|
# connect QUndoStack signal to UndoStack's ones
|
||||||
|
self.cleanChanged.connect(self._cleanChanged)
|
||||||
|
self.canUndoChanged.connect(self._canUndoChanged)
|
||||||
|
self.canRedoChanged.connect(self._canRedoChanged)
|
||||||
|
self.undoTextChanged.connect(self._undoTextChanged)
|
||||||
|
self.redoTextChanged.connect(self._redoTextChanged)
|
||||||
|
|
||||||
def tryAndPush(self, command: UndoCommand):
|
def tryAndPush(self, command: UndoCommand):
|
||||||
if command.redoImpl():
|
if command.redoImpl():
|
||||||
|
@ -40,6 +47,19 @@ class UndoStack(QtWidgets.QUndoStack):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Redeclare QUndoStack signal since original ones can not be used for properties notifying
|
||||||
|
_cleanChanged = Signal()
|
||||||
|
_canUndoChanged = Signal()
|
||||||
|
_canRedoChanged = Signal()
|
||||||
|
_undoTextChanged = Signal()
|
||||||
|
_redoTextChanged = Signal()
|
||||||
|
|
||||||
|
clean = Property(bool, QUndoStack.isClean, notify=_cleanChanged)
|
||||||
|
canUndo = Property(bool, QUndoStack.canUndo, notify=_canRedoChanged)
|
||||||
|
canRedo = Property(bool, QUndoStack.canRedo, notify=_canUndoChanged)
|
||||||
|
undoText = Property(str, QUndoStack.undoText, notify=_undoTextChanged)
|
||||||
|
redoText = Property(str, QUndoStack.redoText, notify=_redoTextChanged)
|
||||||
|
|
||||||
|
|
||||||
class GraphCommand(UndoCommand):
|
class GraphCommand(UndoCommand):
|
||||||
def __init__(self, graph, parent=None):
|
def __init__(self, graph, parent=None):
|
||||||
|
|
|
@ -42,9 +42,12 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
Item {width: 4; height: 1}
|
Item {width: 4; height: 1}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
text: "Undo"
|
text: "Undo"
|
||||||
activeFocusOnPress: true
|
activeFocusOnPress: true
|
||||||
|
enabled: _reconstruction.undoStack.canUndo
|
||||||
|
tooltip: 'Undo "' +_reconstruction.undoStack.undoText +'"'
|
||||||
onClicked: {
|
onClicked: {
|
||||||
_reconstruction.undoStack.undo()
|
_reconstruction.undoStack.undo()
|
||||||
}
|
}
|
||||||
|
@ -52,6 +55,8 @@ ApplicationWindow {
|
||||||
Button {
|
Button {
|
||||||
text: "Redo"
|
text: "Redo"
|
||||||
activeFocusOnPress: true
|
activeFocusOnPress: true
|
||||||
|
enabled: _reconstruction.undoStack.canRedo
|
||||||
|
tooltip: 'Redo "' +_reconstruction.undoStack.redoText +'"'
|
||||||
onClicked: {
|
onClicked: {
|
||||||
_reconstruction.undoStack.redo()
|
_reconstruction.undoStack.redo()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue