diff --git a/allzpark/dock.py b/allzpark/dock.py index f71cf0a..7560d66 100644 --- a/allzpark/dock.py +++ b/allzpark/dock.py @@ -708,7 +708,11 @@ def on_copy_full(): else: data = model_.json() - text = str(data) + text = json.dumps(data, + indent=4, + sort_keys=True, + ensure_ascii=False) + app = QtWidgets.QApplication.instance() app.clipboard().setText(text) diff --git a/allzpark/model.py b/allzpark/model.py index 55a2292..17349b2 100644 --- a/allzpark/model.py +++ b/allzpark/model.py @@ -541,6 +541,9 @@ def poll(self): class JsonModel(qjsonmodel.QJsonModel): + + JsonRole = QtCore.Qt.UserRole + 1 + def setData(self, index, value, role): # Support copy/paste, but prevent edits return False @@ -562,8 +565,13 @@ def data(self, index, role): if index.column() == 1: return item.value + if role == self.JsonRole: + return self.json(item) + return super(JsonModel, self).data(index, role) + reset = qjsonmodel.QJsonModel.clear + class EnvironmentModel(JsonModel): def load(self, data): diff --git a/allzpark/vendor/qjsonmodel.py b/allzpark/vendor/qjsonmodel.py index 2c396a3..55d0025 100644 --- a/allzpark/vendor/qjsonmodel.py +++ b/allzpark/vendor/qjsonmodel.py @@ -113,7 +113,7 @@ def load(self, value, parent=None, sort=True): elif isinstance(value, list): for index, value in enumerate(value): child = self.load(value, rootItem) - child.key = str(index) + child.key = index child.type = type(value) rootItem.appendChild(child) @@ -125,15 +125,13 @@ def load(self, value, parent=None, sort=True): class QJsonModel(QtCore.QAbstractItemModel): - JsonRole = QtCore.Qt.UserRole + 1 - def __init__(self, parent=None): super(QJsonModel, self).__init__(parent) self._rootItem = QJsonTreeItem() self._headers = ("key", "value") - def reset(self): + def clear(self): self.load({}) def load(self, document): @@ -190,9 +188,6 @@ def data(self, index, role): if index.column() == 1: return item.value - if role == QJsonModel.JsonRole: - return self.json(item) - def setData(self, index, value, role): if role == QtCore.Qt.EditRole: if index.column() == 1: