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


Python QList.insert方法代码示例

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


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

示例1: CommandDataModel

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

#.........这里部分代码省略.........
    ##
    # Returns the drop actions that can be performed.
    ##
    def supportedDropActions(self):
        return Qt.CopyAction | Qt.MoveAction

    ##
    # Handles dropping of mime data onto <i>parent</i>.
    ##
    def dropMimeData(self, data, action, row, column, parent):
        if (not parent.isValid()):
            return False
        dstRow = parent.row()
        if (data.hasFormat(commandMimeType)):
            # Get the ptr to the command that was being dragged
            byteData = data.data(commandMimeType)
            addr = byteData.data()
            # Find the command in the command list so we can move/copy it
            for srcRow in range(self.mCommands.size()):
                if (addr == self.mCommands[srcRow]):
                    # If a command is dropped on another command,
                    # move the src command into the positon of the dst command.
                    if (dstRow < self.mCommands.size()):
                        return self.move(srcRow, dstRow)
                    # If a command is dropped elsewhere, create a copy of it
                    if (dstRow == self.mCommands.size()):
                        self.append(Command(addr.isEnabled,
                                       self.tr("%s (copy)"%addr.name),
                                       addr.command))
                        return True

        if (data.hasText()):
            # If text is dropped on a valid command, just replace the data
            if (dstRow < self.mCommands.size()):
                return self.setData(parent, data.text(), Qt.EditRole)
            # If text is dropped elsewhere, create a new command
            # Assume the dropped text is the command, not the name
            if (dstRow == self.mCommands.size()):
                self.append(Command(True, self.tr("New command"), data.text()))
                return True

        return False

    ##
    # Moves the command at <i>commandIndex</i> to <i>newIndex></i>.
    ##
    def move(self, commandIndex, newIndex):
        commandIndex = self.mCommands.size()
        newIndex = self.mCommands.size()
        if (commandIndex or newIndex or newIndex == commandIndex):
            return False
        tmp = newIndex
        if newIndex > commandIndex:
            tmp += 1

        if (not self.beginMoveRows(QModelIndex(), commandIndex, commandIndex, QModelIndex(), tmp)):
            return False
        if (commandIndex - newIndex == 1 or newIndex - commandIndex == 1):
            # Swapping is probably more efficient than removing/inserting
            self.mCommands.swap(commandIndex, newIndex)
        else:
            command = self.mCommands.at(commandIndex)
            self.mCommands.removeAt(commandIndex)
            self.mCommands.insert(newIndex, command)

        self.endMoveRows()
        return True

    ##
    # Appends <i>command</i> to the command list.
    ##
    def append(self, command):
        self.beginInsertRows(QModelIndex(), self.mCommands.size(), self.mCommands.size())
        self.mCommands.append(command)
        self.endInsertRows()

    ##
    # Moves the command at <i>commandIndex</i> up one index, if possible.
    ##
    def moveUp(self, commandIndex):
        self.move(commandIndex, commandIndex - 1)

    ##
    # Executes the command at<i>commandIndex</i>.
    ##
    def execute(self, commandIndex):
        self.mCommands.at(commandIndex).execute()

    ##
    # Executes the command at <i>commandIndex</i> within the systems native
    # terminal if available.
    ##
    def executeInTerminal(self, commandIndex):
        self.mCommands.at(commandIndex).execute(True)

    ##
    # Deletes the command at <i>commandIndex</i>.
    ##
    def remove(self, commandIndex):
        self.removeRow(commandIndex)
开发者ID:theall,项目名称:Python-Tiled,代码行数:104,代码来源:commanddatamodel.py

示例2: QtButtonPropertyBrowserPrivate

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

