当前位置: 首页>>代码示例>>Python>>正文


Python QMap.erase方法代码示例

本文整理汇总了Python中pyqtcore.QMap.erase方法的典型用法代码示例。如果您正苦于以下问题:Python QMap.erase方法的具体用法?Python QMap.erase怎么用?Python QMap.erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyqtcore.QMap的用法示例。


在下文中一共展示了QMap.erase方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FileSystemWatcher

# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import erase [as 别名]
class FileSystemWatcher(QObject):
    fileChanged = pyqtSignal(str)
    directoryChanged = pyqtSignal(str)

    def __init__(self, parent = None):
        super().__init__(parent)

        self.mWatchCount = QMap()
        self.mWatcher = QFileSystemWatcher(self)
        self.mWatcher.fileChanged.connect(self.onFileChanged)
        self.mWatcher.directoryChanged.connect(self.onDirectoryChanged)

    def addPath(self, path):
        # Just silently ignore the request when the file doesn't exist
        if (not QFile.exists(path)):
            return
        entry = self.mWatchCount.find(path)
        if not entry:
            self.mWatcher.addPath(path)
            self.mWatchCount.insert(path, 1)
        else:
            # Path is already being watched, increment watch count
            self.mWatchCount[path] += 1

    def removePath(self, path):
        entry = self.mWatchCount.find(path)
        if (entry == self.mWatchCount.end()):
            if (QFile.exists(path)):
                qWarning("FileSystemWatcher: Path was never added:\n"+path)
            return

        # Decrement watch count
        entry -= 1
        self.mWatchCount[path] = entry
        if (entry == 0):
            self.mWatchCount.erase(path)
            self.mWatcher.removePath(path)

    def onFileChanged(self, path):
        # If the file was replaced, the watcher is automatically removed and needs
        # to be re-added to keep watching it for changes. This happens commonly
        # with applications that do atomic saving.
        if (not self.mWatcher.files().__contains__(path)):
            if (QFile.exists(path)):
                self.mWatcher.addPath(path)
        self.fileChanged.emit(path)

    def onDirectoryChanged(self, path):
        self.directoryChanged.emit(path)
开发者ID:theall,项目名称:Python-Tiled,代码行数:51,代码来源:filesystemwatcher.py

示例2: QtPropertyEditorDelegate

# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import erase [as 别名]
class QtPropertyEditorDelegate(QItemDelegate):
    def __init__(self, parent=None):
        super(QtPropertyEditorDelegate, self).__init__(parent)

        self.m_editorPrivate = 0
        self.m_editedItem = 0
        self.m_editedWidget = 0
        self.m_disablePainting = False
        self.m_propertyToEditor = QMap()
        self.m_editorToProperty = QMap()

    def setEditorPrivate(self,editorPrivate):
        self.m_editorPrivate = editorPrivate

    def setModelData(self,pt_widget,pt_QAbstractItemModel, modelIndex):
        pass

    def setEditorData(self, pt_widget, modelIndex):
        pass

    def editedItem(self):
        return self.m_editedItem

    def indentation(self,index):
        if (not self.m_editorPrivate):
            return 0

        item = self.m_editorPrivate.indexToItem(index)
        indent = 0
        while (item.parent()):
            item = item.parent()
            indent += 1
        if (self.m_editorPrivate.treeWidget().rootIsDecorated()):
            indent += 1
        return indent * self.m_editorPrivate.treeWidget().indentation()

    def slotEditorDestroyed(self, object):
        return
        if object:
            hv = object.property('hash_value')
            for x in self.m_editorToProperty:
                if x[0].hash_value==hv:
                    self.m_propertyToEditor.remove(x)
                    self.m_editorToProperty.erase(x)
                    break
            if (self.m_editedWidget.hash_value == hv):
                self.m_editedWidget = 0
                self.m_editedItem = 0

    def destroyEditor(self, editor, index):
        if editor:
            hv = editor.property('hash_value')
            for x in self.m_editorToProperty:
                if x[0].hash_value==hv:
                    self.m_propertyToEditor.remove(x)
                    self.m_editorToProperty.erase(x)
                    break
            if (self.m_editedWidget.hash_value == hv):
                self.m_editedWidget = 0
                self.m_editedItem = 0
            #editor.deleteLater()

    def closeEditor(self, property):
        pass

    def createEditor(self, parent,pt_QStyleOptionViewItem, index):
        if index.column() == 1 and self.m_editorPrivate:
            property = self.m_editorPrivate.indexToProperty(index)
            item = self.m_editorPrivate.indexToItem(index)
            if property and item and (item.flags() & Qt.ItemIsEnabled):
                editor = self.m_editorPrivate.createEditor(property, parent)
                if editor:
                    hash = editor.__hash__()
                    editor.setProperty('hash_value',hash)
                    editor.hash_value = hash
                    editor.setAutoFillBackground(True)
                    editor.installEventFilter(self)
                    editor.destroyed.connect(self.slotEditorDestroyed)
                    self.m_propertyToEditor[property] = editor
                    self.m_editorToProperty[editor] = property
                    self.m_editedItem = item
                    self.m_editedWidget = editor

                    return editor
        return

    def updateEditorGeometry(self, editor, option, index):
        editor.setGeometry(option.rect.adjusted(0, 0, 0, -1))

    def paint(self, painter, option, index):
        hasValue = True
        if (self.m_editorPrivate):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property):
                hasValue = property.hasValue()

        opt = QStyleOptionViewItem(option)
        if ((self.m_editorPrivate and index.column() == 0) or not hasValue):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property and property.isModified()):
