document
document
Classes
LayerDocument(config, parent=None)
Bases: QObject
Edit state for every layer of a LayeredConfig.
Each layer gets its own tree model and undo stack, created on first access, so history survives switching layers. Edits only touch a layer's own raw data.
Initialize the document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LayeredConfig
|
The config whose layers are edited. |
required |
parent
|
QObject | None
|
Parent object. |
None
|
Source code in src/json_config_qt/document.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
Attributes
config = config
instance-attribute
currentLayerChanged = QtCore.Signal(str)
class-attribute
instance-attribute
current_layer
property
Return the name of the layer being edited, or None if there are no layers.
dirtyChanged = QtCore.Signal()
class-attribute
instance-attribute
dirty_layers
property
Return the names of layers with unsaved edits.
is_dirty
property
Return whether any layer has unsaved edits.
layers
property
Return the layer names in topological order.
layersChanged = QtCore.Signal()
class-attribute
instance-attribute
model
property
Return the tree model of the current layer, or None if there are no layers.
saved = QtCore.Signal(str)
class-attribute
instance-attribute
undo_group = QtGui.QUndoGroup(self)
instance-attribute
Methods:
layer(name)
Return the config layer registered as name.
Source code in src/json_config_qt/document.py
47 48 49 | |
model_for(name)
Return the tree model of a layer, creating it on first access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The layer name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
JsonTreeModel |
JsonTreeModel
|
The layer's model, holding its own undo stack. |
Source code in src/json_config_qt/document.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
new_layer(name, depends_on=None, file_path=None)
Register a new, empty layer and make it current.
Raises:
| Type | Description |
|---|---|
ValueError
|
if a layer called name already exists or depends_on is not a registered layer. |
Source code in src/json_config_qt/document.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
save_all()
Save every layer that has unsaved edits.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a dirty layer has no file path. |
Source code in src/json_config_qt/document.py
141 142 143 144 145 146 147 148 | |
save_layer(name)
Write one layer to its file and refresh the config's resolved values.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if the layer has no file path. |
Source code in src/json_config_qt/document.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
set_layer(name)
Make name the current layer.
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not a registered layer. |
Source code in src/json_config_qt/document.py
74 75 76 77 78 79 80 81 82 83 84 85 86 | |