本文整理匯總了Python中qgis.gui.QgsMapLayerComboBox.layer方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsMapLayerComboBox.layer方法的具體用法?Python QgsMapLayerComboBox.layer怎麽用?Python QgsMapLayerComboBox.layer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.gui.QgsMapLayerComboBox
的用法示例。
在下文中一共展示了QgsMapLayerComboBox.layer方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: FieldMappingDialog
# 需要導入模塊: from qgis.gui import QgsMapLayerComboBox [as 別名]
# 或者: from qgis.gui.QgsMapLayerComboBox import layer [as 別名]
class FieldMappingDialog(QDialog, FORM_CLASS):
"""Dialog implementation class for the InaSAFE field mapping tool."""
def __init__(self, parent=None, iface=None, setting=None):
"""Constructor."""
QDialog.__init__(self, parent)
self.setupUi(self)
self.setWindowTitle(self.tr('InaSAFE Field Mapping Tool'))
icon = resources_path('img', 'icons', 'show-mapping-tool.svg')
self.setWindowIcon(QIcon(icon))
self.parent = parent
self.iface = iface
if setting is None:
setting = QSettings()
self.setting = setting
self.keyword_io = KeywordIO()
self.layer = None
self.metadata = {}
self.layer_input_layout = QHBoxLayout()
self.layer_label = QLabel(tr('Layer'))
self.layer_combo_box = QgsMapLayerComboBox()
# Filter only for Polygon and Point
self.layer_combo_box.setFilters(
QgsMapLayerProxyModel.PolygonLayer
| QgsMapLayerProxyModel.PointLayer)
# Filter out a layer that don't have layer groups
excepted_layers = []
for i in range(self.layer_combo_box.count()):
layer = self.layer_combo_box.layer(i)
try:
keywords = self.keyword_io.read_keywords(layer)
except (KeywordNotFoundError, NoKeywordsFoundError):
excepted_layers.append(layer)
continue
layer_purpose = keywords.get('layer_purpose')
if not layer_purpose:
excepted_layers.append(layer)
continue
if layer_purpose == layer_purpose_exposure['key']:
layer_subcategory = keywords.get('exposure')
elif layer_purpose == layer_purpose_hazard['key']:
layer_subcategory = keywords.get('hazard')
else:
layer_subcategory = None
field_groups = get_field_groups(layer_purpose, layer_subcategory)
if len(field_groups) == 0:
excepted_layers.append(layer)
continue
self.layer_combo_box.setExceptedLayerList(excepted_layers)
# Select the active layer.
if self.iface.activeLayer():
found = self.layer_combo_box.findText(
self.iface.activeLayer().name())
if found > -1:
self.layer_combo_box.setLayer(self.iface.activeLayer())
self.field_mapping_widget = None
self.main_stacked_widget.setCurrentIndex(1)
# Input
self.layer_input_layout.addWidget(self.layer_label)
self.layer_input_layout.addWidget(self.layer_combo_box)
self.header_label = QLabel()
self.header_label.setWordWrap(True)
self.main_layout.addWidget(self.header_label)
self.main_layout.addLayout(self.layer_input_layout)
# Signal
self.layer_combo_box.layerChanged.connect(self.set_layer)
if self.layer_combo_box.currentLayer():
self.set_layer(self.layer_combo_box.currentLayer())
# Set up things for context help
self.help_button = self.button_box.button(QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
# Set up things for ok button
self.ok_button = self.button_box.button(QDialogButtonBox.Ok)
self.ok_button.clicked.connect(self.accept)
# Set up things for cancel button
self.cancel_button = self.button_box.button(QDialogButtonBox.Cancel)
self.cancel_button.clicked.connect(self.reject)
def set_layer(self, layer=None, keywords=None):
"""Set layer and update UI accordingly.
:param layer: A QgsVectorLayer.
:type layer: QgsVectorLayer
#.........這裏部分代碼省略.........