mirror of
https://github.com/ARUP-CAS/aiscr-qgis-amcr-viewer.git
synced 2026-10-08 20:07:36 +02:00
Merge pull request #60 from ARUP-CAS/version/v2.1.0
release: AMČR Viewer 2.1.0
This commit is contained in:
8 files changed
+18014
-22384
No files matched your search
+136
-84
@@ -9,24 +9,30 @@ from qgis.core import QgsMessageLog, Qgis
|
||||
# Define paths for the plugin and its codelists directory
|
||||
PLUGIN_DIR = os.path.dirname(__file__)
|
||||
CODELISTS_DIR = os.path.join(PLUGIN_DIR, 'codelists')
|
||||
BASE_URL = "https://api.aiscr.cz/2.2/oai"
|
||||
BASE_URL_AMCR = "https://api.aiscr.cz/2.2/oai"
|
||||
BASE_URL_DA = "https://digiarchiv.aiscr.cz/api/search/query"
|
||||
OUTPUT_FILE = os.path.join(CODELISTS_DIR, 'heslar.csv')
|
||||
|
||||
slovnicek = {
|
||||
'obdobi': 'heslo:obdobi',
|
||||
'typ_akce': 'heslo:akce_typ',
|
||||
'areal': 'heslo:areal',
|
||||
'kraj': 'ruian_kraj',
|
||||
'organizace': 'organizace',
|
||||
'okres': 'ruian_okres',
|
||||
'katastr': 'ruian_katastr',
|
||||
'vedouci': 'osoba',
|
||||
'pian_presnost': 'heslo:pian_presnost',
|
||||
'typ_lokality': 'heslo:lokalita_typ',
|
||||
'druh_lokality': 'heslo:lokalita_druh',
|
||||
'jistota': 'heslo:jistota_urceni',
|
||||
'lokalita_zachovalost': 'heslo:stav_dochovani',
|
||||
'pristupnost': 'heslo:pristupnost'
|
||||
'obdobi': (BASE_URL_AMCR, 'heslo:obdobi'),
|
||||
'typ_akce': (BASE_URL_AMCR, 'heslo:akce_typ'),
|
||||
'areal': (BASE_URL_AMCR, 'heslo:areal'),
|
||||
'kraj': (BASE_URL_AMCR, 'ruian_kraj'),
|
||||
'organizace': (BASE_URL_AMCR, 'organizace'),
|
||||
'okres': (BASE_URL_AMCR, 'ruian_okres'),
|
||||
'katastr': (BASE_URL_AMCR, 'ruian_katastr'),
|
||||
'pian_presnost': (BASE_URL_AMCR, 'heslo:pian_presnost'),
|
||||
'typ_lokality': (BASE_URL_AMCR, 'heslo:lokalita_typ'),
|
||||
'druh_lokality': (BASE_URL_AMCR, 'heslo:lokalita_druh'),
|
||||
'jistota': (BASE_URL_AMCR, 'heslo:jistota_urceni'),
|
||||
'lokalita_zachovalost': (BASE_URL_AMCR, 'heslo:stav_dochovani'),
|
||||
'pristupnost': (BASE_URL_AMCR, 'heslo:pristupnost'),
|
||||
'nalez_kategorie': (BASE_URL_AMCR, 'heslo:predmet_druh_kat'),
|
||||
'druh_nalezu': (BASE_URL_AMCR, 'heslo:predmet_druh'),
|
||||
'specifikace': (BASE_URL_AMCR, 'heslo:predmet_specifikace'),
|
||||
'nalezove_okolnosti': (BASE_URL_AMCR, 'heslo:nalezove_okolnosti'),
|
||||
'vedouci': (BASE_URL_DA, 'f_vedouci'),
|
||||
'nalezce': (BASE_URL_DA, 'f_nalezce'),
|
||||
}
|
||||
|
||||
NS = {
|
||||
@@ -97,13 +103,19 @@ def load_all_data():
|
||||
return categorized_data
|
||||
|
||||
|
||||
def fetch_set(internal_name, api_set, task=None):
|
||||
def fetch_set(base_url, internal_name, api_set, task=None):
|
||||
dataset = []
|
||||
params = {
|
||||
params_amcr = {
|
||||
"verb": "ListRecords",
|
||||
"metadataPrefix": "oai_dc",
|
||||
"set": api_set
|
||||
}
|
||||
params_da = {
|
||||
"entity": "samostatny_nalez" if internal_name == "nalezce" else "akce",
|
||||
"rows": 0,
|
||||
"noFacets": "false",
|
||||
"onlyFacets": "true"
|
||||
}
|
||||
|
||||
while True:
|
||||
# Check for cancellation at each iteration
|
||||
@@ -111,75 +123,95 @@ def fetch_set(internal_name, api_set, task=None):
|
||||
return None
|
||||
|
||||
try:
|
||||
response = requests.get(BASE_URL, params=params, timeout=30)
|
||||
response.raise_for_status()
|
||||
root = ET.fromstring(response.content) # nosec
|
||||
if "digiarchiv" not in base_url:
|
||||
response = requests.get(base_url, params=params_amcr, timeout=30)
|
||||
response.raise_for_status()
|
||||
root = ET.fromstring(response.content) # nosec
|
||||
|
||||
records = root.findall('.//oai:record', NS)
|
||||
for rec in records:
|
||||
metadata = rec.find('.//oai_dc:dc', NS)
|
||||
if metadata is not None:
|
||||
# Code (identifier)
|
||||
identifier_el = metadata.find('dc:identifier', NS)
|
||||
kod = (
|
||||
identifier_el.text
|
||||
if identifier_el is not None
|
||||
else ""
|
||||
)
|
||||
|
||||
# Title – filter out system labels "AMČR - ..."
|
||||
titles = metadata.findall('dc:title', NS)
|
||||
nazev = ""
|
||||
for t in titles:
|
||||
if (
|
||||
t.text
|
||||
and not t.text.startswith("AMČR -")
|
||||
and not t.text.startswith(" AMČR -")
|
||||
):
|
||||
nazev = t.text
|
||||
break
|
||||
# If no title passed the filter, fall back
|
||||
# to the first available one
|
||||
if not nazev and titles:
|
||||
nazev = titles[0].text
|
||||
|
||||
specialni_pripady = ['okres', 'katastr']
|
||||
|
||||
if internal_name in specialni_pripady:
|
||||
kod = nazev
|
||||
|
||||
if internal_name == 'pristupnost':
|
||||
kod = next(
|
||||
(
|
||||
t.text for t in titles
|
||||
if t.text
|
||||
and len(t.text) == 1
|
||||
and t.text.isalpha()
|
||||
),
|
||||
None
|
||||
records = root.findall('.//oai:record', NS)
|
||||
for rec in records:
|
||||
metadata = rec.find('.//oai_dc:dc', NS)
|
||||
if metadata is not None:
|
||||
# Code (identifier)
|
||||
identifier_el = metadata.find('dc:identifier', NS)
|
||||
kod = (
|
||||
identifier_el.text
|
||||
if identifier_el is not None
|
||||
else ""
|
||||
)
|
||||
# Skip records without a valid one-letter code –
|
||||
# a None code would end up in the CSV and later
|
||||
# in the API filter as the string "None"
|
||||
if not kod:
|
||||
continue
|
||||
|
||||
# Title – filter out system labels "AMČR - ..."
|
||||
titles = metadata.findall('dc:title', NS)
|
||||
nazev = ""
|
||||
for t in titles:
|
||||
if (
|
||||
t.text
|
||||
and not t.text.startswith("AMČR -")
|
||||
and not t.text.startswith(" AMČR -")
|
||||
):
|
||||
nazev = t.text
|
||||
break
|
||||
# If no title passed the filter, fall back
|
||||
# to the first available one
|
||||
if not nazev and titles:
|
||||
nazev = titles[0].text
|
||||
|
||||
specialni_pripady = ['okres', 'katastr']
|
||||
|
||||
if internal_name in specialni_pripady:
|
||||
kod = nazev
|
||||
|
||||
if internal_name == 'pristupnost':
|
||||
kod = next(
|
||||
(
|
||||
t.text for t in titles
|
||||
if t.text
|
||||
and len(t.text) == 1
|
||||
and t.text.isalpha()
|
||||
),
|
||||
None
|
||||
)
|
||||
# Skip records without a valid one-letter code –
|
||||
# a None code would end up in the CSV and later
|
||||
# in the API filter as the string "None"
|
||||
if not kod:
|
||||
continue
|
||||
|
||||
dataset.append({
|
||||
'Název': nazev,
|
||||
'Kód': kod,
|
||||
'Kategorie': internal_name
|
||||
})
|
||||
|
||||
# Pagination
|
||||
token = root.find('.//oai:resumptionToken', NS)
|
||||
if token is not None and token.text:
|
||||
params_amcr = {
|
||||
"verb": "ListRecords",
|
||||
"resumptionToken": token.text
|
||||
}
|
||||
time.sleep(0.5)
|
||||
else:
|
||||
break
|
||||
|
||||
else:
|
||||
response = requests.get(base_url, params=params_da, timeout=30)
|
||||
response.raise_for_status()
|
||||
data_json = response.json()
|
||||
|
||||
records = data_json['facet_counts']['facet_fields'][api_set]
|
||||
|
||||
for r in records:
|
||||
|
||||
nazev = r["name"]
|
||||
|
||||
dataset.append({
|
||||
'Název': nazev,
|
||||
'Kód': kod,
|
||||
'Kategorie': internal_name
|
||||
})
|
||||
|
||||
# Pagination
|
||||
token = root.find('.//oai:resumptionToken', NS)
|
||||
if token is not None and token.text:
|
||||
params = {
|
||||
"verb": "ListRecords",
|
||||
"resumptionToken": token.text
|
||||
}
|
||||
time.sleep(0.5)
|
||||
else:
|
||||
break
|
||||
'Název': nazev,
|
||||
'Kód': nazev,
|
||||
'Kategorie': internal_name
|
||||
})
|
||||
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
QgsMessageLog.logMessage(
|
||||
@@ -195,8 +227,13 @@ def download_heslare(task=None):
|
||||
ensure_codelists_dir()
|
||||
all_data = []
|
||||
total_sets = len(slovnicek)
|
||||
# index, (interni, api_nazev)
|
||||
for index, (key, value) in enumerate(slovnicek.items()):
|
||||
|
||||
base_url = value[0]
|
||||
interni = key
|
||||
api_nazev = value[1]
|
||||
|
||||
for index, (interni, api_nazev) in enumerate(slovnicek.items()):
|
||||
# Check if the user cancelled the task via the QGIS taskbar
|
||||
if task and task.isCanceled():
|
||||
return False
|
||||
@@ -206,7 +243,7 @@ def download_heslare(task=None):
|
||||
"AMČR", Qgis.Info)
|
||||
|
||||
# Pass the task correctly to the updated fetch function
|
||||
data = fetch_set(interni, api_nazev, task=task)
|
||||
data = fetch_set(base_url, interni, api_nazev, task=task)
|
||||
|
||||
if data is None:
|
||||
return False # Cancelled mid-download
|
||||
@@ -260,6 +297,16 @@ def refresh_globals():
|
||||
LOKALITA_ZACHOVALOST.update(data.get('lokalita_zachovalost', {}))
|
||||
PRISTUPNOST.clear()
|
||||
PRISTUPNOST.update(data.get('pristupnost', {}))
|
||||
NALEZ_KATEGORIE.clear()
|
||||
NALEZ_KATEGORIE.update(data.get('nalez_kategorie', {}))
|
||||
DRUH_NALEZU.clear()
|
||||
DRUH_NALEZU.update(data.get('druh_nalezu', {}))
|
||||
SPECIFIKACE.clear()
|
||||
SPECIFIKACE.update(data.get('specifikace', {}))
|
||||
NALEZOVE_OKOLNOSTI.clear()
|
||||
NALEZOVE_OKOLNOSTI.update(data.get('nalezove_okolnosti', {}))
|
||||
NALEZCE.clear()
|
||||
NALEZCE.update(data.get('nalezce', {}))
|
||||
|
||||
|
||||
# Initialize empty dicts that will be populated immediately below
|
||||
@@ -277,5 +324,10 @@ DRUH_LOKALITY = {}
|
||||
JISTOTA = {}
|
||||
LOKALITA_ZACHOVALOST = {}
|
||||
PRISTUPNOST = {}
|
||||
NALEZ_KATEGORIE = {}
|
||||
DRUH_NALEZU = {}
|
||||
SPECIFIKACE = {}
|
||||
NALEZOVE_OKOLNOSTI = {}
|
||||
NALEZCE = {}
|
||||
|
||||
refresh_globals()
|
||||
+272
-44
@@ -3,18 +3,33 @@ from qgis.PyQt.QtWidgets import (QDialog, QVBoxLayout,
|
||||
QLineEdit, QDialogButtonBox,
|
||||
QCheckBox, QGroupBox, QPushButton,
|
||||
QListWidget, QListWidgetItem, QHBoxLayout,
|
||||
QMessageBox, QLabel, QFormLayout)
|
||||
QMessageBox, QLabel, QFormLayout,
|
||||
QGridLayout, QScrollArea, QFrame, QWidget)
|
||||
from qgis.PyQt.QtCore import Qt, QSettings
|
||||
from qgis.core import (QgsTask, QgsApplication,
|
||||
QgsMessageLog, Qgis, QgsAuthMethodConfig)
|
||||
from qgis.gui import QgsDateEdit
|
||||
from qgis.utils import iface
|
||||
from .amcr_codelists import (OBDOBI, TYP_AKCE, KRAJE, AREAL, ORGANIZACE,
|
||||
OKRESY, KATASTRY, VEDOUCI, PIAN_PRESNOST,
|
||||
TYP_LOKALITY, DRUH_LOKALITY, JISTOTA,
|
||||
LOKALITA_ZACHOVALOST, PRISTUPNOST,
|
||||
LOKALITA_ZACHOVALOST, PRISTUPNOST,
|
||||
NALEZ_KATEGORIE, DRUH_NALEZU, SPECIFIKACE,
|
||||
NALEZOVE_OKOLNOSTI, NALEZCE,
|
||||
download_heslare, refresh_globals)
|
||||
|
||||
|
||||
# The date filter of the API requires both bounds; a one-sided range makes
|
||||
# the server fail with an ArrayIndexOutOfBoundsException and '*' is not
|
||||
# accepted either. An empty picker is therefore replaced by these sentinels,
|
||||
# which are also the default limits of QgsDateEdit.
|
||||
DATE_OPEN_FROM = "0001-01-01"
|
||||
DATE_OPEN_TO = "9999-12-31"
|
||||
|
||||
# Shown by a date picker that is left empty
|
||||
DATE_NULL_TEXT = "neomezeno"
|
||||
|
||||
|
||||
# Keep Python references to running tasks. QgsTaskManager only holds the
|
||||
# C++ object; without a Python-side reference the wrapper can be garbage
|
||||
# collected before the task finishes, which crashes QGIS.
|
||||
@@ -44,16 +59,19 @@ class UpdateCodelistsTask(QgsTask):
|
||||
refresh_globals()
|
||||
QgsMessageLog.logMessage(
|
||||
"Hesláře AMČR byly úspěšně aktualizovány.",
|
||||
"AMČR", Qgis.Info)
|
||||
"AMČR", Qgis.Info
|
||||
)
|
||||
else:
|
||||
if self.isCanceled():
|
||||
QgsMessageLog.logMessage(
|
||||
"Aktualizace heslářů byla zrušena.",
|
||||
"AMČR", Qgis.Warning)
|
||||
"AMČR", Qgis.Warning
|
||||
)
|
||||
else:
|
||||
QgsMessageLog.logMessage(
|
||||
f"Chyba aktualizace: {self.exception}",
|
||||
"AMČR", Qgis.Critical)
|
||||
"AMČR", Qgis.Critical
|
||||
)
|
||||
|
||||
|
||||
class FilterableSelectionDialog(QDialog):
|
||||
@@ -151,12 +169,31 @@ class AmcrFilterDialog(QDialog):
|
||||
|
||||
# Cache dictionary to store selected codes for each category
|
||||
self.selection_cache = {
|
||||
'organizace': [], 'kraj': [], 'obdobi': [], 'areal': [],
|
||||
'typ_akce': [], 'okres': [], 'katastr': [], 'vedouci': [],
|
||||
'pian_presnost': [], 'pristupnost': [], 'typ_lokality': [],
|
||||
'druh_lokality': [], 'jistota': [], 'lokalita_zachovalost': []
|
||||
'organizace': [],
|
||||
'kraj': [],
|
||||
'obdobi': [],
|
||||
'areal': [],
|
||||
'typ_akce': [],
|
||||
'okres': [],
|
||||
'katastr': [],
|
||||
'vedouci': [],
|
||||
'pian_presnost': [],
|
||||
'pristupnost': [],
|
||||
'typ_lokality': [],
|
||||
'druh_lokality': [],
|
||||
'jistota': [],
|
||||
'lokalita_zachovalost': [],
|
||||
'nalez_kategorie': [],
|
||||
'druh_nalezu': [],
|
||||
'specifikace': [],
|
||||
'nalezove_okolnosti': [],
|
||||
'nalezce': [],
|
||||
}
|
||||
|
||||
# Date range pickers, filled by setup_date_range():
|
||||
# (API field, label for messages, 'from' widget, 'to' widget)
|
||||
self.date_ranges = []
|
||||
|
||||
layout = QVBoxLayout()
|
||||
|
||||
# Filter by current map canvas extent
|
||||
@@ -169,6 +206,8 @@ class AmcrFilterDialog(QDialog):
|
||||
if self.typ_dat == "akce":
|
||||
self.chk_posevidence = QCheckBox("Pouze pozitivní zjištění")
|
||||
layout.addWidget(self.chk_posevidence)
|
||||
self.chk_proj_akce = QCheckBox("Pouze projektové akce")
|
||||
layout.addWidget(self.chk_proj_akce)
|
||||
|
||||
layout.addSpacing(10)
|
||||
|
||||
@@ -187,13 +226,6 @@ class AmcrFilterDialog(QDialog):
|
||||
)
|
||||
layout.addWidget(self.picker_katastr)
|
||||
|
||||
self.picker_presnost = self.setup_picker(
|
||||
"PIAN – přesnost",
|
||||
'pian_presnost',
|
||||
PIAN_PRESNOST
|
||||
)
|
||||
layout.addWidget(self.picker_presnost)
|
||||
|
||||
self.picker_pristupnost = self.setup_picker(
|
||||
"Přístupnost",
|
||||
'pristupnost',
|
||||
@@ -203,7 +235,15 @@ class AmcrFilterDialog(QDialog):
|
||||
|
||||
# Filters valid for Akce
|
||||
|
||||
if self.typ_dat == "akce":
|
||||
if self.typ_dat in ["lokalita", "akce"]:
|
||||
self.picker_presnost = self.setup_picker(
|
||||
"PIAN – přesnost",
|
||||
'pian_presnost',
|
||||
PIAN_PRESNOST
|
||||
)
|
||||
layout.addWidget(self.picker_presnost)
|
||||
|
||||
if self.typ_dat in ["samostatny_nalez", "akce"]:
|
||||
self.picker_org = self.setup_picker(
|
||||
"Organizace",
|
||||
'organizace',
|
||||
@@ -211,6 +251,7 @@ class AmcrFilterDialog(QDialog):
|
||||
)
|
||||
layout.addWidget(self.picker_org)
|
||||
|
||||
if self.typ_dat == "akce":
|
||||
self.picker_vedouci = self.setup_picker(
|
||||
"Vedoucí výzkumu",
|
||||
'vedouci',
|
||||
@@ -227,6 +268,12 @@ class AmcrFilterDialog(QDialog):
|
||||
)
|
||||
layout.addWidget(self.picker_typ)
|
||||
|
||||
self.box_datum = self.setup_date_range("Datum", [
|
||||
("akce_datum_zahajeni", "Zahájení", "Datum zahájení"),
|
||||
("akce_datum_ukonceni", "Ukončení", "Datum ukončení"),
|
||||
])
|
||||
layout.addWidget(self.box_datum)
|
||||
|
||||
# Filters valid for Lokality
|
||||
|
||||
if self.typ_dat == "lokalita":
|
||||
@@ -263,12 +310,56 @@ class AmcrFilterDialog(QDialog):
|
||||
self.picker_obdobi = self.setup_picker("Období", 'obdobi', OBDOBI)
|
||||
layout.addWidget(self.picker_obdobi)
|
||||
|
||||
self.picker_areal = self.setup_picker("Areál", 'areal', AREAL)
|
||||
layout.addWidget(self.picker_areal)
|
||||
if self.typ_dat == "samostatny_nalez":
|
||||
self.picker_nalez_kategorie = self.setup_picker(
|
||||
"Kategorie nálezu",
|
||||
'nalez_kategorie',
|
||||
NALEZ_KATEGORIE
|
||||
)
|
||||
layout.addWidget(self.picker_nalez_kategorie)
|
||||
|
||||
# Option to download related components table
|
||||
self.chk_komponenty = QCheckBox("Načíst komponenty")
|
||||
layout.addWidget(self.chk_komponenty)
|
||||
self.picker_druh_nalezu = self.setup_picker(
|
||||
"Druh nálezu",
|
||||
'druh_nalezu',
|
||||
DRUH_NALEZU
|
||||
)
|
||||
layout.addWidget(self.picker_druh_nalezu)
|
||||
|
||||
self.picker_specifikace = self.setup_picker(
|
||||
"Specifikace nálezu",
|
||||
'specifikace',
|
||||
SPECIFIKACE
|
||||
)
|
||||
layout.addWidget(self.picker_specifikace)
|
||||
|
||||
self.picker_nalezove_okolnosti = self.setup_picker(
|
||||
"Okolnosti nálezu",
|
||||
'nalezove_okolnosti',
|
||||
NALEZOVE_OKOLNOSTI
|
||||
)
|
||||
layout.addWidget(self.picker_nalezove_okolnosti)
|
||||
|
||||
self.picker_nalezce = self.setup_picker(
|
||||
"Nálezce",
|
||||
'nalezce',
|
||||
NALEZCE
|
||||
)
|
||||
layout.addWidget(self.picker_nalezce)
|
||||
|
||||
# Lokalita has no date field in the index at all, so the block
|
||||
# is built only for the two entities that do
|
||||
self.box_datum = self.setup_date_range("Datum nálezu", [
|
||||
("samostatny_nalez_datum_nalezu", "", "Datum nálezu"),
|
||||
])
|
||||
layout.addWidget(self.box_datum)
|
||||
|
||||
if self.typ_dat != "samostatny_nalez":
|
||||
self.picker_areal = self.setup_picker("Areál", 'areal', AREAL)
|
||||
layout.addWidget(self.picker_areal)
|
||||
|
||||
# Option to download related components table
|
||||
self.chk_komponenty = QCheckBox("Načíst komponenty")
|
||||
layout.addWidget(self.chk_komponenty)
|
||||
|
||||
# Warning label
|
||||
self.lbl_komponenty_warning = QLabel(
|
||||
@@ -284,13 +375,29 @@ class AmcrFilterDialog(QDialog):
|
||||
self.lbl_komponenty_warning.setVisible(False)
|
||||
layout.addWidget(self.lbl_komponenty_warning)
|
||||
|
||||
self.chk_komponenty.toggled.connect(
|
||||
self.lbl_komponenty_warning.setVisible
|
||||
)
|
||||
if self.typ_dat != "samostatny_nalez":
|
||||
self.chk_komponenty.toggled.connect(
|
||||
self.lbl_komponenty_warning.setVisible
|
||||
)
|
||||
|
||||
# Pushes everything above to the top
|
||||
layout.addStretch(1)
|
||||
|
||||
# The filter stack is taller than the window on every entity
|
||||
# (over 1000 px for 'akce'), so it scrolls. The buttons stay
|
||||
# outside the scroll area, otherwise the user would have to
|
||||
# scroll to the bottom just to confirm the dialog.
|
||||
content = QWidget()
|
||||
content.setLayout(layout)
|
||||
|
||||
scroll = QScrollArea()
|
||||
scroll.setWidgetResizable(True)
|
||||
scroll.setFrameShape(QFrame.Shape.NoFrame)
|
||||
scroll.setWidget(content)
|
||||
|
||||
outer = QVBoxLayout()
|
||||
outer.addWidget(scroll)
|
||||
|
||||
# Main dialog OK/Cancel/Update buttons
|
||||
|
||||
buttons = QDialogButtonBox()
|
||||
@@ -311,9 +418,9 @@ class AmcrFilterDialog(QDialog):
|
||||
|
||||
buttons.accepted.connect(self.accept)
|
||||
buttons.rejected.connect(self.reject)
|
||||
layout.addWidget(buttons)
|
||||
outer.addWidget(buttons)
|
||||
|
||||
self.setLayout(layout)
|
||||
self.setLayout(outer)
|
||||
|
||||
def setup_picker(self, label_text, cache_key, data_source, extra_btn=None):
|
||||
"""
|
||||
@@ -361,7 +468,7 @@ class AmcrFilterDialog(QDialog):
|
||||
self.selection_cache[cache_key] = [
|
||||
'HES-000861',
|
||||
'HES-000862',
|
||||
'HES-000863'
|
||||
'HES-000863',
|
||||
]
|
||||
|
||||
btn.clicked.connect(open_dialog)
|
||||
@@ -376,6 +483,94 @@ class AmcrFilterDialog(QDialog):
|
||||
row_widget.setLayout(row_layout)
|
||||
return row_widget
|
||||
|
||||
def setup_date_range(self, title, rows):
|
||||
"""
|
||||
Creates a compact date range block: one row per API date field,
|
||||
each with a 'from' and a 'to' picker.
|
||||
|
||||
rows is a list of (api_field, row_label, name_for_messages).
|
||||
An empty row_label is used when the group box title already names
|
||||
the field, which keeps the single-row variant from repeating itself.
|
||||
|
||||
A picker left empty means an open bound; the sentinel is
|
||||
substituted in get_filters(), not here, so that an untouched
|
||||
block adds no filter at all.
|
||||
"""
|
||||
row_widget = QGroupBox(title)
|
||||
grid = QGridLayout()
|
||||
grid.setContentsMargins(5, 5, 5, 5)
|
||||
grid.setVerticalSpacing(3)
|
||||
grid.setHorizontalSpacing(6)
|
||||
|
||||
for row, (api_field, row_label, name) in enumerate(rows):
|
||||
if row_label:
|
||||
grid.addWidget(QLabel(row_label), row, 0)
|
||||
|
||||
date_from = self._date_edit(
|
||||
f"{name} – od (prázdné = bez dolní meze)"
|
||||
)
|
||||
date_to = self._date_edit(
|
||||
f"{name} – do (prázdné = bez horní meze)"
|
||||
)
|
||||
|
||||
separator = QLabel("–")
|
||||
separator.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
grid.addWidget(date_from, row, 1)
|
||||
grid.addWidget(separator, row, 2)
|
||||
grid.addWidget(date_to, row, 3)
|
||||
|
||||
self.date_ranges.append((api_field, name, date_from, date_to))
|
||||
|
||||
grid.setColumnStretch(1, 1)
|
||||
grid.setColumnStretch(3, 1)
|
||||
|
||||
row_widget.setLayout(grid)
|
||||
return row_widget
|
||||
|
||||
@staticmethod
|
||||
def _date_edit(tooltip):
|
||||
"""
|
||||
A date picker that may stay empty.
|
||||
|
||||
clear() is essential here – setEmpty() looks empty but leaves
|
||||
isNull() False with today's date, which would silently apply
|
||||
a filter the user never set.
|
||||
"""
|
||||
widget = QgsDateEdit()
|
||||
widget.setAllowNull(True)
|
||||
widget.setNullRepresentation(DATE_NULL_TEXT)
|
||||
widget.setDisplayFormat("d. M. yyyy")
|
||||
widget.setCalendarPopup(True)
|
||||
widget.clear()
|
||||
widget.setToolTip(tooltip)
|
||||
return widget
|
||||
|
||||
def accept(self):
|
||||
"""
|
||||
Blocks the dialog on a reversed date range. The API answers such
|
||||
a query with zero records and no error, which is indistinguishable
|
||||
from a genuinely empty result.
|
||||
"""
|
||||
reversed_ranges = [
|
||||
name for _, name, date_from, date_to in self.date_ranges
|
||||
if not date_from.isNull() and not date_to.isNull()
|
||||
and date_from.date() > date_to.date()
|
||||
]
|
||||
|
||||
if reversed_ranges:
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
"Neplatné rozmezí",
|
||||
"U těchto filtrů je počáteční datum novější než koncové:\n"
|
||||
+ "\n".join(f"• {name}" for name in reversed_ranges)
|
||||
+ "\n\nDotaz by nevrátil žádný záznam. Opravte rozmezí, "
|
||||
"nebo jedno z polí vyprázdněte."
|
||||
)
|
||||
return
|
||||
|
||||
super().accept()
|
||||
|
||||
def action_update_heslare(self):
|
||||
# Create the task instance and keep a reference so the Python
|
||||
# wrapper survives until the task finishes
|
||||
@@ -428,7 +623,10 @@ class AmcrFilterDialog(QDialog):
|
||||
return "true" if self.chk_bbox.isChecked() else "false"
|
||||
|
||||
def get_komponenty(self):
|
||||
return "true" if self.chk_komponenty.isChecked() else "false"
|
||||
if self.typ_dat in ["akce", "lokalita"]:
|
||||
return "true" if self.chk_komponenty.isChecked() else "false"
|
||||
else:
|
||||
return "false"
|
||||
|
||||
def get_filters(self):
|
||||
"""Compiles the user selections from the cache into
|
||||
@@ -453,22 +651,52 @@ class AmcrFilterDialog(QDialog):
|
||||
if self.typ_dat == "akce":
|
||||
if self.chk_posevidence.isChecked():
|
||||
filters['posevidence'] = 'true'
|
||||
if self.selection_cache['organizace']:
|
||||
filters['f_organizace'] = self.selection_cache['organizace']
|
||||
if self.selection_cache['typ_akce']:
|
||||
filters['f_typ_vyzkumu'] = self.selection_cache['typ_akce']
|
||||
if self.selection_cache['vedouci']:
|
||||
filters['f_vedouci'] = self.selection_cache['vedouci']
|
||||
if self.chk_proj_akce.isChecked():
|
||||
filters['proj_akce'] = 'true'
|
||||
|
||||
if self.typ_dat == "lokalita":
|
||||
if self.selection_cache['typ_lokality']:
|
||||
filters['f_typ_lokality'] = self.selection_cache['typ_lokality']
|
||||
if self.selection_cache['druh_lokality']:
|
||||
filters['f_druh_lokality'] = self.selection_cache['druh_lokality']
|
||||
if self.selection_cache['jistota']:
|
||||
filters['f_jistota'] = self.selection_cache['jistota']
|
||||
if self.selection_cache['lokalita_zachovalost']:
|
||||
filters['f_lokalita_zachovalost'] = self.selection_cache['lokalita_zachovalost']
|
||||
if self.selection_cache['typ_akce']:
|
||||
filters['f_typ_vyzkumu'] = self.selection_cache['typ_akce']
|
||||
if self.selection_cache['vedouci']:
|
||||
filters['f_vedouci'] = self.selection_cache['vedouci']
|
||||
|
||||
if self.selection_cache['organizace']:
|
||||
filters['f_organizace'] = self.selection_cache['organizace']
|
||||
|
||||
if self.selection_cache['typ_lokality']:
|
||||
filters['f_typ_lokality'] = self.selection_cache['typ_lokality']
|
||||
if self.selection_cache['druh_lokality']:
|
||||
filters['f_druh_lokality'] = self.selection_cache['druh_lokality']
|
||||
if self.selection_cache['jistota']:
|
||||
filters['f_jistota'] = self.selection_cache['jistota']
|
||||
if self.selection_cache['lokalita_zachovalost']:
|
||||
filters['f_lokalita_zachovalost'] = self.selection_cache['lokalita_zachovalost']
|
||||
|
||||
# Samostatné nálezy
|
||||
if self.selection_cache['nalez_kategorie']:
|
||||
filters['f_kategorie'] = self.selection_cache['nalez_kategorie']
|
||||
if self.selection_cache['druh_nalezu']:
|
||||
filters['f_druh_nalezu'] = self.selection_cache['druh_nalezu']
|
||||
if self.selection_cache['specifikace']:
|
||||
filters['f_specifikace'] = self.selection_cache['specifikace']
|
||||
if self.selection_cache['nalezove_okolnosti']:
|
||||
filters['f_nalezove_okolnosti'] = self.selection_cache['nalezove_okolnosti']
|
||||
if self.selection_cache['nalezce']:
|
||||
filters['f_nalezce'] = self.selection_cache['nalezce']
|
||||
|
||||
# Date ranges – the API needs both bounds, so an empty picker is
|
||||
# replaced by a sentinel. A block with both pickers empty adds no
|
||||
# filter at all; sending the full 0001–9999 range would only
|
||||
# clutter the log without narrowing anything.
|
||||
for api_field, _, date_from, date_to in self.date_ranges:
|
||||
if date_from.isNull() and date_to.isNull():
|
||||
continue
|
||||
|
||||
od = (DATE_OPEN_FROM if date_from.isNull()
|
||||
else date_from.date().toString("yyyy-MM-dd"))
|
||||
do = (DATE_OPEN_TO if date_to.isNull()
|
||||
else date_to.date().toString("yyyy-MM-dd"))
|
||||
|
||||
filters[api_field] = f"{od},{do}"
|
||||
|
||||
return filters
|
||||
|
||||
|
||||
+697
-371
File diff suppressed because it is too large.
Load diff
@@ -90,6 +90,7 @@ class AmcrViewer:
|
||||
"""
|
||||
# Define paths for action-specific icons
|
||||
icon_akce_path = os.path.join(self.plugin_dir, 'akce.png')
|
||||
icon_pas_path = os.path.join(self.plugin_dir, 'sn.png')
|
||||
icon_lokality_path = os.path.join(self.plugin_dir, 'lokality.png')
|
||||
icon_amcr_help_path = os.path.join(self.plugin_dir, 'amcr-help.png')
|
||||
|
||||
@@ -109,6 +110,16 @@ class AmcrViewer:
|
||||
)
|
||||
self.plugin_menu.addAction(self.action_download_akce)
|
||||
|
||||
self.action_download_pas = self.add_action(
|
||||
icon_path=icon_pas_path,
|
||||
text=self.tr(u'Stáhnout data samostatných nálezů | AMČR Viewer'),
|
||||
callback=lambda checked=False: self.run_download('samostatny_nalez'),
|
||||
parent=self.iface.mainWindow(),
|
||||
add_to_menu=False,
|
||||
add_to_toolbar=False
|
||||
)
|
||||
self.plugin_menu.addAction(self.action_download_pas)
|
||||
|
||||
self.action_download_lokality = self.add_action(
|
||||
icon_path=icon_lokality_path,
|
||||
text=self.tr(u'Stáhnout data lokalit | AMČR Viewer'),
|
||||
@@ -120,7 +131,7 @@ class AmcrViewer:
|
||||
self.plugin_menu.addAction(self.action_download_lokality)
|
||||
|
||||
self.action_login_dialog = self.add_action(
|
||||
icon_path=icon_akce_path,
|
||||
icon_path=icon_pas_path,
|
||||
text=self.tr(u'Přihlásit se | AMČR Viewer'),
|
||||
callback=lambda checked=False: self.login(),
|
||||
parent=self.iface.mainWindow(),
|
||||
|
||||
+16863
-21873
File diff suppressed because it is too large.
Load diff
@@ -8,7 +8,7 @@ name=AMČR Viewer
|
||||
qgisMinimumVersion=3.44.0
|
||||
qgisMaximumVersion=4.99.0
|
||||
description=Viewing and downloading the AMČR data.
|
||||
version=2.0.2
|
||||
version=2.1.0
|
||||
author=David Spáčil
|
||||
email=spacil@arub.cz
|
||||
|
||||
@@ -23,9 +23,16 @@ repository=https://github.com/ARUP-CAS/aiscr-qgis-amcr-viewer
|
||||
hasProcessingProvider=no
|
||||
# Uncomment the following line and add your changelog:
|
||||
changelog=
|
||||
Aktualizace na verzi 2.0.0 výrazně mění chování pluginu. Před updatem je doporučeno přečíst si seznam změn níže.
|
||||
Version 2.0.0 changes the plugin behavior dramatically. It is advised to check the changelog below.
|
||||
Plný seznam změn v češtině je dostupný zde: https://github.com/ARUP-CAS/aiscr-qgis-amcr-viewer/releases/tag/v2.0.0
|
||||
Plný seznam změn v češtině je dostupný zde: https://github.com/ARUP-CAS/aiscr-qgis-amcr-viewer/releases/tag/v2.1.0
|
||||
v2.1.0 (2026-09-01)
|
||||
* Added download of Individual finds (PAS), including a dedicated menu entry
|
||||
* Added filtering by date
|
||||
* Added filtering of project fieldwork events and a Project column in the attribute table
|
||||
* Codelists are now built from the Digiarchiv API as well, not only from OAI-PMH; persons come from its facets by role (finder, fieldwork leader)
|
||||
* Updated the bundled codelist file
|
||||
* Filter dialog is now scrollable
|
||||
* Empty API results are now diagnosable from the Messages panel: the query URL and API errors are logged
|
||||
* Code clean-up
|
||||
v2.0.2 (2026-06-13)
|
||||
* Plugin-wide fixes and optimalizations (details https://github.com/ARUP-CAS/aiscr-qgis-amcr-viewer/pull/49)
|
||||
v2.0.1 (2026-06-10)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 871 B |
+23
-7
@@ -9,7 +9,7 @@
|
||||
id="svg1"
|
||||
xml:space="preserve"
|
||||
sodipodi:docname="icon.svg"
|
||||
inkscape:version="1.4.3 (0d15f75, 2025-12-25)"
|
||||
inkscape:version="1.4.4 (dcaf3e7d9e, 2026-05-05)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
@@ -24,12 +24,12 @@
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="22.627417"
|
||||
inkscape:cx="6.8059028"
|
||||
inkscape:cy="14.606174"
|
||||
inkscape:cx="0.57452426"
|
||||
inkscape:cy="15.556349"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1009"
|
||||
inkscape:window-x="1912"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-height="1131"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" /><defs
|
||||
id="defs1"><clipPath
|
||||
@@ -96,4 +96,20 @@
|
||||
d="M 3.3486328 2.4970052 L 3.3486328 3.8323242 L 2.7424683 3.8323242 L 4.2085286 5.738151 L 5.674589 3.8323242 L 5.0684245 3.8323242 L 5.0684245 2.4970052 L 3.3486328 2.4970052 z "
|
||||
inkscape:export-filename="path32.png"
|
||||
inkscape:export-xdpi="3000"
|
||||
inkscape:export-ydpi="3000" /></g></svg>
|
||||
inkscape:export-ydpi="3000" /><rect
|
||||
style="opacity:1;fill:#85140e;fill-opacity:1;stroke:none;stroke-width:0.414999;stroke-linecap:butt;stroke-linejoin:round;stroke-dasharray:none;paint-order:stroke fill markers"
|
||||
id="rect1"
|
||||
width="1.672105"
|
||||
height="1.2511554"
|
||||
x="-4.501821"
|
||||
y="4.2814822" /><text
|
||||
xml:space="preserve"
|
||||
style="font-size:0.705556px;font-family:'Open Sans';-inkscape-font-specification:'Open Sans';text-align:start;writing-mode:lr-tb;direction:ltr;text-anchor:start;opacity:1;fill:#85140e;fill-opacity:1;stroke:none;stroke-width:0.414999;stroke-linecap:butt;stroke-linejoin:round;stroke-dasharray:none;paint-order:stroke fill markers"
|
||||
x="-2.6360023"
|
||||
y="5.1136947"
|
||||
id="text1"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan1"
|
||||
style="font-size:0.705556px;fill:#85140e;fill-opacity:1;stroke-width:0.415"
|
||||
x="-2.6360023"
|
||||
y="5.1136947">lokality</tspan></text></g></svg>
|
||||
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 7.2 KiB |
Reference in new issue
Block a user