本文整理汇总了Python中pyqtcore.QMap.contains方法的典型用法代码示例。如果您正苦于以下问题:Python QMap.contains方法的具体用法?Python QMap.contains怎么用?Python QMap.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QMap
的用法示例。
在下文中一共展示了QMap.contains方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enumToInt
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
def enumToInt(self, metaEnum, enumValue):
valueMap = QMap() # dont show multiple enum values which have the same values
pos = 0
for i in range(metaEnum.keyCount()):
value = metaEnum.value(i)
if (not valueMap.contains(value)):
if (value == enumValue):
return pos
valueMap[value] = pos
pos += 1
return -1
示例2: intToEnum
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
def intToEnum(self, metaEnum, intValue):
valueMap = QMap() # dont show multiple enum values which have the same values
values = QList()
for i in range(metaEnum.keyCount()):
value = metaEnum.value(i)
if (not valueMap.contains(value)):
valueMap[value] = True
values.append(value)
if (intValue >= values.count()):
return -1
return values.at(intValue)
示例3: flagToInt
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
def flagToInt(self, metaEnum, flagValue):
if (not flagValue):
return 0
intValue = 0
valueMap = QMap() # dont show multiple enum values which have the same values
pos = 0
for i in range(metaEnum.keyCount()):
value = metaEnum.value(i)
if (not valueMap.contains(value) and self.isPowerOf2(value)):
if (self.isSubValue(flagValue, value)):
intValue |= (1 << pos)
valueMap[value] = pos
pos += 1
return intValue
示例4: intToFlag
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
def intToFlag(self, metaEnum, intValue):
valueMap = QMap() # dont show multiple enum values which have the same values
values = QList()
for i in range(metaEnum.keyCount()):
value = metaEnum.value(i)
if (not valueMap.contains(value) and self.isPowerOf2(value)):
valueMap[value] = True
values.append(value)
flagValue = 0
temp = intValue
i = 0
while (temp):
if (i >= values.count()):
return -1
if (temp & 1):
flagValue |= values.at(i)
i += 1
temp = temp >> 1
return flagValue
示例5: DecoratedDoublePropertyManager
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
class DecoratedDoublePropertyManager(QtDoublePropertyManager):
prefixChangedSignal = pyqtSignal(QtProperty, str)
suffixChangedSignal = pyqtSignal(QtProperty, str)
class Data:
prefix = ''
suffix = ''
def __init__(self, parent=None):
super().__init__(parent)
self.propertyToData = QMap()
def __del__(self):
pass
def prefix(self, property):
if (not self.propertyToData.contains(property)):
return ''
return self.propertyToData[property].prefix
def suffix(self, property):
if (not self.propertyToData.contains(property)):
return ''
return self.propertyToData[property].suffix
def setPrefix(self, property, prefix):
if (not self.propertyToData.contains(property)):
return
data = self.propertyToData[property]
if (data.prefix == prefix):
return
data.prefix = prefix
self.propertyToData[property] = data
self.propertyChangedSignal.emit(property)
self.suffixChangedSignal.emit(property, prefix)
def setSuffix(self, property, suffix):
if (not self.propertyToData.contains(property)):
return
data = self.propertyToData[property]
if (data.suffix == suffix):
return
data.suffix = suffix
self.propertyToData[property] = data
self.propertyChangedSignal.emit(property)
self.suffixChangedSignal.emit(property, suffix)
def valueText(self, property):
text = super().valueText(property)
if (not self.propertyToData.contains(property)):
return text
data = self.propertyToData[property]
text = data.prefix + text + data.suffix
return text
def initializeProperty(self, property):
self.propertyToData[property] = DecoratedDoublePropertyManager.Data()
super().initializeProperty(property)
def uninitializeProperty(self, property):
self.propertyToData.remove(property)
super().uninitializeProperty(property)
示例6: VariantPropertyManager
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
class VariantPropertyManager(QtVariantPropertyManager):
TYPEID_FILEPATH = 400
class Data:
def __init__(self):
self.value = QString()
self.filter = QString()
def __init__(self, parent = None):
self.mValues = QMap()
self.mSuggestions = QMapList()
self.mSuggestionsAttribute = QString()
self.Data = VariantPropertyManager.Data()
super().__init__(parent)
self.mSuggestionsAttribute = "suggestions"
def value(self, property):
if (self.mValues.contains(property)):
return self.mValues[property].value
return super().value(property)
def valueType(self, propertyType):
if (propertyType == VariantPropertyManager.filePathTypeId()):
return QVariant.String
return super().valueType(propertyType)
def isPropertyTypeSupported(self, propertyType):
if (propertyType == VariantPropertyManager.filePathTypeId()):
return True
return super().isPropertyTypeSupported(propertyType)
def attributes(self, propertyType):
if (propertyType == VariantPropertyManager.filePathTypeId()):
attr = QStringList()
attr.append("filter")
return attr
return super().attributes(propertyType)
def attributeType(self, propertyType, attribute):
if (propertyType == VariantPropertyManager.filePathTypeId()):
if (attribute == "filter"):
return QVariant.String
return 0
return super().attributeType(propertyType, attribute)
def attributeValue(self, property, attribute):
if (self.mValues.contains(property)):
if (attribute == "filter"):
return self.mValues[property].filter
return QVariant()
if (attribute == self.mSuggestionsAttribute and self.mSuggestions.contains(property)):
return self.mSuggestions[property]
return super().attributeValue(property, attribute)
def filePathTypeId():
return VariantPropertyManager.TYPEID_FILEPATH
def setValue(self, property, val):
if (self.mValues.contains(property)):
if type(val) != str:
return
s = val
d = self.mValues[property]
if (d.value == s):
return
d.value = s
self.mValues[property] = d
self.propertyChangedSignal.emit(property)
self.valueChangedSignal.emit(property, s)
return
super().setValue(property, val)
def setAttribute(self, property, attribute, val):
if (self.mValues.contains(property)):
if (attribute == "filter"):
if type(val) != str:
return
s = val
d = self.mValues[property]
if (d.filter == s):
return
d.filter = s
self.mValues[property] = d
self.attributeChangedSignal.emit(property, attribute, s)
return
if (attribute == self.mSuggestionsAttribute and self.mSuggestions.contains(property)):
self.mSuggestions[property] = val
super().setAttribute(property, attribute, val)
def valueText(self, property):
if (self.mValues.contains(property)):
return self.mValues[property].value
return super().valueText(property)
#.........这里部分代码省略.........
示例7: TilesetManager
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
class TilesetManager(QObject):
mInstance = None
##
# Emitted when a tileset's images have changed and views need updating.
##
tilesetChanged = pyqtSignal(Tileset)
##
# Emitted when any images of the tiles in the given \a tileset have
# changed. This is used to trigger repaints for displaying tile
# animations.
##
repaintTileset = pyqtSignal(Tileset)
##
# Constructor. Only used by the tileset manager it
##
def __init__(self):
super().__init__()
##
# Stores the tilesets and maps them to the number of references.
##
self.mTilesets = QMap()
self.mChangedFiles = QSet()
self.mWatcher = FileSystemWatcher(self)
self.mAnimationDriver = TileAnimationDriver(self)
self.mReloadTilesetsOnChange = False
self.mChangedFilesTimer = QTimer()
self.mWatcher.fileChanged.connect(self.fileChanged)
self.mChangedFilesTimer.setInterval(500)
self.mChangedFilesTimer.setSingleShot(True)
self.mChangedFilesTimer.timeout.connect(self.fileChangedTimeout)
self.mAnimationDriver.update.connect(self.advanceTileAnimations)
##
# Destructor.
##
def __del__(self):
# Since all MapDocuments should be deleted first, we assert that there are
# no remaining tileset references.
self.mTilesets.size() == 0
##
# Requests the tileset manager. When the manager doesn't exist yet, it
# will be created.
##
def instance():
if (not TilesetManager.mInstance):
TilesetManager.mInstance = TilesetManager()
return TilesetManager.mInstance
##
# Deletes the tileset manager instance, when it exists.
##
def deleteInstance():
del TilesetManager.mInstance
TilesetManager.mInstance = None
def findTileset(self, arg):
tp = type(arg)
if tp in [QString, str]:
##
# Searches for a tileset matching the given file name.
# @return a tileset matching the given file name, or 0 if none exists
##
fileName = arg
for tileset in self.tilesets():
if (tileset.fileName() == fileName):
return tileset
return None
elif tp==TilesetSpec:
##
# Searches for a tileset matching the given specification.
# @return a tileset matching the given specification, or 0 if none exists
##
spec = arg
for tileset in self.tilesets():
if (tileset.imageSource() == spec.imageSource
and tileset.tileWidth() == spec.tileWidth
and tileset.tileHeight() == spec.tileHeight
and tileset.tileSpacing() == spec.tileSpacing
and tileset.margin() == spec.margin):
return tileset
return None
##
# Adds a tileset reference. This will make sure the tileset is watched for
# changes and can be found using findTileset().
##
def addReference(self, tileset):
if (self.mTilesets.contains(tileset)):
self.mTilesets[tileset] += 1
else:
self.mTilesets.insert(tileset, 1)
imgSrc = tileset.imageSource()
if (imgSrc != ''):
self.mWatcher.addPath(imgSrc)
#.........这里部分代码省略.........
示例8: VariantManager
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
class VariantManager(QtVariantPropertyManager):
class Data:
value = QVariant()
x = 0
y = 0
def __init__(self, parent=None):
super(VariantManager, self).__init__(parent)
self.propertyToData = QMap()
self.xToProperty = QMap()
self.yToProperty = QMap()
self.valueChangedSignal.connect(self.slotValueChanged)
self.propertyDestroyedSignal.connect(self.slotPropertyDestroyed)
def __del__(self):
pass
def slotValueChanged(self, property, value):
if (self.xToProperty.contains(property)):
pointProperty = self.xToProperty[property]
v = self.value(pointProperty)
p = v.value()
p.setX(value)
self.setValue(pointProperty, p)
elif (self.yToProperty.contains(property)):
pointProperty = self.yToProperty[property]
v = self.value(pointProperty)
p = v.value()
p.setY(value)
self.setValue(pointProperty, p)
def slotPropertyDestroyed(self, property):
if (self.xToProperty.contains(property)):
pointProperty = self.xToProperty[property]
self.propertyToData[pointProperty].x = 0
self.xToProperty.remove(property)
elif (self.yToProperty.contains(property)):
pointProperty = self.yToProperty[property]
self.propertyToData[pointProperty].y = 0
self.yToProperty.remove(property)
def isPropertyTypeSupported(self, propertyType):
if (propertyType == QVariant.PointF):
return True
return super(VariantManager, self).isPropertyTypeSupported(propertyType)
def valueType(self, propertyType):
if (propertyType == QVariant.PointF):
return QVariant.PointF
return super(VariantManager, self).valueType(propertyType)
def value(self, property):
if (self.propertyToData.contains(property)):
return self.propertyToData[property].value
return super(VariantManager, self).value(property)
def valueText(self, property):
if (self.propertyToData.contains(property)):
v = self.propertyToData[property].value
p = v.value()
return self.tr("(%.2f, %.2f)"%(p.x(), p.y()))
return super(VariantManager, self).valueText(property)
def setValue(self, property, val):
if (self.propertyToData.contains(property)):
if type(val)!=QVariant:
val = QVariant(val)
if (val.type() != QVariant.PointF and not val.canConvert(QVariant.PointF)):
return
p = val.value()
d = self.propertyToData[property]
d.value = QVariant(p)
if (d.x):
d.x.setValue(p.x())
if (d.y):
d.y.setValue(p.y())
self.propertyToData[property] = d
self.propertyChangedSignal.emit(property)
self.valueChangedSignal.emit(property, p)
return
super(VariantManager, self).setValue(property, val)
def initializeProperty(self, property):
if (self.propertyType(property) == QVariant.PointF):
d = VariantManager.Data()
d.value = QVariant(QPointF(0, 0))
d.x = self.addProperty(QVariant.Double)
d.x.setPropertyName(self.tr("Position X"))
property.addSubProperty(d.x)
self.xToProperty[d.x] = property
d.y = self.addProperty(QVariant.Double)
d.y.setPropertyName(self.tr("Position Y"))
property.addSubProperty(d.y)
self.yToProperty[d.y] = property
#.........这里部分代码省略.........
示例9: MainWindow
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
#.........这里部分代码省略.........
self.addProperty(property, "size")
elif (item.rtti() == RttiValues.Rtti_Line):
i = item
property = self.colorManager.addProperty(self.tr("Pen Color"))
self.colorManager.setValue(property, i.pen().color())
self.addProperty(property, "pen")
property = self.pointManager.addProperty(self.tr("Vector"))
self.pointManager.setValue(property, i.endPoint())
self.addProperty(property, "endpoint")
elif (item.rtti() == RttiValues.Rtti_Ellipse):
i = item
property = self.colorManager.addProperty(self.tr("Brush Color"))
self.colorManager.setValue(property, i.brush().color())
self.addProperty(property, "brush")
property = self.sizeManager.addProperty(self.tr("Size"))
self.sizeManager.setValue(property, QSize(i.width(), i.height()))
self.sizeManager.setRange(property, QSize(0, 0), QSize(1000, 1000))
self.addProperty(property, "size")
elif (item.rtti() == RttiValues.Rtti_Text):
i = item
property = self.colorManager.addProperty(self.tr("Color"))
self.colorManager.setValue(property, i.color())
self.addProperty(property, "color")
property = self.stringManager.addProperty(self.tr("Text"))
self.stringManager.setValue(property, i.text())
self.addProperty(property, "text")
property = self.fontManager.addProperty(self.tr("Font"))
self.fontManager.setValue(property, i.font())
self.addProperty(property, "font")
def addProperty(self, property, id):
self.propertyToId[property] = id
self.idToProperty[id] = property
item = self.propertyEditor.addProperty(property)
if (self.idToExpanded.contains(id)):
self.propertyEditor.setExpanded(item, self.idToExpanded[id])
def valueChanged(self, property, value):
if (not self.propertyToId.contains(property)):
return
if (not self.currentItem or self.currentItem.isNone()):
return
tp = type(value)
id = self.propertyToId[property]
if tp == float:
if (id == "xpos"):
self.currentItem.setX(value)
elif (id == "ypos"):
self.currentItem.setY(value)
elif (id == "zpos"):
self.currentItem.setZ(value)
elif tp == str:
if (id == "text"):
if (self.currentItem.rtti() == RttiValues.Rtti_Text):
i = self.currentItem
i.setText(value)
elif tp == QColor:
if (id == "color"):
if (self.currentItem.rtti() == RttiValues.Rtti_Text):
i = self.currentItem
i.setColor(value)
elif (id == "brush"):
if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle or self.currentItem.rtti() == RttiValues.Rtti_Ellipse):
i = self.currentItem
b = QBrush(i.brush())
b.setColor(value)
i.setBrush(b)
elif (id == "pen"):
if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle or self.currentItem.rtti() == RttiValues.Rtti_Line):
i = self.currentItem
p = QPen(i.pen())
p.setColor(value)
i.setPen(p)
elif tp == QFont:
if (id == "font"):
if (self.currentItem.rtti() == RttiValues.Rtti_Text):
i = self.currentItem
i.setFont(value)
elif tp == QPoint:
if (self.currentItem.rtti() == RttiValues.Rtti_Line):
i = self.currentItem
if (id == "endpoint"):
i.setPoints(i.startPoint().x(), i.startPoint().y(), value.x(), value.y())
elif tp == QSize:
if (id == "size"):
if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle):
i = self.currentItem
i.setSize(value.width(), value.height())
elif (self.currentItem.rtti() == RttiValues.Rtti_Ellipse):
i = self.currentItem
i.setSize(value.width(), value.height())
self.canvas.update()
示例10: ObjectControllerPrivate
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
class ObjectControllerPrivate():
def __init__(self):
self.q_ptr = 0
self.m_object = 0
self.m_classToProperty = QMap()
self.m_propertyToClass = QMap()
self.m_propertyToIndex = QMap()
self.m_classToIndexToProperty = QMapMap()
self.m_propertyToExpanded = QMap()
self.m_topLevelProperties = QList()
self.m_browser = 0
self.m_manager = 0
self.m_readOnlyManager = 0
def enumToInt(self, metaEnum, enumValue):
valueMap = QMap() # dont show multiple enum values which have the same values
pos = 0
for i in range(metaEnum.keyCount()):
value = metaEnum.value(i)
if (not valueMap.contains(value)):
if (value == enumValue):
return pos
valueMap[value] = pos
pos += 1
return -1
def intToEnum(self, metaEnum, intValue):
valueMap = QMap() # dont show multiple enum values which have the same values
values = QList()
for i in range(metaEnum.keyCount()):
value = metaEnum.value(i)
if (not valueMap.contains(value)):
valueMap[value] = True
values.append(value)
if (intValue >= values.count()):
return -1
return values.at(intValue)
def isSubValue(self, value, subValue):
if (value == subValue):
return True
i = 0
while (subValue):
if (not (value & (1 << i))):
if (subValue & 1):
return False
i += 1
subValue = subValue >> 1
return True
def isPowerOf2(self, value):
while (value):
if (value & 1):
return value == 1
value = value >> 1
return False
def flagToInt(self, metaEnum, flagValue):
if (not flagValue):
return 0
intValue = 0
valueMap = QMap() # dont show multiple enum values which have the same values
pos = 0
for i in range(metaEnum.keyCount()):
value = metaEnum.value(i)
if (not valueMap.contains(value) and self.isPowerOf2(value)):
if (self.isSubValue(flagValue, value)):
intValue |= (1 << pos)
valueMap[value] = pos
pos += 1
return intValue
def intToFlag(self, metaEnum, intValue):
valueMap = QMap() # dont show multiple enum values which have the same values
values = QList()
for i in range(metaEnum.keyCount()):
value = metaEnum.value(i)
if (not valueMap.contains(value) and self.isPowerOf2(value)):
valueMap[value] = True
values.append(value)
flagValue = 0
temp = intValue
i = 0
while (temp):
if (i >= values.count()):
return -1
if (temp & 1):
flagValue |= values.at(i)
i += 1
temp = temp >> 1
return flagValue
#.........这里部分代码省略.........
示例11: addClassProperties
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
def addClassProperties(self, metaObject):
if (not metaObject):
return
self.addClassProperties(metaObject.superClass())
classProperty = self.m_classToProperty.value(metaObject)
if (not classProperty):
className = metaObject.className()
classProperty = self.m_manager.addProperty(QtVariantPropertyManager.groupTypeId(), className)
self.m_classToProperty[metaObject] = classProperty
self.m_propertyToClass[classProperty] = metaObject
for idx in range(metaObject.propertyOffset(), metaObject.propertyCount(), 1):
metaProperty = metaObject.property(idx)
type = metaProperty.userType()
subProperty = 0
if (not metaProperty.isReadable()):
subProperty = self.m_readOnlyManager.addProperty(QVariant.String, metaProperty.name())
subProperty.setValue("< Non Readable >")
elif (metaProperty.isEnumType()):
if (metaProperty.isFlagType()):
subProperty = self.m_manager.addProperty(QtVariantPropertyManager.flagTypeId(), metaProperty.name())
metaEnum = metaProperty.enumerator()
valueMap = QMap()
flagNames = QList()
for i in range(metaEnum.keyCount()):
value = metaEnum.value(i)
if (not valueMap.contains(value) and self.isPowerOf2(value)):
valueMap[value] = True
flagNames.append(metaEnum.key(i))
subProperty.setAttribute("flagNames", flagNames)
subProperty.setValue(self.flagToInt(metaEnum, metaProperty.read(self.m_object)))
else:
subProperty = self.m_manager.addProperty(QtVariantPropertyManager.enumTypeId(), metaProperty.name())
metaEnum = metaProperty.enumerator()
valueMap = QMap() # dont show multiple enum values which have the same values
enumNames = QList()
for i in range(metaEnum.keyCount()):
value = metaEnum.value(i)
if (not valueMap.contains(value)):
valueMap[value] = True
enumNames.append(metaEnum.key(i))
subProperty.setAttribute("enumNames", enumNames)
subProperty.setValue(self.enumToInt(metaEnum, metaProperty.read(self.m_object)))
elif (self.m_manager.isPropertyTypeSupported(type)):
if (not metaProperty.isWritable()):
subProperty = self.m_readOnlyManager.addProperty(type, metaProperty.name() + " (Non Writable)")
if (not metaProperty.isDesignable()):
subProperty = self.m_readOnlyManager.addProperty(type, metaProperty.name() + " (Non Designable)")
else:
subProperty = self.m_manager.addProperty(type, metaProperty.name())
subProperty.setValue(metaProperty.read(self.m_object))
else:
subProperty = self.m_readOnlyManager.addProperty(QVariant.String, metaProperty.name())
subProperty.setValue("< Unknown Type >")
subProperty.setEnabled(False)
classProperty.addSubProperty(subProperty)
self.m_propertyToIndex[subProperty] = idx
self.m_classToIndexToProperty[metaObject][idx] = subProperty
else:
self.updateClassProperties(metaObject, False)
self.m_topLevelProperties.append(classProperty)
self.m_browser.addProperty(classProperty)
示例12: MapObjectModel
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
class MapObjectModel(QAbstractItemModel):
objectsAdded = pyqtSignal(QList)
objectsChanged = pyqtSignal(QList)
objectsRemoved = pyqtSignal(QList)
def __init__(self, parent):
super().__init__(parent)
self.mObjectGroups = QList()
self.mObjects = QMap()
self.mGroups = QMap()
self.mMapDocument = None
self.mMap = None
self.mObject = None
self.mObjectGroupIcon = ":/images/16x16/layer-object.png"
def index(self, *args):
l = len(args)
if l>0:
tp = type(args[0])
if tp==int:
if l==2:
args = (args[0], args[1], QModelIndex())
row, column, parent = args
if (not parent.isValid()):
if (row < self.mObjectGroups.count()):
return self.createIndex(row, column, self.mGroups[self.mObjectGroups.at(row)])
return QModelIndex()
og = self.toObjectGroup(parent)
# happens when deleting the last item in a parent
if (row >= og.objectCount()):
return QModelIndex()
# Paranoia: sometimes "fake" objects are in use (see createobjecttool)
if (not self.mObjects.contains(og.objects().at(row))):
return QModelIndex()
return self.createIndex(row, column, self.mObjects[og.objects()[row]])
elif tp==ObjectGroup:
og = args[0]
row = self.mObjectGroups.indexOf(og)
return self.createIndex(row, 0, self.mGroups[og])
elif tp==MapObject:
if l==1:
args = (args[0],0)
o, column = args
row = o.objectGroup().objects().indexOf(o)
return self.createIndex(row, column, self.mObjects[o])
def parent(self, index):
mapObject = self.toMapObject(index)
if mapObject:
return self.index(mapObject.objectGroup())
return QModelIndex()
def rowCount(self, parent = QModelIndex()):
if (not self.mMapDocument):
return 0
if (not parent.isValid()):
return self.mObjectGroups.size()
og = self.toObjectGroup(parent)
if og:
return og.objectCount()
return 0
def columnCount(self, parent = QModelIndex()):
return 2 # MapObject name|type
def headerData(self, section, orientation, role = Qt.DisplayRole):
if (role == Qt.DisplayRole and orientation == Qt.Horizontal):
x = section
if x==0:
return self.tr("Name")
elif x==1:
return self.tr("Type")
return QVariant()
def setData(self, index, value, role):
mapObject = self.toMapObject(index)
if mapObject:
x = role
if x==Qt.CheckStateRole:
c = value
visible = (c == Qt.Checked)
if (visible != mapObject.isVisible()):
command = SetMapObjectVisible(self.mMapDocument, mapObject, visible)
self.mMapDocument.undoStack().push(command)
return True
elif x==Qt.EditRole:
s = value
if (index.column() == 0 and s != mapObject.name()):
undo = self.mMapDocument.undoStack()
undo.beginMacro(self.tr("Change Object Name"))
undo.push(ChangeMapObject(self.mMapDocument, mapObject, s, mapObject.type()))
undo.endMacro()
if (index.column() == 1 and s != mapObject.type()):
undo = self.mMapDocument.undoStack()
undo.beginMacro(self.tr("Change Object Type"))
undo.push(ChangeMapObject(self.mMapDocument, mapObject, mapObject.name(), s))
#.........这里部分代码省略.........
示例13: TileStampManager
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [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()):
#.........这里部分代码省略.........
示例14: EditPolygonTool
# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import contains [as 别名]
#.........这里部分代码省略.........
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:
super().mousePressed(event)
def mouseReleased(self, event):
if (event.button() != Qt.LeftButton):
return
x = self.mMode
if x==EditPolygonTool.NoMode:
if (self.mClickedHandle):
selection = self.mSelectedHandles
modifiers = event.modifiers()
if (modifiers & (Qt.ShiftModifier | Qt.ControlModifier)):
if (selection.contains(self.mClickedHandle)):
selection.remove(self.mClickedHandle)
else:
selection.insert(self.mClickedHandle)
else:
selection.clear()
selection.insert(self.mClickedHandle)
self.setSelectedHandles(selection)
elif (self.mClickedObjectItem):
selection = self.mapScene().selectedObjectItems()
modifiers = event.modifiers()
if (modifiers & (Qt.ShiftModifier | Qt.ControlModifier)):
if (selection.contains(self.mClickedObjectItem)):
selection.remove(self.mClickedObjectItem)
else:
selection.insert(self.mClickedObjectItem)
else:
selection.clear()
selection.insert(self.mClickedObjectItem)
self.mapScene().setSelectedObjectItems(selection)
self.updateHandles()
elif (not self.mSelectedHandles.isEmpty()):
# First clear the handle selection
self.setSelectedHandles(QSet())
else:
# If there is no handle selection, clear the object selection
self.mapScene().setSelectedObjectItems(QSet())
self.updateHandles()
elif x==EditPolygonTool.Selecting:
self.updateSelection(event)
self.mapScene().removeItem(self.mSelectionRectangle)