Skip to content

Commit

Permalink
v1.4.1-pop (#74)
Browse files Browse the repository at this point in the history
* Naprawa nieusuwajacego QGIS-feed

* poprawa qgis-feed o wylaczanie wtyczki w menagerze wtyczek
  • Loading branch information
wojtek19022 authored Nov 7, 2024
1 parent d8b5e5f commit 3a0afdd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 84 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

### Uwaga

Warunkiem koniecznym do prawidłowego działania wtyczki jest posiadanie wersji QGIS 3.16.16 lub wyższej.
Warunkiem koniecznym do prawidłowego działania wtyczki jest posiadanie wersji QGIS 3.22 lub wyższej.



Expand Down Expand Up @@ -82,4 +82,4 @@ The plugin offers 3 methods for searching and downloading boundaries.
In the side panel, there are options to select the area of interest (parcel, registration area, municipality, county, voivodeship). If you want to download the voivodeship layer where your parcel is located, select "Województwo" in the side panel. Once you enter the parcel identifier, the plugin will automatically download the associated voivodeship or another selected area. If the parcel number appears more than once in the same registration area, a message will appear at the top of QGIS, and the plugin will download the first parcel returned by the ULDK service.

### Note
A necessary condition for the plugin to work correctly is having QGIS version 3.16.16 or higher."
A necessary condition for the plugin to work correctly is having QGIS version 3.22 or higher."
28 changes: 15 additions & 13 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
ULDK_GMINA_DICT_URL = 'https://uldk.gugik.gov.pl/service.php?obiekt=gmina&wynik=gmina,teryt&teryt='
ULDK_POWIAT_DICT_URL = 'https://uldk.gugik.gov.pl/service.php?obiekt=powiat&wynik=powiat,teryt&teryt='
ULDK_WOJEWODZTWO_DICT_URL = 'https://uldk.gugik.gov.pl/service.php?obiekt=wojewodztwo&wynik=wojewodztwo,teryt'
FEED_URL = 'https://qgisfeed.envirosolutions.pl/'

INDUSTRIES = {
"999":"Nie wybrano",
"e":"Energetyka/OZE",
"u":"Urząd",
"td":"Transport/Drogi",
"pg":"Planowanie/Geodezja",
"wk":"WodKan",
"s":"Środowisko",
"rl":"Rolnictwo/Leśnictwo",
"tk":"Telkom",
"edu":"Edukacja",
"i":"Inne",
"it":"IT",
"n":"Nieruchomości"
"999": "Nie wybrano",
"e": "Energetyka/OZE",
"u": "Urząd",
"td": "Transport/Drogi",
"pg": "Planowanie/Geodezja",
"wk": "WodKan",
"s": "Środowisko",
"rl": "Rolnictwo/Leśnictwo",
"tk": "Telkom",
"edu": "Edukacja",
"i": "Inne",
"it": "IT",
"n": "Nieruchomości"
}

DIALOG_MAPPING = {
Expand Down
3 changes: 2 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[general]
name=Usługa Lokalizacji Działek Katastralnych
qgisMinimumVersion=3.0
qgisMinimumVersion=3.22
description=Wtyczka pozwala na pobieranie geometrii granic działek katastralnych, obrębów, gmin, powiatów i województw. ENG: The plugin made for dowloading parcells geometry from The Central Office of Geodesy and Cartography of Poland "ULDK API".
version=1.4.1
author=EnviroSolutions Sp. z o.o.
Expand All @@ -27,6 +27,7 @@ changelog=
Wersja 1.4.1
* Dodanie branż do QGIS-feed
* Zmiana lokalizacji UI wtyczki
* Zmiana minimalnej wersji QGIS na 3.22
# Wersja 1.4.0
# * Dodanie możliwości pobierania budynkow
# * Przyspieszenie działania trzeciej zakładki
Expand Down
103 changes: 35 additions & 68 deletions qgis_feed.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from qgis.core import (QgsNewsFeedParser, QgsSettings, QgsNewsFeedModel,
from qgis.core import (QgsNewsFeedParser, QgsSettings, QgsNewsFeedModel,
QgsMessageLog, QgsApplication)
from qgis.PyQt.QtCore import QUrl
from qgis.PyQt import uic
Expand All @@ -8,34 +8,36 @@
import os
import unicodedata

from .constants import INDUSTRIES
from .constants import INDUSTRIES, FEED_URL


class QgisFeed:
def __init__(self, selected_industry, plugin_name):
self.s = QgsSettings()
# self.envirosolutionsFeedPattern = re.compile('core/NewsFeed/httpsqgisfeedenvirosolutionspl/\d+/\w+')
self.industries_dict = INDUSTRIES

self.industry_decoded = [key for key, val in self.industries_dict.items() if val == selected_industry]
self.plugin_name_slug = self.create_slug(plugin_name)

self.es_url = "https://qgisfeed.envirosolutions.pl/" if len(self.industry_decoded) == 0 else f"https://qgisfeed.envirosolutions.pl/?industry={self.industry_decoded[0]}&plugin={self.plugin_name_slug}"
self.es_url = (
f"{FEED_URL}?industry={self.industry_decoded[0]}&plugin={self.plugin_name_slug}" if self.industry_decoded else FEED_URL
)
self.parser = QgsNewsFeedParser(
feedUrl= QUrl(self.es_url)
feedUrl=QUrl(self.es_url)
)
self.industry_url_short = self.shortenUrl(self.es_url)
self.envirosolutionsFeedPattern_old = re.compile(f"core/NewsFeed/{self.industry_url_short}")
self.envirosolutionsFeedPattern_new = re.compile(f"app/news-feed/items/{self.industry_url_short}")

self.parser.fetched.connect(self.registerFeed)

def shortenUrl(self, url):
"""
Funkcja przetwarza zapisany adres qgisfeed'a
Funkcja przetwarza zapisany adres qgisfeed'a
na forme zapisana w qgis settingsach
"""
return re.sub(r'://|\.|:|/\?|=|&|-', '', url)

return re.sub(r'://|\.|:|/\?|=|&|-|:', '', url)

def create_slug(self, text):
"""
Expand All @@ -44,7 +46,7 @@ def create_slug(self, text):
slug = self.normalizeString(text)
slug = re.sub(r'[^a-z0-9\s-]', '', slug.lower()) # Remove non-alphanumeric characters except spaces and hyphens
slug = re.sub(r'[\s]+', '-', slug) # Replace spaces with hyphens

return slug.strip('-')

def normalizeString(self, text):
Expand All @@ -55,7 +57,6 @@ def registerFeed(self):
"""
Function registers QGIS Feed
"""

QgsMessageLog.logMessage('Registering feed')
for key in self.s.allKeys():
if self.envirosolutionsFeedPattern_old.match(key) or self.envirosolutionsFeedPattern_new.match(key):
Expand All @@ -65,10 +66,14 @@ def registerFeed(self):
# ponizszy fragment odpowiada za mozliwosc ciaglego wyswietlania wiadomosci
# przy wlaczeniu qgis za kazdym razem

#check_fetch = self.checkIsFetchTime()
#if check_fetch is True: self.s.remove(key)
if 'cache' in key:
check_fetch = self.checkIsFetchTime()
if check_fetch is True: self.s.remove(key)

self.s.sync()

self.s.beginGroup(f"app/news-feed/items/{self.industry_url_short}")
self.s.setValue("last-fetch-time", 0)

def removeDismissed(self):
"""
Function checks whether there was already initialized QGIS Feed
Expand All @@ -77,17 +82,21 @@ def removeDismissed(self):
for key in self.s.allKeys():
if self.envirosolutionsFeedPattern_old.match(key) or self.envirosolutionsFeedPattern_new.match(key):
# sprawdz czy jest odpowiadajacy w qgis
if self.s.contains(re.sub(r'(\d+)', r'9999\1', key.replace(self.industry_url_short, 'httpsfeedqgisorg'))):
if self.s.contains(
re.sub(
r'(\d+)',
r'9999\1',
key.replace(self.industry_url_short, 'httpsfeedqgisorg')
)
):
self.s.remove(key)
#self.s.remove(key)

def checkIsFetchTime(self):
"""
Function check if the fetch time from QGIS Feed was already registered
"""

return self.s.contains(f"core/NewsFeed/{self.industry_url_short}/lastFetchTime") \
or self.s.contains(f"app/news-feed/items/{self.industry_url_short}/last-fetch-time")
or self.s.contains(f"app/news-feed/items/{self.industry_url_short}/last-fetch-time")

def initFeed(self):
"""
Expand All @@ -97,14 +106,14 @@ def initFeed(self):
check_fetch = self.checkIsFetchTime()
if check_fetch is True: self.removeDismissed()
self.parser.fetch()


class QgisFeedDialog(QDialog):
def __init__(self, parent=None):
super(QgisFeedDialog, self).__init__(parent)
self.ui_file_path = os.path.join(os.path.dirname(__file__),'ui','qgis_feed.ui')
self.ui_file_path = os.path.join(os.path.dirname(__file__), 'ui', 'qgis_feed.ui')
uic.loadUi(self.ui_file_path, self)

self.comboBox = self.findChild(QComboBox, 'comboBox')
self.pushButton = self.findChild(QPushButton, 'pushButton')
self.pushButton.clicked.connect(self.onSaveClicked)
Expand All @@ -113,57 +122,15 @@ def __init__(self, parent=None):

def loadPreviousSelection(self):
settings = QgsSettings()
previous_selection = settings.value("selected_industry")
if previous_selection:
if previous_selection := settings.value("selected_industry"):
index = self.comboBox.findText(previous_selection)
if index != -1:
self.comboBox.setCurrentIndex(index)
self.hide()
self.hide()

def onSaveClicked(self):
#zapisz wybraną branżę
# zapisz wybraną branżę
selected_industry = self.comboBox.currentText()
settings = QgsSettings()
settings.setValue("selected_industry", selected_industry)
self.accept()

# class QgisFeedDB:

# def __init__(self):
# self.db = QgsApplication.qgisUserDatabaseFilePath()
# self.tbl_name = "qgis_feed_vals"

# def createConnection(self):
# print(self.db)
# connection = sql.connect(self.db)
# cursor = connection.cursor()

# return cursor

# def checkTblExist(self, cursor):
# querry = f"SELECT name FROM sqlite_master WHERE type='table' AND name='{self.tbl_name}';"
# print(f"query: {querry}")
# res = cursor.execute(querry)

# return res.fetchone()

# def createUserParamsDB(self, cursor):
# query = """
# CREATE TABLE qgis_feed_vals(
# id serial PRIMARY KEY,
# industry VARCHAR(100),
# date_insert DATE
# );
# """
# cursor.execute(query)

# def selectUserBrand(self, cursor):
# query = f"SELECT industry from '{self.tbl_name}'"
# cursor.execute(query)

# def insertNecessaryVals(self, cursor, user_industry):
# query = f"""
# INSERT INTO {self.tbl_name}(industry, date_insert) VALUES ('{user_industry}',DATE('NOW'))
# """
# cursor.execute(query)

settings.setValue("selected_industry", selected_industry)
self.accept()

0 comments on commit 3a0afdd

Please sign in to comment.