本文整理汇总了Python中pyqtcore.QVector.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QVector.clear方法的具体用法?Python QVector.clear怎么用?Python QVector.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QVector
的用法示例。
在下文中一共展示了QVector.clear方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BucketFillTool
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import clear [as 别名]
class BucketFillTool(AbstractTileTool):
def tr(self, sourceText, disambiguation = '', n = -1):
return QCoreApplication.translate('BucketFillTool', sourceText, disambiguation, n)
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()
def __del__(self):
pass
def activate(self, scene):
super().activate(scene)
self.mIsActive = True
self.tilePositionChanged(self.tilePosition())
def deactivate(self, scene):
super().deactivate(scene)
self.mFillRegion = QRegion()
self.mIsActive = False
def mousePressed(self, event):
if (event.button() != Qt.LeftButton or self.mFillRegion.isEmpty()):
return
if (not self.brushItem().isVisible()):
return
preview = self.mFillOverlay
if not preview:
return
paint = PaintTileLayer(self.mapDocument(),
self.currentTileLayer(),
preview.x(),
preview.y(),
preview)
paint.setText(QCoreApplication.translate("Undo Commands", "Fill Area"))
if not self.mMissingTilesets.isEmpty():
for tileset in self.mMissingTilesets:
AddTileset(self.mapDocument(), tileset, paint)
self.mMissingTilesets.clear()
fillRegion = QRegion(self.mFillRegion)
self.mapDocument().undoStack().push(paint)
self.mapDocument().emitRegionEdited(fillRegion, self.currentTileLayer())
def mouseReleased(self, event):
pass
def modifiersChanged(self, modifiers):
# Don't need to recalculate fill region if there was no fill region
if (not self.mFillOverlay):
return
self.tilePositionChanged(self.tilePosition())
def languageChanged(self):
self.setName(self.tr("Bucket Fill Tool"))
self.setShortcut(QKeySequence(self.tr("F")))
##
# Sets the stamp that is drawn when filling. The BucketFillTool takes
# ownership over the stamp layer.
##
def setStamp(self, stamp):
# Clear any overlay that we presently have with an old stamp
self.clearOverlay()
self.mStamp = stamp
self.updateRandomListAndMissingTilesets()
if (self.mIsActive and self.brushItem().isVisible()):
self.tilePositionChanged(self.tilePosition())
##
#.........这里部分代码省略.........
示例2: AutomappingManager
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import clear [as 别名]
#.........这里部分代码省略.........
return False
if (not rulesFile.open(QIODevice.ReadOnly | QIODevice.Text)):
self.mError += self.tr("Error opening rules file:\n%s\n"%filePath)
return False
i = QTextStream(rulesFile)
line = ' '
while line != '':
line = i.readLine()
rulePath = line.strip()
if (rulePath=='' or rulePath.startswith('#') or rulePath.startswith("//")):
continue
if (QFileInfo(rulePath).isRelative()):
rulePath = absPath + '/' + rulePath
if (not QFileInfo(rulePath).exists()):
self.mError += self.tr("File not found:\n%s"%rulePath) + '\n'
ret = False
continue
if (rulePath.lower().endswith(".tmx")):
tmxFormat = TmxMapFormat()
rules = tmxFormat.read(rulePath)
if (not rules):
self.mError += self.tr("Opening rules map failed:\n%s"%tmxFormat.errorString()) + '\n'
ret = False
continue
tilesetManager = TilesetManager.instance()
tilesetManager.addReferences(rules.tilesets())
autoMapper = None
autoMapper = AutoMapper(self.mMapDocument, rules, rulePath)
self.mWarning += autoMapper.warningString()
error = autoMapper.errorString()
if error != '':
self.mAutoMappers.append(autoMapper)
else:
self.mError += error
del autoMapper
if (rulePath.lower().endswith(".txt")):
if (not self.loadFile(rulePath)):
ret = False
return ret
##
# Applies automapping to the Region \a where, considering only layer
# \a touchedLayer has changed.
# There will only those Automappers be used which have a rule layer
# touching the \a touchedLayer
# If layer is 0, all Automappers are used.
##
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)
##
# deletes all its data structures
##
def cleanUp(self):
self.mAutoMappers.clear()
示例3: StampBrush
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import clear [as 别名]
#.........这里部分代码省略.........
self.mBrushBehavior = BrushBehavior.Paint
self.doPaint()
##
# Merges the tile layer of its brush item into the current map.
#
# \a flags can be set to Mergeable, which applies to the undo command.
#
# \a offsetX and \a offsetY give an offset where to merge the brush items tile
# layer into the current map.
#
# Returns the edited region.
##
def doPaint(self, flags = 0):
preview = self.mPreviewLayer
if not preview:
return QRegion()
# This method shouldn't be called when current layer is not a tile layer
tileLayer = self.currentTileLayer()
if (not tileLayer.bounds().intersects(QRect(preview.x(), preview.y(), preview.width(), preview.height()))):
return QRegion()
paint = PaintTileLayer(self.mapDocument(),
tileLayer,
preview.x(),
preview.y(),
preview)
if not self.mMissingTilesets.isEmpty():
for tileset in self.mMissingTilesets:
AddTileset(self.mapDocument(), tileset, paint)
self.mMissingTilesets.clear()
paint.setMergeable(flags & PaintFlags.Mergeable)
self.mapDocument().undoStack().push(paint)
editedRegion = preview.region()
if (not (flags & PaintFlags.SuppressRegionEdited)):
self.mapDocument().emitRegionEdited(editedRegion, tileLayer)
return editedRegion
def beginCapture(self):
if (self.mBrushBehavior != BrushBehavior.Free):
return
self.mBrushBehavior = BrushBehavior.Capture
self.mCaptureStart = self.tilePosition()
self.setStamp(TileStamp())
def endCapture(self):
if (self.mBrushBehavior != BrushBehavior.Capture):
return
self.mBrushBehavior = BrushBehavior.Free
tileLayer = self.currentTileLayer()
# Intersect with the layer and translate to layer coordinates
captured = self.capturedArea()
captured &= QRect(tileLayer.x(), tileLayer.y(),
tileLayer.width(), tileLayer.height())
if (captured.isValid()):
captured.translate(-tileLayer.x(), -tileLayer.y())
map = tileLayer.map()
capture = tileLayer.copy(captured)
stamp = Map(map.orientation(),
capture.width(),
示例4: MapScene
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import clear [as 别名]
class MapScene(QGraphicsScene):
selectedObjectItemsChanged = pyqtSignal()
##
# Constructor.
##
def __init__(self, parent):
super().__init__(parent)
self.mMapDocument = None
self.mSelectedTool = None
self.mActiveTool = None
self.mObjectSelectionItem = None
self.mUnderMouse = False
self.mCurrentModifiers = Qt.NoModifier,
self.mDarkRectangle = QGraphicsRectItem()
self.mDefaultBackgroundColor = Qt.darkGray
self.mLayerItems = QVector()
self.mObjectItems = QMap()
self.mObjectLineWidth = 0.0
self.mSelectedObjectItems = QSet()
self.mLastMousePos = QPointF()
self.mShowTileObjectOutlines = False
self.mHighlightCurrentLayer = False
self.mGridVisible = False
self.setBackgroundBrush(self.mDefaultBackgroundColor)
tilesetManager = TilesetManager.instance()
tilesetManager.tilesetChanged.connect(self.tilesetChanged)
tilesetManager.repaintTileset.connect(self.tilesetChanged)
prefs = preferences.Preferences.instance()
prefs.showGridChanged.connect(self.setGridVisible)
prefs.showTileObjectOutlinesChanged.connect(self.setShowTileObjectOutlines)
prefs.objectTypesChanged.connect(self.syncAllObjectItems)
prefs.highlightCurrentLayerChanged.connect(self.setHighlightCurrentLayer)
prefs.gridColorChanged.connect(self.update)
prefs.objectLineWidthChanged.connect(self.setObjectLineWidth)
self.mDarkRectangle.setPen(QPen(Qt.NoPen))
self.mDarkRectangle.setBrush(Qt.black)
self.mDarkRectangle.setOpacity(darkeningFactor)
self.addItem(self.mDarkRectangle)
self.mGridVisible = prefs.showGrid()
self.mObjectLineWidth = prefs.objectLineWidth()
self.mShowTileObjectOutlines = prefs.showTileObjectOutlines()
self.mHighlightCurrentLayer = prefs.highlightCurrentLayer()
# Install an event filter so that we can get key events on behalf of the
# active tool without having to have the current focus.
QCoreApplication.instance().installEventFilter(self)
##
# Destructor.
##
def __del__(self):
if QCoreApplication.instance():
QCoreApplication.instance().removeEventFilter(self)
##
# Returns the map document this scene is displaying.
##
def mapDocument(self):
return self.mMapDocument
##
# Sets the map this scene displays.
##
def setMapDocument(self, mapDocument):
if (self.mMapDocument):
self.mMapDocument.disconnect()
if (not self.mSelectedObjectItems.isEmpty()):
self.mSelectedObjectItems.clear()
self.selectedObjectItemsChanged.emit()
self.mMapDocument = mapDocument
if (self.mMapDocument):
renderer = self.mMapDocument.renderer()
renderer.setObjectLineWidth(self.mObjectLineWidth)
renderer.setFlag(RenderFlag.ShowTileObjectOutlines, self.mShowTileObjectOutlines)
self.mMapDocument.mapChanged.connect(self.mapChanged)
self.mMapDocument.regionChanged.connect(self.repaintRegion)
self.mMapDocument.tileLayerDrawMarginsChanged.connect(self.tileLayerDrawMarginsChanged)
self.mMapDocument.layerAdded.connect(self.layerAdded)
self.mMapDocument.layerRemoved.connect(self.layerRemoved)
self.mMapDocument.layerChanged.connect(self.layerChanged)
self.mMapDocument.objectGroupChanged.connect(self.objectGroupChanged)
self.mMapDocument.imageLayerChanged.connect(self.imageLayerChanged)
self.mMapDocument.currentLayerIndexChanged.connect(self.currentLayerIndexChanged)
self.mMapDocument.tilesetTileOffsetChanged.connect(self.tilesetTileOffsetChanged)
self.mMapDocument.objectsInserted.connect(self.objectsInserted)
self.mMapDocument.objectsRemoved.connect(self.objectsRemoved)
self.mMapDocument.objectsChanged.connect(self.objectsChanged)
self.mMapDocument.objectsIndexChanged.connect(self.objectsIndexChanged)
self.mMapDocument.selectedObjectsChanged.connect(self.updateSelectedObjectItems)
self.refreshScene()
##
# Returns whether the tile grid is visible.
##
def isGridVisible(self):
return self.mGridVisible
#.........这里部分代码省略.........
示例5: AutoMapper
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import clear [as 别名]
#.........这里部分代码省略.........
def setupRuleMapProperties(self):
properties = self.mMapRules.properties()
for key in properties.keys():
value = properties.value(key)
raiseWarning = True
if (key.toLower() == "deletetiles"):
if (value.canConvert(QVariant.Bool)):
self.mDeleteTiles = value.toBool()
raiseWarning = False
elif (key.toLower() == "automappingradius"):
if (value.canConvert(QVariant.Int)):
self.mAutoMappingRadius = value
raiseWarning = False
elif (key.toLower() == "nooverlappingrules"):
if (value.canConvert(QVariant.Bool)):
self.mNoOverlappingRules = value.toBool()
raiseWarning = False
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()):
示例6: ObjectSelectionTool
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import clear [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:
#.........这里部分代码省略.........
示例7: EditPolygonTool
# 需要导入模块: from pyqtcore import QVector [as 别名]
# 或者: from pyqtcore.QVector import clear [as 别名]
class EditPolygonTool(AbstractObjectTool):
NoMode, Selecting, Moving = range(3)
def __init__(self, parent = None):
super().__init__(self.tr("Edit Polygons"),
QIcon(":images/24x24/tool-edit-polygons.png"),
QKeySequence(self.tr("E")),
parent)
self.mSelectedHandles = QSet()
self.mModifiers = Qt.KeyboardModifiers()
self.mScreenStart = QPoint()
self.mOldHandlePositions = QVector()
self.mAlignPosition = QPointF()
## The list of handles associated with each selected map object
self.mHandles = QMapList()
self.mOldPolygons = QMap()
self.mStart = QPointF()
self.mSelectionRectangle = SelectionRectangle()
self.mMousePressed = False
self.mClickedHandle = None
self.mClickedObjectItem = None
self.mMode = EditPolygonTool.NoMode
def __del__(self):
del self.mSelectionRectangle
def tr(self, sourceText, disambiguation = '', n = -1):
return QCoreApplication.translate('EditPolygonTool', sourceText, disambiguation, n)
def activate(self, scene):
super().activate(scene)
self.updateHandles()
# TODO: Could be more optimal by separating the updating of handles from
# the creation and removal of handles depending on changes in the
# selection, and by only updating the handles of the objects that changed.
self.mapDocument().objectsChanged.connect(self.updateHandles)
scene.selectedObjectItemsChanged.connect(self.updateHandles)
self.mapDocument().objectsRemoved.connect(self.objectsRemoved)
def deactivate(self, scene):
try:
self.mapDocument().objectsChanged.disconnect(self.updateHandles)
scene.selectedObjectItemsChanged.disconnect(self.updateHandles)
except:
pass
# Delete all handles
self.mHandles.clear()
self.mSelectedHandles.clear()
self.mClickedHandle = None
super().deactivate(scene)
def mouseEntered(self):
pass
def mouseMoved(self, pos, modifiers):
super().mouseMoved(pos, modifiers)
if (self.mMode == EditPolygonTool.NoMode and self.mMousePressed):
screenPos = QCursor.pos()
dragDistance = (self.mScreenStart - screenPos).manhattanLength()
if (dragDistance >= QApplication.startDragDistance()):
if (self.mClickedHandle):
self.startMoving()
else:
self.startSelecting()
x = self.mMode
if x==EditPolygonTool.Selecting:
self.mSelectionRectangle.setRectangle(QRectF(self.mStart, pos).normalized())
elif x==EditPolygonTool.Moving:
self.updateMovingItems(pos, modifiers)
elif x==EditPolygonTool.NoMode:
pass
def mousePressed(self, event):
if (self.mMode != EditPolygonTool.NoMode): # Ignore additional presses during select/move
return
x = event.button()
if x==Qt.LeftButton:
self.mMousePressed = True
self.mStart = event.scenePos()
self.mScreenStart = event.screenPos()
items = self.mapScene().items(self.mStart,
Qt.IntersectsItemShape,
Qt.DescendingOrder,
viewTransform(event))
self.mClickedObjectItem = first(items, MapObjectItem)
self.mClickedHandle = first(items, PointHandle)
elif x==Qt.RightButton:
items = self.mapScene().items(event.scenePos(),
Qt.IntersectsItemShape,
Qt.DescendingOrder,
viewTransform(event))
clickedHandle = first(items)
if (clickedHandle or not self.mSelectedHandles.isEmpty()):
self.showHandleContextMenu(clickedHandle,
event.screenPos())
else:
super().mousePressed(event)
else:
#.........这里部分代码省略.........