本文整理汇总了Python中pyqtcore.QVector.size方法的典型用法代码示例。如果您正苦于以下问题:Python QVector.size方法的具体用法?Python QVector.size怎么用?Python QVector.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QVector
的用法示例。
在下文中一共展示了QVector.size方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ObjectTypesModel
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import size [as 别名]
class ObjectTypesModel(QAbstractTableModel):
ColorRole = Qt.UserRole
def __init__(self, parent):
super().__init__(parent)
self.mObjectTypes = QVector()
def setObjectTypes(self, objectTypes):
self.beginResetModel()
self.mObjectTypes = objectTypes
self.endResetModel()
def objectTypes(self):
return self.mObjectTypes
def rowCount(self, parent):
if parent.isValid():
_x = 0
else:
_x = self.mObjectTypes.size()
return _x
def columnCount(self, parent):
if parent.isValid():
_x = 0
else:
_x = 2
return _x
def headerData(self, section, orientation, role):
if (orientation == Qt.Horizontal):
if (role == Qt.DisplayRole):
x = section
if x==0:
return self.tr("Type")
elif x==1:
return self.tr("Color")
elif (role == Qt.TextAlignmentRole):
return Qt.AlignLeft
return QVariant()
def data(self, index, role):
# QComboBox requests data for an invalid index when the model is empty
if (not index.isValid()):
return QVariant()
objectType = self.mObjectTypes.at(index.row())
if (role == Qt.DisplayRole or role == Qt.EditRole):
if (index.column() == 0):
return objectType.name
if (role == ObjectTypesModel.ColorRole and index.column() == 1):
return objectType.color
return QVariant()
def setData(self, index, value, role):
if (role == Qt.EditRole and index.column() == 0):
self.mObjectTypes[index.row()].name = value.strip()
self.dataChanged.emit(index, index)
return True
return False
def flags(self, index):
f = super().flags(index)
if (index.column() == 0):
f |= Qt.ItemIsEditable
return f
def setObjectTypeColor(self, objectIndex, color):
self.mObjectTypes[objectIndex].color = color
mi = self.index(objectIndex, 1)
self.dataChanged.emit(mi, mi)
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()
def appendNewObjectType(self):
self.beginInsertRows(QModelIndex(), self.mObjectTypes.size(), self.mObjectTypes.size())
self.mObjectTypes.append(ObjectType())
self.endInsertRows()
示例2: AutoMapperWrapper
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import size [as 别名]
class AutoMapperWrapper(QUndoCommand):
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()
def __del__(self):
for i in self.mLayersAfter:
del i
for i in self.mLayersBefore:
del i
def undo(self):
map = self.mMapDocument.Map()
for layer in self.mLayersBefore:
layerindex = map.indexOfLayer(layer.name())
if (layerindex != -1):
self.patchLayer(layerindex, layer)
def redo(self):
map = self.mMapDocument.Map()
for layer in self.mLayersAfter:
layerindex = (map.indexOfLayer(layer.name()))
if (layerindex != -1):
self.patchLayer(layerindex, layer)
def patchLayer(self, layerIndex, layer):
map = self.mMapDocument.Map()
b = layer.bounds()
t = map.layerAt(layerIndex)
t.setCells(b.left() - t.x(), b.top() - t.y(), layer,
b.translated(-t.position()))
self.mMapDocument.emitRegionChanged(b, t)
示例3: Tile
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import size [as 别名]
#.........这里部分代码省略.........
self.mImage = image
##
# Returns the file name of the external image that represents this tile.
# When this tile doesn't refer to an external image, an empty string is
# returned.
##
def imageSource(self):
return self.mImageSource
##
# Returns the file name of the external image that represents this tile.
# When this tile doesn't refer to an external image, an empty string is
# returned.
##
def setImageSource(self, imageSource):
self.mImageSource = imageSource
##
# Returns the width of this tile.
##
def width(self):
return self.mImage.width()
##
# Returns the height of this tile.
##
def height(self):
return self.mImage.height()
##
# Returns the size of this tile.
##
def size(self):
return self.mImage.size()
##
# Returns the Terrain of a given corner.
##
def terrainAtCorner(self, corner):
return self.mTileset.terrain(self.cornerTerrainId(corner))
##
# Returns the terrain id at a given corner.
##
def cornerTerrainId(self, corner):
t = (self.terrain() >> (3 - corner)*8) & 0xFF
if t == 0xFF:
return -1
return t
##
# Set the terrain type of a given corner.
##
def setCornerTerrainId(self, corner, terrainId):
self.setTerrain(setTerrainCorner(self.mTerrain, corner, terrainId))
##
# Returns the terrain for each corner of this tile.
##
def terrain(self):
return self.mTerrain
##
# Set the terrain for each corner of the tile.
##
示例4: TileLayer
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import size [as 别名]
class TileLayer(Layer):
##
# Constructor.
##
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()
def __iter__(self):
return self.mGrid.__iter__()
##
# Returns the maximum tile size of this layer.
##
def maxTileSize(self):
return self.mMaxTileSize
##
# Returns the margins that have to be taken into account while drawing
# this tile layer. The margins depend on the maximum tile size and the
# offset applied to the tiles.
##
def drawMargins(self):
return QMargins(self.mOffsetMargins.left(),
self.mOffsetMargins.top() + self.mMaxTileSize.height(),
self.mOffsetMargins.right() + self.mMaxTileSize.width(),
self.mOffsetMargins.bottom())
##
# Recomputes the draw margins. Needed after the tile offset of a tileset
# has changed for example.
#
# Generally you want to call Map.recomputeDrawMargins instead.
##
def recomputeDrawMargins(self):
maxTileSize = QSize(0, 0)
offsetMargins = QMargins()
i = 0
while(i<self.mGrid.size()):
cell = self.mGrid.at(i)
tile = cell.tile
if tile:
size = tile.size()
if (cell.flippedAntiDiagonally):
size.transpose()
offset = tile.offset()
maxTileSize = maxSize(size, maxTileSize)
offsetMargins = maxMargins(QMargins(-offset.x(),
-offset.y(),
offset.x(),
offset.y()),
offsetMargins)
i += 1
self.mMaxTileSize = maxTileSize
self.mOffsetMargins = offsetMargins
if (self.mMap):
self.mMap.adjustDrawMargins(self.drawMargins())
##
# Returns whether (x, y) is inside this map layer.
##
def contains(self, *args):
l = len(args)
if l==2:
x, y = args
return x >= 0 and y >= 0 and x < self.mWidth and y < self.mHeight
elif l==1:
point = args[0]
return self.contains(point.x(), point.y())
##
# Calculates the region of cells in this tile layer for which the given
# \a condition returns True.
##
def region(self, *args):
l = len(args)
if l==1:
condition = args[0]
region = QRegion()
for y in range(self.mHeight):
for x in range(self.mWidth):
if (condition(self.cellAt(x, y))):
rangeStart = x
x += 1
while(x<=self.mWidth):
if (x == self.mWidth or not condition(self.cellAt(x, y))):
rangeEnd = x
region += QRect(rangeStart + self.mX, y + self.mY,
rangeEnd - rangeStart, 1)
break
x += 1
return region
elif l==0:
##
#.........这里部分代码省略.........
示例5: TileStampManager
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import size [as 别名]
#.........这里部分代码省略.........
self.mTileStampModel.clear()
self.loadStamps()
def eraseQuickStamp(self, index):
stamp = self.mQuickStamps.at(index)
if (not stamp.isEmpty()):
self.mQuickStamps[index] = TileStamp()
if (not self.mQuickStamps.contains(stamp)):
self.mTileStampModel.removeStamp(stamp)
def setQuickStamp(self, index, stamp):
stamp.setQuickStampIndex(index)
# make sure existing quickstamp is removed from stamp model
self.eraseQuickStamp(index)
self.mTileStampModel.addStamp(stamp)
self.mQuickStamps[index] = stamp
def loadStamps(self):
prefs = preferences.Preferences.instance()
stampsDirectory = prefs.stampsDirectory()
stampsDir = QDir(stampsDirectory)
iterator = QDirIterator(stampsDirectory,
["*.stamp"],
QDir.Files | QDir.Readable)
while (iterator.hasNext()):
stampFileName = iterator.next()
stampFile = QFile(stampFileName)
if (not stampFile.open(QIODevice.ReadOnly)):
continue
data = stampFile.readAll()
document = QJsonDocument.fromBinaryData(data)
if (document.isNull()):
# document not valid binary data, maybe it's an JSON text file
error = QJsonParseError()
document = QJsonDocument.fromJson(data, error)
if (error.error != QJsonParseError.NoError):
qDebug("Failed to parse stamp file:" + error.errorString())
continue
stamp = TileStamp.fromJson(document.object(), stampsDir)
if (stamp.isEmpty()):
continue
stamp.setFileName(iterator.fileInfo().fileName())
self.mTileStampModel.addStamp(stamp)
index = stamp.quickStampIndex()
if (index >= 0 and index < self.mQuickStamps.size()):
self.mQuickStamps[index] = stamp
def stampAdded(self, stamp):
if (stamp.name().isEmpty() or self.mStampsByName.contains(stamp.name())):
# pick the first available stamp name
name = QString()
index = self.mTileStampModel.stamps().size()
while(self.mStampsByName.contains(name)):
name = str(index)
index += 1
stamp.setName(name)
self.mStampsByName.insert(stamp.name(), stamp)
if (stamp.fileName().isEmpty()):
stamp.setFileName(findStampFileName(stamp.name()))
self.saveStamp(stamp)
def stampRenamed(self, stamp):
existingName = self.mStampsByName.key(stamp)
self.mStampsByName.remove(existingName)
self.mStampsByName.insert(stamp.name(), stamp)
existingFileName = stamp.fileName()
newFileName = findStampFileName(stamp.name(), existingFileName)
if (existingFileName != newFileName):
if (QFile.rename(stampFilePath(existingFileName),
stampFilePath(newFileName))):
stamp.setFileName(newFileName)
def saveStamp(self, stamp):
# make sure we have a stamps directory
prefs = preferences.Preferences.instance()
stampsDirectory = prefs.stampsDirectory()
stampsDir = QDir(stampsDirectory)
if (not stampsDir.exists() and not stampsDir.mkpath(".")):
qDebug("Failed to create stamps directory" + stampsDirectory)
return
filePath = stampsDir.filePath(stamp.fileName())
file = QSaveFile(filePath)
if (not file.open(QIODevice.WriteOnly)):
qDebug("Failed to open stamp file for writing" + filePath)
return
stampJson = stamp.toJson(QFileInfo(filePath).dir())
file.write(QJsonDocument(stampJson).toJson(QJsonDocument.Compact))
if (not file.commit()):
qDebug() << "Failed to write stamp" << filePath
def deleteStamp(self, stamp):
self.mStampsByName.remove(stamp.name())
QFile.remove(stampFilePath(stamp.fileName()))
示例6: MapScene
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import size [as 别名]
#.........这里部分代码省略.........
if (self.mShowTileObjectOutlines == enabled):
return
self.mShowTileObjectOutlines = enabled
if (self.mMapDocument):
self.mMapDocument.renderer().setFlag(RenderFlag.ShowTileObjectOutlines, enabled)
if (not self.mObjectItems.isEmpty()):
self.update()
##
# Sets whether the current layer should be highlighted.
##
def setHighlightCurrentLayer(self, highlightCurrentLayer):
if (self.mHighlightCurrentLayer == highlightCurrentLayer):
return
self.mHighlightCurrentLayer = highlightCurrentLayer
self.updateCurrentLayerHighlight()
##
# Refreshes the map scene.
##
def refreshScene(self):
self.mLayerItems.clear()
self.mObjectItems.clear()
self.removeItem(self.mDarkRectangle)
self.clear()
self.addItem(self.mDarkRectangle)
if (not self.mMapDocument):
self.setSceneRect(QRectF())
return
self.updateSceneRect()
map = self.mMapDocument.map()
self.mLayerItems.resize(map.layerCount())
if (map.backgroundColor().isValid()):
self.setBackgroundBrush(map.backgroundColor())
else:
self.setBackgroundBrush(self.mDefaultBackgroundColor)
layerIndex = 0
for layer in map.layers():
layerItem = self.createLayerItem(layer)
layerItem.setZValue(layerIndex)
self.addItem(layerItem)
self.mLayerItems[layerIndex] = layerItem
layerIndex += 1
tileSelectionItem = TileSelectionItem(self.mMapDocument)
tileSelectionItem.setZValue(10000 - 2)
self.addItem(tileSelectionItem)
self.mObjectSelectionItem = ObjectSelectionItem(self.mMapDocument)
self.mObjectSelectionItem.setZValue(10000 - 1)
self.addItem(self.mObjectSelectionItem)
self.updateCurrentLayerHighlight()
##
# Repaints the specified region. The region is in tile coordinates.
##
def repaintRegion(self, region, layer):
renderer = self.mMapDocument.renderer()
margins = self.mMapDocument.map().drawMargins()
for r in region.rects():
boundingRect = QRectF(renderer.boundingRect(r))
self.update(QRectF(renderer.boundingRect(r).adjusted(-margins.left(),
-margins.top(),
margins.right(),
margins.bottom())))
示例7: ObjectSelectionTool
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import size [as 别名]
class ObjectSelectionTool(AbstractObjectTool):
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)
def __del__(self):
if self.mSelectionRectangle.scene():
self.mSelectionRectangle.scene().removeItem(self.mSelectionRectangle)
if self.mOriginIndicator.scene():
self.mOriginIndicator.scene().removeItem(self.mOriginIndicator)
for i in range(AnchorPosition.CornerAnchorCount):
handle = self.mRotateHandles[i]
scene = handle.scene()
if scene:
scene.removeItem(handle)
self.mRotateHandles.clear()
for i in range(AnchorPosition.AnchorCount):
handle = self.mResizeHandles[i]
scene = handle.scene()
if scene:
scene.removeItem(handle)
self.mResizeHandles.clear()
def tr(self, sourceText, disambiguation = '', n = -1):
return QCoreApplication.translate('ObjectSelectionTool', sourceText, disambiguation, n)
def activate(self, scene):
super().activate(scene)
self.updateHandles()
self.mapDocument().objectsChanged.connect(self.updateHandles)
self.mapDocument().mapChanged.connect(self.updateHandles)
scene.selectedObjectItemsChanged.connect(self.updateHandles)
self.mapDocument().objectsRemoved.connect(self.objectsRemoved)
if self.mOriginIndicator.scene() != scene:
scene.addItem(self.mOriginIndicator)
for i in range(AnchorPosition.CornerAnchorCount):
handle = self.mRotateHandles[i]
if handle.scene() != scene:
scene.addItem(handle)
for i in range(AnchorPosition.AnchorCount):
handle = self.mResizeHandles[i]
if handle.scene() != scene:
scene.addItem(handle)
def deactivate(self, scene):
if self.mOriginIndicator.scene() == scene:
scene.removeItem(self.mOriginIndicator)
for i in range(AnchorPosition.CornerAnchorCount):
handle = self.mRotateHandles[i]
if handle.scene() == scene:
scene.removeItem(handle)
for i in range(AnchorPosition.AnchorCount):
handle = self.mResizeHandles[i]
if handle.scene() == scene:
scene.removeItem(handle)
self.mapDocument().objectsChanged.disconnect(self.updateHandles)
self.mapDocument().mapChanged.disconnect(self.updateHandles)
scene.selectedObjectItemsChanged.disconnect(self.updateHandles)
super().deactivate(scene)
def keyPressed(self, event):
if (self.mAction != Action.NoAction):
event.ignore()
return
moveBy = QPointF()
x = event.key()
if x==Qt.Key_Up:
moveBy = QPointF(0, -1)
elif x==Qt.Key_Down:
moveBy = QPointF(0, 1)
elif x==Qt.Key_Left:
moveBy = QPointF(-1, 0)
elif x==Qt.Key_Right:
#.........这里部分代码省略.........