本文整理汇总了Python中pyqtcore.QMap.upperBound方法的典型用法代码示例。如果您正苦于以下问题:Python QMap.upperBound方法的具体用法?Python QMap.upperBound怎么用?Python QMap.upperBound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QMap
的用法示例。
在下文中一共展示了QMap.upperBound方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GidMapper
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import upperBound [as 别名]
class GidMapper():
##
# Default constructor. Use \l insert to initialize the gid mapper
# incrementally.
##
def __init__(self, *args):
self.mInvalidTile = None
self.mTilesetColumnCounts = QMap()
self.mFirstGidToTileset = QMap()
if len(args)==1:
##
# Constructor that initializes the gid mapper using the given \a tilesets.
##
firstGid = 1
tilesets = args[0]
for tileset in tilesets:
self.insert(firstGid, tileset)
firstGid += tileset.tileCount()
##
# Insert the given \a tileset with \a firstGid as its first global ID.
##
def insert(self, firstGid, tileset):
self.mFirstGidToTileset.insert(firstGid, tileset)
##
# Clears the gid mapper, so that it can be reused.
##
def clear(self):
self.mFirstGidToTileset.clear()
##
# Returns True when no tilesets are known to this gid mapper.
##
def isEmpty(self):
return self.mFirstGidToTileset.isEmpty()
##
# Returns the GID of the invalid tile in case decodeLayerData() returns
# the InvalidTile error.
##
def invalidTile(self):
return self.mInvalidTile
##
# Returns the cell data matched by the given \a gid. The \a ok parameter
# indicates whether an error occurred.
##
def gidToCell(self, gid):
result = Cell()
# Read out the flags
result.flippedHorizontally = (gid & FlippedHorizontallyFlag)
result.flippedVertically = (gid & FlippedVerticallyFlag)
result.flippedAntiDiagonally = (gid & FlippedAntiDiagonallyFlag)
# Clear the flags
gid &= ~(FlippedHorizontallyFlag |
FlippedVerticallyFlag |
FlippedAntiDiagonallyFlag)
if (gid == 0):
ok = True
elif (self.isEmpty()):
ok = False
else:
# Find the tileset containing this tile
index = self.mFirstGidToTileset.upperBound(gid)
if index==0:
ok = False
else:
item = self.mFirstGidToTileset.itemByIndex(index-1)
# Navigate one tileset back since upper bound finds the next
tileId = gid - item[0]
tileset = item[1]
columnCount = self.mTilesetColumnCounts.value(tileset, 0)
if (columnCount > 0 and columnCount != tileset.columnCount()):
# Correct tile index for changes in image width
row = int(tileId / columnCount)
column = int(tileId % columnCount)
tileId = row * tileset.columnCount() + column
result.tile = tileset.tileAt(tileId)
ok = True
return result, ok
##
# Returns the global tile ID for the given \a cell. Returns 0 when the
# cell is empty or when its tileset isn't known.
##
def cellToGid(self, cell):
if (cell.isEmpty()):
return 0
tileset = cell.tile.tileset()
# Find the first GID for the tileset
for item in self.mFirstGidToTileset:
if item[1] == tileset:
gid = item[0] + cell.tile.id()
if (cell.flippedHorizontally):
gid |= FlippedHorizontallyFlag
if (cell.flippedVertically):
gid |= FlippedVerticallyFlag
#.........这里部分代码省略.........