当前位置: 首页>>代码示例>>Python>>正文


Python QList.erase方法代码示例

本文整理汇总了Python中pyqtcore.QList.erase方法的典型用法代码示例。如果您正苦于以下问题:Python QList.erase方法的具体用法?Python QList.erase怎么用?Python QList.erase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyqtcore.QList的用法示例。


在下文中一共展示了QList.erase方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Tileset

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import erase [as 别名]

#.........这里部分代码省略.........
            terrainType1 = -1

        # Do some magic, since we don't have a transition array for no-terrain
        if (terrainType0 == -1 and terrainType1 == -1):
            return 0
        if (terrainType0 == -1):
            return self.mTerrainTypes.at(terrainType1).transitionDistance(terrainType0)
        return self.mTerrainTypes.at(terrainType0).transitionDistance(terrainType1)

    ##
    # Adds a new tile to the end of the tileset.
    ##
    def addTile(self, image, source=QString()):
        newTile = Tile(image, source, self.tileCount(), self)
        self.mTiles.append(newTile)
        if (self.mTileHeight < image.height()):
            self.mTileHeight = image.height()
        if (self.mTileWidth < image.width()):
            self.mTileWidth = image.width()
        return newTile

    def insertTiles(self, index, tiles):
        count = tiles.count()
        for i in range(count):
            self.mTiles.insert(index + i, tiles.at(i))
        # Adjust the tile IDs of the remaining tiles
        for i in range(index + count, self.mTiles.size()):
            self.mTiles.at(i).mId += count
        self.updateTileSize()

    def removeTiles(self, index, count):
        first = self.mTiles.begin() + index
        last = first + count
        last = self.mTiles.erase(first, last)
        # Adjust the tile IDs of the remaining tiles
        for last in self.mTiles:
            last.mId -= count
        self.updateTileSize()

    ##
    # Sets the \a image to be used for the tile with the given \a id.
    ##
    def setTileImage(self, id, image, source = QString()):
        # This operation is not supposed to be used on tilesets that are based
        # on a single image
        tile = self.tileAt(id)
        if (not tile):
            return
        previousImageSize = tile.image().size()
        newImageSize = image.size()
        tile.setImage(image)
        tile.setImageSource(source)
        if (previousImageSize != newImageSize):
            # Update our max. tile size
            if (previousImageSize.height() == self.mTileHeight or
                    previousImageSize.width() == self.mTileWidth):
                # This used to be the max image; we have to recompute
                self.updateTileSize()
            else:
                # Check if we have a new maximum
                if (self.mTileHeight < newImageSize.height()):
                    self.mTileHeight = newImageSize.height()
                if (self.mTileWidth < newImageSize.width()):
                    self.mTileWidth = newImageSize.width()

    ##
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:tileset.py

