NBTEditorWidget now emits tagValueChanged when a value is changed. More signals soon, maybe?
This commit is contained in:
parent
ef302935a2
commit
69f7f3696f
@ -291,6 +291,7 @@ class InventoryEditor(QtGui.QWidget):
|
||||
self.rawIDCheckbox.toggled.connect(self.rawIDInput.setEnabled)
|
||||
|
||||
self.itemNBTEditor = NBTEditorWidget()
|
||||
self.itemNBTEditor.tagValueChanged.connect(self.tagValueDidChange)
|
||||
|
||||
self.currentIndex = None
|
||||
|
||||
@ -334,6 +335,9 @@ class InventoryEditor(QtGui.QWidget):
|
||||
self.currentIndex = self.inventoryModel.index(slotNumber)
|
||||
self.updateFields()
|
||||
|
||||
def tagValueDidChange(self, tagPath):
|
||||
self.updateFields()
|
||||
|
||||
def updateFields(self):
|
||||
with self.disableEdits():
|
||||
self._updateFields()
|
||||
|
@ -9,7 +9,7 @@ from PySide.QtCore import Qt
|
||||
|
||||
from mcedit2.command import SimpleRevisionCommand
|
||||
from mceditlib.util.lazyprop import weakrefprop
|
||||
from mcedit2.widgets.nbttree.nbttreemodel import NBTFilterProxyModel, NBTPathRole, NBTIcon, NBTTreeModel
|
||||
from mcedit2.widgets.nbttree.nbttreemodel import NBTFilterProxyModel, NBTIcon, NBTTreeModel
|
||||
from mcedit2.util.load_ui import registerCustomWidget
|
||||
from mcedit2.widgets.layout import Column
|
||||
|
||||
@ -66,12 +66,12 @@ class NBTEditorWidget(QtGui.QWidget):
|
||||
expanded = []
|
||||
current = None
|
||||
if keepExpanded and self.proxyModel:
|
||||
current = self.proxyModel.data(self.treeView.currentIndex(), NBTPathRole)
|
||||
current = self.proxyModel.data(self.treeView.currentIndex(), NBTTreeModel.NBTPathRole)
|
||||
def addExpanded(parentIndex):
|
||||
for row in range(self.proxyModel.rowCount(parentIndex)):
|
||||
index = self.proxyModel.index(row, 0, parentIndex)
|
||||
if self.treeView.isExpanded(index):
|
||||
expanded.append(self.proxyModel.data(index, NBTPathRole))
|
||||
expanded.append(self.proxyModel.data(index, NBTTreeModel.NBTPathRole))
|
||||
addExpanded(index)
|
||||
|
||||
addExpanded(QtCore.QModelIndex())
|
||||
@ -94,12 +94,12 @@ class NBTEditorWidget(QtGui.QWidget):
|
||||
if keepExpanded:
|
||||
for path in expanded:
|
||||
matches = self.proxyModel.match(self.proxyModel.index(0, 0, QtCore.QModelIndex()),
|
||||
NBTPathRole, path, flags=Qt.MatchExactly | Qt.MatchRecursive)
|
||||
NBTTreeModel.NBTPathRole, path, flags=Qt.MatchExactly | Qt.MatchRecursive)
|
||||
for i in matches:
|
||||
self.treeView.setExpanded(i, True)
|
||||
if current is not None:
|
||||
matches = self.proxyModel.match(self.proxyModel.index(0, 0, QtCore.QModelIndex()),
|
||||
NBTPathRole, current, flags=Qt.MatchExactly | Qt.MatchRecursive)
|
||||
NBTTreeModel.NBTPathRole, current, flags=Qt.MatchExactly | Qt.MatchRecursive)
|
||||
if len(matches):
|
||||
self.treeView.setCurrentIndex(matches[0])
|
||||
else:
|
||||
@ -206,6 +206,7 @@ class NBTEditorWidget(QtGui.QWidget):
|
||||
self.rootTagRef.dirty = True
|
||||
self.editorSession.worldEditor.syncToDisk()
|
||||
self.editorSession.pushCommand(command)
|
||||
self.tagValueChanged.emit(index.data(NBTTreeModel.NBTPathRole))
|
||||
|
||||
def rowsDidInsert(self, index):
|
||||
name = self.tagNameForUndo(index.parent())
|
||||
@ -229,5 +230,6 @@ class NBTEditorWidget(QtGui.QWidget):
|
||||
self.editorSession.worldEditor.syncToDisk()
|
||||
self.editorSession.pushCommand(command)
|
||||
|
||||
def reload(self):
|
||||
self.treeView.blah
|
||||
tagValueChanged = QtCore.Signal(list)
|
||||
tagAdded = QtCore.Signal(list)
|
||||
tagRemoved = QtCore.Signal(list)
|
||||
|
@ -28,8 +28,6 @@ _iconTypes = [
|
||||
"array.png", # 12 - shortarray
|
||||
]
|
||||
|
||||
NBTPathRole = QtCore.Qt.UserRole + 1
|
||||
|
||||
def NBTIcon(type):
|
||||
icon = _nbtIcons.get(type)
|
||||
if icon:
|
||||
@ -276,6 +274,9 @@ class NBTTreeItem(object):
|
||||
return self.parentItem.nbtPath(self)
|
||||
|
||||
class NBTTreeModel(QtCore.QAbstractItemModel):
|
||||
|
||||
NBTPathRole = QtCore.Qt.UserRole + 1
|
||||
|
||||
def __init__(self, rootTag, parent=None):
|
||||
super(NBTTreeModel, self).__init__(parent)
|
||||
|
||||
@ -323,7 +324,7 @@ class NBTTreeModel(QtCore.QAbstractItemModel):
|
||||
if role in (QtCore.Qt.DisplayRole, QtCore.Qt.EditRole):
|
||||
return item.data(column)
|
||||
|
||||
if role == NBTPathRole:
|
||||
if role == self.NBTPathRole:
|
||||
return item.nbtPath()
|
||||
|
||||
# --- Structure ---
|
||||
|
Reference in New Issue
Block a user