Skip to content

Add editable checkbox and enable row insertion/deletion for impact categories#1589

Merged
mrvisscher merged 11 commits intomajorfrom
copilot/add-checkbox-for-editable-mode
Oct 23, 2025
Merged

Add editable checkbox and enable row insertion/deletion for impact categories#1589
mrvisscher merged 11 commits intomajorfrom
copilot/add-checkbox-for-editable-mode

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 16, 2025

Summary

Fixes the issue where impact assessment characterization factors could be modified accidentally, and adds the ability to insert and delete rows from impact categories.

Problem

Previously, impact category characterization factors were always editable with no protection mechanism, leading to potential accidental modifications. Additionally, there was no way to add new characterization factors or remove existing ones directly from the impact category view.

Solution

This PR implements three key features:

1. Editable Checkbox for Protection

Added a checkbox labeled "Editable" to the impact category header that acts as a safety gate:

  • Default state: Unchecked (read-only mode)
  • Purpose: Prevents accidental modifications to characterization factors
  • Behavior: Must be explicitly checked to enable any editing operations

2. Row Deletion via Context Menu

When the editable checkbox is checked:

  • Right-click on selected rows shows "Remove characterization factor(s)" option
  • Confirmation dialog prevents accidental deletions
  • Uses existing CFRemove action for consistency

3. Row Insertion via Drag-and-Drop

When the editable checkbox is checked:

  • Drag biosphere flows from database explorer and drop onto the impact category table
  • Automatically filters to only accept biosphere flows (emissions, natural resources, etc.)
  • Technosphere products are filtered out
  • New characterization factors are added with default amount of 0.0
  • Uses existing CFNew action for consistency

Implementation Details

Files Modified:

  • impact_category_header.py: Added editable checkbox widget and state change callback (+17 lines)
  • impact_category_details.py: Added state tracking, context menu, drag-drop support, and conditional editability (+65 lines)

Key Design Decisions:

  • Checkbox defaults to unchecked for safety (prevents accidental changes on every open)
  • State is not persisted between sessions (always starts in safe read-only mode)
  • Only biosphere flows can be added (follows LCIA method conventions)
  • Cell editability is conditional on checkbox state (amount and uncertainty fields)
  • Integrated with existing ABAction and ABMenu infrastructure

Changes in Behavior

Feature Before After
Default state Always editable Read-only by default
Accidental edits Easy to make Prevented by checkbox
Adding rows Not available ✅ Drag-and-drop (when editable)
Deleting rows Not available ✅ Context menu (when editable)
Edit protection None ✅ Checkbox required

Usage Example

# To add a new characterization factor:
1. Open an impact category (e.g., "IPCC 2013 | climate change | GWP 100a")
2. Check the "Editable" checkbox
3. Open biosphere3 database
4. Drag "Methane" emission to the impact category table
5. Drop itNew row appears with amount = 0.0
6. Double-click amount cell to edit value
7. Uncheck "Editable" when done to prevent accidental changes

# To delete characterization factors:
1. Open an impact category
2. Check the "Editable" checkbox
3. Select one or more rows
4. Right-click"Remove characterization factor(s)"
5. Confirm deletion

Backward Compatibility

Fully backward compatible - no breaking changes:

  • All existing functionality preserved
  • No new dependencies added
  • Works with all existing databases and impact categories
  • Default behavior is safe (read-only)

Testing

Manual testing required to verify:

  • Checkbox appears and toggles correctly in impact category header
  • Read-only mode (unchecked) prevents all editing, deletion, and drag-drop operations
  • Editable mode (checked) enables all modification operations
  • Drag-and-drop correctly filters biosphere vs. technosphere flows
  • Context menu delete works with proper confirmation dialog
  • Multiple open impact categories maintain independent editable states

Closes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Impact Category Modification - Cannot add / remove biosphere rows</issue_title>
<issue_description>### What do you want to report?

When duplicating an impact assessment method, before there was a checkbox to make it editable, then rows could be added/removed and amounts could be changed. Could you

  • re-add the checkbox, such that we won't change impact assessment characterisation factors by accident?
  • enable the deletion and insertion of rows to the impact categories, when in editable mode

Thank you!

Relevant errors

Version

3.0.0b1091

Installation method

Anaconda (conda)

Operating system

Windows 10</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #1588


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 16, 2025 11:35
- Added editable checkbox to impact category header to control editing state
- Implemented context menu with delete option for characterization factors
- Added drag-and-drop support for adding biosphere flows to impact categories
- Conditional editing: amount and uncertainty fields only editable when checkbox is checked
- All functionality gated behind editable state to prevent accidental modifications

Co-authored-by: mrvisscher <103424764+mrvisscher@users.noreply.github.com>
- Use is_node_biosphere utility function for cleaner biosphere flow filtering
- Simplify dropEvent implementation with list comprehension

Co-authored-by: mrvisscher <103424764+mrvisscher@users.noreply.github.com>
Copilot AI changed the title [WIP] Add checkbox for editable impact assessment method Add editable checkbox and enable row insertion/deletion for impact categories Oct 16, 2025
Copilot AI requested a review from mrvisscher October 16, 2025 11:48
@mrvisscher mrvisscher marked this pull request as ready for review October 23, 2025 11:04
@mrvisscher mrvisscher merged commit d425ece into major Oct 23, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants