- modified the Bookmark manager to be installed as a widget tab in Plot Area; fixed the drag & drop function for the table rows that have CellWidgets inside
- marked in gray color the rows in the Bookmark Manager table that will populate the BookMark menu - made sure that only one instance of the BookmarkManager class is active at one time
This commit is contained in:
@@ -20,7 +20,10 @@ from copy import copy
|
||||
import re
|
||||
import logging
|
||||
import html
|
||||
import webbrowser
|
||||
from copy import deepcopy
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
log = logging.getLogger('base')
|
||||
|
||||
@@ -1705,6 +1708,9 @@ class OptionalHideInputSection:
|
||||
|
||||
|
||||
class FCTable(QtWidgets.QTableWidget):
|
||||
|
||||
drag_drop_sig = pyqtSignal()
|
||||
|
||||
def __init__(self, drag_drop=False, parent=None):
|
||||
super(FCTable, self).__init__(parent)
|
||||
|
||||
@@ -1763,71 +1769,117 @@ class FCTable(QtWidgets.QTableWidget):
|
||||
self.addAction(action)
|
||||
action.triggered.connect(call_function)
|
||||
|
||||
def dropEvent(self, event: QtGui.QDropEvent):
|
||||
if not event.isAccepted() and event.source() == self:
|
||||
drop_row = self.drop_on(event)
|
||||
# def dropEvent(self, event: QtGui.QDropEvent):
|
||||
# if not event.isAccepted() and event.source() == self:
|
||||
# drop_row = self.drop_on(event)
|
||||
#
|
||||
# rows = sorted(set(item.row() for item in self.selectedItems()))
|
||||
# # rows_to_move = [
|
||||
# # [QtWidgets.QTableWidgetItem(self.item(row_index, column_index))
|
||||
# # for column_index in range(self.columnCount())] for row_index in rows
|
||||
# # ]
|
||||
# self.rows_to_move[:] = []
|
||||
# for row_index in rows:
|
||||
# row_items = list()
|
||||
# for column_index in range(self.columnCount()):
|
||||
# r_item = self.item(row_index, column_index)
|
||||
# w_item = self.cellWidget(row_index, column_index)
|
||||
#
|
||||
# if r_item is not None:
|
||||
# row_items.append(QtWidgets.QTableWidgetItem(r_item))
|
||||
# elif w_item is not None:
|
||||
# row_items.append(w_item)
|
||||
#
|
||||
# self.rows_to_move.append(row_items)
|
||||
#
|
||||
# for row_index in reversed(rows):
|
||||
# self.removeRow(row_index)
|
||||
# if row_index < drop_row:
|
||||
# drop_row -= 1
|
||||
#
|
||||
# for row_index, data in enumerate(self.rows_to_move):
|
||||
# row_index += drop_row
|
||||
# self.insertRow(row_index)
|
||||
#
|
||||
# for column_index, column_data in enumerate(data):
|
||||
# if isinstance(column_data, QtWidgets.QTableWidgetItem):
|
||||
# self.setItem(row_index, column_index, column_data)
|
||||
# else:
|
||||
# self.setCellWidget(row_index, column_index, column_data)
|
||||
#
|
||||
# event.accept()
|
||||
# for row_index in range(len(self.rows_to_move)):
|
||||
# self.item(drop_row + row_index, 0).setSelected(True)
|
||||
# self.item(drop_row + row_index, 1).setSelected(True)
|
||||
#
|
||||
# super().dropEvent(event)
|
||||
#
|
||||
# def drop_on(self, event):
|
||||
# ret_val = False
|
||||
# index = self.indexAt(event.pos())
|
||||
# if not index.isValid():
|
||||
# return self.rowCount()
|
||||
#
|
||||
# ret_val = index.row() + 1 if self.is_below(event.pos(), index) else index.row()
|
||||
#
|
||||
# return ret_val
|
||||
#
|
||||
# def is_below(self, pos, index):
|
||||
# rect = self.visualRect(index)
|
||||
# margin = 2
|
||||
# if pos.y() - rect.top() < margin:
|
||||
# return False
|
||||
# elif rect.bottom() - pos.y() < margin:
|
||||
# return True
|
||||
# # noinspection PyTypeChecker
|
||||
# return rect.contains(pos, True) and not (
|
||||
# int(self.model().flags(index)) & Qt.ItemIsDropEnabled) and pos.y() >= rect.center().y()
|
||||
|
||||
rows = sorted(set(item.row() for item in self.selectedItems()))
|
||||
# rows_to_move = [
|
||||
# [QtWidgets.QTableWidgetItem(self.item(row_index, column_index))
|
||||
# for column_index in range(self.columnCount())] for row_index in rows
|
||||
# ]
|
||||
self.rows_to_move[:] = []
|
||||
for row_index in rows:
|
||||
row_items = list()
|
||||
for column_index in range(self.columnCount()):
|
||||
r_item = self.item(row_index, column_index)
|
||||
w_item = self.cellWidget(row_index, column_index)
|
||||
def dropEvent(self, event):
|
||||
"""
|
||||
From here: https://stackoverflow.com/questions/26227885/drag-and-drop-rows-within-qtablewidget
|
||||
:param event:
|
||||
:return:
|
||||
"""
|
||||
if event.source() == self:
|
||||
rows = set([mi.row() for mi in self.selectedIndexes()])
|
||||
targetRow = self.indexAt(event.pos()).row()
|
||||
rows.discard(targetRow)
|
||||
rows = sorted(rows)
|
||||
|
||||
if r_item is not None:
|
||||
row_items.append(QtWidgets.QTableWidgetItem(r_item))
|
||||
elif w_item is not None:
|
||||
row_items.append(w_item)
|
||||
if not rows:
|
||||
return
|
||||
if targetRow == -1:
|
||||
targetRow = self.rowCount()
|
||||
|
||||
self.rows_to_move.append(row_items)
|
||||
for _ in range(len(rows)):
|
||||
self.insertRow(targetRow)
|
||||
|
||||
for row_index in reversed(rows):
|
||||
self.removeRow(row_index)
|
||||
if row_index < drop_row:
|
||||
drop_row -= 1
|
||||
rowMapping = dict() # Src row to target row.
|
||||
for idx, row in enumerate(rows):
|
||||
if row < targetRow:
|
||||
rowMapping[row] = targetRow + idx
|
||||
else:
|
||||
rowMapping[row + len(rows)] = targetRow + idx
|
||||
|
||||
for row_index, data in enumerate(self.rows_to_move):
|
||||
row_index += drop_row
|
||||
self.insertRow(row_index)
|
||||
|
||||
for column_index, column_data in enumerate(data):
|
||||
if isinstance(column_data, QtWidgets.QTableWidgetItem):
|
||||
self.setItem(row_index, column_index, column_data)
|
||||
colCount = self.columnCount()
|
||||
for srcRow, tgtRow in sorted(rowMapping.items()):
|
||||
for col in range(0, colCount):
|
||||
new_item = self.item(srcRow, col)
|
||||
if new_item is None:
|
||||
new_item = self.cellWidget(srcRow, col)
|
||||
if isinstance(new_item, QtWidgets.QTableWidgetItem):
|
||||
new_item = self.takeItem(srcRow, col)
|
||||
self.setItem(tgtRow, col, new_item)
|
||||
else:
|
||||
self.setCellWidget(row_index, column_index, column_data)
|
||||
self.setCellWidget(tgtRow, col, new_item)
|
||||
|
||||
for row in reversed(sorted(rowMapping.keys())):
|
||||
self.removeRow(row)
|
||||
event.accept()
|
||||
for row_index in range(len(self.rows_to_move)):
|
||||
self.item(drop_row + row_index, 0).setSelected(True)
|
||||
self.item(drop_row + row_index, 1).setSelected(True)
|
||||
self.drag_drop_sig.emit()
|
||||
|
||||
super().dropEvent(event)
|
||||
|
||||
def drop_on(self, event):
|
||||
ret_val = False
|
||||
index = self.indexAt(event.pos())
|
||||
if not index.isValid():
|
||||
return self.rowCount()
|
||||
|
||||
ret_val = index.row() + 1 if self.is_below(event.pos(), index) else index.row()
|
||||
|
||||
return ret_val
|
||||
|
||||
def is_below(self, pos, index):
|
||||
rect = self.visualRect(index)
|
||||
margin = 2
|
||||
if pos.y() - rect.top() < margin:
|
||||
return False
|
||||
elif rect.bottom() - pos.y() < margin:
|
||||
return True
|
||||
# noinspection PyTypeChecker
|
||||
return rect.contains(pos, True) and not (
|
||||
int(self.model().flags(index)) & Qt.ItemIsDropEnabled) and pos.y() >= rect.center().y()
|
||||
return
|
||||
|
||||
|
||||
class SpinBoxDelegate(QtWidgets.QItemDelegate):
|
||||
|
||||
Reference in New Issue
Block a user