This commit is contained in:
恍兮惚兮 2024-08-01 22:33:05 +08:00
parent 60ef30195b
commit d694a34d1a

View File

@ -105,12 +105,18 @@ class TableViewW(QTableView):
if isinstance(m, LStandardItemModel): if isinstance(m, LStandardItemModel):
m.updatelangtext() m.updatelangtext()
def safetext(self, row, col): def safetext(self, row, col=None):
_1 = self.model().item(row, col) if col is None:
index = row
else:
index = self.model().index(row, col)
_1 = self.model().itemFromIndex(index)
_1 = _1.text() if _1 else "" _1 = _1.text() if _1 else ""
return _1 return _1
def copytable(self) -> str: def copytable(self) -> str:
if len(self.selectedIndexes()) <= 1:
return winsharedutils.clipboard_set(self.safetext(self.currentIndex()))
_data = [] _data = []
minr = minc = 999999999 minr = minc = 999999999
maxr = maxc = 0 maxr = maxc = 0
@ -119,10 +125,9 @@ class TableViewW(QTableView):
minc = min(minc, index.column()) minc = min(minc, index.column())
maxr = max(maxr, index.row()) maxr = max(maxr, index.row())
maxc = max(maxc, index.column()) maxc = max(maxc, index.column())
_data.append(self.model().itemFromIndex(index).text()) _data.append(self.safetext(index))
data = { data = {
"data": _data, "data": _data,
"isluna": True,
"row": maxr - minr + 1, "row": maxr - minr + 1,
"col": maxc - minc + 1, "col": maxc - minc + 1,
} }
@ -132,8 +137,6 @@ class TableViewW(QTableView):
string = winsharedutils.clipboard_get() string = winsharedutils.clipboard_get()
try: try:
js = json.loads(string) js = json.loads(string)
if not js.get("isluna", False):
raise
current = self.currentIndex() current = self.currentIndex()
for _ in range(js["row"]): for _ in range(js["row"]):
self.model().insertRow(current.row() + 1, []) self.model().insertRow(current.row() + 1, [])
@ -147,7 +150,6 @@ class TableViewW(QTableView):
) )
except: except:
print_exc()
self.model().itemFromIndex(self.currentIndex()).setText(string) self.model().itemFromIndex(self.currentIndex()).setText(string)