0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

fix: replace add'l md table w/ tree view

This commit is contained in:
2025-02-17 13:02:48 +01:00
committed by wyzula_j
parent 209c898e3d
commit 42665b69c5
2 changed files with 10 additions and 5 deletions

View File

@ -2,13 +2,14 @@ from __future__ import annotations
from typing import Any
from PySide6.QtWidgets import QSizePolicy
from qtpy.QtCore import QAbstractTableModel, QModelIndex, Qt, Signal # type: ignore
from qtpy.QtWidgets import (
QApplication,
QHBoxLayout,
QLabel,
QPushButton,
QTableView,
QTreeView,
QVBoxLayout,
QWidget,
)
@ -105,9 +106,11 @@ class AdditionalMetadataTable(QWidget):
self._layout = QHBoxLayout()
self.setLayout(self._layout)
self._table_model = AdditionalMetadataTableModel(initial_data)
self._table_view = QTableView()
self._table_view = QTreeView()
self._table_view.setModel(self._table_model)
self._table_view.horizontalHeader().setStretchLastSection(True)
self._table_view.setSizePolicy(
QSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum)
)
self._layout.addWidget(self._table_view)
self._buttons = QVBoxLayout()

View File

@ -1,11 +1,12 @@
from decimal import Decimal
from typing import Annotated
from PySide6.QtCore import QItemSelectionModel, QModelIndex, QRect
import pytest
from bec_lib.metadata_schema import BasicScanMetadata
from pydantic import Field
from pydantic.types import Json
from qtpy.QtCore import Qt
from qtpy.QtCore import QPoint, Qt
from qtpy.QtWidgets import QCheckBox, QDoubleSpinBox, QLineEdit, QSpinBox, QWidget
from bec_widgets.widgets.editors.scan_metadata import AdditionalMetadataTableModel, ScanMetadata
@ -189,7 +190,8 @@ def test_additional_metadata_table_add_row(table: AdditionalMetadataTable):
def test_additional_metadata_table_delete_row(table: AdditionalMetadataTable):
assert table._table_model.rowCount() == 3
table._table_view.selectRow(1)
m = table._table_view.selectionModel()
m.select(table._table_view.indexAt(QPoint(40, 30)), QItemSelectionModel.SelectionFlag.Select)
table.delete_selected_rows()
assert table._table_model.rowCount() == 2
assert list(table.dump_dict().keys()) == ["key1", "key3"]