Profiles: new functionnality, navigate between differents profiles (next and previous one) directly in the edit profile window

mesh_tab
JeaDylan 2026-08-20 22:17:49 +02:00
parent ef5430ae2c
commit 587e5412d5
2 changed files with 103 additions and 0 deletions

View File

@ -128,6 +128,15 @@ class ProfileWindow(PamhyrWindow):
self._tablemodel.blockSignals(False)
def setup_connections(self):
navigation_actions = {
"action_previous_profile": self.previous_profile,
"action_next_profile": self.next_profile,
}
for action in navigation_actions:
self.find(QAction, action)\
.triggered.connect(navigation_actions[action])
if self._study.is_read_only():
actions = {}
else:
@ -152,6 +161,73 @@ class ProfileWindow(PamhyrWindow):
.connect(self.update_points_selection)
self._tablemodel.dataChanged.connect(self.update)
self.update_navigation_actions()
def previous_profile(self):
self.navigate_profile(-1)
def next_profile(self):
self.navigate_profile(1)
def profiles(self):
"""Return profiles from the geometry model owning this profile."""
return self._profile.reach.reach.profiles
def navigate_profile(self, offset):
profiles = self.profiles()
try:
index = profiles.index(self._profile)
except ValueError:
self.update_navigation_actions()
return
target_index = index + offset
if not 0 <= target_index < len(profiles):
self.update_navigation_actions()
return
target = profiles[target_index]
if self._parent is not None and self._parent.sub_window_exists(
ProfileWindow,
data=[self._study, self._config, target]
):
self.close()
return
self.set_profile(target)
def set_profile(self, profile):
self._profile = profile
self._hash_data[-1] = profile
self._undo_stack.clear()
self._tablemodel.beginResetModel()
self._tablemodel._data = profile
self._tablemodel.endResetModel()
self._plot.data = profile
self._plot.highlight = None
self._plot.draw()
self._title = (
self._trad[self._pamhyr_name] +
f" - {profile.name} {profile.rk}"
)
self._set_title()
self.update_navigation_actions()
def update_navigation_actions(self):
profiles = self.profiles()
try:
index = profiles.index(self._profile)
except ValueError:
index = -1
self.find(QAction, "action_previous_profile")\
.setEnabled(index > 0)
self.find(QAction, "action_next_profile")\
.setEnabled(0 <= index < len(profiles) - 1)
def update_points_selection(self):
rows = self.index_selected_rows()

View File

@ -52,6 +52,9 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="action_previous_profile"/>
<addaction name="action_next_profile"/>
<addaction name="separator"/>
<addaction name="action_add"/>
<addaction name="action_delete"/>
<addaction name="action_sort_asc"/>
@ -61,6 +64,30 @@
<addaction name="action_purge"/>
<addaction name="action_reverse"/>
</widget>
<action name="action_previous_profile">
<property name="icon">
<iconset>
<normaloff>ressources/left.png</normaloff>ressources/left.png</iconset>
</property>
<property name="text">
<string>Previous profile</string>
</property>
<property name="toolTip">
<string>Open the previous profile</string>
</property>
</action>
<action name="action_next_profile">
<property name="icon">
<iconset>
<normaloff>ressources/right.png</normaloff>ressources/right.png</iconset>
</property>
<property name="text">
<string>Next profile</string>
</property>
<property name="toolTip">
<string>Open the next profile</string>
</property>
</action>
<action name="action_add">
<property name="icon">
<iconset>