def __init__(self, parent=None): """Constructor.""" super().__init__(parent) self.setupUi(self) self.blocked = False self.previous_map_tool = None self.extent_tool = None for name in SERVICE_MANAGER.available_predefined_bounding_boxes(): extent = SERVICE_MANAGER.predefined_bounding_box(name) item = QListWidgetItem(extent['title']) item.setData(Qt.UserRole, name) item.setData(Qt.UserRole + 1, extent.get('read_only', False)) item.setData(Qt.UserRole + 2, extent.get('title', '')) item.setData(Qt.UserRole + 3, extent.get('boundingbox', [0, 0, 0, 0])[0]) item.setData(Qt.UserRole + 4, extent.get('boundingbox', [0, 0, 0, 0])[1]) item.setData(Qt.UserRole + 5, extent.get('boundingbox', [0, 0, 0, 0])[2]) item.setData(Qt.UserRole + 6, extent.get('boundingbox', [0, 0, 0, 0])[3]) self.region_list.addItem(item) self.region_list.currentItemChanged.connect(self._item_changed) self.button_add.clicked.connect(self._add_item) self.button_remove.clicked.connect(self._remove_item) self.edit_label.textEdited.connect(self._update_item) self.spin_min_long.valueChanged.connect(self._update_item) self.spin_max_long.valueChanged.connect(self._update_item) self.spin_min_lat.valueChanged.connect(self._update_item) self.spin_max_lat.valueChanged.connect(self._update_item) self.button_draw_on_map.clicked.connect(self.draw_rect_on_map)
def save_areas(self): previous = list(SERVICE_MANAGER.available_predefined_bounding_boxes()) for p in previous: if SERVICE_MANAGER.predefined_bounding_box(p).get('read_only'): continue SERVICE_MANAGER.remove_predefined_bounding_box(p) for i in range(self.region_list.count()): item = self.region_list.item(i) if item.data(Qt.UserRole + 1): # read only continue title = item.data(Qt.UserRole + 2) bounding_box = [ item.data(Qt.UserRole + 3), item.data(Qt.UserRole + 4), item.data(Qt.UserRole + 5), item.data(Qt.UserRole + 6) ] SERVICE_MANAGER.add_predefined_bounding_box( title, { 'title': title, 'boundingbox': bounding_box })
def _populated_predefined_areas(self): """ Populates the predefined area choices """ self.combo_predefined_area.clear() for name in SERVICE_MANAGER.available_predefined_bounding_boxes(): extent = SERVICE_MANAGER.predefined_bounding_box(name) self.combo_predefined_area.addItem(extent['title'], name)
def _use_predefined_area(self): """ Retrieves the selected predefined area details and updates the widget state accordingly """ if not self.radio_predefined_area.isChecked(): return selected_extent_id = self.combo_predefined_area.currentData() if selected_extent_id not in SERVICE_MANAGER.available_predefined_bounding_boxes( ): return extent = SERVICE_MANAGER.predefined_bounding_box( selected_extent_id)['boundingbox'] self.lat_min_spinbox.setValue(extent[1]) self.lat_max_spinbox.setValue(extent[3]) self.long_min_spinbox.setValue(extent[0]) self.long_max_spinbox.setValue(extent[2]) self.lat_max_checkbox.setChecked(True) self.long_max_checkbox.setChecked(True) self.lat_min_checkbox.setChecked(True) self.long_min_checkbox.setChecked(True)