From 701f6b3292d383394500755d7be1639e130c7962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20R=C3=A9aux?= Date: Fri, 6 Feb 2026 11:13:29 +0100 Subject: [PATCH] fix remove round used in sector --- src/warchron/controller/dtos.py | 4 ++-- src/warchron/model/campaign.py | 5 ++++- src/warchron/model/model.py | 4 +++- src/warchron/model/sector.py | 4 ++-- src/warchron/view/helpers.py | 2 +- src/warchron/view/sector_dialog.py | 3 ++- src/warchron/view/view.py | 2 +- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/warchron/controller/dtos.py b/src/warchron/controller/dtos.py index cf063bd..48e2749 100644 --- a/src/warchron/controller/dtos.py +++ b/src/warchron/controller/dtos.py @@ -62,7 +62,7 @@ class CampaignParticipantDTO: class SectorDTO: id: str name: str - round_index: int + round_index: int | None major: str minor: str influence: str @@ -71,7 +71,7 @@ class SectorDTO: @dataclass class RoundDTO: id: str - index: int + index: int | None @dataclass(frozen=True, slots=True) diff --git a/src/warchron/model/campaign.py b/src/warchron/model/campaign.py index 84e680f..82aea5c 100644 --- a/src/warchron/model/campaign.py +++ b/src/warchron/model/campaign.py @@ -269,10 +269,13 @@ class Campaign: def remove_round(self, round_id: str) -> None: rnd = next((r for r in self.rounds if r.id == round_id), None) + for sect in self.sectors.values(): + if sect.round_id == round_id: + sect.round_id = None if rnd: self.rounds.remove(rnd) - def get_round_index(self, round_id: str) -> int: + def get_round_index(self, round_id: str | None) -> int | None: if round_id is None: return None for index, rnd in enumerate(self.rounds, start=1): diff --git a/src/warchron/model/model.py b/src/warchron/model/model.py index 1f448b3..77abd42 100644 --- a/src/warchron/model/model.py +++ b/src/warchron/model/model.py @@ -380,7 +380,9 @@ class Model: return rnd raise KeyError("Round not found") - def get_round_index(self, round_id: str) -> int: + def get_round_index(self, round_id: str | None) -> int | None: + if round_id is None: + return None camp = self.get_campaign_by_round(round_id) return camp.get_round_index(round_id) diff --git a/src/warchron/model/sector.py b/src/warchron/model/sector.py index f367c8c..65e8895 100644 --- a/src/warchron/model/sector.py +++ b/src/warchron/model/sector.py @@ -7,14 +7,14 @@ class Sector: def __init__( self, name: str, - round_id: str, + round_id: str | None, major_id: str | None, minor_id: str | None, influence_id: str | None, ): self.id: str = str(uuid4()) self.name: str = name - self.round_id: str = round_id + self.round_id: str | None = round_id self.major_objective_id: str | None = major_id # ref to War.objectives self.minor_objective_id: str | None = minor_id # ref to War.objectives self.influence_objective_id: str | None = influence_id # ref to War.objectives diff --git a/src/warchron/view/helpers.py b/src/warchron/view/helpers.py index 3e2f585..35d38a5 100644 --- a/src/warchron/view/helpers.py +++ b/src/warchron/view/helpers.py @@ -21,7 +21,7 @@ def format_campaign_label(camp: CampaignDTO) -> str: return f"{camp.name} ({calendar.month_name[camp.month]})" -def format_round_label(index: int) -> str: +def format_round_label(index: int | None) -> str: if index is None: return "" return f"Round {index}" diff --git a/src/warchron/view/sector_dialog.py b/src/warchron/view/sector_dialog.py index 74312dd..66d0194 100644 --- a/src/warchron/view/sector_dialog.py +++ b/src/warchron/view/sector_dialog.py @@ -23,10 +23,11 @@ class SectorDialog(QDialog): super().__init__(parent) self.ui: Ui_sectorDialog = Ui_sectorDialog() self.ui.setupUi(self) # type: ignore + self.ui.sectorName.setText(default_name) self.ui.majorComboBox.addItem("(none)", None) self.ui.minorComboBox.addItem("(none)", None) self.ui.influenceComboBox.addItem("(none)", None) - self.ui.sectorName.setText(default_name) + self.ui.roundComboBox.addItem("(none)", None) for index, rnd in enumerate(rounds, start=1): self.ui.roundComboBox.addItem(format_round_label(index), rnd.id) select_if_exists(self.ui.roundComboBox, default_round_id) diff --git a/src/warchron/view/view.py b/src/warchron/view/view.py index 8a86271..ca2afc4 100644 --- a/src/warchron/view/view.py +++ b/src/warchron/view/view.py @@ -448,7 +448,7 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow): if action == edit_action and self.on_edit_item: self.on_edit_item(ItemType.BATTLE, battle_id) - def show_round_details(self, *, index: int) -> None: + def show_round_details(self, *, index: int | None) -> None: self.roundNb.setText(f"Round {index}") def display_round_choices(self, participants: List[ChoiceDTO]) -> None: