Skip to content

Commit

Permalink
try to edit the addlayerstask
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Feb 8, 2024
1 parent f663ca7 commit 74c47ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(self):
log_dir_path = home_dir / "Downloads" / "REMEDY" / "log"
self.logger = CustomLogger(log_dir_path, "BegrensSkadeII_QGIS_EXCAVATION.log", "EXCAVATION_LOGGER").get_logger()
self.logger.info(f"__INIT__ - Finished initialize BegrensSkadeExcavation ")
self.add_layers_task = AddLayersTask()

# Constants used to refer to parameters and outputs. They will be
# used when calling the algorithm from another algorithm, or when
Expand Down Expand Up @@ -706,7 +707,7 @@ def processAlgorithm(self, parameters, context, feedback):

######### EXPERIMENTAL ADD LAYERS TO GUI #########
# Create the task
add_layers_task = AddLayersTask("Add Layers", layers_info, feature_name, styles_dir_path, self.logger)
self.add_layers_task.setParameters(layers_info, feature_name, styles_dir_path, self.logger)
# Local event loop
loop = QEventLoop()
# Define a slot to handle the task completion
Expand All @@ -718,15 +719,15 @@ def onTaskCompleted(success):
loop.quit() # Quit the event loop

# Connect the task's completed signal to the slot
add_layers_task.taskCompleted.connect(onTaskCompleted)
self.add_layers_task.taskCompleted.connect(onTaskCompleted)

# Start the task
QgsApplication.taskManager().addTask(add_layers_task)
QgsApplication.taskManager().addTask(self.add_layers_task)
# Start the event loop
loop.exec_()

# Check if the task was successful
if not add_layers_task.completed:
if not self.add_layers_task.completed:
raise QgsProcessingException("Error occurred while adding layers.")

feedback.setProgress(100)
Expand Down
14 changes: 10 additions & 4 deletions geovita_processing_plugin/utilities/AddLayersTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AddLayersTask(QgsTask):

taskCompleted = pyqtSignal(bool)

def __init__(self, description: str, layers_info: list[tuple[str, str, str]], group_name: str, styles_dir_path: Path, logger: logger.CustomLogger) -> None:
def __init__(self) -> None:
"""
Initializes the AddLayersTask.
Expand All @@ -40,13 +40,19 @@ def __init__(self, description: str, layers_info: list[tuple[str, str, str]], gr
styles_dir_path (Path): The directory path where style files are located.
logger (Logger): Logger for logging messages.
"""
super().__init__(description, QgsTask.CanCancel)
super().__init__("Add Layers Task", QgsTask.CanCancel)
self.layers_info = []
self.group_name = ""
self.styles_dir_path = None
self.logger = None
self.prepared_layers = [] # Initialize prepared layers list
self.completed = False

def setParameters(self, layers_info, group_name, styles_dir_path, logger):
self.layers_info = layers_info
self.group_name = group_name
self.styles_dir_path = styles_dir_path
self.logger = logger
self.prepared_layers = [] # Initialize prepared layers list
self.completed = False

def run(self) -> bool:
"""
Expand Down

0 comments on commit 74c47ad

Please sign in to comment.