本文整理汇总了Python中qgis.PyQt.QtWidgets.QTreeWidgetItem.childCount方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidgetItem.childCount方法的具体用法?Python QTreeWidgetItem.childCount怎么用?Python QTreeWidgetItem.childCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.PyQt.QtWidgets.QTreeWidgetItem
的用法示例。
在下文中一共展示了QTreeWidgetItem.childCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __setupModelData
# 需要导入模块: from qgis.PyQt.QtWidgets import QTreeWidgetItem [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QTreeWidgetItem import childCount [as 别名]
def __setupModelData(self):
dsList = DataSourcesList().data_sources.values()
groupInfoList = GroupsList().groups
groupsItems = []
groups = []
for ds in dsList:
if ds.group in groups:
group_item = groupsItems[groups.index(ds.group)]
else:
group_item = QTreeWidgetItem()
group_item.setData(self.COLUMN_GROUP_DS, Qt.DisplayRole, ds.group)
group_item.setData(self.COLUMN_VISIBILITY, Qt.DisplayRole, "")
group_item.setData(self.COLUMN_SOURCE, Qt.DisplayRole, ds.category)
group_item.setCheckState(self.COLUMN_VISIBILITY, Qt.Unchecked)
groupInfo = groupInfoList.get(ds.group)
if groupInfo is not None:
group_item.setIcon(self.COLUMN_GROUP_DS, QIcon(groupInfo.icon))
else:
group_item.setData(self.COLUMN_GROUP_DS, Qt.DisplayRole, ds.group + " (%s!)" % self.tr("group not found"))
group_item.setData(self.COLUMN_GROUP_DS, Qt.UserRole, groupInfo)
groups.append(ds.group)
groupsItems.append(group_item)
self.rootItem.addChild(group_item)
ds_item = QTreeWidgetItem()
ds_item.setData(self.COLUMN_GROUP_DS, Qt.DisplayRole, ds.alias)
ds_item.setIcon(self.COLUMN_GROUP_DS, QIcon(ds.icon_path))
ds_item.setData(self.COLUMN_GROUP_DS, Qt.UserRole, ds)
ds_item.setData(self.COLUMN_VISIBILITY, Qt.DisplayRole, "")
ds_item.setData(self.COLUMN_SOURCE, Qt.DisplayRole, ds.category)
ds_check_state = Qt.Checked
if ds.id in PluginSettings.get_hide_ds_id_list():
ds_check_state = Qt.Unchecked
ds_item.setCheckState(self.COLUMN_VISIBILITY, ds_check_state)
if group_item.childCount() != 0 and group_item.checkState(1) != ds_check_state:
group_item.setCheckState(self.COLUMN_VISIBILITY, Qt.PartiallyChecked)
else:
group_item.setCheckState(self.COLUMN_VISIBILITY, ds_check_state)
group_item.addChild(
ds_item
)
示例2: GetScriptsAndModelsDialog
# 需要导入模块: from qgis.PyQt.QtWidgets import QTreeWidgetItem [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QTreeWidgetItem import childCount [as 别名]
#.........这里部分代码省略.........
self.txtHelp.setHtml(self.HELP_TEXT)
def setHelp(self, reply, item):
"""Change the HTML content"""
QApplication.restoreOverrideCursor()
if reply.error() != QNetworkReply.NoError:
html = self.tr('<h2>No detailed description available for this script</h2>')
else:
content = unicode(reply.readAll())
descriptions = json.loads(content)
html = '<h2>%s</h2>' % item.name
html += self.tr('<p><b>Description:</b> %s</p>') % getDescription(ALG_DESC, descriptions)
html += self.tr('<p><b>Created by:</b> %s') % getDescription(ALG_CREATOR, descriptions)
html += self.tr('<p><b>Version:</b> %s') % getDescription(ALG_VERSION, descriptions)
reply.deleteLater()
self.txtHelp.setHtml(html)
def currentItemChanged(self, item, prev):
if isinstance(item, TreeItem):
url = self.urlBase + item.filename.replace(' ', '%20') + '.help'
self.grabHTTP(url, self.setHelp, item)
else:
self.txtHelp.setHtml(self.HELP_TEXT)
def getTreeBranchForState(self, filename, version):
if not os.path.exists(os.path.join(self.folder, filename)):
return self.notinstalledItem
else:
helpFile = os.path.join(self.folder, filename + '.help')
try:
with open(helpFile) as f:
helpContent = json.load(f)
currentVersion = float(helpContent[Help2Html.ALG_VERSION])
except Exception:
currentVersion = 0
if version > currentVersion:
return self.toupdateItem
else:
return self.uptodateItem
def cancelPressed(self):
super(GetScriptsAndModelsDialog, self).reject()
def storeFile(self, reply, filename):
"""store a script/model that has been downloaded"""
QApplication.restoreOverrideCursor()
if reply.error() != QNetworkReply.NoError:
if os.path.splitext(filename)[1].lower() == '.help':
content = '{"ALG_VERSION" : %s}' % self.resources[filename[:-5]][0]
else:
self.popupError(reply.error(), reply.request().url().toString())
content = None
else:
content = reply.readAll()
reply.deleteLater()
if content:
path = os.path.join(self.folder, filename)
with open(path, 'w') as f:
f.write(content)
self.progressBar.setValue(self.progressBar.value() + 1)
def okPressed(self):
toDownload = []
for i in xrange(self.toupdateItem.childCount()):
item = self.toupdateItem.child(i)
if item.checkState(0) == Qt.Checked:
toDownload.append(item.filename)
for i in xrange(self.notinstalledItem.childCount()):
item = self.notinstalledItem.child(i)
if item.checkState(0) == Qt.Checked:
toDownload.append(item.filename)
if toDownload:
self.progressBar.setMaximum(len(toDownload) * 2)
for i, filename in enumerate(toDownload):
QCoreApplication.processEvents()
url = self.urlBase + filename.replace(' ', '%20')
self.grabHTTP(url, self.storeFile, filename)
url += '.help'
self.grabHTTP(url, self.storeFile, filename + '.help')
toDelete = []
for i in xrange(self.uptodateItem.childCount()):
item = self.uptodateItem.child(i)
if item.checkState(0) == Qt.Unchecked:
toDelete.append(item.filename)
# Remove py and help files if they exist
for filename in toDelete:
for pathname in (filename, filename + u".help"):
path = os.path.join(self.folder, pathname)
if os.path.exists(path):
os.remove(path)
self.updateProvider = len(toDownload) + len(toDelete) > 0
super(GetScriptsAndModelsDialog, self).accept()
示例3: DSManagerModel
# 需要导入模块: from qgis.PyQt.QtWidgets import QTreeWidgetItem [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QTreeWidgetItem import childCount [as 别名]
class DSManagerModel(QAbstractItemModel):
__metaclass__ = QSingleton
COLUMN_GROUP_DS = 0
COLUMN_VISIBILITY = 1
COLUMN_SOURCE = 2
# instance = None
# @classmethod
# def getInstance(cls):
# if cls.instance
def __init__(self, parent=None):
super(DSManagerModel, self).__init__(parent)
self.columnNames = []
self.columnNames.insert(self.COLUMN_GROUP_DS, self.tr("Group/DS"))
self.columnNames.insert(self.COLUMN_VISIBILITY, self.tr("Visible"))
self.columnNames.insert(self.COLUMN_SOURCE, self.tr("Source"))
self.rootItem = QTreeWidgetItem(self.columnNames)
self.__setupModelData()
def resetModel(self):
self.beginResetModel()
self.__clear()
self.__setupModelData()
self.endResetModel()
self.modelReset.emit()
def __clear(self):
for groupIndex in range(self.rootItem.childCount() - 1, -1, -1):
groupItem = self.rootItem.child(groupIndex)
for dsIndex in range(groupItem.childCount() - 1, -1, -1):
dsItem = groupItem.child(dsIndex)
groupItem.removeChild(dsItem)
self.rootItem.removeChild(groupItem)
def __setupModelData(self):
dsList = DataSourcesList().data_sources.values()
groupInfoList = GroupsList().groups
groupsItems = []
groups = []
for ds in dsList:
if ds.group in groups:
group_item = groupsItems[groups.index(ds.group)]
else:
group_item = QTreeWidgetItem()
group_item.setData(self.COLUMN_GROUP_DS, Qt.DisplayRole, ds.group)
group_item.setData(self.COLUMN_VISIBILITY, Qt.DisplayRole, "")
group_item.setData(self.COLUMN_SOURCE, Qt.DisplayRole, ds.category)
group_item.setCheckState(self.COLUMN_VISIBILITY, Qt.Unchecked)
groupInfo = groupInfoList.get(ds.group)
if groupInfo is not None:
group_item.setIcon(self.COLUMN_GROUP_DS, QIcon(groupInfo.icon))
else:
group_item.setData(self.COLUMN_GROUP_DS, Qt.DisplayRole, ds.group + " (%s!)" % self.tr("group not found"))
group_item.setData(self.COLUMN_GROUP_DS, Qt.UserRole, groupInfo)
groups.append(ds.group)
groupsItems.append(group_item)
self.rootItem.addChild(group_item)
ds_item = QTreeWidgetItem()
ds_item.setData(self.COLUMN_GROUP_DS, Qt.DisplayRole, ds.alias)
ds_item.setIcon(self.COLUMN_GROUP_DS, QIcon(ds.icon_path))
ds_item.setData(self.COLUMN_GROUP_DS, Qt.UserRole, ds)
ds_item.setData(self.COLUMN_VISIBILITY, Qt.DisplayRole, "")
ds_item.setData(self.COLUMN_SOURCE, Qt.DisplayRole, ds.category)
ds_check_state = Qt.Checked
if ds.id in PluginSettings.get_hide_ds_id_list():
ds_check_state = Qt.Unchecked
ds_item.setCheckState(self.COLUMN_VISIBILITY, ds_check_state)
if group_item.childCount() != 0 and group_item.checkState(1) != ds_check_state:
group_item.setCheckState(self.COLUMN_VISIBILITY, Qt.PartiallyChecked)
else:
group_item.setCheckState(self.COLUMN_VISIBILITY, ds_check_state)
group_item.addChild(
ds_item
)
def setData(self, index, value, role):
if not index.isValid():
return False
else:
item = index.internalPointer()
if role == Qt.CheckStateRole:
item.setData(self.COLUMN_VISIBILITY, role, value)
self.dataChanged.emit(
index,
index
)
#.........这里部分代码省略.........
示例4: data
# 需要导入模块: from qgis.PyQt.QtWidgets import QTreeWidgetItem [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QTreeWidgetItem import childCount [as 别名]
def data(self, profile_data):
"""Set data for the widget.
:param profile_data: profile data.
:type profile_data: dict
It will replace the previous data.
"""
default_profile = generate_default_profile()
self.clear()
for hazard in sorted(default_profile.keys()):
classifications = default_profile[hazard]
hazard_widget_item = QTreeWidgetItem()
hazard_widget_item.setData(0, Qt.UserRole, hazard)
hazard_widget_item.setText(0, get_name(hazard))
for classification in sorted(classifications.keys()):
# Filter out classification that doesn't support population.
# TODO(IS): This is not the best place to put the filtering.
# It's more suitable in the generate_default_profile method
# in safe/definitions/utilities.
classification_definition = definition(classification)
supported_exposures = classification_definition.get(
'exposures', [])
# Empty list means support all exposure
if supported_exposures != []:
if exposure_population not in supported_exposures:
continue
classes = classifications[classification]
classification_widget_item = QTreeWidgetItem()
classification_widget_item.setData(
0, Qt.UserRole, classification)
classification_widget_item.setText(0, get_name(classification))
hazard_widget_item.addChild(classification_widget_item)
for the_class, the_value in list(classes.items()):
the_class_widget_item = QTreeWidgetItem()
the_class_widget_item.setData(0, Qt.UserRole, the_class)
the_class_widget_item.setText(
0, get_class_name(the_class, classification))
classification_widget_item.addChild(the_class_widget_item)
# Adding widget must be happened after addChild
affected_check_box = QCheckBox(self)
# Set from profile_data if exist, else get default
profile_value = profile_data.get(
hazard, {}).get(classification, {}).get(
the_class, the_value)
affected_check_box.setChecked(profile_value['affected'])
self.setItemWidget(
the_class_widget_item, 1, affected_check_box)
displacement_rate_spinbox = PercentageSpinBox(self)
displacement_rate_spinbox.setValue(
profile_value['displacement_rate'])
displacement_rate_spinbox.setEnabled(
profile_value['affected'])
self.setItemWidget(
the_class_widget_item, 2, displacement_rate_spinbox)
# Behaviour when the check box is checked
# noinspection PyUnresolvedReferences
affected_check_box.stateChanged.connect(
displacement_rate_spinbox.setEnabled)
if hazard_widget_item.childCount() > 0:
self.widget_items.append(hazard_widget_item)
self.addTopLevelItems(self.widget_items)
self.expandAll()
示例5: __init__
# 需要导入模块: from qgis.PyQt.QtWidgets import QTreeWidgetItem [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QTreeWidgetItem import childCount [as 别名]
def __init__(self):
super(TestSelector, self).__init__()
self.setupUi(self)
self.tests = None
self.bar = QgsMessageBar()
self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
self.layout().insertWidget(1, self.bar)
allTests = defaultdict(list)
for test in tests.tests:
allTests[test.group].append(test)
for group, groupTests in iteritems(allTests):
groupItem = QTreeWidgetItem()
groupItem.setText(0, group)
groupItem.setFlags(groupItem.flags() | Qt.ItemIsTristate)
unitItem = QTreeWidgetItem()
unitItem.setText(0, "Fully automated tests")
unitItem.setFlags(unitItem.flags() | Qt.ItemIsTristate)
manualItem = QTreeWidgetItem()
manualItem.setText(0, "Manual and semi-automated tests")
manualItem.setFlags(manualItem.flags() | Qt.ItemIsTristate)
for test in groupTests:
testItem = QTreeWidgetItem()
testItem.setFlags(testItem.flags() | Qt.ItemIsUserCheckable)
testItem.setCheckState(0, Qt.Unchecked)
testItem.test = test
testItem.setText(0, test.name)
if isinstance(test, UnitTestWrapper):
unitItem.addChild(testItem)
else:
manualItem.addChild(testItem)
if manualItem.childCount():
groupItem.addChild(manualItem)
if unitItem.childCount():
groupItem.addChild(unitItem)
self.testsTree.addTopLevelItem(groupItem)
groupItem.setExpanded(True)
self.buttonBox.button(QDialogButtonBox.Ok).setText("Run selected tests")
self.buttonBox.accepted.connect(self.okPressed)
self.buttonBox.rejected.connect(self.cancelPressed)
self.selectAllLabel.linkActivated.connect(lambda: self.checkTests(lambda t: Qt.Checked))
self.unselectAllLabel.linkActivated.connect(lambda: self.checkTests(lambda t: Qt.Unchecked))
def _onlyManual(t):
if isinstance(t, UnitTestWrapper):
return Qt.Unchecked
else:
return Qt.Checked
self.onlyManualLabel.linkActivated.connect(lambda: self.checkTests(_onlyManual))
def _onlyUnit(t):
if isinstance(t, UnitTestWrapper):
return Qt.Checked
else:
return Qt.Unchecked
self.onlyUnitLabel.linkActivated.connect(lambda: self.checkTests(_onlyUnit))
self.exportButton.clicked.connect(self.export)
示例6: __init__
# 需要导入模块: from qgis.PyQt.QtWidgets import QTreeWidgetItem [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QTreeWidgetItem import childCount [as 别名]
def __init__(self):
super(TestSelector, self).__init__()
self.setupUi(self)
self.tests = None
self.bar = QgsMessageBar()
self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
self.layout().insertWidget(1, self.bar)
allTests = defaultdict(list)
for test in tests.tests:
allTests[test.group].append(test)
for group, groupTests in iteritems(allTests):
groupItem = QTreeWidgetItem()
groupItem.setText(0, group)
groupItem.setFlags(groupItem.flags() | Qt.ItemIsTristate);
unitItem = QTreeWidgetItem()
unitItem.setText(0, "Fully automated tests")
unitItem.setFlags(unitItem.flags() | Qt.ItemIsTristate);
manualItem = QTreeWidgetItem()
manualItem.setText(0, "Manual and semi-automated tests")
manualItem.setFlags(manualItem.flags() | Qt.ItemIsTristate);
unitTestsByCategories = defaultdict(list)
manualTestsByCategories = defaultdict(list)
for test in groupTests:
if isinstance(test, UnitTestWrapper):
unitTestsByCategories[test.category].append(test)
else:
manualTestsByCategories[test.category].append(test)
for testsList, parentItem in [(unitTestsByCategories, unitItem), (manualTestsByCategories, manualItem)]:
for cat, catTests in iteritems(testsList):
categoryItem = QTreeWidgetItem()
categoryItem.setText(0, cat)
categoryItem.setFlags(manualItem.flags() | Qt.ItemIsTristate);
for test in catTests:
testItem = QTreeWidgetItem()
testItem.setFlags(testItem.flags() | Qt.ItemIsUserCheckable);
testItem.setCheckState(0, Qt.Unchecked);
testItem.test = test
testItem.setText(0, test.name)
categoryItem.addChild(testItem)
parentItem.addChild(categoryItem)
if manualItem.childCount():
groupItem.addChild(manualItem)
if unitItem.childCount():
groupItem.addChild(unitItem)
self.testsTree.addTopLevelItem(groupItem)
groupItem.setExpanded(True)
self.buttonBox.button(QDialogButtonBox.Ok).setText("Run selected tests")
self.buttonBox.accepted.connect(self.okPressed)
self.buttonBox.rejected.connect(self.cancelPressed)
self.selectAllLabel.linkActivated.connect(lambda: self.checkTests(lambda t: Qt.Checked))
self.unselectAllLabel.linkActivated.connect(lambda: self.checkTests(lambda t: Qt.Unchecked))
def _onlyManual(t):
if isinstance(t, UnitTestWrapper):
return Qt.Unchecked
else:
return Qt.Checked
self.onlyManualLabel.linkActivated.connect(lambda: self.checkTests(_onlyManual))
def _onlyUnit(t):
if isinstance(t, UnitTestWrapper):
return Qt.Checked
else:
return Qt.Unchecked
self.onlyUnitLabel.linkActivated.connect(lambda: self.checkTests(_onlyUnit))
filepath = os.path.expanduser("~/.testerplugin/failed.txt")
if os.path.exists(filepath):
with open(filepath) as f:
failed = json.load(f)
else:
failed = []
def _onlyLastFailures(t):
if t.group in failed and t.name in failed[t.group]:
return Qt.Checked
else:
return Qt.Unchecked
self.onlyLastFailuresLabel.linkActivated.connect(lambda: self.checkTests(_onlyLastFailures))
self.exportButton.clicked.connect(self.export)