#.........这里部分代码省略.........
开发者ID:theall,项目名称:QtPropertyBrowserV2.6-for-pyqt5,代码行数:103,代码来源:qttreepropertybrowser.py

示例3: RangeSet

# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import erase [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()

#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:rangeset.py

示例4: MapScene

# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import erase [as 别名]

#.........这里部分代码省略.........

    ##
    # Inserts map object items for the given objects.
    ##
    def objectsInserted(self, objectGroup, first, last):
        ogItem = None
        # Find the object group item for the object group
        for item in self.mLayerItems:
            ogi = item
            if type(ogi)==ObjectGroupItem:
                if (ogi.objectGroup() == objectGroup):
                    ogItem = ogi
                    break

        drawOrder = objectGroup.drawOrder()
        for i in range(first, last+1):
            object = objectGroup.objectAt(i)
            item = MapObjectItem(object, self.mMapDocument, ogItem)
            if (drawOrder == ObjectGroup.DrawOrder.TopDownOrder):
                item.setZValue(item.y())
            else:
                item.setZValue(i)
            self.mObjectItems.insert(object, item)

    ##
    # Removes the map object items related to the given objects.
    ##
    def objectsRemoved(self, objects):
        for o in objects:
            i = self.mObjectItems.find(o)
            self.mSelectedObjectItems.remove(i)
            # python would not force delete QGraphicsItem
            self.removeItem(i)
            self.mObjectItems.erase(o)

    ##
    # Updates the map object items related to the given objects.
    ##
    def objectsChanged(self, objects):
        for object in objects:
            item = self.itemForObject(object)
            item.syncWithMapObject()

    ##
    # Updates the Z value of the objects when appropriate.
    ##
    def objectsIndexChanged(self, objectGroup, first, last):
        if (objectGroup.drawOrder() != ObjectGroup.DrawOrder.IndexOrder):
            return
        for i in range(first, last+1):
            item = self.itemForObject(objectGroup.objectAt(i))
            item.setZValue(i)

    def updateSelectedObjectItems(self):
        objects = self.mMapDocument.selectedObjects()
        items = QSet()
        for object in objects:
            item = self.itemForObject(object)
            if item:
                items.insert(item)

        self.mSelectedObjectItems = items
        self.selectedObjectItemsChanged.emit()

    def syncAllObjectItems(self):
        for item in self.mObjectItems:
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:mapscene.py


注:本文中的pyqtcore.QMap.erase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。