#.........这里部分代码省略.........
                l = parent.layout
            else:
                w = self.q_ptr
                l = self.m_mainLayout

            span = 1
            if (not item.widget and not item.widgetLabel):
                span = 2
            item.label = QLabel(w)
            item.label.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
            l.addWidget(item.label, oldRow, 0, 1, span)

            self.updateItem(item)

        self.m_recreateQueue.clear()

    def setExpanded(self, item, expanded):
        if (item.expanded == expanded):
            return

        if (not item.container):
            return

        item.expanded = expanded
        row = self.gridRow(item)
        parent = item.parent
        l = 0
        if (parent):
            l = parent.layout
        else:
            l = self.m_mainLayout

        if (expanded):
            self.insertRow(l, row + 1)
            l.addWidget(item.container, row + 1, 0, 1, 2)
            item.container.show()
        else:
            l.removeWidget(item.container)
            item.container.hide()
            self.removeRow(l, row + 1)

        item.button.setChecked(expanded)
        if expanded:
            item.button.setArrowType(Qt.UpArrow)
        else:
            item.button.setArrowType(Qt.DownArrow)

    def slotToggled(self, checked):
        item = self.m_buttonToItem[self.q_ptr.sender()]
        if (not item):
            return

        self.setExpanded(item, checked)

        if (checked):
            self.q_ptr.expandedSignal.emit(self.m_itemToIndex[item])
        else:
            self.q_ptr.collapsedSignal.emit(self.m_itemToIndex[item])

    def updateLater(self):
        QTimer.singleShot(0, self.slotUpdate)

    def propertyInserted(self, index, afterIndex):
        afterItem = self.m_indexToItem[afterIndex]
        parentItem = self.m_indexToItem.value(index.parent())
开发者ID:theall,项目名称:QtPropertyBrowserV2.6-for-pyqt5,代码行数:69,代码来源:qtbuttonpropertybrowser.py

示例3: Tileset

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

#.........这里部分代码省略.........
        return int((width - self.mMargin + self.mTileSpacing) / (self.mTileWidth + self.mTileSpacing))

    ##
    # Returns a const reference to the list of terrains in this tileset.
    ##
    def terrains(self):
        return QList(self.mTerrainTypes)

    ##
    # Returns the number of terrain types in this tileset.
    ##
    def terrainCount(self):
        return self.mTerrainTypes.size()

    ##
    # Returns the terrain type at the given \a index.
    ##
    def terrain(self, index):
        if index >= 0:
            _x = self.mTerrainTypes[index]
        else:
            _x = None
        return _x

    ##
    # Adds a new terrain type.
    #
    # @param name      the name of the terrain
    # @param imageTile the id of the tile that represents the terrain visually
    # @return the created Terrain instance
    ##
    def addTerrain(self, name, imageTileId):
        terrain = Terrain(self.terrainCount(), self, name, imageTileId)
        self.insertTerrain(self.terrainCount(), terrain)
        return terrain

    ##
    # Adds the \a terrain type at the given \a index.
    #
    # The terrain should already have this tileset associated with it.
    ##
    def insertTerrain(self, index, terrain):
        self.mTerrainTypes.insert(index, terrain)
        # Reassign terrain IDs
        for terrainId in range(index, self.mTerrainTypes.size()):
            self.mTerrainTypes.at(terrainId).mId = terrainId
        # Adjust tile terrain references
        for tile in self.mTiles:
            for corner in range(4):
                terrainId = tile.cornerTerrainId(corner)
                if (terrainId >= index):
                    tile.setCornerTerrainId(corner, terrainId + 1)

        self.mTerrainDistancesDirty = True

    ##
    # Removes the terrain type at the given \a index and returns it. The
    # caller becomes responsible for the lifetime of the terrain type.
    #
    # This will cause the terrain ids of subsequent terrains to shift up to
    # fill the space and the terrain information of all tiles in this tileset
    # will be updated accordingly.
    ##
    def takeTerrainAt(self, index):
        terrain = self.mTerrainTypes.takeAt(index)
        # Reassign terrain IDs
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:tileset.py

