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


Python QList.swap方法代码示例

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


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

示例1: CommandDataModel

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import swap [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


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