Skip to content

Commit

Permalink
Merge pull request #17 from GIAPspzoo/main_Patryk_zbieranie_sekcji
Browse files Browse the repository at this point in the history
Main patryk zbieranie sekcji
  • Loading branch information
eryk918 authored Jul 19, 2022
2 parents 4323bd7 + deaf675 commit f388aad
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
25 changes: 23 additions & 2 deletions SectionManager/CustomSectionManager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
import os
from datetime import datetime
from typing import List, Union, Set
Expand All @@ -6,10 +7,12 @@
from qgis.PyQt.QtCore import QModelIndex
from qgis.PyQt.QtCore import QSortFilterProxyModel
from qgis.PyQt.QtGui import QStandardItemModel, QStandardItem
from qgis.PyQt.QtWidgets import QDialog
from qgis.PyQt.QtWidgets import QDialog, QToolBar, QAction
from qgis.utils import iface

from ..utils import STANDARD_TOOLS, unpack_nested_lists, Qt, tr, \
icon_manager, CustomMessageBox, get_tool_label, GIAP_CUSTOM_TOOLS
icon_manager, CustomMessageBox, get_tool_label, GIAP_CUSTOM_TOOLS, get_action_from_toolbar, \
find_widget_with_menu_in_toolbar

FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'UI/add_section_dialog.ui'))
Expand Down Expand Up @@ -41,8 +44,12 @@ def add_available_tools_into_list(self) -> None:
unpack_nested_lists([tool['btns'] for tool in STANDARD_TOOLS]))
tools = list(
set([tool for tool in tmp_tools_list if isinstance(tool, str)]))
toolbar_tools = [tool.objectName() for tool in self.get_all_actions_from_qgis_toolbars()]
[tools.append(tool) for tool in toolbar_tools if tool not in tools]
tools.sort()
for tool in tools:
if not tool:
continue
item = QStandardItem(
tr(get_tool_label(tool, self.main_qgs_widget)))
item.setData(icon_manager([tool], self.main_qgs_widget)[tool],
Expand All @@ -58,6 +65,20 @@ def add_available_tools_into_list(self) -> None:
self.availableToolTable.hideColumn(0)
self.selectedToolTable.hideColumn(0)

def get_all_actions_from_qgis_toolbars(self) -> List[QAction]:
qgis_toolbars = [toolbar for toolbar in iface.mainWindow().findChildren(QToolBar)
if "toolbar" in toolbar.objectName().lower() and "giap" not in toolbar.objectName().lower()]
actions = []
for toolbar in qgis_toolbars:
acts = get_action_from_toolbar(toolbar)
widgs = find_widget_with_menu_in_toolbar(toolbar)
for widg in widgs:
[acts.append(act) for act in widg.actions()]
actions.append(acts)

all_actions = list(itertools.chain(*actions))
return all_actions

def prepare_selected_tools_list(self) -> List[str or int]:
btns_list = []
row = 0
Expand Down
21 changes: 13 additions & 8 deletions giap_dynamic_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def __init__(self, parent: QtWidgets=None) -> None:
self.icon_timer.setInterval(1)
iface.currentLayerChanged.connect(self.icon_timer.start)

icon = icon_manager(['giapAreaLength'], self.parent)['giapAreaLength']
self.area_length_event = AreaAndLengthTool(iface)
self.area_length_action = QAction(QIcon(icon),None, iface.mainWindow())
self.area_length_action.setCheckable(True)
self.area_length_action.triggered.connect(self.area_length_event.run)
self.setObjectName('giapAreaLength')

def reload_add_icons(self) -> None:
if hasattr(self, 'add_action'):
self.add_action.setIcon(
Expand Down Expand Up @@ -846,16 +853,14 @@ def set_custom_action(self) -> None:
if oname == "giapMyPrints":
self.tbut.setToolTip(tr("My Prints"))
if oname == "giapAreaLength":
self.tbut.setToolTip(tr("Area and length"))
giap_tool_bar = iface.mainWindow().findChildren(QToolBar, 'GiapToolBar')[0]
main_widget = giap_tool_bar.findChildren(MainWidget)[0]

iface.mapCanvas().refresh()
area_length_tool = QgsMapTool(iface.mapCanvas())
self.area_length_event = AreaAndLengthTool(iface)
self.area_length_action = QAction( QIcon(icon),
tr("Area and length"), iface.mainWindow())
self.area_length_action.setCheckable(True)
self.area_length_action.triggered.connect(self.area_length_event.run)
area_length_tool.setAction(self.area_length_action)
self.tbut.setDefaultAction(self.area_length_action)
area_length_tool.setAction(main_widget.area_length_action)
self.tbut.setDefaultAction(main_widget.area_length_action)

self.tbut.setIcon(icon)

def unload_custom_actions(self) -> None:
Expand Down
13 changes: 3 additions & 10 deletions giap_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from .ribbon_config import RIBBON_DEFAULT
from .tools import StyleManager
from .utils import tr, Qt, icon_manager, CustomMessageBox, add_action_from_toolbar, GIAP_NEWS_WEB_PAGE
from .AreaAndLengthTool.AreaAndLengthTool import AreaAndLengthTool
from qgis.gui import QgsMapTool
project = QgsProject.instance()

Expand Down Expand Up @@ -175,15 +174,8 @@ def initGui(self) -> None:
tr("Composition settings"))

area_length_tool = QgsMapTool(self.iface.mapCanvas())
self.area_length_event = AreaAndLengthTool(self.iface)
self.area_length_action = QAction(QIcon(os.path.join(self.plugin_dir, 'icons', 'measuring.png')),
None, self.iface.mainWindow())
self.area_length_action.setCheckable(True)
self.area_length_action.triggered.connect(self.area_length_event.run)
area_length_tool.setAction(self.area_length_action)
self.main_widget.runArea.setDefaultAction(self.area_length_action)
self.main_widget.runArea.setIcon(QIcon(os.path.join(self.plugin_dir, 'icons', 'measuring.png')))
self.main_widget.runArea.setToolTip(tr("Area and length"))
area_length_tool.setAction(self.main_widget.area_length_action)
self.main_widget.runArea.setDefaultAction(self.main_widget.area_length_action)

orto_button = self.main_widget.runOrtoTool
orto_button.setIcon(QIcon(os.path.join(self.plugin_dir, 'icons', 'orto_icon2.png')))
Expand Down Expand Up @@ -226,6 +218,7 @@ def ustaw_legende(self) -> None:
self.main_widget.pokaz_warstwy.toggled.connect(self.warstwy_show)

def load_ribbons(self) -> None:
self.main_widget.area_length_action.setToolTip(tr("Area and length"))
self.main_widget.edit_session_toggle()
ribbon_conf = self.config.load_user_ribbon_setup()
if not ribbon_conf:
Expand Down
7 changes: 1 addition & 6 deletions i18n/giap_pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ Proszę czekać...</translation>
<translation>Zakończ edycję</translation>
</message>
<message>
<location filename="../giap_layout.py" line="181"/>
<location filename="../giap_layout.py" line="221"/>
<source>Area and length</source>
<translation>Powierzchnia i długość</translation>
</message>
Expand Down Expand Up @@ -692,11 +692,6 @@ Proszę czekać...</translation>
<source>Error - Unable to remove the object.</source>
<translation>Błąd - nie udało się usunąć obiektu.</translation>
</message>
<message>
<location filename="../giap_dynamic_layout.py" line="848"/>
<source>Area and length</source>
<translation>Powierzchnia i długość</translation>
</message>
<message>
<location filename="../SectionManager/CustomSectionManager.py" line="425"/>
<source>Error - Check the entered data.</source>
Expand Down
3 changes: 2 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,8 @@ def paint(self, painter, option, index):
'giapWMS': "Add WMS/WMTS services",
'giapCompositions': "Composition settings",
"giapQuickPrint": "Map quick print",
"giapMyPrints": "My Prints"
"giapMyPrints": "My Prints",
"giapAreaLength": 'Area and length'
}

max_ele_nazwy = 4
Expand Down

0 comments on commit f388aad

Please sign in to comment.