diff --git a/geest/gui/layer_details_dialog.py b/geest/gui/layer_details_dialog.py index 63fed6bc..86ad9cd3 100644 --- a/geest/gui/layer_details_dialog.py +++ b/geest/gui/layer_details_dialog.py @@ -1,55 +1,34 @@ -import sys -import os -import json -# Change to this when implementing in QGIS -#from qgis.PyQt.QtWidgets import ( from qgis.PyQt.QtWidgets import ( - QAbstractItemDelegate, - QApplication, - QTreeView, - QMainWindow, + QDialog, QVBoxLayout, - QWidget, - QFileDialog, - QMessageBox, - QHeaderView, + QLabel, + QTableWidget, + QTableWidgetItem, QPushButton, + QHeaderView, + QLineEdit, + QCheckBox, + QSpinBox, + QDoubleSpinBox, + QComboBox, QHBoxLayout, - QTableWidget, - QTableWidgetItem, - QMenu, - QAction, - QDialog, - QLabel, QTextEdit, ) -# Change to this when implementing in QGIS -#from qgis.PyQt.QtCore import ( -from qgis.PyQt.QtCore import ( - QAbstractItemModel, - QModelIndex, - Qt, - QFileSystemWatcher, - QPoint, - QEvent, - QTimer, - pyqtSignal, - Qt -) -# Change to this when implementing in QGIS -#from qgis.PyQt.QtGui import ( -from qgis.PyQt.QtGui import QColor, QColor, QMovie +from qgis.PyQt.QtCore import Qt, pyqtSignal +from .toggle_switch import ToggleSwitch class LayerDetailDialog(QDialog): - """Dialog to show layer properties.""" - + """Dialog to show layer properties, with a Markdown editor for the 'indicator' field.""" + # Signal to emit the updated data as a dictionary dataUpdated = pyqtSignal(dict) - - def __init__(self, layer_name, layer_data, parent=None): + + def __init__(self, layer_name, layer_data, tree_item, parent=None): super().__init__(parent) self.setWindowTitle(layer_name) + self.layer_data = layer_data + self.tree_item = tree_item # Reference to the QTreeView item to update layout = QVBoxLayout() @@ -57,30 +36,34 @@ def __init__(self, layer_name, layer_data, parent=None): heading_label = QLabel(layer_name) layout.addWidget(heading_label) - # Description for the dialog - description_text = QTextEdit( - layer_data["indicator"] if "indicator" in layer_data else "") - description_text.setReadOnly(True) - layout.addWidget(description_text) + # Create the QTextEdit for Markdown editing + self.text_edit = QTextEdit() + self.text_edit.setPlainText(layer_data.get("indicator", "")) + self.text_edit.setMinimumHeight(100) # Set at least 5 lines high + layout.addWidget(self.text_edit) + + # Create a layout for the toggle and label at the bottom-right of the text edit + toggle_layout = QHBoxLayout() + toggle_layout.addStretch() # Push to the right - # Create the QTableWidget + # Add the toggle switch and "Edit" label + self.edit_mode_toggle = ToggleSwitch(initial_value=True) + self.edit_mode_toggle.toggled.connect(self.toggle_edit_mode) + toggle_layout.addWidget(QLabel("Edit")) + toggle_layout.addWidget(self.edit_mode_toggle) + + layout.addLayout(toggle_layout) + + # Set the initial mode to edit mode + self.is_edit_mode = True + + # Create the QTableWidget for other properties self.table = QTableWidget() self.table.setColumnCount(2) # Two columns (Key and Value) - self.table.setHorizontalHeaderLabels(["Key", "Value"]) + self.table.setHorizontalHeaderLabels(["Property", "Value"]) - # Set the number of rows equal to the number of key-value pairs - self.table.setRowCount(len(layer_data)) - - # Populate the table with key-value pairs - for row, (key, value) in enumerate(layer_data.items()): - # Column 1: Key (read-only) - key_item = QTableWidgetItem(str(key)) - key_item.setFlags(key_item.flags() & ~Qt.ItemIsEditable) # Make it read-only - self.table.setItem(row, 0, key_item) - - # Column 2: Value (editable) - value_item = QTableWidgetItem(str(value)) - self.table.setItem(row, 1, value_item) + # Set the number of rows equal to the number of key-value pairs, excluding 'indicator' + self.populate_table() # Set column resize mode to stretch to fill the layout header = self.table.horizontalHeader() @@ -97,10 +80,81 @@ def __init__(self, layer_name, layer_data, parent=None): self.setLayout(layout) + def populate_table(self): + """Populate the table with all key-value pairs except 'indicator'.""" + filtered_data = {k: v for k, v in self.layer_data.items() if k != "indicator"} + self.table.setRowCount(len(filtered_data)) + + for row, (key, value) in enumerate(filtered_data.items()): + # Column 1: Key (Property name, read-only) + key_item = QTableWidgetItem(str(key)) + key_item.setFlags(key_item.flags() & ~Qt.ItemIsEditable) # Make it read-only + self.table.setItem(row, 0, key_item) + + # Column 2: Value (use appropriate widgets based on data type) + value_widget = self.get_widget_for_value(key, value) + self.table.setCellWidget(row, 1, value_widget) + + def toggle_edit_mode(self, checked): + """Switch between edit mode (plain text) and display mode (render as HTML).""" + if checked: + # In Edit Mode: Show plain text to allow Markdown writing + self.is_edit_mode = True + self.text_edit.setReadOnly(False) + self.text_edit.setPlainText(self.text_edit.toPlainText()) # Reset to plain text + else: + # In Display Mode: Render Markdown as HTML + self.is_edit_mode = False + self.text_edit.setReadOnly(True) + markdown_text = self.text_edit.toPlainText() + + # Render basic Markdown elements as HTML + rendered_html = markdown_text.replace("# ", "