diff --git a/src/ui/MainWindow.py b/src/ui/MainWindow.py index 36f7522..c2965a6 100644 --- a/src/ui/MainWindow.py +++ b/src/ui/MainWindow.py @@ -1226,6 +1226,9 @@ class MainWindow(QMainWindow): print(f"{len(self.pdf_project.nodes)} Root-Nodes in TreeWidget geladen (alphabetisch sortiert)") + # Aktualisiere Diff-PDF-Anzahl nach dem Laden + self._update_all_diff_pdf_counts() + except Exception as e: print(f"Fehler beim Laden der Nodes in TreeWidget: {e}") @@ -1268,6 +1271,11 @@ class MainWindow(QMainWindow): child_item = self._create_tree_item_from_node(child) item.addChild(child_item) + # Setze Diff-PDF-Anzahl in Spalte 2 (wird später aktualisiert) + diff_count = self._count_diff_pdfs_under_node(node, item) + if diff_count > 0: + item.setText(2, str(diff_count)) + elif isinstance(node, XslFile): # XslFile: Zeige XSL-Datei-Pfad item.setText(1, str(node.xsl_file)) @@ -1275,6 +1283,11 @@ class MainWindow(QMainWindow): # Speichere zusätzlich die Node-ID in UserRole+1 für Kompatibilität item.setData(0, Qt.ItemDataRole.UserRole + 1, node.id) + # Setze Diff-PDF-Anzahl in Spalte 2 (wird später aktualisiert) + diff_count = self._count_diff_pdfs_under_node(node, item) + if diff_count > 0: + item.setText(2, str(diff_count)) + # Lade XML-Dateien als Knoten if node.xmls: for xml in node.xmls: @@ -3093,6 +3106,73 @@ class MainWindow(QMainWindow): logger.error(f"Fehler beim Transformieren der XSL-Datei: {e}") QMessageBox.critical(self, "Fehler", f"Fehler beim Transformieren: {str(e)}") + def _count_diff_pdfs_under_node(self, node: TreeNode | XslFile, node_item: QTreeWidgetItem) -> int: + """ + Zählt die Anzahl der existierenden Diff-PDFs unter einem Knoten. + + Args: + node: TreeNode oder XslFile Objekt + node_item: Das TreeWidgetItem des Knotens + + Returns: + int: Anzahl der existierenden Diff-PDF-Dateien + """ + count = 0 + + if isinstance(node, XslFile): + # Für XslFile: Zähle Diff-PDFs für jede XML-Datei + if not self.project: + return 0 + + diff_dir = self.project.project_dir / "diff" + xsl_id_str = "_".join(str(x) for x in node.id) if node.id else "" + + for xml_file_obj in node.xmls: + xml_stem = xml_file_obj.xml.stem + pdf_basename = f"{xml_stem}_xsl_{xsl_id_str}.pdf" + diff_pdf_path = diff_dir / pdf_basename + + if diff_pdf_path.exists(): + count += 1 + + elif isinstance(node, TreeNode): + # Für TreeNode: Rekursiv alle Kinder durchgehen + for i in range(node_item.childCount()): + child_item = node_item.child(i) + child_node = child_item.data(0, Qt.ItemDataRole.UserRole) + + if isinstance(child_node, (XslFile, TreeNode)): + count += self._count_diff_pdfs_under_node(child_node, child_item) + + return count + + def _update_diff_pdf_counts_recursive(self, tree_item: QTreeWidgetItem): + """ + Aktualisiert rekursiv die Diff-PDF-Anzahl in Spalte 2 für alle TreeNode und XslFile Items. + + Args: + tree_item: Das TreeWidgetItem (kann Root oder beliebiger Knoten sein) + """ + node = tree_item.data(0, Qt.ItemDataRole.UserRole) + + # Aktualisiere nur für TreeNode und XslFile, nicht für XmlFile + if isinstance(node, (TreeNode, XslFile)): + count = self._count_diff_pdfs_under_node(node, tree_item) + tree_item.setText(2, str(count) if count > 0 else "") + + # Rekursiv für alle Kinder + for i in range(tree_item.childCount()): + child_item = tree_item.child(i) + self._update_diff_pdf_counts_recursive(child_item) + + def _update_all_diff_pdf_counts(self): + """ + Aktualisiert die Diff-PDF-Anzahl für alle Knoten im TreeWidget. + """ + root = self.ui.treeWidget.invisibleRootItem() + for i in range(root.childCount()): + self._update_diff_pdf_counts_recursive(root.child(i)) + def _has_xml_files_recursive(self, node: TreeNode) -> bool: """ Prüft rekursiv, ob unter einem TreeNode mindestens eine XML-Datei vorhanden ist. @@ -3456,6 +3536,9 @@ class MainWindow(QMainWindow): """ logger.info(f"Alle Transformationen abgeschlossen: {successful_count}/{total_count} erfolgreich") + # Aktualisiere Diff-PDF-Anzahl in allen Knoten + self._update_all_diff_pdf_counts() + if successful_count == total_count: self.statusBar().showMessage(f"✓ Alle {total_count} Transformationen erfolgreich", 5000) QMessageBox.information(