|
29 | 29 | import warnings
|
30 | 30 |
|
31 | 31 | from qgis.PyQt import uic
|
32 |
| -from qgis.PyQt.QtWidgets import QMenu, QAction, QInputDialog |
| 32 | +from qgis.PyQt.QtWidgets import ( |
| 33 | + QMenu, |
| 34 | + QAction, |
| 35 | + QDialog, |
| 36 | + QVBoxLayout, |
| 37 | + QDialogButtonBox, |
| 38 | + QLabel |
| 39 | +) |
33 | 40 | from qgis.PyQt.QtGui import QCursor
|
34 | 41 | from qgis.PyQt.QtCore import QCoreApplication, pyqtSignal
|
35 | 42 |
|
36 |
| -from qgis.gui import QgsMessageBar |
| 43 | +from qgis.gui import QgsMapLayerComboBox |
37 | 44 | from qgis.utils import iface
|
38 |
| -from qgis.core import (QgsProcessingUtils, |
39 |
| - QgsProcessingParameterDefinition, |
| 45 | +from qgis.core import (QgsProcessingParameterDefinition, |
40 | 46 | QgsProcessingParameters,
|
41 | 47 | QgsProject,
|
42 |
| - QgsCoordinateReferenceSystem, |
43 |
| - QgsRectangle, |
44 |
| - QgsReferencedRectangle) |
| 48 | + QgsReferencedRectangle, |
| 49 | + QgsMapLayerProxyModel) |
45 | 50 | from processing.gui.RectangleMapTool import RectangleMapTool
|
46 | 51 | from processing.core.ProcessingConfig import ProcessingConfig
|
47 | 52 | from processing.tools.dataobjects import createContext
|
|
54 | 59 | os.path.join(pluginPath, 'ui', 'widgetBaseSelector.ui'))
|
55 | 60 |
|
56 | 61 |
|
| 62 | +class LayerSelectionDialog(QDialog): |
| 63 | + |
| 64 | + def __init__(self, parent=None): |
| 65 | + super().__init__(parent) |
| 66 | + self.setWindowTitle(self.tr('Select Extent')) |
| 67 | + |
| 68 | + vl = QVBoxLayout() |
| 69 | + vl.addWidget(QLabel(self.tr('Use extent from'))) |
| 70 | + self.combo = QgsMapLayerComboBox() |
| 71 | + self.combo.setFilters( |
| 72 | + QgsMapLayerProxyModel.HasGeometry | QgsMapLayerProxyModel.RasterLayer | QgsMapLayerProxyModel.MeshLayer) |
| 73 | + self.combo.setShowCrs(ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF)) |
| 74 | + vl.addWidget(self.combo) |
| 75 | + |
| 76 | + self.button_box = QDialogButtonBox() |
| 77 | + self.button_box.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) |
| 78 | + self.button_box.accepted.connect(self.accept) |
| 79 | + self.button_box.rejected.connect(self.reject) |
| 80 | + |
| 81 | + vl.addWidget(self.button_box) |
| 82 | + self.setLayout(vl) |
| 83 | + |
| 84 | + def selected_layer(self): |
| 85 | + return self.combo.currentLayer() |
| 86 | + |
| 87 | + |
57 | 88 | class ExtentSelectionPanel(BASE, WIDGET):
|
58 | 89 |
|
59 | 90 | hasChanged = pyqtSignal()
|
@@ -133,22 +164,10 @@ def useMinCoveringExtent(self):
|
133 | 164 | self.leText.setText('')
|
134 | 165 |
|
135 | 166 | def useLayerExtent(self):
|
136 |
| - extentsDict = {} |
137 |
| - extents = [] |
138 |
| - layers = QgsProcessingUtils.compatibleLayers(QgsProject.instance()) |
139 |
| - for layer in layers: |
140 |
| - authid = layer.crs().authid() |
141 |
| - if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF) \ |
142 |
| - and authid is not None: |
143 |
| - layerName = u'{} [{}]'.format(layer.name(), authid) |
144 |
| - else: |
145 |
| - layerName = layer.name() |
146 |
| - extents.append(layerName) |
147 |
| - extentsDict[layerName] = {"extent": layer.extent(), "authid": authid} |
148 |
| - (item, ok) = QInputDialog.getItem(self, self.tr('Select Extent'), |
149 |
| - self.tr('Use extent from'), extents, 0, False) |
150 |
| - if ok: |
151 |
| - self.setValueFromRect(QgsReferencedRectangle(extentsDict[item]["extent"], QgsCoordinateReferenceSystem(extentsDict[item]["authid"]))) |
| 167 | + dlg = LayerSelectionDialog(self) |
| 168 | + if dlg.exec_(): |
| 169 | + layer = dlg.selected_layer() |
| 170 | + self.setValueFromRect(QgsReferencedRectangle(layer.extent(), layer.crs())) |
152 | 171 |
|
153 | 172 | def useCanvasExtent(self):
|
154 | 173 | self.setValueFromRect(QgsReferencedRectangle(iface.mapCanvas().extent(),
|
|
0 commit comments