Add read-only mode to NBT editor
This commit is contained in:
parent
abb0089f62
commit
ddc3b1578f
@ -123,7 +123,7 @@ class NBTEditorWidget(QtGui.QWidget):
|
||||
self.model = None
|
||||
return
|
||||
|
||||
self.model = NBTTreeModel(rootTagRef.rootTag, self.editorSession.worldEditor.blocktypes)
|
||||
self.model = NBTTreeModel(rootTagRef.rootTag, self.editorSession.worldEditor.blocktypes, not self.editorSession.readonly)
|
||||
expanded = []
|
||||
current = None
|
||||
if keepExpanded and self.proxyModel:
|
||||
@ -177,6 +177,9 @@ class NBTEditorWidget(QtGui.QWidget):
|
||||
indexAddingTo = None
|
||||
|
||||
def itemClicked(self, index):
|
||||
if self.editorSession.readonly:
|
||||
return
|
||||
|
||||
index = self.proxyModel.mapToSource(index)
|
||||
item = self.model.getItem(index)
|
||||
if index.column() == 2:
|
||||
|
@ -290,7 +290,7 @@ class NBTTreeModel(QtCore.QAbstractItemModel):
|
||||
NBTPathRole = QtCore.Qt.UserRole + 1
|
||||
NBTTagTypeRole = NBTPathRole + 1
|
||||
|
||||
def __init__(self, rootTag, blocktypes):
|
||||
def __init__(self, rootTag, blocktypes, editable):
|
||||
"""
|
||||
|
||||
Parameters
|
||||
@ -303,6 +303,7 @@ class NBTTreeModel(QtCore.QAbstractItemModel):
|
||||
self.blocktypes = blocktypes
|
||||
self.rootItem = MakeNBTTreeItem(rootTag, None)
|
||||
self.rootTag = rootTag
|
||||
self.editable = editable
|
||||
self.allowNameChanges = True
|
||||
self.addIcon = QtGui.QIcon(resourcePath("mcedit2/assets/mcedit2/icons/add.png"))
|
||||
self.removeIcon = QtGui.QIcon(resourcePath("mcedit2/assets/mcedit2/icons/remove.png"))
|
||||
@ -326,7 +327,7 @@ class NBTTreeModel(QtCore.QAbstractItemModel):
|
||||
parent = self.parent(index)
|
||||
parentItem = self.getItem(parent) if parent else None
|
||||
|
||||
if index.column() == 1 or (index.column() == 0 and self.allowNameChanges and parentItem and parentItem.isCompound):
|
||||
if self.editable and (index.column() == 1 or (index.column() == 0 and self.allowNameChanges and parentItem and parentItem.isCompound)):
|
||||
flags |= QtCore.Qt.ItemIsEditable
|
||||
return flags
|
||||
|
||||
|
Reference in New Issue
Block a user