mirror of https://gitlab.com/pamhyr/pamhyr2
geometry: Profile: Fix delete command undo point order.
parent
b3a6d0713d
commit
ff9c47eb83
|
|
@ -140,19 +140,47 @@ class Profile(object):
|
||||||
self._points.insert(index, point)
|
self._points.insert(index, point)
|
||||||
|
|
||||||
|
|
||||||
def delete(self, index: int):
|
def delete(self, indexes: int):
|
||||||
"""Delete the point at index
|
"""Delete points at index
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
index: Index of point.
|
indexes: List of index of points.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Nothing.
|
Nothing.
|
||||||
"""
|
"""
|
||||||
try:
|
points = set(
|
||||||
self._points.pop(index)
|
map(
|
||||||
except IndexError:
|
lambda e: e[1],
|
||||||
raise IndexError(f"Invalid point index: {index}")
|
filter(
|
||||||
|
lambda e: e[0] in indexes,
|
||||||
|
enumerate(self.points)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self._points = list(
|
||||||
|
filter(
|
||||||
|
lambda p: p not in points,
|
||||||
|
self.points
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def delete_points(self, points):
|
||||||
|
"""Delete some elements in profile list
|
||||||
|
|
||||||
|
Args:
|
||||||
|
points: The list of profile to delete
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Nothing.
|
||||||
|
"""
|
||||||
|
self._points = list(
|
||||||
|
filter(
|
||||||
|
lambda p: p not in points,
|
||||||
|
self.points
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Move
|
# Move
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,18 +69,15 @@ class DelCommand(QUndoCommand):
|
||||||
|
|
||||||
self._points = []
|
self._points = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
self._points.append(self._profile.point(row))
|
self._points.append((row, self._profile.point(row)))
|
||||||
self._points.reverse()
|
self._points.sort() # Sort by row index
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
row = self._rows[0]
|
for row, point in self._points:
|
||||||
for point in self._points:
|
|
||||||
self._profile.insert_point(row, point)
|
self._profile.insert_point(row, point)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
row = self._rows[0]
|
self._profile.delete(self._rows)
|
||||||
for _ in self._rows:
|
|
||||||
self._profile.delete(row)
|
|
||||||
|
|
||||||
class SortCommand(QUndoCommand):
|
class SortCommand(QUndoCommand):
|
||||||
def __init__(self, profile, column, _reverse):
|
def __init__(self, profile, column, _reverse):
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@ class TableEditableModel(QAbstractTableModel):
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def remove_rows(self, rows, parent=QModelIndex()):
|
def remove_rows(self, rows, parent=QModelIndex()):
|
||||||
self.beginRemoveRows(parent, rows[0], row[-1])
|
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||||
|
|
||||||
self._undo_stack.push(
|
self._undo_stack.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
|
|
||||||
from colorama import Fore
|
from colorama import Fore
|
||||||
from colorama import Back
|
from colorama import Back
|
||||||
|
|
@ -59,6 +60,7 @@ def timer(func):
|
||||||
print(f"[{Fore.RED}ERROR{Style.RESET_ALL}]" +
|
print(f"[{Fore.RED}ERROR{Style.RESET_ALL}]" +
|
||||||
f"[{func.__module__}.{Fore.GREEN}{func.__qualname__}{Style.RESET_ALL}]: " +
|
f"[{func.__module__}.{Fore.GREEN}{func.__qualname__}{Style.RESET_ALL}]: " +
|
||||||
f"{Fore.RED}{e}{Style.RESET_ALL}")
|
f"{Fore.RED}{e}{Style.RESET_ALL}")
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
end_time = time.perf_counter()
|
end_time = time.perf_counter()
|
||||||
run_time = end_time - start_time
|
run_time = end_time - start_time
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue