本文整理汇总了Python中pyqtcore.QVector类的典型用法代码示例。如果您正苦于以下问题:Python QVector类的具体用法?Python QVector怎么用?Python QVector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readObjectTypes
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
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)
示例3: drawGrid
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)
示例4: offsetTiles
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
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
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
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: __init__
def __init__(self, parent = None):
super().__init__(self.tr("Bucket Fill Tool"),
QIcon(":images/22x22/stock-tool-bucket-fill.png"),
QKeySequence(self.tr("F")),
parent)
self.mStamp = TileStamp()
self.mFillOverlay = None
self.mFillRegion = QRegion()
self.mMissingTilesets = QVector()
self.mIsActive = False
self.mLastShiftStatus = False
##
# Indicates if the tool is using the random mode.
##
self.mIsRandom = False
##
# Contains the value of mIsRandom at that time, when the latest call of
# tilePositionChanged() took place.
# This variable is needed to detect if the random mode was changed during
# mFillOverlay being brushed at an area.
##
self.mLastRandomStatus = False
##
# Contains all used random cells to use in random mode.
# The same cell can be in the list multiple times to make different
# random weights possible.
##
self.mRandomCellPicker = RandomPicker()
示例9: __init__
def __init__(self, name, x, y, width, height):
super().__init__(Layer.TileLayerType, name, x, y, width, height)
self.mMaxTileSize = QSize(0, 0)
self.mGrid = QVector()
for i in range(width * height):
self.mGrid.append(Cell())
self.mOffsetMargins = QMargins()
示例10: __init__
def __init__(self, parent = None):
super().__init__(self.tr("Select Objects"),
QIcon(":images/22x22/tool-select-objects.png"),
QKeySequence(self.tr("S")),
parent)
self.mSelectionRectangle = SelectionRectangle()
self.mOriginIndicator = OriginIndicator()
self.mMousePressed = False
self.mHoveredObjectItem = None
self.mClickedObjectItem = None
self.mClickedRotateHandle = None
self.mClickedResizeHandle = None
self.mResizingLimitHorizontal = False
self.mResizingLimitVertical = False
self.mMode = Mode.Resize
self.mAction = Action.NoAction
self.mRotateHandles = [0, 0, 0, 0]
self.mResizeHandles = [0, 0, 0, 0, 0, 0, 0, 0]
self.mAlignPosition = QPointF()
self.mMovingObjects = QVector()
self.mScreenStart = QPoint()
self.mStart = QPointF()
self.mModifiers = 0
self.mOrigin = QPointF()
for i in range(AnchorPosition.CornerAnchorCount):
self.mRotateHandles[i] = RotateHandle(i)
for i in range(AnchorPosition.AnchorCount):
self.mResizeHandles[i] = ResizeHandle(i)
示例11: __init__
def __init__(self, parent = None):
super().__init__(parent)
##
# The current map document.
##
self.mMapDocument = None
##
# For each new file of rules a new AutoMapper is setup. In this vector we
# can store all of the AutoMappers in order.
##
self.mAutoMappers = QVector()
##
# This tells you if the rules for the current map document were already
# loaded.
##
self.mLoaded = False
##
# Contains all errors which occurred until canceling.
# If mError is not empty, no serious result can be expected.
##
self.mError = ''
##
# Contains all strings, which try to explain unusual and unexpected
# behavior.
##
self.mWarning = QString()
示例12: __init__
def __init__(self, mapDocument, autoMapper, where):
super().__init__()
self.mLayersAfter = QVector()
self.mLayersBefore = QVector()
self.mMapDocument = mapDocument
map = self.mMapDocument.Map()
touchedLayers = QSet()
index = 0
while (index < autoMapper.size()):
a = autoMapper.at(index)
if (a.prepareAutoMap()):
touchedLayers|= a.getTouchedTileLayers()
index += 1
else:
autoMapper.remove(index)
for layerName in touchedLayers:
layerindex = map.indexOfLayer(layerName)
self.mLayersBefore (map.layerAt(layerindex).clone())
for a in autoMapper:
a.autoMap(where)
for layerName in touchedLayers:
layerindex = map.indexOfLayer(layerName)
# layerindex exists, because AutoMapper is still alive, dont check
self.mLayersAfter (map.layerAt(layerindex).clone())
# reduce memory usage by saving only diffs
for i in range(self.mLayersAfter.size()):
before = self.mLayersBefore.at(i)
after = self.mLayersAfter.at(i)
diffRegion = before.computeDiffRegion(after).boundingRect()
before1 = before.copy(diffRegion)
after1 = after.copy(diffRegion)
before1.setPosition(diffRegion.topLeft())
after1.setPosition(diffRegion.topLeft())
before1.setName(before.name())
after1.setName(after.name())
self.mLayersBefore.replace(i, before1)
self.mLayersAfter.replace(i, after1)
del before
del after
for a in autoMapper:
a.cleanAll()
示例13: flip
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
示例14: resize
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)
示例15: autoMapInternal
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)