本文整理汇总了Python中qgis.PyQt.QtGui.QStandardItemModel.appendRow方法的典型用法代码示例。如果您正苦于以下问题:Python QStandardItemModel.appendRow方法的具体用法?Python QStandardItemModel.appendRow怎么用?Python QStandardItemModel.appendRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.PyQt.QtGui.QStandardItemModel
的用法示例。
在下文中一共展示了QStandardItemModel.appendRow方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: populateList
# 需要导入模块: from qgis.PyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from qgis.PyQt.QtGui.QStandardItemModel import appendRow [as 别名]
def populateList(self):
model = QStandardItemModel()
for option in self.selectedoptions:
item = QStandardItem(option)
model.appendRow(item)
self.lstLayers.setModel(model)
示例2: populateList
# 需要导入模块: from qgis.PyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from qgis.PyQt.QtGui.QStandardItemModel import appendRow [as 别名]
def populateList(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)
model.appendRow(item)
self.lstLayers.setModel(model)
示例3: HistoryDialog
# 需要导入模块: from qgis.PyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from qgis.PyQt.QtGui.QStandardItemModel import appendRow [as 别名]
class HistoryDialog(QDialog, Ui_HistoryDialogPythonConsole):
def __init__(self, parent):
QDialog.__init__(self, parent)
self.setupUi(self)
self.parent = parent
self.setWindowTitle(QCoreApplication.translate("PythonConsole",
"Python Console - Command History"))
self.listView.setToolTip(QCoreApplication.translate("PythonConsole",
"Double click on item to execute"))
self.model = QStandardItemModel(self.listView)
self._reloadHistory()
self.deleteScut = QShortcut(QKeySequence(Qt.Key_Delete), self)
self.deleteScut.activated.connect(self._deleteItem)
self.listView.doubleClicked.connect(self._runHistory)
self.reloadHistory.clicked.connect(self._reloadHistory)
self.saveHistory.clicked.connect(self._saveHistory)
def _runHistory(self, item):
cmd = item.data(Qt.DisplayRole)
self.parent.runCommand(cmd)
def _saveHistory(self):
self.parent.writeHistoryFile(True)
def _reloadHistory(self):
self.model.clear()
for i in self.parent.history:
item = QStandardItem(i)
if sys.platform.startswith('win'):
item.setSizeHint(QSize(18, 18))
self.model.appendRow(item)
self.listView.setModel(self.model)
self.listView.scrollToBottom()
def _deleteItem(self):
itemsSelected = self.listView.selectionModel().selectedIndexes()
if itemsSelected:
item = itemsSelected[0].row()
## Remove item from the command history (just for the current session)
self.parent.history.pop(item)
self.parent.historyIndex -= 1
## Remove row from the command history dialog
self.model.removeRow(item)
示例4: MultipleInputDialog
# 需要导入模块: from qgis.PyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from qgis.PyQt.QtGui.QStandardItemModel import appendRow [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)
#.........这里部分代码省略.........
示例5: PdokServicesPlugin
# 需要导入模块: from qgis.PyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from qgis.PyQt.QtGui.QStandardItemModel import appendRow [as 别名]
#.........这里部分代码省略.........
self.dlg.geocoderSearch.clear()
if self.toolbarSearch is not None:
self.toolbarSearch.clear()
def filterLayers(self, string):
# remove selection if one row is selected
self.dlg.servicesView.selectRow(0)
#self.currentLayer = None
self.proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
self.proxyModel.setFilterFixedString(string)
#def addSourceRow(self, service, layer):
def addSourceRow(self, serviceLayer):
# you can attache different "data's" to to an QStandarditem
# default one is the visible one:
itemType = QStandardItem("%s" % (serviceLayer["type"].upper()) )
# userrole is a free form one:
# only attach the data to the first item
# service layer = a dict/object with all props of the layer
itemType.setData( serviceLayer, Qt.UserRole )
itemType.setToolTip("%s - %s" % (serviceLayer["type"].upper() ,serviceLayer["title"] ))
# only wms services have styles (sometimes)
layername = serviceLayer["title"]
if 'style' in serviceLayer:
itemLayername = QStandardItem("%s [%s]" % (serviceLayer["title"], serviceLayer["style"]) )
layername = "%s [%s]" % (serviceLayer["title"], serviceLayer["style"])
else:
itemLayername = QStandardItem("%s" % (serviceLayer["title"]))
itemLayername.setToolTip("%s - %s" % (serviceLayer["type"].upper() ,serviceLayer["servicetitle"] ))
# itemFilter is the item used to search filter in. That is why layername is a combi of layername + filter here
itemFilter = QStandardItem("%s %s %s %s" % (serviceLayer["type"], layername, serviceLayer["servicetitle"], serviceLayer["abstract"]) )
itemServicetitle = QStandardItem("%s" % (serviceLayer["servicetitle"]))
itemServicetitle.setToolTip("%s - %s" % (serviceLayer["type"].upper() ,serviceLayer["title"] ))
self.sourceModel.appendRow( [ itemLayername, itemType, itemServicetitle, itemFilter ] )
# run method that performs all the real work
def run(self, hiddenDialog=False):
# enable possible remote pycharm debugging
#import pydevd
#pydevd.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True)
# last viewed/selected tab
if QSettings().contains("/pdokservicesplugin/currenttab"):
if Qgis.QGIS_VERSION_INT < 10900:
# qgis <= 1.8
self.dlg.tabs.widget(QSettings().value("/pdokservicesplugin/currenttab").toInt()[0])
else:
self.dlg.tabs.widget(int(QSettings().value("/pdokservicesplugin/currenttab")))
if self.servicesLoaded == False:
pdokjson = os.path.join(os.path.dirname(__file__), ".", "pdok.json")
f = open(pdokjson, 'r', encoding='utf-8')
self.pdok = json.load(f)
f.close()
self.proxyModel = QSortFilterProxyModel()
self.sourceModel = QStandardItemModel()
self.proxyModel.setSourceModel(self.sourceModel)
# filter == search on itemFilter column:
self.proxyModel.setFilterKeyColumn(3)
self.dlg.servicesView.setModel(self.proxyModel)
self.dlg.servicesView.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.geocoderProxyModel = QSortFilterProxyModel()
self.geocoderSourceModel = QStandardItemModel()
示例6: ThinGreyscaleDialog
# 需要导入模块: from qgis.PyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from qgis.PyQt.QtGui.QStandardItemModel import appendRow [as 别名]
#.........这里部分代码省略.........
# Add lines for the levels
minvalue = float(self.histMinValue.text())
maxvalue = float(self.histMaxValue.text())
datarange = maxvalue - minvalue
if datarange == 0:
return
i = 0
while self.levelsListView.model().item(i):
#self.showInfo("Element: " +
# str(self.levelsListView.model().item(i).text()))
#continue
value = float(self.levelsListView.model().item(i).text())
xvalue = start.x() + histwidth * (value - minvalue) / datarange
line = QGraphicsLineItem(xvalue, 0, xvalue, histheight)
if i == 0 or i == (self.levelsListView.model().rowCount() - 1):
line.setPen(QPen(QColor(204, 0, 0)))
else:
line.setPen(QPen(QColor(0, 204, 0)))
self.setupScene.addItem(line)
i = i + 1
def suggestLevels(self):
self.listModel.clear()
self.showInfo("Suggesting levels")
levels = self.levelsSpinBox.value()
startvalue = self.minValueSpinBox.value()
endvalue = self.maxValueSpinBox.value()
increment = (endvalue - startvalue) / levels
for i in range(levels + 1):
value = startvalue + increment * i
if self.intband:
value = int(value)
item = QStandardItem(str(value))
self.listModel.appendRow(item)
self.drawHistogram()
def addLevel(self):
newvalue = self.levelSpinBox.value()
if self.intband:
newvalue = int(newvalue)
for i in range(self.listModel.rowCount()):
# Check if the value is already in the list
if self.listModel.item(i).text() == str(newvalue):
return
else:
# Maintain a sorted list of distances
if (float(self.listModel.item(i).text()) >
float(str(newvalue))):
item = QStandardItem(str(newvalue))
self.listModel.insertRow(i, item)
self.drawHistogram()
return
item = QStandardItem(str(newvalue))
self.listModel.appendRow(item)
#if self.histogramAvailable:
# addLevelsToHistogram()
self.drawHistogram()
def removeLevel(self):
self.levelsListView.setUpdatesEnabled(False)
indexes = self.levelsListView.selectedIndexes()
indexes.sort()
for i in range(len(indexes) - 1, -1, -1):
self.listModel.removeRow(indexes[i].row())
self.levelsListView.setUpdatesEnabled(True)
#if self.histogramAvailable:
示例7: ResourceSharingDialog
# 需要导入模块: from qgis.PyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from qgis.PyQt.QtGui.QStandardItemModel import appendRow [as 别名]
#.........这里部分代码省略.........
def populate_repositories_widget(self):
"""Populate the current dictionary repositories to the tree widget."""
# Clear the current tree widget
self.tree_repositories.clear()
# Export the updated ones from the repository manager
for repo_name in self.repository_manager.directories:
url = self.repository_manager.directories[repo_name]['url']
item = QTreeWidgetItem(self.tree_repositories)
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)