Commit 77554119 authored by Michael Büsch's avatar Michael Büsch

gui: Add intermediate dirt level for cpu state view changes

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent ea7245bf
......@@ -19,7 +19,6 @@
## GUI
* Add feature: Save window status (open MDI windows, positions, etc)
* Add feature: LAD (KOP) editor
## FBD/FUP GUI only
......
......@@ -1243,7 +1243,10 @@ class StateMdiArea(QMdiArea):
subWinClosed = Signal(QMdiSubWindow)
# Config-change (address, type, etc...) signal of sub window.
configChanged = Signal(QMdiSubWindow)
settingsChanged = Signal()
# Content-change (config or window positions).
contentChanged = Signal()
# Signal: Open an item.
# Argument: MDI sub window
......@@ -1256,16 +1259,24 @@ class StateMdiArea(QMdiArea):
QMdiArea.__init__(self, parent)
self.client = client
self.subWinAdded.connect(lambda w: self.contentChanged.emit())
self.subWinClosed.connect(lambda w: self.contentChanged.emit())
def addCpuStateWindow(self, stateWin):
"""Add a StateWindow instance to this MDI area.
This automatically creates the MDI window wrapper.
"""
mdiWin = StateMdiSubWindow(stateWin)
mdiWin.closed.connect(self.subWinClosed)
mdiWin.moved.connect(lambda w: self.contentChanged.emit())
self.addSubWindow(mdiWin, Qt.Window)
stateWin.configChanged.connect(lambda w: self.configChanged.emit(mdiWin))
stateWin.configChanged.connect(lambda w: self.settingsChanged.emit())
stateWin.configChanged.connect(lambda w: self.contentChanged.emit())
stateWin.openByIdentHash.connect(lambda h: self.openByIdentHash.emit(mdiWin, h))
stateWin.show()
self.subWinAdded.emit(mdiWin)
return mdiWin
......@@ -1327,6 +1338,7 @@ class StateMdiSubWindow(QMdiSubWindow):
"""
closed = Signal(QMdiSubWindow)
moved = Signal(QMdiSubWindow)
def __init__(self, childWidget):
QMdiSubWindow.__init__(self)
......@@ -1338,6 +1350,10 @@ class StateMdiSubWindow(QMdiSubWindow):
self.closed.emit(self)
QMdiSubWindow.closeEvent(self, ev)
def moveEvent(self, moveEvent):
QMdiSubWindow.moveEvent(self, moveEvent)
self.moved.emit(self)
def getWinSettings(self):
"""Get the GuiCpuStateWindowSettings object for this CPU view window.
"""
......
......@@ -284,7 +284,9 @@ class CpuWidget(QWidget):
self.stateMdi.subWinAdded.connect(lambda w: self.__uploadMemReadAreas())
self.stateMdi.subWinClosed.connect(lambda w: self.__stateMdiWindowClosed(w))
self.stateMdi.configChanged.connect(lambda w: self.__uploadMemReadAreas())
self.stateMdi.settingsChanged.connect(lambda: self.__uploadMemReadAreas())
self.stateMdi.contentChanged.connect(
lambda: self.mainWidget.setDirty(self.mainWidget.DIRTY_SLIGHT))
self.stateMdi.openByIdentHash.connect(
lambda mdiWin, identHash: self.mainWidget.openByIdentHash(identHash))
......@@ -793,8 +795,8 @@ class CpuWidget(QWidget):
else:
self.__stop()
def handleDirtyChange(self, dirty):
if dirty:
def handleDirtyChange(self, dirtyLevel):
if dirtyLevel == self.mainWidget.DIRTY_FULL:
self.reqOnlineDiagButtonState.emit(False)
def _onlineDiagToggled(self, onlineDiagBtnPressed):
......
......@@ -95,7 +95,7 @@ class MainWidget(QWidget):
# Signal: Project loaded
projectLoaded = Signal(Project)
# Signal: Dirty-status changed
dirtyChanged = Signal(bool)
dirtyChanged = Signal(int)
# Signal: Source text focus changed
textFocusChanged = Signal(bool)
# Signal: UndoAvailable state changed
......@@ -109,6 +109,13 @@ class MainWidget(QWidget):
# Signal: PasteAvailable state changed
pasteAvailableChanged = Signal(bool)
# Document dirty levels
EnumGen.start
DIRTY_NO = EnumGen.item
DIRTY_SLIGHT = EnumGen.item
DIRTY_FULL = EnumGen.item
EnumGen.end
def __init__(self, mainWindow, parent=None):
QWidget.__init__(self, parent)
self.setLayout(QGridLayout(self))
......@@ -120,7 +127,7 @@ class MainWidget(QWidget):
self.layout().addWidget(self.editMdiArea, 0, 0)
self.filename = None
self.dirty = False
self.__dirtyLevel = self.DIRTY_NO
self.editMdiArea.sourceChanged.connect(self.somethingChanged)
self.editMdiArea.focusChanged.connect(self.textFocusChanged)
......@@ -138,15 +145,20 @@ class MainWidget(QWidget):
return self.projectTreeModel.getProject()
def isDirty(self):
return self.dirty
def setDirty(self, dirty, force=False):
if dirty != self.dirty or force:
self.dirty = dirty
self.dirtyChanged.emit(self.dirty)
return self.__dirtyLevel == self.DIRTY_FULL
def setDirty(self, dirtyLevel=DIRTY_FULL, force=False):
if dirtyLevel != self.__dirtyLevel or force:
if (not force and
self.__dirtyLevel == self.DIRTY_FULL and
dirtyLevel == self.DIRTY_SLIGHT):
# Cannot go from full to slight.
return
self.__dirtyLevel = dirtyLevel
self.dirtyChanged.emit(self.__dirtyLevel)
def somethingChanged(self):
self.setDirty(True)
self.setDirty(self.DIRTY_FULL)
def getFilename(self):
return self.filename
......@@ -196,7 +208,7 @@ class MainWidget(QWidget):
return
def loadFile(self, filename, newIfNotExist=False):
if self.dirty:
if self.isDirty():
res = QMessageBox.question(self,
"Unsaved project",
"The current project is modified and contains unsaved changes.\n "
......@@ -244,9 +256,9 @@ class MainWidget(QWidget):
return False
self.filename = filename
if isNewProject or not self.getProject().getProjectFile():
self.setDirty(True, force=True)
self.setDirty(self.DIRTY_FULL, force=True)
else:
self.setDirty(False, force=True)
self.setDirty(self.DIRTY_NO, force=True)
self.projectLoaded.emit(self.getProject())
return True
......@@ -278,7 +290,7 @@ class MainWidget(QWidget):
"Failed to write project file", str(e))
return False
self.filename = filename
self.setDirty(dirty = False, force = True)
self.setDirty(self.DIRTY_NO, force=True)
return True
def save(self, newFile=False):
......@@ -509,6 +521,12 @@ class MainWindow(QMainWindow):
mainwnd = cls(initialAwlSource)
mainwnd.show()
if initialAwlSource and not mainwnd.mainWidget.isDirty():
# Revert back from DIRTY_SLIGHT to DIRTY_NO.
mainwnd.mainWidget.setDirty(mainwnd.mainWidget.DIRTY_NO,
force=True)
return mainwnd
def __init__(self, awlSource=None, parent=None):
......@@ -657,7 +675,7 @@ class MainWindow(QMainWindow):
self.menuBar().addMenu(menu)
self.__sourceTextHasFocus = False
self.__dirtyChanged(False)
self.__dirtyChanged(MainWidget.DIRTY_NO)
self.__textFocusChanged(False)
self.__undoAvailableChanged(False)
self.__redoAvailableChanged(False)
......@@ -792,14 +810,14 @@ class MainWindow(QMainWindow):
cpuDockEn = self.cpuDockWidget.toggleViewAction().isChecked()
self.inspectTb.toggleViewAction().setEnabled(cpuDockEn)
def __dirtyChanged(self, isDirty):
self.saveAct.setEnabled(isDirty)
self.tbSaveAct.setEnabled(isDirty)
def __dirtyChanged(self, dirtyLevel):
self.saveAct.setEnabled(dirtyLevel != MainWidget.DIRTY_NO)
self.tbSaveAct.setEnabled(dirtyLevel != MainWidget.DIRTY_NO)
filename = self.mainWidget.getFilename()
if filename:
postfix = " -- " + os.path.basename(filename)
if isDirty:
if dirtyLevel == MainWidget.DIRTY_FULL:
postfix += "*"
else:
postfix = ""
......
......@@ -1163,7 +1163,7 @@ class ProjectTreeModel(QAbstractItemModel):
return title
return None
def __handleProjectDirtyChanged(self, dirty):
def __handleProjectDirtyChanged(self, dirtyLevel):
self.headerDataChanged.emit(Qt.Horizontal, 0, 0)
def mimeData(self, indexes):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment