mirror of https://gitlab.com/pamhyr/pamhyr2
SL: Model add basic command for SL and fix DB save artifact.
parent
17c0035a0a
commit
7898ab86c6
|
|
@ -180,7 +180,56 @@ class SedimentLayer(SQLSubModel):
|
|||
for l in self._layers:
|
||||
data["ind"] = ind
|
||||
l._sql_save(execute, data)
|
||||
|
||||
ind += 1
|
||||
|
||||
return True
|
||||
|
||||
def get(self, index):
|
||||
return self._layers[index]
|
||||
|
||||
def set(self, index, new):
|
||||
self._layers[index] = new
|
||||
self._status.modified()
|
||||
|
||||
def insert(self, index, new):
|
||||
self._layers.insert(index, new)
|
||||
self._status.modified()
|
||||
|
||||
def new(self, index):
|
||||
n = Layer(status = self._status)
|
||||
self.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def delete(self, els):
|
||||
for el in els:
|
||||
self._layers.remove(el)
|
||||
self._status.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
els = list(
|
||||
map(
|
||||
lambda x: x[1],
|
||||
filter(
|
||||
lambda x: x[0] in indexes,
|
||||
enumerate(self._layers)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.delete(els)
|
||||
|
||||
def move_up(self, index):
|
||||
if index < len(self._layers):
|
||||
next = index - 1
|
||||
|
||||
l = self._layers
|
||||
l[index], l[next] = l[next], l[index]
|
||||
self._status.modified()
|
||||
|
||||
def move_down(self, index):
|
||||
if index >= 0:
|
||||
prev = index + 1
|
||||
|
||||
l = self._layers
|
||||
l[index], l[prev] = l[prev], l[index]
|
||||
self._status.modified()
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ class SedimentLayerList(SQLSubModel):
|
|||
def _sql_save(self, execute, data = None):
|
||||
ok = True
|
||||
|
||||
# Delete previous data
|
||||
execute("DELETE FROM sedimentary_layer")
|
||||
execute("DELETE FROM sedimentary_layer_layer")
|
||||
|
||||
for sl in self._sl:
|
||||
ok &= sl._sql_save(execute, data)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue