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


Python QList.at方法代码示例

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


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

示例1: intToEnum

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [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)
开发者ID:theall,项目名称:QtPropertyBrowserV2.6-for-pyqt5,代码行数:14,代码来源:objectcontroller.py

示例2: intToFlag

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [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
开发者ID:theall,项目名称:QtPropertyBrowserV2.6-for-pyqt5,代码行数:23,代码来源:objectcontroller.py

示例3: CommandDataModel

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [as 别名]
class CommandDataModel(QAbstractTableModel):
    NameColumn, CommandColumn, EnabledColumn = range(3)

    ##
    # Constructs the object and parses the users settings to allow easy
    # programmatic access to the command list.
    ##
    def __init__(self, parent):
        super().__init__(parent)
        
        self.mSettings = QSettings()
        self.mSaveBeforeExecute = False
        self.mCommands = QList()
        
        # Load saveBeforeExecute option
        s = self.mSettings.value("saveBeforeExecute", True)
        self.mSaveBeforeExecute = bool(s)
        # Load command list
        variant = self.mSettings.value("commandList")
        commands = variant
        if commands is None:
            commands = []
        for commandVariant in commands:
            self.mCommands.append(Command.fromQVariant(commandVariant))
        # Add default commands the first time the app has booted up.
        # This is useful on it's own and helps demonstrate how to use the commands.
        addPrefStr = "addedDefaultCommands"
        addedCommands = self.mSettings.value(addPrefStr, False)
        if (not addedCommands):
            # Disable default commands by default so user gets an informative
            # warning when clicking the command button for the first time
            command = Command(False)
            if sys.platform == 'linux':
                command.command = "gedit %mapfile"
            elif sys.platform == 'darwin':
                command.command = "open -t %mapfile"
            if (not command.command.isEmpty()):
                command.name = self.tr("Open in text editor")
                self.mCommands.push_back(command)

            self.commit()
            self.mSettings.setValue(addPrefStr, True)
            
    ##
    # Saves the data to the users preferences.
    ##
    def commit(self):
        # Save saveBeforeExecute option
        self.mSettings.setValue("saveBeforeExecute", self.mSaveBeforeExecute)
        # Save command list
        commands = QList()
        for command in self.mCommands:
            commands.append(command.toQVariant())
        self.mSettings.setValue("commandList", commands)

    ##
    # Returns whether saving before executing commands is enabled.
    ##
    def saveBeforeExecute(self):
        return self.mSaveBeforeExecute

    ##
    # Enables or disables saving before executing commands.
    ##
    def setSaveBeforeExecute(self, enabled):
        self.mSaveBeforeExecute = enabled

    ##
    # Returns the first enabled command in the list, or an empty
    # disabled command if there are no enabled commands.
    ##
    def firstEnabledCommand(self):
        for command in self.mCommands:
            if (command.isEnabled):
                return command
        return Command(False)

    ##
    # Returns a list of all the commands.
    ##
    def allCommands(self):
        return QList(self.mCommands)

    ##
    # Remove the given row or rows from the model.
    ##
    def removeRows(self, *args):
        l = len(args)
        if l>1 and l<4:
            row = args[0]
            count = args[1]
            if l==2:
                parent = QModelIndex()
            elif l==3:
                parent = args[2]

            if (row < 0 or row + count > self.mCommands.size()):
                return False
            self.beginRemoveRows(parent, row, row + count)
            self.mCommands.erase(self.mCommands.begin() + row, self.mCommands.begin() + row + count)
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:commanddatamodel.py

示例4: Tileset

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [as 别名]
class Tileset(Object):
    ##
    # Constructor.
    #
    # @param name        the name of the tileset
    # @param tileWidth   the width of the tiles in the tileset
    # @param tileHeight  the height of the tiles in the tileset
    # @param tileSpacing the spacing between the tiles in the tileset image
    # @param margin      the margin around the tiles in the tileset image
    ##
    def __init__(self, name, tileWidth, tileHeight, tileSpacing = 0, margin = 0):
        super().__init__(Object.TilesetType)

        self.mName = name
        self.mTileWidth = tileWidth
        self.mTileHeight = tileHeight
        self.mTileSpacing = tileSpacing
        self.mMargin = margin
        self.mImageWidth = 0
        self.mImageHeight = 0
        self.mColumnCount = 0
        self.mTerrainDistancesDirty = False

        self.mTileOffset = QPoint()
        self.mFileName = QString()
        self.mTiles = QList()
        self.mTransparentColor = QColor()
        self.mImageSource = QString()
        self.mTerrainTypes = QList()
        self.mWeakPointer = None

    ##
    # Destructor.
    ##
    def __del__(self):
        self.mTiles.clear()
        self.mTerrainTypes.clear()

    def create(name, tileWidth, tileHeight, tileSpacing = 0, margin = 0):
        tileset = Tileset(name, tileWidth, tileHeight, tileSpacing, margin)
        tileset.mWeakPointer = tileset
        return tileset
    
    def __iter__(self):
        return self.mTiles.__iter__()
        
    ##
    # Returns the name of this tileset.
    ##
    def name(self):
        return self.mName

    ##
    # Sets the name of this tileset.
    ##
    def setName(self, name):
        self.mName = name

    ##
    # Returns the file name of this tileset. When the tileset isn't an
    # external tileset, the file name is empty.
    ##
    def fileName(self):
        return self.mFileName

    ##
    # Sets the filename of this tileset.
    ##
    def setFileName(self, fileName):
        self.mFileName = fileName

    ##
    # Returns whether this tileset is external.
    ##
    def isExternal(self):
        return self.mFileName!=''

    ##
    # Returns the maximum width of the tiles in this tileset.
    ##
    def tileWidth(self):
        return self.mTileWidth

    ##
    # Returns the maximum height of the tiles in this tileset.
    ##
    def tileHeight(self):
        return self.mTileHeight

    ##
    # Returns the maximum size of the tiles in this tileset.
    ##
    def tileSize(self):
        return QSize(self.mTileWidth, self.mTileHeight)

    ##
    # Returns the spacing between the tiles in the tileset image.
    ##
    def tileSpacing(self):
        return self.mTileSpacing
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:tileset.py

示例5: Map

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [as 别名]
class Map(Object):

    ##
    # The orientation of the map determines how it should be rendered. An
    # Orthogonal map is using rectangular tiles that are aligned on a
    # straight grid. An Isometric map uses diamond shaped tiles that are
    # aligned on an isometric projected grid. A Hexagonal map uses hexagon
    # shaped tiles that fit into each other by shifting every other row.
    ##
    class Orientation(Enum):
        Unknown, Orthogonal, Isometric, Staggered, Hexagonal = range(5)

    ##
    # The different formats in which the tile layer data can be stored.
    ##
    class LayerDataFormat(Enum):
        XML        = 0
        Base64     = 1
        Base64Gzip = 2
        Base64Zlib = 3
        CSV        = 4

    ##
    # The order in which tiles are rendered on screen.
    ##
    class RenderOrder(Enum):
        RightDown  = 0
        RightUp    = 1
        LeftDown   = 2
        LeftUp     = 3

    ##
    # Which axis is staggered. Only used by the isometric staggered and
    # hexagonal map renderers.
    ##
    class StaggerAxis(Enum):
        StaggerX, StaggerY = range(2)

    ##
    # When staggering, specifies whether the odd or the even rows/columns are
    # shifted half a tile right/down. Only used by the isometric staggered and
    # hexagonal map renderers.
    ##
    class StaggerIndex(Enum):
        StaggerOdd  = 0
        StaggerEven = 1

    def __init__(self, *args):
        self.mOrientation = 0
        self.mRenderOrder = 0
        self.mWidth = 0
        self.mHeight = 0
        self.mTileWidth = 0
        self.mTileHeight = 0
        self.mHexSideLength = 0
        self.mStaggerAxis = 0
        self.mStaggerIndex = 0
        self.mBackgroundColor = QColor()
        self.mDrawMargins = QMargins()
        self.mLayers = QList()
        self.mTilesets = QVector()
        self.mLayerDataFormat = None
        self.mNextObjectId = 0

        l = len(args)
        if l==1:
            ##
            # Copy constructor. Makes sure that a deep-copy of the layers is created.
            ##
            map = args[0]
            super().__init__(map)

            self.mLayers = QList()
            self.mOrientation = map.mOrientation
            self.mRenderOrder = map.mRenderOrder
            self.mWidth = map.mWidth
            self.mHeight = map.mHeight
            self.mTileWidth = map.mTileWidth
            self.mTileHeight = map.mTileHeight
            self.mHexSideLength = map.mHexSideLength
            self.mStaggerAxis = map.mStaggerAxis
            self.mStaggerIndex = map.mStaggerIndex
            self.mBackgroundColor = map.mBackgroundColor
            self.mDrawMargins = map.mDrawMargins
            self.mTilesets = map.mTilesets
            self.mLayerDataFormat = map.mLayerDataFormat
            self.mNextObjectId = 1
            for layer in map.mLayers:
                clone = layer.clone()
                clone.setMap(self)
                self.mLayers.append(clone)
        elif l==5:
            ##
            # Constructor, taking map orientation, size and tile size as parameters.
            ##
            orientation, width, height, tileWidth, tileHeight = args
            super().__init__(Object.MapType)

            self.mLayers = QList()
            self.mTilesets = QList()
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:map.py

示例6: ObjectGroup

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [as 别名]
class ObjectGroup(Layer):
    ##
    # Objects within an object group can either be drawn top down (sorted
    # by their y-coordinate) or by index (manual stacking order).
    #
    # The default is top down.
    ##
    class DrawOrder():
        UnknownOrder = -1
        TopDownOrder = 1
        IndexOrder = 2

    ##
    # Default constructor.
    ##
    def __init__(self, *args):
        self.mObjects = QList()
        self.mColor = QColor()

        l = len(args)
        if l==0:
            super().__init__(Layer.ObjectGroupType, QString(), 0, 0, 0, 0)
        elif l==5:
            ##
            # Constructor with some parameters.
            ##
            name, x, y, width, height = args

            super().__init__(Layer.ObjectGroupType, name, x, y, width, height)
        else:
            pass
        self.mDrawOrder = ObjectGroup.DrawOrder.IndexOrder

    ##
    # Destructor.
    ##
    def __del__(self):
        self.mObjects.clear()

    ##
    # Returns a pointer to the list of objects in this object group.
    ##
    def objects(self):
        return QList(self.mObjects)

    ##
    # Returns the number of objects in this object group.
    ##
    def objectCount(self):
        return self.mObjects.size()

    ##
    # Returns the object at the specified index.
    ##
    def objectAt(self, index):
        return self.mObjects.at(index)

    ##
    # Adds an object to this object group.
    ##
    def addObject(self, object):
        self.mObjects.append(object)
        object.setObjectGroup(self)
        if (self.mMap and object.id() == 0):
            object.setId(self.mMap.takeNextObjectId())

    ##
    # Inserts an object at the specified index. This is only used for undoing
    # the removal of an object at the moment, to make sure not to change the
    # saved order of the objects.
    ##
    def insertObject(self, index, object):
        self.mObjects.insert(index, object)
        object.setObjectGroup(self)
        if (self.mMap and object.id() == 0):
            object.setId(self.mMap.takeNextObjectId())

    ##
    # Removes an object from this object group. Ownership of the object is
    # transferred to the caller.
    #
    # @return the index at which the specified object was removed
    ##
    def removeObject(self, object):
        index = self.mObjects.indexOf(object)
        self.mObjects.removeAt(index)
        object.setObjectGroup(None)
        return index

    ##
    # Removes the object at the given index. Ownership of the object is
    # transferred to the caller.
    #
    # This is faster than removeObject when you've already got the index.
    #
    # @param index the index at which to remove an object
    ##
    def removeObjectAt(self, index):
        object = self.mObjects.takeAt(index)
        object.setObjectGroup(None)
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:objectgroup.py

示例7: MyController

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [as 别名]
class MyController(QDialog):
    def __init__(self, parent=None):
        super(MyController, self).__init__(parent)

        self.theClassNames = QList()
        self.theClassCombo = QComboBox(self)
        self.theControlledObject = None

        button = QToolButton(self)
        self.theController = ObjectController(self)
        buttonBox = QDialogButtonBox(self)

        button.clicked.connect(self.createAndControl)
        buttonBox.rejected.connect(self.reject)

        button.setText(self.tr("Create And Control"))
        buttonBox.setStandardButtons(QDialogButtonBox.Close)

        layout = QVBoxLayout(self)
        internalLayout = QHBoxLayout()
        internalLayout.addWidget(self.theClassCombo)
        internalLayout.addWidget(button)
        layout.addLayout(internalLayout)
        layout.addWidget(self.theController)
        layout.addWidget(buttonBox)

        self.theClassNames.append("QWidget")
        self.theClassNames.append("QPushButton")
        self.theClassNames.append("QDialogButtonBox")
        self.theClassNames.append("QTreeWidget")
        self.theClassNames.append("QCalendarWidget")
        self.theClassNames.append("QAction")
        self.theClassNames.append("QTimeLine")
        self.theClassNames.append("QTextDocument")

        self.theClassCombo.addItems(self.theClassNames)

    def __del__(self):
        if (self.theControlledObject):
            del self.theControlledObject

    def createAndControl(self):
        newObject = 0
        className = self.theClassNames.at(self.theClassCombo.currentIndex())
        if (className == "QWidget"):
            newObject = QWidget()
        elif (className == "QPushButton"):
            newObject = QPushButton()
        elif (className == "QDialogButtonBox"):
            newObject = QDialogButtonBox()
        elif (className == "QTreeWidget"):
            newObject = QTreeWidget()
        elif (className == "QCalendarWidget"):
            newObject = QCalendarWidget()
        elif (className == "QAction"):
            newObject = QAction(None)
        elif (className == "QTimeLine"):
            newObject = QTimeLine()
        elif (className == "QTextDocument"):
            newObject = QTextDocument()

        if (not newObject):
            return

        newWidget = newObject
        if hasattr(newWidget, 'geometry'):
            r = newWidget.geometry()
            r.setSize(newWidget.sizeHint())
            r.setWidth(max(r.width(), 150))
            r.setHeight(max(r.height(), 50))
            r.moveCenter(QApplication.desktop().geometry().center())
            newWidget.setGeometry(r)
            newWidget.setWindowTitle(self.tr("Controlled Object: %s"%className))
            newWidget.show()

        if (self.theControlledObject):
            del self.theControlledObject

        self.theControlledObject = newObject
        self.theController.setObject(self.theControlledObject)
开发者ID:theall,项目名称:QtPropertyBrowserV2.6-for-pyqt5,代码行数:82,代码来源:objectcontroller.py

示例8: MapObjectModel

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [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))
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:mapobjectmodel.py

