本文整理汇总了Python中pyqtcore.QList.indexOf方法的典型用法代码示例。如果您正苦于以下问题:Python QList.indexOf方法的具体用法?Python QList.indexOf怎么用?Python QList.indexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QList
的用法示例。
在下文中一共展示了QList.indexOf方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QtGroupBoxPropertyBrowserPrivate
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import indexOf [as 别名]
class QtGroupBoxPropertyBrowserPrivate():
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 createEditor(self, property, parent):
return self.q_ptr.createEditor(property, parent)
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 editor in self.m_widgetToItem.keys()):
return
self.m_widgetToItem[editor].widget = 0
self.m_widgetToItem.remove(editor)
def slotUpdate(self):
for item in self.m_recreateQueue:
par = item.parent
w = 0
l = 0
oldRow = -1
if (not par):
w = self.q_ptr
l = self.m_mainLayout
oldRow = self.m_children.indexOf(item)
else:
w = par.groupBox
l = par.layout
oldRow = par.children.indexOf(item)
if (self.hasHeader(par)):
oldRow += 2
if (item.widget):
item.widget.setParent(w)
elif (item.widgetLabel):
item.widgetLabel.setParent(w)
else:
item.widgetLabel = QLabel(w)
item.widgetLabel.setSizePolicy(QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed))
item.widgetLabel.setTextFormat(Qt.PlainText)
span = 1
if (item.widget):
l.addWidget(item.widget, oldRow, 1, 1, 1)
elif (item.widgetLabel):
l.addWidget(item.widgetLabel, oldRow, 1, 1, 1)
else:
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 updateLater(self):
QTimer.singleShot(0, self.q_ptr, 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:
if (parentItem):
row = parentItem.children.indexOf(afterItem) + 1
parentItem.children.insert(row, newItem)
else:
row = self.m_children.indexOf(afterItem) + 1
self.m_children.insert(row, newItem)
if (parentItem and self.hasHeader(parentItem)):
row += 2
if (not parentItem):
#.........这里部分代码省略.........
示例2: QtButtonPropertyBrowserPrivate
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import indexOf [as 别名]
#.........这里部分代码省略.........
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
示例3: Map
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import indexOf [as 别名]
#.........这里部分代码省略.........
layers.append(layer)
return layers
def objectGroups(self):
layers = QList()
for layer in self.mLayers:
og = layer.asObjectGroup()
if og:
layers.append(og)
return layers
def tileLayers(self):
layers = QList()
for layer in self.mLayers:
tl = layer.asTileLayer()
if tl:
layers.append(tl)
return layers
##
# Adds a layer to this map.
##
def addLayer(self, layer):
self.adoptLayer(layer)
self.mLayers.append(layer)
##
# Returns the index of the layer given by \a layerName, or -1 if no
# layer with that name is found.
#
# The second optional parameter specifies the layer types which are
# searched.
##
def indexOfLayer(self, layerName, layertypes = Layer.AnyLayerType):
for index in range(self.mLayers.size()):
if (self.layerAt(index).name() == layerName and (layertypes & self.layerAt(index).layerType())):
return index
return -1
##
# Adds a layer to this map, inserting it at the given index.
##
def insertLayer(self, index, layer):
self.adoptLayer(layer)
self.mLayers.insert(index, layer)
##
# Removes the layer at the given index from this map and returns it.
# The caller becomes responsible for the lifetime of this layer.
##
def takeLayerAt(self, index):
layer = self.mLayers.takeAt(index)
layer.setMap(None)
return layer
##
# Adds a tileset to this map. The map does not take ownership over its
# tilesets, this is merely for keeping track of which tilesets are used by
# the map, and their saving order.
#
# @param tileset the tileset to add
##
def addTileset(self, tileset):
self.mTilesets.append(tileset)
##
示例4: ObjectGroup
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import indexOf [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)
#.........这里部分代码省略.........
示例5: MapObjectModel
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import indexOf [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))
#.........这里部分代码省略.........
示例6: TileStampModel
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import indexOf [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:
#.........这里部分代码省略.........
示例7: DocumentManager
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import indexOf [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):
#.........这里部分代码省略.........