示例4: QtGroupBoxPropertyBrowserPrivate

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import insert [as 别名]
class QtGroupBoxPropertyBrowserPrivate():
    def __init__(self):
        self.q_ptr = None
        self.m_indexToItem = QMap()
        self.m_itemToIndex = QMap()
        self.m_widgetToItem = QMap()
        self.m_mainLayout = 0
        self.m_children = QList()
        self.m_recreateQueue = QList()

    def createEditor(self, property, parent):
        return self.q_ptr.createEditor(property, parent)

    def init(self, parent):
        self.m_mainLayout = QGridLayout()
        parent.setLayout(self.m_mainLayout)
        item = QSpacerItem(0, 0, QSizePolicy.Fixed, QSizePolicy.Expanding)
        self.m_mainLayout.addItem(item, 0, 0)

    def slotEditorDestroyed(self):
        editor = self.q_ptr.sender()
        if (not editor):
            return
        if (not editor in self.m_widgetToItem.keys()):
            return
        self.m_widgetToItem[editor].widget = 0
        self.m_widgetToItem.remove(editor)

    def slotUpdate(self):
        for item in self.m_recreateQueue:
            par = item.parent
            w = 0
            l = 0
            oldRow = -1
            if (not par):
                w = self.q_ptr
                l = self.m_mainLayout
                oldRow = self.m_children.indexOf(item)
            else:
                w = par.groupBox
                l = par.layout
                oldRow = par.children.indexOf(item)
                if (self.hasHeader(par)):
                    oldRow += 2

            if (item.widget):
                item.widget.setParent(w)
            elif (item.widgetLabel):
                item.widgetLabel.setParent(w)
            else:
                item.widgetLabel = QLabel(w)
                item.widgetLabel.setSizePolicy(QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed))
                item.widgetLabel.setTextFormat(Qt.PlainText)

            span = 1
            if (item.widget):
                l.addWidget(item.widget, oldRow, 1, 1, 1)
            elif (item.widgetLabel):
                l.addWidget(item.widgetLabel, oldRow, 1, 1, 1)
            else:
                span = 2
            item.label = QLabel(w)
            item.label.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
            l.addWidget(item.label, oldRow, 0, 1, span)

            self.updateItem(item)

        self.m_recreateQueue.clear()

    def updateLater(self):
        QTimer.singleShot(0, self.q_ptr, self.slotUpdate())

    def propertyInserted(self, index, afterIndex):
        afterItem = self.m_indexToItem[afterIndex]
        parentItem = self.m_indexToItem.value(index.parent())

        newItem = WidgetItem()
        newItem.parent = parentItem

        layout = 0
        parentWidget = 0
        row = -1
        if (not afterItem):
            row = 0
            if (parentItem):
                parentItem.children.insert(0, newItem)
            else:
                self.m_children.insert(0, newItem)
        else:
            if (parentItem):
                row = parentItem.children.indexOf(afterItem) + 1
                parentItem.children.insert(row, newItem)
            else:
                row = self.m_children.indexOf(afterItem) + 1
                self.m_children.insert(row, newItem)

        if (parentItem and self.hasHeader(parentItem)):
            row += 2

        if (not parentItem):
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:qtgroupboxpropertybrowser.py

示例5: Map

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

#.........这里部分代码省略.........
        return layers

    def tileLayers(self):
        layers = QList()
        for layer in self.mLayers:
            tl = layer.asTileLayer()
            if tl:
                layers.append(tl)
        return layers

    ##
    # Adds a layer to this map.
    ##
    def addLayer(self, layer):
        self.adoptLayer(layer)
        self.mLayers.append(layer)

    ##
    # Returns the index of the layer given by \a layerName, or -1 if no
    # layer with that name is found.
    #
    # The second optional parameter specifies the layer types which are
    # searched.
    ##
    def indexOfLayer(self, layerName, layertypes = Layer.AnyLayerType):
        for index in range(self.mLayers.size()):
            if (self.layerAt(index).name() == layerName and (layertypes & self.layerAt(index).layerType())):
                return index
        return -1

    ##
    # Adds a layer to this map, inserting it at the given index.
    ##
    def insertLayer(self, index, layer):
        self.adoptLayer(layer)
        self.mLayers.insert(index, layer)

    ##
    # Removes the layer at the given index from this map and returns it.
    # The caller becomes responsible for the lifetime of this layer.
    ##
    def takeLayerAt(self, index):
        layer = self.mLayers.takeAt(index)
        layer.setMap(None)
        return layer

    ##
    # Adds a tileset to this map. The map does not take ownership over its
    # tilesets, this is merely for keeping track of which tilesets are used by
    # the map, and their saving order.
    #
    # @param tileset the tileset to add
    ##
    def addTileset(self, tileset):
        self.mTilesets.append(tileset)

    ##
    # Convenience function to be used together with Layer.usedTilesets()
    ##
    def addTilesets(self, tilesets):
        for tileset in tilesets:
            self.addTileset(tileset)
            
    ##
    # Inserts \a tileset at \a index in the list of tilesets used by this map.
    ##
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:map.py