示例9: TileStampModel

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [as 别名]
class TileStampModel(QAbstractItemModel):
    stampAdded = pyqtSignal(TileStamp)
    stampRenamed = pyqtSignal(TileStamp)
    stampChanged = pyqtSignal(TileStamp)
    stampRemoved = pyqtSignal(TileStamp)

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

        self.mStamps = QList()

    def index(self, *args):
        l = len(args)
        if l==1:
            stamp = args[0]
            i = self.mStamps.indexOf(stamp)
            if i == -1:
                return QModelIndex()
            else:
                return TileStampModel.index(i, 0)
        elif l==2 or l==3:
            if l==2:
                row, column = args
            elif l==3:
                row, column, parent = args
                
            if (not self.hasIndex(row, column, parent)):
                return QModelIndex()
            if (not parent.isValid()):
                return self.createIndex(row, column)
            elif (self.isStamp(parent)):
                return self.createIndex(row, column, parent.row() + 1)
            return QModelIndex()
    
    def parent(self, index):
        id = index.internalId()
        if id:
            return self.createIndex(id - 1, 0)
        return QModelIndex()
    
    def rowCount(self, parent = QModelIndex()):
        if (not parent.isValid()):
            return self.mStamps.size()
        elif (self.isStamp(parent)):
            stamp = self.mStamps.at(parent.row())
            count = stamp.variations().size()
            # it does not make much sense to expand single variations
            if count==1:
                return 0
            else:
                return count        
        return 0
    
    def columnCount(self, parent = QModelIndex()):
        return 2 # stamp | probability
    
    def headerData(self, section, orientation, role = Qt.DisplayRole):
        if (role == Qt.DisplayRole and orientation == Qt.Horizontal):
            x = section
            if x==0:
                return self.tr("Stamp")
            elif x==1:
                return self.tr("Probability")

        return QVariant()
    
    def setData(self, index, value, role = Qt.EditRole):
        if self.isStamp(index):
            stamp = self.mStamps[index.row()]
            if (index.column() == 0):      # stamp name
                x = role
                if x==Qt.EditRole:
                    stamp.setName(value.toString())
                    self.dataChanged.emit(index, index)
                    self.stampRenamed.emit(stamp)
                    self.stampChanged.emit(stamp)
                    return True
                else:
                    pass
        elif (index.column() == 1):   # variation probability
            parent = index.parent()
            if self.isStamp(parent):
                stamp = self.mStamps[parent.row()]
                stamp.setProbability(index.row(), value.toReal())
                self.dataChanged.emit(index, index)
                probabilitySumIndex = TileStampModel.index(parent.row(), 1)
                self.dataChanged.emit(probabilitySumIndex, probabilitySumIndex)
                self.stampChanged.emit(stamp)
                return True

        return False
    
    def data(self, index, role = Qt.DisplayRole):
        if (self.isStamp(index)):
            stamp = self.mStamps.at(index.row())
            if (index.column() == 0):          # preview and name
                x = role
                if x==Qt.DisplayRole or x==Qt.EditRole:
                    return stamp.name()
                elif x==Qt.DecorationRole:
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:tilestampmodel.py

