kopia lustrzana https://github.com/corrscope/corrscope
Mark GUI as edited when browsing for file, or adding/reordering channels (#124)
rodzic
d5b91a05f7
commit
894af9fd01
|
@ -195,6 +195,7 @@ class MainWindow(qw.QMainWindow):
|
||||||
|
|
||||||
if self.model is None:
|
if self.model is None:
|
||||||
self.model = ConfigModel(cfg)
|
self.model = ConfigModel(cfg)
|
||||||
|
self.model.edited.connect(self.on_model_edited)
|
||||||
# Calls self.on_gui_edited() whenever GUI widgets change.
|
# Calls self.on_gui_edited() whenever GUI widgets change.
|
||||||
map_gui(self, self.model)
|
map_gui(self, self.model)
|
||||||
else:
|
else:
|
||||||
|
@ -203,9 +204,12 @@ class MainWindow(qw.QMainWindow):
|
||||||
self.channel_model = ChannelModel(cfg.channels)
|
self.channel_model = ChannelModel(cfg.channels)
|
||||||
# Calling setModel again disconnects previous model.
|
# Calling setModel again disconnects previous model.
|
||||||
self.channel_view.setModel(self.channel_model)
|
self.channel_view.setModel(self.channel_model)
|
||||||
self.channel_model.dataChanged.connect(self.on_gui_edited)
|
self.channel_model.dataChanged.connect(self.on_model_edited)
|
||||||
|
self.channel_model.rowsInserted.connect(self.on_model_edited)
|
||||||
|
self.channel_model.rowsMoved.connect(self.on_model_edited)
|
||||||
|
self.channel_model.rowsRemoved.connect(self.on_model_edited)
|
||||||
|
|
||||||
def on_gui_edited(self):
|
def on_model_edited(self):
|
||||||
self.any_unsaved = True
|
self.any_unsaved = True
|
||||||
|
|
||||||
title_cache: str
|
title_cache: str
|
||||||
|
|
|
@ -21,7 +21,7 @@ WidgetUpdater = Callable[[], None]
|
||||||
Attrs = Any
|
Attrs = Any
|
||||||
|
|
||||||
|
|
||||||
class PresentationModel:
|
class PresentationModel(qc.QObject):
|
||||||
""" Key-value MVP presentation-model.
|
""" Key-value MVP presentation-model.
|
||||||
|
|
||||||
Qt's built-in model-view framework expects all models to
|
Qt's built-in model-view framework expects all models to
|
||||||
|
@ -33,8 +33,10 @@ class PresentationModel:
|
||||||
# Although less explicit, these can be assigned using __init_subclass__.
|
# Although less explicit, these can be assigned using __init_subclass__.
|
||||||
combo_symbols: Dict[str, List[str]]
|
combo_symbols: Dict[str, List[str]]
|
||||||
combo_text: Dict[str, List[str]]
|
combo_text: Dict[str, List[str]]
|
||||||
|
edited = qc.pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, cfg: Attrs):
|
def __init__(self, cfg: Attrs):
|
||||||
|
super().__init__()
|
||||||
self.cfg = cfg
|
self.cfg = cfg
|
||||||
self.update_widget: Dict[str, WidgetUpdater] = {}
|
self.update_widget: Dict[str, WidgetUpdater] = {}
|
||||||
|
|
||||||
|
@ -46,6 +48,8 @@ class PresentationModel:
|
||||||
return rgetattr(self.cfg, item)
|
return rgetattr(self.cfg, item)
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
|
self.edited.emit()
|
||||||
|
|
||||||
# Custom properties
|
# Custom properties
|
||||||
if hasattr(type(self), key):
|
if hasattr(type(self), key):
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
@ -77,7 +81,6 @@ def map_gui(view: "MainWindow", model: PresentationModel):
|
||||||
for widget in widgets:
|
for widget in widgets:
|
||||||
path = widget.objectName()
|
path = widget.objectName()
|
||||||
widget.bind_widget(model, path)
|
widget.bind_widget(model, path)
|
||||||
widget.gui_changed.connect(view.on_gui_edited)
|
|
||||||
|
|
||||||
|
|
||||||
Signal = Any
|
Signal = Any
|
||||||
|
|
Ładowanie…
Reference in New Issue