def __init__(self, *args): super().__init__() self.mChanges = QMap() self.mMapDocument = None self.mTileset = None self.mMergeable = False l = len(args) if l==0: self.initText() elif l==2: ## # Changes the terrain of \a tile. ## mapDocument, changes = args self.mMapDocument = mapDocument self.mTileset = changes.begin().key().tileset() self.mMergeable = True self.initText() elif l==3: ## # Applies the given terrain \a changes. ## mapDocument = args[0] tile = args[1] terrain = args[2] self.mMapDocument = mapDocument self.mTileset = tile.tileset() self.mMergeable = True self.initText() self.mChanges.insert(tile, ChangeTileTerrain.Change(tile.terrain(), terrain))
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)
class FormatHelper(): def __init__(self, capabilities, initialFilter): self.mFilter = initialFilter self.mFormats = QList() self.mFormatByNameFilter = QMap() def t(self, format): if (format.hasCapabilities(capabilities)): nameFilter = format.nameFilter() self.mFilter += ";;" self.mFilter += nameFilter self.mFormats.append(format) self.mFormatByNameFilter.insert(nameFilter, format) PluginManager.each(self, t) def filter(self): return self.mFilter def formats(self): return self.mFormats def formatByNameFilter(self, nameFilter): return self.mFormatByNameFilter.value(nameFilter)
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.variantManager = QtVariantPropertyManager(self) self.variantManager.valueChangedSignal.connect(self.valueChanged) variantFactory = QtVariantEditorFactory(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.variantManager, variantFactory) 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 __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 __init__(self, parent=None): self.mValues = QMap() self.mSuggestions = QMapList() self.mSuggestionsAttribute = QString() self.Data = VariantPropertyManager.Data() super().__init__(parent) self.mSuggestionsAttribute = "suggestions"
def __init__(self): self.q_ptr = None self.m_indexToItem = QMap() self.m_itemToIndex = QMap() self.m_widgetToItem = QMap() self.m_mainLayout = 0 self.m_children = QList() self.m_recreateQueue = QList()
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 __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 __init__(self, parent=None): super(DecoratedDoubleSpinBoxFactory, self).__init__(parent) self.propertyToData = QMap() # We delegate responsibilities for QtDoublePropertyManager, which is a base class # of DecoratedDoublePropertyManager to appropriate self.originalFactory = QtDoubleSpinBoxFactory(self) self.createdEditors = QMapList() self.editorToProperty = QMap()
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 __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 __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 __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()
def removeRow(self, layout, row): itemToPos = QMap() idx = 0 while (idx < len(layout)): r, c, rs, cs = layout.getItemPosition(idx) if (r > row): itemToPos[layout.takeAt(idx)] = QRect(r - 1, c, rs, cs) else: idx += 1 for k in itemToPos.keys(): r = itemToPos[k] layout.addItem(k, r.x(), r.y(), r.width(), r.height())
def __init__(self): self.q_ptr = None self.m_indexToItem = QMap() self.m_itemToIndex = QMap() self.m_indexToBackgroundColor = QMap() self.m_treeWidget = None self.m_headerVisible = True self.m_resizeMode = QtTreePropertyBrowser.Stretch self.m_delegate = None self.m_markPropertiesWithoutValue = False self.m_browserChangedBlocked = False self.m_expandIcon = QIcon()
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 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 insertRow(self, layout, row): itemToPos = QMap() idx = 0 while (idx < layout.count()): r, c, rs, cs = layout.getItemPosition(idx) if (r >= row): itemToPos[layout.takeAt(idx)] = QRect(r + 1, c, rs, cs) else: idx += 1 for it in itemToPos.keys(): r = itemToPos[it] layout.addItem(it, r.x(), r.y(), r.width(), r.height())
def selectTilesInStamp(self, stamp): if self.mEmittingStampCaptured: return processed = QSet() selections = QMap() for variation in stamp.variations(): tileLayer = variation.tileLayer() for cell in tileLayer: tile = cell.tile if tile: if (processed.contains(tile)): continue processed.insert(tile) # avoid spending time on duplicates tileset = tile.tileset() tilesetIndex = self.mTilesets.indexOf( tileset.sharedPointer()) if (tilesetIndex != -1): view = self.tilesetViewAt(tilesetIndex) if (not view.model()): # Lazily set up the model self.setupTilesetModel(view, tileset) model = view.tilesetModel() modelIndex = model.tileIndex(tile) selectionModel = view.selectionModel() _x = QItemSelection() _x.select(modelIndex, modelIndex) selections[selectionModel] = _x if (not selections.isEmpty()): self.mSynchronizingSelection = True # Mark captured tiles as selected for i in selections: selectionModel = i[0] selection = i[1] selectionModel.select(selection, QItemSelectionModel.SelectCurrent) # Show/edit properties of all captured tiles self.mMapDocument.setSelectedTiles(processed.toList()) # Update the current tile (useful for animation and collision editors) first = selections.first() selectionModel = first[0] selection = first[1] currentIndex = QModelIndex(selection.first().topLeft()) if (selectionModel.currentIndex() != currentIndex): selectionModel.setCurrentIndex(currentIndex, QItemSelectionModel.NoUpdate) else: self.currentChanged(currentIndex) self.mSynchronizingSelection = False
def __init__(self, capabilities, initialFilter): self.mFilter = initialFilter self.mFormats = QList() self.mFormatByNameFilter = QMap() def t(self, format): if (format.hasCapabilities(capabilities)): nameFilter = format.nameFilter() self.mFilter += ";;" self.mFilter += nameFilter self.mFormats.append(format) self.mFormatByNameFilter.insert(nameFilter, format) PluginManager.each(self, t)
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 __init__(self, control, parent=None): super().__init__(parent) self.mControl = control self.mFileNames = QList() self.mFileVersions = QMap()
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 __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 constructAdditionalTable(self, props, propOrder): tableString = QString() unhandledProps = QMap(props) # Remove handled properties for i in range(0, propOrder.size()): unhandledProps.remove(propOrder[i]) # Construct the Lua string if (unhandledProps.size() > 0): tableString = "{" for i in unhandledProps: tableString = "%s%s=%s," % tableString, i[0], i[1] tableString = "%s}" % tableString return tableString
def constructAdditionalTable(self, props, propOrder): tableString = QString() unhandledProps = QMap(props) # Remove handled properties for i in range(0, propOrder.size()): unhandledProps.remove(propOrder[i]) # Construct the Lua string if (unhandledProps.size() > 0) : tableString = "{" for i in unhandledProps: tableString = "%s%s=%s,"%tableString, i[0], i[1] tableString = "%s}"%tableString return tableString
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 __init__(self): self.q_ptr = None self.WidgetItem = WidgetItem() self.m_indexToItem = QMap() self.m_itemToIndex = QMap() self.m_widgetToItem = QMap() self.m_buttonToItem = QMap() self.m_mainLayout = None self.m_children = QList() self.m_recreateQueue = QList()
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 __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)
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 __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)
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
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
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 __init__(self, capabilities, initialFilter): self.mFilter = initialFilter self.mFormats = QList() self.mFormatByNameFilter = QMap() def t(self, format): if (format.hasCapabilities(capabilities)): nameFilter = format.nameFilter() self.mFilter += ";;" self.mFilter += nameFilter self.mFormats.append(format) self.mFormatByNameFilter.insert(nameFilter, format) PluginManager.each(self, t)
class FormatHelper(): def __init__(self, capabilities, initialFilter): self.mFilter = initialFilter self.mFormats = QList() self.mFormatByNameFilter = QMap() def t(self, format): if (format.hasCapabilities(capabilities)): nameFilter = format.nameFilter() self.mFilter += ";;" self.mFilter += nameFilter self.mFormats.append(format) self.mFormatByNameFilter.insert(nameFilter, format) PluginManager.each(self, t) def filter(self): return self.mFilter def formats(self): return self.mFormats def formatByNameFilter(self, nameFilter): return self.mFormatByNameFilter.value(nameFilter)
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)
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)
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
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()
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 __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)
def __init__(self): self.q_ptr = None self.m_indexToItem = QMap() self.m_itemToIndex = QMap() self.m_indexToBackgroundColor = QMap() self.m_treeWidget = None self.m_headerVisible = True self.m_resizeMode = QtTreePropertyBrowser.Stretch self.m_delegate = None self.m_markPropertiesWithoutValue = False self.m_browserChangedBlocked = False self.m_expandIcon = QIcon()
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()
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)
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
class QtButtonPropertyBrowserPrivate(): def __init__(self): self.q_ptr = None self.WidgetItem = WidgetItem() self.m_indexToItem = QMap() self.m_itemToIndex = QMap() self.m_widgetToItem = QMap() self.m_buttonToItem = QMap() self.m_mainLayout = None self.m_children = QList() self.m_recreateQueue = QList() def createEditor(self, property, parent): return self.q_ptr.createEditor(property, parent) def createButton(self, parent=None): button = QToolButton(parent) button.setCheckable(True) button.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)) button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) button.setArrowType(Qt.DownArrow) button.setIconSize(QSize(3, 16)) ### #QIcon icon #icon.addPixmap(self.style().standardPixmap(QStyle.SP_ArrowDown), QIcon.Normal, QIcon.Off) #icon.addPixmap(self.style().standardPixmap(QStyle.SP_ArrowUp), QIcon.Normal, QIcon.On) #button.setIcon(icon) ### return button def gridRow(self, item): siblings = QList() if (item.parent): siblings = item.parent.children else: siblings = self.m_children row = 0 for sibling in siblings: if (sibling == item): return row row += self.gridSpan(sibling) return -1 def gridSpan(self, item): if (item.container and item.expanded): return 2 return 1 def init(self, parent): self.m_mainLayout = QGridLayout() parent.setLayout(self.m_mainLayout) item = QSpacerItem(0, 0, QSizePolicy.Fixed, QSizePolicy.Expanding) self.m_mainLayout.addItem(item, 0, 0) def slotEditorDestroyed(self): editor = self.q_ptr.sender() if (not editor): return if not self.m_widgetToItem.get(editor): return self.m_widgetToItem[editor].widget = 0 self.m_widgetToItem.remove(editor) def slotUpdate(self): for item in self.m_recreateQueue: parent = item.parent w = 0 l = 0 oldRow = self.gridRow(item) if (parent): w = parent.container l = parent.layout else: w = self.q_ptr l = self.m_mainLayout span = 1 if (not item.widget and not item.widgetLabel): span = 2 item.label = QLabel(w) item.label.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)) l.addWidget(item.label, oldRow, 0, 1, span) self.updateItem(item) self.m_recreateQueue.clear() def setExpanded(self, item, expanded): if (item.expanded == expanded): return if (not item.container): return item.expanded = expanded row = self.gridRow(item) parent = item.parent l = 0 if (parent): l = parent.layout else: l = self.m_mainLayout if (expanded): self.insertRow(l, row + 1) l.addWidget(item.container, row + 1, 0, 1, 2) item.container.show() else: l.removeWidget(item.container) item.container.hide() self.removeRow(l, row + 1) item.button.setChecked(expanded) if expanded: item.button.setArrowType(Qt.UpArrow) else: item.button.setArrowType(Qt.DownArrow) def slotToggled(self, checked): item = self.m_buttonToItem[self.q_ptr.sender()] if (not item): return self.setExpanded(item, checked) if (checked): self.q_ptr.expandedSignal.emit(self.m_itemToIndex[item]) else: self.q_ptr.collapsedSignal.emit(self.m_itemToIndex[item]) def updateLater(self): QTimer.singleShot(0, self.slotUpdate) def propertyInserted(self, index, afterIndex): afterItem = self.m_indexToItem[afterIndex] parentItem = self.m_indexToItem.value(index.parent()) newItem = WidgetItem() newItem.parent = parentItem layout = 0 parentWidget = 0 row = -1 if (not afterItem): row = 0 if (parentItem): parentItem.children.insert(0, newItem) else: self.m_children.insert(0, newItem) else: row = self.gridRow(afterItem) + self.gridSpan(afterItem) if (parentItem): parentItem.children.insert(parentItem.children.indexOf(afterItem) + 1, newItem) else: self.m_children.insert(self.m_children.indexOf(afterItem) + 1, newItem) if (not parentItem): layout = self.m_mainLayout parentWidget = self.q_ptr else: if (not parentItem.container): self.m_recreateQueue.removeAll(parentItem) grandParent = parentItem.parent l = 0 oldRow = self.gridRow(parentItem) if (grandParent): l = grandParent.layout else: l = self.m_mainLayout container = QFrame() container.setFrameShape(QFrame.Panel) container.setFrameShadow(QFrame.Raised) parentItem.container = container parentItem.button = self.createButton() self.m_buttonToItem[parentItem.button] = parentItem parentItem.button.toggled.connect(self.slotToggled) parentItem.layout = QGridLayout() container.setLayout(parentItem.layout) if (parentItem.label): l.removeWidget(parentItem.label) parentItem.label.close() parentItem.label = 0 span = 1 if (not parentItem.widget and not parentItem.widgetLabel): span = 2 l.addWidget(parentItem.button, oldRow, 0, 1, span) self.updateItem(parentItem) layout = parentItem.layout parentWidget = parentItem.container newItem.label = QLabel(parentWidget) newItem.label.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)) newItem.widget = self.createEditor(index.property(), parentWidget) if (newItem.widget): newItem.widget.destroyed.connect(self.slotEditorDestroyed) self.m_widgetToItem[newItem.widget] = newItem elif (index.property().hasValue()): newItem.widgetLabel = QLabel(parentWidget) newItem.widgetLabel.setSizePolicy(QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed)) self.insertRow(layout, row) span = 1 if (newItem.widget): layout.addWidget(newItem.widget, row, 1) elif (newItem.widgetLabel): layout.addWidget(newItem.widgetLabel, row, 1) else: span = 2 layout.addWidget(newItem.label, row, 0, span, 1) self.m_itemToIndex[newItem] = index self.m_indexToItem[index] = newItem self.updateItem(newItem) def propertyRemoved(self, index): item = self.m_indexToItem[index] self.m_indexToItem.remove(index) self.m_itemToIndex.remove(item) parentItem = item.parent row = self.gridRow(item) if (parentItem): parentItem.children.removeAt(parentItem.children.indexOf(item)) else: self.m_children.removeAt(self.m_children.indexOf(item)) colSpan = self.gridSpan(item) self.m_buttonToItem.remove(item.button) if (item.widget): item.widget.close() del item.widget if (item.label): item.label.close() del item.label if (item.widgetLabel): item.widgetLabel.close() del item.widgetLabel if (item.button): item.button.close() del item.button if (item.container): item.container.close() del item.container if (not parentItem): self.removeRow(self.m_mainLayout, row) if (colSpan > 1): self.removeRow(self.m_mainLayout, row) elif (len(parentItem.children) != 0): self.removeRow(parentItem.layout, row) if (colSpan > 1): self.removeRow(parentItem.layout, row) else: grandParent = parentItem.parent l = 0 if (grandParent): l = grandParent.layout else: l = self.m_mainLayout parentRow = self.gridRow(parentItem) parentSpan = self.gridSpan(parentItem) l.removeWidget(parentItem.button) l.removeWidget(parentItem.container) parentItem.button.close() del parentItem.button parentItem.container.close() del parentItem.container parentItem.button = 0 parentItem.container = 0 parentItem.layout = 0 if (not parentItem in self.m_recreateQueue): self.m_recreateQueue.append(parentItem) if (parentSpan > 1): self.removeRow(l, parentRow + 1) self.updateLater() self.m_recreateQueue.removeAll(item) del item def insertRow(self, layout, row): itemToPos = QMap() idx = 0 while (idx < len(layout)): r, c, rs, cs = layout.getItemPosition(idx) if (r >= row): itemToPos[layout.takeAt(idx)] = QRect(r + 1, c, rs, cs) else: idx += 1 for k in itemToPos.keys(): r = itemToPos[k] layout.addItem(k, r.x(), r.y(), r.width(), r.height()) def removeRow(self, layout, row): itemToPos = QMap() idx = 0 while (idx < len(layout)): r, c, rs, cs = layout.getItemPosition(idx) if (r > row): itemToPos[layout.takeAt(idx)] = QRect(r - 1, c, rs, cs) else: idx += 1 for k in itemToPos.keys(): r = itemToPos[k] layout.addItem(k, r.x(), r.y(), r.width(), r.height()) def propertyChanged(self, index): item = self.m_indexToItem[index] self.updateItem(item) def updateItem(self, item): property = self.m_itemToIndex[item].property() if (item.button): font = item.button.font() font.setUnderline(property.isModified()) item.button.setFont(font) item.button.setText(property.propertyName()) item.button.setToolTip(property.toolTip()) item.button.setStatusTip(property.statusTip()) item.button.setWhatsThis(property.whatsThis()) item.button.setEnabled(property.isEnabled()) if (item.label): font = item.label.font() font.setUnderline(property.isModified()) item.label.setFont(font) item.label.setText(property.propertyName()) item.label.setToolTip(property.toolTip()) item.label.setStatusTip(property.statusTip()) item.label.setWhatsThis(property.whatsThis()) item.label.setEnabled(property.isEnabled()) if (item.widgetLabel): font = item.widgetLabel.font() font.setUnderline(False) item.widgetLabel.setFont(font) item.widgetLabel.setText(property.valueText()) item.widgetLabel.setToolTip(property.valueText()) item.widgetLabel.setEnabled(property.isEnabled()) if (item.widget): font = item.widget.font() font.setUnderline(False) item.widget.setFont(font) item.widget.setEnabled(property.isEnabled()) item.widget.setToolTip(property.valueText())
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)) undo.endMacro() return True return False objectGroup = self.toObjectGroup(index) if objectGroup: x = role if x == Qt.CheckStateRole: layerModel = self.mMapDocument.layerModel() layerIndex = self.mMap.layers().indexOf(objectGroup) row = layerModel.layerIndexToRow(layerIndex) layerModel.setData(layerModel.index(row), value, role) return True elif x == Qt.EditRole: newName = value if (objectGroup.name() != newName): layerIndex = self.mMap.layers().indexOf(objectGroup) rename = RenameLayer(self.mMapDocument, layerIndex, newName) self.mMapDocument.undoStack().push(rename) return True return False return False def data(self, index, role=Qt.DisplayRole): mapObject = self.toMapObject(index) if mapObject: x = role if x == Qt.DisplayRole or x == Qt.EditRole: if index.column(): _x = mapObject.type() else: _x = mapObject.name() return _x elif x == Qt.DecorationRole: return QVariant() # no icon . maybe the color? elif x == Qt.CheckStateRole: if (index.column() > 0): return QVariant() if mapObject.isVisible(): _x = Qt.Checked else: _x = Qt.Unchecked return _x elif x == LayerModel.UserRoles.OpacityRole: return 1.0 else: return QVariant() objectGroup = self.toObjectGroup(index) if objectGroup: x = role if x == Qt.DisplayRole or x == Qt.EditRole: if index.column(): _x = QVariant() else: _x = objectGroup.name() return _x elif x == Qt.DecorationRole: if index.column(): _x = QVariant() else: _x = self.mObjectGroupIcon return _x elif x == Qt.CheckStateRole: if (index.column() > 0): return QVariant() if objectGroup.isVisible(): _x = Qt.Checked else: _x = Qt.Unchecked return _x elif x == LayerModel.UserRoles.OpacityRole: return objectGroup.opacity() else: return QVariant() return QVariant() def flags(self, index): rc = super().flags(index) if (index.column() == 0): rc |= Qt.ItemIsUserCheckable | Qt.ItemIsEditable elif (index.parent().isValid()): rc |= Qt.ItemIsEditable # MapObject type return rc 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])) def removeObject(self, og, o): objects = QList() objects.append(o) row = og.objects().indexOf(o) self.beginRemoveRows(self.index(og), row, row) og.removeObjectAt(row) self.mObjects.remove(o) self.endRemoveRows() self.objectsRemoved.emit(objects) return row def moveObjects(self, og, _from, to, count): parent = self.index(og) if (not self.beginMoveRows(parent, _from, _from + count - 1, parent, to)): return og.moveObjects(_from, to, count) self.endMoveRows() # ObjectGroup color changed # FIXME: layerChanged should let the scene know that objects need redrawing def emitObjectsChanged(self, objects): if objects.isEmpty(): return self.objectsChanged.emit(objects) def setObjectName(self, o, name): if o.name() == name: return o.setName(name) index = self.index(o) self.dataChanged.emit(index, index) self.objectsChanged.emit(QList([o])) def setObjectType(self, o, type): if o.type() == type: return o.setType(type) index = self.index(o, 1) self.dataChanged.emit(index, index) self.objectsChanged.emit(QList([o])) def setObjectPolygon(self, o, polygon): if o.polygon() == polygon: return o.setPolygon(polygon) self.objectsChanged.emit(QList([o])) def setObjectPosition(self, o, pos): if o.position() == pos: return o.setPosition(pos) self.objectsChanged.emit(QList([o])) def setObjectSize(self, o, size): if o.size() == size: return o.setSize(size) self.objectsChanged.emit(QList([o])) def setObjectRotation(self, o, rotation): if o.rotation() == rotation: return o.setRotation(rotation) self.objectsChanged.emit(QList([o])) def setObjectVisible(self, o, visible): if o.isVisible() == visible: return o.setVisible(visible) index = self.index(o) self.dataChanged.emit(index, index) self.objectsChanged.emit(QList([o])) def layerAdded(self, index): layer = self.mMap.layerAt(index) og = layer.asObjectGroup() if og: if (not self.mGroups.contains(og)): prev = None for index in range(index - 1, -1, -1): prev = self.mMap.layerAt(index).asObjectGroup() if prev: break if GROUPS_IN_DISPLAY_ORDER: if prev: _x = self.mObjectGroups.indexOf(prev) else: _x = self.mObjectGroups.count() index = _x else: if prev: index = self.mObjectGroups.indexOf(prev) + 1 else: index = 0 self.mObjectGroups.insert(index, og) row = self.mObjectGroups.indexOf(og) self.beginInsertRows(QModelIndex(), row, row) self.mGroups.insert(og, ObjectOrGroup(og)) for o in og.objects(): if (not self.mObjects.contains(o)): self.mObjects.insert(o, ObjectOrGroup(o)) self.endInsertRows() def layerChanged(self, index): layer = self.mMap.layerAt(index) og = layer.asObjectGroup() if og: index = self.index(og) self.dataChanged.emit(index, index) def layerAboutToBeRemoved(self, index): layer = self.mMap.layerAt(index) og = layer.asObjectGroup() if og: row = self.mObjectGroups.indexOf(og) self.beginRemoveRows(QModelIndex(), row, row) self.mObjectGroups.removeAt(row) self.mGroups.remove(og) for o in og.objects(): self.mObjects.remove(og) self.endRemoveRows()
def __init__(self, parent = None): super().__init__(parent) self.mCreatedEditors = QMapList() self.mEditorToProperty = QMap()
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
def __init__(self, parent=None): super().__init__(parent) self.propertyToData = QMap()