示例10: AutoMapper

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [as 别名]
class AutoMapper(QObject):
    ##
    # Constructs an AutoMapper.
    # All data structures, which only rely on the rules map are setup
    # here.
    #
    # @param workingDocument: the map to work on.
    # @param rules: The rule map which should be used for automapping
    # @param rulePath: The filepath to the rule map.
    ##
    def __init__(self, workingDocument, rules, rulePath):
        ##
        # where to work in
        ##
        self.mMapDocument = workingDocument

        ##
        # the same as mMapDocument.map()
        ##
        self.mMapWork = None
        if workingDocument:
            self.mMapWork = workingDocument.map()

        ##
        # map containing the rules, usually different than mMapWork
        ##
        self.mMapRules = rules

        ##
        # This contains all added tilesets as pointers.
        # if rules use Tilesets which are not in the mMapWork they are added.
        # keep track of them, because we need to delete them afterwards,
        # when they still are unused
        # they will be added while setupTilesets().
        ##
        self.mAddedTilesets = QVector()

        ##
        # description see: mAddedTilesets, just described by Strings
        ##
        self.mAddedTileLayers = QList()

        ##
        # Points to the tilelayer, which defines the inputregions.
        ##
        self.mLayerInputRegions = None

        ##
        # Points to the tilelayer, which defines the outputregions.
        ##
        self.mLayerOutputRegions = None

        ##
        # Contains all tilelayer pointers, which names begin with input*
        # It is sorted by index and name
        ##
        self.mInputRules = InputLayers()

        ##
        # List of Regions in mMapRules to know where the input rules are
        ##
        self.mRulesInput = QList()

        ##
        # List of regions in mMapRules to know where the output of a
        # rule is.
        # mRulesOutput[i] is the output of that rule,
        # which has the input at mRulesInput[i], meaning that mRulesInput
        # and mRulesOutput must match with the indexes.
        ##
        self.mRulesOutput = QList()

        ##
        # The inner set with layers to indexes is needed for translating
        # tile layers from mMapRules to mMapWork.
        #
        # The key is the pointer to the layer in the rulemap. The
        # pointer to the layer within the working map is not hardwired, but the
        # position in the layerlist, where it was found the last time.
        # This loosely bound pointer ensures we will get the right layer, since we
        # need to check before anyway, and it is still fast.
        #
        # The list is used to hold different translation tables
        # => one of the tables is chosen by chance, so randomness is available
        ##
        self.mLayerList = QList()
        ##
        # store the name of the processed rules file, to have detailed
        # error messages available
        ##
        self.mRulePath = rulePath

        ##
        # determines if all tiles in all touched layers should be deleted first.
        ##
        self.mDeleteTiles = False

        ##
        # This variable determines, how many overlapping tiles should be used.
        # The bigger the more area is remapped at an automapping operation.
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:automapper.py

