本文整理汇总了Python中pyqtcore.QList.empty方法的典型用法代码示例。如果您正苦于以下问题:Python QList.empty方法的具体用法?Python QList.empty怎么用?Python QList.empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QList
的用法示例。
在下文中一共展示了QList.empty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fillRegion
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import empty [as 别名]
def fillRegion(layer, fillOrigin):
# Create that region that will hold the fill
fillRegion = QRegion()
# Silently quit if parameters are unsatisfactory
if (not layer.contains(fillOrigin)):
return fillRegion
# Cache cell that we will match other cells against
matchCell = layer.cellAt(fillOrigin)
# Grab map dimensions for later use.
layerWidth = layer.width()
layerHeight = layer.height()
layerSize = layerWidth * layerHeight
# Create a queue to hold cells that need filling
fillPositions = QList()
fillPositions.append(fillOrigin)
# Create an array that will store which cells have been processed
# This is faster than checking if a given cell is in the region/list
processedCellsVec = QVector()
for i in range(layerSize):
processedCellsVec.append(0xff)
processedCells = processedCellsVec
# Loop through queued positions and fill them, while at the same time
# checking adjacent positions to see if they should be added
while (not fillPositions.empty()):
currentPoint = fillPositions.takeFirst()
startOfLine = currentPoint.y() * layerWidth
# Seek as far left as we can
left = currentPoint.x()
while (left > 0 and layer.cellAt(left - 1, currentPoint.y()) == matchCell):
left -= 1
# Seek as far right as we can
right = currentPoint.x()
while (right + 1 < layerWidth and layer.cellAt(right + 1, currentPoint.y()) == matchCell):
right += 1
# Add cells between left and right to the region
fillRegion += QRegion(left, currentPoint.y(), right - left + 1, 1)
# Add cell strip to processed cells
for i in range(startOfLine + left, right + startOfLine, 1):
processedCells[i] = 1
# These variables cache whether the last cell was added to the queue
# or not as an optimization, since adjacent cells on the x axis
# do not need to be added to the queue.
lastAboveCell = False
lastBelowCell = False
# Loop between left and right and check if cells above or
# below need to be added to the queue
for x in range(left, right+1):
fillPoint = QPoint(x, currentPoint.y())
# Check cell above
if (fillPoint.y() > 0):
aboveCell = QPoint(fillPoint.x(), fillPoint.y() - 1)
if (not processedCells[aboveCell.y() * layerWidth + aboveCell.x()] and layer.cellAt(aboveCell) == matchCell):
# Do not add the above cell to the queue if its
# x-adjacent cell was added.
if (not lastAboveCell):
fillPositions.append(aboveCell)
lastAboveCell = True
else:
lastAboveCell = False
processedCells[aboveCell.y() * layerWidth + aboveCell.x()] = 1
# Check cell below
if (fillPoint.y() + 1 < layerHeight):
belowCell = QPoint(fillPoint.x(), fillPoint.y() + 1)
if (not processedCells[belowCell.y() * layerWidth + belowCell.x()] and layer.cellAt(belowCell) == matchCell):
# Do not add the below cell to the queue if its
# x-adjacent cell was added.
if (not lastBelowCell):
fillPositions.append(belowCell)
lastBelowCell = True
else:
lastBelowCell = False
processedCells[belowCell.y() * layerWidth + belowCell.x()] = 1
return fillRegion