Skip to content

Commit

Permalink
Move metadata along with layer when the layer is promoted to another …
Browse files Browse the repository at this point in the history
…feature #439
  • Loading branch information
KellyMWhitehead authored and philipbaileynar committed Oct 8, 2024
1 parent 9427b02 commit 0da267c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/view/frm_mask_aoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def promote_to_aoi(self, db_item: DBItem):

self.basepath, self.layer_name, self.layer_id = layer_path_parser(self.import_source_path)

metadata_json = json.dumps(db_item.metadata) if db_item.metadata is not None else None
self.metadata_widget.load_json(metadata_json)

def accept(self):

if not validate_name(self, self.txtName):
Expand Down
3 changes: 3 additions & 0 deletions src/view/frm_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def promote_to_profile(self, db_item: DBItem):

self.basepath, self.layer_name, self.layer_id = layer_path_parser(self.import_source_path)

metadata_json = json.dumps(db_item.metadata) if db_item.metadata is not None else None
self.metadata_widget.load_json(metadata_json)

def accept(self):

if not validate_name(self, self.txtName):
Expand Down
3 changes: 3 additions & 0 deletions src/view/frm_sample_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def promote_to_sample_frame(self, db_item: DBItem):
self.tabs.addTab(self.tab_inputs, "Inputs")
self.basepath, self.layer_name, self.layer_id = layer_path_parser(self.import_source_path)

metadata_json = json.dumps(db_item.metadata) if db_item.metadata is not None else None
self.metadata_widget.load_json(metadata_json)

def accept(self):

# validate name
Expand Down
3 changes: 3 additions & 0 deletions src/view/frm_valley_bottom.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def promote_to_valley_bottom(self, db_item: DBItem):

self.basepath, self.layer_name, self.layer_id = layer_path_parser(self.import_source_path)

metadata_json = json.dumps(db_item.metadata) if db_item.metadata is not None else None
self.metadata_widget.load_json(metadata_json)

def accept(self):

if not validate_name(self, self.txtName):
Expand Down
36 changes: 20 additions & 16 deletions src/view/widgets/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ def __init__(self, parent: QtWidgets.QDialog, json_meta: str = None, new_keys: l
self.attribute_metadat = dict()
self.table: QtWidgets.QTableWidget = None

self.create_table_ui()

if json_meta is not None and json_meta != '' and json_meta != 'null':
self.load_json(json_meta)

self.create_table_ui()

def load_json(self, json_meta: str):

self.json_meta = json_meta
self.metadata = json.loads(self.json_meta)
if json_meta is not None and json_meta != '' and json_meta != 'null':
self.metadata = json.loads(self.json_meta)
self.check_metadata()
self.load_table()

def add_metadata(self, key: str, value: str):

Expand Down Expand Up @@ -85,19 +87,6 @@ def create_table_ui(self):
self.table.setAlternatingRowColors(True)
self.table.setSortingEnabled(True)

if self.metadata is not None:
if 'metadata' in self.metadata:
for key, value in self.metadata['metadata'].items():
self.table.insertRow(self.table.rowCount())
self.table.setItem(self.table.rowCount() - 1, 0, QtWidgets.QTableWidgetItem(key))
label_widget = MetadataValueLabel(str(value))
self.table.setCellWidget(self.table.rowCount() - 1, 1, label_widget)

if self.new_keys is not None:
for key in self.new_keys:
self.table.insertRow(self.table.rowCount())
self.table.setItem(self.table.rowCount() - 1, 0, QtWidgets.QTableWidgetItem(key))

self.cmdAdd = QtWidgets.QPushButton()
self.cmdAdd.setText('Add')
self.cmdAdd.setToolTip('Add a new key/value pair')
Expand All @@ -119,6 +108,21 @@ def create_table_ui(self):
self.horiz.addLayout(self.vert)
self.horiz.addWidget(self.table)

def load_table(self):

if self.metadata is not None:
if 'metadata' in self.metadata:
for key, value in self.metadata['metadata'].items():
self.table.insertRow(self.table.rowCount())
self.table.setItem(self.table.rowCount() - 1, 0, QtWidgets.QTableWidgetItem(key))
label_widget = MetadataValueLabel(str(value))
self.table.setCellWidget(self.table.rowCount() - 1, 1, label_widget)

if self.new_keys is not None:
for key in self.new_keys:
self.table.insertRow(self.table.rowCount())
self.table.setItem(self.table.rowCount() - 1, 0, QtWidgets.QTableWidgetItem(key))

def add_row(self):

self.table.insertRow(self.table.rowCount())
Expand Down

0 comments on commit 0da267c

Please sign in to comment.