示例11: applyRule

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [as 别名]
    def applyRule(self, ruleIndex, where):
        ret = QRect()
        if (self.mLayerList.isEmpty()):
            return ret
        ruleInput = self.mRulesInput.at(ruleIndex)
        ruleOutput = self.mRulesOutput.at(ruleIndex)
        rbr = ruleInput.boundingRect()
        # Since the rule itself is translated, we need to adjust the borders of the
        # loops. Decrease the size at all sides by one: There must be at least one
        # tile overlap to the rule.
        minX = where.left() - rbr.left() - rbr.width() + 1
        minY = where.top() - rbr.top() - rbr.height() + 1
        maxX = where.right() - rbr.left() + rbr.width() - 1
        maxY = where.bottom() - rbr.top() + rbr.height() - 1
        # In this list of regions it is stored which parts or the map have already
        # been altered by exactly this rule. We store all the altered parts to
        # make sure there are no overlaps of the same rule applied to
        # (neighbouring) places
        appliedRegions = QList()
        if (self.mNoOverlappingRules):
            for i in range(self.mMapWork.layerCount()):
                appliedRegions.append(QRegion())
        for y in range(minY, maxY+1):
            for x in range(minX, maxX+1):
                anymatch = False
                for index in self.mInputRules.indexes:
                    ii = self.mInputRules[index]
                    allLayerNamesMatch = True
                    for name in ii.names:
                        i = self.mMapWork.indexOfLayer(name, Layer.TileLayerType)
                        if (i == -1):
                            allLayerNamesMatch = False
                        else:
                            setLayer = self.mMapWork.layerAt(i).asTileLayer()
                            allLayerNamesMatch &= compareLayerTo(setLayer,
                                                                 ii[name].listYes,
                                                                 ii[name].listNo,
                                                                 ruleInput,
                                                                 QPoint(x, y))

                    if (allLayerNamesMatch):
                        anymatch = True
                        break

                if (anymatch):
                    r = 0
                    # choose by chance which group of rule_layers should be used:
                    if (self.mLayerList.size() > 1):
                        r = qrand() % self.mLayerList.size()
                    if (not self.mNoOverlappingRules):
                        self.copyMapRegion(ruleOutput, QPoint(x, y), self.mLayerList.at(r))
                        ret = ret.united(rbr.translated(QPoint(x, y)))
                        continue

                    missmatch = False
                    translationTable = self.mLayerList.at(r)
                    layers = translationTable.keys()
                    # check if there are no overlaps within this rule.
                    ruleRegionInLayer = QVector()
                    for i in range(layers.size()):
                        layer = layers.at(i)
                        appliedPlace = QRegion()
                        tileLayer = layer.asTileLayer()
                        if (tileLayer):
                            appliedPlace = tileLayer.region()
                        else:
                            appliedPlace = tileRegionOfObjectGroup(layer.asObjectGroup())
                        ruleRegionInLayer.append(appliedPlace.intersected(ruleOutput))
                        if (appliedRegions.at(i).intersects(
                                    ruleRegionInLayer[i].translated(x, y))):
                            missmatch = True
                            break

                    if (missmatch):
                        continue
                    self.copyMapRegion(ruleOutput, QPoint(x, y), self.mLayerList.at(r))
                    ret = ret.united(rbr.translated(QPoint(x, y)))
                    for i in range(translationTable.size()):
                        appliedRegions[i] += ruleRegionInLayer[i].translated(x, y)

        return ret
