From 1bbc9b785c75dca8bab2fb05802a3d079ef91de5 Mon Sep 17 00:00:00 2001 From: Patryk Date: Tue, 26 Jul 2022 10:32:34 +0200 Subject: [PATCH 1/7] =?UTF-8?q?Dodanie=20mo=C5=BCliwo=C5=9Bci=20dodawania?= =?UTF-8?q?=20granic=20je=C5=9Bli=20nie=20jest=20podany=20adres?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Searcher/searchAddress.py | 13 ++-- Searcher/searchParcel.py | 25 +++---- Searcher/searchTool.py | 138 +++++++++++++++++++++++++++++++------- 3 files changed, 133 insertions(+), 43 deletions(-) diff --git a/Searcher/searchAddress.py b/Searcher/searchAddress.py index 8ea2acc..ac2fa6e 100644 --- a/Searcher/searchAddress.py +++ b/Searcher/searchAddress.py @@ -1,6 +1,7 @@ import json import os from http.client import IncompleteRead +from typing import Union, Tuple from urllib.error import HTTPError, URLError from urllib.parse import quote from urllib.request import urlopen @@ -35,7 +36,7 @@ def __init__(self): QgsField("y", QVariant.Double, "double", 10, 4), ] - def fetch_address(self, address): + def fetch_address(self, address: str) -> None: self.address = address uug = 'https://services.gugik.gov.pl/uug?request=GetAddress&address=' url = uug + quote(self.address) @@ -54,7 +55,7 @@ def fetch_address(self, address): return self.res.decode() - def get_layer(self): + def get_layer(self) -> Union[bool,Tuple[str]]: req_type = self.jres['type'] if req_type in ['city', 'address']: org = 'MultiPoint?crs=epsg:2180&index=yes' @@ -73,7 +74,7 @@ def get_layer(self): return False return org, obj_type, qml - def get_layer_data(self, org, obj_type, qml): + def get_layer_data(self, org: str, obj_type: str, qml: str) -> QgsVectorLayer: lyr = QgsProject.instance().mapLayersByName(obj_type) if lyr: return lyr[0] @@ -94,7 +95,7 @@ def get_layer_data(self, org, obj_type, qml): lyr.loadNamedStyle(os.path.join(direc, qml)) return lyr - def process_results(self): + def process_results(self) -> Union[Tuple[bool,str], Tuple[bool,QgsFeature]]: try: self.jres = json.loads(self.res) except Exception: @@ -145,14 +146,14 @@ def process_results(self): return True, feats - def zoom_to_feature(self, layer): + def zoom_to_feature(self, layer: str) -> None: layer = QgsProject.instance().mapLayersByName(layer)[0] iface.mapCanvas().zoomScale(500) layer.selectByIds([len(layer)]) iface.mapCanvas().zoomToSelected(layer) layer.removeSelection() - def add_feats(self, feats): + def add_feats(self, feats: QgsFeature) -> Union[bool,None]: if isinstance(feats, str): pass else: diff --git a/Searcher/searchParcel.py b/Searcher/searchParcel.py index 9ec2107..9bd86a3 100644 --- a/Searcher/searchParcel.py +++ b/Searcher/searchParcel.py @@ -2,6 +2,7 @@ import re import socket from http.client import IncompleteRead +from typing import List from urllib.error import HTTPError, URLError from urllib.request import urlopen @@ -18,7 +19,7 @@ def __init__(self, params=None): self.params = params self.responce = [] - def fetch_list(self, area, teryt): + def fetch_list(self, area: str, teryt: str) -> bool: map(str, teryt) if area not in {'powiat', 'gmina', 'obreb'}: self.responce = [] @@ -26,11 +27,11 @@ def fetch_list(self, area, teryt): self.params = f'obiekt={area}&wynik=nazwa%2Cteryt&teryt={teryt}&' return self.fetch() - def fetch_voivodeships(self): + def fetch_voivodeships(self) -> bool: self.params = 'obiekt=wojewodztwo&wynik=nazwa%2Cteryt&teryt=&' return self.fetch() - def fetch_parcel(self, teryt): + def fetch_parcel(self, teryt: str) -> bool: self.responce = [] if not isinstance(teryt, str): return False @@ -42,15 +43,15 @@ def fetch_in_point(self, coords): # TODO: Dodac pobieranie działki w pkt po kliknieciu pass - def fetch(self): + def fetch(self) -> bool: if '- gmina' in self.params or '- miasto' in self.params: flag = self.params.find('-') self.params = self.params[0:flag] url = f'https://uldk.gugik.gov.pl/?{self.params}' self.responce = [] try: - with urlopen(url, timeout=19) as r: - content = r.read() + with urlopen(url, timeout=19) as url_handler: + content = url_handler.read() except IncompleteRead: CustomMessageBox(None, f"{tr('Error!')} {tr('Service returned incomplete responce.')}").button_ok() @@ -75,10 +76,10 @@ def fetch(self): f"{tr('Service did not find any matches, wrong plot number.')}").button_ok() return False - self.responce = self.natural_sort([x for x in res[1:] if x != '']) + self.responce = self.natural_sort([ter for ter in res[1:] if ter != '']) return True - def natural_sort(self, list): + def natural_sort(self, list: List[str]) -> List[str]: convert = lambda text: int(text) if text.isdigit() else text.lower() alpha_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] return sorted(list, key=alpha_key) @@ -97,7 +98,7 @@ def __init__(self): self.lyr_name, 'memory' ) - def get_layer(self): + def get_layer(self) -> None: lyr = QgsProject.instance().mapLayersByName(self.lyr_name) if len(lyr) > 0: self.lyr = lyr[0] @@ -108,7 +109,7 @@ def get_layer(self): self.lyr.loadNamedStyle( os.path.join(direc, 'layer_style', 'dzialki.qml')) - def parse_responce(self, resp): + def parse_responce(self, resp: List[str]) -> None: feats = [] for row in resp: ft = self._create_feature(row) @@ -129,14 +130,14 @@ def parse_responce(self, resp): Qgis.Warning ) - def zoom_to_feature(self, layer): + def zoom_to_feature(self, layer: str) -> None: layer = QgsProject.instance().mapLayersByName(layer)[0] iface.mapCanvas().zoomScale(500) layer.selectByIds([len(layer)]) iface.mapCanvas().zoomToSelected(layer) layer.removeSelection() - def _create_feature(self, row): + def _create_feature(self, row: str) -> QgsFeature: if row[:4].upper() == 'SRID': row = row[row.index(';') + 1:] feat = QgsFeature() diff --git a/Searcher/searchTool.py b/Searcher/searchTool.py index 22bd049..fb553d1 100644 --- a/Searcher/searchTool.py +++ b/Searcher/searchTool.py @@ -3,16 +3,18 @@ from urllib.request import urlopen import requests -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QFont, QFontMetrics +from qgis.PyQt.QtCore import Qt +from qgis.PyQt.QtGui import QFont, QFontMetrics, QKeySequence from qgis.PyQt.QtCore import QStringListModel from qgis.PyQt.QtCore import QTimer -from qgis.PyQt.QtWidgets import QCompleter +from qgis.PyQt.QtWidgets import QCompleter, QProgressDialog +from qgis._core import QgsVectorLayer, QgsProject from qgis.utils import iface +from typing import Union, Dict, List from .searchAddress import SearchAddress from .searchParcel import FetchULDK, ParseResponce -from ..utils import tr, CustomMessageBox +from ..utils import tr, CustomMessageBox, add_map_layer_to_group class SearcherTool: @@ -53,10 +55,10 @@ def __init__(self, dock, iface): self.font = QFont('Agency FB') self.fontm = QFontMetrics(self.font) - def textChanged(self): + def textChanged(self) -> None: self.typing_timer.start(300) - def tips(self): + def tips(self) -> None: address = self.dock.lineEdit_address.displayText() url_pref = 'http://services.gugik.gov.pl/uug/?request=GetAddress&address=' quo_adr = quote(address) @@ -87,7 +89,7 @@ def tips(self): except Exception: return - def getStreets(self, simc, city): + def getStreets(self, simc: str, city: str) -> None: try: data = json.loads(urlopen( 'https://services.gugik.gov.pl/uug/?request=GetStreet&simc=' + simc).read().decode()) @@ -97,14 +99,14 @@ def getStreets(self, simc, city): except Exception: self.names.setStringList([]) - def validateCity(self, obj): + def validateCity(self, obj: Dict[str, Dict[str, int]]) -> None: city = obj['1']['city'] self.names.setStringList( [f"{city}, {obj[element]['simc']} {obj[element]['county']}" for element in obj]) self.completer.popup().pressed.connect(lambda: self.userPick()) - def userPick(self): + def userPick(self) -> None: line = self.dock.lineEdit_address.text().split() self.completer.popup().pressed.disconnect() if len(line) == 3: @@ -116,7 +118,7 @@ def userPick(self): else: return - def search_address(self): + def search_address(self) -> None: validate_address = self.validate_lineedit() if validate_address: lineedit = self.dock.lineEdit_address.text().split(',') @@ -141,19 +143,102 @@ def change_scale(): self.timer.timeout.connect(change_scale) self.timer.start(10) - def validate_lineedit(self): + def validate_lineedit(self) -> bool: if self.dock.lineEdit_address.text(): return True else: CustomMessageBox(None, f" {tr('Invalid')} {tr('Empty address field')}").button_ok() - def widthforview(self, result): + def add_chosen_border(self, mess: str) -> None: + prg_dlg = QProgressDialog(self.dock,Qt.Dialog) + prg_dlg.setLabelText("Dodawanie warstw...") + prg_dlg.setCancelButton(None) + prg_dlg.setAutoClose(True) + prg_dlg.setMaximum(100) + prg_dlg.setWindowFlags( + Qt.Dialog | + Qt.WindowTitleHint + ) + prg_dlg.show() + + prg_dlg.setValue(0) + if self.dock.comboBox_obr.currentIndex() != 0: + jpt_kod_je = self.dock.comboBox_obr.currentText().split("|")[1] + adres = "A06_Granice_obrebow_ewidencyjnych" + lay_name = 'obreby_ewidencyjne' + + + elif self.dock.comboBox_gmina.currentIndex() != 0: + jpt_kod_je = self.dock.comboBox_gmina.currentText().split("|")[1] + jpt_kod_je = jpt_kod_je.replace("_", "") + adres = "A03_Granice_gmin" + lay_name = 'gminy' + + + elif self.dock.comboBox_pow.currentIndex() != 0: + jpt_kod_je = self.dock.comboBox_pow.currentText().split("|")[1] + adres = "A02_Granice_powiatow" + lay_name = 'powiaty' + + + elif self.dock.comboBox_woj.currentIndex() != 0: + jpt_kod_je = self.dock.comboBox_woj.currentText().split("|")[1] + adres = "A01_Granice_wojewodztw" + lay_name = 'wojewodztwa' + + else: + CustomMessageBox(None, + mess).button_ok() + return + + url = f"https://mapy.geoportal.gov.pl/wss/service/PZGIK/PRG/WFS/AdministrativeBoundaries?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAME=ms:{adres}&TYPENAMES=ms:{adres}" + + vlayer = QgsVectorLayer(url, "my wfs layer", "WFS") + vlayer.setSubsetString(f"""SELECT * FROM {adres} + WHERE JPT_KOD_JE = '{jpt_kod_je}'""") + + prg_dlg.setValue(25) + root = QgsProject.instance().layerTreeRoot() + granice_group = root.findGroup("Granice") + if not root.findGroup("Granice"): + granice_group = root.addGroup("Granice") + + lay = None + + if granice_group.children(): + for child in granice_group.children(): + if child.name() == lay_name: + lay = child.layer() + break + + if not lay: + lay = QgsVectorLayer("Polygon", lay_name, "memory") + attr = vlayer.dataProvider().fields().toList() + lay.dataProvider().addAttributes(attr) + lay.updateFields() + add_map_layer_to_group(lay, "Granice") + + prg_dlg.setValue(50) + + vlayer.selectAll() + feat = vlayer.selectedFeatures()[0] + + prg_dlg.setValue(75) + + lay.dataProvider().addFeature(feat) + lay.updateExtents() + self.searchaddress_call.zoom_to_feature(lay.name()) + prg_dlg.setValue(100) + + + + def widthforview(self, result: List[str]) -> int: longest = max(result, key=len) width = 2 * self.fontm.width(longest) return width - def fetch_voivodeship(self): + def fetch_voivodeship(self) -> None: """Fetching voivodeship list from GUGiK""" voi_list = [ 'Dolnośląskie|02', @@ -178,7 +263,7 @@ def fetch_voivodeship(self): self.dock.comboBox_woj.blockSignals(False) self.clear_comboBoxes('voi') - def woj_changed(self): + def woj_changed(self) -> None: voi = self._get_voi_code() if not voi: return @@ -191,7 +276,7 @@ def woj_changed(self): self.dock.comboBox_pow.view().setFixedWidth(self.widthforview(result)) self.dock.comboBox_pow.blockSignals(False) - def pow_changed(self): + def pow_changed(self) -> None: dis = self._get_dis_code() if not dis: return @@ -200,7 +285,7 @@ def pow_changed(self): fe.fetch_list('gmina', dis) self.dock.comboBox_gmina.blockSignals(True) result, communities = fe.responce, [] - multiples = [e.split('|')[0] for e in result] + multiples = [powiat.split('|')[0] for powiat in result] for district in result: end = district[-2:] if multiples.count(district.split('|')[0]) > 1: @@ -217,7 +302,7 @@ def pow_changed(self): self.widthforview(communities)) self.dock.comboBox_gmina.blockSignals(False) - def gmi_changed(self): + def gmi_changed(self) -> None: mun = self._get_mun_code() self.clear_comboBoxes('mun') if not mun: @@ -230,7 +315,7 @@ def gmi_changed(self): self.dock.comboBox_obr.view().setFixedWidth(self.widthforview(result)) self.dock.comboBox_obr.blockSignals(False) - def clear_comboBoxes(self, level=None): + def clear_comboBoxes(self, level:str = None) -> None: """Clear comboboxes to level where user change something""" self.dock.comboBox_obr.blockSignals(True) self.dock.comboBox_obr.clear() @@ -251,34 +336,37 @@ def clear_comboBoxes(self, level=None): self.dock.comboBox_pow.addItem(tr('District')) self.dock.comboBox_pow.blockSignals(False) - def _get_voi_code(self): + def _get_voi_code(self) -> Union[str,bool]: voi_txt = self.dock.comboBox_woj.currentText() if '|' not in voi_txt: self.clear_comboBoxes() return False return voi_txt.split('|')[1] - def _get_dis_code(self): + def _get_dis_code(self) -> Union[str,bool]: dis_txt = self.dock.comboBox_pow.currentText() if '|' not in dis_txt: self.clear_comboBoxes('dis') return False return dis_txt.split('|')[1] - def _get_mun_code(self): + def _get_mun_code(self) -> Union[str,bool]: mun_txt = self.dock.comboBox_gmina.currentText() if '|' not in mun_txt: self.clear_comboBoxes('mun') return False return mun_txt.split('|')[1] - def search_parcel(self): + def search_parcel(self) -> None: adr = '' # ful address of parcel parc = self.dock.lineEdit_parcel.text() if '.' in parc and '_' in parc: # user input whole address in parcel adr = parc else: comm = self.dock.comboBox_obr.currentText() + if not parc: + self.add_chosen_border(f"{tr('Address of parcel is not valid.')}") + return if '|' not in comm: CustomMessageBox(None, f"{tr('Address of parcel is not valid.')}").button_ok() @@ -286,9 +374,9 @@ def search_parcel(self): comm = comm.split('|')[1] adr = f'{comm}.{parc}' - f = FetchULDK() - if not f.fetch_parcel(adr): + feULDK = FetchULDK() + if not feULDK.fetch_parcel(adr): return pr = ParseResponce() pr.get_layer() - pr.parse_responce(f.responce) + pr.parse_responce(feULDK.responce) From 9d0d9bd8f603d8054411ac31b41b5f15f505f671 Mon Sep 17 00:00:00 2001 From: Patryk Date: Tue, 26 Jul 2022 10:47:58 +0200 Subject: [PATCH 2/7] =?UTF-8?q?Dodanie=20mo=C5=BCliwo=C5=9Bci=20dodawania?= =?UTF-8?q?=20granic=20je=C5=9Bli=20nie=20jest=20podany=20adres?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Searcher/searchTool.py | 20 ++++++++++---------- i18n/giap_pl.ts | 5 +++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Searcher/searchTool.py b/Searcher/searchTool.py index fb553d1..e841972 100644 --- a/Searcher/searchTool.py +++ b/Searcher/searchTool.py @@ -152,7 +152,7 @@ def validate_lineedit(self) -> bool: def add_chosen_border(self, mess: str) -> None: prg_dlg = QProgressDialog(self.dock,Qt.Dialog) - prg_dlg.setLabelText("Dodawanie warstw...") + prg_dlg.setLabelText(tr("Adding layers...")) prg_dlg.setCancelButton(None) prg_dlg.setAutoClose(True) prg_dlg.setMaximum(100) @@ -166,26 +166,26 @@ def add_chosen_border(self, mess: str) -> None: if self.dock.comboBox_obr.currentIndex() != 0: jpt_kod_je = self.dock.comboBox_obr.currentText().split("|")[1] adres = "A06_Granice_obrebow_ewidencyjnych" - lay_name = 'obreby_ewidencyjne' + lay_name = 'Obręby_ewidencyjne' elif self.dock.comboBox_gmina.currentIndex() != 0: jpt_kod_je = self.dock.comboBox_gmina.currentText().split("|")[1] jpt_kod_je = jpt_kod_je.replace("_", "") adres = "A03_Granice_gmin" - lay_name = 'gminy' + lay_name = 'Gminy' elif self.dock.comboBox_pow.currentIndex() != 0: jpt_kod_je = self.dock.comboBox_pow.currentText().split("|")[1] adres = "A02_Granice_powiatow" - lay_name = 'powiaty' + lay_name = 'Powiaty' elif self.dock.comboBox_woj.currentIndex() != 0: jpt_kod_je = self.dock.comboBox_woj.currentText().split("|")[1] adres = "A01_Granice_wojewodztw" - lay_name = 'wojewodztwa' + lay_name = 'Województwa' else: CustomMessageBox(None, @@ -194,15 +194,15 @@ def add_chosen_border(self, mess: str) -> None: url = f"https://mapy.geoportal.gov.pl/wss/service/PZGIK/PRG/WFS/AdministrativeBoundaries?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAME=ms:{adres}&TYPENAMES=ms:{adres}" - vlayer = QgsVectorLayer(url, "my wfs layer", "WFS") + vlayer = QgsVectorLayer(url, "wfs_lay", "WFS") vlayer.setSubsetString(f"""SELECT * FROM {adres} WHERE JPT_KOD_JE = '{jpt_kod_je}'""") prg_dlg.setValue(25) root = QgsProject.instance().layerTreeRoot() - granice_group = root.findGroup("Granice") - if not root.findGroup("Granice"): - granice_group = root.addGroup("Granice") + granice_group = root.findGroup("GRANICE") + if not root.findGroup("GRANICE"): + granice_group = root.addGroup("GRANICE") lay = None @@ -217,7 +217,7 @@ def add_chosen_border(self, mess: str) -> None: attr = vlayer.dataProvider().fields().toList() lay.dataProvider().addAttributes(attr) lay.updateFields() - add_map_layer_to_group(lay, "Granice") + add_map_layer_to_group(lay, "GRANICE") prg_dlg.setValue(50) diff --git a/i18n/giap_pl.ts b/i18n/giap_pl.ts index 9ba01fa..b032f2f 100644 --- a/i18n/giap_pl.ts +++ b/i18n/giap_pl.ts @@ -647,6 +647,11 @@ Proszę czekać... Empty address field Puste pole adresu + + + Adding layers... + Dodawanie warstwy... + Cadastral district From 2ce4ddaa4e7cebac4f86ba30456339f25502ade8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCejewski?= Date: Wed, 27 Jul 2022 09:24:18 +0200 Subject: [PATCH 3/7] =?UTF-8?q?Kompilacja=20t=C5=82umaczenia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- i18n/giap_pl.qm | Bin 23158 -> 23251 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/i18n/giap_pl.qm b/i18n/giap_pl.qm index a094ff4c7258ace8482f1dcbe4cceed6db993967..f95eed0ff4b2344f8f29bbd874b35d07d184d96a 100644 GIT binary patch delta 2047 zcmX9<3s6+&89lpu@9y5ayLV9@%R> zVbZFrqeBZO5+(s1W5IwyV@6aIB#EskMr*6Z#}v&}f?|xuY889%&d!~4?|<+2|KE4c z`M&*izvkQl&DIdlR$!_EBnJbtcM>yHoV65qaW;?>56t_BSOENHJkbN8O#sZ_s+f|l z;_Uel2BrW33m`5!3XDDoaeEgKJ5I&aUKR7o;Zqp{%vgquO__j4a3kyEHvsEiN}dt-*oMck_7(dXkIa!7K^=>DTbodqFb8Q31z^vCe77lt$?mrbFI3KEJAayy&o9s(2jo~ zGA>;E`ony{@4SjLVzlK0jGr`4`_ zfKR^mUl|Tk-k`nN&4X}UXLECX>K)zmC9eUIe!7IHP#|=)Zhni63tDZlR$49;s1;(uWIx z=`Nuvk=~flCTxGTF;w>!o}14(3UOST(**dPsM=bZNQi)anuE_&l(iNDo*gb zdU3qhNrqa*=*Lw+VxegF1OdT+QZaF}INM9EhoSNvY$Q*uO1_?(PwPe%ixCHi&oMD>PP&Rh0UqeJ9exFa#!mU zA{mz#Z5kUdfVQ9CmhAL}=}+|1CbuPGvx69@ElXAS`~ef3R^uL4u5 z^vxNs02ZhI*t$-(+jV`%&9SU(l)+HS1LOTwOsO>3-{HZ!5X0p9NOsi?LtJMS6D>Em z8oBQ8*=u%{f+HD|rucm_>|~s&%sYo@DX zO%0EU?vG84nod^kRWYN_)Vwwf7#CvtIoqsm5AlF9 zbDM^76I)eGbE!DzRdcsXp->ym7uVA}L2p`wON@`mv;<6J!j34*)bm!(nO;l0X9~59 zIAWRKSwvF|SvKTwl1-j#shaQ$pc$~V^$!9uiIy%q57d-f{w-YP#GI}e?YBv(S@Bt3 z#)0xk2{J$8NIj#3YWWAI`$@_9k%bwHl%ip#5~@^8`&#+k|4y(iJC%34cd~oFR6IKl za^vVvl^xy8IQ@>Y>*ad7`?1p0>0||SRg62S;>^=ZN8A!>+oIgD=}2Xd)mofJ26tKg z0vSKK$vP>9o>5>;zgkY}S6C}npJP`wTGww#VgaMAZO8Z1+_zOsxD{nRZ=?3Ye(OaY zHwe9Cz5Jg#YAjl>Jime)7c2(yeOvb!!ZoSUNW*dzViJq5FN^$YxveK|+3oA;>S2`S3QzhTlzZ#oz{|`9UD);~Z delta 1968 zcmXApe^gX;8pfYHbMKwGcV_ND!Hj^AC?i#eMAlG3RsUd++;x-}}7J z`<{DW`0o*6SBPf^FjE6kdw}eN|}I0}h}>mp-`o#O)eNUbn82~y&~tu(m5&+z z=5|r?Jj0b^4OC=`a6;%Z8s3sCyhVP^9Spt300@~-XbZg zI-c*9NYS_V04WwJ))NE-r|C?YBV|{!btzp^k+Ttq9*~xX?*!(|kv9Codgcl|*SDSTFs;f^uocJ6*tpT&X&%hf;nh?VCyyChpgnVUhN^9$~`UIx{Cr z-r6x1cuo3?my)_3l}2`_(%qY+Yj^uNO|zu`Y$*c_ZrOhgKP)F(b~QW&6ikqlA{bY2 z(IXe0VIa21RsGxO`Y+@cJ6W;RBEOoP0R$bBYs)BQOs(Ab*)brkLvHo{hGt8ZeeQ=j z4FmFt&E53CYjW3>Ni6)d$yC7$6He$%pKOYKmKPg7HcdYe!Th^S3EfoA6>3WM@;uP9 z+%$K{NCg&{ii19-t1p;VlIWWUnxW+6;PET6i_KBOBadkafMRa>Bqt@ zDAgOzv8UNe_0e7AM@mf|^NpXYcw2Zu)IXJvOl;}YV&$U3g`*89!%cjD;gB*~;o|%U zUs3L;F7|MdGUobNa06TXb7Jbe7L^-c*lQFX8{ENseXi8nvq}o_k}(J#zl@ z%GEO=G>g-xo{gtFlP;@$+D^dqj5>U`1n_&q68dE$dsc6W4&YRTthO|LWu+;HEKRq` zj7*DH=;q={)al-7@ok*Iz4Ec;gNP>T)n*y;Euh)&LhU3b$K*2gc}uAZxq8 zxR?^18JBhDn616Z8ZVx0z4QXT6Exl?e#!Xo8#YHA3!c_zoB6q&UfOO;^vqx{C$6zA z>n@`y-nPAz&rRm~$+l<8k6cK#w)T51=bJ+Zt{2(^794$_>1nmKlqraG$m{h^Yk zYu19SKeM+RwJ?L5($;AC|KNw2HLdKPQc0;gGk>f7{(q-9mX+Fby$1o?uQgA@Q6`Rd zYYn}uIIBTxUVeb4Y0+A{70kB>jAQ)t zW%jAl=oy>Wo;A3R-U+c+J#~(obE&=kN;;c%4FTJV1f7aAG> From 5b629e03ded854e50e06adf762dcdc632b790cc1 Mon Sep 17 00:00:00 2001 From: Patryk Date: Thu, 28 Jul 2022 13:55:56 +0200 Subject: [PATCH 4/7] Poprawki --- Searcher/searchAddress.py | 11 ++-- Searcher/searchParcel.py | 12 ++--- Searcher/searchTool.py | 105 ++++++++++++-------------------------- utils.py | 70 ++++++++++++++++++++++--- 4 files changed, 105 insertions(+), 93 deletions(-) diff --git a/Searcher/searchAddress.py b/Searcher/searchAddress.py index ac2fa6e..f9156b9 100644 --- a/Searcher/searchAddress.py +++ b/Searcher/searchAddress.py @@ -1,6 +1,7 @@ import json import os from http.client import IncompleteRead +from json import JSONDecodeError from typing import Union, Tuple from urllib.error import HTTPError, URLError from urllib.parse import quote @@ -8,10 +9,10 @@ from qgis.PyQt.QtCore import QVariant from qgis.core import QgsGeometry, QgsFeature, QgsField, QgsFields, \ - QgsProject, QgsVectorLayer, QgsMessageLog, Qgis + QgsVectorLayer, QgsMessageLog, Qgis from qgis.utils import iface -from ..utils import tr, add_map_layer_to_group, search_group_name +from ..utils import tr, add_map_layer_to_group, search_group_name, project class SearchAddress: @@ -75,7 +76,7 @@ def get_layer(self) -> Union[bool,Tuple[str]]: return org, obj_type, qml def get_layer_data(self, org: str, obj_type: str, qml: str) -> QgsVectorLayer: - lyr = QgsProject.instance().mapLayersByName(obj_type) + lyr = project.mapLayersByName(obj_type) if lyr: return lyr[0] @@ -98,7 +99,7 @@ def get_layer_data(self, org: str, obj_type: str, qml: str) -> QgsVectorLayer: def process_results(self) -> Union[Tuple[bool,str], Tuple[bool,QgsFeature]]: try: self.jres = json.loads(self.res) - except Exception: + except JSONDecodeError: return False, tr('Cannot parse results.') if 'found objects' in self.jres: @@ -147,7 +148,7 @@ def process_results(self) -> Union[Tuple[bool,str], Tuple[bool,QgsFeature]]: return True, feats def zoom_to_feature(self, layer: str) -> None: - layer = QgsProject.instance().mapLayersByName(layer)[0] + layer = project.mapLayersByName(layer)[0] iface.mapCanvas().zoomScale(500) layer.selectByIds([len(layer)]) iface.mapCanvas().zoomToSelected(layer) diff --git a/Searcher/searchParcel.py b/Searcher/searchParcel.py index 9bd86a3..31c39a9 100644 --- a/Searcher/searchParcel.py +++ b/Searcher/searchParcel.py @@ -7,11 +7,11 @@ from urllib.request import urlopen from qgis.core import QgsGeometry, QgsFeature, \ - QgsProject, QgsVectorLayer, Qgis + QgsVectorLayer, Qgis from qgis.utils import iface from ..utils import tr, CustomMessageBox, search_group_name, \ - add_map_layer_to_group + add_map_layer_to_group, project class FetchULDK: @@ -39,10 +39,6 @@ def fetch_parcel(self, teryt: str) -> bool: 'geom_wkt,teryt,voivodeship,county,region,commune,parcel' return self.fetch() - def fetch_in_point(self, coords): - # TODO: Dodac pobieranie działki w pkt po kliknieciu - pass - def fetch(self) -> bool: if '- gmina' in self.params or '- miasto' in self.params: flag = self.params.find('-') @@ -99,7 +95,7 @@ def __init__(self): ) def get_layer(self) -> None: - lyr = QgsProject.instance().mapLayersByName(self.lyr_name) + lyr = project.mapLayersByName(self.lyr_name) if len(lyr) > 0: self.lyr = lyr[0] return @@ -131,7 +127,7 @@ def parse_responce(self, resp: List[str]) -> None: ) def zoom_to_feature(self, layer: str) -> None: - layer = QgsProject.instance().mapLayersByName(layer)[0] + layer = project.mapLayersByName(layer)[0] iface.mapCanvas().zoomScale(500) layer.selectByIds([len(layer)]) iface.mapCanvas().zoomToSelected(layer) diff --git a/Searcher/searchTool.py b/Searcher/searchTool.py index e841972..879a138 100644 --- a/Searcher/searchTool.py +++ b/Searcher/searchTool.py @@ -1,20 +1,22 @@ import json +from json import JSONDecodeError from urllib.parse import quote from urllib.request import urlopen import requests from qgis.PyQt.QtCore import Qt -from qgis.PyQt.QtGui import QFont, QFontMetrics, QKeySequence +from qgis.PyQt.QtGui import QFont, QFontMetrics from qgis.PyQt.QtCore import QStringListModel from qgis.PyQt.QtCore import QTimer -from qgis.PyQt.QtWidgets import QCompleter, QProgressDialog -from qgis._core import QgsVectorLayer, QgsProject +from qgis.PyQt.QtWidgets import QCompleter +from qgis.core import QgsVectorLayer from qgis.utils import iface from typing import Union, Dict, List from .searchAddress import SearchAddress from .searchParcel import FetchULDK, ParseResponce -from ..utils import tr, CustomMessageBox, add_map_layer_to_group +from ..utils import tr, CustomMessageBox, add_map_layer_to_group, \ + ProgressDialog, identify_layer_in_group, root, WFS_PRG class SearcherTool: @@ -82,11 +84,11 @@ def tips(self) -> None: if obj_type == 'address': self.names.setStringList([ f"{obj['1']['city']}, {obj['1']['street']} {obj['1']['number']}"]) - if limit == 0: + if not limit: return self.completer.setCompletionPrefix(f"{address.split(',')[0]}, ") self.completer.complete() - except Exception: + except (JSONDecodeError, TypeError): return def getStreets(self, simc: str, city: str) -> None: @@ -96,7 +98,7 @@ def getStreets(self, simc: str, city: str) -> None: obj = data['results'] self.names.setStringList( [f"{city}, {obj[element]['street']}" for element in obj]) - except Exception: + except TypeError: self.names.setStringList([]) def validateCity(self, obj: Dict[str, Dict[str, int]]) -> None: @@ -151,87 +153,47 @@ def validate_lineedit(self) -> bool: f" {tr('Invalid')} {tr('Empty address field')}").button_ok() def add_chosen_border(self, mess: str) -> None: - prg_dlg = QProgressDialog(self.dock,Qt.Dialog) - prg_dlg.setLabelText(tr("Adding layers...")) - prg_dlg.setCancelButton(None) - prg_dlg.setAutoClose(True) - prg_dlg.setMaximum(100) - prg_dlg.setWindowFlags( - Qt.Dialog | - Qt.WindowTitleHint - ) - prg_dlg.show() - - prg_dlg.setValue(0) - if self.dock.comboBox_obr.currentIndex() != 0: - jpt_kod_je = self.dock.comboBox_obr.currentText().split("|")[1] - adres = "A06_Granice_obrebow_ewidencyjnych" - lay_name = 'Obręby_ewidencyjne' - - - elif self.dock.comboBox_gmina.currentIndex() != 0: - jpt_kod_je = self.dock.comboBox_gmina.currentText().split("|")[1] - jpt_kod_je = jpt_kod_je.replace("_", "") - adres = "A03_Granice_gmin" - lay_name = 'Gminy' - - - elif self.dock.comboBox_pow.currentIndex() != 0: - jpt_kod_je = self.dock.comboBox_pow.currentText().split("|")[1] - adres = "A02_Granice_powiatow" - lay_name = 'Powiaty' - - - elif self.dock.comboBox_woj.currentIndex() != 0: - jpt_kod_je = self.dock.comboBox_woj.currentText().split("|")[1] - adres = "A01_Granice_wojewodztw" - lay_name = 'Województwa' - - else: + # lay_keys = ['Obręby_ewidencyjne', 'Gminy', 'Powiaty', 'Województwa'] + lay_data = {'Obręby_ewidencyjne': ["A06_Granice_obrebow_ewidencyjnych", self.dock.comboBox_obr], + 'Gminy': ["A03_Granice_gmin", self.dock.comboBox_gmina], + 'Powiaty': ["A02_Granice_powiatow", self.dock.comboBox_pow], + 'Województwa': ["A01_Granice_wojewodztw", self.dock.comboBox_woj]} + for lay_key in lay_data: + if lay_data[lay_key][1].currentIndex() != 0: + _, jpt_kod_je = lay_data[lay_key][1].currentText().split("|") + if lay_key == "Gminy": + jpt_kod_je = jpt_kod_je.replace("_", "") + adres = lay_data[lay_key][0] + lay_name = lay_key + break + if not jpt_kod_je or not adres or not lay_name: CustomMessageBox(None, mess).button_ok() return - - url = f"https://mapy.geoportal.gov.pl/wss/service/PZGIK/PRG/WFS/AdministrativeBoundaries?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAME=ms:{adres}&TYPENAMES=ms:{adres}" - + prg_dlg = ProgressDialog() + prg_dlg.start_steped(tr("Adding layers...")) + prg_dlg.start() + url = f"{WFS_PRG}?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAME=ms:{adres}&TYPENAMES=ms:{adres}" vlayer = QgsVectorLayer(url, "wfs_lay", "WFS") vlayer.setSubsetString(f"""SELECT * FROM {adres} WHERE JPT_KOD_JE = '{jpt_kod_je}'""") - - prg_dlg.setValue(25) - root = QgsProject.instance().layerTreeRoot() - granice_group = root.findGroup("GRANICE") - if not root.findGroup("GRANICE"): - granice_group = root.addGroup("GRANICE") - - lay = None - - if granice_group.children(): - for child in granice_group.children(): - if child.name() == lay_name: - lay = child.layer() - break - + group_name = "GRANICE" + granice_group = root.findGroup(group_name) + if not granice_group: + root.addGroup(group_name) + lay = identify_layer_in_group(group_name, lay_name) if not lay: lay = QgsVectorLayer("Polygon", lay_name, "memory") attr = vlayer.dataProvider().fields().toList() lay.dataProvider().addAttributes(attr) lay.updateFields() add_map_layer_to_group(lay, "GRANICE") - - prg_dlg.setValue(50) - vlayer.selectAll() feat = vlayer.selectedFeatures()[0] - - prg_dlg.setValue(75) - lay.dataProvider().addFeature(feat) lay.updateExtents() self.searchaddress_call.zoom_to_feature(lay.name()) - prg_dlg.setValue(100) - - + prg_dlg.stop() def widthforview(self, result: List[str]) -> int: longest = max(result, key=len) @@ -358,7 +320,6 @@ def _get_mun_code(self) -> Union[str,bool]: return mun_txt.split('|')[1] def search_parcel(self) -> None: - adr = '' # ful address of parcel parc = self.dock.lineEdit_parcel.text() if '.' in parc and '_' in parc: # user input whole address in parcel adr = parc diff --git a/utils.py b/utils.py index 94f5906..c61720a 100644 --- a/utils.py +++ b/utils.py @@ -14,6 +14,7 @@ from qgis.utils import iface project = QgsProject.instance() +root = project.layerTreeRoot() class CustomMessageBox(QMessageBox): @@ -135,6 +136,55 @@ def __new__(cls, *args): SingletonModel.__instance = object.__new__(cls, *args) return SingletonModel.__instance +class ProgressDialog(QProgressDialog, SingletonModel): + + def __init__(self, parent=None, title='GIAP-PolaMap'): + super(ProgressDialog, self).__init__(parent) + self.setWindowTitle(title) + self.setWindowIcon(QIcon(':/plugins/GIAP-PolaMap/icons/giap_logo.png')) + self.setLabelText('Proszę czekać...') + self.setFixedWidth(300) + self.setFixedHeight(100) + self.setMaximum(100) + self.setCancelButton(None) + # self.setStyleSheet(self.stylesheet) + self.setWindowFlags(Qt.Dialog | Qt.WindowCloseButtonHint) + self.rejected.connect(self.stop) + self.setWindowModality(Qt.WindowModal) + + def make_percent_step(self, step=100, new_text=None): + self.setStyleSheet(self.stylesheet) + if new_text: + self.setLabelText(new_text) + if "wczytywanie" in new_text: + for pos in range(100 - self.value()): + QApplication.processEvents() + self.setValue(self.value() + 1) + return + for pos in range(step): + QApplication.processEvents() + self.setValue(self.value() + 1) + QApplication.sendPostedEvents() + QApplication.processEvents() + + def start_steped(self, title='Trwa ładowanie danych.\n Proszę czekać...'): + self.setLabelText(title) + self.setValue(1) + self.show() + QApplication.sendPostedEvents() + QApplication.processEvents() + + def start(self): + self.setFixedWidth(250) + self.setMaximum(0) + self.setCancelButton(None) + self.show() + QApplication.sendPostedEvents() + QApplication.processEvents() + + def stop(self): + self.setValue(100) + self.close() def identify_layer(ls, layer_to_find): for layer in list(ls.values()): @@ -257,6 +307,7 @@ def paint(self, painter, option, index): GIAP_NEWS_WEB_PAGE = 'https://www.giap.pl/aktualnosci/' +WFS_PRG = "https://mapy.geoportal.gov.pl/wss/service/PZGIK/PRG/WFS/AdministrativeBoundaries" # oba poniższe słowniki powinny być spójne WMS_SERVERS = { @@ -1244,14 +1295,13 @@ def add_map_layer_to_group( f'Warstwa nieprawidłowa {layer.name()}. Wymagana interwencja.', "GIAP - PolaMap Lite", Qgis.Info) - root = project.layerTreeRoot() if main_group_name and root.findGroup(main_group_name): group = root.findGroup(main_group_name).findGroup(group_name) else: group = root.findGroup(group_name) if not group: if force_create: - group = project.layerTreeRoot().addGroup(group_name) + group = root.addGroup(group_name) else: project.addMapLayer(layer) return @@ -1259,6 +1309,7 @@ def add_map_layer_to_group( if group_name: group.insertLayer(position, layer) + def find_widget_with_menu_in_toolbar(toolbar: QToolBar) -> List[QToolButton]: lista_widgets = toolbar.children() qmenu_list = [] @@ -1268,6 +1319,7 @@ def find_widget_with_menu_in_toolbar(toolbar: QToolBar) -> List[QToolButton]: qmenu_list.append(widget) return qmenu_list + def get_action_from_toolbar(toolbar: QToolBar) -> List[QAction]: lista_widgets = toolbar.children() act_list = [] @@ -1277,9 +1329,10 @@ def get_action_from_toolbar(toolbar: QToolBar) -> List[QAction]: act_list.append(widget.actions()[0]) return act_list + def add_action_from_toolbar(iface: iface, sec, btn: list) -> None: if iface.mainWindow().findChild(QToolBar, btn[0].split('_')[0]): - dlu = len(btn[0].split('_')) + dlu = len(btn[0].split('_')) if dlu == max_ele_nazwy: objname_toolbar, ind, typ, ind_menu = btn[0].split('_') else: @@ -1298,22 +1351,23 @@ def add_action_from_toolbar(iface: iface, sec, btn: list) -> None: if dlu == max_ele_nazwy: if widg.menu(): - #Wyciąganie i dodawanie pojdeynczej akcji z menu + # Wyciąganie i dodawanie pojdeynczej akcji z menu sel_act_from_menu = widg.menu().actions()[int(ind_menu)] objname = sel_act_from_menu.objectName() sel_act_from_menu.setObjectName(btn[0]) sec.add_action(sel_act_from_menu, btn[1], btn[2]) sel_act_from_menu.setObjectName(objname) else: - #Dodawanie wybranej akcji + # Dodawanie wybranej akcji sel_act = widg.actions()[int(ind_menu)] objname = sel_act.objectName() sel_act.setObjectName(btn[0]) sec.add_action(sel_act, btn[1], btn[2]) sel_act.setObjectName(objname) else: - #Dodawanie menu i domyślnej akcji + # Dodawanie menu i domyślnej akcji objname = widg.defaultAction().objectName() widg.defaultAction().setObjectName(btn[0]) - sec.add_action(widg.defaultAction(), btn[1], btn[2], widg.menu()) - widg.defaultAction().setObjectName(objname) \ No newline at end of file + sec.add_action(widg.defaultAction(), btn[1], btn[2], + widg.menu()) + widg.defaultAction().setObjectName(objname) From fb7dab16be866c4006afd78a230ed7e689a5b13a Mon Sep 17 00:00:00 2001 From: Patryk Date: Thu, 28 Jul 2022 14:10:37 +0200 Subject: [PATCH 5/7] Poprawki --- Searcher/searchAddress.py | 12 +++++++----- Searcher/searchParcel.py | 5 +++-- Searcher/searchTool.py | 24 ++++++++++++++---------- utils.py | 4 ++++ 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Searcher/searchAddress.py b/Searcher/searchAddress.py index f9156b9..1d61e05 100644 --- a/Searcher/searchAddress.py +++ b/Searcher/searchAddress.py @@ -9,7 +9,7 @@ from qgis.PyQt.QtCore import QVariant from qgis.core import QgsGeometry, QgsFeature, QgsField, QgsFields, \ - QgsVectorLayer, QgsMessageLog, Qgis + QgsVectorLayer, QgsMessageLog, Qgis from qgis.utils import iface from ..utils import tr, add_map_layer_to_group, search_group_name, project @@ -56,7 +56,7 @@ def fetch_address(self, address: str) -> None: return self.res.decode() - def get_layer(self) -> Union[bool,Tuple[str]]: + def get_layer(self) -> Union[bool, Tuple[str]]: req_type = self.jres['type'] if req_type in ['city', 'address']: org = 'MultiPoint?crs=epsg:2180&index=yes' @@ -75,7 +75,8 @@ def get_layer(self) -> Union[bool,Tuple[str]]: return False return org, obj_type, qml - def get_layer_data(self, org: str, obj_type: str, qml: str) -> QgsVectorLayer: + def get_layer_data(self, org: str, obj_type: str, + qml: str) -> QgsVectorLayer: lyr = project.mapLayersByName(obj_type) if lyr: return lyr[0] @@ -96,7 +97,8 @@ def get_layer_data(self, org: str, obj_type: str, qml: str) -> QgsVectorLayer: lyr.loadNamedStyle(os.path.join(direc, qml)) return lyr - def process_results(self) -> Union[Tuple[bool,str], Tuple[bool,QgsFeature]]: + def process_results(self) -> Union[ + Tuple[bool, str], Tuple[bool, QgsFeature]]: try: self.jres = json.loads(self.res) except JSONDecodeError: @@ -154,7 +156,7 @@ def zoom_to_feature(self, layer: str) -> None: iface.mapCanvas().zoomToSelected(layer) layer.removeSelection() - def add_feats(self, feats: QgsFeature) -> Union[bool,None]: + def add_feats(self, feats: QgsFeature) -> Union[bool, None]: if isinstance(feats, str): pass else: diff --git a/Searcher/searchParcel.py b/Searcher/searchParcel.py index 31c39a9..385c16a 100644 --- a/Searcher/searchParcel.py +++ b/Searcher/searchParcel.py @@ -7,7 +7,7 @@ from urllib.request import urlopen from qgis.core import QgsGeometry, QgsFeature, \ - QgsVectorLayer, Qgis + QgsVectorLayer, Qgis from qgis.utils import iface from ..utils import tr, CustomMessageBox, search_group_name, \ @@ -72,7 +72,8 @@ def fetch(self) -> bool: f"{tr('Service did not find any matches, wrong plot number.')}").button_ok() return False - self.responce = self.natural_sort([ter for ter in res[1:] if ter != '']) + self.responce = self.natural_sort( + [ter for ter in res[1:] if ter != '']) return True def natural_sort(self, list: List[str]) -> List[str]: diff --git a/Searcher/searchTool.py b/Searcher/searchTool.py index 879a138..a2e983c 100644 --- a/Searcher/searchTool.py +++ b/Searcher/searchTool.py @@ -83,7 +83,7 @@ def tips(self) -> None: self.getStreets(obj['1']['simc'], obj['1']['city']) if obj_type == 'address': self.names.setStringList([ - f"{obj['1']['city']}, {obj['1']['street']} {obj['1']['number']}"]) + f"{obj['1']['city']}, {obj['1']['street']} {obj['1']['number']}"]) if not limit: return self.completer.setCompletionPrefix(f"{address.split(',')[0]}, ") @@ -154,10 +154,13 @@ def validate_lineedit(self) -> bool: def add_chosen_border(self, mess: str) -> None: # lay_keys = ['Obręby_ewidencyjne', 'Gminy', 'Powiaty', 'Województwa'] - lay_data = {'Obręby_ewidencyjne': ["A06_Granice_obrebow_ewidencyjnych", self.dock.comboBox_obr], - 'Gminy': ["A03_Granice_gmin", self.dock.comboBox_gmina], - 'Powiaty': ["A02_Granice_powiatow", self.dock.comboBox_pow], - 'Województwa': ["A01_Granice_wojewodztw", self.dock.comboBox_woj]} + lay_data = {'Obręby_ewidencyjne': ["A06_Granice_obrebow_ewidencyjnych", + self.dock.comboBox_obr], + 'Gminy': ["A03_Granice_gmin", self.dock.comboBox_gmina], + 'Powiaty': ["A02_Granice_powiatow", + self.dock.comboBox_pow], + 'Województwa': ["A01_Granice_wojewodztw", + self.dock.comboBox_woj]} for lay_key in lay_data: if lay_data[lay_key][1].currentIndex() != 0: _, jpt_kod_je = lay_data[lay_key][1].currentText().split("|") @@ -277,7 +280,7 @@ def gmi_changed(self) -> None: self.dock.comboBox_obr.view().setFixedWidth(self.widthforview(result)) self.dock.comboBox_obr.blockSignals(False) - def clear_comboBoxes(self, level:str = None) -> None: + def clear_comboBoxes(self, level: str = None) -> None: """Clear comboboxes to level where user change something""" self.dock.comboBox_obr.blockSignals(True) self.dock.comboBox_obr.clear() @@ -298,21 +301,21 @@ def clear_comboBoxes(self, level:str = None) -> None: self.dock.comboBox_pow.addItem(tr('District')) self.dock.comboBox_pow.blockSignals(False) - def _get_voi_code(self) -> Union[str,bool]: + def _get_voi_code(self) -> Union[str, bool]: voi_txt = self.dock.comboBox_woj.currentText() if '|' not in voi_txt: self.clear_comboBoxes() return False return voi_txt.split('|')[1] - def _get_dis_code(self) -> Union[str,bool]: + def _get_dis_code(self) -> Union[str, bool]: dis_txt = self.dock.comboBox_pow.currentText() if '|' not in dis_txt: self.clear_comboBoxes('dis') return False return dis_txt.split('|')[1] - def _get_mun_code(self) -> Union[str,bool]: + def _get_mun_code(self) -> Union[str, bool]: mun_txt = self.dock.comboBox_gmina.currentText() if '|' not in mun_txt: self.clear_comboBoxes('mun') @@ -326,7 +329,8 @@ def search_parcel(self) -> None: else: comm = self.dock.comboBox_obr.currentText() if not parc: - self.add_chosen_border(f"{tr('Address of parcel is not valid.')}") + self.add_chosen_border( + f"{tr('Address of parcel is not valid.')}") return if '|' not in comm: CustomMessageBox(None, diff --git a/utils.py b/utils.py index c61720a..a0fad11 100644 --- a/utils.py +++ b/utils.py @@ -125,6 +125,7 @@ def set_size(self, value: int) -> None: self.stylesheet = f'*{{font: {value}pt;}} {self.stylesheet}' self.setStyleSheet(self.stylesheet) + class SingletonModel: __instance = None @@ -136,6 +137,7 @@ def __new__(cls, *args): SingletonModel.__instance = object.__new__(cls, *args) return SingletonModel.__instance + class ProgressDialog(QProgressDialog, SingletonModel): def __init__(self, parent=None, title='GIAP-PolaMap'): @@ -186,6 +188,7 @@ def stop(self): self.setValue(100) self.close() + def identify_layer(ls, layer_to_find): for layer in list(ls.values()): if layer.name() == layer_to_find: @@ -1248,6 +1251,7 @@ def paint(self, painter, option, index): max_ele_nazwy = 4 + def icon_manager(tool_list: List[str], main_qgs_widget: QObject = None) -> \ Dict[str, Union[Optional[QIcon], Any]]: dirnm = normalize_path(os.path.join(os.path.dirname(__file__), 'icons')) From f5aec31bf2551f64d8048fb5bf03b924803d1d02 Mon Sep 17 00:00:00 2001 From: Patryk Date: Fri, 29 Jul 2022 07:19:48 +0200 Subject: [PATCH 6/7] Poprawki --- Searcher/searchTool.py | 12 ++++++------ utils.py | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Searcher/searchTool.py b/Searcher/searchTool.py index a2e983c..35a56a8 100644 --- a/Searcher/searchTool.py +++ b/Searcher/searchTool.py @@ -4,7 +4,7 @@ from urllib.request import urlopen import requests -from qgis.PyQt.QtCore import Qt +from PyQt5.QtCore import Qt from qgis.PyQt.QtGui import QFont, QFontMetrics from qgis.PyQt.QtCore import QStringListModel from qgis.PyQt.QtCore import QTimer @@ -153,7 +153,6 @@ def validate_lineedit(self) -> bool: f" {tr('Invalid')} {tr('Empty address field')}").button_ok() def add_chosen_border(self, mess: str) -> None: - # lay_keys = ['Obręby_ewidencyjne', 'Gminy', 'Powiaty', 'Województwa'] lay_data = {'Obręby_ewidencyjne': ["A06_Granice_obrebow_ewidencyjnych", self.dock.comboBox_obr], 'Gminy': ["A03_Granice_gmin", self.dock.comboBox_gmina], @@ -162,18 +161,19 @@ def add_chosen_border(self, mess: str) -> None: 'Województwa': ["A01_Granice_wojewodztw", self.dock.comboBox_woj]} for lay_key in lay_data: - if lay_data[lay_key][1].currentIndex() != 0: + if lay_data[lay_key][1].currentIndex(): _, jpt_kod_je = lay_data[lay_key][1].currentText().split("|") if lay_key == "Gminy": jpt_kod_je = jpt_kod_je.replace("_", "") adres = lay_data[lay_key][0] lay_name = lay_key break - if not jpt_kod_je or not adres or not lay_name: - CustomMessageBox(None, + if 'jpt_kod_je' not in locals() or 'adres' not in locals()\ + or 'lay_name' not in locals(): + CustomMessageBox(self.iface.mainWindow(), mess).button_ok() return - prg_dlg = ProgressDialog() + prg_dlg = ProgressDialog(self.iface.mainWindow()) prg_dlg.start_steped(tr("Adding layers...")) prg_dlg.start() url = f"{WFS_PRG}?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAME=ms:{adres}&TYPENAMES=ms:{adres}" diff --git a/utils.py b/utils.py index a0fad11..7ebcf2b 100644 --- a/utils.py +++ b/utils.py @@ -149,7 +149,6 @@ def __init__(self, parent=None, title='GIAP-PolaMap'): self.setFixedHeight(100) self.setMaximum(100) self.setCancelButton(None) - # self.setStyleSheet(self.stylesheet) self.setWindowFlags(Qt.Dialog | Qt.WindowCloseButtonHint) self.rejected.connect(self.stop) self.setWindowModality(Qt.WindowModal) From 0f528bd7e8885dbfedd731f9fd77ef4b14c896bf Mon Sep 17 00:00:00 2001 From: Patryk Date: Fri, 29 Jul 2022 08:05:24 +0200 Subject: [PATCH 7/7] Poprawki --- utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 7ebcf2b..593f277 100644 --- a/utils.py +++ b/utils.py @@ -140,10 +140,10 @@ def __new__(cls, *args): class ProgressDialog(QProgressDialog, SingletonModel): - def __init__(self, parent=None, title='GIAP-PolaMap'): + def __init__(self, parent=None, title='GIAP-PolaMap(lite)'): super(ProgressDialog, self).__init__(parent) self.setWindowTitle(title) - self.setWindowIcon(QIcon(':/plugins/GIAP-PolaMap/icons/giap_logo.png')) + self.setWindowIcon(icon_manager(['window_icon'])['window_icon']) self.setLabelText('Proszę czekać...') self.setFixedWidth(300) self.setFixedHeight(100)