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