本文整理汇总了Python中pyqtcore.QMap.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QMap.clear方法的具体用法?Python QMap.clear怎么用?Python QMap.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QMap
的用法示例。
在下文中一共展示了QMap.clear方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RandomPicker
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import clear [as 别名]
class RandomPicker():
def __init__(self):
self.mSum = 0.0
self.mThresholds = QMap()
def add(self, value, probability = 1.0):
self.mSum += probability
self.mThresholds.insert(self.mSum, value)
def isEmpty(self):
return self.mThresholds.isEmpty()
def pick(self):
random = (rand() / RAND_MAX) * self.mSum
it = self.mThresholds.lowerBound(random)
if (it != self.mThresholds.end()):
return self.mThresholds.itemByIndex(it)[1]
else:
return self.mThresholds.itemByIndex(-1)[1]
def clear(self):
self.mSum = 0.0
self.mThresholds.clear()
示例2: VariantEditorFactory
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import clear [as 别名]
class VariantEditorFactory(QtVariantEditorFactory):
def __init__(self, parent = None):
super().__init__(parent)
self.mCreatedEditors = QMapList()
self.mEditorToProperty = QMap()
def __del__(self):
self.mEditorToProperty.clear()
def connectPropertyManager(self, manager):
manager.valueChangedSignal.connect(self.slotPropertyChanged)
manager.attributeChangedSignal.connect(self.slotPropertyAttributeChanged)
super().connectPropertyManager(manager)
def createEditor(self, manager, property, parent):
type = manager.propertyType(property)
if (type == VariantPropertyManager.filePathTypeId()):
editor = FileEdit(parent)
editor.setFilePath(manager.value(property))
editor.setFilter(manager.attributeValue(property, "filter"))
self.mCreatedEditors[property].append(editor)
self.mEditorToProperty[editor] = property
editor.filePathChanged.connect(self.slotSetValue)
editor.destroyed.connect(self.slotEditorDestroyed)
return editor
editor = super().createEditor(manager, property, parent)
if (type == QVariant.String):
# Add support for "suggestions" attribute that adds a QCompleter to the QLineEdit
suggestions = manager.attributeValue(property, "suggestions")
if suggestions and len(suggestions)>0:
lineEdit = editor
if lineEdit:
completer = QCompleter(suggestions, lineEdit)
completer.setCaseSensitivity(Qt.CaseInsensitive)
lineEdit.setCompleter(completer)
return editor
def disconnectPropertyManager(self, manager):
manager.valueChangedSignal.disconnect(self.slotPropertyChanged)
manager.attributeChangedSignal.disconnect(self.slotPropertyAttributeChanged)
super().disconnectPropertyManager(manager)
def slotPropertyChanged(self, property, value):
if (not self.mCreatedEditors.contains(property)):
return
editors = self.mCreatedEditors[property]
for itEditor in editors:
itEditor.setFilePath(value.toString())
def slotPropertyAttributeChanged(self, property, attribute, value):
if (not self.mCreatedEditors.contains(property)):
return
if (attribute != "filter"):
return
editors = self.mCreatedEditors[property]
for itEditor in editors:
itEditor.setFilter(value.toString())
def slotSetValue(self, value):
object = self.sender()
itEditor = self.mEditorToProperty.constBegin()
while (itEditor != self.mEditorToProperty.constEnd()):
if (itEditor.key() == object):
property = itEditor.value()
manager = self.propertyManager(property)
if (not manager):
return
manager.setValue(property, value)
return
itEditor += 1
def slotEditorDestroyed(self, object):
for itEditor in self.mEditorToProperty:
if (itEditor.key() == object):
editor = itEditor.key()
property = itEditor.value()
self.mEditorToProperty.remove(editor)
self.mCreatedEditors[property].removeAll(editor)
if (self.mCreatedEditors[property].isEmpty()):
self.mCreatedEditors.remove(property)
return
示例3: RangeSet
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import clear [as 别名]
class RangeSet():
# This class is based on std.map rather than QMap since std.map's insert
# method has an overload that takes a hint about where to insert the new
# pair.
def __init__(self):
self.mMap = QMap()
##
# Insert \a value in the set of ranges. Has no effect when the value is
# already part of an existing range. When possible, an existing range is
# extended to include the new value, otherwise a new range is inserted.
##
def insert(self, value):
if (self.mMap.empty()):
self.mMap.insert(value, value)
return
# We can now assume that 'it' will be at most one end of the range
# This is the only full-tree search of the map, everything else is
# relative to this
it = self.mMap.lowerBound(value)
itValue = self.mMap.itemByIndex(it)
begin = self.mMap.begin()
end = self.mMap.end()
if (it == end):
# Check whether the value is included in the last range
# assert: it != begin
it -= 1
itValue = self.mMap.itemByIndex(it)
# assert: it.first < value
if (itValue[1] >= value):
return
# Try to add the value to the end of the previous range
itValue[1] += 1
if (itValue[1] == value):
return
# Didn't work, restore the previous range
itValue[1] -= 1
# We have to insert a new range
self.mMap.insert(it, [value, value])
return
# Now we can dereference 'it' itself
# assert: it.first >= value
if (itValue[0] == value):
return
# Check whether we can extend the range downwards to include value
if (itValue[0] == value + 1):
# When extending the range downwards, it may need to be merged
# with the previous range.
# Remember 'prev' for the insertion hint. It is not necessarily
# before the value, if it == begin.
prev = itValue
if (it != begin):
prev = self.mMap.itemByIndex(prev-1)
if (prev[1] == value - 1):
# The new value fills the gab. Merge the ranges, leaving
# only the first, but with a larger range.
prev[1] = itValue[1]
self.mMap.erase(itValue[0])
return
# No merge needed
# To change the key, we have to both add and remove. Add first,
# then remove, to avoid invalidating the iterator too early.
self.mMap.insert(prev, [value, itValue[1]])
self.mMap.erase(it)
return
# Check if we can grow the previous range upwards to include value
if (it != begin):
it -= 1
itValue = self.mMap.itemByIndex(it)
if (itValue[1] == value - 1):
itValue[1] += 1
return
# 'it' now points below the range, unless it was already begin
# We couldn't increase an existing range
self.mMap.insert(it, [value, value])
##
# Removes all ranges from this set.
##
def clear(self):
self.mMap.clear()
# Only are provided, because it is not safe to modify the
# underlying list. Note that const_iterator is a typedef for Range.
def begin(self):
return self.mMap.begin()
def end(self):
return self.mMap.end()
def isEmpty(self):
return self.mMap.empty()
#.........这里部分代码省略.........
示例4: QtCursorDatabase
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import clear [as 别名]
class QtCursorDatabase():
def __init__(self):
self.m_cursorNames = QList()
self.m_cursorIcons = QMap()
self.m_valueToCursorShape = QMap()
self.m_cursorShapeToValue = QMap()
self.appendCursor(Qt.ArrowCursor, QCoreApplication.translate("QtCursorDatabase", "Arrow"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-arrow.png"))
self.appendCursor(Qt.UpArrowCursor, QCoreApplication.translate("QtCursorDatabase", "Up Arrow"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-uparrow.png"))
self.appendCursor(Qt.CrossCursor, QCoreApplication.translate("QtCursorDatabase", "Cross"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-cross.png"))
self.appendCursor(Qt.WaitCursor, QCoreApplication.translate("QtCursorDatabase", "Wait"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-wait.png"))
self.appendCursor(Qt.IBeamCursor, QCoreApplication.translate("QtCursorDatabase", "IBeam"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-ibeam.png"))
self.appendCursor(Qt.SizeVerCursor, QCoreApplication.translate("QtCursorDatabase", "Size Vertical"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-sizev.png"))
self.appendCursor(Qt.SizeHorCursor, QCoreApplication.translate("QtCursorDatabase", "Size Horizontal"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-sizeh.png"))
self.appendCursor(Qt.SizeFDiagCursor, QCoreApplication.translate("QtCursorDatabase", "Size Backslash"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-sizef.png"))
self.appendCursor(Qt.SizeBDiagCursor, QCoreApplication.translate("QtCursorDatabase", "Size Slash"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-sizeb.png"))
self.appendCursor(Qt.SizeAllCursor, QCoreApplication.translate("QtCursorDatabase", "Size All"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-sizeall.png"))
self.appendCursor(Qt.BlankCursor, QCoreApplication.translate("QtCursorDatabase", "Blank"),
QIcon())
self.appendCursor(Qt.SplitVCursor, QCoreApplication.translate("QtCursorDatabase", "Split Vertical"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-vsplit.png"))
self.appendCursor(Qt.SplitHCursor, QCoreApplication.translate("QtCursorDatabase", "Split Horizontal"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-hsplit.png"))
self.appendCursor(Qt.PointingHandCursor, QCoreApplication.translate("QtCursorDatabase", "Pointing Hand"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-hand.png"))
self.appendCursor(Qt.ForbiddenCursor, QCoreApplication.translate("QtCursorDatabase", "Forbidden"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-forbidden.png"))
self.appendCursor(Qt.OpenHandCursor, QCoreApplication.translate("QtCursorDatabase", "Open Hand"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-openhand.png"))
self.appendCursor(Qt.ClosedHandCursor, QCoreApplication.translate("QtCursorDatabase", "Closed Hand"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-closedhand.png"))
self.appendCursor(Qt.WhatsThisCursor, QCoreApplication.translate("QtCursorDatabase", "What's This"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-whatsthis.png"))
self.appendCursor(Qt.BusyCursor, QCoreApplication.translate("QtCursorDatabase", "Busy"),
QIcon(":/qt-project.org/qtpropertybrowser/images/cursor-busy.png"))
def clear(self):
self.m_cursorNames.clear()
self.m_cursorIcons.clear()
self.m_valueToCursorShape.clear()
self.m_cursorShapeToValue.clear()
def appendCursor(self,shape, name, icon):
if self.m_cursorShapeToValue.get(shape):
return
value = len(self.m_cursorNames)
self.m_cursorNames.append(name)
self.m_cursorIcons[value] = icon
self.m_valueToCursorShape[value] = shape
self.m_cursorShapeToValue[shape] = value
def cursorShapeNames(self):
return self.m_cursorNames
def cursorShapeIcons(self):
return self.m_cursorIcons
def cursorToShapeName(self,cursor):
val = self.cursorToValue(cursor)
if val >= 0:
return self.m_cursorNames[val]
return ''
def cursorToShapeIcon(self,cursor):
val = self.cursorToValue(cursor)
return self.m_cursorIcons[val]
def cursorToValue(self,cursor):
shape = cursor.shape()
return self.m_cursorShapeToValue.get(shape, -1)
def valueToCursor(self,value):
if value in self.m_valueToCursorShape:
return QCursor(self.m_valueToCursorShape[value])
return QCursor()
示例5: MainWindow
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import clear [as 别名]
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.propertyToId = QMap()
self.idToProperty = QMap()
self.idToExpanded = QMap()
editMenu = self.menuBar().addMenu(self.tr("Edit"))
newObjectMenu = editMenu.addMenu(self.tr("New Object"))
newRectangleAction = QAction(self.tr("Rectangle"), self)
newRectangleAction.triggered.connect(self.newRectangle)
newObjectMenu.addAction(newRectangleAction)
newLineAction = QAction(self.tr("Line"), self)
newLineAction.triggered.connect(self.newLine)
newObjectMenu.addAction(newLineAction)
newEllipseAction = QAction(self.tr("Ellipse"), self)
newEllipseAction.triggered.connect(self.newEllipse)
newObjectMenu.addAction(newEllipseAction)
newTextAction = QAction(self.tr("Text"), self)
newTextAction.triggered.connect(self.newText)
newObjectMenu.addAction(newTextAction)
self.deleteAction = QAction(self.tr("Delete Object"), self)
self.deleteAction.triggered.connect(self.deleteObject)
editMenu.addAction(self.deleteAction)
clearAction = QAction(self.tr("Clear All"), self)
clearAction.triggered.connect(self.clearAll)
editMenu.addAction(clearAction)
fillAction = QAction(self.tr("Fill View"), self)
fillAction.triggered.connect(self.fillView)
editMenu.addAction(fillAction)
self.doubleManager = QtDoublePropertyManager(self)
self.stringManager = QtStringPropertyManager(self)
self.colorManager = QtColorPropertyManager(self)
self.fontManager = QtFontPropertyManager(self)
self.pointManager = QtPointPropertyManager(self)
self.sizeManager = QtSizePropertyManager(self)
self.doubleManager.valueChangedSignal.connect(self.valueChanged)
self.stringManager.valueChangedSignal.connect(self.valueChanged)
self.colorManager.valueChangedSignal.connect(self.valueChanged)
self.fontManager.valueChangedSignal.connect(self.valueChanged)
self.pointManager.valueChangedSignal.connect(self.valueChanged)
self.sizeManager.valueChangedSignal.connect(self.valueChanged)
doubleSpinBoxFactory = QtDoubleSpinBoxFactory(self)
checkBoxFactory = QtCheckBoxFactory(self)
spinBoxFactory = QtSpinBoxFactory(self)
lineEditFactory = QtLineEditFactory(self)
comboBoxFactory = QtEnumEditorFactory(self)
self.canvas = QtCanvas(800, 600)
self.canvasView = CanvasView(self.canvas, self)
self.setCentralWidget(self.canvasView)
dock = QDockWidget(self)
self.addDockWidget(Qt.RightDockWidgetArea, dock)
self.propertyEditor = QtTreePropertyBrowser(dock)
self.propertyEditor.setFactoryForManager(self.doubleManager, doubleSpinBoxFactory)
self.propertyEditor.setFactoryForManager(self.stringManager, lineEditFactory)
self.propertyEditor.setFactoryForManager(self.colorManager.subIntPropertyManager(), spinBoxFactory)
self.propertyEditor.setFactoryForManager(self.fontManager.subIntPropertyManager(), spinBoxFactory)
self.propertyEditor.setFactoryForManager(self.fontManager.subBoolPropertyManager(), checkBoxFactory)
self.propertyEditor.setFactoryForManager(self.fontManager.subEnumPropertyManager(), comboBoxFactory)
self.propertyEditor.setFactoryForManager(self.pointManager.subIntPropertyManager(), spinBoxFactory)
self.propertyEditor.setFactoryForManager(self.sizeManager.subIntPropertyManager(), spinBoxFactory)
dock.setWidget(self.propertyEditor)
self.currentItem = QtCanvasItem(None)
self.canvasView.itemClickedSignal.connect(self.itemClicked)
self.canvasView.itemMovedSignal.connect(self.itemMoved)
self.fillView()
self.itemClicked(QtCanvasItem(None))
def newRectangle(self):
item = self.addRectangle()
self.canvas.update()
self.itemClicked(item)
def newEllipse(self):
item = self.addEllipse()
self.canvas.update()
self.itemClicked(item)
def newLine(self):
item = self.addLine()
self.canvas.update()
self.itemClicked(item)
#.........这里部分代码省略.........
示例6: MapObjectModel
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import clear [as 别名]
#.........这里部分代码省略.........
def toObjectGroup(self, index):
if (not index.isValid()):
return None
oog = index.internalPointer()
if oog:
return oog.mGroup
def toMapObject(self, index):
if (not index.isValid()):
return None
oog = index.internalPointer()
if oog:
return oog.mObject
def toLayer(self, index):
if (not index.isValid()):
return None
oog = index.internalPointer()
if oog:
if oog.mGroup:
_x = oog.mGroup
else:
_x = oog.mObject.objectGroup()
return _x
def setMapDocument(self, mapDocument):
if (self.mMapDocument == mapDocument):
return
if (self.mMapDocument):
self.mMapDocument.disconnect()
self.beginResetModel()
self.mMapDocument = mapDocument
self.mMap = None
self.mObjectGroups.clear()
self.mGroups.clear()
self.mGroups.clear()
self.mObjects.clear()
self.mObjects.clear()
if (self.mMapDocument):
self.mMap = self.mMapDocument.map()
self.mMapDocument.layerAdded.connect(self.layerAdded)
self.mMapDocument.layerChanged.connect(self.layerChanged)
self.mMapDocument.layerAboutToBeRemoved.connect(self.layerAboutToBeRemoved)
for og in self.mMap.objectGroups():
if GROUPS_IN_DISPLAY_ORDER:
self.mObjectGroups.prepend(og)
else:
self.mObjectGroups.append(og)
self.mGroups.insert(og, ObjectOrGroup(og))
for o in og.objects():
self.mObjects.insert(o, ObjectOrGroup(o))
self.endResetModel()
def insertObject(self, og, index, o):
if (index >= 0):
_x = index
else:
_x = og.objectCount()
row = _x
self.beginInsertRows(self.index(og), row, row)
og.insertObject(row, o)
self.mObjects.insert(o, ObjectOrGroup(o))
self.endInsertRows()
self.objectsAdded.emit(QList([o]))
示例7: TileStampManager
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import clear [as 别名]
class TileStampManager(QObject):
setStamp = pyqtSignal(TileStamp)
def __init__(self, toolManager, parent = None):
super().__init__(parent)
self.mStampsByName = QMap()
self.mQuickStamps = QVector()
for i in range(TileStampManager.quickStampKeys().__len__()):
self.mQuickStamps.append(0)
self.mTileStampModel = TileStampModel(self)
self.mToolManager = toolManager
prefs = preferences.Preferences.instance()
prefs.stampsDirectoryChanged.connect(self.stampsDirectoryChanged)
self.mTileStampModel.stampAdded.connect(self.stampAdded)
self.mTileStampModel.stampRenamed.connect(self.stampRenamed)
self.mTileStampModel.stampChanged.connect(self.saveStamp)
self.mTileStampModel.stampRemoved.connect(self.deleteStamp)
self.loadStamps()
def __del__(self):
# needs to be over here where the TileStamp type is complete
pass
##
# Returns the keys used for quickly accessible tile stamps.
# Note: To store a tile layer <Ctrl> is added. The given keys will work
# for recalling the stored values.
##
def quickStampKeys():
keys=[Qt.Key_1, Qt.Key_2, Qt.Key_3, Qt.Key_4, Qt.Key_5, Qt.Key_6, Qt.Key_7, Qt.Key_8, Qt.Key_9]
return keys
def tileStampModel(self):
return self.mTileStampModel
def createStamp(self):
stamp = self.tampFromContext(self.mToolManager.selectedTool())
if (not stamp.isEmpty()):
self.mTileStampModel.addStamp(stamp)
return stamp
def addVariation(self, targetStamp):
stamp = stampFromContext(self.mToolManager.selectedTool())
if (stamp.isEmpty()):
return
if (stamp == targetStamp): # avoid easy mistake of adding duplicates
return
for variation in stamp.variations():
self.mTileStampModel.addVariation(targetStamp, variation)
def selectQuickStamp(self, index):
stamp = self.mQuickStamps.at(index)
if (not stamp.isEmpty()):
self.setStamp.emit(stamp)
def createQuickStamp(self, index):
stamp = stampFromContext(self.mToolManager.selectedTool())
if (stamp.isEmpty()):
return
self.setQuickStamp(index, stamp)
def extendQuickStamp(self, index):
quickStamp = self.mQuickStamps[index]
if (quickStamp.isEmpty()):
self.createQuickStamp(index)
else:
self.addVariation(quickStamp)
def stampsDirectoryChanged(self):
# erase current stamps
self.mQuickStamps.fill(TileStamp())
self.mStampsByName.clear()
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()):
#.........这里部分代码省略.........
示例8: MapScene
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap 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
#.........这里部分代码省略.........
示例9: GidMapper
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import clear [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
#.........这里部分代码省略.........
示例10: EditPolygonTool
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap 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:
#.........这里部分代码省略.........