示例2: CommandDataModel

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import erase [as 别名]
class CommandDataModel(QAbstractTableModel):
    NameColumn, CommandColumn, EnabledColumn = range(3)

    ##
    # Constructs the object and parses the users settings to allow easy
    # programmatic access to the command list.
    ##
    def __init__(self, parent):
        super().__init__(parent)
        
        self.mSettings = QSettings()
        self.mSaveBeforeExecute = False
        self.mCommands = QList()
        
        # Load saveBeforeExecute option
        s = self.mSettings.value("saveBeforeExecute", True)
        self.mSaveBeforeExecute = bool(s)
        # Load command list
        variant = self.mSettings.value("commandList")
        commands = variant
        if commands is None:
            commands = []
        for commandVariant in commands:
            self.mCommands.append(Command.fromQVariant(commandVariant))
        # Add default commands the first time the app has booted up.
        # This is useful on it's own and helps demonstrate how to use the commands.
        addPrefStr = "addedDefaultCommands"
        addedCommands = self.mSettings.value(addPrefStr, False)
        if (not addedCommands):
            # Disable default commands by default so user gets an informative
            # warning when clicking the command button for the first time
            command = Command(False)
            if sys.platform == 'linux':
                command.command = "gedit %mapfile"
            elif sys.platform == 'darwin':
                command.command = "open -t %mapfile"
            if (not command.command.isEmpty()):
                command.name = self.tr("Open in text editor")
                self.mCommands.push_back(command)

            self.commit()
            self.mSettings.setValue(addPrefStr, True)
            
    ##
    # Saves the data to the users preferences.
    ##
    def commit(self):
        # Save saveBeforeExecute option
        self.mSettings.setValue("saveBeforeExecute", self.mSaveBeforeExecute)
        # Save command list
        commands = QList()
        for command in self.mCommands:
            commands.append(command.toQVariant())
        self.mSettings.setValue("commandList", commands)

    ##
    # Returns whether saving before executing commands is enabled.
    ##
    def saveBeforeExecute(self):
        return self.mSaveBeforeExecute

    ##
    # Enables or disables saving before executing commands.
    ##
    def setSaveBeforeExecute(self, enabled):
        self.mSaveBeforeExecute = enabled

    ##
    # Returns the first enabled command in the list, or an empty
    # disabled command if there are no enabled commands.
    ##
    def firstEnabledCommand(self):
        for command in self.mCommands:
            if (command.isEnabled):
                return command
        return Command(False)

    ##
    # Returns a list of all the commands.
    ##
    def allCommands(self):
        return QList(self.mCommands)

    ##
    # Remove the given row or rows from the model.
    ##
    def removeRows(self, *args):
        l = len(args)
        if l>1 and l<4:
            row = args[0]
            count = args[1]
            if l==2:
                parent = QModelIndex()
            elif l==3:
                parent = args[2]

            if (row < 0 or row + count > self.mCommands.size()):
                return False
            self.beginRemoveRows(parent, row, row + count)
            self.mCommands.erase(self.mCommands.begin() + row, self.mCommands.begin() + row + count)
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:commanddatamodel.py

示例3: ObjectGroup

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import erase [as 别名]

#.........这里部分代码省略.........
    # @return the index at which the specified object was removed
    ##
    def removeObject(self, object):
        index = self.mObjects.indexOf(object)
        self.mObjects.removeAt(index)
        object.setObjectGroup(None)
        return index

    ##
    # Removes the object at the given index. Ownership of the object is
    # transferred to the caller.
    #
    # This is faster than removeObject when you've already got the index.
    #
    # @param index the index at which to remove an object
    ##
    def removeObjectAt(self, index):
        object = self.mObjects.takeAt(index)
        object.setObjectGroup(None)

    ##
    # Moves \a count objects starting at \a from to the index given by \a to.
    #
    # The \a to index may not lie within the range of objects that is
    # being moved.
    ##
    def moveObjects(self, _from, to, count):
        # It's an error when 'to' lies within the moving range of objects
        # Nothing to be done when 'to' is the start or the end of the range, or
        # when the number of objects to be moved is 0.
        if (to == _from or to == _from + count or count == 0):
            return
        movingObjects = self.mObjects[_from:_from+count]
        self.mObjects.erase(_from, _from + count)
        if (to > _from):
            to -= count
        for i in range(count):
            self.mObjects.insert(to + i, movingObjects[i])

    ##
    # Returns the bounding rect around all objects in this object group.
    ##
    def objectsBoundingRect(self):
        boundingRect = QRectF()
        for object in self.mObjects:
            boundingRect = boundingRect.united(object.bounds())
        return boundingRect

    ##
    # Returns whether this object group contains any objects.
    ##
    def isEmpty(self):
        return self.mObjects.isEmpty()

    ##
    # Computes and returns the set of tilesets used by this object group.
    ##
    def usedTilesets(self):
        tilesets = QSet()
        for object in self.mObjects:
            tile = object.cell().tile
            if tile:
                tilesets.insert(tile.sharedTileset())
        return tilesets

    ##
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:objectgroup.py


注:本文中的pyqtcore.QList.erase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。