After changing tag names, update the results view. Really ugly, need to do it through the model and not the results
This commit is contained in:
parent
83826f7179
commit
5abd935862
@ -17,7 +17,19 @@ from mceditlib.selection import BoundingBox
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class NBTResultsEntry(namedtuple("NBTResultsEntry", "tagName value id path position uuid resultType")):
|
class NBTResultsEntry(object):
|
||||||
|
# namedtuple("NBTResultsEntry", "tagName value id path position uuid resultType")):
|
||||||
|
def __init__(self, model, tagNameIndex, tagName, value, id, path, position, uuid, resultType):
|
||||||
|
self.model = model
|
||||||
|
self.tagNameIndex = tagNameIndex # xxx REALLY SHOULD change model data through the model itself
|
||||||
|
self.tagName = tagName
|
||||||
|
self.value = value
|
||||||
|
self.id = id
|
||||||
|
self.path = path
|
||||||
|
self.position = position
|
||||||
|
self.uuid = uuid
|
||||||
|
self.resultType = resultType
|
||||||
|
|
||||||
EntityResult = "ENTITY"
|
EntityResult = "ENTITY"
|
||||||
TileEntityResult = "TILE_ENTITY"
|
TileEntityResult = "TILE_ENTITY"
|
||||||
ItemResult = "ITEM"
|
ItemResult = "ITEM"
|
||||||
@ -25,12 +37,24 @@ class NBTResultsEntry(namedtuple("NBTResultsEntry", "tagName value id path posit
|
|||||||
ChunkResult = "CHUNK"
|
ChunkResult = "CHUNK"
|
||||||
FileResult = "FILE"
|
FileResult = "FILE"
|
||||||
|
|
||||||
|
def setTagName(self, value):
|
||||||
|
self.tagName = value
|
||||||
|
self.model.dataChanged.emit(self.tagNameIndex, self.tagNameIndex)
|
||||||
|
|
||||||
|
|
||||||
class NBTResultsModel(QtCore.QAbstractItemModel):
|
class NBTResultsModel(QtCore.QAbstractItemModel):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(NBTResultsModel, self).__init__()
|
super(NBTResultsModel, self).__init__()
|
||||||
self.results = []
|
self.results = []
|
||||||
|
|
||||||
|
def addEntry(self, *a, **kw):
|
||||||
|
index = self.index(len(self.results), 0)
|
||||||
|
entry = NBTResultsEntry(self, index, *a, **kw)
|
||||||
|
self.beginInsertRows(QtCore.QModelIndex(), len(self.results), len(self.results))
|
||||||
|
self.results.append(entry)
|
||||||
|
self.endInsertRows()
|
||||||
|
return entry
|
||||||
|
|
||||||
# --- Shape ---
|
# --- Shape ---
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
@ -416,7 +440,6 @@ class FindReplaceNBT(QtCore.QObject):
|
|||||||
return str(name_or_index), path, value
|
return str(name_or_index), path, value
|
||||||
|
|
||||||
def _findEntitiesInChunk(chunk):
|
def _findEntitiesInChunk(chunk):
|
||||||
results = []
|
|
||||||
for entity in chunk.Entities:
|
for entity in chunk.Entities:
|
||||||
if entity.Position not in selection:
|
if entity.Position not in selection:
|
||||||
continue
|
continue
|
||||||
@ -435,19 +458,17 @@ class FindReplaceNBT(QtCore.QObject):
|
|||||||
if result:
|
if result:
|
||||||
name, path, value = result
|
name, path, value = result
|
||||||
|
|
||||||
results.append(NBTResultsEntry(tagName=name,
|
self.resultsModel.addEntry(tagName=name,
|
||||||
value=value,
|
value=value,
|
||||||
id=entity.id,
|
id=entity.id,
|
||||||
path=path,
|
path=path,
|
||||||
position=entity.Position,
|
position=entity.Position,
|
||||||
uuid=uuid,
|
uuid=uuid,
|
||||||
resultType=NBTResultsEntry.EntityResult))
|
resultType=NBTResultsEntry.EntityResult)
|
||||||
|
|
||||||
|
|
||||||
self.resultsModel.addResults(results)
|
|
||||||
|
|
||||||
def _findTileEntitiesInChunk(chunk):
|
def _findTileEntitiesInChunk(chunk):
|
||||||
results = []
|
|
||||||
for tileEntity in chunk.TileEntities:
|
for tileEntity in chunk.TileEntities:
|
||||||
if tileEntity.Position not in selection:
|
if tileEntity.Position not in selection:
|
||||||
continue
|
continue
|
||||||
@ -460,15 +481,14 @@ class FindReplaceNBT(QtCore.QObject):
|
|||||||
if result:
|
if result:
|
||||||
name, path, value = result
|
name, path, value = result
|
||||||
|
|
||||||
results.append(NBTResultsEntry(tagName=name,
|
self.resultsModel.addEntry(tagName=name,
|
||||||
value=value,
|
value=value,
|
||||||
id=tileEntity.id,
|
id=tileEntity.id,
|
||||||
path=path,
|
path=path,
|
||||||
position=tileEntity.Position,
|
position=tileEntity.Position,
|
||||||
uuid=None,
|
uuid=None,
|
||||||
resultType=NBTResultsEntry.TileEntityResult))
|
resultType=NBTResultsEntry.TileEntityResult)
|
||||||
|
|
||||||
self.resultsModel.addResults(results)
|
|
||||||
|
|
||||||
def _find():
|
def _find():
|
||||||
self.resultsDockWidget.show()
|
self.resultsDockWidget.show()
|
||||||
@ -523,6 +543,7 @@ class FindReplaceNBT(QtCore.QObject):
|
|||||||
if shouldReplaceName:
|
if shouldReplaceName:
|
||||||
subtag = tag.pop(result.tagName)
|
subtag = tag.pop(result.tagName)
|
||||||
tag[newName] = subtag
|
tag[newName] = subtag
|
||||||
|
result.setTagName(newName)
|
||||||
|
|
||||||
if shouldReplaceValue:
|
if shouldReplaceValue:
|
||||||
subtag = tag[result.tagName]
|
subtag = tag[result.tagName]
|
||||||
|
Reference in New Issue
Block a user