本文整理匯總了Python中qgis.gui.QgsMapLayerComboBox.currentLayer方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsMapLayerComboBox.currentLayer方法的具體用法?Python QgsMapLayerComboBox.currentLayer怎麽用?Python QgsMapLayerComboBox.currentLayer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.gui.QgsMapLayerComboBox
的用法示例。
在下文中一共展示了QgsMapLayerComboBox.currentLayer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: LayerSelectionDialog
# 需要導入模塊: from qgis.gui import QgsMapLayerComboBox [as 別名]
# 或者: from qgis.gui.QgsMapLayerComboBox import currentLayer [as 別名]
class LayerSelectionDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle(self.tr('Select Extent'))
vl = QVBoxLayout()
vl.addWidget(QLabel(self.tr('Use extent from')))
self.combo = QgsMapLayerComboBox()
self.combo.setFilters(
QgsMapLayerProxyModel.HasGeometry | QgsMapLayerProxyModel.RasterLayer | QgsMapLayerProxyModel.MeshLayer)
self.combo.setShowCrs(ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF))
vl.addWidget(self.combo)
self.button_box = QDialogButtonBox()
self.button_box.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok)
self.button_box.accepted.connect(self.accept)
self.button_box.rejected.connect(self.reject)
vl.addWidget(self.button_box)
self.setLayout(vl)
def selected_layer(self):
return self.combo.currentLayer()
示例2: Viewer
# 需要導入模塊: from qgis.gui import QgsMapLayerComboBox [as 別名]
# 或者: from qgis.gui.QgsMapLayerComboBox import currentLayer [as 別名]
#.........這裏部分代碼省略.........
self.clearLine.emit()
self.earthmine.clearLine()
@property
def copyZvalue(self):
layer = self.active_layer
if not layer:
return False
if layer.type() == QgsMapLayer.VectorLayer and layer.geometryType() == QGis.Point:
return self.zvaluecheck.isChecked()
else:
return False
@property
def geom(self):
return self.measuredialog.geom
@geom.setter
def geom(self, value):
self.measuredialog.geom = value
self.measuredialog.update_geom_labels()
@property
def tracking(self):
return self.qgisTrackButton.isChecked()
@property
def mode(self):
return self.measuredialog.mode
@property
def active_layer(self):
return self.activelayercombo.currentLayer()
def layer_changed(self, layer):
if not layer:
self.set_button_states(False, False, False, False)
return
if layer.type() == QgsMapLayer.VectorLayer:
enabledselecttools = layer.geometryType() in [QGis.Line, QGis.Point]
enableedittools = layer.isEditable()
enabledelete = layer.isEditable() and layer.selectedFeatureCount()
enablemove = layer.geometryType() == QGis.Point and layer.isEditable()
else:
enabledselecttools = False
enableedittools = False
enabledelete = False
enablemove = False
self.set_button_states(enabledselecttools, enableedittools, enabledelete, enablemove)
self.action_triggered()
self.layerChanged.emit(layer)
def selection_changed(self, layer):
if layer == self.active_layer:
enabledelete = layer.isEditable() and layer.selectedFeatureCount()
self.deleteaction.setEnabled(enabledelete)
def set_button_states(self, selecttools, edittools, deleteenabled, moveenabled):
actions = [self.selectaction, self.infoaction]
for action in actions:
action.setEnabled(selecttools)
示例3: FieldMappingDialog
# 需要導入模塊: from qgis.gui import QgsMapLayerComboBox [as 別名]
# 或者: from qgis.gui.QgsMapLayerComboBox import currentLayer [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
#.........這裏部分代碼省略.........