Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/merge tab mirror compare #34

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions comparator/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
get_visible_layers,
toggle_layers,
get_map_dockwidgets,
get_right_dockwidgets,
set_panel_width,
)

# Syncronize flag to avoid recursive map sync and crash
Expand Down Expand Up @@ -219,6 +221,35 @@ def compare_with_mapview(compare_layers: list) -> None:
QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable
)

# Tabify right panels layouts Tabify with other Docks in right side
right_dock_widgets = get_right_dockwidgets()

# Calculate size of tabified docks to be half of window
if len(right_dock_widgets) > 0:
max_width = max(dw.geometry().width() for dw in right_dock_widgets)
else:
max_width = 0
compare_map_size = (iface.mapCanvas().size().width() + max_width) / 2

# Do only if there are more than 1 dock widget (1 is mirror compare map panel)
if len(right_dock_widgets) > 1:
base_dock = right_dock_widgets[0] # the one to tabify the others onto
for i in range(1, len(right_dock_widgets)):
if right_dock_widgets[i].windowTitle() == mirror_widget_name:
mirror_dock_widget = right_dock_widgets[i]
set_panel_width(mirror_dock_widget, compare_map_size)
else:
main_window.tabifyDockWidget(base_dock, right_dock_widgets[i])

# add mirror map at last to be active
if mirror_dock_widget:
main_window.tabifyDockWidget(base_dock, mirror_dock_widget)

else:
# Case of if there is no other panel in right side
set_panel_width(right_dock_widgets[0], compare_map_size)
mirror_widget.refresh()

# Add Map themes
mapThemesCollection = QgsProject.instance().mapThemeCollection()
mapThemeRecord = QgsMapThemeCollection.createThemeFromCurrentState(
Expand Down
26 changes: 26 additions & 0 deletions comparator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from qgis.PyQt.QtWidgets import QDockWidget
from qgis.utils import iface
from qgis.PyQt.QtCore import Qt

from .constants import lens_auto_refresh_interval_time

Expand Down Expand Up @@ -80,3 +81,28 @@ def get_map_dockwidgets() -> list:
if dock.findChild(QgsMapCanvas):
map_widgets.append(dock.findChild(QgsMapCanvas))
return map_widgets


def get_right_dockwidgets() -> list:
"""Get visible dockwidgets located in right side of QGIS window"""
main_window = iface.mainWindow()

right_dock_widgets = []
for dock in main_window.findChildren(QDockWidget):
# Check which side (dock area) the widget is in
dock_area = main_window.dockWidgetArea(dock)
if dock_area == Qt.RightDockWidgetArea and dock.isVisible():
right_dock_widgets.append(dock)

return right_dock_widgets


def set_panel_width(widget: QDockWidget, size: int) -> None:
"""Set panel width, and allow afterhand size edit"""
widget.setFixedWidth(size)

# Remove fix width to allow width to be editable
widget.setMinimumWidth(100)
widget.setMaximumWidth(10000)

return