本文整理汇总了Python中qgis.PyQt.QtGui.QStandardItemModel.itemFromIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QStandardItemModel.itemFromIndex方法的具体用法?Python QStandardItemModel.itemFromIndex怎么用?Python QStandardItemModel.itemFromIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.PyQt.QtGui.QStandardItemModel
的用法示例。
在下文中一共展示了QStandardItemModel.itemFromIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MultipleInputDialog
# 需要导入模块: from qgis.PyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from qgis.PyQt.QtGui.QStandardItemModel import itemFromIndex [as 别名]
class MultipleInputDialog(BASE, WIDGET):
def __init__(self, options, selectedoptions=None, datatype=None):
super(MultipleInputDialog, self).__init__(None)
self.setupUi(self)
self.datatype = datatype
self.model = None
self.options = []
for i, option in enumerate(options):
if option is None or isinstance(option, str):
self.options.append((i, option))
else:
self.options.append((option[0], option[1]))
self.selectedoptions = selectedoptions or []
# Additional buttons
self.btnSelectAll = QPushButton(self.tr('Select All'))
self.buttonBox.addButton(self.btnSelectAll,
QDialogButtonBox.ActionRole)
self.btnClearSelection = QPushButton(self.tr('Clear Selection'))
self.buttonBox.addButton(self.btnClearSelection,
QDialogButtonBox.ActionRole)
self.btnToggleSelection = QPushButton(self.tr('Toggle Selection'))
self.buttonBox.addButton(self.btnToggleSelection,
QDialogButtonBox.ActionRole)
if self.datatype is not None:
btnAddFile = QPushButton(QCoreApplication.translate("MultipleInputDialog", 'Add File(s)…'))
btnAddFile.clicked.connect(self.addFiles)
self.buttonBox.addButton(btnAddFile,
QDialogButtonBox.ActionRole)
self.btnSelectAll.clicked.connect(lambda: self.selectAll(True))
self.btnClearSelection.clicked.connect(lambda: self.selectAll(False))
self.btnToggleSelection.clicked.connect(self.toggleSelection)
self.settings = QgsSettings()
self.restoreGeometry(self.settings.value("/Processing/multipleInputDialogGeometry", QByteArray()))
self.lstLayers.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.lstLayers.setDragDropMode(QAbstractItemView.InternalMove)
self.populateList()
self.finished.connect(self.saveWindowGeometry)
def saveWindowGeometry(self):
self.settings.setValue("/Processing/multipleInputDialogGeometry", self.saveGeometry())
def populateList(self):
self.model = QStandardItemModel()
for value, text in self.options:
item = QStandardItem(text)
item.setData(value, Qt.UserRole)
item.setCheckState(Qt.Checked if value in self.selectedoptions else Qt.Unchecked)
item.setCheckable(True)
item.setDropEnabled(False)
self.model.appendRow(item)
# add extra options (e.g. manually added layers)
for t in [o for o in self.selectedoptions if not isinstance(o, int)]:
if isinstance(t, QgsProcessingModelChildParameterSource):
item = QStandardItem(t.staticValue())
else:
item = QStandardItem(t)
item.setData(item.text(), Qt.UserRole)
item.setCheckState(Qt.Checked)
item.setCheckable(True)
item.setDropEnabled(False)
self.model.appendRow(item)
self.lstLayers.setModel(self.model)
def accept(self):
self.selectedoptions = []
model = self.lstLayers.model()
for i in range(model.rowCount()):
item = model.item(i)
if item.checkState() == Qt.Checked:
self.selectedoptions.append(item.data(Qt.UserRole))
QDialog.accept(self)
def reject(self):
self.selectedoptions = None
QDialog.reject(self)
def getItemsToModify(self):
items = []
if len(self.lstLayers.selectedIndexes()) > 1:
for i in self.lstLayers.selectedIndexes():
items.append(self.model.itemFromIndex(i))
else:
for i in range(self.model.rowCount()):
items.append(self.model.item(i))
return items
def selectAll(self, value):
for item in self.getItemsToModify():
item.setCheckState(Qt.Checked if value else Qt.Unchecked)
#.........这里部分代码省略.........
示例2: ResourceSharingDialog
# 需要导入模块: from qgis.PyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from qgis.PyQt.QtGui.QStandardItemModel import itemFromIndex [as 别名]
#.........这里部分代码省略.........
item.setText(0, repo_name)
item.setText(1, url)
self.tree_repositories.resizeColumnToContents(0)
self.tree_repositories.resizeColumnToContents(1)
self.tree_repositories.sortItems(1, Qt.AscendingOrder)
def reload_collections_model(self):
"""Reload the collections model with the current collections."""
self.collections_model.clear()
for id in config.COLLECTIONS:
collection_name = config.COLLECTIONS[id]['name']
collection_author = config.COLLECTIONS[id]['author']
collection_tags = config.COLLECTIONS[id]['tags']
collection_description = config.COLLECTIONS[id]['description']
collection_status = config.COLLECTIONS[id]['status']
item = QStandardItem(collection_name)
item.setEditable(False)
item.setData(id, COLLECTION_ID_ROLE)
item.setData(collection_name, COLLECTION_NAME_ROLE)
item.setData(collection_description, COLLECTION_DESCRIPTION_ROLE)
item.setData(collection_author, COLLECTION_AUTHOR_ROLE)
item.setData(collection_tags, COLLECTION_TAGS_ROLE)
item.setData(collection_status, COLLECTION_STATUS_ROLE)
self.collections_model.appendRow(item)
self.collections_model.sort(0, Qt.AscendingOrder)
def on_tree_repositories_itemSelectionChanged(self):
"""Slot for when the itemSelectionChanged signal emitted."""
# Activate edit and delete button
self.button_edit.setEnabled(True)
self.button_delete.setEnabled(True)
def on_list_view_collections_clicked(self, index):
"""Slot for when the list_view_collections is clicked."""
real_index = self.collection_proxy.mapToSource(index)
if real_index.row() != -1:
collection_item = self.collections_model.itemFromIndex(real_index)
collection_id = collection_item.data(COLLECTION_ID_ROLE)
self._selected_collection_id = collection_id
# Enable/disable button
status = config.COLLECTIONS[self._selected_collection_id]['status']
is_installed = status == COLLECTION_INSTALLED_STATUS
if is_installed:
self.button_install.setEnabled(True)
self.button_install.setText('Reinstall')
self.button_open.setEnabled(True)
self.button_uninstall.setEnabled(True)
else:
self.button_install.setEnabled(True)
self.button_install.setText('Install')
self.button_open.setEnabled(False)
self.button_uninstall.setEnabled(False)
# Show metadata
self.show_collection_metadata(collection_id)
@pyqtSlot(str)
def filter_collections(self, text):
search = QRegExp(
text,
Qt.CaseInsensitive,
QRegExp.RegExp)
self.collection_proxy.setFilterRegExp(search)
def show_collection_metadata(self, id):
"""Show the collection metadata given the id."""
html = self.collection_manager.get_html(id)
self.web_view_details.setHtml(html)
def reject(self):
"""Slot when the dialog is closed."""
# Serialize collections to settings
self.repository_manager.serialize_repositories()
self.done(0)
def open_help(self):
"""Open help."""
doc_url = QUrl('http://www.akbargumbira.com/qgis_resources_sharing')
QDesktopServices.openUrl(doc_url)
def show_progress_dialog(self, text):
"""Show infinite progress dialog with given text.
:param text: Text as the label of the progress dialog
:type text: str
"""
if self.progress_dialog is None:
self.progress_dialog = QProgressDialog(self)
self.progress_dialog.setWindowModality(Qt.WindowModal)
self.progress_dialog.setAutoClose(False)
title = self.tr('Resource Sharing')
self.progress_dialog.setWindowTitle(title)
# Just use infinite progress bar here
self.progress_dialog.setMaximum(0)
self.progress_dialog.setMinimum(0)
self.progress_dialog.setValue(0)
self.progress_dialog.setLabelText(text)
self.progress_dialog.show()