本文整理汇总了Python中pyqtcore.QList.size方法的典型用法代码示例。如果您正苦于以下问题:Python QList.size方法的具体用法?Python QList.size怎么用?Python QList.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QList
的用法示例。
在下文中一共展示了QList.size方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setupRuleList
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import size [as 别名]
def setupRuleList(self):
combinedRegions = coherentRegions(
self.mLayerInputRegions.region() +
self.mLayerOutputRegions.region())
combinedRegions = QList(sorted(combinedRegions, key=lambda x:x.y(), reverse=True))
rulesInput = coherentRegions(
self.mLayerInputRegions.region())
rulesOutput = coherentRegions(
self.mLayerOutputRegions.region())
for i in range(combinedRegions.size()):
self.mRulesInput.append(QRegion())
self.mRulesOutput.append(QRegion())
for reg in rulesInput:
for i in range(combinedRegions.size()):
if (reg.intersects(combinedRegions[i])):
self.mRulesInput[i] += reg
break
for reg in rulesOutput:
for i in range(combinedRegions.size()):
if (reg.intersects(combinedRegions[i])):
self.mRulesOutput[i] += reg
break
for i in range(self.mRulesInput.size()):
checkCoherent = self.mRulesInput.at(i).united(self.mRulesOutput.at(i))
coherentRegions(checkCoherent).length() == 1
return True
示例2: CommandDataModel
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import size [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)
#.........这里部分代码省略.........
示例3: Tileset
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import size [as 别名]
#.........这里部分代码省略.........
return self.mTileSpacing
##
# Returns the margin around the tiles in the tileset image.
##
def margin(self):
return self.mMargin
##
# Returns the offset that is applied when drawing the tiles in this
# tileset.
##
def tileOffset(self):
return self.mTileOffset
##
# @see tileOffset
##
def setTileOffset(self, offset):
self.mTileOffset = offset
##
# Returns a const reference to the list of tiles in this tileset.
##
def tiles(self):
return QList(self.mTiles)
##
# Returns the tile for the given tile ID.
# The tile ID is local to this tileset, which means the IDs are in range
# [0, tileCount() - 1].
##
def tileAt(self, id):
if id < self.mTiles.size():
return self.mTiles.at(id)
return None
##
# Returns the number of tiles in this tileset.
##
def tileCount(self):
return self.mTiles.size()
##
# Returns the number of tile columns in the tileset image.
##
def columnCount(self):
return self.mColumnCount
##
# Returns the width of the tileset image.
##
def imageWidth(self):
return self.mImageWidth
##
# Returns the height of the tileset image.
##
def imageHeight(self):
return self.mImageHeight
##
# Returns the transparent color, or an invalid color if no transparent
# color is used.
##
def transparentColor(self):
示例4: Map
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import size [as 别名]
#.........这里部分代码省略.........
##
# Sets the render order of the map.
##
def setRenderOrder(self, renderOrder):
self.mRenderOrder = renderOrder
##
# Returns the width of this map in tiles.
##
def width(self):
return self.mWidth
##
# Sets the width of this map in tiles.
##
def setWidth(self, width):
self.mWidth = width
##
# Returns the height of this map in tiles.
##
def height(self):
return self.mHeight
##
# Sets the height of this map in tiles.
##
def setHeight(self, height):
self.mHeight = height
##
# Returns the size of this map. Provided for convenience.
##
def size(self):
return QSize(self.mWidth, self.mHeight)
##
# Returns the tile width of this map.
##
def tileWidth(self):
return self.mTileWidth
##
# Sets the width of one tile.
##
def setTileWidth(self, width):
self.mTileWidth = width
##
# Returns the tile height used by this map.
##
def tileHeight(self):
return self.mTileHeight
##
# Sets the height of one tile.
##
def setTileHeight(self, height):
self.mTileHeight = height
##
# Returns the size of one tile. Provided for convenience.
##
def tileSize(self):
return QSize(self.mTileWidth, self.mTileHeight)
示例5: MapDocument
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import size [as 别名]
#.........这里部分代码省略.........
# didn't actually change. This is because the selected index in the layer
# table view might be out of date anyway, and would otherwise not be
# properly updated.
#
# This problem happens due to the selection model not sending signals
# about changes to its current index when it is due to insertion/removal
# of other items. The selected item doesn't change in that case, but our
# layer index does.
##
self.currentLayerIndexChanged.emit(self.mCurrentLayerIndex)
if (changed and self.mCurrentLayerIndex != -1):
self.setCurrentObject(self.currentLayer())
##
# Returns the index of the currently selected layer. Returns -1 if no
# layer is currently selected.
##
def currentLayerIndex(self):
return self.mCurrentLayerIndex
##
# Returns the currently selected layer, or 0 if no layer is currently
# selected.
##
def currentLayer(self):
if (self.mCurrentLayerIndex == -1):
return None
return self.mMap.layerAt(self.mCurrentLayerIndex)
##
# Resize this map to the given \a size, while at the same time shifting
# the contents by \a offset.
##
def resizeMap(self, size, offset):
movedSelection = self.mSelectedArea.translated(offset)
newArea = QRect(-offset, size)
visibleArea = self.mRenderer.boundingRect(newArea)
origin = self.mRenderer.tileToPixelCoords_(QPointF())
newOrigin = self.mRenderer.tileToPixelCoords_(-offset)
pixelOffset = origin - newOrigin
# Resize the map and each layer
self.mUndoStack.beginMacro(self.tr("Resize Map"))
for i in range(self.mMap.layerCount()):
layer = self.mMap.layerAt(i)
x = layer.layerType()
if x==Layer.TileLayerType:
tileLayer = layer
self.mUndoStack.push(ResizeTileLayer(self, tileLayer, size, offset))
elif x==Layer.ObjectGroupType:
objectGroup = layer
# Remove objects that will fall outside of the map
for o in objectGroup.objects():
if (not visibleIn(visibleArea, o, self.mRenderer)):
self.mUndoStack.push(RemoveMapObject(self, o))
else:
oldPos = o.position()
newPos = oldPos + pixelOffset
self.mUndoStack.push(MoveMapObject(self, newPos, oldPos))
elif x==Layer.ImageLayerType:
# Currently not adjusted when resizing the map
break
self.mUndoStack.push(ResizeMap(self, size))
self.mUndoStack.push(ChangeSelectedArea(self, movedSelection))
self.mUndoStack.endMacro()
# TODO: Handle layers that don't match the map size correctly
示例6: ObjectGroup
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import size [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)
#.........这里部分代码省略.........
示例7: MapObjectModel
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import size [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))
#.........这里部分代码省略.........
示例8: TileStampModel
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import size [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:
#.........这里部分代码省略.........
示例9: AutoMapper
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import size [as 别名]
#.........这里部分代码省略.........
# It sets up some data structures which change rapidly, so it is quite
# painful to keep these datastructures up to date all time. (indices of
# layers of the working map)
##
def prepareAutoMap(self):
self.mError = ''
self.mWarning = ''
if (not self.setupMissingLayers()):
return False
if (not self.setupCorrectIndexes()):
return False
if (not self.setupTilesets(self.mMapRules, self.mMapWork)):
return False
return True
##
# Here is done all the automapping.
##
def autoMap(self, where):
# first resize the active area
if (self.mAutoMappingRadius):
region = QRegion()
for r in where.rects():
region += r.adjusted(- self.mAutoMappingRadius,
- self.mAutoMappingRadius,
+ self.mAutoMappingRadius,
+ self.mAutoMappingRadius)
#where += region
# delete all the relevant area, if the property "DeleteTiles" is set
if (self.mDeleteTiles):
setLayersRegion = self.getSetLayersRegion()
for i in range(self.mLayerList.size()):
translationTable = self.mLayerList.at(i)
for layer in translationTable.keys():
index = self.mLayerList.at(i).value(layer)
dstLayer = self.mMapWork.layerAt(index)
region = setLayersRegion.intersected(where)
dstTileLayer = dstLayer.asTileLayer()
if (dstTileLayer):
dstTileLayer.erase(region)
else:
self.eraseRegionObjectGroup(self.mMapDocument,
dstLayer.asObjectGroup(),
region)
# Increase the given region where the next automapper should work.
# This needs to be done, so you can rely on the order of the rules at all
# locations
ret = QRegion()
for rect in where.rects():
for i in range(self.mRulesInput.size()):
# at the moment the parallel execution does not work yet
# TODO: make multithreading available!
# either by dividing the rules or the region to multiple threads
ret = ret.united(self.applyRule(i, rect))
#where = where.united(ret)
##
# This cleans all datastructures, which are setup via prepareAutoMap,
# so the auto mapper becomes ready for its next automatic mapping.
##
def cleanAll(self):
self.cleanTilesets()
示例10: DocumentManager
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import size [as 别名]
#.........这里部分代码省略.........
##
# 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):
return None
return self.mTabWidget.widget(index).mapView()
##
# Returns the number of map documents.
##
def documentCount(self):
return self.mDocuments.size()
##
# Searches for a document with the given \a fileName and returns its
# index. Returns -1 when the document isn't open.
##
def findDocument(self, fileName):
canonicalFilePath = QFileInfo(fileName).canonicalFilePath()
if (canonicalFilePath==''): # file doesn't exist
return -1
for i in range(self.mDocuments.size()):
fileInfo = QFileInfo(self.mDocuments.at(i).fileName())
if (fileInfo.canonicalFilePath() == canonicalFilePath):
return i
return -1
##
# Switches to the map document at the given \a index.
##
def switchToDocument(self, arg):
tp = type(arg)
if tp==int:
index = arg
self.mTabWidget.setCurrentIndex(index)
elif tp==MapDocument:
mapDocument = arg
index = self.mDocuments.indexOf(mapDocument)
if (index != -1):
self.switchToDocument(index)
##
# Adds the new or opened \a mapDocument to the document manager.