|
3 | 3 | import os
|
4 | 4 | from typing import TYPE_CHECKING, Callable, cast
|
5 | 5 |
|
6 |
| -from qgis.core import QgsProject, QgsVectorLayer |
7 | 6 | from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator
|
8 | 7 | from qgis.PyQt.QtGui import QIcon
|
9 | 8 | from qgis.PyQt.QtWidgets import QAction, QWidget
|
10 | 9 | from qgis.utils import iface
|
11 | 10 |
|
12 | 11 | from arho_feature_template.core.feature_template_library import FeatureTemplater, TemplateGeometryDigitizeMapTool
|
13 |
| -from arho_feature_template.core.update_plan import LandUsePlan, update_selected_plan |
| 12 | +from arho_feature_template.core.new_plan import NewPlan |
14 | 13 | from arho_feature_template.qgis_plugin_tools.tools.custom_logging import setup_logger, teardown_logger
|
15 | 14 | from arho_feature_template.qgis_plugin_tools.tools.i18n import setup_translation
|
16 | 15 | from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name
|
@@ -125,6 +124,7 @@ def add_action(
|
125 | 124 |
|
126 | 125 | def initGui(self) -> None: # noqa N802
|
127 | 126 | self.templater = FeatureTemplater()
|
| 127 | + self.new_plan = NewPlan() |
128 | 128 |
|
129 | 129 | plan_icon_path = os.path.join(PLUGIN_PATH, "resources/icons/city.png") # A placeholder icon
|
130 | 130 | load_icon_path = os.path.join(PLUGIN_PATH, "resources/icons/folder.png") # A placeholder icon
|
@@ -165,60 +165,8 @@ def on_map_tool_changed(self, new_tool: QgsMapTool, old_tool: QgsMapTool) -> Non
|
165 | 165 | if not isinstance(new_tool, TemplateGeometryDigitizeMapTool):
|
166 | 166 | self.template_dock_action.setChecked(False)
|
167 | 167 |
|
168 |
| - def clear_all_filters(self): |
169 |
| - """Clear filters for all vector layers in the project.""" |
170 |
| - layers = QgsProject.instance().mapLayers().values() |
171 |
| - |
172 |
| - for layer in layers: |
173 |
| - if isinstance(layer, QgsVectorLayer): |
174 |
| - layer.setSubsetString("") |
175 |
| - |
176 | 168 | def digitize_new_plan(self):
|
177 |
| - # Filtered layers are not editable, so clear filters first. |
178 |
| - self.clear_all_filters() |
179 |
| - # Find and set the "Kaava" layer |
180 |
| - layers = QgsProject.instance().mapLayersByName("Kaava") |
181 |
| - if not layers: |
182 |
| - iface.messageBar().pushMessage("Error", "Layer 'Kaava' not found", level=3) |
183 |
| - return |
184 |
| - |
185 |
| - kaava_layer = layers[0] |
186 |
| - |
187 |
| - if not kaava_layer.isEditable(): |
188 |
| - kaava_layer.startEditing() |
189 |
| - |
190 |
| - iface.setActiveLayer(kaava_layer) |
191 |
| - |
192 |
| - iface.actionAddFeature().trigger() |
193 |
| - kaava_layer.featureAdded.connect(self.feature_added) |
194 |
| - |
195 |
| - def feature_added(self): |
196 |
| - kaava_layer = iface.activeLayer() |
197 |
| - feature_ids_before_commit = kaava_layer.allFeatureIds() |
198 |
| - if kaava_layer.isEditable(): |
199 |
| - if not kaava_layer.commitChanges(): |
200 |
| - iface.messageBar().pushMessage("Error", "Failed to commit changes to the layer.", level=3) |
201 |
| - return |
202 |
| - else: |
203 |
| - iface.messageBar().pushMessage("Error", "Layer is not editable.", level=3) |
204 |
| - return |
205 |
| - feature_ids_after_commit = kaava_layer.allFeatureIds() |
206 |
| - |
207 |
| - # Finds the feature id that was committed by comparing ids before commit to features after commit. |
208 |
| - new_feature_id = next((fid for fid in feature_ids_after_commit if fid not in feature_ids_before_commit), None) |
209 |
| - if new_feature_id is not None: |
210 |
| - new_feature = kaava_layer.getFeature(new_feature_id) |
211 |
| - |
212 |
| - if new_feature.isValid(): |
213 |
| - feature_id_value = new_feature["id"] # UUID of the new feature |
214 |
| - iface.messageBar().pushMessage("Info", f"Feature 'id' field value: {feature_id_value}", level=0) |
215 |
| - |
216 |
| - # plan = LandUsePlan(feature_id_value) |
217 |
| - update_selected_plan(LandUsePlan(feature_id_value)) |
218 |
| - else: |
219 |
| - iface.messageBar().pushMessage("Error", "Invalid feature retrieved.", level=3) |
220 |
| - else: |
221 |
| - iface.messageBar().pushMessage("Error", "No new feature was added.", level=3) |
| 169 | + self.new_plan.add_new_plan() |
222 | 170 |
|
223 | 171 | def load_existing_land_use_plan(self) -> None:
|
224 | 172 | """Open existing land use plan."""
|
|
0 commit comments