當前位置: 首頁>>代碼示例>>Python>>正文


Python QVector.replace方法代碼示例

本文整理匯總了Python中pyqtcore.QVector.replace方法的典型用法代碼示例。如果您正苦於以下問題:Python QVector.replace方法的具體用法?Python QVector.replace怎麽用?Python QVector.replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyqtcore.QVector的用法示例。


在下文中一共展示了QVector.replace方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: AutoMapperWrapper

# 需要導入模塊: from pyqtcore import QVector [as 別名]
# 或者: from pyqtcore.QVector import replace [as 別名]
class AutoMapperWrapper(QUndoCommand):
    def __init__(self, mapDocument, autoMapper, where):
        super().__init__()
        
        self.mLayersAfter = QVector()
        self.mLayersBefore = QVector()
        self.mMapDocument = mapDocument
        map = self.mMapDocument.Map()
        touchedLayers = QSet()
        index = 0
        while (index < autoMapper.size()):
            a = autoMapper.at(index)
            if (a.prepareAutoMap()):
                touchedLayers|= a.getTouchedTileLayers()
                index += 1
            else:
                autoMapper.remove(index)

        for layerName in touchedLayers:
            layerindex = map.indexOfLayer(layerName)
            self.mLayersBefore (map.layerAt(layerindex).clone())

        for a in autoMapper:
            a.autoMap(where)
        for layerName in touchedLayers:
            layerindex = map.indexOfLayer(layerName)
            # layerindex exists, because AutoMapper is still alive, dont check
            self.mLayersAfter (map.layerAt(layerindex).clone())

        # reduce memory usage by saving only diffs
        for i in range(self.mLayersAfter.size()):
            before = self.mLayersBefore.at(i)
            after = self.mLayersAfter.at(i)
            diffRegion = before.computeDiffRegion(after).boundingRect()
            before1 = before.copy(diffRegion)
            after1 = after.copy(diffRegion)
            before1.setPosition(diffRegion.topLeft())
            after1.setPosition(diffRegion.topLeft())
            before1.setName(before.name())
            after1.setName(after.name())
            self.mLayersBefore.replace(i, before1)
            self.mLayersAfter.replace(i, after1)
            del before
            del after

        for a in autoMapper:
            a.cleanAll()

    def __del__(self):
        for i in self.mLayersAfter:
            del i
        for i in self.mLayersBefore:
            del i

    def undo(self):
        map = self.mMapDocument.Map()
        for layer in self.mLayersBefore:
            layerindex = map.indexOfLayer(layer.name())
            if (layerindex != -1):
                self.patchLayer(layerindex, layer)

    def redo(self):
        map = self.mMapDocument.Map()
        for layer in self.mLayersAfter:
            layerindex = (map.indexOfLayer(layer.name()))
            if (layerindex != -1):
                self.patchLayer(layerindex, layer)

    def patchLayer(self, layerIndex, layer):
        map = self.mMapDocument.Map()
        b = layer.bounds()
        t = map.layerAt(layerIndex)
        t.setCells(b.left() - t.x(), b.top() - t.y(), layer,
                    b.translated(-t.position()))
        self.mMapDocument.emitRegionChanged(b, t)
開發者ID:theall,項目名稱:Python-Tiled,代碼行數:77,代碼來源:automapperwrapper.py

示例2: TileLayer

# 需要導入模塊: from pyqtcore import QVector [as 別名]
# 或者: from pyqtcore.QVector import replace [as 別名]

#.........這裏部分代碼省略.........
    ##
    # Returns whether this tile layer has any cell for which the given
    # \a condition returns True.
    ##
    def hasCell(self, condition):
        i = 0
        for cell in self.mGrid:
            if (condition(cell)):
                return True
            i += 1
        return False

    ##
    # Returns whether this tile layer is referencing the given tileset.
    ##
    def referencesTileset(self, tileset):
        i = 0
        while(i<self.mGrid.size()):
            tile = self.mGrid.at(i).tile
            if (tile and tile.tileset() == tileset):
                return True
            i += 1
        return False

    ##
    # Removes all references to the given tileset. This sets all tiles on this
    # layer that are from the given tileset to null.
    ##
    def removeReferencesToTileset(self, tileset):
        i = 0
        while(i<self.mGrid.size()):
            tile = self.mGrid.at(i).tile
            if (tile and tile.tileset() == tileset):
                self.mGrid.replace(i, Cell())
            i += 1

    ##
    # Replaces all tiles from \a oldTileset with tiles from \a newTileset.
    ##
    def replaceReferencesToTileset(self, oldTileset, newTileset):
        i = 0
        while(i<self.mGrid.size()):
            tile = self.mGrid.at(i).tile
            if (tile and tile.tileset() == oldTileset):
                self.mGrid[i].tile = newTileset.tileAt(tile.id())
            i += 1

    ##
    # Resizes this tile layer to \a size, while shifting all tiles by
    # \a offset.
    ##
    def resize(self, size, offset):
        if (self.size() == size and offset.isNull()):
            return
        newGrid = QVector()
        for i in range(size.width() * size.height()):
            newGrid.append(Cell())
        # Copy over the preserved part
        startX = max(0, -offset.x())
        startY = max(0, -offset.y())
        endX = min(self.mWidth, size.width() - offset.x())
        endY = min(self.mHeight, size.height() - offset.y())
        for y in range(startY, endY):
            for x in range(startX, endX):
                index = x + offset.x() + (y + offset.y()) * size.width()
                newGrid[index] = self.cellAt(x, y)
開發者ID:theall,項目名稱:Python-Tiled,代碼行數:70,代碼來源:tilelayer.py


注:本文中的pyqtcore.QVector.replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。