本文整理汇总了Python中pyqtcore.QVector.append方法的典型用法代码示例。如果您正苦于以下问题:Python QVector.append方法的具体用法?Python QVector.append怎么用?Python QVector.append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QVector
的用法示例。
在下文中一共展示了QVector.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readObjectTypes
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def readObjectTypes(self, fileName):
self.mError = ''
objectTypes = QVector()
file = QFile(fileName)
if (not file.open(QIODevice.ReadOnly | QIODevice.Text)):
self.mError = QCoreApplication.translate(
"ObjectTypes", "Could not open file.")
return objectTypes
reader = QXmlStreamReader(file)
if (not reader.readNextStartElement() or reader.name() != "objecttypes"):
self.mError = QCoreApplication.translate(
"ObjectTypes", "File doesn't contain object types.")
return objectTypes
while (reader.readNextStartElement()):
if (reader.name() == "objecttype"):
atts = reader.attributes()
name = QString(atts.value("name"))
color = QColor(atts.value("color"))
objectTypes.append(ObjectType(name, color))
reader.skipCurrentElement()
if (reader.hasError()):
self.mError = QCoreApplication.translate("ObjectTypes", "%s\n\nLine %d, column %d"%(reader.errorString(), reader.lineNumber(), reader.columnNumber()))
return objectTypes
return objectTypes
示例2: drawGrid
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def drawGrid(self, painter, rect, gridColor):
tileWidth = self.map().tileWidth()
tileHeight = self.map().tileHeight()
if (tileWidth <= 0 or tileHeight <= 0):
return
startX = max(0, int(rect.x() / tileWidth) * tileWidth)
startY = max(0, int(rect.y() / tileHeight) * tileHeight)
endX = min(math.ceil(rect.right()), self.map().width() * tileWidth + 1)
endY = min(math.ceil(rect.bottom()), self.map().height() * tileHeight + 1)
gridColor.setAlpha(128)
gridPen = QPen(gridColor)
gridPen.setCosmetic(True)
_x = QVector()
_x.append(2)
_x.append(2)
gridPen.setDashPattern(_x)
if (startY < endY):
gridPen.setDashOffset(startY)
painter.setPen(gridPen)
for x in range(startX, endX, tileWidth):
painter.drawLine(x, startY, x, endY - 1)
if (startX < endX):
gridPen.setDashOffset(startX)
painter.setPen(gridPen)
for y in range(startY, endY, tileHeight):
painter.drawLine(startX, y, endX - 1, y)
示例3: drawGrid
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def drawGrid(self, painter, rect, gridColor):
tileWidth = self.map().tileWidth()
tileHeight = self.map().tileHeight()
r = rect.toAlignedRect()
r.adjust(-tileWidth / 2, -tileHeight / 2, tileWidth / 2, tileHeight / 2)
startX = int(max(0.0, self.screenToTileCoords_(r.topLeft()).x()))
startY = int(max(0.0, self.screenToTileCoords_(r.topRight()).y()))
endX = int(min(self.map().width(), self.screenToTileCoords_(r.bottomRight()).x()))
endY = int(min(self.map().height(), self.screenToTileCoords_(r.bottomLeft()).y()))
gridColor.setAlpha(128)
gridPen = QPen(gridColor)
gridPen.setCosmetic(True)
_x = QVector()
_x.append(2)
_x.append(2)
gridPen.setDashPattern(_x)
painter.setPen(gridPen)
for y in range(startY, endY+1):
start = self.tileToScreenCoords(startX, y)
end = self.tileToScreenCoords(endX, y)
painter.drawLine(start, end)
for x in range(startX, endX+1):
start = self.tileToScreenCoords(x, startY)
end = self.tileToScreenCoords(x, endY)
painter.drawLine(start, end)
示例4: offsetTiles
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def offsetTiles(self, offset, bounds, wrapX, wrapY):
newGrid = QVector()
for i in range(self.mWidth * self.mHeight):
newGrid.append(Cell())
for y in range(self.mHeight):
for x in range(self.mWidth):
# Skip out of bounds tiles
if (not bounds.contains(x, y)):
newGrid[x + y * self.mWidth] = self.cellAt(x, y)
continue
# Get position to pull tile value from
oldX = x - offset.x()
oldY = y - offset.y()
# Wrap x value that will be pulled from
if (wrapX and bounds.width() > 0):
while oldX < bounds.left():
oldX += bounds.width()
while oldX > bounds.right():
oldX -= bounds.width()
# Wrap y value that will be pulled from
if (wrapY and bounds.height() > 0):
while oldY < bounds.top():
oldY += bounds.height()
while oldY > bounds.bottom():
oldY -= bounds.height()
# Set the new tile
if (self.contains(oldX, oldY) and bounds.contains(oldX, oldY)):
newGrid[x + y * self.mWidth] = self.cellAt(oldX, oldY)
else:
newGrid[x + y * self.mWidth] = Cell()
self.mGrid = newGrid
示例5: removeObjectTypes
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def removeObjectTypes(self, indexes):
rows = QVector()
for index in indexes:
rows.append(index.row())
rows = sorted(rows)
for i in range(len(rows) - 1, -1, -1):
row = rows[i]
self.beginRemoveRows(QModelIndex(), row, row)
self.mObjectTypes.remove(row)
self.endRemoveRows()
示例6: cellsInRegion
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def cellsInRegion(list, r):
cells = QVector()
for tilelayer in list:
for rect in r.rects():
for x in range(rect.left(), rect.right()+1):
for y in range(rect.top(), rect.bottom()+1):
cell = tilelayer.cellAt(x, y)
if (not cells.contains(cell)):
cells.append(cell)
return cells
示例7: __readAnimationFrames
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def __readAnimationFrames(self):
frames = QVector()
while (self.xml.readNextStartElement()):
if (self.xml.name() == "frame"):
atts = self.xml.attributes()
frame = Frame()
frame.tileId = Int(atts.value("tileid"))
frame.duration = Int(atts.value("duration"))
frames.append(frame)
self.xml.skipCurrentElement()
else:
self.__readUnknownElement()
return frames
示例8: flip
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def flip(self, direction):
newGrid = QVector()
for i in range(self.mWidth * self.mHeight):
newGrid.append(Cell())
for y in range(self.mHeight):
for x in range(self.mWidth):
dest = newGrid[x + y * self.mWidth]
if (direction == FlipDirection.FlipHorizontally):
source = self.cellAt(self.mWidth - x - 1, y)
dest = source
dest.flippedHorizontally = not source.flippedHorizontally
elif (direction == FlipDirection.FlipVertically):
source = self.cellAt(x, self.mHeight - y - 1)
dest = source
dest.flippedVertically = not source.flippedVertically
self.mGrid = newGrid
示例9: resize
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def resize(self, size, offset):
if (self.size() == size and offset.isNull()):
return
newGrid = QVector()
for i in range(size.width() * size.height()):
newGrid.append(Cell())
# Copy over the preserved part
startX = max(0, -offset.x())
startY = max(0, -offset.y())
endX = min(self.mWidth, size.width() - offset.x())
endY = min(self.mHeight, size.height() - offset.y())
for y in range(startY, endY):
for x in range(startX, endX):
index = x + offset.x() + (y + offset.y()) * size.width()
newGrid[index] = self.cellAt(x, y)
self.mGrid = newGrid
self.setSize(size)
示例10: autoMapInternal
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def autoMapInternal(self, where, touchedLayer):
self.mError = ''
self.mWarning = ''
if (not self.mMapDocument):
return
automatic = touchedLayer != None
if (not self.mLoaded):
mapPath = QFileInfo(self.mMapDocument.fileName()).path()
rulesFileName = mapPath + "/rules.txt"
if (self.loadFile(rulesFileName)):
self.mLoaded = True
else:
self.errorsOccurred.emit(automatic)
return
passedAutoMappers = QVector()
if (touchedLayer):
for a in self.mAutoMappers:
if (a.ruleLayerNameUsed(touchedLayer.name())):
passedAutoMappers.append(a)
else:
passedAutoMappers = self.mAutoMappers
if (not passedAutoMappers.isEmpty()):
# use a pointer to the region, so each automapper can manipulate it and the
# following automappers do see the impact
region = QRegion(where)
undoStack = self.mMapDocument.undoStack()
undoStack.beginMacro(self.tr("Apply AutoMap rules"))
aw = AutoMapperWrapper(self.mMapDocument, passedAutoMappers, region)
undoStack.push(aw)
undoStack.endMacro()
for automapper in self.mAutoMappers:
self.mWarning += automapper.warningString()
self.mError += automapper.errorString()
if self.mWarning != '':
self.warningsOccurred.emit(automatic)
if self.mError != '':
self.errorsOccurred.emit(automatic)
示例11: pointsOnLine
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def pointsOnLine(*args):
l = len(args)
if l==2:
a, b = args
return pointsOnLine(a.x(), a.y(), b.x(), b.y())
else:
x0, y0, x1, y1 = args
ret = QVector()
steep = abs(y1 - y0) > abs(x1 - x0)
if steep:
x0, y0 = y0, x0
x1, y1 = y1, x1
reverse = x0 > x1
if reverse:
x0, x1 = x1, x0
y0, y1 = y1, y0
deltax = x1 - x0
deltay = abs(y1 - y0)
error= int(deltax / 2)
ystep = 0
y = y0
if (y0 < y1):
ystep = 1
else:
ystep = -1
for x in range(x0, x1+1):
if (steep):
ret.append(QPoint(y, x))
else:
ret.append(QPoint(x, y))
error = error - deltay
if (error < 0):
y = y + ystep
error = error + deltax
if reverse:
ret.reverse()
return ret
示例12: SetProperty
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
class SetProperty(QUndoCommand):
##
# Constructs a new 'Set Property' command.
#
# @param mapDocument the map document of the object's map
# @param objects the objects of which the property should be changed
# @param name the name of the property to be changed
# @param value the new value of the property
##
def __init__(self, mapDocument, objects, name, value, parent = None):
super().__init__(parent)
self.mProperties = QVector()
self.mMapDocument = mapDocument
self.mObjects = objects
self.mName = name
self.mValue = value
for obj in self.mObjects:
prop = ObjectProperty()
prop.existed = obj.hasProperty(self.mName)
prop.previousValue = obj.property(self.mName)
self.mProperties.append(prop)
if (self.mObjects.size() > 1 or self.mObjects[0].hasProperty(self.mName)):
self.setText(QCoreApplication.translate("Undo Commands", "Set Property"))
else:
self.setText(QCoreApplication.translate("Undo Commands", "Add Property"))
def undo(self):
for i in range(self.mObjects.size()):
if (self.mProperties[i].existed):
self.mMapDocument.setProperty(self.mObjects[i], self.mName, self.mProperties[i].previousValue)
else:
self.mMapDocument.removeProperty(self.mObjects[i], self.mName)
def redo(self):
for obj in self.mObjects:
self.mMapDocument.setProperty(obj, self.mName, self.mValue)
示例13: applyRule
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
def applyRule(self, ruleIndex, where):
ret = QRect()
if (self.mLayerList.isEmpty()):
return ret
ruleInput = self.mRulesInput.at(ruleIndex)
ruleOutput = self.mRulesOutput.at(ruleIndex)
rbr = ruleInput.boundingRect()
# Since the rule itself is translated, we need to adjust the borders of the
# loops. Decrease the size at all sides by one: There must be at least one
# tile overlap to the rule.
minX = where.left() - rbr.left() - rbr.width() + 1
minY = where.top() - rbr.top() - rbr.height() + 1
maxX = where.right() - rbr.left() + rbr.width() - 1
maxY = where.bottom() - rbr.top() + rbr.height() - 1
# In this list of regions it is stored which parts or the map have already
# been altered by exactly this rule. We store all the altered parts to
# make sure there are no overlaps of the same rule applied to
# (neighbouring) places
appliedRegions = QList()
if (self.mNoOverlappingRules):
for i in range(self.mMapWork.layerCount()):
appliedRegions.append(QRegion())
for y in range(minY, maxY+1):
for x in range(minX, maxX+1):
anymatch = False
for index in self.mInputRules.indexes:
ii = self.mInputRules[index]
allLayerNamesMatch = True
for name in ii.names:
i = self.mMapWork.indexOfLayer(name, Layer.TileLayerType)
if (i == -1):
allLayerNamesMatch = False
else:
setLayer = self.mMapWork.layerAt(i).asTileLayer()
allLayerNamesMatch &= compareLayerTo(setLayer,
ii[name].listYes,
ii[name].listNo,
ruleInput,
QPoint(x, y))
if (allLayerNamesMatch):
anymatch = True
break
if (anymatch):
r = 0
# choose by chance which group of rule_layers should be used:
if (self.mLayerList.size() > 1):
r = qrand() % self.mLayerList.size()
if (not self.mNoOverlappingRules):
self.copyMapRegion(ruleOutput, QPoint(x, y), self.mLayerList.at(r))
ret = ret.united(rbr.translated(QPoint(x, y)))
continue
missmatch = False
translationTable = self.mLayerList.at(r)
layers = translationTable.keys()
# check if there are no overlaps within this rule.
ruleRegionInLayer = QVector()
for i in range(layers.size()):
layer = layers.at(i)
appliedPlace = QRegion()
tileLayer = layer.asTileLayer()
if (tileLayer):
appliedPlace = tileLayer.region()
else:
appliedPlace = tileRegionOfObjectGroup(layer.asObjectGroup())
ruleRegionInLayer.append(appliedPlace.intersected(ruleOutput))
if (appliedRegions.at(i).intersects(
ruleRegionInLayer[i].translated(x, y))):
missmatch = True
break
if (missmatch):
continue
self.copyMapRegion(ruleOutput, QPoint(x, y), self.mLayerList.at(r))
ret = ret.united(rbr.translated(QPoint(x, y)))
for i in range(translationTable.size()):
appliedRegions[i] += ruleRegionInLayer[i].translated(x, y)
return ret
示例14: fillRegion
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [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
示例15: AutoMapper
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import append [as 别名]
#.........这里部分代码省略.........
if (raiseWarning):
self.mWarning += self.tr("'%s': Property '%s' = '%s' does not make sense. \nIgnoring this property."%(self.mRulePath, key, value.toString()) + '\n')
return True
def cleanUpRulesMap(self):
self.cleanTilesets()
# mMapRules can be empty, when in prepareLoad the very first stages fail.
if (not self.mMapRules):
return
tilesetManager = TilesetManager.instance()
tilesetManager.removeReferences(self.mMapRules.tilesets())
del self.mMapRules
self.mMapRules = None
self.cleanUpRuleMapLayers()
self.mRulesInput.clear()
self.mRulesOutput.clear()
##
# Searches the rules layer for regions and stores these in \a rules.
# @return returns True when anything is ok, False when errors occured.
##
def setupRuleList(self):
combinedRegions = coherentRegions(
self.mLayerInputRegions.region() +
self.mLayerOutputRegions.region())
combinedRegions = QList(sorted(combinedRegions, key=lambda x:x.y(), reverse=True))
rulesInput = coherentRegions(
self.mLayerInputRegions.region())
rulesOutput = coherentRegions(
self.mLayerOutputRegions.region())
for i in range(combinedRegions.size()):
self.mRulesInput.append(QRegion())
self.mRulesOutput.append(QRegion())
for reg in rulesInput:
for i in range(combinedRegions.size()):
if (reg.intersects(combinedRegions[i])):
self.mRulesInput[i] += reg
break
for reg in rulesOutput:
for i in range(combinedRegions.size()):
if (reg.intersects(combinedRegions[i])):
self.mRulesOutput[i] += reg
break
for i in range(self.mRulesInput.size()):
checkCoherent = self.mRulesInput.at(i).united(self.mRulesOutput.at(i))
coherentRegions(checkCoherent).length() == 1
return True
##
# Sets up the layers in the rules map, which are used for automapping.
# The layers are detected and put in the internal data structures
# @return returns True when anything is ok, False when errors occured.
##
def setupRuleMapTileLayers(self):
error = QString()
for layer in self.mMapRules.layers():
layerName = layer.name()
if (layerName.lower().startswith("regions")):
treatAsBoth = layerName.toLower() == "regions"
if (layerName.lower().endswith("input") or treatAsBoth):
if (self.mLayerInputRegions):