开发者ID:theall,项目名称:Python-Tiled,代码行数:83,代码来源:automapper.py

示例12: DocumentManager

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import at [as 别名]
class DocumentManager(QObject):
    ##
    # Emitted when the current displayed map document changed.
    ##
    currentDocumentChanged = pyqtSignal(list)
    ##
    # Emitted when the user requested the document at \a index to be closed.
    ##
    documentCloseRequested = pyqtSignal(int)
    ##
    # Emitted when a document is about to be closed.
    ##
    documentAboutToClose = pyqtSignal(MapDocument)
    ##
    # Emitted when an error occurred while reloading the map.
    ##
    reloadError = pyqtSignal(str)

    mInstance = None

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

        self.mDocuments = QList()
        self.mTabWidget = MovableTabWidget()
        self.mUndoGroup = QUndoGroup(self)
        self.mSelectedTool = None
        self.mViewWithTool = None
        self.mFileSystemWatcher = FileSystemWatcher(self)

        self.mTabWidget.setDocumentMode(True)
        self.mTabWidget.setTabsClosable(True)
        self.mTabWidget.currentChanged.connect(self.currentIndexChanged)
        self.mTabWidget.tabCloseRequested.connect(self.documentCloseRequested)
        self.mTabWidget.tabMoved.connect(self.documentTabMoved)
        self.mFileSystemWatcher.fileChanged.connect(self.fileChanged)

    def __del__(self):
        # All documents should be closed gracefully beforehand
        del self.mTabWidget

    def instance():
        if not DocumentManager.mInstance:
            DocumentManager.mInstance = DocumentManager()
        return DocumentManager.mInstance

    def deleteInstance():
        del DocumentManager.mInstance
        DocumentManager.mInstance = None

    ##
    # Returns the document manager widget. It contains the different map views
    # and a tab bar to switch between them.
    ##
    def widget(self):
        return self.mTabWidget

    ##
    # Returns the undo group that combines the undo stacks of all opened map
    # documents.
    #
    # @see MapDocument.undoStack()
    ##
    def undoGroup(self):
        return self.mUndoGroup

    ##
    # Returns the current map document, or 0 when there is none.
    ##
    def currentDocument(self):
        index = self.mTabWidget.currentIndex()
        if (index == -1):
            return None
        return self.mDocuments.at(index)

    ##
    # Returns the map view of the current document, or 0 when there is none.
    ##
    def currentMapView(self):
        widget = self.mTabWidget.currentWidget()
        if widget:
            return widget.mapView()
        return None

    ##
    # Returns the map scene of the current document, or 0 when there is none.
    ##
    def currentMapScene(self):
        mapView = self.currentMapView()
        if mapView:
            return mapView.mapScene()
        return None

    ##
    # Returns the map view that displays the given document, or 0 when there
    # is none.
    ##
    def viewForDocument(self, mapDocument):
        index = self.mDocuments.indexOf(mapDocument)
        if (index == -1):
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:documentmanager.py


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