forked from csgis/kgr_finder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_osm_data.py
176 lines (138 loc) · 6.06 KB
/
find_osm_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*- coding: utf-8 -*-
"""
/***************************************************************************
KgrFinder
A QGIS plugin
Find KGR Data
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2023-09-11
git sha : $Format:%H$
copyright : (C) 2023 by csgis gbr
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QVBoxLayout
# Initialize Qt resources from file resources.py
from .resources import *
import os.path
from qgis.core import QgsSettings
from qgis.gui import QgsOptionsWidgetFactory, QgsOptionsPageWidget
from qgis.utils import iface
from qgis.PyQt.QtWidgets import QFormLayout, QCheckBox
import json
from qgis.gui import QgsCollapsibleGroupBox
import requests
from .tools import KgrFinderTool
class KgrFinderOptionsFactory(QgsOptionsWidgetFactory):
def __init__(self):
super().__init__()
def icon(self):
return QIcon(':/plugins/kgr_finder/icon.png')
def createWidget(self, parent):
return ConfigOptionsPage(parent)
class ConfigOptionsPage(QgsOptionsPageWidget):
osm_tags = [
"place_of_worship",
"Historic",
"Museum",
"Memorial",
"Artwork",
"Castle",
"Ruins",
"Archaeological Site",
"Monastery",
"Cultural Centre",
"Library",
"heritage"
]
additional_tags = [
"Tag1",
"Tag2",
"Tag3"
]
def __init__(self, parent):
super().__init__(parent)
layout = QFormLayout()
self.setLayout(layout)
self.section_checkboxes = {} # Initialize as a class variable
self.createCheckBoxes(layout, "OSM – Cultural Tags", self.osm_tags, "osm_tags")
self.createCheckBoxes(layout, "Additional Tags", self.additional_tags, "additional_tags")
self.loadAndSetCheckboxes()
def createCheckBoxes(self, layout, group_title, tags, settings_key):
group_box = QgsCollapsibleGroupBox(group_title)
group_box_layout = QVBoxLayout()
group_box.setLayout(group_box_layout)
checkboxes = []
for tag in tags:
checkbox = QCheckBox(tag)
checkbox.setStyleSheet("margin: 10px;")
checkbox.stateChanged.connect(self.checkboxStateChanged)
checkboxes.append((tag, checkbox))
group_box_layout.addWidget(checkbox)
layout.addWidget(group_box)
# Save checkboxes in the dictionary
self.section_checkboxes[settings_key] = checkboxes
# Load selected tags from settings and set checkboxes
osm_tags = QgsSettings().value(f"/KgrFinder/{settings_key}", [])
for tag, checkbox in checkboxes:
checkbox.setChecked(tag in osm_tags)
def apply(self):
for settings_key, checkboxes in self.section_checkboxes.items():
osm_tags = [tag for tag, checkbox in checkboxes if checkbox.isChecked()]
QgsSettings().setValue(f"/KgrFinder/{settings_key}", osm_tags)
def loadAndSetCheckboxes(self):
for settings_key, checkboxes in self.section_checkboxes.items():
osm_tags = QgsSettings().value(f"/KgrFinder/{settings_key}", [])
for tag, checkbox in checkboxes:
checkbox.setChecked(tag in osm_tags)
def checkboxStateChanged(self):
for settings_key, checkboxes in self.section_checkboxes.items():
osm_tags = [tag for tag, checkbox in checkboxes if checkbox.isChecked()]
QgsSettings().setValue(f"/KgrFinder/{settings_key}", osm_tags)
class KgrFinder:
"""QGIS Plugin Implementation."""
def __init__(self, iface):
# save reference to the QGIS interface
self.iface = iface
self.tool = None
def initGui(self):
# create action that will start plugin configuration
self.action = QAction(QIcon(":/plugins/kgr_finder/icon.png"),
"KGR Finder",
self.iface.mainWindow())
self.action.setObjectName("KGRAction")
self.action.setWhatsThis("Configuration for KGR Finder")
self.action.setStatusTip("This is status tip")
self.action.setCheckable(True) # Make the action checkable
self.action.toggled.connect(self.toggleTool)
# add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
# self.iface.addPluginToMenu("&Test plugins", self.action)
self.options_factory = KgrFinderOptionsFactory()
self.options_factory.setTitle('OSM Finder')
iface.registerOptionsWidgetFactory(self.options_factory)
def unload(self):
# remove the plugin menu item and icon
# self.iface.removePluginMenu("&Test plugins", self.action)
self.iface.removeToolBarIcon(self.action)
iface.unregisterOptionsWidgetFactory(self.options_factory)
def toggleTool(self, checked):
if checked:
self.tool = KgrFinderTool(self.iface.mapCanvas())
self.iface.mapCanvas().setMapTool(self.tool)
else:
self.iface.mapCanvas().unsetMapTool(self.tool)
self.tool = None
def run(self):
# create and show a configuration dialog or something similar
print("KGR Plugin: run called!")