示例6: ObjectGroup

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import insert [as 别名]
class ObjectGroup(Layer):
    ##
    # Objects within an object group can either be drawn top down (sorted
    # by their y-coordinate) or by index (manual stacking order).
    #
    # The default is top down.
    ##
    class DrawOrder():
        UnknownOrder = -1
        TopDownOrder = 1
        IndexOrder = 2

    ##
    # Default constructor.
    ##
    def __init__(self, *args):
        self.mObjects = QList()
        self.mColor = QColor()

        l = len(args)
        if l==0:
            super().__init__(Layer.ObjectGroupType, QString(), 0, 0, 0, 0)
        elif l==5:
            ##
            # Constructor with some parameters.
            ##
            name, x, y, width, height = args

            super().__init__(Layer.ObjectGroupType, name, x, y, width, height)
        else:
            pass
        self.mDrawOrder = ObjectGroup.DrawOrder.IndexOrder

    ##
    # Destructor.
    ##
    def __del__(self):
        self.mObjects.clear()

    ##
    # Returns a pointer to the list of objects in this object group.
    ##
    def objects(self):
        return QList(self.mObjects)

    ##
    # Returns the number of objects in this object group.
    ##
    def objectCount(self):
        return self.mObjects.size()

    ##
    # Returns the object at the specified index.
    ##
    def objectAt(self, index):
        return self.mObjects.at(index)

    ##
    # Adds an object to this object group.
    ##
    def addObject(self, object):
        self.mObjects.append(object)
        object.setObjectGroup(self)
        if (self.mMap and object.id() == 0):
            object.setId(self.mMap.takeNextObjectId())

    ##
    # Inserts an object at the specified index. This is only used for undoing
    # the removal of an object at the moment, to make sure not to change the
    # saved order of the objects.
    ##
    def insertObject(self, index, object):
        self.mObjects.insert(index, object)
        object.setObjectGroup(self)
        if (self.mMap and object.id() == 0):
            object.setId(self.mMap.takeNextObjectId())

    ##
    # Removes an object from this object group. Ownership of the object is
    # transferred to the caller.
    #
    # @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)
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:objectgroup.py

示例7: MapObjectModel

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

#.........这里部分代码省略.........
        if (not index.isValid()):
            return None
        oog = index.internalPointer()
        if oog:
            if oog.mGroup:
                _x = oog.mGroup
            else:
                _x = oog.mObject.objectGroup()
            return _x

    def setMapDocument(self, mapDocument):
        if (self.mMapDocument == mapDocument):
            return
        if (self.mMapDocument):
            self.mMapDocument.disconnect()
        self.beginResetModel()
        self.mMapDocument = mapDocument
        self.mMap = None
        self.mObjectGroups.clear()
        self.mGroups.clear()
        self.mGroups.clear()
        self.mObjects.clear()
        self.mObjects.clear()
        if (self.mMapDocument):
            self.mMap = self.mMapDocument.map()
            self.mMapDocument.layerAdded.connect(self.layerAdded)
            self.mMapDocument.layerChanged.connect(self.layerChanged)
            self.mMapDocument.layerAboutToBeRemoved.connect(self.layerAboutToBeRemoved)
            for og in self.mMap.objectGroups():
                if GROUPS_IN_DISPLAY_ORDER:
                    self.mObjectGroups.prepend(og)
                else:
                    self.mObjectGroups.append(og)
                self.mGroups.insert(og, ObjectOrGroup(og))
                for o in og.objects():
                    self.mObjects.insert(o, ObjectOrGroup(o))

        self.endResetModel()

    def insertObject(self, og, index, o):
        if (index >= 0):
            _x = index
        else:
            _x = og.objectCount()
        row = _x
        self.beginInsertRows(self.index(og), row, row)
        og.insertObject(row, o)
        self.mObjects.insert(o, ObjectOrGroup(o))
        self.endInsertRows()
        self.objectsAdded.emit(QList([o]))

    def removeObject(self, og, o):
        objects = QList()
        objects.append(o)
        row = og.objects().indexOf(o)
        self.beginRemoveRows(self.index(og), row, row)
        og.removeObjectAt(row)
        self.mObjects.remove(o)
        self.endRemoveRows()
        self.objectsRemoved.emit(objects)
        return row

    def moveObjects(self, og, _from, to, count):
        parent = self.index(og)
        if (not self.beginMoveRows(parent, _from, _from + count - 1, parent, to)):
            return
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:mapobjectmodel.py


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