本文整理匯總了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)